hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/sh/mm/init.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/arch/sh/mm/init.c
34 *
....@@ -11,12 +12,11 @@
1112 #include <linux/swap.h>
1213 #include <linux/init.h>
1314 #include <linux/gfp.h>
14
-#include <linux/bootmem.h>
15
+#include <linux/memblock.h>
1516 #include <linux/proc_fs.h>
1617 #include <linux/pagemap.h>
1718 #include <linux/percpu.h>
1819 #include <linux/io.h>
19
-#include <linux/memblock.h>
2020 #include <linux/dma-mapping.h>
2121 #include <linux/export.h>
2222 #include <asm/mmu_context.h>
....@@ -27,7 +27,9 @@
2727 #include <asm/sections.h>
2828 #include <asm/setup.h>
2929 #include <asm/cache.h>
30
-#include <asm/sizes.h>
30
+#include <asm/pgalloc.h>
31
+#include <linux/sizes.h>
32
+#include "ioremap.h"
3133
3234 pgd_t swapper_pg_dir[PTRS_PER_PGD];
3335
....@@ -45,6 +47,7 @@
4547 static pte_t *__get_pte_phys(unsigned long addr)
4648 {
4749 pgd_t *pgd;
50
+ p4d_t *p4d;
4851 pud_t *pud;
4952 pmd_t *pmd;
5053
....@@ -54,7 +57,13 @@
5457 return NULL;
5558 }
5659
57
- pud = pud_alloc(NULL, pgd, addr);
60
+ p4d = p4d_alloc(NULL, pgd, addr);
61
+ if (unlikely(!p4d)) {
62
+ p4d_ERROR(*p4d);
63
+ return NULL;
64
+ }
65
+
66
+ pud = pud_alloc(NULL, p4d, addr);
5867 if (unlikely(!pud)) {
5968 pud_ERROR(*pud);
6069 return NULL;
....@@ -128,7 +137,10 @@
128137 if (pud_none(*pud)) {
129138 pmd_t *pmd;
130139
131
- pmd = alloc_bootmem_pages(PAGE_SIZE);
140
+ pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
141
+ if (!pmd)
142
+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
143
+ __func__, PAGE_SIZE, PAGE_SIZE);
132144 pud_populate(&init_mm, pud, pmd);
133145 BUG_ON(pmd != pmd_offset(pud, 0));
134146 }
....@@ -141,7 +153,10 @@
141153 if (pmd_none(*pmd)) {
142154 pte_t *pte;
143155
144
- pte = alloc_bootmem_pages(PAGE_SIZE);
156
+ pte = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
157
+ if (!pte)
158
+ panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
159
+ __func__, PAGE_SIZE, PAGE_SIZE);
145160 pmd_populate_kernel(&init_mm, pmd, pte);
146161 BUG_ON(pte != pte_offset_kernel(pmd, 0));
147162 }
....@@ -166,9 +181,9 @@
166181 unsigned long vaddr;
167182
168183 vaddr = start;
169
- i = __pgd_offset(vaddr);
170
- j = __pud_offset(vaddr);
171
- k = __pmd_offset(vaddr);
184
+ i = pgd_index(vaddr);
185
+ j = pud_index(vaddr);
186
+ k = pmd_index(vaddr);
172187 pgd = pgd_base + i;
173188
174189 for ( ; (i < PTRS_PER_PGD) && (vaddr != end); pgd++, i++) {
....@@ -193,24 +208,16 @@
193208 void __init allocate_pgdat(unsigned int nid)
194209 {
195210 unsigned long start_pfn, end_pfn;
196
-#ifdef CONFIG_NEED_MULTIPLE_NODES
197
- unsigned long phys;
198
-#endif
199211
200212 get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
201213
202214 #ifdef CONFIG_NEED_MULTIPLE_NODES
203
- phys = __memblock_alloc_base(sizeof(struct pglist_data),
204
- SMP_CACHE_BYTES, end_pfn << PAGE_SHIFT);
205
- /* Retry with all of system memory */
206
- if (!phys)
207
- phys = __memblock_alloc_base(sizeof(struct pglist_data),
208
- SMP_CACHE_BYTES, memblock_end_of_DRAM());
209
- if (!phys)
215
+ NODE_DATA(nid) = memblock_alloc_try_nid(
216
+ sizeof(struct pglist_data),
217
+ SMP_CACHE_BYTES, MEMBLOCK_LOW_LIMIT,
218
+ MEMBLOCK_ALLOC_ACCESSIBLE, nid);
219
+ if (!NODE_DATA(nid))
210220 panic("Can't allocate pgdat for node %d\n", nid);
211
-
212
- NODE_DATA(nid) = __va(phys);
213
- memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
214221 #endif
215222
216223 NODE_DATA(nid)->node_start_pfn = start_pfn;
....@@ -219,15 +226,12 @@
219226
220227 static void __init do_init_bootmem(void)
221228 {
222
- struct memblock_region *reg;
229
+ unsigned long start_pfn, end_pfn;
230
+ int i;
223231
224232 /* Add active regions with valid PFNs. */
225
- for_each_memblock(memory, reg) {
226
- unsigned long start_pfn, end_pfn;
227
- start_pfn = memblock_region_memory_base_pfn(reg);
228
- end_pfn = memblock_region_memory_end_pfn(reg);
233
+ for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, NULL)
229234 __add_active_range(0, start_pfn, end_pfn);
230
- }
231235
232236 /* All of system RAM sits in node 0 for the non-NUMA case */
233237 allocate_pgdat(0);
....@@ -235,12 +239,6 @@
235239
236240 plat_mem_setup();
237241
238
- for_each_memblock(memory, reg) {
239
- int nid = memblock_get_region_node(reg);
240
-
241
- memory_present(nid, memblock_region_memory_base_pfn(reg),
242
- memblock_region_memory_end_pfn(reg));
243
- }
244242 sparse_init();
245243 }
246244
....@@ -336,7 +334,7 @@
336334
337335 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
338336 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
339
- free_area_init_nodes(max_zone_pfns);
337
+ free_area_init(max_zone_pfns);
340338 }
341339
342340 unsigned int mem_init_done = 0;
....@@ -350,7 +348,7 @@
350348 high_memory = max_t(void *, high_memory,
351349 __va(pgdat_end_pfn(pgdat) << PAGE_SHIFT));
352350
353
- free_all_bootmem();
351
+ memblock_free_all();
354352
355353 /* Set this up early, so we can take care of the zero page */
356354 cpu_cache_init();
....@@ -406,42 +404,24 @@
406404 mem_init_done = 1;
407405 }
408406
409
-void free_initmem(void)
410
-{
411
- free_initmem_default(-1);
412
-}
413
-
414
-#ifdef CONFIG_BLK_DEV_INITRD
415
-void free_initrd_mem(unsigned long start, unsigned long end)
416
-{
417
- free_reserved_area((void *)start, (void *)end, -1, "initrd");
418
-}
419
-#endif
420
-
421407 #ifdef CONFIG_MEMORY_HOTPLUG
422
-int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
423
- bool want_memblock)
408
+int arch_add_memory(int nid, u64 start, u64 size,
409
+ struct mhp_params *params)
424410 {
425411 unsigned long start_pfn = PFN_DOWN(start);
426412 unsigned long nr_pages = size >> PAGE_SHIFT;
427413 int ret;
428414
415
+ if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
416
+ return -EINVAL;
417
+
429418 /* We only have ZONE_NORMAL, so this is easy.. */
430
- ret = __add_pages(nid, start_pfn, nr_pages, altmap, want_memblock);
419
+ ret = __add_pages(nid, start_pfn, nr_pages, params);
431420 if (unlikely(ret))
432421 printk("%s: Failed, __add_pages() == %d\n", __func__, ret);
433422
434423 return ret;
435424 }
436
-
437
-#ifdef CONFIG_NUMA
438
-int memory_add_physaddr_to_nid(u64 addr)
439
-{
440
- /* Node 0 for now.. */
441
- return 0;
442
-}
443
-EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
444
-#endif
445425
446426 void arch_remove_memory(int nid, u64 start, u64 size,
447427 struct vmem_altmap *altmap)