2 * Based on arch/arm/mm/mmu.c
4 * Copyright (C) 1995-2005 Russell King
5 * Copyright (C) 2012 ARM Ltd.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <linux/export.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/init.h>
24 #include <linux/libfdt.h>
25 #include <linux/mman.h>
26 #include <linux/nodemask.h>
27 #include <linux/memblock.h>
30 #include <linux/slab.h>
31 #include <linux/stop_machine.h>
34 #include <asm/barrier.h>
35 #include <asm/cputype.h>
36 #include <asm/fixmap.h>
37 #include <asm/kasan.h>
38 #include <asm/kernel-pgtable.h>
39 #include <asm/sections.h>
40 #include <asm/setup.h>
41 #include <asm/sizes.h>
43 #include <asm/memblock.h>
44 #include <asm/mmu_context.h>
48 u64 idmap_t0sz = TCR_T0SZ(VA_BITS);
50 u64 kimage_voffset __read_mostly;
51 EXPORT_SYMBOL(kimage_voffset);
54 * Empty_zero_page is a special page that is used for zero-initialized data
57 unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;
58 EXPORT_SYMBOL(empty_zero_page);
60 static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss;
61 static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused;
62 static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused;
64 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
65 unsigned long size, pgprot_t vma_prot)
68 return pgprot_noncached(vma_prot);
69 else if (file->f_flags & O_SYNC)
70 return pgprot_writecombine(vma_prot);
73 EXPORT_SYMBOL(phys_mem_access_prot);
75 static phys_addr_t __init early_pgtable_alloc(void)
80 phys = memblock_alloc(PAGE_SIZE, PAGE_SIZE);
84 * The FIX_{PGD,PUD,PMD} slots may be in active use, but the FIX_PTE
85 * slot will be free, so we can (ab)use the FIX_PTE slot to initialise
88 ptr = pte_set_fixmap(phys);
90 memset(ptr, 0, PAGE_SIZE);
93 * Implicit barriers also ensure the zeroed page is visible to the page
102 * remap a PMD into pages
104 static void split_pmd(pmd_t *pmd, pte_t *pte)
106 unsigned long pfn = pmd_pfn(*pmd);
111 * Need to have the least restrictive permissions available
112 * permissions will be fixed up later
114 set_pte(pte, pfn_pte(pfn, PAGE_KERNEL_EXEC));
116 } while (pte++, i++, i < PTRS_PER_PTE);
119 static void alloc_init_pte(pmd_t *pmd, unsigned long addr,
120 unsigned long end, unsigned long pfn,
122 phys_addr_t (*pgtable_alloc)(void))
126 if (pmd_none(*pmd) || pmd_sect(*pmd)) {
127 phys_addr_t pte_phys;
128 BUG_ON(!pgtable_alloc);
129 pte_phys = pgtable_alloc();
130 pte = pte_set_fixmap(pte_phys);
133 __pmd_populate(pmd, pte_phys, PMD_TYPE_TABLE);
137 BUG_ON(pmd_bad(*pmd));
139 pte = pte_set_fixmap_offset(pmd, addr);
141 set_pte(pte, pfn_pte(pfn, prot));
143 } while (pte++, addr += PAGE_SIZE, addr != end);
148 static void split_pud(pud_t *old_pud, pmd_t *pmd)
150 unsigned long addr = pud_pfn(*old_pud) << PAGE_SHIFT;
151 pgprot_t prot = __pgprot(pud_val(*old_pud) ^ addr);
155 set_pmd(pmd, __pmd(addr | pgprot_val(prot)));
157 } while (pmd++, i++, i < PTRS_PER_PMD);
160 #ifdef CONFIG_DEBUG_PAGEALLOC
161 static bool block_mappings_allowed(phys_addr_t (*pgtable_alloc)(void))
165 * If debug_page_alloc is enabled we must map the linear map
166 * using pages. However, other mappings created by
167 * create_mapping_noalloc must use sections in some cases. Allow
168 * sections to be used in those cases, where no pgtable_alloc
169 * function is provided.
171 return !pgtable_alloc || !debug_pagealloc_enabled();
174 static bool block_mappings_allowed(phys_addr_t (*pgtable_alloc)(void))
180 static void alloc_init_pmd(pud_t *pud, unsigned long addr, unsigned long end,
181 phys_addr_t phys, pgprot_t prot,
182 phys_addr_t (*pgtable_alloc)(void))
188 * Check for initial section mappings in the pgd/pud and remove them.
190 if (pud_none(*pud) || pud_sect(*pud)) {
191 phys_addr_t pmd_phys;
192 BUG_ON(!pgtable_alloc);
193 pmd_phys = pgtable_alloc();
194 pmd = pmd_set_fixmap(pmd_phys);
195 if (pud_sect(*pud)) {
197 * need to have the 1G of mappings continue to be
202 __pud_populate(pud, pmd_phys, PUD_TYPE_TABLE);
206 BUG_ON(pud_bad(*pud));
208 pmd = pmd_set_fixmap_offset(pud, addr);
210 next = pmd_addr_end(addr, end);
211 /* try section mapping first */
212 if (((addr | next | phys) & ~SECTION_MASK) == 0 &&
213 block_mappings_allowed(pgtable_alloc)) {
215 pmd_set_huge(pmd, phys, prot);
217 * Check for previous table entries created during
218 * boot (__create_page_tables) and flush them.
220 if (!pmd_none(old_pmd)) {
222 if (pmd_table(old_pmd)) {
223 phys_addr_t table = pmd_page_paddr(old_pmd);
224 if (!WARN_ON_ONCE(slab_is_available()))
225 memblock_free(table, PAGE_SIZE);
229 alloc_init_pte(pmd, addr, next, __phys_to_pfn(phys),
230 prot, pgtable_alloc);
233 } while (pmd++, addr = next, addr != end);
238 static inline bool use_1G_block(unsigned long addr, unsigned long next,
241 if (PAGE_SHIFT != 12)
244 if (((addr | next | phys) & ~PUD_MASK) != 0)
250 static void alloc_init_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
251 phys_addr_t phys, pgprot_t prot,
252 phys_addr_t (*pgtable_alloc)(void))
257 if (pgd_none(*pgd)) {
258 phys_addr_t pud_phys;
259 BUG_ON(!pgtable_alloc);
260 pud_phys = pgtable_alloc();
261 __pgd_populate(pgd, pud_phys, PUD_TYPE_TABLE);
263 BUG_ON(pgd_bad(*pgd));
265 pud = pud_set_fixmap_offset(pgd, addr);
267 next = pud_addr_end(addr, end);
270 * For 4K granule only, attempt to put down a 1GB block
272 if (use_1G_block(addr, next, phys) &&
273 block_mappings_allowed(pgtable_alloc)) {
274 pud_t old_pud = *pud;
275 pud_set_huge(pud, phys, prot);
278 * If we have an old value for a pud, it will
279 * be pointing to a pmd table that we no longer
280 * need (from swapper_pg_dir).
282 * Look up the old pmd table and free it.
284 if (!pud_none(old_pud)) {
286 if (pud_table(old_pud)) {
287 phys_addr_t table = pud_page_paddr(old_pud);
288 if (!WARN_ON_ONCE(slab_is_available()))
289 memblock_free(table, PAGE_SIZE);
293 alloc_init_pmd(pud, addr, next, phys, prot,
297 } while (pud++, addr = next, addr != end);
303 * Create the page directory entries and any necessary page tables for the
304 * mapping specified by 'md'.
306 static void init_pgd(pgd_t *pgd, phys_addr_t phys, unsigned long virt,
307 phys_addr_t size, pgprot_t prot,
308 phys_addr_t (*pgtable_alloc)(void))
310 unsigned long addr, length, end, next;
313 * If the virtual and physical address don't have the same offset
314 * within a page, we cannot map the region as the caller expects.
316 if (WARN_ON((phys ^ virt) & ~PAGE_MASK))
320 addr = virt & PAGE_MASK;
321 length = PAGE_ALIGN(size + (virt & ~PAGE_MASK));
325 next = pgd_addr_end(addr, end);
326 alloc_init_pud(pgd, addr, next, phys, prot, pgtable_alloc);
328 } while (pgd++, addr = next, addr != end);
331 static phys_addr_t late_pgtable_alloc(void)
333 void *ptr = (void *)__get_free_page(PGALLOC_GFP);
336 /* Ensure the zeroed page is visible to the page table walker */
341 static void __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys,
342 unsigned long virt, phys_addr_t size,
344 phys_addr_t (*alloc)(void))
346 init_pgd(pgd_offset_raw(pgdir, virt), phys, virt, size, prot, alloc);
350 * This function can only be used to modify existing table entries,
351 * without allocating new levels of table. Note that this permits the
352 * creation of new section or page entries.
354 static void __init create_mapping_noalloc(phys_addr_t phys, unsigned long virt,
355 phys_addr_t size, pgprot_t prot)
357 if (virt < VMALLOC_START) {
358 pr_warn("BUG: not creating mapping for %pa at 0x%016lx - outside kernel range\n",
362 __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot,
366 void __init create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys,
367 unsigned long virt, phys_addr_t size,
370 __create_pgd_mapping(mm->pgd, phys, virt, size, prot,
374 static void create_mapping_late(phys_addr_t phys, unsigned long virt,
375 phys_addr_t size, pgprot_t prot)
377 if (virt < VMALLOC_START) {
378 pr_warn("BUG: not creating mapping for %pa at 0x%016lx - outside kernel range\n",
383 __create_pgd_mapping(init_mm.pgd, phys, virt, size, prot,
387 static void __init __map_memblock(pgd_t *pgd, phys_addr_t start, phys_addr_t end)
389 unsigned long kernel_start = __pa_symbol(_stext);
390 unsigned long kernel_end = __pa_symbol(__init_begin);
393 * Take care not to create a writable alias for the
394 * read-only text and rodata sections of the kernel image.
397 /* No overlap with the kernel text/rodata */
398 if (end < kernel_start || start >= kernel_end) {
399 __create_pgd_mapping(pgd, start, __phys_to_virt(start),
400 end - start, PAGE_KERNEL,
401 early_pgtable_alloc);
406 * This block overlaps the kernel text/rodata mapping.
407 * Map the portion(s) which don't overlap.
409 if (start < kernel_start)
410 __create_pgd_mapping(pgd, start,
411 __phys_to_virt(start),
412 kernel_start - start, PAGE_KERNEL,
413 early_pgtable_alloc);
414 if (kernel_end < end)
415 __create_pgd_mapping(pgd, kernel_end,
416 __phys_to_virt(kernel_end),
417 end - kernel_end, PAGE_KERNEL,
418 early_pgtable_alloc);
421 * Map the linear alias of the [_stext, __init_begin) interval as
422 * read-only/non-executable. This makes the contents of the
423 * region accessible to subsystems such as hibernate, but
424 * protects it from inadvertent modification or execution.
426 __create_pgd_mapping(pgd, kernel_start, __phys_to_virt(kernel_start),
427 kernel_end - kernel_start, PAGE_KERNEL_RO,
428 early_pgtable_alloc);
431 static void __init map_mem(pgd_t *pgd)
433 struct memblock_region *reg;
435 /* map all the memory banks */
436 for_each_memblock(memory, reg) {
437 phys_addr_t start = reg->base;
438 phys_addr_t end = start + reg->size;
442 if (memblock_is_nomap(reg))
445 __map_memblock(pgd, start, end);
449 void mark_rodata_ro(void)
451 unsigned long section_size;
453 section_size = (unsigned long)_etext - (unsigned long)_stext;
454 create_mapping_late(__pa_symbol(_stext), (unsigned long)_stext,
455 section_size, PAGE_KERNEL_ROX);
457 * mark .rodata as read only. Use __init_begin rather than __end_rodata
458 * to cover NOTES and EXCEPTION_TABLE.
460 section_size = (unsigned long)__init_begin - (unsigned long)__start_rodata;
461 create_mapping_late(__pa_symbol(__start_rodata),
462 (unsigned long)__start_rodata,
463 section_size, PAGE_KERNEL_RO);
466 void fixup_init(void)
469 * Unmap the __init region but leave the VM area in place. This
470 * prevents the region from being reused for kernel modules, which
471 * is not supported by kallsyms.
473 unmap_kernel_range((u64)__init_begin, (u64)(__init_end - __init_begin));
476 static void __init map_kernel_chunk(pgd_t *pgd, void *va_start, void *va_end,
477 pgprot_t prot, struct vm_struct *vma)
479 phys_addr_t pa_start = __pa_symbol(va_start);
480 unsigned long size = va_end - va_start;
482 BUG_ON(!PAGE_ALIGNED(pa_start));
483 BUG_ON(!PAGE_ALIGNED(size));
485 __create_pgd_mapping(pgd, pa_start, (unsigned long)va_start, size, prot,
486 early_pgtable_alloc);
488 vma->addr = va_start;
489 vma->phys_addr = pa_start;
492 vma->caller = __builtin_return_address(0);
494 vm_area_add_early(vma);
497 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
498 static int __init map_entry_trampoline(void)
500 extern char __entry_tramp_text_start[];
502 pgprot_t prot = PAGE_KERNEL_ROX;
503 phys_addr_t pa_start = __pa_symbol(__entry_tramp_text_start);
505 /* The trampoline is always mapped and can therefore be global */
506 pgprot_val(prot) &= ~PTE_NG;
508 /* Map only the text into the trampoline page table */
509 memset(tramp_pg_dir, 0, PGD_SIZE);
510 __create_pgd_mapping(tramp_pg_dir, pa_start, TRAMP_VALIAS, PAGE_SIZE,
511 prot, late_pgtable_alloc);
513 /* Map both the text and data into the kernel page table */
514 __set_fixmap(FIX_ENTRY_TRAMP_TEXT, pa_start, prot);
515 if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) {
516 extern char __entry_tramp_data_start[];
518 __set_fixmap(FIX_ENTRY_TRAMP_DATA,
519 __pa_symbol(__entry_tramp_data_start),
525 core_initcall(map_entry_trampoline);
529 * Create fine-grained mappings for the kernel.
531 static void __init map_kernel(pgd_t *pgd)
533 static struct vm_struct vmlinux_text, vmlinux_rodata, vmlinux_init, vmlinux_data;
535 map_kernel_chunk(pgd, _stext, _etext, PAGE_KERNEL_EXEC, &vmlinux_text);
536 map_kernel_chunk(pgd, __start_rodata, __init_begin, PAGE_KERNEL, &vmlinux_rodata);
537 map_kernel_chunk(pgd, __init_begin, __init_end, PAGE_KERNEL_EXEC,
539 map_kernel_chunk(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data);
541 if (!pgd_val(*pgd_offset_raw(pgd, FIXADDR_START))) {
543 * The fixmap falls in a separate pgd to the kernel, and doesn't
544 * live in the carveout for the swapper_pg_dir. We can simply
545 * re-use the existing dir for the fixmap.
547 set_pgd(pgd_offset_raw(pgd, FIXADDR_START),
548 *pgd_offset_k(FIXADDR_START));
549 } else if (CONFIG_PGTABLE_LEVELS > 3) {
551 * The fixmap shares its top level pgd entry with the kernel
552 * mapping. This can really only occur when we are running
553 * with 16k/4 levels, so we can simply reuse the pud level
556 BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES));
557 set_pud(pud_set_fixmap_offset(pgd, FIXADDR_START),
558 __pud(__pa_symbol(bm_pmd) | PUD_TYPE_TABLE));
564 kasan_copy_shadow(pgd);
568 * paging_init() sets up the page tables, initialises the zone memory
569 * maps and sets up the zero page.
571 void __init paging_init(void)
573 phys_addr_t pgd_phys = early_pgtable_alloc();
574 pgd_t *pgd = pgd_set_fixmap(pgd_phys);
580 * We want to reuse the original swapper_pg_dir so we don't have to
581 * communicate the new address to non-coherent secondaries in
582 * secondary_entry, and so cpu_switch_mm can generate the address with
583 * adrp+add rather than a load from some global variable.
585 * To do this we need to go via a temporary pgd.
587 cpu_replace_ttbr1(__va(pgd_phys));
588 memcpy(swapper_pg_dir, pgd, PAGE_SIZE);
589 cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
592 memblock_free(pgd_phys, PAGE_SIZE);
594 /* Ensure the zero page is visible to the page table walker */
598 * We only reuse the PGD from the swapper_pg_dir, not the pud + pmd
601 memblock_free(__pa_symbol(swapper_pg_dir) + PAGE_SIZE,
602 SWAPPER_DIR_SIZE - PAGE_SIZE);
608 * Check whether a kernel address is valid (derived from arch/x86/).
610 int kern_addr_valid(unsigned long addr)
617 if ((((long)addr) >> VA_BITS) != -1UL)
620 pgd = pgd_offset_k(addr);
624 pud = pud_offset(pgd, addr);
629 return pfn_valid(pud_pfn(*pud));
631 pmd = pmd_offset(pud, addr);
636 return pfn_valid(pmd_pfn(*pmd));
638 pte = pte_offset_kernel(pmd, addr);
642 return pfn_valid(pte_pfn(*pte));
644 #ifdef CONFIG_SPARSEMEM_VMEMMAP
645 #if !ARM64_SWAPPER_USES_SECTION_MAPS
646 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
648 return vmemmap_populate_basepages(start, end, node);
650 #else /* !ARM64_SWAPPER_USES_SECTION_MAPS */
651 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node)
653 unsigned long addr = start;
660 next = pmd_addr_end(addr, end);
662 pgd = vmemmap_pgd_populate(addr, node);
666 pud = vmemmap_pud_populate(pgd, addr, node);
670 pmd = pmd_offset(pud, addr);
671 if (pmd_none(*pmd)) {
674 p = vmemmap_alloc_block_buf(PMD_SIZE, node);
678 set_pmd(pmd, __pmd(__pa(p) | PROT_SECT_NORMAL));
680 vmemmap_verify((pte_t *)pmd, node, addr, next);
681 } while (addr = next, addr != end);
685 #endif /* CONFIG_ARM64_64K_PAGES */
686 void vmemmap_free(unsigned long start, unsigned long end)
689 #endif /* CONFIG_SPARSEMEM_VMEMMAP */
691 static inline pud_t * fixmap_pud(unsigned long addr)
693 pgd_t *pgd = pgd_offset_k(addr);
695 BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd));
697 return pud_offset_kimg(pgd, addr);
700 static inline pmd_t * fixmap_pmd(unsigned long addr)
702 pud_t *pud = fixmap_pud(addr);
704 BUG_ON(pud_none(*pud) || pud_bad(*pud));
706 return pmd_offset_kimg(pud, addr);
709 static inline pte_t * fixmap_pte(unsigned long addr)
711 return &bm_pte[pte_index(addr)];
715 * The p*d_populate functions call virt_to_phys implicitly so they can't be used
716 * directly on kernel symbols (bm_p*d). This function is called too early to use
717 * lm_alias so __p*d_populate functions must be used to populate with the
718 * physical address from __pa_symbol.
720 void __init early_fixmap_init(void)
725 unsigned long addr = FIXADDR_START;
727 pgd = pgd_offset_k(addr);
728 if (CONFIG_PGTABLE_LEVELS > 3 &&
729 !(pgd_none(*pgd) || pgd_page_paddr(*pgd) == __pa_symbol(bm_pud))) {
731 * We only end up here if the kernel mapping and the fixmap
732 * share the top level pgd entry, which should only happen on
733 * 16k/4 levels configurations.
735 BUG_ON(!IS_ENABLED(CONFIG_ARM64_16K_PAGES));
736 pud = pud_offset_kimg(pgd, addr);
739 __pgd_populate(pgd, __pa_symbol(bm_pud),
741 pud = fixmap_pud(addr);
744 __pud_populate(pud, __pa_symbol(bm_pmd), PMD_TYPE_TABLE);
745 pmd = fixmap_pmd(addr);
746 __pmd_populate(pmd, __pa_symbol(bm_pte), PMD_TYPE_TABLE);
749 * The boot-ioremap range spans multiple pmds, for which
750 * we are not prepared:
752 BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
753 != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
755 if ((pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)))
756 || pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_END))) {
758 pr_warn("pmd %p != %p, %p\n",
759 pmd, fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)),
760 fixmap_pmd(fix_to_virt(FIX_BTMAP_END)));
761 pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
762 fix_to_virt(FIX_BTMAP_BEGIN));
763 pr_warn("fix_to_virt(FIX_BTMAP_END): %08lx\n",
764 fix_to_virt(FIX_BTMAP_END));
766 pr_warn("FIX_BTMAP_END: %d\n", FIX_BTMAP_END);
767 pr_warn("FIX_BTMAP_BEGIN: %d\n", FIX_BTMAP_BEGIN);
771 void __set_fixmap(enum fixed_addresses idx,
772 phys_addr_t phys, pgprot_t flags)
774 unsigned long addr = __fix_to_virt(idx);
777 BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
779 pte = fixmap_pte(addr);
781 if (pgprot_val(flags)) {
782 set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
784 pte_clear(&init_mm, addr, pte);
785 flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
789 void *__init __fixmap_remap_fdt(phys_addr_t dt_phys, int *size, pgprot_t prot)
791 const u64 dt_virt_base = __fix_to_virt(FIX_FDT);
796 * Check whether the physical FDT address is set and meets the minimum
797 * alignment requirement. Since we are relying on MIN_FDT_ALIGN to be
798 * at least 8 bytes so that we can always access the magic and size
799 * fields of the FDT header after mapping the first chunk, double check
800 * here if that is indeed the case.
802 BUILD_BUG_ON(MIN_FDT_ALIGN < 8);
803 if (!dt_phys || dt_phys % MIN_FDT_ALIGN)
807 * Make sure that the FDT region can be mapped without the need to
808 * allocate additional translation table pages, so that it is safe
809 * to call create_mapping_noalloc() this early.
811 * On 64k pages, the FDT will be mapped using PTEs, so we need to
812 * be in the same PMD as the rest of the fixmap.
813 * On 4k pages, we'll use section mappings for the FDT so we only
814 * have to be in the same PUD.
816 BUILD_BUG_ON(dt_virt_base % SZ_2M);
818 BUILD_BUG_ON(__fix_to_virt(FIX_FDT_END) >> SWAPPER_TABLE_SHIFT !=
819 __fix_to_virt(FIX_BTMAP_BEGIN) >> SWAPPER_TABLE_SHIFT);
821 offset = dt_phys % SWAPPER_BLOCK_SIZE;
822 dt_virt = (void *)dt_virt_base + offset;
824 /* map the first chunk so we can read the size from the header */
825 create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE),
826 dt_virt_base, SWAPPER_BLOCK_SIZE, prot);
828 if (fdt_magic(dt_virt) != FDT_MAGIC)
831 *size = fdt_totalsize(dt_virt);
832 if (*size > MAX_FDT_SIZE)
835 if (offset + *size > SWAPPER_BLOCK_SIZE)
836 create_mapping_noalloc(round_down(dt_phys, SWAPPER_BLOCK_SIZE), dt_virt_base,
837 round_up(offset + *size, SWAPPER_BLOCK_SIZE), prot);
842 void *__init fixmap_remap_fdt(phys_addr_t dt_phys)
847 dt_virt = __fixmap_remap_fdt(dt_phys, &size, PAGE_KERNEL_RO);
851 memblock_reserve(dt_phys, size);
855 int __init arch_ioremap_pud_supported(void)
857 /* only 4k granule supports level 1 block mappings */
858 return IS_ENABLED(CONFIG_ARM64_4K_PAGES);
861 int __init arch_ioremap_pmd_supported(void)
866 int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot)
868 BUG_ON(phys & ~PUD_MASK);
869 set_pud(pud, __pud(phys | PUD_TYPE_SECT | pgprot_val(mk_sect_prot(prot))));
873 int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot)
875 BUG_ON(phys & ~PMD_MASK);
876 set_pmd(pmd, __pmd(phys | PMD_TYPE_SECT | pgprot_val(mk_sect_prot(prot))));
880 int pud_clear_huge(pud_t *pud)
888 int pmd_clear_huge(pmd_t *pmd)
896 #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
897 int pud_free_pmd_page(pud_t *pud, unsigned long addr)
899 return pud_none(*pud);
902 int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
904 return pmd_none(*pmd);