2 * Product specific probe and attach routines for:
5 * Derived from code written by:
7 * Copyright (c) 1998 Justin T. Gibbs
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions, and the following disclaimer,
15 * without modification, immediately at the beginning of the file.
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.
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
31 * $FreeBSD: src/sys/dev/aha/aha_isa.c,v 1.17.2.1 2000/08/02 22:24:40 peter Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
41 #include <bus/isa/isavar.h>
45 #include <bus/cam/scsi/scsi_all.h>
47 static struct isa_pnp_id aha_ids[] = {
48 {ADP0100_PNP, "Adaptec 1540/1542 ISA SCSI"}, /* ADP0100 */
49 {AHA1540_PNP, "Adaptec 1540/aha-1640/aha-1535"},/* ADP1542 */
50 {AHA1542_PNP, "Adaptec 1542/aha-1535"}, /* ADP1542 */
51 {AHA1542_PNPCOMPAT, "Adaptec 1542 compatible"}, /* PNP00A0 */
52 {ICU0091_PNP, "Adaptec AHA-1540/1542 SCSI"}, /* ICU0091 */
57 * Check if the device can be found at the port given
58 * and if so, set it up ready for further work
59 * as an argument, takes the isa_device structure from
63 aha_isa_probe(device_t dev)
66 * find unit and check we have that many defined
68 struct aha_softc **sc = device_get_softc(dev);
69 struct aha_softc *aha;
73 u_long port_start, port_count;
74 struct resource *port_res;
81 /* Check isapnp ids */
82 if (ISA_PNP_PROBE(device_get_parent(dev), dev, aha_ids) == ENXIO)
85 error = bus_get_resource(dev, SYS_RES_IOPORT, 0,
86 &port_start, &port_count);
91 * Bound our board search if the user has
92 * specified an exact port.
94 aha_find_probe_range(port_start, &port_index, &max_port_index);
99 /* Attempt to find an adapter */
100 for (;port_index <= max_port_index; port_index++) {
101 config_data_t config_data;
105 ioport = aha_iop_from_bio(port_index);
107 error = bus_set_resource(dev, SYS_RES_IOPORT, 0,
113 port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid,
114 0, ~0, AHA_NREGS, RF_ACTIVE);
118 /* Allocate a softc for use during probing */
119 aha = aha_alloc(dev, rman_get_bustag(port_res),
120 rman_get_bushandle(port_res));
123 bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
128 /* See if there is really a card present */
129 if (aha_probe(aha) || aha_fetch_adapter_info(aha)) {
131 bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
137 * Determine our IRQ, and DMA settings and
138 * export them to the configuration system.
140 error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
141 (u_int8_t*)&config_data, sizeof(config_data),
142 DEFAULT_CMD_TIMEOUT);
145 kprintf("aha_isa_probe: Could not determine IRQ or DMA "
146 "settings for adapter at 0x%x. Failing probe\n",
149 bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
154 bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
156 switch (config_data.dma_chan) {
167 kprintf("aha_isa_probe: Invalid DMA setting "
168 "detected for adapter at 0x%x. "
169 "Failing probe\n", ioport);
172 error = bus_set_resource(dev, SYS_RES_DRQ, 0, drq, 1);
176 irq = ffs(config_data.irq) + 8;
177 error = bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1);
191 * Attach all the sub-devices we can find
194 aha_isa_attach(device_t dev)
196 struct aha_softc **sc = device_get_softc(dev);
197 struct aha_softc *aha;
198 bus_dma_filter_t *filter;
207 aha->port = bus_alloc_resource(dev, SYS_RES_IOPORT, &aha->portrid,
208 0, ~0, AHA_NREGS, RF_ACTIVE);
210 device_printf(dev, "Unable to allocate I/O ports\n");
215 aha->irq = bus_alloc_resource(dev, SYS_RES_IRQ, &aha->irqrid, 0, ~0, 1,
218 device_printf(dev, "Unable to allocate excluse use of irq\n");
219 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
224 aha->drq = bus_alloc_resource(dev, SYS_RES_DRQ, &aha->drqrid, 0, ~0, 1,
227 device_printf(dev, "Unable to allocate drq\n");
228 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
229 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
233 #if 0 /* is the drq ever unset? */
234 if (dev->id_drq != -1)
235 isa_dmacascade(dev->id_drq);
237 isa_dmacascade(rman_get_start(aha->drq));
239 /* Allocate our parent dmatag */
242 lowaddr = BUS_SPACE_MAXADDR_24BIT;
244 if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
245 lowaddr, /*highaddr*/BUS_SPACE_MAXADDR,
247 /*maxsize*/BUS_SPACE_MAXSIZE_24BIT,
248 /*nsegments*/BUS_SPACE_UNRESTRICTED,
249 /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT,
250 /*flags*/0, &aha->parent_dmat) != 0) {
251 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
252 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
253 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
259 device_printf(dev, "init failed\n");
260 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
261 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
262 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
267 error = aha_attach(aha);
269 device_printf(dev, "attach failed\n");
270 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
271 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
272 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
277 error = bus_setup_intr(dev, aha->irq, 0, aha_intr, aha, &ih, NULL);
279 device_printf(dev, "Unable to register interrupt handler\n");
280 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
281 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
282 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
291 aha_isa_detach(device_t dev)
293 struct aha_softc *aha = *(struct aha_softc **) device_get_softc(dev);
296 error = bus_teardown_intr(dev, aha->irq, aha->ih);
298 device_printf(dev, "failed to unregister interrupt handler\n");
301 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
302 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
303 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
305 error = aha_detach(aha);
307 device_printf(dev, "detach failed\n");
315 static device_method_t aha_isa_methods[] = {
316 /* Device interface */
317 DEVMETHOD(device_probe, aha_isa_probe),
318 DEVMETHOD(device_attach, aha_isa_attach),
319 DEVMETHOD(device_detach, aha_isa_detach),
324 static driver_t aha_isa_driver = {
327 sizeof(struct aha_softc*),
330 static devclass_t aha_devclass;
332 DRIVER_MODULE(aha, isa, aha_isa_driver, aha_devclass, NULL, NULL);