From: Ben Gras Date: Fri, 16 Feb 2007 15:54:28 +0000 (+0000) Subject: . made memory parsing function into a library call X-Git-Tag: v3.1.3~75 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=3275602598f40d6a667ef59edc8fad2813e4251c;p=minix.git . made memory parsing function into a library call (moved 'struct memory' to for this library call) . removed some debugging messages from pci library --- diff --git a/include/env.h b/include/env.h index d25e6a244..81011fc7c 100644 --- a/include/env.h +++ b/include/env.h @@ -2,3 +2,5 @@ _PROTOTYPE( int env_parse, (char *env, char *fmt, int field, long *param, long min, long max) ); _PROTOTYPE( void env_panic, (char *env) ); _PROTOTYPE( int env_prefix, (char *env, char *prefix) ); +_PROTOTYPE( int env_memory_parse, (struct memory *chunks, int nchunks) ); + diff --git a/include/minix/type.h b/include/minix/type.h index 65c9cbe48..08582c253 100755 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -170,4 +170,10 @@ struct exec_newmem char progname[16]; /* Should be at least PROC_NAME_LEN */ }; +/* Memory chunks. */ +struct memory { + phys_bytes base; + phys_bytes size; +}; + #endif /* _TYPE_H */ diff --git a/kernel/type.h b/kernel/type.h index 4a8fb9c93..6f3bff9d1 100755 --- a/kernel/type.h +++ b/kernel/type.h @@ -27,11 +27,6 @@ struct boot_image { endpoint_t endpoint; /* endpoint number when started */ }; -struct memory { - phys_clicks base; /* start address of chunk */ - phys_clicks size; /* size of memory chunk */ -}; - /* The kernel outputs diagnostic messages in a circular buffer. */ struct kmessages { int km_next; /* next index to write */ diff --git a/lib/syslib/pci_set_acl.c b/lib/syslib/pci_set_acl.c index 2ec17decd..164a17791 100644 --- a/lib/syslib/pci_set_acl.c +++ b/lib/syslib/pci_set_acl.c @@ -30,10 +30,8 @@ struct rs_pci *rs_pci; } -printf("pci_set_acl: before cpf_grant_direct\n"); gid= cpf_grant_direct(pci_procnr, (vir_bytes)rs_pci, sizeof(*rs_pci), CPF_READ); -printf("pci_set_acl: after cpf_grant_direct: gid %d\n", gid); if (gid == -1) { printf("pci_set_acl: cpf_grant_direct failed: %d\n", @@ -44,11 +42,8 @@ printf("pci_set_acl: after cpf_grant_direct: gid %d\n", gid); m.m_type= BUSC_PCI_ACL; m.m1_i1= gid; -printf("pci_set_acl: before sendrec to %d\n", pci_procnr); r= sendrec(pci_procnr, &m); -printf("pci_set_acl: after sendrec to %d\n", pci_procnr); cpf_revoke(gid); -printf("pci_set_acl: after cpf_revoke\n"); if (r != 0) panic("pci", "pci_set_acl: can't talk to PCI", r); diff --git a/lib/sysutil/env_parse.c b/lib/sysutil/env_parse.c index ce2768484..c20d5126f 100644 --- a/lib/sysutil/env_parse.c +++ b/lib/sysutil/env_parse.c @@ -1,5 +1,6 @@ #include "sysutil.h" #include +#include #include @@ -88,4 +89,53 @@ badenv: return -1; } +/*=========================================================================* + * env_memory_parse * + *=========================================================================*/ + +PUBLIC int env_memory_parse(mem_chunks, maxchunks) +struct memory *mem_chunks; /* where to store the memory bits */ +int maxchunks; /* how many were found */ +{ + int i, done = 0; + char *s; + struct memory *memp; + char memstr[100], *end; + + /* Initialize everything to zero. */ + for (i = 0; i < maxchunks; i++) { + memp = &mem_chunks[i]; /* next mem chunk is stored here */ + memp->base = memp->size = 0; + } + /* The available memory is determined by MINIX' boot loader as a list of + * (base:size)-pairs in boothead.s. The 'memory' boot variable is set in + * in boot.s. The format is "b0:s0,b1:s1,b2:s2", where b0:s0 is low mem, + * b1:s1 is mem between 1M and 16M, b2:s2 is mem above 16M. Pairs b1:s1 + * and b2:s2 are combined if the memory is adjacent. + */ + if(env_get_param("memory", memstr, sizeof(memstr)-1) != OK) + return -1; + s = memstr; + for (i = 0; i < maxchunks && !done; i++) { + phys_bytes base = 0, size = 0, limit; + memp = &mem_chunks[i]; /* next mem chunk is stored here */ + if (*s != 0) { /* get fresh data, unless at end */ + + /* Read fresh base and expect colon as next char. */ + base = strtoul(s, &end, 0x10); /* get number */ + if (end != s && *end == ':') s = ++end; /* skip ':' */ + else *s=0; /* terminate, should not happen */ + + /* Read fresh size and expect comma or assume end. */ + size = strtoul(s, &end, 0x10); /* get number */ + if (end != s && *end == ',') s = ++end; /* skip ',' */ + else done = 1; + } + if (base + size <= base) continue; + memp->base = base; + memp->size = size; + } + + return OK; +}