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