18197af22SChristophe Leroy /* SPDX-License-Identifier: GPL-2.0 */ 28197af22SChristophe Leroy #ifndef _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H 38197af22SChristophe Leroy #define _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H 48197af22SChristophe Leroy 55fb84fecSChristophe Leroy #define PAGE_SHIFT_8M 23 65fb84fecSChristophe Leroy 78197af22SChristophe Leroy static inline pte_t *hugepd_page(hugepd_t hpd) 88197af22SChristophe Leroy { 98197af22SChristophe Leroy BUG_ON(!hugepd_ok(hpd)); 108197af22SChristophe Leroy 118197af22SChristophe Leroy return (pte_t *)__va(hpd_val(hpd) & ~HUGEPD_SHIFT_MASK); 128197af22SChristophe Leroy } 138197af22SChristophe Leroy 148197af22SChristophe Leroy static inline unsigned int hugepd_shift(hugepd_t hpd) 158197af22SChristophe Leroy { 16d4870b89SChristophe Leroy return PAGE_SHIFT_8M; 178197af22SChristophe Leroy } 188197af22SChristophe Leroy 198197af22SChristophe Leroy static inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr, 208197af22SChristophe Leroy unsigned int pdshift) 218197af22SChristophe Leroy { 22d4870b89SChristophe Leroy unsigned long idx = (addr & (SZ_4M - 1)) >> PAGE_SHIFT; 238197af22SChristophe Leroy 248197af22SChristophe Leroy return hugepd_page(hpd) + idx; 258197af22SChristophe Leroy } 268197af22SChristophe Leroy 278197af22SChristophe Leroy static inline void flush_hugetlb_page(struct vm_area_struct *vma, 288197af22SChristophe Leroy unsigned long vmaddr) 298197af22SChristophe Leroy { 308197af22SChristophe Leroy flush_tlb_page(vma, vmaddr); 318197af22SChristophe Leroy } 328197af22SChristophe Leroy 335fb84fecSChristophe Leroy static inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshift) 345fb84fecSChristophe Leroy { 35d4870b89SChristophe Leroy *hpdp = __hugepd(__pa(new) | _PMD_USER | _PMD_PRESENT | _PMD_PAGE_8M); 365fb84fecSChristophe Leroy } 375fb84fecSChristophe Leroy 3834536d78SChristophe Leroy static inline void hugepd_populate_kernel(hugepd_t *hpdp, pte_t *new, unsigned int pshift) 3934536d78SChristophe Leroy { 4034536d78SChristophe Leroy *hpdp = __hugepd(__pa(new) | _PMD_PRESENT | _PMD_PAGE_8M); 4134536d78SChristophe Leroy } 4234536d78SChristophe Leroy 43723f268fSChristophe Leroy static inline int check_and_get_huge_psize(int shift) 44723f268fSChristophe Leroy { 45723f268fSChristophe Leroy return shift_to_mmu_psize(shift); 46723f268fSChristophe Leroy } 47723f268fSChristophe Leroy 48b12c07a4SChristophe Leroy #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT 49b12c07a4SChristophe Leroy void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep, pte_t pte); 50b12c07a4SChristophe Leroy 51b12c07a4SChristophe Leroy #define __HAVE_ARCH_HUGE_PTE_CLEAR 52b12c07a4SChristophe Leroy static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, 53b12c07a4SChristophe Leroy pte_t *ptep, unsigned long sz) 54b12c07a4SChristophe Leroy { 55b12c07a4SChristophe Leroy pte_update(mm, addr, ptep, ~0UL, 0, 1); 56b12c07a4SChristophe Leroy } 57b12c07a4SChristophe Leroy 58b12c07a4SChristophe Leroy #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT 59b12c07a4SChristophe Leroy static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, 60b12c07a4SChristophe Leroy unsigned long addr, pte_t *ptep) 61b12c07a4SChristophe Leroy { 62b12c07a4SChristophe Leroy unsigned long clr = ~pte_val(pte_wrprotect(__pte(~0))); 63b12c07a4SChristophe Leroy unsigned long set = pte_val(pte_wrprotect(__pte(0))); 64b12c07a4SChristophe Leroy 65b12c07a4SChristophe Leroy pte_update(mm, addr, ptep, clr, set, 1); 66b12c07a4SChristophe Leroy } 67b12c07a4SChristophe Leroy 68e47168f3SChristophe Leroy #ifdef CONFIG_PPC_4K_PAGES 6979c1c594SChristophe Leroy static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags) 70e47168f3SChristophe Leroy { 7179c1c594SChristophe Leroy size_t size = 1UL << shift; 72e47168f3SChristophe Leroy 73e47168f3SChristophe Leroy if (size == SZ_16K) 74*16785bd7SAnshuman Khandual return __pte(pte_val(entry) | _PAGE_SPS); 75e47168f3SChristophe Leroy else 76*16785bd7SAnshuman Khandual return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE); 77e47168f3SChristophe Leroy } 78e47168f3SChristophe Leroy #define arch_make_huge_pte arch_make_huge_pte 79e47168f3SChristophe Leroy #endif 80e47168f3SChristophe Leroy 818197af22SChristophe Leroy #endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */ 82