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
hugepd_page(hugepd_t hpd)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
hugepd_shift(hugepd_t hpd)148197af22SChristophe Leroy static inline unsigned int hugepd_shift(hugepd_t hpd)
158197af22SChristophe Leroy {
16d4870b89SChristophe Leroy return PAGE_SHIFT_8M;
178197af22SChristophe Leroy }
188197af22SChristophe Leroy
hugepte_offset(hugepd_t hpd,unsigned long addr,unsigned int pdshift)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
flush_hugetlb_page(struct vm_area_struct * vma,unsigned long vmaddr)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
hugepd_populate(hugepd_t * hpdp,pte_t * new,unsigned int pshift)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
hugepd_populate_kernel(hugepd_t * hpdp,pte_t * new,unsigned int pshift)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
check_and_get_huge_psize(int shift)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
49*935d4f0cSRyan Roberts void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
50*935d4f0cSRyan Roberts pte_t pte, unsigned long sz);
51b12c07a4SChristophe Leroy
52b12c07a4SChristophe Leroy #define __HAVE_ARCH_HUGE_PTE_CLEAR
huge_pte_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep,unsigned long sz)53b12c07a4SChristophe Leroy static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
54b12c07a4SChristophe Leroy pte_t *ptep, unsigned long sz)
55b12c07a4SChristophe Leroy {
56b12c07a4SChristophe Leroy pte_update(mm, addr, ptep, ~0UL, 0, 1);
57b12c07a4SChristophe Leroy }
58b12c07a4SChristophe Leroy
59b12c07a4SChristophe Leroy #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
huge_ptep_set_wrprotect(struct mm_struct * mm,unsigned long addr,pte_t * ptep)60b12c07a4SChristophe Leroy static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
61b12c07a4SChristophe Leroy unsigned long addr, pte_t *ptep)
62b12c07a4SChristophe Leroy {
63b12c07a4SChristophe Leroy unsigned long clr = ~pte_val(pte_wrprotect(__pte(~0)));
64b12c07a4SChristophe Leroy unsigned long set = pte_val(pte_wrprotect(__pte(0)));
65b12c07a4SChristophe Leroy
66b12c07a4SChristophe Leroy pte_update(mm, addr, ptep, clr, set, 1);
67b12c07a4SChristophe Leroy }
68b12c07a4SChristophe Leroy
69e47168f3SChristophe Leroy #ifdef CONFIG_PPC_4K_PAGES
arch_make_huge_pte(pte_t entry,unsigned int shift,vm_flags_t flags)7079c1c594SChristophe Leroy static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
71e47168f3SChristophe Leroy {
7279c1c594SChristophe Leroy size_t size = 1UL << shift;
73e47168f3SChristophe Leroy
74e47168f3SChristophe Leroy if (size == SZ_16K)
7516785bd7SAnshuman Khandual return __pte(pte_val(entry) | _PAGE_SPS);
76e47168f3SChristophe Leroy else
7716785bd7SAnshuman Khandual return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE);
78e47168f3SChristophe Leroy }
79e47168f3SChristophe Leroy #define arch_make_huge_pte arch_make_huge_pte
80e47168f3SChristophe Leroy #endif
81e47168f3SChristophe Leroy
828197af22SChristophe Leroy #endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */
83