aboutsummaryrefslogtreecommitdiffstats
path: root/hw/goldfish_nand.c
diff options
context:
space:
mode:
authorVladimir Chtchetkine <vchtchetkine@google.com>2010-08-26 09:03:54 -0700
committerVladimir Chtchetkine <vchtchetkine@google.com>2010-08-26 09:03:54 -0700
commite13168648d5947955e0fd4fbf396f891ae53921f (patch)
tree6ca7f9f091daa6097e5b36812be87c905a243f81 /hw/goldfish_nand.c
parent3f16680b70d6c065fd2c1672ae324a49c5d1d316 (diff)
downloadexternal_qemu-e13168648d5947955e0fd4fbf396f891ae53921f.zip
external_qemu-e13168648d5947955e0fd4fbf396f891ae53921f.tar.gz
external_qemu-e13168648d5947955e0fd4fbf396f891ae53921f.tar.bz2
Moved nand and netspeed initialization from main to core.
Change-Id: Ide3914fa52f62f618d39ac20f02bce8185a6805a
Diffstat (limited to 'hw/goldfish_nand.c')
-rw-r--r--hw/goldfish_nand.c110
1 files changed, 108 insertions, 2 deletions
diff --git a/hw/goldfish_nand.c b/hw/goldfish_nand.c
index 2d23baa..1570095 100644
--- a/hw/goldfish_nand.c
+++ b/hw/goldfish_nand.c
@@ -76,13 +76,13 @@ nand_threshold_update( nand_threshold* t, uint32_t len )
avail = len;
if (t->counter == 0) {
- T("%s: starting threshold counting to %lld",
+ T("%s: starting threshold counting to %lld",
__FUNCTION__, t->limit);
}
t->counter += avail;
if (t->counter >= t->limit) {
/* threshold reach, send a signal to an external process */
- T( "%s: sending signal %d to pid %d !",
+ T( "%s: sending signal %d to pid %d !",
__FUNCTION__, t->signal, t->pid );
kill( t->pid, t->signal );
@@ -632,3 +632,109 @@ bad_arg_and_value:
exit(1);
}
+#ifdef CONFIG_NAND_LIMITS
+
+static uint64_t
+parse_nand_rw_limit( const char* value )
+{
+ char* end;
+ uint64_t val = strtoul( value, &end, 0 );
+
+ if (end == value) {
+ derror( "bad parameter value '%s': expecting unsigned integer", value );
+ exit(1);
+ }
+
+ switch (end[0]) {
+ case 'K': val <<= 10; break;
+ case 'M': val <<= 20; break;
+ case 'G': val <<= 30; break;
+ case 0: break;
+ default:
+ derror( "bad read/write limit suffix: use K, M or G" );
+ exit(1);
+ }
+ return val;
+}
+
+void
+parse_nand_limits(char* limits)
+{
+ int pid = -1, signal = -1;
+ int64_t reads = 0, writes = 0;
+ char* item = limits;
+
+ /* parse over comma-separated items */
+ while (item && *item) {
+ char* next = strchr(item, ',');
+ char* end;
+
+ if (next == NULL) {
+ next = item + strlen(item);
+ } else {
+ *next++ = 0;
+ }
+
+ if ( !memcmp(item, "pid=", 4) ) {
+ pid = strtol(item+4, &end, 10);
+ if (end == NULL || *end) {
+ derror( "bad parameter, expecting pid=<number>, got '%s'",
+ item );
+ exit(1);
+ }
+ if (pid <= 0) {
+ derror( "bad parameter: process identifier must be > 0" );
+ exit(1);
+ }
+ }
+ else if ( !memcmp(item, "signal=", 7) ) {
+ signal = strtol(item+7,&end, 10);
+ if (end == NULL || *end) {
+ derror( "bad parameter: expecting signal=<number>, got '%s'",
+ item );
+ exit(1);
+ }
+ if (signal <= 0) {
+ derror( "bad parameter: signal number must be > 0" );
+ exit(1);
+ }
+ }
+ else if ( !memcmp(item, "reads=", 6) ) {
+ reads = parse_nand_rw_limit(item+6);
+ }
+ else if ( !memcmp(item, "writes=", 7) ) {
+ writes = parse_nand_rw_limit(item+7);
+ }
+ else {
+ derror( "bad parameter '%s' (see -help-nand-limits)", item );
+ exit(1);
+ }
+ item = next;
+ }
+ if (pid < 0) {
+ derror( "bad paramater: missing pid=<number>" );
+ exit(1);
+ }
+ else if (signal < 0) {
+ derror( "bad parameter: missing signal=<number>" );
+ exit(1);
+ }
+ else if (reads == 0 && writes == 0) {
+ dwarning( "no read or write limit specified. ignoring -nand-limits" );
+ } else {
+ nand_threshold* t;
+
+ t = &android_nand_read_threshold;
+ t->pid = pid;
+ t->signal = signal;
+ t->counter = 0;
+ t->limit = reads;
+
+ t = &android_nand_write_threshold;
+ t->pid = pid;
+ t->signal = signal;
+ t->counter = 0;
+ t->limit = writes;
+ }
+}
+#endif /* CONFIG_NAND_LIMITS */