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