ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h @ 8534:da7873110bbb

Tiny bootstrap cleanup.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Jan 09 19:46:46 2006 +0100 (2006-01-09)
parents a08aef9f1c8e
children 990c009015e8
line source
1 #ifndef _I386_PAGE_H
2 #define _I386_PAGE_H
4 /* PAGE_SHIFT determines the page size */
5 #define PAGE_SHIFT 12
6 #define PAGE_SIZE (1UL << PAGE_SHIFT)
7 #define PAGE_MASK (~(PAGE_SIZE-1))
9 #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
10 #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
12 #ifdef __KERNEL__
13 #ifndef __ASSEMBLY__
15 #include <linux/config.h>
16 #include <linux/string.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <asm/bug.h>
20 #include <asm-xen/xen-public/xen.h>
21 #include <asm-xen/foreign_page.h>
23 #define arch_free_page(_page,_order) \
24 ({ int foreign = PageForeign(_page); \
25 if (foreign) \
26 (PageForeignDestructor(_page))(_page); \
27 foreign; \
28 })
29 #define HAVE_ARCH_FREE_PAGE
31 #ifdef CONFIG_XEN_SCRUB_PAGES
32 #define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
33 #else
34 #define scrub_pages(_p,_n) ((void)0)
35 #endif
37 #ifdef CONFIG_X86_USE_3DNOW
39 #include <asm/mmx.h>
41 #define clear_page(page) mmx_clear_page((void *)(page))
42 #define copy_page(to,from) mmx_copy_page(to,from)
44 #else
46 #define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO, vma, vaddr)
47 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
49 /*
50 * On older X86 processors it's not a win to use MMX here it seems.
51 * Maybe the K6-III ?
52 */
54 #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
55 #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
57 #endif
59 #define clear_user_page(page, vaddr, pg) clear_page(page)
60 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
62 /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
63 #define INVALID_P2M_ENTRY (~0UL)
64 #define FOREIGN_FRAME(m) ((m) | (1UL<<31))
65 extern unsigned long *phys_to_machine_mapping;
66 #define pfn_to_mfn(pfn) \
67 (phys_to_machine_mapping[(unsigned int)(pfn)] & ~(1UL<<31))
68 #define phys_to_machine_mapping_valid(pfn) \
69 (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY)
70 static inline unsigned long mfn_to_pfn(unsigned long mfn)
71 {
72 unsigned long pfn;
74 /*
75 * The array access can fail (e.g., device space beyond end of RAM).
76 * In such cases it doesn't matter what we return (we return garbage),
77 * but we must handle the fault without crashing!
78 */
79 asm (
80 "1: movl %1,%0\n"
81 "2:\n"
82 ".section __ex_table,\"a\"\n"
83 " .align 4\n"
84 " .long 1b,2b\n"
85 ".previous"
86 : "=r" (pfn) : "m" (machine_to_phys_mapping[mfn]) );
88 return pfn;
89 }
91 static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
92 {
93 phys_to_machine_mapping[pfn] = mfn;
94 }
96 /* Definitions for machine and pseudophysical addresses. */
97 #ifdef CONFIG_X86_PAE
98 typedef unsigned long long paddr_t;
99 typedef unsigned long long maddr_t;
100 #else
101 typedef unsigned long paddr_t;
102 typedef unsigned long maddr_t;
103 #endif
105 static inline maddr_t phys_to_machine(paddr_t phys)
106 {
107 maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
108 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
109 return machine;
110 }
111 static inline paddr_t machine_to_phys(maddr_t machine)
112 {
113 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
114 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
115 return phys;
116 }
118 /*
119 * These are used to make use of C type-checking..
120 */
121 extern int nx_enabled;
122 #ifdef CONFIG_X86_PAE
123 extern unsigned long long __supported_pte_mask;
124 typedef struct { unsigned long pte_low, pte_high; } pte_t;
125 typedef struct { unsigned long long pmd; } pmd_t;
126 typedef struct { unsigned long long pgd; } pgd_t;
127 typedef struct { unsigned long long pgprot; } pgprot_t;
128 #define __pte(x) ({ unsigned long long _x = (x); \
129 if (_x & 1) _x = phys_to_machine(_x); \
130 ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
131 #define __pgd(x) ({ unsigned long long _x = (x); \
132 (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
133 #define __pmd(x) ({ unsigned long long _x = (x); \
134 (((_x)&1) ? ((pmd_t) {phys_to_machine(_x)}) : ((pmd_t) {(_x)})); })
135 static inline unsigned long long pte_val(pte_t x)
136 {
137 unsigned long long ret;
139 if (x.pte_low) {
140 ret = x.pte_low | (unsigned long long)x.pte_high << 32;
141 ret = machine_to_phys(ret) | 1;
142 } else {
143 ret = 0;
144 }
145 return ret;
146 }
147 static inline unsigned long long pmd_val(pmd_t x)
148 {
149 unsigned long long ret = x.pmd;
150 if (ret) ret = machine_to_phys(ret) | 1;
151 return ret;
152 }
153 static inline unsigned long long pgd_val(pgd_t x)
154 {
155 unsigned long long ret = x.pgd;
156 if (ret) ret = machine_to_phys(ret) | 1;
157 return ret;
158 }
159 static inline unsigned long long pte_val_ma(pte_t x)
160 {
161 return (unsigned long long)x.pte_high << 32 | x.pte_low;
162 }
163 #define HPAGE_SHIFT 21
164 #else
165 typedef struct { unsigned long pte_low; } pte_t;
166 typedef struct { unsigned long pgd; } pgd_t;
167 typedef struct { unsigned long pgprot; } pgprot_t;
168 #define boot_pte_t pte_t /* or would you rather have a typedef */
169 #define pte_val(x) (((x).pte_low & 1) ? machine_to_phys((x).pte_low) : \
170 (x).pte_low)
171 #define pte_val_ma(x) ((x).pte_low)
172 #define __pte(x) ({ unsigned long _x = (x); \
173 (((_x)&1) ? ((pte_t) {phys_to_machine(_x)}) : ((pte_t) {(_x)})); })
174 #define __pgd(x) ({ unsigned long _x = (x); \
175 (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
176 static inline unsigned long pgd_val(pgd_t x)
177 {
178 unsigned long ret = x.pgd;
179 if (ret) ret = machine_to_phys(ret) | 1;
180 return ret;
181 }
182 #define HPAGE_SHIFT 22
183 #endif
184 #define PTE_MASK PAGE_MASK
186 #ifdef CONFIG_HUGETLB_PAGE
187 #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
188 #define HPAGE_MASK (~(HPAGE_SIZE - 1))
189 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
190 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
191 #endif
193 #define pgprot_val(x) ((x).pgprot)
195 #define __pte_ma(x) ((pte_t) { (x) } )
196 #define __pgprot(x) ((pgprot_t) { (x) } )
198 #endif /* !__ASSEMBLY__ */
200 /* to align the pointer to the (next) page boundary */
201 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
203 /*
204 * This handles the memory map.. We could make this a config
205 * option, but too many people screw it up, and too few need
206 * it.
207 *
208 * A __PAGE_OFFSET of 0xC0000000 means that the kernel has
209 * a virtual address space of one gigabyte, which limits the
210 * amount of physical memory you can use to about 950MB.
211 *
212 * If you want more physical memory than this then see the CONFIG_HIGHMEM4G
213 * and CONFIG_HIGHMEM64G options in the kernel configuration.
214 */
216 #ifndef __ASSEMBLY__
218 /*
219 * This much address space is reserved for vmalloc() and iomap()
220 * as well as fixmap mappings.
221 */
222 extern unsigned int __VMALLOC_RESERVE;
224 /* Pure 2^n version of get_order */
225 static __inline__ int get_order(unsigned long size)
226 {
227 int order;
229 size = (size-1) >> (PAGE_SHIFT-1);
230 order = -1;
231 do {
232 size >>= 1;
233 order++;
234 } while (size);
235 return order;
236 }
238 extern int sysctl_legacy_va_layout;
240 #endif /* __ASSEMBLY__ */
242 #ifdef __ASSEMBLY__
243 #define __PAGE_OFFSET (0xC0000000)
244 #else
245 #define __PAGE_OFFSET (0xC0000000UL)
246 #endif
249 #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
250 #define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE)
251 #define MAXMEM (HYPERVISOR_VIRT_START-__PAGE_OFFSET-__VMALLOC_RESERVE)
252 #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
253 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
254 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
255 #ifndef CONFIG_DISCONTIGMEM
256 #define pfn_to_page(pfn) (mem_map + (pfn))
257 #define page_to_pfn(page) ((unsigned long)((page) - mem_map))
258 #define pfn_valid(pfn) ((pfn) < max_mapnr)
259 #endif /* !CONFIG_DISCONTIGMEM */
260 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
262 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
264 #define VM_DATA_DEFAULT_FLAGS \
265 (VM_READ | VM_WRITE | \
266 ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
267 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
269 /* VIRT <-> MACHINE conversion */
270 #define virt_to_machine(v) (phys_to_machine(__pa(v)))
271 #define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
272 #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
274 #endif /* __KERNEL__ */
276 #endif /* _I386_PAGE_H */