Home | History | Annotate | Line # | Download | only in mca
aha_mca.c revision 1.3.2.2
      1  1.3.2.2  jdolecek /*	$NetBSD: aha_mca.c,v 1.3.2.2 2002/06/23 17:47:12 jdolecek Exp $	*/
      2      1.1  jdolecek 
      3      1.1  jdolecek /*
      4  1.3.2.2  jdolecek  * Copyright (c) 2000-2002 The NetBSD Foundation, Inc.
      5      1.1  jdolecek  * Copyright (c) 1996-1999 Scott D. Telford.
      6      1.1  jdolecek  * Copyright (c) 1994, 1996 Charles M. Hannum.  All rights reserved.
      7      1.1  jdolecek  * Portions:
      8      1.1  jdolecek  *
      9      1.1  jdolecek  * Redistribution and use in source and binary forms, with or without
     10      1.1  jdolecek  * modification, are permitted provided that the following conditions
     11      1.1  jdolecek  * are met:
     12      1.1  jdolecek  * 1. Redistributions of source code must retain the above copyright
     13      1.1  jdolecek  *    notice, this list of conditions and the following disclaimer.
     14      1.1  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     16      1.1  jdolecek  *    documentation and/or other materials provided with the distribution.
     17      1.1  jdolecek  * 3. All advertising materials mentioning features or use of this software
     18      1.1  jdolecek  *    must display the following acknowledgement:
     19      1.1  jdolecek  *	This product includes software developed by Charles M. Hannum.
     20      1.1  jdolecek  * 4. The name of the author may not be used to endorse or promote products
     21      1.1  jdolecek  *    derived from this software without specific prior written permission.
     22      1.1  jdolecek  *
     23      1.1  jdolecek  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24      1.1  jdolecek  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25      1.1  jdolecek  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26      1.1  jdolecek  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27      1.1  jdolecek  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28      1.1  jdolecek  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29      1.1  jdolecek  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30      1.1  jdolecek  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31      1.1  jdolecek  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32      1.1  jdolecek  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33      1.1  jdolecek  */
     34      1.1  jdolecek 
     35      1.1  jdolecek /*
     36      1.1  jdolecek  * Originally written by Julian Elischer (julian (at) tfs.com)
     37      1.1  jdolecek  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     38      1.1  jdolecek  *
     39      1.1  jdolecek  * TRW Financial Systems, in accordance with their agreement with Carnegie
     40      1.1  jdolecek  * Mellon University, makes this software available to CMU to distribute
     41      1.1  jdolecek  * or use in any manner that they see fit as long as this message is kept with
     42      1.1  jdolecek  * the software. For this reason TFS also grants any other persons or
     43      1.1  jdolecek  * organisations permission to use or modify this software.
     44      1.1  jdolecek  *
     45      1.1  jdolecek  * TFS supplies this software to be publicly redistributed
     46      1.1  jdolecek  * on the understanding that TFS is not responsible for the correct
     47      1.1  jdolecek  * functioning of this software in any circumstances.
     48      1.1  jdolecek  */
     49      1.1  jdolecek 
     50      1.1  jdolecek /*
     51      1.1  jdolecek  * AHA-1640 MCA bus code by Scott Telford
     52      1.1  jdolecek  */
     53      1.1  jdolecek 
     54  1.3.2.1   thorpej #include <sys/cdefs.h>
     55  1.3.2.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: aha_mca.c,v 1.3.2.2 2002/06/23 17:47:12 jdolecek Exp $");
     56  1.3.2.1   thorpej 
     57      1.1  jdolecek #include <sys/param.h>
     58      1.1  jdolecek #include <sys/systm.h>
     59      1.1  jdolecek #include <sys/device.h>
     60      1.1  jdolecek 
     61      1.1  jdolecek #include <machine/bus.h>
     62      1.1  jdolecek #include <machine/intr.h>
     63      1.1  jdolecek 
     64      1.1  jdolecek #include <dev/scsipi/scsi_all.h>
     65      1.1  jdolecek #include <dev/scsipi/scsipi_all.h>
     66      1.1  jdolecek #include <dev/scsipi/scsiconf.h>
     67      1.1  jdolecek 
     68      1.1  jdolecek #include <dev/isa/isavar.h>
     69      1.1  jdolecek #include <dev/isa/isadmavar.h>
     70      1.1  jdolecek 
     71      1.1  jdolecek #include <dev/ic/ahareg.h>
     72      1.1  jdolecek #include <dev/ic/ahavar.h>
     73      1.1  jdolecek 
     74      1.1  jdolecek #include <dev/mca/mcareg.h>
     75      1.1  jdolecek #include <dev/mca/mcavar.h>
     76      1.1  jdolecek #include <dev/mca/mcadevs.h>
     77      1.1  jdolecek 
     78      1.1  jdolecek #define	AHA_ISA_IOSIZE	4
     79      1.1  jdolecek 
     80      1.1  jdolecek int	aha_mca_probe __P((struct device *, struct cfdata *, void *));
     81      1.1  jdolecek void	aha_mca_attach __P((struct device *, struct device *, void *));
     82      1.1  jdolecek 
     83      1.1  jdolecek struct cfattach aha_mca_ca = {
     84      1.1  jdolecek 	sizeof(struct aha_softc), aha_mca_probe, aha_mca_attach
     85      1.1  jdolecek };
     86      1.1  jdolecek 
     87      1.1  jdolecek 
     88      1.1  jdolecek int
     89      1.1  jdolecek aha_mca_probe(parent, match, aux)
     90      1.1  jdolecek 	struct device *parent;
     91      1.1  jdolecek 	struct cfdata *match;
     92      1.1  jdolecek 	void *aux;
     93      1.1  jdolecek {
     94      1.1  jdolecek 	register struct mca_attach_args *ma = aux;
     95      1.1  jdolecek 
     96  1.3.2.2  jdolecek 	if (ma->ma_id == MCA_PRODUCT_AHA1640)
     97  1.3.2.2  jdolecek 		return (1);
     98      1.1  jdolecek 
     99  1.3.2.2  jdolecek 	return (0);
    100      1.1  jdolecek }
    101      1.1  jdolecek 
    102      1.1  jdolecek 
    103      1.1  jdolecek void
    104      1.1  jdolecek aha_mca_attach(parent, self, aux)
    105      1.1  jdolecek 	struct device *parent, *self;
    106      1.1  jdolecek 	void *aux;
    107      1.1  jdolecek {
    108      1.1  jdolecek 	struct mca_attach_args *ma = aux;
    109      1.1  jdolecek 	struct aha_softc *sc = (void *)self;
    110      1.1  jdolecek 	bus_space_tag_t iot = ma->ma_iot;
    111      1.1  jdolecek 	bus_space_handle_t ioh;
    112      1.1  jdolecek 	struct aha_probe_data apd;
    113      1.1  jdolecek 	mca_chipset_tag_t mc = ma->ma_mc;
    114      1.1  jdolecek 	bus_addr_t iobase;
    115      1.1  jdolecek 
    116  1.3.2.2  jdolecek 	/*
    117  1.3.2.2  jdolecek 	 * POS registers differ much between 8003 and 8013, so they are
    118  1.3.2.2  jdolecek 	 * divided to two sections.
    119  1.3.2.2  jdolecek 	 *
    120  1.3.2.2  jdolecek 	 * POS register 2: (adf pos0)
    121  1.3.2.2  jdolecek 	 * 7 6 5 4 3 2 1 0
    122  1.3.2.2  jdolecek 	 * | 0 0 0 0 0 0 \__ enable: 0=adapter disabled, 1=adapter enabled
    123  1.3.2.2  jdolecek 	 *  \_______________ Adapter BIOS location
    124  1.3.2.2  jdolecek 	 *
    125  1.3.2.2  jdolecek 	 * POS register 3: (adf pos1)
    126  1.3.2.2  jdolecek 	 * 7 6 5 4 3 2 1 0
    127  1.3.2.2  jdolecek 	 * \_/ \___/ \___/
    128  1.3.2.2  jdolecek 	 *  |    |       \__ I/O Port Address (upper part)
    129  1.3.2.2  jdolecek 	 *  |    |__________ Adapter BIOS location
    130  1.3.2.2  jdolecek 	 *  |_______________ I/O Port Address (lower part)
    131  1.3.2.2  jdolecek 	 *
    132  1.3.2.2  jdolecek 	 * POS register 4: (adf pos2)
    133  1.3.2.2  jdolecek 	 * 7 6 5 4 3 2 1 0
    134  1.3.2.2  jdolecek 	 * \___/ | | \___/
    135  1.3.2.2  jdolecek 	 *   |   | |     \__ IRQ: XXX+8
    136  1.3.2.2  jdolecek 	 *   |   | |________ Sync xfer started by AHA-1640: 1=YES 2=NO
    137  1.3.2.2  jdolecek 	 *   |   |__________ SCSI Parity Checking On/Off
    138  1.3.2.2  jdolecek 	 *   |______________ SCSI Address
    139  1.3.2.2  jdolecek 	 *
    140  1.3.2.2  jdolecek 	 * POS register 3: (adf pos3)
    141  1.3.2.2  jdolecek 	 * 7 6 5 4 3 2 1 0
    142  1.3.2.2  jdolecek 	 *       | \_____/
    143  1.3.2.2  jdolecek 	 *       |       \__ Arbitration lvl (DMA channel)
    144  1.3.2.2  jdolecek 	 *       |__________ Fairness On/Off
    145  1.3.2.2  jdolecek 	 *
    146  1.3.2.2  jdolecek 	 */
    147  1.3.2.2  jdolecek 
    148  1.3.2.1   thorpej 	apd.sc_irq = (ma->ma_pos[4] & 0x7) + 8;
    149  1.3.2.1   thorpej 	apd.sc_drq = ma->ma_pos[5] & 0xf;
    150  1.3.2.1   thorpej 	apd.sc_scsi_dev = (ma->ma_pos[4] & 0xe0) >> 5;
    151      1.3  jdolecek 
    152  1.3.2.1   thorpej 	printf(" slot %d irq %d drq %d: Adaptec AHA-1640 SCSI Adapter\n",
    153      1.3  jdolecek 		ma->ma_slot + 1,
    154  1.3.2.1   thorpej 		apd.sc_irq, apd.sc_drq);
    155      1.1  jdolecek 
    156  1.3.2.1   thorpej 	iobase = ((ma->ma_pos[3] & 0x03) << 8) + 0x30 +
    157  1.3.2.1   thorpej 		 ((ma->ma_pos[3] & 0x40) >> 4);
    158      1.1  jdolecek 
    159      1.1  jdolecek 	if (bus_space_map(iot, iobase, AHA_ISA_IOSIZE, 0, &ioh)) {
    160      1.1  jdolecek 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
    161      1.1  jdolecek 		return;
    162      1.1  jdolecek 	}
    163      1.1  jdolecek 
    164      1.1  jdolecek 	sc->sc_iot = iot;
    165      1.1  jdolecek 	sc->sc_ioh = ioh;
    166      1.1  jdolecek 	sc->sc_dmat = ma->ma_dmat;
    167      1.1  jdolecek 
    168  1.3.2.1   thorpej 	/*
    169  1.3.2.2  jdolecek 	 * AHA1640 is bus-mastering card, does not need any assistance
    170  1.3.2.2  jdolecek 	 * with DMA transfers by MCA DMA controller.
    171  1.3.2.1   thorpej 	 */
    172      1.1  jdolecek 
    173      1.1  jdolecek 	sc->sc_ih = mca_intr_establish(mc, apd.sc_irq, IPL_BIO, aha_intr, sc);
    174      1.1  jdolecek 	if (sc->sc_ih == NULL) {
    175      1.1  jdolecek 		printf("%s: couldn't establish interrupt\n",
    176      1.1  jdolecek 		    sc->sc_dev.dv_xname);
    177      1.1  jdolecek 		return;
    178      1.1  jdolecek 	}
    179      1.1  jdolecek 
    180      1.1  jdolecek 	aha_attach(sc, &apd);
    181      1.1  jdolecek }
    182