blob: b52ed85f32f56ba2c4616a4decef26f742cb4cdf [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
Jeremy Fitzhardinge11b7c7d2008-01-30 13:32:44 +010011#ifdef __KERNEL__
12
Jeremy Fitzhardingec57c05d2008-05-20 08:26:19 +010013#define __PHYSICAL_MASK ((phys_addr_t)(1ULL << __PHYSICAL_MASK_SHIFT) - 1)
14#define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1)
15
Jeremy Fitzhardinge2bd3a99c2008-05-20 08:26:17 +010016/* Cast PAGE_MASK to a signed type so that it is sign-extended if
17 virtual addresses are 32-bits but physical addresses are larger
18 (ie, 32-bit PAE). */
19#define PHYSICAL_PAGE_MASK (((signed long)PAGE_MASK) & __PHYSICAL_MASK)
20
21/* PTE_MASK extracts the PFN from a (pte|pmd|pud|pgd)val_t */
22#define PTE_MASK ((pteval_t)PHYSICAL_PAGE_MASK)
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010023
Andi Kleen31422c52008-02-04 16:48:08 +010024#define PMD_PAGE_SIZE (_AC(1, UL) << PMD_SHIFT)
25#define PMD_PAGE_MASK (~(PMD_PAGE_SIZE-1))
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010026
27#define HPAGE_SHIFT PMD_SHIFT
28#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT)
29#define HPAGE_MASK (~(HPAGE_SIZE - 1))
30#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
31
32/* to align the pointer to the (next) page boundary */
33#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
34
Ingo Molnar3da1bcc2008-01-30 13:32:42 +010035#ifndef __ASSEMBLY__
36#include <linux/types.h>
37#endif
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010038
39#ifdef CONFIG_X86_64
Jeremy Fitzhardinge11b7c7d2008-01-30 13:32:44 +010040#include <asm/page_64.h>
41#else
42#include <asm/page_32.h>
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010043#endif /* CONFIG_X86_64 */
44
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010045#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
46
47#define VM_DATA_DEFAULT_FLAGS \
48 (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
49 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
50
51
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010052#ifndef __ASSEMBLY__
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010053
Thomas Gleixner635ee412008-05-12 15:43:35 +020054typedef struct { pgdval_t pgd; } pgd_t;
55typedef struct { pgprotval_t pgprot; } pgprot_t;
56
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010057extern int page_is_ram(unsigned long pagenr);
Arjan van de Venae531c22008-04-24 23:40:47 +020058extern int devmem_is_allowed(unsigned long pagenr);
Thomas Gleixner635ee412008-05-12 15:43:35 +020059extern void map_devmem(unsigned long pfn, unsigned long size,
60 pgprot_t vma_prot);
61extern void unmap_devmem(unsigned long pfn, unsigned long size,
62 pgprot_t vma_prot);
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010063
Thomas Gleixner67794292008-03-21 21:27:10 +010064extern unsigned long max_pfn_mapped;
Andi Kleen7d1116a2008-03-12 03:53:27 +010065
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010066struct page;
67
Chuck Leverf2f7abc2008-03-04 14:55:45 -080068static inline void clear_user_page(void *page, unsigned long vaddr,
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010069 struct page *pg)
70{
71 clear_page(page);
72}
73
Chuck Leverf2f7abc2008-03-04 14:55:45 -080074static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010075 struct page *topage)
76{
77 copy_page(to, from);
78}
79
80#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
81 alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
82#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
83
Ingo Molnar38f0f122008-01-30 13:32:43 +010084static inline pgd_t native_make_pgd(pgdval_t val)
85{
86 return (pgd_t) { val };
87}
88
89static inline pgdval_t native_pgd_val(pgd_t pgd)
90{
91 return pgd.pgd;
92}
93
94#if PAGETABLE_LEVELS >= 3
95#if PAGETABLE_LEVELS == 4
96typedef struct { pudval_t pud; } pud_t;
97
98static inline pud_t native_make_pud(pmdval_t val)
99{
100 return (pud_t) { val };
101}
102
103static inline pudval_t native_pud_val(pud_t pud)
104{
105 return pud.pud;
106}
107#else /* PAGETABLE_LEVELS == 3 */
108#include <asm-generic/pgtable-nopud.h>
Jeremy Fitzhardinge2f98b2f2008-01-30 13:33:14 +0100109
110static inline pudval_t native_pud_val(pud_t pud)
111{
112 return native_pgd_val(pud.pgd);
113}
Ingo Molnar38f0f122008-01-30 13:32:43 +0100114#endif /* PAGETABLE_LEVELS == 4 */
115
116typedef struct { pmdval_t pmd; } pmd_t;
117
118static inline pmd_t native_make_pmd(pmdval_t val)
119{
120 return (pmd_t) { val };
121}
122
123static inline pmdval_t native_pmd_val(pmd_t pmd)
124{
125 return pmd.pmd;
126}
127#else /* PAGETABLE_LEVELS == 2 */
128#include <asm-generic/pgtable-nopmd.h>
Jeremy Fitzhardinge2f98b2f2008-01-30 13:33:14 +0100129
130static inline pmdval_t native_pmd_val(pmd_t pmd)
131{
132 return native_pgd_val(pmd.pud.pgd);
133}
Ingo Molnar38f0f122008-01-30 13:32:43 +0100134#endif /* PAGETABLE_LEVELS >= 3 */
135
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100136static inline pte_t native_make_pte(pteval_t val)
137{
138 return (pte_t) { .pte = val };
139}
140
141static inline pteval_t native_pte_val(pte_t pte)
142{
143 return pte.pte;
144}
145
Ingo Molnar38f0f122008-01-30 13:32:43 +0100146#define pgprot_val(x) ((x).pgprot)
147#define __pgprot(x) ((pgprot_t) { (x) } )
148
149#ifdef CONFIG_PARAVIRT
150#include <asm/paravirt.h>
151#else /* !CONFIG_PARAVIRT */
152
153#define pgd_val(x) native_pgd_val(x)
154#define __pgd(x) native_make_pgd(x)
155
156#ifndef __PAGETABLE_PUD_FOLDED
157#define pud_val(x) native_pud_val(x)
158#define __pud(x) native_make_pud(x)
159#endif
160
161#ifndef __PAGETABLE_PMD_FOLDED
162#define pmd_val(x) native_pmd_val(x)
163#define __pmd(x) native_make_pmd(x)
164#endif
165
166#define pte_val(x) native_pte_val(x)
Jeremy Fitzhardingea15af1c2008-05-26 23:31:06 +0100167#define pte_flags(x) native_pte_val(x)
Ingo Molnar38f0f122008-01-30 13:32:43 +0100168#define __pte(x) native_make_pte(x)
169
170#endif /* CONFIG_PARAVIRT */
171
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100172#define __pa(x) __phys_addr((unsigned long)(x))
173/* __pa_symbol should be used for C visible symbols.
174 This seems to be the official gcc blessed way to do such arithmetic. */
175#define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x)))
176
177#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
178
179#define __boot_va(x) __va(x)
180#define __boot_pa(x) __pa(x)
181
182#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
183#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
184#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
185
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +0100186#endif /* __ASSEMBLY__ */
187
Jeremy Fitzhardingee62f4472008-01-30 13:32:44 +0100188#include <asm-generic/memory_model.h>
189#include <asm-generic/page.h>
190
191#define __HAVE_ARCH_GATE_AREA 1
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +0100192
Jeremy Fitzhardinge11b7c7d2008-01-30 13:32:44 +0100193#endif /* __KERNEL__ */
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +0100194#endif /* _ASM_X86_PAGE_H */