x86: clean up arch/x86/mm/pageattr.c
[wrt350n-kernel.git] / include / asm-x86 / pgtable_64.h
blobfaa6a96c2a5c21f5a287dae838b4f0078a382aff
1 #ifndef _X86_64_PGTABLE_H
2 #define _X86_64_PGTABLE_H
4 #include <linux/const.h>
5 #ifndef __ASSEMBLY__
7 /*
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>
14 #include <asm/pda.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);
24 extern void clear_kernel_mapping(unsigned long addr, unsigned long size);
26 #endif /* !__ASSEMBLY__ */
28 #define SHARED_KERNEL_PMD 1
31 * PGDIR_SHIFT determines what a top-level page table entry can map
33 #define PGDIR_SHIFT 39
34 #define PTRS_PER_PGD 512
37 * 3rd level page
39 #define PUD_SHIFT 30
40 #define PTRS_PER_PUD 512
43 * PMD_SHIFT determines the size of the area a middle-level
44 * page table can map
46 #define PMD_SHIFT 21
47 #define PTRS_PER_PMD 512
50 * entries per page directory level
52 #define PTRS_PER_PTE 512
54 #ifndef __ASSEMBLY__
56 #define pte_ERROR(e) \
57 printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), pte_val(e))
58 #define pmd_ERROR(e) \
59 printk("%s:%d: bad pmd %p(%016lx).\n", __FILE__, __LINE__, &(e), pmd_val(e))
60 #define pud_ERROR(e) \
61 printk("%s:%d: bad pud %p(%016lx).\n", __FILE__, __LINE__, &(e), pud_val(e))
62 #define pgd_ERROR(e) \
63 printk("%s:%d: bad pgd %p(%016lx).\n", __FILE__, __LINE__, &(e), pgd_val(e))
65 #define pgd_none(x) (!pgd_val(x))
66 #define pud_none(x) (!pud_val(x))
68 struct mm_struct;
70 static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
71 pte_t *ptep)
73 *ptep = native_make_pte(0);
76 static inline void native_set_pte(pte_t *ptep, pte_t pte)
78 *ptep = pte;
81 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
83 native_set_pte(ptep, pte);
86 static inline pte_t native_ptep_get_and_clear(pte_t *xp)
88 #ifdef CONFIG_SMP
89 return native_make_pte(xchg(&xp->pte, 0));
90 #else
91 /* native_local_ptep_get_and_clear, but duplicated because of cyclic dependency */
92 pte_t ret = *xp;
93 native_pte_clear(NULL, 0, xp);
94 return ret;
95 #endif
98 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
100 *pmdp = pmd;
103 static inline void native_pmd_clear(pmd_t *pmd)
105 native_set_pmd(pmd, native_make_pmd(0));
108 static inline void native_set_pud(pud_t *pudp, pud_t pud)
110 *pudp = pud;
113 static inline void native_pud_clear(pud_t *pud)
115 native_set_pud(pud, native_make_pud(0));
118 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
120 *pgdp = pgd;
123 static inline void native_pgd_clear(pgd_t * pgd)
125 native_set_pgd(pgd, native_make_pgd(0));
128 #define pte_same(a, b) ((a).pte == (b).pte)
130 #endif /* !__ASSEMBLY__ */
132 #define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
133 #define PMD_MASK (~(PMD_SIZE-1))
134 #define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
135 #define PUD_MASK (~(PUD_SIZE-1))
136 #define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
137 #define PGDIR_MASK (~(PGDIR_SIZE-1))
140 #define MAXMEM _AC(0x3fffffffffff, UL)
141 #define VMALLOC_START _AC(0xffffc20000000000, UL)
142 #define VMALLOC_END _AC(0xffffe1ffffffffff, UL)
143 #define VMEMMAP_START _AC(0xffffe20000000000, UL)
144 #define MODULES_VADDR _AC(0xffffffff88000000, UL)
145 #define MODULES_END _AC(0xfffffffffff00000, UL)
146 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
148 #ifndef __ASSEMBLY__
150 static inline unsigned long pgd_bad(pgd_t pgd)
152 return pgd_val(pgd) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
155 static inline unsigned long pud_bad(pud_t pud)
157 return pud_val(pud) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
160 static inline unsigned long pmd_bad(pmd_t pmd)
162 return pmd_val(pmd) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
165 #define pte_none(x) (!pte_val(x))
166 #define pte_present(x) (pte_val(x) & (_PAGE_PRESENT | _PAGE_PROTNONE))
168 #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT)) /* FIXME: is this right? */
169 #define pte_page(x) pfn_to_page(pte_pfn(x))
170 #define pte_pfn(x) ((pte_val(x) & __PHYSICAL_MASK) >> PAGE_SHIFT)
173 * Macro to mark a page protection value as "uncacheable".
175 #define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) | _PAGE_PCD | _PAGE_PWT))
179 * Conversion functions: convert a page and protection to a page entry,
180 * and a page entry and page directory to the page they refer to.
184 * Level 4 access.
186 #define pgd_page_vaddr(pgd) ((unsigned long) __va((unsigned long)pgd_val(pgd) & PTE_MASK))
187 #define pgd_page(pgd) (pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT))
188 #define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD-1))
189 #define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
190 #define pgd_offset_k(address) (init_level4_pgt + pgd_index(address))
191 #define pgd_present(pgd) (pgd_val(pgd) & _PAGE_PRESENT)
192 #define mk_kernel_pgd(address) ((pgd_t){ (address) | _KERNPG_TABLE })
194 /* PUD - Level3 access */
195 /* to find an entry in a page-table-directory. */
196 #define pud_page_vaddr(pud) ((unsigned long) __va(pud_val(pud) & PHYSICAL_PAGE_MASK))
197 #define pud_page(pud) (pfn_to_page(pud_val(pud) >> PAGE_SHIFT))
198 #define pud_index(address) (((address) >> PUD_SHIFT) & (PTRS_PER_PUD-1))
199 #define pud_offset(pgd, address) ((pud_t *) pgd_page_vaddr(*(pgd)) + pud_index(address))
200 #define pud_present(pud) (pud_val(pud) & _PAGE_PRESENT)
202 /* PMD - Level 2 access */
203 #define pmd_page_vaddr(pmd) ((unsigned long) __va(pmd_val(pmd) & PTE_MASK))
204 #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
206 #define pmd_index(address) (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1))
207 #define pmd_offset(dir, address) ((pmd_t *) pud_page_vaddr(*(dir)) + \
208 pmd_index(address))
209 #define pmd_none(x) (!pmd_val(x))
210 #define pmd_present(x) (pmd_val(x) & _PAGE_PRESENT)
211 #define pfn_pmd(nr,prot) (__pmd(((nr) << PAGE_SHIFT) | pgprot_val(prot)))
212 #define pmd_pfn(x) ((pmd_val(x) & __PHYSICAL_MASK) >> PAGE_SHIFT)
214 #define pte_to_pgoff(pte) ((pte_val(pte) & PHYSICAL_PAGE_MASK) >> PAGE_SHIFT)
215 #define pgoff_to_pte(off) ((pte_t) { .pte = ((off) << PAGE_SHIFT) | _PAGE_FILE })
216 #define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
218 /* PTE - Level 1 access. */
220 /* page, protection -> pte */
221 #define mk_pte(page, pgprot) pfn_pte(page_to_pfn(page), (pgprot))
223 #define pte_index(address) \
224 (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
225 #define pte_offset_kernel(dir, address) ((pte_t *) pmd_page_vaddr(*(dir)) + \
226 pte_index(address))
228 /* x86-64 always has all page tables mapped. */
229 #define pte_offset_map(dir,address) pte_offset_kernel(dir,address)
230 #define pte_offset_map_nested(dir,address) pte_offset_kernel(dir,address)
231 #define pte_unmap(pte) /* NOP */
232 #define pte_unmap_nested(pte) /* NOP */
234 #define update_mmu_cache(vma,address,pte) do { } while (0)
236 /* Encode and de-code a swap entry */
237 #define __swp_type(x) (((x).val >> 1) & 0x3f)
238 #define __swp_offset(x) ((x).val >> 8)
239 #define __swp_entry(type, offset) ((swp_entry_t) { ((type) << 1) | ((offset) << 8) })
240 #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
241 #define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
243 extern spinlock_t pgd_lock;
244 extern struct list_head pgd_list;
246 extern int kern_addr_valid(unsigned long addr);
248 pte_t *lookup_address(unsigned long addr, int *level);
250 #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
251 remap_pfn_range(vma, vaddr, pfn, size, prot)
253 #define HAVE_ARCH_UNMAPPED_AREA
254 #define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
256 #define pgtable_cache_init() do { } while (0)
257 #define check_pgt_cache() do { } while (0)
259 #define PAGE_AGP PAGE_KERNEL_NOCACHE
260 #define HAVE_PAGE_AGP 1
262 /* fs/proc/kcore.c */
263 #define kc_vaddr_to_offset(v) ((v) & __VIRTUAL_MASK)
264 #define kc_offset_to_vaddr(o) \
265 (((o) & (1UL << (__VIRTUAL_MASK_SHIFT-1))) ? ((o) | (~__VIRTUAL_MASK)) : (o))
267 #define __HAVE_ARCH_PTE_SAME
268 #endif /* !__ASSEMBLY__ */
270 #endif /* _X86_64_PGTABLE_H */