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