summaryrefslogtreecommitdiffstats
path: root/sys/dev/dpt/dpt_scsi.c
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2003-03-29 08:30:45 +0000
committermdodd <mdodd@FreeBSD.org>2003-03-29 08:30:45 +0000
commit17572bf81ce7a80b29d6c0e015977079bcb2b654 (patch)
treef754c77209c0705a05db1aba8a4d86c1fb7c3d37 /sys/dev/dpt/dpt_scsi.c
parentebb10b6a3fecd2a638cbcdb52111e82230dd9b66 (diff)
downloadFreeBSD-src-17572bf81ce7a80b29d6c0e015977079bcb2b654.zip
FreeBSD-src-17572bf81ce7a80b29d6c0e015977079bcb2b654.tar.gz
- Track resources in our softc.
- Sanitize dpt_alloc(). - Add helper functions for resource alloc/release. - Add detach method. - Relocate definition of devclass_t. - Move some debugging output behind bootverbose. - Implement an identify method for ISA devices but don't use it right now.
Diffstat (limited to 'sys/dev/dpt/dpt_scsi.c')
-rw-r--r--sys/dev/dpt/dpt_scsi.c101
1 files changed, 90 insertions, 11 deletions
diff --git a/sys/dev/dpt/dpt_scsi.c b/sys/dev/dpt/dpt_scsi.c
index f035a8c..922e95b 100644
--- a/sys/dev/dpt/dpt_scsi.c
+++ b/sys/dev/dpt/dpt_scsi.c
@@ -60,6 +60,10 @@
#include <machine/bus_pio.h>
#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <machine/clock.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
@@ -75,9 +79,8 @@
#include <dev/dpt/dpt.h>
/* dpt_isa.c, dpt_eisa.c, and dpt_pci.c need this in a central place */
-int dpt_controllers_present;
-
-u_long dpt_unit; /* Next unit number to use */
+int dpt_controllers_present;
+devclass_t dpt_devclass;
/* The linked list of softc structures */
struct dpt_softc_list dpt_softcs = TAILQ_HEAD_INITIALIZER(dpt_softcs);
@@ -447,7 +450,8 @@ dpt_pio_get_conf (u_int32_t base)
for (i = 0; i < (sizeof(dpt_conf_t) / 2); i++) {
if (dpt_pio_wait(base, HA_RSTATUS, HA_SDRQ, 0)) {
- printf("dpt: timeout in data read.\n");
+ if (bootverbose)
+ printf("dpt: timeout in data read.\n");
return (NULL);
}
@@ -456,7 +460,8 @@ dpt_pio_get_conf (u_int32_t base)
}
if (inb(base + HA_RSTATUS) & HA_SERROR) {
- printf("dpt: error reading configuration data.\n");
+ if (bootverbose)
+ printf("dpt: error reading configuration data.\n");
return (NULL);
}
@@ -1178,15 +1183,14 @@ dpt_send_eata_command(dpt_softc_t *dpt, eata_ccb_t *cmd_block,
/* ==================== Exported Function definitions =======================*/
-dpt_softc_t *
-dpt_alloc(device_t dev, bus_space_tag_t tag, bus_space_handle_t bsh)
+void
+dpt_alloc(device_t dev)
{
dpt_softc_t *dpt = device_get_softc(dev);
int i;
- bzero(dpt, sizeof(dpt_softc_t));
- dpt->tag = tag;
- dpt->bsh = bsh;
+ dpt->tag = rman_get_bustag(dpt->io_res);
+ dpt->bsh = rman_get_bushandle(dpt->io_res) + dpt->io_offset;
dpt->unit = device_get_unit(dev);
SLIST_INIT(&dpt->free_dccb_list);
LIST_INIT(&dpt->pending_ccb_list);
@@ -1197,7 +1201,7 @@ dpt_alloc(device_t dev, bus_space_tag_t tag, bus_space_handle_t bsh)
#ifdef DPT_MEASURE_PERFORMANCE
dpt_reset_performance(dpt);
#endif /* DPT_MEASURE_PERFORMANCE */
- return (dpt);
+ return;
}
void
@@ -1232,9 +1236,59 @@ dpt_free(struct dpt_softc *dpt)
case 0:
break;
}
+
TAILQ_REMOVE(&dpt_softcs, dpt, links);
}
+int
+dpt_alloc_resources (device_t dev)
+{
+ dpt_softc_t * dpt;
+ int error;
+
+ dpt = device_get_softc(dev);
+
+ dpt->io_res = bus_alloc_resource(dev, dpt->io_type, &dpt->io_rid,
+ 0, ~0, 1, RF_ACTIVE);
+ if (dpt->io_res == NULL) {
+ device_printf(dev, "No I/O space?!\n");
+ error = ENOMEM;
+ goto bad;
+ }
+
+ dpt->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &dpt->irq_rid,
+ 0, ~0, 1, RF_ACTIVE);
+ if (dpt->irq_res == NULL) {
+ device_printf(dev, "No IRQ!\n");
+ error = ENOMEM;
+ goto bad;
+ }
+
+ return (0);
+bad:
+ return(error);
+}
+
+
+void
+dpt_release_resources (device_t dev)
+{
+ struct dpt_softc * dpt;
+
+ dpt = device_get_softc(dev);
+
+ if (dpt->ih)
+ bus_teardown_intr(dev, dpt->irq_res, dpt->ih);
+ if (dpt->io_res)
+ bus_release_resource(dev, dpt->io_type, dpt->io_rid, dpt->io_res);
+ if (dpt->irq_res)
+ bus_release_resource(dev, SYS_RES_IRQ, dpt->irq_rid, dpt->irq_res);
+ if (dpt->drq_res)
+ bus_release_resource(dev, SYS_RES_DRQ, dpt->drq_rid, dpt->drq_res);
+
+ return;
+}
+
static u_int8_t string_sizes[] =
{
sizeof(((dpt_inq_t*)NULL)->vendor),
@@ -1522,6 +1576,31 @@ dpt_attach(dpt_softc_t *dpt)
return (i);
}
+int
+dpt_detach (device_t dev)
+{
+ struct dpt_softc * dpt;
+ int i;
+
+ dpt = device_get_softc(dev);
+
+ for (i = 0; i < dpt->channels; i++) {
+#if 0
+ xpt_async(AC_LOST_DEVICE, dpt->paths[i], NULL);
+#endif
+ xpt_free_path(dpt->paths[i]);
+ xpt_bus_deregister(cam_sim_path(dpt->sims[i]));
+ cam_sim_free(dpt->sims[i], /*free_devq*/TRUE);
+ }
+
+ dptshutdown((void *)dpt, SHUTDOWN_PRI_DEFAULT);
+
+ dpt_release_resources(dev);
+
+ dpt_free(dpt);
+
+ return (0);
+}
/*
* This is the interrupt handler for the DPT driver.
OpenPOWER on IntegriCloud