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