summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/pvr_fence.h')
-rw-r--r--jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/pvr_fence.h252
1 files changed, 252 insertions, 0 deletions
diff --git a/jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/pvr_fence.h b/jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/pvr_fence.h
new file mode 100644
index 0000000..f7e9b22
--- /dev/null
+++ b/jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/pvr_fence.h
@@ -0,0 +1,252 @@
1/*************************************************************************/ /*!
2@File
3@Title PowerVR Linux fence interface
4@Codingstyle LinuxKernel
5@Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
6@License Strictly Confidential.
7*/ /**************************************************************************/
8
9#if !defined(__PVR_FENCE_H__)
10#define __PVR_FENCE_H__
11
12#include <linux/list.h>
13#include <linux/spinlock.h>
14#include <linux/workqueue.h>
15#include <linux/version.h>
16
17#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0))
18#include <linux/fence.h>
19#else
20#include <linux/dma-fence.h>
21#endif
22
23//#define PVR_FENCE_DEBUG 1
24
25struct PVR_SYNC_KERNEL_SYNC_INFO
26{
27 /* Base services sync info structure */
28 PVRSRV_KERNEL_SYNC_INFO *psBase;
29
30 /* Sync points can go away when there are deferred hardware
31 * operations still outstanding. We must not free the SYNC_INFO
32 * until the hardware is finished, so we add it to a defer list
33 * which is processed periodically ("defer-free").
34 *
35 * This is also used for "defer-free" of a timeline -- the process
36 * may destroy its timeline or terminate abnormally but the HW could
37 * still be using the sync object hanging off of the timeline.
38 *
39 * Note that the defer-free list is global, not per-timeline.
40 */
41 struct list_head sHead;
42};
43
44struct PVR_SYNC_DATA
45{
46 /* Every sync fence has a services sync object. This object is used
47 * by the hardware to enforce ordering -- it is attached as a source
48 * dependency to various commands.
49 */
50 struct PVR_SYNC_KERNEL_SYNC_INFO *psSyncInfo;
51
52 /* This is purely a debug feature. Record the WOP snapshot from the
53 * timeline synchronization object when a new fence is created.
54 */
55 IMG_UINT32 ui32WOPSnapshot;
56};
57
58/* A PVR_ALLOC_SYNC_DATA is used to back an allocated, but not yet created
59 * and inserted into a timeline, sync data. This is required as we must
60 * allocate the syncinfo to be passed down with the transfer task used to
61 * implement fences in the hardware.
62 */
63struct PVR_ALLOC_SYNC_DATA
64{
65 struct PVR_SYNC_KERNEL_SYNC_INFO *psSyncInfo;
66
67 /* A link to the timeline is required to add a per-timeline sync
68 * to the fence transfer task.
69 */
70 struct PVR_SYNC_TIMELINE *psTimeline;
71 struct file *psFile;
72};
73
74/**
75 * PVR_FENCE_CONTEXT - PVR fence context used to create and manage PVR fences
76 * @sLock: protects the context and fences created on the context
77 * @pcName: fence context name (used for debugging)
78 * @ui64FenceCtx: fence context with which to associate fences
79 * @sSeqno: sequence number to use for the next fence
80 * @psFenceWq: work queue for signalled fence work
81 * @sSignalWork: work item used to signal fences when fence syncs are met
82 * @sListLock: protects the active and active foreign lists
83 * @sSignalList: list of fences waiting to be signalled
84 * @sFenceList: list of fences (used for debugging)
85 * @sDeferredFreeList: list of fences that we will free when we are no longer
86 * @sFenceCtxList: list of all fence context
87 * holding spinlocks. The frees get implemented when an update fence is
88 * signalled or the context is freed.
89 */
90struct PVR_FENCE_CONTEXT
91{
92 spinlock_t sLock;
93 const char *pName;
94
95 /* True if a sync fence on the fence context has signaled */
96 IMG_BOOL bSyncHasSignaled;
97
98 IMG_UINT64 ui64FenceCtx;
99 atomic_t sSeqno;
100
101 struct workqueue_struct *psFenceWq;
102 struct work_struct sSignalWork;
103
104 spinlock_t sListLock;
105 struct list_head sSignalList;
106 struct list_head sFenceList;
107 struct list_head sDeferredFreeList;
108 struct list_head sFenceCtxList;
109
110 struct kref sRef;
111 struct workqueue_struct *psDestroyWq;
112 struct work_struct sDestroyWork;
113};
114
115/**
116 * PVR_FENCE - PVR fence that represents both native and foreign fences
117 * @sBase: fence structure
118 * @psFenceCtx: fence context on which this fence was created
119 * @pcName: fence name (used for debugging)
120 * @psFencefence: pointer to base fence structure or foreign fence
121 * @psSyncData: services sync data used by hardware
122 * @sFenceHead: entry on the context fence and deferred free list
123 * @sSignalHead: entry on the context signal list
124 * @sFenceCb: foreign fence callback to set the sync to signalled
125 */
126struct PVR_FENCE {
127 struct dma_fence sBase;
128 struct PVR_FENCE_CONTEXT *psFenceCtx;
129 const char *pName;
130
131 struct dma_fence *psFence;
132 struct PVR_SYNC_DATA *psSyncData;
133
134 struct list_head sFenceHead;
135 struct list_head sSignalHead;
136 struct dma_fence_cb sFenceCb;
137};
138
139/* This is the actual timeline metadata. We might keep this around after the
140 * base sync driver has destroyed the pvr_sync_timeline_wrapper object.
141 */
142struct PVR_SYNC_TIMELINE {
143 struct PVR_FENCE_CONTEXT *psFenceCtx;
144 struct file *psFile;
145 char name[32];
146 struct PVR_COUNTING_FENCE_TIMELINE *pSWTimeline;
147
148 /* Every timeline has a services sync object. This object must not
149 * be used by the hardware to enforce ordering -- that's what the
150 * per sync-point objects are for. This object is attached to every
151 * TQ scheduled on the timeline and is primarily useful for debugging.
152 */
153 struct PVR_SYNC_KERNEL_SYNC_INFO *psSyncInfo;
154};
155
156extern const struct dma_fence_ops pvr_fence_ops;
157extern const struct dma_fence_ops pvr_fence_foreign_ops;
158
159static inline bool is_our_fence(struct PVR_FENCE_CONTEXT *psFenceCtx,
160 struct dma_fence *psFence)
161{
162 return (psFence->context == psFenceCtx->ui64FenceCtx);
163}
164
165static inline bool is_pvr_fence(struct dma_fence *psFence)
166{
167 return ((psFence->ops == &pvr_fence_ops) ||
168 (psFence->ops == &pvr_fence_foreign_ops));
169}
170
171static inline struct PVR_FENCE *to_pvr_fence(struct dma_fence *psFence)
172{
173 if (is_pvr_fence(psFence))
174 return container_of(psFence, struct PVR_FENCE, sBase);
175
176 return NULL;
177}
178
179struct PVR_FENCE_CONTEXT *pvr_fence_context_create(const char *pcName);
180void pvr_fence_context_destroy(struct PVR_FENCE_CONTEXT *psFenceCtx);
181
182struct PVR_FENCE *pvr_fence_create(struct PVR_FENCE_CONTEXT *fctx,
183 const char *name, struct PVR_SYNC_KERNEL_SYNC_INFO *psSyncInfo);
184struct PVR_FENCE *pvr_fence_create_from_fence(struct PVR_FENCE_CONTEXT *psFenceCtx,
185 struct dma_fence *psFence,
186 const char *pcName);
187void pvr_fence_destroy(struct PVR_FENCE *psPvrFence);
188
189PVRSRV_ERROR PVRSyncInitServices(void);
190void PVRSyncCloseServices(void);
191
192IMG_BOOL ExpandAndDeDuplicateFenceSyncs(IMG_UINT32 ui32NumSyncs,
193 IMG_HANDLE aiFenceFds[],
194 IMG_UINT32 ui32SyncPointLimit,
195 struct dma_fence *apsFence[],
196 IMG_UINT32 *pui32NumRealSyncs,
197 PVRSRV_KERNEL_SYNC_INFO *apsSyncInfo[]);
198
199struct PVR_ALLOC_SYNC_DATA *PVRSyncAllocFDGet(int fd);
200
201struct PVR_COUNTING_FENCE_TIMELINE *pvr_sync_get_sw_timeline(int fd);
202
203static inline void pvr_fence_cleanup(void)
204{
205 /*
206 * Ensure all PVR fence contexts have been destroyed, by flushing
207 * the global workqueue.
208 * For those versions of the DDK don't use PVR fences, this isn't
209 * necessary, but should be harmless.
210 */
211 flush_scheduled_work();
212}
213
214#if defined(PVR_FENCE_DEBUG)
215#define PVR_FENCE_CTX_TRACE(c, fmt, ...) \
216 do { \
217 struct PVR_FENCE_CONTEXT *__fctx = (c); \
218 pr_err("c %llu: (PVR) " fmt, (u64) __fctx->ui64FenceCtx, \
219 ## __VA_ARGS__); \
220 } while (0)
221#else
222#define PVR_FENCE_CTX_TRACE(c, fmt, ...)
223#endif
224
225#define PVR_FENCE_CTX_WARN(c, fmt, ...) \
226 do { \
227 struct PVR_FENCE_CONTEXT *__fctx = (c); \
228 pr_warn("c %llu: (PVR) " fmt, (u64) __fctx->ui64FenceCtx, \
229 ## __VA_ARGS__); \
230 } while (0)
231
232#define PVR_FENCE_CTX_ERR(c, fmt, ...) \
233 do { \
234 struct PVR_FENCE_CONTEXT *__fctx = (c); \
235 pr_err("c %llu: (PVR) " fmt, (u64) __fctx->ui64FenceCtx, \
236 ## __VA_ARGS__); \
237 } while (0)
238
239#if defined(PVR_FENCE_DEBUG)
240#define PVR_FENCE_TRACE(f, fmt, ...) \
241 FENCE_ERR(f, "(PVR) " fmt, ## __VA_ARGS__)
242#else
243#define PVR_FENCE_TRACE(f, fmt, ...)
244#endif
245
246#define PVR_FENCE_WARN(f, fmt, ...) \
247 FENCE_WARN(f, "(PVR) " fmt, ## __VA_ARGS__)
248
249#define PVR_FENCE_ERR(f, fmt, ...) \
250 FENCE_ERR(f, "(PVR) " fmt, ## __VA_ARGS__)
251
252#endif /* !defined(__PVR_FENCE_H__) */