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