1998-01-26 06:11:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 by Simon Shapiro
|
|
|
|
* 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. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1998-09-15 08:33:38 +00:00
|
|
|
* dptpci.c: PCI Bus Attachment for DPT SCSI HBAs
|
1998-01-26 06:11:18 +00:00
|
|
|
*/
|
|
|
|
|
1999-08-28 01:08:13 +00:00
|
|
|
#ident "$FreeBSD$"
|
1998-01-26 06:11:18 +00:00
|
|
|
|
|
|
|
#include "opt_dpt.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#include <pci/pcivar.h>
|
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
#include <machine/bus_memio.h>
|
|
|
|
#include <machine/bus_pio.h>
|
|
|
|
#include <machine/bus.h>
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
|
|
|
|
#include <dev/dpt/dpt.h>
|
|
|
|
#include <pci/dpt_pci.h>
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
#define PCI_BASEADR0 PCI_MAP_REG_START /* I/O Address */
|
1998-01-26 06:11:18 +00:00
|
|
|
#define PCI_BASEADR1 PCI_MAP_REG_START + 4 /* Mem I/O Address */
|
|
|
|
|
|
|
|
#define ISA_PRIMARY_WD_ADDRESS 0x1f8
|
|
|
|
|
|
|
|
/* Global variables */
|
|
|
|
|
|
|
|
/* Function Prototypes */
|
|
|
|
|
1998-12-14 06:37:37 +00:00
|
|
|
static const char *dpt_pci_probe(pcici_t tag, pcidi_t type);
|
1998-02-10 17:36:44 +00:00
|
|
|
static void dpt_pci_attach(pcici_t config_id, int unit);
|
1998-01-26 06:11:18 +00:00
|
|
|
|
|
|
|
extern struct cdevsw dpt_cdevsw;
|
|
|
|
|
|
|
|
static struct pci_device dpt_pci_driver =
|
|
|
|
{
|
1998-09-15 08:33:38 +00:00
|
|
|
"dpt",
|
|
|
|
dpt_pci_probe,
|
|
|
|
dpt_pci_attach,
|
|
|
|
&dpt_unit,
|
|
|
|
NULL
|
1998-01-26 06:11:18 +00:00
|
|
|
};
|
|
|
|
|
1999-04-24 20:17:05 +00:00
|
|
|
COMPAT_PCI_DRIVER(dpt_pci, dpt_pci_driver);
|
1998-01-26 06:11:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe the PCI device.
|
|
|
|
* Some of this work will have to be duplicated in _attach
|
|
|
|
* because we do not know for sure how the two relate.
|
|
|
|
*/
|
|
|
|
|
1998-12-14 06:37:37 +00:00
|
|
|
static const char *
|
1998-01-26 06:11:18 +00:00
|
|
|
dpt_pci_probe(pcici_t tag, pcidi_t type)
|
|
|
|
{
|
1998-09-15 08:33:38 +00:00
|
|
|
u_int32_t class;
|
1998-01-26 06:11:18 +00:00
|
|
|
|
|
|
|
#ifndef PCI_COMMAND_MASTER_ENABLE
|
|
|
|
#define PCI_COMMAND_MASTER_ENABLE 0x00000004
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PCI_SUBCLASS_MASS_STORAGE_SCSI
|
|
|
|
#define PCI_SUBCLASS_MASS_STORAGE_SCSI 0x00000000
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class = pci_conf_read(tag, PCI_CLASS_REG);
|
1998-09-15 08:33:38 +00:00
|
|
|
if (((type & 0xffff0000) >> 16) == DPT_DEVICE_ID
|
|
|
|
&& (class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE
|
|
|
|
&& (class & PCI_SUBCLASS_MASK) == PCI_SUBCLASS_MASS_STORAGE_SCSI)
|
|
|
|
return ("DPT Caching SCSI RAID Controller");
|
|
|
|
return (NULL);
|
1998-01-26 06:11:18 +00:00
|
|
|
}
|
|
|
|
|
1998-02-10 17:36:44 +00:00
|
|
|
static void
|
1998-01-26 06:11:18 +00:00
|
|
|
dpt_pci_attach(pcici_t config_id, int unit)
|
|
|
|
{
|
1998-09-15 08:33:38 +00:00
|
|
|
dpt_softc_t *dpt;
|
|
|
|
vm_offset_t vaddr;
|
1998-12-07 21:58:50 +00:00
|
|
|
#ifdef DPT_ALLOW_MEMIO
|
1998-09-15 08:33:38 +00:00
|
|
|
vm_offset_t paddr;
|
1998-12-07 21:58:50 +00:00
|
|
|
#endif
|
1998-09-15 08:33:38 +00:00
|
|
|
u_int16_t io_base;
|
|
|
|
bus_space_tag_t tag;
|
|
|
|
bus_space_handle_t bsh;
|
|
|
|
u_int32_t command;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
vaddr = NULL;
|
|
|
|
command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
|
1998-01-26 06:11:18 +00:00
|
|
|
#ifdef DPT_ALLOW_MEMIO
|
1998-09-15 08:33:38 +00:00
|
|
|
if ((command & PCI_COMMAND_MEM_ENABLE) == 0
|
1998-10-07 03:40:51 +00:00
|
|
|
|| (pci_map_mem(config_id, PCI_BASEADR1, &vaddr, &paddr)) == 0)
|
1998-09-15 08:33:38 +00:00
|
|
|
#endif
|
|
|
|
if ((command & PCI_COMMAND_IO_ENABLE) == 0
|
|
|
|
|| (pci_map_port(config_id, PCI_BASEADR0, &io_base)) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the DPT is mapped as an IDE controller,
|
|
|
|
* let it be IDE controller
|
|
|
|
*/
|
|
|
|
if (io_base == ISA_PRIMARY_WD_ADDRESS - 0x10) {
|
1998-01-26 06:11:18 +00:00
|
|
|
#ifdef DPT_DEBUG_WARN
|
1998-09-15 08:33:38 +00:00
|
|
|
printf("dpt%d: Mapped as an IDE controller. "
|
|
|
|
"Disabling SCSI setup\n", unit);
|
1998-01-26 06:11:18 +00:00
|
|
|
#endif
|
1998-09-15 08:33:38 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
/* XXX Should be passed in by parent bus */
|
|
|
|
/* XXX Why isn't the 0x10 offset incorporated into the reg defs? */
|
|
|
|
if (vaddr != 0) {
|
|
|
|
tag = I386_BUS_SPACE_MEM;
|
|
|
|
bsh = vaddr + 0x10;
|
|
|
|
} else {
|
|
|
|
tag = I386_BUS_SPACE_IO;
|
|
|
|
bsh = io_base + 0x10;
|
|
|
|
}
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
if ((dpt = dpt_alloc(unit, tag, bsh)) == NULL)
|
|
|
|
return; /* XXX PCI code should take return status */
|
|
|
|
|
|
|
|
/* Allocate a dmatag representing the capabilities of this attachment */
|
|
|
|
/* XXX Should be a child of the PCI bus dma tag */
|
1999-08-16 01:52:21 +00:00
|
|
|
if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/1, /*boundary*/0,
|
1998-09-15 08:33:38 +00:00
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/*nsegments*/BUS_SPACE_UNRESTRICTED,
|
|
|
|
/*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/*flags*/0, &dpt->parent_dmat) != 0) {
|
|
|
|
dpt_free(dpt);
|
|
|
|
return;
|
|
|
|
}
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
if (pci_map_int(config_id, dpt_intr, (void *)dpt, &cam_imask) == 0) {
|
|
|
|
dpt_free(dpt);
|
|
|
|
return;
|
|
|
|
}
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
s = splcam();
|
|
|
|
if (dpt_init(dpt) != 0) {
|
|
|
|
dpt_free(dpt);
|
|
|
|
return;
|
|
|
|
}
|
1998-01-26 06:11:18 +00:00
|
|
|
|
1998-09-15 08:33:38 +00:00
|
|
|
/* Register with the XPT */
|
|
|
|
dpt_attach(dpt);
|
|
|
|
splx(s);
|
1998-01-26 06:11:18 +00:00
|
|
|
}
|