Home | History | Annotate | Line # | Download | only in isa
bha_isa.c revision 1.7
      1 /*	$NetBSD: bha_isa.c,v 1.7 1997/06/06 23:43:48 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 <scsi/scsi_all.h>
     41 #include <scsi/scsiconf.h>
     42 
     43 #include <dev/isa/isavar.h>
     44 #include <dev/isa/isadmavar.h>
     45 
     46 #include <dev/ic/bhareg.h>
     47 #include <dev/ic/bhavar.h>
     48 
     49 #define	BHA_ISA_IOSIZE	4
     50 
     51 #ifdef __BROKEN_INDIRECT_CONFIG
     52 int	bha_isa_probe __P((struct device *, void *, void *));
     53 #else
     54 int	bha_isa_probe __P((struct device *, struct cfdata *, void *));
     55 #endif
     56 void	bha_isa_attach __P((struct device *, struct device *, void *));
     57 
     58 struct cfattach bha_isa_ca = {
     59 	sizeof(struct bha_softc), bha_isa_probe, bha_isa_attach
     60 };
     61 
     62 /*
     63  * Check the slots looking for a board we recognise
     64  * If we find one, note it's address (slot) and call
     65  * the actual probe routine to check it out.
     66  */
     67 int
     68 bha_isa_probe(parent, match, aux)
     69 	struct device *parent;
     70 #ifdef __BROKEN_INDIRECT_CONFIG
     71 	void *match;
     72 #else
     73 	struct cfdata *match;
     74 #endif
     75 	void *aux;
     76 {
     77 	struct isa_attach_args *ia = aux;
     78 	bus_space_tag_t iot = ia->ia_iot;
     79 	bus_space_handle_t ioh;
     80 	struct bha_probe_data bpd;
     81 	int rv;
     82 
     83 	if (bus_space_map(iot, ia->ia_iobase, BHA_ISA_IOSIZE, 0, &ioh))
     84 		return (0);
     85 
     86 	rv = bha_find(iot, ioh, &bpd);
     87 
     88 	bus_space_unmap(iot, ioh, BHA_ISA_IOSIZE);
     89 
     90 	if (rv) {
     91 		if (ia->ia_irq != -1 && ia->ia_irq != bpd.sc_irq)
     92 			return (0);
     93 		if (ia->ia_drq != -1 && ia->ia_drq != bpd.sc_drq)
     94 			return (0);
     95 		ia->ia_irq = bpd.sc_irq;
     96 		ia->ia_drq = bpd.sc_drq;
     97 		ia->ia_msize = 0;
     98 		ia->ia_iosize = BHA_ISA_IOSIZE;
     99 	}
    100 	return (rv);
    101 }
    102 
    103 /*
    104  * Attach all the sub-devices we can find
    105  */
    106 void
    107 bha_isa_attach(parent, self, aux)
    108 	struct device *parent, *self;
    109 	void *aux;
    110 {
    111 	struct isa_attach_args *ia = aux;
    112 	struct bha_softc *sc = (void *)self;
    113 	bus_space_tag_t iot = ia->ia_iot;
    114 	bus_space_handle_t ioh;
    115 	struct bha_probe_data bpd;
    116 	isa_chipset_tag_t ic = ia->ia_ic;
    117 
    118 	printf("\n");
    119 
    120 	if (bus_space_map(iot, ia->ia_iobase, BHA_ISA_IOSIZE, 0, &ioh))
    121 		panic("bha_isa_attach: bus_space_map failed");
    122 
    123 	sc->sc_iot = iot;
    124 	sc->sc_ioh = ioh;
    125 	sc->sc_dmat = ia->ia_dmat;
    126 	if (!bha_find(iot, ioh, &bpd))
    127 		panic("bha_isa_attach: bha_find failed");
    128 
    129 	sc->sc_dmaflags = 0;
    130 	if (bpd.sc_drq != -1)
    131 		isa_dmacascade(parent, bpd.sc_drq);
    132 	else {
    133 		/*
    134 		 * We have a VLB controller.  If we're at least both
    135 		 * hardware revision E and firmware revision 3.37,
    136 		 * we can do 32-bit DMA (earlier revisions are buggy
    137 		 * in this regard).
    138 		 */
    139 		bha_inquire_setup_information(sc);
    140 		if (strcmp(sc->sc_firmware, "3.37") < 0)
    141 		    printf("%s: buggy VLB controller, disabling 32-bit DMA\n",
    142 		        sc->sc_dev.dv_xname);
    143 		else
    144 			sc->sc_dmaflags = ISABUS_DMA_32BIT;
    145 	}
    146 
    147 	sc->sc_ih = isa_intr_establish(ic, bpd.sc_irq, IST_EDGE, IPL_BIO,
    148 	    bha_intr, sc);
    149 	if (sc->sc_ih == NULL) {
    150 		printf("%s: couldn't establish interrupt\n",
    151 		    sc->sc_dev.dv_xname);
    152 		return;
    153 	}
    154 
    155 	bha_attach(sc, &bpd);
    156 }
    157