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 {
168197af22SChristophe Leroy 	return ((hpd_val(hpd) & _PMD_PAGE_MASK) >> 1) + 17;
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 {
228197af22SChristophe Leroy 	unsigned long idx = (addr & ((1UL << pdshift) - 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 {
355fb84fecSChristophe Leroy 	*hpdp = __hugepd(__pa(new) | _PMD_USER | _PMD_PRESENT |
365fb84fecSChristophe Leroy 			 (pshift == PAGE_SHIFT_8M ? _PMD_PAGE_8M : _PMD_PAGE_512K));
375fb84fecSChristophe Leroy }
385fb84fecSChristophe Leroy 
39723f268fSChristophe Leroy static inline int check_and_get_huge_psize(int shift)
40723f268fSChristophe Leroy {
41723f268fSChristophe Leroy 	return shift_to_mmu_psize(shift);
42723f268fSChristophe Leroy }
43723f268fSChristophe Leroy 
448197af22SChristophe Leroy #endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */
45