2 * Product specific probe and attach routines for:
5 * Copyright (c) 1999-2003 M. Warner Losh
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Derived from bt isa from end, written by:
31 * Copyright (c) 1998 Justin T. Gibbs
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions, and the following disclaimer,
39 * without modification, immediately at the beginning of the file.
40 * 2. The name of the author may not be used to endorse or promote products
41 * derived from this software without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
47 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 #include <sys/cdefs.h>
57 __FBSDID("$FreeBSD$");
59 #include <sys/param.h>
60 #include <sys/systm.h>
61 #include <sys/kernel.h>
63 #include <sys/mutex.h>
65 #include <machine/bus_pio.h>
66 #include <machine/bus.h>
67 #include <machine/resource.h>
68 #include <sys/module.h>
72 #include <isa/isavar.h>
74 #include <dev/aha/ahareg.h>
76 #include <cam/scsi/scsi_all.h>
78 static struct isa_pnp_id aha_ids[] = {
79 {ADP0100_PNP, "Adaptec 1540/1542 ISA SCSI"}, /* ADP0100 */
80 {AHA1540_PNP, "Adaptec 1540/aha-1640/aha-1535"},/* ADP1540 */
81 {AHA1542_PNP, "Adaptec 1542/aha-1535"}, /* ADP1542 */
82 {AHA1542_PNPCOMPAT, "Adaptec 1542 compatible"}, /* PNP00A0 */
83 {ICU0091_PNP, "Adaptec AHA-1540/1542 SCSI"}, /* ICU0091 */
88 * I/O ports listed in the order enumerated by the card for certain op codes.
90 static bus_addr_t aha_board_ports[] =
101 * Check if the device can be found at the port given
104 aha_isa_probe(device_t dev)
107 * find unit and check we have that many defined
109 struct aha_softc *aha = device_get_softc(dev);
112 struct resource *port_res;
116 config_data_t config_data;
119 /* Check isapnp ids */
120 if (ISA_PNP_PROBE(device_get_parent(dev), dev, aha_ids) == ENXIO)
124 port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid,
125 0, ~0, AHA_NREGS, RF_ACTIVE);
127 if (port_res == NULL)
130 port_start = rman_get_start(port_res);
131 aha_alloc(aha, device_get_unit(dev), rman_get_bustag(port_res),
132 rman_get_bushandle(port_res));
134 /* See if there is really a card present */
135 if (aha_probe(aha) || aha_fetch_adapter_info(aha)) {
137 bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
142 * Determine our IRQ, and DMA settings and
143 * export them to the configuration system.
145 error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
146 (uint8_t*)&config_data, sizeof(config_data), DEFAULT_CMD_TIMEOUT);
149 device_printf(dev, "Could not determine IRQ or DMA "
150 "settings for adapter at %#jx. Failing probe\n",
151 (uintmax_t)port_start);
153 bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
158 bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
160 switch (config_data.dma_chan) {
171 device_printf(dev, "Invalid DMA setting for adapter at %#jx.",
172 (uintmax_t)port_start);
175 error = bus_set_resource(dev, SYS_RES_DRQ, 0, drq, 1);
179 irq = ffs(config_data.irq) + 8;
180 error = bus_set_resource(dev, SYS_RES_IRQ, 0, irq, 1);
185 * Attach all the sub-devices we can find
188 aha_isa_attach(device_t dev)
190 struct aha_softc *aha = device_get_softc(dev);
191 bus_dma_filter_t *filter;
199 aha->port = bus_alloc_resource(dev, SYS_RES_IOPORT, &aha->portrid,
200 0, ~0, AHA_NREGS, RF_ACTIVE);
202 device_printf(dev, "Unable to allocate I/O ports\n");
207 aha->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &aha->irqrid,
210 device_printf(dev, "Unable to allocate excluse use of irq\n");
211 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid,
217 aha->drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &aha->drqrid,
220 device_printf(dev, "Unable to allocate drq\n");
221 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid,
223 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
227 #if 0 /* is the drq ever unset? */
228 if (dev->id_drq != -1)
229 isa_dmacascade(dev->id_drq);
231 isa_dmacascade(rman_get_start(aha->drq));
233 /* Allocate our parent dmatag */
236 lowaddr = BUS_SPACE_MAXADDR_24BIT;
238 if (bus_dma_tag_create( /* parent */ NULL,
241 /* lowaddr */ lowaddr,
242 /* highaddr */ BUS_SPACE_MAXADDR,
244 /* filterarg */ filter_arg,
245 /* maxsize */ BUS_SPACE_MAXSIZE_24BIT,
247 /* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
249 /* lockfunc */ busdma_lock_mutex,
250 /* lockarg */ &Giant,
251 &aha->parent_dmat) != 0) {
252 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid,
254 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
255 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
261 device_printf(dev, "init failed\n");
262 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid,
264 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
265 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
270 error = aha_attach(aha);
272 device_printf(dev, "attach failed\n");
273 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid,
275 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
276 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
281 error = bus_setup_intr(dev, aha->irq, INTR_TYPE_CAM|INTR_ENTROPY,
284 device_printf(dev, "Unable to register interrupt handler\n");
285 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid,
287 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
288 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
297 aha_isa_detach(device_t dev)
299 struct aha_softc *aha = (struct aha_softc *)device_get_softc(dev);
302 error = bus_teardown_intr(dev, aha->irq, aha->ih);
304 device_printf(dev, "failed to unregister interrupt handler\n");
307 bus_release_resource(dev, SYS_RES_IOPORT, aha->portrid, aha->port);
308 bus_release_resource(dev, SYS_RES_IRQ, aha->irqrid, aha->irq);
309 bus_release_resource(dev, SYS_RES_DRQ, aha->drqrid, aha->drq);
311 error = aha_detach(aha);
313 device_printf(dev, "detach failed\n");
322 aha_isa_identify(driver_t *driver, device_t parent)
326 struct aha_softc aha;
328 struct resource *res;
331 /* Attempt to find an adapter */
332 for (i = 0; i < sizeof(aha_board_ports) / sizeof(aha_board_ports[0]);
334 bzero(&aha, sizeof(aha));
335 ioport = aha_board_ports[i];
337 * XXX Check to see if we have a hard-wired aha device at
338 * XXX this port, if so, skip. This should also cover the
339 * XXX case where we are run multiple times due to, eg,
340 * XXX kldload/kldunload.
343 res = bus_alloc_resource(parent, SYS_RES_IOPORT, &rid,
344 ioport, ioport, AHA_NREGS, RF_ACTIVE);
347 aha_alloc(&aha, -1, rman_get_bustag(res),
348 rman_get_bushandle(res));
349 /* See if there is really a card present */
350 if (aha_probe(&aha) || aha_fetch_adapter_info(&aha))
352 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "aha", -1);
353 bus_set_resource(child, SYS_RES_IOPORT, 0, ioport, AHA_NREGS);
355 * Could query the board and set IRQ/DRQ, but probe does
359 bus_release_resource(parent, SYS_RES_IOPORT, rid, res);
364 static device_method_t aha_isa_methods[] = {
365 /* Device interface */
366 DEVMETHOD(device_probe, aha_isa_probe),
367 DEVMETHOD(device_attach, aha_isa_attach),
368 DEVMETHOD(device_detach, aha_isa_detach),
369 DEVMETHOD(device_identify, aha_isa_identify),
374 static driver_t aha_isa_driver = {
377 sizeof(struct aha_softc),
380 static devclass_t aha_devclass;
382 DRIVER_MODULE(aha, isa, aha_isa_driver, aha_devclass, 0, 0);