xenpmap.h revision 1.35 1 1.35 jym /* $NetBSD: xenpmap.h,v 1.35 2012/06/24 18:31:52 jym Exp $ */
2 1.1 cl
3 1.1 cl /*
4 1.1 cl *
5 1.1 cl * Copyright (c) 2004 Christian Limpach.
6 1.1 cl * All rights reserved.
7 1.1 cl *
8 1.1 cl * Redistribution and use in source and binary forms, with or without
9 1.1 cl * modification, are permitted provided that the following conditions
10 1.1 cl * are met:
11 1.1 cl * 1. Redistributions of source code must retain the above copyright
12 1.1 cl * notice, this list of conditions and the following disclaimer.
13 1.1 cl * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cl * notice, this list of conditions and the following disclaimer in the
15 1.1 cl * documentation and/or other materials provided with the distribution.
16 1.1 cl *
17 1.1 cl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1 cl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 1.1 cl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 1.1 cl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 1.1 cl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 1.1 cl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 1.1 cl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 1.1 cl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 1.1 cl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 1.1 cl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 cl */
28 1.1 cl
29 1.1 cl
30 1.1 cl #ifndef _XEN_XENPMAP_H_
31 1.1 cl #define _XEN_XENPMAP_H_
32 1.26 mrg
33 1.26 mrg #ifdef _KERNEL_OPT
34 1.19 bouyer #include "opt_xen.h"
35 1.26 mrg #endif
36 1.1 cl
37 1.34 rmind #include <sys/types.h>
38 1.34 rmind #include <sys/kcpuset.h>
39 1.34 rmind
40 1.4 bouyer #define INVALID_P2M_ENTRY (~0UL)
41 1.4 bouyer
42 1.8 bouyer void xpq_queue_machphys_update(paddr_t, paddr_t);
43 1.1 cl void xpq_queue_invlpg(vaddr_t);
44 1.19 bouyer void xpq_queue_pte_update(paddr_t, pt_entry_t);
45 1.1 cl void xpq_queue_pt_switch(paddr_t);
46 1.1 cl void xpq_flush_queue(void);
47 1.1 cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
48 1.1 cl void xpq_queue_tlb_flush(void);
49 1.25 jym void xpq_queue_pin_table(paddr_t, int);
50 1.1 cl void xpq_queue_unpin_table(paddr_t);
51 1.19 bouyer int xpq_update_foreign(paddr_t, pt_entry_t, int);
52 1.34 rmind void xen_vcpu_mcast_invlpg(vaddr_t, vaddr_t, kcpuset_t *);
53 1.28 cherry void xen_vcpu_bcast_invlpg(vaddr_t, vaddr_t);
54 1.34 rmind void xen_mcast_tlbflush(kcpuset_t *);
55 1.28 cherry void xen_bcast_tlbflush(void);
56 1.34 rmind void xen_mcast_invlpg(vaddr_t, kcpuset_t *);
57 1.28 cherry void xen_bcast_invlpg(vaddr_t);
58 1.28 cherry
59 1.32 jym void pmap_xen_resume(void);
60 1.32 jym void pmap_xen_suspend(void);
61 1.35 jym void pmap_map_recursive_entries(void);
62 1.35 jym void pmap_unmap_recursive_entries(void);
63 1.1 cl
64 1.33 cherry #if defined(PAE) || defined(__x86_64__)
65 1.33 cherry void xen_kpm_sync(struct pmap *, int);
66 1.33 cherry #endif /* PAE || __x86_64__ */
67 1.33 cherry
68 1.25 jym #define xpq_queue_pin_l1_table(pa) \
69 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L1_TABLE)
70 1.25 jym #define xpq_queue_pin_l2_table(pa) \
71 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L2_TABLE)
72 1.25 jym #define xpq_queue_pin_l3_table(pa) \
73 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L3_TABLE)
74 1.25 jym #define xpq_queue_pin_l4_table(pa) \
75 1.25 jym xpq_queue_pin_table(pa, MMUEXT_PIN_L4_TABLE)
76 1.25 jym
77 1.19 bouyer extern unsigned long *xpmap_phys_to_machine_mapping;
78 1.1 cl
79 1.12 bouyer /*
80 1.20 jym * On Xen-2, the start of the day virtual memory starts at KERNTEXTOFF
81 1.12 bouyer * (0xc0100000). On Xen-3 for domain0 it starts at KERNBASE (0xc0000000).
82 1.12 bouyer * So the offset between physical and virtual address is different on
83 1.12 bouyer * Xen-2 and Xen-3 for domain0.
84 1.20 jym * starting with xen-3.0.2, we can add notes so that virtual memory starts
85 1.15 bouyer * at KERNBASE for domU as well.
86 1.12 bouyer */
87 1.23 cegger #if defined(DOM0OPS) || !defined(XEN_COMPAT_030001)
88 1.12 bouyer #define XPMAP_OFFSET 0
89 1.12 bouyer #else
90 1.9 yamt #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE)
91 1.12 bouyer #endif
92 1.12 bouyer
93 1.21 jym #define mfn_to_pfn(mfn) (machine_to_phys_mapping[(mfn)])
94 1.21 jym #define pfn_to_mfn(pfn) (xpmap_phys_to_machine_mapping[(pfn)])
95 1.21 jym
96 1.13 perry static __inline paddr_t
97 1.27 jym xpmap_mtop_masked(paddr_t mpa)
98 1.1 cl {
99 1.22 bouyer return (
100 1.22 bouyer ((paddr_t)machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT)
101 1.27 jym + XPMAP_OFFSET);
102 1.1 cl }
103 1.1 cl
104 1.13 perry static __inline paddr_t
105 1.27 jym xpmap_mtop(paddr_t mpa)
106 1.16 bouyer {
107 1.27 jym return (xpmap_mtop_masked(mpa) | (mpa & ~PG_FRAME));
108 1.16 bouyer }
109 1.16 bouyer
110 1.16 bouyer static __inline paddr_t
111 1.27 jym xpmap_ptom_masked(paddr_t ppa)
112 1.1 cl {
113 1.19 bouyer return (((paddr_t)xpmap_phys_to_machine_mapping[(ppa -
114 1.27 jym XPMAP_OFFSET) >> PAGE_SHIFT]) << PAGE_SHIFT);
115 1.3 cl }
116 1.3 cl
117 1.13 perry static __inline paddr_t
118 1.27 jym xpmap_ptom(paddr_t ppa)
119 1.3 cl {
120 1.27 jym return (xpmap_ptom_masked(ppa) | (ppa & ~PG_FRAME));
121 1.1 cl }
122 1.1 cl
123 1.14 bouyer static inline void
124 1.14 bouyer MULTI_update_va_mapping(
125 1.14 bouyer multicall_entry_t *mcl, vaddr_t va,
126 1.19 bouyer pt_entry_t new_val, unsigned long flags)
127 1.14 bouyer {
128 1.14 bouyer mcl->op = __HYPERVISOR_update_va_mapping;
129 1.14 bouyer mcl->args[0] = va;
130 1.14 bouyer #if defined(__x86_64__)
131 1.14 bouyer mcl->args[1] = new_val;
132 1.14 bouyer mcl->args[2] = flags;
133 1.14 bouyer #else
134 1.19 bouyer mcl->args[1] = (new_val & 0xffffffff);
135 1.19 bouyer #ifdef PAE
136 1.19 bouyer mcl->args[2] = (new_val >> 32);
137 1.19 bouyer #else
138 1.14 bouyer mcl->args[2] = 0;
139 1.19 bouyer #endif
140 1.14 bouyer mcl->args[3] = flags;
141 1.14 bouyer #endif
142 1.14 bouyer }
143 1.14 bouyer
144 1.14 bouyer static inline void
145 1.14 bouyer MULTI_update_va_mapping_otherdomain(
146 1.14 bouyer multicall_entry_t *mcl, vaddr_t va,
147 1.19 bouyer pt_entry_t new_val, unsigned long flags, domid_t domid)
148 1.14 bouyer {
149 1.14 bouyer mcl->op = __HYPERVISOR_update_va_mapping_otherdomain;
150 1.14 bouyer mcl->args[0] = va;
151 1.14 bouyer #if defined(__x86_64__)
152 1.14 bouyer mcl->args[1] = new_val;
153 1.14 bouyer mcl->args[2] = flags;
154 1.14 bouyer mcl->args[3] = domid;
155 1.14 bouyer #else
156 1.19 bouyer mcl->args[1] = (new_val & 0xffffffff);
157 1.19 bouyer #ifdef PAE
158 1.19 bouyer mcl->args[2] = (new_val >> 32);
159 1.19 bouyer #else
160 1.14 bouyer mcl->args[2] = 0;
161 1.19 bouyer #endif
162 1.14 bouyer mcl->args[3] = flags;
163 1.14 bouyer mcl->args[4] = domid;
164 1.14 bouyer #endif
165 1.14 bouyer }
166 1.14 bouyer #if defined(__x86_64__)
167 1.14 bouyer #define MULTI_UVMFLAGS_INDEX 2
168 1.14 bouyer #define MULTI_UVMDOMID_INDEX 3
169 1.14 bouyer #else
170 1.14 bouyer #define MULTI_UVMFLAGS_INDEX 3
171 1.14 bouyer #define MULTI_UVMDOMID_INDEX 4
172 1.14 bouyer #endif
173 1.14 bouyer
174 1.16 bouyer #if defined(__x86_64__)
175 1.16 bouyer void xen_set_user_pgd(paddr_t);
176 1.16 bouyer #endif
177 1.16 bouyer
178 1.1 cl #endif /* _XEN_XENPMAP_H_ */
179