Skip to content

Commit 6706c83

Browse files
hoshinolinajannau
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 87b59fd commit 6706c83

4 files changed

Lines changed: 516 additions & 0 deletions

File tree

rust/bindings/bindings_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include <linux/debugfs.h>
5252
#include <linux/device/faux.h>
5353
#include <linux/dma-direction.h>
54+
#include <linux/dma-fence.h>
55+
#include <linux/dma-fence-chain.h>
5456
#include <linux/dma-mapping.h>
5557
#include <linux/dma-resv.h>
5658
#include <linux/errname.h>

rust/helpers/dma-fence.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/dma-fence.h>
4+
#include <linux/dma-fence-chain.h>
5+
6+
#ifdef CONFIG_DMA_SHARED_BUFFER
7+
8+
void rust_helper_dma_fence_get(struct dma_fence *fence)
9+
{
10+
dma_fence_get(fence);
11+
}
12+
13+
void rust_helper_dma_fence_put(struct dma_fence *fence)
14+
{
15+
dma_fence_put(fence);
16+
}
17+
18+
struct dma_fence_chain *rust_helper_dma_fence_chain_alloc(void)
19+
{
20+
return dma_fence_chain_alloc();
21+
}
22+
23+
void rust_helper_dma_fence_chain_free(struct dma_fence_chain *chain)
24+
{
25+
dma_fence_chain_free(chain);
26+
}
27+
28+
void rust_helper_dma_fence_set_error(struct dma_fence *fence, int error)
29+
{
30+
dma_fence_set_error(fence, error);
31+
}
32+
33+
#endif

rust/helpers/helpers.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "cred.c"
2626
#include "device.c"
2727
#include "dma.c"
28+
#include "dma-fence.c"
2829
#include "dma-mapping.c"
2930
#include "dma-resv.c"
3031
#include "drm.c"

0 commit comments

Comments
 (0)