1 #ifndef _X86_64_PGTABLE_H
2 #define _X86_64_PGTABLE_H
4 #include <linux/const.h>
8 * This file contains the functions and defines necessary to modify and use
9 * the x86-64 page table tree.
11 #include <asm/processor.h>
12 #include <linux/bitops.h>
13 #include <linux/threads.h>
16 extern pud_t level3_kernel_pgt[512];
17 extern pud_t level3_ident_pgt[512];
18 extern pmd_t level2_kernel_pgt[512];
19 extern pgd_t init_level4_pgt[];
21 #define swapper_pg_dir init_level4_pgt
23 extern void paging_init(void);
25 #endif /* !__ASSEMBLY__ */
27 #define SHARED_KERNEL_PMD 0
30 * PGDIR_SHIFT determines what a top-level page table entry can map
32 #define PGDIR_SHIFT 39
33 #define PTRS_PER_PGD 512
39 #define PTRS_PER_PUD 512
42 * PMD_SHIFT determines the size of the area a middle-level
46 #define PTRS_PER_PMD 512
49 * entries per page directory level
51 #define PTRS_PER_PTE 512
55 #define pte_ERROR(e) \
56 printk("%s:%d: bad pte %p(%016lx).\n", \
57 __FILE__, __LINE__, &(e), pte_val(e))
58 #define pmd_ERROR(e) \
59 printk("%s:%d: bad pmd %p(%016lx).\n", \
60 __FILE__, __LINE__, &(e), pmd_val(e))
61 #define pud_ERROR(e) \
62 printk("%s:%d: bad pud %p(%016lx).\n", \
63 __FILE__, __LINE__, &(e), pud_val(e))
64 #define pgd_ERROR(e) \
65 printk("%s:%d: bad pgd %p(%016lx).\n", \
66 __FILE__, __LINE__, &(e), pgd_val(e))
68 #define pgd_none(x) (!pgd_val(x))
69 #define pud_none(x) (!pud_val(x))
73 static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
76 *ptep = native_make_pte(0);
79 static inline void native_set_pte(pte_t *ptep, pte_t pte)
84 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
86 native_set_pte(ptep, pte);
89 static inline pte_t native_ptep_get_and_clear(pte_t *xp)
92 return native_make_pte(xchg(&xp->pte, 0));
94 /* native_local_ptep_get_and_clear,
95 but duplicated because of cyclic dependency */
97 native_pte_clear(NULL, 0, xp);
102 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
107 static inline void native_pmd_clear(pmd_t *pmd)
109 native_set_pmd(pmd, native_make_pmd(0));
112 static inline void native_set_pud(pud_t *pudp, pud_t pud)
117 static inline void native_pud_clear(pud_t *pud)
119 native_set_pud(pud, native_make_pud(0));
122 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
127 static inline void native_pgd_clear(pgd_t *pgd)
129 native_set_pgd(pgd, native_make_pgd(0));
132 #define pte_same(a, b) ((a).pte == (b).pte)
134 #endif /* !__ASSEMBLY__ */
136 #define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
137 #define PMD_MASK (~(PMD_SIZE - 1))
138 #define PUD_SIZE (_AC(1, UL) << PUD_SHIFT)
139 #define PUD_MASK (~(PUD_SIZE - 1))
140 #define PGDIR_SIZE (_AC(1, UL) << PGDIR_SHIFT)
141 #define PGDIR_MASK (~(PGDIR_SIZE - 1))
144 #define MAXMEM _AC(0x00003fffffffffff, UL)
145 #define VMALLOC_START _AC(0xffffc20000000000, UL)
146 #define VMALLOC_END _AC(0xffffe1ffffffffff, UL)
147 #define VMEMMAP_START _AC(0xffffe20000000000, UL)
148 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
149 #define MODULES_END _AC(0xfffffffffff00000, UL)
150 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
154 static inline unsigned long pgd_bad(pgd_t pgd)
156 return pgd_val(pgd) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
159 static inline unsigned long pud_bad(pud_t pud)
161 return pud_val(pud) &
162 ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER | _PAGE_PSE | _PAGE_NX);
165 static inline unsigned long pmd_bad(pmd_t pmd)
167 return pmd_val(pmd) &
168 ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER | _PAGE_PSE | _PAGE_NX);
171 #define pte_none(x) (!pte_val((x)))
172 #define pte_present(x) (pte_val((x)) & (_PAGE_PRESENT | _PAGE_PROTNONE))
174 #define pages_to_mb(x) ((x) >> (20 - PAGE_SHIFT)) /* FIXME: is this right? */
175 #define pte_page(x) pfn_to_page(pte_pfn((x)))
176 #define pte_pfn(x) ((pte_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
179 * Macro to mark a page protection value as "uncacheable".
181 #define pgprot_noncached(prot) \
182 (__pgprot(pgprot_val((prot)) | _PAGE_PCD | _PAGE_PWT))
185 * Conversion functions: convert a page and protection to a page entry,
186 * and a page entry and page directory to the page they refer to.
192 #define pgd_page_vaddr(pgd) \
193 ((unsigned long)__va((unsigned long)pgd_val((pgd)) & PTE_MASK))
194 #define pgd_page(pgd) (pfn_to_page(pgd_val((pgd)) >> PAGE_SHIFT))
195 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
196 #define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
197 #define pgd_offset_k(address) (init_level4_pgt + pgd_index((address)))
198 #define pgd_present(pgd) (pgd_val(pgd) & _PAGE_PRESENT)
199 static inline int pgd_large(pgd_t pgd) { return 0; }
200 #define mk_kernel_pgd(address) ((pgd_t){ (address) | _KERNPG_TABLE })
202 /* PUD - Level3 access */
203 /* to find an entry in a page-table-directory. */
204 #define pud_page_vaddr(pud) \
205 ((unsigned long)__va(pud_val((pud)) & PHYSICAL_PAGE_MASK))
206 #define pud_page(pud) (pfn_to_page(pud_val((pud)) >> PAGE_SHIFT))
207 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD - 1))
208 #define pud_offset(pgd, address) \
209 ((pud_t *)pgd_page_vaddr(*(pgd)) + pud_index((address)))
210 #define pud_present(pud) (pud_val((pud)) & _PAGE_PRESENT)
212 static inline int pud_large(pud_t pte)
214 return (pud_val(pte) & (_PAGE_PSE | _PAGE_PRESENT)) ==
215 (_PAGE_PSE | _PAGE_PRESENT);
218 /* PMD - Level 2 access */
219 #define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val((pmd)) & PTE_MASK))
220 #define pmd_page(pmd) (pfn_to_page(pmd_val((pmd)) >> PAGE_SHIFT))
222 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
223 #define pmd_offset(dir, address) ((pmd_t *)pud_page_vaddr(*(dir)) + \
225 #define pmd_none(x) (!pmd_val((x)))
226 #define pmd_present(x) (pmd_val((x)) & _PAGE_PRESENT)
227 #define pfn_pmd(nr, prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val((prot))))
228 #define pmd_pfn(x) ((pmd_val((x)) & __PHYSICAL_MASK) >> PAGE_SHIFT)
230 #define pte_to_pgoff(pte) ((pte_val((pte)) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
231 #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) | \
233 #define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
235 /* PTE - Level 1 access. */
237 /* page, protection -> pte */
238 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn((page)), (pgprot))
240 #define pte_index(address) (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
241 #define pte_offset_kernel(dir, address) ((pte_t *) pmd_page_vaddr(*(dir)) + \
242 pte_index((address)))
244 /* x86-64 always has all page tables mapped. */
245 #define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
246 #define pte_offset_map_nested(dir, address) pte_offset_kernel((dir), (address))
247 #define pte_unmap(pte) /* NOP */
248 #define pte_unmap_nested(pte) /* NOP */
250 #define update_mmu_cache(vma, address, pte) do { } while (0)
252 extern int direct_gbpages;
254 /* Encode and de-code a swap entry */
255 #define __swp_type(x) (((x).val >> 1) & 0x3f)
256 #define __swp_offset(x) ((x).val >> 8)
257 #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | \
259 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
260 #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
262 extern int kern_addr_valid(unsigned long addr);
263 extern void cleanup_highmap(void);
265 #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
266 remap_pfn_range(vma, vaddr, pfn, size, prot)
268 #define HAVE_ARCH_UNMAPPED_AREA
269 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
271 #define pgtable_cache_init() do { } while (0)
272 #define check_pgt_cache() do { } while (0)
274 #define PAGE_AGP PAGE_KERNEL_NOCACHE
275 #define HAVE_PAGE_AGP 1
277 /* fs/proc/kcore.c */
278 #define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
279 #define kc_offset_to_vaddr(o) \
280 (((o) & (1UL << (__VIRTUAL_MASK_SHIFT - 1))) \
281 ? ((o) | ~__VIRTUAL_MASK) \
284 #define __HAVE_ARCH_PTE_SAME
285 #endif /* !__ASSEMBLY__ */
287 #endif /* _X86_64_PGTABLE_H */