4 /* PAGE_SHIFT determines the page size */
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)
15 #include <linux/config.h>
16 #include <linux/string.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
20 #include <xen/interface/xen.h>
21 #include <xen/features.h>
22 #include <xen/foreign_page.h>
24 #define arch_free_page(_page,_order) \
25 ({ int foreign = PageForeign(_page); \
27 (PageForeignDestructor(_page))(_page); \
30 #define HAVE_ARCH_FREE_PAGE
32 #ifdef CONFIG_XEN_SCRUB_PAGES
33 #define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
35 #define scrub_pages(_p,_n) ((void)0)
38 #ifdef CONFIG_X86_USE_3DNOW
42 #define clear_page(page) mmx_clear_page((void *)(page))
43 #define copy_page(to,from) mmx_copy_page(to,from)
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
51 * On older X86 processors it's not a win to use MMX here it seems.
55 #define clear_page(page) memset((void *)(page), 0, PAGE_SIZE)
56 #define copy_page(to,from) memcpy((void *)(to), (void *)(from), PAGE_SIZE)
60 #define clear_user_page(page, vaddr, pg) clear_page(page)
61 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
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)
68 extern unsigned long *phys_to_machine_mapping;
70 #undef machine_to_phys_mapping
71 extern unsigned long *machine_to_phys_mapping;
72 extern unsigned int machine_to_phys_order;
74 static inline unsigned long pfn_to_mfn(unsigned long pfn)
76 if (xen_feature(XENFEAT_auto_translated_physmap))
78 return phys_to_machine_mapping[(unsigned int)(pfn)] &
82 static inline int phys_to_machine_mapping_valid(unsigned long pfn)
84 if (xen_feature(XENFEAT_auto_translated_physmap))
86 return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
89 static inline unsigned long mfn_to_pfn(unsigned long mfn)
91 extern unsigned long max_mapnr;
94 if (xen_feature(XENFEAT_auto_translated_physmap))
97 if (unlikely((mfn >> machine_to_phys_order) != 0))
100 /* The array access can fail (e.g., device space beyond end of RAM). */
104 ".section .fixup,\"ax\"\n"
108 ".section __ex_table,\"a\"\n"
113 : "m" (machine_to_phys_mapping[mfn]), "m" (max_mapnr) );
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.
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.
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.
138 static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
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() */
149 static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
151 if (xen_feature(XENFEAT_auto_translated_physmap)) {
152 BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
155 phys_to_machine_mapping[pfn] = mfn;
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;
163 typedef unsigned long paddr_t;
164 typedef unsigned long maddr_t;
167 static inline maddr_t phys_to_machine(paddr_t phys)
169 maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
170 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
173 static inline paddr_t machine_to_phys(maddr_t machine)
175 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
176 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
181 * These are used to make use of C type-checking..
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)
199 unsigned long long ret;
202 ret = x.pte_low | (unsigned long long)x.pte_high << 32;
203 ret = machine_to_phys(ret) | 1;
209 static inline unsigned long long pmd_val(pmd_t x)
211 unsigned long long ret = x.pmd;
212 if (ret) ret = machine_to_phys(ret) | 1;
215 static inline unsigned long long pgd_val(pgd_t x)
217 unsigned long long ret = x.pgd;
218 if (ret) ret = machine_to_phys(ret) | 1;
221 static inline unsigned long long pte_val_ma(pte_t x)
223 return (unsigned long long)x.pte_high << 32 | x.pte_low;
225 #define HPAGE_SHIFT 21
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) : \
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)
240 unsigned long ret = x.pgd;
241 if (ret) ret = machine_to_phys(ret) | 1;
244 #define HPAGE_SHIFT 22
246 #define PTE_MASK PAGE_MASK
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
255 #define pgprot_val(x) ((x).pgprot)
257 #define __pte_ma(x) ((pte_t) { (x) } )
258 #define __pgprot(x) ((pgprot_t) { (x) } )
260 #endif /* !__ASSEMBLY__ */
262 /* to align the pointer to the (next) page boundary */
263 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
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
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.
274 * If you want more physical memory than this then see the CONFIG_HIGHMEM4G
275 * and CONFIG_HIGHMEM64G options in the kernel configuration.
281 * This much address space is reserved for vmalloc() and iomap()
282 * as well as fixmap mappings.
284 extern unsigned int __VMALLOC_RESERVE;
286 extern int sysctl_legacy_va_layout;
288 extern int devmem_is_allowed(unsigned long pagenr);
289 extern int page_is_ram(unsigned long pagenr);
291 #endif /* __ASSEMBLY__ */
294 #define __PAGE_OFFSET CONFIG_PAGE_OFFSET
295 #define __PHYSICAL_START CONFIG_PHYSICAL_START
297 #define __PAGE_OFFSET ((unsigned long)CONFIG_PAGE_OFFSET)
298 #define __PHYSICAL_START ((unsigned long)CONFIG_PHYSICAL_START)
300 #define __KERNEL_START (__PAGE_OFFSET + __PHYSICAL_START)
302 #ifdef CONFIG_XEN_COMPAT_030002
304 #define LOAD_OFFSET 0
305 #endif /* CONFIG_XEN_COMPAT_030002 */
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)
318 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
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)
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))
330 #endif /* __KERNEL__ */
332 #include <asm-generic/memory_model.h>
333 #include <asm-generic/page.h>
335 #endif /* _I386_PAGE_H */