1 
2 #ifndef __NOUVEAU_FENCE_H__
3 #define __NOUVEAU_FENCE_H__
4 
5 #include "util/u_inlines.h"
6 #include "util/list.h"
7 
8 #define NOUVEAU_FENCE_STATE_AVAILABLE 0
9 #define NOUVEAU_FENCE_STATE_EMITTING  1
10 #define NOUVEAU_FENCE_STATE_EMITTED   2
11 #define NOUVEAU_FENCE_STATE_FLUSHED   3
12 #define NOUVEAU_FENCE_STATE_SIGNALLED 4
13 
14 struct pipe_debug_callback;
15 
16 struct nouveau_fence_work {
17    struct list_head list;
18    void (*func)(void *);
19    void *data;
20 };
21 
22 struct nouveau_fence {
23    struct nouveau_fence *next;
24    struct nouveau_screen *screen;
25    int state;
26    int ref;
27    uint32_t sequence;
28    uint32_t work_count;
29    struct list_head work;
30 };
31 
32 void nouveau_fence_emit(struct nouveau_fence *);
33 void nouveau_fence_del(struct nouveau_fence *);
34 
35 bool nouveau_fence_new(struct nouveau_screen *, struct nouveau_fence **);
36 void nouveau_fence_cleanup(struct nouveau_screen *);
37 bool nouveau_fence_work(struct nouveau_fence *, void (*)(void *), void *);
38 void nouveau_fence_update(struct nouveau_screen *, bool flushed);
39 void nouveau_fence_next(struct nouveau_screen *);
40 bool nouveau_fence_wait(struct nouveau_fence *, struct pipe_debug_callback *);
41 bool nouveau_fence_signalled(struct nouveau_fence *);
42 
43 void nouveau_fence_unref_bo(void *data); /* generic unref bo callback */
44 
45 
46 static inline void
nouveau_fence_ref(struct nouveau_fence * fence,struct nouveau_fence ** ref)47 nouveau_fence_ref(struct nouveau_fence *fence, struct nouveau_fence **ref)
48 {
49    if (fence)
50       ++fence->ref;
51 
52    if (*ref) {
53       if (--(*ref)->ref == 0)
54          nouveau_fence_del(*ref);
55    }
56 
57    *ref = fence;
58 }
59 
60 static inline struct nouveau_fence *
nouveau_fence(struct pipe_fence_handle * fence)61 nouveau_fence(struct pipe_fence_handle *fence)
62 {
63    return (struct nouveau_fence *)fence;
64 }
65 
66 #endif // __NOUVEAU_FENCE_H__
67