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 QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS (500)
33 #define CIK_VMID_NUM (8)
34 #define KFD_VMID_START_OFFSET (8)
35 #define VMID_PER_DEVICE CIK_VMID_NUM
36 #define KFD_DQM_FIRST_PIPE (0)
37 #define CIK_SDMA_QUEUES (4)
38 #define CIK_SDMA_QUEUES_PER_ENGINE (2)
39 #define CIK_SDMA_ENGINE_NUM (2)
41 struct device_process_node {
42 struct qcm_process_device *qpd;
43 struct list_head list;
47 * struct device_queue_manager_ops
49 * @create_queue: Queue creation routine.
51 * @destroy_queue: Queue destruction routine.
53 * @update_queue: Queue update routine.
55 * @get_mqd_manager: Returns the mqd manager according to the mqd type.
57 * @exeute_queues: Dispatches the queues list to the H/W.
59 * @register_process: This routine associates a specific process with device.
61 * @unregister_process: destroys the associations between process to device.
63 * @initialize: Initializes the pipelines and memory module for that device.
65 * @start: Initializes the resources/modules the the device needs for queues
66 * execution. This function is called on device initialization and after the
67 * system woke up after suspension.
69 * @stop: This routine stops execution of all the active queue running on the
70 * H/W and basically this function called on system suspend.
72 * @uninitialize: Destroys all the device queue manager resources allocated in
75 * @create_kernel_queue: Creates kernel queue. Used for debug queue.
77 * @destroy_kernel_queue: Destroys kernel queue. Used for debug queue.
79 * @set_cache_memory_policy: Sets memory policy (cached/ non cached) for the
84 struct device_queue_manager_ops {
85 int (*create_queue)(struct device_queue_manager *dqm,
87 struct qcm_process_device *qpd,
90 int (*destroy_queue)(struct device_queue_manager *dqm,
91 struct qcm_process_device *qpd,
94 int (*update_queue)(struct device_queue_manager *dqm,
97 struct mqd_manager * (*get_mqd_manager)
98 (struct device_queue_manager *dqm,
99 enum KFD_MQD_TYPE type);
101 int (*register_process)(struct device_queue_manager *dqm,
102 struct qcm_process_device *qpd);
104 int (*unregister_process)(struct device_queue_manager *dqm,
105 struct qcm_process_device *qpd);
107 int (*initialize)(struct device_queue_manager *dqm);
108 int (*start)(struct device_queue_manager *dqm);
109 int (*stop)(struct device_queue_manager *dqm);
110 void (*uninitialize)(struct device_queue_manager *dqm);
111 int (*create_kernel_queue)(struct device_queue_manager *dqm,
112 struct kernel_queue *kq,
113 struct qcm_process_device *qpd);
115 void (*destroy_kernel_queue)(struct device_queue_manager *dqm,
116 struct kernel_queue *kq,
117 struct qcm_process_device *qpd);
119 bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
120 struct qcm_process_device *qpd,
121 enum cache_policy default_policy,
122 enum cache_policy alternate_policy,
123 void __user *alternate_aperture_base,
124 uint64_t alternate_aperture_size);
127 struct device_queue_manager_asic_ops {
128 int (*register_process)(struct device_queue_manager *dqm,
129 struct qcm_process_device *qpd);
130 int (*initialize)(struct device_queue_manager *dqm);
131 bool (*set_cache_memory_policy)(struct device_queue_manager *dqm,
132 struct qcm_process_device *qpd,
133 enum cache_policy default_policy,
134 enum cache_policy alternate_policy,
135 void __user *alternate_aperture_base,
136 uint64_t alternate_aperture_size);
137 void (*init_sdma_vm)(struct device_queue_manager *dqm,
139 struct qcm_process_device *qpd);
143 * struct device_queue_manager
145 * This struct is a base class for the kfd queues scheduler in the
146 * device level. The device base class should expose the basic operations
147 * for queue creation and queue destruction. This base class hides the
148 * scheduling mode of the driver and the specific implementation of the
149 * concrete device. This class is the only class in the queues scheduler
150 * that configures the H/W.
154 struct device_queue_manager {
155 struct device_queue_manager_ops ops;
156 struct device_queue_manager_asic_ops ops_asic_specific;
158 struct mqd_manager *mqds[KFD_MQD_TYPE_MAX];
159 struct packet_manager packets;
162 struct list_head queues;
163 unsigned int processes_count;
164 unsigned int queue_count;
165 unsigned int sdma_queue_count;
166 unsigned int total_queue_count;
167 unsigned int next_pipe_to_allocate;
168 unsigned int *allocated_queues;
169 unsigned int sdma_bitmap;
170 unsigned int vmid_bitmap;
171 uint64_t pipelines_addr;
172 struct kfd_mem_obj *pipeline_mem;
173 uint64_t fence_gpu_addr;
174 unsigned int *fence_addr;
175 struct kfd_mem_obj *fence_mem;
179 void device_queue_manager_init_cik(struct device_queue_manager_asic_ops *ops);
180 void device_queue_manager_init_vi(struct device_queue_manager_asic_ops *ops);
181 void program_sh_mem_settings(struct device_queue_manager *dqm,
182 struct qcm_process_device *qpd);
183 unsigned int get_queues_num(struct device_queue_manager *dqm);
184 unsigned int get_queues_per_pipe(struct device_queue_manager *dqm);
185 unsigned int get_pipes_per_mec(struct device_queue_manager *dqm);
187 static inline unsigned int get_sh_mem_bases_32(struct kfd_process_device *pdd)
189 return (pdd->lds_base >> 16) & 0xFF;
192 static inline unsigned int
193 get_sh_mem_bases_nybble_64(struct kfd_process_device *pdd)
195 return (pdd->lds_base >> 60) & 0x0E;
198 #endif /* KFD_DEVICE_QUEUE_MANAGER_H_ */