1 /* $NetBSD: mainbus.c,v 1.2 2002/05/16 01:01:38 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 <sys/param.h> 34 #include <sys/extent.h> 35 #include <sys/systm.h> 36 #include <sys/device.h> 37 #include <sys/malloc.h> 38 39 #include <machine/autoconf.h> 40 #include <machine/bus.h> 41 42 #include "pci.h" 43 #include "opt_pci.h" 44 #include <dev/pci/pcivar.h> 45 #include <dev/pci/pciconf.h> 46 47 int mainbus_match(struct device *, struct cfdata *, void *); 48 void mainbus_attach(struct device *, struct device *, void *); 49 50 struct cfattach mainbus_ca = { 51 sizeof(struct device), mainbus_match, mainbus_attach 52 }; 53 54 int mainbus_print(void *, const char *); 55 56 union mainbus_attach_args { 57 const char *mba_busname; /* first elem of all */ 58 struct pcibus_attach_args mba_pba; 59 }; 60 61 /* There can be only one */ 62 static int mainbus_found; 63 64 /* 65 * Probe for the mainbus; always succeeds. 66 */ 67 int 68 mainbus_match(parent, match, aux) 69 struct device *parent; 70 struct cfdata *match; 71 void *aux; 72 { 73 74 if (mainbus_found) 75 return 0; 76 return 1; 77 } 78 79 /* 80 * Attach the mainbus. 81 */ 82 void 83 mainbus_attach(parent, self, aux) 84 struct device *parent; 85 struct device *self; 86 void *aux; 87 { 88 union mainbus_attach_args mba; 89 struct confargs ca; 90 #ifdef PCI_NETBSD_CONFIGURE 91 struct extent *ioext, *memext; 92 #endif 93 94 mainbus_found = 1; 95 96 printf("\n"); 97 98 ca.ca_name = "cpu"; 99 ca.ca_node = 0; 100 config_found(self, &ca, mainbus_print); 101 102 /* 103 * XXX Note also that the presence of a PCI bus should 104 * XXX _always_ be checked, and if present the bus should be 105 * XXX 'found'. However, because of the structure of the code, 106 * XXX that's not currently possible. 107 */ 108 #if NPCI > 0 109 #ifdef PCI_NETBSD_CONFIGURE 110 ioext = extent_create("pciio", 0x00008000, 0x0000ffff, M_DEVBUF, 111 NULL, 0, EX_NOWAIT); 112 memext = extent_create("pcimem", 0x00000000, 0x0fffffff, M_DEVBUF, 113 NULL, 0, EX_NOWAIT); 114 115 pci_configure_bus(0, ioext, memext, NULL, 0, 32); 116 117 extent_destroy(ioext); 118 extent_destroy(memext); 119 #endif 120 121 mba.mba_pba.pba_busname = "pci"; 122 mba.mba_pba.pba_iot = &mvmeppc_pci_io_bs_tag; 123 mba.mba_pba.pba_memt = &mvmeppc_pci_mem_bs_tag; 124 mba.mba_pba.pba_dmat = &pci_bus_dma_tag; 125 mba.mba_pba.pba_bus = 0; 126 mba.mba_pba.pba_bridgetag = NULL; 127 mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; 128 config_found(self, &mba.mba_pba, mainbus_print); 129 #endif 130 } 131 132 int 133 mainbus_print(aux, pnp) 134 void *aux; 135 const char *pnp; 136 { 137 union mainbus_attach_args *mba = aux; 138 139 if (pnp) 140 printf("%s at %s", mba->mba_busname, pnp); 141 if (!strcmp(mba->mba_busname, "pci")) 142 printf(" bus %d", mba->mba_pba.pba_bus); 143 144 return (UNCONF); 145 } 146