xen_mainbus.c revision 1.2 1 1.2 cherry /* $NetBSD: xen_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $ */
2 1.2 cherry /* NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp */
3 1.1 cherry /* NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp */
4 1.1 cherry
5 1.1 cherry /*
6 1.1 cherry * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
7 1.1 cherry *
8 1.1 cherry * Redistribution and use in source and binary forms, with or without
9 1.1 cherry * modification, are permitted provided that the following conditions
10 1.1 cherry * are met:
11 1.1 cherry * 1. Redistributions of source code must retain the above copyright
12 1.1 cherry * notice, this list of conditions and the following disclaimer.
13 1.1 cherry * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cherry * notice, this list of conditions and the following disclaimer in the
15 1.1 cherry * documentation and/or other materials provided with the distribution.
16 1.1 cherry * 3. All advertising materials mentioning features or use of this software
17 1.1 cherry * must display the following acknowledgement:
18 1.1 cherry * This product includes software developed by Christopher G. Demetriou
19 1.1 cherry * for the NetBSD Project.
20 1.1 cherry * 4. The name of the author may not be used to endorse or promote products
21 1.1 cherry * derived from this software without specific prior written permission
22 1.1 cherry *
23 1.1 cherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 cherry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 cherry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 cherry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 cherry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 cherry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 cherry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 cherry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 cherry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 cherry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 cherry */
34 1.1 cherry
35 1.1 cherry #include <sys/cdefs.h>
36 1.2 cherry __KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.2 2018/12/22 06:59:27 cherry Exp $");
37 1.1 cherry
38 1.1 cherry #include <sys/param.h>
39 1.1 cherry #include <sys/systm.h>
40 1.1 cherry #include <sys/device.h>
41 1.1 cherry
42 1.1 cherry #include <sys/bus.h>
43 1.1 cherry
44 1.1 cherry #include "hypervisor.h"
45 1.1 cherry #include "pci.h"
46 1.1 cherry
47 1.1 cherry #include "opt_xen.h"
48 1.1 cherry #include "opt_mpbios.h"
49 1.1 cherry #include "opt_pcifixup.h"
50 1.1 cherry
51 1.1 cherry #include "acpica.h"
52 1.1 cherry #include "ioapic.h"
53 1.1 cherry
54 1.1 cherry #include "ipmi.h"
55 1.1 cherry
56 1.1 cherry #include <machine/cpuvar.h>
57 1.1 cherry #include <machine/i82093var.h>
58 1.1 cherry
59 1.1 cherry #include <xen/xen.h>
60 1.1 cherry #include <xen/hypervisor.h>
61 1.1 cherry
62 1.1 cherry #if NIPMI > 0
63 1.1 cherry #include <x86/ipmivar.h>
64 1.1 cherry #endif
65 1.1 cherry
66 1.1 cherry #if NPCI > 0
67 1.1 cherry #include <dev/pci/pcivar.h>
68 1.1 cherry #if NACPICA > 0
69 1.1 cherry #include <dev/acpi/acpivar.h>
70 1.1 cherry #include <xen/mpacpi.h>
71 1.1 cherry #endif /* NACPICA > 0 */
72 1.1 cherry #ifdef MPBIOS
73 1.1 cherry #include <machine/mpbiosvar.h>
74 1.1 cherry #endif /* MPBIOS */
75 1.1 cherry #ifdef PCI_BUS_FIXUP
76 1.1 cherry #include <arch/x86/pci/pci_bus_fixup.h>
77 1.1 cherry #ifdef PCI_ADDR_FIXUP
78 1.1 cherry #include <arch/x86/pci/pci_addr_fixup.h>
79 1.1 cherry #endif
80 1.1 cherry #endif
81 1.1 cherry
82 1.1 cherry #if defined(MPBIOS) || NACPICA > 0
83 1.1 cherry struct mp_bus *mp_busses;
84 1.1 cherry int mp_nbus;
85 1.1 cherry struct mp_intr_map *mp_intrs;
86 1.1 cherry int mp_nintr;
87 1.1 cherry
88 1.1 cherry int mp_isa_bus = -1; /* XXX */
89 1.1 cherry int mp_eisa_bus = -1; /* XXX */
90 1.1 cherry
91 1.1 cherry bool acpi_present;
92 1.1 cherry bool mpacpi_active;
93 1.1 cherry #ifdef MPVERBOSE
94 1.1 cherry int mp_verbose = 1;
95 1.1 cherry #else /* MPVERBOSE */
96 1.1 cherry int mp_verbose = 0;
97 1.1 cherry #endif /* MPVERBOSE */
98 1.1 cherry #endif /* defined(MPBIOS) || NACPICA > 0 */
99 1.1 cherry #endif /* NPCI > 0 */
100 1.1 cherry
101 1.1 cherry
102 1.1 cherry int mainbus_match(device_t, cfdata_t, void *);
103 1.1 cherry void mainbus_attach(device_t, device_t, void *);
104 1.1 cherry
105 1.1 cherry CFATTACH_DECL_NEW(mainbus, 0,
106 1.1 cherry mainbus_match, mainbus_attach, NULL, NULL);
107 1.1 cherry
108 1.1 cherry int mainbus_print(void *, const char *);
109 1.1 cherry
110 1.1 cherry union mainbus_attach_args {
111 1.1 cherry const char *mba_busname; /* first elem of all */
112 1.1 cherry struct cpu_attach_args mba_caa;
113 1.1 cherry #if NHYPERVISOR > 0
114 1.1 cherry struct hypervisor_attach_args mba_haa;
115 1.1 cherry #endif
116 1.1 cherry #if NIPMI > 0
117 1.1 cherry struct ipmi_attach_args mba_ipmi;
118 1.1 cherry #endif
119 1.1 cherry };
120 1.1 cherry
121 1.1 cherry /*
122 1.1 cherry * Probe for the mainbus; always succeeds.
123 1.1 cherry */
124 1.1 cherry int
125 1.1 cherry mainbus_match(device_t parent, cfdata_t match, void *aux)
126 1.1 cherry {
127 1.1 cherry
128 1.1 cherry return 1;
129 1.1 cherry }
130 1.1 cherry
131 1.1 cherry /*
132 1.1 cherry * Attach the mainbus.
133 1.1 cherry */
134 1.1 cherry void
135 1.1 cherry mainbus_attach(device_t parent, device_t self, void *aux)
136 1.1 cherry {
137 1.1 cherry union mainbus_attach_args mba;
138 1.1 cherry #if defined(DOM0OPS)
139 1.1 cherry int numcpus = 0;
140 1.1 cherry #ifdef MPBIOS
141 1.1 cherry int mpbios_present = 0;
142 1.1 cherry #endif
143 1.1 cherry #ifdef PCI_BUS_FIXUP
144 1.1 cherry int pci_maxbus = 0;
145 1.1 cherry #endif
146 1.1 cherry #endif /* defined(DOM0OPS) */
147 1.1 cherry
148 1.1 cherry aprint_naive("\n");
149 1.1 cherry aprint_normal("\n");
150 1.1 cherry
151 1.1 cherry #ifdef DOM0OPS
152 1.1 cherry if (xendomain_is_dom0()) {
153 1.1 cherry #ifdef MPBIOS
154 1.1 cherry mpbios_present = mpbios_probe(self);
155 1.1 cherry #endif
156 1.1 cherry #if NPCI > 0
157 1.1 cherry /* ACPI needs to be able to access PCI configuration space. */
158 1.1 cherry pci_mode_detect();
159 1.1 cherry #ifdef PCI_BUS_FIXUP
160 1.1 cherry if (pci_mode != 0) {
161 1.1 cherry pci_maxbus = pci_bus_fixup(NULL, 0);
162 1.1 cherry aprint_debug_dev(self, "PCI bus max, after "
163 1.1 cherry "pci_bus_fixup: %i\n", pci_maxbus);
164 1.1 cherry #ifdef PCI_ADDR_FIXUP
165 1.1 cherry pciaddr.extent_port = NULL;
166 1.1 cherry pciaddr.extent_mem = NULL;
167 1.1 cherry pci_addr_fixup(NULL, pci_maxbus);
168 1.1 cherry #endif /* PCI_ADDR_FIXUP */
169 1.1 cherry }
170 1.1 cherry #endif /* PCI_BUS_FIXUP */
171 1.1 cherry #if NACPICA > 0
172 1.1 cherry acpi_present = acpi_probe() != 0;
173 1.1 cherry if (acpi_present)
174 1.1 cherry mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
175 1.1 cherry if (!mpacpi_active)
176 1.1 cherry #endif
177 1.1 cherry {
178 1.1 cherry #ifdef MPBIOS
179 1.1 cherry if (mpbios_present)
180 1.1 cherry mpbios_scan(self, &numcpus);
181 1.1 cherry else
182 1.1 cherry #endif
183 1.1 cherry if (numcpus == 0) {
184 1.1 cherry memset(&mba.mba_caa, 0, sizeof(mba.mba_caa));
185 1.1 cherry mba.mba_caa.cpu_number = 0;
186 1.1 cherry mba.mba_caa.cpu_role = CPU_ROLE_SP;
187 1.1 cherry mba.mba_caa.cpu_func = 0;
188 1.1 cherry config_found_ia(self, "cpubus",
189 1.1 cherry &mba.mba_caa, mainbus_print);
190 1.1 cherry }
191 1.1 cherry }
192 1.1 cherry #if NIOAPIC > 0
193 1.1 cherry ioapic_enable();
194 1.1 cherry #endif
195 1.1 cherry #endif /* NPCI */
196 1.1 cherry }
197 1.1 cherry #endif /* DOM0OPS */
198 1.1 cherry
199 1.1 cherry #if NIPMI > 0
200 1.1 cherry memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
201 1.1 cherry mba.mba_ipmi.iaa_iot = x86_bus_space_io;
202 1.1 cherry mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
203 1.1 cherry if (ipmi_probe(&mba.mba_ipmi))
204 1.1 cherry config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
205 1.1 cherry #endif
206 1.1 cherry
207 1.1 cherry #if NHYPERVISOR > 0
208 1.1 cherry mba.mba_haa.haa_busname = "hypervisor";
209 1.1 cherry config_found_ia(self, "hypervisorbus", &mba.mba_haa, mainbus_print);
210 1.1 cherry #endif
211 1.1 cherry
212 1.1 cherry /* save/restore for Xen */
213 1.1 cherry if (!pmf_device_register(self, NULL, NULL))
214 1.1 cherry aprint_error_dev(self, "couldn't establish power handler\n");
215 1.1 cherry
216 1.1 cherry }
217 1.1 cherry
218 1.1 cherry int
219 1.1 cherry mainbus_print(void *aux, const char *pnp)
220 1.1 cherry {
221 1.1 cherry union mainbus_attach_args *mba = aux;
222 1.1 cherry
223 1.1 cherry if (pnp)
224 1.1 cherry aprint_normal("%s at %s", mba->mba_busname, pnp);
225 1.1 cherry return (UNCONF);
226 1.1 cherry }
227