xref: /linux/drivers/gpu/drm/nouveau/nouveau_fence.h (revision 965c995c9a4b395471ff48790a0155ee986ca405)
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 int  nouveau_fence_wait(struct nouveau_fence *, bool lazy, bool intr);
33 int  nouveau_fence_sync(struct nouveau_bo *, struct nouveau_channel *, bool exclusive, bool intr);
34 
35 struct nouveau_fence_chan {
36 	spinlock_t lock;
37 	struct kref fence_ref;
38 
39 	struct list_head pending;
40 	struct list_head flip;
41 
42 	int  (*emit)(struct nouveau_fence *);
43 	int  (*sync)(struct nouveau_fence *, struct nouveau_channel *,
44 		     struct nouveau_channel *);
45 	u32  (*read)(struct nouveau_channel *);
46 	int  (*emit32)(struct nouveau_channel *, u64, u32);
47 	int  (*sync32)(struct nouveau_channel *, u64, u32);
48 
49 	u32 sequence;
50 	u32 context;
51 	char name[32];
52 
53 	struct work_struct uevent_work;
54 	struct nvif_event event;
55 	int notify_ref, dead, killed;
56 };
57 
58 struct nouveau_fence_priv {
59 	void (*dtor)(struct nouveau_drm *);
60 	bool (*suspend)(struct nouveau_drm *);
61 	void (*resume)(struct nouveau_drm *);
62 	int  (*context_new)(struct nouveau_channel *);
63 	void (*context_del)(struct nouveau_channel *);
64 
65 	bool uevent;
66 };
67 
68 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
69 
70 void nouveau_fence_context_new(struct nouveau_channel *, struct nouveau_fence_chan *);
71 void nouveau_fence_context_del(struct nouveau_fence_chan *);
72 void nouveau_fence_context_free(struct nouveau_fence_chan *);
73 void nouveau_fence_context_kill(struct nouveau_fence_chan *, int error);
74 
75 int nv04_fence_create(struct nouveau_drm *);
76 int nv04_fence_mthd(struct nouveau_channel *, u32, u32, u32);
77 
78 int  nv10_fence_emit(struct nouveau_fence *);
79 int  nv17_fence_sync(struct nouveau_fence *, struct nouveau_channel *,
80 		     struct nouveau_channel *);
81 u32  nv10_fence_read(struct nouveau_channel *);
82 void nv10_fence_context_del(struct nouveau_channel *);
83 void nv10_fence_destroy(struct nouveau_drm *);
84 int  nv10_fence_create(struct nouveau_drm *);
85 
86 int  nv17_fence_create(struct nouveau_drm *);
87 void nv17_fence_resume(struct nouveau_drm *drm);
88 
89 int nv50_fence_create(struct nouveau_drm *);
90 int nv84_fence_create(struct nouveau_drm *);
91 int nvc0_fence_create(struct nouveau_drm *);
92 int gv100_fence_create(struct nouveau_drm *);
93 
94 struct nv84_fence_chan {
95 	struct nouveau_fence_chan base;
96 	struct nouveau_vma *vma;
97 };
98 
99 struct nv84_fence_priv {
100 	struct nouveau_fence_priv base;
101 	struct nouveau_bo *bo;
102 	u32 *suspend;
103 	struct mutex mutex;
104 };
105 
106 int  nv84_fence_context_new(struct nouveau_channel *);
107 
108 #endif
109