]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/amd/scheduler/gpu_scheduler.h
drm/amdgpu: remove some more unused entity members v2
[karo-tx-linux.git] / drivers / gpu / drm / amd / scheduler / gpu_scheduler.h
1 /*
2  * Copyright 2015 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23
24 #ifndef _GPU_SCHEDULER_H_
25 #define _GPU_SCHEDULER_H_
26
27 #include <linux/kfifo.h>
28 #include <linux/fence.h>
29
30 #define AMD_GPU_WAIT_IDLE_TIMEOUT_IN_MS         3000
31
32 struct amd_gpu_scheduler;
33 struct amd_sched_rq;
34
35 /**
36  * A scheduler entity is a wrapper around a job queue or a group
37  * of other entities. Entities take turns emitting jobs from their 
38  * job queues to corresponding hardware ring based on scheduling
39  * policy.
40 */
41 struct amd_sched_entity {
42         struct list_head                list;
43         struct amd_sched_rq             *belongto_rq;
44         atomic_t                        fence_seq;
45         /* the job_queue maintains the jobs submitted by clients */
46         struct kfifo                    job_queue;
47         spinlock_t                      queue_lock;
48         struct amd_gpu_scheduler        *scheduler;
49         wait_queue_head_t               wait_queue;
50         uint64_t                        fence_context;
51         char                            name[20];
52         bool                            need_wakeup;
53 };
54
55 /**
56  * Run queue is a set of entities scheduling command submissions for
57  * one specific ring. It implements the scheduling policy that selects
58  * the next entity to emit commands from.
59 */
60 struct amd_sched_rq {
61         spinlock_t              lock;
62         struct list_head        entities;
63         struct amd_sched_entity *current_entity;
64 };
65
66 struct amd_sched_fence {
67         struct fence                    base;
68         struct fence_cb                 cb;
69         struct amd_sched_entity         *entity;
70         spinlock_t                      lock;
71 };
72
73 struct amd_sched_job {
74         struct fence_cb                 cb;
75         struct amd_gpu_scheduler        *sched;
76         struct amd_sched_entity         *s_entity;
77         struct amd_sched_fence          *s_fence;
78 };
79
80 extern const struct fence_ops amd_sched_fence_ops;
81 static inline struct amd_sched_fence *to_amd_sched_fence(struct fence *f)
82 {
83         struct amd_sched_fence *__f = container_of(f, struct amd_sched_fence, base);
84
85         if (__f->base.ops == &amd_sched_fence_ops)
86                 return __f;
87
88         return NULL;
89 }
90
91 /**
92  * Define the backend operations called by the scheduler,
93  * these functions should be implemented in driver side
94 */
95 struct amd_sched_backend_ops {
96         int (*prepare_job)(struct amd_gpu_scheduler *sched,
97                            struct amd_sched_entity *c_entity,
98                            struct amd_sched_job *job);
99         struct fence *(*run_job)(struct amd_gpu_scheduler *sched,
100                                  struct amd_sched_entity *c_entity,
101                                  struct amd_sched_job *job);
102         void (*process_job)(struct amd_gpu_scheduler *sched,
103                                     struct amd_sched_job *job);
104 };
105
106 /**
107  * One scheduler is implemented for each hardware ring
108 */
109 struct amd_gpu_scheduler {
110         void                            *device;
111         struct task_struct              *thread;
112         struct amd_sched_rq             sched_rq;
113         struct amd_sched_rq             kernel_rq;
114         atomic_t                        hw_rq_count;
115         struct amd_sched_backend_ops    *ops;
116         uint32_t                        ring_id;
117         uint32_t                        granularity; /* in ms unit */
118         uint32_t                        preemption;
119         wait_queue_head_t               wait_queue;
120         struct amd_sched_entity *current_entity;
121         struct mutex                    sched_lock;
122         uint32_t                        hw_submission_limit;
123 };
124
125 struct amd_gpu_scheduler *amd_sched_create(void *device,
126                                 struct amd_sched_backend_ops *ops,
127                                 uint32_t ring,
128                                 uint32_t granularity,
129                                 uint32_t preemption,
130                                 uint32_t hw_submission);
131 int amd_sched_destroy(struct amd_gpu_scheduler *sched);
132
133 int amd_sched_push_job(struct amd_sched_job *sched_job);
134
135 int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
136                           struct amd_sched_entity *entity,
137                           struct amd_sched_rq *rq,
138                           uint32_t jobs);
139 int amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
140                           struct amd_sched_entity *entity);
141
142 struct amd_sched_fence *amd_sched_fence_create(
143         struct amd_sched_entity *s_entity);
144 void amd_sched_fence_signal(struct amd_sched_fence *fence);
145
146
147 #endif