xref: /openbmc/linux/arch/s390/include/asm/hugetlb.h (revision dea54fba)
1 /*
2  *  IBM System z Huge TLB Page Support for Kernel.
3  *
4  *    Copyright IBM Corp. 2008
5  *    Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com>
6  */
7 
8 #ifndef _ASM_S390_HUGETLB_H
9 #define _ASM_S390_HUGETLB_H
10 
11 #include <asm/page.h>
12 #include <asm/pgtable.h>
13 
14 
15 #define is_hugepage_only_range(mm, addr, len)	0
16 #define hugetlb_free_pgd_range			free_pgd_range
17 #define hugepages_supported()			(MACHINE_HAS_EDAT1)
18 
19 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
20 		     pte_t *ptep, pte_t pte);
21 pte_t huge_ptep_get(pte_t *ptep);
22 pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
23 			      unsigned long addr, pte_t *ptep);
24 
25 /*
26  * If the arch doesn't supply something else, assume that hugepage
27  * size aligned regions are ok without further preparation.
28  */
29 static inline int prepare_hugepage_range(struct file *file,
30 			unsigned long addr, unsigned long len)
31 {
32 	if (len & ~HPAGE_MASK)
33 		return -EINVAL;
34 	if (addr & ~HPAGE_MASK)
35 		return -EINVAL;
36 	return 0;
37 }
38 
39 #define arch_clear_hugepage_flags(page)		do { } while (0)
40 
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 		pte_val(*ptep) = _REGION3_ENTRY_EMPTY;
46 	else
47 		pte_val(*ptep) = _SEGMENT_ENTRY_EMPTY;
48 }
49 
50 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
51 					 unsigned long address, pte_t *ptep)
52 {
53 	huge_ptep_get_and_clear(vma->vm_mm, address, ptep);
54 }
55 
56 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
57 					     unsigned long addr, pte_t *ptep,
58 					     pte_t pte, int dirty)
59 {
60 	int changed = !pte_same(huge_ptep_get(ptep), pte);
61 	if (changed) {
62 		huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
63 		set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
64 	}
65 	return changed;
66 }
67 
68 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
69 					   unsigned long addr, pte_t *ptep)
70 {
71 	pte_t pte = huge_ptep_get_and_clear(mm, addr, ptep);
72 	set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte));
73 }
74 
75 static inline pte_t mk_huge_pte(struct page *page, pgprot_t pgprot)
76 {
77 	return mk_pte(page, pgprot);
78 }
79 
80 static inline int huge_pte_none(pte_t pte)
81 {
82 	return pte_none(pte);
83 }
84 
85 static inline int huge_pte_write(pte_t pte)
86 {
87 	return pte_write(pte);
88 }
89 
90 static inline int huge_pte_dirty(pte_t pte)
91 {
92 	return pte_dirty(pte);
93 }
94 
95 static inline pte_t huge_pte_mkwrite(pte_t pte)
96 {
97 	return pte_mkwrite(pte);
98 }
99 
100 static inline pte_t huge_pte_mkdirty(pte_t pte)
101 {
102 	return pte_mkdirty(pte);
103 }
104 
105 static inline pte_t huge_pte_wrprotect(pte_t pte)
106 {
107 	return pte_wrprotect(pte);
108 }
109 
110 static inline pte_t huge_pte_modify(pte_t pte, pgprot_t newprot)
111 {
112 	return pte_modify(pte, newprot);
113 }
114 
115 #ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE
116 static inline bool gigantic_page_supported(void) { return true; }
117 #endif
118 #endif /* _ASM_S390_HUGETLB_H */
119