mainbus.c revision 1.13
1/* $OpenBSD: mainbus.c,v 1.13 2007/11/16 16:16:07 deraadt Exp $ */ 2/* $NetBSD: mainbus.c,v 1.1 2003/04/26 18:39:29 fvdl 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/param.h> 35#include <sys/systm.h> 36#include <sys/device.h> 37 38#include <machine/bus.h> 39 40#include <dev/isa/isavar.h> 41#include <dev/pci/pcivar.h> 42 43#include <dev/isa/isareg.h> 44 45#include "pci.h" 46#include "isa.h" 47#include "acpi.h" 48#include "ipmi.h" 49#include "bios.h" 50 51#include <machine/cpuvar.h> 52#include <machine/i82093var.h> 53#include <machine/mpbiosvar.h> 54 55#if NACPI > 0 56#include <dev/acpi/acpireg.h> 57#include <dev/acpi/acpivar.h> 58#endif 59 60#if NIPMI > 0 61#include <dev/ipmivar.h> 62#endif 63 64#if NBIOS > 0 65#include <machine/biosvar.h> 66#endif 67 68int mainbus_match(struct device *, void *, void *); 69void mainbus_attach(struct device *, struct device *, void *); 70 71struct cfattach mainbus_ca = { 72 sizeof(struct device), mainbus_match, mainbus_attach 73}; 74 75struct cfdriver mainbus_cd = { 76 NULL, "mainbus", DV_DULL 77}; 78 79int mainbus_print(void *, const char *); 80 81union mainbus_attach_args { 82 const char *mba_busname; /* first elem of all */ 83 struct pcibus_attach_args mba_pba; 84 struct isabus_attach_args mba_iba; 85 struct cpu_attach_args mba_caa; 86 struct apic_attach_args aaa_caa; 87#if NACPI > 0 88 struct acpi_attach_args mba_aaa; 89#endif 90#if NIPMI > 0 91 struct ipmi_attach_args mba_iaa; 92#endif 93#if NBIOS > 0 94 struct bios_attach_args mba_bios; 95#endif 96}; 97 98/* 99 * This is set when the ISA bus is attached. If it's not set by the 100 * time it's checked below, then mainbus attempts to attach an ISA. 101 */ 102int isa_has_been_seen; 103#if NISA > 0 104struct isabus_attach_args mba_iba = { 105 "isa", 106 X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM, 107#if NISADMA > 0 108 &isa_bus_dma_tag 109#else 110 NULL 111#endif 112}; 113#endif 114 115#if defined(MPBIOS) || defined(MPACPI) 116struct mp_bus *mp_busses; 117int mp_nbus; 118struct mp_intr_map *mp_intrs; 119int mp_nintrs; 120 121struct mp_bus *mp_isa_bus; 122struct mp_bus *mp_eisa_bus; 123 124#ifdef MPVERBOSE 125int mp_verbose = 1; 126#else 127int mp_verbose = 0; 128#endif 129#endif 130 131 132/* 133 * Probe for the mainbus; always succeeds. 134 */ 135int 136mainbus_match(struct device *parent, void *match, void *aux) 137{ 138 return (1); 139} 140 141/* 142 * Attach the mainbus. 143 */ 144void 145mainbus_attach(struct device *parent, struct device *self, void *aux) 146{ 147#if NPCI > 0 148 union mainbus_attach_args mba; 149#endif 150#ifdef MPBIOS 151 int mpbios_present = 0; 152#endif 153 extern void (*setperf_setup)(struct cpu_info *); 154 155 printf("\n"); 156 157#if NPCI > 0 158 pci_mode = pci_mode_detect(); 159#endif 160 161#if NBIOS > 0 162 { 163 mba.mba_bios.bios_dev = "bios"; 164 mba.mba_bios.bios_iot = X86_BUS_SPACE_IO; 165 mba.mba_bios.bios_memt = X86_BUS_SPACE_MEM; 166 config_found(self, &mba.mba_bios, mainbus_print); 167 } 168#endif 169 170#if NACPI > 0 171#if NPCI > 0 172 if (pci_mode != 0) 173#endif 174 { 175 memset(&mba.mba_aaa, 0, sizeof(mba.mba_aaa)); 176 mba.mba_aaa.aaa_name = "acpi"; 177 mba.mba_aaa.aaa_iot = X86_BUS_SPACE_IO; 178 mba.mba_aaa.aaa_memt = X86_BUS_SPACE_MEM; 179 180 config_found(self, &mba.mba_aaa, mainbus_print); 181 } 182#endif 183 184#if NIPMI > 0 185 { 186 memset(&mba.mba_iaa, 0, sizeof(mba.mba_iaa)); 187 mba.mba_iaa.iaa_name = "ipmi"; 188 mba.mba_iaa.iaa_iot = X86_BUS_SPACE_IO; 189 mba.mba_iaa.iaa_memt = X86_BUS_SPACE_MEM; 190 if (ipmi_probe(&mba.mba_iaa)) 191 config_found(self, &mba.mba_iaa, mainbus_print); 192 } 193#endif 194 195#ifdef MPBIOS 196 mpbios_present = mpbios_probe(self); 197#endif 198 199#ifdef MPBIOS 200 if (mpbios_present) 201 mpbios_scan(self); 202 else 203#endif 204 205 if ((cpu_info_primary.ci_flags & CPUF_PRESENT) == 0) { 206 struct cpu_attach_args caa; 207 208 memset(&caa, 0, sizeof(caa)); 209 caa.caa_name = "cpu"; 210 caa.cpu_number = 0; 211 caa.cpu_role = CPU_ROLE_SP; 212 caa.cpu_func = 0; 213 214 config_found(self, &caa, mainbus_print); 215 } 216 217#if NACPI > 0 218 if (!acpi_hasprocfvs) 219#endif 220 { 221 if (setperf_setup != NULL) 222 setperf_setup(&cpu_info_primary); 223 } 224 225#ifdef MULTIPROCESSOR 226 mp_setperf_init(); 227#endif 228 229#if NPCI > 0 230 if (pci_mode != 0) { 231 mba.mba_pba.pba_busname = "pci"; 232 mba.mba_pba.pba_iot = X86_BUS_SPACE_IO; 233 mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM; 234 mba.mba_pba.pba_dmat = &pci_bus_dma_tag; 235 mba.mba_pba.pba_domain = pci_ndomains++; 236 mba.mba_pba.pba_bus = 0; 237 mba.mba_pba.pba_bridgetag = NULL; 238 mba.mba_pba.pba_pc = NULL; 239 config_found(self, &mba.mba_pba, mainbus_print); 240 } 241#endif 242 243#if NISA > 0 244 if (isa_has_been_seen == 0) 245 config_found(self, &mba_iba, mainbus_print); 246#endif 247 248} 249 250int 251mainbus_print(void *aux, const char *pnp) 252{ 253 union mainbus_attach_args *mba = aux; 254 255 if (pnp) 256 printf("%s at %s", mba->mba_busname, pnp); 257 if (strcmp(mba->mba_busname, "pci") == 0) 258 printf(" bus %d", mba->mba_pba.pba_bus); 259 260 return (UNCONF); 261} 262