Home | History | Annotate | Line # | Download | only in isa
aha_isa.c revision 1.17
      1 /*	$NetBSD: aha_isa.c,v 1.17 2002/10/02 03:10:45 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: aha_isa.c,v 1.17 2002/10/02 03:10:45 thorpej Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 
     46 #include <machine/bus.h>
     47 #include <machine/intr.h>
     48 
     49 #include <dev/scsipi/scsi_all.h>
     50 #include <dev/scsipi/scsipi_all.h>
     51 #include <dev/scsipi/scsiconf.h>
     52 
     53 #include <dev/isa/isavar.h>
     54 #include <dev/isa/isadmavar.h>
     55 
     56 #include <dev/ic/ahareg.h>
     57 #include <dev/ic/ahavar.h>
     58 
     59 #define	AHA_ISA_IOSIZE	4
     60 
     61 int	aha_isa_probe __P((struct device *, struct cfdata *, void *));
     62 void	aha_isa_attach __P((struct device *, struct device *, void *));
     63 
     64 CFATTACH_DECL(aha_isa, sizeof(struct aha_softc),
     65     aha_isa_probe, aha_isa_attach, NULL, NULL);
     66 
     67 /*
     68  * Check the slots looking for a board we recognise
     69  * If we find one, note it's address (slot) and call
     70  * the actual probe routine to check it out.
     71  */
     72 int
     73 aha_isa_probe(parent, match, aux)
     74 	struct device *parent;
     75 	struct cfdata *match;
     76 	void *aux;
     77 {
     78 	struct isa_attach_args *ia = aux;
     79 	bus_space_tag_t iot = ia->ia_iot;
     80 	bus_space_handle_t ioh;
     81 	struct aha_probe_data apd;
     82 	int rv;
     83 
     84 	if (ia->ia_nio < 1)
     85 		return (0);
     86 	if (ia->ia_nirq < 1)
     87 		return (0);
     88 	if (ia->ia_ndrq < 1)
     89 		return (0);
     90 
     91 	if (ISA_DIRECT_CONFIG(ia))
     92 		return (0);
     93 
     94 	/* Disallow wildcarded i/o address. */
     95 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
     96 		return (0);
     97 
     98 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh))
     99 		return (0);
    100 
    101 	rv = aha_find(iot, ioh, &apd);
    102 
    103 	bus_space_unmap(iot, ioh, AHA_ISA_IOSIZE);
    104 
    105 	if (rv) {
    106 		if (ia->ia_irq[0].ir_irq != ISACF_IRQ_DEFAULT &&
    107 		    ia->ia_irq[0].ir_irq != apd.sc_irq)
    108 			return (0);
    109 		if (ia->ia_drq[0].ir_drq != ISACF_DRQ_DEFAULT &&
    110 		    ia->ia_drq[0].ir_drq != apd.sc_drq)
    111 			return (0);
    112 
    113 		ia->ia_nio = 1;
    114 		ia->ia_io[0].ir_size = AHA_ISA_IOSIZE;
    115 
    116 		ia->ia_nirq = 1;
    117 		ia->ia_irq[0].ir_irq = apd.sc_irq;
    118 
    119 		ia->ia_ndrq = 1;
    120 		ia->ia_drq[0].ir_drq = apd.sc_drq;
    121 
    122 		ia->ia_niomem = 0;
    123 	}
    124 	return (rv);
    125 }
    126 
    127 /*
    128  * Attach all the sub-devices we can find
    129  */
    130 void
    131 aha_isa_attach(parent, self, aux)
    132 	struct device *parent, *self;
    133 	void *aux;
    134 {
    135 	struct isa_attach_args *ia = aux;
    136 	struct aha_softc *sc = (void *)self;
    137 	bus_space_tag_t iot = ia->ia_iot;
    138 	bus_space_handle_t ioh;
    139 	struct aha_probe_data apd;
    140 	isa_chipset_tag_t ic = ia->ia_ic;
    141 	int error;
    142 
    143 	printf("\n");
    144 
    145 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh)) {
    146 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    147 		return;
    148 	}
    149 
    150 	sc->sc_iot = iot;
    151 	sc->sc_ioh = ioh;
    152 	sc->sc_dmat = ia->ia_dmat;
    153 	if (!aha_find(iot, ioh, &apd)) {
    154 		printf("%s: aha_find failed\n", sc->sc_dev.dv_xname);
    155 		return;
    156 	}
    157 
    158 	if (apd.sc_drq != -1) {
    159 		if ((error = isa_dmacascade(ic, apd.sc_drq)) != 0) {
    160 			printf("%s: unable to cascade DRQ, error = %d\n",
    161 			    sc->sc_dev.dv_xname, error);
    162 			return;
    163 		}
    164 	}
    165 
    166 	sc->sc_ih = isa_intr_establish(ic, apd.sc_irq, IST_EDGE, IPL_BIO,
    167 	    aha_intr, sc);
    168 	if (sc->sc_ih == NULL) {
    169 		printf("%s: couldn't establish interrupt\n",
    170 		    sc->sc_dev.dv_xname);
    171 		return;
    172 	}
    173 
    174 	aha_attach(sc, &apd);
    175 }
    176