1*c7fb772bSthorpej /* $NetBSD: xen_mainbus.c,v 1.10 2021/08/07 16:19:08 thorpej Exp $ */
2962a684eScherry /* NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp */
37bd4c28fScherry /* NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp */
47bd4c28fScherry
57bd4c28fScherry /*
67bd4c28fScherry * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
77bd4c28fScherry *
87bd4c28fScherry * Redistribution and use in source and binary forms, with or without
97bd4c28fScherry * modification, are permitted provided that the following conditions
107bd4c28fScherry * are met:
117bd4c28fScherry * 1. Redistributions of source code must retain the above copyright
127bd4c28fScherry * notice, this list of conditions and the following disclaimer.
137bd4c28fScherry * 2. Redistributions in binary form must reproduce the above copyright
147bd4c28fScherry * notice, this list of conditions and the following disclaimer in the
157bd4c28fScherry * documentation and/or other materials provided with the distribution.
167bd4c28fScherry * 3. All advertising materials mentioning features or use of this software
177bd4c28fScherry * must display the following acknowledgement:
187bd4c28fScherry * This product includes software developed by Christopher G. Demetriou
197bd4c28fScherry * for the NetBSD Project.
207bd4c28fScherry * 4. The name of the author may not be used to endorse or promote products
217bd4c28fScherry * derived from this software without specific prior written permission
227bd4c28fScherry *
237bd4c28fScherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
247bd4c28fScherry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
257bd4c28fScherry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
267bd4c28fScherry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
277bd4c28fScherry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
287bd4c28fScherry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
297bd4c28fScherry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
307bd4c28fScherry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
317bd4c28fScherry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
327bd4c28fScherry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
337bd4c28fScherry */
347bd4c28fScherry
357bd4c28fScherry #include <sys/cdefs.h>
36*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.10 2021/08/07 16:19:08 thorpej Exp $");
377bd4c28fScherry
387bd4c28fScherry #include <sys/param.h>
397bd4c28fScherry #include <sys/systm.h>
407bd4c28fScherry #include <sys/device.h>
417bd4c28fScherry
427bd4c28fScherry #include <sys/bus.h>
437bd4c28fScherry
447bd4c28fScherry #include "hypervisor.h"
457bd4c28fScherry #include "pci.h"
467bd4c28fScherry
477bd4c28fScherry #include "opt_xen.h"
487bd4c28fScherry #include "opt_mpbios.h"
497bd4c28fScherry #include "opt_pcifixup.h"
507bd4c28fScherry
517bd4c28fScherry #include "acpica.h"
527bd4c28fScherry #include "ioapic.h"
537bd4c28fScherry
547bd4c28fScherry #include "ipmi.h"
557bd4c28fScherry
567bd4c28fScherry #include <machine/cpuvar.h>
577bd4c28fScherry #include <machine/i82093var.h>
587bd4c28fScherry
597bd4c28fScherry #include <xen/xen.h>
607bd4c28fScherry #include <xen/hypervisor.h>
617bd4c28fScherry
627bd4c28fScherry #if NIPMI > 0
637bd4c28fScherry #include <x86/ipmivar.h>
647bd4c28fScherry #endif
657bd4c28fScherry
667bd4c28fScherry #if NPCI > 0
677bd4c28fScherry #include <dev/pci/pcivar.h>
687bd4c28fScherry #if NACPICA > 0
697bd4c28fScherry #include <dev/acpi/acpivar.h>
707bd4c28fScherry #include <xen/mpacpi.h>
717bd4c28fScherry #endif /* NACPICA > 0 */
727bd4c28fScherry #ifdef MPBIOS
737bd4c28fScherry #include <machine/mpbiosvar.h>
747bd4c28fScherry #endif /* MPBIOS */
757bd4c28fScherry #ifdef PCI_BUS_FIXUP
767bd4c28fScherry #include <arch/x86/pci/pci_bus_fixup.h>
777bd4c28fScherry #ifdef PCI_ADDR_FIXUP
787bd4c28fScherry #include <arch/x86/pci/pci_addr_fixup.h>
797bd4c28fScherry #endif
807bd4c28fScherry #endif
817bd4c28fScherry
821e3d30b0Scherry #if defined(XENPV) && (defined(MPBIOS) || NACPICA > 0)
837bd4c28fScherry struct mp_bus *mp_busses;
847bd4c28fScherry int mp_nbus;
857bd4c28fScherry struct mp_intr_map *mp_intrs;
867bd4c28fScherry int mp_nintr;
877bd4c28fScherry
887bd4c28fScherry int mp_isa_bus = -1; /* XXX */
897bd4c28fScherry int mp_eisa_bus = -1; /* XXX */
907bd4c28fScherry
917bd4c28fScherry #ifdef MPVERBOSE
927bd4c28fScherry int mp_verbose = 1;
937bd4c28fScherry #else /* MPVERBOSE */
947bd4c28fScherry int mp_verbose = 0;
957bd4c28fScherry #endif /* MPVERBOSE */
967bd4c28fScherry #endif /* defined(MPBIOS) || NACPICA > 0 */
977bd4c28fScherry #endif /* NPCI > 0 */
987bd4c28fScherry
993355a42fScherry extern bool acpi_present;
1003355a42fScherry extern bool mpacpi_active;
1017bd4c28fScherry
1023355a42fScherry void xen_mainbus_attach(device_t, device_t, void *);
103c24c993fSbouyer static int xen_mainbus_print(void *, const char *);
1047bd4c28fScherry
1053355a42fScherry union xen_mainbus_attach_args {
1067bd4c28fScherry const char *mba_busname; /* first elem of all */
1077bd4c28fScherry struct cpu_attach_args mba_caa;
1087bd4c28fScherry #if NHYPERVISOR > 0
1097bd4c28fScherry struct hypervisor_attach_args mba_haa;
1107bd4c28fScherry #endif
1117bd4c28fScherry #if NIPMI > 0
1127bd4c28fScherry struct ipmi_attach_args mba_ipmi;
1137bd4c28fScherry #endif
1147bd4c28fScherry };
1157bd4c28fScherry
1167bd4c28fScherry /*
1177bd4c28fScherry * Attach the mainbus.
1187bd4c28fScherry */
1197bd4c28fScherry void
xen_mainbus_attach(device_t parent,device_t self,void * aux)1203355a42fScherry xen_mainbus_attach(device_t parent, device_t self, void *aux)
1217bd4c28fScherry {
1223355a42fScherry union xen_mainbus_attach_args mba;
1237bd4c28fScherry
124c24c993fSbouyer switch(vm_guest) {
125c24c993fSbouyer case VM_GUEST_XENPV:
126c24c993fSbouyer #if NIPMI > 0 && defined(XENPV)
1277bd4c28fScherry memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
1287bd4c28fScherry mba.mba_ipmi.iaa_iot = x86_bus_space_io;
1297bd4c28fScherry mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
1307bd4c28fScherry if (ipmi_probe(&mba.mba_ipmi))
1312685996bSthorpej config_found(self, &mba.mba_ipmi, NULL,
132*c7fb772bSthorpej CFARGS(.iattr = "ipmibus"));
1337bd4c28fScherry #endif
134c24c993fSbouyer /* FALLTHROUGH */
135d5c9d50fSbouyer case VM_GUEST_XENPVH:
136c24c993fSbouyer case VM_GUEST_XENPVHVM:
1377bd4c28fScherry mba.mba_haa.haa_busname = "hypervisor";
1382685996bSthorpej config_found(self, &mba.mba_haa, xen_mainbus_print,
139*c7fb772bSthorpej CFARGS(.iattr = "hypervisorbus"));
140c24c993fSbouyer break;
141c24c993fSbouyer default:
142c24c993fSbouyer return;
1437bd4c28fScherry }
1447bd4c28fScherry
145c24c993fSbouyer if (vm_guest == VM_GUEST_XENPV) {
146c24c993fSbouyer /* save/restore for Xen */
147c24c993fSbouyer if (!pmf_device_register(self, NULL, NULL))
148c24c993fSbouyer aprint_error_dev(self,
149c24c993fSbouyer "couldn't establish power handler\n");
150c24c993fSbouyer }
151c24c993fSbouyer }
152c24c993fSbouyer
153c24c993fSbouyer static int
xen_mainbus_print(void * aux,const char * pnp)1543355a42fScherry xen_mainbus_print(void *aux, const char *pnp)
1557bd4c28fScherry {
1563355a42fScherry union xen_mainbus_attach_args *mba = aux;
1577bd4c28fScherry
1587bd4c28fScherry if (pnp)
1597bd4c28fScherry aprint_normal("%s at %s", mba->mba_busname, pnp);
16064b14b76Smaxv return UNCONF;
1617bd4c28fScherry }
162