Home | History | Annotate | Line # | Download | only in eisa
ahc_eisa.c revision 1.17
      1  1.17   thorpej /*	$NetBSD: ahc_eisa.c,v 1.17 2000/01/26 06:41:11 thorpej Exp $	*/
      2   1.4   thorpej 
      3   1.1   mycroft /*
      4   1.1   mycroft  * Product specific probe and attach routines for:
      5   1.1   mycroft  * 	27/284X and aic7770 motherboard SCSI controllers
      6   1.1   mycroft  *
      7   1.1   mycroft  * Copyright (c) 1994, 1995, 1996 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.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     18   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     19   1.1   mycroft  * 3. The name of the author may not be used to endorse or promote products
     20   1.1   mycroft  *    derived from this software without specific prior written permission.
     21   1.1   mycroft  *
     22   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1   mycroft  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     26   1.1   mycroft  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1   mycroft  * SUCH DAMAGE.
     33   1.5  explorer  *
     34   1.5  explorer  * from Id: aic7770.c,v 1.29 1996/05/30 07:18:52 gibbs Exp
     35   1.1   mycroft  */
     36   1.1   mycroft 
     37   1.1   mycroft #include <sys/param.h>
     38   1.1   mycroft #include <sys/systm.h>
     39   1.1   mycroft #include <sys/kernel.h>
     40  1.17   thorpej #include <sys/device.h>
     41   1.1   mycroft 
     42   1.1   mycroft #include <machine/bus.h>
     43   1.1   mycroft #include <machine/intr.h>
     44   1.1   mycroft 
     45  1.13    bouyer #include <dev/scsipi/scsi_all.h>
     46  1.13    bouyer #include <dev/scsipi/scsipi_all.h>
     47  1.13    bouyer #include <dev/scsipi/scsiconf.h>
     48   1.1   mycroft 
     49   1.1   mycroft #include <dev/eisa/eisareg.h>
     50   1.1   mycroft #include <dev/eisa/eisavar.h>
     51   1.1   mycroft #include <dev/eisa/eisadevs.h>
     52   1.1   mycroft 
     53   1.1   mycroft #include <dev/ic/aic7xxxreg.h>
     54   1.1   mycroft #include <dev/ic/aic7xxxvar.h>
     55   1.1   mycroft 
     56   1.1   mycroft #define AHC_EISA_SLOT_OFFSET	0xc00
     57   1.1   mycroft #define AHC_EISA_IOSIZE		0x100
     58   1.1   mycroft #define INTDEF			0x5cul	/* Interrupt Definition Register */
     59   1.1   mycroft 
     60   1.7   thorpej /*
     61   1.7   thorpej  * Under normal circumstances, these messages are unnecessary
     62   1.7   thorpej  * and not terribly cosmetic.
     63   1.7   thorpej  */
     64   1.7   thorpej #ifdef DEBUG
     65   1.1   mycroft #define bootverbose	1
     66   1.7   thorpej #else
     67   1.7   thorpej #define bootverbose	0
     68   1.7   thorpej #endif
     69   1.1   mycroft 
     70  1.10   thorpej int	ahc_eisa_irq __P((bus_space_tag_t, bus_space_handle_t));
     71  1.11       cgd int	ahc_eisa_match __P((struct device *, struct cfdata *, void *));
     72   1.1   mycroft void	ahc_eisa_attach __P((struct device *, struct device *, void *));
     73   1.1   mycroft 
     74   1.1   mycroft 
     75   1.1   mycroft struct cfattach ahc_eisa_ca = {
     76   1.1   mycroft 	sizeof(struct ahc_data), ahc_eisa_match, ahc_eisa_attach
     77   1.1   mycroft };
     78   1.1   mycroft 
     79   1.1   mycroft /*
     80   1.1   mycroft  * Return irq setting of the board, otherwise -1.
     81   1.1   mycroft  */
     82   1.1   mycroft int
     83  1.10   thorpej ahc_eisa_irq(iot, ioh)
     84  1.10   thorpej 	bus_space_tag_t iot;
     85  1.10   thorpej 	bus_space_handle_t ioh;
     86   1.1   mycroft {
     87   1.1   mycroft 	int irq;
     88   1.1   mycroft 	u_char intdef;
     89   1.1   mycroft 
     90  1.10   thorpej 	ahc_reset("ahc_eisa", iot, ioh);
     91  1.10   thorpej 	intdef = bus_space_read_1(iot, ioh, INTDEF);
     92   1.1   mycroft 	switch (irq = (intdef & 0xf)) {
     93   1.1   mycroft 	case 9:
     94   1.1   mycroft 	case 10:
     95   1.1   mycroft 	case 11:
     96   1.1   mycroft 	case 12:
     97   1.1   mycroft 	case 14:
     98   1.1   mycroft 	case 15:
     99   1.1   mycroft 		break;
    100   1.1   mycroft 	default:
    101   1.9  christos 		printf("ahc_eisa_irq: illegal irq setting %d\n", intdef);
    102   1.1   mycroft 		return -1;
    103   1.1   mycroft 	}
    104   1.1   mycroft 
    105   1.1   mycroft 	/* Note that we are going and return (to probe) */
    106   1.1   mycroft 	return irq;
    107   1.1   mycroft }
    108   1.1   mycroft 
    109   1.1   mycroft /*
    110   1.1   mycroft  * Check the slots looking for a board we recognise
    111   1.1   mycroft  * If we find one, note it's address (slot) and call
    112   1.1   mycroft  * the actual probe routine to check it out.
    113   1.1   mycroft  */
    114   1.1   mycroft int
    115   1.1   mycroft ahc_eisa_match(parent, match, aux)
    116   1.1   mycroft 	struct device *parent;
    117  1.11       cgd         struct cfdata *match;
    118  1.11       cgd         void *aux;
    119   1.1   mycroft {
    120   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    121  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    122  1.10   thorpej 	bus_space_handle_t ioh;
    123   1.1   mycroft 	int irq;
    124   1.1   mycroft 
    125   1.1   mycroft 	/* must match one of our known ID strings */
    126   1.1   mycroft 	if (strcmp(ea->ea_idstring, "ADP7770") &&
    127   1.6      soda 	    strcmp(ea->ea_idstring, "ADP7771")
    128   1.6      soda #if 0
    129   1.6      soda 	    && strcmp(ea->ea_idstring, "ADP7756") /* not EISA, but VL */
    130   1.6      soda 	    && strcmp(ea->ea_idstring, "ADP7757") /* not EISA, but VL */
    131   1.6      soda #endif
    132   1.6      soda 	    )
    133   1.1   mycroft 		return (0);
    134   1.1   mycroft 
    135  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    136  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
    137   1.1   mycroft 		return (0);
    138   1.3   mycroft 
    139  1.10   thorpej 	irq = ahc_eisa_irq(iot, ioh);
    140   1.3   mycroft 
    141  1.10   thorpej 	bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
    142   1.3   mycroft 
    143   1.1   mycroft 	return (irq >= 0);
    144   1.1   mycroft }
    145   1.1   mycroft 
    146   1.1   mycroft void
    147   1.1   mycroft ahc_eisa_attach(parent, self, aux)
    148   1.1   mycroft 	struct device *parent, *self;
    149   1.1   mycroft 	void *aux;
    150   1.1   mycroft {
    151   1.1   mycroft 	ahc_type type;
    152   1.1   mycroft 	struct ahc_data *ahc = (void *)self;
    153   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    154  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    155  1.10   thorpej 	bus_space_handle_t ioh;
    156   1.2   mycroft 	int irq;
    157   1.2   mycroft 	eisa_chipset_tag_t ec = ea->ea_ec;
    158   1.1   mycroft 	eisa_intr_handle_t ih;
    159   1.2   mycroft 	const char *model, *intrstr;
    160   1.1   mycroft 
    161  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    162  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
    163   1.1   mycroft 		panic("ahc_eisa_attach: could not map I/O addresses");
    164  1.10   thorpej 	if ((irq = ahc_eisa_irq(iot, ioh)) < 0)
    165   1.1   mycroft 		panic("ahc_eisa_attach: ahc_eisa_irq failed!");
    166   1.1   mycroft 
    167   1.1   mycroft 	if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
    168   1.1   mycroft 		model = EISA_PRODUCT_ADP7770;
    169   1.1   mycroft 		type = AHC_AIC7770;
    170   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
    171   1.1   mycroft 		model = EISA_PRODUCT_ADP7771;
    172   1.1   mycroft 		type = AHC_274;
    173   1.6      soda #if 0
    174   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7756") == 0) {
    175   1.1   mycroft 		model = EISA_PRODUCT_ADP7756;
    176   1.1   mycroft 		type = AHC_284;
    177   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7757") == 0) {
    178   1.1   mycroft 		model = EISA_PRODUCT_ADP7757;
    179   1.1   mycroft 		type = AHC_284;
    180   1.6      soda #endif
    181   1.1   mycroft 	} else {
    182   1.1   mycroft 		panic("ahc_eisa_attach: Unknown device type %s\n",
    183   1.1   mycroft 		      ea->ea_idstring);
    184   1.1   mycroft 	}
    185   1.9  christos 	printf(": %s\n", model);
    186   1.1   mycroft 
    187  1.15   thorpej 	ahc_construct(ahc, iot, ioh, ea->ea_dmat, type, AHC_FNONE);
    188   1.2   mycroft 	if (eisa_intr_map(ec, irq, &ih)) {
    189   1.9  christos 		printf("%s: couldn't map interrupt (%d)\n",
    190   1.8  christos 		    ahc->sc_dev.dv_xname, irq);
    191   1.1   mycroft 		return;
    192   1.1   mycroft 	}
    193   1.1   mycroft 
    194   1.1   mycroft 	/*
    195   1.1   mycroft 	 * Tell the user what type of interrupts we're using.
    196   1.1   mycroft 	 * usefull for debugging irq problems
    197   1.1   mycroft 	 */
    198   1.1   mycroft 	if(bootverbose) {
    199   1.9  christos 		printf("%s: Using %s Interrupts\n",
    200   1.8  christos 		    ahc_name(ahc),
    201   1.8  christos 		    ahc->pause & IRQMS ?  "Level Sensitive" : "Edge Triggered");
    202   1.1   mycroft 	}
    203   1.1   mycroft 
    204   1.1   mycroft 	/*
    205   1.1   mycroft 	 * Now that we know we own the resources we need, do the
    206   1.1   mycroft 	 * card initialization.
    207   1.1   mycroft 	 *
    208   1.1   mycroft 	 * First, the aic7770 card specific setup.
    209   1.1   mycroft 	 */
    210   1.1   mycroft 	switch( ahc->type ) {
    211   1.1   mycroft 	    case AHC_AIC7770:
    212   1.1   mycroft 	    case AHC_274:
    213   1.1   mycroft 	    {
    214   1.1   mycroft 		u_char biosctrl = AHC_INB(ahc, HA_274_BIOSCTRL);
    215   1.1   mycroft 
    216   1.1   mycroft 		/* Get the primary channel information */
    217   1.1   mycroft 		ahc->flags |= (biosctrl & CHANNEL_B_PRIMARY);
    218   1.1   mycroft 
    219   1.1   mycroft 		if((biosctrl & BIOSMODE) == BIOSDISABLED)
    220   1.1   mycroft 			ahc->flags |= AHC_USEDEFAULTS;
    221   1.1   mycroft 		break;
    222   1.1   mycroft 	    }
    223   1.1   mycroft 	    case AHC_284:
    224   1.1   mycroft 	    {
    225   1.1   mycroft 		/* XXX
    226   1.1   mycroft 		 * All values are automagically intialized at
    227   1.1   mycroft 		 * POST for these cards, so we can always rely
    228   1.1   mycroft 		 * on the Scratch Ram values.  However, we should
    229   1.1   mycroft 		 * read the SEEPROM here (Dan has the code to do
    230   1.1   mycroft 		 * it) so we can say what kind of translation the
    231   1.1   mycroft 		 * BIOS is using.  Printing out the geometry could
    232   1.1   mycroft 		 * save a lot of users the grief of failed installs.
    233   1.1   mycroft 		 */
    234   1.1   mycroft 		break;
    235   1.1   mycroft 	    }
    236   1.1   mycroft 	    default:
    237   1.1   mycroft 		break;
    238   1.1   mycroft 	}
    239   1.1   mycroft 
    240   1.1   mycroft 	/*
    241   1.1   mycroft 	 * See if we have a Rev E or higher aic7770. Anything below a
    242   1.1   mycroft 	 * Rev E will have a R/O autoflush disable configuration bit.
    243   1.1   mycroft 	 * It's still not clear exactly what is differenent about the Rev E.
    244   1.1   mycroft 	 * We think it allows 8 bit entries in the QOUTFIFO to support
    245   1.1   mycroft 	 * "paging" SCBs so you can have more than 4 commands active at
    246   1.1   mycroft 	 * once.
    247   1.1   mycroft 	 */
    248   1.1   mycroft 	{
    249   1.1   mycroft 		char *id_string;
    250   1.1   mycroft 		u_char sblkctl;
    251   1.1   mycroft 		u_char sblkctl_orig;
    252   1.1   mycroft 
    253   1.1   mycroft 		sblkctl_orig = AHC_INB(ahc, SBLKCTL);
    254   1.1   mycroft 		sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
    255   1.1   mycroft 		AHC_OUTB(ahc, SBLKCTL, sblkctl);
    256   1.1   mycroft 		sblkctl = AHC_INB(ahc, SBLKCTL);
    257   1.1   mycroft 		if(sblkctl != sblkctl_orig)
    258   1.1   mycroft 		{
    259   1.1   mycroft 			id_string = "aic7770 >= Rev E, ";
    260   1.1   mycroft 			/*
    261   1.1   mycroft 			 * Ensure autoflush is enabled
    262   1.1   mycroft 			 */
    263   1.1   mycroft 			sblkctl &= ~AUTOFLUSHDIS;
    264   1.1   mycroft 			AHC_OUTB(ahc, SBLKCTL, sblkctl);
    265   1.1   mycroft 
    266   1.1   mycroft 			/* Allow paging on this adapter */
    267   1.1   mycroft 			ahc->flags |= AHC_PAGESCBS;
    268   1.1   mycroft 		}
    269   1.1   mycroft 		else
    270   1.1   mycroft 			id_string = "aic7770 <= Rev C, ";
    271   1.1   mycroft 
    272   1.9  christos 		printf("%s: %s", ahc_name(ahc), id_string);
    273   1.1   mycroft 	}
    274   1.1   mycroft 
    275   1.1   mycroft 	/* Setup the FIFO threshold and the bus off time */
    276   1.1   mycroft 	{
    277   1.1   mycroft 		u_char hostconf = AHC_INB(ahc, HOSTCONF);
    278   1.1   mycroft 		AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
    279   1.1   mycroft 		AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
    280   1.1   mycroft 	}
    281   1.1   mycroft 
    282   1.1   mycroft 	/*
    283   1.1   mycroft 	 * Generic aic7xxx initialization.
    284   1.1   mycroft 	 */
    285   1.1   mycroft 	if(ahc_init(ahc)){
    286   1.1   mycroft 		ahc_free(ahc);
    287   1.1   mycroft 		return;
    288   1.1   mycroft 	}
    289   1.1   mycroft 
    290   1.1   mycroft 	/*
    291   1.1   mycroft 	 * Enable the board's BUS drivers
    292   1.1   mycroft 	 */
    293   1.1   mycroft 	AHC_OUTB(ahc, BCTL, ENABLE);
    294   1.1   mycroft 
    295   1.2   mycroft 	intrstr = eisa_intr_string(ec, ih);
    296   1.1   mycroft 	/*
    297   1.1   mycroft 	 * The IRQMS bit enables level sensitive interrupts only allow
    298   1.1   mycroft 	 * IRQ sharing if its set.
    299   1.1   mycroft 	 */
    300   1.2   mycroft 	ahc->sc_ih = eisa_intr_establish(ec, ih,
    301  1.11       cgd 	    ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc);
    302   1.1   mycroft 	if (ahc->sc_ih == NULL) {
    303   1.9  christos 		printf("%s: couldn't establish interrupt",
    304   1.8  christos 		    ahc->sc_dev.dv_xname);
    305   1.1   mycroft 		if (intrstr != NULL)
    306   1.9  christos 			printf(" at %s", intrstr);
    307   1.9  christos 		printf("\n");
    308   1.1   mycroft 		ahc_free(ahc);
    309   1.1   mycroft 		return;
    310   1.1   mycroft 	}
    311   1.1   mycroft 	if (intrstr != NULL)
    312   1.9  christos 		printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
    313   1.1   mycroft 		       intrstr);
    314   1.1   mycroft 
    315   1.1   mycroft 	/* Attach sub-devices - always succeeds */
    316   1.1   mycroft 	ahc_attach(ahc);
    317   1.1   mycroft }
    318