1 /* $NetBSD: ahc_eisa.c,v 1.20 2001/11/13 12:47:33 lukem Exp $ */ 2 3 /* 4 * Product specific probe and attach routines for: 5 * 274X and aic7770 motherboard SCSI controllers 6 * 7 * Copyright (c) 1994, 1995, 1996, 1997, 1998 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. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15 2000/01/29 14:22:19 peter Exp $ 32 */ 33 34 #include <sys/cdefs.h> 35 __KERNEL_RCSID(0, "$NetBSD: ahc_eisa.c,v 1.20 2001/11/13 12:47:33 lukem Exp $"); 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/kernel.h> 40 #include <sys/device.h> 41 #include <sys/reboot.h> 42 43 #include <machine/bus.h> 44 #include <machine/intr.h> 45 46 #include <dev/scsipi/scsi_all.h> 47 #include <dev/scsipi/scsipi_all.h> 48 #include <dev/scsipi/scsiconf.h> 49 50 #include <dev/eisa/eisareg.h> 51 #include <dev/eisa/eisavar.h> 52 #include <dev/eisa/eisadevs.h> 53 54 #include <dev/microcode/aic7xxx/aic7xxx_reg.h> 55 #include <dev/ic/aic7xxxvar.h> 56 #include <dev/ic/aic77xxreg.h> 57 #include <dev/ic/aic77xxvar.h> 58 59 int ahc_eisa_match __P((struct device *, struct cfdata *, void *)); 60 void ahc_eisa_attach __P((struct device *, struct device *, void *)); 61 62 63 struct cfattach ahc_eisa_ca = { 64 sizeof(struct ahc_softc), ahc_eisa_match, ahc_eisa_attach 65 }; 66 67 /* 68 * Check the slots looking for a board we recognise 69 * If we find one, note it's address (slot) and call 70 * the actual probe routine to check it out. 71 */ 72 int 73 ahc_eisa_match(parent, match, aux) 74 struct device *parent; 75 struct cfdata *match; 76 void *aux; 77 { 78 struct eisa_attach_args *ea = aux; 79 bus_space_tag_t iot = ea->ea_iot; 80 bus_space_handle_t ioh; 81 int irq; 82 83 /* must match one of our known ID strings */ 84 if (strcmp(ea->ea_idstring, "ADP7770") && 85 strcmp(ea->ea_idstring, "ADP7771")) 86 return (0); 87 88 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + 89 AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh)) 90 return (0); 91 92 irq = ahc_aic77xx_irq(iot, ioh); 93 94 bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE); 95 96 return (irq >= 0); 97 } 98 99 void 100 ahc_eisa_attach(parent, self, aux) 101 struct device *parent, *self; 102 void *aux; 103 { 104 struct ahc_softc *ahc = (void *)self; 105 struct eisa_attach_args *ea = aux; 106 eisa_chipset_tag_t ec = ea->ea_ec; 107 eisa_intr_handle_t ih; 108 bus_space_tag_t iot = ea->ea_iot; 109 bus_space_handle_t ioh; 110 int irq, intrtype; 111 const char *intrstr, *intrtypestr; 112 u_int biosctrl; 113 u_int scsiconf; 114 u_int scsiconf1; 115 #if DEBUG 116 int i; 117 #endif 118 119 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) + 120 AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh)) 121 panic("%s: could not map I/O addresses", ahc->sc_dev.dv_xname); 122 if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0) 123 panic("%s: ahc_aic77xx_irq failed!", ahc->sc_dev.dv_xname); 124 125 if (strcmp(ea->ea_idstring, "ADP7770") == 0) { 126 printf(": %s\n", EISA_PRODUCT_ADP7770); 127 } else if (strcmp(ea->ea_idstring, "ADP7771") == 0) { 128 printf(": %s\n", EISA_PRODUCT_ADP7771); 129 } else { 130 panic(": Unknown device type %s\n", ea->ea_idstring); 131 } 132 133 if (ahc_alloc(ahc, ioh, iot, ea->ea_dmat, 134 AHC_AIC7770|AHC_EISA, AHC_AIC7770_FE, AHC_FNONE) < 0) 135 goto free_io; 136 137 ahc->channel = 'A'; 138 ahc->channel_b = 'B'; 139 if (ahc_reset(ahc) != 0) 140 goto free_ahc; 141 142 if (eisa_intr_map(ec, irq, &ih)) { 143 printf("%s: couldn't map interrupt (%d)\n", 144 ahc->sc_dev.dv_xname, irq); 145 goto free_ahc; 146 } 147 148 /* 149 * The IRQMS bit enables level sensitive interrupts. Only allow 150 * IRQ sharing if it's set. 151 * NOTE: ahc->pause is initialized in ahc_alloc(). 152 * 153 * Tell the user what type of interrupts we're using. 154 * usefull for debugging irq problems 155 */ 156 if (ahc->pause & IRQMS) { 157 intrtype = IST_LEVEL; 158 intrtypestr = "level sensitive"; 159 } else { 160 intrtype = IST_EDGE; 161 intrtypestr = "edge triggered"; 162 } 163 intrstr = eisa_intr_string(ec, ih); 164 ahc->ih = eisa_intr_establish(ec, ih, 165 intrtype, IPL_BIO, ahc_intr, ahc); 166 if (ahc->ih == NULL) { 167 printf("%s: couldn't establish %s interrupt", 168 ahc->sc_dev.dv_xname, intrtypestr); 169 if (intrstr != NULL) 170 printf(" at %s", intrstr); 171 printf("\n"); 172 goto free_ahc; 173 } 174 if (intrstr != NULL) 175 printf("%s: %s interrupting at %s\n", ahc->sc_dev.dv_xname, 176 intrtypestr, intrstr); 177 178 /* 179 * Now that we know we own the resources we need, do the 180 * card initialization. 181 * 182 * First, the aic7770 card specific setup. 183 */ 184 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL); 185 scsiconf = ahc_inb(ahc, SCSICONF); 186 scsiconf1 = ahc_inb(ahc, SCSICONF + 1); 187 188 #if DEBUG 189 for (i = TARG_SCSIRATE; i <= HA_274_BIOSCTRL; i+=8) { 190 printf("0x%x, 0x%x, 0x%x, 0x%x, " 191 "0x%x, 0x%x, 0x%x, 0x%x\n", 192 ahc_inb(ahc, i), 193 ahc_inb(ahc, i+1), 194 ahc_inb(ahc, i+2), 195 ahc_inb(ahc, i+3), 196 ahc_inb(ahc, i+4), 197 ahc_inb(ahc, i+5), 198 ahc_inb(ahc, i+6), 199 ahc_inb(ahc, i+7)); 200 } 201 #endif 202 203 /* Get the primary channel information */ 204 if ((biosctrl & CHANNEL_B_PRIMARY) != 0) 205 ahc->flags |= AHC_CHANNEL_B_PRIMARY; 206 207 if ((biosctrl & BIOSMODE) == BIOSDISABLED) { 208 ahc->flags |= AHC_USEDEFAULTS; 209 } else if ((ahc->features & AHC_WIDE) != 0) { 210 ahc->our_id = scsiconf1 & HWSCSIID; 211 if (scsiconf & TERM_ENB) 212 ahc->flags |= AHC_TERM_ENB_A; 213 } else { 214 ahc->our_id = scsiconf & HSCSIID; 215 ahc->our_id_b = scsiconf1 & HSCSIID; 216 if (scsiconf & TERM_ENB) 217 ahc->flags |= AHC_TERM_ENB_A; 218 if (scsiconf1 & TERM_ENB) 219 ahc->flags |= AHC_TERM_ENB_B; 220 } 221 /* 222 * We have no way to tell, so assume extended 223 * translation is enabled. 224 */ 225 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B; 226 227 /* Attach sub-devices */ 228 if (ahc_aic77xx_attach(ahc) == 0) 229 return; /* succeed */ 230 231 /* failed */ 232 eisa_intr_disestablish(ec, ahc->ih); 233 free_ahc: 234 ahc_free(ahc); 235 free_io: 236 bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE); 237 } 238