ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h @ 6538:84ee014ebd41

Merge xen-vtx-unstable.hg
author adsharma@los-vmm.sc.intel.com
date Wed Aug 17 12:34:38 2005 -0800 (2005-08-17)
parents 23979fb12c49 c31e1abf4df2
children 99914b54f7bf
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)]))
66 #ifdef CONFIG_X86_PAE
67 typedef unsigned long long physaddr_t;
68 #else
69 typedef unsigned long physaddr_t;
70 #endif
71 static inline physaddr_t phys_to_machine(physaddr_t phys)
72 {
73 physaddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
74 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
75 return machine;
76 }
77 static inline physaddr_t machine_to_phys(physaddr_t machine)
78 {
79 physaddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
80 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
81 return phys;
82 }
84 /*
85 * These are used to make use of C type-checking..
86 */
87 extern int nx_enabled;
88 #ifdef CONFIG_X86_PAE
89 extern unsigned long long __supported_pte_mask;
90 typedef struct { unsigned long pte_low, pte_high; } pte_t;
91 typedef struct { unsigned long long pmd; } pmd_t;
92 typedef struct { unsigned long long pgd; } pgd_t;
93 typedef struct { unsigned long long pgprot; } pgprot_t;
94 #define __pte(x) ({ unsigned long long _x = (x); \
95 if (_x & 1) _x = phys_to_machine(_x); \
96 ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
97 #define __pgd(x) ({ unsigned long long _x = (x); \
98 (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
99 #define __pmd(x) ({ unsigned long long _x = (x); \
100 (((_x)&1) ? ((pmd_t) {phys_to_machine(_x)}) : ((pmd_t) {(_x)})); })
101 static inline unsigned long long pte_val(pte_t x)
102 {
103 unsigned long long ret;
105 if (x.pte_low) {
106 ret = x.pte_low | (unsigned long long)x.pte_high << 32;
107 ret = machine_to_phys(ret) | 1;
108 } else {
109 ret = 0;
110 }
111 return ret;
112 }
113 static inline unsigned long long pmd_val(pmd_t x)
114 {
115 unsigned long long ret = x.pmd;
116 if (ret) ret = machine_to_phys(ret) | 1;
117 return ret;
118 }
119 static inline unsigned long long pgd_val(pgd_t x)
120 {
121 unsigned long long ret = x.pgd;
122 if (ret) ret = machine_to_phys(ret) | 1;
123 return ret;
124 }
125 static inline unsigned long long pte_val_ma(pte_t x)
126 {
127 return (unsigned long long)x.pte_high << 32 | x.pte_low;
128 }
129 #define HPAGE_SHIFT 21
130 #else
131 typedef struct { unsigned long pte_low; } pte_t;
132 typedef struct { unsigned long pgd; } pgd_t;
133 typedef struct { unsigned long pgprot; } pgprot_t;
134 #define boot_pte_t pte_t /* or would you rather have a typedef */
135 #define pte_val(x) (((x).pte_low & 1) ? machine_to_phys((x).pte_low) : \
136 (x).pte_low)
137 #define pte_val_ma(x) ((x).pte_low)
138 #define __pte(x) ({ unsigned long _x = (x); \
139 (((_x)&1) ? ((pte_t) {phys_to_machine(_x)}) : ((pte_t) {(_x)})); })
140 #define __pgd(x) ({ unsigned long _x = (x); \
141 (((_x)&1) ? ((pgd_t) {phys_to_machine(_x)}) : ((pgd_t) {(_x)})); })
142 static inline unsigned long pgd_val(pgd_t x)
143 {
144 unsigned long ret = x.pgd;
145 if (ret) ret = machine_to_phys(ret) | 1;
146 return ret;
147 }
148 #define HPAGE_SHIFT 22
149 #endif
150 #define PTE_MASK PAGE_MASK
152 #ifdef CONFIG_HUGETLB_PAGE
153 #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
154 #define HPAGE_MASK (~(HPAGE_SIZE - 1))
155 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
156 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
157 #endif
159 #define pgprot_val(x) ((x).pgprot)
161 #define __pte_ma(x) ((pte_t) { (x) } )
162 #define __pgprot(x) ((pgprot_t) { (x) } )
164 #endif /* !__ASSEMBLY__ */
166 /* to align the pointer to the (next) page boundary */
167 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
169 /*
170 * This handles the memory map.. We could make this a config
171 * option, but too many people screw it up, and too few need
172 * it.
173 *
174 * A __PAGE_OFFSET of 0xC0000000 means that the kernel has
175 * a virtual address space of one gigabyte, which limits the
176 * amount of physical memory you can use to about 950MB.
177 *
178 * If you want more physical memory than this then see the CONFIG_HIGHMEM4G
179 * and CONFIG_HIGHMEM64G options in the kernel configuration.
180 */
182 #ifndef __ASSEMBLY__
184 /*
185 * This much address space is reserved for vmalloc() and iomap()
186 * as well as fixmap mappings.
187 */
188 extern unsigned int __VMALLOC_RESERVE;
190 /* Pure 2^n version of get_order */
191 static __inline__ int get_order(unsigned long size)
192 {
193 int order;
195 size = (size-1) >> (PAGE_SHIFT-1);
196 order = -1;
197 do {
198 size >>= 1;
199 order++;
200 } while (size);
201 return order;
202 }
204 extern int sysctl_legacy_va_layout;
206 #endif /* __ASSEMBLY__ */
208 #ifdef __ASSEMBLY__
209 #define __PAGE_OFFSET (0xC0000000)
210 #else
211 #define __PAGE_OFFSET (0xC0000000UL)
212 #endif
215 #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
216 #define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE)
217 #define MAXMEM (HYPERVISOR_VIRT_START-__PAGE_OFFSET-__VMALLOC_RESERVE)
218 #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
219 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
220 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
221 #ifndef CONFIG_DISCONTIGMEM
222 #define pfn_to_page(pfn) (mem_map + (pfn))
223 #define page_to_pfn(page) ((unsigned long)((page) - mem_map))
224 #define pfn_valid(pfn) ((pfn) < max_mapnr)
225 #endif /* !CONFIG_DISCONTIGMEM */
226 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
228 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
230 #define VM_DATA_DEFAULT_FLAGS \
231 (VM_READ | VM_WRITE | \
232 ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
233 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
235 /* VIRT <-> MACHINE conversion */
236 #define virt_to_machine(_a) (phys_to_machine(__pa(_a)))
237 #define machine_to_virt(_m) (__va(machine_to_phys(_m)))
239 #endif /* __KERNEL__ */
241 #endif /* _I386_PAGE_H */