]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/x86/xen/pvcpu_enum.c
xen: change quality of the MADT ACPI enumerator
[FreeBSD/FreeBSD.git] / sys / x86 / xen / pvcpu_enum.c
1 /*-
2  * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
3  * Copyright (c) 2013 Roger Pau MonnĂ© <roger.pau@citrix.com>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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
25  * SUCH DAMAGE.
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/kernel.h>
35 #include <sys/smp.h>
36 #include <sys/pcpu.h>
37 #include <vm/vm.h>
38 #include <vm/pmap.h>
39
40 #include <machine/intr_machdep.h>
41 #include <x86/apicvar.h>
42
43 #include <machine/cpu.h>
44 #include <machine/smp.h>
45
46 #include <xen/xen-os.h>
47 #include <xen/hypervisor.h>
48
49 #include <xen/interface/vcpu.h>
50
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);
55
56 static struct apic_enumerator xenpv_enumerator = {
57         "Xen PV",
58         xenpv_probe,
59         xenpv_probe_cpus,
60         xenpv_setup_local,
61         xenpv_setup_io
62 };
63
64 /*
65  * This enumerator will only be registered on PVH
66  */
67 static int
68 xenpv_probe(void)
69 {
70         return (0);
71 }
72
73 /*
74  * Test each possible vCPU in order to find the number of vCPUs
75  */
76 static int
77 xenpv_probe_cpus(void)
78 {
79 #ifdef SMP
80         int i, ret;
81
82         for (i = 0; i < MAXCPU; i++) {
83                 ret = HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL);
84                 if (ret >= 0)
85                         lapic_create((i * 2), (i == 0));
86         }
87 #endif
88         return (0);
89 }
90
91 /*
92  * Initialize the vCPU id of the BSP
93  */
94 static int
95 xenpv_setup_local(void)
96 {
97         PCPU_SET(vcpu_id, 0);
98         lapic_init(0);
99         return (0);
100 }
101
102 /*
103  * On PVH guests there's no IO APIC
104  */
105 static int
106 xenpv_setup_io(void)
107 {
108         return (0);
109 }
110
111 static void
112 xenpv_register(void *dummy __unused)
113 {
114         if (xen_pv_domain()) {
115                 apic_register_enumerator(&xenpv_enumerator);
116         }
117 }
118 SYSINIT(xenpv_register, SI_SUB_TUNABLES - 1, SI_ORDER_FIRST, xenpv_register, NULL);
119
120 /*
121  * Setup per-CPU vCPU IDs
122  */
123 static void
124 xenpv_set_ids(void *dummy)
125 {
126         struct pcpu *pc;
127         int i;
128
129         CPU_FOREACH(i) {
130                 pc = pcpu_find(i);
131                 pc->pc_vcpu_id = i;
132         }
133 }
134 SYSINIT(xenpv_set_ids, SI_SUB_CPU, SI_ORDER_MIDDLE, xenpv_set_ids, NULL);