1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) Rockchip Electronics Co., Ltd.
4 *
5 * Author: Huang Lee <Putin.li@rock-chips.com>
6 */
7
8 #ifndef __LINUX_RGA_FENCE_H_
9 #define __LINUX_RGA_FENCE_H_
10
11 struct rga_fence_context {
12 unsigned int context;
13 unsigned int seqno;
14 spinlock_t spinlock;
15 };
16
17 struct rga_fence_waiter {
18 /* Base sync driver waiter structure */
19 struct dma_fence_cb waiter;
20
21 void *private;
22 };
23
24 #ifdef CONFIG_ROCKCHIP_RGA_ASYNC
25 int rga_fence_context_init(struct rga_fence_context **ctx);
26 void rga_fence_context_remove(struct rga_fence_context **ctx);
27
28 struct dma_fence *rga_dma_fence_alloc(void);
29 int rga_dma_fence_get_fd(struct dma_fence *fence);
30 struct dma_fence *rga_get_dma_fence_from_fd(int fence_fd);
31 int rga_dma_fence_wait(struct dma_fence *fence);
32 int rga_dma_fence_add_callback(struct dma_fence *fence, dma_fence_func_t func, void *private);
33
34
rga_dma_fence_put(struct dma_fence * fence)35 static inline void rga_dma_fence_put(struct dma_fence *fence)
36 {
37 if (fence)
38 dma_fence_put(fence);
39 }
40
rga_dma_fence_signal(struct dma_fence * fence,int error)41 static inline void rga_dma_fence_signal(struct dma_fence *fence, int error)
42 {
43 if (fence) {
44 if (error != 0)
45 dma_fence_set_error(fence, error);
46 dma_fence_signal(fence);
47 }
48 }
49
rga_dma_fence_get_status(struct dma_fence * fence)50 static inline int rga_dma_fence_get_status(struct dma_fence *fence)
51 {
52 if (fence)
53 return dma_fence_get_status(fence);
54 else
55 return 1;
56 }
57
58 #else
rga_dma_fence_alloc(void)59 static inline struct dma_fence *rga_dma_fence_alloc(void)
60 {
61 return NULL;
62 }
63
rga_dma_fence_get_fd(struct dma_fence * fence)64 static inline int rga_dma_fence_get_fd(struct dma_fence *fence)
65 {
66 return 0;
67 }
68
rga_get_dma_fence_from_fd(int fence_fd)69 static inline struct dma_fence *rga_get_dma_fence_from_fd(int fence_fd)
70 {
71 return NULL;
72 }
73
rga_dma_fence_wait(struct dma_fence * fence)74 static inline int rga_dma_fence_wait(struct dma_fence *fence)
75 {
76 return 0;
77 }
78
rga_dma_fence_add_callback(struct dma_fence * fence,dma_fence_func_t func,void * private)79 static inline int rga_dma_fence_add_callback(struct dma_fence *fence,
80 dma_fence_func_t func,
81 void *private)
82 {
83 return 0;
84 }
85
rga_dma_fence_put(struct dma_fence * fence)86 static inline void rga_dma_fence_put(struct dma_fence *fence)
87 {
88 }
89
rga_dma_fence_signal(struct dma_fence * fence,int error)90 static inline void rga_dma_fence_signal(struct dma_fence *fence, int error)
91 {
92 }
93
rga_dma_fence_get_status(struct dma_fence * fence)94 static inline int rga_dma_fence_get_status(struct dma_fence *fence)
95 {
96 return 0;
97 }
98
99 #endif /* #ifdef CONFIG_SYNC_FILE */
100
101 #endif /* __LINUX_RGA_FENCE_H_ */
102