1 /* $NetBSD: ahc_eisa.c,v 1.28 2003/04/22 14:33:01 tsutsui 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.28 2003/04/22 14:33:01 tsutsui 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/ic/aic7xxx_osm.h>
55 #include <dev/ic/aic7xxx_inline.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 CFATTACH_DECL(ahc_eisa, sizeof(struct ahc_softc),
64 ahc_eisa_match, ahc_eisa_attach, NULL, NULL);
65
66 /*
67 * Check the slots looking for a board we recognise
68 * If we find one, note it's address (slot) and call
69 * the actual probe routine to check it out.
70 */
71 int
72 ahc_eisa_match(parent, match, aux)
73 struct device *parent;
74 struct cfdata *match;
75 void *aux;
76 {
77 struct eisa_attach_args *ea = aux;
78 bus_space_tag_t iot = ea->ea_iot;
79 bus_space_handle_t ioh;
80 int irq;
81
82 /* must match one of our known ID strings */
83 if (strcmp(ea->ea_idstring, "ADP7770") &&
84 strcmp(ea->ea_idstring, "ADP7771"))
85 return (0);
86
87 if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot) +
88 AHC_EISA_SLOT_OFFSET, AHC_EISA_IOSIZE, 0, &ioh))
89 return (0);
90
91 irq = ahc_aic77xx_irq(iot, ioh);
92
93 bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
94
95 return (irq >= 0);
96 }
97
98 void
99 ahc_eisa_attach(parent, self, aux)
100 struct device *parent, *self;
101 void *aux;
102 {
103 struct ahc_softc *ahc = (void *)self;
104 struct eisa_attach_args *ea = aux;
105 eisa_chipset_tag_t ec = ea->ea_ec;
106 eisa_intr_handle_t ih;
107 bus_space_tag_t iot = ea->ea_iot;
108 bus_space_handle_t ioh;
109 int irq, intrtype;
110 const char *intrstr, *intrtypestr;
111 u_int biosctrl;
112 u_int scsiconf;
113 u_int scsiconf1;
114 u_char intdef;
115 #ifdef AHC_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 printf("%s: could not map I/O addresses", ahc->sc_dev.dv_xname);
122 return;
123 }
124 if ((irq = ahc_aic77xx_irq(iot, ioh)) < 0) {
125 printf("%s: ahc_aic77xx_irq failed!", ahc->sc_dev.dv_xname);
126 goto free_io;
127 }
128
129 if (strcmp(ea->ea_idstring, "ADP7770") == 0) {
130 printf(": %s\n", EISA_PRODUCT_ADP7770);
131 } else if (strcmp(ea->ea_idstring, "ADP7771") == 0) {
132 printf(": %s\n", EISA_PRODUCT_ADP7771);
133 } else {
134 printf(": Unknown device type %s", ea->ea_idstring);
135 goto free_io;
136 }
137
138 ahc_set_name(ahc, ahc->sc_dev.dv_xname);
139 ahc->parent_dmat = ea->ea_dmat;
140 ahc->chip = AHC_AIC7770|AHC_EISA;
141 ahc->features = AHC_AIC7770_FE;
142 ahc->flags = AHC_PAGESCBS;
143 ahc->bugs = AHC_TMODE_WIDEODD_BUG;
144 ahc->tag = iot;
145 ahc->bsh = ioh;
146 ahc->channel = 'A';
147
148 if (ahc_softc_init(ahc) != 0)
149 goto free_io;
150
151 ahc_intr_enable(ahc, FALSE);
152
153 if (ahc_reset(ahc) != 0)
154 goto free_io;
155
156 if (eisa_intr_map(ec, irq, &ih)) {
157 printf("%s: couldn't map interrupt (%d)\n",
158 ahc->sc_dev.dv_xname, irq);
159 goto free_io;
160 }
161
162 intdef = bus_space_read_1(iot, ioh, INTDEF);
163
164 if (intdef & EDGE_TRIG) {
165 intrtype = IST_EDGE;
166 intrtypestr = "edge triggered";
167 } else {
168 intrtype = IST_LEVEL;
169 intrtypestr = "level sensitive";
170 }
171 intrstr = eisa_intr_string(ec, ih);
172 ahc->ih = eisa_intr_establish(ec, ih,
173 intrtype, IPL_BIO, ahc_intr, ahc);
174 if (ahc->ih == NULL) {
175 printf("%s: couldn't establish %s interrupt",
176 ahc->sc_dev.dv_xname, intrtypestr);
177 if (intrstr != NULL)
178 printf(" at %s", intrstr);
179 printf("\n");
180 goto free_io;
181 }
182 if (intrstr != NULL)
183 printf("%s: %s interrupting at %s\n", ahc->sc_dev.dv_xname,
184 intrtypestr, intrstr);
185
186 /*
187 * Now that we know we own the resources we need, do the
188 * card initialization.
189 *
190 * First, the aic7770 card specific setup.
191 */
192 biosctrl = ahc_inb(ahc, HA_274_BIOSCTRL);
193 scsiconf = ahc_inb(ahc, SCSICONF);
194 scsiconf1 = ahc_inb(ahc, SCSICONF + 1);
195
196 #ifdef AHC_DEBUG
197 for (i = TARG_SCSIRATE; i <= HA_274_BIOSCTRL; i+=8) {
198 printf("0x%x, 0x%x, 0x%x, 0x%x, "
199 "0x%x, 0x%x, 0x%x, 0x%x\n",
200 ahc_inb(ahc, i),
201 ahc_inb(ahc, i+1),
202 ahc_inb(ahc, i+2),
203 ahc_inb(ahc, i+3),
204 ahc_inb(ahc, i+4),
205 ahc_inb(ahc, i+5),
206 ahc_inb(ahc, i+6),
207 ahc_inb(ahc, i+7));
208 }
209 #endif
210
211 /* Get the primary channel information */
212 if ((biosctrl & CHANNEL_B_PRIMARY) != 0)
213 ahc->flags |= AHC_PRIMARY_CHANNEL;
214
215 if ((biosctrl & BIOSMODE) == BIOSDISABLED) {
216 ahc->flags |= AHC_USEDEFAULTS;
217 } else if ((ahc->features & AHC_WIDE) != 0) {
218 ahc->our_id = scsiconf1 & HWSCSIID;
219 if (scsiconf & TERM_ENB)
220 ahc->flags |= AHC_TERM_ENB_A;
221 } else {
222 ahc->our_id = scsiconf & HSCSIID;
223 ahc->our_id_b = scsiconf1 & HSCSIID;
224 if (scsiconf & TERM_ENB)
225 ahc->flags |= AHC_TERM_ENB_A;
226 if (scsiconf1 & TERM_ENB)
227 ahc->flags |= AHC_TERM_ENB_B;
228 }
229 if ((ahc_inb(ahc, HA_274_BIOSGLOBAL) & HA_274_EXTENDED_TRANS))
230 ahc->flags |= AHC_EXTENDED_TRANS_A|AHC_EXTENDED_TRANS_B;
231
232 /* Attach sub-devices */
233 if (ahc_aic77xx_attach(ahc) == 0)
234 return; /* succeed */
235
236 /* failed */
237 eisa_intr_disestablish(ec, ahc->ih);
238 free_io:
239 bus_space_unmap(iot, ioh, AHC_EISA_IOSIZE);
240 }
Cache object: 5b3ec31dc4321df193c99011f9798a10
|