Home | History | Annotate | Line # | Download | only in eisa
ahc_eisa.c revision 1.13
      1  1.13    bouyer /*	$NetBSD: ahc_eisa.c,v 1.13 1997/08/27 11:24:42 bouyer 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 #if defined(__FreeBSD__)
     38   1.1   mycroft #include <eisa.h>
     39   1.1   mycroft #endif
     40   1.1   mycroft #if NEISA > 0 || defined(__NetBSD__)
     41   1.1   mycroft 
     42   1.1   mycroft #include <sys/param.h>
     43   1.1   mycroft #include <sys/systm.h>
     44   1.1   mycroft #if defined(__FreeBSD__)
     45   1.1   mycroft #include <sys/devconf.h>
     46   1.1   mycroft #endif
     47   1.1   mycroft #include <sys/kernel.h>
     48   1.1   mycroft 
     49   1.1   mycroft #if defined(__NetBSD__)
     50   1.1   mycroft #include <sys/device.h>
     51   1.1   mycroft #include <machine/bus.h>
     52   1.1   mycroft #include <machine/intr.h>
     53   1.1   mycroft #endif /* defined(__NetBSD__) */
     54   1.1   mycroft 
     55  1.13    bouyer #include <dev/scsipi/scsi_all.h>
     56  1.13    bouyer #include <dev/scsipi/scsipi_all.h>
     57  1.13    bouyer #include <dev/scsipi/scsiconf.h>
     58   1.1   mycroft 
     59   1.1   mycroft #if defined(__FreeBSD__)
     60   1.1   mycroft 
     61   1.1   mycroft #include <machine/clock.h>
     62   1.1   mycroft 
     63   1.1   mycroft #include <i386/eisa/eisaconf.h>
     64   1.1   mycroft #include <i386/scsi/aic7xxx.h>
     65   1.1   mycroft #include <dev/aic7xxx/aic7xxx_reg.h>
     66   1.1   mycroft 
     67   1.1   mycroft #define EISA_DEVICE_ID_ADAPTEC_AIC7770	0x04907770
     68   1.1   mycroft #define EISA_DEVICE_ID_ADAPTEC_274x	0x04907771
     69   1.1   mycroft #define EISA_DEVICE_ID_ADAPTEC_284xB	0x04907756 /* BIOS enabled */
     70   1.1   mycroft #define EISA_DEVICE_ID_ADAPTEC_284x	0x04907757 /* BIOS disabled*/
     71   1.1   mycroft 
     72   1.1   mycroft #elif defined(__NetBSD__)
     73   1.1   mycroft 
     74   1.1   mycroft #include <dev/eisa/eisareg.h>
     75   1.1   mycroft #include <dev/eisa/eisavar.h>
     76   1.1   mycroft #include <dev/eisa/eisadevs.h>
     77   1.1   mycroft 
     78   1.1   mycroft #include <dev/ic/aic7xxxreg.h>
     79   1.1   mycroft #include <dev/ic/aic7xxxvar.h>
     80   1.1   mycroft 
     81   1.1   mycroft #endif /* defined(__NetBSD__) */
     82   1.1   mycroft 
     83   1.1   mycroft #define AHC_EISA_SLOT_OFFSET	0xc00
     84   1.1   mycroft #define AHC_EISA_IOSIZE		0x100
     85   1.1   mycroft #define INTDEF			0x5cul	/* Interrupt Definition Register */
     86   1.1   mycroft 
     87   1.1   mycroft #if defined(__FreeBSD__)
     88   1.1   mycroft 
     89   1.1   mycroft static int	aic7770probe __P((void));
     90   1.1   mycroft static int	aic7770_attach __P((struct eisa_device *e_dev));
     91   1.1   mycroft 
     92   1.1   mycroft static struct eisa_driver ahc_eisa_driver = {
     93   1.1   mycroft 					"ahc",
     94   1.1   mycroft 					aic7770probe,
     95   1.1   mycroft 					aic7770_attach,
     96   1.1   mycroft 					/*shutdown*/NULL,
     97   1.1   mycroft 					&ahc_unit
     98   1.1   mycroft 				      };
     99   1.1   mycroft 
    100   1.1   mycroft DATA_SET (eisadriver_set, ahc_eisa_driver);
    101   1.1   mycroft 
    102   1.1   mycroft static struct kern_devconf kdc_aic7770 = {
    103   1.1   mycroft 	0, 0, 0,                /* filled in by dev_attach */
    104   1.1   mycroft 	"ahc", 0, { MDDT_EISA, 0, "bio" },
    105   1.1   mycroft 	eisa_generic_externalize, 0, 0, EISA_EXTERNALLEN,
    106   1.1   mycroft 	&kdc_eisa0,		/* parent */
    107   1.1   mycroft 	0,			/* parentdata */
    108   1.1   mycroft 	DC_UNCONFIGURED,	/* always start out here */
    109   1.1   mycroft 	NULL,
    110   1.1   mycroft 	DC_CLS_MISC		/* host adapters aren't special */
    111   1.1   mycroft };
    112   1.1   mycroft 
    113   1.1   mycroft 
    114   1.1   mycroft static char	*aic7770_match __P((eisa_id_t type));
    115   1.1   mycroft 
    116   1.1   mycroft static  char*
    117   1.1   mycroft aic7770_match(type)
    118   1.1   mycroft 	eisa_id_t type;
    119   1.1   mycroft {
    120   1.1   mycroft 	switch(type) {
    121   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_AIC7770:
    122   1.1   mycroft 			return ("Adaptec aic7770 SCSI host adapter");
    123   1.1   mycroft 			break;
    124   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_274x:
    125   1.1   mycroft 			return ("Adaptec 274X SCSI host adapter");
    126   1.1   mycroft 			break;
    127   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_284xB:
    128   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_284x:
    129   1.1   mycroft 			return ("Adaptec 284X SCSI host adapter");
    130   1.1   mycroft 			break;
    131   1.1   mycroft 		default:
    132   1.1   mycroft 			break;
    133   1.1   mycroft 	}
    134   1.1   mycroft 	return (NULL);
    135   1.1   mycroft }
    136   1.1   mycroft 
    137   1.1   mycroft static int
    138   1.1   mycroft aic7770probe(void)
    139   1.1   mycroft {
    140   1.1   mycroft 	u_long iobase;
    141   1.1   mycroft 	char intdef;
    142   1.1   mycroft 	u_long irq;
    143   1.1   mycroft 	struct eisa_device *e_dev = NULL;
    144   1.1   mycroft 	int count;
    145   1.1   mycroft 
    146   1.1   mycroft 	count = 0;
    147   1.1   mycroft 	while ((e_dev = eisa_match_dev(e_dev, aic7770_match))) {
    148   1.1   mycroft 		iobase = (e_dev->ioconf.slot * EISA_SLOT_SIZE)
    149   1.1   mycroft 			 + AHC_EISA_SLOT_OFFSET;
    150   1.1   mycroft 		ahc_reset(iobase);
    151   1.1   mycroft 
    152   1.1   mycroft 		eisa_add_iospace(e_dev, iobase, AHC_EISA_IOSIZE, RESVADDR_NONE);
    153   1.1   mycroft 		intdef = inb(INTDEF + iobase);
    154   1.1   mycroft 		switch (intdef & 0xf) {
    155   1.1   mycroft 			case 9:
    156   1.1   mycroft 				irq = 9;
    157   1.1   mycroft 				break;
    158   1.1   mycroft 			case 10:
    159   1.1   mycroft 				irq = 10;
    160   1.1   mycroft 				break;
    161   1.1   mycroft 			case 11:
    162   1.1   mycroft 				irq = 11;
    163   1.1   mycroft 				break;
    164   1.1   mycroft 			case 12:
    165   1.1   mycroft 				irq = 12;
    166   1.1   mycroft 				break;
    167   1.1   mycroft 			case 14:
    168   1.1   mycroft 				irq = 14;
    169   1.1   mycroft 				break;
    170   1.1   mycroft 			case 15:
    171   1.1   mycroft 				irq = 15;
    172   1.1   mycroft 				break;
    173   1.1   mycroft 			default:
    174   1.9  christos 				printf("aic7770 at slot %d: illegal "
    175   1.8  christos 				    "irq setting %d\n", e_dev->ioconf.slot,
    176   1.8  christos 				    intdef);
    177   1.1   mycroft 				continue;
    178   1.1   mycroft 		}
    179   1.1   mycroft 		eisa_add_intr(e_dev, irq);
    180   1.1   mycroft 		eisa_registerdev(e_dev, &ahc_eisa_driver, &kdc_aic7770);
    181   1.1   mycroft 		if(e_dev->id == EISA_DEVICE_ID_ADAPTEC_284xB
    182   1.1   mycroft 		   || e_dev->id == EISA_DEVICE_ID_ADAPTEC_284x) {
    183   1.1   mycroft 			/* Our real parent is the isa bus.  Say so. */
    184   1.1   mycroft 			e_dev->kdc->kdc_parent = &kdc_isa0;
    185   1.1   mycroft 		}
    186   1.1   mycroft 		count++;
    187   1.1   mycroft 	}
    188   1.1   mycroft 	return count;
    189   1.1   mycroft }
    190   1.1   mycroft 
    191   1.1   mycroft #elif defined(__NetBSD__)
    192   1.1   mycroft 
    193   1.7   thorpej /*
    194   1.7   thorpej  * Under normal circumstances, these messages are unnecessary
    195   1.7   thorpej  * and not terribly cosmetic.
    196   1.7   thorpej  */
    197   1.7   thorpej #ifdef DEBUG
    198   1.1   mycroft #define bootverbose	1
    199   1.7   thorpej #else
    200   1.7   thorpej #define bootverbose	0
    201   1.7   thorpej #endif
    202   1.1   mycroft 
    203  1.10   thorpej int	ahc_eisa_irq __P((bus_space_tag_t, bus_space_handle_t));
    204  1.11       cgd #ifdef	__BROKEN_INDIRECT_CONFIG
    205   1.1   mycroft int	ahc_eisa_match __P((struct device *, void *, void *));
    206  1.11       cgd #else
    207  1.11       cgd int	ahc_eisa_match __P((struct device *, struct cfdata *, void *));
    208  1.11       cgd #endif
    209   1.1   mycroft void	ahc_eisa_attach __P((struct device *, struct device *, void *));
    210   1.1   mycroft 
    211   1.1   mycroft 
    212   1.1   mycroft struct cfattach ahc_eisa_ca = {
    213   1.1   mycroft 	sizeof(struct ahc_data), ahc_eisa_match, ahc_eisa_attach
    214   1.1   mycroft };
    215   1.1   mycroft 
    216   1.1   mycroft /*
    217   1.1   mycroft  * Return irq setting of the board, otherwise -1.
    218   1.1   mycroft  */
    219   1.1   mycroft int
    220  1.10   thorpej ahc_eisa_irq(iot, ioh)
    221  1.10   thorpej 	bus_space_tag_t iot;
    222  1.10   thorpej 	bus_space_handle_t ioh;
    223   1.1   mycroft {
    224   1.1   mycroft 	int irq;
    225   1.1   mycroft 	u_char intdef;
    226   1.1   mycroft 
    227  1.10   thorpej 	ahc_reset("ahc_eisa", iot, ioh);
    228  1.10   thorpej 	intdef = bus_space_read_1(iot, ioh, INTDEF);
    229   1.1   mycroft 	switch (irq = (intdef & 0xf)) {
    230   1.1   mycroft 	case 9:
    231   1.1   mycroft 	case 10:
    232   1.1   mycroft 	case 11:
    233   1.1   mycroft 	case 12:
    234   1.1   mycroft 	case 14:
    235   1.1   mycroft 	case 15:
    236   1.1   mycroft 		break;
    237   1.1   mycroft 	default:
    238   1.9  christos 		printf("ahc_eisa_irq: illegal irq setting %d\n", intdef);
    239   1.1   mycroft 		return -1;
    240   1.1   mycroft 	}
    241   1.1   mycroft 
    242   1.1   mycroft 	/* Note that we are going and return (to probe) */
    243   1.1   mycroft 	return irq;
    244   1.1   mycroft }
    245   1.1   mycroft 
    246   1.1   mycroft /*
    247   1.1   mycroft  * Check the slots looking for a board we recognise
    248   1.1   mycroft  * If we find one, note it's address (slot) and call
    249   1.1   mycroft  * the actual probe routine to check it out.
    250   1.1   mycroft  */
    251   1.1   mycroft int
    252   1.1   mycroft ahc_eisa_match(parent, match, aux)
    253   1.1   mycroft 	struct device *parent;
    254  1.11       cgd #ifdef	__BROKEN_INDIRECT_CONFIG
    255  1.11       cgd         void *match;
    256  1.11       cgd #else
    257  1.11       cgd         struct cfdata *match;
    258  1.11       cgd #endif
    259  1.11       cgd         void *aux;
    260   1.1   mycroft {
    261   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    262  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    263  1.10   thorpej 	bus_space_handle_t ioh;
    264   1.1   mycroft 	int irq;
    265   1.1   mycroft 
    266   1.1   mycroft 	/* must match one of our known ID strings */
    267   1.1   mycroft 	if (strcmp(ea->ea_idstring, "ADP7770") &&
    268   1.6      soda 	    strcmp(ea->ea_idstring, "ADP7771")
    269   1.6      soda #if 0
    270   1.6      soda 	    && strcmp(ea->ea_idstring, "ADP7756") /* not EISA, but VL */
    271   1.6      soda 	    && strcmp(ea->ea_idstring, "ADP7757") /* not EISA, but VL */
    272   1.6      soda #endif
    273   1.6      soda 	    )
    274   1.1   mycroft 		return (0);
    275   1.1   mycroft 
    276  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    277  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
    278   1.1   mycroft 		return (0);
    279   1.3   mycroft 
    280  1.10   thorpej 	irq = ahc_eisa_irq(iot, ioh);
    281   1.3   mycroft 
    282  1.10   thorpej 	bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
    283   1.3   mycroft 
    284   1.1   mycroft 	return (irq >= 0);
    285   1.1   mycroft }
    286   1.1   mycroft 
    287   1.1   mycroft #endif /* defined(__NetBSD__) */
    288   1.1   mycroft 
    289   1.1   mycroft #if defined(__FreeBSD__)
    290   1.1   mycroft static int
    291   1.1   mycroft aic7770_attach(e_dev)
    292   1.1   mycroft 	struct eisa_device *e_dev;
    293   1.1   mycroft #elif defined(__NetBSD__)
    294   1.1   mycroft void
    295   1.1   mycroft ahc_eisa_attach(parent, self, aux)
    296   1.1   mycroft 	struct device *parent, *self;
    297   1.1   mycroft 	void *aux;
    298   1.1   mycroft #endif
    299   1.1   mycroft {
    300   1.1   mycroft 	ahc_type type;
    301   1.1   mycroft 
    302   1.1   mycroft #if defined(__FreeBSD__)
    303   1.1   mycroft 	struct ahc_data *ahc;
    304   1.1   mycroft 	resvaddr_t *iospace;
    305   1.1   mycroft 	int unit = e_dev->unit;
    306   1.1   mycroft 	int irq = ffs(e_dev->ioconf.irq) - 1;
    307   1.1   mycroft 
    308   1.1   mycroft 	iospace = e_dev->ioconf.ioaddrs.lh_first;
    309   1.1   mycroft 
    310   1.1   mycroft 	if(!iospace)
    311   1.1   mycroft 		return -1;
    312   1.1   mycroft 
    313   1.1   mycroft 	switch(e_dev->id) {
    314   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_AIC7770:
    315   1.1   mycroft 			type = AHC_AIC7770;
    316   1.1   mycroft 			break;
    317   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_274x:
    318   1.1   mycroft 			type = AHC_274;
    319   1.1   mycroft 			break;
    320   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_284xB:
    321   1.1   mycroft 		case EISA_DEVICE_ID_ADAPTEC_284x:
    322   1.1   mycroft 			type = AHC_284;
    323   1.1   mycroft 			break;
    324   1.1   mycroft 		default:
    325   1.9  christos 			printf("aic7770_attach: Unknown device type!\n");
    326   1.1   mycroft 			return -1;
    327   1.1   mycroft 			break;
    328   1.1   mycroft 	}
    329   1.1   mycroft 
    330   1.1   mycroft 	if(!(ahc = ahc_alloc(unit, iospace->addr, type, AHC_FNONE)))
    331   1.1   mycroft 		return -1;
    332   1.1   mycroft 
    333   1.1   mycroft 	eisa_reg_start(e_dev);
    334   1.1   mycroft 	if(eisa_reg_iospace(e_dev, iospace)) {
    335   1.1   mycroft 		ahc_free(ahc);
    336   1.1   mycroft 		return -1;
    337   1.1   mycroft 	}
    338   1.1   mycroft 
    339   1.1   mycroft 	/*
    340   1.1   mycroft 	 * The IRQMS bit enables level sensitive interrupts. Only allow
    341   1.1   mycroft 	 * IRQ sharing if it's set.
    342   1.1   mycroft 	 */
    343   1.1   mycroft 	if(eisa_reg_intr(e_dev, irq, ahc_intr, (void *)ahc, &bio_imask,
    344   1.1   mycroft 			 /*shared ==*/ahc->pause & IRQMS)) {
    345   1.1   mycroft 		ahc_free(ahc);
    346   1.1   mycroft 		return -1;
    347   1.1   mycroft 	}
    348   1.1   mycroft 	eisa_reg_end(e_dev);
    349   1.1   mycroft 
    350   1.1   mycroft #elif defined(__NetBSD__)
    351   1.1   mycroft 
    352   1.1   mycroft 	struct ahc_data *ahc = (void *)self;
    353   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    354  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    355  1.10   thorpej 	bus_space_handle_t ioh;
    356   1.2   mycroft 	int irq;
    357   1.2   mycroft 	eisa_chipset_tag_t ec = ea->ea_ec;
    358   1.1   mycroft 	eisa_intr_handle_t ih;
    359   1.2   mycroft 	const char *model, *intrstr;
    360   1.1   mycroft 
    361  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    362  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
    363   1.1   mycroft 		panic("ahc_eisa_attach: could not map I/O addresses");
    364  1.10   thorpej 	if ((irq = ahc_eisa_irq(iot, ioh)) < 0)
    365   1.1   mycroft 		panic("ahc_eisa_attach: ahc_eisa_irq failed!");
    366   1.1   mycroft 
    367   1.1   mycroft 	if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
    368   1.1   mycroft 		model = EISA_PRODUCT_ADP7770;
    369   1.1   mycroft 		type = AHC_AIC7770;
    370   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
    371   1.1   mycroft 		model = EISA_PRODUCT_ADP7771;
    372   1.1   mycroft 		type = AHC_274;
    373   1.6      soda #if 0
    374   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7756") == 0) {
    375   1.1   mycroft 		model = EISA_PRODUCT_ADP7756;
    376   1.1   mycroft 		type = AHC_284;
    377   1.1   mycroft 	} else if (strcmp(ea->ea_idstring, "ADP7757") == 0) {
    378   1.1   mycroft 		model = EISA_PRODUCT_ADP7757;
    379   1.1   mycroft 		type = AHC_284;
    380   1.6      soda #endif
    381   1.1   mycroft 	} else {
    382   1.1   mycroft 		panic("ahc_eisa_attach: Unknown device type %s\n",
    383   1.1   mycroft 		      ea->ea_idstring);
    384   1.1   mycroft 	}
    385   1.9  christos 	printf(": %s\n", model);
    386   1.1   mycroft 
    387  1.10   thorpej 	ahc_construct(ahc, iot, ioh, type, AHC_FNONE);
    388   1.2   mycroft 	if (eisa_intr_map(ec, irq, &ih)) {
    389   1.9  christos 		printf("%s: couldn't map interrupt (%d)\n",
    390   1.8  christos 		    ahc->sc_dev.dv_xname, irq);
    391   1.1   mycroft 		return;
    392   1.1   mycroft 	}
    393   1.1   mycroft #endif /* defined(__NetBSD__) */
    394   1.1   mycroft 
    395   1.1   mycroft 	/*
    396   1.1   mycroft 	 * Tell the user what type of interrupts we're using.
    397   1.1   mycroft 	 * usefull for debugging irq problems
    398   1.1   mycroft 	 */
    399   1.1   mycroft 	if(bootverbose) {
    400   1.9  christos 		printf("%s: Using %s Interrupts\n",
    401   1.8  christos 		    ahc_name(ahc),
    402   1.8  christos 		    ahc->pause & IRQMS ?  "Level Sensitive" : "Edge Triggered");
    403   1.1   mycroft 	}
    404   1.1   mycroft 
    405   1.1   mycroft 	/*
    406   1.1   mycroft 	 * Now that we know we own the resources we need, do the
    407   1.1   mycroft 	 * card initialization.
    408   1.1   mycroft 	 *
    409   1.1   mycroft 	 * First, the aic7770 card specific setup.
    410   1.1   mycroft 	 */
    411   1.1   mycroft 	switch( ahc->type ) {
    412   1.1   mycroft 	    case AHC_AIC7770:
    413   1.1   mycroft 	    case AHC_274:
    414   1.1   mycroft 	    {
    415   1.1   mycroft 		u_char biosctrl = AHC_INB(ahc, HA_274_BIOSCTRL);
    416   1.1   mycroft 
    417   1.1   mycroft 		/* Get the primary channel information */
    418   1.1   mycroft 		ahc->flags |= (biosctrl & CHANNEL_B_PRIMARY);
    419   1.1   mycroft 
    420   1.1   mycroft 		if((biosctrl & BIOSMODE) == BIOSDISABLED)
    421   1.1   mycroft 			ahc->flags |= AHC_USEDEFAULTS;
    422   1.1   mycroft 		break;
    423   1.1   mycroft 	    }
    424   1.1   mycroft 	    case AHC_284:
    425   1.1   mycroft 	    {
    426   1.1   mycroft 		/* XXX
    427   1.1   mycroft 		 * All values are automagically intialized at
    428   1.1   mycroft 		 * POST for these cards, so we can always rely
    429   1.1   mycroft 		 * on the Scratch Ram values.  However, we should
    430   1.1   mycroft 		 * read the SEEPROM here (Dan has the code to do
    431   1.1   mycroft 		 * it) so we can say what kind of translation the
    432   1.1   mycroft 		 * BIOS is using.  Printing out the geometry could
    433   1.1   mycroft 		 * save a lot of users the grief of failed installs.
    434   1.1   mycroft 		 */
    435   1.1   mycroft 		break;
    436   1.1   mycroft 	    }
    437   1.1   mycroft 	    default:
    438   1.1   mycroft 		break;
    439   1.1   mycroft 	}
    440   1.1   mycroft 
    441   1.1   mycroft 	/*
    442   1.1   mycroft 	 * See if we have a Rev E or higher aic7770. Anything below a
    443   1.1   mycroft 	 * Rev E will have a R/O autoflush disable configuration bit.
    444   1.1   mycroft 	 * It's still not clear exactly what is differenent about the Rev E.
    445   1.1   mycroft 	 * We think it allows 8 bit entries in the QOUTFIFO to support
    446   1.1   mycroft 	 * "paging" SCBs so you can have more than 4 commands active at
    447   1.1   mycroft 	 * once.
    448   1.1   mycroft 	 */
    449   1.1   mycroft 	{
    450   1.1   mycroft 		char *id_string;
    451   1.1   mycroft 		u_char sblkctl;
    452   1.1   mycroft 		u_char sblkctl_orig;
    453   1.1   mycroft 
    454   1.1   mycroft 		sblkctl_orig = AHC_INB(ahc, SBLKCTL);
    455   1.1   mycroft 		sblkctl = sblkctl_orig ^ AUTOFLUSHDIS;
    456   1.1   mycroft 		AHC_OUTB(ahc, SBLKCTL, sblkctl);
    457   1.1   mycroft 		sblkctl = AHC_INB(ahc, SBLKCTL);
    458   1.1   mycroft 		if(sblkctl != sblkctl_orig)
    459   1.1   mycroft 		{
    460   1.1   mycroft 			id_string = "aic7770 >= Rev E, ";
    461   1.1   mycroft 			/*
    462   1.1   mycroft 			 * Ensure autoflush is enabled
    463   1.1   mycroft 			 */
    464   1.1   mycroft 			sblkctl &= ~AUTOFLUSHDIS;
    465   1.1   mycroft 			AHC_OUTB(ahc, SBLKCTL, sblkctl);
    466   1.1   mycroft 
    467   1.1   mycroft 			/* Allow paging on this adapter */
    468   1.1   mycroft 			ahc->flags |= AHC_PAGESCBS;
    469   1.1   mycroft 		}
    470   1.1   mycroft 		else
    471   1.1   mycroft 			id_string = "aic7770 <= Rev C, ";
    472   1.1   mycroft 
    473   1.9  christos 		printf("%s: %s", ahc_name(ahc), id_string);
    474   1.1   mycroft 	}
    475   1.1   mycroft 
    476   1.1   mycroft 	/* Setup the FIFO threshold and the bus off time */
    477   1.1   mycroft 	{
    478   1.1   mycroft 		u_char hostconf = AHC_INB(ahc, HOSTCONF);
    479   1.1   mycroft 		AHC_OUTB(ahc, BUSSPD, hostconf & DFTHRSH);
    480   1.1   mycroft 		AHC_OUTB(ahc, BUSTIME, (hostconf << 2) & BOFF);
    481   1.1   mycroft 	}
    482   1.1   mycroft 
    483   1.1   mycroft 	/*
    484   1.1   mycroft 	 * Generic aic7xxx initialization.
    485   1.1   mycroft 	 */
    486   1.1   mycroft 	if(ahc_init(ahc)){
    487   1.1   mycroft #if defined(__FreeBSD__)
    488   1.1   mycroft 		ahc_free(ahc);
    489   1.1   mycroft 		/*
    490   1.1   mycroft 		 * The board's IRQ line is not yet enabled so it's safe
    491   1.1   mycroft 		 * to release the irq.
    492   1.1   mycroft 		 */
    493   1.1   mycroft 		eisa_release_intr(e_dev, irq, ahc_intr);
    494   1.1   mycroft 		return -1;
    495   1.1   mycroft #elif defined(__NetBSD__)
    496   1.1   mycroft 		ahc_free(ahc);
    497   1.1   mycroft 		return;
    498   1.1   mycroft #endif
    499   1.1   mycroft 	}
    500   1.1   mycroft 
    501   1.1   mycroft 	/*
    502   1.1   mycroft 	 * Enable the board's BUS drivers
    503   1.1   mycroft 	 */
    504   1.1   mycroft 	AHC_OUTB(ahc, BCTL, ENABLE);
    505   1.1   mycroft 
    506   1.1   mycroft #if defined(__FreeBSD__)
    507   1.1   mycroft 	/*
    508   1.1   mycroft 	 * Enable our interrupt handler.
    509   1.1   mycroft 	 */
    510   1.1   mycroft 	if(eisa_enable_intr(e_dev, irq)) {
    511   1.1   mycroft 		ahc_free(ahc);
    512   1.1   mycroft 		eisa_release_intr(e_dev, irq, ahc_intr);
    513   1.1   mycroft 		return -1;
    514   1.1   mycroft 	}
    515   1.1   mycroft 
    516   1.1   mycroft 	e_dev->kdc->kdc_state = DC_BUSY; /* host adapters always busy */
    517   1.1   mycroft #elif defined(__NetBSD__)
    518   1.2   mycroft 	intrstr = eisa_intr_string(ec, ih);
    519   1.1   mycroft 	/*
    520   1.1   mycroft 	 * The IRQMS bit enables level sensitive interrupts only allow
    521   1.1   mycroft 	 * IRQ sharing if its set.
    522   1.1   mycroft 	 */
    523   1.2   mycroft 	ahc->sc_ih = eisa_intr_establish(ec, ih,
    524  1.11       cgd 	    ahc->pause & IRQMS ? IST_LEVEL : IST_EDGE, IPL_BIO, ahc_intr, ahc);
    525   1.1   mycroft 	if (ahc->sc_ih == NULL) {
    526   1.9  christos 		printf("%s: couldn't establish interrupt",
    527   1.8  christos 		    ahc->sc_dev.dv_xname);
    528   1.1   mycroft 		if (intrstr != NULL)
    529   1.9  christos 			printf(" at %s", intrstr);
    530   1.9  christos 		printf("\n");
    531   1.1   mycroft 		ahc_free(ahc);
    532   1.1   mycroft 		return;
    533   1.1   mycroft 	}
    534   1.1   mycroft 	if (intrstr != NULL)
    535   1.9  christos 		printf("%s: interrupting at %s\n", ahc->sc_dev.dv_xname,
    536   1.1   mycroft 		       intrstr);
    537   1.1   mycroft #endif /* defined(__NetBSD__) */
    538   1.1   mycroft 
    539   1.1   mycroft 	/* Attach sub-devices - always succeeds */
    540   1.1   mycroft 	ahc_attach(ahc);
    541   1.1   mycroft 
    542   1.1   mycroft #if defined(__FreeBSD__)
    543   1.1   mycroft 	return 0;
    544   1.1   mycroft #endif
    545   1.1   mycroft }
    546   1.1   mycroft 
    547   1.1   mycroft #endif /* NEISA > 0 */
    548