1 /* $NetBSD: xen_mainbus.c,v 1.8 2020/05/02 16:44:36 bouyer Exp $ */ 2 /* NetBSD: mainbus.c,v 1.19 2017/05/23 08:54:39 nonaka Exp */ 3 /* NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp */ 4 5 /* 6 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Christopher G. Demetriou 19 * for the NetBSD Project. 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.8 2020/05/02 16:44:36 bouyer Exp $"); 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/device.h> 41 42 #include <sys/bus.h> 43 44 #include "hypervisor.h" 45 #include "pci.h" 46 47 #include "opt_xen.h" 48 #include "opt_mpbios.h" 49 #include "opt_pcifixup.h" 50 51 #include "acpica.h" 52 #include "ioapic.h" 53 54 #include "ipmi.h" 55 56 #include <machine/cpuvar.h> 57 #include <machine/i82093var.h> 58 59 #include <xen/xen.h> 60 #include <xen/hypervisor.h> 61 62 #if NIPMI > 0 63 #include <x86/ipmivar.h> 64 #endif 65 66 #if NPCI > 0 67 #include <dev/pci/pcivar.h> 68 #if NACPICA > 0 69 #include <dev/acpi/acpivar.h> 70 #include <xen/mpacpi.h> 71 #endif /* NACPICA > 0 */ 72 #ifdef MPBIOS 73 #include <machine/mpbiosvar.h> 74 #endif /* MPBIOS */ 75 #ifdef PCI_BUS_FIXUP 76 #include <arch/x86/pci/pci_bus_fixup.h> 77 #ifdef PCI_ADDR_FIXUP 78 #include <arch/x86/pci/pci_addr_fixup.h> 79 #endif 80 #endif 81 82 #if defined(XENPV) && (defined(MPBIOS) || NACPICA > 0) 83 struct mp_bus *mp_busses; 84 int mp_nbus; 85 struct mp_intr_map *mp_intrs; 86 int mp_nintr; 87 88 int mp_isa_bus = -1; /* XXX */ 89 int mp_eisa_bus = -1; /* XXX */ 90 91 #ifdef MPVERBOSE 92 int mp_verbose = 1; 93 #else /* MPVERBOSE */ 94 int mp_verbose = 0; 95 #endif /* MPVERBOSE */ 96 #endif /* defined(MPBIOS) || NACPICA > 0 */ 97 #endif /* NPCI > 0 */ 98 99 extern bool acpi_present; 100 extern bool mpacpi_active; 101 102 void xen_mainbus_attach(device_t, device_t, void *); 103 static int xen_mainbus_print(void *, const char *); 104 105 union xen_mainbus_attach_args { 106 const char *mba_busname; /* first elem of all */ 107 struct cpu_attach_args mba_caa; 108 #if NHYPERVISOR > 0 109 struct hypervisor_attach_args mba_haa; 110 #endif 111 #if NIPMI > 0 112 struct ipmi_attach_args mba_ipmi; 113 #endif 114 }; 115 116 /* 117 * Attach the mainbus. 118 */ 119 void 120 xen_mainbus_attach(device_t parent, device_t self, void *aux) 121 { 122 union xen_mainbus_attach_args mba; 123 124 switch(vm_guest) { 125 case VM_GUEST_XENPV: 126 #if NIPMI > 0 && defined(XENPV) 127 memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi)); 128 mba.mba_ipmi.iaa_iot = x86_bus_space_io; 129 mba.mba_ipmi.iaa_memt = x86_bus_space_mem; 130 if (ipmi_probe(&mba.mba_ipmi)) 131 config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0); 132 #endif 133 /* FALLTHROUGH */ 134 case VM_GUEST_XENPVH: 135 case VM_GUEST_XENPVHVM: 136 mba.mba_haa.haa_busname = "hypervisor"; 137 config_found_ia(self, "hypervisorbus", 138 &mba.mba_haa, xen_mainbus_print); 139 break; 140 default: 141 return; 142 } 143 144 if (vm_guest == VM_GUEST_XENPV) { 145 /* save/restore for Xen */ 146 if (!pmf_device_register(self, NULL, NULL)) 147 aprint_error_dev(self, 148 "couldn't establish power handler\n"); 149 } 150 } 151 152 static int 153 xen_mainbus_print(void *aux, const char *pnp) 154 { 155 union xen_mainbus_attach_args *mba = aux; 156 157 if (pnp) 158 aprint_normal("%s at %s", mba->mba_busname, pnp); 159 return UNCONF; 160 } 161