Home | History | Annotate | Line # | Download | only in isa
aha_isa.c revision 1.10
      1 /*	$NetBSD: aha_isa.c,v 1.10 1998/06/25 19:18:05 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994, 1996, 1997 Charles M. 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 M. 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/types.h>
     33 #include <sys/param.h>
     34 #include <sys/systm.h>
     35 #include <sys/device.h>
     36 
     37 #include <machine/bus.h>
     38 #include <machine/intr.h>
     39 
     40 #include <dev/scsipi/scsi_all.h>
     41 #include <dev/scsipi/scsipi_all.h>
     42 #include <dev/scsipi/scsiconf.h>
     43 
     44 #include <dev/isa/isavar.h>
     45 #include <dev/isa/isadmavar.h>
     46 
     47 #include <dev/ic/ahareg.h>
     48 #include <dev/ic/ahavar.h>
     49 
     50 #define	AHA_ISA_IOSIZE	4
     51 
     52 int	aha_isa_probe __P((struct device *, struct cfdata *, void *));
     53 void	aha_isa_attach __P((struct device *, struct device *, void *));
     54 
     55 struct cfattach aha_isa_ca = {
     56 	sizeof(struct aha_softc), aha_isa_probe, aha_isa_attach
     57 };
     58 
     59 /*
     60  * Check the slots looking for a board we recognise
     61  * If we find one, note it's address (slot) and call
     62  * the actual probe routine to check it out.
     63  */
     64 int
     65 aha_isa_probe(parent, match, aux)
     66 	struct device *parent;
     67 	struct cfdata *match;
     68 	void *aux;
     69 {
     70 	struct isa_attach_args *ia = aux;
     71 	bus_space_tag_t iot = ia->ia_iot;
     72 	bus_space_handle_t ioh;
     73 	struct aha_probe_data apd;
     74 	int rv;
     75 
     76 	/* Disallow wildcarded i/o address. */
     77 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
     78 		return (0);
     79 
     80 	if (bus_space_map(iot, ia->ia_iobase, AHA_ISA_IOSIZE, 0, &ioh))
     81 		return (0);
     82 
     83 	rv = aha_find(iot, ioh, &apd);
     84 
     85 	bus_space_unmap(iot, ioh, AHA_ISA_IOSIZE);
     86 
     87 	if (rv) {
     88 		if (ia->ia_irq != -1 && ia->ia_irq != apd.sc_irq)
     89 			return (0);
     90 		if (ia->ia_drq != -1 && ia->ia_drq != apd.sc_drq)
     91 			return (0);
     92 		ia->ia_irq = apd.sc_irq;
     93 		ia->ia_drq = apd.sc_drq;
     94 		ia->ia_msize = 0;
     95 		ia->ia_iosize = AHA_ISA_IOSIZE;
     96 	}
     97 	return (rv);
     98 }
     99 
    100 /*
    101  * Attach all the sub-devices we can find
    102  */
    103 void
    104 aha_isa_attach(parent, self, aux)
    105 	struct device *parent, *self;
    106 	void *aux;
    107 {
    108 	struct isa_attach_args *ia = aux;
    109 	struct aha_softc *sc = (void *)self;
    110 	bus_space_tag_t iot = ia->ia_iot;
    111 	bus_space_handle_t ioh;
    112 	struct aha_probe_data apd;
    113 	isa_chipset_tag_t ic = ia->ia_ic;
    114 	int error;
    115 
    116 	printf("\n");
    117 
    118 	if (bus_space_map(iot, ia->ia_iobase, AHA_ISA_IOSIZE, 0, &ioh)) {
    119 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    120 		return;
    121 	}
    122 
    123 	sc->sc_iot = iot;
    124 	sc->sc_ioh = ioh;
    125 	sc->sc_dmat = ia->ia_dmat;
    126 	if (!aha_find(iot, ioh, &apd)) {
    127 		printf("%s: aha_find failed\n", sc->sc_dev.dv_xname);
    128 		return;
    129 	}
    130 
    131 	if (apd.sc_drq != -1) {
    132 		if ((error = isa_dmacascade(ic, apd.sc_drq)) != 0) {
    133 			printf("%s: unable to cascade DRQ, error = %d\n",
    134 			    sc->sc_dev.dv_xname, error);
    135 			return;
    136 		}
    137 	}
    138 
    139 	sc->sc_ih = isa_intr_establish(ic, apd.sc_irq, IST_EDGE, IPL_BIO,
    140 	    aha_intr, sc);
    141 	if (sc->sc_ih == NULL) {
    142 		printf("%s: couldn't establish interrupt\n",
    143 		    sc->sc_dev.dv_xname);
    144 		return;
    145 	}
    146 
    147 	aha_attach(sc, &apd);
    148 }
    149