Skip to contentSkip to conversation

ARM: use memblock memory regions for "System RAM" I/O resources

PATCH New Dima Zavin 2 participants 8 messages Jan 12, 2011 – Jan 14, 2011 Arm (32-bit)

lore
Share & tools
lore

Dima Zavin

author
#0 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Instead, iterate through the regions of memblock.memory and add those as "System RAM" resources.

---
 arch/arm/kernel/setup.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
arch/arm/kernel/setup.c +4 -6
index 336f14e..c3aa394 100644
@@ -520,6 +520,7 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
 static void __init
 request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
 {
+	struct memblock_type *mem = &memblock.memory;
 	struct resource *res;
 	int i;
 
@@ -528,14 +529,11 @@ request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
 	kernel_data.start   = virt_to_phys(_sdata);
 	kernel_data.end     = virt_to_phys(_end - 1);
 
-	for (i = 0; i < mi->nr_banks; i++) {
-		if (mi->bank[i].size == 0)
-			continue;
-
+	for (i = 0; i < mem->cnt; i++) {
 		res = alloc_bootmem_low(sizeof(*res));
 		res->name  = "System RAM";
-		res->start = mi->bank[i].start;
-		res->end   = mi->bank[i].start + mi->bank[i].size - 1;
+		res->start = mem->regions[i].base;
+		res->end   = mem->regions[i].base + mem->regions[i].size - 1;
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 
 		request_resource(&iomem_resource, res);
Signature · 1 line
1.7.3.1
#1 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

Quoted 20 lines · Dima Zavin

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Instead, iterate through the regions of memblock.memory and add those as "System RAM" resources.

---
 arch/arm/kernel/setup.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
arch/arm/kernel/setup.c +0 -0
index 336f14e..c3aa394 100644

arch/arm/kernel/setup.c setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz) · line 521

Quoted 2 lines
arch/arm/kernel/setup.c +0 -0
@@ -520,6 +520,7 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
 static void __init
 request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)

Doesn't this means we can get rid of the 'mi' argument?

author
#2 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

yes. I'll respin the patch.

Quoted 26 lines · Russell King - ARM Linux
Quoted 20 lines · Dima Zavin

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Instead, iterate through the regions of memblock.memory and add those as "System RAM" resources.

---
?arch/arm/kernel/setup.c | ? 10 ++++------
?1 files changed, 4 insertions(+), 6 deletions(-)

arch/arm/kernel/setup.c +0 -0
index 336f14e..c3aa394 100644
@@ -520,6 +520,7 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
Quoted 2 lines

?static void __init
?request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)

Doesn't this means we can get rid of the 'mi' argument?

author
#3 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Instead, iterate through the regions of memblock.memory and add those as "System RAM" resources.

---
 arch/arm/kernel/setup.c |   14 ++++++--------
 1 files changed, 6 insertions(+), 8 deletions(-)
arch/arm/kernel/setup.c +6 -8
index 336f14e..b291a6b 100644
@@ -518,8 +518,9 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
 }
 
 static void __init
-request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
+request_standard_resources(struct machine_desc *mdesc)
 {
+	struct memblock_type *mem = &memblock.memory;
 	struct resource *res;
 	int i;
 
@@ -528,14 +529,11 @@ request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
 	kernel_data.start   = virt_to_phys(_sdata);
 	kernel_data.end     = virt_to_phys(_end - 1);
 
-	for (i = 0; i < mi->nr_banks; i++) {
-		if (mi->bank[i].size == 0)
-			continue;
-
+	for (i = 0; i < mem->cnt; i++) {
 		res = alloc_bootmem_low(sizeof(*res));
 		res->name  = "System RAM";
-		res->start = mi->bank[i].start;
-		res->end   = mi->bank[i].start + mi->bank[i].size - 1;
+		res->start = mem->regions[i].base;
+		res->end   = mem->regions[i].base + mem->regions[i].size - 1;
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 
 		request_resource(&iomem_resource, res);
@@ -857,7 +855,7 @@ void __init setup_arch(char **cmdline_p)
 	arm_memblock_init(&meminfo, mdesc);
 
 	paging_init(mdesc);
-	request_standard_resources(&meminfo, mdesc);
+	request_standard_resources(mdesc);
 
 #ifdef CONFIG_SMP
 	if (is_smp())
Signature · 1 line
1.7.3.1
#4 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

arch/arm/kernel/setup.c setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz) · line 521

Quoted 6 lines · Dima Zavin
arch/arm/kernel/setup.c +1 -1
@@ -518,8 +518,9 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
 }
 
 static void __init
-request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
+request_standard_resources(struct machine_desc *mdesc)

Almost there. This line can now be combined with the preceding line without wrapping over the 80 column limit.

Quoted 6 lines
arch/arm/kernel/setup.c +1 -0
 {
+	struct memblock_type *mem = &memblock.memory;
 	struct resource *res;
 	int i;
 

arch/arm/kernel/setup.c request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc) · line 532

Quoted 8 lines
arch/arm/kernel/setup.c +1 -4
@@ -528,14 +529,11 @@ request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
 	kernel_data.start   = virt_to_phys(_sdata);
 	kernel_data.end     = virt_to_phys(_end - 1);
 
-	for (i = 0; i < mi->nr_banks; i++) {
-		if (mi->bank[i].size == 0)
-			continue;
-
+	for (i = 0; i < mem->cnt; i++) {

Hmm, probably shouldn't rely on that - we should be using the accessors which memblock people have provided for us.

	for_each_memblock(memory, mem) {

arch/arm/kernel/setup.c request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc) · line 536

Quoted 6 lines
arch/arm/kernel/setup.c +2 -2
 		res = alloc_bootmem_low(sizeof(*res));
 		res->name  = "System RAM";
-		res->start = mi->bank[i].start;
-		res->end   = mi->bank[i].start + mi->bank[i].size - 1;
+		res->start = mem->regions[i].base;
+		res->end   = mem->regions[i].base + mem->regions[i].size - 1;
		res->start = __pfn_to_phys(memblock_region_memory_base_pfn(mem));
		res->end   = __pfn_to_phys(memblock_region_memory_end_pfn(mem)) - 1;

And I'd say ignore the 80-column limit on that because of the excessively long memblock function names.

author
#5 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Instead, iterate through the regions of memblock.memory and add those as "System RAM" resources.

---
 arch/arm/kernel/setup.c |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)
arch/arm/kernel/setup.c +6 -10
index 336f14e..470efbc 100644
@@ -517,25 +517,21 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)
 #endif
 }
 
-static void __init
-request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
+static void __init request_standard_resources(struct machine_desc *mdesc)
 {
+	struct memblock_region *region;
 	struct resource *res;
-	int i;
 
 	kernel_code.start   = virt_to_phys(_text);
 	kernel_code.end     = virt_to_phys(_etext - 1);
 	kernel_data.start   = virt_to_phys(_sdata);
 	kernel_data.end     = virt_to_phys(_end - 1);
 
-	for (i = 0; i < mi->nr_banks; i++) {
-		if (mi->bank[i].size == 0)
-			continue;
-
+	for_each_memblock(memory, region) {
 		res = alloc_bootmem_low(sizeof(*res));
 		res->name  = "System RAM";
-		res->start = mi->bank[i].start;
-		res->end   = mi->bank[i].start + mi->bank[i].size - 1;
+		res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
+		res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1;
 		res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
 
 		request_resource(&iomem_resource, res);
@@ -857,7 +853,7 @@ void __init setup_arch(char **cmdline_p)
 	arm_memblock_init(&meminfo, mdesc);
 
 	paging_init(mdesc);
-	request_standard_resources(&meminfo, mdesc);
+	request_standard_resources(mdesc);
 
 #ifdef CONFIG_SMP
 	if (is_smp())
Signature · 1 line
1.7.3.1
author
#6 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

Thanks for the review.

--Dima

Quoted 63 lines · Dima Zavin

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Instead, iterate through the regions of memblock.memory and add those as "System RAM" resources.

---
?arch/arm/kernel/setup.c | ? 16 ++++++---------- ?1 files changed, 6 insertions(+), 10 deletions(-)

arch/arm/kernel/setup.c +0 -0
index 336f14e..470efbc 100644
@@ -517,25 +517,21 @@ setup_ramdisk(int doload, int prompt, int image_start, unsigned int rd_sz)

?#endif
?}

arch/arm/kernel/setup.c +1 -2
-static void __init
-request_standard_resources(struct meminfo *mi, struct machine_desc *mdesc)
+static void __init request_standard_resources(struct machine_desc *mdesc)

?{
+ ? ? ? struct memblock_region *region;
? ? ? ?struct resource *res;
- ? ? ? int i;

? ? ? ?kernel_code.start ? = virt_to_phys(_text); ? ? ? ?kernel_code.end ? ? = virt_to_phys(_etext - 1); ? ? ? ?kernel_data.start ? = virt_to_phys(_sdata); ? ? ? ?kernel_data.end ? ? = virt_to_phys(_end - 1);

- ? ? ? for (i = 0; i < mi->nr_banks; i++) {
- ? ? ? ? ? ? ? if (mi->bank[i].size == 0)
- ? ? ? ? ? ? ? ? ? ? ? continue;
-
+ ? ? ? for_each_memblock(memory, region) {
? ? ? ? ? ? ? ?res = alloc_bootmem_low(sizeof(*res));
? ? ? ? ? ? ? ?res->name ?= "System RAM";
- ? ? ? ? ? ? ? res->start = mi->bank[i].start;
- ? ? ? ? ? ? ? res->end ? = mi->bank[i].start + mi->bank[i].size - 1;
+ ? ? ? ? ? ? ? res->start = __pfn_to_phys(memblock_region_memory_base_pfn(region));
+ ? ? ? ? ? ? ? res->end = __pfn_to_phys(memblock_region_memory_end_pfn(region)) - 1; ? ? ? ? ? ? ? ?res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;

? ? ? ? ? ? ? ?request_resource(&iomem_resource, res);

arch/arm/kernel/setup.c +1 -1
@@ -857,7 +853,7 @@ void __init setup_arch(char **cmdline_p)
 ? ? ? ?arm_memblock_init(&meminfo, mdesc);
 
 ? ? ? ?paging_init(mdesc);
- ? ? ? request_standard_resources(&meminfo, mdesc);
+ ? ? ? request_standard_resources(mdesc);
 

?#ifdef CONFIG_SMP
? ? ? ?if (is_smp())
--
1.7.3.1

#7 lore raw

PATCH 1/1 ARM: use memblock memory regions for "System RAM" I/O resources

In reply to Dima Zavin
Quoted 6 lines · Dima Zavin

Do not use memory bank info to request the "system ram" resources as they do not track holes created by memblock_remove inside machine's reserve callback. If the removed memory is passed as platform_device's ioresource, then drivers that call request_mem_region would fail due to a conflict with the incorrectly configured system ram resource.

Patch looks fine - please send it to the patch system, thanks.