1 /* $NetBSD: mainbus.c,v 1.14 2003/07/14 22:57:47 lukem 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 <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.14 2003/07/14 22:57:47 lukem Exp $"); 41 42 #include "opt_algor_p4032.h" 43 #include "opt_algor_p5064.h" 44 #include "opt_algor_p6032.h" 45 46 #include "opt_pci.h" 47 48 #include <sys/param.h> 49 #include <sys/systm.h> 50 #include <sys/conf.h> 51 #include <sys/reboot.h> 52 #include <sys/device.h> 53 #include <sys/malloc.h> 54 #include <sys/extent.h> 55 56 #include <machine/bus.h> 57 #include <machine/autoconf.h> 58 59 #include <mips/cache.h> 60 61 #include <dev/pci/pcivar.h> 62 #include <dev/pci/pciconf.h> 63 64 #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE) 65 #if defined(ALGOR_P5064) || defined(ALGOR_P6032) 66 #include <dev/pci/pciide_piix_reg.h> 67 #endif /* ALGOR_P5064 || ALGOR_P6032 */ 68 #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */ 69 70 #include "locators.h" 71 #include "pci.h" 72 73 int mainbus_match(struct device *, struct cfdata *, void *); 74 void mainbus_attach(struct device *, struct device *, void *); 75 76 CFATTACH_DECL(mainbus, sizeof(struct device), 77 mainbus_match, mainbus_attach, NULL, NULL); 78 79 int mainbus_print(void *, const char *); 80 int mainbus_submatch(struct device *, struct cfdata *, void *); 81 82 /* There can be only one. */ 83 int mainbus_found; 84 85 struct mainbusdev { 86 const char *md_name; 87 bus_addr_t md_addr; 88 int md_irq; 89 }; 90 91 #if defined(ALGOR_P4032) 92 #include <algor/algor/algor_p4032reg.h> 93 #include <algor/algor/algor_p4032var.h> 94 95 struct mainbusdev mainbusdevs[] = { 96 { "cpu", -1, -1 }, 97 { "mcclock", P4032_RTC, P4032_IRQ_RTC }, 98 { "com", P4032_COM1, P4032_IRQ_COM1 }, 99 { "com", P4032_COM2, P4032_IRQ_COM2 }, 100 { "lpt", P4032_LPT, P4032_IRQ_LPT }, 101 { "pckbc", P4032_PCKBC, P4032_IRQ_PCKBC }, 102 { "fdc", P4032_FDC, P4032_IRQ_FLOPPY }, 103 { "vtpbc", P4032_V962PBC, -1 }, 104 105 { NULL, 0, 0 }, 106 }; 107 #endif /* ALGOR_P4032 */ 108 109 #if defined(ALGOR_P5064) 110 #include <algor/algor/algor_p5064reg.h> 111 #include <algor/algor/algor_p5064var.h> 112 113 struct mainbusdev mainbusdevs[] = { 114 { "cpu", -1, -1 }, 115 { "vtpbc", P5064_V360EPC, -1 }, 116 117 { NULL, 0, 0 }, 118 }; 119 #endif /* ALGOR_P5064 */ 120 121 #if defined(ALGOR_P6032) 122 #include <algor/algor/algor_p6032reg.h> 123 #include <algor/algor/algor_p6032var.h> 124 125 struct mainbusdev mainbusdevs[] = { 126 { "cpu", -1, -1 }, 127 { "bonito", BONITO_REG_BASE, -1 }, 128 129 { NULL, 0, 0 }, 130 }; 131 #endif /* ALGOR_P6032 */ 132 133 int 134 mainbus_match(struct device *parent, struct cfdata *cf, void *aux) 135 { 136 137 if (mainbus_found) 138 return (0); 139 140 return (1); 141 } 142 143 void 144 mainbus_attach(struct device *parent, struct device *self, void *aux) 145 { 146 struct mainbus_attach_args ma; 147 struct mainbusdev *md; 148 bus_space_tag_t st; 149 #if defined(PCI_NETBSD_CONFIGURE) 150 struct extent *ioext, *memext; 151 pci_chipset_tag_t pc; 152 #if defined(PCI_NETBSD_ENABLE_IDE) 153 pcitag_t idetag; 154 pcireg_t idetim; 155 #endif 156 #endif 157 158 mainbus_found = 1; 159 160 printf("\n"); 161 162 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) 163 #if defined(ALGOR_P4032) 164 /* 165 * Reserve the bottom 64K of the I/O space for ISA devices. 166 */ 167 ioext = extent_create("pciio", 0x00010000, 0x000effff, 168 M_DEVBUF, NULL, 0, EX_NOWAIT); 169 memext = extent_create("pcimem", 0x01000000, 0x07ffffff, 170 M_DEVBUF, NULL, 0, EX_NOWAIT); 171 172 pc = &p4032_configuration.ac_pc; 173 #elif defined(ALGOR_P5064) 174 /* 175 * Reserve the bottom 512K of the I/O space for ISA devices. 176 * According to the PMON sources, this is a work-around for 177 * a bug in the ISA bridge. 178 */ 179 ioext = extent_create("pciio", 0x00080000, 0x00ffffff, 180 M_DEVBUF, NULL, 0, EX_NOWAIT); 181 memext = extent_create("pcimem", 0x01000000, 0x07ffffff, 182 M_DEVBUF, NULL, 0, EX_NOWAIT); 183 184 pc = &p5064_configuration.ac_pc; 185 #if defined(PCI_NETBSD_ENABLE_IDE) 186 idetag = pci_make_tag(pc, 0, 2, 1); 187 #endif 188 #elif defined(ALGOR_P6032) 189 /* 190 * Reserve the bottom 64K of the I/O space for ISA devices. 191 */ 192 ioext = extent_create("pciio", 0x00010000, 0x000effff, 193 M_DEVBUF, NULL, 0, EX_NOWAIT); 194 memext = extent_create("pcimem", 0x01000000, 0x0affffff, 195 M_DEVBUF, NULL, 0, EX_NOWAIT); 196 197 pc = &p6032_configuration.ac_pc; 198 #if defined(PCI_NETBSD_ENABLE_IDE) 199 idetag = pci_make_tag(pc, 0, 17, 1); 200 #endif 201 #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */ 202 203 pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align); 204 extent_destroy(ioext); 205 extent_destroy(memext); 206 207 #if defined(PCI_NETBSD_ENABLE_IDE) 208 /* 209 * Perhaps PMON has not enabled the IDE controller. Easy to 210 * fix -- just set the ENABLE bits for each channel in the 211 * IDETIM register. Just clear all the bits for the channel 212 * except for the ENABLE bits -- the `pciide' driver will 213 * properly configure it later. 214 */ 215 idetim = 0; 216 if (PCI_NETBSD_ENABLE_IDE & 0x01) 217 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0); 218 if (PCI_NETBSD_ENABLE_IDE & 0x02) 219 idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1); 220 pci_conf_write(pc, idetag, PIIX_IDETIM, idetim); 221 #endif 222 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */ 223 224 #if defined(ALGOR_P4032) 225 st = &p4032_configuration.ac_lociot; 226 #elif defined(ALGOR_P5064) 227 st = NULL; 228 #elif defined(ALGOR_P6032) 229 st = NULL; 230 #endif 231 232 for (md = mainbusdevs; md->md_name != NULL; md++) { 233 ma.ma_name = md->md_name; 234 ma.ma_st = st; 235 ma.ma_addr = md->md_addr; 236 ma.ma_irq = md->md_irq; 237 (void) config_found_sm(self, &ma, mainbus_print, 238 mainbus_submatch); 239 } 240 } 241 242 int 243 mainbus_print(void *aux, const char *pnp) 244 { 245 struct mainbus_attach_args *ma = aux; 246 247 if (pnp) 248 aprint_normal("%s at %s", ma->ma_name, pnp); 249 if (ma->ma_addr != (bus_addr_t) -1) 250 aprint_normal(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR], 251 ma->ma_addr); 252 253 return (UNCONF); 254 } 255 256 int 257 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux) 258 { 259 struct mainbus_attach_args *ma = aux; 260 261 if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT && 262 cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr) 263 return (0); 264 265 return (config_match(parent, cf, aux)); 266 } 267