[PATCH 7/8] sparc32: Move memory config to setup_32

From: Sam Ravnborg

Date: Sun Dec 31 2023 - 13:27:15 EST


Move all early memory configuration to setup_memory.
Replace sp_banks use with memblock.

Signed-off-by: Sam Ravnborg <sam@xxxxxxxxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: Andreas Larsson <andreas@xxxxxxxxxxx>
---
arch/sparc/include/asm/pgtable_32.h | 2 +-
arch/sparc/kernel/setup_32.c | 44 ++++++++++++++++++++-
arch/sparc/mm/init_32.c | 61 +----------------------------
3 files changed, 45 insertions(+), 62 deletions(-)

diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
index 533f842ef5fe..ac92e4801d10 100644
--- a/arch/sparc/include/asm/pgtable_32.h
+++ b/arch/sparc/include/asm/pgtable_32.h
@@ -37,7 +37,7 @@ struct vm_area_struct;
struct page;

void load_mmu(void);
-void __init bootmem_init(void);
+void __init find_ramdisk(unsigned long end_of_phys_memory);

#define pte_ERROR(e) __builtin_trap()
#define pmd_ERROR(e) __builtin_trap()
diff --git a/arch/sparc/kernel/setup_32.c b/arch/sparc/kernel/setup_32.c
index c8b3e19472af..79dcd564a919 100644
--- a/arch/sparc/kernel/setup_32.c
+++ b/arch/sparc/kernel/setup_32.c
@@ -172,14 +172,41 @@ void __init sparc32_start_kernel(struct linux_romvec *rp)
start_kernel();
}

+static unsigned long calc_max_low_pfn(void)
+{
+ unsigned long tmp = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT);
+ unsigned long last_pfn = 0;
+ unsigned long curr_pfn;
+ phys_addr_t start, end;
+ u64 i;
+
+ for_each_mem_range(i, &start, &end) {
+ curr_pfn = PFN_DOWN(start);
+
+ if (curr_pfn >= tmp) {
+ if (last_pfn < tmp)
+ tmp = last_pfn;
+ break;
+ }
+
+ last_pfn = PFN_DOWN(start + end + 1);
+ }
+
+ return tmp;
+}
+
unsigned long phys_base;
EXPORT_SYMBOL(phys_base);

unsigned long pfn_base;
EXPORT_SYMBOL(pfn_base);

+unsigned long highend_pfn;
+
static void __init setup_memory(void)
{
+ unsigned long size;
+
memblock_set_bottom_up(true);
memblock_allow_resize();

@@ -187,12 +214,27 @@ static void __init setup_memory(void)

/* Setup memblock globals */
min_low_pfn = PFN_DOWN(memblock_start_of_DRAM());
+ max_pfn = PFN_DOWN(memblock_end_of_DRAM());
+ max_low_pfn = max_pfn;

/* Lowest address available */
phys_base = memblock_start_of_DRAM();
pfn_base = min_low_pfn;

- bootmem_init();
+ highend_pfn = max_pfn;
+
+ if (max_low_pfn > pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT))
+ 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 via memblock allocation */
+ memblock_set_current_limit(PFN_PHYS(max_low_pfn));
}

void __init setup_arch(char **cmdline_p)
diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
index cd16e9ae81b6..74174d20e566 100644
--- a/arch/sparc/mm/init_32.c
+++ b/arch/sparc/mm/init_32.c
@@ -43,31 +43,7 @@ struct sparc_phys_banks sp_banks[SPARC_PHYS_BANKS+1];
extern unsigned int sparc_ramdisk_image;
extern unsigned int sparc_ramdisk_size;

-unsigned long highstart_pfn, highend_pfn;
-
-static unsigned long calc_max_low_pfn(void)
-{
- int i;
- unsigned long tmp = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT);
- unsigned long curr_pfn, last_pfn;
-
- last_pfn = (sp_banks[0].base_addr + sp_banks[0].num_bytes) >> PAGE_SHIFT;
- for (i = 1; sp_banks[i].num_bytes != 0; i++) {
- curr_pfn = sp_banks[i].base_addr >> PAGE_SHIFT;
-
- if (curr_pfn >= tmp) {
- if (last_pfn < tmp)
- tmp = last_pfn;
- break;
- }
-
- last_pfn = (sp_banks[i].base_addr + sp_banks[i].num_bytes) >> PAGE_SHIFT;
- }
-
- return tmp;
-}
-
-static void __init find_ramdisk(unsigned long end_of_phys_memory)
+void __init find_ramdisk(unsigned long end_of_phys_memory)
{
#ifdef CONFIG_BLK_DEV_INITRD
unsigned long size;
@@ -97,41 +73,6 @@ static void __init find_ramdisk(unsigned long end_of_phys_memory)
#endif
}

-void __init bootmem_init(void)
-{
- unsigned long start_pfn, size;
-
- /* Start with page aligned address of last symbol in kernel
- * image.
- */
- start_pfn = (unsigned long)__pa(PAGE_ALIGN((unsigned long) &_end));
-
- /* Now shift down to get the real physical page frame number. */
- start_pfn >>= PAGE_SHIFT;
-
- max_pfn = PFN_DOWN(memblock_end_of_DRAM());
-
- max_low_pfn = max_pfn;
- highstart_pfn = highend_pfn = max_pfn;
-
- if (max_low_pfn > pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT)) {
- highstart_pfn = pfn_base + (SRMMU_MAXMEM >> PAGE_SHIFT);
- max_low_pfn = calc_max_low_pfn();
- }
-
- find_ramdisk(memblock_end_of_DRAM());
-
- /* Reserve the kernel text/data/bss. */
- size = (start_pfn << PAGE_SHIFT) - phys_base;
- memblock_reserve(phys_base, size);
- memblock_add(phys_base, size);
-
- size = memblock_phys_mem_size() - memblock_reserved_size();
-
- /* Only allow low memory to be allocated via memblock allocation */
- memblock_set_current_limit(max_low_pfn << PAGE_SHIFT);
-}
-
/*
* paging_init() sets up the page tables: We call the MMU specific
* init routine based upon the Sun model type on the Sparc.
--
2.53.0


--7JT2ezVoPwppFeaz
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0008-sparc32-Drop-sp_banks.patch"