Loading...
1/*
2 * Copyright 2014 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#include <linux/slab.h>
25#include <linux/list.h>
26#include "kfd_device_queue_manager.h"
27#include "kfd_priv.h"
28#include "kfd_kernel_queue.h"
29
30static inline struct process_queue_node *get_queue_by_qid(
31 struct process_queue_manager *pqm, unsigned int qid)
32{
33 struct process_queue_node *pqn;
34
35 BUG_ON(!pqm);
36
37 list_for_each_entry(pqn, &pqm->queues, process_queue_list) {
38 if (pqn->q && pqn->q->properties.queue_id == qid)
39 return pqn;
40 if (pqn->kq && pqn->kq->queue->properties.queue_id == qid)
41 return pqn;
42 }
43
44 return NULL;
45}
46
47static int find_available_queue_slot(struct process_queue_manager *pqm,
48 unsigned int *qid)
49{
50 unsigned long found;
51
52 BUG_ON(!pqm || !qid);
53
54 pr_debug("kfd: in %s\n", __func__);
55
56 found = find_first_zero_bit(pqm->queue_slot_bitmap,
57 KFD_MAX_NUM_OF_QUEUES_PER_PROCESS);
58
59 pr_debug("kfd: the new slot id %lu\n", found);
60
61 if (found >= KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) {
62 pr_info("amdkfd: Can not open more queues for process with pasid %d\n",
63 pqm->process->pasid);
64 return -ENOMEM;
65 }
66
67 set_bit(found, pqm->queue_slot_bitmap);
68 *qid = found;
69
70 return 0;
71}
72
73int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p)
74{
75 BUG_ON(!pqm);
76
77 INIT_LIST_HEAD(&pqm->queues);
78 pqm->queue_slot_bitmap =
79 kzalloc(DIV_ROUND_UP(KFD_MAX_NUM_OF_QUEUES_PER_PROCESS,
80 BITS_PER_BYTE), GFP_KERNEL);
81 if (pqm->queue_slot_bitmap == NULL)
82 return -ENOMEM;
83 pqm->process = p;
84
85 return 0;
86}
87
88void pqm_uninit(struct process_queue_manager *pqm)
89{
90 int retval;
91 struct process_queue_node *pqn, *next;
92
93 BUG_ON(!pqm);
94
95 pr_debug("In func %s\n", __func__);
96
97 list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) {
98 retval = pqm_destroy_queue(
99 pqm,
100 (pqn->q != NULL) ?
101 pqn->q->properties.queue_id :
102 pqn->kq->queue->properties.queue_id);
103
104 if (retval != 0) {
105 pr_err("kfd: failed to destroy queue\n");
106 return;
107 }
108 }
109 kfree(pqm->queue_slot_bitmap);
110 pqm->queue_slot_bitmap = NULL;
111}
112
113static int create_cp_queue(struct process_queue_manager *pqm,
114 struct kfd_dev *dev, struct queue **q,
115 struct queue_properties *q_properties,
116 struct file *f, unsigned int qid)
117{
118 int retval;
119
120 retval = 0;
121
122 /* Doorbell initialized in user space*/
123 q_properties->doorbell_ptr = NULL;
124
125 q_properties->doorbell_off =
126 kfd_queue_id_to_doorbell(dev, pqm->process, qid);
127
128 /* let DQM handle it*/
129 q_properties->vmid = 0;
130 q_properties->queue_id = qid;
131
132 retval = init_queue(q, *q_properties);
133 if (retval != 0)
134 goto err_init_queue;
135
136 (*q)->device = dev;
137 (*q)->process = pqm->process;
138
139 pr_debug("kfd: PQM After init queue");
140
141 return retval;
142
143err_init_queue:
144 return retval;
145}
146
147int pqm_create_queue(struct process_queue_manager *pqm,
148 struct kfd_dev *dev,
149 struct file *f,
150 struct queue_properties *properties,
151 unsigned int flags,
152 enum kfd_queue_type type,
153 unsigned int *qid)
154{
155 int retval;
156 struct kfd_process_device *pdd;
157 struct queue_properties q_properties;
158 struct queue *q;
159 struct process_queue_node *pqn;
160 struct kernel_queue *kq;
161 int num_queues = 0;
162 struct queue *cur;
163
164 BUG_ON(!pqm || !dev || !properties || !qid);
165
166 memset(&q_properties, 0, sizeof(struct queue_properties));
167 memcpy(&q_properties, properties, sizeof(struct queue_properties));
168 q = NULL;
169 kq = NULL;
170
171 pdd = kfd_get_process_device_data(dev, pqm->process);
172 if (!pdd) {
173 pr_err("Process device data doesn't exist\n");
174 return -1;
175 }
176
177 /*
178 * for debug process, verify that it is within the static queues limit
179 * currently limit is set to half of the total avail HQD slots
180 * If we are just about to create DIQ, the is_debug flag is not set yet
181 * Hence we also check the type as well
182 */
183 if ((pdd->qpd.is_debug) ||
184 (type == KFD_QUEUE_TYPE_DIQ)) {
185 list_for_each_entry(cur, &pdd->qpd.queues_list, list)
186 num_queues++;
187 if (num_queues >= dev->device_info->max_no_of_hqd/2)
188 return (-ENOSPC);
189 }
190
191 retval = find_available_queue_slot(pqm, qid);
192 if (retval != 0)
193 return retval;
194
195 if (list_empty(&pqm->queues)) {
196 pdd->qpd.pqm = pqm;
197 dev->dqm->ops.register_process(dev->dqm, &pdd->qpd);
198 }
199
200 pqn = kzalloc(sizeof(struct process_queue_node), GFP_KERNEL);
201 if (!pqn) {
202 retval = -ENOMEM;
203 goto err_allocate_pqn;
204 }
205
206 switch (type) {
207 case KFD_QUEUE_TYPE_SDMA:
208 case KFD_QUEUE_TYPE_COMPUTE:
209 /* check if there is over subscription */
210 if ((sched_policy == KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION) &&
211 ((dev->dqm->processes_count >= VMID_PER_DEVICE) ||
212 (dev->dqm->queue_count >= PIPE_PER_ME_CP_SCHEDULING * QUEUES_PER_PIPE))) {
213 pr_err("kfd: over-subscription is not allowed in radeon_kfd.sched_policy == 1\n");
214 retval = -EPERM;
215 goto err_create_queue;
216 }
217
218 retval = create_cp_queue(pqm, dev, &q, &q_properties, f, *qid);
219 if (retval != 0)
220 goto err_create_queue;
221 pqn->q = q;
222 pqn->kq = NULL;
223 retval = dev->dqm->ops.create_queue(dev->dqm, q, &pdd->qpd,
224 &q->properties.vmid);
225 pr_debug("DQM returned %d for create_queue\n", retval);
226 print_queue(q);
227 break;
228 case KFD_QUEUE_TYPE_DIQ:
229 kq = kernel_queue_init(dev, KFD_QUEUE_TYPE_DIQ);
230 if (kq == NULL) {
231 retval = -ENOMEM;
232 goto err_create_queue;
233 }
234 kq->queue->properties.queue_id = *qid;
235 pqn->kq = kq;
236 pqn->q = NULL;
237 retval = dev->dqm->ops.create_kernel_queue(dev->dqm,
238 kq, &pdd->qpd);
239 break;
240 default:
241 BUG();
242 break;
243 }
244
245 if (retval != 0) {
246 pr_debug("Error dqm create queue\n");
247 goto err_create_queue;
248 }
249
250 pr_debug("kfd: PQM After DQM create queue\n");
251
252 list_add(&pqn->process_queue_list, &pqm->queues);
253
254 if (q) {
255 *properties = q->properties;
256 pr_debug("kfd: PQM done creating queue\n");
257 print_queue_properties(properties);
258 }
259
260 return retval;
261
262err_create_queue:
263 kfree(pqn);
264err_allocate_pqn:
265 /* check if queues list is empty unregister process from device */
266 clear_bit(*qid, pqm->queue_slot_bitmap);
267 if (list_empty(&pqm->queues))
268 dev->dqm->ops.unregister_process(dev->dqm, &pdd->qpd);
269 return retval;
270}
271
272int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
273{
274 struct process_queue_node *pqn;
275 struct kfd_process_device *pdd;
276 struct device_queue_manager *dqm;
277 struct kfd_dev *dev;
278 int retval;
279
280 dqm = NULL;
281
282 BUG_ON(!pqm);
283 retval = 0;
284
285 pr_debug("kfd: In Func %s\n", __func__);
286
287 pqn = get_queue_by_qid(pqm, qid);
288 if (pqn == NULL) {
289 pr_err("kfd: queue id does not match any known queue\n");
290 return -EINVAL;
291 }
292
293 dev = NULL;
294 if (pqn->kq)
295 dev = pqn->kq->dev;
296 if (pqn->q)
297 dev = pqn->q->device;
298 BUG_ON(!dev);
299
300 pdd = kfd_get_process_device_data(dev, pqm->process);
301 if (!pdd) {
302 pr_err("Process device data doesn't exist\n");
303 return -1;
304 }
305
306 if (pqn->kq) {
307 /* destroy kernel queue (DIQ) */
308 dqm = pqn->kq->dev->dqm;
309 dqm->ops.destroy_kernel_queue(dqm, pqn->kq, &pdd->qpd);
310 kernel_queue_uninit(pqn->kq);
311 }
312
313 if (pqn->q) {
314 dqm = pqn->q->device->dqm;
315 retval = dqm->ops.destroy_queue(dqm, &pdd->qpd, pqn->q);
316 if (retval != 0)
317 return retval;
318
319 uninit_queue(pqn->q);
320 }
321
322 list_del(&pqn->process_queue_list);
323 kfree(pqn);
324 clear_bit(qid, pqm->queue_slot_bitmap);
325
326 if (list_empty(&pqm->queues))
327 dqm->ops.unregister_process(dqm, &pdd->qpd);
328
329 return retval;
330}
331
332int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
333 struct queue_properties *p)
334{
335 int retval;
336 struct process_queue_node *pqn;
337
338 BUG_ON(!pqm);
339
340 pqn = get_queue_by_qid(pqm, qid);
341 if (!pqn) {
342 pr_debug("amdkfd: No queue %d exists for update operation\n",
343 qid);
344 return -EFAULT;
345 }
346
347 pqn->q->properties.queue_address = p->queue_address;
348 pqn->q->properties.queue_size = p->queue_size;
349 pqn->q->properties.queue_percent = p->queue_percent;
350 pqn->q->properties.priority = p->priority;
351
352 retval = pqn->q->device->dqm->ops.update_queue(pqn->q->device->dqm,
353 pqn->q);
354 if (retval != 0)
355 return retval;
356
357 return 0;
358}
359
360struct kernel_queue *pqm_get_kernel_queue(
361 struct process_queue_manager *pqm,
362 unsigned int qid)
363{
364 struct process_queue_node *pqn;
365
366 BUG_ON(!pqm);
367
368 pqn = get_queue_by_qid(pqm, qid);
369 if (pqn && pqn->kq)
370 return pqn->kq;
371
372 return NULL;
373}
374
375
1/*
2 * Copyright 2014 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#include <linux/slab.h>
25#include <linux/list.h>
26#include "kfd_device_queue_manager.h"
27#include "kfd_priv.h"
28#include "kfd_kernel_queue.h"
29
30static inline struct process_queue_node *get_queue_by_qid(
31 struct process_queue_manager *pqm, unsigned int qid)
32{
33 struct process_queue_node *pqn;
34
35 list_for_each_entry(pqn, &pqm->queues, process_queue_list) {
36 if ((pqn->q && pqn->q->properties.queue_id == qid) ||
37 (pqn->kq && pqn->kq->queue->properties.queue_id == qid))
38 return pqn;
39 }
40
41 return NULL;
42}
43
44static int find_available_queue_slot(struct process_queue_manager *pqm,
45 unsigned int *qid)
46{
47 unsigned long found;
48
49 found = find_first_zero_bit(pqm->queue_slot_bitmap,
50 KFD_MAX_NUM_OF_QUEUES_PER_PROCESS);
51
52 pr_debug("The new slot id %lu\n", found);
53
54 if (found >= KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) {
55 pr_info("Cannot open more queues for process with pasid %d\n",
56 pqm->process->pasid);
57 return -ENOMEM;
58 }
59
60 set_bit(found, pqm->queue_slot_bitmap);
61 *qid = found;
62
63 return 0;
64}
65
66void kfd_process_dequeue_from_device(struct kfd_process_device *pdd)
67{
68 struct kfd_dev *dev = pdd->dev;
69
70 if (pdd->already_dequeued)
71 return;
72
73 dev->dqm->ops.process_termination(dev->dqm, &pdd->qpd);
74 pdd->already_dequeued = true;
75}
76
77void kfd_process_dequeue_from_all_devices(struct kfd_process *p)
78{
79 struct kfd_process_device *pdd;
80
81 list_for_each_entry(pdd, &p->per_device_data, per_device_list)
82 kfd_process_dequeue_from_device(pdd);
83}
84
85int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p)
86{
87 INIT_LIST_HEAD(&pqm->queues);
88 pqm->queue_slot_bitmap =
89 kzalloc(DIV_ROUND_UP(KFD_MAX_NUM_OF_QUEUES_PER_PROCESS,
90 BITS_PER_BYTE), GFP_KERNEL);
91 if (!pqm->queue_slot_bitmap)
92 return -ENOMEM;
93 pqm->process = p;
94
95 return 0;
96}
97
98void pqm_uninit(struct process_queue_manager *pqm)
99{
100 struct process_queue_node *pqn, *next;
101
102 list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) {
103 uninit_queue(pqn->q);
104 list_del(&pqn->process_queue_list);
105 kfree(pqn);
106 }
107
108 kfree(pqm->queue_slot_bitmap);
109 pqm->queue_slot_bitmap = NULL;
110}
111
112static int create_cp_queue(struct process_queue_manager *pqm,
113 struct kfd_dev *dev, struct queue **q,
114 struct queue_properties *q_properties,
115 struct file *f, unsigned int qid)
116{
117 int retval;
118
119 /* Doorbell initialized in user space*/
120 q_properties->doorbell_ptr = NULL;
121
122 q_properties->doorbell_off =
123 kfd_queue_id_to_doorbell(dev, pqm->process, qid);
124
125 /* let DQM handle it*/
126 q_properties->vmid = 0;
127 q_properties->queue_id = qid;
128
129 retval = init_queue(q, q_properties);
130 if (retval != 0)
131 return retval;
132
133 (*q)->device = dev;
134 (*q)->process = pqm->process;
135
136 pr_debug("PQM After init queue");
137
138 return retval;
139}
140
141int pqm_create_queue(struct process_queue_manager *pqm,
142 struct kfd_dev *dev,
143 struct file *f,
144 struct queue_properties *properties,
145 unsigned int *qid)
146{
147 int retval;
148 struct kfd_process_device *pdd;
149 struct queue *q;
150 struct process_queue_node *pqn;
151 struct kernel_queue *kq;
152 enum kfd_queue_type type = properties->type;
153 unsigned int max_queues = 127; /* HWS limit */
154
155 q = NULL;
156 kq = NULL;
157
158 pdd = kfd_get_process_device_data(dev, pqm->process);
159 if (!pdd) {
160 pr_err("Process device data doesn't exist\n");
161 return -1;
162 }
163
164 /*
165 * for debug process, verify that it is within the static queues limit
166 * currently limit is set to half of the total avail HQD slots
167 * If we are just about to create DIQ, the is_debug flag is not set yet
168 * Hence we also check the type as well
169 */
170 if ((pdd->qpd.is_debug) || (type == KFD_QUEUE_TYPE_DIQ))
171 max_queues = dev->device_info->max_no_of_hqd/2;
172
173 if (pdd->qpd.queue_count >= max_queues)
174 return -ENOSPC;
175
176 retval = find_available_queue_slot(pqm, qid);
177 if (retval != 0)
178 return retval;
179
180 if (list_empty(&pdd->qpd.queues_list) &&
181 list_empty(&pdd->qpd.priv_queue_list))
182 dev->dqm->ops.register_process(dev->dqm, &pdd->qpd);
183
184 pqn = kzalloc(sizeof(*pqn), GFP_KERNEL);
185 if (!pqn) {
186 retval = -ENOMEM;
187 goto err_allocate_pqn;
188 }
189
190 switch (type) {
191 case KFD_QUEUE_TYPE_SDMA:
192 if (dev->dqm->queue_count >=
193 CIK_SDMA_QUEUES_PER_ENGINE * CIK_SDMA_ENGINE_NUM) {
194 pr_err("Over-subscription is not allowed for SDMA.\n");
195 retval = -EPERM;
196 goto err_create_queue;
197 }
198
199 retval = create_cp_queue(pqm, dev, &q, properties, f, *qid);
200 if (retval != 0)
201 goto err_create_queue;
202 pqn->q = q;
203 pqn->kq = NULL;
204 retval = dev->dqm->ops.create_queue(dev->dqm, q, &pdd->qpd);
205 pr_debug("DQM returned %d for create_queue\n", retval);
206 print_queue(q);
207 break;
208
209 case KFD_QUEUE_TYPE_COMPUTE:
210 /* check if there is over subscription */
211 if ((dev->dqm->sched_policy ==
212 KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION) &&
213 ((dev->dqm->processes_count >= dev->vm_info.vmid_num_kfd) ||
214 (dev->dqm->queue_count >= get_queues_num(dev->dqm)))) {
215 pr_err("Over-subscription is not allowed in radeon_kfd.sched_policy == 1\n");
216 retval = -EPERM;
217 goto err_create_queue;
218 }
219
220 retval = create_cp_queue(pqm, dev, &q, properties, f, *qid);
221 if (retval != 0)
222 goto err_create_queue;
223 pqn->q = q;
224 pqn->kq = NULL;
225 retval = dev->dqm->ops.create_queue(dev->dqm, q, &pdd->qpd);
226 pr_debug("DQM returned %d for create_queue\n", retval);
227 print_queue(q);
228 break;
229 case KFD_QUEUE_TYPE_DIQ:
230 kq = kernel_queue_init(dev, KFD_QUEUE_TYPE_DIQ);
231 if (!kq) {
232 retval = -ENOMEM;
233 goto err_create_queue;
234 }
235 kq->queue->properties.queue_id = *qid;
236 pqn->kq = kq;
237 pqn->q = NULL;
238 retval = dev->dqm->ops.create_kernel_queue(dev->dqm,
239 kq, &pdd->qpd);
240 break;
241 default:
242 WARN(1, "Invalid queue type %d", type);
243 retval = -EINVAL;
244 }
245
246 if (retval != 0) {
247 pr_err("DQM create queue failed\n");
248 goto err_create_queue;
249 }
250
251 pr_debug("PQM After DQM create queue\n");
252
253 list_add(&pqn->process_queue_list, &pqm->queues);
254
255 if (q) {
256 pr_debug("PQM done creating queue\n");
257 print_queue_properties(&q->properties);
258 }
259
260 return retval;
261
262err_create_queue:
263 kfree(pqn);
264err_allocate_pqn:
265 /* check if queues list is empty unregister process from device */
266 clear_bit(*qid, pqm->queue_slot_bitmap);
267 if (list_empty(&pdd->qpd.queues_list) &&
268 list_empty(&pdd->qpd.priv_queue_list))
269 dev->dqm->ops.unregister_process(dev->dqm, &pdd->qpd);
270 return retval;
271}
272
273int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid)
274{
275 struct process_queue_node *pqn;
276 struct kfd_process_device *pdd;
277 struct device_queue_manager *dqm;
278 struct kfd_dev *dev;
279 int retval;
280
281 dqm = NULL;
282
283 retval = 0;
284
285 pqn = get_queue_by_qid(pqm, qid);
286 if (!pqn) {
287 pr_err("Queue id does not match any known queue\n");
288 return -EINVAL;
289 }
290
291 dev = NULL;
292 if (pqn->kq)
293 dev = pqn->kq->dev;
294 if (pqn->q)
295 dev = pqn->q->device;
296 if (WARN_ON(!dev))
297 return -ENODEV;
298
299 pdd = kfd_get_process_device_data(dev, pqm->process);
300 if (!pdd) {
301 pr_err("Process device data doesn't exist\n");
302 return -1;
303 }
304
305 if (pqn->kq) {
306 /* destroy kernel queue (DIQ) */
307 dqm = pqn->kq->dev->dqm;
308 dqm->ops.destroy_kernel_queue(dqm, pqn->kq, &pdd->qpd);
309 kernel_queue_uninit(pqn->kq);
310 }
311
312 if (pqn->q) {
313 dqm = pqn->q->device->dqm;
314 retval = dqm->ops.destroy_queue(dqm, &pdd->qpd, pqn->q);
315 if (retval) {
316 pr_debug("Destroy queue failed, returned %d\n", retval);
317 goto err_destroy_queue;
318 }
319 uninit_queue(pqn->q);
320 }
321
322 list_del(&pqn->process_queue_list);
323 kfree(pqn);
324 clear_bit(qid, pqm->queue_slot_bitmap);
325
326 if (list_empty(&pdd->qpd.queues_list) &&
327 list_empty(&pdd->qpd.priv_queue_list))
328 dqm->ops.unregister_process(dqm, &pdd->qpd);
329
330err_destroy_queue:
331 return retval;
332}
333
334int pqm_update_queue(struct process_queue_manager *pqm, unsigned int qid,
335 struct queue_properties *p)
336{
337 int retval;
338 struct process_queue_node *pqn;
339
340 pqn = get_queue_by_qid(pqm, qid);
341 if (!pqn) {
342 pr_debug("No queue %d exists for update operation\n", qid);
343 return -EFAULT;
344 }
345
346 pqn->q->properties.queue_address = p->queue_address;
347 pqn->q->properties.queue_size = p->queue_size;
348 pqn->q->properties.queue_percent = p->queue_percent;
349 pqn->q->properties.priority = p->priority;
350
351 retval = pqn->q->device->dqm->ops.update_queue(pqn->q->device->dqm,
352 pqn->q);
353 if (retval != 0)
354 return retval;
355
356 return 0;
357}
358
359struct kernel_queue *pqm_get_kernel_queue(
360 struct process_queue_manager *pqm,
361 unsigned int qid)
362{
363 struct process_queue_node *pqn;
364
365 pqn = get_queue_by_qid(pqm, qid);
366 if (pqn && pqn->kq)
367 return pqn->kq;
368
369 return NULL;
370}
371
372#if defined(CONFIG_DEBUG_FS)
373
374int pqm_debugfs_mqds(struct seq_file *m, void *data)
375{
376 struct process_queue_manager *pqm = data;
377 struct process_queue_node *pqn;
378 struct queue *q;
379 enum KFD_MQD_TYPE mqd_type;
380 struct mqd_manager *mqd_manager;
381 int r = 0;
382
383 list_for_each_entry(pqn, &pqm->queues, process_queue_list) {
384 if (pqn->q) {
385 q = pqn->q;
386 switch (q->properties.type) {
387 case KFD_QUEUE_TYPE_SDMA:
388 seq_printf(m, " SDMA queue on device %x\n",
389 q->device->id);
390 mqd_type = KFD_MQD_TYPE_SDMA;
391 break;
392 case KFD_QUEUE_TYPE_COMPUTE:
393 seq_printf(m, " Compute queue on device %x\n",
394 q->device->id);
395 mqd_type = KFD_MQD_TYPE_CP;
396 break;
397 default:
398 seq_printf(m,
399 " Bad user queue type %d on device %x\n",
400 q->properties.type, q->device->id);
401 continue;
402 }
403 mqd_manager = q->device->dqm->ops.get_mqd_manager(
404 q->device->dqm, mqd_type);
405 } else if (pqn->kq) {
406 q = pqn->kq->queue;
407 mqd_manager = pqn->kq->mqd;
408 switch (q->properties.type) {
409 case KFD_QUEUE_TYPE_DIQ:
410 seq_printf(m, " DIQ on device %x\n",
411 pqn->kq->dev->id);
412 mqd_type = KFD_MQD_TYPE_HIQ;
413 break;
414 default:
415 seq_printf(m,
416 " Bad kernel queue type %d on device %x\n",
417 q->properties.type,
418 pqn->kq->dev->id);
419 continue;
420 }
421 } else {
422 seq_printf(m,
423 " Weird: Queue node with neither kernel nor user queue\n");
424 continue;
425 }
426
427 r = mqd_manager->debugfs_show_mqd(m, q->mqd);
428 if (r != 0)
429 break;
430 }
431
432 return r;
433}
434
435#endif