Re: [PATCH v4 5/6] sparc32: move early memory setup to setup_arch

From: Andreas Larsson

Date: Wed Oct 07 2026 - 01:48:15 EST


On 2026-09-27 23:43, Magnus Lindholm wrote:
> +static void __init setup_memory(void)
> +{
> + unsigned long ram_base = memblock_start_of_DRAM();
> + unsigned long real_base = __get_phys(PAGE_OFFSET);
> + unsigned long size;
> +
> + memblock_set_bottom_up(true);
> + memblock_allow_resize();
> +
> + phys_base = ram_base;
> + if (real_base && real_base != phys_base) {
> + prom_printf("phys_base: RAM starts 0x%x but kernel is at 0x%x\n",
> + (unsigned int)phys_base, (unsigned int)real_base);
> + phys_base = real_base;
> + memblock_remove(0, phys_base);
> + prom_printf("phys_base: adopted 0x%x, RAM below it dropped\n",
> + (unsigned int)phys_base);

This undos the v3 changes of https://lore.kernel.org/sparclinux/cover.1790548064.git.linmag7@xxxxxxxxx/T/#t ...

> }
> - sp_banks[j].base_addr = 0;
> - sp_banks[j].num_bytes = 0;
> +
> + if (cmdline_memory_size)
> + memblock_enforce_memory_limit(cmdline_memory_size);
> +
> + min_low_pfn = PFN_DOWN(memblock_start_of_DRAM());
> + pfn_base = PHYS_PFN(phys_base);
> + max_pfn = PFN_DOWN(memblock_end_of_DRAM());
> + max_low_pfn = max_pfn;
> +
> + if (max_low_pfn > pfn_base + PHYS_PFN(SRMMU_MAXMEM))
> + max_low_pfn = calc_max_low_pfn();
> +
> + find_ramdisk(memblock_end_of_DRAM());
> +
> + /* Reserve the kernel text/data/bss. */
> + size = __pa(PAGE_ALIGN((unsigned long)&_end)) - phys_base;
> + memblock_reserve(phys_base, size);
> + memblock_add(phys_base, size);
> +
> + /* Only allow low memory to be allocated by memblock. */
> + memblock_set_current_limit(PFN_PHYS(max_low_pfn));
> }
>
> /* Called from head_32.S - before we have setup anything
> @@ -306,9 +350,6 @@ void __init sparc32_start_kernel(struct linux_romvec *rp)
>
> void __init setup_arch(char **cmdline_p)
> {
> - int i;
> - unsigned long highest_paddr;
> -
> sparc_ttable = &trapbase[0];
>
> /* Initialize PROM console and command line. */
> @@ -343,36 +384,7 @@ void __init setup_arch(char **cmdline_p)
>
> idprom_init();
> load_mmu();
> -
> - phys_base = 0xffffffffUL;
> - highest_paddr = 0UL;
> - for (i = 0; sp_banks[i].num_bytes != 0; i++) {
> - unsigned long top;
> -
> - if (sp_banks[i].base_addr < phys_base)
> - phys_base = sp_banks[i].base_addr;
> - top = sp_banks[i].base_addr +
> - sp_banks[i].num_bytes;
> - if (highest_paddr < top)
> - highest_paddr = top;
> - }
> -
> - /* phys_base must describe what PAGE_OFFSET maps to, not where RAM starts. */
> - {
> - unsigned long real_base = __get_phys(PAGE_OFFSET);
> -
> - if (real_base && real_base != phys_base) {
> - prom_printf("phys_base: RAM starts 0x%x but kernel is at 0x%x\n",
> - (unsigned int)phys_base,
> - (unsigned int)real_base);
> - phys_base = real_base;
> - trim_sp_banks_below(phys_base);
> - prom_printf("phys_base: adopted 0x%x, RAM below it dropped\n",
> - (unsigned int)phys_base);
> - }
> - }

...and does not apply on top of that.

Please rework the series on top of the for-next branch of
git://git.kernel.org/pub/scm/linux/kernel/git/alarsson/linux-sparc.git

Thanks,
Andreas