1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef _ASM_PGTABLE_H
22#define _ASM_PGTABLE_H
23
24
25
26
27#include <asm/page.h>
28#define __ARCH_USE_5LEVEL_HACK
29#include <asm-generic/pgtable-nopmd.h>
30
31
32extern unsigned long empty_zero_page;
33
34
35
36
37
38
39
40
41#include <asm/vm_mmu.h>
42
43
44
45
46
47#define _PAGE_READ __HVM_PTE_R
48#define _PAGE_WRITE __HVM_PTE_W
49#define _PAGE_EXECUTE __HVM_PTE_X
50#define _PAGE_USER __HVM_PTE_U
51
52
53
54
55
56
57
58
59#define _PAGE_PRESENT (1<<0)
60#define _PAGE_DIRTY (1<<1)
61#define _PAGE_ACCESSED (1<<2)
62
63
64
65
66
67
68#define _PAGE_VALID _PAGE_PRESENT
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84#define PGDIR_SHIFT 22
85#define PTRS_PER_PGD 1024
86
87#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
88#define PGDIR_MASK (~(PGDIR_SIZE-1))
89
90#ifdef CONFIG_PAGE_SIZE_4KB
91#define PTRS_PER_PTE 1024
92#endif
93
94#ifdef CONFIG_PAGE_SIZE_16KB
95#define PTRS_PER_PTE 256
96#endif
97
98#ifdef CONFIG_PAGE_SIZE_64KB
99#define PTRS_PER_PTE 64
100#endif
101
102#ifdef CONFIG_PAGE_SIZE_256KB
103#define PTRS_PER_PTE 16
104#endif
105
106#ifdef CONFIG_PAGE_SIZE_1MB
107#define PTRS_PER_PTE 4
108#endif
109
110
111#define pgd_ERROR(e) \
112 printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__,\
113 pgd_val(e))
114
115
116
117
118extern unsigned long _dflt_cache_att;
119
120#define PAGE_NONE __pgprot(_PAGE_PRESENT | _PAGE_USER | \
121 _dflt_cache_att)
122#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER | \
123 _PAGE_READ | _PAGE_EXECUTE | _dflt_cache_att)
124#define PAGE_COPY PAGE_READONLY
125#define PAGE_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
126 _PAGE_READ | _PAGE_EXECUTE | _dflt_cache_att)
127#define PAGE_COPY_EXEC PAGE_EXEC
128#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \
129 _PAGE_EXECUTE | _PAGE_WRITE | _dflt_cache_att)
130#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_READ | \
131 _PAGE_WRITE | _PAGE_EXECUTE | _dflt_cache_att)
132
133
134
135
136
137
138
139
140
141#define CACHEDEF (CACHE_DEFAULT << 6)
142
143
144#define __P000 __pgprot(_PAGE_PRESENT | _PAGE_USER | CACHEDEF)
145#define __P001 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | CACHEDEF)
146#define __P010 __P000
147#define __P011 __P001
148#define __P100 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
149 _PAGE_EXECUTE | CACHEDEF)
150#define __P101 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_EXECUTE | \
151 _PAGE_READ | CACHEDEF)
152#define __P110 __P100
153#define __P111 __P101
154
155
156#define __S000 __P000
157#define __S001 __P001
158#define __S010 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
159 _PAGE_WRITE | CACHEDEF)
160#define __S011 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \
161 _PAGE_WRITE | CACHEDEF)
162#define __S100 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
163 _PAGE_EXECUTE | CACHEDEF)
164#define __S101 __P101
165#define __S110 __pgprot(_PAGE_PRESENT | _PAGE_USER | \
166 _PAGE_EXECUTE | _PAGE_WRITE | CACHEDEF)
167#define __S111 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | \
168 _PAGE_EXECUTE | _PAGE_WRITE | CACHEDEF)
169
170extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
171
172
173#define FIRST_USER_ADDRESS 0UL
174#define pte_special(pte) 0
175#define pte_mkspecial(pte) (pte)
176
177
178#ifdef CONFIG_HUGETLB_PAGE
179#define pte_mkhuge(pte) __pte((pte_val(pte) & ~0x3) | HVM_HUGEPAGE_SIZE)
180#endif
181
182
183
184
185
186extern void sync_icache_dcache(pte_t pte);
187
188#define pte_present_exec_user(pte) \
189 ((pte_val(pte) & (_PAGE_EXECUTE | _PAGE_USER)) == \
190 (_PAGE_EXECUTE | _PAGE_USER))
191
192static inline void set_pte(pte_t *ptep, pte_t pteval)
193{
194
195 if (pte_present_exec_user(pteval))
196 sync_icache_dcache(pteval);
197
198 *ptep = pteval;
199}
200
201
202
203
204
205
206
207
208#define _NULL_PMD 0x7
209#define _NULL_PTE 0x0
210
211static inline void pmd_clear(pmd_t *pmd_entry_ptr)
212{
213 pmd_val(*pmd_entry_ptr) = _NULL_PMD;
214}
215
216
217
218
219static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
220 pte_t *ptep)
221{
222 pte_val(*ptep) = _NULL_PTE;
223}
224
225#ifdef NEED_PMD_INDEX_DESPITE_BEING_2_LEVEL
226
227
228
229
230#define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
231
232#endif
233
234
235
236
237
238
239
240#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
241
242
243
244
245#define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
246
247
248
249
250#define pgd_offset_k(address) pgd_offset(&init_mm, address)
251
252
253
254
255
256
257
258static inline int pmd_none(pmd_t pmd)
259{
260 return pmd_val(pmd) == _NULL_PMD;
261}
262
263
264
265
266
267
268
269static inline int pmd_present(pmd_t pmd)
270{
271 return pmd_val(pmd) != (unsigned long)_NULL_PMD;
272}
273
274
275
276
277
278
279static inline int pmd_bad(pmd_t pmd)
280{
281 return 0;
282}
283
284
285
286
287#define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
288#define pmd_pgtable(pmd) pmd_page(pmd)
289
290
291
292
293
294static inline int pte_none(pte_t pte)
295{
296 return pte_val(pte) == _NULL_PTE;
297};
298
299
300
301
302static inline int pte_present(pte_t pte)
303{
304 return pte_val(pte) & _PAGE_PRESENT;
305}
306
307
308#define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
309
310
311#define pte_page(x) pfn_to_page(pte_pfn(x))
312
313
314static inline pte_t pte_mkold(pte_t pte)
315{
316 pte_val(pte) &= ~_PAGE_ACCESSED;
317 return pte;
318}
319
320
321static inline pte_t pte_mkyoung(pte_t pte)
322{
323 pte_val(pte) |= _PAGE_ACCESSED;
324 return pte;
325}
326
327
328static inline pte_t pte_mkclean(pte_t pte)
329{
330 pte_val(pte) &= ~_PAGE_DIRTY;
331 return pte;
332}
333
334
335static inline pte_t pte_mkdirty(pte_t pte)
336{
337 pte_val(pte) |= _PAGE_DIRTY;
338 return pte;
339}
340
341
342static inline int pte_young(pte_t pte)
343{
344 return pte_val(pte) & _PAGE_ACCESSED;
345}
346
347
348static inline int pte_dirty(pte_t pte)
349{
350 return pte_val(pte) & _PAGE_DIRTY;
351}
352
353
354static inline pte_t pte_modify(pte_t pte, pgprot_t prot)
355{
356 pte_val(pte) &= PAGE_MASK;
357 pte_val(pte) |= pgprot_val(prot);
358 return pte;
359}
360
361
362static inline pte_t pte_wrprotect(pte_t pte)
363{
364 pte_val(pte) &= ~_PAGE_WRITE;
365 return pte;
366}
367
368
369static inline pte_t pte_mkwrite(pte_t pte)
370{
371 pte_val(pte) |= _PAGE_WRITE;
372 return pte;
373}
374
375
376static inline pte_t pte_mkexec(pte_t pte)
377{
378 pte_val(pte) |= _PAGE_EXECUTE;
379 return pte;
380}
381
382
383static inline int pte_read(pte_t pte)
384{
385 return pte_val(pte) & _PAGE_READ;
386}
387
388
389static inline int pte_write(pte_t pte)
390{
391 return pte_val(pte) & _PAGE_WRITE;
392}
393
394
395
396static inline int pte_exec(pte_t pte)
397{
398 return pte_val(pte) & _PAGE_EXECUTE;
399}
400
401
402#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
403
404
405#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
406
407
408#define pfn_pte(pfn, pgprot) __pte((pfn << PAGE_SHIFT) | pgprot_val(pgprot))
409
410
411#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
412#define set_pmd(pmdptr, pmdval) (*(pmdptr) = (pmdval))
413
414
415
416
417
418
419
420#define set_pte_at(mm, addr, ptep, pte) set_pte(ptep, pte)
421
422
423
424
425#define pte_unmap(pte) do { } while (0)
426#define pte_unmap_nested(pte) do { } while (0)
427
428
429
430
431
432#define pte_offset_map(dir, address) \
433 ((pte_t *)page_address(pmd_page(*(dir))) + __pte_offset(address))
434
435#define pte_offset_map_nested(pmd, addr) pte_offset_map(pmd, addr)
436
437
438#define pte_offset_kernel(dir, address) \
439 ((pte_t *) (unsigned long) __va(pmd_val(*dir) & PAGE_MASK) \
440 + __pte_offset(address))
441
442
443#define ZERO_PAGE(vaddr) (virt_to_page(&empty_zero_page))
444
445#define __pte_offset(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
446
447
448#define pgtable_cache_init() do { } while (0)
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472#define __swp_type(swp_pte) (((swp_pte).val >> 1) & 0x1f)
473
474#define __swp_offset(swp_pte) \
475 ((((swp_pte).val >> 6) & 0xf) | (((swp_pte).val >> 9) & 0x7ffff0))
476
477#define __swp_entry(type, offset) \
478 ((swp_entry_t) { \
479 ((type << 1) | \
480 ((offset & 0x7ffff0) << 9) | ((offset & 0xf) << 6)) })
481
482
483#include <asm-generic/pgtable.h>
484
485#endif
486