2 * Device probe and attach routines for the following
3 * Advanced Systems Inc. SCSI controllers:
5 * Single Channel Products:
6 * ABP742 - Bus-Master EISA (240 CDB)
8 * Dual Channel Products:
9 * ABP752 - Dual Channel Bus-Master EISA (240 CDB Per Channel)
11 * Copyright (c) 1997 Justin Gibbs.
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions, and the following disclaimer,
19 * without modification, immediately at the beginning of the file.
20 * 2. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/module.h>
44 #include <sys/mutex.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
51 #include <dev/eisa/eisaconf.h>
53 #include <dev/advansys/advansys.h>
55 #define EISA_DEVICE_ID_ADVANSYS_740 0x04507400
56 #define EISA_DEVICE_ID_ADVANSYS_750 0x04507500
58 #define ADV_EISA_SLOT_OFFSET 0xc00
59 #define ADV_EISA_OFFSET_CHAN1 0x30
60 #define ADV_EISA_OFFSET_CHAN2 0x50
61 #define ADV_EISA_IOSIZE 0x100
63 #define ADV_EISA_ROM_BIOS_ADDR_REG 0x86
64 #define ADV_EISA_IRQ_BURST_LEN_REG 0x87
65 #define ADV_EISA_IRQ_MASK 0x07
66 #define ADV_EISA_IRQ_10 0x00
67 #define ADV_EISA_IRQ_11 0x01
68 #define ADV_EISA_IRQ_12 0x02
69 #define ADV_EISA_IRQ_14 0x04
70 #define ADV_EISA_IRQ_15 0x05
72 #define ADV_EISA_MAX_DMA_ADDR (0x07FFFFFFL)
73 #define ADV_EISA_MAX_DMA_COUNT (0x07FFFFFFL)
76 * The overrun buffer shared amongst all EISA adapters.
78 static void* overrun_buf;
79 static bus_dma_tag_t overrun_dmat;
80 static bus_dmamap_t overrun_dmamap;
81 static bus_addr_t overrun_physbase;
84 adv_eisa_match(eisa_id_t type)
86 switch (type & ~0xF) {
87 case EISA_DEVICE_ID_ADVANSYS_740:
88 return ("AdvanSys ABP-740/742 SCSI adapter");
90 case EISA_DEVICE_ID_ADVANSYS_750:
91 return ("AdvanSys ABP-750/752 SCSI adapter");
100 adv_eisa_probe(device_t dev)
106 desc = adv_eisa_match(eisa_get_id(dev));
109 device_set_desc(dev, desc);
111 iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + ADV_EISA_SLOT_OFFSET;
113 eisa_add_iospace(dev, iobase, ADV_EISA_IOSIZE, RESVADDR_NONE);
114 irq = inb(iobase + ADV_EISA_IRQ_BURST_LEN_REG);
115 irq &= ADV_EISA_IRQ_MASK;
124 printf("adv at slot %d: illegal "
125 "irq setting %d\n", eisa_get_slot(dev),
129 eisa_add_intr(dev, irq + 10, EISA_TRIGGER_LEVEL);
135 adv_eisa_attach(device_t dev)
137 struct adv_softc *adv;
138 struct adv_softc *adv_b;
140 struct resource *irq;
147 io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
149 device_printf(dev, "No I/O space?!\n");
154 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
155 RF_SHAREABLE | RF_ACTIVE);
157 device_printf(dev, "No irq?!\n");
158 bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
163 switch (eisa_get_id(dev) & ~0xF) {
164 case EISA_DEVICE_ID_ADVANSYS_750:
165 adv_b = adv_alloc(dev, rman_get_bustag(io),
166 rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN2);
171 * Allocate a parent dmatag for all tags created
172 * by the MI portions of the advansys driver
174 /* XXX Should be a child of the PCI bus dma tag */
175 error = bus_dma_tag_create(
179 /* lowaddr */ ADV_EISA_MAX_DMA_ADDR,
180 /* highaddr */ BUS_SPACE_MAXADDR,
182 /* filterarg */ NULL,
183 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
185 /* maxsegsz */ ADV_EISA_MAX_DMA_COUNT,
187 /* lockfunc */ busdma_lock_mutex,
188 /* lockarg */ &Giant,
189 &adv_b->parent_dmat);
192 printf("%s: Could not allocate DMA tag - error %d\n",
193 adv_name(adv_b), error);
201 case EISA_DEVICE_ID_ADVANSYS_740:
202 adv = adv_alloc(dev, rman_get_bustag(io),
203 rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN1);
211 * Allocate a parent dmatag for all tags created
212 * by the MI portions of the advansys driver
214 /* XXX Should be a child of the PCI bus dma tag */
215 error = bus_dma_tag_create(
219 /* lowaddr */ ADV_EISA_MAX_DMA_ADDR,
220 /* highaddr */ BUS_SPACE_MAXADDR,
222 /* filterarg */ NULL,
223 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
225 /* maxsegsz */ ADV_EISA_MAX_DMA_COUNT,
227 /* lockfunc */ busdma_lock_mutex,
228 /* lockarg */ &Giant,
232 printf("%s: Could not allocate DMA tag - error %d\n",
233 adv_name(adv), error);
241 printf("adveisaattach: Unknown device type!\n");
246 if (overrun_buf == NULL) {
247 /* Need to allocate our overrun buffer */
248 if (bus_dma_tag_create(
249 /* parent */ adv->parent_dmat,
252 /* lowaddr */ ADV_EISA_MAX_DMA_ADDR,
253 /* highaddr */ BUS_SPACE_MAXADDR,
255 /* filterarg */ NULL,
256 /* maxsize */ ADV_OVERRUN_BSIZE,
258 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
260 /* lockfunc */ busdma_lock_mutex,
261 /* lockarg */ &Giant,
262 &overrun_dmat) != 0) {
266 if (bus_dmamem_alloc(overrun_dmat,
269 &overrun_dmamap) != 0) {
270 bus_dma_tag_destroy(overrun_dmat);
274 /* And permanently map it in */
275 bus_dmamap_load(overrun_dmat, overrun_dmamap,
276 overrun_buf, ADV_OVERRUN_BSIZE,
277 adv_map, &overrun_physbase,
282 * Now that we know we own the resources we need, do the
283 * card initialization.
289 ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
290 ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
292 adv->chip_version = EISA_REVISION_ID(eisa_get_id(dev))
293 + ADV_CHIP_MIN_VER_EISA - 1;
295 if (adv_init(adv) != 0) {
302 adv->max_dma_count = ADV_EISA_MAX_DMA_COUNT;
303 adv->max_dma_addr = ADV_EISA_MAX_DMA_ADDR;
309 ADV_OUTB(adv_b, ADV_CHIP_CTRL, ADV_CC_HALT);
310 ADV_OUTW(adv_b, ADV_CHIP_STATUS, 0);
312 adv_b->chip_version = EISA_REVISION_ID(eisa_get_id(dev))
313 + ADV_CHIP_MIN_VER_EISA - 1;
315 if (adv_init(adv_b) != 0) {
318 adv_b->max_dma_count = ADV_EISA_MAX_DMA_COUNT;
319 adv_b->max_dma_addr = ADV_EISA_MAX_DMA_ADDR;
324 * Enable our interrupt handler.
326 bus_setup_intr(dev, irq, INTR_TYPE_CAM|INTR_ENTROPY, NULL, adv_intr,
329 /* Attach sub-devices - always succeeds */
337 bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
338 bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
342 static device_method_t adv_eisa_methods[] = {
343 /* Device interface */
344 DEVMETHOD(device_probe, adv_eisa_probe),
345 DEVMETHOD(device_attach, adv_eisa_attach),
349 static driver_t adv_eisa_driver = {
350 "adv", adv_eisa_methods, sizeof(struct adv_softc)
353 static devclass_t adv_eisa_devclass;
354 DRIVER_MODULE(adv, eisa, adv_eisa_driver, adv_eisa_devclass, 0, 0);
355 MODULE_DEPEND(adv, eisa, 1, 1, 1);