1 /* $NetBSD: isa.c,v 1.97 1997/08/26 19:27:22 augustss Exp $ */ 2 3 /*- 4 * Copyright (c) 1993, 1994 Charles Hannum. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Charles Hannum. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/kernel.h> 35 #include <sys/conf.h> 36 #include <sys/malloc.h> 37 #include <sys/device.h> 38 39 #include <machine/intr.h> 40 41 #include <dev/isa/isareg.h> 42 #include <dev/isa/isavar.h> 43 #include <dev/isa/isadmareg.h> 44 45 #ifdef __BROKEN_INDIRECT_CONFIG 46 int isamatch __P((struct device *, void *, void *)); 47 #else 48 int isamatch __P((struct device *, struct cfdata *, void *)); 49 #endif 50 void isaattach __P((struct device *, struct device *, void *)); 51 int isaprint __P((void *, const char *)); 52 53 struct cfattach isa_ca = { 54 sizeof(struct isa_softc), isamatch, isaattach 55 }; 56 57 struct cfdriver isa_cd = { 58 #ifdef __BROKEN_INDIRECT_CONFIG 59 NULL, "isa", DV_DULL, 1 60 #else 61 NULL, "isa", DV_DULL 62 #endif 63 }; 64 65 #ifdef __BROKEN_INDIRECT_CONFIG 66 void isascan __P((struct device *, void *)); 67 #else 68 int isasearch __P((struct device *, struct cfdata *, void *)); 69 #endif 70 71 int 72 #ifdef __BROKEN_INDIRECT_CONFIG 73 isamatch(parent, match, aux) 74 #else 75 isamatch(parent, cf, aux) 76 #endif 77 struct device *parent; 78 #ifdef __BROKEN_INDIRECT_CONFIG 79 void *match; 80 #else 81 struct cfdata *cf; 82 #endif 83 void *aux; 84 { 85 #ifdef __BROKEN_INDIRECT_CONFIG 86 struct cfdata *cf = match; 87 #endif 88 struct isabus_attach_args *iba = aux; 89 90 if (strcmp(iba->iba_busname, cf->cf_driver->cd_name)) 91 return (0); 92 93 /* XXX check other indicators */ 94 95 return (1); 96 } 97 98 void 99 isaattach(parent, self, aux) 100 struct device *parent, *self; 101 void *aux; 102 { 103 struct isa_softc *sc = (struct isa_softc *)self; 104 struct isabus_attach_args *iba = aux; 105 106 isa_attach_hook(parent, self, iba); 107 printf("\n"); 108 109 sc->sc_iot = iba->iba_iot; 110 sc->sc_memt = iba->iba_memt; 111 sc->sc_dmat = iba->iba_dmat; 112 sc->sc_ic = iba->iba_ic; 113 114 /* 115 * Map the registers used by the ISA DMA controller. 116 */ 117 if (bus_space_map(sc->sc_iot, IO_DMA1, DMA1_IOSIZE, 0, &sc->sc_dma1h)) 118 panic("isaattach: can't map DMA controller #1"); 119 if (bus_space_map(sc->sc_iot, IO_DMA2, DMA2_IOSIZE, 0, &sc->sc_dma2h)) 120 panic("isaattach: can't map DMA controller #2"); 121 if (bus_space_map(sc->sc_iot, IO_DMAPG, 0xf, 0, &sc->sc_dmapgh)) 122 panic("isaattach: can't map DMA page registers"); 123 124 /* 125 * Map port 0x84, which causes a 1.25us delay when read. 126 * We do this now, since several drivers need it. 127 */ 128 if (bus_space_subregion(sc->sc_iot, sc->sc_dmapgh, 0x04, 1, 129 &sc->sc_delaybah)) 130 panic("isaattach: can't map `delay port'"); /* XXX */ 131 132 TAILQ_INIT(&sc->sc_subdevs); 133 #ifdef __BROKEN_INDIRECT_CONFIG 134 config_scan(isascan, self); 135 #else 136 config_search(isasearch, self, NULL); 137 #endif 138 } 139 140 int 141 isaprint(aux, isa) 142 void *aux; 143 const char *isa; 144 { 145 struct isa_attach_args *ia = aux; 146 147 if (ia->ia_iosize) 148 printf(" port 0x%x", ia->ia_iobase); 149 if (ia->ia_iosize > 1) 150 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1); 151 if (ia->ia_msize) 152 printf(" iomem 0x%x", ia->ia_maddr); 153 if (ia->ia_msize > 1) 154 printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1); 155 if (ia->ia_irq != IRQUNK) 156 printf(" irq %d", ia->ia_irq); 157 if (ia->ia_drq != DRQUNK) 158 printf(" drq %d", ia->ia_drq); 159 if (ia->ia_drq2 != DRQUNK) 160 printf(" drq2 %d", ia->ia_drq2); 161 return (UNCONF); 162 } 163 164 #ifdef __BROKEN_INDIRECT_CONFIG 165 void 166 isascan(parent, match) 167 struct device *parent; 168 void *match; 169 { 170 struct isa_softc *sc = (struct isa_softc *)parent; 171 struct device *dev = match; 172 struct cfdata *cf = dev->dv_cfdata; 173 struct isa_attach_args ia; 174 175 #if defined(__i386__) 176 if (cf->cf_fstate == FSTATE_STAR) 177 panic("clone devices not supported on ISA bus"); 178 #endif 179 180 ia.ia_iot = sc->sc_iot; 181 ia.ia_memt = sc->sc_memt; 182 ia.ia_dmat = sc->sc_dmat; 183 ia.ia_ic = sc->sc_ic; 184 ia.ia_iobase = cf->cf_iobase; 185 ia.ia_iosize = 0x666;/* cf->cf_iosize; */ 186 ia.ia_maddr = cf->cf_maddr; 187 ia.ia_msize = cf->cf_msize; 188 ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq; 189 ia.ia_drq = cf->cf_drq; 190 ia.ia_drq2 = cf->cf_drq2; 191 ia.ia_delaybah = sc->sc_delaybah; 192 193 if ((*cf->cf_attach->ca_match)(parent, match, &ia) > 0) 194 config_attach(parent, match, &ia, isaprint); 195 else 196 free(dev, M_DEVBUF); 197 } 198 #else /* !__BROKEN_INDIRECT_CONFIG */ 199 int 200 isasearch(parent, cf, aux) 201 struct device *parent; 202 struct cfdata *cf; 203 void *aux; 204 { 205 struct isa_softc *sc = (struct isa_softc *)parent; 206 struct isa_attach_args ia; 207 int tryagain; 208 209 do { 210 ia.ia_iot = sc->sc_iot; 211 ia.ia_memt = sc->sc_memt; 212 ia.ia_dmat = sc->sc_dmat; 213 ia.ia_ic = sc->sc_ic; 214 ia.ia_iobase = cf->cf_iobase; 215 ia.ia_iosize = 0x666; /* cf->cf_iosize; */ 216 ia.ia_maddr = cf->cf_maddr; 217 ia.ia_msize = cf->cf_msize; 218 ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq; 219 ia.ia_drq = cf->cf_drq; 220 ia.ia_drq2 = cf->cf_drq2; 221 ia.ia_delaybah = sc->sc_delaybah; 222 223 tryagain = 0; 224 if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) { 225 config_attach(parent, cf, &ia, isaprint); 226 tryagain = (cf->cf_fstate == FSTATE_STAR); 227 } 228 } while (tryagain); 229 230 return (0); 231 } 232 #endif /* __BROKEN_INDIRECT_CONFIG */ 233 234 char * 235 isa_intr_typename(type) 236 int type; 237 { 238 239 switch (type) { 240 case IST_NONE : 241 return ("none"); 242 case IST_PULSE: 243 return ("pulsed"); 244 case IST_EDGE: 245 return ("edge-triggered"); 246 case IST_LEVEL: 247 return ("level-triggered"); 248 default: 249 panic("isa_intr_typename: invalid type %d", type); 250 } 251 } 252