[PATCH 3/5] sparc32: populate memblock from the PROM memory map

From: Magnus Lindholm

Date: Thu Aug 27 2026 - 14:32:54 EST


Add each available PROM memory range to memblock as it is discovered.
Keep populating sp_banks temporarily so the remaining users continue to
work while they are converted in the following patches.

Since the complete PROM map is now present before bootmem_init(), enforce
the mem= limit after the legacy bank processing. Adding a smaller
overlapping range would otherwise leave memory beyond the requested limit
in memblock during this intermediate commit.

Suggested-by: Sam Ravnborg <sam@xxxxxxxxxxxx>
Signed-off-by: Magnus Lindholm <linmag7@xxxxxxxxx>
---
arch/sparc/mm/init_32.c | 3 +++
arch/sparc/prom/memory.c | 3 +++
2 files changed, 6 insertions(+)

diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
index e0e66f91ceeb..75050dfbc2ea 100644
--- a/arch/sparc/mm/init_32.c
+++ b/arch/sparc/mm/init_32.c
@@ -165,6 +165,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail)
memblock_add(sp_banks[i].base_addr, sp_banks[i].num_bytes);
}

+ if (cmdline_memory_size)
+ memblock_enforce_memory_limit(cmdline_memory_size);
+
/* Start with page aligned address of last symbol in kernel
* image.
*/
diff --git a/arch/sparc/prom/memory.c b/arch/sparc/prom/memory.c
index 269d6ab5ef5e..59962bc0bc82 100644
--- a/arch/sparc/prom/memory.c
+++ b/arch/sparc/prom/memory.c
@@ -7,6 +7,7 @@
*/

#include <linux/kernel.h>
+#include <linux/memblock.h>
#include <linux/sort.h>
#include <linux/init.h>

@@ -23,6 +24,7 @@ static int __init prom_meminit_v0(void)
for (p = *(romvec->pv_v0mem.v0_available); p; p = p->theres_more) {
sp_banks[index].base_addr = (unsigned long) p->start_adr;
sp_banks[index].num_bytes = p->num_bytes;
+ memblock_add(p->start_adr, p->num_bytes & PAGE_MASK);
index++;
}

@@ -42,6 +44,7 @@ static int __init prom_meminit_v2(void)
for (i = 0; i < num_ents; i++) {
sp_banks[i].base_addr = reg[i].phys_addr;
sp_banks[i].num_bytes = reg[i].reg_size;
+ memblock_add(reg[i].phys_addr, reg[i].reg_size & PAGE_MASK);
}

return num_ents;
--
2.43.0