1 /* $NetBSD: mainbus.c,v 1.8 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 <sys/param.h> 34 #include <sys/extent.h> 35 #include <sys/device.h> 36 #include <sys/malloc.h> 37 #include <sys/systm.h> 38 39 #include <machine/bus.h> 40 41 #include "mainbus.h" 42 #include "pci.h" 43 #include "opt_pci.h" 44 #include <dev/pci/pcivar.h> 45 #include <dev/pci/pciconf.h> 46 47 #if NCPU == 0 48 #error A cpu device is now required 49 #endif 50 51 int mainbus_match __P((struct device *, void *, void *)); 52 void mainbus_attach __P((struct device *, struct device *, void *)); 53 54 struct cfattach mainbus_ca = { 55 sizeof(struct device), (cfmatch_t)mainbus_match, mainbus_attach 56 }; 57 58 int mainbus_print __P((void *, const char *)); 59 60 union mainbus_attach_args { 61 const char *mba_busname; /* first elem of all */ 62 struct pcibus_attach_args mba_pba; 63 }; 64 65 /* 66 * Probe for the mainbus; always succeeds. 67 */ 68 int 69 mainbus_match(parent, match, aux) 70 struct device *parent; 71 void *match, *aux; 72 { 73 74 return 1; 75 } 76 77 /* 78 * Attach the mainbus. 79 */ 80 void 81 mainbus_attach(parent, self, aux) 82 struct device *parent, *self; 83 void *aux; 84 { 85 union mainbus_attach_args mba; 86 #if defined(PCI_NETBSD_CONFIGURE) 87 struct extent *ioext, *memext; 88 #endif 89 90 printf("\n"); 91 92 /* 93 * Always find the CPU 94 */ 95 mba.mba_busname = "cpu"; 96 config_found(self, &mba, mainbus_print); 97 98 /* 99 * XXX Note also that the presence of a PCI bus should 100 * XXX _always_ be checked, and if present the bus should be 101 * XXX 'found'. However, because of the structure of the code, 102 * XXX that's not currently possible. 103 */ 104 #if NPCI > 0 105 #if !defined(PCI_NETBSD_CONFIGURE) 106 /* #error Sandpoint needs PCI_NETBSD_CONFIGURE if PCI busses are defined. */ 107 #else 108 ioext = extent_create("pciio", 0x00000600, 0x0000ffff, M_DEVBUF, 109 NULL, 0, EX_NOWAIT); 110 memext = extent_create("pcimem", 0x80000000, 0x8fffffff, M_DEVBUF, 111 NULL, 0, EX_NOWAIT); 112 113 pci_configure_bus(0, ioext, memext, NULL, 0, 32); 114 115 extent_destroy(ioext); 116 extent_destroy(memext); 117 #endif 118 119 mba.mba_pba.pba_busname = "pci"; 120 mba.mba_pba.pba_iot = &sandpoint_io_bs_tag; 121 mba.mba_pba.pba_memt = &sandpoint_mem_bs_tag; 122 mba.mba_pba.pba_dmat = &pci_bus_dma_tag; 123 mba.mba_pba.pba_bus = 0; 124 mba.mba_pba.pba_pc = 0; 125 mba.mba_pba.pba_bridgetag = NULL; 126 mba.mba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; 127 128 config_found(self, &mba.mba_pba, mainbus_print); 129 #endif 130 } 131 132 static int cpu_match(struct device *, struct cfdata *, void *); 133 static void cpu_attach(struct device *, struct device *, void *); 134 135 struct cfattach cpu_ca = { 136 sizeof(struct device), cpu_match, cpu_attach 137 }; 138 139 extern struct cfdriver cpu_cd; 140 141 int 142 cpu_match(struct device *parent, struct cfdata *cf, void *aux) 143 { 144 union mainbus_attach_args *mba = aux; 145 146 if (strcmp(mba->mba_busname, cpu_cd.cd_name) != 0) 147 return 0; 148 149 if (cpu_info_store.ci_dev != NULL) 150 return 0; 151 152 return 1; 153 } 154 155 void 156 cpu_attach(struct device *parent, struct device *self, void *aux) 157 { 158 (void) cpu_attach_common(self, 0); 159 } 160 161 int 162 mainbus_print(aux, pnp) 163 void *aux; 164 const char *pnp; 165 { 166 union mainbus_attach_args *mba = aux; 167 168 if (pnp) 169 printf("%s at %s", mba->mba_busname, pnp); 170 if (!strcmp(mba->mba_busname, "pci")) 171 printf(" bus %d", mba->mba_pba.pba_bus); 172 return (UNCONF); 173 } 174