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 | |
Jeremy Fitzhardinge | 11b7c7d | 2008-01-30 13:32:44 +0100 | [diff] [blame] | 11 | #ifdef __KERNEL__ |
| 12 | |
Jeremy Fitzhardinge | c57c05d | 2008-05-20 08:26:19 +0100 | [diff] [blame] | 13 | #define __PHYSICAL_MASK ((phys_addr_t)(1ULL << __PHYSICAL_MASK_SHIFT) - 1) |
| 14 | #define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1) |
| 15 | |
Jeremy Fitzhardinge | 2bd3a99c | 2008-05-20 08:26:17 +0100 | [diff] [blame] | 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 |
| 18 | (ie, 32-bit PAE). */ |
| 19 | #define PHYSICAL_PAGE_MASK (((signed long)PAGE_MASK) & __PHYSICAL_MASK) |
| 20 | |
Jeremy Fitzhardinge | 59438c9 | 2008-07-21 22:59:42 -0700 | [diff] [blame^] | 21 | /* 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 Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 23 | |
Andi Kleen | 31422c5 | 2008-02-04 16:48:08 +0100 | [diff] [blame] | 24 | #define PMD_PAGE_SIZE (_AC(1, UL) << PMD_SHIFT) |
| 25 | #define PMD_PAGE_MASK (~(PMD_PAGE_SIZE-1)) |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 26 | |
| 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 Molnar | 3da1bcc | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 35 | #ifndef __ASSEMBLY__ |
| 36 | #include <linux/types.h> |
| 37 | #endif |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 38 | |
| 39 | #ifdef CONFIG_X86_64 |
Jeremy Fitzhardinge | 11b7c7d | 2008-01-30 13:32:44 +0100 | [diff] [blame] | 40 | #include <asm/page_64.h> |
| 41 | #else |
| 42 | #include <asm/page_32.h> |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 43 | #endif /* CONFIG_X86_64 */ |
| 44 | |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 45 | #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 Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 52 | #ifndef __ASSEMBLY__ |
Thomas Gleixner | 5f5192b | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 53 | |
Thomas Gleixner | 635ee41 | 2008-05-12 15:43:35 +0200 | [diff] [blame] | 54 | typedef struct { pgdval_t pgd; } pgd_t; |
| 55 | typedef struct { pgprotval_t pgprot; } pgprot_t; |
| 56 | |
Thomas Gleixner | 5f5192b | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 57 | extern int page_is_ram(unsigned long pagenr); |
Arjan van de Ven | ae531c2 | 2008-04-24 23:40:47 +0200 | [diff] [blame] | 58 | extern int devmem_is_allowed(unsigned long pagenr); |
Thomas Gleixner | 635ee41 | 2008-05-12 15:43:35 +0200 | [diff] [blame] | 59 | extern void map_devmem(unsigned long pfn, unsigned long size, |
| 60 | pgprot_t vma_prot); |
| 61 | extern void unmap_devmem(unsigned long pfn, unsigned long size, |
| 62 | pgprot_t vma_prot); |
Thomas Gleixner | 5f5192b | 2008-01-30 13:34:06 +0100 | [diff] [blame] | 63 | |
Yinghai Lu | f361a45 | 2008-07-10 20:38:26 -0700 | [diff] [blame] | 64 | extern unsigned long max_low_pfn_mapped; |
Thomas Gleixner | 6779429 | 2008-03-21 21:27:10 +0100 | [diff] [blame] | 65 | extern unsigned long max_pfn_mapped; |
Andi Kleen | 7d1116a | 2008-03-12 03:53:27 +0100 | [diff] [blame] | 66 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 67 | struct page; |
| 68 | |
Chuck Lever | f2f7abc | 2008-03-04 14:55:45 -0800 | [diff] [blame] | 69 | static inline void clear_user_page(void *page, unsigned long vaddr, |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 70 | struct page *pg) |
| 71 | { |
| 72 | clear_page(page); |
| 73 | } |
| 74 | |
Chuck Lever | f2f7abc | 2008-03-04 14:55:45 -0800 | [diff] [blame] | 75 | static inline void copy_user_page(void *to, void *from, unsigned long vaddr, |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 76 | struct page *topage) |
| 77 | { |
| 78 | copy_page(to, from); |
| 79 | } |
| 80 | |
| 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 |
| 84 | |
Ingo Molnar | 38f0f12 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 85 | static inline pgd_t native_make_pgd(pgdval_t val) |
| 86 | { |
| 87 | return (pgd_t) { val }; |
| 88 | } |
| 89 | |
| 90 | static inline pgdval_t native_pgd_val(pgd_t pgd) |
| 91 | { |
| 92 | return pgd.pgd; |
| 93 | } |
| 94 | |
| 95 | #if PAGETABLE_LEVELS >= 3 |
| 96 | #if PAGETABLE_LEVELS == 4 |
| 97 | typedef struct { pudval_t pud; } pud_t; |
| 98 | |
| 99 | static inline pud_t native_make_pud(pmdval_t val) |
| 100 | { |
| 101 | return (pud_t) { val }; |
| 102 | } |
| 103 | |
| 104 | static inline pudval_t native_pud_val(pud_t pud) |
| 105 | { |
| 106 | return pud.pud; |
| 107 | } |
| 108 | #else /* PAGETABLE_LEVELS == 3 */ |
| 109 | #include <asm-generic/pgtable-nopud.h> |
Jeremy Fitzhardinge | 2f98b2f | 2008-01-30 13:33:14 +0100 | [diff] [blame] | 110 | |
| 111 | static inline pudval_t native_pud_val(pud_t pud) |
| 112 | { |
| 113 | return native_pgd_val(pud.pgd); |
| 114 | } |
Ingo Molnar | 38f0f12 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 115 | #endif /* PAGETABLE_LEVELS == 4 */ |
| 116 | |
| 117 | typedef struct { pmdval_t pmd; } pmd_t; |
| 118 | |
| 119 | static inline pmd_t native_make_pmd(pmdval_t val) |
| 120 | { |
| 121 | return (pmd_t) { val }; |
| 122 | } |
| 123 | |
| 124 | static inline pmdval_t native_pmd_val(pmd_t pmd) |
| 125 | { |
| 126 | return pmd.pmd; |
| 127 | } |
| 128 | #else /* PAGETABLE_LEVELS == 2 */ |
| 129 | #include <asm-generic/pgtable-nopmd.h> |
Jeremy Fitzhardinge | 2f98b2f | 2008-01-30 13:33:14 +0100 | [diff] [blame] | 130 | |
| 131 | static inline pmdval_t native_pmd_val(pmd_t pmd) |
| 132 | { |
| 133 | return native_pgd_val(pmd.pud.pgd); |
| 134 | } |
Ingo Molnar | 38f0f12 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 135 | #endif /* PAGETABLE_LEVELS >= 3 */ |
| 136 | |
Jeremy Fitzhardinge | c8e5393 | 2008-01-30 13:32:57 +0100 | [diff] [blame] | 137 | static inline pte_t native_make_pte(pteval_t val) |
| 138 | { |
| 139 | return (pte_t) { .pte = val }; |
| 140 | } |
| 141 | |
| 142 | static inline pteval_t native_pte_val(pte_t pte) |
| 143 | { |
| 144 | return pte.pte; |
| 145 | } |
| 146 | |
Rusty Russell | c2e3277 | 2008-07-22 15:40:46 +1000 | [diff] [blame] | 147 | static inline pteval_t native_pte_flags(pte_t pte) |
| 148 | { |
Jeremy Fitzhardinge | 59438c9 | 2008-07-21 22:59:42 -0700 | [diff] [blame^] | 149 | return native_pte_val(pte) & ~PTE_PFN_MASK; |
Rusty Russell | c2e3277 | 2008-07-22 15:40:46 +1000 | [diff] [blame] | 150 | } |
| 151 | |
Ingo Molnar | 38f0f12 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 152 | #define pgprot_val(x) ((x).pgprot) |
| 153 | #define __pgprot(x) ((pgprot_t) { (x) } ) |
| 154 | |
| 155 | #ifdef CONFIG_PARAVIRT |
| 156 | #include <asm/paravirt.h> |
| 157 | #else /* !CONFIG_PARAVIRT */ |
| 158 | |
| 159 | #define pgd_val(x) native_pgd_val(x) |
| 160 | #define __pgd(x) native_make_pgd(x) |
| 161 | |
| 162 | #ifndef __PAGETABLE_PUD_FOLDED |
| 163 | #define pud_val(x) native_pud_val(x) |
| 164 | #define __pud(x) native_make_pud(x) |
| 165 | #endif |
| 166 | |
| 167 | #ifndef __PAGETABLE_PMD_FOLDED |
| 168 | #define pmd_val(x) native_pmd_val(x) |
| 169 | #define __pmd(x) native_make_pmd(x) |
| 170 | #endif |
| 171 | |
| 172 | #define pte_val(x) native_pte_val(x) |
Rusty Russell | c2e3277 | 2008-07-22 15:40:46 +1000 | [diff] [blame] | 173 | #define pte_flags(x) native_pte_flags(x) |
Ingo Molnar | 38f0f12 | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 174 | #define __pte(x) native_make_pte(x) |
| 175 | |
| 176 | #endif /* CONFIG_PARAVIRT */ |
| 177 | |
Jeremy Fitzhardinge | 98fd5ae | 2008-01-30 13:32:43 +0100 | [diff] [blame] | 178 | #define __pa(x) __phys_addr((unsigned long)(x)) |
| 179 | /* __pa_symbol should be used for C visible symbols. |
| 180 | This seems to be the official gcc blessed way to do such arithmetic. */ |
| 181 | #define __pa_symbol(x) __pa(__phys_reloc_hide((unsigned long)(x))) |
| 182 | |
| 183 | #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET)) |
| 184 | |
| 185 | #define __boot_va(x) __va(x) |
| 186 | #define __boot_pa(x) __pa(x) |
| 187 | |
| 188 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
| 189 | #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) |
| 190 | #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) |
| 191 | |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 192 | #endif /* __ASSEMBLY__ */ |
| 193 | |
Jeremy Fitzhardinge | e62f447 | 2008-01-30 13:32:44 +0100 | [diff] [blame] | 194 | #include <asm-generic/memory_model.h> |
| 195 | #include <asm-generic/page.h> |
| 196 | |
| 197 | #define __HAVE_ARCH_GATE_AREA 1 |
Jeremy Fitzhardinge | 345b904 | 2008-01-30 13:32:42 +0100 | [diff] [blame] | 198 | |
Jeremy Fitzhardinge | 11b7c7d | 2008-01-30 13:32:44 +0100 | [diff] [blame] | 199 | #endif /* __KERNEL__ */ |
Jeremy Fitzhardinge | 83a5101 | 2008-01-30 13:32:41 +0100 | [diff] [blame] | 200 | #endif /* _ASM_X86_PAGE_H */ |