30 #include <linux/kernel.h>
31 #include <linux/export.h>
42 #include <asm/tlbflush.h>
45 #include <asm/hugetlb.h>
54 #ifdef CONFIG_PPC_BOOK3E_MMU
55 #ifdef CONFIG_PPC_FSL_BOOK3E
118 static inline int mmu_get_tsize(
int psize)
120 return mmu_psize_defs[psize].
enc;
123 static inline int mmu_get_tsize(
int psize)
139 int book3e_htw_enabled;
140 unsigned long linear_map_top;
144 #ifdef CONFIG_PPC_FSL_BOOK3E
185 _tlbil_va(vmaddr, pid, tsize, ind);
203 static int mm_is_core_local(
struct mm_struct *mm)
205 return cpumask_subset(mm_cpumask(mm),
209 struct tlb_flush_param {
216 static void do_flush_tlb_mm_ipi(
void *
param)
218 struct tlb_flush_param *
p =
param;
220 _tlbil_pid(p ? p->pid : 0);
223 static void do_flush_tlb_page_ipi(
void *
param)
225 struct tlb_flush_param *
p =
param;
227 _tlbil_va(p->addr, p->pid, p->tsize, p->ind);
255 if (!mm_is_core_local(mm)) {
256 struct tlb_flush_param
p = { .pid = pid };
259 do_flush_tlb_mm_ipi, &p, 1);
277 cpu_mask = mm_cpumask(mm);
278 if (!mm_is_core_local(mm)) {
280 if (mmu_has_feature(MMU_FTR_USE_TLBIVAX_BCAST)) {
281 int lock = mmu_has_feature(MMU_FTR_LOCK_BCAST_INVAL);
284 _tlbivax_bcast(vmaddr, pid, tsize, ind);
289 struct tlb_flush_param
p = {
297 do_flush_tlb_page_ipi, &p, 1);
300 _tlbil_va(vmaddr, pid, tsize, ind);
307 #ifdef CONFIG_HUGETLB_PAGE
308 if (is_vm_hugetlb_page(vma))
319 #ifdef CONFIG_PPC_47x
320 void __init early_init_mmu_47x(
void)
323 unsigned long root = of_get_flat_dt_root();
324 if (of_get_flat_dt_prop(root,
"cooperative-partition",
NULL))
325 mmu_clear_feature(MMU_FTR_USE_TLBIVAX_BCAST);
378 int tsize = mmu_psize_defs[mmu_pte_psize].
enc;
380 if (book3e_htw_enabled) {
383 unsigned long size = 1
UL << mmu_psize_defs[mmu_pte_psize].
shift;
389 while (start < end) {
394 unsigned long rmask = 0xf000000000000000ul;
395 unsigned long rid = (address &
rmask) | 0x1000000000000000ul;
396 unsigned long vpte = address & ~rmask;
398 #ifdef CONFIG_PPC_64K_PAGES
399 vpte = (vpte >> (
PAGE_SHIFT - 4)) & ~0xfffful;
408 static void setup_page_sizes(
void)
410 unsigned int tlb0cfg;
415 #ifdef CONFIG_PPC_FSL_BOOK3E
416 unsigned int mmucfg =
mfspr(SPRN_MMUCFG);
419 (mmu_has_feature(MMU_FTR_TYPE_FSL_E))) {
420 unsigned int tlb1cfg =
mfspr(SPRN_TLB1CFG);
421 unsigned int min_pg, max_pg;
426 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
430 def = &mmu_psize_defs[psize];
437 shift = (shift - 10) >> 1;
439 if ((shift >= min_pg) && (shift <= max_pg))
447 tlb0cfg =
mfspr(SPRN_TLB0CFG);
448 tlb0ps =
mfspr(SPRN_TLB0PS);
449 eptcfg =
mfspr(SPRN_EPTCFG);
452 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
455 if (tlb0ps & (1
U << (def->
shift - 10)))
468 for (i = 0; i < 3; i++) {
469 unsigned int ps, sps;
477 for (psize = 0; psize < MMU_PAGE_COUNT; psize++) {
480 if (ps == (def->
shift - 10))
482 if (sps == (def->
shift - 10))
489 pr_info(
"MMU: Supported page sizes\n");
490 for (psize = 0; psize < MMU_PAGE_COUNT; ++psize) {
492 const char *__page_type_names[] = {
498 if (def->
flags == 0) {
503 __page_type_names[def->
flags & 0x3]);
507 static void __patch_exception(
int exc,
unsigned long addr)
509 extern unsigned int interrupt_base_book3e;
510 unsigned int *
ibase = &interrupt_base_book3e;
521 #define patch_exception(exc, name) do { \
522 extern unsigned int name; \
523 __patch_exception((exc), (unsigned long)&name); \
526 static void setup_mmu_htw(
void)
535 unsigned int tlb0cfg =
mfspr(SPRN_TLB0CFG);
537 if ((tlb0cfg & TLBnCFG_IND) &&
539 patch_exception(0x1c0, exc_data_tlb_miss_htw_book3e);
540 patch_exception(0x1e0, exc_instruction_tlb_miss_htw_book3e);
541 book3e_htw_enabled = 1;
543 pr_info(
"MMU: Book3E HW tablewalk %s\n",
544 book3e_htw_enabled ?
"enabled" :
"not supported");
550 static void __early_init_mmu(
int boot_cpu)
584 if (book3e_htw_enabled) {
586 #ifdef CONFIG_PPC_64K_PAGES
588 mmu_pte_psize = MMU_PAGE_256M;
591 mmu_pte_psize = MMU_PAGE_1M;
594 #ifdef CONFIG_PPC_64K_PAGES
601 mtspr(SPRN_MAS4, mas4);
608 #ifdef CONFIG_PPC_FSL_BOOK3E
609 if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
610 unsigned int num_cams;
619 patch_exception(0x1c0, exc_data_tlb_miss_bolted_book3e);
620 patch_exception(0x1e0, exc_instruction_tlb_miss_bolted_book3e);
637 void __cpuinit early_init_mmu_secondary(
void)
658 #ifdef CONFIG_PPC_FSL_BOOK3E
659 if (mmu_has_feature(MMU_FTR_TYPE_FSL_E)) {
660 unsigned long linear_sz;
662 first_memblock_base);
663 ppc64_rma_size =
min_t(
u64, linear_sz, 0x40000000);
666 ppc64_rma_size =
min_t(
u64, first_memblock_size, 0x40000000);
674 #ifdef CONFIG_PPC_47x
675 early_init_mmu_47x();