1 /* $NetBSD: mainbus.c,v 1.5 2002/10/02 15:45:18 thorpej Exp $ */ 2 3 /* 4 * Copyright 2002 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Simon Burge for Wasabi Systems, Inc. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed for the NetBSD Project by 20 * Wasabi Systems, Inc. 21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse 22 * or promote products derived from this software without specific prior 23 * written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 #include "opt_pci.h" 39 40 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 #if defined(PCI_NETBSD_CONFIGURE) 44 #include <sys/extent.h> 45 #include <sys/malloc.h> 46 #endif 47 48 #include <dev/pci/pcivar.h> 49 #if defined(PCI_NETBSD_CONFIGURE) 50 #include <dev/pci/pciconf.h> 51 #endif 52 53 #include <mips/cache.h> 54 #include <mips/cpuregs.h> 55 56 #include <evbmips/malta/autoconf.h> 57 #include <evbmips/malta/maltareg.h> 58 #include <evbmips/malta/maltavar.h> 59 60 #if defined(PCI_NETBSD_ENABLE_IDE) 61 #include <dev/pci/pciide_piix_reg.h> 62 #endif /* PCI_NETBSD_ENABLE_IDE */ 63 64 #include "locators.h" 65 #include "pci.h" 66 67 static int mainbus_match(struct device *, struct cfdata *, void *); 68 static void mainbus_attach(struct device *, struct device *, void *); 69 static int mainbus_submatch(struct device *, struct cfdata *, void *); 70 static int mainbus_print(void *, const char *); 71 72 CFATTACH_DECL(mainbus, sizeof(struct device), 73 mainbus_match, mainbus_attach, NULL, NULL); 74 75 /* There can be only one. */ 76 int mainbus_found; 77 78 struct mainbusdev { 79 const char *md_name; 80 bus_addr_t md_addr; 81 int md_intr; 82 }; 83 84 struct mainbusdev mainbusdevs[] = { 85 { "cpu", -1, -1 }, 86 { "gt", MALTA_CORECTRL_BASE, -1 }, 87 { "com", MALTA_CBUSUART, MALTA_CBUSUART_INTR }, 88 { "i2c", MALTA_I2C_BASE, -1 }, 89 { "gpio", MALTA_GPIO_BASE, -1 }, 90 { NULL, 0, 0 }, 91 }; 92 93 static int 94 mainbus_match(parent, match, aux) 95 struct device *parent; 96 struct cfdata *match; 97 void *aux; 98 { 99 100 if (mainbus_found) 101 return (0); 102 103 return (1); 104 } 105 106 static void 107 mainbus_attach(parent, self, aux) 108 struct device *parent; 109 struct device *self; 110 void *aux; 111 { 112 struct mainbus_attach_args ma; 113 struct mainbusdev *md; 114 #if defined(PCI_NETBSD_CONFIGURE) 115 struct extent *ioext, *memext; 116 #endif 117 #if defined(PCI_NETBSD_ENABLE_IDE) 118 struct malta_config *mcp = &malta_configuration; 119 pci_chipset_tag_t pc = &mcp->mc_pc; 120 pcitag_t idetag; 121 pcireg_t idetim; 122 #endif 123 124 mainbus_found = 1; 125 printf("\n"); 126 127 #if defined(PCI_NETBSD_CONFIGURE) 128 ioext = extent_create("pciio", 0x00001000, 0x0000efff, 129 M_DEVBUF, NULL, 0, EX_NOWAIT); 130 memext = extent_create("pcimem", MALTA_PCIMEM1_BASE, 131 MALTA_PCIMEM1_BASE + MALTA_PCIMEM1_SIZE, 132 M_DEVBUF, NULL, 0, EX_NOWAIT); 133 134 pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align); 135 extent_destroy(ioext); 136 extent_destroy(memext); 137 #endif /* PCI_NETBSD_CONFIGURE */ 138 139 #if defined(PCI_NETBSD_ENABLE_IDE) 140 /* 141 * Perhaps PMON has not enabled the IDE controller. Easy to 142 * fix -- just set the ENABLE bits for each channel in the 143 * IDETIM register. Just clear all the bits for the channel 144 * except for the ENABLE bits -- the `pciide' driver will 145 * properly configure it later. 146 */ 147 idetim = 0; 148 if (PCI_NETBSD_ENABLE_IDE & 0x01) 149 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0); 150 if (PCI_NETBSD_ENABLE_IDE & 0x02) 151 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1); 152 153 /* pciide0 is pci device 10, function 1 */ 154 idetag = pci_make_tag(pc, 0, 10, 1); 155 pci_conf_write(pc, idetag, PIIX_IDETIM, idetim); 156 #endif 157 for (md = mainbusdevs; md->md_name != NULL; md++) { 158 ma.ma_name = md->md_name; 159 ma.ma_addr = md->md_addr; 160 ma.ma_intr = md->md_intr; 161 (void) config_found_sm(self, &ma, mainbus_print, 162 mainbus_submatch); 163 } 164 } 165 166 static int 167 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux) 168 { 169 struct mainbus_attach_args *ma = aux; 170 171 if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT && 172 cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr) 173 return (0); 174 175 return (config_match(parent, cf, aux)); 176 } 177 178 static int 179 mainbus_print(void *aux, const char *pnp) 180 { 181 struct mainbus_attach_args *ma = aux; 182 183 if (pnp != 0) 184 return QUIET; 185 186 if (pnp) 187 printf("%s at %s", ma->ma_name, pnp); 188 if (ma->ma_addr != MAINBUSCF_ADDR_DEFAULT) 189 printf(" addr 0x%lx", ma->ma_addr); 190 191 return (UNCONF); 192 } 193