ia64/xen-unstable

view linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/maddr.h @ 11221:7c9d7fc3dce5

[HVM] Fix SMBIOS entry point copy destination.
Spotted by Xiaowei Yang <xiaowei.yang@intel.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@localhost.localdomain
date Sat Aug 19 12:06:36 2006 +0100 (2006-08-19)
parents 9c953e1b6fad
children ade94aa072c5
line source
1 #ifndef _X86_64_MADDR_H
2 #define _X86_64_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<<63)
10 #define FOREIGN_FRAME(m) ((m) | FOREIGN_FRAME_BIT)
12 #ifdef CONFIG_XEN
14 extern unsigned long *phys_to_machine_mapping;
16 #undef machine_to_phys_mapping
17 extern unsigned long *machine_to_phys_mapping;
18 extern unsigned int machine_to_phys_order;
20 static inline unsigned long pfn_to_mfn(unsigned long pfn)
21 {
22 if (xen_feature(XENFEAT_auto_translated_physmap))
23 return pfn;
24 return phys_to_machine_mapping[(unsigned int)(pfn)] &
25 ~FOREIGN_FRAME_BIT;
26 }
28 static inline int phys_to_machine_mapping_valid(unsigned long pfn)
29 {
30 if (xen_feature(XENFEAT_auto_translated_physmap))
31 return 1;
32 return (phys_to_machine_mapping[pfn] != INVALID_P2M_ENTRY);
33 }
35 static inline unsigned long mfn_to_pfn(unsigned long mfn)
36 {
37 unsigned long pfn;
39 if (xen_feature(XENFEAT_auto_translated_physmap))
40 return mfn;
42 if (unlikely((mfn >> machine_to_phys_order) != 0))
43 return end_pfn;
45 /* The array access can fail (e.g., device space beyond end of RAM). */
46 asm (
47 "1: movq %1,%0\n"
48 "2:\n"
49 ".section .fixup,\"ax\"\n"
50 "3: movq %2,%0\n"
51 " jmp 2b\n"
52 ".previous\n"
53 ".section __ex_table,\"a\"\n"
54 " .align 8\n"
55 " .quad 1b,3b\n"
56 ".previous"
57 : "=r" (pfn)
58 : "m" (machine_to_phys_mapping[mfn]), "m" (end_pfn) );
60 return pfn;
61 }
63 /*
64 * We detect special mappings in one of two ways:
65 * 1. If the MFN is an I/O page then Xen will set the m2p entry
66 * to be outside our maximum possible pseudophys range.
67 * 2. If the MFN belongs to a different domain then we will certainly
68 * not have MFN in our p2m table. Conversely, if the page is ours,
69 * then we'll have p2m(m2p(MFN))==MFN.
70 * If we detect a special mapping then it doesn't have a 'struct page'.
71 * We force !pfn_valid() by returning an out-of-range pointer.
72 *
73 * NB. These checks require that, for any MFN that is not in our reservation,
74 * there is no PFN such that p2m(PFN) == MFN. Otherwise we can get confused if
75 * we are foreign-mapping the MFN, and the other domain as m2p(MFN) == PFN.
76 * Yikes! Various places must poke in INVALID_P2M_ENTRY for safety.
77 *
78 * NB2. When deliberately mapping foreign pages into the p2m table, you *must*
79 * use FOREIGN_FRAME(). This will cause pte_pfn() to choke on it, as we
80 * require. In all the cases we care about, the FOREIGN_FRAME bit is
81 * masked (e.g., pfn_to_mfn()) so behaviour there is correct.
82 */
83 static inline unsigned long mfn_to_local_pfn(unsigned long mfn)
84 {
85 unsigned long pfn = mfn_to_pfn(mfn);
86 if ((pfn < end_pfn)
87 && !xen_feature(XENFEAT_auto_translated_physmap)
88 && (phys_to_machine_mapping[pfn] != mfn))
89 return end_pfn; /* force !pfn_valid() */
90 return pfn;
91 }
93 static inline void set_phys_to_machine(unsigned long pfn, unsigned long mfn)
94 {
95 if (xen_feature(XENFEAT_auto_translated_physmap)) {
96 BUG_ON(pfn != mfn && mfn != INVALID_P2M_ENTRY);
97 return;
98 }
99 phys_to_machine_mapping[pfn] = mfn;
100 }
102 #else /* !CONFIG_XEN */
104 #define pfn_to_mfn(pfn) (pfn)
105 #define mfn_to_pfn(mfn) (mfn)
106 #define mfn_to_local_pfn(mfn) (mfn)
107 #define set_phys_to_machine(pfn, mfn) BUG_ON((pfn) != (mfn))
108 #define phys_to_machine_mapping_valid(pfn) (1)
110 #endif /* !CONFIG_XEN */
112 /* Definitions for machine and pseudophysical addresses. */
113 typedef unsigned long paddr_t;
114 typedef unsigned long maddr_t;
116 static inline maddr_t phys_to_machine(paddr_t phys)
117 {
118 maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
119 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK);
120 return machine;
121 }
123 static inline paddr_t machine_to_phys(maddr_t machine)
124 {
125 paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
126 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
127 return phys;
128 }
130 /* VIRT <-> MACHINE conversion */
131 #define virt_to_machine(v) (phys_to_machine(__pa(v)))
132 #define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT))
133 #define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT))
135 #define __pte_ma(x) ((pte_t) { (x) } )
136 #define pfn_pte_ma(pfn, prot) __pte_ma((((pfn) << PAGE_SHIFT) | pgprot_val(prot)) & __supported_pte_mask)
138 #endif /* _X86_64_MADDR_H */