Home | History | Annotate | Line # | Download | only in isa
isa.c revision 1.91
      1  1.91       cgd /*	$NetBSD: isa.c,v 1.91 1996/12/05 01:25:40 cgd Exp $	*/
      2  1.58       cgd 
      3   1.1       cgd /*-
      4  1.59   mycroft  * Copyright (c) 1993, 1994 Charles Hannum.  All rights reserved.
      5   1.1       cgd  *
      6   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      7   1.1       cgd  * modification, are permitted provided that the following conditions
      8   1.1       cgd  * are met:
      9   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     10   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     11   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     13   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     14   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     15   1.1       cgd  *    must display the following acknowledgement:
     16  1.59   mycroft  *	This product includes software developed by Charles Hannum.
     17  1.59   mycroft  * 4. The name of the author may not be used to endorse or promote products
     18  1.59   mycroft  *    derived from this software without specific prior written permission.
     19   1.1       cgd  *
     20  1.59   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.59   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.59   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.59   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.59   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.59   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.59   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.59   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.59   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.59   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32  1.31   mycroft #include <sys/param.h>
     33  1.31   mycroft #include <sys/systm.h>
     34  1.40   mycroft #include <sys/kernel.h>
     35  1.31   mycroft #include <sys/conf.h>
     36  1.31   mycroft #include <sys/malloc.h>
     37  1.46   mycroft #include <sys/device.h>
     38  1.85   thorpej 
     39  1.85   thorpej #include <machine/intr.h>
     40  1.31   mycroft 
     41  1.72       cgd #include <dev/isa/isareg.h>
     42  1.72       cgd #include <dev/isa/isavar.h>
     43  1.77       cgd 
     44  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     45  1.77       cgd int isamatch __P((struct device *, void *, void *));
     46  1.91       cgd #else
     47  1.91       cgd int isamatch __P((struct device *, struct cfdata *, void *));
     48  1.91       cgd #endif
     49  1.77       cgd void isaattach __P((struct device *, struct device *, void *));
     50  1.86       cgd int isaprint __P((void *, const char *));
     51  1.77       cgd 
     52  1.79   thorpej struct cfattach isa_ca = {
     53  1.79   thorpej 	sizeof(struct isa_softc), isamatch, isaattach
     54  1.79   thorpej };
     55  1.79   thorpej 
     56  1.79   thorpej struct cfdriver isa_cd = {
     57  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     58  1.79   thorpej 	NULL, "isa", DV_DULL, 1
     59  1.91       cgd #else
     60  1.91       cgd 	NULL, "isa", DV_DULL
     61  1.91       cgd #endif
     62  1.77       cgd };
     63  1.77       cgd 
     64  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     65  1.91       cgd void	isascan __P((struct device *, void *));
     66  1.91       cgd #else
     67  1.91       cgd int	isasearch __P((struct device *, struct cfdata *, void *));
     68  1.91       cgd #endif
     69  1.91       cgd 
     70  1.77       cgd int
     71  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     72  1.77       cgd isamatch(parent, match, aux)
     73  1.91       cgd #else
     74  1.91       cgd isamatch(parent, cf, aux)
     75  1.91       cgd #endif
     76  1.77       cgd 	struct device *parent;
     77  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     78  1.91       cgd 	void *match;
     79  1.91       cgd #else
     80  1.91       cgd 	struct cfdata *cf;
     81  1.91       cgd #endif
     82  1.91       cgd 	void *aux;
     83  1.77       cgd {
     84  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     85  1.77       cgd 	struct cfdata *cf = match;
     86  1.91       cgd #endif
     87  1.77       cgd 	struct isabus_attach_args *iba = aux;
     88  1.77       cgd 
     89  1.77       cgd 	if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
     90  1.77       cgd 		return (0);
     91  1.77       cgd 
     92  1.77       cgd 	/* XXX check other indicators */
     93  1.77       cgd 
     94  1.77       cgd         return (1);
     95  1.77       cgd }
     96  1.77       cgd 
     97  1.77       cgd void
     98  1.77       cgd isaattach(parent, self, aux)
     99  1.77       cgd 	struct device *parent, *self;
    100  1.77       cgd 	void *aux;
    101  1.77       cgd {
    102  1.77       cgd 	struct isa_softc *sc = (struct isa_softc *)self;
    103  1.77       cgd 	struct isabus_attach_args *iba = aux;
    104  1.77       cgd 
    105  1.80       cgd 	isa_attach_hook(parent, self, iba);
    106  1.88  christos 	printf("\n");
    107  1.77       cgd 
    108  1.89   thorpej 	sc->sc_iot = iba->iba_iot;
    109  1.89   thorpej 	sc->sc_memt = iba->iba_memt;
    110  1.80       cgd 	sc->sc_ic = iba->iba_ic;
    111  1.78       cgd 
    112  1.82   thorpej 	/*
    113  1.83   thorpej 	 * Map port 0x84, which causes a 1.25us delay when read.
    114  1.82   thorpej 	 * We do this now, since several drivers need it.
    115  1.82   thorpej 	 */
    116  1.89   thorpej 	if (bus_space_map(sc->sc_iot, 0x84, 1, 0, &sc->sc_delaybah))
    117  1.82   thorpej 		panic("isaattach: can't map `delay port'");	/* XXX */
    118  1.82   thorpej 
    119  1.77       cgd 	TAILQ_INIT(&sc->sc_subdevs);
    120  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    121  1.77       cgd 	config_scan(isascan, self);
    122  1.91       cgd #else
    123  1.91       cgd 	config_search(isasearch, self, NULL);
    124  1.91       cgd #endif
    125  1.77       cgd }
    126   1.1       cgd 
    127  1.46   mycroft int
    128  1.46   mycroft isaprint(aux, isa)
    129  1.46   mycroft 	void *aux;
    130  1.86       cgd 	const char *isa;
    131  1.46   mycroft {
    132  1.46   mycroft 	struct isa_attach_args *ia = aux;
    133  1.46   mycroft 
    134  1.46   mycroft 	if (ia->ia_iosize)
    135  1.88  christos 		printf(" port 0x%x", ia->ia_iobase);
    136  1.46   mycroft 	if (ia->ia_iosize > 1)
    137  1.88  christos 		printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
    138  1.46   mycroft 	if (ia->ia_msize)
    139  1.88  christos 		printf(" iomem 0x%x", ia->ia_maddr);
    140  1.46   mycroft 	if (ia->ia_msize > 1)
    141  1.88  christos 		printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
    142  1.69   mycroft 	if (ia->ia_irq != IRQUNK)
    143  1.88  christos 		printf(" irq %d", ia->ia_irq);
    144  1.69   mycroft 	if (ia->ia_drq != DRQUNK)
    145  1.88  christos 		printf(" drq %d", ia->ia_drq);
    146  1.71   mycroft 	return (UNCONF);
    147  1.46   mycroft }
    148  1.46   mycroft 
    149  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    150  1.21    andrew void
    151  1.64   mycroft isascan(parent, match)
    152  1.64   mycroft 	struct device *parent;
    153  1.64   mycroft 	void *match;
    154  1.91       cgd #else
    155  1.91       cgd int
    156  1.91       cgd isasearch(parent, cf, aux)
    157  1.91       cgd 	struct device *parent;
    158  1.91       cgd 	struct cfdata *cf;
    159  1.91       cgd 	void *aux;
    160  1.91       cgd #endif
    161  1.64   mycroft {
    162  1.78       cgd 	struct isa_softc *sc = (struct isa_softc *)parent;
    163  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    164  1.64   mycroft 	struct device *dev = match;
    165  1.64   mycroft 	struct cfdata *cf = dev->dv_cfdata;
    166  1.91       cgd #endif
    167  1.64   mycroft 	struct isa_attach_args ia;
    168  1.64   mycroft 
    169  1.91       cgd #if defined(__BROKEN_INDIRECT_CONFIG) && defined(__i386__)
    170  1.64   mycroft 	if (cf->cf_fstate == FSTATE_STAR)
    171  1.76   mycroft 		panic("clone devices not supported on ISA bus");
    172  1.90       cgd #endif
    173  1.64   mycroft 
    174  1.89   thorpej 	ia.ia_iot = sc->sc_iot;
    175  1.89   thorpej 	ia.ia_memt = sc->sc_memt;
    176  1.80       cgd 	ia.ia_ic = sc->sc_ic;
    177  1.64   mycroft 	ia.ia_iobase = cf->cf_loc[0];
    178  1.64   mycroft 	ia.ia_iosize = 0x666;
    179  1.70   mycroft 	ia.ia_maddr = cf->cf_loc[2];
    180  1.64   mycroft 	ia.ia_msize = cf->cf_loc[3];
    181  1.70   mycroft 	ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
    182  1.64   mycroft 	ia.ia_drq = cf->cf_loc[5];
    183  1.89   thorpej 	ia.ia_delaybah = sc->sc_delaybah;
    184  1.64   mycroft 
    185  1.91       cgd 	if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0)
    186  1.91       cgd 		config_attach(parent, cf, &ia, isaprint);
    187  1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    188  1.64   mycroft 	else
    189  1.64   mycroft 		free(dev, M_DEVBUF);
    190  1.91       cgd #else
    191  1.91       cgd 	return (0);
    192  1.91       cgd #endif
    193  1.72       cgd }
    194  1.72       cgd 
    195  1.72       cgd char *
    196  1.72       cgd isa_intr_typename(type)
    197  1.75   mycroft 	int type;
    198  1.72       cgd {
    199  1.72       cgd 
    200  1.72       cgd 	switch (type) {
    201  1.75   mycroft         case IST_NONE :
    202  1.72       cgd 		return ("none");
    203  1.75   mycroft         case IST_PULSE:
    204  1.72       cgd 		return ("pulsed");
    205  1.75   mycroft         case IST_EDGE:
    206  1.72       cgd 		return ("edge-triggered");
    207  1.75   mycroft         case IST_LEVEL:
    208  1.72       cgd 		return ("level-triggered");
    209  1.72       cgd 	default:
    210  1.72       cgd 		panic("isa_intr_typename: invalid type %d", type);
    211  1.72       cgd 	}
    212   1.1       cgd }
    213