2003-08-24 17:55:58 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2003-09-26 15:36:47 +00:00
|
|
|
* Copyright (c) 2000-03 ICP vortex GmbH
|
|
|
|
* Copyright (c) 2002-03 Intel Corporation
|
|
|
|
* Copyright (c) 2003 Adaptec Inc.
|
2002-01-20 08:51:08 +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. 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.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-01-20 08:51:08 +00:00
|
|
|
/*
|
|
|
|
* iir_pci.c: PCI Bus Attachment for Intel Integrated RAID Controller driver
|
|
|
|
*
|
|
|
|
* Written by: Achim Leubner <achim.leubner@intel.com>
|
2003-09-26 15:36:47 +00:00
|
|
|
* Written by: Achim Leubner <achim_leubner@adaptec.com>
|
2002-01-20 08:51:08 +00:00
|
|
|
* Fixes/Additions: Boji Tony Kannanthanam <boji.t.kannanthanam@intel.com>
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #include "opt_iir.h" */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2002-04-26 22:48:23 +00:00
|
|
|
#include <sys/endian.h>
|
2002-01-20 08:51:08 +00:00
|
|
|
#include <sys/kernel.h>
|
2003-07-01 15:52:06 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
2002-01-20 08:51:08 +00:00
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
|
2003-08-22 06:00:27 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
|
|
|
|
#include <dev/iir/iir.h>
|
|
|
|
|
|
|
|
/* Mapping registers for various areas */
|
2003-09-02 17:30:40 +00:00
|
|
|
#define PCI_DPMEM PCIR_BAR(0)
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
/* Product numbers for Fibre-Channel are greater than or equal to 0x200 */
|
|
|
|
#define GDT_PCI_PRODUCT_FC 0x200
|
|
|
|
|
|
|
|
/* PCI SRAM structure */
|
|
|
|
#define GDT_MAGIC 0x00 /* u_int32_t, controller ID from BIOS */
|
|
|
|
#define GDT_NEED_DEINIT 0x04 /* u_int16_t, switch between BIOS/driver */
|
|
|
|
#define GDT_SWITCH_SUPPORT 0x06 /* u_int8_t, see GDT_NEED_DEINIT */
|
|
|
|
#define GDT_OS_USED 0x10 /* u_int8_t [16], OS code per service */
|
|
|
|
#define GDT_FW_MAGIC 0x3c /* u_int8_t, controller ID from firmware */
|
|
|
|
#define GDT_SRAM_SZ 0x40
|
|
|
|
|
|
|
|
/* DPRAM PCI controllers */
|
|
|
|
#define GDT_DPR_IF 0x00 /* interface area */
|
|
|
|
#define GDT_6SR (0xff0 - GDT_SRAM_SZ)
|
|
|
|
#define GDT_SEMA1 0xff1 /* volatile u_int8_t, command semaphore */
|
|
|
|
#define GDT_IRQEN 0xff5 /* u_int8_t, board interrupts enable */
|
|
|
|
#define GDT_EVENT 0xff8 /* u_int8_t, release event */
|
|
|
|
#define GDT_IRQDEL 0xffc /* u_int8_t, acknowledge board interrupt */
|
|
|
|
#define GDT_DPRAM_SZ 0x1000
|
|
|
|
|
|
|
|
/* PLX register structure (new PCI controllers) */
|
|
|
|
#define GDT_CFG_REG 0x00 /* u_int8_t, DPRAM cfg. (2: < 1MB, 0: any) */
|
|
|
|
#define GDT_SEMA0_REG 0x40 /* volatile u_int8_t, command semaphore */
|
|
|
|
#define GDT_SEMA1_REG 0x41 /* volatile u_int8_t, status semaphore */
|
|
|
|
#define GDT_PLX_STATUS 0x44 /* volatile u_int16_t, command status */
|
|
|
|
#define GDT_PLX_SERVICE 0x46 /* u_int16_t, service */
|
|
|
|
#define GDT_PLX_INFO 0x48 /* u_int32_t [2], additional info */
|
|
|
|
#define GDT_LDOOR_REG 0x60 /* u_int8_t, PCI to local doorbell */
|
|
|
|
#define GDT_EDOOR_REG 0x64 /* volatile u_int8_t, local to PCI doorbell */
|
|
|
|
#define GDT_CONTROL0 0x68 /* u_int8_t, control0 register (unused) */
|
|
|
|
#define GDT_CONTROL1 0x69 /* u_int8_t, board interrupts enable */
|
|
|
|
#define GDT_PLX_SZ 0x80
|
|
|
|
|
|
|
|
/* DPRAM new PCI controllers */
|
|
|
|
#define GDT_IC 0x00 /* interface */
|
|
|
|
#define GDT_PCINEW_6SR (0x4000 - GDT_SRAM_SZ)
|
|
|
|
/* SRAM structure */
|
|
|
|
#define GDT_PCINEW_SZ 0x4000
|
|
|
|
|
|
|
|
/* i960 register structure (PCI MPR controllers) */
|
|
|
|
#define GDT_MPR_SEMA0 0x10 /* volatile u_int8_t, command semaphore */
|
|
|
|
#define GDT_MPR_SEMA1 0x12 /* volatile u_int8_t, status semaphore */
|
|
|
|
#define GDT_MPR_STATUS 0x14 /* volatile u_int16_t, command status */
|
|
|
|
#define GDT_MPR_SERVICE 0x16 /* u_int16_t, service */
|
|
|
|
#define GDT_MPR_INFO 0x18 /* u_int32_t [2], additional info */
|
|
|
|
#define GDT_MPR_LDOOR 0x20 /* u_int8_t, PCI to local doorbell */
|
|
|
|
#define GDT_MPR_EDOOR 0x2c /* volatile u_int8_t, locl to PCI doorbell */
|
|
|
|
#define GDT_EDOOR_EN 0x34 /* u_int8_t, board interrupts enable */
|
|
|
|
#define GDT_SEVERITY 0xefc /* u_int8_t, event severity */
|
|
|
|
#define GDT_EVT_BUF 0xf00 /* u_int8_t [256], event buffer */
|
|
|
|
#define GDT_I960_SZ 0x1000
|
|
|
|
|
|
|
|
/* DPRAM PCI MPR controllers */
|
|
|
|
#define GDT_I960R 0x00 /* 4KB i960 registers */
|
|
|
|
#define GDT_MPR_IC GDT_I960_SZ
|
|
|
|
/* i960 register area */
|
|
|
|
#define GDT_MPR_6SR (GDT_I960_SZ + 0x3000 - GDT_SRAM_SZ)
|
|
|
|
/* DPRAM struct. */
|
|
|
|
#define GDT_MPR_SZ (0x3000 - GDT_SRAM_SZ)
|
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
static int iir_pci_probe(device_t dev);
|
|
|
|
static int iir_pci_attach(device_t dev);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
void gdt_pci_enable_intr(struct gdt_softc *);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
2002-03-20 02:08:01 +00:00
|
|
|
void gdt_mpr_copy_cmd(struct gdt_softc *, struct gdt_ccb *);
|
|
|
|
u_int8_t gdt_mpr_get_status(struct gdt_softc *);
|
|
|
|
void gdt_mpr_intr(struct gdt_softc *, struct gdt_intr_ctx *);
|
|
|
|
void gdt_mpr_release_event(struct gdt_softc *);
|
|
|
|
void gdt_mpr_set_sema0(struct gdt_softc *);
|
|
|
|
int gdt_mpr_test_busy(struct gdt_softc *);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
static device_method_t iir_pci_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, iir_pci_probe),
|
|
|
|
DEVMETHOD(device_attach, iir_pci_attach),
|
|
|
|
{ 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static driver_t iir_pci_driver =
|
|
|
|
{
|
|
|
|
"iir",
|
|
|
|
iir_pci_methods,
|
|
|
|
sizeof(struct gdt_softc)
|
|
|
|
};
|
|
|
|
|
|
|
|
static devclass_t iir_devclass;
|
|
|
|
|
|
|
|
DRIVER_MODULE(iir, pci, iir_pci_driver, iir_devclass, 0, 0);
|
2006-12-11 18:28:31 +00:00
|
|
|
MODULE_DEPEND(iir, pci, 1, 1, 1);
|
|
|
|
MODULE_DEPEND(iir, cam, 1, 1, 1);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
iir_pci_probe(device_t dev)
|
|
|
|
{
|
2013-08-15 20:03:22 +00:00
|
|
|
if (pci_get_vendor(dev) == INTEL_VENDOR_ID_IIR &&
|
2002-01-20 08:51:08 +00:00
|
|
|
pci_get_device(dev) == INTEL_DEVICE_ID_IIR) {
|
|
|
|
device_set_desc(dev, "Intel Integrated RAID Controller");
|
2005-03-05 18:17:35 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
if (pci_get_vendor(dev) == GDT_VENDOR_ID &&
|
|
|
|
((pci_get_device(dev) >= GDT_DEVICE_ID_MIN &&
|
|
|
|
pci_get_device(dev) <= GDT_DEVICE_ID_MAX) ||
|
|
|
|
pci_get_device(dev) == GDT_DEVICE_ID_NEWRX)) {
|
|
|
|
device_set_desc(dev, "ICP Disk Array Controller");
|
2005-03-05 18:17:35 +00:00
|
|
|
return (BUS_PROBE_DEFAULT);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
iir_pci_attach(device_t dev)
|
|
|
|
{
|
|
|
|
struct gdt_softc *gdt;
|
2014-11-13 22:00:18 +00:00
|
|
|
struct resource *irq = NULL;
|
2002-01-20 08:51:08 +00:00
|
|
|
int retries, rid, error = 0;
|
|
|
|
void *ih;
|
|
|
|
u_int8_t protocol;
|
2014-11-13 22:00:18 +00:00
|
|
|
|
|
|
|
gdt = device_get_softc(dev);
|
|
|
|
mtx_init(&gdt->sc_lock, "iir", NULL, MTX_DEF);
|
|
|
|
|
2002-01-20 08:51:08 +00:00
|
|
|
/* map DPMEM */
|
|
|
|
rid = PCI_DPMEM;
|
2014-11-13 22:00:18 +00:00
|
|
|
gdt->sc_dpmem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
|
|
|
|
if (gdt->sc_dpmem == NULL) {
|
2002-01-20 08:51:08 +00:00
|
|
|
device_printf(dev, "can't allocate register resources\n");
|
|
|
|
error = ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get IRQ */
|
|
|
|
rid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
|
|
|
|
RF_ACTIVE | RF_SHAREABLE);
|
2009-05-14 13:32:33 +00:00
|
|
|
if (irq == NULL) {
|
2002-01-20 08:51:08 +00:00
|
|
|
device_printf(dev, "can't find IRQ value\n");
|
|
|
|
error = ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2007-06-17 05:55:54 +00:00
|
|
|
gdt->sc_devnode = dev;
|
2002-01-20 08:51:08 +00:00
|
|
|
gdt->sc_init_level = 0;
|
|
|
|
gdt->sc_hanum = device_get_unit(dev);
|
|
|
|
gdt->sc_bus = pci_get_bus(dev);
|
|
|
|
gdt->sc_slot = pci_get_slot(dev);
|
2003-04-25 05:37:04 +00:00
|
|
|
gdt->sc_vendor = pci_get_vendor(dev);
|
2002-01-20 08:51:08 +00:00
|
|
|
gdt->sc_device = pci_get_device(dev);
|
|
|
|
gdt->sc_subdevice = pci_get_subdevice(dev);
|
|
|
|
gdt->sc_class = GDT_MPR;
|
|
|
|
/* no FC ctr.
|
|
|
|
if (gdt->sc_device >= GDT_PCI_PRODUCT_FC)
|
|
|
|
gdt->sc_class |= GDT_FC;
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* initialize RP controller */
|
|
|
|
/* check and reset interface area */
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_4(gdt->sc_dpmem, GDT_MPR_IC, htole32(GDT_MPR_MAGIC));
|
|
|
|
if (bus_read_4(gdt->sc_dpmem, GDT_MPR_IC) != htole32(GDT_MPR_MAGIC)) {
|
Use uintmax_t (typedef'd to rman_res_t type) for rman ranges.
On some architectures, u_long isn't large enough for resource definitions.
Particularly, powerpc and arm allow 36-bit (or larger) physical addresses, but
type `long' is only 32-bit. This extends rman's resources to uintmax_t. With
this change, any resource can feasibly be placed anywhere in physical memory
(within the constraints of the driver).
Why uintmax_t and not something machine dependent, or uint64_t? Though it's
possible for uintmax_t to grow, it's highly unlikely it will become 128-bit on
32-bit architectures. 64-bit architectures should have plenty of RAM to absorb
the increase on resource sizes if and when this occurs, and the number of
resources on memory-constrained systems should be sufficiently small as to not
pose a drastic overhead. That being said, uintmax_t was chosen for source
clarity. If it's specified as uint64_t, all printf()-like calls would either
need casts to uintmax_t, or be littered with PRI*64 macros. Casts to uintmax_t
aren't horrible, but it would also bake into the API for
resource_list_print_type() either a hidden assumption that entries get cast to
uintmax_t for printing, or these calls would need the PRI*64 macros. Since
source code is meant to be read more often than written, I chose the clearest
path of simply using uintmax_t.
Tested on a PowerPC p5020-based board, which places all device resources in
0xfxxxxxxxx, and has 8GB RAM.
Regression tested on qemu-system-i386
Regression tested on qemu-system-mips (malta profile)
Tested PAE and devinfo on virtualbox (live CD)
Special thanks to bz for his testing on ARM.
Reviewed By: bz, jhb (previous)
Relnotes: Yes
Sponsored by: Alex Perez/Inertial Computing
Differential Revision: https://reviews.freebsd.org/D4544
2016-03-18 01:28:41 +00:00
|
|
|
device_printf(dev, "cannot access DPMEM at 0x%jx (shadowed?)\n",
|
2014-11-13 22:00:18 +00:00
|
|
|
rman_get_start(gdt->sc_dpmem));
|
2002-01-20 08:51:08 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_set_region_4(gdt->sc_dpmem, GDT_I960_SZ, htole32(0), GDT_MPR_SZ >> 2);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
/* Disable everything */
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_EDOOR_EN,
|
|
|
|
bus_read_1(gdt->sc_dpmem, GDT_EDOOR_EN) | 4);
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_EDOOR, 0xff);
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_STATUS, 0);
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_CMD_INDEX, 0);
|
|
|
|
|
|
|
|
bus_write_4(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_INFO,
|
|
|
|
htole32(rman_get_start(gdt->sc_dpmem)));
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_CMD_INDX, 0xff);
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_LDOOR, 1);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
DELAY(20);
|
|
|
|
retries = GDT_RETRIES;
|
2014-11-13 22:00:18 +00:00
|
|
|
while (bus_read_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_STATUS) != 0xff) {
|
2002-01-20 08:51:08 +00:00
|
|
|
if (--retries == 0) {
|
2014-11-13 22:00:18 +00:00
|
|
|
device_printf(dev, "DEINIT failed\n");
|
2002-01-20 08:51:08 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
protocol = (uint8_t)le32toh(bus_read_4(gdt->sc_dpmem,
|
|
|
|
GDT_MPR_IC + GDT_S_INFO));
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_STATUS, 0);
|
2002-01-20 08:51:08 +00:00
|
|
|
if (protocol != GDT_PROTOCOL_VERSION) {
|
2014-11-13 22:00:18 +00:00
|
|
|
device_printf(dev, "unsupported protocol %d\n", protocol);
|
2002-01-20 08:51:08 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
/* special command to controller BIOS */
|
|
|
|
bus_write_4(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_INFO, htole32(0));
|
|
|
|
bus_write_4(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_INFO + sizeof (u_int32_t),
|
|
|
|
htole32(0));
|
|
|
|
bus_write_4(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_INFO + 2 * sizeof (u_int32_t),
|
|
|
|
htole32(1));
|
|
|
|
bus_write_4(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_INFO + 3 * sizeof (u_int32_t),
|
|
|
|
htole32(0));
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_CMD_INDX, 0xfe);
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_LDOOR, 1);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
DELAY(20);
|
|
|
|
retries = GDT_RETRIES;
|
2014-11-13 22:00:18 +00:00
|
|
|
while (bus_read_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_STATUS) != 0xfe) {
|
2002-01-20 08:51:08 +00:00
|
|
|
if (--retries == 0) {
|
2014-11-13 22:00:18 +00:00
|
|
|
device_printf(dev, "initialization error\n");
|
2002-01-20 08:51:08 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
DELAY(1);
|
|
|
|
}
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_IC + GDT_S_STATUS, 0);
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
gdt->sc_ic_all_size = GDT_MPR_SZ;
|
|
|
|
|
|
|
|
gdt->sc_copy_cmd = gdt_mpr_copy_cmd;
|
|
|
|
gdt->sc_get_status = gdt_mpr_get_status;
|
|
|
|
gdt->sc_intr = gdt_mpr_intr;
|
|
|
|
gdt->sc_release_event = gdt_mpr_release_event;
|
|
|
|
gdt->sc_set_sema0 = gdt_mpr_set_sema0;
|
|
|
|
gdt->sc_test_busy = gdt_mpr_test_busy;
|
|
|
|
|
|
|
|
/* Allocate a dmatag representing the capabilities of this attachment */
|
2012-03-12 08:03:51 +00:00
|
|
|
if (bus_dma_tag_create(/*parent*/bus_get_dma_tag(dev),
|
|
|
|
/*alignemnt*/1, /*boundary*/0,
|
2002-01-20 08:51:08 +00:00
|
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
|
|
/*maxsize*/BUS_SPACE_MAXSIZE_32BIT,
|
2015-03-22 16:10:28 +00:00
|
|
|
/*nsegments*/BUS_SPACE_UNRESTRICTED,
|
2002-01-20 08:51:08 +00:00
|
|
|
/*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT,
|
2003-07-01 15:52:06 +00:00
|
|
|
/*flags*/0, /*lockfunc*/busdma_lock_mutex,
|
2014-11-13 22:00:18 +00:00
|
|
|
/*lockarg*/&gdt->sc_lock, &gdt->sc_parent_dmat) != 0) {
|
2002-01-20 08:51:08 +00:00
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
gdt->sc_init_level++;
|
|
|
|
|
|
|
|
if (iir_init(gdt) != 0) {
|
|
|
|
iir_free(gdt);
|
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register with the XPT */
|
|
|
|
iir_attach(gdt);
|
|
|
|
|
|
|
|
/* associate interrupt handler */
|
2014-11-13 22:00:18 +00:00
|
|
|
if (bus_setup_intr(dev, irq, INTR_TYPE_CAM | INTR_MPSAFE,
|
2007-02-23 12:19:07 +00:00
|
|
|
NULL, iir_intr, gdt, &ih )) {
|
2002-01-20 08:51:08 +00:00
|
|
|
device_printf(dev, "Unable to register interrupt handler\n");
|
|
|
|
error = ENXIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
gdt_pci_enable_intr(gdt);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (irq)
|
|
|
|
bus_release_resource( dev, SYS_RES_IRQ, 0, irq );
|
2014-11-13 22:00:18 +00:00
|
|
|
|
|
|
|
if (gdt->sc_dpmem)
|
|
|
|
bus_release_resource( dev, SYS_RES_MEMORY, rid, gdt->sc_dpmem );
|
|
|
|
mtx_destroy(&gdt->sc_lock);
|
|
|
|
|
2002-01-20 08:51:08 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Enable interrupts */
|
|
|
|
void
|
|
|
|
gdt_pci_enable_intr(struct gdt_softc *gdt)
|
|
|
|
{
|
|
|
|
GDT_DPRINTF(GDT_D_INTR, ("gdt_pci_enable_intr(%p) ", gdt));
|
|
|
|
|
|
|
|
switch(GDT_CLASS(gdt)) {
|
|
|
|
case GDT_MPR:
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_EDOOR, 0xff);
|
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_EDOOR_EN,
|
|
|
|
bus_read_1(gdt->sc_dpmem, GDT_EDOOR_EN) & ~4);
|
2002-01-20 08:51:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MPR PCI controller-specific functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2006-03-01 07:24:39 +00:00
|
|
|
gdt_mpr_copy_cmd(struct gdt_softc *gdt, struct gdt_ccb *gccb)
|
2002-01-20 08:51:08 +00:00
|
|
|
{
|
2006-03-01 07:24:39 +00:00
|
|
|
u_int16_t cp_count = roundup(gccb->gc_cmd_len, sizeof (u_int32_t));
|
2002-01-20 08:51:08 +00:00
|
|
|
u_int16_t dp_offset = gdt->sc_cmd_off;
|
|
|
|
u_int16_t cmd_no = gdt->sc_cmd_cnt++;
|
|
|
|
|
|
|
|
GDT_DPRINTF(GDT_D_CMD, ("gdt_mpr_copy_cmd(%p) ", gdt));
|
|
|
|
|
|
|
|
gdt->sc_cmd_off += cp_count;
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_region_4(gdt->sc_dpmem, GDT_MPR_IC + GDT_DPR_CMD + dp_offset,
|
|
|
|
(u_int32_t *)gccb->gc_cmd, cp_count >> 2);
|
|
|
|
bus_write_2(gdt->sc_dpmem,
|
|
|
|
GDT_MPR_IC + GDT_COMM_QUEUE + cmd_no * GDT_COMM_Q_SZ + GDT_OFFSET,
|
|
|
|
htole16(GDT_DPMEM_COMMAND_OFFSET + dp_offset));
|
|
|
|
bus_write_2(gdt->sc_dpmem,
|
|
|
|
GDT_MPR_IC + GDT_COMM_QUEUE + cmd_no * GDT_COMM_Q_SZ + GDT_SERV_ID,
|
|
|
|
htole16(gccb->gc_service));
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int8_t
|
|
|
|
gdt_mpr_get_status(struct gdt_softc *gdt)
|
|
|
|
{
|
|
|
|
GDT_DPRINTF(GDT_D_MISC, ("gdt_mpr_get_status(%p) ", gdt));
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
return bus_read_1(gdt->sc_dpmem, GDT_MPR_EDOOR);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdt_mpr_intr(struct gdt_softc *gdt, struct gdt_intr_ctx *ctx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
GDT_DPRINTF(GDT_D_INTR, ("gdt_mpr_intr(%p) ", gdt));
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_EDOOR, 0xff);
|
2006-03-01 07:24:39 +00:00
|
|
|
|
2002-01-20 08:51:08 +00:00
|
|
|
if (ctx->istatus & 0x80) { /* error flag */
|
|
|
|
ctx->istatus &= ~0x80;
|
2014-11-13 22:00:18 +00:00
|
|
|
ctx->cmd_status = bus_read_2(gdt->sc_dpmem, GDT_MPR_STATUS);
|
2002-01-20 08:51:08 +00:00
|
|
|
} else /* no error */
|
|
|
|
ctx->cmd_status = GDT_S_OK;
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
ctx->info = bus_read_4(gdt->sc_dpmem, GDT_MPR_INFO);
|
|
|
|
ctx->service = bus_read_2(gdt->sc_dpmem, GDT_MPR_SERVICE);
|
|
|
|
ctx->info2 = bus_read_4(gdt->sc_dpmem, GDT_MPR_INFO + sizeof (u_int32_t));
|
2002-01-20 08:51:08 +00:00
|
|
|
|
|
|
|
/* event string */
|
|
|
|
if (ctx->istatus == GDT_ASYNCINDEX) {
|
|
|
|
if (ctx->service != GDT_SCREENSERVICE &&
|
|
|
|
(gdt->sc_fw_vers & 0xff) >= 0x1a) {
|
2014-11-13 22:00:18 +00:00
|
|
|
gdt->sc_dvr.severity = bus_read_1(gdt->sc_dpmem, GDT_SEVERITY);
|
2002-01-20 08:51:08 +00:00
|
|
|
for (i = 0; i < 256; ++i) {
|
2014-11-13 22:00:18 +00:00
|
|
|
gdt->sc_dvr.event_string[i] = bus_read_1(gdt->sc_dpmem,
|
|
|
|
GDT_EVT_BUF + i);
|
2002-01-20 08:51:08 +00:00
|
|
|
if (gdt->sc_dvr.event_string[i] == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_SEMA1, 0);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdt_mpr_release_event(struct gdt_softc *gdt)
|
|
|
|
{
|
|
|
|
GDT_DPRINTF(GDT_D_MISC, ("gdt_mpr_release_event(%p) ", gdt));
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_LDOOR, 1);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdt_mpr_set_sema0(struct gdt_softc *gdt)
|
|
|
|
{
|
|
|
|
GDT_DPRINTF(GDT_D_MISC, ("gdt_mpr_set_sema0(%p) ", gdt));
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
bus_write_1(gdt->sc_dpmem, GDT_MPR_SEMA0, 1);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
gdt_mpr_test_busy(struct gdt_softc *gdt)
|
|
|
|
{
|
|
|
|
GDT_DPRINTF(GDT_D_MISC, ("gdt_mpr_test_busy(%p) ", gdt));
|
|
|
|
|
2014-11-13 22:00:18 +00:00
|
|
|
return (bus_read_1(gdt->sc_dpmem, GDT_MPR_SEMA0) & 1);
|
2002-01-20 08:51:08 +00:00
|
|
|
}
|