18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_HUGETLB_BOOK3E_H
38c2ecf20Sopenharmony_ci#define _ASM_POWERPC_NOHASH_HUGETLB_BOOK3E_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_cistatic inline pte_t *hugepd_page(hugepd_t hpd)
68c2ecf20Sopenharmony_ci{
78c2ecf20Sopenharmony_ci	if (WARN_ON(!hugepd_ok(hpd)))
88c2ecf20Sopenharmony_ci		return NULL;
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci	return (pte_t *)((hpd_val(hpd) & ~HUGEPD_SHIFT_MASK) | PD_HUGE);
118c2ecf20Sopenharmony_ci}
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistatic inline unsigned int hugepd_shift(hugepd_t hpd)
148c2ecf20Sopenharmony_ci{
158c2ecf20Sopenharmony_ci	return hpd_val(hpd) & HUGEPD_SHIFT_MASK;
168c2ecf20Sopenharmony_ci}
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cistatic inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
198c2ecf20Sopenharmony_ci				    unsigned int pdshift)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	/*
228c2ecf20Sopenharmony_ci	 * On FSL BookE, we have multiple higher-level table entries that
238c2ecf20Sopenharmony_ci	 * point to the same hugepte.  Just use the first one since they're all
248c2ecf20Sopenharmony_ci	 * identical.  So for that case, idx=0.
258c2ecf20Sopenharmony_ci	 */
268c2ecf20Sopenharmony_ci	return hugepd_page(hpd);
278c2ecf20Sopenharmony_ci}
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_civoid flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_cistatic inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshift)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	/* We use the old format for PPC_FSL_BOOK3E */
348c2ecf20Sopenharmony_ci	*hpdp = __hugepd(((unsigned long)new & ~PD_HUGE) | pshift);
358c2ecf20Sopenharmony_ci}
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic inline int check_and_get_huge_psize(int shift)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	if (shift & 1)	/* Not a power of 4 */
408c2ecf20Sopenharmony_ci		return -EINVAL;
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	return shift_to_mmu_psize(shift);
438c2ecf20Sopenharmony_ci}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_NOHASH_HUGETLB_BOOK3E_H */
46