Home | History | Annotate | Line # | Download | only in isa
ahc_isa.c revision 1.23.2.3
      1  1.23.2.3     skrll /*	$NetBSD: ahc_isa.c,v 1.23.2.3 2004/09/21 13:16:57 skrll Exp $	*/
      2       1.8   thorpej 
      3       1.8   thorpej /*
      4       1.8   thorpej  * Product specific probe and attach routines for:
      5      1.13      fvdl  * 	AHA-284X VL-bus SCSI controllers
      6       1.8   thorpej  *
      7      1.13      fvdl  * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
      8       1.8   thorpej  * All rights reserved.
      9       1.8   thorpej  *
     10       1.8   thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.8   thorpej  * modification, are permitted provided that the following conditions
     12       1.8   thorpej  * are met:
     13       1.8   thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.8   thorpej  *    notice immediately at the beginning of the file, without modification,
     15       1.8   thorpej  *    this list of conditions, and the following disclaimer.
     16      1.13      fvdl  * 2. The name of the author may not be used to endorse or promote products
     17       1.8   thorpej  *    derived from this software without specific prior written permission.
     18       1.8   thorpej  *
     19       1.8   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     20       1.8   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.8   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.8   thorpej  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     23       1.8   thorpej  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.8   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.8   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.8   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.8   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.8   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.8   thorpej  * SUCH DAMAGE.
     30      1.13      fvdl  *
     31      1.13      fvdl  * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
     32       1.8   thorpej  */
     33       1.7   thorpej 
     34       1.7   thorpej /*-
     35       1.7   thorpej  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
     36       1.7   thorpej  * All rights reserved.
     37       1.7   thorpej  *
     38       1.7   thorpej  * This code is derived from software contributed to The NetBSD Foundation
     39       1.7   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     40       1.7   thorpej  * NASA Ames Research Center.
     41       1.7   thorpej  *
     42       1.7   thorpej  * Redistribution and use in source and binary forms, with or without
     43       1.7   thorpej  * modification, are permitted provided that the following conditions
     44       1.7   thorpej  * are met:
     45       1.7   thorpej  * 1. Redistributions of source code must retain the above copyright
     46       1.7   thorpej  *    notice, this list of conditions and the following disclaimer.
     47       1.7   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     48       1.7   thorpej  *    notice, this list of conditions and the following disclaimer in the
     49       1.7   thorpej  *    documentation and/or other materials provided with the distribution.
     50       1.7   thorpej  * 3. All advertising materials mentioning features or use of this software
     51       1.7   thorpej  *    must display the following acknowledgement:
     52       1.7   thorpej  *	This product includes software developed by the NetBSD
     53       1.7   thorpej  *	Foundation, Inc. and its contributors.
     54       1.7   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     55       1.7   thorpej  *    contributors may be used to endorse or promote products derived
     56       1.7   thorpej  *    from this software without specific prior written permission.
     57       1.7   thorpej  *
     58       1.7   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     59       1.7   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     60       1.7   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     61       1.7   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     62       1.7   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     63       1.7   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     64       1.7   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     65       1.7   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     66       1.7   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     67       1.7   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     68       1.7   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     69       1.7   thorpej  */
     70       1.1      soda 
     71       1.1      soda /*
     72       1.8   thorpej  * Copyright (c) 1995, 1996 Christopher G. Demetriou
     73       1.1      soda  * All rights reserved.
     74       1.1      soda  *
     75       1.1      soda  * Redistribution and use in source and binary forms, with or without
     76       1.1      soda  * modification, are permitted provided that the following conditions
     77       1.1      soda  * are met:
     78       1.1      soda  * 1. Redistributions of source code must retain the above copyright
     79       1.8   thorpej  *    notice, this list of conditions and the following disclaimer.
     80       1.1      soda  * 2. Redistributions in binary form must reproduce the above copyright
     81       1.1      soda  *    notice, this list of conditions and the following disclaimer in the
     82       1.1      soda  *    documentation and/or other materials provided with the distribution.
     83       1.1      soda  * 3. All advertising materials mentioning features or use of this software
     84       1.1      soda  *    must display the following acknowledgement:
     85       1.8   thorpej  *      This product includes software developed by Christopher G. Demetriou
     86       1.8   thorpej  *      for the NetBSD Project.
     87       1.1      soda  * 4. The name of the author may not be used to endorse or promote products
     88       1.8   thorpej  *    derived from this software without specific prior written permission
     89       1.1      soda  *
     90       1.8   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     91       1.8   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     92       1.8   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     93       1.8   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     94       1.8   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     95       1.8   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     96       1.8   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     97       1.8   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     98       1.8   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     99       1.8   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    100       1.1      soda  */
    101       1.1      soda 
    102       1.1      soda /*
    103       1.1      soda  * This front-end driver is really sort of a hack.  The AHA-284X likes
    104       1.1      soda  * to masquerade as an EISA device.  However, on VLbus machines with
    105       1.1      soda  * no EISA signature in the BIOS, the EISA bus will never be scanned.
    106       1.1      soda  * This is intended to catch the 284X controllers on those systems
    107       1.1      soda  * by looking in "EISA i/o space" for 284X controllers.
    108       1.1      soda  *
    109       1.1      soda  * This relies heavily on i/o port accounting.  We also just use the
    110       1.1      soda  * EISA macros for everything ... it's a real waste to redefine them.
    111       1.1      soda  *
    112       1.1      soda  * Note: there isn't any #ifdef for FreeBSD in this file, since the
    113       1.1      soda  * FreeBSD EISA driver handles all cases of the 284X.
    114       1.1      soda  *
    115  1.23.2.1     skrll  *	-- Jason R. Thorpe <thorpej (at) NetBSD.org>
    116       1.1      soda  *	   July 12, 1996
    117       1.1      soda  */
    118      1.15     lukem 
    119      1.15     lukem #include <sys/cdefs.h>
    120  1.23.2.3     skrll __KERNEL_RCSID(0, "$NetBSD: ahc_isa.c,v 1.23.2.3 2004/09/21 13:16:57 skrll Exp $");
    121       1.1      soda 
    122       1.1      soda #include <sys/param.h>
    123       1.1      soda #include <sys/systm.h>
    124       1.1      soda #include <sys/kernel.h>
    125       1.1      soda #include <sys/device.h>
    126       1.1      soda #include <sys/queue.h>
    127       1.1      soda #include <sys/malloc.h>
    128      1.14  jdolecek #include <sys/reboot.h>
    129       1.1      soda 
    130       1.1      soda #include <machine/bus.h>
    131       1.1      soda #include <machine/intr.h>
    132       1.1      soda 
    133       1.6    bouyer #include <dev/scsipi/scsi_all.h>
    134       1.6    bouyer #include <dev/scsipi/scsipi_all.h>
    135       1.6    bouyer #include <dev/scsipi/scsiconf.h>
    136       1.1      soda 
    137       1.1      soda #include <dev/isa/isavar.h>
    138       1.1      soda 
    139       1.1      soda #include <dev/eisa/eisareg.h>
    140       1.1      soda #include <dev/eisa/eisavar.h>
    141       1.1      soda #include <dev/eisa/eisadevs.h>
    142       1.1      soda 
    143      1.20      fvdl #include <dev/ic/aic7xxx_osm.h>
    144      1.20      fvdl #include <dev/ic/aic7xxx_inline.h>
    145      1.13      fvdl #include <dev/ic/aic77xxreg.h>
    146      1.13      fvdl #include <dev/ic/aic77xxvar.h>
    147      1.13      fvdl #include <dev/ic/smc93cx6var.h>
    148       1.1      soda 
    149       1.1      soda /* IO port address setting range as EISA slot number */
    150       1.1      soda #define AHC_ISA_MIN_SLOT	0x1	/* from iobase = 0x1c00 */
    151       1.1      soda #define AHC_ISA_MAX_SLOT	0xe	/* to   iobase = 0xec00 */
    152       1.1      soda 
    153      1.13      fvdl #define AHC_ISA_SLOT_OFFSET	AHC_EISA_SLOT_OFFSET
    154      1.13      fvdl #define AHC_ISA_IOSIZE		AHC_EISA_IOSIZE
    155       1.1      soda 
    156       1.1      soda /*
    157       1.1      soda  * I/O port offsets
    158       1.1      soda  */
    159       1.1      soda #define	AHC_ISA_VID		(EISA_SLOTOFF_VID - AHC_ISA_SLOT_OFFSET)
    160       1.1      soda #define	AHC_ISA_PID		(EISA_SLOTOFF_PID - AHC_ISA_SLOT_OFFSET)
    161       1.1      soda #define	AHC_ISA_PRIMING		AHC_ISA_VID	/* enable vendor/product ID */
    162       1.1      soda 
    163       1.1      soda /*
    164       1.1      soda  * AHC_ISA_PRIMING register values (write)
    165       1.1      soda  */
    166       1.1      soda #define	AHC_ISA_PRIMING_VID(index)	(AHC_ISA_VID + (index))
    167       1.1      soda #define	AHC_ISA_PRIMING_PID(index)	(AHC_ISA_PID + (index))
    168       1.1      soda 
    169       1.5   thorpej int	ahc_isa_idstring __P((bus_space_tag_t, bus_space_handle_t, char *));
    170       1.5   thorpej int	ahc_isa_match __P((struct isa_attach_args *, bus_addr_t));
    171       1.1      soda 
    172      1.12  drochner int	ahc_isa_probe __P((struct device *, struct cfdata *, void *));
    173       1.1      soda void	ahc_isa_attach __P((struct device *, struct device *, void *));
    174      1.13      fvdl void	aha2840_load_seeprom __P((struct ahc_softc *ahc));
    175      1.20      fvdl static int verify_seeprom_cksum(struct seeprom_config *sc);
    176       1.1      soda 
    177      1.19   thorpej CFATTACH_DECL(ahc_isa, sizeof(struct ahc_softc),
    178      1.19   thorpej     ahc_isa_probe, ahc_isa_attach, NULL, NULL);
    179       1.1      soda 
    180       1.1      soda /*
    181       1.1      soda  * This keeps track of which slots are to be checked next if the
    182       1.1      soda  * iobase locator is a wildcard.  A simple static variable isn't enough,
    183       1.1      soda  * since it's conceivable that a system might have more than one ISA
    184       1.1      soda  * bus.
    185       1.1      soda  *
    186       1.1      soda  * The "bus" member is the unit number of the parent ISA bus, e.g. "0"
    187       1.1      soda  * for "isa0".
    188       1.1      soda  */
    189       1.1      soda struct ahc_isa_slot {
    190       1.1      soda 	LIST_ENTRY(ahc_isa_slot)	link;
    191       1.1      soda 	int				bus;
    192       1.1      soda 	int				slot;
    193       1.1      soda };
    194       1.1      soda static LIST_HEAD(, ahc_isa_slot) ahc_isa_all_slots;
    195       1.1      soda static int ahc_isa_slot_initialized;
    196       1.1      soda 
    197       1.1      soda int
    198       1.5   thorpej ahc_isa_idstring(iot, ioh, idstring)
    199       1.5   thorpej 	bus_space_tag_t iot;
    200       1.5   thorpej 	bus_space_handle_t ioh;
    201       1.1      soda 	char *idstring;
    202       1.1      soda {
    203       1.1      soda 	u_int8_t vid[EISA_NVIDREGS], pid[EISA_NPIDREGS];
    204       1.1      soda 	int i;
    205       1.1      soda 
    206       1.1      soda 	/* Get the vendor ID bytes */
    207       1.1      soda 	for (i = 0; i < EISA_NVIDREGS; i++) {
    208       1.5   thorpej 		bus_space_write_1(iot, ioh, AHC_ISA_PRIMING,
    209       1.1      soda 		    AHC_ISA_PRIMING_VID(i));
    210       1.5   thorpej 		vid[i] = bus_space_read_1(iot, ioh, AHC_ISA_VID + i);
    211       1.1      soda 	}
    212       1.1      soda 
    213       1.1      soda 	/* Check for device existence */
    214       1.1      soda 	if (EISA_VENDID_NODEV(vid)) {
    215       1.1      soda #if 0
    216       1.4  christos 		printf("ahc_isa_idstring: no device at 0x%lx\n",
    217       1.1      soda 		    ioh); /* XXX knows about ioh guts */
    218       1.4  christos 		printf("\t(0x%x, 0x%x)\n", vid[0], vid[1]);
    219       1.1      soda #endif
    220       1.1      soda 		return (0);
    221       1.1      soda 	}
    222       1.1      soda 
    223       1.1      soda 	/* And check that the firmware didn't biff something badly */
    224       1.1      soda 	if (EISA_VENDID_IDDELAY(vid)) {
    225       1.4  christos 		printf("ahc_isa_idstring: BIOS biffed it at 0x%lx\n",
    226       1.1      soda 		    ioh);	/* XXX knows about ioh guts */
    227       1.1      soda 		return (0);
    228       1.1      soda 	}
    229       1.1      soda 
    230       1.1      soda 	/* Get the product ID bytes */
    231       1.1      soda 	for (i = 0; i < EISA_NPIDREGS; i++) {
    232       1.5   thorpej 		bus_space_write_1(iot, ioh, AHC_ISA_PRIMING,
    233       1.1      soda 		    AHC_ISA_PRIMING_PID(i));
    234       1.5   thorpej 		pid[i] = bus_space_read_1(iot, ioh, AHC_ISA_PID + i);
    235       1.1      soda 	}
    236       1.1      soda 
    237       1.1      soda 	/* Create the ID string from the vendor and product IDs */
    238       1.1      soda 	idstring[0] = EISA_VENDID_0(vid);
    239       1.1      soda 	idstring[1] = EISA_VENDID_1(vid);
    240       1.1      soda 	idstring[2] = EISA_VENDID_2(vid);
    241       1.1      soda 	idstring[3] = EISA_PRODID_0(pid);
    242       1.1      soda 	idstring[4] = EISA_PRODID_1(pid);
    243       1.1      soda 	idstring[5] = EISA_PRODID_2(pid);
    244       1.1      soda 	idstring[6] = EISA_PRODID_3(pid);
    245       1.1      soda 	idstring[7] = '\0';		/* sanity */
    246       1.1      soda 
    247       1.1      soda 	return (1);
    248       1.1      soda }
    249       1.1      soda 
    250       1.1      soda int
    251       1.1      soda ahc_isa_match(ia, iobase)
    252       1.1      soda 	struct isa_attach_args *ia;
    253       1.5   thorpej 	bus_addr_t iobase;
    254       1.1      soda {
    255       1.5   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    256       1.5   thorpej 	bus_space_handle_t ioh;
    257       1.1      soda 	int irq;
    258       1.1      soda 	char idstring[EISA_IDSTRINGLEN];
    259       1.1      soda 
    260       1.1      soda 	/*
    261       1.1      soda 	 * Get a mapping for the while slot-specific address
    262       1.1      soda 	 * space.  If we can't, assume nothing's there, but
    263       1.1      soda 	 * warn about it.
    264       1.1      soda 	 */
    265       1.5   thorpej 	if (bus_space_map(iot, iobase, AHC_ISA_IOSIZE, 0, &ioh)) {
    266       1.1      soda #if 0
    267       1.1      soda 		/*
    268       1.1      soda 		 * Don't print anything out here, since this could
    269       1.1      soda 		 * be common on machines configured to look for
    270       1.1      soda 		 * ahc_eisa and ahc_isa.
    271       1.1      soda 		 */
    272       1.4  christos 		printf("ahc_isa_match: can't map I/O space for 0x%x\n",
    273       1.1      soda 		    iobase);
    274       1.1      soda #endif
    275       1.1      soda 		return (0);
    276       1.1      soda 	}
    277       1.1      soda 
    278       1.5   thorpej 	if (!ahc_isa_idstring(iot, ioh, idstring))
    279       1.1      soda 		irq = -1;	/* cannot get the ID string */
    280       1.1      soda 	else if (strcmp(idstring, "ADP7756") &&
    281       1.1      soda 	    strcmp(idstring, "ADP7757"))
    282       1.1      soda 		irq = -1;	/* unknown ID strings */
    283       1.1      soda 	else
    284      1.13      fvdl 		irq = ahc_aic77xx_irq(iot, ioh);
    285       1.1      soda 
    286       1.5   thorpej 	bus_space_unmap(iot, ioh, AHC_ISA_IOSIZE);
    287       1.1      soda 
    288       1.1      soda 	if (irq < 0)
    289       1.1      soda 		return (0);
    290       1.1      soda 
    291  1.23.2.2     skrll 	if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
    292      1.16   thorpej 	    ia->ia_irq[0].ir_irq != irq) {
    293       1.4  christos 		printf("ahc_isa_match: irq mismatch (kernel %d, card %d)\n",
    294      1.16   thorpej 		    ia->ia_irq[0].ir_irq, irq);
    295       1.1      soda 		return (0);
    296       1.1      soda 	}
    297       1.1      soda 
    298       1.1      soda 	/* We have a match */
    299      1.16   thorpej 	ia->ia_nio = 1;
    300      1.16   thorpej 	ia->ia_io[0].ir_addr = iobase;
    301      1.16   thorpej 	ia->ia_io[0].ir_size = AHC_ISA_IOSIZE;
    302      1.16   thorpej 
    303      1.16   thorpej 	ia->ia_nirq = 1;
    304      1.16   thorpej 	ia->ia_irq[0].ir_irq = irq;
    305      1.16   thorpej 
    306      1.16   thorpej 	ia->ia_ndrq = 0;
    307      1.16   thorpej 	ia->ia_niomem = 0;
    308      1.16   thorpej 
    309       1.1      soda 	return (1);
    310       1.1      soda }
    311       1.1      soda 
    312       1.1      soda /*
    313       1.1      soda  * Check the slots looking for a board we recognise
    314       1.1      soda  * If we find one, note it's address (slot) and call
    315       1.1      soda  * the actual probe routine to check it out.
    316       1.1      soda  */
    317       1.1      soda int
    318       1.1      soda ahc_isa_probe(parent, match, aux)
    319       1.1      soda         struct device *parent;
    320      1.12  drochner         struct cfdata *match;
    321      1.12  drochner 	void *aux;
    322       1.1      soda {
    323       1.1      soda 	struct isa_attach_args *ia = aux;
    324       1.1      soda 	struct ahc_isa_slot *as;
    325       1.1      soda 
    326       1.1      soda 	if (ahc_isa_slot_initialized == 0) {
    327       1.1      soda 		LIST_INIT(&ahc_isa_all_slots);
    328       1.1      soda 		ahc_isa_slot_initialized = 1;
    329       1.1      soda 	}
    330       1.1      soda 
    331      1.16   thorpej 	if (ia->ia_nio < 1)
    332      1.16   thorpej 		return (0);
    333      1.16   thorpej 	if (ia->ia_nirq < 1)
    334      1.16   thorpej 		return (0);
    335      1.16   thorpej 
    336      1.16   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    337      1.16   thorpej 		return (0);
    338      1.16   thorpej 
    339  1.23.2.2     skrll 	if (ia->ia_io[0].ir_addr != ISA_UNKNOWN_PORT)
    340      1.16   thorpej 		return (ahc_isa_match(ia, ia->ia_io[0].ir_addr));
    341       1.1      soda 
    342       1.1      soda 	/*
    343       1.1      soda 	 * Find this bus's state.  If we don't yet have a slot
    344       1.1      soda 	 * marker, allocate and initialize one.
    345       1.1      soda 	 */
    346       1.1      soda 	for (as = ahc_isa_all_slots.lh_first; as != NULL;
    347       1.1      soda 	    as = as->link.le_next)
    348       1.1      soda 		if (as->bus == parent->dv_unit)
    349       1.1      soda 			goto found_slot_marker;
    350       1.1      soda 
    351       1.1      soda 	/*
    352       1.1      soda 	 * Don't have one, so make one.
    353       1.1      soda 	 */
    354       1.1      soda 	as = (struct ahc_isa_slot *)
    355       1.1      soda 	    malloc(sizeof(struct ahc_isa_slot), M_DEVBUF, M_NOWAIT);
    356       1.1      soda 	if (as == NULL)
    357       1.1      soda 		panic("ahc_isa_probe: can't allocate slot marker");
    358       1.1      soda 
    359       1.1      soda 	as->bus = parent->dv_unit;
    360       1.1      soda 	as->slot = AHC_ISA_MIN_SLOT;
    361       1.1      soda 	LIST_INSERT_HEAD(&ahc_isa_all_slots, as, link);
    362       1.1      soda 
    363       1.1      soda  found_slot_marker:
    364       1.1      soda 
    365       1.1      soda 	for (; as->slot <= AHC_ISA_MAX_SLOT; as->slot++) {
    366       1.1      soda 		if (ahc_isa_match(ia, EISA_SLOT_ADDR(as->slot) +
    367       1.1      soda 		    AHC_ISA_SLOT_OFFSET)) {
    368       1.1      soda 			as->slot++; /* next slot to search */
    369       1.1      soda 			return (1);
    370       1.1      soda 		}
    371       1.1      soda 	}
    372       1.1      soda 
    373       1.1      soda 	/* No matching cards were found. */
    374       1.1      soda 	return (0);
    375       1.1      soda }
    376       1.1      soda 
    377       1.1      soda void
    378       1.1      soda ahc_isa_attach(parent, self, aux)
    379       1.1      soda 	struct device *parent, *self;
    380       1.1      soda 	void *aux;
    381       1.1      soda {
    382      1.13      fvdl 	struct ahc_softc *ahc = (void *)self;
    383       1.1      soda 	struct isa_attach_args *ia = aux;
    384       1.5   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    385       1.5   thorpej 	bus_space_handle_t ioh;
    386      1.13      fvdl 	int irq, intrtype;
    387      1.13      fvdl 	const char *intrtypestr;
    388       1.1      soda 	char idstring[EISA_IDSTRINGLEN];
    389      1.20      fvdl 	u_char intdef;
    390       1.1      soda 
    391      1.16   thorpej 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, ia->ia_io[0].ir_size,
    392      1.16   thorpej 	    0, &ioh)) {
    393       1.9   thorpej 		printf(": can't map i/o space\n");
    394       1.9   thorpej 		return;
    395       1.9   thorpej 	}
    396       1.9   thorpej 	if (!ahc_isa_idstring(iot, ioh, idstring)) {
    397       1.9   thorpej 		printf(": can't read ID string\n");
    398      1.13      fvdl 		goto free_io;
    399       1.9   thorpej 	}
    400      1.13      fvdl 	if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0) {
    401      1.13      fvdl 		printf(": ahc_aic77xx_irq failed\n");
    402      1.13      fvdl 		goto free_io;
    403       1.9   thorpej 	}
    404       1.1      soda 
    405       1.1      soda 	if (strcmp(idstring, "ADP7756") == 0) {
    406      1.13      fvdl 		printf(": %s\n", EISA_PRODUCT_ADP7756);
    407       1.1      soda 	} else if (strcmp(idstring, "ADP7757") == 0) {
    408      1.13      fvdl 		printf(": %s\n", EISA_PRODUCT_ADP7757);
    409       1.1      soda 	} else {
    410       1.9   thorpej 		printf(": unknown device type %s\n", idstring);
    411      1.13      fvdl 		goto free_io;
    412       1.1      soda 	}
    413       1.1      soda 
    414      1.11       leo 	/*
    415      1.23       wiz 	 * Tell the bus-DMA interface that we can do 32bit DMA
    416      1.13      fvdl 	 * NOTE: this variable is first referenced in ahc_init().
    417      1.11       leo 	 */
    418      1.11       leo 	ahc->sc_dmaflags = ISABUS_DMA_32BIT;
    419       1.1      soda 
    420      1.22      fvdl 	ahc_set_name(ahc, ahc->sc_dev.dv_xname);
    421      1.22      fvdl 	ahc->parent_dmat = ia->ia_dmat;
    422      1.13      fvdl 	ahc->channel = 'A';
    423      1.20      fvdl 	ahc->chip =  AHC_AIC7770|AHC_VL;
    424      1.20      fvdl 	ahc->features = AHC_AIC7770_FE;
    425      1.20      fvdl 	ahc->bugs |= AHC_TMODE_WIDEODD_BUG;
    426      1.20      fvdl 	ahc->flags |= AHC_PAGESCBS;
    427      1.20      fvdl 	ahc->tag = iot;
    428      1.20      fvdl 	ahc->bsh = ioh;
    429      1.21      fvdl 
    430      1.21      fvdl 	if (ahc_softc_init(ahc) != 0)
    431      1.21      fvdl 		goto free_io;
    432      1.20      fvdl 
    433      1.20      fvdl 	ahc_intr_enable(ahc, FALSE);
    434      1.20      fvdl 
    435      1.13      fvdl 	if (ahc_reset(ahc) != 0)
    436      1.20      fvdl 		goto free_io;
    437      1.20      fvdl 
    438      1.20      fvdl 	intdef = bus_space_read_1(iot, ioh, INTDEF);
    439      1.13      fvdl 
    440      1.20      fvdl 	if (intdef & EDGE_TRIG) {
    441      1.20      fvdl 		intrtype = IST_EDGE;
    442      1.20      fvdl 		intrtypestr = "edge triggered";
    443      1.20      fvdl 	} else {
    444      1.13      fvdl 		intrtype = IST_LEVEL;
    445      1.13      fvdl 		intrtypestr = "level sensitive";
    446      1.13      fvdl 	}
    447      1.13      fvdl 	ahc->ih = isa_intr_establish(ia->ia_ic, irq,
    448      1.13      fvdl 	    intrtype, IPL_BIO, ahc_intr, ahc);
    449      1.13      fvdl 	if (ahc->ih == NULL) {
    450      1.13      fvdl 		printf("%s: couldn't establish %s interrupt\n",
    451      1.13      fvdl 		       ahc->sc_dev.dv_xname, intrtypestr);
    452      1.20      fvdl 		goto free_io;
    453      1.13      fvdl 	}
    454      1.13      fvdl 
    455       1.1      soda 	/*
    456       1.1      soda 	 * Tell the user what type of interrupts we're using.
    457       1.1      soda 	 * usefull for debugging irq problems
    458       1.1      soda 	 */
    459      1.13      fvdl 	if (bootverbose) {
    460      1.13      fvdl 		printf("%s: Using %s interrupts\n",
    461      1.13      fvdl 		       ahc->sc_dev.dv_xname, intrtypestr);
    462      1.13      fvdl 	}
    463       1.1      soda 
    464       1.1      soda 	/*
    465       1.1      soda 	 * Now that we know we own the resources we need, do the
    466       1.1      soda 	 * card initialization.
    467       1.1      soda 	 */
    468      1.13      fvdl 	aha2840_load_seeprom(ahc);
    469       1.1      soda 
    470      1.13      fvdl 	/* Attach sub-devices */
    471      1.13      fvdl 	if (ahc_aic77xx_attach(ahc) == 0)
    472      1.13      fvdl 		return; /* succeed */
    473      1.13      fvdl 
    474      1.13      fvdl 	/* failed */
    475      1.13      fvdl 	isa_intr_disestablish(ia->ia_ic, ahc->ih);
    476      1.13      fvdl free_io:
    477      1.16   thorpej 	bus_space_unmap(iot, ioh, ia->ia_io[0].ir_size);
    478      1.13      fvdl }
    479       1.1      soda 
    480      1.13      fvdl /*
    481      1.13      fvdl  * Read the 284x SEEPROM.
    482      1.13      fvdl  */
    483      1.13      fvdl void
    484      1.13      fvdl aha2840_load_seeprom(struct ahc_softc *ahc)
    485      1.13      fvdl {
    486      1.13      fvdl 	struct	  seeprom_descriptor sd;
    487      1.13      fvdl 	struct	  seeprom_config sc;
    488      1.13      fvdl 	u_int8_t  scsi_conf;
    489      1.13      fvdl 	int	  have_seeprom;
    490      1.13      fvdl 
    491      1.13      fvdl 	sd.sd_tag = ahc->tag;
    492      1.13      fvdl 	sd.sd_bsh = ahc->bsh;
    493      1.13      fvdl 	sd.sd_control_offset = SEECTL_2840;
    494      1.13      fvdl 	sd.sd_status_offset = STATUS_2840;
    495      1.13      fvdl 	sd.sd_dataout_offset = STATUS_2840;
    496      1.13      fvdl 	sd.sd_chip = C46;
    497      1.13      fvdl 	sd.sd_MS = 0;
    498      1.13      fvdl 	sd.sd_RDY = EEPROM_TF;
    499      1.13      fvdl 	sd.sd_CS = CS_2840;
    500      1.13      fvdl 	sd.sd_CK = CK_2840;
    501      1.13      fvdl 	sd.sd_DO = DO_2840;
    502      1.13      fvdl 	sd.sd_DI = DI_2840;
    503      1.13      fvdl 
    504      1.13      fvdl 	if (bootverbose)
    505      1.13      fvdl 		printf("%s: Reading SEEPROM...", ahc_name(ahc));
    506      1.20      fvdl 	have_seeprom = read_seeprom(&sd, (u_int16_t *)&sc,
    507      1.20      fvdl 				    /*start_addr*/0, sizeof(sc)/2);
    508      1.13      fvdl 
    509      1.13      fvdl 	if (have_seeprom) {
    510      1.20      fvdl 		if (verify_seeprom_cksum(&sc) == 0) {
    511      1.13      fvdl 			if(bootverbose)
    512      1.13      fvdl 				printf ("checksum error\n");
    513      1.13      fvdl 			have_seeprom = 0;
    514      1.13      fvdl 		} else if (bootverbose) {
    515      1.13      fvdl 			printf("done.\n");
    516       1.1      soda 		}
    517       1.1      soda 	}
    518       1.1      soda 
    519      1.13      fvdl 	if (!have_seeprom) {
    520      1.13      fvdl 		if (bootverbose)
    521      1.13      fvdl 			printf("%s: No SEEPROM available\n", ahc_name(ahc));
    522      1.13      fvdl 		ahc->flags |= AHC_USEDEFAULTS;
    523      1.13      fvdl 	} else {
    524      1.13      fvdl 		/*
    525      1.13      fvdl 		 * Put the data we've collected down into SRAM
    526      1.13      fvdl 		 * where ahc_init will find it.
    527      1.13      fvdl 		 */
    528      1.13      fvdl 		int i;
    529      1.13      fvdl 		int max_targ = (ahc->features & AHC_WIDE) != 0 ? 16 : 8;
    530      1.13      fvdl 		u_int16_t discenable;
    531      1.13      fvdl 
    532      1.13      fvdl 		discenable = 0;
    533      1.13      fvdl 		for (i = 0; i < max_targ; i++){
    534      1.13      fvdl 	                u_int8_t target_settings;
    535      1.13      fvdl 			target_settings = (sc.device_flags[i] & CFXFER) << 4;
    536      1.13      fvdl 			if (sc.device_flags[i] & CFSYNCH)
    537      1.13      fvdl 				target_settings |= SOFS;
    538      1.13      fvdl 			if (sc.device_flags[i] & CFWIDEB)
    539      1.13      fvdl 				target_settings |= WIDEXFER;
    540      1.13      fvdl 			if (sc.device_flags[i] & CFDISC)
    541      1.13      fvdl 				discenable |= (0x01 << i);
    542      1.13      fvdl 			ahc_outb(ahc, TARG_SCSIRATE + i, target_settings);
    543      1.13      fvdl 		}
    544      1.13      fvdl 		ahc_outb(ahc, DISC_DSB, ~(discenable & 0xff));
    545      1.13      fvdl 		ahc_outb(ahc, DISC_DSB + 1, ~((discenable >> 8) & 0xff));
    546       1.1      soda 
    547      1.13      fvdl 		ahc->our_id = sc.brtime_id & CFSCSIID;
    548       1.1      soda 
    549      1.13      fvdl 		scsi_conf = (ahc->our_id & 0x7);
    550      1.13      fvdl 		if (sc.adapter_control & CFSPARITY)
    551      1.13      fvdl 			scsi_conf |= ENSPCHK;
    552      1.13      fvdl 		if (sc.adapter_control & CFRESETB)
    553      1.13      fvdl 			scsi_conf |= RESET_SCSI;
    554      1.13      fvdl 
    555      1.13      fvdl 		if (sc.bios_control & CF284XEXTEND)
    556      1.13      fvdl 			ahc->flags |= AHC_EXTENDED_TRANS_A;
    557      1.13      fvdl 		/* Set SCSICONF info */
    558      1.13      fvdl 		ahc_outb(ahc, SCSICONF, scsi_conf);
    559       1.1      soda 
    560      1.13      fvdl 		if (sc.adapter_control & CF284XSTERM)
    561      1.13      fvdl 			ahc->flags |= AHC_TERM_ENB_A;
    562      1.20      fvdl 	}
    563      1.20      fvdl }
    564      1.20      fvdl 
    565      1.20      fvdl static int
    566      1.20      fvdl verify_seeprom_cksum(struct seeprom_config *sc)
    567      1.20      fvdl {
    568      1.20      fvdl 	int i;
    569      1.20      fvdl 	int maxaddr;
    570      1.20      fvdl 	uint32_t checksum;
    571      1.20      fvdl 	uint16_t *scarray;
    572      1.20      fvdl 
    573      1.20      fvdl 	maxaddr = (sizeof(*sc)/2) - 1;
    574      1.20      fvdl 	checksum = 0;
    575      1.20      fvdl 	scarray = (uint16_t *)sc;
    576      1.20      fvdl 
    577      1.20      fvdl 	for (i = 0; i < maxaddr; i++)
    578      1.20      fvdl 		checksum = checksum + scarray[i];
    579      1.20      fvdl 	if (checksum == 0
    580      1.20      fvdl 	 || (checksum & 0xFFFF) != sc->checksum) {
    581      1.20      fvdl 		return (0);
    582      1.20      fvdl 	} else {
    583      1.20      fvdl 		return(1);
    584       1.1      soda 	}
    585       1.1      soda }
    586