2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1998-09-15 07:32:57 +00:00
|
|
|
* Product specific probe and attach routines for:
|
|
|
|
* Buslogic BT-54X and BT-445 cards
|
|
|
|
*
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
1999-03-08 21:32:59 +00:00
|
|
|
* Copyright (c) 1998, 1999 Justin T. Gibbs
|
1998-09-15 07:32:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-15 07:32:57 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
2003-07-01 15:52:06 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <sys/bus.h>
|
1998-09-15 07:32:57 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
1998-09-15 07:32:57 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
#include <isa/isavar.h>
|
1998-09-15 07:32:57 +00:00
|
|
|
#include <dev/buslogic/btreg.h>
|
|
|
|
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
|
|
|
|
static bus_dma_filter_t btvlbouncefilter;
|
|
|
|
static bus_dmamap_callback_t btmapsensebuffers;
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
static int
|
1999-05-22 15:45:47 +00:00
|
|
|
bt_isa_alloc_resources(device_t dev, u_long portstart, u_long portend)
|
1998-09-15 07:32:57 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
int rid;
|
|
|
|
struct resource *port;
|
|
|
|
struct resource *irq;
|
|
|
|
struct resource *drq;
|
|
|
|
|
|
|
|
rid = 0;
|
|
|
|
port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
|
1999-05-22 15:45:47 +00:00
|
|
|
portstart, portend, BT_NREGS, RF_ACTIVE);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!port)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
if (isa_get_irq(dev) != -1) {
|
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!irq) {
|
|
|
|
if (port)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT,
|
|
|
|
0, port);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
} else
|
2012-10-15 16:13:55 +00:00
|
|
|
irq = NULL;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
if (isa_get_drq(dev) != -1) {
|
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &rid, RF_ACTIVE);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!drq) {
|
|
|
|
if (port)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT,
|
|
|
|
0, port);
|
|
|
|
if (irq)
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ,
|
|
|
|
0, irq);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
} else
|
2012-10-15 16:13:55 +00:00
|
|
|
drq = NULL;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
bt_init_softc(dev, port, irq, drq);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bt_isa_release_resources(device_t dev)
|
|
|
|
{
|
|
|
|
struct bt_softc *bt = device_get_softc(dev);
|
|
|
|
|
|
|
|
if (bt->port)
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->port);
|
|
|
|
if (bt->irq)
|
1999-04-18 19:08:28 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (bt->drq)
|
1999-04-18 19:08:28 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_DRQ, 0, bt->drq);
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_free_softc(dev);
|
|
|
|
}
|
1998-09-15 07:32:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the device can be found at the port given
|
|
|
|
* and if so, set it up ready for further work
|
|
|
|
* as an argument, takes the isa_device structure from
|
|
|
|
* autoconf.c
|
|
|
|
*/
|
|
|
|
static int
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_probe(device_t dev)
|
1998-09-15 07:32:57 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* find unit and check we have that many defined
|
|
|
|
*/
|
|
|
|
int port_index;
|
|
|
|
int max_port_index;
|
|
|
|
|
1999-05-30 11:10:10 +00:00
|
|
|
/* No pnp support */
|
|
|
|
if (isa_get_vendorid(dev))
|
|
|
|
return (ENXIO);
|
|
|
|
|
1998-09-15 07:32:57 +00:00
|
|
|
port_index = 0;
|
|
|
|
max_port_index = BT_NUM_ISAPORTS - 1;
|
|
|
|
/*
|
|
|
|
* Bound our board search if the user has
|
|
|
|
* specified an exact port.
|
|
|
|
*/
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_find_probe_range(isa_get_port(dev), &port_index, &max_port_index);
|
1998-11-10 06:44:54 +00:00
|
|
|
|
|
|
|
if (port_index < 0)
|
1999-04-18 15:50:35 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:32:57 +00:00
|
|
|
|
|
|
|
/* Attempt to find an adapter */
|
|
|
|
for (;port_index <= max_port_index; port_index++) {
|
1999-03-08 21:32:59 +00:00
|
|
|
struct bt_probe_info info;
|
1998-09-15 07:32:57 +00:00
|
|
|
u_int ioport;
|
|
|
|
|
1998-11-10 06:44:54 +00:00
|
|
|
ioport = bt_iop_from_bio(port_index);
|
1998-09-15 07:32:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure this port has not already been claimed already
|
2017-02-16 21:57:25 +00:00
|
|
|
* by a PCI, ISA adapter.
|
1998-09-15 07:32:57 +00:00
|
|
|
*/
|
|
|
|
if (bt_check_probed_iop(ioport) != 0)
|
|
|
|
continue;
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
/* Initialise the softc for use during probing */
|
1999-05-22 15:45:47 +00:00
|
|
|
if (bt_isa_alloc_resources(dev, ioport,
|
|
|
|
ioport + BT_NREGS -1) != 0)
|
1999-04-18 15:50:35 +00:00
|
|
|
continue;
|
1998-09-15 07:32:57 +00:00
|
|
|
|
|
|
|
/* We're going to attempt to probe it now, so mark it probed */
|
|
|
|
bt_mark_probed_bio(port_index);
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
if (bt_port_probe(dev, &info) != 0) {
|
1999-06-03 20:56:09 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("bt_isa_probe: Probe failed at 0x%x\n",
|
|
|
|
ioport);
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_release_resources(dev);
|
1998-09-15 07:32:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_release_resources(dev);
|
|
|
|
|
* Add struct resource_list* argument to resource_list_alloc and
resource_list_release. This removes the dependancy on the
layout of ivars.
* Move set_resource, get_resource and delete_resource from
isa_if.m to bus_if.m.
* Simplify driver code by providing wrappers to those methods:
bus_set_resource(dev, type, rid, start, count);
bus_get_resource(dev, type, rid, startp, countp);
bus_get_resource_start(dev, type, rid);
bus_get_resource_count(dev, type, rid);
bus_delete_resource(dev, type, rid);
* Delete isa_get_rsrc and use bus_get_resource_start instead.
* Fix a stupid typo in isa_alloc_resource reported by Takahashi
Yoshihiro <nyan@FreeBSD.org>.
* Print a diagnostic message if we can't assign resources to a PnP
device.
* Change device_print_prettyname() so that it doesn't print
"(no driver assigned)-1" for anonymous devices.
1999-10-12 21:35:51 +00:00
|
|
|
bus_set_resource(dev, SYS_RES_DRQ, 0, info.drq, 1);
|
|
|
|
bus_set_resource(dev, SYS_RES_IRQ, 0, info.irq, 1);
|
1998-10-10 00:44:12 +00:00
|
|
|
|
2012-10-15 16:13:55 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
*/
|
|
|
|
static int
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_attach(device_t dev)
|
1998-09-15 07:32:57 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
struct bt_softc *bt = device_get_softc(dev);
|
1998-09-15 07:32:57 +00:00
|
|
|
bus_dma_filter_t *filter;
|
|
|
|
void *filter_arg;
|
|
|
|
bus_addr_t lowaddr;
|
1999-04-18 19:08:28 +00:00
|
|
|
int error, drq;
|
1998-09-15 07:32:57 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
/* Initialise softc */
|
1999-05-22 15:45:47 +00:00
|
|
|
error = bt_isa_alloc_resources(dev, 0, ~0);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "can't allocate resources in bt_isa_attach\n");
|
|
|
|
return error;
|
|
|
|
}
|
1998-09-15 07:32:57 +00:00
|
|
|
|
1999-04-18 19:08:28 +00:00
|
|
|
/* Program the DMA channel for external control */
|
|
|
|
if ((drq = isa_get_drq(dev)) != -1)
|
|
|
|
isa_dmacascade(drq);
|
|
|
|
|
1998-09-15 07:32:57 +00:00
|
|
|
/* Allocate our parent dmatag */
|
|
|
|
filter = NULL;
|
|
|
|
filter_arg = NULL;
|
|
|
|
lowaddr = BUS_SPACE_MAXADDR_24BIT;
|
|
|
|
if (bt->model[0] == '4') {
|
|
|
|
/*
|
|
|
|
* This is a VL adapter. Typically, VL devices have access
|
|
|
|
* to the full 32bit address space. On BT-445S adapters
|
|
|
|
* prior to revision E, there is a hardware bug that causes
|
|
|
|
* corruption of transfers to/from addresses in the range of
|
|
|
|
* the BIOS modulo 16MB. The only properly functioning
|
|
|
|
* BT-445S Host Adapters have firmware version 3.37.
|
|
|
|
* If we encounter one of these adapters and the BIOS is
|
|
|
|
* installed, install a filter function for our bus_dma_map
|
|
|
|
* that will catch these accesses and bounce them to a safe
|
|
|
|
* region of memory.
|
|
|
|
*/
|
|
|
|
if (bt->bios_addr != 0
|
|
|
|
&& strcmp(bt->model, "445S") == 0
|
|
|
|
&& strcmp(bt->firmware_ver, "3.37") < 0) {
|
|
|
|
filter = btvlbouncefilter;
|
|
|
|
filter_arg = bt;
|
|
|
|
} else {
|
|
|
|
lowaddr = BUS_SPACE_MAXADDR_32BIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX Should be a child of the ISA or VL bus dma tag */
|
2012-10-15 16:13:55 +00:00
|
|
|
if (bus_dma_tag_create( /* parent */ bus_get_dma_tag(dev),
|
2003-03-29 09:46:10 +00:00
|
|
|
/* alignemnt */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ lowaddr,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ filter,
|
|
|
|
/* filterarg */ filter_arg,
|
|
|
|
/* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* nsegments */ ~0,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* flags */ 0,
|
2012-10-15 16:13:55 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-03-29 09:46:10 +00:00
|
|
|
&bt->parent_dmat) != 0) {
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_release_resources(dev);
|
|
|
|
return (ENOMEM);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
1999-04-18 19:08:28 +00:00
|
|
|
error = bt_init(dev);
|
|
|
|
if (error) {
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_release_resources(dev);
|
|
|
|
return (ENOMEM);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lowaddr != BUS_SPACE_MAXADDR_32BIT) {
|
|
|
|
/* DMA tag for our sense buffers */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create(
|
|
|
|
/* parent */ bt->parent_dmat,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ bt->max_ccbs *
|
|
|
|
sizeof(struct scsi_sense_data),
|
|
|
|
/* nsegments */ 1,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* flags */ 0,
|
2012-10-15 16:13:55 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-03-29 09:46:10 +00:00
|
|
|
&bt->sense_dmat) != 0) {
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_release_resources(dev);
|
|
|
|
return (ENOMEM);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bt->init_level++;
|
|
|
|
|
|
|
|
/* Allocation of sense buffers */
|
|
|
|
if (bus_dmamem_alloc(bt->sense_dmat,
|
|
|
|
(void **)&bt->sense_buffers,
|
|
|
|
BUS_DMA_NOWAIT, &bt->sense_dmamap) != 0) {
|
1999-04-18 15:50:35 +00:00
|
|
|
bt_isa_release_resources(dev);
|
|
|
|
return (ENOMEM);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bt->init_level++;
|
|
|
|
|
|
|
|
/* And permanently map them */
|
|
|
|
bus_dmamap_load(bt->sense_dmat, bt->sense_dmamap,
|
|
|
|
bt->sense_buffers,
|
|
|
|
bt->max_ccbs * sizeof(*bt->sense_buffers),
|
|
|
|
btmapsensebuffers, bt, /*flags*/0);
|
|
|
|
|
|
|
|
bt->init_level++;
|
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
error = bt_attach(dev);
|
|
|
|
if (error) {
|
|
|
|
bt_isa_release_resources(dev);
|
|
|
|
return (error);
|
|
|
|
}
|
1998-09-15 07:32:57 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
return (0);
|
1998-09-15 07:32:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define BIOS_MAP_SIZE (16 * 1024)
|
|
|
|
|
|
|
|
static int
|
|
|
|
btvlbouncefilter(void *arg, bus_addr_t addr)
|
|
|
|
{
|
|
|
|
struct bt_softc *bt;
|
|
|
|
|
|
|
|
bt = (struct bt_softc *)arg;
|
|
|
|
|
|
|
|
addr &= BUS_SPACE_MAXADDR_24BIT;
|
|
|
|
|
|
|
|
if (addr == 0
|
|
|
|
|| (addr >= bt->bios_addr
|
|
|
|
&& addr < (bt->bios_addr + BIOS_MAP_SIZE)))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
btmapsensebuffers(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
struct bt_softc* bt;
|
|
|
|
|
|
|
|
bt = (struct bt_softc*)arg;
|
|
|
|
bt->sense_buffers_physbase = segs->ds_addr;
|
|
|
|
}
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
static device_method_t bt_isa_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, bt_isa_probe),
|
|
|
|
DEVMETHOD(device_attach, bt_isa_attach),
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t bt_isa_driver = {
|
|
|
|
"bt",
|
|
|
|
bt_isa_methods,
|
|
|
|
sizeof(struct bt_softc),
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t bt_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(bt, isa, bt_isa_driver, bt_devclass, 0, 0);
|
2006-12-11 18:28:31 +00:00
|
|
|
MODULE_DEPEND(bt, isa, 1, 1, 1);
|