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