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