Home | History | Annotate | Line # | Download | only in x86
xen_mainbus.c revision 1.1
      1  1.1  cherry /*	$NetBSD: xen_mainbus.c,v 1.1 2018/12/22 06:33:37 cherry Exp $	*/
      2  1.1  cherry /*	NetBSD: mainbus.c,v 1.53 2003/10/27 14:11:47 junyoung Exp 	*/
      3  1.1  cherry 
      4  1.1  cherry /*
      5  1.1  cherry  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
      6  1.1  cherry  *
      7  1.1  cherry  * Redistribution and use in source and binary forms, with or without
      8  1.1  cherry  * modification, are permitted provided that the following conditions
      9  1.1  cherry  * are met:
     10  1.1  cherry  * 1. Redistributions of source code must retain the above copyright
     11  1.1  cherry  *    notice, this list of conditions and the following disclaimer.
     12  1.1  cherry  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  cherry  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  cherry  *    documentation and/or other materials provided with the distribution.
     15  1.1  cherry  * 3. All advertising materials mentioning features or use of this software
     16  1.1  cherry  *    must display the following acknowledgement:
     17  1.1  cherry  *      This product includes software developed by Christopher G. Demetriou
     18  1.1  cherry  *	for the NetBSD Project.
     19  1.1  cherry  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  cherry  *    derived from this software without specific prior written permission
     21  1.1  cherry  *
     22  1.1  cherry  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  cherry  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  cherry  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  cherry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  cherry  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  cherry  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  cherry  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  cherry  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  cherry  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  cherry  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  cherry  */
     33  1.1  cherry 
     34  1.1  cherry #include <sys/cdefs.h>
     35  1.1  cherry __KERNEL_RCSID(0, "$NetBSD: xen_mainbus.c,v 1.1 2018/12/22 06:33:37 cherry Exp $");
     36  1.1  cherry 
     37  1.1  cherry #include <sys/param.h>
     38  1.1  cherry #include <sys/systm.h>
     39  1.1  cherry #include <sys/device.h>
     40  1.1  cherry 
     41  1.1  cherry #include <sys/bus.h>
     42  1.1  cherry 
     43  1.1  cherry #include "hypervisor.h"
     44  1.1  cherry #include "pci.h"
     45  1.1  cherry 
     46  1.1  cherry #include "opt_xen.h"
     47  1.1  cherry #include "opt_mpbios.h"
     48  1.1  cherry #include "opt_pcifixup.h"
     49  1.1  cherry 
     50  1.1  cherry #include "acpica.h"
     51  1.1  cherry #include "ioapic.h"
     52  1.1  cherry 
     53  1.1  cherry #include "ipmi.h"
     54  1.1  cherry 
     55  1.1  cherry #include <machine/cpuvar.h>
     56  1.1  cherry #include <machine/i82093var.h>
     57  1.1  cherry 
     58  1.1  cherry #include <xen/xen.h>
     59  1.1  cherry #include <xen/hypervisor.h>
     60  1.1  cherry 
     61  1.1  cherry #if NIPMI > 0
     62  1.1  cherry #include <x86/ipmivar.h>
     63  1.1  cherry #endif
     64  1.1  cherry 
     65  1.1  cherry #if NPCI > 0
     66  1.1  cherry #include <dev/pci/pcivar.h>
     67  1.1  cherry #if NACPICA > 0
     68  1.1  cherry #include <dev/acpi/acpivar.h>
     69  1.1  cherry #include <xen/mpacpi.h>
     70  1.1  cherry #endif /* NACPICA > 0 */
     71  1.1  cherry #ifdef MPBIOS
     72  1.1  cherry #include <machine/mpbiosvar.h>
     73  1.1  cherry #endif /* MPBIOS */
     74  1.1  cherry #ifdef PCI_BUS_FIXUP
     75  1.1  cherry #include <arch/x86/pci/pci_bus_fixup.h>
     76  1.1  cherry #ifdef PCI_ADDR_FIXUP
     77  1.1  cherry #include <arch/x86/pci/pci_addr_fixup.h>
     78  1.1  cherry #endif
     79  1.1  cherry #endif
     80  1.1  cherry 
     81  1.1  cherry #if defined(MPBIOS) || NACPICA > 0
     82  1.1  cherry struct mp_bus *mp_busses;
     83  1.1  cherry int mp_nbus;
     84  1.1  cherry struct mp_intr_map *mp_intrs;
     85  1.1  cherry int mp_nintr;
     86  1.1  cherry 
     87  1.1  cherry int mp_isa_bus = -1;	    /* XXX */
     88  1.1  cherry int mp_eisa_bus = -1;	   /* XXX */
     89  1.1  cherry 
     90  1.1  cherry bool acpi_present;
     91  1.1  cherry bool mpacpi_active;
     92  1.1  cherry #ifdef MPVERBOSE
     93  1.1  cherry int mp_verbose = 1;
     94  1.1  cherry #else /* MPVERBOSE */
     95  1.1  cherry int mp_verbose = 0;
     96  1.1  cherry #endif /* MPVERBOSE */
     97  1.1  cherry #endif /* defined(MPBIOS) || NACPICA > 0 */
     98  1.1  cherry #endif /* NPCI > 0 */
     99  1.1  cherry 
    100  1.1  cherry 
    101  1.1  cherry int	mainbus_match(device_t, cfdata_t, void *);
    102  1.1  cherry void	mainbus_attach(device_t, device_t, void *);
    103  1.1  cherry 
    104  1.1  cherry CFATTACH_DECL_NEW(mainbus, 0,
    105  1.1  cherry     mainbus_match, mainbus_attach, NULL, NULL);
    106  1.1  cherry 
    107  1.1  cherry int	mainbus_print(void *, const char *);
    108  1.1  cherry 
    109  1.1  cherry union mainbus_attach_args {
    110  1.1  cherry 	const char *mba_busname;		/* first elem of all */
    111  1.1  cherry 	struct cpu_attach_args mba_caa;
    112  1.1  cherry #if NHYPERVISOR > 0
    113  1.1  cherry 	struct hypervisor_attach_args mba_haa;
    114  1.1  cherry #endif
    115  1.1  cherry #if NIPMI > 0
    116  1.1  cherry 	struct ipmi_attach_args mba_ipmi;
    117  1.1  cherry #endif
    118  1.1  cherry };
    119  1.1  cherry 
    120  1.1  cherry /*
    121  1.1  cherry  * Probe for the mainbus; always succeeds.
    122  1.1  cherry  */
    123  1.1  cherry int
    124  1.1  cherry mainbus_match(device_t parent, cfdata_t match, void *aux)
    125  1.1  cherry {
    126  1.1  cherry 
    127  1.1  cherry 	return 1;
    128  1.1  cherry }
    129  1.1  cherry 
    130  1.1  cherry /*
    131  1.1  cherry  * Attach the mainbus.
    132  1.1  cherry  */
    133  1.1  cherry void
    134  1.1  cherry mainbus_attach(device_t parent, device_t self, void *aux)
    135  1.1  cherry {
    136  1.1  cherry 	union mainbus_attach_args mba;
    137  1.1  cherry #if defined(DOM0OPS)
    138  1.1  cherry 	int numcpus = 0;
    139  1.1  cherry #ifdef MPBIOS
    140  1.1  cherry 	int mpbios_present = 0;
    141  1.1  cherry #endif
    142  1.1  cherry #ifdef PCI_BUS_FIXUP
    143  1.1  cherry 	int pci_maxbus = 0;
    144  1.1  cherry #endif
    145  1.1  cherry #endif /* defined(DOM0OPS) */
    146  1.1  cherry 
    147  1.1  cherry 	aprint_naive("\n");
    148  1.1  cherry 	aprint_normal("\n");
    149  1.1  cherry 
    150  1.1  cherry #ifdef DOM0OPS
    151  1.1  cherry 	if (xendomain_is_dom0()) {
    152  1.1  cherry #ifdef MPBIOS
    153  1.1  cherry 		mpbios_present = mpbios_probe(self);
    154  1.1  cherry #endif
    155  1.1  cherry #if NPCI > 0
    156  1.1  cherry 		/* ACPI needs to be able to access PCI configuration space. */
    157  1.1  cherry 		pci_mode_detect();
    158  1.1  cherry #ifdef PCI_BUS_FIXUP
    159  1.1  cherry 		if (pci_mode != 0) {
    160  1.1  cherry 			pci_maxbus = pci_bus_fixup(NULL, 0);
    161  1.1  cherry 			aprint_debug_dev(self, "PCI bus max, after "
    162  1.1  cherry 			    "pci_bus_fixup: %i\n", pci_maxbus);
    163  1.1  cherry #ifdef PCI_ADDR_FIXUP
    164  1.1  cherry 			pciaddr.extent_port = NULL;
    165  1.1  cherry 			pciaddr.extent_mem = NULL;
    166  1.1  cherry 			pci_addr_fixup(NULL, pci_maxbus);
    167  1.1  cherry #endif /* PCI_ADDR_FIXUP */
    168  1.1  cherry 		}
    169  1.1  cherry #endif /* PCI_BUS_FIXUP */
    170  1.1  cherry #if NACPICA > 0
    171  1.1  cherry 		acpi_present = acpi_probe() != 0;
    172  1.1  cherry 		if (acpi_present)
    173  1.1  cherry 			mpacpi_active = mpacpi_scan_apics(self, &numcpus) != 0;
    174  1.1  cherry 		if (!mpacpi_active)
    175  1.1  cherry #endif
    176  1.1  cherry 		{
    177  1.1  cherry #ifdef MPBIOS
    178  1.1  cherry 			if (mpbios_present)
    179  1.1  cherry 				mpbios_scan(self, &numcpus);
    180  1.1  cherry 			else
    181  1.1  cherry #endif
    182  1.1  cherry 			if (numcpus == 0) {
    183  1.1  cherry 				memset(&mba.mba_caa, 0, sizeof(mba.mba_caa));
    184  1.1  cherry 				mba.mba_caa.cpu_number = 0;
    185  1.1  cherry 				mba.mba_caa.cpu_role = CPU_ROLE_SP;
    186  1.1  cherry 				mba.mba_caa.cpu_func = 0;
    187  1.1  cherry 				config_found_ia(self, "cpubus",
    188  1.1  cherry 				    &mba.mba_caa, mainbus_print);
    189  1.1  cherry 			}
    190  1.1  cherry 		}
    191  1.1  cherry #if NIOAPIC > 0
    192  1.1  cherry 	ioapic_enable();
    193  1.1  cherry #endif
    194  1.1  cherry #endif /* NPCI */
    195  1.1  cherry 	}
    196  1.1  cherry #endif /* DOM0OPS */
    197  1.1  cherry 
    198  1.1  cherry #if NIPMI > 0
    199  1.1  cherry 	memset(&mba.mba_ipmi, 0, sizeof(mba.mba_ipmi));
    200  1.1  cherry 	mba.mba_ipmi.iaa_iot = x86_bus_space_io;
    201  1.1  cherry 	mba.mba_ipmi.iaa_memt = x86_bus_space_mem;
    202  1.1  cherry 	if (ipmi_probe(&mba.mba_ipmi))
    203  1.1  cherry 		config_found_ia(self, "ipmibus", &mba.mba_ipmi, 0);
    204  1.1  cherry #endif
    205  1.1  cherry 
    206  1.1  cherry #if NHYPERVISOR > 0
    207  1.1  cherry 	mba.mba_haa.haa_busname = "hypervisor";
    208  1.1  cherry 	config_found_ia(self, "hypervisorbus", &mba.mba_haa, mainbus_print);
    209  1.1  cherry #endif
    210  1.1  cherry 
    211  1.1  cherry 	/* save/restore for Xen */
    212  1.1  cherry 	if (!pmf_device_register(self, NULL, NULL))
    213  1.1  cherry 		aprint_error_dev(self, "couldn't establish power handler\n");
    214  1.1  cherry 
    215  1.1  cherry }
    216  1.1  cherry 
    217  1.1  cherry int
    218  1.1  cherry mainbus_print(void *aux, const char *pnp)
    219  1.1  cherry {
    220  1.1  cherry 	union mainbus_attach_args *mba = aux;
    221  1.1  cherry 
    222  1.1  cherry 	if (pnp)
    223  1.1  cherry 		aprint_normal("%s at %s", mba->mba_busname, pnp);
    224  1.1  cherry 	return (UNCONF);
    225  1.1  cherry }
    226