1 /* $NetBSD: sio.c,v 1.29 2000/06/05 21:47:28 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 32 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.29 2000/06/05 21:47:28 thorpej Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/device.h> 38 39 #include <machine/intr.h> 40 #include <machine/bus.h> 41 42 #include <dev/isa/isavar.h> 43 #include <dev/eisa/eisavar.h> 44 45 #include <dev/pci/pcireg.h> 46 #include <dev/pci/pcivar.h> 47 #include <dev/pci/pcidevs.h> 48 49 #include <alpha/pci/siovar.h> 50 51 struct sio_softc { 52 struct device sc_dv; 53 54 bus_space_tag_t sc_iot, sc_memt; 55 bus_dma_tag_t sc_parent_dmat; 56 int sc_haseisa; 57 int sc_is82c693; 58 59 /* ISA chipset must persist; it's used after autoconfig. */ 60 struct alpha_isa_chipset sc_isa_chipset; 61 }; 62 63 int siomatch __P((struct device *, struct cfdata *, void *)); 64 void sioattach __P((struct device *, struct device *, void *)); 65 66 struct cfattach sio_ca = { 67 sizeof(struct sio_softc), siomatch, sioattach, 68 }; 69 70 int pcebmatch __P((struct device *, struct cfdata *, void *)); 71 72 struct cfattach pceb_ca = { 73 sizeof(struct sio_softc), pcebmatch, sioattach, 74 }; 75 76 union sio_attach_args { 77 const char *sa_name; /* XXX should be common */ 78 struct isabus_attach_args sa_iba; 79 struct eisabus_attach_args sa_eba; 80 }; 81 82 int sioprint __P((void *, const char *pnp)); 83 void sio_isa_attach_hook __P((struct device *, struct device *, 84 struct isabus_attach_args *)); 85 void sio_eisa_attach_hook __P((struct device *, struct device *, 86 struct eisabus_attach_args *)); 87 int sio_eisa_maxslots __P((void *)); 88 int sio_eisa_intr_map __P((void *, u_int, eisa_intr_handle_t *)); 89 90 void sio_bridge_callback __P((struct device *)); 91 92 int 93 siomatch(parent, match, aux) 94 struct device *parent; 95 struct cfdata *match; 96 void *aux; 97 { 98 struct pci_attach_args *pa = aux; 99 100 /* 101 * The Cypress 82C693 is more-or-less an SIO, but with 102 * indirect register access. (XXX for everything, or 103 * just the ELCR?) 104 */ 105 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ && 106 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693 && 107 pa->pa_function == 0) 108 return (1); 109 110 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL && 111 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_SIO) 112 return (1); 113 114 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ALI && 115 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ALI_M1543) 116 return (1); 117 118 return (0); 119 } 120 121 int 122 pcebmatch(parent, match, aux) 123 struct device *parent; 124 struct cfdata *match; 125 void *aux; 126 { 127 struct pci_attach_args *pa = aux; 128 129 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL && 130 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB) 131 return (1); 132 133 return (0); 134 } 135 136 void 137 sioattach(parent, self, aux) 138 struct device *parent, *self; 139 void *aux; 140 { 141 struct sio_softc *sc = (struct sio_softc *)self; 142 struct pci_attach_args *pa = aux; 143 char devinfo[256]; 144 145 pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo); 146 printf(": %s (rev. 0x%02x)\n", devinfo, 147 PCI_REVISION(pa->pa_class)); 148 149 sc->sc_iot = pa->pa_iot; 150 sc->sc_memt = pa->pa_memt; 151 sc->sc_parent_dmat = pa->pa_dmat; 152 sc->sc_haseisa = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL && 153 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEL_PCEB); 154 sc->sc_is82c693 = (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_CONTAQ && 155 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_CONTAQ_82C693); 156 157 config_defer(self, sio_bridge_callback); 158 } 159 160 void 161 sio_bridge_callback(self) 162 struct device *self; 163 { 164 struct sio_softc *sc = (struct sio_softc *)self; 165 struct alpha_eisa_chipset ec; 166 union sio_attach_args sa; 167 168 if (sc->sc_haseisa) { 169 ec.ec_v = NULL; 170 ec.ec_attach_hook = sio_eisa_attach_hook; 171 ec.ec_maxslots = sio_eisa_maxslots; 172 ec.ec_intr_map = sio_eisa_intr_map; 173 ec.ec_intr_string = sio_intr_string; 174 ec.ec_intr_evcnt = sio_intr_evcnt; 175 ec.ec_intr_establish = sio_intr_establish; 176 ec.ec_intr_disestablish = sio_intr_disestablish; 177 178 sa.sa_eba.eba_busname = "eisa"; 179 sa.sa_eba.eba_iot = sc->sc_iot; 180 sa.sa_eba.eba_memt = sc->sc_memt; 181 sa.sa_eba.eba_dmat = 182 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_EISA); 183 sa.sa_eba.eba_ec = &ec; 184 config_found(&sc->sc_dv, &sa.sa_eba, sioprint); 185 } 186 187 sc->sc_isa_chipset.ic_v = NULL; 188 sc->sc_isa_chipset.ic_attach_hook = sio_isa_attach_hook; 189 sc->sc_isa_chipset.ic_intr_evcnt = sio_intr_evcnt; 190 sc->sc_isa_chipset.ic_intr_establish = sio_intr_establish; 191 sc->sc_isa_chipset.ic_intr_disestablish = sio_intr_disestablish; 192 sc->sc_isa_chipset.ic_intr_alloc = sio_intr_alloc; 193 194 sa.sa_iba.iba_busname = "isa"; 195 sa.sa_iba.iba_iot = sc->sc_iot; 196 sa.sa_iba.iba_memt = sc->sc_memt; 197 sa.sa_iba.iba_dmat = 198 alphabus_dma_get_tag(sc->sc_parent_dmat, ALPHA_BUS_ISA); 199 sa.sa_iba.iba_ic = &sc->sc_isa_chipset; 200 config_found(&sc->sc_dv, &sa.sa_iba, sioprint); 201 } 202 203 int 204 sioprint(aux, pnp) 205 void *aux; 206 const char *pnp; 207 { 208 register union sio_attach_args *sa = aux; 209 210 if (pnp) 211 printf("%s at %s", sa->sa_name, pnp); 212 return (UNCONF); 213 } 214 215 void 216 sio_isa_attach_hook(parent, self, iba) 217 struct device *parent, *self; 218 struct isabus_attach_args *iba; 219 { 220 221 /* Nothing to do. */ 222 } 223 224 void 225 sio_eisa_attach_hook(parent, self, eba) 226 struct device *parent, *self; 227 struct eisabus_attach_args *eba; 228 { 229 230 /* Nothing to do. */ 231 } 232 233 int 234 sio_eisa_maxslots(v) 235 void *v; 236 { 237 238 return 16; /* as good a number as any. only 8, maybe? */ 239 } 240 241 int 242 sio_eisa_intr_map(v, irq, ihp) 243 void *v; 244 u_int irq; 245 eisa_intr_handle_t *ihp; 246 { 247 248 #define ICU_LEN 16 /* number of ISA IRQs (XXX) */ 249 250 if (irq >= ICU_LEN) { 251 printf("sio_eisa_intr_map: bad IRQ %d\n", irq); 252 *ihp = -1; 253 return 1; 254 } 255 if (irq == 2) { 256 printf("sio_eisa_intr_map: changed IRQ 2 to IRQ 9\n"); 257 irq = 9; 258 } 259 260 *ihp = irq; 261 return 0; 262 } 263