1 /* $NetBSD: isa.c,v 1.106 1999/02/19 16:15:06 mycroft Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Charles M. Hannum. 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/param.h> 40 #include <sys/systm.h> 41 #include <sys/kernel.h> 42 #include <sys/conf.h> 43 #include <sys/malloc.h> 44 #include <sys/device.h> 45 46 #include <machine/intr.h> 47 48 #include <dev/isa/isareg.h> 49 #include <dev/isa/isavar.h> 50 #include <dev/isa/isadmareg.h> 51 52 #include "isadma.h" 53 54 #include "isapnp.h" 55 #ifdef NISAPNP 56 #include <dev/isapnp/isapnpreg.h> 57 #include <dev/isapnp/isapnpvar.h> 58 #endif 59 60 int isamatch __P((struct device *, struct cfdata *, void *)); 61 void isaattach __P((struct device *, struct device *, void *)); 62 int isaprint __P((void *, const char *)); 63 64 struct cfattach isa_ca = { 65 sizeof(struct isa_softc), isamatch, isaattach 66 }; 67 68 int isasearch __P((struct device *, struct cfdata *, void *)); 69 70 int 71 isamatch(parent, cf, aux) 72 struct device *parent; 73 struct cfdata *cf; 74 void *aux; 75 { 76 struct isabus_attach_args *iba = aux; 77 78 if (strcmp(iba->iba_busname, cf->cf_driver->cd_name)) 79 return (0); 80 81 /* XXX check other indicators */ 82 83 return (1); 84 } 85 86 void 87 isaattach(parent, self, aux) 88 struct device *parent, *self; 89 void *aux; 90 { 91 struct isa_softc *sc = (struct isa_softc *)self; 92 struct isabus_attach_args *iba = aux; 93 94 isa_attach_hook(parent, self, iba); 95 printf("\n"); 96 97 sc->sc_iot = iba->iba_iot; 98 sc->sc_memt = iba->iba_memt; 99 sc->sc_dmat = iba->iba_dmat; 100 sc->sc_ic = iba->iba_ic; 101 102 #if NISAPNP > 0 103 /* 104 * Reset isapnp cards that the bios configured for us 105 */ 106 isapnp_isa_attach_hook(sc); 107 #endif 108 109 #if NISADMA > 0 110 /* 111 * Initialize our DMA state. 112 */ 113 isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self); 114 #endif 115 116 config_search(isasearch, self, NULL); 117 } 118 119 int 120 isaprint(aux, isa) 121 void *aux; 122 const char *isa; 123 { 124 struct isa_attach_args *ia = aux; 125 126 if (ia->ia_iosize) 127 printf(" port 0x%x", ia->ia_iobase); 128 if (ia->ia_iosize > 1) 129 printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1); 130 if (ia->ia_msize) 131 printf(" iomem 0x%x", ia->ia_maddr); 132 if (ia->ia_msize > 1) 133 printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1); 134 if (ia->ia_irq != IRQUNK) 135 printf(" irq %d", ia->ia_irq); 136 if (ia->ia_drq != DRQUNK) 137 printf(" drq %d", ia->ia_drq); 138 if (ia->ia_drq2 != DRQUNK) 139 printf(" drq2 %d", ia->ia_drq2); 140 return (UNCONF); 141 } 142 143 int 144 isasearch(parent, cf, aux) 145 struct device *parent; 146 struct cfdata *cf; 147 void *aux; 148 { 149 struct isa_softc *sc = (struct isa_softc *)parent; 150 struct isa_attach_args ia; 151 int tryagain; 152 153 do { 154 ia.ia_iot = sc->sc_iot; 155 ia.ia_memt = sc->sc_memt; 156 ia.ia_dmat = sc->sc_dmat; 157 ia.ia_ic = sc->sc_ic; 158 ia.ia_iobase = cf->cf_iobase; 159 ia.ia_iosize = 0x666; /* cf->cf_iosize; */ 160 ia.ia_maddr = cf->cf_maddr; 161 ia.ia_msize = cf->cf_msize; 162 ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq; 163 ia.ia_drq = cf->cf_drq; 164 ia.ia_drq2 = cf->cf_drq2; 165 166 tryagain = 0; 167 if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) { 168 config_attach(parent, cf, &ia, isaprint); 169 tryagain = (cf->cf_fstate == FSTATE_STAR); 170 } 171 } while (tryagain); 172 173 return (0); 174 } 175 176 char * 177 isa_intr_typename(type) 178 int type; 179 { 180 181 switch (type) { 182 case IST_NONE : 183 return ("none"); 184 case IST_PULSE: 185 return ("pulsed"); 186 case IST_EDGE: 187 return ("edge-triggered"); 188 case IST_LEVEL: 189 return ("level-triggered"); 190 default: 191 panic("isa_intr_typename: invalid type %d", type); 192 } 193 } 194