Home | History | Annotate | Line # | Download | only in isa
isa.c revision 1.81
      1 /*	$NetBSD: isa.c,v 1.81 1996/04/29 20:03:24 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 #ifndef i386							/* XXX */
     39 #include <machine/intr.h>
     40 #endif								/* XXX */
     41 
     42 #include <dev/isa/isareg.h>
     43 #include <dev/isa/isavar.h>
     44 
     45 int isamatch __P((struct device *, void *, void *));
     46 void isaattach __P((struct device *, struct device *, void *));
     47 int isaprint __P((void *, char *));
     48 
     49 struct cfattach isa_ca = {
     50 	sizeof(struct isa_softc), isamatch, isaattach
     51 };
     52 
     53 struct cfdriver isa_cd = {
     54 	NULL, "isa", DV_DULL, 1
     55 };
     56 
     57 int
     58 isamatch(parent, match, aux)
     59 	struct device *parent;
     60 	void *match, *aux;
     61 {
     62 	struct cfdata *cf = match;
     63 	struct isabus_attach_args *iba = aux;
     64 
     65 	if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
     66 		return (0);
     67 
     68 	/* XXX check other indicators */
     69 
     70         return (1);
     71 }
     72 
     73 void
     74 isaattach(parent, self, aux)
     75 	struct device *parent, *self;
     76 	void *aux;
     77 {
     78 	struct isa_softc *sc = (struct isa_softc *)self;
     79 	struct isabus_attach_args *iba = aux;
     80 
     81 	isa_attach_hook(parent, self, iba);
     82 	printf("\n");
     83 
     84 	sc->sc_bc = iba->iba_bc;
     85 	sc->sc_ic = iba->iba_ic;
     86 
     87 	TAILQ_INIT(&sc->sc_subdevs);
     88 	config_scan(isascan, self);
     89 }
     90 
     91 int
     92 isaprint(aux, isa)
     93 	void *aux;
     94 	char *isa;
     95 {
     96 	struct isa_attach_args *ia = aux;
     97 
     98 	if (ia->ia_iosize)
     99 		printf(" port 0x%x", ia->ia_iobase);
    100 	if (ia->ia_iosize > 1)
    101 		printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
    102 	if (ia->ia_msize)
    103 		printf(" iomem 0x%x", ia->ia_maddr);
    104 	if (ia->ia_msize > 1)
    105 		printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
    106 	if (ia->ia_irq != IRQUNK)
    107 		printf(" irq %d", ia->ia_irq);
    108 	if (ia->ia_drq != DRQUNK)
    109 		printf(" drq %d", ia->ia_drq);
    110 	return (UNCONF);
    111 }
    112 
    113 void
    114 isascan(parent, match)
    115 	struct device *parent;
    116 	void *match;
    117 {
    118 	struct isa_softc *sc = (struct isa_softc *)parent;
    119 	struct device *dev = match;
    120 	struct cfdata *cf = dev->dv_cfdata;
    121 	struct isa_attach_args ia;
    122 
    123 	if (cf->cf_fstate == FSTATE_STAR)
    124 		panic("clone devices not supported on ISA bus");
    125 
    126 	ia.ia_bc = sc->sc_bc;
    127 	ia.ia_ic = sc->sc_ic;
    128 	ia.ia_iobase = cf->cf_loc[0];
    129 	ia.ia_iosize = 0x666;
    130 	ia.ia_maddr = cf->cf_loc[2];
    131 	ia.ia_msize = cf->cf_loc[3];
    132 	ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
    133 	ia.ia_drq = cf->cf_loc[5];
    134 
    135 	if ((*cf->cf_attach->ca_match)(parent, dev, &ia) > 0)
    136 		config_attach(parent, dev, &ia, isaprint);
    137 	else
    138 		free(dev, M_DEVBUF);
    139 }
    140 
    141 char *
    142 isa_intr_typename(type)
    143 	int type;
    144 {
    145 
    146 	switch (type) {
    147         case IST_NONE :
    148 		return ("none");
    149         case IST_PULSE:
    150 		return ("pulsed");
    151         case IST_EDGE:
    152 		return ("edge-triggered");
    153         case IST_LEVEL:
    154 		return ("level-triggered");
    155 	default:
    156 		panic("isa_intr_typename: invalid type %d", type);
    157 	}
    158 }
    159