2 * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3 * Copyright (c) 2013 Roger Pau Monné <roger.pau@citrix.com>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
34 #include <sys/kernel.h>
40 #include <machine/intr_machdep.h>
41 #include <x86/apicvar.h>
43 #include <machine/cpu.h>
44 #include <machine/smp.h>
46 #include <xen/xen-os.h>
47 #include <xen/hypervisor.h>
49 #include <xen/interface/vcpu.h>
51 static int xenpv_probe(void);
52 static int xenpv_probe_cpus(void);
53 static int xenpv_setup_local(void);
54 static int xenpv_setup_io(void);
56 static struct apic_enumerator xenpv_enumerator = {
65 * This enumerator will only be registered on PVH
74 * Test each possible vCPU in order to find the number of vCPUs
77 xenpv_probe_cpus(void)
82 for (i = 0; i < MAXCPU; i++) {
83 ret = HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL);
85 lapic_create((i * 2), (i == 0));
92 * Initialize the vCPU id of the BSP
95 xenpv_setup_local(void)
103 * On PVH guests there's no IO APIC
112 xenpv_register(void *dummy __unused)
114 if (xen_pv_domain()) {
115 apic_register_enumerator(&xenpv_enumerator);
118 SYSINIT(xenpv_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, xenpv_register, NULL);
121 * Setup per-CPU vCPU IDs
124 xenpv_set_ids(void *dummy)
134 SYSINIT(xenpv_set_ids, SI_SUB_CPU, SI_ORDER_MIDDLE, xenpv_set_ids, NULL);