xref: /linux/arch/powerpc/include/asm/nohash/32/hugetlb-8xx.h (revision d53b8e36925256097a08d7cb749198d85cbf9b2b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H
3 #define _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H
4 
5 #define PAGE_SHIFT_8M		23
6 
7 static inline void flush_hugetlb_page(struct vm_area_struct *vma,
8 				      unsigned long vmaddr)
9 {
10 	flush_tlb_page(vma, vmaddr);
11 }
12 
13 static inline int check_and_get_huge_psize(int shift)
14 {
15 	return shift_to_mmu_psize(shift);
16 }
17 
18 #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT
19 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
20 		     pte_t pte, unsigned long sz);
21 
22 #define __HAVE_ARCH_HUGE_PTEP_GET
23 static inline pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
24 {
25 	if (ptep_is_8m_pmdp(mm, addr, ptep))
26 		ptep = pte_offset_kernel((pmd_t *)ptep, ALIGN_DOWN(addr, SZ_8M));
27 	return ptep_get(ptep);
28 }
29 
30 #define __HAVE_ARCH_HUGE_PTE_CLEAR
31 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
32 				  pte_t *ptep, unsigned long sz)
33 {
34 	pte_update(mm, addr, ptep, ~0UL, 0, 1);
35 }
36 
37 #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
38 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
39 					   unsigned long addr, pte_t *ptep)
40 {
41 	unsigned long clr = ~pte_val(pte_wrprotect(__pte(~0)));
42 	unsigned long set = pte_val(pte_wrprotect(__pte(0)));
43 
44 	pte_update(mm, addr, ptep, clr, set, 1);
45 }
46 
47 #ifdef CONFIG_PPC_4K_PAGES
48 static inline pte_t arch_make_huge_pte(pte_t entry, unsigned int shift, vm_flags_t flags)
49 {
50 	size_t size = 1UL << shift;
51 
52 	if (size == SZ_16K)
53 		return __pte(pte_val(entry) | _PAGE_SPS);
54 	else
55 		return __pte(pte_val(entry) | _PAGE_SPS | _PAGE_HUGE);
56 }
57 #define arch_make_huge_pte arch_make_huge_pte
58 #endif
59 
60 #endif /* _ASM_POWERPC_NOHASH_32_HUGETLB_8XX_H */
61