Home | History | Annotate | Line # | Download | only in eisa
ahc_eisa.c revision 1.19
      1  1.19  jdolecek /*	$NetBSD: ahc_eisa.c,v 1.19 2000/09/24 12:37:04 jdolecek Exp $	*/
      2   1.4   thorpej 
      3   1.1   mycroft /*
      4   1.1   mycroft  * Product specific probe and attach routines for:
      5  1.18      fvdl  * 	274X and aic7770 motherboard SCSI controllers
      6   1.1   mycroft  *
      7  1.18      fvdl  * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
      8   1.1   mycroft  * All rights reserved.
      9   1.1   mycroft  *
     10   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     11   1.1   mycroft  * modification, are permitted provided that the following conditions
     12   1.1   mycroft  * are met:
     13   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     14   1.1   mycroft  *    notice immediately at the beginning of the file, without modification,
     15   1.1   mycroft  *    this list of conditions, and the following disclaimer.
     16  1.18      fvdl  * 2. The name of the author may not be used to endorse or promote products
     17   1.1   mycroft  *    derived from this software without specific prior written permission.
     18   1.1   mycroft  *
     19   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     20   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1   mycroft  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     23   1.1   mycroft  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1   mycroft  * SUCH DAMAGE.
     30   1.5  explorer  *
     31  1.18      fvdl  * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
     32   1.1   mycroft  */
     33   1.1   mycroft 
     34   1.1   mycroft #include <sys/param.h>
     35   1.1   mycroft #include <sys/systm.h>
     36   1.1   mycroft #include <sys/kernel.h>
     37  1.17   thorpej #include <sys/device.h>
     38  1.19  jdolecek #include <sys/reboot.h>
     39   1.1   mycroft 
     40   1.1   mycroft #include <machine/bus.h>
     41   1.1   mycroft #include <machine/intr.h>
     42   1.1   mycroft 
     43  1.13    bouyer #include <dev/scsipi/scsi_all.h>
     44  1.13    bouyer #include <dev/scsipi/scsipi_all.h>
     45  1.13    bouyer #include <dev/scsipi/scsiconf.h>
     46   1.1   mycroft 
     47   1.1   mycroft #include <dev/eisa/eisareg.h>
     48   1.1   mycroft #include <dev/eisa/eisavar.h>
     49   1.1   mycroft #include <dev/eisa/eisadevs.h>
     50   1.1   mycroft 
     51  1.18      fvdl #include <dev/microcode/aic7xxx/aic7xxx_reg.h>
     52   1.1   mycroft #include <dev/ic/aic7xxxvar.h>
     53  1.18      fvdl #include <dev/ic/aic77xxreg.h>
     54  1.18      fvdl #include <dev/ic/aic77xxvar.h>
     55   1.1   mycroft 
     56  1.11       cgd int	ahc_eisa_match __P((struct device *, struct cfdata *, void *));
     57   1.1   mycroft void	ahc_eisa_attach __P((struct device *, struct device *, void *));
     58   1.1   mycroft 
     59   1.1   mycroft 
     60   1.1   mycroft struct cfattach ahc_eisa_ca = {
     61  1.18      fvdl 	sizeof(struct ahc_softc), ahc_eisa_match, ahc_eisa_attach
     62   1.1   mycroft };
     63   1.1   mycroft 
     64   1.1   mycroft /*
     65   1.1   mycroft  * Check the slots looking for a board we recognise
     66   1.1   mycroft  * If we find one, note it's address (slot) and call
     67   1.1   mycroft  * the actual probe routine to check it out.
     68   1.1   mycroft  */
     69   1.1   mycroft int
     70   1.1   mycroft ahc_eisa_match(parent, match, aux)
     71   1.1   mycroft 	struct device *parent;
     72  1.11       cgd         struct cfdata *match;
     73  1.11       cgd         void *aux;
     74   1.1   mycroft {
     75   1.1   mycroft 	struct eisa_attach_args *ea = aux;
     76  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
     77  1.10   thorpej 	bus_space_handle_t ioh;
     78   1.1   mycroft 	int irq;
     79   1.1   mycroft 
     80   1.1   mycroft 	/* must match one of our known ID strings */
     81   1.1   mycroft 	if (strcmp(ea->ea_idstring, "ADP7770") &&
     82  1.18      fvdl 	    strcmp(ea->ea_idstring, "ADP7771"))
     83   1.1   mycroft 		return (0);
     84   1.1   mycroft 
     85  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
     86  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
     87   1.1   mycroft 		return (0);
     88   1.3   mycroft 
     89  1.18      fvdl 	irq = ahc_aic77xx_irq(iot, ioh);
     90   1.3   mycroft 
     91  1.10   thorpej 	bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
     92   1.3   mycroft 
     93   1.1   mycroft 	return (irq >= 0);
     94   1.1   mycroft }
     95   1.1   mycroft 
     96   1.1   mycroft void
     97   1.1   mycroft ahc_eisa_attach(parent, self, aux)
     98   1.1   mycroft 	struct device *parent, *self;
     99   1.1   mycroft 	void *aux;
    100   1.1   mycroft {
    101  1.18      fvdl 	struct ahc_softc *ahc = (void *)self;
    102   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    103  1.18      fvdl 	eisa_chipset_tag_t ec = ea->ea_ec;
    104  1.18      fvdl 	eisa_intr_handle_t ih;
    105  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    106  1.10   thorpej 	bus_space_handle_t ioh;
    107  1.18      fvdl 	int irq, intrtype;
    108  1.18      fvdl 	const char *intrstr, *intrtypestr;
    109  1.18      fvdl 	u_int biosctrl;
    110  1.18      fvdl 	u_int scsiconf;
    111  1.18      fvdl 	u_int scsiconf1;
    112  1.18      fvdl #if DEBUG
    113  1.18      fvdl 	int i;
    114  1.18      fvdl #endif
    115   1.1   mycroft 
    116  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    117  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
    118  1.18      fvdl 		panic("%s: could not map I/O addresses", ahc->sc_dev.dv_xname);
    119  1.18      fvdl 	if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0)
    120  1.18      fvdl 		panic("%s: ahc_aic77xx_irq failed!", ahc->sc_dev.dv_xname);
    121   1.1   mycroft 
    122   1.1   mycroft 	if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
    123  1.18      fvdl 		printf(": %s\n", EISA_PRODUCT_ADP7770);
    124   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
    125  1.18      fvdl 		printf(": %s\n", EISA_PRODUCT_ADP7771);
    126   1.1   mycroft 	} else {
    127  1.18      fvdl 		panic(": Unknown device type %s\n", ea->ea_idstring);
    128   1.1   mycroft 	}
    129   1.1   mycroft 
    130  1.18      fvdl 	if (ahc_alloc(ahc, ioh, iot, ea->ea_dmat,
    131  1.18      fvdl 	    AHC_AIC7770|AHC_EISA, AHC_AIC7770_FE, AHC_FNONE) < 0)
    132  1.18      fvdl 		goto free_io;
    133  1.18      fvdl 
    134  1.18      fvdl 	ahc->channel = 'A';
    135  1.18      fvdl 	ahc->channel_b = 'B';
    136  1.18      fvdl 	if (ahc_reset(ahc) != 0)
    137  1.18      fvdl 		goto free_ahc;
    138  1.18      fvdl 
    139   1.2   mycroft 	if (eisa_intr_map(ec, irq, &ih)) {
    140   1.9  christos 		printf("%s: couldn't map interrupt (%d)\n",
    141   1.8  christos 		    ahc->sc_dev.dv_xname, irq);
    142  1.18      fvdl 		goto free_ahc;
    143   1.1   mycroft 	}
    144   1.1   mycroft 
    145   1.1   mycroft 	/*
    146  1.18      fvdl 	 * The IRQMS bit enables level sensitive interrupts. Only allow
    147  1.18      fvdl 	 * IRQ sharing if it's set.
    148  1.18      fvdl 	 * NOTE: ahc->pause is initialized in ahc_alloc().
    149  1.18      fvdl 	 *
    150   1.1   mycroft 	 * Tell the user what type of interrupts we're using.
    151   1.1   mycroft 	 * usefull for debugging irq problems
    152   1.1   mycroft 	 */
    153  1.18      fvdl 	if (ahc->pause & IRQMS) {
    154  1.18      fvdl 		intrtype = IST_LEVEL;
    155  1.18      fvdl 		intrtypestr = "level sensitive";
    156  1.18      fvdl 	} else {
    157  1.18      fvdl 		intrtype = IST_EDGE;
    158  1.18      fvdl 		intrtypestr = "edge triggered";
    159   1.1   mycroft 	}
    160  1.18      fvdl 	intrstr = eisa_intr_string(ec, ih);
    161  1.18      fvdl 	ahc->ih = eisa_intr_establish(ec, ih,
    162  1.18      fvdl 	    intrtype, IPL_BIO, ahc_intr, ahc);
    163  1.18      fvdl 	if (ahc->ih == NULL) {
    164  1.18      fvdl 		printf("%s: couldn't establish %s interrupt",
    165  1.18      fvdl 		    ahc->sc_dev.dv_xname, intrtypestr);
    166  1.18      fvdl 		if (intrstr != NULL)
    167  1.18      fvdl 			printf(" at %s", intrstr);
    168  1.18      fvdl 		printf("\n");
    169  1.18      fvdl 		goto free_ahc;
    170  1.18      fvdl 	}
    171  1.18      fvdl 	if (intrstr != NULL)
    172  1.18      fvdl 		printf("%s: %s interrupting at %s\n", ahc->sc_dev.dv_xname,
    173  1.18      fvdl 		       intrtypestr, intrstr);
    174   1.1   mycroft 
    175   1.1   mycroft 	/*
    176   1.1   mycroft 	 * Now that we know we own the resources we need, do the
    177   1.1   mycroft 	 * card initialization.
    178   1.1   mycroft 	 *
    179   1.1   mycroft 	 * First, the aic7770 card specific setup.
    180   1.1   mycroft 	 */
    181  1.18      fvdl 	biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
    182  1.18      fvdl 	scsiconf = ahc_inb(ahc, SCSICONF);
    183  1.18      fvdl 	scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
    184  1.18      fvdl 
    185  1.18      fvdl #if DEBUG
    186  1.18      fvdl 	for (i = TARG_SCSIRATE; i <= HA_274_BIOSCTRL; i+=8) {
    187  1.18      fvdl 		printf("0x%x, 0x%x, 0x%x, 0x%x, "
    188  1.18      fvdl 		       "0x%x, 0x%x, 0x%x, 0x%x\n",
    189  1.18      fvdl 		       ahc_inb(ahc, i),
    190  1.18      fvdl 		       ahc_inb(ahc, i+1),
    191  1.18      fvdl 		       ahc_inb(ahc, i+2),
    192  1.18      fvdl 		       ahc_inb(ahc, i+3),
    193  1.18      fvdl 		       ahc_inb(ahc, i+4),
    194  1.18      fvdl 		       ahc_inb(ahc, i+5),
    195  1.18      fvdl 		       ahc_inb(ahc, i+6),
    196  1.18      fvdl 		       ahc_inb(ahc, i+7));
    197   1.1   mycroft 	}
    198  1.18      fvdl #endif
    199   1.1   mycroft 
    200  1.18      fvdl 	/* Get the primary channel information */
    201  1.18      fvdl 	if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
    202  1.18      fvdl 		ahc->flags |= AHC_CHANNEL_B_PRIMARY;
    203  1.18      fvdl 
    204  1.18      fvdl 	if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
    205  1.18      fvdl 		ahc->flags |= AHC_USEDEFAULTS;
    206  1.18      fvdl 	} else if ((ahc->features & AHC_WIDE) != 0) {
    207  1.18      fvdl 		ahc->our_id = scsiconf1 & HWSCSIID;
    208  1.18      fvdl 		if (scsiconf & TERM_ENB)
    209  1.18      fvdl 			ahc->flags |= AHC_TERM_ENB_A;
    210  1.18      fvdl 	} else {
    211  1.18      fvdl 		ahc->our_id = scsiconf & HSCSIID;
    212  1.18      fvdl 		ahc->our_id_b = scsiconf1 & HSCSIID;
    213  1.18      fvdl 		if (scsiconf & TERM_ENB)
    214  1.18      fvdl 			ahc->flags |= AHC_TERM_ENB_A;
    215  1.18      fvdl 		if (scsiconf1 & TERM_ENB)
    216  1.18      fvdl 			ahc->flags |= AHC_TERM_ENB_B;
    217   1.1   mycroft 	}
    218   1.1   mycroft 	/*
    219  1.18      fvdl 	 * We have no way to tell, so assume extended
    220  1.18      fvdl 	 * translation is enabled.
    221   1.1   mycroft 	 */
    222  1.18      fvdl 	ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
    223   1.1   mycroft 
    224  1.18      fvdl 	/* Attach sub-devices */
    225  1.18      fvdl 	if (ahc_aic77xx_attach(ahc) == 0)
    226  1.18      fvdl 		return; /* succeed */
    227  1.18      fvdl 
    228  1.18      fvdl 	/* failed */
    229  1.18      fvdl 	eisa_intr_disestablish(ec, ahc->ih);
    230  1.18      fvdl free_ahc:
    231  1.18      fvdl 	ahc_free(ahc);
    232  1.18      fvdl free_io:
    233  1.18      fvdl 	bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
    234   1.1   mycroft }
    235