1 /* $NetBSD: mainbus.c,v 1.11 2002/05/16 01:01:39 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 struct cfattach mainbus_ca = { 60 sizeof(struct device), mainbus_match, mainbus_attach 61 }; 62 63 int mainbus_print(void *, const char *); 64 65 union mainbus_attach_args { 66 const char *mba_busname; /* first elem of all */ 67 struct pcibus_attach_args mba_pba; 68 }; 69 70 /* There can be only one. */ 71 int mainbus_found = 0; 72 73 /* 74 * Probe for the mainbus; always succeeds. 75 */ 76 int 77 mainbus_match(parent, match, aux) 78 struct device *parent; 79 struct cfdata *match; 80 void *aux; 81 { 82 83 if (mainbus_found) 84 return 0; 85 return 1; 86 } 87 88 /* 89 * Attach the mainbus. 90 */ 91 void 92 mainbus_attach(parent, self, aux) 93 struct device *parent; 94 struct device *self; 95 void *aux; 96 { 97 union mainbus_attach_args mba; 98 struct confargs ca; 99 #if NPCI > 0 100 static struct prep_pci_chipset pc; 101 #ifdef PCI_NETBSD_CONFIGURE 102 struct extent *ioext, *memext; 103 #endif 104 #endif 105 106 mainbus_found = 1; 107 108 printf("\n"); 109 110 #if defined(RESIDUAL_DATA_DUMP) 111 print_residual_device_info(); 112 #endif 113 114 ca.ca_name = "cpu"; 115 ca.ca_node = 0; 116 config_found(self, &ca, mainbus_print); 117 118 #if NOBIO > 0 119 obio_reserve_resource_map(); 120 #endif 121 122 /* 123 * XXX Note also that the presence of a PCI bus should 124 * XXX _always_ be checked, and if present the bus should be 125 * XXX 'found'. However, because of the structure of the code, 126 * XXX that's not currently possible. 127 */ 128 #if NPCI > 0 129 (*platform->pci_get_chipset_tag)(&pc); 130 131 #ifdef PCI_NETBSD_CONFIGURE 132 ioext = extent_create("pciio", 0x00008000, 0x0000ffff, M_DEVBUF, 133 NULL, 0, EX_NOWAIT); 134 memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF, 135 NULL, 0, EX_NOWAIT); 136 137 pci_configure_bus(&pc, ioext, memext, NULL, 0, CACHELINESIZE); 138 139 extent_destroy(ioext); 140 extent_destroy(memext); 141 #endif 142 143 mba.mba_pba.pba_busname = "pci"; 144 mba.mba_pba.pba_iot = &prep_io_space_tag; 145 mba.mba_pba.pba_memt = &prep_mem_space_tag; 146 mba.mba_pba.pba_dmat = &pci_bus_dma_tag; 147 mba.mba_pba.pba_pc = &pc; 148 mba.mba_pba.pba_bus = 0; 149 mba.mba_pba.pba_bridgetag = NULL; 150 mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; 151 config_found(self, &mba.mba_pba, mainbus_print); 152 #endif 153 154 #if NOBIO > 0 155 obio_reserve_resource_unmap(); 156 157 if (platform->obiodevs != obiodevs_nodev) { 158 bzero(&mba, sizeof(mba)); 159 mba.mba_pba.pba_busname = "obio"; 160 mba.mba_pba.pba_iot = &prep_isa_io_space_tag; 161 mba.mba_pba.pba_memt = &prep_isa_mem_space_tag; 162 config_found(self, &mba.mba_pba, mainbus_print); 163 } 164 #endif 165 } 166 167 int 168 mainbus_print(aux, pnp) 169 void *aux; 170 const char *pnp; 171 { 172 union mainbus_attach_args *mba = aux; 173 174 if (pnp) 175 printf("%s at %s", mba->mba_busname, pnp); 176 if (!strcmp(mba->mba_busname, "pci")) 177 printf(" bus %d", mba->mba_pba.pba_bus); 178 179 return (UNCONF); 180 } 181