cpu.c revision 1.80 1 /* $NetBSD: cpu.c,v 1.80 2012/02/13 23:54:58 jym Exp $ */
2 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp */
3
4 /*-
5 * Copyright (c) 2000 The NetBSD Foundation, Inc.
6 * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by RedBack Networks Inc.
11 *
12 * Author: Bill Sommerfeld
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 /*
37 * Copyright (c) 1999 Stefan Grefen
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by the NetBSD
50 * Foundation, Inc. and its contributors.
51 * 4. Neither the name of The NetBSD Foundation nor the names of its
52 * contributors may be used to endorse or promote products derived
53 * from this software without specific prior written permission.
54 *
55 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
56 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE.
66 */
67
68 #include <sys/cdefs.h>
69 __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.80 2012/02/13 23:54:58 jym Exp $");
70
71 #include "opt_ddb.h"
72 #include "opt_multiprocessor.h"
73 #include "opt_mpbios.h" /* for MPDEBUG */
74 #include "opt_mtrr.h"
75 #include "opt_xen.h"
76
77 #include "lapic.h"
78 #include "ioapic.h"
79
80 #include <sys/param.h>
81 #include <sys/proc.h>
82 #include <sys/systm.h>
83 #include <sys/device.h>
84 #include <sys/kmem.h>
85 #include <sys/cpu.h>
86 #include <sys/cpufreq.h>
87 #include <sys/atomic.h>
88 #include <sys/reboot.h>
89 #include <sys/idle.h>
90
91 #include <uvm/uvm.h>
92
93 #include <machine/cpufunc.h>
94 #include <machine/cpuvar.h>
95 #include <machine/pmap.h>
96 #include <machine/vmparam.h>
97 #include <machine/mpbiosvar.h>
98 #include <machine/pcb.h>
99 #include <machine/specialreg.h>
100 #include <machine/segments.h>
101 #include <machine/gdt.h>
102 #include <machine/mtrr.h>
103 #include <machine/pio.h>
104
105 #ifdef i386
106 #include <machine/npx.h>
107 #else
108 #include <machine/fpu.h>
109 #endif
110
111 #include <xen/xen.h>
112 #include <xen/xen-public/vcpu.h>
113 #include <xen/vcpuvar.h>
114
115 #if NLAPIC > 0
116 #include <machine/apicvar.h>
117 #include <machine/i82489reg.h>
118 #include <machine/i82489var.h>
119 #endif
120
121 #include <dev/ic/mc146818reg.h>
122 #include <dev/isa/isareg.h>
123
124 #if MAXCPUS > 32
125 #error cpu_info contains 32bit bitmasks
126 #endif
127
128 static int cpu_match(device_t, cfdata_t, void *);
129 static void cpu_attach(device_t, device_t, void *);
130 static void cpu_defer(device_t);
131 static int cpu_rescan(device_t, const char *, const int *);
132 static void cpu_childdetached(device_t, device_t);
133 static int vcpu_match(device_t, cfdata_t, void *);
134 static void vcpu_attach(device_t, device_t, void *);
135 static void cpu_attach_common(device_t, device_t, void *);
136 void cpu_offline_md(void);
137
138 struct cpu_softc {
139 device_t sc_dev; /* device tree glue */
140 struct cpu_info *sc_info; /* pointer to CPU info */
141 bool sc_wasonline;
142 };
143
144 int mp_cpu_start(struct cpu_info *, vaddr_t);
145 void mp_cpu_start_cleanup(struct cpu_info *);
146 const struct cpu_functions mp_cpu_funcs = { mp_cpu_start, NULL,
147 mp_cpu_start_cleanup };
148
149 CFATTACH_DECL2_NEW(cpu, sizeof(struct cpu_softc),
150 cpu_match, cpu_attach, NULL, NULL, cpu_rescan, cpu_childdetached);
151
152 CFATTACH_DECL_NEW(vcpu, sizeof(struct cpu_softc),
153 vcpu_match, vcpu_attach, NULL, NULL);
154
155 /*
156 * Statically-allocated CPU info for the primary CPU (or the only
157 * CPU, on uniprocessors). The CPU info list is initialized to
158 * point at it.
159 */
160 #ifdef TRAPLOG
161 #include <machine/tlog.h>
162 struct tlog tlog_primary;
163 #endif
164 struct cpu_info cpu_info_primary __aligned(CACHE_LINE_SIZE) = {
165 .ci_dev = 0,
166 .ci_self = &cpu_info_primary,
167 .ci_idepth = -1,
168 .ci_curlwp = &lwp0,
169 .ci_curldt = -1,
170 .ci_cpumask = 1,
171 #ifdef TRAPLOG
172 .ci_tlog = &tlog_primary,
173 #endif
174
175 };
176 struct cpu_info phycpu_info_primary __aligned(CACHE_LINE_SIZE) = {
177 .ci_dev = 0,
178 .ci_self = &phycpu_info_primary,
179 };
180
181 struct cpu_info *cpu_info_list = &cpu_info_primary;
182 struct cpu_info *phycpu_info_list = &phycpu_info_primary;
183
184 uint32_t cpus_attached = 1;
185 uint32_t cpus_running = 1;
186
187 uint32_t phycpus_attached = 0;
188 uint32_t phycpus_running = 0;
189
190 uint32_t cpu_feature[5]; /* X86 CPUID feature bits
191 * [0] basic features %edx
192 * [1] basic features %ecx
193 * [2] extended features %edx
194 * [3] extended features %ecx
195 * [4] VIA padlock features
196 */
197
198 bool x86_mp_online;
199 paddr_t mp_trampoline_paddr = MP_TRAMPOLINE;
200
201 #if defined(MULTIPROCESSOR)
202 void cpu_hatch(void *);
203 static void cpu_boot_secondary(struct cpu_info *ci);
204 static void cpu_start_secondary(struct cpu_info *ci);
205 #endif /* MULTIPROCESSOR */
206
207 static int
208 cpu_match(device_t parent, cfdata_t match, void *aux)
209 {
210
211 return 1;
212 }
213
214 static void
215 cpu_attach(device_t parent, device_t self, void *aux)
216 {
217 struct cpu_softc *sc = device_private(self);
218 struct cpu_attach_args *caa = aux;
219 struct cpu_info *ci;
220 uintptr_t ptr;
221 static int nphycpu = 0;
222
223 sc->sc_dev = self;
224
225 if (phycpus_attached == ~0) {
226 aprint_error(": increase MAXCPUS\n");
227 return;
228 }
229
230 /*
231 * If we're an Application Processor, allocate a cpu_info
232 * If we're the first attached CPU use the primary cpu_info,
233 * otherwise allocate a new one
234 */
235 aprint_naive("\n");
236 aprint_normal("\n");
237 if (nphycpu > 0) {
238 struct cpu_info *tmp;
239 ptr = (uintptr_t)kmem_zalloc(sizeof(*ci) + CACHE_LINE_SIZE - 1,
240 KM_SLEEP);
241 ci = (struct cpu_info *)roundup2(ptr, CACHE_LINE_SIZE);
242 ci->ci_curldt = -1;
243
244 tmp = phycpu_info_list;
245 while (tmp->ci_next)
246 tmp = tmp->ci_next;
247
248 tmp->ci_next = ci;
249 } else {
250 ci = &phycpu_info_primary;
251 }
252
253 ci->ci_self = ci;
254 sc->sc_info = ci;
255
256 ci->ci_dev = self;
257 ci->ci_acpiid = caa->cpu_id;
258 ci->ci_cpuid = caa->cpu_number;
259 ci->ci_vcpu = NULL;
260 ci->ci_index = nphycpu++;
261 ci->ci_cpumask = (1 << cpu_index(ci));
262
263 atomic_or_32(&phycpus_attached, ci->ci_cpumask);
264
265 if (!pmf_device_register(self, NULL, NULL))
266 aprint_error_dev(self, "couldn't establish power handler\n");
267
268 (void)config_defer(self, cpu_defer);
269 }
270
271 static void
272 cpu_defer(device_t self)
273 {
274 cpu_rescan(self, NULL, NULL);
275 }
276
277 static int
278 cpu_rescan(device_t self, const char *ifattr, const int *locators)
279 {
280 struct cpu_softc *sc = device_private(self);
281 struct cpufeature_attach_args cfaa;
282 struct cpu_info *ci = sc->sc_info;
283
284 memset(&cfaa, 0, sizeof(cfaa));
285 cfaa.ci = ci;
286
287 if (ifattr_match(ifattr, "cpufeaturebus")) {
288
289 if (ci->ci_frequency == NULL) {
290 cfaa.name = "frequency";
291 ci->ci_frequency = config_found_ia(self,
292 "cpufeaturebus", &cfaa, NULL);
293 }
294 }
295
296 return 0;
297 }
298
299 static void
300 cpu_childdetached(device_t self, device_t child)
301 {
302 struct cpu_softc *sc = device_private(self);
303 struct cpu_info *ci = sc->sc_info;
304
305 if (ci->ci_frequency == child)
306 ci->ci_frequency = NULL;
307 }
308
309 static int
310 vcpu_match(device_t parent, cfdata_t match, void *aux)
311 {
312 struct vcpu_attach_args *vcaa = aux;
313 struct vcpu_runstate_info vcr;
314 int error;
315
316 if (strcmp(vcaa->vcaa_name, match->cf_name) == 0) {
317 error = HYPERVISOR_vcpu_op(VCPUOP_get_runstate_info,
318 vcaa->vcaa_caa.cpu_number,
319 &vcr);
320 switch (error) {
321 case 0:
322 return 1;
323 case -ENOENT:
324 return 0;
325 default:
326 panic("Unknown hypervisor error %d returned on vcpu runstate probe\n", error);
327 }
328 }
329
330 return 0;
331 }
332
333 static void
334 vcpu_attach(device_t parent, device_t self, void *aux)
335 {
336 struct vcpu_attach_args *vcaa = aux;
337
338 KASSERT(vcaa->vcaa_caa.cpu_func == NULL);
339 vcaa->vcaa_caa.cpu_func = &mp_cpu_funcs;
340 cpu_attach_common(parent, self, &vcaa->vcaa_caa);
341
342 if (!pmf_device_register(self, NULL, NULL))
343 aprint_error_dev(self, "couldn't establish power handler\n");
344 }
345
346 static int
347 vcpu_is_up(struct cpu_info *ci)
348 {
349 KASSERT(ci != NULL);
350 return HYPERVISOR_vcpu_op(VCPUOP_is_up, ci->ci_cpuid, NULL);
351 }
352
353 static void
354 cpu_vm_init(struct cpu_info *ci)
355 {
356 int ncolors = 2, i;
357
358 for (i = CAI_ICACHE; i <= CAI_L2CACHE; i++) {
359 struct x86_cache_info *cai;
360 int tcolors;
361
362 cai = &ci->ci_cinfo[i];
363
364 tcolors = atop(cai->cai_totalsize);
365 switch(cai->cai_associativity) {
366 case 0xff:
367 tcolors = 1; /* fully associative */
368 break;
369 case 0:
370 case 1:
371 break;
372 default:
373 tcolors /= cai->cai_associativity;
374 }
375 ncolors = max(ncolors, tcolors);
376 }
377
378 /*
379 * Knowing the size of the largest cache on this CPU, potentially
380 * re-color our pages.
381 */
382 aprint_debug_dev(ci->ci_dev, "%d page colors\n", ncolors);
383 uvm_page_recolor(ncolors);
384 }
385
386 static void
387 cpu_attach_common(device_t parent, device_t self, void *aux)
388 {
389 struct cpu_softc *sc = device_private(self);
390 struct cpu_attach_args *caa = aux;
391 struct cpu_info *ci;
392 uintptr_t ptr;
393 int cpunum = caa->cpu_number;
394 static bool again = false;
395
396 sc->sc_dev = self;
397
398 /*
399 * If we're an Application Processor, allocate a cpu_info
400 * structure, otherwise use the primary's.
401 */
402 if (caa->cpu_role == CPU_ROLE_AP) {
403 aprint_naive(": Application Processor\n");
404 ptr = (uintptr_t)kmem_alloc(sizeof(*ci) + CACHE_LINE_SIZE - 1,
405 KM_SLEEP);
406 ci = (struct cpu_info *)roundup2(ptr, CACHE_LINE_SIZE);
407 memset(ci, 0, sizeof(*ci));
408 #ifdef TRAPLOG
409 ci->ci_tlog_base = kmem_zalloc(sizeof(struct tlog), KM_SLEEP);
410 #endif
411 } else {
412 aprint_naive(": %s Processor\n",
413 caa->cpu_role == CPU_ROLE_SP ? "Single" : "Boot");
414 ci = &cpu_info_primary;
415 }
416
417 ci->ci_self = ci;
418 sc->sc_info = ci;
419 ci->ci_dev = self;
420 ci->ci_cpuid = cpunum;
421
422 KASSERT(HYPERVISOR_shared_info != NULL);
423 ci->ci_vcpu = &HYPERVISOR_shared_info->vcpu_info[cpunum];
424
425 KASSERT(ci->ci_func == 0);
426 ci->ci_func = caa->cpu_func;
427
428 /* Must be called before mi_cpu_attach(). */
429 cpu_vm_init(ci);
430
431 if (caa->cpu_role == CPU_ROLE_AP) {
432 int error;
433
434 error = mi_cpu_attach(ci);
435
436 KASSERT(ci->ci_data.cpu_idlelwp != NULL);
437 if (error != 0) {
438 aprint_normal("\n");
439 aprint_error_dev(self,
440 "mi_cpu_attach failed with %d\n", error);
441 return;
442 }
443
444 } else {
445 KASSERT(ci->ci_data.cpu_idlelwp != NULL);
446 }
447
448 ci->ci_cpumask = (1 << cpu_index(ci));
449 pmap_reference(pmap_kernel());
450 ci->ci_pmap = pmap_kernel();
451 ci->ci_tlbstate = TLBSTATE_STALE;
452
453 /*
454 * Boot processor may not be attached first, but the below
455 * must be done to allow booting other processors.
456 */
457 if (!again) {
458 atomic_or_32(&ci->ci_flags, CPUF_PRESENT | CPUF_PRIMARY);
459 /* Basic init. */
460 cpu_intr_init(ci);
461 cpu_get_tsc_freq(ci);
462 cpu_init(ci);
463 pmap_cpu_init_late(ci);
464
465 /* Every processor needs to init it's own ipi h/w (similar to lapic) */
466 xen_ipi_init();
467 /* XXX: clock_init() */
468
469 /* Make sure DELAY() is initialized. */
470 DELAY(1);
471 again = true;
472 }
473
474 /* further PCB init done later. */
475
476 switch (caa->cpu_role) {
477 case CPU_ROLE_SP:
478 atomic_or_32(&ci->ci_flags, CPUF_SP);
479 cpu_identify(ci);
480 #if 0
481 x86_errata();
482 #endif
483 x86_cpu_idle_init();
484
485 break;
486
487 case CPU_ROLE_BP:
488 atomic_or_32(&ci->ci_flags, CPUF_BSP);
489 cpu_identify(ci);
490 cpu_init(ci);
491 #if 0
492 x86_errata();
493 #endif
494 x86_cpu_idle_init();
495
496 break;
497
498 case CPU_ROLE_AP:
499 atomic_or_32(&ci->ci_flags, CPUF_AP);
500
501 /*
502 * report on an AP
503 */
504
505 #if defined(MULTIPROCESSOR)
506 /* interrupt handler stack */
507 cpu_intr_init(ci);
508
509 /* Setup per-cpu memory for gdt */
510 gdt_alloc_cpu(ci);
511
512 pmap_cpu_init_late(ci);
513 cpu_start_secondary(ci);
514
515 if (ci->ci_flags & CPUF_PRESENT) {
516 struct cpu_info *tmp;
517
518 cpu_identify(ci);
519 tmp = cpu_info_list;
520 while (tmp->ci_next)
521 tmp = tmp->ci_next;
522
523 tmp->ci_next = ci;
524 }
525 #else
526 aprint_error(": not started\n");
527 #endif
528 break;
529
530 default:
531 aprint_normal("\n");
532 panic("unknown processor type??\n");
533 }
534
535 atomic_or_32(&cpus_attached, ci->ci_cpumask);
536
537 #ifdef MPVERBOSE
538 if (mp_verbose) {
539 struct lwp *l = ci->ci_data.cpu_idlelwp;
540 struct pcb *pcb = lwp_getpcb(l);
541
542 aprint_verbose_dev(self,
543 "idle lwp at %p, idle sp at 0x%p\n",
544 l,
545 #ifdef i386
546 (void *)pcb->pcb_esp
547 #else /* i386 */
548 (void *)pcb->pcb_rsp
549 #endif /* i386 */
550 );
551
552 }
553 #endif /* MPVERBOSE */
554 }
555
556 /*
557 * Initialize the processor appropriately.
558 */
559
560 void
561 cpu_init(struct cpu_info *ci)
562 {
563
564 /*
565 * On a P6 or above, enable global TLB caching if the
566 * hardware supports it.
567 */
568 if (cpu_feature[0] & CPUID_PGE)
569 lcr4(rcr4() | CR4_PGE); /* enable global TLB caching */
570
571 #ifdef XXXMTRR
572 /*
573 * On a P6 or above, initialize MTRR's if the hardware supports them.
574 */
575 if (cpu_feature[0] & CPUID_MTRR) {
576 if ((ci->ci_flags & CPUF_AP) == 0)
577 i686_mtrr_init_first();
578 mtrr_init_cpu(ci);
579 }
580 #endif
581 /*
582 * If we have FXSAVE/FXRESTOR, use them.
583 */
584 if (cpu_feature[0] & CPUID_FXSR) {
585 lcr4(rcr4() | CR4_OSFXSR);
586
587 /*
588 * If we have SSE/SSE2, enable XMM exceptions.
589 */
590 if (cpu_feature[0] & (CPUID_SSE|CPUID_SSE2))
591 lcr4(rcr4() | CR4_OSXMMEXCPT);
592 }
593
594 #ifdef __x86_64__
595 /* No user PGD mapped for this CPU yet */
596 ci->ci_xen_current_user_pgd = 0;
597 #endif
598
599 atomic_or_32(&cpus_running, ci->ci_cpumask);
600 atomic_or_32(&ci->ci_flags, CPUF_RUNNING);
601
602 /* XXX: register vcpu_register_runstate_memory_area, and figure out how to make sure this VCPU is running ? */
603 }
604
605
606 #ifdef MULTIPROCESSOR
607
608 void
609 cpu_boot_secondary_processors(void)
610 {
611 struct cpu_info *ci;
612 u_long i;
613 for (i = 0; i < maxcpus; i++) {
614 ci = cpu_lookup(i);
615 if (ci == NULL)
616 continue;
617 if (ci->ci_data.cpu_idlelwp == NULL)
618 continue;
619 if ((ci->ci_flags & CPUF_PRESENT) == 0)
620 continue;
621 if (ci->ci_flags & (CPUF_BSP|CPUF_SP|CPUF_PRIMARY))
622 continue;
623 cpu_boot_secondary(ci);
624 }
625
626 x86_mp_online = true;
627 }
628
629 static void
630 cpu_init_idle_lwp(struct cpu_info *ci)
631 {
632 struct lwp *l = ci->ci_data.cpu_idlelwp;
633 struct pcb *pcb = lwp_getpcb(l);
634
635 pcb->pcb_cr0 = rcr0();
636 }
637
638 void
639 cpu_init_idle_lwps(void)
640 {
641 struct cpu_info *ci;
642 u_long i;
643
644 for (i = 0; i < maxcpus; i++) {
645 ci = cpu_lookup(i);
646 if (ci == NULL)
647 continue;
648 if (ci->ci_data.cpu_idlelwp == NULL)
649 continue;
650 if ((ci->ci_flags & CPUF_PRESENT) == 0)
651 continue;
652 cpu_init_idle_lwp(ci);
653 }
654 }
655
656 static void
657 cpu_start_secondary(struct cpu_info *ci)
658 {
659 int i;
660
661 aprint_debug_dev(ci->ci_dev, "starting\n");
662
663 ci->ci_curlwp = ci->ci_data.cpu_idlelwp;
664
665 if (CPU_STARTUP(ci, (vaddr_t) cpu_hatch) != 0) {
666 return;
667 }
668
669 /*
670 * wait for it to become ready
671 */
672 for (i = 100000; (!(ci->ci_flags & CPUF_PRESENT)) && i > 0; i--) {
673 delay(10);
674 }
675 if ((ci->ci_flags & CPUF_PRESENT) == 0) {
676 aprint_error_dev(ci->ci_dev, "failed to become ready\n");
677 #if defined(MPDEBUG) && defined(DDB)
678 printf("dropping into debugger; continue from here to resume boot\n");
679 Debugger();
680 #endif
681 }
682
683 CPU_START_CLEANUP(ci);
684 }
685
686 void
687 cpu_boot_secondary(struct cpu_info *ci)
688 {
689 int i;
690 atomic_or_32(&ci->ci_flags, CPUF_GO);
691 for (i = 100000; (!(ci->ci_flags & CPUF_RUNNING)) && i > 0; i--) {
692 delay(10);
693 }
694 if ((ci->ci_flags & CPUF_RUNNING) == 0) {
695 aprint_error_dev(ci->ci_dev, "CPU failed to start\n");
696 #if defined(MPDEBUG) && defined(DDB)
697 printf("dropping into debugger; continue from here to resume boot\n");
698 Debugger();
699 #endif
700 }
701 }
702
703 /*
704 * APs end up here immediately after initialisation and VCPUOP_up in
705 * mp_cpu_start().
706 * At this point, we are running in the idle pcb/idle stack of the new
707 * CPU. This function jumps to the idle loop and starts looking for
708 * work.
709 */
710 extern void x86_64_tls_switch(struct lwp *);
711 void
712 cpu_hatch(void *v)
713 {
714 struct cpu_info *ci = (struct cpu_info *)v;
715 struct pcb *pcb;
716 int s, i;
717
718 /* Setup TLS and kernel GS/FS */
719 cpu_init_msrs(ci, true);
720 cpu_init_idt();
721 gdt_init_cpu(ci);
722
723 cpu_probe(ci);
724
725 atomic_or_32(&ci->ci_flags, CPUF_PRESENT);
726
727 while ((ci->ci_flags & CPUF_GO) == 0) {
728 /* Don't use delay, boot CPU may be patching the text. */
729 for (i = 10000; i != 0; i--)
730 x86_pause();
731 }
732
733 /* Because the text may have been patched in x86_patch(). */
734 x86_flush();
735 tlbflushg();
736
737 KASSERT((ci->ci_flags & CPUF_RUNNING) == 0);
738
739 pcb = lwp_getpcb(curlwp);
740 pcb->pcb_cr3 = pmap_pdirpa(pmap_kernel(), 0); /* XXX: consider using pmap_load() ? */
741 pcb = lwp_getpcb(ci->ci_data.cpu_idlelwp);
742
743 xen_ipi_init();
744
745 xen_initclocks();
746
747 /* XXX: lapic_initclocks(); */
748
749 #ifdef __x86_64__
750 fpuinit(ci);
751 #endif
752
753 lldt(GSEL(GLDT_SEL, SEL_KPL));
754
755 cpu_init(ci);
756 cpu_get_tsc_freq(ci);
757
758 s = splhigh();
759 x86_enable_intr();
760 splx(s);
761 #if 0
762 x86_errata();
763 #endif
764
765 aprint_debug_dev(ci->ci_dev, "running\n");
766
767 cpu_switchto(NULL, ci->ci_data.cpu_idlelwp, true);
768
769 panic("switch to idle_loop context returned!\n");
770 /* NOTREACHED */
771 }
772
773 #if defined(DDB)
774
775 #include <ddb/db_output.h>
776 #include <machine/db_machdep.h>
777
778 /*
779 * Dump CPU information from ddb.
780 */
781 void
782 cpu_debug_dump(void)
783 {
784 struct cpu_info *ci;
785 CPU_INFO_ITERATOR cii;
786
787 db_printf("addr dev id flags ipis curlwp fpcurlwp\n");
788 for (CPU_INFO_FOREACH(cii, ci)) {
789 db_printf("%p %s %ld %x %x %10p %10p\n",
790 ci,
791 ci->ci_dev == NULL ? "BOOT" : device_xname(ci->ci_dev),
792 (long)ci->ci_cpuid,
793 ci->ci_flags, ci->ci_ipis,
794 ci->ci_curlwp,
795 ci->ci_fpcurlwp);
796 }
797 }
798 #endif /* DDB */
799
800 #endif /* MULTIPROCESSOR */
801
802 extern void hypervisor_callback(void);
803 extern void failsafe_callback(void);
804 #ifdef __x86_64__
805 typedef void (vector)(void);
806 extern vector Xsyscall, Xsyscall32;
807 #endif
808
809 /*
810 * Setup the "trampoline". On Xen, we setup nearly all cpu context
811 * outside a trampoline, so we prototype and call targetip like so:
812 * void targetip(struct cpu_info *);
813 */
814
815 static void
816 gdt_prepframes(paddr_t *frames, vaddr_t base, uint32_t entries)
817 {
818 int i;
819 for (i = 0; i < roundup(entries, PAGE_SIZE) >> PAGE_SHIFT; i++) {
820
821 frames[i] = ((paddr_t) xpmap_ptetomach(
822 (pt_entry_t *) (base + (i << PAGE_SHIFT))))
823 >> PAGE_SHIFT;
824
825 /* Mark Read-only */
826 pmap_pte_clearbits(kvtopte(base + (i << PAGE_SHIFT)),
827 PG_RW);
828 }
829 }
830
831 #ifdef __x86_64__
832 extern char *ldtstore; /* XXX: Xen MP todo */
833
834 static void
835 xen_init_amd64_vcpuctxt(struct cpu_info *ci,
836 struct vcpu_guest_context *initctx,
837 void targetrip(struct cpu_info *))
838 {
839 /* page frames to point at GDT */
840 extern int gdt_size;
841 paddr_t frames[16];
842 psize_t gdt_ents;
843
844 struct lwp *l;
845 struct pcb *pcb;
846
847 volatile struct vcpu_info *vci;
848
849 KASSERT(ci != NULL);
850 KASSERT(ci != &cpu_info_primary);
851 KASSERT(initctx != NULL);
852 KASSERT(targetrip != NULL);
853
854 memset(initctx, 0, sizeof *initctx);
855
856 gdt_ents = roundup(gdt_size, PAGE_SIZE) >> PAGE_SHIFT; /* XXX: re-investigate roundup(gdt_size... ) for gdt_ents. */
857 KASSERT(gdt_ents <= 16);
858
859 gdt_prepframes(frames, (vaddr_t) ci->ci_gdt, gdt_ents);
860
861 /* XXX: The stuff in here is amd64 specific. move to mptramp.[Sc] ? */
862
863 /* Initialise the vcpu context: We use idle_loop()'s pcb context. */
864
865 l = ci->ci_data.cpu_idlelwp;
866
867 KASSERT(l != NULL);
868 pcb = lwp_getpcb(l);
869 KASSERT(pcb != NULL);
870
871 /* resume with interrupts off */
872 vci = ci->ci_vcpu;
873 vci->evtchn_upcall_mask = 1;
874 xen_mb();
875
876 /* resume in kernel-mode */
877 initctx->flags = VGCF_in_kernel | VGCF_online;
878
879 /* Stack and entry points:
880 * We arrange for the stack frame for cpu_hatch() to
881 * appear as a callee frame of lwp_trampoline(). Being a
882 * leaf frame prevents trampling on any of the MD stack setup
883 * that x86/vm_machdep.c:cpu_lwp_fork() does for idle_loop()
884 */
885
886 initctx->user_regs.rdi = (uint64_t) ci; /* targetrip(ci); */
887 initctx->user_regs.rip = (vaddr_t) targetrip;
888
889 initctx->user_regs.cs = GSEL(GCODE_SEL, SEL_KPL);
890
891 initctx->user_regs.rflags = pcb->pcb_flags;
892 initctx->user_regs.rsp = pcb->pcb_rsp;
893
894 /* Data segments */
895 initctx->user_regs.ss = GSEL(GDATA_SEL, SEL_KPL);
896 initctx->user_regs.es = GSEL(GDATA_SEL, SEL_KPL);
897 initctx->user_regs.ds = GSEL(GDATA_SEL, SEL_KPL);
898
899 /* GDT */
900 memcpy(initctx->gdt_frames, frames, sizeof frames);
901 initctx->gdt_ents = gdt_ents;
902
903 /* LDT */
904 initctx->ldt_base = (unsigned long) ldtstore;
905 initctx->ldt_ents = LDT_SIZE >> 3;
906
907 /* Kernel context state */
908 initctx->kernel_ss = GSEL(GDATA_SEL, SEL_KPL);
909 initctx->kernel_sp = pcb->pcb_rsp0;
910 initctx->ctrlreg[0] = pcb->pcb_cr0;
911 initctx->ctrlreg[1] = 0; /* "resuming" from kernel - no User cr3. */
912 initctx->ctrlreg[2] = pcb->pcb_cr2; /* XXX: */
913 /*
914 * Use pmap_kernel() L4 PD directly, until we setup the
915 * per-cpu L4 PD in pmap_cpu_init_late()
916 */
917 initctx->ctrlreg[3] = xen_pfn_to_cr3(x86_btop(xpmap_ptom(ci->ci_kpm_pdirpa)));
918 initctx->ctrlreg[4] = CR4_PAE | CR4_OSFXSR | CR4_OSXMMEXCPT;
919
920
921 /* Xen callbacks */
922 initctx->event_callback_eip = (unsigned long) hypervisor_callback;
923 initctx->failsafe_callback_eip = (unsigned long) failsafe_callback;
924 initctx->syscall_callback_eip = (unsigned long) Xsyscall;
925
926 return;
927 }
928 #else /* i386 */
929 extern union descriptor *ldt;
930 extern void Xsyscall(void);
931
932 static void
933 xen_init_i386_vcpuctxt(struct cpu_info *ci,
934 struct vcpu_guest_context *initctx,
935 void targeteip(struct cpu_info *))
936 {
937 /* page frames to point at GDT */
938 extern int gdt_size;
939 paddr_t frames[16];
940 psize_t gdt_ents;
941
942 struct lwp *l;
943 struct pcb *pcb;
944
945 volatile struct vcpu_info *vci;
946
947 KASSERT(ci != NULL);
948 KASSERT(ci != &cpu_info_primary);
949 KASSERT(initctx != NULL);
950 KASSERT(targeteip != NULL);
951
952 memset(initctx, 0, sizeof *initctx);
953
954 gdt_ents = roundup(gdt_size, PAGE_SIZE) >> PAGE_SHIFT; /* XXX: re-investigate roundup(gdt_size... ) for gdt_ents. */
955 KASSERT(gdt_ents <= 16);
956
957 gdt_prepframes(frames, (vaddr_t) ci->ci_gdt, gdt_ents);
958
959 /*
960 * Initialise the vcpu context:
961 * We use this cpu's idle_loop() pcb context.
962 */
963
964 l = ci->ci_data.cpu_idlelwp;
965
966 KASSERT(l != NULL);
967 pcb = lwp_getpcb(l);
968 KASSERT(pcb != NULL);
969
970 /* resume with interrupts off */
971 vci = ci->ci_vcpu;
972 vci->evtchn_upcall_mask = 1;
973 xen_mb();
974
975 /* resume in kernel-mode */
976 initctx->flags = VGCF_in_kernel | VGCF_online;
977
978 /* Stack frame setup for cpu_hatch():
979 * We arrange for the stack frame for cpu_hatch() to
980 * appear as a callee frame of lwp_trampoline(). Being a
981 * leaf frame prevents trampling on any of the MD stack setup
982 * that x86/vm_machdep.c:cpu_lwp_fork() does for idle_loop()
983 */
984
985 initctx->user_regs.esp = pcb->pcb_esp - 4; /* Leave word for
986 arg1 */
987 { /* targeteip(ci); */
988 uint32_t *arg = (uint32_t *) initctx->user_regs.esp;
989 arg[1] = (uint32_t) ci; /* arg1 */
990
991 }
992
993 initctx->user_regs.eip = (vaddr_t) targeteip;
994 initctx->user_regs.cs = GSEL(GCODE_SEL, SEL_KPL);
995 initctx->user_regs.eflags |= pcb->pcb_iopl;
996
997 /* Data segments */
998 initctx->user_regs.ss = GSEL(GDATA_SEL, SEL_KPL);
999 initctx->user_regs.es = GSEL(GDATA_SEL, SEL_KPL);
1000 initctx->user_regs.ds = GSEL(GDATA_SEL, SEL_KPL);
1001 initctx->user_regs.fs = GSEL(GDATA_SEL, SEL_KPL);
1002
1003 /* GDT */
1004 memcpy(initctx->gdt_frames, frames, sizeof frames);
1005 initctx->gdt_ents = gdt_ents;
1006
1007 /* LDT */
1008 initctx->ldt_base = (unsigned long) ldt;
1009 initctx->ldt_ents = NLDT;
1010
1011 /* Kernel context state */
1012 initctx->kernel_ss = GSEL(GDATA_SEL, SEL_KPL);
1013 initctx->kernel_sp = pcb->pcb_esp0;
1014 initctx->ctrlreg[0] = pcb->pcb_cr0;
1015 initctx->ctrlreg[1] = 0; /* "resuming" from kernel - no User cr3. */
1016 initctx->ctrlreg[2] = pcb->pcb_cr2; /* XXX: */
1017 #ifdef PAE
1018 initctx->ctrlreg[3] = xen_pfn_to_cr3(x86_btop(xpmap_ptom(ci->ci_pae_l3_pdirpa)));
1019 #else /* PAE */
1020 initctx->ctrlreg[3] = xen_pfn_to_cr3(x86_btop(xpmap_ptom(pcb->pcb_cr3)));
1021 #endif /* PAE */
1022 initctx->ctrlreg[4] = /* CR4_PAE | */CR4_OSFXSR | CR4_OSXMMEXCPT;
1023
1024
1025 /* Xen callbacks */
1026 initctx->event_callback_eip = (unsigned long) hypervisor_callback;
1027 initctx->event_callback_cs = GSEL(GCODE_SEL, SEL_KPL);
1028 initctx->failsafe_callback_eip = (unsigned long) failsafe_callback;
1029 initctx->failsafe_callback_cs = GSEL(GCODE_SEL, SEL_KPL);
1030
1031 return;
1032 }
1033 #endif /* __x86_64__ */
1034
1035 int
1036 mp_cpu_start(struct cpu_info *ci, vaddr_t target)
1037 {
1038
1039 int hyperror;
1040 struct vcpu_guest_context vcpuctx;
1041
1042 KASSERT(ci != NULL);
1043 KASSERT(ci != &cpu_info_primary);
1044 KASSERT(ci->ci_flags & CPUF_AP);
1045
1046 #ifdef __x86_64__
1047 xen_init_amd64_vcpuctxt(ci, &vcpuctx, (void (*)(struct cpu_info *))target);
1048 #else /* i386 */
1049 xen_init_i386_vcpuctxt(ci, &vcpuctx, (void (*)(struct cpu_info *))target);
1050 #endif /* __x86_64__ */
1051
1052 /* Initialise the given vcpu to execute cpu_hatch(ci); */
1053 if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_initialise, ci->ci_cpuid, &vcpuctx))) {
1054 aprint_error(": context initialisation failed. errno = %d\n", hyperror);
1055 return hyperror;
1056 }
1057
1058 /* Start it up */
1059
1060 /* First bring it down */
1061 if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_down, ci->ci_cpuid, NULL))) {
1062 aprint_error(": VCPUOP_down hypervisor command failed. errno = %d\n", hyperror);
1063 return hyperror;
1064 }
1065
1066 if ((hyperror = HYPERVISOR_vcpu_op(VCPUOP_up, ci->ci_cpuid, NULL))) {
1067 aprint_error(": VCPUOP_up hypervisor command failed. errno = %d\n", hyperror);
1068 return hyperror;
1069 }
1070
1071 if (!vcpu_is_up(ci)) {
1072 aprint_error(": did not come up\n");
1073 return -1;
1074 }
1075
1076 return 0;
1077 }
1078
1079 void
1080 mp_cpu_start_cleanup(struct cpu_info *ci)
1081 {
1082 #if 0
1083 /*
1084 * Ensure the NVRAM reset byte contains something vaguely sane.
1085 */
1086
1087 outb(IO_RTC, NVRAM_RESET);
1088 outb(IO_RTC+1, NVRAM_RESET_RST);
1089 #endif
1090 if (vcpu_is_up(ci)) {
1091 aprint_debug_dev(ci->ci_dev, "is started.\n");
1092 }
1093 else {
1094 aprint_error_dev(ci->ci_dev, "did not start up.\n");
1095 }
1096
1097 }
1098
1099 /* curcpu() uses %fs - shim for until cpu_init_msrs(), below */
1100 static struct cpu_info *cpu_primary(void)
1101 {
1102 return &cpu_info_primary;
1103 }
1104 /* XXX: rename to something more generic. users other than xpq exist */
1105 struct cpu_info * (*xpq_cpu)(void) = cpu_primary;
1106
1107 void
1108 cpu_init_msrs(struct cpu_info *ci, bool full)
1109 {
1110 #ifdef __x86_64__
1111 if (full) {
1112 HYPERVISOR_set_segment_base (SEGBASE_FS, 0);
1113 HYPERVISOR_set_segment_base (SEGBASE_GS_KERNEL, (uint64_t) ci);
1114 HYPERVISOR_set_segment_base (SEGBASE_GS_USER, 0);
1115 xpq_cpu = x86_curcpu;
1116 }
1117 #endif /* __x86_64__ */
1118
1119 if (cpu_feature[2] & CPUID_NOX)
1120 wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NXE);
1121
1122 }
1123
1124 void
1125 cpu_offline_md(void)
1126 {
1127 int s;
1128
1129 s = splhigh();
1130 #ifdef __i386__
1131 npxsave_cpu(true);
1132 #else
1133 fpusave_cpu(true);
1134 #endif
1135 splx(s);
1136 }
1137
1138 void
1139 cpu_get_tsc_freq(struct cpu_info *ci)
1140 {
1141 uint32_t vcpu_tversion;
1142 const volatile vcpu_time_info_t *tinfo = &ci->ci_vcpu->time;
1143
1144 vcpu_tversion = tinfo->version;
1145 while (tinfo->version == vcpu_tversion); /* Wait for a time update. XXX: timeout ? */
1146
1147 uint64_t freq = 1000000000ULL << 32;
1148 freq = freq / (uint64_t)tinfo->tsc_to_system_mul;
1149 if ( tinfo->tsc_shift < 0 )
1150 freq = freq << -tinfo->tsc_shift;
1151 else
1152 freq = freq >> tinfo->tsc_shift;
1153 ci->ci_data.cpu_cc_freq = freq;
1154 }
1155
1156 void
1157 x86_cpu_idle_xen(void)
1158 {
1159 struct cpu_info *ci = curcpu();
1160
1161 KASSERT(ci->ci_ilevel == IPL_NONE);
1162
1163 x86_disable_intr();
1164 if (!__predict_false(ci->ci_want_resched)) {
1165 idle_block();
1166 } else {
1167 x86_enable_intr();
1168 }
1169 }
1170
1171 /*
1172 * Loads pmap for the current CPU.
1173 */
1174 void
1175 cpu_load_pmap(struct pmap *pmap)
1176 {
1177 #ifdef i386
1178 #ifdef PAE
1179 int i, s;
1180 struct cpu_info *ci;
1181
1182 s = splvm(); /* just to be safe */
1183 ci = curcpu();
1184 paddr_t l3_pd = xpmap_ptom_masked(ci->ci_pae_l3_pdirpa);
1185 /* don't update the kernel L3 slot */
1186 for (i = 0 ; i < PDP_SIZE - 1; i++) {
1187 xpq_queue_pte_update(l3_pd + i * sizeof(pd_entry_t),
1188 xpmap_ptom(pmap->pm_pdirpa[i]) | PG_V);
1189 }
1190 splx(s);
1191 tlbflush();
1192 #else /* PAE */
1193 lcr3(pmap_pdirpa(pmap, 0));
1194 #endif /* PAE */
1195 #endif /* i386 */
1196
1197 #ifdef __x86_64__
1198 int i, s;
1199 pd_entry_t *new_pgd;
1200 struct cpu_info *ci;
1201 paddr_t l4_pd_ma;
1202
1203 ci = curcpu();
1204 l4_pd_ma = xpmap_ptom_masked(ci->ci_kpm_pdirpa);
1205
1206 /*
1207 * Map user space address in kernel space and load
1208 * user cr3
1209 */
1210 s = splvm();
1211 new_pgd = pmap->pm_pdir;
1212
1213 /* Copy user pmap L4 PDEs (in user addr. range) to per-cpu L4 */
1214 for (i = 0; i < PDIR_SLOT_PTE; i++) {
1215 xpq_queue_pte_update(l4_pd_ma + i * sizeof(pd_entry_t), new_pgd[i]);
1216 }
1217
1218 if (__predict_true(pmap != pmap_kernel())) {
1219 xen_set_user_pgd(pmap_pdirpa(pmap, 0));
1220 ci->ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
1221 }
1222 else {
1223 xpq_queue_pt_switch(l4_pd_ma);
1224 ci->ci_xen_current_user_pgd = 0;
1225 }
1226
1227 tlbflush();
1228 splx(s);
1229
1230 #endif /* __x86_64__ */
1231 }
1232
1233 /*
1234 * pmap_cpu_init_late: perform late per-CPU initialization.
1235 * Short note about percpu PDIR pages:
1236 * Both the PAE and __x86_64__ architectures have per-cpu PDIR
1237 * tables. This is to get around Xen's pagetable setup constraints for
1238 * PAE (multiple L3[3]s cannot point to the same L2 - Xen
1239 * will refuse to pin a table setup this way.) and for multiple cpus
1240 * to map in different user pmaps on __x86_64__ (see: cpu_load_pmap())
1241 *
1242 * What this means for us is that the PDIR of the pmap_kernel() is
1243 * considered to be a canonical "SHADOW" PDIR with the following
1244 * properties:
1245 * - Its recursive mapping points to itself
1246 * - per-cpu recurseive mappings point to themselves on __x86_64__
1247 * - per-cpu L4 pages' kernel entries are expected to be in sync with
1248 * the shadow
1249 */
1250
1251 void
1252 pmap_cpu_init_late(struct cpu_info *ci)
1253 {
1254 #if defined(PAE) || defined(__x86_64__)
1255 /*
1256 * The BP has already its own PD page allocated during early
1257 * MD startup.
1258 */
1259
1260 #if defined(__x86_64__)
1261 /* Setup per-cpu normal_pdes */
1262 int i;
1263 extern pd_entry_t * const normal_pdes[];
1264 for (i = 0;i < PTP_LEVELS - 1;i++) {
1265 ci->ci_normal_pdes[i] = normal_pdes[i];
1266 }
1267 #endif /* __x86_64__ */
1268
1269 if (ci == &cpu_info_primary)
1270 return;
1271
1272 KASSERT(ci != NULL);
1273
1274 #if defined(PAE)
1275 cpu_alloc_l3_page(ci);
1276 KASSERT(ci->ci_pae_l3_pdirpa != 0);
1277
1278 /* Initialise L2 entries 0 - 2: Point them to pmap_kernel() */
1279 int i;
1280 for (i = 0 ; i < PDP_SIZE - 1; i++) {
1281 ci->ci_pae_l3_pdir[i] =
1282 xpmap_ptom_masked(pmap_kernel()->pm_pdirpa[i]) | PG_V;
1283 }
1284 #endif /* PAE */
1285
1286 ci->ci_kpm_pdir = (pd_entry_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
1287 UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
1288
1289 if (ci->ci_kpm_pdir == NULL) {
1290 panic("%s: failed to allocate L4 per-cpu PD for CPU %d\n",
1291 __func__, cpu_index(ci));
1292 }
1293 ci->ci_kpm_pdirpa = vtophys((vaddr_t) ci->ci_kpm_pdir);
1294 KASSERT(ci->ci_kpm_pdirpa != 0);
1295
1296 #if defined(__x86_64__)
1297 /*
1298 * Copy over the pmap_kernel() shadow L4 entries
1299 */
1300
1301 memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir, PAGE_SIZE);
1302
1303 /* Recursive kernel mapping */
1304 ci->ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_k | PG_V;
1305 #elif defined(PAE)
1306 /* Copy over the pmap_kernel() shadow L2 entries that map the kernel */
1307 memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir + PDIR_SLOT_KERN, nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
1308 #endif /* __x86_64__ else PAE */
1309
1310 /* Xen wants R/O */
1311 pmap_kenter_pa((vaddr_t)ci->ci_kpm_pdir, ci->ci_kpm_pdirpa,
1312 VM_PROT_READ, 0);
1313
1314 #if defined(PAE)
1315 /* Initialise L3 entry 3. This mapping is shared across all
1316 * pmaps and is static, ie; loading a new pmap will not update
1317 * this entry.
1318 */
1319
1320 ci->ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_k | PG_V;
1321
1322 /* Mark L3 R/O (Xen wants this) */
1323 pmap_kenter_pa((vaddr_t)ci->ci_pae_l3_pdir, ci->ci_pae_l3_pdirpa,
1324 VM_PROT_READ, 0);
1325
1326 xpq_queue_pin_l3_table(xpmap_ptom_masked(ci->ci_pae_l3_pdirpa));
1327
1328 #elif defined(__x86_64__)
1329 xpq_queue_pin_l4_table(xpmap_ptom_masked(ci->ci_kpm_pdirpa));
1330 #endif /* PAE , __x86_64__ */
1331 #endif /* defined(PAE) || defined(__x86_64__) */
1332 }
1333
1334 /*
1335 * Notify all other cpus to halt.
1336 */
1337
1338 void
1339 cpu_broadcast_halt(void)
1340 {
1341 xen_broadcast_ipi(XEN_IPI_HALT);
1342 }
1343
1344 /*
1345 * Send a dummy ipi to a cpu.
1346 */
1347
1348 void
1349 cpu_kick(struct cpu_info *ci)
1350 {
1351 (void)xen_send_ipi(ci, XEN_IPI_KICK);
1352 }
1353