1 /* $OpenBSD: mainbus.c,v 1.52 2022/02/21 11:03:39 mpi Exp $ */
2 /* $NetBSD: mainbus.c,v 1.1 2003/04/26 18:39:29 fvdl Exp $ */
3
4 /*
5 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christopher G. Demetriou
18 * for the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/device.h>
37
38 #include <machine/bus.h>
39 #include <machine/specialreg.h>
40 #include <machine/codepatch.h>
41
42 #include <dev/isa/isavar.h>
43 #include <dev/pci/pcivar.h>
44
45 #include "pci.h"
46 #include "isa.h"
47 #include "acpi.h"
48 #include "ipmi.h"
49 #include "bios.h"
50 #include "mpbios.h"
51 #include "vmm.h"
52 #include "pvbus.h"
53 #include "efifb.h"
54
55 #include <machine/cpuvar.h>
56 #include <machine/i82093var.h>
57
58 #include <dev/acpi/acpivar.h>
59
60 #if NIPMI > 0
61 #include <dev/ipmivar.h>
62 #endif
63
64 #if NPVBUS > 0
65 #include <dev/pv/pvvar.h>
66 #endif
67
68 #if NBIOS > 0
69 #include <machine/biosvar.h>
70 #endif
71
72 #if NEFIFB > 0
73 #include <machine/efifbvar.h>
74 #endif
75
76 void replacemds(void);
77
78 int mainbus_match(struct device *, void *, void *);
79 void mainbus_attach(struct device *, struct device *, void *);
80
81 const struct cfattach mainbus_ca = {
82 sizeof(struct device), mainbus_match, mainbus_attach
83 };
84
85 struct cfdriver mainbus_cd = {
86 NULL, "mainbus", DV_DULL
87 };
88
89 int mainbus_print(void *, const char *);
90
91 union mainbus_attach_args {
92 const char *mba_busname; /* first elem of all */
93 struct pcibus_attach_args mba_pba;
94 struct isabus_attach_args mba_iba;
95 struct cpu_attach_args mba_caa;
96 struct apic_attach_args aaa_caa;
97 #if NIPMI > 0
98 struct ipmi_attach_args mba_iaa;
99 #endif
100 #if NBIOS > 0
101 struct bios_attach_args mba_bios;
102 #endif
103 #if NPVBUS > 0
104 struct pvbus_attach_args mba_pvba;
105 #endif
106 #if NEFIFB > 0
107 struct efifb_attach_args mba_eaa;
108 #endif
109 };
110
111 /*
112 * This is set when the ISA bus is attached. If it's not set by the
113 * time it's checked below, then mainbus attempts to attach an ISA.
114 */
115 int isa_has_been_seen;
116 #if NISA > 0
117 struct isabus_attach_args mba_iba = {
118 "isa",
119 X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM,
120 #if NISADMA > 0
121 &isa_bus_dma_tag
122 #else
123 NULL
124 #endif
125 };
126 #endif
127
128 #if NMPBIOS > 0 || NACPI > 0
129 struct mp_bus *mp_busses;
130 int mp_nbusses;
131 struct mp_intr_map *mp_intrs;
132 int mp_nintrs;
133
134 struct mp_bus *mp_isa_bus;
135 struct mp_bus *mp_eisa_bus;
136
137 #ifdef MPVERBOSE
138 int mp_verbose = 1;
139 #else
140 int mp_verbose = 0;
141 #endif
142 #endif
143
144
145 /*
146 * Probe for the mainbus; always succeeds.
147 */
148 int
mainbus_match(struct device * parent,void * match,void * aux)149 mainbus_match(struct device *parent, void *match, void *aux)
150 {
151 return (1);
152 }
153
154 /*
155 * Attach the mainbus.
156 */
157 void
mainbus_attach(struct device * parent,struct device * self,void * aux)158 mainbus_attach(struct device *parent, struct device *self, void *aux)
159 {
160 #if NPCI > 0
161 union mainbus_attach_args mba;
162 #endif
163 #if NVMM > 0
164 extern int vmm_enabled(void);
165 #endif
166 extern void (*setperf_setup)(struct cpu_info *);
167
168 printf("\n");
169
170 #if NEFIFB > 0
171 efifb_cnremap();
172 #endif
173
174 #if NBIOS > 0
175 {
176 mba.mba_bios.ba_name = "bios";
177 mba.mba_bios.ba_iot = X86_BUS_SPACE_IO;
178 mba.mba_bios.ba_memt = X86_BUS_SPACE_MEM;
179 config_found(self, &mba.mba_bios, mainbus_print);
180 }
181 #endif
182
183 #if NIPMI > 0
184 {
185 memset(&mba.mba_iaa, 0, sizeof(mba.mba_iaa));
186 mba.mba_iaa.iaa_name = "ipmi";
187 mba.mba_iaa.iaa_iot = X86_BUS_SPACE_IO;
188 mba.mba_iaa.iaa_memt = X86_BUS_SPACE_MEM;
189 if (ipmi_probe(&mba.mba_iaa))
190 config_found(self, &mba.mba_iaa, mainbus_print);
191 }
192 #endif
193
194 if ((cpu_info_primary.ci_flags & CPUF_PRESENT) == 0) {
195 struct cpu_attach_args caa;
196
197 memset(&caa, 0, sizeof(caa));
198 caa.caa_name = "cpu";
199 caa.cpu_role = CPU_ROLE_SP;
200
201 config_found(self, &caa, mainbus_print);
202 }
203
204 /* All CPUs are attached, handle MDS */
205 replacemds();
206
207 #if NACPI > 0
208 if (!acpi_hasprocfvs)
209 #endif
210 {
211 if (setperf_setup != NULL)
212 setperf_setup(&cpu_info_primary);
213 }
214
215 #ifdef MULTIPROCESSOR
216 mp_setperf_init();
217 #endif
218
219 #if NPVBUS > 0
220 /* Probe first to hide the "not configured" message */
221 if (pvbus_probe()) {
222 mba.mba_pvba.pvba_busname = "pvbus";
223 config_found(self, &mba.mba_pvba.pvba_busname, mainbus_print);
224 }
225 #endif
226
227 #if NPCI > 0
228 #if NACPI > 0
229 if (acpi_haspci) {
230 extern void acpipci_attach_busses(struct device *);
231
232 acpipci_attach_busses(self);
233 } else
234 #endif
235 {
236 pci_init_extents();
237
238 bzero(&mba.mba_pba, sizeof(mba.mba_pba));
239 mba.mba_pba.pba_busname = "pci";
240 mba.mba_pba.pba_iot = X86_BUS_SPACE_IO;
241 mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM;
242 mba.mba_pba.pba_dmat = &pci_bus_dma_tag;
243 mba.mba_pba.pba_ioex = pciio_ex;
244 mba.mba_pba.pba_memex = pcimem_ex;
245 mba.mba_pba.pba_busex = pcibus_ex;
246 mba.mba_pba.pba_domain = pci_ndomains++;
247 mba.mba_pba.pba_bus = 0;
248 config_found(self, &mba.mba_pba, mainbus_print);
249 }
250 #endif
251
252 #if NISA > 0
253 if (isa_has_been_seen == 0)
254 config_found(self, &mba_iba, mainbus_print);
255 #endif
256
257 #if NVMM > 0
258 if (vmm_enabled()) {
259 mba.mba_busname = "vmm";
260 config_found(self, &mba.mba_busname, mainbus_print);
261 }
262 #endif /* NVMM > 0 */
263
264 #if NEFIFB > 0
265 if (bios_efiinfo != NULL || efifb_cb_found()) {
266 mba.mba_eaa.eaa_name = "efifb";
267 config_found(self, &mba, mainbus_print);
268 }
269 #endif
270 codepatch_disable();
271 }
272
273 #if NEFIFB > 0
274 void
mainbus_efifb_reattach(void)275 mainbus_efifb_reattach(void)
276 {
277 union mainbus_attach_args mba;
278 struct device *self = device_mainbus();
279
280 if (bios_efiinfo != NULL || efifb_cb_found()) {
281 mba.mba_eaa.eaa_name = "efifb";
282 config_found(self, &mba, mainbus_print);
283 }
284 }
285 #endif
286
287 int
mainbus_print(void * aux,const char * pnp)288 mainbus_print(void *aux, const char *pnp)
289 {
290 union mainbus_attach_args *mba = aux;
291
292 if (pnp)
293 printf("%s at %s", mba->mba_busname, pnp);
294 if (strcmp(mba->mba_busname, "pci") == 0)
295 printf(" bus %d", mba->mba_pba.pba_bus);
296
297 return (UNCONF);
298 }
299