blob: 9830eeb571733e2a9600a1dfce804ef663ea16ae [file] [log] [blame]
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +01001#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 Molnar3da1bcc2008-01-30 13:32:42 +010012#define PTE_MASK PHYSICAL_PAGE_MASK
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010013
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 Molnar6724a1d2008-01-30 13:32:43 +010025#define __PHYSICAL_MASK _AT(phys_addr_t, (_AC(1,ULL) << __PHYSICAL_MASK_SHIFT) - 1)
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010026#define __VIRTUAL_MASK ((_AC(1,UL) << __VIRTUAL_MASK_SHIFT) - 1)
27
Ingo Molnar3da1bcc2008-01-30 13:32:42 +010028#ifndef __ASSEMBLY__
29#include <linux/types.h>
30#endif
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010031
32#ifdef CONFIG_X86_64
Ingo Molnar3da1bcc2008-01-30 13:32:42 +010033#define PAGETABLE_LEVELS 4
34
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010035#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 Gleixner96a388d2007-10-11 11:20:03 +020067#endif
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010068
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 Fitzhardinge345b9042008-01-30 13:32:42 +010079#ifndef __ASSEMBLY__
80void clear_page(void *page);
81void copy_page(void *to, void *from);
Ingo Molnarba2b6c52008-01-30 13:32:42 +010082
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +010083extern unsigned long __phys_addr(unsigned long);
84#define __phys_reloc_hide(x) (x)
85
Ingo Molnarba2b6c52008-01-30 13:32:42 +010086/*
87 * These are used to make use of C type-checking..
88 */
89typedef unsigned long pteval_t;
90typedef unsigned long pmdval_t;
91typedef unsigned long pudval_t;
92typedef unsigned long pgdval_t;
93typedef unsigned long pgprotval_t;
94typedef unsigned long phys_addr_t;
95
96typedef struct { pteval_t pte; } pte_t;
97
Ingo Molnard6e3cf62008-01-30 13:32:43 +010098#define native_pte_val(x) ((x).pte)
99#define native_make_pte(x) ((pte_t) { (x) } )
100
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +0100101#endif /* !__ASSEMBLY__ */
102
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +0100103#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 Fitzhardinge881d90d2008-01-30 13:32:43 +0100122#define PAGETABLE_LEVELS 3
123
124#ifndef __ASSEMBLY__
125typedef u64 pteval_t;
126typedef u64 pmdval_t;
127typedef u64 pudval_t;
128typedef u64 pgdval_t;
129typedef u64 pgprotval_t;
130typedef u64 phys_addr_t;
131
132typedef struct { unsigned long pte_low, pte_high; } pte_t;
133
134static 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
139static 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 Fitzhardinge83a51012008-01-30 13:32:41 +0100146#else /* !CONFIG_X86_PAE */
147#define __PHYSICAL_MASK_SHIFT 32
148#define __VIRTUAL_MASK_SHIFT 32
Jeremy Fitzhardinge881d90d2008-01-30 13:32:43 +0100149#define PAGETABLE_LEVELS 2
150
151#ifndef __ASSEMBLY__
152typedef unsigned long pteval_t;
153typedef unsigned long pmdval_t;
154typedef unsigned long pudval_t;
155typedef unsigned long pgdval_t;
156typedef unsigned long pgprotval_t;
157typedef unsigned long phys_addr_t;
158
159typedef struct { pteval_t pte_low; } pte_t;
160typedef pte_t boot_pte_t;
161
162static inline unsigned long native_pte_val(pte_t pte)
163{
164 return pte.pte_low;
165}
166
167static inline pte_t native_make_pte(unsigned long val)
168{
169 return (pte_t) { .pte_low = val };
170}
171
172#endif /* __ASSEMBLY__ */
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +0100173#endif /* CONFIG_X86_PAE */
174
175#ifdef CONFIG_HUGETLB_PAGE
176#define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
177#endif
178
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +0100179#ifndef __ASSEMBLY__
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100180#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 Fitzhardinge345b9042008-01-30 13:32:42 +0100187#ifdef CONFIG_X86_USE_3DNOW
188#include <asm/mmx.h>
189
190static inline void clear_page(void *page)
191{
192 mmx_clear_page(page);
193}
194
195static 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
202static inline void clear_page(void *page)
203{
204 memset(page, 0, PAGE_SIZE);
205}
206
207static 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 Fitzhardinge83a51012008-01-30 13:32:41 +0100214#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 Fitzhardinge345b9042008-01-30 13:32:42 +0100223#ifndef __ASSEMBLY__
224struct page;
225
226static void inline clear_user_page(void *page, unsigned long vaddr,
227 struct page *pg)
228{
229 clear_page(page);
230}
231
232static 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 Molnar38f0f122008-01-30 13:32:43 +0100242typedef struct { pgdval_t pgd; } pgd_t;
243typedef struct { pgprotval_t pgprot; } pgprot_t;
244
245static inline pgd_t native_make_pgd(pgdval_t val)
246{
247 return (pgd_t) { val };
248}
249
250static 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
257typedef struct { pudval_t pud; } pud_t;
258
259static inline pud_t native_make_pud(pmdval_t val)
260{
261 return (pud_t) { val };
262}
263
264static 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
272typedef struct { pmdval_t pmd; } pmd_t;
273
274static inline pmd_t native_make_pmd(pmdval_t val)
275{
276 return (pmd_t) { val };
277}
278
279static 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 Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100312#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 Fitzhardinge345b9042008-01-30 13:32:42 +0100326#endif /* __ASSEMBLY__ */
327
328
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +0100329#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 */