blob: 1c4e247c51fd7a711bb8070b0e97d4a6f2b5c196 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_PGTABLE_64_H
2#define _ASM_X86_PGTABLE_64_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
Randy Dunlap6df95fd2007-05-08 00:31:11 -07004#include <linux/const.h>
Vivek Goyal9d291e72007-05-02 19:27:06 +02005#ifndef __ASSEMBLY__
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007/*
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>
Jiri Slaby1977f032007-10-18 23:40:25 -070012#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/threads.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15extern pud_t level3_kernel_pgt[512];
Linus Torvalds1da177e2005-04-16 15:20:36 -070016extern pud_t level3_ident_pgt[512];
17extern pmd_t level2_kernel_pgt[512];
Jeremy Fitzhardinge084a2a42008-07-08 15:06:50 -070018extern pmd_t level2_fixmap_pgt[512];
19extern pmd_t level2_ident_pgt[512];
Linus Torvalds1da177e2005-04-16 15:20:36 -070020extern pgd_t init_level4_pgt[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvaldse3ebadd2007-05-07 08:44:24 -070022#define swapper_pg_dir init_level4_pgt
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024extern void paging_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Vivek Goyal9d291e72007-05-02 19:27:06 +020026#endif /* !__ASSEMBLY__ */
27
Jeremy Fitzhardinge85958b42008-03-17 16:37:14 -070028#define SHARED_KERNEL_PMD 0
Ingo Molnare4b71dc2008-01-30 13:34:04 +010029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030/*
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
Vivek Goyal9d291e72007-05-02 19:27:06 +020054#ifndef __ASSEMBLY__
55
Joe Perches7f944012008-03-23 01:03:11 -070056#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))
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080069struct mm_struct;
70
Eduardo Habkost0814e0b2008-06-25 00:19:22 -040071void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte);
72
73
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010074static inline void native_pte_clear(struct mm_struct *mm, unsigned long addr,
75 pte_t *ptep)
Zachary Amsden61e06032005-09-03 15:55:06 -070076{
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010077 *ptep = native_make_pte(0);
78}
79
80static inline void native_set_pte(pte_t *ptep, pte_t pte)
81{
82 *ptep = pte;
83}
84
Ingo Molnarb65e6392008-01-30 13:34:01 +010085static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
86{
87 native_set_pte(ptep, pte);
88}
89
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010090static 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
Joe Perches7f944012008-03-23 01:03:11 -070095 /* native_local_ptep_get_and_clear,
96 but duplicated because of cyclic dependency */
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +010097 pte_t ret = *xp;
98 native_pte_clear(NULL, 0, xp);
99 return ret;
100#endif
101}
102
103static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
104{
105 *pmdp = pmd;
106}
107
108static inline void native_pmd_clear(pmd_t *pmd)
109{
110 native_set_pmd(pmd, native_make_pmd(0));
111}
112
113static inline void native_set_pud(pud_t *pudp, pud_t pud)
114{
115 *pudp = pud;
116}
117
118static inline void native_pud_clear(pud_t *pud)
119{
120 native_set_pud(pud, native_make_pud(0));
121}
122
123static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
124{
125 *pgdp = pgd;
126}
127
Joe Perches7f944012008-03-23 01:03:11 -0700128static inline void native_pgd_clear(pgd_t *pgd)
Jeremy Fitzhardinge48916452008-01-30 13:32:58 +0100129{
130 native_set_pgd(pgd, native_make_pgd(0));
Zachary Amsden61e06032005-09-03 15:55:06 -0700131}
132
Vivek Goyal9d291e72007-05-02 19:27:06 +0200133#endif /* !__ASSEMBLY__ */
134
Joe Perches7f944012008-03-23 01:03:11 -0700135#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))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Ingo Molnarb6fd6f22008-12-16 19:23:36 +0100143#define MAXMEM _AC(__AC(1, UL) << MAX_PHYSMEM_BITS, UL)
Randy Dunlap63f65642007-05-08 00:31:14 -0700144#define VMALLOC_START _AC(0xffffc20000000000, UL)
145#define VMALLOC_END _AC(0xffffe1ffffffffff, UL)
Christoph Lameter0889eba2007-10-16 01:24:15 -0700146#define VMEMMAP_START _AC(0xffffe20000000000, UL)
Ingo Molnar85eb69a2008-02-21 12:50:51 +0100147#define MODULES_VADDR _AC(0xffffffffa0000000, UL)
Jan Beulich66d4bdf2008-07-31 16:48:31 +0100148#define MODULES_END _AC(0xffffffffff000000, UL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define MODULES_LEN (MODULES_END - MODULES_VADDR)
150
Vivek Goyal9d291e72007-05-02 19:27:06 +0200151#ifndef __ASSEMBLY__
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/*
159 * Level 4 access.
160 */
H. Peter Anvine00fc5422008-02-19 16:18:32 +0100161static inline int pgd_large(pgd_t pgd) { return 0; }
Eduardo Habkoste7a9b0b2008-06-25 00:19:05 -0400162#define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164/* PUD - Level3 access */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/* PMD - Level 2 access */
Joe Perches7f944012008-03-23 01:03:11 -0700167#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 })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#define PTE_FILE_MAX_BITS __PHYSICAL_MASK_SHIFT
171
172/* PTE - Level 1 access. */
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/* x86-64 always has all page tables mapped. */
Joe Perches7f944012008-03-23 01:03:11 -0700175#define pte_offset_map(dir, address) pte_offset_kernel((dir), (address))
176#define pte_offset_map_nested(dir, address) pte_offset_kernel((dir), (address))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define pte_unmap(pte) /* NOP */
Joe Perches7f944012008-03-23 01:03:11 -0700178#define pte_unmap_nested(pte) /* NOP */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Joe Perches7f944012008-03-23 01:03:11 -0700180#define update_mmu_cache(vma, address, pte) do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Ingo Molnar00d1c5e2008-04-17 17:40:45 +0200182extern int direct_gbpages;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* Encode and de-code a swap entry */
Jan Beulich17963162008-12-16 11:35:24 +0000185#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) })
Joe Perches7f944012008-03-23 01:03:11 -0700201#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val((pte)) })
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100202#define __swp_entry_to_pte(x) ((pte_t) { .pte = (x).val })
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Joe Perches7f944012008-03-23 01:03:11 -0700204extern int kern_addr_valid(unsigned long addr);
Thomas Gleixner31eedd82008-02-15 17:29:12 +0100205extern void cleanup_highmap(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207#define HAVE_ARCH_UNMAPPED_AREA
Jiri Kosinacc503c12008-01-30 13:31:07 +0100208#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210#define pgtable_cache_init() do { } while (0)
Linus Torvaldsda8f1532007-09-21 12:09:41 -0700211#define check_pgt_cache() do { } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
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)
Joe Perches7f944012008-03-23 01:03:11 -0700218#define kc_offset_to_vaddr(o) \
219 (((o) & (1UL << (__VIRTUAL_MASK_SHIFT - 1))) \
220 ? ((o) | ~__VIRTUAL_MASK) \
221 : (o))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define __HAVE_ARCH_PTE_SAME
Vivek Goyal9d291e72007-05-02 19:27:06 +0200224#endif /* !__ASSEMBLY__ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700226#endif /* _ASM_X86_PGTABLE_64_H */