Merge branches 'x86/acpi', 'x86/asm', 'x86/cpudetect', 'x86/crashdump', 'x86/debug...
[sfrench/cifs-2.6.git] / arch / x86 / include / asm / pgtable_64.h
1 #ifndef _ASM_X86_PGTABLE_64_H
2 #define _ASM_X86_PGTABLE_64_H
3
4 #include <linux/const.h>
5 #ifndef __ASSEMBLY__
6
7 /*
8  * This file contains the functions and defines necessary to modify and use
9  * the x86-64 page table tree.
10  */
11 #include <asm/processor.h>
12 #include <linux/bitops.h>
13 #include <linux/threads.h>
14
15 extern pud_t level3_kernel_pgt[512];
16 extern pud_t level3_ident_pgt[512];
17 extern pmd_t level2_kernel_pgt[512];
18 extern pmd_t level2_fixmap_pgt[512];
19 extern pmd_t level2_ident_pgt[512];
20 extern pgd_t init_level4_pgt[];
21
22 #define swapper_pg_dir init_level4_pgt
23
24 extern void paging_init(void);
25
26 #endif /* !__ASSEMBLY__ */
27
28 #define SHARED_KERNEL_PMD       0
29
30 /*
31  * PGDIR_SHIFT determines what a top-level page table entry can map
32  */
33 #define PGDIR_SHIFT     39
34 #define PTRS_PER_PGD    512
35
36 /*
37  * 3rd level page
38  */
39 #define PUD_SHIFT       30
40 #define PTRS_PER_PUD    512
41
42 /*
43  * PMD_SHIFT determines the size of the area a middle-level
44  * page table can map
45  */
46 #define PMD_SHIFT       21
47 #define PTRS_PER_PMD    512
48
49 /*
50  * entries per page directory level
51  */
52 #define PTRS_PER_PTE    512
53
54 #ifndef __ASSEMBLY__
55
56 #define pte_ERROR(e)                                    \
57         printk("%s:%d: bad pte %p(%016lx).\n",          \
58                __FILE__, __LINE__, &(e), pte_val(e))
59 #define pmd_ERROR(e)                                    \
60         printk("%s:%d: bad pmd %p(%016lx).\n",          \
61                __FILE__, __LINE__, &(e), pmd_val(e))
62 #define pud_ERROR(e)                                    \
63         printk("%s:%d: bad pud %p(%016lx).\n",          \
64                __FILE__, __LINE__, &(e), pud_val(e))
65 #define pgd_ERROR(e)                                    \
66         printk("%s:%d: bad pgd %p(%016lx).\n",          \
67                __FILE__, __LINE__, &(e), pgd_val(e))
68
69 struct mm_struct;
70
71 void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
72
73
74 static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
75                                     pte_t *ptep)
76 {
77         *ptep = native_make_pte(0);
78 }
79
80 static inline void native_set_pte(pte_t *ptep, pte_t pte)
81 {
82         *ptep = pte;
83 }
84
85 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
86 {
87         native_set_pte(ptep, pte);
88 }
89
90 static inline pte_t native_ptep_get_and_clear(pte_t *xp)
91 {
92 #ifdef CONFIG_SMP
93         return native_make_pte(xchg(&xp->pte, 0));
94 #else
95         /* native_local_ptep_get_and_clear,
96            but duplicated because of cyclic dependency */
97         pte_t ret = *xp;
98         native_pte_clear(NULL, 0, xp);
99         return ret;
100 #endif
101 }
102
103 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
104 {
105         *pmdp = pmd;
106 }
107
108 static inline void native_pmd_clear(pmd_t *pmd)
109 {
110         native_set_pmd(pmd, native_make_pmd(0));
111 }
112
113 static inline void native_set_pud(pud_t *pudp, pud_t pud)
114 {
115         *pudp = pud;
116 }
117
118 static inline void native_pud_clear(pud_t *pud)
119 {
120         native_set_pud(pud, native_make_pud(0));
121 }
122
123 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
124 {
125         *pgdp = pgd;
126 }
127
128 static inline void native_pgd_clear(pgd_t *pgd)
129 {
130         native_set_pgd(pgd, native_make_pgd(0));
131 }
132
133 #endif /* !__ASSEMBLY__ */
134
135 #define PMD_SIZE        (_AC(1, UL) << PMD_SHIFT)
136 #define PMD_MASK        (~(PMD_SIZE - 1))
137 #define PUD_SIZE        (_AC(1, UL) << PUD_SHIFT)
138 #define PUD_MASK        (~(PUD_SIZE - 1))
139 #define PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
140 #define PGDIR_MASK      (~(PGDIR_SIZE - 1))
141
142
143 #define MAXMEM           _AC(__AC(1, UL) << MAX_PHYSMEM_BITS, UL)
144 #define VMALLOC_START    _AC(0xffffc20000000000, UL)
145 #define VMALLOC_END      _AC(0xffffe1ffffffffff, UL)
146 #define VMEMMAP_START    _AC(0xffffe20000000000, UL)
147 #define MODULES_VADDR    _AC(0xffffffffa0000000, UL)
148 #define MODULES_END      _AC(0xffffffffff000000, UL)
149 #define MODULES_LEN   (MODULES_END - MODULES_VADDR)
150
151 #ifndef __ASSEMBLY__
152
153 /*
154  * Conversion functions: convert a page and protection to a page entry,
155  * and a page entry and page directory to the page they refer to.
156  */
157
158 /*
159  * Level 4 access.
160  */
161 static inline int pgd_large(pgd_t pgd) { return 0; }
162 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
163
164 /* PUD - Level3 access */
165
166 /* PMD  - Level 2 access */
167 #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
168 #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) |     \
169                                             _PAGE_FILE })
170 #define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
171
172 /* PTE - Level 1 access. */
173
174 /* x86-64 always has all page tables mapped. */
175 #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
176 #define pte_offset_map_nested(dir, address) pte_offset_kernel((dir), (address))
177 #define pte_unmap(pte) /* NOP */
178 #define pte_unmap_nested(pte) /* NOP */
179
180 #define update_mmu_cache(vma, address, pte) do { } while (0)
181
182 extern int direct_gbpages;
183
184 /* Encode and de-code a swap entry */
185 #if _PAGE_BIT_FILE < _PAGE_BIT_PROTNONE
186 #define SWP_TYPE_BITS (_PAGE_BIT_FILE - _PAGE_BIT_PRESENT - 1)
187 #define SWP_OFFSET_SHIFT (_PAGE_BIT_PROTNONE + 1)
188 #else
189 #define SWP_TYPE_BITS (_PAGE_BIT_PROTNONE - _PAGE_BIT_PRESENT - 1)
190 #define SWP_OFFSET_SHIFT (_PAGE_BIT_FILE + 1)
191 #endif
192
193 #define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS)
194
195 #define __swp_type(x)                   (((x).val >> (_PAGE_BIT_PRESENT + 1)) \
196                                          & ((1U << SWP_TYPE_BITS) - 1))
197 #define __swp_offset(x)                 ((x).val >> SWP_OFFSET_SHIFT)
198 #define __swp_entry(type, offset)       ((swp_entry_t) { \
199                                          ((type) << (_PAGE_BIT_PRESENT + 1)) \
200                                          | ((offset) << SWP_OFFSET_SHIFT) })
201 #define __pte_to_swp_entry(pte)         ((swp_entry_t) { pte_val((pte)) })
202 #define __swp_entry_to_pte(x)           ((pte_t) { .pte = (x).val })
203
204 extern int kern_addr_valid(unsigned long addr);
205 extern void cleanup_highmap(void);
206
207 #define HAVE_ARCH_UNMAPPED_AREA
208 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
209
210 #define pgtable_cache_init()   do { } while (0)
211 #define check_pgt_cache()      do { } while (0)
212
213 #define PAGE_AGP    PAGE_KERNEL_NOCACHE
214 #define HAVE_PAGE_AGP 1
215
216 /* fs/proc/kcore.c */
217 #define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
218 #define kc_offset_to_vaddr(o)                           \
219         (((o) & (1UL << (__VIRTUAL_MASK_SHIFT - 1)))    \
220          ? ((o) | ~__VIRTUAL_MASK)                      \
221          : (o))
222
223 #define __HAVE_ARCH_PTE_SAME
224 #endif /* !__ASSEMBLY__ */
225
226 #endif /* _ASM_X86_PGTABLE_64_H */