2 * Copyright (c) 2000 Matthew N. Dodd <winter@jurai.net>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
37 #include <machine/bus_pio.h>
38 #include <machine/bus.h>
39 #include <machine/resource.h>
42 #include <isa/isavar.h>
44 #include <cam/scsi/scsi_all.h>
46 #include <dev/dpt/dpt.h>
49 static void dpt_isa_identify (driver_t *, device_t);
51 static int dpt_isa_probe (device_t);
52 static int dpt_isa_attach (device_t);
53 static int dpt_isa_detach (device_t);
55 static int dpt_isa_valid_irq (int);
56 static int dpt_isa_valid_ioport (int);
59 dpt_isa_valid_irq (int irq)
74 dpt_isa_valid_ioport (int ioport)
90 dpt_isa_identify (driver_t *driver, device_t parent)
94 int isa_bases[] = { 0x1f0, 0x170, 0x330, 0x230, 0 };
97 for (i = 0; isa_bases[i]; i++) {
98 conf = dpt_pio_get_conf(isa_bases[i]);
101 device_printf(parent, "dpt: dpt_pio_get_conf(%x) failed.\n",
106 child = BUS_ADD_CHILD(parent, ISA_ORDER_SPECULATIVE, "dpt", -1);
108 device_printf(parent, "dpt: BUS_ADD_CHILD() failed!\n");
111 device_set_driver(child, driver);
112 bus_set_resource(child, SYS_RES_IOPORT, 0, isa_bases[i], 0x9);
119 dpt_isa_probe (device_t dev)
125 if (isa_get_vendorid(dev))
128 if ((io_base = bus_get_resource_start(dev, SYS_RES_IOPORT, 0)) == 0)
131 if (dpt_isa_valid_ioport(io_base))
134 conf = dpt_pio_get_conf(io_base);
136 printf("dpt: dpt_pio_get_conf() failed.\n");
140 if (dpt_isa_valid_irq(conf->IRQ))
143 device_set_desc(dev, "ISA DPT SCSI controller");
144 bus_set_resource(dev, SYS_RES_IRQ, 0, conf->IRQ, 1);
145 bus_set_resource(dev, SYS_RES_DRQ, 0, ((8 - conf->DMA_channel) & 7), 1);
151 dpt_isa_attach (device_t dev)
157 dpt = device_get_softc(dev);
161 dpt->io_type = SYS_RES_IOPORT;
164 error = dpt_alloc_resources(dev);
170 dpt->drq_res = bus_alloc_resource_any(dev, SYS_RES_DRQ, &dpt->drq_rid,
173 device_printf(dev, "No DRQ!\n");
177 isa_dma_acquire(rman_get_start(dpt->drq_res));
178 isa_dmacascade(rman_get_start(dpt->drq_res));
182 /* Allocate a dmatag representing the capabilities of this attachment */
183 if (bus_dma_tag_create( /* parent */ NULL,
186 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
187 /* highaddr */ BUS_SPACE_MAXADDR,
189 /* filterarg */ NULL,
190 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
192 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
194 /* lockfunc */ busdma_lock_mutex,
195 /* lockarg */ &Giant,
196 &dpt->parent_dmat) != 0) {
203 if (dpt_init(dpt) != 0) {
209 /* Register with the XPT */
214 if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
215 dpt_intr, dpt, &dpt->ih)) {
216 device_printf(dev, "Unable to register interrupt handler\n");
225 isa_dma_release(rman_get_start(dpt->drq_res));
228 dpt_release_resources(dev);
237 dpt_isa_detach (device_t dev)
243 dpt = device_get_softc(dev);
245 dma = rman_get_start(dpt->drq_res);
246 error = dpt_detach(dev);
247 isa_dma_release(dma);
253 static device_method_t dpt_isa_methods[] = {
254 /* Device interface */
256 DEVMETHOD(device_identify, dpt_isa_identify),
258 DEVMETHOD(device_probe, dpt_isa_probe),
259 DEVMETHOD(device_attach, dpt_isa_attach),
260 DEVMETHOD(device_detach, dpt_isa_detach),
265 static driver_t dpt_isa_driver = {
271 DRIVER_MODULE(dpt, isa, dpt_isa_driver, dpt_devclass, 0, 0);