xenpmap.h revision 1.7 1 1.7 yamt /* $NetBSD: xenpmap.h,v 1.7 2005/05/31 12:36:56 yamt 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 * 3. All advertising materials mentioning features or use of this software
17 1.1 cl * must display the following acknowledgement:
18 1.1 cl * This product includes software developed by Christian Limpach.
19 1.1 cl * 4. The name of the author may not be used to endorse or promote products
20 1.1 cl * derived from this software without specific prior written permission.
21 1.1 cl *
22 1.1 cl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 1.1 cl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 cl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 cl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 1.1 cl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 1.1 cl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 1.1 cl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 1.1 cl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 1.1 cl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 1.1 cl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 cl */
33 1.1 cl
34 1.1 cl
35 1.1 cl #ifndef _XEN_XENPMAP_H_
36 1.1 cl #define _XEN_XENPMAP_H_
37 1.1 cl
38 1.4 bouyer #define INVALID_P2M_ENTRY (~0UL)
39 1.4 bouyer
40 1.1 cl void xpq_queue_invlpg(vaddr_t);
41 1.1 cl void xpq_queue_pde_update(pd_entry_t *, pd_entry_t);
42 1.1 cl void xpq_queue_pte_update(pt_entry_t *, pt_entry_t);
43 1.3 cl void xpq_queue_unchecked_pte_update(pt_entry_t *, pt_entry_t);
44 1.1 cl void xpq_queue_pt_switch(paddr_t);
45 1.1 cl void xpq_flush_queue(void);
46 1.1 cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
47 1.1 cl void xpq_queue_tlb_flush(void);
48 1.1 cl void xpq_queue_pin_table(paddr_t, int);
49 1.1 cl void xpq_queue_unpin_table(paddr_t);
50 1.5 yamt int xpq_update_foreign(pt_entry_t *, pt_entry_t, int);
51 1.1 cl
52 1.1 cl extern paddr_t *xpmap_phys_to_machine_mapping;
53 1.1 cl
54 1.1 cl #define XPQ_PIN_L1_TABLE 1
55 1.1 cl #define XPQ_PIN_L2_TABLE 2
56 1.1 cl
57 1.1 cl #ifndef XEN
58 1.1 cl #define PDE_GET(_pdp) \
59 1.1 cl *(_pdp)
60 1.4 bouyer #define PDE_SET(_pdp,_mapdp,_npde) \
61 1.4 bouyer *(_mapdp) = (_npde)
62 1.4 bouyer #define PDE_CLEAR(_pdp,_mapdp) \
63 1.4 bouyer *(_mapdp) = 0
64 1.4 bouyer #define PTE_SET(_ptp,_maptp,_npte) \
65 1.4 bouyer *(_maptp) = (_npte)
66 1.4 bouyer #define PTE_CLEAR(_ptp,_maptp) \
67 1.4 bouyer *(_maptp) = 0
68 1.4 bouyer #define PTE_ATOMIC_SET(_ptp,_maptp,_npte,_opte) \
69 1.4 bouyer (_opte) = x86_atomic_testset_ul((_maptp), (_npte))
70 1.4 bouyer #define PTE_ATOMIC_CLEAR(_ptp,_maptp,_opte) \
71 1.4 bouyer (_opte) = x86_atomic_testset_ul((_maptp), 0)
72 1.4 bouyer #define PDE_CLEARBITS(_pdp,_mapdp,_bits) \
73 1.4 bouyer *(_mapdp) &= ~(_bits)
74 1.4 bouyer #define PTE_ATOMIC_CLEARBITS(_ptp,_maptp,_bits) \
75 1.4 bouyer x86_atomic_clearbits_l((_maptp), (_bits))
76 1.4 bouyer #define PTE_SETBITS(_ptp,_maptp,_bits) \
77 1.4 bouyer *(_maptp) |= (_bits)
78 1.4 bouyer #define PTE_ATOMIC_SETBITS(_ptp,_maptp,_bits) \
79 1.4 bouyer x86_atomic_setbits_l((_maptp), (_bits))
80 1.1 cl #else
81 1.1 cl paddr_t *xpmap_phys_to_machine_mapping;
82 1.1 cl
83 1.1 cl #define PDE_GET(_pdp) \
84 1.1 cl (pmap_valid_entry(*(_pdp)) ? xpmap_mtop(*(_pdp)) : *(_pdp))
85 1.4 bouyer #define PDE_SET(_pdp,_mapdp,_npde) do { \
86 1.7 yamt int _s = splvm(); \
87 1.4 bouyer xpq_queue_pde_update((_mapdp), xpmap_ptom((_npde))); \
88 1.1 cl xpq_flush_queue(); \
89 1.7 yamt splx(_s); \
90 1.1 cl } while (/*CONSTCOND*/0)
91 1.4 bouyer #define PDE_CLEAR(_pdp,_mapdp) do { \
92 1.7 yamt int _s = splvm(); \
93 1.4 bouyer xpq_queue_pde_update((_mapdp), 0); \
94 1.1 cl xpq_flush_queue(); \
95 1.7 yamt splx(_s); \
96 1.1 cl } while (/*CONSTCOND*/0)
97 1.1 cl #define PTE_GET(_ptp) \
98 1.1 cl (pmap_valid_entry(*(_ptp)) ? xpmap_mtop(*(_ptp)) : *(_ptp))
99 1.3 cl #define PTE_GET_MA(_ptp) \
100 1.3 cl *(_ptp)
101 1.4 bouyer #define PTE_SET(_ptp,_maptp,_npte) do { \
102 1.7 yamt int _s = splvm(); \
103 1.4 bouyer xpq_queue_pte_update((_maptp), xpmap_ptom((_npte))); \
104 1.1 cl xpq_flush_queue(); \
105 1.7 yamt splx(_s); \
106 1.1 cl } while (/*CONSTCOND*/0)
107 1.4 bouyer #define PTE_SET_MA(_ptp,_maptp,_npte) do { \
108 1.7 yamt int _s = splvm(); \
109 1.4 bouyer xpq_queue_pte_update((_maptp), (_npte)); \
110 1.1 cl xpq_flush_queue(); \
111 1.7 yamt splx(_s); \
112 1.1 cl } while (/*CONSTCOND*/0)
113 1.4 bouyer #define PTE_SET_MA_UNCHECKED(_ptp,_maptp,_npte) do { \
114 1.7 yamt _s = splvm(); \
115 1.4 bouyer xpq_queue_unchecked_pte_update((_maptp), (_npte)); \
116 1.3 cl xpq_flush_queue(); \
117 1.7 yamt splx(_s); \
118 1.3 cl } while (/*CONSTCOND*/0)
119 1.4 bouyer #define PTE_CLEAR(_ptp,_maptp) do { \
120 1.7 yamt int _s = splvm(); \
121 1.4 bouyer xpq_queue_pte_update((_maptp), 0); \
122 1.1 cl xpq_flush_queue(); \
123 1.7 yamt splx(_s); \
124 1.1 cl } while (/*CONSTCOND*/0)
125 1.4 bouyer #define PTE_ATOMIC_SET(_ptp,_maptp,_npte,_opte) do { \
126 1.7 yamt int _s; \
127 1.1 cl (_opte) = PTE_GET(_ptp); \
128 1.7 yamt _s = splvm(); \
129 1.4 bouyer xpq_queue_pte_update((_maptp), xpmap_ptom((_npte))); \
130 1.1 cl xpq_flush_queue(); \
131 1.7 yamt splx(_s); \
132 1.1 cl } while (/*CONSTCOND*/0)
133 1.4 bouyer #define PTE_ATOMIC_SET_MA(_ptp,_maptp,_npte,_opte) do { \
134 1.7 yamt int _s; \
135 1.3 cl (_opte) = *(_ptp); \
136 1.7 yamt _s = splvm(); \
137 1.4 bouyer xpq_queue_pte_update((_maptp), (_npte)); \
138 1.1 cl xpq_flush_queue(); \
139 1.7 yamt splx(_s); \
140 1.1 cl } while (/*CONSTCOND*/0)
141 1.4 bouyer #define PTE_ATOMIC_CLEAR(_ptp,_maptp,_opte) do { \
142 1.7 yamt int _s; \
143 1.1 cl (_opte) = PTE_GET(_ptp); \
144 1.7 yamt _s = splvm(); \
145 1.4 bouyer xpq_queue_pte_update((_maptp), 0); \
146 1.1 cl xpq_flush_queue(); \
147 1.7 yamt splx(_s); \
148 1.1 cl } while (/*CONSTCOND*/0)
149 1.4 bouyer #define PTE_ATOMIC_CLEAR_MA(_ptp,_maptp,_opte) do { \
150 1.7 yamt int _s; \
151 1.3 cl (_opte) = *(_ptp); \
152 1.7 yamt _s = splvm(); \
153 1.4 bouyer xpq_queue_pte_update((_maptp), 0); \
154 1.3 cl xpq_flush_queue(); \
155 1.7 yamt splx(_s); \
156 1.3 cl } while (/*CONSTCOND*/0)
157 1.4 bouyer #define PDE_CLEARBITS(_pdp,_mapdp,_bits) do { \
158 1.7 yamt int _s = splvm(); \
159 1.4 bouyer xpq_queue_pte_update((_mapdp), *(_pdp) & ~((_bits) & ~PG_FRAME)); \
160 1.1 cl xpq_flush_queue(); \
161 1.7 yamt splx(_s); \
162 1.1 cl } while (/*CONSTCOND*/0)
163 1.4 bouyer #define PTE_CLEARBITS(_ptp,_maptp,_bits) do { \
164 1.7 yamt int _s = splvm(); \
165 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) & ~((_bits) & ~PG_FRAME)); \
166 1.1 cl xpq_flush_queue(); \
167 1.7 yamt splx(_s); \
168 1.1 cl } while (/*CONSTCOND*/0)
169 1.4 bouyer #define PDE_ATOMIC_CLEARBITS(_pdp,_mapdp,_bits) do { \
170 1.7 yamt int _s = splvm(); \
171 1.4 bouyer xpq_queue_pde_update((_mapdp), *(_pdp) & ~((_bits) & ~PG_FRAME)); \
172 1.1 cl xpq_flush_queue(); \
173 1.7 yamt splx(_s); \
174 1.1 cl } while (/*CONSTCOND*/0)
175 1.4 bouyer #define PTE_ATOMIC_CLEARBITS(_ptp,_maptp,_bits) do { \
176 1.7 yamt int _s = splvm(); \
177 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) & ~((_bits) & ~PG_FRAME)); \
178 1.1 cl xpq_flush_queue(); \
179 1.7 yamt splx(_s); \
180 1.1 cl } while (/*CONSTCOND*/0)
181 1.4 bouyer #define PTE_SETBITS(_ptp,_maptp,_bits) do { \
182 1.7 yamt int _s = splvm(); \
183 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) | ((_bits) & ~PG_FRAME)); \
184 1.2 cl xpq_flush_queue(); \
185 1.7 yamt splx(_s); \
186 1.1 cl } while (/*CONSTCOND*/0)
187 1.4 bouyer #define PDE_ATOMIC_SETBITS(_pdp,_mapdp,_bits) do { \
188 1.7 yamt int _s = splvm(); \
189 1.4 bouyer xpq_queue_pde_update((_mapdp), *(_pdp) | ((_bits) & ~PG_FRAME)); \
190 1.1 cl xpq_flush_queue(); \
191 1.7 yamt splx(_s); \
192 1.1 cl } while (/*CONSTCOND*/0)
193 1.4 bouyer #define PTE_ATOMIC_SETBITS(_ptp,_maptp,_bits) do { \
194 1.7 yamt int _s = splvm(); \
195 1.4 bouyer xpq_queue_pte_update((_maptp), *(_ptp) | ((_bits) & ~PG_FRAME)); \
196 1.1 cl xpq_flush_queue(); \
197 1.7 yamt splx(_s); \
198 1.1 cl } while (/*CONSTCOND*/0)
199 1.4 bouyer #define PDE_COPY(_dpdp,_madpdp,_spdp) do { \
200 1.7 yamt int _s = splvm(); \
201 1.4 bouyer xpq_queue_pde_update((_madpdp), *(_spdp)); \
202 1.1 cl xpq_flush_queue(); \
203 1.7 yamt splx(_s); \
204 1.1 cl } while (/*CONSTCOND*/0)
205 1.1 cl #define PTE_UPDATES_FLUSH() do { \
206 1.7 yamt int _s = splvm(); \
207 1.1 cl xpq_flush_queue(); \
208 1.7 yamt splx(_s); \
209 1.1 cl } while (/*CONSTCOND*/0)
210 1.1 cl
211 1.1 cl #endif
212 1.1 cl
213 1.4 bouyer #define XPMAP_OFFSET (KERNTEXTOFF - KERNBASE_LOCORE)
214 1.1 cl static __inline paddr_t
215 1.1 cl xpmap_mtop(paddr_t mpa)
216 1.1 cl {
217 1.3 cl return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
218 1.4 bouyer XPMAP_OFFSET) | (mpa & ~PG_FRAME);
219 1.1 cl }
220 1.1 cl
221 1.1 cl static __inline paddr_t
222 1.1 cl xpmap_ptom(paddr_t ppa)
223 1.1 cl {
224 1.3 cl return (xpmap_phys_to_machine_mapping[(ppa -
225 1.4 bouyer XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT)
226 1.3 cl | (ppa & ~PG_FRAME);
227 1.3 cl }
228 1.3 cl
229 1.3 cl static __inline paddr_t
230 1.3 cl xpmap_ptom_masked(paddr_t ppa)
231 1.3 cl {
232 1.3 cl return (xpmap_phys_to_machine_mapping[(ppa -
233 1.4 bouyer XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT);
234 1.1 cl }
235 1.1 cl
236 1.1 cl #endif /* _XEN_XENPMAP_H_ */
237