2 * Copyright 2015 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
24 #ifndef _GPU_SCHEDULER_H_
25 #define _GPU_SCHEDULER_H_
27 #include <linux/kfifo.h>
28 #include <linux/fence.h>
30 #define AMD_GPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
32 struct amd_gpu_scheduler;
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
41 struct amd_sched_entity {
42 struct list_head list;
43 struct amd_sched_rq *belongto_rq;
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;
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.
62 struct list_head entities;
63 struct amd_sched_entity *current_entity;
66 struct amd_sched_fence {
69 struct amd_sched_entity *entity;
73 struct amd_sched_job {
75 struct amd_gpu_scheduler *sched;
76 struct amd_sched_entity *s_entity;
77 struct amd_sched_fence *s_fence;
80 extern const struct fence_ops amd_sched_fence_ops;
81 static inline struct amd_sched_fence *to_amd_sched_fence(struct fence *f)
83 struct amd_sched_fence *__f = container_of(f, struct amd_sched_fence, base);
85 if (__f->base.ops == &amd_sched_fence_ops)
92 * Define the backend operations called by the scheduler,
93 * these functions should be implemented in driver side
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);
107 * One scheduler is implemented for each hardware ring
109 struct amd_gpu_scheduler {
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;
117 uint32_t granularity; /* in ms unit */
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;
125 struct amd_gpu_scheduler *amd_sched_create(void *device,
126 struct amd_sched_backend_ops *ops,
128 uint32_t granularity,
130 uint32_t hw_submission);
131 int amd_sched_destroy(struct amd_gpu_scheduler *sched);
133 int amd_sched_push_job(struct amd_sched_job *sched_job);
135 int amd_sched_entity_init(struct amd_gpu_scheduler *sched,
136 struct amd_sched_entity *entity,
137 struct amd_sched_rq *rq,
139 int amd_sched_entity_fini(struct amd_gpu_scheduler *sched,
140 struct amd_sched_entity *entity);
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);