xref: /aosp_15_r20/external/virglrenderer/src/drm/drm_fence.h (revision bbecb9d118dfdb95f99bd754f8fa9be01f189df3)
1 /*
2  * Copyright 2022 Google LLC
3  * SPDX-License-Identifier: MIT
4  */
5 
6 #ifndef DRM_FENCE_H_
7 #define DRM_FENCE_H_
8 
9 #include <stdbool.h>
10 #include <stdint.h>
11 
12 #include "c11/threads.h"
13 #include "util/list.h"
14 
15 /*
16  * Helpers to deal with managing dma-fence fd's.  This should something that
17  * can be re-used by any virtgpu native context implementation.
18  */
19 
20 struct drm_fence;
21 struct virgl_context;
22 
23 /**
24  * Represents a single timeline of fence-fd's.  Fences on a timeline are
25  * signaled in FIFO order.
26  */
27 struct drm_timeline {
28    struct virgl_context *vctx;
29    const char *name;
30    int eventfd;
31    int ring_idx;
32 
33    int last_fence_fd;
34    struct list_head pending_fences;
35 
36    mtx_t fence_mutex;
37    cnd_t fence_cond;
38    thrd_t sync_thread;
39    bool stop_sync_thread;
40 };
41 
42 void drm_timeline_init(struct drm_timeline *timeline, struct virgl_context *vctx,
43                        const char *name, int eventfd, int ring_idx);
44 
45 void drm_timeline_fini(struct drm_timeline *timeline);
46 
47 int drm_timeline_submit_fence(struct drm_timeline *timeline, uint32_t flags,
48                               uint64_t fence_id);
49 
50 void drm_timeline_set_last_fence_fd(struct drm_timeline *timeline, int fd);
51 
52 #endif /* DRM_FENCE_H_ */
53