Home | History | Annotate | Line # | Download | only in isa
isa.c revision 1.94.6.1
      1  1.94.6.1   thorpej /*	$NetBSD: isa.c,v 1.94.6.1 1997/05/13 03:12:42 thorpej 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.94.6.1   thorpej #include <dev/isa/isadmareg.h>
     44      1.77       cgd 
     45      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     46      1.77       cgd int isamatch __P((struct device *, void *, void *));
     47      1.91       cgd #else
     48      1.91       cgd int isamatch __P((struct device *, struct cfdata *, void *));
     49      1.91       cgd #endif
     50      1.77       cgd void isaattach __P((struct device *, struct device *, void *));
     51      1.86       cgd int isaprint __P((void *, const char *));
     52      1.77       cgd 
     53      1.79   thorpej struct cfattach isa_ca = {
     54      1.79   thorpej 	sizeof(struct isa_softc), isamatch, isaattach
     55      1.79   thorpej };
     56      1.79   thorpej 
     57      1.79   thorpej struct cfdriver isa_cd = {
     58      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     59      1.79   thorpej 	NULL, "isa", DV_DULL, 1
     60      1.91       cgd #else
     61      1.91       cgd 	NULL, "isa", DV_DULL
     62      1.91       cgd #endif
     63      1.77       cgd };
     64      1.77       cgd 
     65      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     66      1.91       cgd void	isascan __P((struct device *, void *));
     67      1.91       cgd #else
     68      1.91       cgd int	isasearch __P((struct device *, struct cfdata *, void *));
     69      1.91       cgd #endif
     70      1.91       cgd 
     71      1.77       cgd int
     72      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     73      1.77       cgd isamatch(parent, match, aux)
     74      1.91       cgd #else
     75      1.91       cgd isamatch(parent, cf, aux)
     76      1.91       cgd #endif
     77      1.77       cgd 	struct device *parent;
     78      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     79      1.91       cgd 	void *match;
     80      1.91       cgd #else
     81      1.91       cgd 	struct cfdata *cf;
     82      1.91       cgd #endif
     83      1.91       cgd 	void *aux;
     84      1.77       cgd {
     85      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
     86      1.77       cgd 	struct cfdata *cf = match;
     87      1.91       cgd #endif
     88      1.77       cgd 	struct isabus_attach_args *iba = aux;
     89      1.77       cgd 
     90      1.77       cgd 	if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
     91      1.77       cgd 		return (0);
     92      1.77       cgd 
     93      1.77       cgd 	/* XXX check other indicators */
     94      1.77       cgd 
     95      1.77       cgd         return (1);
     96      1.77       cgd }
     97      1.77       cgd 
     98      1.77       cgd void
     99      1.77       cgd isaattach(parent, self, aux)
    100      1.77       cgd 	struct device *parent, *self;
    101      1.77       cgd 	void *aux;
    102      1.77       cgd {
    103      1.77       cgd 	struct isa_softc *sc = (struct isa_softc *)self;
    104      1.77       cgd 	struct isabus_attach_args *iba = aux;
    105      1.77       cgd 
    106      1.80       cgd 	isa_attach_hook(parent, self, iba);
    107      1.88  christos 	printf("\n");
    108      1.77       cgd 
    109      1.89   thorpej 	sc->sc_iot = iba->iba_iot;
    110      1.89   thorpej 	sc->sc_memt = iba->iba_memt;
    111  1.94.6.1   thorpej 	sc->sc_dmat = iba->iba_dmat;
    112      1.80       cgd 	sc->sc_ic = iba->iba_ic;
    113      1.78       cgd 
    114      1.82   thorpej 	/*
    115  1.94.6.1   thorpej 	 * Map the registers used by the ISA DMA controller.
    116  1.94.6.1   thorpej 	 */
    117  1.94.6.1   thorpej 	if (bus_space_map(sc->sc_iot, IO_DMA1, DMA1_IOSIZE, 0, &sc->sc_dma1h))
    118  1.94.6.1   thorpej 		panic("isaattach: can't map DMA controller #1");
    119  1.94.6.1   thorpej 	if (bus_space_map(sc->sc_iot, IO_DMA2, DMA2_IOSIZE, 0, &sc->sc_dma2h))
    120  1.94.6.1   thorpej 		panic("isaattach: can't map DMA controller #2");
    121  1.94.6.1   thorpej 	if (bus_space_map(sc->sc_iot, IO_DMAPG, 0xf, 0, &sc->sc_dmapgh))
    122  1.94.6.1   thorpej 		panic("isaattach: can't map DMA page registers");
    123  1.94.6.1   thorpej 
    124  1.94.6.1   thorpej 	/*
    125      1.83   thorpej 	 * Map port 0x84, which causes a 1.25us delay when read.
    126      1.82   thorpej 	 * We do this now, since several drivers need it.
    127      1.82   thorpej 	 */
    128  1.94.6.1   thorpej 	if (bus_space_subregion(sc->sc_iot, sc->sc_dmapgh, 0x04, 1,
    129  1.94.6.1   thorpej 	    &sc->sc_delaybah))
    130      1.82   thorpej 		panic("isaattach: can't map `delay port'");	/* XXX */
    131      1.82   thorpej 
    132      1.77       cgd 	TAILQ_INIT(&sc->sc_subdevs);
    133      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    134      1.77       cgd 	config_scan(isascan, self);
    135      1.91       cgd #else
    136      1.91       cgd 	config_search(isasearch, self, NULL);
    137      1.91       cgd #endif
    138      1.77       cgd }
    139       1.1       cgd 
    140      1.46   mycroft int
    141      1.46   mycroft isaprint(aux, isa)
    142      1.46   mycroft 	void *aux;
    143      1.86       cgd 	const char *isa;
    144      1.46   mycroft {
    145      1.46   mycroft 	struct isa_attach_args *ia = aux;
    146      1.46   mycroft 
    147      1.46   mycroft 	if (ia->ia_iosize)
    148      1.88  christos 		printf(" port 0x%x", ia->ia_iobase);
    149      1.46   mycroft 	if (ia->ia_iosize > 1)
    150      1.88  christos 		printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
    151      1.46   mycroft 	if (ia->ia_msize)
    152      1.88  christos 		printf(" iomem 0x%x", ia->ia_maddr);
    153      1.46   mycroft 	if (ia->ia_msize > 1)
    154      1.88  christos 		printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
    155      1.69   mycroft 	if (ia->ia_irq != IRQUNK)
    156      1.88  christos 		printf(" irq %d", ia->ia_irq);
    157      1.69   mycroft 	if (ia->ia_drq != DRQUNK)
    158      1.88  christos 		printf(" drq %d", ia->ia_drq);
    159      1.71   mycroft 	return (UNCONF);
    160      1.46   mycroft }
    161      1.46   mycroft 
    162      1.91       cgd #ifdef __BROKEN_INDIRECT_CONFIG
    163      1.21    andrew void
    164      1.64   mycroft isascan(parent, match)
    165      1.64   mycroft 	struct device *parent;
    166      1.64   mycroft 	void *match;
    167      1.64   mycroft {
    168      1.78       cgd 	struct isa_softc *sc = (struct isa_softc *)parent;
    169      1.64   mycroft 	struct device *dev = match;
    170      1.64   mycroft 	struct cfdata *cf = dev->dv_cfdata;
    171      1.64   mycroft 	struct isa_attach_args ia;
    172      1.64   mycroft 
    173      1.94       cgd #if defined(__i386__)
    174      1.64   mycroft 	if (cf->cf_fstate == FSTATE_STAR)
    175      1.76   mycroft 		panic("clone devices not supported on ISA bus");
    176      1.90       cgd #endif
    177      1.64   mycroft 
    178      1.89   thorpej 	ia.ia_iot = sc->sc_iot;
    179      1.89   thorpej 	ia.ia_memt = sc->sc_memt;
    180  1.94.6.1   thorpej 	ia.ia_dmat = sc->sc_dmat;
    181      1.80       cgd 	ia.ia_ic = sc->sc_ic;
    182      1.64   mycroft 	ia.ia_iobase = cf->cf_loc[0];
    183      1.64   mycroft 	ia.ia_iosize = 0x666;
    184      1.70   mycroft 	ia.ia_maddr = cf->cf_loc[2];
    185      1.64   mycroft 	ia.ia_msize = cf->cf_loc[3];
    186      1.70   mycroft 	ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
    187      1.64   mycroft 	ia.ia_drq = cf->cf_loc[5];
    188      1.89   thorpej 	ia.ia_delaybah = sc->sc_delaybah;
    189      1.64   mycroft 
    190      1.92       cgd 	if ((*cf->cf_attach->ca_match)(parent, match, &ia) > 0)
    191      1.92       cgd 		config_attach(parent, match, &ia, isaprint);
    192      1.64   mycroft 	else
    193      1.64   mycroft 		free(dev, M_DEVBUF);
    194      1.94       cgd }
    195      1.94       cgd #else /* !__BROKEN_INDIRECT_CONFIG */
    196      1.94       cgd int
    197      1.94       cgd isasearch(parent, cf, aux)
    198      1.94       cgd 	struct device *parent;
    199      1.94       cgd 	struct cfdata *cf;
    200      1.94       cgd 	void *aux;
    201      1.94       cgd {
    202      1.94       cgd 	struct isa_softc *sc = (struct isa_softc *)parent;
    203      1.94       cgd 	struct isa_attach_args ia;
    204      1.94       cgd 	int tryagain;
    205      1.94       cgd 
    206      1.94       cgd 	do {
    207      1.94       cgd 		ia.ia_iot = sc->sc_iot;
    208      1.94       cgd 		ia.ia_memt = sc->sc_memt;
    209  1.94.6.1   thorpej 		ia.ia_dmat = sc->sc_dmat;
    210      1.94       cgd 		ia.ia_ic = sc->sc_ic;
    211      1.94       cgd 		ia.ia_iobase = cf->cf_loc[0];
    212      1.94       cgd 		ia.ia_iosize = 0x666;
    213      1.94       cgd 		ia.ia_maddr = cf->cf_loc[2];
    214      1.94       cgd 		ia.ia_msize = cf->cf_loc[3];
    215      1.94       cgd 		ia.ia_irq = cf->cf_loc[4] == 2 ? 9 : cf->cf_loc[4];
    216      1.94       cgd 		ia.ia_drq = cf->cf_loc[5];
    217      1.94       cgd 		ia.ia_delaybah = sc->sc_delaybah;
    218      1.94       cgd 
    219      1.94       cgd 		tryagain = 0;
    220      1.94       cgd 		if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
    221      1.94       cgd 			config_attach(parent, cf, &ia, isaprint);
    222      1.94       cgd 			tryagain = (cf->cf_fstate == FSTATE_STAR);
    223      1.94       cgd 		}
    224      1.94       cgd 	} while (tryagain);
    225      1.94       cgd 
    226      1.91       cgd 	return (0);
    227      1.72       cgd }
    228      1.94       cgd #endif /* __BROKEN_INDIRECT_CONFIG */
    229      1.72       cgd 
    230      1.72       cgd char *
    231      1.72       cgd isa_intr_typename(type)
    232      1.75   mycroft 	int type;
    233      1.72       cgd {
    234      1.72       cgd 
    235      1.72       cgd 	switch (type) {
    236      1.75   mycroft         case IST_NONE :
    237      1.72       cgd 		return ("none");
    238      1.75   mycroft         case IST_PULSE:
    239      1.72       cgd 		return ("pulsed");
    240      1.75   mycroft         case IST_EDGE:
    241      1.72       cgd 		return ("edge-triggered");
    242      1.75   mycroft         case IST_LEVEL:
    243      1.72       cgd 		return ("level-triggered");
    244      1.72       cgd 	default:
    245      1.72       cgd 		panic("isa_intr_typename: invalid type %d", type);
    246      1.72       cgd 	}
    247       1.1       cgd }
    248