ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/maddr.h @ 13341:3040ba0f2d3d

When booting via xm, only run the bootloader if it's in non-interactive mode:
otherwise we lose the user's named kernel and try to bootload the temporary
file pygrub returned.

Signed-off-by: John Levon <john.levon@sun.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Tue Jan 09 13:24:45 2007 +0000 (2007-01-09)
parents 50467f56ed65
children d2dff286994d
line source
1 #ifndef _I386_MADDR_H
2 #define _I386_MADDR_H
4 #include <xen/features.h>
5 #include <xen/interface/xen.h>
7 /**** MACHINE <-> PHYSICAL CONVERSION MACROS ****/
8 #define INVALID_P2M_ENTRY (~0UL)
9 #define FOREIGN_FRAME_BIT (1UL<<31)
10 #define FOREIGN_FRAME(m) ((m) | FOREIGN_FRAME_BIT)
12 /* Definitions for machine and pseudophysical addresses. */
13 #ifdef CONFIG_X86_PAE
14 typedef unsigned long long paddr_t;
15 typedef unsigned long long maddr_t;
16 #else
17 typedef unsigned long paddr_t;
18 typedef unsigned long maddr_t;
19 #endif
21 #ifdef CONFIG_XEN
23 extern unsigned long *phys_to_machine_mapping;
25 #undef machine_to_phys_mapping
26 extern unsigned long *machine_to_phys_mapping;
27 extern unsigned int machine_to_phys_order;
29 static inline unsigned long pfn_to_mfn(unsigned long pfn)
30 {
31 if (xen_feature(XENFEAT_auto_translated_physmap))
32 return pfn;
33 return phys_to_machine_mapping[(unsigned int)(pfn)] &
34 ~FOREIGN_FRAME_BIT;
35 }
37 static inline int phys_to_machine_mapping_valid(unsigned long pfn)
38 {
39 if (xen_feature(XENFEAT_auto_translated_physmap))
40 return 1;
41 return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
42 }
44 static inline unsigned long mfn_to_pfn(unsigned long mfn)
45 {
46 extern unsigned long max_mapnr;
47 unsigned long pfn;
49 if (xen_feature(XENFEAT_auto_translated_physmap))
50 return mfn;
52 if (unlikely((mfn >> machine_to_phys_order) != 0))
53 return max_mapnr;
55 /* The array access can fail (e.g., device space beyond end of RAM). */
56 asm (
57 "1: movl %1,%0\n"
58 "2:\n"
59 ".section .fixup,\"ax\"\n"
60 "3: movl %2,%0\n"
61 " jmp 2b\n"
62 ".previous\n"
63 ".section __ex_table,\"a\"\n"
64 " .align 4\n"
65 " .long 1b,3b\n"
66 ".previous"
67 : "=r" (pfn)
68 : "m" (machine_to_phys_mapping[mfn]), "m" (max_mapnr) );
70 return pfn;
71 }
73 /*
74 * We detect special mappings in one of two ways:
75 * 1. If the MFN is an I/O page then Xen will set the m2p entry
76 * to be outside our maximum possible pseudophys range.
77 * 2. If the MFN belongs to a different domain then we will certainly
78 * not have MFN in our p2m table. Conversely, if the page is ours,
79 * then we'll have p2m(m2p(MFN))==MFN.
80 * If we detect a special mapping then it doesn't have a 'struct page'.
81 * We force !pfn_valid() by returning an out-of-range pointer.
82 *
83 * NB. These checks require that, for any MFN that is not in our reservation,
84 * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
85 * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
86 * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
87 *
88 * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
89 * use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
90 * require. In all the cases we care about, the FOREIGN_FRAME bit is
91 * masked (e.g., pfn_to_mfn()) so behaviour there is correct.
92 */
93 static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
94 {
95 extern unsigned long max_mapnr;
96 unsigned long pfn = mfn_to_pfn(mfn);
97 if ((pfn < max_mapnr)
98 && !xen_feature(XENFEAT_auto_translated_physmap)
99 && (phys_to_machine_mapping[pfn] != mfn))
100 return max_mapnr; /* force !pfn_valid() */
101 return pfn;
102 }
104 static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
105 {
106 if (xen_feature(XENFEAT_auto_translated_physmap)) {
107 BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
108 return;
109 }
110 phys_to_machine_mapping[pfn] = mfn;
111 }
113 static inline maddr_t phys_to_machine(paddr_t phys)
114 {
115 maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
116 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
117 return machine;
118 }
120 static inline paddr_t machine_to_phys(maddr_t machine)
121 {
122 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
123 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
124 return phys;
125 }
127 static inline paddr_t pte_machine_to_phys(maddr_t machine)
128 {
129 /*
130 * In PAE mode, the NX bit needs to be dealt with in the value
131 * passed to mfn_to_pfn(). On x86_64, we need to mask it off,
132 * but for i386 the conversion to ulong for the argument will
133 * clip it off.
134 */
135 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
136 phys = (phys << PAGE_SHIFT) | (machine & ~PHYSICAL_PAGE_MASK);
137 return phys;
138 }
140 #else /* !CONFIG_XEN */
142 #define pfn_to_mfn(pfn) (pfn)
143 #define mfn_to_pfn(mfn) (mfn)
144 #define mfn_to_local_pfn(mfn) (mfn)
145 #define set_phys_to_machine(pfn, mfn) BUG_ON((pfn) != (mfn))
146 #define phys_to_machine_mapping_valid(pfn) (1)
147 #define phys_to_machine(phys) ((maddr_t)(phys))
148 #define machine_to_phys(mach) ((paddr_t)(mach))
149 #define pte_machine_to_phys(mach) ((paddr_t)(mach))
151 #endif /* !CONFIG_XEN */
153 /* VIRT <-> MACHINE conversion */
154 #define virt_to_machine(v) (phys_to_machine(__pa(v)))
155 #define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
156 #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
158 #ifdef CONFIG_X86_PAE
159 static inline pte_t pfn_pte_ma(unsigned long page_nr, pgprot_t pgprot)
160 {
161 pte_t pte;
163 pte.pte_high = (page_nr >> (32 - PAGE_SHIFT)) | \
164 (pgprot_val(pgprot) >> 32);
165 pte.pte_high &= (__supported_pte_mask >> 32);
166 pte.pte_low = ((page_nr << PAGE_SHIFT) | pgprot_val(pgprot)) & \
167 __supported_pte_mask;
168 return pte;
169 }
170 #else
171 #define pfn_pte_ma(pfn, prot) __pte_ma(((pfn) << PAGE_SHIFT) | pgprot_val(prot))
172 #endif
174 #define __pte_ma(x) ((pte_t) { (x) } )
176 #endif /* _I386_MADDR_H */