1 /* $NetBSD: mainbus.c,v 1.14 2002/10/02 15:52:30 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Christopher G. Demetriou 17 * for the NetBSD Project. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #include "opt_pci.h" 34 #include "opt_residual.h" 35 36 #include "obio.h" 37 #include "pci.h" 38 39 #include <sys/param.h> 40 #include <sys/extent.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 #include <sys/malloc.h> 44 45 #include <machine/autoconf.h> 46 #include <machine/bus.h> 47 48 #include <dev/pci/pcivar.h> 49 #include <dev/pci/pciconf.h> 50 51 #include <prep/dev/obiovar.h> 52 53 #include <machine/platform.h> 54 #include <machine/residual.h> 55 56 int mainbus_match(struct device *, struct cfdata *, void *); 57 void mainbus_attach(struct device *, struct device *, void *); 58 59 CFATTACH_DECL(mainbus, sizeof(struct device), 60 mainbus_match, mainbus_attach, NULL, NULL); 61 62 int mainbus_print(void *, const char *); 63 64 union mainbus_attach_args { 65 const char *mba_busname; /* first elem of all */ 66 struct pcibus_attach_args mba_pba; 67 }; 68 69 /* There can be only one. */ 70 int mainbus_found = 0; 71 72 /* 73 * Probe for the mainbus; always succeeds. 74 */ 75 int 76 mainbus_match(parent, match, aux) 77 struct device *parent; 78 struct cfdata *match; 79 void *aux; 80 { 81 82 if (mainbus_found) 83 return 0; 84 return 1; 85 } 86 87 /* 88 * Attach the mainbus. 89 */ 90 void 91 mainbus_attach(parent, self, aux) 92 struct device *parent; 93 struct device *self; 94 void *aux; 95 { 96 union mainbus_attach_args mba; 97 struct confargs ca; 98 #if NPCI > 0 99 static struct prep_pci_chipset pc; 100 #ifdef PCI_NETBSD_CONFIGURE 101 struct extent *ioext, *memext; 102 #endif 103 #endif 104 105 mainbus_found = 1; 106 107 printf("\n"); 108 109 #if defined(RESIDUAL_DATA_DUMP) 110 print_residual_device_info(); 111 #endif 112 113 ca.ca_name = "cpu"; 114 ca.ca_node = 0; 115 config_found(self, &ca, mainbus_print); 116 117 #if NOBIO > 0 118 obio_reserve_resource_map(); 119 #endif 120 121 /* 122 * XXX Note also that the presence of a PCI bus should 123 * XXX _always_ be checked, and if present the bus should be 124 * XXX 'found'. However, because of the structure of the code, 125 * XXX that's not currently possible. 126 */ 127 #if NPCI > 0 128 (*platform->pci_get_chipset_tag)(&pc); 129 130 #ifdef PCI_NETBSD_CONFIGURE 131 ioext = extent_create("pciio", 0x00008000, 0x0000ffff, M_DEVBUF, 132 NULL, 0, EX_NOWAIT); 133 memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF, 134 NULL, 0, EX_NOWAIT); 135 136 pci_configure_bus(&pc, ioext, memext, NULL, 0, CACHELINESIZE); 137 138 extent_destroy(ioext); 139 extent_destroy(memext); 140 #endif 141 142 mba.mba_pba.pba_busname = "pci"; 143 mba.mba_pba.pba_iot = &prep_io_space_tag; 144 mba.mba_pba.pba_memt = &prep_mem_space_tag; 145 mba.mba_pba.pba_dmat = &pci_bus_dma_tag; 146 mba.mba_pba.pba_pc = &pc; 147 mba.mba_pba.pba_bus = 0; 148 mba.mba_pba.pba_bridgetag = NULL; 149 mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; 150 config_found(self, &mba.mba_pba, mainbus_print); 151 #endif 152 153 #if NOBIO > 0 154 obio_reserve_resource_unmap(); 155 156 if (platform->obiodevs != obiodevs_nodev) { 157 bzero(&mba, sizeof(mba)); 158 mba.mba_pba.pba_busname = "obio"; 159 mba.mba_pba.pba_iot = &prep_isa_io_space_tag; 160 mba.mba_pba.pba_memt = &prep_isa_mem_space_tag; 161 config_found(self, &mba.mba_pba, mainbus_print); 162 } 163 #endif 164 } 165 166 int 167 mainbus_print(aux, pnp) 168 void *aux; 169 const char *pnp; 170 { 171 union mainbus_attach_args *mba = aux; 172 173 if (pnp) 174 printf("%s at %s", mba->mba_busname, pnp); 175 if (!strcmp(mba->mba_busname, "pci")) 176 printf(" bus %d", mba->mba_pba.pba_bus); 177 178 return (UNCONF); 179 } 180