Skip to content

Commit ce5ad03

Browse files
committed
LoongArch: Consolidate max_pfn & max_low_pfn calculation
Now there 5 places which calculate max_pfn & max_low_pfn: 1. in fdt_setup() for FDT systems; 2. in memblock_init() for ACPI systems; 3. in init_numa_memory() for NUMA systems; 4. in arch_mem_init() to recalculate for "mem=" cmdline; 5. in paging_init() to recalculate for NUMA systems. Since memblock_init() is called both for ACPI and FDT systems, move the calculation out of the for_each_efi_memory_desc() loop can eliminate the first case. The last case is very questionable (may be derived from the MIPS/Loongson code) and breaks the "mem=" cmdline, so should be removed. And then the NUMA version of paging_init() can be also eliminated. After consolidation there are 3 places of calculation: 1. in memblock_init() for both ACPI and FDT systems; 2. in init_numa_memory() to recalculate for NUMA systems; 3. in arch_mem_init() to recalculate for the "mem=" cmdline. For all cases the calculation is: max_pfn = PFN_DOWN(memblock_end_of_DRAM()); max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn); Cc: stable@vger.kernel.org Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 43a9e6a commit ce5ad03

4 files changed

Lines changed: 7 additions & 30 deletions

File tree

arch/loongarch/kernel/mem.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
void __init memblock_init(void)
1414
{
1515
u32 mem_type;
16-
u64 mem_start, mem_end, mem_size;
16+
u64 mem_start, mem_size;
1717
efi_memory_desc_t *md;
1818

1919
/* Parse memory information */
2020
for_each_efi_memory_desc(md) {
2121
mem_type = md->type;
2222
mem_start = md->phys_addr;
2323
mem_size = md->num_pages << EFI_PAGE_SHIFT;
24-
mem_end = mem_start + mem_size;
2524

2625
switch (mem_type) {
2726
case EFI_LOADER_CODE:
@@ -31,8 +30,6 @@ void __init memblock_init(void)
3130
case EFI_PERSISTENT_MEMORY:
3231
case EFI_CONVENTIONAL_MEMORY:
3332
memblock_add(mem_start, mem_size);
34-
if (max_low_pfn < (mem_end >> PAGE_SHIFT))
35-
max_low_pfn = mem_end >> PAGE_SHIFT;
3633
break;
3734
case EFI_PAL_CODE:
3835
case EFI_UNUSABLE_MEMORY:
@@ -49,6 +46,8 @@ void __init memblock_init(void)
4946
}
5047
}
5148

49+
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
50+
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
5251
memblock_set_current_limit(PFN_PHYS(max_low_pfn));
5352

5453
/* Reserve the first 2MB */

arch/loongarch/kernel/numa.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ int __init init_numa_memory(void)
272272
node_mem_init(node);
273273
node_set_online(node);
274274
}
275-
max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
275+
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
276+
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
276277

277278
setup_nr_node_ids();
278279
loongson_sysconf.nr_nodes = nr_node_ids;
@@ -283,26 +284,6 @@ int __init init_numa_memory(void)
283284

284285
#endif
285286

286-
void __init paging_init(void)
287-
{
288-
unsigned int node;
289-
unsigned long zones_size[MAX_NR_ZONES] = {0, };
290-
291-
for_each_online_node(node) {
292-
unsigned long start_pfn, end_pfn;
293-
294-
get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
295-
296-
if (end_pfn > max_low_pfn)
297-
max_low_pfn = end_pfn;
298-
}
299-
#ifdef CONFIG_ZONE_DMA32
300-
zones_size[ZONE_DMA32] = MAX_DMA32_PFN;
301-
#endif
302-
zones_size[ZONE_NORMAL] = max_low_pfn;
303-
free_area_init(zones_size);
304-
}
305-
306287
int pcibus_to_node(struct pci_bus *bus)
307288
{
308289
return dev_to_node(&bus->dev);

arch/loongarch/kernel/setup.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ static void __init fdt_setup(void)
294294

295295
early_init_dt_scan(fdt_pointer, __pa(fdt_pointer));
296296
early_init_fdt_reserve_self();
297-
298-
max_low_pfn = PFN_PHYS(memblock_end_of_DRAM());
299297
#endif
300298
}
301299

@@ -390,7 +388,8 @@ static void __init check_kernel_sections_mem(void)
390388
static void __init arch_mem_init(char **cmdline_p)
391389
{
392390
/* Recalculate max_low_pfn for "mem=xxx" */
393-
max_pfn = max_low_pfn = PHYS_PFN(memblock_end_of_DRAM());
391+
max_pfn = PFN_DOWN(memblock_end_of_DRAM());
392+
max_low_pfn = min(PFN_DOWN(HIGHMEM_START), max_pfn);
394393

395394
if (usermem)
396395
pr_info("User-defined physical RAM map overwrite\n");

arch/loongarch/mm/init.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ int __ref page_is_ram(unsigned long pfn)
6060
return memblock_is_memory(addr) && !memblock_is_reserved(addr);
6161
}
6262

63-
#ifndef CONFIG_NUMA
6463
void __init paging_init(void)
6564
{
6665
unsigned long max_zone_pfns[MAX_NR_ZONES];
@@ -72,7 +71,6 @@ void __init paging_init(void)
7271

7372
free_area_init(max_zone_pfns);
7473
}
75-
#endif /* !CONFIG_NUMA */
7674

7775
void __ref free_initmem(void)
7876
{

0 commit comments

Comments
 (0)