xen_mainbus.c revision 1.7
1/* $NetBSD: xen_mainbus.c,v 1.7 2020/04/25 15:26:17 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.7 2020/04/25 15:26:17 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) 83struct mp_bus *mp_busses; 84int mp_nbus; 85struct mp_intr_map *mp_intrs; 86int mp_nintr; 87 88int mp_isa_bus = -1; /* XXX */ 89int mp_eisa_bus = -1; /* XXX */ 90 91#ifdef MPVERBOSE 92int mp_verbose = 1; 93#else /* MPVERBOSE */ 94int mp_verbose = 0; 95#endif /* MPVERBOSE */ 96#endif /* defined(MPBIOS) || NACPICA > 0 */ 97#endif /* NPCI > 0 */ 98 99extern bool acpi_present; 100extern bool mpacpi_active; 101 102void xen_mainbus_attach(device_t, device_t, void *); 103static int xen_mainbus_print(void *, const char *); 104 105union 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 */ 119void 120xen_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_XENPVHVM: 135 mba.mba_haa.haa_busname = "hypervisor"; 136 config_found_ia(self, "hypervisorbus", 137 &mba.mba_haa, xen_mainbus_print); 138 break; 139 default: 140 return; 141 } 142 143 if (vm_guest == VM_GUEST_XENPV) { 144 /* save/restore for Xen */ 145 if (!pmf_device_register(self, NULL, NULL)) 146 aprint_error_dev(self, 147 "couldn't establish power handler\n"); 148 } 149} 150 151static int 152xen_mainbus_print(void *aux, const char *pnp) 153{ 154 union xen_mainbus_attach_args *mba = aux; 155 156 if (pnp) 157 aprint_normal("%s at %s", mba->mba_busname, pnp); 158 return UNCONF; 159} 160