1*5ce3f1d1Sthorpej /* $NetBSD: ahc_eisa.c,v 1.42 2021/01/27 04:35:15 thorpej Exp $ */
2917f00ceSthorpej
319b0b950Smycroft /*
419b0b950Smycroft * Product specific probe and attach routines for:
57df61531Sfvdl * 274X and aic7770 motherboard SCSI controllers
619b0b950Smycroft *
77df61531Sfvdl * Copyright (c) 1994, 1995, 1996, 1997, 1998 Justin T. Gibbs.
819b0b950Smycroft * All rights reserved.
919b0b950Smycroft *
1019b0b950Smycroft * Redistribution and use in source and binary forms, with or without
1119b0b950Smycroft * modification, are permitted provided that the following conditions
1219b0b950Smycroft * are met:
1319b0b950Smycroft * 1. Redistributions of source code must retain the above copyright
1419b0b950Smycroft * notice immediately at the beginning of the file, without modification,
1519b0b950Smycroft * this list of conditions, and the following disclaimer.
167df61531Sfvdl * 2. The name of the author may not be used to endorse or promote products
1719b0b950Smycroft * derived from this software without specific prior written permission.
1819b0b950Smycroft *
1919b0b950Smycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2019b0b950Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2119b0b950Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2219b0b950Smycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2319b0b950Smycroft * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2419b0b950Smycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2519b0b950Smycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2619b0b950Smycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2719b0b950Smycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2819b0b950Smycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2919b0b950Smycroft * SUCH DAMAGE.
30c62a6661Sexplorer *
317df61531Sfvdl * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $
3219b0b950Smycroft */
3319b0b950Smycroft
34b84f53efSlukem #include <sys/cdefs.h>
35*5ce3f1d1Sthorpej __KERNEL_RCSID(0, "$NetBSD: ahc_eisa.c,v 1.42 2021/01/27 04:35:15 thorpej Exp $");
36b84f53efSlukem
3719b0b950Smycroft #include <sys/param.h>
3819b0b950Smycroft #include <sys/systm.h>
3919b0b950Smycroft #include <sys/kernel.h>
4019b0b950Smycroft #include <sys/device.h>
415fea9616Sjdolecek #include <sys/reboot.h>
424656f0baSthorpej
43a2a38285Sad #include <sys/bus.h>
44a2a38285Sad #include <sys/intr.h>
4519b0b950Smycroft
466f3bab1fSbouyer #include <dev/scsipi/scsi_all.h>
476f3bab1fSbouyer #include <dev/scsipi/scsipi_all.h>
486f3bab1fSbouyer #include <dev/scsipi/scsiconf.h>
4919b0b950Smycroft
5019b0b950Smycroft #include <dev/eisa/eisareg.h>
5119b0b950Smycroft #include <dev/eisa/eisavar.h>
5219b0b950Smycroft #include <dev/eisa/eisadevs.h>
5319b0b950Smycroft
540d9c871cSfvdl #include <dev/ic/aic7xxx_osm.h>
550d9c871cSfvdl #include <dev/ic/aic7xxx_inline.h>
567df61531Sfvdl #include <dev/ic/aic77xxreg.h>
577df61531Sfvdl #include <dev/ic/aic77xxvar.h>
5819b0b950Smycroft
596a970ea2Scegger static int ahc_eisa_match(device_t, cfdata_t, void *);
606a970ea2Scegger static void ahc_eisa_attach(device_t, device_t, void *);
6119b0b950Smycroft
6219b0b950Smycroft
636a970ea2Scegger CFATTACH_DECL_NEW(ahc_eisa, sizeof(struct ahc_softc),
64c9b3657cSthorpej ahc_eisa_match, ahc_eisa_attach, NULL, NULL);
6519b0b950Smycroft
66*5ce3f1d1Sthorpej static const struct device_compatible_entry compat_data[] = {
67*5ce3f1d1Sthorpej { .compat = "ADP7770", .data = EISA_PRODUCT_ADP7770 },
68*5ce3f1d1Sthorpej { .compat = "ADP7771", .data = EISA_PRODUCT_ADP7771 },
69*5ce3f1d1Sthorpej DEVICE_COMPAT_EOL
70*5ce3f1d1Sthorpej };
71*5ce3f1d1Sthorpej
7219b0b950Smycroft /*
7319b0b950Smycroft * Check the slots looking for a board we recognise
74f0a7346dSsnj * If we find one, note its address (slot) and call
7519b0b950Smycroft * the actual probe routine to check it out.
7619b0b950Smycroft */
7741e5f04cSthorpej static int
ahc_eisa_match(device_t parent,cfdata_t match,void * aux)786a970ea2Scegger ahc_eisa_match(device_t parent, cfdata_t match, void *aux)
7919b0b950Smycroft {
8019b0b950Smycroft struct eisa_attach_args *ea = aux;
8116c4c5afSthorpej bus_space_tag_t iot = ea->ea_iot;
8216c4c5afSthorpej bus_space_handle_t ioh;
8319b0b950Smycroft int irq;
8419b0b950Smycroft
85*5ce3f1d1Sthorpej if (!eisa_compatible_match(ea, compat_data))
8619b0b950Smycroft return (0);
8719b0b950Smycroft
8816c4c5afSthorpej if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
8916c4c5afSthorpej AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
9019b0b950Smycroft return (0);
912001bba8Smycroft
927df61531Sfvdl irq = ahc_aic77xx_irq(iot, ioh);
932001bba8Smycroft
9416c4c5afSthorpej bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
952001bba8Smycroft
9619b0b950Smycroft return (irq >= 0);
9719b0b950Smycroft }
9819b0b950Smycroft
9941e5f04cSthorpej static void
ahc_eisa_attach(device_t parent,device_t self,void * aux)1006a970ea2Scegger ahc_eisa_attach(device_t parent, device_t self, void *aux)
10119b0b950Smycroft {
10292c7bba3Sthorpej struct ahc_softc *ahc = device_private(self);
10319b0b950Smycroft struct eisa_attach_args *ea = aux;
104*5ce3f1d1Sthorpej const struct device_compatible_entry *dce;
105f952cd37Smycroft eisa_chipset_tag_t ec = ea->ea_ec;
106f952cd37Smycroft eisa_intr_handle_t ih;
1077df61531Sfvdl bus_space_tag_t iot = ea->ea_iot;
1087df61531Sfvdl bus_space_handle_t ioh;
1097df61531Sfvdl int irq, intrtype;
1107df61531Sfvdl const char *intrstr, *intrtypestr;
1117df61531Sfvdl u_int biosctrl;
1127df61531Sfvdl u_int scsiconf;
1137df61531Sfvdl u_int scsiconf1;
1140d9c871cSfvdl u_char intdef;
1154762c81fStsutsui #ifdef AHC_DEBUG
1167df61531Sfvdl int i;
1177df61531Sfvdl #endif
118e58a356cSchristos char intrbuf[EISA_INTRSTR_LEN];
11919b0b950Smycroft
1206a970ea2Scegger ahc->sc_dev = self;
1216a970ea2Scegger
122*5ce3f1d1Sthorpej dce = eisa_compatible_lookup(ea, compat_data);
123*5ce3f1d1Sthorpej KASSERT(dce != NULL);
124*5ce3f1d1Sthorpej
12516c4c5afSthorpej if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
1260d9c871cSfvdl AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh)) {
1276a970ea2Scegger aprint_error_dev(ahc->sc_dev, "could not map I/O addresses");
1280d9c871cSfvdl return;
1290d9c871cSfvdl }
1300d9c871cSfvdl if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0) {
1316a970ea2Scegger aprint_error_dev(ahc->sc_dev, "ahc_aic77xx_irq failed!");
1320d9c871cSfvdl goto free_io;
1330d9c871cSfvdl }
13419b0b950Smycroft
135*5ce3f1d1Sthorpej printf(": %s\n", (const char *)dce->data);
13619b0b950Smycroft
1376a970ea2Scegger ahc_set_name(ahc, device_xname(ahc->sc_dev));
138da526ebfSfvdl ahc->parent_dmat = ea->ea_dmat;
1390d9c871cSfvdl ahc->chip = AHC_AIC7770|AHC_EISA;
1400d9c871cSfvdl ahc->features = AHC_AIC7770_FE;
1410d9c871cSfvdl ahc->flags = AHC_PAGESCBS;
1420d9c871cSfvdl ahc->bugs = AHC_TMODE_WIDEODD_BUG;
1430d9c871cSfvdl ahc->tag = iot;
1440d9c871cSfvdl ahc->bsh = ioh;
1457df61531Sfvdl ahc->channel = 'A';
1460d9c871cSfvdl
1474d6d3fb3Sfvdl if (ahc_softc_init(ahc) != 0)
1484d6d3fb3Sfvdl goto free_io;
1494d6d3fb3Sfvdl
1500d9c871cSfvdl ahc_intr_enable(ahc, FALSE);
1510d9c871cSfvdl
1527df61531Sfvdl if (ahc_reset(ahc) != 0)
1530d9c871cSfvdl goto free_io;
1547df61531Sfvdl
155f952cd37Smycroft if (eisa_intr_map(ec, irq, &ih)) {
1566a970ea2Scegger aprint_error_dev(ahc->sc_dev, "couldn't map interrupt (%d)\n",
15758956204Scegger irq);
1580d9c871cSfvdl goto free_io;
15919b0b950Smycroft }
16019b0b950Smycroft
1610d9c871cSfvdl intdef = bus_space_read_1(iot, ioh, INTDEF);
1620d9c871cSfvdl
1630d9c871cSfvdl if (intdef & EDGE_TRIG) {
1647df61531Sfvdl intrtype = IST_EDGE;
1657df61531Sfvdl intrtypestr = "edge triggered";
1660d9c871cSfvdl } else {
1670d9c871cSfvdl intrtype = IST_LEVEL;
1680d9c871cSfvdl intrtypestr = "level sensitive";
16919b0b950Smycroft }
170e58a356cSchristos intrstr = eisa_intr_string(ec, ih, intrbuf, sizeof(intrbuf));
1717df61531Sfvdl ahc->ih = eisa_intr_establish(ec, ih,
1727df61531Sfvdl intrtype, IPL_BIO, ahc_intr, ahc);
1737df61531Sfvdl if (ahc->ih == NULL) {
17471fbb921Smsaitoh aprint_error_dev(ahc->sc_dev,
17571fbb921Smsaitoh "couldn't establish %s interrupt", intrtypestr);
1767df61531Sfvdl if (intrstr != NULL)
17774341862Snjoly aprint_error(" at %s", intrstr);
17874341862Snjoly aprint_error("\n");
1790d9c871cSfvdl goto free_io;
1807df61531Sfvdl }
1817df61531Sfvdl if (intrstr != NULL)
18274341862Snjoly aprint_normal_dev(ahc->sc_dev, "%s interrupting at %s\n",
1837df61531Sfvdl intrtypestr, intrstr);
18419b0b950Smycroft
18519b0b950Smycroft /*
18619b0b950Smycroft * Now that we know we own the resources we need, do the
18719b0b950Smycroft * card initialization.
18819b0b950Smycroft *
18919b0b950Smycroft * First, the aic7770 card specific setup.
19019b0b950Smycroft */
1917df61531Sfvdl biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
1927df61531Sfvdl scsiconf = ahc_inb(ahc, SCSICONF);
1937df61531Sfvdl scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
1947df61531Sfvdl
1954762c81fStsutsui #ifdef AHC_DEBUG
1967df61531Sfvdl for (i = TARG_SCSIRATE; i <= HA_274_BIOSCTRL; i+=8) {
1977df61531Sfvdl printf("0x%x, 0x%x, 0x%x, 0x%x, "
1987df61531Sfvdl "0x%x, 0x%x, 0x%x, 0x%x\n",
1997df61531Sfvdl ahc_inb(ahc, i),
2007df61531Sfvdl ahc_inb(ahc, i+1),
2017df61531Sfvdl ahc_inb(ahc, i+2),
2027df61531Sfvdl ahc_inb(ahc, i+3),
2037df61531Sfvdl ahc_inb(ahc, i+4),
2047df61531Sfvdl ahc_inb(ahc, i+5),
2057df61531Sfvdl ahc_inb(ahc, i+6),
2067df61531Sfvdl ahc_inb(ahc, i+7));
2077df61531Sfvdl }
2087df61531Sfvdl #endif
20919b0b950Smycroft
21019b0b950Smycroft /* Get the primary channel information */
2117df61531Sfvdl if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
2120d9c871cSfvdl ahc->flags |= AHC_PRIMARY_CHANNEL;
21319b0b950Smycroft
2147df61531Sfvdl if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
21519b0b950Smycroft ahc->flags |= AHC_USEDEFAULTS;
2167df61531Sfvdl } else if ((ahc->features & AHC_WIDE) != 0) {
2177df61531Sfvdl ahc->our_id = scsiconf1 & HWSCSIID;
2187df61531Sfvdl if (scsiconf & TERM_ENB)
2197df61531Sfvdl ahc->flags |= AHC_TERM_ENB_A;
2207df61531Sfvdl } else {
2217df61531Sfvdl ahc->our_id = scsiconf & HSCSIID;
2227df61531Sfvdl ahc->our_id_b = scsiconf1 & HSCSIID;
2237df61531Sfvdl if (scsiconf & TERM_ENB)
2247df61531Sfvdl ahc->flags |= AHC_TERM_ENB_A;
2257df61531Sfvdl if (scsiconf1 & TERM_ENB)
2267df61531Sfvdl ahc->flags |= AHC_TERM_ENB_B;
22719b0b950Smycroft }
2280d9c871cSfvdl if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
2297df61531Sfvdl ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
23019b0b950Smycroft
2317df61531Sfvdl /* Attach sub-devices */
2327df61531Sfvdl if (ahc_aic77xx_attach(ahc) == 0)
2337df61531Sfvdl return; /* succeed */
23419b0b950Smycroft
2357df61531Sfvdl /* failed */
2367df61531Sfvdl eisa_intr_disestablish(ec, ahc->ih);
2377df61531Sfvdl free_io:
2387df61531Sfvdl bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
23919b0b950Smycroft }
240