Add locking to the dpt(4) driver and mark it MPSAFE.

- Use device_printf() and device_get_unit() instead of storing the unit
  number in the softc.
- Remove use of explicit bus space handles and tags.
- Remove the global dpt_softcs list and use devclass_get_device() instead.
- Use pci_enable_busmaster() rather than frobbing the PCI command register
  directly.

Tested by:	no one
This commit is contained in:
John Baldwin 2012-10-15 16:29:08 +00:00
parent 04dd49d0a2
commit b5688bc4e2
5 changed files with 234 additions and 287 deletions

View file

@ -876,6 +876,7 @@ typedef enum {
typedef struct dpt_ccb {
eata_ccb_t eata_ccb;
bus_dmamap_t dmamap;
struct callout timer;
dpt_sg_t *sg_list;
u_int32_t sg_busaddr;
dccb_state state;
@ -1017,6 +1018,7 @@ struct sg_map_node {
/* Main state machine and interface structure */
typedef struct dpt_softc {
device_t dev;
struct mtx lock;
struct resource * io_res;
int io_rid;
@ -1030,8 +1032,6 @@ typedef struct dpt_softc {
struct resource * drq_res;
int drq_rid;
bus_space_tag_t tag;
bus_space_handle_t bsh;
bus_dma_tag_t buffer_dmat; /* dmat for buffer I/O */
dpt_ccb_t *dpt_dccbs; /* Array of dpt ccbs */
bus_addr_t dpt_ccb_busbase; /* phys base address of array */
@ -1079,7 +1079,6 @@ typedef struct dpt_softc {
u_int8_t dma_channel;
TAILQ_ENTRY(dpt_softc) links;
int unit;
int init_level;
/*
@ -1275,9 +1274,6 @@ dpt_time_delta(struct timeval start,
(end.tv_usec - start.tv_usec) );
}
extern TAILQ_HEAD(dpt_softc_list, dpt_softc) dpt_softcs;
extern int dpt_controllers_present;
extern devclass_t dpt_devclass;
#ifdef _KERNEL

View file

@ -105,11 +105,11 @@ static int
dpt_eisa_attach (device_t dev)
{
dpt_softc_t * dpt;
int s;
int error = 0;
dpt = device_get_softc(dev);
dpt->dev = dev;
dpt_alloc(dev);
dpt->io_rid = 0;
dpt->io_type = SYS_RES_IOPORT;
@ -120,11 +120,8 @@ dpt_eisa_attach (device_t dev)
goto bad;
}
dpt_alloc(dev);
/* Allocate a dmatag representing the capabilities of this attachment */
/* XXX Should be a child of the EISA bus dma tag */
if (bus_dma_tag_create( /* parent */ NULL,
if (bus_dma_tag_create( /* parent */ bus_get_dma_tag(dev),
/* alignemnt */ 1,
/* boundary */ 0,
/* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
@ -135,17 +132,14 @@ dpt_eisa_attach (device_t dev)
/* nsegments */ ~0,
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
/* flags */ 0,
/* lockfunc */ busdma_lock_mutex,
/* lockarg */ &Giant,
/* lockfunc */ NULL,
/* lockarg */ NULL,
&dpt->parent_dmat) != 0) {
error = ENXIO;
goto bad;
}
s = splcam();
if (dpt_init(dpt) != 0) {
splx(s);
error = ENXIO;
goto bad;
}
@ -153,10 +147,8 @@ dpt_eisa_attach (device_t dev)
/* Register with the XPT */
dpt_attach(dpt);
splx(s);
if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
NULL, dpt_intr, dpt, &dpt->ih)) {
if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY |
INTR_MPSAFE, NULL, dpt_intr, dpt, &dpt->ih)) {
device_printf(dev, "Unable to register interrupt handler\n");
error = ENXIO;
goto bad;

View file

@ -31,7 +31,9 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/bus.h>
#include <machine/bus.h>
@ -150,11 +152,11 @@ static int
dpt_isa_attach (device_t dev)
{
dpt_softc_t * dpt;
int s;
int error = 0;
dpt = device_get_softc(dev);
dpt->dev = dev;
dpt_alloc(dev);
dpt->io_rid = 0;
dpt->io_type = SYS_RES_IOPORT;
@ -176,10 +178,8 @@ dpt_isa_attach (device_t dev)
isa_dma_acquire(rman_get_start(dpt->drq_res));
isa_dmacascade(rman_get_start(dpt->drq_res));
dpt_alloc(dev);
/* Allocate a dmatag representing the capabilities of this attachment */
if (bus_dma_tag_create( /* parent */ NULL,
if (bus_dma_tag_create( /* parent */ bus_get_dma_tag(dev),
/* alignemnt */ 1,
/* boundary */ 0,
/* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
@ -190,17 +190,14 @@ dpt_isa_attach (device_t dev)
/* nsegments */ ~0,
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
/* flags */ 0,
/* lockfunc */ busdma_lock_mutex,
/* lockarg */ &Giant,
/* lockfunc */ NULL,
/* lockarg */ NULL,
&dpt->parent_dmat) != 0) {
error = ENXIO;
goto bad;
}
s = splcam();
if (dpt_init(dpt) != 0) {
splx(s);
error = ENXIO;
goto bad;
}
@ -208,10 +205,8 @@ dpt_isa_attach (device_t dev)
/* Register with the XPT */
dpt_attach(dpt);
splx(s);
if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
dpt_intr, dpt, &dpt->ih)) {
if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY |
INTR_MPSAFE, NULL, dpt_intr, dpt, &dpt->ih)) {
device_printf(dev, "Unable to register interrupt handler\n");
error = ENXIO;
goto bad;

View file

@ -75,13 +75,13 @@ static int
dpt_pci_attach (device_t dev)
{
dpt_softc_t * dpt;
int s;
int error = 0;
u_int32_t command;
dpt = device_get_softc(dev);
dpt->dev = dev;
dpt_alloc(dev);
command = pci_read_config(dev, PCIR_COMMAND, /*bytes*/1);
@ -117,8 +117,7 @@ dpt_pci_attach (device_t dev)
}
/* Ensure busmastering is enabled */
command |= PCIM_CMD_BUSMASTEREN;
pci_write_config(dev, PCIR_COMMAND, command, /*bytes*/1);
pci_enable_busmaster(dev);
if (rman_get_start(dpt->io_res) == (ISA_PRIMARY_WD_ADDRESS - 0x10)) {
#ifdef DPT_DEBUG_WARN
@ -129,8 +128,6 @@ dpt_pci_attach (device_t dev)
goto bad;
}
dpt_alloc(dev);
/* Allocate a dmatag representing the capabilities of this attachment */
if (bus_dma_tag_create( /* PCI parent */ bus_get_dma_tag(dev),
/* alignemnt */ 1,
@ -143,15 +140,13 @@ dpt_pci_attach (device_t dev)
/* nsegments */ ~0,
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
/* flags */ 0,
/* lockfunc */ busdma_lock_mutex,
/* lockarg */ &Giant,
/* lockfunc */ NULL,
/* lockarg */ NULL,
&dpt->parent_dmat) != 0) {
error = ENXIO;
goto bad;
}
s = splcam();
if (dpt_init(dpt) != 0) {
error = ENXIO;
goto bad;
@ -160,10 +155,8 @@ dpt_pci_attach (device_t dev)
/* Register with the XPT */
dpt_attach(dpt);
splx(s);
if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
NULL, dpt_intr, dpt, &dpt->ih)) {
if (bus_setup_intr(dev, dpt->irq_res, INTR_TYPE_CAM | INTR_ENTROPY |
INTR_MPSAFE, NULL, dpt_intr, dpt, &dpt->ih)) {
device_printf(dev, "Unable to register interrupt handler\n");
error = ENXIO;
goto bad;

File diff suppressed because it is too large Load diff