- Update Xen patches to 3.3-rc5 and c/s 1157.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / include / mach-xen / asm / pgtable_types.h
1 #ifndef _ASM_X86_PGTABLE_DEFS_H
2 #define _ASM_X86_PGTABLE_DEFS_H
3
4 #include <linux/const.h>
5 #include <asm/page_types.h>
6
7 #define FIRST_USER_ADDRESS      0
8
9 #define _PAGE_BIT_PRESENT       0       /* is present */
10 #define _PAGE_BIT_RW            1       /* writeable */
11 #define _PAGE_BIT_USER          2       /* userspace addressable */
12 #define _PAGE_BIT_PWT           3       /* page write through */
13 #define _PAGE_BIT_PCD           4       /* page cache disabled */
14 #define _PAGE_BIT_ACCESSED      5       /* was accessed (raised by CPU) */
15 #define _PAGE_BIT_DIRTY         6       /* was written to (raised by CPU) */
16 #define _PAGE_BIT_PSE           7       /* 4 MB (or 2MB) page */
17 #define _PAGE_BIT_PAT           7       /* on 4KB pages */
18 #define _PAGE_BIT_GLOBAL        8       /* Global TLB entry PPro+ */
19 #define _PAGE_BIT_UNUSED1       9       /* available for programmer */
20 #define _PAGE_BIT_IOMAP         10      /* flag used to indicate IO mapping */
21 #define _PAGE_BIT_HIDDEN        11      /* hidden by kmemcheck */
22 #define _PAGE_BIT_PAT_LARGE     12      /* On 2MB or 1GB pages */
23 #define _PAGE_BIT_SPECIAL       _PAGE_BIT_UNUSED1
24 #define _PAGE_BIT_CPA_TEST      _PAGE_BIT_UNUSED1
25 #define _PAGE_BIT_SPLITTING     _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
26 #define _PAGE_BIT_NX           63       /* No execute: only valid after cpuid check */
27
28 /* If _PAGE_BIT_PRESENT is clear, we use these: */
29 /* - if the user mapped it with PROT_NONE; pte_present gives true */
30 #define _PAGE_BIT_PROTNONE      _PAGE_BIT_GLOBAL
31 /* - set: nonlinear file mapping, saved PTE; unset:swap */
32 #define _PAGE_BIT_FILE          _PAGE_BIT_DIRTY
33
34 #define _PAGE_PRESENT   (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT)
35 #define _PAGE_RW        (_AT(pteval_t, 1) << _PAGE_BIT_RW)
36 #define _PAGE_USER      (_AT(pteval_t, 1) << _PAGE_BIT_USER)
37 #define _PAGE_PWT       (_AT(pteval_t, 1) << _PAGE_BIT_PWT)
38 #define _PAGE_PCD       (_AT(pteval_t, 1) << _PAGE_BIT_PCD)
39 #define _PAGE_ACCESSED  (_AT(pteval_t, 1) << _PAGE_BIT_ACCESSED)
40 #define _PAGE_DIRTY     (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
41 #define _PAGE_PSE       (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
42 #define _PAGE_GLOBAL    (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
43 #define _PAGE_UNUSED1   (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
44 #define _PAGE_IOMAP     (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
45 #define _PAGE_PAT       (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
46 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
47 #define _PAGE_SPECIAL   (_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
48 #define _PAGE_CPA_TEST  (_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
49 #define _PAGE_SPLITTING (_AT(pteval_t, 1) << _PAGE_BIT_SPLITTING)
50 #define __HAVE_ARCH_PTE_SPECIAL
51
52 #ifdef CONFIG_KMEMCHECK
53 #define _PAGE_HIDDEN    (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
54 #else
55 #define _PAGE_HIDDEN    (_AT(pteval_t, 0))
56 #endif
57
58 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
59 #define _PAGE_NX        (_AT(pteval_t, 1) << _PAGE_BIT_NX)
60 #else
61 #define _PAGE_NX        (_AT(pteval_t, 0))
62 #endif
63
64 #define _PAGE_FILE      (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
65 #define _PAGE_PROTNONE  (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)
66
67 #ifndef __ASSEMBLY__
68 #if defined(CONFIG_X86_64) && CONFIG_XEN_COMPAT <= 0x030002
69 extern unsigned int __kernel_page_user;
70 #else
71 #define __kernel_page_user 0
72 #endif
73 #endif
74
75 #define _PAGE_TABLE     (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER |        \
76                          _PAGE_ACCESSED | _PAGE_DIRTY)
77 #define _KERNPG_TABLE   (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED |    \
78                          _PAGE_DIRTY | __kernel_page_user)
79
80 /* Set of bits not changed in pte_modify */
81 #define _PAGE_CHG_MASK  (PTE_PFN_MASK | _PAGE_CACHE_MASK | _PAGE_IOMAP | \
82                          _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY)
83 #define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE)
84
85 /*
86  * PAT settings are part of the hypervisor interface, which sets the
87  * MSR to 0x050100070406 (i.e. WB, WT, UC-, UC, WC, WP [, UC, UC]).
88  */
89 #define _PAGE_CACHE_MASK        (_PAGE_PCD | _PAGE_PWT | _PAGE_PAT)
90 #define _PAGE_CACHE_WB          (0)
91 #define _PAGE_CACHE_WT          (_PAGE_PWT)
92 #define _PAGE_CACHE_WC          (_PAGE_PAT)
93 #define _PAGE_CACHE_WP          (_PAGE_PAT | _PAGE_PWT)
94 #define _PAGE_CACHE_UC_MINUS    (_PAGE_PCD)
95 #define _PAGE_CACHE_UC          (_PAGE_PCD | _PAGE_PWT)
96
97 #define PAGE_NONE       __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED)
98 #define PAGE_SHARED     __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \
99                                  _PAGE_ACCESSED | _PAGE_NX)
100
101 #define PAGE_SHARED_EXEC        __pgprot(_PAGE_PRESENT | _PAGE_RW |     \
102                                          _PAGE_USER | _PAGE_ACCESSED)
103 #define PAGE_COPY_NOEXEC        __pgprot(_PAGE_PRESENT | _PAGE_USER |   \
104                                          _PAGE_ACCESSED | _PAGE_NX)
105 #define PAGE_COPY_EXEC          __pgprot(_PAGE_PRESENT | _PAGE_USER |   \
106                                          _PAGE_ACCESSED)
107 #define PAGE_COPY               PAGE_COPY_NOEXEC
108 #define PAGE_READONLY           __pgprot(_PAGE_PRESENT | _PAGE_USER |   \
109                                          _PAGE_ACCESSED | _PAGE_NX)
110 #define PAGE_READONLY_EXEC      __pgprot(_PAGE_PRESENT | _PAGE_USER |   \
111                                          _PAGE_ACCESSED)
112
113 #define __PAGE_KERNEL_EXEC                                              \
114         (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | __kernel_page_user)
115 #define __PAGE_KERNEL           (__PAGE_KERNEL_EXEC | _PAGE_NX)
116
117 #define __PAGE_KERNEL_RO                (__PAGE_KERNEL & ~_PAGE_RW)
118 #define __PAGE_KERNEL_RX                (__PAGE_KERNEL_EXEC & ~_PAGE_RW)
119 #define __PAGE_KERNEL_EXEC_NOCACHE      (__PAGE_KERNEL_EXEC | _PAGE_PCD | _PAGE_PWT)
120 #define __PAGE_KERNEL_WC                (__PAGE_KERNEL | _PAGE_CACHE_WC)
121 #define __PAGE_KERNEL_NOCACHE           (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
122 #define __PAGE_KERNEL_UC_MINUS          (__PAGE_KERNEL | _PAGE_PCD)
123 #define __PAGE_KERNEL_VSYSCALL          (__PAGE_KERNEL_RX | _PAGE_USER)
124 #define __PAGE_KERNEL_VVAR              (__PAGE_KERNEL_RO | _PAGE_USER)
125 #define __PAGE_KERNEL_VVAR_NOCACHE      (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
126 #define __PAGE_KERNEL_LARGE             (__PAGE_KERNEL | _PAGE_PSE)
127 #define __PAGE_KERNEL_LARGE_NOCACHE     (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
128 #define __PAGE_KERNEL_LARGE_EXEC        (__PAGE_KERNEL_EXEC | _PAGE_PSE)
129
130 #define __PAGE_KERNEL_IO                (__PAGE_KERNEL | _PAGE_IOMAP)
131 #define __PAGE_KERNEL_IO_NOCACHE        (__PAGE_KERNEL_NOCACHE | _PAGE_IOMAP)
132 #define __PAGE_KERNEL_IO_UC_MINUS       (__PAGE_KERNEL_UC_MINUS | _PAGE_IOMAP)
133 #define __PAGE_KERNEL_IO_WC             (__PAGE_KERNEL_WC | _PAGE_IOMAP)
134
135 #define PAGE_KERNEL                     __pgprot(__PAGE_KERNEL)
136 #define PAGE_KERNEL_RO                  __pgprot(__PAGE_KERNEL_RO)
137 #define PAGE_KERNEL_EXEC                __pgprot(__PAGE_KERNEL_EXEC)
138 #define PAGE_KERNEL_RX                  __pgprot(__PAGE_KERNEL_RX)
139 #define PAGE_KERNEL_WC                  __pgprot(__PAGE_KERNEL_WC)
140 #define PAGE_KERNEL_NOCACHE             __pgprot(__PAGE_KERNEL_NOCACHE)
141 #define PAGE_KERNEL_UC_MINUS            __pgprot(__PAGE_KERNEL_UC_MINUS)
142 #define PAGE_KERNEL_EXEC_NOCACHE        __pgprot(__PAGE_KERNEL_EXEC_NOCACHE)
143 #define PAGE_KERNEL_LARGE               __pgprot(__PAGE_KERNEL_LARGE)
144 #define PAGE_KERNEL_LARGE_NOCACHE       __pgprot(__PAGE_KERNEL_LARGE_NOCACHE)
145 #define PAGE_KERNEL_LARGE_EXEC          __pgprot(__PAGE_KERNEL_LARGE_EXEC)
146 #define PAGE_KERNEL_VSYSCALL            __pgprot(__PAGE_KERNEL_VSYSCALL)
147 #define PAGE_KERNEL_VVAR                __pgprot(__PAGE_KERNEL_VVAR)
148 #define PAGE_KERNEL_VVAR_NOCACHE        __pgprot(__PAGE_KERNEL_VVAR_NOCACHE)
149
150 #define PAGE_KERNEL_IO                  __pgprot(__PAGE_KERNEL_IO)
151 #define PAGE_KERNEL_IO_NOCACHE          __pgprot(__PAGE_KERNEL_IO_NOCACHE)
152 #define PAGE_KERNEL_IO_UC_MINUS         __pgprot(__PAGE_KERNEL_IO_UC_MINUS)
153 #define PAGE_KERNEL_IO_WC               __pgprot(__PAGE_KERNEL_IO_WC)
154
155 /*         xwr */
156 #define __P000  PAGE_NONE
157 #define __P001  PAGE_READONLY
158 #define __P010  PAGE_COPY
159 #define __P011  PAGE_COPY
160 #define __P100  PAGE_READONLY_EXEC
161 #define __P101  PAGE_READONLY_EXEC
162 #define __P110  PAGE_COPY_EXEC
163 #define __P111  PAGE_COPY_EXEC
164
165 #define __S000  PAGE_NONE
166 #define __S001  PAGE_READONLY
167 #define __S010  PAGE_SHARED
168 #define __S011  PAGE_SHARED
169 #define __S100  PAGE_READONLY_EXEC
170 #define __S101  PAGE_READONLY_EXEC
171 #define __S110  PAGE_SHARED_EXEC
172 #define __S111  PAGE_SHARED_EXEC
173
174 /*
175  * early identity mapping  pte attrib macros.
176  */
177 #ifdef CONFIG_X86_64
178 #define __PAGE_KERNEL_IDENT_LARGE_EXEC  __PAGE_KERNEL_LARGE_EXEC
179 #else
180 /*
181  * For PDE_IDENT_ATTR include USER bit. As the PDE and PTE protection
182  * bits are combined, this will alow user to access the high address mapped
183  * VDSO in the presence of CONFIG_COMPAT_VDSO
184  */
185 #define PTE_IDENT_ATTR   0x003          /* PRESENT+RW */
186 #define PDE_IDENT_ATTR   0x067          /* PRESENT+RW+USER+DIRTY+ACCESSED */
187 #define PGD_IDENT_ATTR   0x001          /* PRESENT (no other attributes) */
188 #endif
189
190 #ifdef CONFIG_X86_32
191 # include <asm/pgtable_32_types.h>
192 #else
193 # include "pgtable_64_types.h"
194 #endif
195
196 #ifndef __ASSEMBLY__
197
198 #include <linux/types.h>
199
200 /* PTE_PFN_MASK extracts the PFN from a (pte|pmd|pud|pgd)val_t */
201 #define PTE_PFN_MASK            ((pteval_t)PHYSICAL_PAGE_MASK)
202
203 /* PTE_FLAGS_MASK extracts the flags from a (pte|pmd|pud|pgd)val_t */
204 #define PTE_FLAGS_MASK          (~PTE_PFN_MASK)
205
206 typedef struct pgprot { pgprotval_t pgprot; } pgprot_t;
207
208 #include <asm/maddr.h>
209
210 typedef struct { pgdval_t pgd; } pgd_t;
211
212 #define __pgd_ma(x) ((pgd_t) { (x) } )
213 static inline pgd_t xen_make_pgd(pgdval_t val)
214 {
215         if (likely(val & _PAGE_PRESENT))
216                 val = pte_phys_to_machine(val);
217         return (pgd_t) { val };
218 }
219
220 #define __pgd_val(x) ((x).pgd)
221 static inline pgdval_t xen_pgd_val(pgd_t pgd)
222 {
223         pgdval_t ret = __pgd_val(pgd);
224 #if PAGETABLE_LEVELS == 2 && CONFIG_XEN_COMPAT <= 0x030002
225         if (likely(ret))
226                 ret = machine_to_phys(ret) | _PAGE_PRESENT;
227 #else
228         if (likely(ret & _PAGE_PRESENT))
229                 ret = pte_machine_to_phys(ret);
230 #endif
231         return ret;
232 }
233
234 static inline pgdval_t pgd_flags(pgd_t pgd)
235 {
236         return __pgd_val(pgd) & PTE_FLAGS_MASK;
237 }
238
239 #if PAGETABLE_LEVELS > 3
240 typedef struct { pudval_t pud; } pud_t;
241
242 #define __pud_ma(x) ((pud_t) { (x) } )
243 static inline pud_t xen_make_pud(pudval_t val)
244 {
245         if (likely(val & _PAGE_PRESENT))
246                 val = pte_phys_to_machine(val);
247         return (pud_t) { val };
248 }
249
250 #define __pud_val(x) ((x).pud)
251 static inline pudval_t xen_pud_val(pud_t pud)
252 {
253         pudval_t ret = __pud_val(pud);
254         if (likely(ret & _PAGE_PRESENT))
255                 ret = pte_machine_to_phys(ret);
256         return ret;
257 }
258 #else
259 #include <asm-generic/pgtable-nopud.h>
260
261 #define __pud_val(x) __pgd_val((x).pgd)
262 static inline pudval_t xen_pud_val(pud_t pud)
263 {
264         return xen_pgd_val(pud.pgd);
265 }
266 #endif
267
268 #if PAGETABLE_LEVELS > 2
269 typedef struct { pmdval_t pmd; } pmd_t;
270
271 #define __pmd_ma(x)     ((pmd_t) { (x) } )
272 static inline pmd_t xen_make_pmd(pmdval_t val)
273 {
274         if (likely(val & _PAGE_PRESENT))
275                 val = pte_phys_to_machine(val);
276         return (pmd_t) { val };
277 }
278
279 #define __pmd_val(x) ((x).pmd)
280 static inline pmdval_t xen_pmd_val(pmd_t pmd)
281 {
282         pmdval_t ret = __pmd_val(pmd);
283 #if CONFIG_XEN_COMPAT <= 0x030002
284         if (likely(ret))
285                 ret = pte_machine_to_phys(ret) | _PAGE_PRESENT;
286 #else
287         if (likely(ret & _PAGE_PRESENT))
288                 ret = pte_machine_to_phys(ret);
289 #endif
290         return ret;
291 }
292 #else
293 #include <asm-generic/pgtable-nopmd.h>
294
295 #define __pmd_ma(x) ((pmd_t) { .pud.pgd = __pgd_ma(x) } )
296 #define __pmd_val(x) __pgd_val((x).pud.pgd)
297 static inline pmdval_t xen_pmd_val(pmd_t pmd)
298 {
299         return xen_pgd_val(pmd.pud.pgd);
300 }
301 #endif
302
303 static inline pudval_t pud_flags(pud_t pud)
304 {
305         return __pud_val(pud) & PTE_FLAGS_MASK;
306 }
307
308 static inline pmdval_t pmd_flags(pmd_t pmd)
309 {
310         return __pmd_val(pmd) & PTE_FLAGS_MASK;
311 }
312
313 #define __pte_ma(x) ((pte_t) { .pte = (x) } )
314 static inline pte_t xen_make_pte(pteval_t val)
315 {
316         if (likely((val & (_PAGE_PRESENT|_PAGE_IOMAP)) == _PAGE_PRESENT))
317                 val = pte_phys_to_machine(val);
318         return (pte_t) { .pte = val };
319 }
320
321 #define __pte_val(x) ((x).pte)
322 static inline pteval_t xen_pte_val(pte_t pte)
323 {
324         pteval_t ret = __pte_val(pte);
325         if (likely((pte.pte_low & (_PAGE_PRESENT|_PAGE_IOMAP)) == _PAGE_PRESENT))
326                 ret = pte_machine_to_phys(ret);
327         return ret;
328 }
329
330 static inline pteval_t pte_flags(pte_t pte)
331 {
332         return __pte_val(pte) & PTE_FLAGS_MASK;
333 }
334
335 #define pgprot_val(x)   ((x).pgprot)
336 #define __pgprot(x)     ((pgprot_t) { (x) } )
337
338
339 typedef struct page *pgtable_t;
340
341 extern pteval_t __supported_pte_mask;
342 extern void set_nx(void);
343 extern int nx_enabled;
344
345 #define pgprot_writecombine     pgprot_writecombine
346 extern pgprot_t pgprot_writecombine(pgprot_t prot);
347
348 #ifndef CONFIG_XEN
349 /* Indicate that x86 has its own track and untrack pfn vma functions */
350 #define __HAVE_PFNMAP_TRACKING
351 #endif
352
353 #define __HAVE_PHYS_MEM_ACCESS_PROT
354 struct file;
355 pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
356                               unsigned long size, pgprot_t vma_prot);
357 int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
358                               unsigned long size, pgprot_t *vma_prot);
359
360 /* Install a pte for a particular vaddr in kernel space. */
361 void set_pte_vaddr(unsigned long vaddr, pte_t pte);
362
363 extern void xen_pagetable_reserve(u64 start, u64 end);
364
365 struct seq_file;
366 extern void arch_report_meminfo(struct seq_file *m);
367
368 enum {
369         PG_LEVEL_NONE,
370         PG_LEVEL_4K,
371         PG_LEVEL_2M,
372         PG_LEVEL_1G,
373         PG_LEVEL_NUM
374 };
375
376 #ifdef CONFIG_PROC_FS
377 extern void update_page_count(int level, unsigned long pages);
378 #else
379 static inline void update_page_count(int level, unsigned long pages) { }
380 #endif
381
382 /*
383  * Helper function that returns the kernel pagetable entry controlling
384  * the virtual address 'address'. NULL means no pagetable entry present.
385  * NOTE: the return type is pte_t but if the pmd is PSE then we return it
386  * as a pte too.
387  */
388 extern pte_t *lookup_address(unsigned long address, unsigned int *level);
389
390 #endif  /* !__ASSEMBLY__ */
391
392 #endif /* _ASM_X86_PGTABLE_DEFS_H */