diff options
author | scottl <scottl@FreeBSD.org> | 2003-07-01 15:52:06 +0000 |
---|---|---|
committer | scottl <scottl@FreeBSD.org> | 2003-07-01 15:52:06 +0000 |
commit | 4d495abb9d6f6e6d703264c4133ce1f0c4e7df92 (patch) | |
tree | 1bbd76935b6d5917753df7328c69bd2f3c75f15a /sys/sparc64 | |
parent | 40bbdc533036dcf851a5b4c44f1b64b82b887a5a (diff) | |
download | FreeBSD-src-4d495abb9d6f6e6d703264c4133ce1f0c4e7df92.zip FreeBSD-src-4d495abb9d6f6e6d703264c4133ce1f0c4e7df92.tar.gz |
Mega busdma API commit.
Add two new arguments to bus_dma_tag_create(): lockfunc and lockfuncarg.
Lockfunc allows a driver to provide a function for managing its locking
semantics while using busdma. At the moment, this is used for the
asynchronous busdma_swi and callback mechanism. Two lockfunc implementations
are provided: busdma_lock_mutex() performs standard mutex operations on the
mutex that is specified from lockfuncarg. dftl_lock() is a panic
implementation and is defaulted to when NULL, NULL are passed to
bus_dma_tag_create(). The only time that NULL, NULL should ever be used is
when the driver ensures that bus_dmamap_load() will not be deferred.
Drivers that do not provide their own locking can pass
busdma_lock_mutex,&Giant args in order to preserve the former behaviour.
sparc64 and powerpc do not provide real busdma_swi functions, so this is
largely a noop on those platforms. The busdma_swi on is64 is not properly
locked yet, so warnings will be emitted on this platform when busdma
callback deferrals happen.
If anyone gets panics or warnings from dflt_lock() being called, please
let me know right away.
Reviewed by: tmm, gibbs
Diffstat (limited to 'sys/sparc64')
-rw-r--r-- | sys/sparc64/include/bus.h | 19 | ||||
-rw-r--r-- | sys/sparc64/pci/psycho.c | 2 | ||||
-rw-r--r-- | sys/sparc64/sbus/sbus.c | 2 | ||||
-rw-r--r-- | sys/sparc64/sparc64/bus_machdep.c | 55 |
4 files changed, 73 insertions, 5 deletions
diff --git a/sys/sparc64/include/bus.h b/sys/sparc64/include/bus.h index 2a3e5a6..4e0c2b4 100644 --- a/sys/sparc64/include/bus.h +++ b/sys/sparc64/include/bus.h @@ -957,6 +957,17 @@ typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); /* + * A function that performs driver-specific syncronization on behalf of + * busdma. + */ +typedef enum { + BUS_DMA_LOCK = 0x01, + BUS_DMA_UNLOCK = 0x02, +} bus_dma_lock_op_t; + +typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); + +/* * Method table for a bus_dma_tag. */ struct bus_dma_methods { @@ -996,13 +1007,15 @@ struct bus_dma_tag { int dt_flags; int dt_ref_count; int dt_map_count; + bus_dma_lock_t *dt_lockfunc; + void * *dt_lockfuncarg; struct bus_dma_methods *dt_mt; }; int bus_dma_tag_create(bus_dma_tag_t, bus_size_t, bus_size_t, bus_addr_t, bus_addr_t, bus_dma_filter_t *, void *, bus_size_t, int, bus_size_t, - int, bus_dma_tag_t *); + int, bus_dma_lock_t *, void *, bus_dma_tag_t *); int bus_dma_tag_destroy(bus_dma_tag_t); @@ -1025,4 +1038,8 @@ int bus_dma_tag_destroy(bus_dma_tag_t); #define bus_dmamem_free(t, v, m) \ ((t)->dt_mt->dm_dmamem_free((t), (v), (m))) +/* + * Generic helper function for manipulating mutexes. + */ +void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); #endif /* !_MACHINE_BUS_H_ */ diff --git a/sys/sparc64/pci/psycho.c b/sys/sparc64/pci/psycho.c index a1d7fee..bf76c3c 100644 --- a/sys/sparc64/pci/psycho.c +++ b/sys/sparc64/pci/psycho.c @@ -553,7 +553,7 @@ psycho_attach(device_t dev) sc->sc_iot = psycho_alloc_bus_tag(sc, PCI_IO_BUS_SPACE); sc->sc_cfgt = psycho_alloc_bus_tag(sc, PCI_CONFIG_BUS_SPACE); if (bus_dma_tag_create(sc->sc_dmatag, 8, 1, 0, 0x3ffffffff, NULL, NULL, - 0x3ffffffff, 0xff, 0xffffffff, 0, &sc->sc_dmat) != 0) + 0x3ffffffff, 0xff, 0xffffffff, 0, NULL, NULL, &sc->sc_dmat) != 0) panic("psycho_attach: bus_dma_tag_create failed"); /* Customize the tag. */ sc->sc_dmat->dt_cookie = sc->sc_is; diff --git a/sys/sparc64/sbus/sbus.c b/sys/sparc64/sbus/sbus.c index 22a0aeb..028933e 100644 --- a/sys/sparc64/sbus/sbus.c +++ b/sys/sparc64/sbus/sbus.c @@ -393,7 +393,7 @@ sbus_probe(device_t dev) /* Create the DMA tag. */ sc->sc_dmatag = nexus_get_dmatag(dev); if (bus_dma_tag_create(sc->sc_dmatag, 8, 1, 0, 0x3ffffffff, NULL, NULL, - 0x3ffffffff, 0xff, 0xffffffff, 0, &sc->sc_cdmatag) != 0) + 0x3ffffffff, 0xff, 0xffffffff, 0, NULL, NULL, &sc->sc_cdmatag) != 0) panic("bus_dma_tag_create failed"); /* Customize the tag. */ sc->sc_cdmatag->dt_cookie = &sc->sc_is; diff --git a/sys/sparc64/sparc64/bus_machdep.c b/sys/sparc64/sparc64/bus_machdep.c index 90d6ffd..b9fa29e 100644 --- a/sys/sparc64/sparc64/bus_machdep.c +++ b/sys/sparc64/sparc64/bus_machdep.c @@ -155,7 +155,47 @@ int bus_stream_asi[] = { }; /* - * Since there is now way for a device to obtain a dma tag from its parent + * Convenience function for manipulating driver locks from busdma (during + * busdma_swi, for example). Drivers that don't provide their own locks + * should specify &Giant to dmat->lockfuncarg. Drivers that use their own + * non-mutex locking scheme don't have to use this at all. + */ +void +busdma_lock_mutex(void *arg, bus_dma_lock_op_t op) +{ + struct mtx *dmtx; + + dmtx = (struct mtx *)arg; + switch (op) { + case BUS_DMA_LOCK: + mtx_lock(dmtx); + break; + case BUS_DMA_UNLOCK: + mtx_unlock(dmtx); + break; + default: + panic("Unknown operation 0x%x for busdma_lock_mutex!", op); + } +} + +/* + * dflt_lock should never get called. It gets put into the dma tag when + * lockfunc == NULL, which is only valid if the maps that are associated + * with the tag are meant to never be defered. + * XXX Should have a way to identify which driver is responsible here. + */ +static void +dflt_lock(void *arg, bus_dma_lock_op_t op) +{ +#ifdef INVARIANTS + panic("driver error: busdma dflt_lock called"); +#else + printf("DRIVER_ERROR: busdma dflt_lock called\n"); +#endif +} + +/* + * Since there is no way for a device to obtain a dma tag from its parent * we use this kluge to handle different the different supported bus systems. * The sparc64_root_dma_tag is used as parent for tags that have none, so that * the correct methods will be used. @@ -169,7 +209,8 @@ int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, bus_size_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, bus_dma_filter_t *filter, void *filterarg, bus_size_t maxsize, - int nsegments, bus_size_t maxsegsz, int flags, bus_dma_tag_t *dmat) + int nsegments, bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, + void *lockfuncarg, bus_dma_tag_t *dmat) { bus_dma_tag_t impptag; bus_dma_tag_t newtag; @@ -204,6 +245,14 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, newtag->dt_ref_count = 1; /* Count ourselves */ newtag->dt_map_count = 0; + if (lockfunc != NULL) { + newtag->dt_lockfunc = lockfunc; + newtag->dt_lockfuncarg = lockfuncarg; + } else { + newtag->dt_lockfunc = dflt_lock; + newtag->dt_lockfuncarg = NULL; + } + /* Take into account any restrictions imposed by our parent tag */ if (parent != NULL) { newtag->dt_lowaddr = ulmin(parent->dt_lowaddr, @@ -630,6 +679,8 @@ struct bus_dma_tag nexus_dmatag = { 0, 0, 0, + NULL, + NULL, &nexus_dma_methods, }; |