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