2 * Copyright 2014 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 KFD_DEVICE_QUEUE_MANAGER_H_
25 #define KFD_DEVICE_QUEUE_MANAGER_H_
27 #include <linux/rwsem.h>
28 #include <linux/list.h>
30 #include "kfd_mqd_manager.h"
32 #define KFD_UNMAP_LATENCY_MS (4000)
33 #define QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS (2 * KFD_UNMAP_LATENCY_MS + 1000)
35 #define CIK_SDMA_QUEUES (4)
36 #define CIK_SDMA_QUEUES_PER_ENGINE (2)
37 #define CIK_SDMA_ENGINE_NUM (2)
39 struct device_process_node {
40 struct qcm_process_device *qpd;
41 struct list_head list;
45 * struct device_queue_manager_ops
47 * @create_queue: Queue creation routine.
49 * @destroy_queue: Queue destruction routine.
51 * @update_queue: Queue update routine.
53 * @get_mqd_manager: Returns the mqd manager according to the mqd type.
55 * @exeute_queues: Dispatches the queues list to the H/W.
57 * @register_process: This routine associates a specific process with device.
59 * @unregister_process: destroys the associations between process to device.
61 * @initialize: Initializes the pipelines and memory module for that device.
63 * @start: Initializes the resources/modules the the device needs for queues
64 * execution. This function is called on device initialization and after the
65 * system woke up after suspension.
67 * @stop: This routine stops execution of all the active queue running on the
68 * H/W and basically this function called on system suspend.
70 * @uninitialize: Destroys all the device queue manager resources allocated in
73 * @create_kernel_queue: Creates kernel queue. Used for debug queue.
75 * @destroy_kernel_queue: Destroys kernel queue. Used for debug queue.
77 * @set_cache_memory_policy: Sets memory policy (cached/ non cached) for the
80 * @process_termination: Clears all process queues belongs to that device.
84 struct device_queue_manager_ops {
85 int (*create_queue)(struct device_queue_manager *dqm,
87 struct qcm_process_device *qpd);
89 int (*destroy_queue)(struct device_queue_manager *dqm,
90 struct qcm_process_device *qpd,
93 int (*update_queue)(struct device_queue_manager *dqm,
96 struct mqd_manager * (*get_mqd_manager)
97 (struct device_queue_manager *dqm,
98 enum KFD_MQD_TYPE type);
100 int (*register_process)(struct device_queue_manager *dqm,
101 struct qcm_process_device *qpd);
103 int (*unregister_process)(struct device_queue_manager *dqm,
104 struct qcm_process_device *qpd);
106 int (*initialize)(struct device_queue_manager *dqm);
107 int (*start)(struct device_queue_manager *dqm);
108 int (*stop)(struct device_queue_manager *dqm);
109 void (*uninitialize)(struct device_queue_manager *dqm);
110 int (*create_kernel_queue)(struct device_queue_manager *dqm,
111 struct kernel_queue *kq,
112 struct qcm_process_device *qpd);
114 void (*destroy_kernel_queue)(struct device_queue_manager *dqm,
115 struct kernel_queue *kq,
116 struct qcm_process_device *qpd);
118 bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
119 struct qcm_process_device *qpd,
120 enum cache_policy default_policy,
121 enum cache_policy alternate_policy,
122 void __user *alternate_aperture_base,
123 uint64_t alternate_aperture_size);
125 int (*set_trap_handler)(struct device_queue_manager *dqm,
126 struct qcm_process_device *qpd,
130 int (*process_termination)(struct device_queue_manager *dqm,
131 struct qcm_process_device *qpd);
134 struct device_queue_manager_asic_ops {
135 int (*update_qpd)(struct device_queue_manager *dqm,
136 struct qcm_process_device *qpd);
137 bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
138 struct qcm_process_device *qpd,
139 enum cache_policy default_policy,
140 enum cache_policy alternate_policy,
141 void __user *alternate_aperture_base,
142 uint64_t alternate_aperture_size);
143 void (*init_sdma_vm)(struct device_queue_manager *dqm,
145 struct qcm_process_device *qpd);
149 * struct device_queue_manager
151 * This struct is a base class for the kfd queues scheduler in the
152 * device level. The device base class should expose the basic operations
153 * for queue creation and queue destruction. This base class hides the
154 * scheduling mode of the driver and the specific implementation of the
155 * concrete device. This class is the only class in the queues scheduler
156 * that configures the H/W.
160 struct device_queue_manager {
161 struct device_queue_manager_ops ops;
162 struct device_queue_manager_asic_ops asic_ops;
164 struct mqd_manager *mqds[KFD_MQD_TYPE_MAX];
165 struct packet_manager packets;
168 struct list_head queues;
169 unsigned int processes_count;
170 unsigned int queue_count;
171 unsigned int sdma_queue_count;
172 unsigned int total_queue_count;
173 unsigned int next_pipe_to_allocate;
174 unsigned int *allocated_queues;
175 unsigned int sdma_bitmap;
176 unsigned int vmid_bitmap;
177 uint64_t pipelines_addr;
178 struct kfd_mem_obj *pipeline_mem;
179 uint64_t fence_gpu_addr;
180 unsigned int *fence_addr;
181 struct kfd_mem_obj *fence_mem;
185 void device_queue_manager_init_cik(
186 struct device_queue_manager_asic_ops *asic_ops);
187 void device_queue_manager_init_vi(
188 struct device_queue_manager_asic_ops *asic_ops);
189 void program_sh_mem_settings(struct device_queue_manager *dqm,
190 struct qcm_process_device *qpd);
191 unsigned int get_queues_num(struct device_queue_manager *dqm);
192 unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);
193 unsigned int get_pipes_per_mec(struct device_queue_manager *dqm);
195 static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
197 return (pdd->lds_base >> 16) & 0xFF;
200 static inline unsigned int
201 get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
203 return (pdd->lds_base >> 60) & 0x0E;
206 #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */