[parisc-linux-cvs] patch for "mem=" support

Bjorn Helgaas bjorn_helgaas@hp.com
Fri, 16 Mar 2001 16:45:40 -0700


Here's a proposal for adding support for the "mem=" kernel parameter.  
Unfortunately, this information is needed before the __setup() functions 
are called, hence the explicit call in setup_bootmem().

Bjorn


Index: arch/parisc/mm/init.c
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc/mm/init.c,v
retrieving revision 1.31
diff -u -p -r1.31 init.c
--- init.c	2001/03/02 10:31:49	1.31
+++ init.c	2001/03/15 23:07:17
@@ -79,6 +79,37 @@ int npmem_ranges;
 #define MAX_MEM         (3584U*1024U*1024U)
 #endif /* !__LP64__ */
 
+static unsigned long mem_limit = MAX_MEM;
+
+static int __init mem_limit_func(void)
+{
+	char *cp, *end;
+	unsigned long limit;
+	extern char saved_command_line[];
+
+	/* We need this before __setup() functions are called */
+
+	for (cp = saved_command_line; *cp; ) {
+		if (memcmp(cp, "mem=", 4) == 0) {
+			cp += 4;
+			limit = memparse(cp, &end);
+			if (end != cp)
+				break;
+			cp = end;
+		} else {
+			while (*cp != ' ' && *cp)
+				++cp;
+			while (*cp == ' ')
+				++cp;
+		}
+	}
+
+	if (limit < mem_limit) {
+		mem_limit = limit;
+	}
+	return 1;
+}
+
 static void __init setup_bootmem(void)
 {
 	unsigned long bootmap_size;
@@ -139,17 +170,18 @@ static void __init setup_bootmem(void)
 	 * to work with multiple memory ranges).
 	 */
 
+	mem_limit_func();	/* check for "mem=" argument */
 	mem_max = 0;
 
-	for (i = 0; (i < npmem_ranges) && (mem_max < MAX_MEM); i++) {
+	for (i = 0; (i < npmem_ranges) && (mem_max < mem_limit); i++) {
 		unsigned long rsize;
 
 		rsize = pmem_ranges[i].pages << PAGE_SHIFT;
-		if ((mem_max + rsize) > MAX_MEM) {
-			printk("Memory truncated to %ld Mb\n", MAX_MEM >> 20);
-			pmem_ranges[i].pages =   (MAX_MEM >> PAGE_SHIFT)
+		if ((mem_max + rsize) > mem_limit) {
+			printk("Memory truncated to %ld Mb\n", mem_limit >> 20);
+			pmem_ranges[i].pages =   (mem_limit >> PAGE_SHIFT)
 					       - (mem_max >> PAGE_SHIFT);
-			mem_max = MAX_MEM;
+			mem_max = mem_limit;
 			npmem_ranges = i + 1;
 			break;
 		}