1/*
2 * Device probe and attach routines for the following
3 * Advanced Systems Inc. SCSI controllers:
4 *
5 * Connectivity Products:
6 * ABP510/5150 - Bus-Master ISA (240 CDB) *
7 * ABP5140 - Bus-Master ISA PnP (16 CDB) * **
8 * ABP5142 - Bus-Master ISA PnP with floppy (16 CDB) ***
9 *
10 * Single Channel Products:
11 * ABP542 - Bus-Master ISA with floppy (240 CDB)
12 * ABP842 - Bus-Master VL (240 CDB)
13 *
14 * Dual Channel Products:
15 * ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
16 *
17 * * This board has been shipped by HP with the 4020i CD-R drive.
18 * The board has no BIOS so it cannot control a boot device, but
19 * it can control any secondary SCSI device.
20 * ** This board has been sold by SIIG as the i540 SpeedMaster.
21 * *** This board has been sold by SIIG as the i542 SpeedMaster.
22 *
23 * Copyright (c) 1996, 1997 Justin T. Gibbs.
24 * All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions, and the following disclaimer,
31 * without modification, immediately at the beginning of the file.
32 * 2. The name of the author may not be used to endorse or promote products
33 * derived from this software without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
39 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 * $FreeBSD: head/sys/dev/advansys/adv_isa.c 56178 2000-01-17 12:49:54Z nyan $
48 */
49
50#include <sys/param.h>
51#include <sys/systm.h>
52
53#include <machine/bus_pio.h>
54#include <machine/bus.h>
55
56#include <i386/isa/isa_device.h>
57
58#include <dev/advansys/advansys.h>
59
60#include <cam/scsi/scsi_all.h>
61
62#define ADV_ISA_MAX_DMA_ADDR (0x00FFFFFFL)
63#define ADV_ISA_MAX_DMA_COUNT (0x00FFFFFFL)
64
65#define ADV_VL_MAX_DMA_ADDR (0x07FFFFFFL)
66#define ADV_VL_MAX_DMA_COUNT (0x07FFFFFFL)
67
68/*
69 * The overrun buffer shared amongst all ISA/VL adapters.
70 */
71static u_int8_t* overrun_buf;
72static bus_dma_tag_t overrun_dmat;
73static bus_dmamap_t overrun_dmamap;
74static bus_addr_t overrun_physbase;
75
76/* Possible port addresses an ISA or VL adapter can live at */
77static u_int16_t adv_isa_ioports[] =
78{
79 0x100,
80 0x110, /* First selection in BIOS setup */
81 0x120,
82 0x130, /* Second selection in BIOS setup */
83 0x140,
84 0x150, /* Third selection in BIOS setup */
85 0x190, /* Fourth selection in BIOS setup */
86 0x210, /* Fifth selection in BIOS setup */
87 0x230, /* Sixth selection in BIOS setup */
88 0x250, /* Seventh selection in BIOS setup */
89 0x330 /* Eighth and default selection in BIOS setup */
90};
91
92#define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1)
93
94static int advisaprobe(struct isa_device *id);
95static int advisaattach(struct isa_device *id);
96static void adv_set_isapnp_wait_for_key(void);
97static int adv_get_isa_dma_channel(struct adv_softc *adv);
98static int adv_set_isa_dma_settings(struct adv_softc *adv);
99
100static void adv_isa_intr(void *unit);
101
102struct isa_driver advdriver =
103{
104 advisaprobe,
105 advisaattach,
106 "adv"
107};
108
109static int
110advisaprobe(struct isa_device *id)
111{
112 int port_index;
113 int max_port_index;
114
115 /*
116 * Default to scanning all possible device locations.
117 */
118 port_index = 0;
119 max_port_index = MAX_ISA_IOPORT_INDEX;
120
121 if (id->id_iobase > 0) {
122 for (;port_index <= max_port_index; port_index++)
123 if (id->id_iobase <= adv_isa_ioports[port_index])
124 break;
125 if ((port_index > max_port_index)
126 || (id->id_iobase != adv_isa_ioports[port_index])) {
127 printf("adv%d: Invalid baseport of 0x%x specified. "
128 "Neerest valid baseport is 0x%x. Failing "
129 "probe.\n", id->id_unit, id->id_iobase,
130 (port_index <= max_port_index) ?
131 adv_isa_ioports[port_index] :
132 adv_isa_ioports[max_port_index]);
133 return 0;
134 }
135 max_port_index = port_index;
136 }
137
138 /* Perform the actual probing */
139 adv_set_isapnp_wait_for_key();
140 for (;port_index <= max_port_index; port_index++) {
141 u_int16_t port_addr = adv_isa_ioports[port_index];
142 bus_size_t maxsegsz;
143 bus_size_t maxsize;
144 bus_addr_t lowaddr;
145 int error;
146
147 if (port_addr == 0)
148 /* Already been attached */
149 continue;
150 id->id_iobase = port_addr;
151 if (haveseen_iobase(id, 1)) /* XXX real portsize? */
152 continue;
153
154 if (adv_find_signature(I386_BUS_SPACE_IO, port_addr)) {
155 /*
156 * Got one. Now allocate our softc
157 * and see if we can initialize the card.
158 */
159 struct adv_softc *adv;
160 adv = adv_alloc(id->id_unit, I386_BUS_SPACE_IO,
161 port_addr);
162 if (adv == NULL)
163 return (0);
164
165 adv_unit++;
166
167 id->id_iobase = adv->bsh;
168
169 /*
170 * Stop the chip.
171 */
172 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
173 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
174 /*
175 * Determine the chip version.
176 */
177 adv->chip_version = ADV_INB(adv,
178 ADV_NONEISA_CHIP_REVISION);
179 if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
180 && (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
181 adv->type = ADV_VL;
182 maxsegsz = ADV_VL_MAX_DMA_COUNT;
183 maxsize = BUS_SPACE_MAXSIZE_32BIT;
184 lowaddr = ADV_VL_MAX_DMA_ADDR;
185 id->id_drq = -1;
186 } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
187 && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
188 if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
189 adv->type = ADV_ISAPNP;
190 ADV_OUTB(adv, ADV_REG_IFC,
191 ADV_IFC_INIT_DEFAULT);
192 } else {
193 adv->type = ADV_ISA;
194 }
195 maxsegsz = ADV_ISA_MAX_DMA_COUNT;
196 maxsize = BUS_SPACE_MAXSIZE_24BIT;
197 lowaddr = ADV_ISA_MAX_DMA_ADDR;
198 adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
199 adv->isa_dma_channel =
200 adv_get_isa_dma_channel(adv);
201 id->id_drq = adv->isa_dma_channel;
202 } else {
203 panic("advisaprobe: Unknown card revision\n");
204 }
205
206 /*
207 * Allocate a parent dmatag for all tags created
208 * by the MI portions of the advansys driver
209 */
210 /* XXX Should be a child of the ISA bus dma tag */
211 error =
212 bus_dma_tag_create(/*parent*/NULL,
213 /*alignemnt*/1,
214 /*boundary*/0,
215 lowaddr,
216 /*highaddr*/BUS_SPACE_MAXADDR,
217 /*filter*/NULL,
218 /*filterarg*/NULL,
219 maxsize,
220 /*nsegs*/BUS_SPACE_UNRESTRICTED,
221 maxsegsz,
222 /*flags*/0,
223 &adv->parent_dmat);
224
225 if (error != 0) {
226 printf("%s: Could not allocate DMA tag - error %d\n",
227 adv_name(adv), error);
228 adv_free(adv);
229 return (0);
230 }
231
232 adv->init_level++;
233
234 if (overrun_buf == NULL) {
235 /* Need to allocate our overrun buffer */
236 if (bus_dma_tag_create(adv->parent_dmat,
237 /*alignment*/8,
238 /*boundary*/0,
239 ADV_ISA_MAX_DMA_ADDR,
240 BUS_SPACE_MAXADDR,
241 /*filter*/NULL,
242 /*filterarg*/NULL,
243 ADV_OVERRUN_BSIZE,
244 /*nsegments*/1,
245 BUS_SPACE_MAXSIZE_32BIT,
246 /*flags*/0,
247 &overrun_dmat) != 0) {
248 adv_free(adv);
249 return (0);
250 }
251 if (bus_dmamem_alloc(overrun_dmat,
252 (void **)&overrun_buf,
253 BUS_DMA_NOWAIT,
254 &overrun_dmamap) != 0) {
255 bus_dma_tag_destroy(overrun_dmat);
256 adv_free(adv);
257 return (0);
258 }
259 /* And permanently map it in */
260 bus_dmamap_load(overrun_dmat, overrun_dmamap,
261 overrun_buf, ADV_OVERRUN_BSIZE,
262 adv_map, &overrun_physbase,
263 /*flags*/0);
264 }
265
266 adv->overrun_physbase = overrun_physbase;
267
268 if (adv_init(adv) != 0) {
269 adv_free(adv);
270 return (0);
271 }
272
273 switch (adv->type) {
274 case ADV_ISAPNP:
275 if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG){
276 adv->bug_fix_control
277 |= ADV_BUG_FIX_ASYN_USE_SYN;
278 adv->fix_asyn_xfer = ~0;
279 }
280 /* Fall Through */
281 case ADV_ISA:
282 adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
283 adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
284 adv_set_isa_dma_settings(adv);
285 break;
286
287 case ADV_VL:
288 adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
289 adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
290 break;
291 default:
292 panic("advisaprobe: Invalid card type\n");
293 }
294
295 /* Determine our IRQ */
296 if (id->id_irq == 0 /* irq ? */)
297 id->id_irq = 1 << adv_get_chip_irq(adv);
298 else
299 adv_set_chip_irq(adv, ffs(id->id_irq) - 1);
300
301 id->id_intr = adv_isa_intr;
302
303 /* Mark as probed */
304 adv_isa_ioports[port_index] = 0;
305 return 1; /* XXX what is the real portsize? */
306 }
307 }
308
309 return 0;
310}
311
312static int
313advisaattach(struct isa_device *id)
314{
315 struct adv_softc *adv;
316
317 adv = advsoftcs[id->id_unit];
318 return (adv_attach(adv));
319}
320
321static int
322adv_get_isa_dma_channel(struct adv_softc *adv)
323{
324 int channel;
325
326 channel = ADV_INW(adv, ADV_CONFIG_LSW) & ADV_CFG_LSW_ISA_DMA_CHANNEL;
327 if (channel == 0x03)
328 return (0);
329 else if (channel == 0x00)
330 return (7);
331 return (channel + 4);
332}
333
334static int
335adv_set_isa_dma_settings(struct adv_softc *adv)
336{
337 u_int16_t cfg_lsw;
338 u_int8_t value;
339
340 if ((adv->isa_dma_channel >= 5) && (adv->isa_dma_channel <= 7)) {
341 if (adv->isa_dma_channel == 7)
342 value = 0x00;
343 else
344 value = adv->isa_dma_channel - 4;
345 cfg_lsw = ADV_INW(adv, ADV_CONFIG_LSW)
346 & ~ADV_CFG_LSW_ISA_DMA_CHANNEL;
347 cfg_lsw |= value;
348 ADV_OUTW(adv, ADV_CONFIG_LSW, cfg_lsw);
349
350 adv->isa_dma_speed &= 0x07;
351 adv_set_bank(adv, 1);
352 ADV_OUTB(adv, ADV_DMA_SPEED, adv->isa_dma_speed);
353 adv_set_bank(adv, 0);
354 isa_dmacascade(adv->isa_dma_channel);
355 }
356 return (0);
357}
358
359static void
360adv_set_isapnp_wait_for_key(void)
361{
362 static int isapnp_wait_set = 0;
363 if (isapnp_wait_set == 0) {
364 outb(ADV_ISA_PNP_PORT_ADDR, 0x02);
365 outb(ADV_ISA_PNP_PORT_WRITE, 0x02);
366 isapnp_wait_set++;
367 }
368 return;
369}
370
371/*
372 * Handle an ISA interrupt.
373 * XXX should go away as soon as ISA interrupt handlers
374 * take a (void *) arg.
375 */
376static void
377adv_isa_intr(void *unit)
378{
379 struct adv_softc *arg = advsoftcs[(int)unit];
380 adv_intr((void *)arg);
381}
2 * Device probe and attach routines for the following
3 * Advanced Systems Inc. SCSI controllers:
4 *
5 * Connectivity Products:
6 * ABP510/5150 - Bus-Master ISA (240 CDB) *
7 * ABP5140 - Bus-Master ISA PnP (16 CDB) * **
8 * ABP5142 - Bus-Master ISA PnP with floppy (16 CDB) ***
9 *
10 * Single Channel Products:
11 * ABP542 - Bus-Master ISA with floppy (240 CDB)
12 * ABP842 - Bus-Master VL (240 CDB)
13 *
14 * Dual Channel Products:
15 * ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
16 *
17 * * This board has been shipped by HP with the 4020i CD-R drive.
18 * The board has no BIOS so it cannot control a boot device, but
19 * it can control any secondary SCSI device.
20 * ** This board has been sold by SIIG as the i540 SpeedMaster.
21 * *** This board has been sold by SIIG as the i542 SpeedMaster.
22 *
23 * Copyright (c) 1996, 1997 Justin T. Gibbs.
24 * All rights reserved.
25 *
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
28 * are met:
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions, and the following disclaimer,
31 * without modification, immediately at the beginning of the file.
32 * 2. The name of the author may not be used to endorse or promote products
33 * derived from this software without specific prior written permission.
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
39 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 * SUCH DAMAGE.
46 *
47 * $FreeBSD: head/sys/dev/advansys/adv_isa.c 56178 2000-01-17 12:49:54Z nyan $
48 */
49
50#include <sys/param.h>
51#include <sys/systm.h>
52
53#include <machine/bus_pio.h>
54#include <machine/bus.h>
55
56#include <i386/isa/isa_device.h>
57
58#include <dev/advansys/advansys.h>
59
60#include <cam/scsi/scsi_all.h>
61
62#define ADV_ISA_MAX_DMA_ADDR (0x00FFFFFFL)
63#define ADV_ISA_MAX_DMA_COUNT (0x00FFFFFFL)
64
65#define ADV_VL_MAX_DMA_ADDR (0x07FFFFFFL)
66#define ADV_VL_MAX_DMA_COUNT (0x07FFFFFFL)
67
68/*
69 * The overrun buffer shared amongst all ISA/VL adapters.
70 */
71static u_int8_t* overrun_buf;
72static bus_dma_tag_t overrun_dmat;
73static bus_dmamap_t overrun_dmamap;
74static bus_addr_t overrun_physbase;
75
76/* Possible port addresses an ISA or VL adapter can live at */
77static u_int16_t adv_isa_ioports[] =
78{
79 0x100,
80 0x110, /* First selection in BIOS setup */
81 0x120,
82 0x130, /* Second selection in BIOS setup */
83 0x140,
84 0x150, /* Third selection in BIOS setup */
85 0x190, /* Fourth selection in BIOS setup */
86 0x210, /* Fifth selection in BIOS setup */
87 0x230, /* Sixth selection in BIOS setup */
88 0x250, /* Seventh selection in BIOS setup */
89 0x330 /* Eighth and default selection in BIOS setup */
90};
91
92#define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1)
93
94static int advisaprobe(struct isa_device *id);
95static int advisaattach(struct isa_device *id);
96static void adv_set_isapnp_wait_for_key(void);
97static int adv_get_isa_dma_channel(struct adv_softc *adv);
98static int adv_set_isa_dma_settings(struct adv_softc *adv);
99
100static void adv_isa_intr(void *unit);
101
102struct isa_driver advdriver =
103{
104 advisaprobe,
105 advisaattach,
106 "adv"
107};
108
109static int
110advisaprobe(struct isa_device *id)
111{
112 int port_index;
113 int max_port_index;
114
115 /*
116 * Default to scanning all possible device locations.
117 */
118 port_index = 0;
119 max_port_index = MAX_ISA_IOPORT_INDEX;
120
121 if (id->id_iobase > 0) {
122 for (;port_index <= max_port_index; port_index++)
123 if (id->id_iobase <= adv_isa_ioports[port_index])
124 break;
125 if ((port_index > max_port_index)
126 || (id->id_iobase != adv_isa_ioports[port_index])) {
127 printf("adv%d: Invalid baseport of 0x%x specified. "
128 "Neerest valid baseport is 0x%x. Failing "
129 "probe.\n", id->id_unit, id->id_iobase,
130 (port_index <= max_port_index) ?
131 adv_isa_ioports[port_index] :
132 adv_isa_ioports[max_port_index]);
133 return 0;
134 }
135 max_port_index = port_index;
136 }
137
138 /* Perform the actual probing */
139 adv_set_isapnp_wait_for_key();
140 for (;port_index <= max_port_index; port_index++) {
141 u_int16_t port_addr = adv_isa_ioports[port_index];
142 bus_size_t maxsegsz;
143 bus_size_t maxsize;
144 bus_addr_t lowaddr;
145 int error;
146
147 if (port_addr == 0)
148 /* Already been attached */
149 continue;
150 id->id_iobase = port_addr;
151 if (haveseen_iobase(id, 1)) /* XXX real portsize? */
152 continue;
153
154 if (adv_find_signature(I386_BUS_SPACE_IO, port_addr)) {
155 /*
156 * Got one. Now allocate our softc
157 * and see if we can initialize the card.
158 */
159 struct adv_softc *adv;
160 adv = adv_alloc(id->id_unit, I386_BUS_SPACE_IO,
161 port_addr);
162 if (adv == NULL)
163 return (0);
164
165 adv_unit++;
166
167 id->id_iobase = adv->bsh;
168
169 /*
170 * Stop the chip.
171 */
172 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
173 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
174 /*
175 * Determine the chip version.
176 */
177 adv->chip_version = ADV_INB(adv,
178 ADV_NONEISA_CHIP_REVISION);
179 if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
180 && (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
181 adv->type = ADV_VL;
182 maxsegsz = ADV_VL_MAX_DMA_COUNT;
183 maxsize = BUS_SPACE_MAXSIZE_32BIT;
184 lowaddr = ADV_VL_MAX_DMA_ADDR;
185 id->id_drq = -1;
186 } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
187 && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
188 if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
189 adv->type = ADV_ISAPNP;
190 ADV_OUTB(adv, ADV_REG_IFC,
191 ADV_IFC_INIT_DEFAULT);
192 } else {
193 adv->type = ADV_ISA;
194 }
195 maxsegsz = ADV_ISA_MAX_DMA_COUNT;
196 maxsize = BUS_SPACE_MAXSIZE_24BIT;
197 lowaddr = ADV_ISA_MAX_DMA_ADDR;
198 adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
199 adv->isa_dma_channel =
200 adv_get_isa_dma_channel(adv);
201 id->id_drq = adv->isa_dma_channel;
202 } else {
203 panic("advisaprobe: Unknown card revision\n");
204 }
205
206 /*
207 * Allocate a parent dmatag for all tags created
208 * by the MI portions of the advansys driver
209 */
210 /* XXX Should be a child of the ISA bus dma tag */
211 error =
212 bus_dma_tag_create(/*parent*/NULL,
213 /*alignemnt*/1,
214 /*boundary*/0,
215 lowaddr,
216 /*highaddr*/BUS_SPACE_MAXADDR,
217 /*filter*/NULL,
218 /*filterarg*/NULL,
219 maxsize,
220 /*nsegs*/BUS_SPACE_UNRESTRICTED,
221 maxsegsz,
222 /*flags*/0,
223 &adv->parent_dmat);
224
225 if (error != 0) {
226 printf("%s: Could not allocate DMA tag - error %d\n",
227 adv_name(adv), error);
228 adv_free(adv);
229 return (0);
230 }
231
232 adv->init_level++;
233
234 if (overrun_buf == NULL) {
235 /* Need to allocate our overrun buffer */
236 if (bus_dma_tag_create(adv->parent_dmat,
237 /*alignment*/8,
238 /*boundary*/0,
239 ADV_ISA_MAX_DMA_ADDR,
240 BUS_SPACE_MAXADDR,
241 /*filter*/NULL,
242 /*filterarg*/NULL,
243 ADV_OVERRUN_BSIZE,
244 /*nsegments*/1,
245 BUS_SPACE_MAXSIZE_32BIT,
246 /*flags*/0,
247 &overrun_dmat) != 0) {
248 adv_free(adv);
249 return (0);
250 }
251 if (bus_dmamem_alloc(overrun_dmat,
252 (void **)&overrun_buf,
253 BUS_DMA_NOWAIT,
254 &overrun_dmamap) != 0) {
255 bus_dma_tag_destroy(overrun_dmat);
256 adv_free(adv);
257 return (0);
258 }
259 /* And permanently map it in */
260 bus_dmamap_load(overrun_dmat, overrun_dmamap,
261 overrun_buf, ADV_OVERRUN_BSIZE,
262 adv_map, &overrun_physbase,
263 /*flags*/0);
264 }
265
266 adv->overrun_physbase = overrun_physbase;
267
268 if (adv_init(adv) != 0) {
269 adv_free(adv);
270 return (0);
271 }
272
273 switch (adv->type) {
274 case ADV_ISAPNP:
275 if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG){
276 adv->bug_fix_control
277 |= ADV_BUG_FIX_ASYN_USE_SYN;
278 adv->fix_asyn_xfer = ~0;
279 }
280 /* Fall Through */
281 case ADV_ISA:
282 adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
283 adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
284 adv_set_isa_dma_settings(adv);
285 break;
286
287 case ADV_VL:
288 adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
289 adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
290 break;
291 default:
292 panic("advisaprobe: Invalid card type\n");
293 }
294
295 /* Determine our IRQ */
296 if (id->id_irq == 0 /* irq ? */)
297 id->id_irq = 1 << adv_get_chip_irq(adv);
298 else
299 adv_set_chip_irq(adv, ffs(id->id_irq) - 1);
300
301 id->id_intr = adv_isa_intr;
302
303 /* Mark as probed */
304 adv_isa_ioports[port_index] = 0;
305 return 1; /* XXX what is the real portsize? */
306 }
307 }
308
309 return 0;
310}
311
312static int
313advisaattach(struct isa_device *id)
314{
315 struct adv_softc *adv;
316
317 adv = advsoftcs[id->id_unit];
318 return (adv_attach(adv));
319}
320
321static int
322adv_get_isa_dma_channel(struct adv_softc *adv)
323{
324 int channel;
325
326 channel = ADV_INW(adv, ADV_CONFIG_LSW) & ADV_CFG_LSW_ISA_DMA_CHANNEL;
327 if (channel == 0x03)
328 return (0);
329 else if (channel == 0x00)
330 return (7);
331 return (channel + 4);
332}
333
334static int
335adv_set_isa_dma_settings(struct adv_softc *adv)
336{
337 u_int16_t cfg_lsw;
338 u_int8_t value;
339
340 if ((adv->isa_dma_channel >= 5) && (adv->isa_dma_channel <= 7)) {
341 if (adv->isa_dma_channel == 7)
342 value = 0x00;
343 else
344 value = adv->isa_dma_channel - 4;
345 cfg_lsw = ADV_INW(adv, ADV_CONFIG_LSW)
346 & ~ADV_CFG_LSW_ISA_DMA_CHANNEL;
347 cfg_lsw |= value;
348 ADV_OUTW(adv, ADV_CONFIG_LSW, cfg_lsw);
349
350 adv->isa_dma_speed &= 0x07;
351 adv_set_bank(adv, 1);
352 ADV_OUTB(adv, ADV_DMA_SPEED, adv->isa_dma_speed);
353 adv_set_bank(adv, 0);
354 isa_dmacascade(adv->isa_dma_channel);
355 }
356 return (0);
357}
358
359static void
360adv_set_isapnp_wait_for_key(void)
361{
362 static int isapnp_wait_set = 0;
363 if (isapnp_wait_set == 0) {
364 outb(ADV_ISA_PNP_PORT_ADDR, 0x02);
365 outb(ADV_ISA_PNP_PORT_WRITE, 0x02);
366 isapnp_wait_set++;
367 }
368 return;
369}
370
371/*
372 * Handle an ISA interrupt.
373 * XXX should go away as soon as ISA interrupt handlers
374 * take a (void *) arg.
375 */
376static void
377adv_isa_intr(void *unit)
378{
379 struct adv_softc *arg = advsoftcs[(int)unit];
380 adv_intr((void *)arg);
381}