Home | History | Annotate | Line # | Download | only in eisa
      1  1.42   thorpej /*	$NetBSD: ahc_eisa.c,v 1.42 2021/01/27 04:35:15 thorpej 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.20     lukem 
     34  1.20     lukem #include <sys/cdefs.h>
     35  1.42   thorpej __KERNEL_RCSID(0, "$NetBSD: ahc_eisa.c,v 1.42 2021/01/27 04:35:15 thorpej Exp $");
     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.19  jdolecek #include <sys/reboot.h>
     42   1.1   mycroft 
     43  1.34        ad #include <sys/bus.h>
     44  1.34        ad #include <sys/intr.h>
     45   1.1   mycroft 
     46  1.13    bouyer #include <dev/scsipi/scsi_all.h>
     47  1.13    bouyer #include <dev/scsipi/scsipi_all.h>
     48  1.13    bouyer #include <dev/scsipi/scsiconf.h>
     49   1.1   mycroft 
     50   1.1   mycroft #include <dev/eisa/eisareg.h>
     51   1.1   mycroft #include <dev/eisa/eisavar.h>
     52   1.1   mycroft #include <dev/eisa/eisadevs.h>
     53   1.1   mycroft 
     54  1.25      fvdl #include <dev/ic/aic7xxx_osm.h>
     55  1.25      fvdl #include <dev/ic/aic7xxx_inline.h>
     56  1.18      fvdl #include <dev/ic/aic77xxreg.h>
     57  1.18      fvdl #include <dev/ic/aic77xxvar.h>
     58   1.1   mycroft 
     59  1.37    cegger static int	ahc_eisa_match(device_t, cfdata_t, void *);
     60  1.37    cegger static void	ahc_eisa_attach(device_t, device_t, void *);
     61   1.1   mycroft 
     62   1.1   mycroft 
     63  1.37    cegger CFATTACH_DECL_NEW(ahc_eisa, sizeof(struct ahc_softc),
     64  1.24   thorpej     ahc_eisa_match, ahc_eisa_attach, NULL, NULL);
     65   1.1   mycroft 
     66  1.42   thorpej static const struct device_compatible_entry compat_data[] = {
     67  1.42   thorpej 	{ .compat = "ADP7770",	.data = EISA_PRODUCT_ADP7770 },
     68  1.42   thorpej 	{ .compat = "ADP7771",	.data = EISA_PRODUCT_ADP7771 },
     69  1.42   thorpej 	DEVICE_COMPAT_EOL
     70  1.42   thorpej };
     71  1.42   thorpej 
     72   1.1   mycroft /*
     73   1.1   mycroft  * Check the slots looking for a board we recognise
     74  1.40       snj  * If we find one, note its address (slot) and call
     75   1.1   mycroft  * the actual probe routine to check it out.
     76   1.1   mycroft  */
     77  1.29   thorpej static int
     78  1.37    cegger ahc_eisa_match(device_t parent, cfdata_t match, void *aux)
     79   1.1   mycroft {
     80   1.1   mycroft 	struct eisa_attach_args *ea = aux;
     81  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
     82  1.10   thorpej 	bus_space_handle_t ioh;
     83   1.1   mycroft 	int irq;
     84   1.1   mycroft 
     85  1.42   thorpej 	if (!eisa_compatible_match(ea, compat_data))
     86   1.1   mycroft 		return (0);
     87   1.1   mycroft 
     88  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
     89  1.10   thorpej 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
     90   1.1   mycroft 		return (0);
     91   1.3   mycroft 
     92  1.18      fvdl 	irq = ahc_aic77xx_irq(iot, ioh);
     93   1.3   mycroft 
     94  1.10   thorpej 	bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
     95   1.3   mycroft 
     96   1.1   mycroft 	return (irq >= 0);
     97   1.1   mycroft }
     98   1.1   mycroft 
     99  1.29   thorpej static void
    100  1.37    cegger ahc_eisa_attach(device_t parent, device_t self, void *aux)
    101   1.1   mycroft {
    102  1.31   thorpej 	struct ahc_softc *ahc = device_private(self);
    103   1.1   mycroft 	struct eisa_attach_args *ea = aux;
    104  1.42   thorpej 	const struct device_compatible_entry *dce;
    105  1.18      fvdl 	eisa_chipset_tag_t ec = ea->ea_ec;
    106  1.18      fvdl 	eisa_intr_handle_t ih;
    107  1.10   thorpej 	bus_space_tag_t iot = ea->ea_iot;
    108  1.10   thorpej 	bus_space_handle_t ioh;
    109  1.18      fvdl 	int irq, intrtype;
    110  1.18      fvdl 	const char *intrstr, *intrtypestr;
    111  1.18      fvdl 	u_int biosctrl;
    112  1.18      fvdl 	u_int scsiconf;
    113  1.18      fvdl 	u_int scsiconf1;
    114  1.25      fvdl 	u_char intdef;
    115  1.28   tsutsui #ifdef AHC_DEBUG
    116  1.18      fvdl 	int i;
    117  1.18      fvdl #endif
    118  1.39  christos 	char intrbuf[EISA_INTRSTR_LEN];
    119   1.1   mycroft 
    120  1.37    cegger 	ahc->sc_dev = self;
    121  1.37    cegger 
    122  1.42   thorpej 	dce = eisa_compatible_lookup(ea, compat_data);
    123  1.42   thorpej 	KASSERT(dce != NULL);
    124  1.42   thorpej 
    125  1.10   thorpej 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
    126  1.25      fvdl 	    AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh)) {
    127  1.37    cegger 		aprint_error_dev(ahc->sc_dev, "could not map I/O addresses");
    128  1.25      fvdl 		return;
    129  1.25      fvdl 	}
    130  1.25      fvdl 	if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0) {
    131  1.37    cegger 		aprint_error_dev(ahc->sc_dev, "ahc_aic77xx_irq failed!");
    132  1.25      fvdl 		goto free_io;
    133  1.25      fvdl 	}
    134   1.1   mycroft 
    135  1.42   thorpej 	printf(": %s\n", (const char *)dce->data);
    136   1.1   mycroft 
    137  1.37    cegger 	ahc_set_name(ahc, device_xname(ahc->sc_dev));
    138  1.27      fvdl 	ahc->parent_dmat = ea->ea_dmat;
    139  1.25      fvdl 	ahc->chip = AHC_AIC7770|AHC_EISA;
    140  1.25      fvdl 	ahc->features = AHC_AIC7770_FE;
    141  1.25      fvdl 	ahc->flags = AHC_PAGESCBS;
    142  1.25      fvdl 	ahc->bugs = AHC_TMODE_WIDEODD_BUG;
    143  1.25      fvdl 	ahc->tag = iot;
    144  1.25      fvdl 	ahc->bsh = ioh;
    145  1.25      fvdl 	ahc->channel = 'A';
    146  1.26      fvdl 
    147  1.26      fvdl 	if (ahc_softc_init(ahc) != 0)
    148  1.26      fvdl 		goto free_io;
    149  1.25      fvdl 
    150  1.25      fvdl 	ahc_intr_enable(ahc, FALSE);
    151  1.18      fvdl 
    152  1.18      fvdl 	if (ahc_reset(ahc) != 0)
    153  1.25      fvdl 		goto free_io;
    154  1.18      fvdl 
    155   1.2   mycroft 	if (eisa_intr_map(ec, irq, &ih)) {
    156  1.37    cegger 		aprint_error_dev(ahc->sc_dev, "couldn't map interrupt (%d)\n",
    157  1.36    cegger 		    irq);
    158  1.25      fvdl 		goto free_io;
    159   1.1   mycroft 	}
    160   1.1   mycroft 
    161  1.25      fvdl 	intdef = bus_space_read_1(iot, ioh, INTDEF);
    162  1.25      fvdl 
    163  1.25      fvdl 	if (intdef & EDGE_TRIG) {
    164  1.25      fvdl 		intrtype = IST_EDGE;
    165  1.25      fvdl 		intrtypestr = "edge triggered";
    166  1.25      fvdl 	} else {
    167  1.18      fvdl 		intrtype = IST_LEVEL;
    168  1.18      fvdl 		intrtypestr = "level sensitive";
    169   1.1   mycroft 	}
    170  1.39  christos 	intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
    171  1.18      fvdl 	ahc->ih = eisa_intr_establish(ec, ih,
    172  1.18      fvdl 	    intrtype, IPL_BIO, ahc_intr, ahc);
    173  1.18      fvdl 	if (ahc->ih == NULL) {
    174  1.41   msaitoh 		aprint_error_dev(ahc->sc_dev,
    175  1.41   msaitoh 		    "couldn't establish %s interrupt", intrtypestr);
    176  1.18      fvdl 		if (intrstr != NULL)
    177  1.38     njoly 			aprint_error(" at %s", intrstr);
    178  1.38     njoly 		aprint_error("\n");
    179  1.25      fvdl 		goto free_io;
    180  1.18      fvdl 	}
    181  1.18      fvdl 	if (intrstr != NULL)
    182  1.38     njoly 		aprint_normal_dev(ahc->sc_dev, "%s interrupting at %s\n",
    183  1.18      fvdl 		       intrtypestr, intrstr);
    184   1.1   mycroft 
    185   1.1   mycroft 	/*
    186  1.28   tsutsui 	 * Now that we know we own the resources we need, do the
    187   1.1   mycroft 	 * card initialization.
    188   1.1   mycroft 	 *
    189   1.1   mycroft 	 * First, the aic7770 card specific setup.
    190   1.1   mycroft 	 */
    191  1.18      fvdl 	biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
    192  1.18      fvdl 	scsiconf = ahc_inb(ahc, SCSICONF);
    193  1.18      fvdl 	scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
    194  1.18      fvdl 
    195  1.28   tsutsui #ifdef AHC_DEBUG
    196  1.18      fvdl 	for (i = TARG_SCSIRATE; i <= HA_274_BIOSCTRL; i+=8) {
    197  1.18      fvdl 		printf("0x%x, 0x%x, 0x%x, 0x%x, "
    198  1.18      fvdl 		       "0x%x, 0x%x, 0x%x, 0x%x\n",
    199  1.18      fvdl 		       ahc_inb(ahc, i),
    200  1.18      fvdl 		       ahc_inb(ahc, i+1),
    201  1.18      fvdl 		       ahc_inb(ahc, i+2),
    202  1.18      fvdl 		       ahc_inb(ahc, i+3),
    203  1.18      fvdl 		       ahc_inb(ahc, i+4),
    204  1.18      fvdl 		       ahc_inb(ahc, i+5),
    205  1.18      fvdl 		       ahc_inb(ahc, i+6),
    206  1.18      fvdl 		       ahc_inb(ahc, i+7));
    207   1.1   mycroft 	}
    208  1.18      fvdl #endif
    209   1.1   mycroft 
    210  1.18      fvdl 	/* Get the primary channel information */
    211  1.18      fvdl 	if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
    212  1.25      fvdl 		ahc->flags |= AHC_PRIMARY_CHANNEL;
    213  1.18      fvdl 
    214  1.18      fvdl 	if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
    215  1.18      fvdl 		ahc->flags |= AHC_USEDEFAULTS;
    216  1.18      fvdl 	} else if ((ahc->features & AHC_WIDE) != 0) {
    217  1.18      fvdl 		ahc->our_id = scsiconf1 & HWSCSIID;
    218  1.18      fvdl 		if (scsiconf & TERM_ENB)
    219  1.18      fvdl 			ahc->flags |= AHC_TERM_ENB_A;
    220  1.18      fvdl 	} else {
    221  1.18      fvdl 		ahc->our_id = scsiconf & HSCSIID;
    222  1.18      fvdl 		ahc->our_id_b = scsiconf1 & HSCSIID;
    223  1.18      fvdl 		if (scsiconf & TERM_ENB)
    224  1.18      fvdl 			ahc->flags |= AHC_TERM_ENB_A;
    225  1.18      fvdl 		if (scsiconf1 & TERM_ENB)
    226  1.18      fvdl 			ahc->flags |= AHC_TERM_ENB_B;
    227   1.1   mycroft 	}
    228  1.25      fvdl 	if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
    229  1.25      fvdl 		ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
    230   1.1   mycroft 
    231  1.18      fvdl 	/* Attach sub-devices */
    232  1.18      fvdl 	if (ahc_aic77xx_attach(ahc) == 0)
    233  1.18      fvdl 		return; /* succeed */
    234  1.18      fvdl 
    235  1.18      fvdl 	/* failed */
    236  1.18      fvdl 	eisa_intr_disestablish(ec, ahc->ih);
    237  1.18      fvdl free_io:
    238  1.18      fvdl 	bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
    239   1.1   mycroft }
    240