1 #ifndef _ASM_X86_PAGE_H
2 #define _ASM_X86_PAGE_H
4 #include <linux/const.h>
6 /* PAGE_SHIFT determines the page size */
8 #define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
9 #define PAGE_MASK (~(PAGE_SIZE-1))
13 #define __PHYSICAL_MASK ((phys_addr_t)(1ULL << __PHYSICAL_MASK_SHIFT) - 1)
14 #define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1)
16 /* 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
19 #define PHYSICAL_PAGE_MASK (((signed long)PAGE_MASK) & __PHYSICAL_MASK)
21 /* PTE_MASK extracts the PFN from a (pte|pmd|pud|pgd)val_t */
22 #define PTE_MASK ((pteval_t)PHYSICAL_PAGE_MASK)
24 #define PMD_PAGE_SIZE (_AC(1, UL) << PMD_SHIFT)
25 #define PMD_PAGE_MASK (~(PMD_PAGE_SIZE-1))
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)
32 /* to align the pointer to the (next) page boundary */
33 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
36 #include <linux/types.h>
40 #include <asm/page_64.h>
42 #include <asm/page_32.h>
43 #endif /* CONFIG_X86_64 */
45 #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
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)
54 typedef struct { pgdval_t pgd; } pgd_t;
55 typedef struct { pgprotval_t pgprot; } pgprot_t;
57 extern int page_is_ram(unsigned long pagenr);
58 extern int devmem_is_allowed(unsigned long pagenr);
59 extern void map_devmem(unsigned long pfn, unsigned long size,
61 extern void unmap_devmem(unsigned long pfn, unsigned long size,
64 extern unsigned long max_low_pfn_mapped;
65 extern unsigned long max_pfn_mapped;
69 static inline void clear_user_page(void *page, unsigned long vaddr,
75 static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
81 #define __alloc_zeroed_user_highpage(movableflags, vma, vaddr) \
82 alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO | movableflags, vma, vaddr)
83 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
85 static inline pgd_t native_make_pgd(pgdval_t val)
87 return (pgd_t) { val };
90 static inline pgdval_t native_pgd_val(pgd_t pgd)
95 #if PAGETABLE_LEVELS >= 3
96 #if PAGETABLE_LEVELS == 4
97 typedef struct { pudval_t pud; } pud_t;
99 static inline pud_t native_make_pud(pmdval_t val)
101 return (pud_t) { val };
104 static inline pudval_t native_pud_val(pud_t pud)
108 #else /* PAGETABLE_LEVELS == 3 */
109 #include <asm-generic/pgtable-nopud.h>
111 static inline pudval_t native_pud_val(pud_t pud)
113 return native_pgd_val(pud.pgd);
115 #endif /* PAGETABLE_LEVELS == 4 */
117 typedef struct { pmdval_t pmd; } pmd_t;
119 static inline pmd_t native_make_pmd(pmdval_t val)
121 return (pmd_t) { val };
124 static inline pmdval_t native_pmd_val(pmd_t pmd)
128 #else /* PAGETABLE_LEVELS == 2 */
129 #include <asm-generic/pgtable-nopmd.h>
131 static inline pmdval_t native_pmd_val(pmd_t pmd)
133 return native_pgd_val(pmd.pud.pgd);
135 #endif /* PAGETABLE_LEVELS >= 3 */
137 static inline pte_t native_make_pte(pteval_t val)
139 return (pte_t) { .pte = val };
142 static inline pteval_t native_pte_val(pte_t pte)
147 #define pgprot_val(x) ((x).pgprot)
148 #define __pgprot(x) ((pgprot_t) { (x) } )
150 #ifdef CONFIG_PARAVIRT
151 #include <asm/paravirt.h>
152 #else /* !CONFIG_PARAVIRT */
154 #define pgd_val(x) native_pgd_val(x)
155 #define __pgd(x) native_make_pgd(x)
157 #ifndef __PAGETABLE_PUD_FOLDED
158 #define pud_val(x) native_pud_val(x)
159 #define __pud(x) native_make_pud(x)
162 #ifndef __PAGETABLE_PMD_FOLDED
163 #define pmd_val(x) native_pmd_val(x)
164 #define __pmd(x) native_make_pmd(x)
167 #define pte_val(x) native_pte_val(x)
168 #define pte_flags(x) native_pte_val(x)
169 #define __pte(x) native_make_pte(x)
171 #endif /* CONFIG_PARAVIRT */
173 #define __pa(x) __phys_addr((unsigned long)(x))
174 /* __pa_symbol should be used for C visible symbols.
175 This seems to be the official gcc blessed way to do such arithmetic. */
176 #define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x)))
178 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
180 #define __boot_va(x) __va(x)
181 #define __boot_pa(x) __pa(x)
183 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
184 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
185 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
187 #endif /* __ASSEMBLY__ */
189 #include <asm-generic/memory_model.h>
190 #include <asm-generic/page.h>
192 #define __HAVE_ARCH_GATE_AREA 1
194 #endif /* __KERNEL__ */
195 #endif /* _ASM_X86_PAGE_H */