1 /* $NetBSD: sio.c,v 1.39 2004/09/13 18:42:59 drochner Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 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 /* 40 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 41 * All rights reserved. 42 * 43 * Author: Chris G. Demetriou 44 * 45 * Permission to use, copy, modify and distribute this software and 46 * its documentation is hereby granted, provided that both the copyright 47 * notice and this permission notice appear in all copies of the 48 * software, derivative works or modified versions, and any portions 49 * thereof, and that both notices appear in supporting documentation. 50 * 51 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 52 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 53 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 54 * 55 * Carnegie Mellon requests users of this software to return to 56 * 57 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 58 * School of Computer Science 59 * Carnegie Mellon University 60 * Pittsburgh PA 15213-3890 61 * 62 * any improvements or extensions that they make and grant Carnegie the 63 * rights to redistribute these changes. 64 */ 65 66 #include "opt_dec_2100_a500.h" 67 #include "opt_dec_2100a_a500.h" 68 #include "eisa.h" 69 #include "sio.h" 70 71 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 72 73 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.39 2004/09/13 18:42:59 drochner Exp $"); 74 75 #include <sys/param.h> 76 #include <sys/systm.h> 77 #include <sys/kernel.h> 78 #include <sys/device.h> 79 #include <sys/malloc.h> 80 81 #include <machine/intr.h> 82 #include <machine/bus.h> 83 #include <machine/rpb.h> 84 85 #include <dev/isa/isavar.h> 86 #include <dev/eisa/eisavar.h> 87 88 #include <dev/pci/pcireg.h> 89 #include <dev/pci/pcivar.h> 90 #include <dev/pci/pcidevs.h> 91 92 #include <alpha/pci/siovar.h> 93 94 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500) 95 #include <alpha/pci/pci_2100_a500.h> 96 #include <alpha/sableio/sableiovar.h> 97 #endif 98 99 struct sio_softc { 100 struct device sc_dv; 101 102 pci_chipset_tag_t sc_pc; 103 104 bus_space_tag_t sc_iot, sc_memt; 105 bus_dma_tag_t sc_parent_dmat; 106 #if NPCEB > 0 107 int sc_haseisa; 108 #endif 109 int sc_is82c693; 110 111 /* ISA chipset must persist; it's used after autoconfig. */ 112 isa_chipset_tag_t sc_ic; 113 }; 114 115 int siomatch __P((struct device *, struct cfdata *, void *)); 116 void sioattach __P((struct device *, struct device *, void *)); 117 118 CFATTACH_DECL(sio, sizeof(struct sio_softc), 119 siomatch, sioattach, NULL, NULL); 120 121 #if NPCEB > 0 122 int pcebmatch __P((struct device *, struct cfdata *, void *)); 123 124 CFATTACH_DECL(pceb, sizeof(struct sio_softc), 125 pcebmatch, sioattach, NULL, NULL); 126 #endif 127 128 union sio_attach_args { 129 struct isabus_attach_args sa_iba; 130 struct eisabus_attach_args sa_eba; 131 }; 132 133 void sio_isa_attach_hook __P((struct device *, struct device *, 134 struct isabus_attach_args *)); 135 #if NPCEB > 0 136 void sio_eisa_attach_hook __P((struct device *, struct device *, 137 struct eisabus_attach_args *)); 138 int sio_eisa_maxslots __P((void *)); 139 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *)); 140 #endif 141 142 void sio_bridge_callback __P((struct device *)); 143 144 int 145 siomatch(parent, match, aux) 146 struct device *parent; 147 struct cfdata *match; 148 void *aux; 149 { 150 struct pci_attach_args *pa = aux; 151 152 /* 153 * The Cypress 82C693 is more-or-less an SIO, but with 154 * indirect register access. (XXX for everything, or 155 * just the ELCR?) 156 */ 157 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ && 158 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 && 159 pa->pa_function == 0) 160 return (1); 161 162 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL && 163 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO) 164 return (1); 165 166 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI && 167 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1543) 168 return (1); 169 170 return (0); 171 } 172 173 #if NPCEB > 0 174 int 175 pcebmatch(parent, match, aux) 176 struct device *parent; 177 struct cfdata *match; 178 void *aux; 179 { 180 struct pci_attach_args *pa = aux; 181 182 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL && 183 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB) 184 return (1); 185 186 return (0); 187 } 188 #endif 189 190 void 191 sioattach(parent, self, aux) 192 struct device *parent, *self; 193 void *aux; 194 { 195 struct sio_softc *sc = (struct sio_softc *)self; 196 struct pci_attach_args *pa = aux; 197 char devinfo[256]; 198 199 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo)); 200 printf(": %s (rev. 0x%02x)\n", devinfo, 201 PCI_REVISION(pa->pa_class)); 202 203 sc->sc_pc = pa->pa_pc; 204 sc->sc_iot = pa->pa_iot; 205 sc->sc_memt = pa->pa_memt; 206 sc->sc_parent_dmat = pa->pa_dmat; 207 #if NPCEB > 0 208 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL && 209 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB); 210 #endif 211 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ && 212 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693); 213 214 config_defer(self, sio_bridge_callback); 215 } 216 217 void 218 sio_bridge_callback(self) 219 struct device *self; 220 { 221 struct sio_softc *sc = (struct sio_softc *)self; 222 union sio_attach_args sa; 223 #if NPCEB > 0 224 struct alpha_eisa_chipset ec; 225 226 if (sc->sc_haseisa) { 227 ec.ec_v = NULL; 228 ec.ec_attach_hook = sio_eisa_attach_hook; 229 ec.ec_maxslots = sio_eisa_maxslots; 230 231 /* 232 * Deal with platforms that hook EISA interrupts 233 * up differently. 234 */ 235 switch (cputype) { 236 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500) 237 case ST_DEC_2100_A500: 238 case ST_DEC_2100A_A500: 239 pci_2100_a500_eisa_pickintr(sc->sc_pc, &ec); 240 break; 241 #endif 242 default: 243 ec.ec_intr_map = sio_eisa_intr_map; 244 ec.ec_intr_string = sio_intr_string; 245 ec.ec_intr_evcnt = sio_intr_evcnt; 246 ec.ec_intr_establish = sio_intr_establish; 247 ec.ec_intr_disestablish = sio_intr_disestablish; 248 } 249 250 sa.sa_eba.eba_iot = sc->sc_iot; 251 sa.sa_eba.eba_memt = sc->sc_memt; 252 sa.sa_eba.eba_dmat = 253 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA); 254 sa.sa_eba.eba_ec = &ec; 255 config_found_ia(&sc->sc_dv, "eisabus", &sa.sa_eba, 256 eisabusprint); 257 } 258 #endif /* NPCEB */ 259 260 /* 261 * Deal with platforms which have Odd ISA DMA needs. 262 */ 263 switch (cputype) { 264 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500) 265 case ST_DEC_2100_A500: 266 case ST_DEC_2100A_A500: 267 sc->sc_ic = sableio_pickisa(); 268 break; 269 #endif 270 default: 271 sc->sc_ic = malloc(sizeof(*sc->sc_ic), M_DEVBUF, M_WAITOK); 272 memset(sc->sc_ic, 0, sizeof(*sc->sc_ic)); 273 } 274 275 sc->sc_ic->ic_v = NULL; 276 sc->sc_ic->ic_attach_hook = sio_isa_attach_hook; 277 278 /* 279 * Deal with platforms that hook up ISA interrupts differently. 280 */ 281 switch (cputype) { 282 #if defined(DEC_2100_A500) || defined(DEC_2100A_A500) 283 case ST_DEC_2100_A500: 284 case ST_DEC_2100A_A500: 285 pci_2100_a500_isa_pickintr(sc->sc_pc, sc->sc_ic); 286 break; 287 #endif 288 default: 289 sc->sc_ic->ic_intr_evcnt = sio_intr_evcnt; 290 sc->sc_ic->ic_intr_establish = sio_intr_establish; 291 sc->sc_ic->ic_intr_disestablish = sio_intr_disestablish; 292 sc->sc_ic->ic_intr_alloc = sio_intr_alloc; 293 } 294 295 sa.sa_iba.iba_iot = sc->sc_iot; 296 sa.sa_iba.iba_memt = sc->sc_memt; 297 sa.sa_iba.iba_dmat = 298 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA); 299 sa.sa_iba.iba_ic = sc->sc_ic; 300 config_found_ia(&sc->sc_dv, "isabus", &sa.sa_iba, isabusprint); 301 } 302 303 void 304 sio_isa_attach_hook(parent, self, iba) 305 struct device *parent, *self; 306 struct isabus_attach_args *iba; 307 { 308 309 /* Nothing to do. */ 310 } 311 312 #if NPCEB > 0 313 314 void 315 sio_eisa_attach_hook(parent, self, eba) 316 struct device *parent, *self; 317 struct eisabus_attach_args *eba; 318 { 319 320 #if NEISA > 0 321 eisa_init(); 322 #endif 323 } 324 325 int 326 sio_eisa_maxslots(v) 327 void *v; 328 { 329 330 return 16; /* as good a number as any. only 8, maybe? */ 331 } 332 333 int 334 sio_eisa_intr_map(v, irq, ihp) 335 void *v; 336 u_int irq; 337 eisa_intr_handle_t *ihp; 338 { 339 340 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */ 341 342 if (irq >= ICU_LEN) { 343 printf("sio_eisa_intr_map: bad IRQ %d\n", irq); 344 *ihp = -1; 345 return 1; 346 } 347 if (irq == 2) { 348 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n"); 349 irq = 9; 350 } 351 352 *ihp = irq; 353 return 0; 354 } 355 356 #endif /* NPCEB */ 357