162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci#ifndef _ASM_POWERPC_NOHASH_HUGETLB_E500_H
362306a36Sopenharmony_ci#define _ASM_POWERPC_NOHASH_HUGETLB_E500_H
462306a36Sopenharmony_ci
562306a36Sopenharmony_cistatic inline pte_t *hugepd_page(hugepd_t hpd)
662306a36Sopenharmony_ci{
762306a36Sopenharmony_ci	if (WARN_ON(!hugepd_ok(hpd)))
862306a36Sopenharmony_ci		return NULL;
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci	return (pte_t *)((hpd_val(hpd) & ~HUGEPD_SHIFT_MASK) | PD_HUGE);
1162306a36Sopenharmony_ci}
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_cistatic inline unsigned int hugepd_shift(hugepd_t hpd)
1462306a36Sopenharmony_ci{
1562306a36Sopenharmony_ci	return hpd_val(hpd) & HUGEPD_SHIFT_MASK;
1662306a36Sopenharmony_ci}
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cistatic inline pte_t *hugepte_offset(hugepd_t hpd, unsigned long addr,
1962306a36Sopenharmony_ci				    unsigned int pdshift)
2062306a36Sopenharmony_ci{
2162306a36Sopenharmony_ci	/*
2262306a36Sopenharmony_ci	 * On FSL BookE, we have multiple higher-level table entries that
2362306a36Sopenharmony_ci	 * point to the same hugepte.  Just use the first one since they're all
2462306a36Sopenharmony_ci	 * identical.  So for that case, idx=0.
2562306a36Sopenharmony_ci	 */
2662306a36Sopenharmony_ci	return hugepd_page(hpd);
2762306a36Sopenharmony_ci}
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_civoid flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic inline void hugepd_populate(hugepd_t *hpdp, pte_t *new, unsigned int pshift)
3262306a36Sopenharmony_ci{
3362306a36Sopenharmony_ci	/* We use the old format for PPC_E500 */
3462306a36Sopenharmony_ci	*hpdp = __hugepd(((unsigned long)new & ~PD_HUGE) | pshift);
3562306a36Sopenharmony_ci}
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistatic inline int check_and_get_huge_psize(int shift)
3862306a36Sopenharmony_ci{
3962306a36Sopenharmony_ci	if (shift & 1)	/* Not a power of 4 */
4062306a36Sopenharmony_ci		return -EINVAL;
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci	return shift_to_mmu_psize(shift);
4362306a36Sopenharmony_ci}
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#endif /* _ASM_POWERPC_NOHASH_HUGETLB_E500_H */
46