xen_pmap.c revision 1.1.2.3 1 1.1.2.3 rmind /* $NetBSD: xen_pmap.c,v 1.1.2.3 2010/05/31 01:12:14 rmind Exp $ */
2 1.1.2.3 rmind
3 1.1.2.2 rmind /*
4 1.1.2.2 rmind * Copyright (c) 2007 Manuel Bouyer.
5 1.1.2.2 rmind *
6 1.1.2.2 rmind * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 rmind * modification, are permitted provided that the following conditions
8 1.1.2.2 rmind * are met:
9 1.1.2.2 rmind * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 rmind * documentation and/or other materials provided with the distribution.
14 1.1.2.2 rmind *
15 1.1.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1.2.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1.2.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.1.2.2 rmind * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1.2.2 rmind * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1.2.2 rmind * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1.2.2 rmind * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1.2.2 rmind * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1.2.2 rmind * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1.2.2 rmind * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1.2.2 rmind *
26 1.1.2.2 rmind */
27 1.1.2.2 rmind
28 1.1.2.2 rmind /*
29 1.1.2.2 rmind * Copyright (c) 2006 Mathieu Ropert <mro (at) adviseo.fr>
30 1.1.2.2 rmind *
31 1.1.2.2 rmind * Permission to use, copy, modify, and distribute this software for any
32 1.1.2.2 rmind * purpose with or without fee is hereby granted, provided that the above
33 1.1.2.2 rmind * copyright notice and this permission notice appear in all copies.
34 1.1.2.2 rmind *
35 1.1.2.2 rmind * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
36 1.1.2.2 rmind * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
37 1.1.2.2 rmind * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
38 1.1.2.2 rmind * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
39 1.1.2.2 rmind * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
40 1.1.2.2 rmind * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
41 1.1.2.2 rmind * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 1.1.2.2 rmind */
43 1.1.2.2 rmind
44 1.1.2.2 rmind /*
45 1.1.2.2 rmind *
46 1.1.2.2 rmind * Copyright (c) 1997 Charles D. Cranor and Washington University.
47 1.1.2.2 rmind * All rights reserved.
48 1.1.2.2 rmind *
49 1.1.2.2 rmind * Redistribution and use in source and binary forms, with or without
50 1.1.2.2 rmind * modification, are permitted provided that the following conditions
51 1.1.2.2 rmind * are met:
52 1.1.2.2 rmind * 1. Redistributions of source code must retain the above copyright
53 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer.
54 1.1.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
55 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer in the
56 1.1.2.2 rmind * documentation and/or other materials provided with the distribution.
57 1.1.2.2 rmind * 3. All advertising materials mentioning features or use of this software
58 1.1.2.2 rmind * must display the following acknowledgement:
59 1.1.2.2 rmind * This product includes software developed by Charles D. Cranor and
60 1.1.2.2 rmind * Washington University.
61 1.1.2.2 rmind * 4. The name of the author may not be used to endorse or promote products
62 1.1.2.2 rmind * derived from this software without specific prior written permission.
63 1.1.2.2 rmind *
64 1.1.2.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
65 1.1.2.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
66 1.1.2.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
67 1.1.2.2 rmind * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
68 1.1.2.2 rmind * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
69 1.1.2.2 rmind * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
70 1.1.2.2 rmind * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
71 1.1.2.2 rmind * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
72 1.1.2.2 rmind * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
73 1.1.2.2 rmind * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
74 1.1.2.2 rmind */
75 1.1.2.2 rmind
76 1.1.2.2 rmind /*
77 1.1.2.2 rmind * Copyright 2001 (c) Wasabi Systems, Inc.
78 1.1.2.2 rmind * All rights reserved.
79 1.1.2.2 rmind *
80 1.1.2.2 rmind * Written by Frank van der Linden for Wasabi Systems, Inc.
81 1.1.2.2 rmind *
82 1.1.2.2 rmind * Redistribution and use in source and binary forms, with or without
83 1.1.2.2 rmind * modification, are permitted provided that the following conditions
84 1.1.2.2 rmind * are met:
85 1.1.2.2 rmind * 1. Redistributions of source code must retain the above copyright
86 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer.
87 1.1.2.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
88 1.1.2.2 rmind * notice, this list of conditions and the following disclaimer in the
89 1.1.2.2 rmind * documentation and/or other materials provided with the distribution.
90 1.1.2.2 rmind * 3. All advertising materials mentioning features or use of this software
91 1.1.2.2 rmind * must display the following acknowledgement:
92 1.1.2.2 rmind * This product includes software developed for the NetBSD Project by
93 1.1.2.2 rmind * Wasabi Systems, Inc.
94 1.1.2.2 rmind * 4. The name of Wasabi Systems, Inc. may not be used to endorse
95 1.1.2.2 rmind * or promote products derived from this software without specific prior
96 1.1.2.2 rmind * written permission.
97 1.1.2.2 rmind *
98 1.1.2.2 rmind * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
99 1.1.2.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
100 1.1.2.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
101 1.1.2.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
102 1.1.2.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
103 1.1.2.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
104 1.1.2.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
105 1.1.2.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
106 1.1.2.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
107 1.1.2.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
108 1.1.2.2 rmind * POSSIBILITY OF SUCH DAMAGE.
109 1.1.2.2 rmind */
110 1.1.2.2 rmind
111 1.1.2.2 rmind #include <sys/cdefs.h>
112 1.1.2.3 rmind __KERNEL_RCSID(0, "$NetBSD: xen_pmap.c,v 1.1.2.3 2010/05/31 01:12:14 rmind Exp $");
113 1.1.2.2 rmind
114 1.1.2.2 rmind #include "opt_user_ldt.h"
115 1.1.2.2 rmind #include "opt_lockdebug.h"
116 1.1.2.2 rmind #include "opt_multiprocessor.h"
117 1.1.2.2 rmind #include "opt_xen.h"
118 1.1.2.2 rmind #if !defined(__x86_64__)
119 1.1.2.2 rmind #include "opt_kstack_dr0.h"
120 1.1.2.2 rmind #endif /* !defined(__x86_64__) */
121 1.1.2.2 rmind
122 1.1.2.2 rmind #include <sys/param.h>
123 1.1.2.2 rmind #include <sys/systm.h>
124 1.1.2.2 rmind #include <sys/proc.h>
125 1.1.2.2 rmind #include <sys/pool.h>
126 1.1.2.2 rmind #include <sys/kernel.h>
127 1.1.2.2 rmind #include <sys/atomic.h>
128 1.1.2.2 rmind #include <sys/cpu.h>
129 1.1.2.2 rmind #include <sys/intr.h>
130 1.1.2.2 rmind #include <sys/xcall.h>
131 1.1.2.2 rmind
132 1.1.2.2 rmind #include <uvm/uvm.h>
133 1.1.2.2 rmind
134 1.1.2.2 rmind #include <dev/isa/isareg.h>
135 1.1.2.2 rmind
136 1.1.2.2 rmind #include <machine/specialreg.h>
137 1.1.2.2 rmind #include <machine/gdt.h>
138 1.1.2.2 rmind #include <machine/isa_machdep.h>
139 1.1.2.2 rmind #include <machine/cpuvar.h>
140 1.1.2.2 rmind
141 1.1.2.2 rmind #include <x86/pmap.h>
142 1.1.2.2 rmind #include <x86/pmap_pv.h>
143 1.1.2.2 rmind
144 1.1.2.2 rmind #include <x86/i82489reg.h>
145 1.1.2.2 rmind #include <x86/i82489var.h>
146 1.1.2.2 rmind
147 1.1.2.2 rmind #ifdef XEN
148 1.1.2.2 rmind #include <xen/xen3-public/xen.h>
149 1.1.2.2 rmind #include <xen/hypervisor.h>
150 1.1.2.2 rmind #endif
151 1.1.2.2 rmind
152 1.1.2.2 rmind /* flag to be used for kernel mappings: PG_u on Xen/amd64, 0 otherwise */
153 1.1.2.2 rmind #if defined(XEN) && defined(__x86_64__)
154 1.1.2.2 rmind #define PG_k PG_u
155 1.1.2.2 rmind #else
156 1.1.2.2 rmind #define PG_k 0
157 1.1.2.2 rmind #endif
158 1.1.2.2 rmind
159 1.1.2.3 rmind #define COUNT(x) /* nothing */
160 1.1.2.3 rmind
161 1.1.2.3 rmind static pd_entry_t * const alternate_pdes[] = APDES_INITIALIZER;
162 1.1.2.3 rmind extern pd_entry_t * const normal_pdes[];
163 1.1.2.3 rmind
164 1.1.2.2 rmind extern paddr_t pmap_pa_start; /* PA of first physical page for this domain */
165 1.1.2.2 rmind extern paddr_t pmap_pa_end; /* PA of last physical page for this domain */
166 1.1.2.2 rmind
167 1.1.2.3 rmind void
168 1.1.2.3 rmind pmap_apte_flush(struct pmap *pmap)
169 1.1.2.3 rmind {
170 1.1.2.3 rmind
171 1.1.2.3 rmind KASSERT(kpreempt_disabled());
172 1.1.2.3 rmind
173 1.1.2.3 rmind /*
174 1.1.2.3 rmind * Flush the APTE mapping from all other CPUs that
175 1.1.2.3 rmind * are using the pmap we are using (who's APTE space
176 1.1.2.3 rmind * is the one we've just modified).
177 1.1.2.3 rmind *
178 1.1.2.3 rmind * XXXthorpej -- find a way to defer the IPI.
179 1.1.2.3 rmind */
180 1.1.2.3 rmind pmap_tlb_shootdown(pmap, (vaddr_t)-1LL, 0, TLBSHOOT_APTE);
181 1.1.2.3 rmind pmap_tlb_shootnow();
182 1.1.2.3 rmind }
183 1.1.2.3 rmind
184 1.1.2.3 rmind /*
185 1.1.2.3 rmind * Unmap the content of APDP PDEs
186 1.1.2.3 rmind */
187 1.1.2.3 rmind void
188 1.1.2.3 rmind pmap_unmap_apdp(void)
189 1.1.2.3 rmind {
190 1.1.2.3 rmind int i;
191 1.1.2.3 rmind
192 1.1.2.3 rmind for (i = 0; i < PDP_SIZE; i++) {
193 1.1.2.3 rmind pmap_pte_set(APDP_PDE+i, 0);
194 1.1.2.3 rmind #if defined (PAE)
195 1.1.2.3 rmind /* clear shadow entries too */
196 1.1.2.3 rmind pmap_pte_set(APDP_PDE_SHADOW+i, 0);
197 1.1.2.3 rmind #endif
198 1.1.2.3 rmind }
199 1.1.2.3 rmind }
200 1.1.2.3 rmind
201 1.1.2.3 rmind /*
202 1.1.2.3 rmind * pmap_map_ptes: map a pmap's PTEs into KVM and lock them in
203 1.1.2.3 rmind *
204 1.1.2.3 rmind * => we lock enough pmaps to keep things locked in
205 1.1.2.3 rmind * => must be undone with pmap_unmap_ptes before returning
206 1.1.2.3 rmind */
207 1.1.2.3 rmind
208 1.1.2.3 rmind void
209 1.1.2.3 rmind pmap_map_ptes(struct pmap *pmap, struct pmap **pmap2,
210 1.1.2.3 rmind pd_entry_t **ptepp, pd_entry_t * const **pdeppp)
211 1.1.2.3 rmind {
212 1.1.2.3 rmind pd_entry_t opde, npde;
213 1.1.2.3 rmind struct pmap *ourpmap;
214 1.1.2.3 rmind struct cpu_info *ci;
215 1.1.2.3 rmind struct lwp *l;
216 1.1.2.3 rmind bool iscurrent;
217 1.1.2.3 rmind uint64_t ncsw;
218 1.1.2.3 rmind int s;
219 1.1.2.3 rmind
220 1.1.2.3 rmind /* the kernel's pmap is always accessible */
221 1.1.2.3 rmind if (pmap == pmap_kernel()) {
222 1.1.2.3 rmind *pmap2 = NULL;
223 1.1.2.3 rmind *ptepp = PTE_BASE;
224 1.1.2.3 rmind *pdeppp = normal_pdes;
225 1.1.2.3 rmind return;
226 1.1.2.3 rmind }
227 1.1.2.3 rmind KASSERT(kpreempt_disabled());
228 1.1.2.3 rmind
229 1.1.2.3 rmind retry:
230 1.1.2.3 rmind l = curlwp;
231 1.1.2.3 rmind ncsw = l->l_ncsw;
232 1.1.2.3 rmind ourpmap = NULL;
233 1.1.2.3 rmind ci = curcpu();
234 1.1.2.3 rmind #if defined(__x86_64__)
235 1.1.2.3 rmind /*
236 1.1.2.3 rmind * curmap can only be pmap_kernel so at this point
237 1.1.2.3 rmind * pmap_is_curpmap is always false
238 1.1.2.3 rmind */
239 1.1.2.3 rmind iscurrent = 0;
240 1.1.2.3 rmind ourpmap = pmap_kernel();
241 1.1.2.3 rmind #else /* __x86_64__*/
242 1.1.2.3 rmind if (ci->ci_want_pmapload &&
243 1.1.2.3 rmind vm_map_pmap(&l->l_proc->p_vmspace->vm_map) == pmap) {
244 1.1.2.3 rmind pmap_load();
245 1.1.2.3 rmind if (l->l_ncsw != ncsw)
246 1.1.2.3 rmind goto retry;
247 1.1.2.3 rmind }
248 1.1.2.3 rmind iscurrent = pmap_is_curpmap(pmap);
249 1.1.2.3 rmind /* if curpmap then we are always mapped */
250 1.1.2.3 rmind if (iscurrent) {
251 1.1.2.3 rmind mutex_enter(pmap->pm_lock);
252 1.1.2.3 rmind *pmap2 = NULL;
253 1.1.2.3 rmind *ptepp = PTE_BASE;
254 1.1.2.3 rmind *pdeppp = normal_pdes;
255 1.1.2.3 rmind goto out;
256 1.1.2.3 rmind }
257 1.1.2.3 rmind ourpmap = ci->ci_pmap;
258 1.1.2.3 rmind #endif /* __x86_64__ */
259 1.1.2.3 rmind
260 1.1.2.3 rmind /* need to lock both curpmap and pmap: use ordered locking */
261 1.1.2.3 rmind pmap_reference(ourpmap);
262 1.1.2.3 rmind if ((uintptr_t) pmap < (uintptr_t) ourpmap) {
263 1.1.2.3 rmind mutex_enter(pmap->pm_lock);
264 1.1.2.3 rmind mutex_enter(ourpmap->pm_lock);
265 1.1.2.3 rmind } else {
266 1.1.2.3 rmind mutex_enter(ourpmap->pm_lock);
267 1.1.2.3 rmind mutex_enter(pmap->pm_lock);
268 1.1.2.3 rmind }
269 1.1.2.3 rmind
270 1.1.2.3 rmind if (l->l_ncsw != ncsw)
271 1.1.2.3 rmind goto unlock_and_retry;
272 1.1.2.3 rmind
273 1.1.2.3 rmind /* need to load a new alternate pt space into curpmap? */
274 1.1.2.3 rmind COUNT(apdp_pde_map);
275 1.1.2.3 rmind opde = *APDP_PDE;
276 1.1.2.3 rmind if (!pmap_valid_entry(opde) ||
277 1.1.2.3 rmind pmap_pte2pa(opde) != pmap_pdirpa(pmap, 0)) {
278 1.1.2.3 rmind int i;
279 1.1.2.3 rmind s = splvm();
280 1.1.2.3 rmind /* Make recursive entry usable in user PGD */
281 1.1.2.3 rmind for (i = 0; i < PDP_SIZE; i++) {
282 1.1.2.3 rmind npde = pmap_pa2pte(
283 1.1.2.3 rmind pmap_pdirpa(pmap, i * NPDPG)) | PG_k | PG_V;
284 1.1.2.3 rmind xpq_queue_pte_update(
285 1.1.2.3 rmind xpmap_ptom(pmap_pdirpa(pmap, PDIR_SLOT_PTE + i)),
286 1.1.2.3 rmind npde);
287 1.1.2.3 rmind xpq_queue_pte_update(xpmap_ptetomach(&APDP_PDE[i]),
288 1.1.2.3 rmind npde);
289 1.1.2.3 rmind #ifdef PAE
290 1.1.2.3 rmind /* update shadow entry too */
291 1.1.2.3 rmind xpq_queue_pte_update(
292 1.1.2.3 rmind xpmap_ptetomach(&APDP_PDE_SHADOW[i]), npde);
293 1.1.2.3 rmind #endif /* PAE */
294 1.1.2.3 rmind xpq_queue_invlpg(
295 1.1.2.3 rmind (vaddr_t)&pmap->pm_pdir[PDIR_SLOT_PTE + i]);
296 1.1.2.3 rmind }
297 1.1.2.3 rmind if (pmap_valid_entry(opde))
298 1.1.2.3 rmind pmap_apte_flush(ourpmap);
299 1.1.2.3 rmind splx(s);
300 1.1.2.3 rmind }
301 1.1.2.3 rmind *pmap2 = ourpmap;
302 1.1.2.3 rmind *ptepp = APTE_BASE;
303 1.1.2.3 rmind *pdeppp = alternate_pdes;
304 1.1.2.3 rmind KASSERT(l->l_ncsw == ncsw);
305 1.1.2.3 rmind #if !defined(__x86_64__)
306 1.1.2.3 rmind out:
307 1.1.2.3 rmind #endif
308 1.1.2.3 rmind /*
309 1.1.2.3 rmind * might have blocked, need to retry?
310 1.1.2.3 rmind */
311 1.1.2.3 rmind if (l->l_ncsw != ncsw) {
312 1.1.2.3 rmind unlock_and_retry:
313 1.1.2.3 rmind if (ourpmap != NULL) {
314 1.1.2.3 rmind mutex_exit(ourpmap->pm_lock);
315 1.1.2.3 rmind pmap_destroy(ourpmap);
316 1.1.2.3 rmind }
317 1.1.2.3 rmind mutex_exit(pmap->pm_lock);
318 1.1.2.3 rmind goto retry;
319 1.1.2.3 rmind }
320 1.1.2.3 rmind }
321 1.1.2.3 rmind
322 1.1.2.3 rmind /*
323 1.1.2.3 rmind * pmap_unmap_ptes: unlock the PTE mapping of "pmap"
324 1.1.2.3 rmind */
325 1.1.2.3 rmind
326 1.1.2.3 rmind void
327 1.1.2.3 rmind pmap_unmap_ptes(struct pmap *pmap, struct pmap *pmap2)
328 1.1.2.3 rmind {
329 1.1.2.3 rmind
330 1.1.2.3 rmind if (pmap == pmap_kernel()) {
331 1.1.2.3 rmind return;
332 1.1.2.3 rmind }
333 1.1.2.3 rmind KASSERT(kpreempt_disabled());
334 1.1.2.3 rmind if (pmap2 == NULL) {
335 1.1.2.3 rmind mutex_exit(pmap->pm_lock);
336 1.1.2.3 rmind } else {
337 1.1.2.3 rmind #if defined(__x86_64__)
338 1.1.2.3 rmind KASSERT(pmap2 == pmap_kernel());
339 1.1.2.3 rmind #else
340 1.1.2.3 rmind KASSERT(curcpu()->ci_pmap == pmap2);
341 1.1.2.3 rmind #endif
342 1.1.2.3 rmind #if defined(MULTIPROCESSOR)
343 1.1.2.3 rmind pmap_unmap_apdp();
344 1.1.2.3 rmind pmap_pte_flush();
345 1.1.2.3 rmind pmap_apte_flush(pmap2);
346 1.1.2.3 rmind #endif /* MULTIPROCESSOR */
347 1.1.2.3 rmind COUNT(apdp_pde_unmap);
348 1.1.2.3 rmind mutex_exit(pmap->pm_lock);
349 1.1.2.3 rmind mutex_exit(pmap2->pm_lock);
350 1.1.2.3 rmind pmap_destroy(pmap2);
351 1.1.2.3 rmind }
352 1.1.2.3 rmind }
353 1.1.2.3 rmind
354 1.1.2.2 rmind int
355 1.1.2.2 rmind pmap_enter(struct pmap *pmap, vaddr_t va, paddr_t pa, vm_prot_t prot, u_int flags)
356 1.1.2.2 rmind {
357 1.1.2.2 rmind paddr_t ma;
358 1.1.2.2 rmind
359 1.1.2.2 rmind if (__predict_false(pa < pmap_pa_start || pmap_pa_end <= pa)) {
360 1.1.2.2 rmind ma = pa; /* XXX hack */
361 1.1.2.2 rmind } else {
362 1.1.2.2 rmind ma = xpmap_ptom(pa);
363 1.1.2.2 rmind }
364 1.1.2.2 rmind
365 1.1.2.2 rmind return pmap_enter_ma(pmap, va, ma, pa, prot, flags, DOMID_SELF);
366 1.1.2.2 rmind }
367 1.1.2.2 rmind
368 1.1.2.2 rmind /*
369 1.1.2.2 rmind * pmap_kenter_ma: enter a kernel mapping without R/M (pv_entry) tracking
370 1.1.2.2 rmind *
371 1.1.2.2 rmind * => no need to lock anything, assume va is already allocated
372 1.1.2.2 rmind * => should be faster than normal pmap enter function
373 1.1.2.2 rmind * => we expect a MACHINE address
374 1.1.2.2 rmind */
375 1.1.2.2 rmind
376 1.1.2.2 rmind void
377 1.1.2.2 rmind pmap_kenter_ma(vaddr_t va, paddr_t ma, vm_prot_t prot, u_int flags)
378 1.1.2.2 rmind {
379 1.1.2.2 rmind pt_entry_t *pte, opte, npte;
380 1.1.2.2 rmind
381 1.1.2.2 rmind if (va < VM_MIN_KERNEL_ADDRESS)
382 1.1.2.2 rmind pte = vtopte(va);
383 1.1.2.2 rmind else
384 1.1.2.2 rmind pte = kvtopte(va);
385 1.1.2.2 rmind
386 1.1.2.2 rmind npte = ma | ((prot & VM_PROT_WRITE) ? PG_RW : PG_RO) |
387 1.1.2.2 rmind PG_V | PG_k;
388 1.1.2.2 rmind if (flags & PMAP_NOCACHE)
389 1.1.2.2 rmind npte |= PG_N;
390 1.1.2.2 rmind
391 1.1.2.2 rmind if ((cpu_feature[2] & CPUID_NOX) && !(prot & VM_PROT_EXECUTE))
392 1.1.2.2 rmind npte |= PG_NX;
393 1.1.2.2 rmind
394 1.1.2.2 rmind opte = pmap_pte_testset (pte, npte); /* zap! */
395 1.1.2.2 rmind
396 1.1.2.2 rmind if (pmap_valid_entry(opte)) {
397 1.1.2.2 rmind #if defined(MULTIPROCESSOR)
398 1.1.2.2 rmind kpreempt_disable();
399 1.1.2.2 rmind pmap_tlb_shootdown(pmap_kernel(), va, opte, TLBSHOOT_KENTER);
400 1.1.2.2 rmind kpreempt_enable();
401 1.1.2.2 rmind #else
402 1.1.2.2 rmind /* Don't bother deferring in the single CPU case. */
403 1.1.2.2 rmind pmap_update_pg(va);
404 1.1.2.2 rmind #endif
405 1.1.2.2 rmind }
406 1.1.2.2 rmind }
407 1.1.2.2 rmind
408 1.1.2.2 rmind /*
409 1.1.2.2 rmind * pmap_extract_ma: extract a MA for the given VA
410 1.1.2.2 rmind */
411 1.1.2.2 rmind
412 1.1.2.2 rmind bool
413 1.1.2.2 rmind pmap_extract_ma(struct pmap *pmap, vaddr_t va, paddr_t *pap)
414 1.1.2.2 rmind {
415 1.1.2.2 rmind pt_entry_t *ptes, pte;
416 1.1.2.2 rmind pd_entry_t pde;
417 1.1.2.2 rmind pd_entry_t * const *pdes;
418 1.1.2.2 rmind struct pmap *pmap2;
419 1.1.2.2 rmind
420 1.1.2.2 rmind kpreempt_disable();
421 1.1.2.2 rmind pmap_map_ptes(pmap, &pmap2, &ptes, &pdes);
422 1.1.2.2 rmind if (!pmap_pdes_valid(va, pdes, &pde)) {
423 1.1.2.2 rmind pmap_unmap_ptes(pmap, pmap2);
424 1.1.2.2 rmind kpreempt_enable();
425 1.1.2.2 rmind return false;
426 1.1.2.2 rmind }
427 1.1.2.2 rmind
428 1.1.2.2 rmind pte = ptes[pl1_i(va)];
429 1.1.2.2 rmind pmap_unmap_ptes(pmap, pmap2);
430 1.1.2.2 rmind kpreempt_enable();
431 1.1.2.2 rmind
432 1.1.2.2 rmind if (__predict_true((pte & PG_V) != 0)) {
433 1.1.2.2 rmind if (pap != NULL)
434 1.1.2.2 rmind *pap = (pte & PG_FRAME) | (va & (NBPD_L1 - 1));
435 1.1.2.2 rmind return true;
436 1.1.2.2 rmind }
437 1.1.2.2 rmind
438 1.1.2.2 rmind return false;
439 1.1.2.2 rmind }
440