1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NOUVEAU_FENCE_H__
3 #define __NOUVEAU_FENCE_H__
4
5 #include <linux/dma-fence.h>
6 #include <nvif/event.h>
7
8 struct nouveau_drm;
9 struct nouveau_bo;
10
11 struct nouveau_fence {
12 struct dma_fence base;
13
14 struct list_head head;
15
16 struct nouveau_channel __rcu *channel;
17 unsigned long timeout;
18 };
19
20 static inline struct nouveau_fence *
to_nouveau_fence(struct dma_fence * fence)21 to_nouveau_fence(struct dma_fence *fence)
22 {
23 return container_of(fence, struct nouveau_fence, base);
24 }
25
26 int nouveau_fence_create(struct nouveau_fence **, struct nouveau_channel *);
27 int nouveau_fence_new(struct nouveau_fence **, struct nouveau_channel *);
28 void nouveau_fence_unref(struct nouveau_fence **);
29
30 int nouveau_fence_emit(struct nouveau_fence *);
31 bool nouveau_fence_done(struct nouveau_fence *);
32 void nouveau_fence_cancel(struct nouveau_fence *fence);
33 int nouveau_fence_wait(struct nouveau_fence *, bool lazy, bool intr);
34 int nouveau_fence_sync(struct nouveau_bo *, struct nouveau_channel *, bool exclusive, bool intr);
35
36 struct nouveau_fence_chan {
37 spinlock_t lock;
38 struct kref fence_ref;
39
40 struct list_head pending;
41 struct list_head flip;
42
43 int (*emit)(struct nouveau_fence *);
44 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
45 struct nouveau_channel *);
46 u32 (*read)(struct nouveau_channel *);
47 int (*emit32)(struct nouveau_channel *, u64, u32);
48 int (*sync32)(struct nouveau_channel *, u64, u32);
49
50 u32 sequence;
51 u32 context;
52 char name[32];
53
54 struct work_struct uevent_work;
55 struct nvif_event event;
56 int notify_ref, dead, killed;
57 };
58
59 struct nouveau_fence_priv {
60 void (*dtor)(struct nouveau_drm *);
61 bool (*suspend)(struct nouveau_drm *);
62 void (*resume)(struct nouveau_drm *);
63 int (*context_new)(struct nouveau_channel *);
64 void (*context_del)(struct nouveau_channel *);
65
66 bool uevent;
67 };
68
69 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
70
71 void nouveau_fence_context_new(struct nouveau_channel *, struct nouveau_fence_chan *);
72 void nouveau_fence_context_del(struct nouveau_fence_chan *);
73 void nouveau_fence_context_free(struct nouveau_fence_chan *);
74 void nouveau_fence_context_kill(struct nouveau_fence_chan *, int error);
75
76 int nv04_fence_create(struct nouveau_drm *);
77 int nv04_fence_mthd(struct nouveau_channel *, u32, u32, u32);
78
79 int nv10_fence_emit(struct nouveau_fence *);
80 int nv17_fence_sync(struct nouveau_fence *, struct nouveau_channel *,
81 struct nouveau_channel *);
82 u32 nv10_fence_read(struct nouveau_channel *);
83 void nv10_fence_context_del(struct nouveau_channel *);
84 void nv10_fence_destroy(struct nouveau_drm *);
85 int nv10_fence_create(struct nouveau_drm *);
86
87 int nv17_fence_create(struct nouveau_drm *);
88 void nv17_fence_resume(struct nouveau_drm *drm);
89
90 int nv50_fence_create(struct nouveau_drm *);
91 int nv84_fence_create(struct nouveau_drm *);
92 int nvc0_fence_create(struct nouveau_drm *);
93 int gv100_fence_create(struct nouveau_drm *);
94
95 struct nv84_fence_chan {
96 struct nouveau_fence_chan base;
97 struct nouveau_vma *vma;
98 };
99
100 struct nv84_fence_priv {
101 struct nouveau_fence_priv base;
102 struct nouveau_bo *bo;
103 u32 *suspend;
104 struct mutex mutex;
105 };
106
107 int nv84_fence_context_new(struct nouveau_channel *);
108
109 #endif
110