xenpmap.h revision 1.18 1 /* $NetBSD: xenpmap.h,v 1.18 2008/01/11 20:00:42 bouyer 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
38 #define INVALID_P2M_ENTRY (~0UL)
39
40 void xpq_queue_machphys_update(paddr_t, paddr_t);
41 void xpq_queue_invlpg(vaddr_t);
42 void xpq_queue_pde_update(pd_entry_t *, pd_entry_t);
43 void xpq_queue_pte_update(pt_entry_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(pt_entry_t *, pt_entry_t, int);
51
52 extern paddr_t *xpmap_phys_to_machine_mapping;
53
54 /*
55 * On Xen-2, the start of the day virual 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 virual memory starts
60 * at KERNBASE for domU as well.
61 */
62 #if defined(XEN3) && (defined(DOM0OPS) || !defined(XEN_COMPAT_030001))
63 #define XPMAP_OFFSET 0
64 #else
65 #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE)
66 #endif
67
68 static __inline paddr_t
69 xpmap_mtop(paddr_t mpa)
70 {
71 return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
72 XPMAP_OFFSET) | (mpa & ~PG_FRAME);
73 }
74
75 static __inline paddr_t
76 xpmap_mtop_masked(paddr_t mpa)
77 {
78 return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
79 XPMAP_OFFSET);
80 }
81
82 static __inline paddr_t
83 xpmap_ptom(paddr_t ppa)
84 {
85 return (xpmap_phys_to_machine_mapping[(ppa -
86 XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT)
87 | (ppa & ~PG_FRAME);
88 }
89
90 static __inline paddr_t
91 xpmap_ptom_masked(paddr_t ppa)
92 {
93 return (xpmap_phys_to_machine_mapping[(ppa -
94 XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT);
95 }
96
97 #ifdef XEN3
98 static inline void
99 MULTI_update_va_mapping(
100 multicall_entry_t *mcl, vaddr_t va,
101 paddr_t new_val, unsigned long flags)
102 {
103 mcl->op = __HYPERVISOR_update_va_mapping;
104 mcl->args[0] = va;
105 #if defined(__x86_64__)
106 mcl->args[1] = new_val;
107 mcl->args[2] = flags;
108 #else
109 mcl->args[1] = new_val;
110 mcl->args[2] = 0;
111 mcl->args[3] = flags;
112 #endif
113 }
114
115 static inline void
116 MULTI_update_va_mapping_otherdomain(
117 multicall_entry_t *mcl, vaddr_t va,
118 paddr_t new_val, unsigned long flags, domid_t domid)
119 {
120 mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
121 mcl->args[0] = va;
122 #if defined(__x86_64__)
123 mcl->args[1] = new_val;
124 mcl->args[2] = flags;
125 mcl->args[3] = domid;
126 #else
127 mcl->args[1] = new_val;
128 mcl->args[2] = 0;
129 mcl->args[3] = flags;
130 mcl->args[4] = domid;
131 #endif
132 }
133 #if defined(__x86_64__)
134 #define MULTI_UVMFLAGS_INDEX 2
135 #define MULTI_UVMDOMID_INDEX 3
136 #else
137 #define MULTI_UVMFLAGS_INDEX 3
138 #define MULTI_UVMDOMID_INDEX 4
139 #endif
140
141 #if defined(__x86_64__)
142 void xen_set_user_pgd(paddr_t);
143 #endif
144
145 #endif /* XEN3 */
146
147 #endif /* _XEN_XENPMAP_H_ */
148