Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 1 | #ifndef _ASM_X86_PAGE_H |
| 2 | #define _ASM_X86_PAGE_H |
| 3 | |
| 4 | #include <linux/const.h> |
| 5 | |
| 6 | /* PAGE_SHIFT determines the page size */ |
| 7 | #define PAGE_SHIFT 12 |
| 8 | #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT) |
| 9 | #define PAGE_MASK (~(PAGE_SIZE-1)) |
| 10 | |
| 11 | #define PHYSICAL_PAGE_MASK (PAGE_MASK & __PHYSICAL_MASK) |
Ingo Molnar | 3da1bcc | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 12 | #define PTE_MASK PHYSICAL_PAGE_MASK |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 13 | |
| 14 | #define LARGE_PAGE_SIZE (_AC(1,UL) << PMD_SHIFT) |
| 15 | #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1)) |
| 16 | |
| 17 | #define HPAGE_SHIFT PMD_SHIFT |
| 18 | #define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT) |
| 19 | #define HPAGE_MASK (~(HPAGE_SIZE - 1)) |
| 20 | #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) |
| 21 | |
| 22 | /* to align the pointer to the (next) page boundary */ |
| 23 | #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK) |
| 24 | |
Ingo Molnar | 6724a1d | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 25 | #define __PHYSICAL_MASK _AT(phys_addr_t, (_AC(1,ULL) << __PHYSICAL_MASK_SHIFT) - 1) |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 26 | #define __VIRTUAL_MASK ((_AC(1,UL) << __VIRTUAL_MASK_SHIFT) - 1) |
| 27 | |
Ingo Molnar | 3da1bcc | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 28 | #ifndef __ASSEMBLY__ |
| 29 | #include <linux/types.h> |
| 30 | #endif |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 31 | |
| 32 | #ifdef CONFIG_X86_64 |
Ingo Molnar | 3da1bcc | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 33 | #define PAGETABLE_LEVELS 4 |
| 34 | |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 35 | #define THREAD_ORDER 1 |
| 36 | #define THREAD_SIZE (PAGE_SIZE << THREAD_ORDER) |
| 37 | #define CURRENT_MASK (~(THREAD_SIZE-1)) |
| 38 | |
| 39 | #define EXCEPTION_STACK_ORDER 0 |
| 40 | #define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER) |
| 41 | |
| 42 | #define DEBUG_STACK_ORDER (EXCEPTION_STACK_ORDER + 1) |
| 43 | #define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER) |
| 44 | |
| 45 | #define IRQSTACK_ORDER 2 |
| 46 | #define IRQSTACKSIZE (PAGE_SIZE << IRQSTACK_ORDER) |
| 47 | |
| 48 | #define STACKFAULT_STACK 1 |
| 49 | #define DOUBLEFAULT_STACK 2 |
| 50 | #define NMI_STACK 3 |
| 51 | #define DEBUG_STACK 4 |
| 52 | #define MCE_STACK 5 |
| 53 | #define N_EXCEPTION_STACKS 5 /* hw limit: 7 */ |
| 54 | |
| 55 | #define __PAGE_OFFSET _AC(0xffff810000000000, UL) |
| 56 | |
| 57 | #define __PHYSICAL_START CONFIG_PHYSICAL_START |
| 58 | #define __KERNEL_ALIGN 0x200000 |
| 59 | |
| 60 | /* |
| 61 | * Make sure kernel is aligned to 2MB address. Catching it at compile |
| 62 | * time is better. Change your config file and compile the kernel |
| 63 | * for a 2MB aligned address (CONFIG_PHYSICAL_START) |
| 64 | */ |
| 65 | #if (CONFIG_PHYSICAL_START % __KERNEL_ALIGN) != 0 |
| 66 | #error "CONFIG_PHYSICAL_START must be a multiple of 2MB" |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 67 | #endif |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 68 | |
| 69 | #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START) |
| 70 | #define __START_KERNEL_map _AC(0xffffffff80000000, UL) |
| 71 | |
| 72 | /* See Documentation/x86_64/mm.txt for a description of the memory map. */ |
| 73 | #define __PHYSICAL_MASK_SHIFT 46 |
| 74 | #define __VIRTUAL_MASK_SHIFT 48 |
| 75 | |
| 76 | #define KERNEL_TEXT_SIZE (40*1024*1024) |
| 77 | #define KERNEL_TEXT_START _AC(0xffffffff80000000, UL) |
| 78 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 79 | #ifndef __ASSEMBLY__ |
| 80 | void clear_page(void *page); |
| 81 | void copy_page(void *to, void *from); |
Ingo Molnar | ba2b6c5 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 82 | |
Jeremy Fitzhardinge | 98fd5ae | 2008-01-30 13:32:43 +0100 | [diff] [blame^] | 83 | extern unsigned long __phys_addr(unsigned long); |
| 84 | #define __phys_reloc_hide(x) (x) |
| 85 | |
Ingo Molnar | ba2b6c5 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 86 | /* |
| 87 | * These are used to make use of C type-checking.. |
| 88 | */ |
| 89 | typedef unsigned long pteval_t; |
| 90 | typedef unsigned long pmdval_t; |
| 91 | typedef unsigned long pudval_t; |
| 92 | typedef unsigned long pgdval_t; |
| 93 | typedef unsigned long pgprotval_t; |
| 94 | typedef unsigned long phys_addr_t; |
| 95 | |
| 96 | typedef struct { pteval_t pte; } pte_t; |
| 97 | |
Ingo Molnar | d6e3cf6 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 98 | #define native_pte_val(x) ((x).pte) |
| 99 | #define native_make_pte(x) ((pte_t) { (x) } ) |
| 100 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 101 | #endif /* !__ASSEMBLY__ */ |
| 102 | |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 103 | #endif /* CONFIG_X86_64 */ |
| 104 | |
| 105 | #ifdef CONFIG_X86_32 |
| 106 | |
| 107 | /* |
| 108 | * This handles the memory map. |
| 109 | * |
| 110 | * A __PAGE_OFFSET of 0xC0000000 means that the kernel has |
| 111 | * a virtual address space of one gigabyte, which limits the |
| 112 | * amount of physical memory you can use to about 950MB. |
| 113 | * |
| 114 | * If you want more physical memory than this then see the CONFIG_HIGHMEM4G |
| 115 | * and CONFIG_HIGHMEM64G options in the kernel configuration. |
| 116 | */ |
| 117 | #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL) |
| 118 | |
| 119 | #ifdef CONFIG_X86_PAE |
| 120 | #define __PHYSICAL_MASK_SHIFT 36 |
| 121 | #define __VIRTUAL_MASK_SHIFT 32 |
Jeremy Fitzhardinge | 881d90d | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 122 | #define PAGETABLE_LEVELS 3 |
| 123 | |
| 124 | #ifndef __ASSEMBLY__ |
| 125 | typedef u64 pteval_t; |
| 126 | typedef u64 pmdval_t; |
| 127 | typedef u64 pudval_t; |
| 128 | typedef u64 pgdval_t; |
| 129 | typedef u64 pgprotval_t; |
| 130 | typedef u64 phys_addr_t; |
| 131 | |
| 132 | typedef struct { unsigned long pte_low, pte_high; } pte_t; |
| 133 | |
| 134 | static inline unsigned long long native_pte_val(pte_t pte) |
| 135 | { |
| 136 | return pte.pte_low | ((unsigned long long)pte.pte_high << 32); |
| 137 | } |
| 138 | |
| 139 | static inline pte_t native_make_pte(unsigned long long val) |
| 140 | { |
| 141 | return (pte_t) { .pte_low = val, .pte_high = (val >> 32) } ; |
| 142 | } |
| 143 | |
| 144 | #endif /* __ASSEMBLY__ |
| 145 | */ |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 146 | #else /* !CONFIG_X86_PAE */ |
| 147 | #define __PHYSICAL_MASK_SHIFT 32 |
| 148 | #define __VIRTUAL_MASK_SHIFT 32 |
Jeremy Fitzhardinge | 881d90d | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 149 | #define PAGETABLE_LEVELS 2 |
| 150 | |
| 151 | #ifndef __ASSEMBLY__ |
| 152 | typedef unsigned long pteval_t; |
| 153 | typedef unsigned long pmdval_t; |
| 154 | typedef unsigned long pudval_t; |
| 155 | typedef unsigned long pgdval_t; |
| 156 | typedef unsigned long pgprotval_t; |
| 157 | typedef unsigned long phys_addr_t; |
| 158 | |
| 159 | typedef struct { pteval_t pte_low; } pte_t; |
| 160 | typedef pte_t boot_pte_t; |
| 161 | |
| 162 | static inline unsigned long native_pte_val(pte_t pte) |
| 163 | { |
| 164 | return pte.pte_low; |
| 165 | } |
| 166 | |
| 167 | static inline pte_t native_make_pte(unsigned long val) |
| 168 | { |
| 169 | return (pte_t) { .pte_low = val }; |
| 170 | } |
| 171 | |
| 172 | #endif /* __ASSEMBLY__ */ |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 173 | #endif /* CONFIG_X86_PAE */ |
| 174 | |
| 175 | #ifdef CONFIG_HUGETLB_PAGE |
| 176 | #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA |
| 177 | #endif |
| 178 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 179 | #ifndef __ASSEMBLY__ |
Jeremy Fitzhardinge | 98fd5ae | 2008-01-30 13:32:43 +0100 | [diff] [blame^] | 180 | #define __phys_addr(x) ((x)-PAGE_OFFSET) |
| 181 | #define __phys_reloc_hide(x) RELOC_HIDE((x), 0) |
| 182 | |
| 183 | #ifdef CONFIG_FLATMEM |
| 184 | #define pfn_valid(pfn) ((pfn) < max_mapnr) |
| 185 | #endif /* CONFIG_FLATMEM */ |
| 186 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 187 | #ifdef CONFIG_X86_USE_3DNOW |
| 188 | #include <asm/mmx.h> |
| 189 | |
| 190 | static inline void clear_page(void *page) |
| 191 | { |
| 192 | mmx_clear_page(page); |
| 193 | } |
| 194 | |
| 195 | static inline void copy_page(void *to, void *from) |
| 196 | { |
| 197 | mmx_copy_page(to, from); |
| 198 | } |
| 199 | #else /* !CONFIG_X86_USE_3DNOW */ |
| 200 | #include <linux/string.h> |
| 201 | |
| 202 | static inline void clear_page(void *page) |
| 203 | { |
| 204 | memset(page, 0, PAGE_SIZE); |
| 205 | } |
| 206 | |
| 207 | static inline void copy_page(void *to, void *from) |
| 208 | { |
| 209 | memcpy(to, from, PAGE_SIZE); |
| 210 | } |
| 211 | #endif /* CONFIG_X86_3DNOW */ |
| 212 | #endif /* !__ASSEMBLY__ */ |
| 213 | |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 214 | #endif /* CONFIG_X86_32 */ |
| 215 | |
| 216 | #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) |
| 217 | |
| 218 | #define VM_DATA_DEFAULT_FLAGS \ |
| 219 | (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \ |
| 220 | VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) |
| 221 | |
| 222 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 223 | #ifndef __ASSEMBLY__ |
| 224 | struct page; |
| 225 | |
| 226 | static void inline clear_user_page(void *page, unsigned long vaddr, |
| 227 | struct page *pg) |
| 228 | { |
| 229 | clear_page(page); |
| 230 | } |
| 231 | |
| 232 | static void inline copy_user_page(void *to, void *from, unsigned long vaddr, |
| 233 | struct page *topage) |
| 234 | { |
| 235 | copy_page(to, from); |
| 236 | } |
| 237 | |
| 238 | #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \ |
| 239 | alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr) |
| 240 | #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE |
| 241 | |
Ingo Molnar | 38f0f12 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 242 | typedef struct { pgdval_t pgd; } pgd_t; |
| 243 | typedef struct { pgprotval_t pgprot; } pgprot_t; |
| 244 | |
| 245 | static inline pgd_t native_make_pgd(pgdval_t val) |
| 246 | { |
| 247 | return (pgd_t) { val }; |
| 248 | } |
| 249 | |
| 250 | static inline pgdval_t native_pgd_val(pgd_t pgd) |
| 251 | { |
| 252 | return pgd.pgd; |
| 253 | } |
| 254 | |
| 255 | #if PAGETABLE_LEVELS >= 3 |
| 256 | #if PAGETABLE_LEVELS == 4 |
| 257 | typedef struct { pudval_t pud; } pud_t; |
| 258 | |
| 259 | static inline pud_t native_make_pud(pmdval_t val) |
| 260 | { |
| 261 | return (pud_t) { val }; |
| 262 | } |
| 263 | |
| 264 | static inline pudval_t native_pud_val(pud_t pud) |
| 265 | { |
| 266 | return pud.pud; |
| 267 | } |
| 268 | #else /* PAGETABLE_LEVELS == 3 */ |
| 269 | #include <asm-generic/pgtable-nopud.h> |
| 270 | #endif /* PAGETABLE_LEVELS == 4 */ |
| 271 | |
| 272 | typedef struct { pmdval_t pmd; } pmd_t; |
| 273 | |
| 274 | static inline pmd_t native_make_pmd(pmdval_t val) |
| 275 | { |
| 276 | return (pmd_t) { val }; |
| 277 | } |
| 278 | |
| 279 | static inline pmdval_t native_pmd_val(pmd_t pmd) |
| 280 | { |
| 281 | return pmd.pmd; |
| 282 | } |
| 283 | #else /* PAGETABLE_LEVELS == 2 */ |
| 284 | #include <asm-generic/pgtable-nopmd.h> |
| 285 | #endif /* PAGETABLE_LEVELS >= 3 */ |
| 286 | |
| 287 | #define pgprot_val(x) ((x).pgprot) |
| 288 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 289 | |
| 290 | #ifdef CONFIG_PARAVIRT |
| 291 | #include <asm/paravirt.h> |
| 292 | #else /* !CONFIG_PARAVIRT */ |
| 293 | |
| 294 | #define pgd_val(x) native_pgd_val(x) |
| 295 | #define __pgd(x) native_make_pgd(x) |
| 296 | |
| 297 | #ifndef __PAGETABLE_PUD_FOLDED |
| 298 | #define pud_val(x) native_pud_val(x) |
| 299 | #define __pud(x) native_make_pud(x) |
| 300 | #endif |
| 301 | |
| 302 | #ifndef __PAGETABLE_PMD_FOLDED |
| 303 | #define pmd_val(x) native_pmd_val(x) |
| 304 | #define __pmd(x) native_make_pmd(x) |
| 305 | #endif |
| 306 | |
| 307 | #define pte_val(x) native_pte_val(x) |
| 308 | #define __pte(x) native_make_pte(x) |
| 309 | |
| 310 | #endif /* CONFIG_PARAVIRT */ |
| 311 | |
Jeremy Fitzhardinge | 98fd5ae | 2008-01-30 13:32:43 +0100 | [diff] [blame^] | 312 | #define __pa(x) __phys_addr((unsigned long)(x)) |
| 313 | /* __pa_symbol should be used for C visible symbols. |
| 314 | This seems to be the official gcc blessed way to do such arithmetic. */ |
| 315 | #define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x))) |
| 316 | |
| 317 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) |
| 318 | |
| 319 | #define __boot_va(x) __va(x) |
| 320 | #define __boot_pa(x) __pa(x) |
| 321 | |
| 322 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
| 323 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) |
| 324 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
| 325 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 326 | #endif /* __ASSEMBLY__ */ |
| 327 | |
| 328 | |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 329 | #ifdef CONFIG_X86_32 |
| 330 | # include "page_32.h" |
| 331 | #else |
| 332 | # include "page_64.h" |
| 333 | #endif |
| 334 | |
| 335 | #endif /* _ASM_X86_PAGE_H */ |