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