git: 7def1e10b3cc - main - bus_dma: Deduplicate locking helper functions.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 05 Jan 2022 21:51:06 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=7def1e10b3cc8ff8fd509aab07618d406f0d5bf2 commit 7def1e10b3cc8ff8fd509aab07618d406f0d5bf2 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2022-01-05 21:50:40 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2022-01-05 21:50:40 +0000 bus_dma: Deduplicate locking helper functions. - Move busdma_lock_mutex to subr_bus_dma.c. - Move _busdma_lock_dflt to subr_bus_dma.c. This function was named a couple of different things previously. It is not a public API but an internal helper used in place of a NULL pointer. The prototype is in <sys/bus_dma.h> as not all backends include <sys/bus_dma_internal.h>. Reviewed by: kib Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D33694 --- sys/arm/arm/busdma_machdep.c | 37 +--------------------------------- sys/arm64/arm64/busdma_machdep.c | 37 +--------------------------------- sys/arm64/include/bus_dma_impl.h | 1 - sys/kern/subr_bus_dma.c | 39 ++++++++++++++++++++++++++++++++++++ sys/powerpc/powerpc/busdma_machdep.c | 36 +-------------------------------- sys/riscv/include/bus_dma_impl.h | 1 - sys/riscv/riscv/busdma_machdep.c | 37 +--------------------------------- sys/sys/bus_dma.h | 5 +++++ sys/x86/include/busdma_impl.h | 1 - sys/x86/x86/busdma_machdep.c | 37 +--------------------------------- 10 files changed, 49 insertions(+), 182 deletions(-) diff --git a/sys/arm/arm/busdma_machdep.c b/sys/arm/arm/busdma_machdep.c index 758517323ff1..a754cb13ddc5 100644 --- a/sys/arm/arm/busdma_machdep.c +++ b/sys/arm/arm/busdma_machdep.c @@ -375,41 +375,6 @@ must_bounce(bus_dma_tag_t dmat, bus_dmamap_t map, bus_addr_t paddr, return (0); } -/* - * Convenience function for manipulating driver locks from busdma (during - * busdma_swi, for example). - */ -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) -{ - - panic("driver error: busdma dflt_lock called"); -} - /* * Allocate a device specific dma_tag. */ @@ -461,7 +426,7 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, newtag->lockfunc = lockfunc; newtag->lockfuncarg = lockfuncarg; } else { - newtag->lockfunc = dflt_lock; + newtag->lockfunc = _busdma_dflt_lock; newtag->lockfuncarg = NULL; } diff --git a/sys/arm64/arm64/busdma_machdep.c b/sys/arm64/arm64/busdma_machdep.c index 5d42d4e58c22..4ea604ce474c 100644 --- a/sys/arm64/arm64/busdma_machdep.c +++ b/sys/arm64/arm64/busdma_machdep.c @@ -51,41 +51,6 @@ __FBSDID("$FreeBSD$"); #include <machine/bus.h> #include <arm64/include/bus_dma_impl.h> -/* - * Convenience function for manipulating driver locks from busdma (during - * busdma_swi, for example). - */ -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. - */ -void -bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op) -{ - - panic("driver error: busdma dflt_lock called"); -} - /* * Return true if a match is made. * @@ -154,7 +119,7 @@ common_bus_dma_tag_create(struct bus_dma_tag_common *parent, common->lockfunc = lockfunc; common->lockfuncarg = lockfuncarg; } else { - common->lockfunc = bus_dma_dflt_lock; + common->lockfunc = _busdma_dflt_lock; common->lockfuncarg = NULL; } diff --git a/sys/arm64/include/bus_dma_impl.h b/sys/arm64/include/bus_dma_impl.h index 1488bd3a55da..949850cc528e 100644 --- a/sys/arm64/include/bus_dma_impl.h +++ b/sys/arm64/include/bus_dma_impl.h @@ -84,7 +84,6 @@ struct bus_dma_impl { bus_dmasync_op_t op); }; -void bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op); int bus_dma_run_filter(struct bus_dma_tag_common *dmat, bus_addr_t paddr); int common_bus_dma_tag_create(struct bus_dma_tag_common *parent, bus_size_t alignment, diff --git a/sys/kern/subr_bus_dma.c b/sys/kern/subr_bus_dma.c index 909750112a96..7ed012ba1a4f 100644 --- a/sys/kern/subr_bus_dma.c +++ b/sys/kern/subr_bus_dma.c @@ -42,8 +42,10 @@ __FBSDID("$FreeBSD$"); #include <sys/bus.h> #include <sys/callout.h> #include <sys/ktr.h> +#include <sys/lock.h> #include <sys/mbuf.h> #include <sys/memdesc.h> +#include <sys/mutex.h> #include <sys/proc.h> #include <sys/uio.h> @@ -59,6 +61,43 @@ __FBSDID("$FreeBSD$"); #include <machine/bus.h> +/* + * Convenience function for manipulating driver locks from busdma (during + * busdma_swi, for example). + */ +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 deferred. + * + * XXX Should have a way to identify which driver is responsible here. + */ +void +_busdma_dflt_lock(void *arg, bus_dma_lock_op_t op) +{ + + panic("driver error: _bus_dma_dflt_lock called"); +} + + /* * Load up data starting at offset within a region specified by a * list of virtual address ranges until either length or the region diff --git a/sys/powerpc/powerpc/busdma_machdep.c b/sys/powerpc/powerpc/busdma_machdep.c index ea3ab3dc7315..666f40d4edd7 100644 --- a/sys/powerpc/powerpc/busdma_machdep.c +++ b/sys/powerpc/powerpc/busdma_machdep.c @@ -146,40 +146,6 @@ run_filter(bus_dma_tag_t dmat, bus_addr_t paddr) return (retval); } -/* - * Convenience function for manipulating driver locks from busdma (during - * busdma_swi, for example). - */ -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) -{ - panic("driver error: busdma dflt_lock called"); -} - #define BUS_DMA_COULD_BOUNCE BUS_DMA_BUS3 #define BUS_DMA_MIN_ALLOC_COMP BUS_DMA_BUS4 /* @@ -232,7 +198,7 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, newtag->lockfunc = lockfunc; newtag->lockfuncarg = lockfuncarg; } else { - newtag->lockfunc = dflt_lock; + newtag->lockfunc = _busdma_dflt_lock; newtag->lockfuncarg = NULL; } diff --git a/sys/riscv/include/bus_dma_impl.h b/sys/riscv/include/bus_dma_impl.h index e482fb76a716..fd741210ca29 100644 --- a/sys/riscv/include/bus_dma_impl.h +++ b/sys/riscv/include/bus_dma_impl.h @@ -81,7 +81,6 @@ struct bus_dma_impl { bus_dmasync_op_t op); }; -void bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op); int bus_dma_run_filter(struct bus_dma_tag_common *dmat, bus_addr_t paddr); int common_bus_dma_tag_create(struct bus_dma_tag_common *parent, bus_size_t alignment, diff --git a/sys/riscv/riscv/busdma_machdep.c b/sys/riscv/riscv/busdma_machdep.c index 5a80def489e9..11ff9aa6afa5 100644 --- a/sys/riscv/riscv/busdma_machdep.c +++ b/sys/riscv/riscv/busdma_machdep.c @@ -51,41 +51,6 @@ __FBSDID("$FreeBSD$"); #include <machine/bus.h> #include <machine/bus_dma_impl.h> -/* - * Convenience function for manipulating driver locks from busdma (during - * busdma_swi, for example). - */ -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. - */ -void -bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op) -{ - - panic("driver error: busdma dflt_lock called"); -} - /* * Return true if a match is made. * @@ -156,7 +121,7 @@ common_bus_dma_tag_create(struct bus_dma_tag_common *parent, common->lockfunc = lockfunc; common->lockfuncarg = lockfuncarg; } else { - common->lockfunc = bus_dma_dflt_lock; + common->lockfunc = _busdma_dflt_lock; common->lockfuncarg = NULL; } diff --git a/sys/sys/bus_dma.h b/sys/sys/bus_dma.h index 7eac96b5af1e..212d8e3af09d 100644 --- a/sys/sys/bus_dma.h +++ b/sys/sys/bus_dma.h @@ -149,6 +149,11 @@ typedef int bus_dma_filter_t(void *, bus_addr_t); */ void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); +/* + * Internal helper function used by tags that do not defer loads. + */ +void _busdma_dflt_lock(void *arg, bus_dma_lock_op_t op); + /* * Allocate a device specific dma_tag encapsulating the constraints of * the parent tag in addition to other restrictions specified: diff --git a/sys/x86/include/busdma_impl.h b/sys/x86/include/busdma_impl.h index 9ae75095821a..577fd99f9496 100644 --- a/sys/x86/include/busdma_impl.h +++ b/sys/x86/include/busdma_impl.h @@ -89,7 +89,6 @@ struct bus_dma_impl { #endif }; -void bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op); int bus_dma_run_filter(struct bus_dma_tag_common *dmat, vm_paddr_t paddr); int common_bus_dma_tag_create(struct bus_dma_tag_common *parent, bus_size_t alignment, diff --git a/sys/x86/x86/busdma_machdep.c b/sys/x86/x86/busdma_machdep.c index ae62f83ea300..52bc765138c9 100644 --- a/sys/x86/x86/busdma_machdep.c +++ b/sys/x86/x86/busdma_machdep.c @@ -55,41 +55,6 @@ __FBSDID("$FreeBSD$"); #include <machine/bus.h> #include <x86/include/busdma_impl.h> -/* - * Convenience function for manipulating driver locks from busdma (during - * busdma_swi, for example). - */ -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. - */ -void -bus_dma_dflt_lock(void *arg, bus_dma_lock_op_t op) -{ - - panic("driver error: busdma dflt_lock called"); -} - /* * Return true if a match is made. * @@ -161,7 +126,7 @@ common_bus_dma_tag_create(struct bus_dma_tag_common *parent, common->lockfunc = lockfunc; common->lockfuncarg = lockfuncarg; } else { - common->lockfunc = bus_dma_dflt_lock; + common->lockfunc = _busdma_dflt_lock; common->lockfuncarg = NULL; }