1998-09-15 07:39:55 +00:00
|
|
|
/*
|
|
|
|
* Product specific probe and attach routines for:
|
|
|
|
* Adaptec 154x.
|
|
|
|
*
|
|
|
|
* Derived from code written by:
|
|
|
|
*
|
|
|
|
* Copyright (c) 1998 Justin T. Gibbs
|
|
|
|
* 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.
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1999-01-20 06:21:27 +00:00
|
|
|
#include <sys/kernel.h>
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
#include <machine/bus_pio.h>
|
|
|
|
#include <machine/bus.h>
|
1999-09-28 02:39:45 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
|
|
|
#include <isa/isavar.h>
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
#include <dev/aha/ahareg.h>
|
|
|
|
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
static struct isa_pnp_id aha_ids[] = {
|
|
|
|
{AHA1542_PNP, NULL}, /* ADP1542 */
|
|
|
|
{AHA1542_PNPCOMPAT, NULL}, /* PNP00A0 */
|
|
|
|
{0}
|
1998-09-15 07:39:55 +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-09-28 02:39:45 +00:00
|
|
|
aha_isa_probe(device_t dev)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* find unit and check we have that many defined
|
|
|
|
*/
|
1999-09-28 02:39:45 +00:00
|
|
|
struct aha_softc **sc = device_get_softc(dev);
|
1998-09-15 07:39:55 +00:00
|
|
|
struct aha_softc *aha;
|
|
|
|
int port_index;
|
1998-11-10 06:44:54 +00:00
|
|
|
int max_port_index;
|
1999-09-28 02:39:45 +00:00
|
|
|
int error;
|
|
|
|
u_long port_start, port_count;
|
|
|
|
struct resource *port_res;
|
|
|
|
int port_rid;
|
|
|
|
int drq;
|
|
|
|
int irq;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
aha = NULL;
|
1998-11-10 06:44:54 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
/* Check isapnp ids */
|
|
|
|
if (ISA_PNP_PROBE(device_get_parent(dev), dev, aha_ids) == ENXIO)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
error = ISA_GET_RESOURCE(device_get_parent(dev), dev, SYS_RES_IOPORT,
|
|
|
|
0, &port_start, &port_count);
|
|
|
|
if (error != 0)
|
|
|
|
port_start = 0;
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
/*
|
|
|
|
* Bound our board search if the user has
|
|
|
|
* specified an exact port.
|
|
|
|
*/
|
1999-09-28 02:39:45 +00:00
|
|
|
aha_find_probe_range(port_start, &port_index, &max_port_index);
|
1998-11-10 06:44:54 +00:00
|
|
|
|
|
|
|
if (port_index < 0)
|
1999-09-28 02:39:45 +00:00
|
|
|
return ENXIO;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* Attempt to find an adapter */
|
|
|
|
for (;port_index <= max_port_index; port_index++) {
|
|
|
|
config_data_t config_data;
|
|
|
|
u_int ioport;
|
|
|
|
int error;
|
|
|
|
|
1998-11-10 06:44:54 +00:00
|
|
|
ioport = aha_iop_from_bio(port_index);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure this port has not already been claimed already
|
1999-09-28 19:59:41 +00:00
|
|
|
* by another adapter.
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
|
|
|
if (aha_check_probed_iop(ioport) != 0)
|
|
|
|
continue;
|
1999-09-28 02:39:45 +00:00
|
|
|
error = ISA_SET_RESOURCE(device_get_parent(dev), dev,
|
|
|
|
SYS_RES_IOPORT, 0, ioport, AHA_NREGS);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
port_rid = 0;
|
|
|
|
port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid,
|
|
|
|
0, ~0, AHA_NREGS, RF_ACTIVE);
|
|
|
|
if (!port_res)
|
1998-10-10 00:44:12 +00:00
|
|
|
continue;
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
/* Allocate a softc for use during probing */
|
1999-09-28 19:59:41 +00:00
|
|
|
aha = aha_alloc(device_get_unit(dev), rman_get_bustag(port_res),
|
|
|
|
rman_get_bushandle(port_res));
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
if (aha == NULL) {
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
|
|
|
|
port_res);
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
1999-09-28 02:39:45 +00:00
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* We're going to attempt to probe it now, so mark it probed */
|
|
|
|
aha_mark_probed_bio(port_index);
|
|
|
|
|
|
|
|
/* See if there is really a card present */
|
|
|
|
if (aha_probe(aha) || aha_fetch_adapter_info(aha)) {
|
|
|
|
aha_free(aha);
|
1999-09-28 02:39:45 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
|
|
|
|
port_res);
|
1998-09-15 07:39:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine our IRQ, and DMA settings and
|
|
|
|
* export them to the configuration system.
|
|
|
|
*/
|
1998-11-10 06:44:54 +00:00
|
|
|
error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
|
1999-09-28 02:39:45 +00:00
|
|
|
(u_int8_t*)&config_data, sizeof(config_data),
|
|
|
|
DEFAULT_CMD_TIMEOUT);
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
if (error != 0) {
|
|
|
|
printf("aha_isa_probe: Could not determine IRQ or DMA "
|
1999-09-28 02:39:45 +00:00
|
|
|
"settings for adapter at 0x%x. Failing probe\n",
|
|
|
|
ioport);
|
1998-09-15 07:39:55 +00:00
|
|
|
aha_free(aha);
|
1999-09-28 02:39:45 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid,
|
|
|
|
port_res);
|
1998-09-15 07:39:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
switch (config_data.dma_chan) {
|
|
|
|
case DMA_CHAN_5:
|
1999-09-28 02:39:45 +00:00
|
|
|
drq = 5;
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case DMA_CHAN_6:
|
1999-09-28 02:39:45 +00:00
|
|
|
drq = 6;
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case DMA_CHAN_7:
|
1999-09-28 02:39:45 +00:00
|
|
|
drq = 7;
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("aha_isa_probe: Invalid DMA setting "
|
1999-09-28 02:39:45 +00:00
|
|
|
"detected for adapter at 0x%x. "
|
|
|
|
"Failing probe\n", ioport);
|
|
|
|
return (ENXIO);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
1999-09-28 02:39:45 +00:00
|
|
|
error = ISA_SET_RESOURCE(device_get_parent(dev), dev,
|
|
|
|
SYS_RES_DRQ, 0, drq, 1);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
irq = ffs(config_data.irq) + 8;
|
|
|
|
error = ISA_SET_RESOURCE(device_get_parent(dev), dev,
|
|
|
|
SYS_RES_IRQ, 0, irq, 1);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
*sc = aha;
|
1998-09-15 07:39:55 +00:00
|
|
|
aha_unit++;
|
1999-09-28 02:39:45 +00:00
|
|
|
|
|
|
|
return (0);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
*/
|
|
|
|
static int
|
1999-09-28 02:39:45 +00:00
|
|
|
aha_isa_attach(device_t dev)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
1999-09-28 02:39:45 +00:00
|
|
|
struct aha_softc **sc = device_get_softc(dev);
|
1998-09-15 07:39:55 +00:00
|
|
|
struct aha_softc *aha;
|
|
|
|
bus_dma_filter_t *filter;
|
|
|
|
void *filter_arg;
|
|
|
|
bus_addr_t lowaddr;
|
1999-09-28 02:39:45 +00:00
|
|
|
struct resource *port_res;
|
|
|
|
int port_rid;
|
|
|
|
struct resource *irq_res;
|
|
|
|
int irq_rid;
|
|
|
|
struct resource *drq_res;
|
|
|
|
int drq_rid;
|
|
|
|
void *ih;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
port_rid = 0;
|
|
|
|
port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid,
|
|
|
|
0, ~0, AHA_NREGS, RF_ACTIVE);
|
|
|
|
if (!port_res) {
|
|
|
|
device_printf(dev, "Unable to allocate I/O ports\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
irq_rid = 0;
|
|
|
|
irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &irq_rid, 0, ~0, 1,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (!irq_res) {
|
|
|
|
device_printf(dev, "Unable to allocate excluse use of irq\n");
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
drq_rid = 0;
|
|
|
|
drq_res = bus_alloc_resource(dev, SYS_RES_DRQ, &drq_rid, 0, ~0, 1,
|
|
|
|
RF_ACTIVE);
|
|
|
|
if (!drq_res) {
|
|
|
|
device_printf(dev, "Unable to allocate drq\n");
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
aha = *sc;
|
|
|
|
#if 0 /* is the drq ever unset? */
|
1998-09-15 07:39:55 +00:00
|
|
|
if (dev->id_drq != -1)
|
|
|
|
isa_dmacascade(dev->id_drq);
|
1999-09-28 02:39:45 +00:00
|
|
|
#endif
|
|
|
|
isa_dmacascade(rman_get_start(drq_res));
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* Allocate our parent dmatag */
|
|
|
|
filter = NULL;
|
|
|
|
filter_arg = NULL;
|
|
|
|
lowaddr = BUS_SPACE_MAXADDR_24BIT;
|
|
|
|
|
1999-08-16 01:52:21 +00:00
|
|
|
if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
|
1999-09-28 02:39:45 +00:00
|
|
|
lowaddr, /*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
filter, filter_arg,
|
|
|
|
/*maxsize*/BUS_SPACE_MAXSIZE_24BIT,
|
|
|
|
/*nsegments*/BUS_SPACE_UNRESTRICTED,
|
|
|
|
/*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT,
|
|
|
|
/*flags*/0, &aha->parent_dmat) != 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
aha_free(aha);
|
1999-09-28 02:39:45 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_DRQ, drq_rid, drq_res);
|
|
|
|
return (ENOMEM);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aha_init(aha)) {
|
1999-09-28 02:39:45 +00:00
|
|
|
device_printf(dev, "init failed\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
aha_free(aha);
|
1999-09-28 02:39:45 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_DRQ, drq_rid, drq_res);
|
|
|
|
return (ENOMEM);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
error = aha_attach(aha);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "attach failed\n");
|
|
|
|
aha_free(aha);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_DRQ, drq_rid, drq_res);
|
|
|
|
return (error);
|
|
|
|
}
|
1999-01-20 06:21:27 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
error = bus_setup_intr(dev, irq_res, INTR_TYPE_CAM, aha_intr, aha,
|
|
|
|
&ih);
|
|
|
|
if (error) {
|
|
|
|
device_printf(dev, "Unable to register interrupt handler\n");
|
|
|
|
aha_free(aha);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, port_rid, port_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, irq_rid, irq_res);
|
|
|
|
bus_release_resource(dev, SYS_RES_DRQ, drq_rid, drq_res);
|
|
|
|
return (error);
|
1999-01-20 06:21:27 +00:00
|
|
|
}
|
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
return (0);
|
1999-01-20 06:21:27 +00:00
|
|
|
}
|
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
static device_method_t aha_isa_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, aha_isa_probe),
|
|
|
|
DEVMETHOD(device_attach, aha_isa_attach),
|
1999-01-20 06:21:27 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
1999-01-20 06:21:27 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
static driver_t aha_isa_driver = {
|
|
|
|
"aha",
|
|
|
|
aha_isa_methods,
|
|
|
|
sizeof(struct aha_softc*),
|
|
|
|
};
|
1999-01-20 06:21:27 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
static devclass_t aha_devclass;
|
1999-01-20 06:21:27 +00:00
|
|
|
|
1999-09-28 02:39:45 +00:00
|
|
|
DRIVER_MODULE(aha, isa, aha_isa_driver, aha_devclass, 0, 0);
|