Home | History | Annotate | Line # | Download | only in isa
aic_isa.c revision 1.10
      1  1.10   thorpej /*	$NetBSD: aic_isa.c,v 1.10 2002/01/07 21:47:03 thorpej Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*
      4   1.1  christos  * Copyright (c) 1994, 1995, 1996 Charles M. Hannum.  All rights reserved.
      5   1.1  christos  *
      6   1.1  christos  * Redistribution and use in source and binary forms, with or without
      7   1.1  christos  * modification, are permitted provided that the following conditions
      8   1.1  christos  * are met:
      9   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13   1.1  christos  *    documentation and/or other materials provided with the distribution.
     14   1.1  christos  * 3. All advertising materials mentioning features or use of this software
     15   1.1  christos  *    must display the following acknowledgement:
     16   1.1  christos  *	This product includes software developed by Charles M. Hannum.
     17   1.1  christos  * 4. The name of the author may not be used to endorse or promote products
     18   1.1  christos  *    derived from this software without specific prior written permission.
     19   1.1  christos  *
     20   1.1  christos  * Copyright (c) 1994 Jarle Greipsland
     21   1.1  christos  * All rights reserved.
     22   1.1  christos  *
     23   1.1  christos  * Redistribution and use in source and binary forms, with or without
     24   1.1  christos  * modification, are permitted provided that the following conditions
     25   1.1  christos  * are met:
     26   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     27   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     28   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     29   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     30   1.1  christos  *    documentation and/or other materials provided with the distribution.
     31   1.1  christos  * 3. The name of the author may not be used to endorse or promote products
     32   1.1  christos  *    derived from this software without specific prior written permission.
     33   1.1  christos  *
     34   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     35   1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     36   1.1  christos  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     37   1.1  christos  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     38   1.1  christos  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     39   1.1  christos  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     40   1.1  christos  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     41   1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     42   1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     43   1.1  christos  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     44   1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     45   1.1  christos  */
     46   1.1  christos 
     47   1.1  christos /*
     48   1.1  christos  * Acknowledgements: Many of the algorithms used in this driver are
     49   1.1  christos  * inspired by the work of Julian Elischer (julian (at) tfs.com) and
     50   1.1  christos  * Charles Hannum (mycroft (at) duality.gnu.ai.mit.edu).  Thanks a million!
     51   1.1  christos  */
     52   1.8     lukem 
     53   1.8     lukem #include <sys/cdefs.h>
     54  1.10   thorpej __KERNEL_RCSID(0, "$NetBSD: aic_isa.c,v 1.10 2002/01/07 21:47:03 thorpej Exp $");
     55   1.1  christos 
     56   1.1  christos #include <sys/param.h>
     57   1.1  christos #include <sys/systm.h>
     58   1.1  christos #include <sys/kernel.h>
     59   1.1  christos #include <sys/errno.h>
     60   1.1  christos #include <sys/ioctl.h>
     61   1.1  christos #include <sys/device.h>
     62   1.1  christos #include <sys/buf.h>
     63   1.1  christos #include <sys/proc.h>
     64   1.1  christos #include <sys/user.h>
     65   1.1  christos #include <sys/queue.h>
     66   1.1  christos 
     67   1.6     enami #include <machine/bus.h>
     68   1.1  christos #include <machine/intr.h>
     69   1.1  christos 
     70   1.1  christos #include <dev/scsipi/scsi_all.h>
     71   1.1  christos #include <dev/scsipi/scsipi_all.h>
     72   1.1  christos #include <dev/scsipi/scsiconf.h>
     73   1.1  christos 
     74   1.1  christos #include <dev/isa/isavar.h>
     75   1.6     enami 
     76   1.1  christos #include <dev/ic/aic6360reg.h>
     77   1.1  christos #include <dev/ic/aic6360var.h>
     78   1.1  christos 
     79   1.5  drochner int	aic_isa_probe __P((struct device *, struct cfdata *, void *));
     80   1.1  christos 
     81   1.2     enami struct aic_isa_softc {
     82   1.2     enami 	struct	aic_softc sc_aic;	/* real "aic" softc */
     83   1.2     enami 
     84   1.2     enami 	/* ISA-specific goo. */
     85   1.2     enami 	void	*sc_ih;			/* interrupt handler */
     86   1.2     enami };
     87   1.2     enami 
     88   1.1  christos struct cfattach aic_isa_ca = {
     89   1.2     enami 	sizeof(struct aic_isa_softc), aic_isa_probe, aic_isa_attach
     90   1.1  christos };
     91   1.1  christos 
     92   1.1  christos 
     93   1.1  christos /*
     95   1.1  christos  * INITIALIZATION ROUTINES (probe, attach ++)
     96   1.1  christos  */
     97   1.1  christos 
     98   1.1  christos /*
     99   1.1  christos  * aic_isa_probe: probe for AIC6360 SCSI-controller
    100   1.1  christos  * returns non-zero value if a controller is found.
    101   1.1  christos  */
    102   1.1  christos int
    103   1.1  christos aic_isa_probe(parent, match, aux)
    104   1.5  drochner 	struct device *parent;
    105   1.5  drochner 	struct cfdata *match;
    106   1.1  christos 	void *aux;
    107   1.1  christos {
    108   1.1  christos 	struct isa_attach_args *ia = aux;
    109   1.1  christos 	bus_space_tag_t iot = ia->ia_iot;
    110   1.1  christos 	bus_space_handle_t ioh;
    111   1.3   thorpej 	int rv;
    112  1.10   thorpej 
    113  1.10   thorpej 	if (ia->ia_nio < 1)
    114  1.10   thorpej 		return (0);
    115  1.10   thorpej 	if (ia->ia_nirq < 1)
    116  1.10   thorpej 		return (0);
    117  1.10   thorpej 
    118  1.10   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    119  1.10   thorpej 		return (0);
    120   1.3   thorpej 
    121  1.10   thorpej 	/* Disallow wildcarded i/o address. */
    122   1.3   thorpej 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
    123   1.1  christos 		return (0);
    124  1.10   thorpej 
    125  1.10   thorpej 	/* Disallow wildcarded IRQ. */
    126  1.10   thorpej 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
    127  1.10   thorpej 		return (0);
    128  1.10   thorpej 
    129   1.1  christos 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AIC_ISA_IOSIZE, 0, &ioh))
    130   1.1  christos 		return (0);
    131   1.1  christos 
    132   1.1  christos 	AIC_TRACE(("aic_isa_probe: port 0x%x\n", ia->ia_iobase));
    133   1.1  christos 	rv = aic_find(iot, ioh);
    134   1.1  christos 
    135   1.1  christos 	bus_space_unmap(iot, ioh, AIC_ISA_IOSIZE);
    136   1.1  christos 
    137  1.10   thorpej 	if (rv) {
    138  1.10   thorpej 		ia->ia_nio = 1;
    139  1.10   thorpej 		ia->ia_io[0].ir_size = AIC_ISA_IOSIZE;
    140  1.10   thorpej 
    141  1.10   thorpej 		ia->ia_nirq = 1;
    142  1.10   thorpej 
    143  1.10   thorpej 		ia->ia_niomem = 0;
    144   1.1  christos 		ia->ia_ndrq = 0;
    145   1.1  christos 	}
    146   1.1  christos 	return rv;
    147   1.1  christos }
    148   1.1  christos 
    149   1.1  christos void
    150   1.1  christos aic_isa_attach(parent, self, aux)
    151   1.1  christos 	struct device *parent, *self;
    152   1.1  christos 	void *aux;
    153   1.1  christos {
    154   1.2     enami 	struct isa_attach_args *ia = aux;
    155   1.2     enami 	struct aic_isa_softc *isc = (void *)self;
    156   1.1  christos 	struct aic_softc *sc = &isc->sc_aic;
    157   1.1  christos 	bus_space_tag_t iot = ia->ia_iot;
    158   1.1  christos 	bus_space_handle_t ioh;
    159   1.1  christos 	isa_chipset_tag_t ic = ia->ia_ic;
    160   1.1  christos 
    161   1.1  christos 	printf("\n");
    162  1.10   thorpej 
    163   1.4   thorpej 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AIC_ISA_IOSIZE, 0, &ioh)) {
    164   1.4   thorpej 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    165   1.4   thorpej 		return;
    166   1.1  christos 	}
    167   1.1  christos 
    168   1.1  christos 	sc->sc_iot = iot;
    169   1.1  christos 	sc->sc_ioh = ioh;
    170   1.4   thorpej 	AIC_TRACE(("aic_isa_attach: port 0x%x\n", ia->ia_iobase));
    171   1.4   thorpej 	if (!aic_find(iot, ioh)) {
    172   1.4   thorpej 		printf("%s: aic_find failed", sc->sc_dev.dv_xname);
    173   1.4   thorpej 		return;
    174   1.1  christos 	}
    175  1.10   thorpej 
    176  1.10   thorpej 	isc->sc_ih = isa_intr_establish(ic, ia->ia_irq[0].ir_irq, IST_EDGE,
    177   1.2     enami 	    IPL_BIO, aicintr, sc);
    178   1.1  christos 	if (isc->sc_ih == NULL) {
    179   1.1  christos 		printf("%s: couldn't establish interrupt\n",
    180   1.1  christos 		    sc->sc_dev.dv_xname);
    181   1.1  christos 		return;
    182   1.1  christos 	}
    183   1.1  christos 
    184   1.1  christos 	aicattach(sc);
    185                 }
    186