Home | History | Annotate | Line # | Download | only in isa
isa.c revision 1.109
      1  1.109     lukem /*	$NetBSD: isa.c,v 1.109 2001/11/13 08:01:21 lukem Exp $	*/
      2   1.58       cgd 
      3    1.1       cgd /*-
      4  1.105   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  1.105   mycroft  * All rights reserved.
      6  1.105   mycroft  *
      7  1.105   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8  1.105   mycroft  * by Charles M. Hannum.
      9    1.1       cgd  *
     10    1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11    1.1       cgd  * modification, are permitted provided that the following conditions
     12    1.1       cgd  * are met:
     13    1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14    1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15    1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16    1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17    1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18    1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     19    1.1       cgd  *    must display the following acknowledgement:
     20  1.105   mycroft  *        This product includes software developed by the NetBSD
     21  1.105   mycroft  *        Foundation, Inc. and its contributors.
     22  1.105   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.105   mycroft  *    contributors may be used to endorse or promote products derived
     24  1.105   mycroft  *    from this software without specific prior written permission.
     25    1.1       cgd  *
     26  1.105   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.105   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.105   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.105   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.105   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.105   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.105   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.105   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.105   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.105   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.105   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37    1.1       cgd  */
     38  1.109     lukem 
     39  1.109     lukem #include <sys/cdefs.h>
     40  1.109     lukem __KERNEL_RCSID(0, "$NetBSD: isa.c,v 1.109 2001/11/13 08:01:21 lukem Exp $");
     41    1.1       cgd 
     42   1.31   mycroft #include <sys/param.h>
     43   1.31   mycroft #include <sys/systm.h>
     44   1.40   mycroft #include <sys/kernel.h>
     45   1.31   mycroft #include <sys/malloc.h>
     46   1.46   mycroft #include <sys/device.h>
     47   1.85   thorpej 
     48   1.85   thorpej #include <machine/intr.h>
     49   1.31   mycroft 
     50   1.72       cgd #include <dev/isa/isareg.h>
     51   1.72       cgd #include <dev/isa/isavar.h>
     52   1.95   thorpej #include <dev/isa/isadmareg.h>
     53   1.77       cgd 
     54  1.102       leo #include "isadma.h"
     55  1.102       leo 
     56  1.103  christos #include "isapnp.h"
     57  1.108      fvdl #if NISAPNP > 0
     58  1.103  christos #include <dev/isapnp/isapnpreg.h>
     59  1.103  christos #include <dev/isapnp/isapnpvar.h>
     60  1.103  christos #endif
     61  1.103  christos 
     62   1.91       cgd int isamatch __P((struct device *, struct cfdata *, void *));
     63   1.77       cgd void isaattach __P((struct device *, struct device *, void *));
     64   1.86       cgd int isaprint __P((void *, const char *));
     65   1.77       cgd 
     66   1.79   thorpej struct cfattach isa_ca = {
     67   1.79   thorpej 	sizeof(struct isa_softc), isamatch, isaattach
     68   1.79   thorpej };
     69   1.79   thorpej 
     70   1.91       cgd int	isasearch __P((struct device *, struct cfdata *, void *));
     71   1.91       cgd 
     72   1.77       cgd int
     73   1.91       cgd isamatch(parent, cf, aux)
     74   1.77       cgd 	struct device *parent;
     75   1.91       cgd 	struct cfdata *cf;
     76   1.91       cgd 	void *aux;
     77   1.77       cgd {
     78   1.77       cgd 	struct isabus_attach_args *iba = aux;
     79   1.77       cgd 
     80   1.77       cgd 	if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
     81   1.77       cgd 		return (0);
     82   1.77       cgd 
     83   1.77       cgd 	/* XXX check other indicators */
     84   1.77       cgd 
     85   1.77       cgd         return (1);
     86   1.77       cgd }
     87   1.77       cgd 
     88   1.77       cgd void
     89   1.77       cgd isaattach(parent, self, aux)
     90   1.77       cgd 	struct device *parent, *self;
     91   1.77       cgd 	void *aux;
     92   1.77       cgd {
     93   1.77       cgd 	struct isa_softc *sc = (struct isa_softc *)self;
     94   1.77       cgd 	struct isabus_attach_args *iba = aux;
     95   1.98   thorpej 
     96   1.80       cgd 	isa_attach_hook(parent, self, iba);
     97   1.88  christos 	printf("\n");
     98   1.77       cgd 
     99   1.89   thorpej 	sc->sc_iot = iba->iba_iot;
    100   1.89   thorpej 	sc->sc_memt = iba->iba_memt;
    101   1.95   thorpej 	sc->sc_dmat = iba->iba_dmat;
    102   1.80       cgd 	sc->sc_ic = iba->iba_ic;
    103  1.103  christos 
    104  1.103  christos #if NISAPNP > 0
    105  1.103  christos 	/*
    106  1.103  christos 	 * Reset isapnp cards that the bios configured for us
    107  1.103  christos 	 */
    108  1.103  christos 	isapnp_isa_attach_hook(sc);
    109  1.103  christos #endif
    110   1.78       cgd 
    111  1.102       leo #if NISADMA > 0
    112   1.82   thorpej 	/*
    113  1.101   thorpej 	 * Initialize our DMA state.
    114   1.95   thorpej 	 */
    115  1.101   thorpej 	isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
    116  1.102       leo #endif
    117  1.100  drochner 
    118   1.91       cgd 	config_search(isasearch, self, NULL);
    119   1.77       cgd }
    120    1.1       cgd 
    121   1.46   mycroft int
    122   1.46   mycroft isaprint(aux, isa)
    123   1.46   mycroft 	void *aux;
    124   1.86       cgd 	const char *isa;
    125   1.46   mycroft {
    126   1.46   mycroft 	struct isa_attach_args *ia = aux;
    127   1.46   mycroft 
    128   1.46   mycroft 	if (ia->ia_iosize)
    129   1.88  christos 		printf(" port 0x%x", ia->ia_iobase);
    130   1.46   mycroft 	if (ia->ia_iosize > 1)
    131   1.88  christos 		printf("-0x%x", ia->ia_iobase + ia->ia_iosize - 1);
    132   1.46   mycroft 	if (ia->ia_msize)
    133   1.88  christos 		printf(" iomem 0x%x", ia->ia_maddr);
    134   1.46   mycroft 	if (ia->ia_msize > 1)
    135   1.88  christos 		printf("-0x%x", ia->ia_maddr + ia->ia_msize - 1);
    136   1.69   mycroft 	if (ia->ia_irq != IRQUNK)
    137   1.88  christos 		printf(" irq %d", ia->ia_irq);
    138   1.69   mycroft 	if (ia->ia_drq != DRQUNK)
    139   1.88  christos 		printf(" drq %d", ia->ia_drq);
    140   1.97  augustss 	if (ia->ia_drq2 != DRQUNK)
    141   1.97  augustss 		printf(" drq2 %d", ia->ia_drq2);
    142   1.71   mycroft 	return (UNCONF);
    143   1.46   mycroft }
    144   1.46   mycroft 
    145   1.94       cgd int
    146   1.94       cgd isasearch(parent, cf, aux)
    147   1.94       cgd 	struct device *parent;
    148   1.94       cgd 	struct cfdata *cf;
    149   1.94       cgd 	void *aux;
    150   1.94       cgd {
    151   1.94       cgd 	struct isa_softc *sc = (struct isa_softc *)parent;
    152   1.94       cgd 	struct isa_attach_args ia;
    153   1.94       cgd 	int tryagain;
    154   1.94       cgd 
    155   1.94       cgd 	do {
    156   1.94       cgd 		ia.ia_iot = sc->sc_iot;
    157   1.94       cgd 		ia.ia_memt = sc->sc_memt;
    158   1.95   thorpej 		ia.ia_dmat = sc->sc_dmat;
    159   1.94       cgd 		ia.ia_ic = sc->sc_ic;
    160   1.96       jtk 		ia.ia_iobase = cf->cf_iobase;
    161   1.96       jtk 		ia.ia_iosize = 0x666; /* cf->cf_iosize; */
    162   1.96       jtk 		ia.ia_maddr = cf->cf_maddr;
    163   1.96       jtk 		ia.ia_msize = cf->cf_msize;
    164   1.96       jtk 		ia.ia_irq = cf->cf_irq == 2 ? 9 : cf->cf_irq;
    165   1.96       jtk 		ia.ia_drq = cf->cf_drq;
    166   1.97  augustss 		ia.ia_drq2 = cf->cf_drq2;
    167   1.94       cgd 
    168   1.94       cgd 		tryagain = 0;
    169   1.94       cgd 		if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
    170   1.94       cgd 			config_attach(parent, cf, &ia, isaprint);
    171   1.94       cgd 			tryagain = (cf->cf_fstate == FSTATE_STAR);
    172   1.94       cgd 		}
    173   1.94       cgd 	} while (tryagain);
    174   1.94       cgd 
    175   1.91       cgd 	return (0);
    176   1.72       cgd }
    177   1.72       cgd 
    178   1.72       cgd char *
    179   1.72       cgd isa_intr_typename(type)
    180   1.75   mycroft 	int type;
    181   1.72       cgd {
    182   1.72       cgd 
    183   1.72       cgd 	switch (type) {
    184   1.75   mycroft         case IST_NONE :
    185   1.72       cgd 		return ("none");
    186   1.75   mycroft         case IST_PULSE:
    187   1.72       cgd 		return ("pulsed");
    188   1.75   mycroft         case IST_EDGE:
    189   1.72       cgd 		return ("edge-triggered");
    190   1.75   mycroft         case IST_LEVEL:
    191   1.72       cgd 		return ("level-triggered");
    192   1.72       cgd 	default:
    193   1.72       cgd 		panic("isa_intr_typename: invalid type %d", type);
    194   1.72       cgd 	}
    195    1.1       cgd }
    196