[parisc-linux-cvs] System RAM / ROM in /proc/iomem

Matthew Wilcox willy@ldl.fc.hp.com
Sat, 06 Oct 2001 19:18:56 -0600


This patch removes two kludges & a fixme.  It also removes 4 compiler
warnings.  As a nice sideeffect, it puts the ranges in /proc/iomem that
the original author intended :-)

Index: arch/parisc/mm/init.c
===================================================================
RCS file: /home/cvs/parisc/linux/arch/parisc/mm/init.c,v
retrieving revision 1.39
diff -u -p -r1.39 init.c
--- arch/parisc/mm/init.c	2001/10/04 11:05:46	1.39
+++ arch/parisc/mm/init.c	2001/10/07 01:11:04
@@ -33,44 +33,31 @@ unsigned char *chunkmap;
 unsigned int maxchunkmap;
 #endif
 
-/*
-** KLUGE ALERT!
-**
-** We *really* should be using a combination of request_resource()
-** and request_region()! But request_region() requires kmalloc since
-** returns a new struct resource. And kmalloc just isn't available
-** until after mem_init() is called from start_kernel().
-**
-** FIXME: assume contiguous memory initially.
-**     Additional chunks of memory might be added to sysram_resource.sibling.
-*/
-static struct resource sysrom_resource  = {
-	name: "System ROM", start: 0x0f0000000UL, end: 0x0f00fffffUL,
-	flags: IORESOURCE_BUSY | IORESOURCE_MEM,
-	parent: &iomem_resource, sibling: NULL, child: NULL };
-
-static struct resource pdcdata_resource;
-
-static struct resource sysram_resource  = {
-	name: "System RAM", start: 0UL, end: ~0UL /* bogus */,
-	flags: IORESOURCE_MEM,
-	parent: &iomem_resource, sibling: &sysrom_resource, child: &pdcdata_resource};
-
-static struct resource data_resource    = {
-	name: "kernel Data", start: virt_to_phys(&data_start), end: virt_to_phys(&_end)-1,
-	flags: IORESOURCE_BUSY | IORESOURCE_MEM,
-	parent: &sysram_resource, sibling: NULL, child: NULL};
+static struct resource sysrom_resource = {
+	name:	"System ROM",
+	start:	0xf0000000UL,
+	end:	0xf00fffffUL,
+	flags:	IORESOURCE_BUSY | IORESOURCE_MEM,
+};
+
+static struct resource data_resource = {
+	name:	"Kernel data",
+	flags:	IORESOURCE_BUSY | IORESOURCE_MEM,
+};
 
 static struct resource code_resource = {
-	name: "Kernel Code", start: virt_to_phys(&_text), end: virt_to_phys(&data_start)-1,
-	flags: IORESOURCE_BUSY | IORESOURCE_MEM,
-	parent: &sysram_resource, sibling: &data_resource, child: NULL};
+	name:	"Kernel code",
+	flags:	IORESOURCE_BUSY | IORESOURCE_MEM,
+};
 
 static struct resource pdcdata_resource = {
-	name: "PDC data (Page Zero)", start: 0, end: 0x9ff,
-	flags: IORESOURCE_BUSY | IORESOURCE_MEM,
-	parent: &sysram_resource, sibling: &code_resource, child: NULL};
+	name:	"PDC data (Page Zero)",
+	start:	0,
+	end:	0x9ff,
+	flags:	IORESOURCE_BUSY | IORESOURCE_MEM,
+};
 
+static struct resource sysram_resources[MAX_PHYSMEM_RANGES];
 
 static unsigned long max_pfn;
 
@@ -130,7 +117,7 @@ static void __init setup_bootmem(void)
 	physmem_range_t pmem_holes[MAX_PHYSMEM_RANGES - 1];
 	int npmem_holes;
 #endif
-	int i;
+	int i, sysram_resource_count;
 
 	disable_sr_hashing(); /* Turn off space register hashing */
 
@@ -211,6 +198,21 @@ static void __init setup_bootmem(void)
 
 #endif /* __LP64__ */
 
+#if 1
+	/* KLUGE! this really belongs in kernel/resource.c! */
+	iomem_resource.end = ~0UL;
+#endif
+
+	sysram_resource_count = npmem_ranges;
+	for (i = 0; i < sysram_resource_count; i++) {
+		struct resource *res = &sysram_resources[i];
+		res->name = "System RAM";
+		res->start = pmem_ranges[i].start_pfn << PAGE_SHIFT;
+		res->end = res->start + (pmem_ranges[i].pages << PAGE_SHIFT)-1;
+		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+		request_resource(&iomem_resource, res);
+	}
+
 	/*
 	 * For 32 bit kernels we limit the amount of memory we can
 	 * support, in order to preserve enough kernel address space
@@ -337,7 +339,7 @@ static void __init setup_bootmem(void)
 
 #ifdef CONFIG_BLK_DEV_INITRD
 	if (initrd_start) {
-		printk(KERN_INFO "initrd: %08x-%08x\n", initrd_start, initrd_end);
+		printk(KERN_INFO "initrd: %08lx-%08lx\n", initrd_start, initrd_end);
 		if (__pa(initrd_start) < mem_max) {
 			unsigned long initrd_reserve;
 
@@ -354,14 +356,21 @@ static void __init setup_bootmem(void)
 	}
 #endif
 
-#if 1
-	/* KLUGE! this really belongs in kernel/resource.c! */
-	iomem_resource.end = ~0UL;
-#endif
+	data_resource.start =  virt_to_phys(&data_start);
+	data_resource.end = virt_to_phys(&_end)-1;
+	code_resource.start = virt_to_phys(&_text);
+	code_resource.end = virt_to_phys(&data_start)-1;
 
-	/* HACK! just use range 0 for now */
-
-	sysram_resource.end = ((pmem_ranges[0].start_pfn + pmem_ranges[0].pages) << PAGE_SHIFT) - 1;
+	/* We don't know which region the kernel will be in, so try
+	 * all of them.
+	 */
+	for (i = 0; i < sysram_resource_count; i++) {
+		struct resource *res = &sysram_resources[i];
+		request_resource(res, &code_resource);
+		request_resource(res, &data_resource);
+	}
+	request_resource(&sysram_resources[0], &pdcdata_resource);
+	request_resource(&iomem_resource, &sysrom_resource);
 }
 
 void free_initmem(void)