Skip to content

Commit da2ab13

Browse files
hoshinolinamarcan
authored andcommitted
rust: dma_fence: Add DMA Fence abstraction
DMA fences are the internal synchronization primitive used for DMA operations like GPU rendering, video en/decoding, etc. Add an abstraction to allow Rust drivers to interact with this subsystem. Note: This uses a raw spinlock living next to the fence, since we do not interact with it other than for initialization. TODO: Expose this to the user at some point with a safe abstraction. Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 0f4fa00 commit da2ab13

4 files changed

Lines changed: 570 additions & 1 deletion

File tree

rust/bindings/bindings_helper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include <drm/drm_ioctl.h>
1515
#include <linux/delay.h>
1616
#include <linux/device.h>
17+
#include <linux/dma-fence.h>
18+
#include <linux/dma-fence-chain.h>
1719
#include <linux/dma-mapping.h>
1820
#include <linux/errname.h>
1921
#include <linux/slab.h>
2022
#include <linux/fs.h>
21-
#include <linux/io-pgtable.h>
2223
#include <linux/iosys-map.h>
24+
#include <linux/io-pgtable.h>
2325
#include <linux/ktime.h>
2426
#include <linux/lockdep.h>
2527
#include <linux/of.h>

rust/helpers.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <linux/bug.h>
2424
#include <linux/build_bug.h>
2525
#include <linux/device.h>
26+
#include <linux/dma-fence.h>
27+
#include <linux/dma-fence-chain.h>
2628
#include <linux/dma-mapping.h>
2729
#include <linux/err.h>
2830
#include <linux/errname.h>
@@ -436,6 +438,40 @@ int rust_helper_sg_dma_len(const struct scatterlist *sg)
436438
}
437439
EXPORT_SYMBOL_GPL(rust_helper_sg_dma_len);
438440

441+
#ifdef CONFIG_DMA_SHARED_BUFFER
442+
443+
void rust_helper_dma_fence_get(struct dma_fence *fence)
444+
{
445+
dma_fence_get(fence);
446+
}
447+
EXPORT_SYMBOL_GPL(rust_helper_dma_fence_get);
448+
449+
void rust_helper_dma_fence_put(struct dma_fence *fence)
450+
{
451+
dma_fence_put(fence);
452+
}
453+
EXPORT_SYMBOL_GPL(rust_helper_dma_fence_put);
454+
455+
struct dma_fence_chain *rust_helper_dma_fence_chain_alloc(void)
456+
{
457+
return dma_fence_chain_alloc();
458+
}
459+
EXPORT_SYMBOL_GPL(rust_helper_dma_fence_chain_alloc);
460+
461+
void rust_helper_dma_fence_chain_free(struct dma_fence_chain *chain)
462+
{
463+
dma_fence_chain_free(chain);
464+
}
465+
EXPORT_SYMBOL_GPL(rust_helper_dma_fence_chain_free);
466+
467+
void rust_helper_dma_fence_set_error(struct dma_fence *fence, int error)
468+
{
469+
dma_fence_set_error(fence, error);
470+
}
471+
EXPORT_SYMBOL_GPL(rust_helper_dma_fence_set_error);
472+
473+
#endif
474+
439475
#ifdef CONFIG_DRM
440476

441477
void rust_helper_drm_gem_object_get(struct drm_gem_object *obj)

0 commit comments

Comments
 (0)