xenpmap.h revision 1.23 1 /* $NetBSD: xenpmap.h,v 1.23 2009/07/29 12:02:06 cegger Exp $ */
2
3 /*
4 *
5 * Copyright (c) 2004 Christian Limpach.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Christian Limpach.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35 #ifndef _XEN_XENPMAP_H_
36 #define _XEN_XENPMAP_H_
37 #include "opt_xen.h"
38
39 #define INVALID_P2M_ENTRY (~0UL)
40
41 void xpq_queue_machphys_update(paddr_t, paddr_t);
42 void xpq_queue_invlpg(vaddr_t);
43 void xpq_queue_pte_update(paddr_t, pt_entry_t);
44 void xpq_queue_pt_switch(paddr_t);
45 void xpq_flush_queue(void);
46 void xpq_queue_set_ldt(vaddr_t, uint32_t);
47 void xpq_queue_tlb_flush(void);
48 void xpq_queue_pin_table(paddr_t);
49 void xpq_queue_unpin_table(paddr_t);
50 int xpq_update_foreign(paddr_t, pt_entry_t, int);
51
52 extern unsigned long *xpmap_phys_to_machine_mapping;
53
54 /*
55 * On Xen-2, the start of the day virtual memory starts at KERNTEXTOFF
56 * (0xc0100000). On Xen-3 for domain0 it starts at KERNBASE (0xc0000000).
57 * So the offset between physical and virtual address is different on
58 * Xen-2 and Xen-3 for domain0.
59 * starting with xen-3.0.2, we can add notes so that virtual memory starts
60 * at KERNBASE for domU as well.
61 */
62 #if defined(DOM0OPS) || !defined(XEN_COMPAT_030001)
63 #define XPMAP_OFFSET 0
64 #else
65 #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE)
66 #endif
67
68 #define mfn_to_pfn(mfn) (machine_to_phys_mapping[(mfn)])
69 #define pfn_to_mfn(pfn) (xpmap_phys_to_machine_mapping[(pfn)])
70
71 static __inline paddr_t
72 xpmap_mtop(paddr_t mpa)
73 {
74 return (
75 ((paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT)
76 + XPMAP_OFFSET) | (mpa & ~PG_FRAME);
77 }
78
79 static __inline paddr_t
80 xpmap_mtop_masked(paddr_t mpa)
81 {
82 return (
83 ((paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT)
84 + XPMAP_OFFSET);
85 }
86
87 static __inline paddr_t
88 xpmap_ptom(paddr_t ppa)
89 {
90 return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
91 XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT)
92 | (ppa & ~PG_FRAME);
93 }
94
95 static __inline paddr_t
96 xpmap_ptom_masked(paddr_t ppa)
97 {
98 return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
99 XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT);
100 }
101
102 static inline void
103 MULTI_update_va_mapping(
104 multicall_entry_t *mcl, vaddr_t va,
105 pt_entry_t new_val, unsigned long flags)
106 {
107 mcl->op = __HYPERVISOR_update_va_mapping;
108 mcl->args[0] = va;
109 #if defined(__x86_64__)
110 mcl->args[1] = new_val;
111 mcl->args[2] = flags;
112 #else
113 mcl->args[1] = (new_val & 0xffffffff);
114 #ifdef PAE
115 mcl->args[2] = (new_val >> 32);
116 #else
117 mcl->args[2] = 0;
118 #endif
119 mcl->args[3] = flags;
120 #endif
121 }
122
123 static inline void
124 MULTI_update_va_mapping_otherdomain(
125 multicall_entry_t *mcl, vaddr_t va,
126 pt_entry_t new_val, unsigned long flags, domid_t domid)
127 {
128 mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
129 mcl->args[0] = va;
130 #if defined(__x86_64__)
131 mcl->args[1] = new_val;
132 mcl->args[2] = flags;
133 mcl->args[3] = domid;
134 #else
135 mcl->args[1] = (new_val & 0xffffffff);
136 #ifdef PAE
137 mcl->args[2] = (new_val >> 32);
138 #else
139 mcl->args[2] = 0;
140 #endif
141 mcl->args[3] = flags;
142 mcl->args[4] = domid;
143 #endif
144 }
145 #if defined(__x86_64__)
146 #define MULTI_UVMFLAGS_INDEX 2
147 #define MULTI_UVMDOMID_INDEX 3
148 #else
149 #define MULTI_UVMFLAGS_INDEX 3
150 #define MULTI_UVMDOMID_INDEX 4
151 #endif
152
153 #if defined(__x86_64__)
154 void xen_set_user_pgd(paddr_t);
155 #endif
156
157 #endif /* _XEN_XENPMAP_H_ */
158