ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h @ 6294:1a0723cd37f1

Fix many uses of machine addresses in XenLinux. Primarily
this fixes users of virt_to_machine/machine_to_virt to
use virt_to_mfn/mfn_to_virt where that is more appropriate.

This should be a big step to improved PAE stability.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Aug 19 16:06:43 2005 +0000 (2005-08-19)
parents c31e1abf4df2
children f51fe43c5d1c 5f4724c13040 81576d3d1ca8 3a8f27c6d56c
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 extern unsigned int *phys_to_machine_mapping;
64 #define pfn_to_mfn(_pfn) ((unsigned long)(phys_to_machine_mapping[(_pfn)]))
65 #define mfn_to_pfn(_mfn) ((unsigned long)(machine_to_phys_mapping[(_mfn)]))
67 /* Definitions for machine and pseudophysical addresses. */
68 #ifdef CONFIG_X86_PAE
69 typedef unsigned long long paddr_t;
70 typedef unsigned long long maddr_t;
71 #else
72 typedef unsigned long paddr_t;
73 typedef unsigned long maddr_t;
74 #endif
76 static inline maddr_t phys_to_machine(paddr_t phys)
77 {
78 maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
79 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
80 return machine;
81 }
82 static inline paddr_t machine_to_phys(maddr_t machine)
83 {
84 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
85 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
86 return phys;
87 }
89 /*
90 * These are used to make use of C type-checking..
91 */
92 extern int nx_enabled;
93 #ifdef CONFIG_X86_PAE
94 extern unsigned long long __supported_pte_mask;
95 typedef struct { unsigned long pte_low, pte_high; } pte_t;
96 typedef struct { unsigned long long pmd; } pmd_t;
97 typedef struct { unsigned long long pgd; } pgd_t;
98 typedef struct { unsigned long long pgprot; } pgprot_t;
99 #define __pte(x) ({ unsigned long long _x = (x); \
100 if (_x & 1) _x = phys_to_machine(_x); \
101 ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
102 #define __pgd(x) ({ unsigned long long _x = (x); \
103 (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
104 #define __pmd(x) ({ unsigned long long _x = (x); \
105 (((_x)&1) ? ((pmd_t) {phys_to_machine(_x)}) : ((pmd_t) {(_x)})); })
106 static inline unsigned long long pte_val(pte_t x)
107 {
108 unsigned long long ret;
110 if (x.pte_low) {
111 ret = x.pte_low | (unsigned long long)x.pte_high << 32;
112 ret = machine_to_phys(ret) | 1;
113 } else {
114 ret = 0;
115 }
116 return ret;
117 }
118 static inline unsigned long long pmd_val(pmd_t x)
119 {
120 unsigned long long ret = x.pmd;
121 if (ret) ret = machine_to_phys(ret) | 1;
122 return ret;
123 }
124 static inline unsigned long long pgd_val(pgd_t x)
125 {
126 unsigned long long ret = x.pgd;
127 if (ret) ret = machine_to_phys(ret) | 1;
128 return ret;
129 }
130 static inline unsigned long long pte_val_ma(pte_t x)
131 {
132 return (unsigned long long)x.pte_high << 32 | x.pte_low;
133 }
134 #define HPAGE_SHIFT 21
135 #else
136 typedef struct { unsigned long pte_low; } pte_t;
137 typedef struct { unsigned long pgd; } pgd_t;
138 typedef struct { unsigned long pgprot; } pgprot_t;
139 #define boot_pte_t pte_t /* or would you rather have a typedef */
140 #define pte_val(x) (((x).pte_low & 1) ? machine_to_phys((x).pte_low) : \
141 (x).pte_low)
142 #define pte_val_ma(x) ((x).pte_low)
143 #define __pte(x) ({ unsigned long _x = (x); \
144 (((_x)&1) ? ((pte_t) {phys_to_machine(_x)}) : ((pte_t) {(_x)})); })
145 #define __pgd(x) ({ unsigned long _x = (x); \
146 (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
147 static inline unsigned long pgd_val(pgd_t x)
148 {
149 unsigned long ret = x.pgd;
150 if (ret) ret = machine_to_phys(ret) | 1;
151 return ret;
152 }
153 #define HPAGE_SHIFT 22
154 #endif
155 #define PTE_MASK PAGE_MASK
157 #ifdef CONFIG_HUGETLB_PAGE
158 #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
159 #define HPAGE_MASK (~(HPAGE_SIZE - 1))
160 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
161 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
162 #endif
164 #define pgprot_val(x) ((x).pgprot)
166 #define __pte_ma(x) ((pte_t) { (x) } )
167 #define __pgprot(x) ((pgprot_t) { (x) } )
169 #endif /* !__ASSEMBLY__ */
171 /* to align the pointer to the (next) page boundary */
172 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
174 /*
175 * This handles the memory map.. We could make this a config
176 * option, but too many people screw it up, and too few need
177 * it.
178 *
179 * A __PAGE_OFFSET of 0xC0000000 means that the kernel has
180 * a virtual address space of one gigabyte, which limits the
181 * amount of physical memory you can use to about 950MB.
182 *
183 * If you want more physical memory than this then see the CONFIG_HIGHMEM4G
184 * and CONFIG_HIGHMEM64G options in the kernel configuration.
185 */
187 #ifndef __ASSEMBLY__
189 /*
190 * This much address space is reserved for vmalloc() and iomap()
191 * as well as fixmap mappings.
192 */
193 extern unsigned int __VMALLOC_RESERVE;
195 /* Pure 2^n version of get_order */
196 static __inline__ int get_order(unsigned long size)
197 {
198 int order;
200 size = (size-1) >> (PAGE_SHIFT-1);
201 order = -1;
202 do {
203 size >>= 1;
204 order++;
205 } while (size);
206 return order;
207 }
209 extern int sysctl_legacy_va_layout;
211 #endif /* __ASSEMBLY__ */
213 #ifdef __ASSEMBLY__
214 #define __PAGE_OFFSET (0xC0000000)
215 #else
216 #define __PAGE_OFFSET (0xC0000000UL)
217 #endif
220 #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
221 #define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE)
222 #define MAXMEM (HYPERVISOR_VIRT_START-__PAGE_OFFSET-__VMALLOC_RESERVE)
223 #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
224 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
225 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
226 #ifndef CONFIG_DISCONTIGMEM
227 #define pfn_to_page(pfn) (mem_map + (pfn))
228 #define page_to_pfn(page) ((unsigned long)((page) - mem_map))
229 #define pfn_valid(pfn) ((pfn) < max_mapnr)
230 #endif /* !CONFIG_DISCONTIGMEM */
231 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
233 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
235 #define VM_DATA_DEFAULT_FLAGS \
236 (VM_READ | VM_WRITE | \
237 ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
238 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
240 /* VIRT <-> MACHINE conversion */
241 #define virt_to_machine(v) (phys_to_machine(__pa(v)))
242 #define machine_to_virt(m) (__va(machine_to_phys(m)))
243 #define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
244 #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
246 #endif /* __KERNEL__ */
248 #endif /* _I386_PAGE_H */