Merge tag 'gpio-updates-for-v5.13-v2' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / arch / riscv / mm / init.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2012 Regents of the University of California
4  * Copyright (C) 2019 Western Digital Corporation or its affiliates.
5  */
6
7 #include <linux/init.h>
8 #include <linux/mm.h>
9 #include <linux/memblock.h>
10 #include <linux/initrd.h>
11 #include <linux/swap.h>
12 #include <linux/sizes.h>
13 #include <linux/of_fdt.h>
14 #include <linux/libfdt.h>
15 #include <linux/set_memory.h>
16 #include <linux/dma-map-ops.h>
17
18 #include <asm/fixmap.h>
19 #include <asm/tlbflush.h>
20 #include <asm/sections.h>
21 #include <asm/soc.h>
22 #include <asm/io.h>
23 #include <asm/ptdump.h>
24 #include <asm/numa.h>
25
26 #include "../kernel/head.h"
27
28 unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]
29                                                         __page_aligned_bss;
30 EXPORT_SYMBOL(empty_zero_page);
31
32 extern char _start[];
33 #define DTB_EARLY_BASE_VA      PGDIR_SIZE
34 void *dtb_early_va __initdata;
35 uintptr_t dtb_early_pa __initdata;
36
37 struct pt_alloc_ops {
38         pte_t *(*get_pte_virt)(phys_addr_t pa);
39         phys_addr_t (*alloc_pte)(uintptr_t va);
40 #ifndef __PAGETABLE_PMD_FOLDED
41         pmd_t *(*get_pmd_virt)(phys_addr_t pa);
42         phys_addr_t (*alloc_pmd)(uintptr_t va);
43 #endif
44 };
45
46 static phys_addr_t dma32_phys_limit __ro_after_init;
47
48 static void __init zone_sizes_init(void)
49 {
50         unsigned long max_zone_pfns[MAX_NR_ZONES] = { 0, };
51
52 #ifdef CONFIG_ZONE_DMA32
53         max_zone_pfns[ZONE_DMA32] = PFN_DOWN(dma32_phys_limit);
54 #endif
55         max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
56
57         free_area_init(max_zone_pfns);
58 }
59
60 static void setup_zero_page(void)
61 {
62         memset((void *)empty_zero_page, 0, PAGE_SIZE);
63 }
64
65 #if defined(CONFIG_MMU) && defined(CONFIG_DEBUG_VM)
66 static inline void print_mlk(char *name, unsigned long b, unsigned long t)
67 {
68         pr_notice("%12s : 0x%08lx - 0x%08lx   (%4ld kB)\n", name, b, t,
69                   (((t) - (b)) >> 10));
70 }
71
72 static inline void print_mlm(char *name, unsigned long b, unsigned long t)
73 {
74         pr_notice("%12s : 0x%08lx - 0x%08lx   (%4ld MB)\n", name, b, t,
75                   (((t) - (b)) >> 20));
76 }
77
78 static void print_vm_layout(void)
79 {
80         pr_notice("Virtual kernel memory layout:\n");
81         print_mlk("fixmap", (unsigned long)FIXADDR_START,
82                   (unsigned long)FIXADDR_TOP);
83         print_mlm("pci io", (unsigned long)PCI_IO_START,
84                   (unsigned long)PCI_IO_END);
85         print_mlm("vmemmap", (unsigned long)VMEMMAP_START,
86                   (unsigned long)VMEMMAP_END);
87         print_mlm("vmalloc", (unsigned long)VMALLOC_START,
88                   (unsigned long)VMALLOC_END);
89         print_mlm("lowmem", (unsigned long)PAGE_OFFSET,
90                   (unsigned long)high_memory);
91 }
92 #else
93 static void print_vm_layout(void) { }
94 #endif /* CONFIG_DEBUG_VM */
95
96 void __init mem_init(void)
97 {
98 #ifdef CONFIG_FLATMEM
99         BUG_ON(!mem_map);
100 #endif /* CONFIG_FLATMEM */
101
102         high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
103         memblock_free_all();
104
105         print_vm_layout();
106 }
107
108 void __init setup_bootmem(void)
109 {
110         phys_addr_t vmlinux_end = __pa_symbol(&_end);
111         phys_addr_t vmlinux_start = __pa_symbol(&_start);
112         phys_addr_t dram_end = memblock_end_of_DRAM();
113         phys_addr_t max_mapped_addr = __pa(~(ulong)0);
114
115         /* The maximal physical memory size is -PAGE_OFFSET. */
116         memblock_enforce_memory_limit(-PAGE_OFFSET);
117
118         /* Reserve from the start of the kernel to the end of the kernel */
119         memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
120
121         /*
122          * memblock allocator is not aware of the fact that last 4K bytes of
123          * the addressable memory can not be mapped because of IS_ERR_VALUE
124          * macro. Make sure that last 4k bytes are not usable by memblock
125          * if end of dram is equal to maximum addressable memory.
126          */
127         if (max_mapped_addr == (dram_end - 1))
128                 memblock_set_current_limit(max_mapped_addr - 4096);
129
130         max_pfn = PFN_DOWN(dram_end);
131         max_low_pfn = max_pfn;
132         dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn));
133         set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET);
134
135         reserve_initrd_mem();
136         /*
137          * If DTB is built in, no need to reserve its memblock.
138          * Otherwise, do reserve it but avoid using
139          * early_init_fdt_reserve_self() since __pa() does
140          * not work for DTB pointers that are fixmap addresses
141          */
142         if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
143                 memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
144
145         early_init_fdt_scan_reserved_mem();
146         dma_contiguous_reserve(dma32_phys_limit);
147         memblock_allow_resize();
148 }
149
150 #ifdef CONFIG_MMU
151 static struct pt_alloc_ops pt_ops;
152
153 unsigned long va_pa_offset;
154 EXPORT_SYMBOL(va_pa_offset);
155 unsigned long pfn_base;
156 EXPORT_SYMBOL(pfn_base);
157
158 pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
159 pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
160 pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
161
162 pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
163
164 void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
165 {
166         unsigned long addr = __fix_to_virt(idx);
167         pte_t *ptep;
168
169         BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
170
171         ptep = &fixmap_pte[pte_index(addr)];
172
173         if (pgprot_val(prot))
174                 set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
175         else
176                 pte_clear(&init_mm, addr, ptep);
177         local_flush_tlb_page(addr);
178 }
179
180 static inline pte_t *__init get_pte_virt_early(phys_addr_t pa)
181 {
182         return (pte_t *)((uintptr_t)pa);
183 }
184
185 static inline pte_t *__init get_pte_virt_fixmap(phys_addr_t pa)
186 {
187         clear_fixmap(FIX_PTE);
188         return (pte_t *)set_fixmap_offset(FIX_PTE, pa);
189 }
190
191 static inline pte_t *get_pte_virt_late(phys_addr_t pa)
192 {
193         return (pte_t *) __va(pa);
194 }
195
196 static inline phys_addr_t __init alloc_pte_early(uintptr_t va)
197 {
198         /*
199          * We only create PMD or PGD early mappings so we
200          * should never reach here with MMU disabled.
201          */
202         BUG();
203 }
204
205 static inline phys_addr_t __init alloc_pte_fixmap(uintptr_t va)
206 {
207         return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
208 }
209
210 static phys_addr_t alloc_pte_late(uintptr_t va)
211 {
212         unsigned long vaddr;
213
214         vaddr = __get_free_page(GFP_KERNEL);
215         if (!vaddr || !pgtable_pte_page_ctor(virt_to_page(vaddr)))
216                 BUG();
217         return __pa(vaddr);
218 }
219
220 static void __init create_pte_mapping(pte_t *ptep,
221                                       uintptr_t va, phys_addr_t pa,
222                                       phys_addr_t sz, pgprot_t prot)
223 {
224         uintptr_t pte_idx = pte_index(va);
225
226         BUG_ON(sz != PAGE_SIZE);
227
228         if (pte_none(ptep[pte_idx]))
229                 ptep[pte_idx] = pfn_pte(PFN_DOWN(pa), prot);
230 }
231
232 #ifndef __PAGETABLE_PMD_FOLDED
233
234 pmd_t trampoline_pmd[PTRS_PER_PMD] __page_aligned_bss;
235 pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
236 pmd_t early_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
237 pmd_t early_dtb_pmd[PTRS_PER_PMD] __initdata __aligned(PAGE_SIZE);
238
239 static pmd_t *__init get_pmd_virt_early(phys_addr_t pa)
240 {
241         /* Before MMU is enabled */
242         return (pmd_t *)((uintptr_t)pa);
243 }
244
245 static pmd_t *__init get_pmd_virt_fixmap(phys_addr_t pa)
246 {
247         clear_fixmap(FIX_PMD);
248         return (pmd_t *)set_fixmap_offset(FIX_PMD, pa);
249 }
250
251 static pmd_t *get_pmd_virt_late(phys_addr_t pa)
252 {
253         return (pmd_t *) __va(pa);
254 }
255
256 static phys_addr_t __init alloc_pmd_early(uintptr_t va)
257 {
258         BUG_ON((va - PAGE_OFFSET) >> PGDIR_SHIFT);
259
260         return (uintptr_t)early_pmd;
261 }
262
263 static phys_addr_t __init alloc_pmd_fixmap(uintptr_t va)
264 {
265         return memblock_phys_alloc(PAGE_SIZE, PAGE_SIZE);
266 }
267
268 static phys_addr_t alloc_pmd_late(uintptr_t va)
269 {
270         unsigned long vaddr;
271
272         vaddr = __get_free_page(GFP_KERNEL);
273         BUG_ON(!vaddr);
274         return __pa(vaddr);
275 }
276
277 static void __init create_pmd_mapping(pmd_t *pmdp,
278                                       uintptr_t va, phys_addr_t pa,
279                                       phys_addr_t sz, pgprot_t prot)
280 {
281         pte_t *ptep;
282         phys_addr_t pte_phys;
283         uintptr_t pmd_idx = pmd_index(va);
284
285         if (sz == PMD_SIZE) {
286                 if (pmd_none(pmdp[pmd_idx]))
287                         pmdp[pmd_idx] = pfn_pmd(PFN_DOWN(pa), prot);
288                 return;
289         }
290
291         if (pmd_none(pmdp[pmd_idx])) {
292                 pte_phys = pt_ops.alloc_pte(va);
293                 pmdp[pmd_idx] = pfn_pmd(PFN_DOWN(pte_phys), PAGE_TABLE);
294                 ptep = pt_ops.get_pte_virt(pte_phys);
295                 memset(ptep, 0, PAGE_SIZE);
296         } else {
297                 pte_phys = PFN_PHYS(_pmd_pfn(pmdp[pmd_idx]));
298                 ptep = pt_ops.get_pte_virt(pte_phys);
299         }
300
301         create_pte_mapping(ptep, va, pa, sz, prot);
302 }
303
304 #define pgd_next_t              pmd_t
305 #define alloc_pgd_next(__va)    pt_ops.alloc_pmd(__va)
306 #define get_pgd_next_virt(__pa) pt_ops.get_pmd_virt(__pa)
307 #define create_pgd_next_mapping(__nextp, __va, __pa, __sz, __prot)      \
308         create_pmd_mapping(__nextp, __va, __pa, __sz, __prot)
309 #define fixmap_pgd_next         fixmap_pmd
310 #else
311 #define pgd_next_t              pte_t
312 #define alloc_pgd_next(__va)    pt_ops.alloc_pte(__va)
313 #define get_pgd_next_virt(__pa) pt_ops.get_pte_virt(__pa)
314 #define create_pgd_next_mapping(__nextp, __va, __pa, __sz, __prot)      \
315         create_pte_mapping(__nextp, __va, __pa, __sz, __prot)
316 #define fixmap_pgd_next         fixmap_pte
317 #endif
318
319 void __init create_pgd_mapping(pgd_t *pgdp,
320                                       uintptr_t va, phys_addr_t pa,
321                                       phys_addr_t sz, pgprot_t prot)
322 {
323         pgd_next_t *nextp;
324         phys_addr_t next_phys;
325         uintptr_t pgd_idx = pgd_index(va);
326
327         if (sz == PGDIR_SIZE) {
328                 if (pgd_val(pgdp[pgd_idx]) == 0)
329                         pgdp[pgd_idx] = pfn_pgd(PFN_DOWN(pa), prot);
330                 return;
331         }
332
333         if (pgd_val(pgdp[pgd_idx]) == 0) {
334                 next_phys = alloc_pgd_next(va);
335                 pgdp[pgd_idx] = pfn_pgd(PFN_DOWN(next_phys), PAGE_TABLE);
336                 nextp = get_pgd_next_virt(next_phys);
337                 memset(nextp, 0, PAGE_SIZE);
338         } else {
339                 next_phys = PFN_PHYS(_pgd_pfn(pgdp[pgd_idx]));
340                 nextp = get_pgd_next_virt(next_phys);
341         }
342
343         create_pgd_next_mapping(nextp, va, pa, sz, prot);
344 }
345
346 static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size)
347 {
348         /* Upgrade to PMD_SIZE mappings whenever possible */
349         if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1)))
350                 return PAGE_SIZE;
351
352         return PMD_SIZE;
353 }
354
355 /*
356  * setup_vm() is called from head.S with MMU-off.
357  *
358  * Following requirements should be honoured for setup_vm() to work
359  * correctly:
360  * 1) It should use PC-relative addressing for accessing kernel symbols.
361  *    To achieve this we always use GCC cmodel=medany.
362  * 2) The compiler instrumentation for FTRACE will not work for setup_vm()
363  *    so disable compiler instrumentation when FTRACE is enabled.
364  *
365  * Currently, the above requirements are honoured by using custom CFLAGS
366  * for init.o in mm/Makefile.
367  */
368
369 #ifndef __riscv_cmodel_medany
370 #error "setup_vm() is called from head.S before relocate so it should not use absolute addressing."
371 #endif
372
373 asmlinkage void __init setup_vm(uintptr_t dtb_pa)
374 {
375         uintptr_t va, pa, end_va;
376         uintptr_t load_pa = (uintptr_t)(&_start);
377         uintptr_t load_sz = (uintptr_t)(&_end) - load_pa;
378         uintptr_t map_size;
379 #ifndef __PAGETABLE_PMD_FOLDED
380         pmd_t fix_bmap_spmd, fix_bmap_epmd;
381 #endif
382
383         va_pa_offset = PAGE_OFFSET - load_pa;
384         pfn_base = PFN_DOWN(load_pa);
385
386         /*
387          * Enforce boot alignment requirements of RV32 and
388          * RV64 by only allowing PMD or PGD mappings.
389          */
390         map_size = PMD_SIZE;
391
392         /* Sanity check alignment and size */
393         BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
394         BUG_ON((load_pa % map_size) != 0);
395
396         pt_ops.alloc_pte = alloc_pte_early;
397         pt_ops.get_pte_virt = get_pte_virt_early;
398 #ifndef __PAGETABLE_PMD_FOLDED
399         pt_ops.alloc_pmd = alloc_pmd_early;
400         pt_ops.get_pmd_virt = get_pmd_virt_early;
401 #endif
402         /* Setup early PGD for fixmap */
403         create_pgd_mapping(early_pg_dir, FIXADDR_START,
404                            (uintptr_t)fixmap_pgd_next, PGDIR_SIZE, PAGE_TABLE);
405
406 #ifndef __PAGETABLE_PMD_FOLDED
407         /* Setup fixmap PMD */
408         create_pmd_mapping(fixmap_pmd, FIXADDR_START,
409                            (uintptr_t)fixmap_pte, PMD_SIZE, PAGE_TABLE);
410         /* Setup trampoline PGD and PMD */
411         create_pgd_mapping(trampoline_pg_dir, PAGE_OFFSET,
412                            (uintptr_t)trampoline_pmd, PGDIR_SIZE, PAGE_TABLE);
413         create_pmd_mapping(trampoline_pmd, PAGE_OFFSET,
414                            load_pa, PMD_SIZE, PAGE_KERNEL_EXEC);
415 #else
416         /* Setup trampoline PGD */
417         create_pgd_mapping(trampoline_pg_dir, PAGE_OFFSET,
418                            load_pa, PGDIR_SIZE, PAGE_KERNEL_EXEC);
419 #endif
420
421         /*
422          * Setup early PGD covering entire kernel which will allows
423          * us to reach paging_init(). We map all memory banks later
424          * in setup_vm_final() below.
425          */
426         end_va = PAGE_OFFSET + load_sz;
427         for (va = PAGE_OFFSET; va < end_va; va += map_size)
428                 create_pgd_mapping(early_pg_dir, va,
429                                    load_pa + (va - PAGE_OFFSET),
430                                    map_size, PAGE_KERNEL_EXEC);
431
432 #ifndef __PAGETABLE_PMD_FOLDED
433         /* Setup early PMD for DTB */
434         create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
435                            (uintptr_t)early_dtb_pmd, PGDIR_SIZE, PAGE_TABLE);
436 #ifndef CONFIG_BUILTIN_DTB
437         /* Create two consecutive PMD mappings for FDT early scan */
438         pa = dtb_pa & ~(PMD_SIZE - 1);
439         create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA,
440                            pa, PMD_SIZE, PAGE_KERNEL);
441         create_pmd_mapping(early_dtb_pmd, DTB_EARLY_BASE_VA + PMD_SIZE,
442                            pa + PMD_SIZE, PMD_SIZE, PAGE_KERNEL);
443         dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PMD_SIZE - 1));
444 #else /* CONFIG_BUILTIN_DTB */
445         dtb_early_va = __va(dtb_pa);
446 #endif /* CONFIG_BUILTIN_DTB */
447 #else
448 #ifndef CONFIG_BUILTIN_DTB
449         /* Create two consecutive PGD mappings for FDT early scan */
450         pa = dtb_pa & ~(PGDIR_SIZE - 1);
451         create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA,
452                            pa, PGDIR_SIZE, PAGE_KERNEL);
453         create_pgd_mapping(early_pg_dir, DTB_EARLY_BASE_VA + PGDIR_SIZE,
454                            pa + PGDIR_SIZE, PGDIR_SIZE, PAGE_KERNEL);
455         dtb_early_va = (void *)DTB_EARLY_BASE_VA + (dtb_pa & (PGDIR_SIZE - 1));
456 #else /* CONFIG_BUILTIN_DTB */
457         dtb_early_va = __va(dtb_pa);
458 #endif /* CONFIG_BUILTIN_DTB */
459 #endif
460         dtb_early_pa = dtb_pa;
461
462         /*
463          * Bootime fixmap only can handle PMD_SIZE mapping. Thus, boot-ioremap
464          * range can not span multiple pmds.
465          */
466         BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
467                      != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
468
469 #ifndef __PAGETABLE_PMD_FOLDED
470         /*
471          * Early ioremap fixmap is already created as it lies within first 2MB
472          * of fixmap region. We always map PMD_SIZE. Thus, both FIX_BTMAP_END
473          * FIX_BTMAP_BEGIN should lie in the same pmd. Verify that and warn
474          * the user if not.
475          */
476         fix_bmap_spmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_BEGIN))];
477         fix_bmap_epmd = fixmap_pmd[pmd_index(__fix_to_virt(FIX_BTMAP_END))];
478         if (pmd_val(fix_bmap_spmd) != pmd_val(fix_bmap_epmd)) {
479                 WARN_ON(1);
480                 pr_warn("fixmap btmap start [%08lx] != end [%08lx]\n",
481                         pmd_val(fix_bmap_spmd), pmd_val(fix_bmap_epmd));
482                 pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
483                         fix_to_virt(FIX_BTMAP_BEGIN));
484                 pr_warn("fix_to_virt(FIX_BTMAP_END):   %08lx\n",
485                         fix_to_virt(FIX_BTMAP_END));
486
487                 pr_warn("FIX_BTMAP_END:       %d\n", FIX_BTMAP_END);
488                 pr_warn("FIX_BTMAP_BEGIN:     %d\n", FIX_BTMAP_BEGIN);
489         }
490 #endif
491 }
492
493 static void __init setup_vm_final(void)
494 {
495         uintptr_t va, map_size;
496         phys_addr_t pa, start, end;
497         u64 i;
498
499         /**
500          * MMU is enabled at this point. But page table setup is not complete yet.
501          * fixmap page table alloc functions should be used at this point
502          */
503         pt_ops.alloc_pte = alloc_pte_fixmap;
504         pt_ops.get_pte_virt = get_pte_virt_fixmap;
505 #ifndef __PAGETABLE_PMD_FOLDED
506         pt_ops.alloc_pmd = alloc_pmd_fixmap;
507         pt_ops.get_pmd_virt = get_pmd_virt_fixmap;
508 #endif
509         /* Setup swapper PGD for fixmap */
510         create_pgd_mapping(swapper_pg_dir, FIXADDR_START,
511                            __pa_symbol(fixmap_pgd_next),
512                            PGDIR_SIZE, PAGE_TABLE);
513
514         /* Map all memory banks */
515         for_each_mem_range(i, &start, &end) {
516                 if (start >= end)
517                         break;
518                 if (start <= __pa(PAGE_OFFSET) &&
519                     __pa(PAGE_OFFSET) < end)
520                         start = __pa(PAGE_OFFSET);
521
522                 map_size = best_map_size(start, end - start);
523                 for (pa = start; pa < end; pa += map_size) {
524                         va = (uintptr_t)__va(pa);
525                         create_pgd_mapping(swapper_pg_dir, va, pa,
526                                            map_size, PAGE_KERNEL_EXEC);
527                 }
528         }
529
530         /* Clear fixmap PTE and PMD mappings */
531         clear_fixmap(FIX_PTE);
532         clear_fixmap(FIX_PMD);
533
534         /* Move to swapper page table */
535         csr_write(CSR_SATP, PFN_DOWN(__pa_symbol(swapper_pg_dir)) | SATP_MODE);
536         local_flush_tlb_all();
537
538         /* generic page allocation functions must be used to setup page table */
539         pt_ops.alloc_pte = alloc_pte_late;
540         pt_ops.get_pte_virt = get_pte_virt_late;
541 #ifndef __PAGETABLE_PMD_FOLDED
542         pt_ops.alloc_pmd = alloc_pmd_late;
543         pt_ops.get_pmd_virt = get_pmd_virt_late;
544 #endif
545 }
546 #else
547 asmlinkage void __init setup_vm(uintptr_t dtb_pa)
548 {
549         dtb_early_va = (void *)dtb_pa;
550         dtb_early_pa = dtb_pa;
551 }
552
553 static inline void setup_vm_final(void)
554 {
555 }
556 #endif /* CONFIG_MMU */
557
558 #ifdef CONFIG_STRICT_KERNEL_RWX
559 void protect_kernel_text_data(void)
560 {
561         unsigned long text_start = (unsigned long)_start;
562         unsigned long init_text_start = (unsigned long)__init_text_begin;
563         unsigned long init_data_start = (unsigned long)__init_data_begin;
564         unsigned long rodata_start = (unsigned long)__start_rodata;
565         unsigned long data_start = (unsigned long)_data;
566         unsigned long max_low = (unsigned long)(__va(PFN_PHYS(max_low_pfn)));
567
568         set_memory_ro(text_start, (init_text_start - text_start) >> PAGE_SHIFT);
569         set_memory_ro(init_text_start, (init_data_start - init_text_start) >> PAGE_SHIFT);
570         set_memory_nx(init_data_start, (rodata_start - init_data_start) >> PAGE_SHIFT);
571         /* rodata section is marked readonly in mark_rodata_ro */
572         set_memory_nx(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT);
573         set_memory_nx(data_start, (max_low - data_start) >> PAGE_SHIFT);
574 }
575
576 void mark_rodata_ro(void)
577 {
578         unsigned long rodata_start = (unsigned long)__start_rodata;
579         unsigned long data_start = (unsigned long)_data;
580
581         set_memory_ro(rodata_start, (data_start - rodata_start) >> PAGE_SHIFT);
582
583         debug_checkwx();
584 }
585 #endif
586
587 void __init paging_init(void)
588 {
589         setup_vm_final();
590         setup_zero_page();
591 }
592
593 void __init misc_mem_init(void)
594 {
595         arch_numa_init();
596         sparse_init();
597         zone_sizes_init();
598         memblock_dump_all();
599 }
600
601 #ifdef CONFIG_SPARSEMEM_VMEMMAP
602 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
603                                struct vmem_altmap *altmap)
604 {
605         return vmemmap_populate_basepages(start, end, node, NULL);
606 }
607 #endif