xref: /linux/drivers/gpu/drm/nouveau/nouveau_sched.h (revision 8e1bb4a41aa78d6105e59186af3dcd545fc66e70)
1 /* SPDX-License-Identifier: MIT */
2 
3 #ifndef NOUVEAU_SCHED_H
4 #define NOUVEAU_SCHED_H
5 
6 #include <linux/types.h>
7 
8 #include <drm/drm_gpuvm.h>
9 #include <drm/gpu_scheduler.h>
10 
11 #include "nouveau_drv.h"
12 
13 #define to_nouveau_job(sched_job)		\
14 		container_of((sched_job), struct nouveau_job, base)
15 
16 struct nouveau_job_ops;
17 
18 enum nouveau_job_state {
19 	NOUVEAU_JOB_UNINITIALIZED = 0,
20 	NOUVEAU_JOB_INITIALIZED,
21 	NOUVEAU_JOB_SUBMIT_SUCCESS,
22 	NOUVEAU_JOB_SUBMIT_FAILED,
23 	NOUVEAU_JOB_RUN_SUCCESS,
24 	NOUVEAU_JOB_RUN_FAILED,
25 };
26 
27 struct nouveau_job_args {
28 	struct drm_file *file_priv;
29 	struct nouveau_sched *sched;
30 	u32 credits;
31 
32 	enum dma_resv_usage resv_usage;
33 	bool sync;
34 
35 	struct {
36 		struct drm_nouveau_sync *s;
37 		u32 count;
38 	} in_sync;
39 
40 	struct {
41 		struct drm_nouveau_sync *s;
42 		u32 count;
43 	} out_sync;
44 
45 	const struct nouveau_job_ops *ops;
46 };
47 
48 struct nouveau_job {
49 	struct drm_sched_job base;
50 
51 	enum nouveau_job_state state;
52 
53 	struct nouveau_sched *sched;
54 	struct list_head entry;
55 
56 	struct drm_file *file_priv;
57 	struct nouveau_cli *cli;
58 
59 	enum dma_resv_usage resv_usage;
60 	struct dma_fence *done_fence;
61 
62 	bool sync;
63 
64 	struct {
65 		struct drm_nouveau_sync *data;
66 		u32 count;
67 	} in_sync;
68 
69 	struct {
70 		struct drm_nouveau_sync *data;
71 		struct drm_syncobj **objs;
72 		struct dma_fence_chain **chains;
73 		u32 count;
74 	} out_sync;
75 
76 	const struct nouveau_job_ops {
77 		/* If .submit() returns without any error, it is guaranteed that
78 		 * armed_submit() is called.
79 		 */
80 		int (*submit)(struct nouveau_job *, struct drm_gpuvm_exec *);
81 		void (*armed_submit)(struct nouveau_job *, struct drm_gpuvm_exec *);
82 		struct dma_fence *(*run)(struct nouveau_job *);
83 		void (*free)(struct nouveau_job *);
84 		enum drm_gpu_sched_stat (*timeout)(struct nouveau_job *);
85 	} *ops;
86 };
87 
88 int nouveau_job_ucopy_syncs(struct nouveau_job_args *args,
89 			    u32 inc, u64 ins,
90 			    u32 outc, u64 outs);
91 
92 int nouveau_job_init(struct nouveau_job *job,
93 		     struct nouveau_job_args *args);
94 void nouveau_job_fini(struct nouveau_job *job);
95 int nouveau_job_submit(struct nouveau_job *job);
96 void nouveau_job_done(struct nouveau_job *job);
97 void nouveau_job_free(struct nouveau_job *job);
98 
99 struct nouveau_sched {
100 	struct drm_gpu_scheduler base;
101 	struct drm_sched_entity entity;
102 	struct workqueue_struct *wq;
103 	struct mutex mutex;
104 
105 	struct {
106 		struct {
107 			struct list_head head;
108 			spinlock_t lock;
109 		} list;
110 		struct wait_queue_head wq;
111 	} job;
112 };
113 
114 int nouveau_sched_create(struct nouveau_sched **psched, struct nouveau_drm *drm,
115 			 struct workqueue_struct *wq, u32 credit_limit);
116 void nouveau_sched_destroy(struct nouveau_sched **psched);
117 
118 #endif
119