2 * Device probe and attach routines for the following
3 * Advanced Systems Inc. SCSI controllers:
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) ***
10 * Single Channel Products:
11 * ABP542 - Bus-Master ISA with floppy (240 CDB)
12 * ABP842 - Bus-Master VL (240 CDB)
14 * Dual Channel Products:
15 * ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
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.
23 * Copyright (c) 1996, 1997 Justin T. Gibbs.
24 * All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
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.
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
47 * $FreeBSD: src/sys/dev/advansys/adv_isa.c,v 1.14.2.5 2002/01/06 21:21:42 dwmalone Exp $
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/kernel.h>
54 #include <machine/bus_pio.h>
55 #include <machine/bus.h>
56 #include <machine/resource.h>
60 #include <isa/isavar.h>
62 #include <dev/advansys/advansys.h>
64 #include <cam/scsi/scsi_all.h>
66 #define ADV_ISA_MAX_DMA_ADDR (0x00FFFFFFL)
67 #define ADV_ISA_MAX_DMA_COUNT (0x00FFFFFFL)
69 #define ADV_VL_MAX_DMA_ADDR (0x07FFFFFFL)
70 #define ADV_VL_MAX_DMA_COUNT (0x07FFFFFFL)
73 * The overrun buffer shared amongst all ISA/VL adapters.
75 static u_int8_t* overrun_buf;
76 static bus_dma_tag_t overrun_dmat;
77 static bus_dmamap_t overrun_dmamap;
78 static bus_addr_t overrun_physbase;
80 /* Possible port addresses an ISA or VL adapter can live at */
81 static u_int16_t adv_isa_ioports[] =
84 0x110, /* First selection in BIOS setup */
86 0x130, /* Second selection in BIOS setup */
88 0x150, /* Third selection in BIOS setup */
89 0x190, /* Fourth selection in BIOS setup */
90 0x210, /* Fifth selection in BIOS setup */
91 0x230, /* Sixth selection in BIOS setup */
92 0x250, /* Seventh selection in BIOS setup */
93 0x330 /* Eighth and default selection in BIOS setup */
96 #define MAX_ISA_IOPORT_INDEX (sizeof(adv_isa_ioports)/sizeof(u_int16_t) - 1)
98 static int adv_isa_probe(device_t dev);
99 static int adv_isa_attach(device_t dev);
100 static void adv_set_isapnp_wait_for_key(void);
101 static int adv_get_isa_dma_channel(struct adv_softc *adv);
102 static int adv_set_isa_dma_settings(struct adv_softc *adv);
105 adv_isa_probe(device_t dev)
109 u_long iobase, iocount, irq;
113 struct resource *iores, *irqres;
116 * Default to scanning all possible device locations.
119 max_port_index = MAX_ISA_IOPORT_INDEX;
121 if (bus_get_resource(dev, SYS_RES_IOPORT, 0, &iobase, &iocount) == 0) {
123 for (;port_index <= max_port_index; port_index++)
124 if (iobase <= adv_isa_ioports[port_index])
126 if ((port_index > max_port_index)
127 || (iobase != adv_isa_ioports[port_index])) {
129 printf("adv%d: Invalid baseport of 0x%lx specified. "
130 "Nearest valid baseport is 0x%x. Failing "
131 "probe.\n", device_get_unit(dev), iobase,
132 (port_index <= max_port_index) ?
133 adv_isa_ioports[port_index] :
134 adv_isa_ioports[max_port_index]);
137 max_port_index = port_index;
140 /* Perform the actual probing */
141 adv_set_isapnp_wait_for_key();
142 for (;port_index <= max_port_index; port_index++) {
143 u_int16_t port_addr = adv_isa_ioports[port_index];
148 struct adv_softc *adv;
151 /* Already been attached */
154 if (bus_set_resource(dev, SYS_RES_IOPORT, 0, port_addr, 1))
157 /* XXX what is the real portsize? */
158 iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1,
163 if (adv_find_signature(rman_get_bustag(iores),
164 rman_get_bushandle(iores)) == 0) {
165 bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
170 * Got one. Now allocate our softc
171 * and see if we can initialize the card.
173 adv = adv_alloc(dev, rman_get_bustag(iores),
174 rman_get_bushandle(iores));
176 bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
183 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
184 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
186 * Determine the chip version.
188 adv->chip_version = ADV_INB(adv, ADV_NONEISA_CHIP_REVISION);
189 if ((adv->chip_version >= ADV_CHIP_MIN_VER_VL)
190 && (adv->chip_version <= ADV_CHIP_MAX_VER_VL)) {
192 maxsegsz = ADV_VL_MAX_DMA_COUNT;
193 maxsize = BUS_SPACE_MAXSIZE_32BIT;
194 lowaddr = ADV_VL_MAX_DMA_ADDR;
195 bus_delete_resource(dev, SYS_RES_DRQ, 0);
196 } else if ((adv->chip_version >= ADV_CHIP_MIN_VER_ISA)
197 && (adv->chip_version <= ADV_CHIP_MAX_VER_ISA)) {
198 if (adv->chip_version >= ADV_CHIP_MIN_VER_ISA_PNP) {
199 adv->type = ADV_ISAPNP;
200 ADV_OUTB(adv, ADV_REG_IFC,
201 ADV_IFC_INIT_DEFAULT);
205 maxsegsz = ADV_ISA_MAX_DMA_COUNT;
206 maxsize = BUS_SPACE_MAXSIZE_24BIT;
207 lowaddr = ADV_ISA_MAX_DMA_ADDR;
208 adv->isa_dma_speed = ADV_DEF_ISA_DMA_SPEED;
209 adv->isa_dma_channel = adv_get_isa_dma_channel(adv);
210 bus_set_resource(dev, SYS_RES_DRQ, 0,
211 adv->isa_dma_channel, 1);
213 panic("advisaprobe: Unknown card revision\n");
217 * Allocate a parent dmatag for all tags created
218 * by the MI portions of the advansys driver
220 /* XXX Should be a child of the ISA bus dma tag */
221 error = bus_dma_tag_create(/*parent*/NULL,
225 /*highaddr*/BUS_SPACE_MAXADDR,
229 /*nsegs*/BUS_SPACE_UNRESTRICTED,
235 printf("%s: Could not allocate DMA tag - error %d\n",
236 adv_name(adv), error);
238 bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
242 adv->init_level += 2;
244 if (overrun_buf == NULL) {
245 /* Need to allocate our overrun buffer */
246 if (bus_dma_tag_create(adv->parent_dmat,
249 ADV_ISA_MAX_DMA_ADDR,
255 BUS_SPACE_MAXSIZE_32BIT,
257 &overrun_dmat) != 0) {
259 bus_release_resource(dev, SYS_RES_IOPORT, 0,
263 if (bus_dmamem_alloc(overrun_dmat,
264 (void **)&overrun_buf,
266 &overrun_dmamap) != 0) {
267 bus_dma_tag_destroy(overrun_dmat);
269 bus_release_resource(dev, SYS_RES_IOPORT, 0,
273 /* And permanently map it in */
274 bus_dmamap_load(overrun_dmat, overrun_dmamap,
275 overrun_buf, ADV_OVERRUN_BSIZE,
276 adv_map, &overrun_physbase,
280 adv->overrun_physbase = overrun_physbase;
282 if (adv_init(adv) != 0) {
283 bus_dmamap_unload(overrun_dmat, overrun_dmamap);
284 bus_dmamem_free(overrun_dmat, overrun_buf,
286 bus_dma_tag_destroy(overrun_dmat);
288 bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
294 if (adv->chip_version == ADV_CHIP_VER_ASYN_BUG) {
296 |= ADV_BUG_FIX_ASYN_USE_SYN;
297 adv->fix_asyn_xfer = ~0;
301 adv->max_dma_count = ADV_ISA_MAX_DMA_COUNT;
302 adv->max_dma_addr = ADV_ISA_MAX_DMA_ADDR;
303 adv_set_isa_dma_settings(adv);
307 adv->max_dma_count = ADV_VL_MAX_DMA_COUNT;
308 adv->max_dma_addr = ADV_VL_MAX_DMA_ADDR;
311 panic("advisaprobe: Invalid card type\n");
314 /* Determine our IRQ */
315 if (bus_get_resource(dev, SYS_RES_IRQ, 0, &irq, NULL))
316 bus_set_resource(dev, SYS_RES_IRQ, 0,
317 adv_get_chip_irq(adv), 1);
319 adv_set_chip_irq(adv, irq);
321 irqres = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
323 if (irqres == NULL ||
324 bus_setup_intr(dev, irqres, INTR_TYPE_CAM, adv_intr, adv,
326 bus_dmamap_unload(overrun_dmat, overrun_dmamap);
327 bus_dmamem_free(overrun_dmat, overrun_buf,
329 bus_dma_tag_destroy(overrun_dmat);
331 bus_release_resource(dev, SYS_RES_IOPORT, 0, iores);
336 adv_isa_ioports[port_index] = 0;
341 bus_set_resource(dev, SYS_RES_IOPORT, 0, iobase, iocount);
343 bus_delete_resource(dev, SYS_RES_IOPORT, 0);
349 adv_isa_attach(device_t dev)
351 struct adv_softc *adv = device_get_softc(dev);
353 return (adv_attach(adv));
357 adv_get_isa_dma_channel(struct adv_softc *adv)
361 channel = ADV_INW(adv, ADV_CONFIG_LSW) & ADV_CFG_LSW_ISA_DMA_CHANNEL;
364 else if (channel == 0x00)
366 return (channel + 4);
370 adv_set_isa_dma_settings(struct adv_softc *adv)
375 if ((adv->isa_dma_channel >= 5) && (adv->isa_dma_channel <= 7)) {
376 if (adv->isa_dma_channel == 7)
379 value = adv->isa_dma_channel - 4;
380 cfg_lsw = ADV_INW(adv, ADV_CONFIG_LSW)
381 & ~ADV_CFG_LSW_ISA_DMA_CHANNEL;
383 ADV_OUTW(adv, ADV_CONFIG_LSW, cfg_lsw);
385 adv->isa_dma_speed &= 0x07;
386 adv_set_bank(adv, 1);
387 ADV_OUTB(adv, ADV_DMA_SPEED, adv->isa_dma_speed);
388 adv_set_bank(adv, 0);
389 isa_dmacascade(adv->isa_dma_channel);
395 adv_set_isapnp_wait_for_key(void)
397 static int isapnp_wait_set = 0;
398 if (isapnp_wait_set == 0) {
399 outb(ADV_ISA_PNP_PORT_ADDR, 0x02);
400 outb(ADV_ISA_PNP_PORT_WRITE, 0x02);
405 static device_method_t adv_isa_methods[] = {
406 /* Device interface */
407 DEVMETHOD(device_probe, adv_isa_probe),
408 DEVMETHOD(device_attach, adv_isa_attach),
412 static driver_t adv_isa_driver = {
413 "adv", adv_isa_methods, sizeof(struct adv_softc)
416 static devclass_t adv_isa_devclass;
417 DRIVER_MODULE(adv, isa, adv_isa_driver, adv_isa_devclass, 0, 0);