1 /* SPDX-License-Identifier: MIT */
3 #ifndef NOUVEAU_SCHED_H
4 #define NOUVEAU_SCHED_H
6 #include <linux/types.h>
8 #include <drm/drm_gpuvm.h>
9 #include <drm/gpu_scheduler.h>
11 #include "nouveau_drv.h"
13 #define to_nouveau_job(sched_job) \
14 container_of((sched_job), struct nouveau_job, base)
16 struct nouveau_job_ops;
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,
27 struct nouveau_job_args {
28 struct drm_file *file_priv;
29 struct nouveau_sched *sched;
32 enum dma_resv_usage resv_usage;
36 struct drm_nouveau_sync *s;
41 struct drm_nouveau_sync *s;
45 struct nouveau_job_ops *ops;
49 struct drm_sched_job base;
51 enum nouveau_job_state state;
53 struct nouveau_sched *sched;
54 struct list_head entry;
56 struct drm_file *file_priv;
57 struct nouveau_cli *cli;
59 enum dma_resv_usage resv_usage;
60 struct dma_fence *done_fence;
65 struct drm_nouveau_sync *data;
70 struct drm_nouveau_sync *data;
71 struct drm_syncobj **objs;
72 struct dma_fence_chain **chains;
76 struct nouveau_job_ops {
77 /* If .submit() returns without any error, it is guaranteed that
78 * armed_submit() is called.
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 *);
88 int nouveau_job_ucopy_syncs(struct nouveau_job_args *args,
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);
99 struct nouveau_sched {
100 struct drm_gpu_scheduler base;
101 struct drm_sched_entity entity;
102 struct workqueue_struct *wq;
107 struct list_head head;
110 struct wait_queue_head wq;
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);