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