xref: /linux/arch/s390/include/asm/hugetlb.h (revision 1fd1dc41724319406b0aff221a352a400b0ddfc5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  IBM System z Huge TLB Page Support for Kernel.
4  *
5  *    Copyright IBM Corp. 2008
6  *    Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com>
7  */
8 
9 #ifndef _ASM_S390_HUGETLB_H
10 #define _ASM_S390_HUGETLB_H
11 
12 #include <linux/cpufeature.h>
13 #include <linux/pgtable.h>
14 #include <linux/swap.h>
15 #include <linux/swapops.h>
16 #include <asm/page.h>
17 
18 #define hugepages_supported()	cpu_has_edat1()
19 
20 #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT
21 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
22 		     pte_t *ptep, pte_t pte, unsigned long sz);
23 void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
24 		       pte_t *ptep, pte_t pte);
25 
26 #define __HAVE_ARCH_HUGE_PTEP_GET
27 pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep);
28 
29 pte_t __huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
30 				pte_t *ptep);
31 
32 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
33 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
34 					    unsigned long addr, pte_t *ptep,
35 					    unsigned long sz)
36 {
37 	return __huge_ptep_get_and_clear(mm, addr, ptep);
38 }
39 
40 #define __HAVE_ARCH_HUGE_PTE_CLEAR
41 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
42 				  pte_t *ptep, unsigned long sz)
43 {
44 	if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3)
45 		set_pte(ptep, __pte(_REGION3_ENTRY_EMPTY));
46 	else
47 		set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY));
48 }
49 
50 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
51 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
52 					  unsigned long address, pte_t *ptep)
53 {
54 	return __huge_ptep_get_and_clear(vma->vm_mm, address, ptep);
55 }
56 
57 #define  __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
58 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
59 					     unsigned long addr, pte_t *ptep,
60 					     pte_t pte, int dirty)
61 {
62 	int changed = !pte_same(huge_ptep_get(vma->vm_mm, addr, ptep), pte);
63 
64 	if (changed) {
65 		__huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
66 		__set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
67 	}
68 	return changed;
69 }
70 
71 #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
72 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
73 					   unsigned long addr, pte_t *ptep)
74 {
75 	pte_t pte = __huge_ptep_get_and_clear(mm, addr, ptep);
76 
77 	__set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte));
78 }
79 
80 #define __HAVE_ARCH_HUGE_PTE_MKUFFD_WP
81 static inline pte_t huge_pte_mkuffd_wp(pte_t pte)
82 {
83 	return pte;
84 }
85 
86 #define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP
87 static inline pte_t huge_pte_clear_uffd_wp(pte_t pte)
88 {
89 	return pte;
90 }
91 
92 #define __HAVE_ARCH_HUGE_PTE_UFFD_WP
93 static inline int huge_pte_uffd_wp(pte_t pte)
94 {
95 	return 0;
96 }
97 
98 #include <asm-generic/hugetlb.h>
99 
100 #endif /* _ASM_S390_HUGETLB_H */
101