1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_POWERPC_HUGETLB_H 3 #define _ASM_POWERPC_HUGETLB_H 4 5 #ifdef CONFIG_HUGETLB_PAGE 6 #include <asm/page.h> 7 8 #ifdef CONFIG_PPC_BOOK3S_64 9 10 #include <asm/book3s/64/hugetlb.h> 11 /* 12 * This should work for other subarchs too. But right now we use the 13 * new format only for 64bit book3s 14 */ 15 static inline pte_t *hugepd_page(hugepd_t hpd) 16 { 17 BUG_ON(!hugepd_ok(hpd)); 18 /* 19 * We have only four bits to encode, MMU page size 20 */ 21 BUILD_BUG_ON((MMU_PAGE_COUNT - 1) > 0xf); 22 return __va(hpd_val(hpd) & HUGEPD_ADDR_MASK); 23 } 24 25 static inline unsigned int hugepd_mmu_psize(hugepd_t hpd) 26 { 27 return (hpd_val(hpd) & HUGEPD_SHIFT_MASK) >> 2; 28 } 29 30 static inline unsigned int hugepd_shift(hugepd_t hpd) 31 { 32 return mmu_psize_to_shift(hugepd_mmu_psize(hpd)); 33 } 34 static inline void flush_hugetlb_page(struct vm_area_struct *vma, 35 unsigned long vmaddr) 36 { 37 if (radix_enabled()) 38 return radix__flush_hugetlb_page(vma, vmaddr); 39 } 40 41 #else 42 43 static inline pte_t *hugepd_page(hugepd_t hpd) 44 { 45 BUG_ON(!hugepd_ok(hpd)); 46 #ifdef CONFIG_PPC_8xx 47 return (pte_t *)__va(hpd_val(hpd) & ~HUGEPD_SHIFT_MASK); 48 #else 49 return (pte_t *)((hpd_val(hpd) & 50 ~HUGEPD_SHIFT_MASK) | PD_HUGE); 51 #endif 52 } 53 54 static inline unsigned int hugepd_shift(hugepd_t hpd) 55 { 56 #ifdef CONFIG_PPC_8xx 57 return ((hpd_val(hpd) & _PMD_PAGE_MASK) >> 1) + 17; 58 #else 59 return hpd_val(hpd) & HUGEPD_SHIFT_MASK; 60 #endif 61 } 62 63 #endif /* CONFIG_PPC_BOOK3S_64 */ 64 65 66 static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr, 67 unsigned pdshift) 68 { 69 /* 70 * On FSL BookE, we have multiple higher-level table entries that 71 * point to the same hugepte. Just use the first one since they're all 72 * identical. So for that case, idx=0. 73 */ 74 unsigned long idx = 0; 75 76 pte_t *dir = hugepd_page(hpd); 77 #ifdef CONFIG_PPC_8xx 78 idx = (addr & ((1UL << pdshift) - 1)) >> PAGE_SHIFT; 79 #elif !defined(CONFIG_PPC_FSL_BOOK3E) 80 idx = (addr & ((1UL << pdshift) - 1)) >> hugepd_shift(hpd); 81 #endif 82 83 return dir + idx; 84 } 85 86 void flush_dcache_icache_hugepage(struct page *page); 87 88 int slice_is_hugepage_only_range(struct mm_struct *mm, unsigned long addr, 89 unsigned long len); 90 91 static inline int is_hugepage_only_range(struct mm_struct *mm, 92 unsigned long addr, 93 unsigned long len) 94 { 95 if (IS_ENABLED(CONFIG_PPC_MM_SLICES) && !radix_enabled()) 96 return slice_is_hugepage_only_range(mm, addr, len); 97 return 0; 98 } 99 100 void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea, 101 pte_t pte); 102 #ifdef CONFIG_PPC_8xx 103 static inline void flush_hugetlb_page(struct vm_area_struct *vma, 104 unsigned long vmaddr) 105 { 106 flush_tlb_page(vma, vmaddr); 107 } 108 #else 109 void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr); 110 #endif 111 112 #define __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE 113 void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr, 114 unsigned long end, unsigned long floor, 115 unsigned long ceiling); 116 117 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR 118 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, 119 unsigned long addr, pte_t *ptep) 120 { 121 #ifdef CONFIG_PPC64 122 return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1)); 123 #else 124 return __pte(pte_update(ptep, ~0UL, 0)); 125 #endif 126 } 127 128 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH 129 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma, 130 unsigned long addr, pte_t *ptep) 131 { 132 huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); 133 flush_hugetlb_page(vma, addr); 134 } 135 136 #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS 137 int huge_ptep_set_access_flags(struct vm_area_struct *vma, 138 unsigned long addr, pte_t *ptep, 139 pte_t pte, int dirty); 140 141 static inline void arch_clear_hugepage_flags(struct page *page) 142 { 143 } 144 145 #include <asm-generic/hugetlb.h> 146 147 #else /* ! CONFIG_HUGETLB_PAGE */ 148 static inline void flush_hugetlb_page(struct vm_area_struct *vma, 149 unsigned long vmaddr) 150 { 151 } 152 153 #define hugepd_shift(x) 0 154 static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr, 155 unsigned pdshift) 156 { 157 return NULL; 158 } 159 #endif /* CONFIG_HUGETLB_PAGE */ 160 161 #endif /* _ASM_POWERPC_HUGETLB_H */ 162