This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / asm-i386 / mach-xen / asm / page.h
1 #ifndef _I386_PAGE_H
2 #define _I386_PAGE_H
3
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))
8
9 #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
10 #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
11
12 #ifdef __KERNEL__
13 #ifndef __ASSEMBLY__
14
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 <xen/interface/xen.h>
21 #include <xen/features.h>
22 #include <xen/foreign_page.h>
23
24 #define arch_free_page(_page,_order)                    \
25 ({      int foreign = PageForeign(_page);               \
26         if (foreign)                                    \
27                 (PageForeignDestructor(_page))(_page);  \
28         foreign;                                        \
29 })
30 #define HAVE_ARCH_FREE_PAGE
31
32 #ifdef CONFIG_XEN_SCRUB_PAGES
33 #define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
34 #else
35 #define scrub_pages(_p,_n) ((void)0)
36 #endif
37
38 #ifdef CONFIG_X86_USE_3DNOW
39
40 #include <asm/mmx.h>
41
42 #define clear_page(page)        mmx_clear_page((void *)(page))
43 #define copy_page(to,from)      mmx_copy_page(to,from)
44
45 #else
46
47 #define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO, vma, vaddr)
48 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
49
50 /*
51  *      On older X86 processors it's not a win to use MMX here it seems.
52  *      Maybe the K6-III ?
53  */
54  
55 #define clear_page(page)        memset((void *)(page), 0, PAGE_SIZE)
56 #define copy_page(to,from)      memcpy((void *)(to), (void *)(from), PAGE_SIZE)
57
58 #endif
59
60 #define clear_user_page(page, vaddr, pg)        clear_page(page)
61 #define copy_user_page(to, from, vaddr, pg)     copy_page(to, from)
62
63 /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
64 #define INVALID_P2M_ENTRY       (~0UL)
65 #define FOREIGN_FRAME_BIT       (1UL<<31)
66 #define FOREIGN_FRAME(m)        ((m) | FOREIGN_FRAME_BIT)
67
68 extern unsigned long *phys_to_machine_mapping;
69
70 #undef machine_to_phys_mapping
71 extern unsigned long *machine_to_phys_mapping;
72 extern unsigned int   machine_to_phys_order;
73
74 static inline unsigned long pfn_to_mfn(unsigned long pfn)
75 {
76         if (xen_feature(XENFEAT_auto_translated_physmap))
77                 return pfn;
78         return phys_to_machine_mapping[(unsigned int)(pfn)] &
79                 ~FOREIGN_FRAME_BIT;
80 }
81
82 static inline int phys_to_machine_mapping_valid(unsigned long pfn)
83 {
84         if (xen_feature(XENFEAT_auto_translated_physmap))
85                 return 1;
86         return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
87 }
88
89 static inline unsigned long mfn_to_pfn(unsigned long mfn)
90 {
91         extern unsigned long max_mapnr;
92         unsigned long pfn;
93
94         if (xen_feature(XENFEAT_auto_translated_physmap))
95                 return mfn;
96
97         if (unlikely((mfn >> machine_to_phys_order) != 0))
98                 return max_mapnr;
99
100         /* The array access can fail (e.g., device space beyond end of RAM). */
101         asm (
102                 "1:     movl %1,%0\n"
103                 "2:\n"
104                 ".section .fixup,\"ax\"\n"
105                 "3:     movl %2,%0\n"
106                 "       jmp  2b\n"
107                 ".previous\n"
108                 ".section __ex_table,\"a\"\n"
109                 "       .align 4\n"
110                 "       .long 1b,3b\n"
111                 ".previous"
112                 : "=r" (pfn)
113                 : "m" (machine_to_phys_mapping[mfn]), "m" (max_mapnr) );
114
115         return pfn;
116 }
117
118 /*
119  * We detect special mappings in one of two ways:
120  *  1. If the MFN is an I/O page then Xen will set the m2p entry
121  *     to be outside our maximum possible pseudophys range.
122  *  2. If the MFN belongs to a different domain then we will certainly
123  *     not have MFN in our p2m table. Conversely, if the page is ours,
124  *     then we'll have p2m(m2p(MFN))==MFN.
125  * If we detect a special mapping then it doesn't have a 'struct page'.
126  * We force !pfn_valid() by returning an out-of-range pointer.
127  *
128  * NB. These checks require that, for any MFN that is not in our reservation,
129  * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
130  * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
131  * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
132  *
133  * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
134  *      use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
135  *      require. In all the cases we care about, the FOREIGN_FRAME bit is
136  *      masked (e.g., pfn_to_mfn()) so behaviour there is correct.
137  */
138 static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
139 {
140         extern unsigned long max_mapnr;
141         unsigned long pfn = mfn_to_pfn(mfn);
142         if ((pfn < max_mapnr)
143             && !xen_feature(XENFEAT_auto_translated_physmap)
144             && (phys_to_machine_mapping[pfn] != mfn))
145                 return max_mapnr; /* force !pfn_valid() */
146         return pfn;
147 }
148
149 static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
150 {
151         if (xen_feature(XENFEAT_auto_translated_physmap)) {
152                 BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
153                 return;
154         }
155         phys_to_machine_mapping[pfn] = mfn;
156 }
157
158 /* Definitions for machine and pseudophysical addresses. */
159 #ifdef CONFIG_X86_PAE
160 typedef unsigned long long paddr_t;
161 typedef unsigned long long maddr_t;
162 #else
163 typedef unsigned long paddr_t;
164 typedef unsigned long maddr_t;
165 #endif
166
167 static inline maddr_t phys_to_machine(paddr_t phys)
168 {
169         maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
170         machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
171         return machine;
172 }
173 static inline paddr_t machine_to_phys(maddr_t machine)
174 {
175         paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
176         phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
177         return phys;
178 }
179
180 /*
181  * These are used to make use of C type-checking..
182  */
183 extern int nx_enabled;
184 #ifdef CONFIG_X86_PAE
185 extern unsigned long long __supported_pte_mask;
186 typedef struct { unsigned long pte_low, pte_high; } pte_t;
187 typedef struct { unsigned long long pmd; } pmd_t;
188 typedef struct { unsigned long long pgd; } pgd_t;
189 typedef struct { unsigned long long pgprot; } pgprot_t;
190 #define __pte(x) ({ unsigned long long _x = (x);        \
191     if (_x & 1) _x = phys_to_machine(_x);               \
192     ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
193 #define __pgd(x) ({ unsigned long long _x = (x); \
194     (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
195 #define __pmd(x) ({ unsigned long long _x = (x); \
196     (((_x)&1) ? ((pmd_t) {phys_to_machine(_x)}) : ((pmd_t) {(_x)})); })
197 static inline unsigned long long pte_val(pte_t x)
198 {
199         unsigned long long ret;
200
201         if (x.pte_low) {
202                 ret = x.pte_low | (unsigned long long)x.pte_high << 32;
203                 ret = machine_to_phys(ret) | 1;
204         } else {
205                 ret = 0;
206         }
207         return ret;
208 }
209 static inline unsigned long long pmd_val(pmd_t x)
210 {
211         unsigned long long ret = x.pmd;
212         if (ret) ret = machine_to_phys(ret) | 1;
213         return ret;
214 }
215 static inline unsigned long long pgd_val(pgd_t x)
216 {
217         unsigned long long ret = x.pgd;
218         if (ret) ret = machine_to_phys(ret) | 1;
219         return ret;
220 }
221 static inline unsigned long long pte_val_ma(pte_t x)
222 {
223         return (unsigned long long)x.pte_high << 32 | x.pte_low;
224 }
225 #define HPAGE_SHIFT     21
226 #else
227 typedef struct { unsigned long pte_low; } pte_t;
228 typedef struct { unsigned long pgd; } pgd_t;
229 typedef struct { unsigned long pgprot; } pgprot_t;
230 #define boot_pte_t pte_t /* or would you rather have a typedef */
231 #define pte_val(x)      (((x).pte_low & 1) ? machine_to_phys((x).pte_low) : \
232                          (x).pte_low)
233 #define pte_val_ma(x)   ((x).pte_low)
234 #define __pte(x) ({ unsigned long _x = (x); \
235     (((_x)&1) ? ((pte_t) {phys_to_machine(_x)}) : ((pte_t) {(_x)})); })
236 #define __pgd(x) ({ unsigned long _x = (x); \
237     (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
238 static inline unsigned long pgd_val(pgd_t x)
239 {
240         unsigned long ret = x.pgd;
241         if (ret) ret = machine_to_phys(ret) | 1;
242         return ret;
243 }
244 #define HPAGE_SHIFT     22
245 #endif
246 #define PTE_MASK        PAGE_MASK
247
248 #ifdef CONFIG_HUGETLB_PAGE
249 #define HPAGE_SIZE      ((1UL) << HPAGE_SHIFT)
250 #define HPAGE_MASK      (~(HPAGE_SIZE - 1))
251 #define HUGETLB_PAGE_ORDER      (HPAGE_SHIFT - PAGE_SHIFT)
252 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
253 #endif
254
255 #define pgprot_val(x)   ((x).pgprot)
256
257 #define __pte_ma(x)     ((pte_t) { (x) } )
258 #define __pgprot(x)     ((pgprot_t) { (x) } )
259
260 #endif /* !__ASSEMBLY__ */
261
262 /* to align the pointer to the (next) page boundary */
263 #define PAGE_ALIGN(addr)        (((addr)+PAGE_SIZE-1)&PAGE_MASK)
264
265 /*
266  * This handles the memory map.. We could make this a config
267  * option, but too many people screw it up, and too few need
268  * it.
269  *
270  * A __PAGE_OFFSET of 0xC0000000 means that the kernel has
271  * a virtual address space of one gigabyte, which limits the
272  * amount of physical memory you can use to about 950MB. 
273  *
274  * If you want more physical memory than this then see the CONFIG_HIGHMEM4G
275  * and CONFIG_HIGHMEM64G options in the kernel configuration.
276  */
277
278 #ifndef __ASSEMBLY__
279
280 /*
281  * This much address space is reserved for vmalloc() and iomap()
282  * as well as fixmap mappings.
283  */
284 extern unsigned int __VMALLOC_RESERVE;
285
286 extern int sysctl_legacy_va_layout;
287
288 extern int devmem_is_allowed(unsigned long pagenr);
289 extern int page_is_ram(unsigned long pagenr);
290
291 #endif /* __ASSEMBLY__ */
292
293 #ifdef __ASSEMBLY__
294 #define __PAGE_OFFSET           CONFIG_PAGE_OFFSET
295 #define __PHYSICAL_START        CONFIG_PHYSICAL_START
296 #else
297 #define __PAGE_OFFSET           ((unsigned long)CONFIG_PAGE_OFFSET)
298 #define __PHYSICAL_START        ((unsigned long)CONFIG_PHYSICAL_START)
299 #endif
300 #define __KERNEL_START          (__PAGE_OFFSET + __PHYSICAL_START)
301
302 #ifdef CONFIG_XEN_COMPAT_030002
303 #undef LOAD_OFFSET
304 #define LOAD_OFFSET             0
305 #endif /* CONFIG_XEN_COMPAT_030002 */
306
307 #define PAGE_OFFSET             ((unsigned long)__PAGE_OFFSET)
308 #define VMALLOC_RESERVE         ((unsigned long)__VMALLOC_RESERVE)
309 #define MAXMEM                  (__FIXADDR_TOP-__PAGE_OFFSET-__VMALLOC_RESERVE)
310 #define __pa(x)                 ((unsigned long)(x)-PAGE_OFFSET)
311 #define __va(x)                 ((void *)((unsigned long)(x)+PAGE_OFFSET))
312 #define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
313 #ifdef CONFIG_FLATMEM
314 #define pfn_valid(pfn)          ((pfn) < max_mapnr)
315 #endif /* CONFIG_FLATMEM */
316 #define virt_to_page(kaddr)     pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
317
318 #define virt_addr_valid(kaddr)  pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
319
320 #define VM_DATA_DEFAULT_FLAGS \
321         (VM_READ | VM_WRITE | \
322         ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
323                  VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
324
325 /* VIRT <-> MACHINE conversion */
326 #define virt_to_machine(v)      (phys_to_machine(__pa(v)))
327 #define virt_to_mfn(v)          (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
328 #define mfn_to_virt(m)          (__va(mfn_to_pfn(m) << PAGE_SHIFT))
329
330 #endif /* __KERNEL__ */
331
332 #include <asm-generic/memory_model.h>
333 #include <asm-generic/page.h>
334
335 #endif /* _I386_PAGE_H */