2 * Product specific probe and attach routines for:
3 * Buslogic BT-54X and BT-445 cards
5 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
7 * Copyright (c) 1998, 1999 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
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
41 #include <sys/mutex.h>
44 #include <machine/bus.h>
45 #include <machine/resource.h>
48 #include <isa/isavar.h>
49 #include <dev/buslogic/btreg.h>
51 #include <cam/scsi/scsi_all.h>
53 static bus_dma_filter_t btvlbouncefilter;
54 static bus_dmamap_callback_t btmapsensebuffers;
57 bt_isa_alloc_resources(device_t dev, u_long portstart, u_long portend)
60 struct resource *port;
65 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
66 portstart, portend, BT_NREGS, RF_ACTIVE);
70 if (isa_get_irq(dev) != -1) {
72 irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
75 bus_release_resource(dev, SYS_RES_IOPORT,
82 if (isa_get_drq(dev) != -1) {
84 drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &rid, RF_ACTIVE);
87 bus_release_resource(dev, SYS_RES_IOPORT,
90 bus_release_resource(dev, SYS_RES_IRQ,
97 bt_init_softc(dev, port, irq, drq);
103 bt_isa_release_resources(device_t dev)
105 struct bt_softc *bt = device_get_softc(dev);
108 bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->port);
110 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
112 bus_release_resource(dev, SYS_RES_DRQ, 0, bt->drq);
117 * Check if the device can be found at the port given
118 * and if so, set it up ready for further work
119 * as an argument, takes the isa_device structure from
123 bt_isa_probe(device_t dev)
126 * find unit and check we have that many defined
132 if (isa_get_vendorid(dev))
136 max_port_index = BT_NUM_ISAPORTS - 1;
138 * Bound our board search if the user has
139 * specified an exact port.
141 bt_find_probe_range(isa_get_port(dev), &port_index, &max_port_index);
146 /* Attempt to find an adapter */
147 for (;port_index <= max_port_index; port_index++) {
148 struct bt_probe_info info;
151 ioport = bt_iop_from_bio(port_index);
154 * Ensure this port has not already been claimed already
155 * by a PCI, ISA adapter.
157 if (bt_check_probed_iop(ioport) != 0)
160 /* Initialise the softc for use during probing */
161 if (bt_isa_alloc_resources(dev, ioport,
162 ioport + BT_NREGS -1) != 0)
165 /* We're going to attempt to probe it now, so mark it probed */
166 bt_mark_probed_bio(port_index);
168 if (bt_port_probe(dev, &info) != 0) {
170 printf("bt_isa_probe: Probe failed at 0x%x\n",
172 bt_isa_release_resources(dev);
176 bt_isa_release_resources(dev);
178 bus_set_resource(dev, SYS_RES_DRQ, 0, info.drq, 1);
179 bus_set_resource(dev, SYS_RES_IRQ, 0, info.irq, 1);
181 return (BUS_PROBE_DEFAULT);
188 * Attach all the sub-devices we can find
191 bt_isa_attach(device_t dev)
193 struct bt_softc *bt = device_get_softc(dev);
194 bus_dma_filter_t *filter;
199 /* Initialise softc */
200 error = bt_isa_alloc_resources(dev, 0, ~0);
202 device_printf(dev, "can't allocate resources in bt_isa_attach\n");
206 /* Program the DMA channel for external control */
207 if ((drq = isa_get_drq(dev)) != -1)
210 /* Allocate our parent dmatag */
213 lowaddr = BUS_SPACE_MAXADDR_24BIT;
214 if (bt->model[0] == '4') {
216 * This is a VL adapter. Typically, VL devices have access
217 * to the full 32bit address space. On BT-445S adapters
218 * prior to revision E, there is a hardware bug that causes
219 * corruption of transfers to/from addresses in the range of
220 * the BIOS modulo 16MB. The only properly functioning
221 * BT-445S Host Adapters have firmware version 3.37.
222 * If we encounter one of these adapters and the BIOS is
223 * installed, install a filter function for our bus_dma_map
224 * that will catch these accesses and bounce them to a safe
227 if (bt->bios_addr != 0
228 && strcmp(bt->model, "445S") == 0
229 && strcmp(bt->firmware_ver, "3.37") < 0) {
230 filter = btvlbouncefilter;
233 lowaddr = BUS_SPACE_MAXADDR_32BIT;
237 /* XXX Should be a child of the ISA or VL bus dma tag */
238 if (bus_dma_tag_create( /* parent */ bus_get_dma_tag(dev),
241 /* lowaddr */ lowaddr,
242 /* highaddr */ BUS_SPACE_MAXADDR,
244 /* filterarg */ filter_arg,
245 /* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
247 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
251 &bt->parent_dmat) != 0) {
252 bt_isa_release_resources(dev);
256 error = bt_init(dev);
258 bt_isa_release_resources(dev);
262 if (lowaddr != BUS_SPACE_MAXADDR_32BIT) {
263 /* DMA tag for our sense buffers */
264 if (bus_dma_tag_create(
265 /* parent */ bt->parent_dmat,
268 /* lowaddr */ BUS_SPACE_MAXADDR,
269 /* highaddr */ BUS_SPACE_MAXADDR,
271 /* filterarg */ NULL,
272 /* maxsize */ bt->max_ccbs *
273 sizeof(struct scsi_sense_data),
275 /* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
279 &bt->sense_dmat) != 0) {
280 bt_isa_release_resources(dev);
286 /* Allocation of sense buffers */
287 if (bus_dmamem_alloc(bt->sense_dmat,
288 (void **)&bt->sense_buffers,
289 BUS_DMA_NOWAIT, &bt->sense_dmamap) != 0) {
290 bt_isa_release_resources(dev);
296 /* And permanently map them */
297 bus_dmamap_load(bt->sense_dmat, bt->sense_dmamap,
299 bt->max_ccbs * sizeof(*bt->sense_buffers),
300 btmapsensebuffers, bt, /*flags*/0);
305 error = bt_attach(dev);
307 bt_isa_release_resources(dev);
314 #define BIOS_MAP_SIZE (16 * 1024)
317 btvlbouncefilter(void *arg, bus_addr_t addr)
321 bt = (struct bt_softc *)arg;
323 addr &= BUS_SPACE_MAXADDR_24BIT;
326 || (addr >= bt->bios_addr
327 && addr < (bt->bios_addr + BIOS_MAP_SIZE)))
333 btmapsensebuffers(void *arg, bus_dma_segment_t *segs, int nseg, int error)
337 bt = (struct bt_softc*)arg;
338 bt->sense_buffers_physbase = segs->ds_addr;
341 static device_method_t bt_isa_methods[] = {
342 /* Device interface */
343 DEVMETHOD(device_probe, bt_isa_probe),
344 DEVMETHOD(device_attach, bt_isa_attach),
349 static driver_t bt_isa_driver = {
352 sizeof(struct bt_softc),
355 static devclass_t bt_devclass;
357 DRIVER_MODULE(bt, isa, bt_isa_driver, bt_devclass, 0, 0);
358 MODULE_DEPEND(bt, isa, 1, 1, 1);