ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/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 56a63f9f378f
children f51fe43c5d1c 5f4724c13040 3a8f27c6d56c
line source
1 #ifndef _X86_64_PAGE_H
2 #define _X86_64_PAGE_H
4 #include <linux/config.h>
5 /* #include <linux/string.h> */
6 #ifndef __ASSEMBLY__
7 #include <linux/types.h>
8 #endif
9 #include <asm-xen/xen-public/xen.h>
10 #include <asm-xen/foreign_page.h>
12 #define arch_free_page(_page,_order) \
13 ({ int foreign = PageForeign(_page); \
14 if (foreign) \
15 (PageForeignDestructor(_page))(_page); \
16 foreign; \
17 })
18 #define HAVE_ARCH_FREE_PAGE
20 #ifdef CONFIG_XEN_SCRUB_PAGES
21 #define scrub_pages(_p,_n) memset((void *)(_p), 0, (_n) << PAGE_SHIFT)
22 #else
23 #define scrub_pages(_p,_n) ((void)0)
24 #endif
26 /* PAGE_SHIFT determines the page size */
27 #define PAGE_SHIFT 12
28 #ifdef __ASSEMBLY__
29 #define PAGE_SIZE (0x1 << PAGE_SHIFT)
30 #else
31 #define PAGE_SIZE (1UL << PAGE_SHIFT)
32 #endif
33 #define PAGE_MASK (~(PAGE_SIZE-1))
34 #define PHYSICAL_PAGE_MASK (~(PAGE_SIZE-1) & (__PHYSICAL_MASK << PAGE_SHIFT))
36 #define THREAD_ORDER 1
37 #ifdef __ASSEMBLY__
38 #define THREAD_SIZE (1 << (PAGE_SHIFT + THREAD_ORDER))
39 #else
40 #define THREAD_SIZE (1UL << (PAGE_SHIFT + THREAD_ORDER))
41 #endif
42 #define CURRENT_MASK (~(THREAD_SIZE-1))
44 #define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))
45 #define LARGE_PAGE_SIZE (1UL << PMD_SHIFT)
47 #define HPAGE_SHIFT PMD_SHIFT
48 #define HPAGE_SIZE ((1UL) << HPAGE_SHIFT)
49 #define HPAGE_MASK (~(HPAGE_SIZE - 1))
50 #define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT)
52 #ifdef __KERNEL__
53 #ifndef __ASSEMBLY__
55 void clear_page(void *);
56 void copy_page(void *, void *);
58 #define clear_user_page(page, vaddr, pg) clear_page(page)
59 #define copy_user_page(to, from, vaddr, pg) copy_page(to, from)
61 #define alloc_zeroed_user_highpage(vma, vaddr) alloc_page_vma(GFP_HIGHUSER | __GFP_ZERO, vma, vaddr)
62 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
64 /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
65 extern u32 *phys_to_machine_mapping;
66 #define pfn_to_mfn(_pfn) ((unsigned long) phys_to_machine_mapping[(unsigned int)(_pfn)])
67 #define mfn_to_pfn(_mfn) ((unsigned long) machine_to_phys_mapping[(unsigned int)(_mfn)])
69 /* Definitions for machine and pseudophysical addresses. */
70 typedef unsigned long paddr_t;
71 typedef unsigned long maddr_t;
73 static inline maddr_t phys_to_machine(paddr_t phys)
74 {
75 maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
76 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
77 return machine;
78 }
80 static inline paddr_t machine_to_phys(maddr_t machine)
81 {
82 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
83 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
84 return phys;
85 }
87 /*
88 * These are used to make use of C type-checking..
89 */
90 typedef struct { unsigned long pte; } pte_t;
91 typedef struct { unsigned long pmd; } pmd_t;
92 typedef struct { unsigned long pud; } pud_t;
93 typedef struct { unsigned long pgd; } pgd_t;
94 #define PTE_MASK PHYSICAL_PAGE_MASK
96 typedef struct { unsigned long pgprot; } pgprot_t;
98 #define pte_val(x) (((x).pte & 1) ? machine_to_phys((x).pte) : \
99 (x).pte)
100 #define pte_val_ma(x) ((x).pte)
102 static inline unsigned long pmd_val(pmd_t x)
103 {
104 unsigned long ret = x.pmd;
105 if (ret) ret = machine_to_phys(ret);
106 return ret;
107 }
109 static inline unsigned long pud_val(pud_t x)
110 {
111 unsigned long ret = x.pud;
112 if (ret) ret = machine_to_phys(ret);
113 return ret;
114 }
116 static inline unsigned long pgd_val(pgd_t x)
117 {
118 unsigned long ret = x.pgd;
119 if (ret) ret = machine_to_phys(ret);
120 return ret;
121 }
123 #define pgprot_val(x) ((x).pgprot)
125 #define __pte_ma(x) ((pte_t) { (x) } )
127 static inline pte_t __pte(unsigned long x)
128 {
129 if (x & 1) x = phys_to_machine(x);
130 return ((pte_t) { (x) });
131 }
133 static inline pmd_t __pmd(unsigned long x)
134 {
135 if ((x & 1)) x = phys_to_machine(x);
136 return ((pmd_t) { (x) });
137 }
139 static inline pud_t __pud(unsigned long x)
140 {
141 if ((x & 1)) x = phys_to_machine(x);
142 return ((pud_t) { (x) });
143 }
145 static inline pgd_t __pgd(unsigned long x)
146 {
147 if ((x & 1)) x = phys_to_machine(x);
148 return ((pgd_t) { (x) });
149 }
151 #define __pgprot(x) ((pgprot_t) { (x) } )
153 #define __START_KERNEL 0xffffffff80100000UL
154 #define __START_KERNEL_map 0xffffffff80000000UL
155 #define __PAGE_OFFSET 0xffff880000000000UL
157 #else
158 #define __START_KERNEL 0xffffffff80100000
159 #define __START_KERNEL_map 0xffffffff80000000
160 #define __PAGE_OFFSET 0xffff880000000000
161 #endif /* !__ASSEMBLY__ */
163 /* to align the pointer to the (next) page boundary */
164 #define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
166 /* See Documentation/x86_64/mm.txt for a description of the memory map. */
167 #define __PHYSICAL_MASK_SHIFT 46
168 #define __PHYSICAL_MASK ((1UL << __PHYSICAL_MASK_SHIFT) - 1)
169 #define __VIRTUAL_MASK_SHIFT 48
170 #define __VIRTUAL_MASK ((1UL << __VIRTUAL_MASK_SHIFT) - 1)
172 #define KERNEL_TEXT_SIZE (40UL*1024*1024)
173 #define KERNEL_TEXT_START 0xffffffff80000000UL
175 #ifndef __ASSEMBLY__
177 #include <asm/bug.h>
179 /* Pure 2^n version of get_order */
180 extern __inline__ int get_order(unsigned long size)
181 {
182 int order;
184 size = (size-1) >> (PAGE_SHIFT-1);
185 order = -1;
186 do {
187 size >>= 1;
188 order++;
189 } while (size);
190 return order;
191 }
193 #endif /* __ASSEMBLY__ */
195 #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)
197 /* Note: __pa(&symbol_visible_to_c) should be always replaced with __pa_symbol.
198 Otherwise you risk miscompilation. */
199 #define __pa(x) (((unsigned long)(x)>=__START_KERNEL_map)?(unsigned long)(x) - (unsigned long)__START_KERNEL_map:(unsigned long)(x) - PAGE_OFFSET)
200 /* __pa_symbol should be used for C visible symbols.
201 This seems to be the official gcc blessed way to do such arithmetic. */
202 #define __pa_symbol(x) \
203 ({unsigned long v; \
204 asm("" : "=r" (v) : "0" (x)); \
205 __pa(v); })
207 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
208 #ifndef CONFIG_DISCONTIGMEM
209 #define pfn_to_page(pfn) (mem_map + (pfn))
210 #define page_to_pfn(page) ((unsigned long)((page) - mem_map))
211 #define pfn_valid(pfn) ((pfn) < max_mapnr)
212 #endif
214 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
215 #define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
216 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
218 /* VIRT <-> MACHINE conversion */
219 #define virt_to_machine(v) (phys_to_machine(__pa(v)))
220 #define machine_to_virt(m) (__va(machine_to_phys(m)))
221 #define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
222 #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
224 #define VM_DATA_DEFAULT_FLAGS \
225 (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
226 VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
228 #define __HAVE_ARCH_GATE_AREA 1
230 #endif /* __KERNEL__ */
232 #endif /* _X86_64_PAGE_H */