blob: d4f1d5791fc186f29a9a60d4fe182d80f05038e4 [file] [log] [blame]
Vegard Nossum77ef50a2008-06-18 17:08:48 +02001#ifndef ASM_X86__PAGE_H
2#define ASM_X86__PAGE_H
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +01003
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
Jeremy Fitzhardinge59438c92008-07-21 22:59:42 -070021/* PTE_PFN_MASK extracts the PFN from a (pte|pmd|pud|pgd)val_t */
22#define PTE_PFN_MASK ((pteval_t)PHYSICAL_PAGE_MASK)
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010023
Jeremy Fitzhardinge77be1fa2008-07-21 22:59:56 -070024/* PTE_FLAGS_MASK extracts the flags from a (pte|pmd|pud|pgd)val_t */
25#define PTE_FLAGS_MASK (~PTE_PFN_MASK)
26
Andi Kleen31422c52008-02-04 16:48:08 +010027#define PMD_PAGE_SIZE (_AC(1, UL) << PMD_SHIFT)
28#define PMD_PAGE_MASK (~(PMD_PAGE_SIZE-1))
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010029
30#define HPAGE_SHIFT PMD_SHIFT
31#define HPAGE_SIZE (_AC(1,UL) << HPAGE_SHIFT)
32#define HPAGE_MASK (~(HPAGE_SIZE - 1))
33#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
34
Andi Kleenb4718e62008-07-23 21:27:51 -070035#define HUGE_MAX_HSTATE 2
36
Ingo Molnar3da1bcc2008-01-30 13:32:42 +010037#ifndef __ASSEMBLY__
38#include <linux/types.h>
39#endif
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010040
41#ifdef CONFIG_X86_64
Jeremy Fitzhardinge11b7c7d2008-01-30 13:32:44 +010042#include <asm/page_64.h>
43#else
44#include <asm/page_32.h>
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010045#endif /* CONFIG_X86_64 */
46
Jeremy Fitzhardinge83a51012008-01-30 13:32:41 +010047#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
48
49#define VM_DATA_DEFAULT_FLAGS \
50 (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
51 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
52
53
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010054#ifndef __ASSEMBLY__
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010055
Thomas Gleixner635ee412008-05-12 15:43:35 +020056typedef struct { pgdval_t pgd; } pgd_t;
57typedef struct { pgprotval_t pgprot; } pgprot_t;
58
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010059extern int page_is_ram(unsigned long pagenr);
Suresh Siddha9542ada2008-09-24 08:53:33 -070060extern int pagerange_is_ram(unsigned long start, unsigned long end);
Arjan van de Venae531c22008-04-24 23:40:47 +020061extern int devmem_is_allowed(unsigned long pagenr);
Thomas Gleixner635ee412008-05-12 15:43:35 +020062extern void map_devmem(unsigned long pfn, unsigned long size,
63 pgprot_t vma_prot);
64extern void unmap_devmem(unsigned long pfn, unsigned long size,
65 pgprot_t vma_prot);
Thomas Gleixner5f5192b2008-01-30 13:34:06 +010066
Yinghai Luf361a452008-07-10 20:38:26 -070067extern unsigned long max_low_pfn_mapped;
Thomas Gleixner67794292008-03-21 21:27:10 +010068extern unsigned long max_pfn_mapped;
Andi Kleen7d1116a2008-03-12 03:53:27 +010069
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010070struct page;
71
Chuck Leverf2f7abc2008-03-04 14:55:45 -080072static inline void clear_user_page(void *page, unsigned long vaddr,
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010073 struct page *pg)
74{
75 clear_page(page);
76}
77
Chuck Leverf2f7abc2008-03-04 14:55:45 -080078static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +010079 struct page *topage)
80{
81 copy_page(to, from);
82}
83
84#define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
85 alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
86#define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
87
Ingo Molnar38f0f122008-01-30 13:32:43 +010088static inline pgd_t native_make_pgd(pgdval_t val)
89{
90 return (pgd_t) { val };
91}
92
93static inline pgdval_t native_pgd_val(pgd_t pgd)
94{
95 return pgd.pgd;
96}
97
98#if PAGETABLE_LEVELS >= 3
99#if PAGETABLE_LEVELS == 4
100typedef struct { pudval_t pud; } pud_t;
101
102static inline pud_t native_make_pud(pmdval_t val)
103{
104 return (pud_t) { val };
105}
106
107static inline pudval_t native_pud_val(pud_t pud)
108{
109 return pud.pud;
110}
111#else /* PAGETABLE_LEVELS == 3 */
112#include <asm-generic/pgtable-nopud.h>
Jeremy Fitzhardinge2f98b2f2008-01-30 13:33:14 +0100113
114static inline pudval_t native_pud_val(pud_t pud)
115{
116 return native_pgd_val(pud.pgd);
117}
Ingo Molnar38f0f122008-01-30 13:32:43 +0100118#endif /* PAGETABLE_LEVELS == 4 */
119
120typedef struct { pmdval_t pmd; } pmd_t;
121
122static inline pmd_t native_make_pmd(pmdval_t val)
123{
124 return (pmd_t) { val };
125}
126
127static inline pmdval_t native_pmd_val(pmd_t pmd)
128{
129 return pmd.pmd;
130}
131#else /* PAGETABLE_LEVELS == 2 */
132#include <asm-generic/pgtable-nopmd.h>
Jeremy Fitzhardinge2f98b2f2008-01-30 13:33:14 +0100133
134static inline pmdval_t native_pmd_val(pmd_t pmd)
135{
136 return native_pgd_val(pmd.pud.pgd);
137}
Ingo Molnar38f0f122008-01-30 13:32:43 +0100138#endif /* PAGETABLE_LEVELS >= 3 */
139
Jeremy Fitzhardingec8e53932008-01-30 13:32:57 +0100140static inline pte_t native_make_pte(pteval_t val)
141{
142 return (pte_t) { .pte = val };
143}
144
145static inline pteval_t native_pte_val(pte_t pte)
146{
147 return pte.pte;
148}
149
Rusty Russellc2e32772008-07-22 15:40:46 +1000150static inline pteval_t native_pte_flags(pte_t pte)
151{
Jeremy Fitzhardinge77be1fa2008-07-21 22:59:56 -0700152 return native_pte_val(pte) & PTE_FLAGS_MASK;
Rusty Russellc2e32772008-07-22 15:40:46 +1000153}
154
Ingo Molnar38f0f122008-01-30 13:32:43 +0100155#define pgprot_val(x) ((x).pgprot)
156#define __pgprot(x) ((pgprot_t) { (x) } )
157
158#ifdef CONFIG_PARAVIRT
159#include <asm/paravirt.h>
160#else /* !CONFIG_PARAVIRT */
161
162#define pgd_val(x) native_pgd_val(x)
163#define __pgd(x) native_make_pgd(x)
164
165#ifndef __PAGETABLE_PUD_FOLDED
166#define pud_val(x) native_pud_val(x)
167#define __pud(x) native_make_pud(x)
168#endif
169
170#ifndef __PAGETABLE_PMD_FOLDED
171#define pmd_val(x) native_pmd_val(x)
172#define __pmd(x) native_make_pmd(x)
173#endif
174
175#define pte_val(x) native_pte_val(x)
Rusty Russellc2e32772008-07-22 15:40:46 +1000176#define pte_flags(x) native_pte_flags(x)
Ingo Molnar38f0f122008-01-30 13:32:43 +0100177#define __pte(x) native_make_pte(x)
178
179#endif /* CONFIG_PARAVIRT */
180
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100181#define __pa(x) __phys_addr((unsigned long)(x))
Vegard Nossumaf5c2bd2008-10-03 17:54:25 +0200182#define __pa_nodebug(x) __phys_addr_nodebug((unsigned long)(x))
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100183/* __pa_symbol should be used for C visible symbols.
184 This seems to be the official gcc blessed way to do such arithmetic. */
185#define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x)))
186
187#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
188
189#define __boot_va(x) __va(x)
190#define __boot_pa(x) __pa(x)
191
Vegard Nossumaf5c2bd2008-10-03 17:54:25 +0200192/*
193 * virt_to_page(kaddr) returns a valid pointer if and only if
194 * virt_addr_valid(kaddr) returns true.
195 */
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100196#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
197#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
Vegard Nossumaf5c2bd2008-10-03 17:54:25 +0200198extern bool __virt_addr_valid(unsigned long kaddr);
199#define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
Jeremy Fitzhardinge98fd5ae2008-01-30 13:32:43 +0100200
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +0100201#endif /* __ASSEMBLY__ */
202
Jeremy Fitzhardingee62f4472008-01-30 13:32:44 +0100203#include <asm-generic/memory_model.h>
204#include <asm-generic/page.h>
205
206#define __HAVE_ARCH_GATE_AREA 1
Jeremy Fitzhardinge345b9042008-01-30 13:32:42 +0100207
Jeremy Fitzhardinge11b7c7d2008-01-30 13:32:44 +0100208#endif /* __KERNEL__ */
Vegard Nossum77ef50a2008-06-18 17:08:48 +0200209#endif /* ASM_X86__PAGE_H */