1 /* $NetBSD: mainbus.c,v 1.12 2002/10/02 03:36:20 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 #include "opt_algor_p4032.h" 40 #include "opt_algor_p5064.h" 41 #include "opt_algor_p6032.h" 42 43 #include "opt_pci.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/conf.h> 48 #include <sys/reboot.h> 49 #include <sys/device.h> 50 #include <sys/malloc.h> 51 #include <sys/extent.h> 52 53 #include <machine/bus.h> 54 #include <machine/autoconf.h> 55 56 #include <mips/cache.h> 57 58 #include <dev/pci/pcivar.h> 59 #include <dev/pci/pciconf.h> 60 61 #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE) 62 #if defined(ALGOR_P5064) || defined(ALGOR_P6032) 63 #include <dev/pci/pciide_piix_reg.h> 64 #endif /* ALGOR_P5064 || ALGOR_P6032 */ 65 #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */ 66 67 #include "locators.h" 68 #include "pci.h" 69 70 int mainbus_match(struct device *, struct cfdata *, void *); 71 void mainbus_attach(struct device *, struct device *, void *); 72 73 CFATTACH_DECL(mainbus, sizeof(struct device), 74 mainbus_match, mainbus_attach, NULL, NULL); 75 76 int mainbus_print(void *, const char *); 77 int mainbus_submatch(struct device *, struct cfdata *, void *); 78 79 /* There can be only one. */ 80 int mainbus_found; 81 82 struct mainbusdev { 83 const char *md_name; 84 bus_addr_t md_addr; 85 int md_irq; 86 }; 87 88 #if defined(ALGOR_P4032) 89 #include <algor/algor/algor_p4032reg.h> 90 #include <algor/algor/algor_p4032var.h> 91 92 struct mainbusdev mainbusdevs[] = { 93 { "cpu", -1, -1 }, 94 { "mcclock", P4032_RTC, P4032_IRQ_RTC }, 95 { "com", P4032_COM1, P4032_IRQ_COM1 }, 96 { "com", P4032_COM2, P4032_IRQ_COM2 }, 97 { "lpt", P4032_LPT, P4032_IRQ_LPT }, 98 { "pckbc", P4032_PCKBC, P4032_IRQ_PCKBC }, 99 { "fdc", P4032_FDC, P4032_IRQ_FLOPPY }, 100 { "vtpbc", P4032_V962PBC, -1 }, 101 102 { NULL, 0, 0 }, 103 }; 104 #endif /* ALGOR_P4032 */ 105 106 #if defined(ALGOR_P5064) 107 #include <algor/algor/algor_p5064reg.h> 108 #include <algor/algor/algor_p5064var.h> 109 110 struct mainbusdev mainbusdevs[] = { 111 { "cpu", -1, -1 }, 112 { "vtpbc", P5064_V360EPC, -1 }, 113 114 { NULL, 0, 0 }, 115 }; 116 #endif /* ALGOR_P5064 */ 117 118 #if defined(ALGOR_P6032) 119 #include <algor/algor/algor_p6032reg.h> 120 #include <algor/algor/algor_p6032var.h> 121 122 struct mainbusdev mainbusdevs[] = { 123 { "cpu", -1, -1 }, 124 { "bonito", BONITO_REG_BASE, -1 }, 125 126 { NULL, 0, 0 }, 127 }; 128 #endif /* ALGOR_P6032 */ 129 130 int 131 mainbus_match(struct device *parent, struct cfdata *cf, void *aux) 132 { 133 134 if (mainbus_found) 135 return (0); 136 137 return (1); 138 } 139 140 void 141 mainbus_attach(struct device *parent, struct device *self, void *aux) 142 { 143 struct mainbus_attach_args ma; 144 struct mainbusdev *md; 145 bus_space_tag_t st; 146 #if defined(PCI_NETBSD_CONFIGURE) 147 struct extent *ioext, *memext; 148 pci_chipset_tag_t pc; 149 #if defined(PCI_NETBSD_ENABLE_IDE) 150 pcitag_t idetag; 151 pcireg_t idetim; 152 #endif 153 #endif 154 155 mainbus_found = 1; 156 157 printf("\n"); 158 159 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) 160 #if defined(ALGOR_P4032) 161 /* 162 * Reserve the bottom 64K of the I/O space for ISA devices. 163 */ 164 ioext = extent_create("pciio", 0x00010000, 0x000effff, 165 M_DEVBUF, NULL, 0, EX_NOWAIT); 166 memext = extent_create("pcimem", 0x01000000, 0x07ffffff, 167 M_DEVBUF, NULL, 0, EX_NOWAIT); 168 169 pc = &p4032_configuration.ac_pc; 170 #elif defined(ALGOR_P5064) 171 /* 172 * Reserve the bottom 512K of the I/O space for ISA devices. 173 * According to the PMON sources, this is a work-around for 174 * a bug in the ISA bridge. 175 */ 176 ioext = extent_create("pciio", 0x00080000, 0x00ffffff, 177 M_DEVBUF, NULL, 0, EX_NOWAIT); 178 memext = extent_create("pcimem", 0x01000000, 0x07ffffff, 179 M_DEVBUF, NULL, 0, EX_NOWAIT); 180 181 pc = &p5064_configuration.ac_pc; 182 #if defined(PCI_NETBSD_ENABLE_IDE) 183 idetag = pci_make_tag(pc, 0, 2, 1); 184 #endif 185 #elif defined(ALGOR_P6032) 186 /* 187 * Reserve the bottom 64K of the I/O space for ISA devices. 188 */ 189 ioext = extent_create("pciio", 0x00010000, 0x000effff, 190 M_DEVBUF, NULL, 0, EX_NOWAIT); 191 memext = extent_create("pcimem", 0x01000000, 0x0affffff, 192 M_DEVBUF, NULL, 0, EX_NOWAIT); 193 194 pc = &p6032_configuration.ac_pc; 195 #if defined(PCI_NETBSD_ENABLE_IDE) 196 idetag = pci_make_tag(pc, 0, 17, 1); 197 #endif 198 #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */ 199 200 pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align); 201 extent_destroy(ioext); 202 extent_destroy(memext); 203 204 #if defined(PCI_NETBSD_ENABLE_IDE) 205 /* 206 * Perhaps PMON has not enabled the IDE controller. Easy to 207 * fix -- just set the ENABLE bits for each channel in the 208 * IDETIM register. Just clear all the bits for the channel 209 * except for the ENABLE bits -- the `pciide' driver will 210 * properly configure it later. 211 */ 212 idetim = 0; 213 if (PCI_NETBSD_ENABLE_IDE & 0x01) 214 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0); 215 if (PCI_NETBSD_ENABLE_IDE & 0x02) 216 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1); 217 pci_conf_write(pc, idetag, PIIX_IDETIM, idetim); 218 #endif 219 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */ 220 221 #if defined(ALGOR_P4032) 222 st = &p4032_configuration.ac_lociot; 223 #elif defined(ALGOR_P5064) 224 st = NULL; 225 #elif defined(ALGOR_P6032) 226 st = NULL; 227 #endif 228 229 for (md = mainbusdevs; md->md_name != NULL; md++) { 230 ma.ma_name = md->md_name; 231 ma.ma_st = st; 232 ma.ma_addr = md->md_addr; 233 ma.ma_irq = md->md_irq; 234 (void) config_found_sm(self, &ma, mainbus_print, 235 mainbus_submatch); 236 } 237 } 238 239 int 240 mainbus_print(void *aux, const char *pnp) 241 { 242 struct mainbus_attach_args *ma = aux; 243 244 if (pnp) 245 printf("%s at %s", ma->ma_name, pnp); 246 if (ma->ma_addr != (bus_addr_t) -1) 247 printf(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR], 248 ma->ma_addr); 249 250 return (UNCONF); 251 } 252 253 int 254 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux) 255 { 256 struct mainbus_attach_args *ma = aux; 257 258 if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT && 259 cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr) 260 return (0); 261 262 return (config_match(parent, cf, aux)); 263 } 264