This source file includes following definitions.
- __real_pte
- __rpte_to_hidx
- pte_set_hidx
- hash__remap_4k_pfn
- get_hpte_slot_array
- hpte_valid
- hpte_hash_index
- mark_hpte_slot_valid
- hash__pmd_trans_huge
- hash__pmd_same
- hash__pmd_mkhuge
- hash__pmd_mkdevmap
1
2 #ifndef _ASM_POWERPC_BOOK3S_64_HASH_64K_H
3 #define _ASM_POWERPC_BOOK3S_64_HASH_64K_H
4
5 #define H_PTE_INDEX_SIZE 8
6 #define H_PMD_INDEX_SIZE 10
7 #define H_PUD_INDEX_SIZE 10
8 #define H_PGD_INDEX_SIZE 8
9
10
11
12
13
14
15 #define MAX_EA_BITS_PER_CONTEXT 49
16 #define REGION_SHIFT MAX_EA_BITS_PER_CONTEXT
17
18
19
20
21 #define H_KERN_MAP_SIZE (1UL << MAX_EA_BITS_PER_CONTEXT)
22
23
24
25
26
27 #define H_KERN_VIRT_START ASM_CONST(0xc008000000000000)
28
29
30
31
32
33 #define H_PAGE_COMBO _RPAGE_RPN0
34 #define H_PAGE_4K_PFN _RPAGE_RPN1
35 #define H_PAGE_BUSY _RPAGE_RPN44
36 #define H_PAGE_HASHPTE _RPAGE_RPN43
37
38
39 #define H_PTE_PKEY_BIT0 _RPAGE_RSV1
40 #define H_PTE_PKEY_BIT1 _RPAGE_RSV2
41 #define H_PTE_PKEY_BIT2 _RPAGE_RSV3
42 #define H_PTE_PKEY_BIT3 _RPAGE_RSV4
43 #define H_PTE_PKEY_BIT4 _RPAGE_RSV5
44
45
46
47
48
49 #define H_PAGE_THP_HUGE H_PAGE_4K_PFN
50
51
52 #define _PAGE_HPTEFLAGS (H_PAGE_BUSY | H_PAGE_HASHPTE | H_PAGE_COMBO)
53
54
55
56
57
58
59 #define H_PTE_FRAG_SIZE_SHIFT (H_PTE_INDEX_SIZE + 3 + 1)
60 #define H_PTE_FRAG_NR (PAGE_SIZE >> H_PTE_FRAG_SIZE_SHIFT)
61
62 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE)
63 #define H_PMD_FRAG_SIZE_SHIFT (H_PMD_INDEX_SIZE + 3 + 1)
64 #else
65 #define H_PMD_FRAG_SIZE_SHIFT (H_PMD_INDEX_SIZE + 3)
66 #endif
67 #define H_PMD_FRAG_NR (PAGE_SIZE >> H_PMD_FRAG_SIZE_SHIFT)
68
69 #ifndef __ASSEMBLY__
70 #include <asm/errno.h>
71
72
73
74
75
76
77
78 #define __real_pte __real_pte
79 static inline real_pte_t __real_pte(pte_t pte, pte_t *ptep, int offset)
80 {
81 real_pte_t rpte;
82 unsigned long *hidxp;
83
84 rpte.pte = pte;
85
86
87
88
89
90
91 smp_rmb();
92
93 hidxp = (unsigned long *)(ptep + offset);
94 rpte.hidx = *hidxp;
95 return rpte;
96 }
97
98
99
100
101
102
103
104 #define HIDX_UNSHIFT_BY_ONE(x) ((x + 0xfUL) & 0xfUL)
105 #define HIDX_SHIFT_BY_ONE(x) ((x + 0x1UL) & 0xfUL)
106 #define HIDX_BITS(x, index) (x << (index << 2))
107 #define BITS_TO_HIDX(x, index) ((x >> (index << 2)) & 0xfUL)
108 #define INVALID_RPTE_HIDX 0x0UL
109
110 static inline unsigned long __rpte_to_hidx(real_pte_t rpte, unsigned long index)
111 {
112 return HIDX_UNSHIFT_BY_ONE(BITS_TO_HIDX(rpte.hidx, index));
113 }
114
115
116
117
118
119 static inline unsigned long pte_set_hidx(pte_t *ptep, real_pte_t rpte,
120 unsigned int subpg_index,
121 unsigned long hidx, int offset)
122 {
123 unsigned long *hidxp = (unsigned long *)(ptep + offset);
124
125 rpte.hidx &= ~HIDX_BITS(0xfUL, subpg_index);
126 *hidxp = rpte.hidx | HIDX_BITS(HIDX_SHIFT_BY_ONE(hidx), subpg_index);
127
128
129
130
131
132
133 smp_wmb();
134
135
136 return 0x0UL;
137 }
138
139 #define __rpte_to_pte(r) ((r).pte)
140 extern bool __rpte_sub_valid(real_pte_t rpte, unsigned long index);
141
142
143
144
145 #define pte_iterate_hashed_subpages(rpte, psize, vpn, index, shift) \
146 do { \
147 unsigned long __end = vpn + (1UL << (PAGE_SHIFT - VPN_SHIFT)); \
148 unsigned __split = (psize == MMU_PAGE_4K || \
149 psize == MMU_PAGE_64K_AP); \
150 shift = mmu_psize_defs[psize].shift; \
151 for (index = 0; vpn < __end; index++, \
152 vpn += (1L << (shift - VPN_SHIFT))) { \
153 if (!__split || __rpte_sub_valid(rpte, index))
154
155 #define pte_iterate_hashed_end() } } while(0)
156
157 #define pte_pagesize_index(mm, addr, pte) \
158 (((pte) & H_PAGE_COMBO)? MMU_PAGE_4K: MMU_PAGE_64K)
159
160 extern int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
161 unsigned long pfn, unsigned long size, pgprot_t);
162 static inline int hash__remap_4k_pfn(struct vm_area_struct *vma, unsigned long addr,
163 unsigned long pfn, pgprot_t prot)
164 {
165 if (pfn > (PTE_RPN_MASK >> PAGE_SHIFT)) {
166 WARN(1, "remap_4k_pfn called with wrong pfn value\n");
167 return -EINVAL;
168 }
169 return remap_pfn_range(vma, addr, pfn, PAGE_SIZE,
170 __pgprot(pgprot_val(prot) | H_PAGE_4K_PFN));
171 }
172
173 #define H_PTE_TABLE_SIZE PTE_FRAG_SIZE
174 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined (CONFIG_HUGETLB_PAGE)
175 #define H_PMD_TABLE_SIZE ((sizeof(pmd_t) << PMD_INDEX_SIZE) + \
176 (sizeof(unsigned long) << PMD_INDEX_SIZE))
177 #else
178 #define H_PMD_TABLE_SIZE (sizeof(pmd_t) << PMD_INDEX_SIZE)
179 #endif
180 #ifdef CONFIG_HUGETLB_PAGE
181 #define H_PUD_TABLE_SIZE ((sizeof(pud_t) << PUD_INDEX_SIZE) + \
182 (sizeof(unsigned long) << PUD_INDEX_SIZE))
183 #else
184 #define H_PUD_TABLE_SIZE (sizeof(pud_t) << PUD_INDEX_SIZE)
185 #endif
186 #define H_PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)
187
188 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
189 static inline char *get_hpte_slot_array(pmd_t *pmdp)
190 {
191
192
193
194
195
196
197 smp_rmb();
198 return *(char **)(pmdp + PTRS_PER_PMD);
199
200
201 }
202
203
204
205
206
207
208
209
210
211
212
213
214 static inline unsigned int hpte_valid(unsigned char *hpte_slot_array, int index)
215 {
216 return hpte_slot_array[index] & 0x1;
217 }
218
219 static inline unsigned int hpte_hash_index(unsigned char *hpte_slot_array,
220 int index)
221 {
222 return hpte_slot_array[index] >> 1;
223 }
224
225 static inline void mark_hpte_slot_valid(unsigned char *hpte_slot_array,
226 unsigned int index, unsigned int hidx)
227 {
228 hpte_slot_array[index] = (hidx << 1) | 0x1;
229 }
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247 static inline int hash__pmd_trans_huge(pmd_t pmd)
248 {
249 return !!((pmd_val(pmd) & (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP)) ==
250 (_PAGE_PTE | H_PAGE_THP_HUGE));
251 }
252
253 static inline int hash__pmd_same(pmd_t pmd_a, pmd_t pmd_b)
254 {
255 return (((pmd_raw(pmd_a) ^ pmd_raw(pmd_b)) & ~cpu_to_be64(_PAGE_HPTEFLAGS)) == 0);
256 }
257
258 static inline pmd_t hash__pmd_mkhuge(pmd_t pmd)
259 {
260 return __pmd(pmd_val(pmd) | (_PAGE_PTE | H_PAGE_THP_HUGE));
261 }
262
263 extern unsigned long hash__pmd_hugepage_update(struct mm_struct *mm,
264 unsigned long addr, pmd_t *pmdp,
265 unsigned long clr, unsigned long set);
266 extern pmd_t hash__pmdp_collapse_flush(struct vm_area_struct *vma,
267 unsigned long address, pmd_t *pmdp);
268 extern void hash__pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp,
269 pgtable_t pgtable);
270 extern pgtable_t hash__pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp);
271 extern pmd_t hash__pmdp_huge_get_and_clear(struct mm_struct *mm,
272 unsigned long addr, pmd_t *pmdp);
273 extern int hash__has_transparent_hugepage(void);
274 #endif
275
276 static inline pmd_t hash__pmd_mkdevmap(pmd_t pmd)
277 {
278 return __pmd(pmd_val(pmd) | (_PAGE_PTE | H_PAGE_THP_HUGE | _PAGE_DEVMAP));
279 }
280
281 #endif
282
283 #endif