1 // SPDX-License-Identifier: GPL-2.0
5 * Extracted from init.c
7 #include <linux/memblock.h>
8 #include <linux/percpu.h>
9 #include <linux/init.h>
10 #include <linux/string.h>
11 #include <linux/slab.h>
12 #include <linux/cache.h>
15 #include <asm/tlbflush.h>
16 #include <asm/mmu_context.h>
18 #include <asm/initialize_mmu.h>
21 DEFINE_PER_CPU(unsigned long, asid_cache
) = ASID_USER_FIRST
;
23 #if defined(CONFIG_HIGHMEM)
24 static void * __init
init_pmd(unsigned long vaddr
, unsigned long n_pages
)
26 pmd_t
*pmd
= pmd_off_k(vaddr
);
30 n_pages
= ALIGN(n_pages
, PTRS_PER_PTE
);
32 pr_debug("%s: vaddr: 0x%08lx, n_pages: %ld\n",
33 __func__
, vaddr
, n_pages
);
35 pte
= memblock_alloc_low(n_pages
* sizeof(pte_t
), PAGE_SIZE
);
37 panic("%s: Failed to allocate %lu bytes align=%lx\n",
38 __func__
, n_pages
* sizeof(pte_t
), PAGE_SIZE
);
40 for (i
= 0; i
< n_pages
; ++i
)
41 pte_clear(NULL
, 0, pte
+ i
);
43 for (i
= 0; i
< n_pages
; i
+= PTRS_PER_PTE
, ++pmd
) {
44 pte_t
*cur_pte
= pte
+ i
;
46 BUG_ON(!pmd_none(*pmd
));
47 set_pmd(pmd
, __pmd(((unsigned long)cur_pte
) & PAGE_MASK
));
48 BUG_ON(cur_pte
!= pte_offset_kernel(pmd
, 0));
49 pr_debug("%s: pmd: 0x%p, pte: 0x%p\n",
50 __func__
, pmd
, cur_pte
);
55 static void __init
fixedrange_init(void)
57 BUILD_BUG_ON(FIXADDR_START
< TLBTEMP_BASE_1
+ TLBTEMP_SIZE
);
58 init_pmd(FIXADDR_START
, __end_of_fixed_addresses
);
62 void __init
paging_init(void)
66 pkmap_page_table
= init_pmd(PKMAP_BASE
, LAST_PKMAP
);
72 * Flush the mmu and reset associated register to default values.
76 #if !(XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY)
78 * Writing zeros to the instruction and data TLBCFG special
79 * registers ensure that valid values exist in the register.
81 * For existing PGSZID<w> fields, zero selects the first element
82 * of the page-size array. For nonexistent PGSZID<w> fields,
83 * zero is the best value to write. Also, when changing PGSZID<w>
84 * fields, the corresponding TLB must be flushed.
86 set_itlbcfg_register(0);
87 set_dtlbcfg_register(0);
90 local_flush_tlb_all();
92 /* Set rasid register to a known value. */
94 set_rasid_register(ASID_INSERT(ASID_USER_FIRST
));
96 /* Set PTEVADDR special register to the start of the page
97 * table, which is in kernel mappable space (ie. not
98 * statically mapped). This register's value is undefined on
101 set_ptevaddr_register(XCHAL_PAGE_TABLE_VADDR
);
106 #if XCHAL_HAVE_PTP_MMU && XCHAL_HAVE_SPANNING_WAY && defined(CONFIG_USE_OF)
108 * Update the IO area mapping in case xtensa_kio_paddr has changed
110 write_dtlb_entry(__pte(xtensa_kio_paddr
+ CA_WRITEBACK
),
111 XCHAL_KIO_CACHED_VADDR
+ 6);
112 write_itlb_entry(__pte(xtensa_kio_paddr
+ CA_WRITEBACK
),
113 XCHAL_KIO_CACHED_VADDR
+ 6);
114 write_dtlb_entry(__pte(xtensa_kio_paddr
+ CA_BYPASS
),
115 XCHAL_KIO_BYPASS_VADDR
+ 6);
116 write_itlb_entry(__pte(xtensa_kio_paddr
+ CA_BYPASS
),
117 XCHAL_KIO_BYPASS_VADDR
+ 6);