2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1998-09-15 07:05:39 +00:00
|
|
|
* Device probe and attach routines for the following
|
|
|
|
* Advanced Systems Inc. SCSI controllers:
|
|
|
|
*
|
|
|
|
* Single Channel Products:
|
|
|
|
* ABP742 - Bus-Master EISA (240 CDB)
|
|
|
|
*
|
|
|
|
* Dual Channel Products:
|
|
|
|
* ABP752 - Dual Channel Bus-Master EISA (240 CDB Per Channel)
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 Justin 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-15 07:05:39 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
1999-04-18 15:50:35 +00:00
|
|
|
#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:05:39 +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:05:39 +00:00
|
|
|
|
2000-01-14 07:14:17 +00:00
|
|
|
#include <dev/eisa/eisaconf.h>
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
#include <dev/advansys/advansys.h>
|
|
|
|
|
|
|
|
#define EISA_DEVICE_ID_ADVANSYS_740 0x04507400
|
|
|
|
#define EISA_DEVICE_ID_ADVANSYS_750 0x04507500
|
|
|
|
|
|
|
|
#define ADV_EISA_SLOT_OFFSET 0xc00
|
|
|
|
#define ADV_EISA_OFFSET_CHAN1 0x30
|
|
|
|
#define ADV_EISA_OFFSET_CHAN2 0x50
|
|
|
|
#define ADV_EISA_IOSIZE 0x100
|
|
|
|
|
|
|
|
#define ADV_EISA_ROM_BIOS_ADDR_REG 0x86
|
|
|
|
#define ADV_EISA_IRQ_BURST_LEN_REG 0x87
|
|
|
|
#define ADV_EISA_IRQ_MASK 0x07
|
|
|
|
#define ADV_EISA_IRQ_10 0x00
|
|
|
|
#define ADV_EISA_IRQ_11 0x01
|
|
|
|
#define ADV_EISA_IRQ_12 0x02
|
|
|
|
#define ADV_EISA_IRQ_14 0x04
|
|
|
|
#define ADV_EISA_IRQ_15 0x05
|
|
|
|
|
|
|
|
#define ADV_EISA_MAX_DMA_ADDR (0x07FFFFFFL)
|
|
|
|
#define ADV_EISA_MAX_DMA_COUNT (0x07FFFFFFL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The overrun buffer shared amongst all EISA adapters.
|
|
|
|
*/
|
2006-02-04 22:33:08 +00:00
|
|
|
static void* overrun_buf;
|
1998-12-22 18:14:15 +00:00
|
|
|
static bus_dma_tag_t overrun_dmat;
|
|
|
|
static bus_dmamap_t overrun_dmamap;
|
|
|
|
static bus_addr_t overrun_physbase;
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
static const char*
|
2000-04-07 11:32:42 +00:00
|
|
|
adv_eisa_match(eisa_id_t type)
|
1998-09-15 07:05:39 +00:00
|
|
|
{
|
|
|
|
switch (type & ~0xF) {
|
|
|
|
case EISA_DEVICE_ID_ADVANSYS_740:
|
|
|
|
return ("AdvanSys ABP-740/742 SCSI adapter");
|
|
|
|
break;
|
|
|
|
case EISA_DEVICE_ID_ADVANSYS_750:
|
|
|
|
return ("AdvanSys ABP-750/752 SCSI adapter");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-07 11:32:42 +00:00
|
|
|
adv_eisa_probe(device_t dev)
|
1998-09-15 07:05:39 +00:00
|
|
|
{
|
1999-04-18 15:50:35 +00:00
|
|
|
const char *desc;
|
1998-09-15 07:05:39 +00:00
|
|
|
u_int32_t iobase;
|
|
|
|
u_int8_t irq;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
2000-04-07 11:32:42 +00:00
|
|
|
desc = adv_eisa_match(eisa_get_id(dev));
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!desc)
|
|
|
|
return (ENXIO);
|
|
|
|
device_set_desc(dev, desc);
|
|
|
|
|
2000-04-07 11:32:42 +00:00
|
|
|
iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + ADV_EISA_SLOT_OFFSET;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
eisa_add_iospace(dev, iobase, ADV_EISA_IOSIZE, RESVADDR_NONE);
|
|
|
|
irq = inb(iobase + ADV_EISA_IRQ_BURST_LEN_REG);
|
|
|
|
irq &= ADV_EISA_IRQ_MASK;
|
|
|
|
switch (irq) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("adv at slot %d: illegal "
|
|
|
|
"irq setting %d\n", eisa_get_slot(dev),
|
|
|
|
irq);
|
|
|
|
return ENXIO;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
1999-08-01 22:57:09 +00:00
|
|
|
eisa_add_intr(dev, irq + 10, EISA_TRIGGER_LEVEL);
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
return 0;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-04-07 11:32:42 +00:00
|
|
|
adv_eisa_attach(device_t dev)
|
1998-09-15 07:05:39 +00:00
|
|
|
{
|
|
|
|
struct adv_softc *adv;
|
|
|
|
struct adv_softc *adv_b;
|
1999-04-18 15:50:35 +00:00
|
|
|
struct resource *io;
|
|
|
|
struct resource *irq;
|
|
|
|
int rid, error;
|
|
|
|
void *ih;
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
adv_b = NULL;
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
io = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid, RF_ACTIVE);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!io) {
|
|
|
|
device_printf(dev, "No I/O space?!\n");
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
1998-09-15 07:05:39 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
|
|
|
RF_SHAREABLE | RF_ACTIVE);
|
1999-04-18 15:50:35 +00:00
|
|
|
if (!irq) {
|
|
|
|
device_printf(dev, "No irq?!\n");
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
|
|
|
|
return ENOMEM;
|
1998-09-15 07:05:39 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
}
|
1998-09-15 07:05:39 +00:00
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
switch (eisa_get_id(dev) & ~0xF) {
|
1998-09-15 07:05:39 +00:00
|
|
|
case EISA_DEVICE_ID_ADVANSYS_750:
|
2000-04-07 11:32:42 +00:00
|
|
|
adv_b = adv_alloc(dev, rman_get_bustag(io),
|
1999-04-18 15:50:35 +00:00
|
|
|
rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN2);
|
1998-09-15 07:05:39 +00:00
|
|
|
if (adv_b == NULL)
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a parent dmatag for all tags created
|
|
|
|
* by the MI portions of the advansys driver
|
|
|
|
*/
|
|
|
|
/* XXX Should be a child of the PCI bus dma tag */
|
2003-03-29 09:46:10 +00:00
|
|
|
error = bus_dma_tag_create(
|
|
|
|
/* parent */ NULL,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ ADV_EISA_MAX_DMA_ADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* nsegments */ ~0,
|
|
|
|
/* maxsegsz */ ADV_EISA_MAX_DMA_COUNT,
|
|
|
|
/* flags */ 0,
|
2003-07-01 15:52:06 +00:00
|
|
|
/* lockfunc */ busdma_lock_mutex,
|
|
|
|
/* lockarg */ &Giant,
|
2003-03-29 09:46:10 +00:00
|
|
|
&adv_b->parent_dmat);
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
if (error != 0) {
|
|
|
|
printf("%s: Could not allocate DMA tag - error %d\n",
|
|
|
|
adv_name(adv_b), error);
|
|
|
|
adv_free(adv_b);
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adv_b->init_level++;
|
|
|
|
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case EISA_DEVICE_ID_ADVANSYS_740:
|
2000-04-07 11:32:42 +00:00
|
|
|
adv = adv_alloc(dev, rman_get_bustag(io),
|
1999-04-18 15:50:35 +00:00
|
|
|
rman_get_bushandle(io) + ADV_EISA_OFFSET_CHAN1);
|
1998-09-15 07:05:39 +00:00
|
|
|
if (adv == NULL) {
|
|
|
|
if (adv_b != NULL)
|
|
|
|
adv_free(adv_b);
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a parent dmatag for all tags created
|
|
|
|
* by the MI portions of the advansys driver
|
|
|
|
*/
|
|
|
|
/* XXX Should be a child of the PCI bus dma tag */
|
2003-03-29 09:46:10 +00:00
|
|
|
error = bus_dma_tag_create(
|
|
|
|
/* parent */ NULL,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ ADV_EISA_MAX_DMA_ADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* nsegments */ ~0,
|
|
|
|
/* maxsegsz */ ADV_EISA_MAX_DMA_COUNT,
|
|
|
|
/* flags */ 0,
|
2003-07-01 15:52:06 +00:00
|
|
|
/* lockfunc */ busdma_lock_mutex,
|
|
|
|
/* lockarg */ &Giant,
|
2003-03-29 09:46:10 +00:00
|
|
|
&adv->parent_dmat);
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
if (error != 0) {
|
|
|
|
printf("%s: Could not allocate DMA tag - error %d\n",
|
|
|
|
adv_name(adv), error);
|
|
|
|
adv_free(adv);
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adv->init_level++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("adveisaattach: Unknown device type!\n");
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (overrun_buf == NULL) {
|
|
|
|
/* Need to allocate our overrun buffer */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create(
|
|
|
|
/* parent */ adv->parent_dmat,
|
|
|
|
/* alignment */ 8,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ ADV_EISA_MAX_DMA_ADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ ADV_OVERRUN_BSIZE,
|
|
|
|
/* nsegments */ 1,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* flags */ 0,
|
2003-07-01 15:52:06 +00:00
|
|
|
/* lockfunc */ busdma_lock_mutex,
|
|
|
|
/* lockarg */ &Giant,
|
2003-03-29 09:46:10 +00:00
|
|
|
&overrun_dmat) != 0) {
|
1998-09-15 07:05:39 +00:00
|
|
|
adv_free(adv);
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
if (bus_dmamem_alloc(overrun_dmat,
|
2006-02-04 22:33:08 +00:00
|
|
|
&overrun_buf,
|
1998-09-15 07:05:39 +00:00
|
|
|
BUS_DMA_NOWAIT,
|
|
|
|
&overrun_dmamap) != 0) {
|
|
|
|
bus_dma_tag_destroy(overrun_dmat);
|
|
|
|
adv_free(adv);
|
1999-04-18 15:50:35 +00:00
|
|
|
goto bad;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
/* And permanently map it in */
|
|
|
|
bus_dmamap_load(overrun_dmat, overrun_dmamap,
|
|
|
|
overrun_buf, ADV_OVERRUN_BSIZE,
|
|
|
|
adv_map, &overrun_physbase,
|
|
|
|
/*flags*/0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we know we own the resources we need, do the
|
|
|
|
* card initialization.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop the chip.
|
|
|
|
*/
|
|
|
|
ADV_OUTB(adv, ADV_CHIP_CTRL, ADV_CC_HALT);
|
|
|
|
ADV_OUTW(adv, ADV_CHIP_STATUS, 0);
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
adv->chip_version = EISA_REVISION_ID(eisa_get_id(dev))
|
1998-09-15 07:05:39 +00:00
|
|
|
+ ADV_CHIP_MIN_VER_EISA - 1;
|
|
|
|
|
|
|
|
if (adv_init(adv) != 0) {
|
|
|
|
adv_free(adv);
|
|
|
|
if (adv_b != NULL)
|
|
|
|
adv_free(adv_b);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
adv->max_dma_count = ADV_EISA_MAX_DMA_COUNT;
|
|
|
|
adv->max_dma_addr = ADV_EISA_MAX_DMA_ADDR;
|
|
|
|
|
|
|
|
if (adv_b != NULL) {
|
|
|
|
/*
|
|
|
|
* Stop the chip.
|
|
|
|
*/
|
|
|
|
ADV_OUTB(adv_b, ADV_CHIP_CTRL, ADV_CC_HALT);
|
|
|
|
ADV_OUTW(adv_b, ADV_CHIP_STATUS, 0);
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
adv_b->chip_version = EISA_REVISION_ID(eisa_get_id(dev))
|
1998-09-15 07:05:39 +00:00
|
|
|
+ ADV_CHIP_MIN_VER_EISA - 1;
|
|
|
|
|
|
|
|
if (adv_init(adv_b) != 0) {
|
|
|
|
adv_free(adv_b);
|
|
|
|
} else {
|
|
|
|
adv_b->max_dma_count = ADV_EISA_MAX_DMA_COUNT;
|
|
|
|
adv_b->max_dma_addr = ADV_EISA_MAX_DMA_ADDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable our interrupt handler.
|
|
|
|
*/
|
2007-02-23 12:19:07 +00:00
|
|
|
bus_setup_intr(dev, irq, INTR_TYPE_CAM|INTR_ENTROPY, NULL, adv_intr,
|
|
|
|
adv, &ih);
|
1998-09-15 07:05:39 +00:00
|
|
|
|
|
|
|
/* Attach sub-devices - always succeeds */
|
|
|
|
adv_attach(adv);
|
|
|
|
if (adv_b != NULL)
|
|
|
|
adv_attach(adv_b);
|
|
|
|
|
|
|
|
return 0;
|
1999-04-18 15:50:35 +00:00
|
|
|
|
|
|
|
bad:
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
|
|
|
|
bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
|
|
|
|
return -1;
|
1998-09-15 07:05:39 +00:00
|
|
|
}
|
|
|
|
|
1999-04-18 15:50:35 +00:00
|
|
|
static device_method_t adv_eisa_methods[] = {
|
|
|
|
/* Device interface */
|
2000-04-07 11:32:42 +00:00
|
|
|
DEVMETHOD(device_probe, adv_eisa_probe),
|
|
|
|
DEVMETHOD(device_attach, adv_eisa_attach),
|
1999-04-18 15:50:35 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t adv_eisa_driver = {
|
2000-04-07 11:32:42 +00:00
|
|
|
"adv", adv_eisa_methods, sizeof(struct adv_softc)
|
1999-04-18 15:50:35 +00:00
|
|
|
};
|
|
|
|
|
2000-04-07 11:32:42 +00:00
|
|
|
static devclass_t adv_eisa_devclass;
|
|
|
|
DRIVER_MODULE(adv, eisa, adv_eisa_driver, adv_eisa_devclass, 0, 0);
|
2006-12-11 18:28:31 +00:00
|
|
|
MODULE_DEPEND(adv, eisa, 1, 1, 1);
|