mainbus.c revision 1.28
1/* $OpenBSD: mainbus.c,v 1.28 2015/03/14 03:38:46 jsg 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#include "mpbios.h" 51#include "vmt.h" 52 53#include <machine/cpuvar.h> 54#include <machine/i82093var.h> 55 56#include <dev/acpi/acpivar.h> 57 58#if NIPMI > 0 59#include <dev/ipmivar.h> 60#endif 61 62#if NVMT > 0 63#include <dev/vmtvar.h> 64#endif 65 66#if NBIOS > 0 67#include <machine/biosvar.h> 68#endif 69 70int mainbus_match(struct device *, void *, void *); 71void mainbus_attach(struct device *, struct device *, void *); 72 73struct cfattach mainbus_ca = { 74 sizeof(struct device), mainbus_match, mainbus_attach 75}; 76 77struct cfdriver mainbus_cd = { 78 NULL, "mainbus", DV_DULL 79}; 80 81int mainbus_print(void *, const char *); 82 83union mainbus_attach_args { 84 const char *mba_busname; /* first elem of all */ 85 struct pcibus_attach_args mba_pba; 86 struct isabus_attach_args mba_iba; 87 struct cpu_attach_args mba_caa; 88 struct apic_attach_args aaa_caa; 89#if NIPMI > 0 90 struct ipmi_attach_args mba_iaa; 91#endif 92#if NBIOS > 0 93 struct bios_attach_args mba_bios; 94#endif 95}; 96 97/* 98 * This is set when the ISA bus is attached. If it's not set by the 99 * time it's checked below, then mainbus attempts to attach an ISA. 100 */ 101int isa_has_been_seen; 102#if NISA > 0 103struct isabus_attach_args mba_iba = { 104 "isa", 105 X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM, 106#if NISADMA > 0 107 &isa_bus_dma_tag 108#else 109 NULL 110#endif 111}; 112#endif 113 114#if NMPBIOS > 0 || NACPI > 0 115struct mp_bus *mp_busses; 116int mp_nbusses; 117struct mp_intr_map *mp_intrs; 118int mp_nintrs; 119 120struct mp_bus *mp_isa_bus; 121struct mp_bus *mp_eisa_bus; 122 123#ifdef MPVERBOSE 124int mp_verbose = 1; 125#else 126int mp_verbose = 0; 127#endif 128#endif 129 130 131/* 132 * Probe for the mainbus; always succeeds. 133 */ 134int 135mainbus_match(struct device *parent, void *match, void *aux) 136{ 137 return (1); 138} 139 140/* 141 * Attach the mainbus. 142 */ 143void 144mainbus_attach(struct device *parent, struct device *self, void *aux) 145{ 146#if NPCI > 0 147 union mainbus_attach_args mba; 148#endif 149 extern void (*setperf_setup)(struct cpu_info *); 150 151 printf("\n"); 152 153#if NBIOS > 0 154 { 155 mba.mba_bios.ba_name = "bios"; 156 mba.mba_bios.ba_iot = X86_BUS_SPACE_IO; 157 mba.mba_bios.ba_memt = X86_BUS_SPACE_MEM; 158 config_found(self, &mba.mba_bios, mainbus_print); 159 } 160#endif 161 162#if NIPMI > 0 163 { 164 memset(&mba.mba_iaa, 0, sizeof(mba.mba_iaa)); 165 mba.mba_iaa.iaa_name = "ipmi"; 166 mba.mba_iaa.iaa_iot = X86_BUS_SPACE_IO; 167 mba.mba_iaa.iaa_memt = X86_BUS_SPACE_MEM; 168 if (ipmi_probe(&mba.mba_iaa)) 169 config_found(self, &mba.mba_iaa, mainbus_print); 170 } 171#endif 172 173#if NVMT > 0 174 if (vmt_probe()) { 175 mba.mba_busname = "vmt"; 176 config_found(self, &mba.mba_busname, mainbus_print); 177 } 178#endif 179 180 if ((cpu_info_primary.ci_flags & CPUF_PRESENT) == 0) { 181 struct cpu_attach_args caa; 182 183 memset(&caa, 0, sizeof(caa)); 184 caa.caa_name = "cpu"; 185 caa.cpu_number = 0; 186 caa.cpu_role = CPU_ROLE_SP; 187 caa.cpu_func = 0; 188 189 config_found(self, &caa, mainbus_print); 190 } 191 192#if NACPI > 0 193 if (!acpi_hasprocfvs) 194#endif 195 { 196 if (setperf_setup != NULL) 197 setperf_setup(&cpu_info_primary); 198 } 199 200#ifdef MULTIPROCESSOR 201 mp_setperf_init(); 202#endif 203 204#if NPCI > 0 205 { 206 pci_init_extents(); 207 208 bzero(&mba.mba_pba, sizeof(mba.mba_pba)); 209 mba.mba_pba.pba_busname = "pci"; 210 mba.mba_pba.pba_iot = X86_BUS_SPACE_IO; 211 mba.mba_pba.pba_memt = X86_BUS_SPACE_MEM; 212 mba.mba_pba.pba_dmat = &pci_bus_dma_tag; 213 mba.mba_pba.pba_ioex = pciio_ex; 214 mba.mba_pba.pba_memex = pcimem_ex; 215 mba.mba_pba.pba_busex = pcibus_ex; 216 mba.mba_pba.pba_domain = pci_ndomains++; 217 mba.mba_pba.pba_bus = 0; 218 config_found(self, &mba.mba_pba, mainbus_print); 219#if NACPI > 0 220 acpi_pciroots_attach(self, &mba.mba_pba, mainbus_print); 221#endif 222 } 223#endif 224 225#if NISA > 0 226 if (isa_has_been_seen == 0) 227 config_found(self, &mba_iba, mainbus_print); 228#endif 229 230} 231 232int 233mainbus_print(void *aux, const char *pnp) 234{ 235 union mainbus_attach_args *mba = aux; 236 237 if (pnp) 238 printf("%s at %s", mba->mba_busname, pnp); 239 if (strcmp(mba->mba_busname, "pci") == 0) 240 printf(" bus %d", mba->mba_pba.pba_bus); 241 242 return (UNCONF); 243} 244