1 /*
2 * Copyright 2016-2018 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/printk.h>
25 #include <linux/slab.h>
26 #include <linux/uaccess.h>
27 #include "kfd_priv.h"
28 #include "kfd_mqd_manager.h"
29 #include "v9_structs.h"
30 #include "gc/gc_9_0_offset.h"
31 #include "gc/gc_9_0_sh_mask.h"
32 #include "sdma0/sdma0_4_0_sh_mask.h"
33 #include "amdgpu_amdkfd.h"
34
get_mqd(void * mqd)35 static inline struct v9_mqd *get_mqd(void *mqd)
36 {
37 return (struct v9_mqd *)mqd;
38 }
39
get_sdma_mqd(void * mqd)40 static inline struct v9_sdma_mqd *get_sdma_mqd(void *mqd)
41 {
42 return (struct v9_sdma_mqd *)mqd;
43 }
44
update_cu_mask(struct mqd_manager * mm,void * mqd,struct queue_properties * q)45 static void update_cu_mask(struct mqd_manager *mm, void *mqd,
46 struct queue_properties *q)
47 {
48 struct v9_mqd *m;
49 uint32_t se_mask[KFD_MAX_NUM_SE] = {0};
50
51 if (q->cu_mask_count == 0)
52 return;
53
54 mqd_symmetrically_map_cu_mask(mm,
55 q->cu_mask, q->cu_mask_count, se_mask);
56
57 m = get_mqd(mqd);
58 m->compute_static_thread_mgmt_se0 = se_mask[0];
59 m->compute_static_thread_mgmt_se1 = se_mask[1];
60 m->compute_static_thread_mgmt_se2 = se_mask[2];
61 m->compute_static_thread_mgmt_se3 = se_mask[3];
62 m->compute_static_thread_mgmt_se4 = se_mask[4];
63 m->compute_static_thread_mgmt_se5 = se_mask[5];
64 m->compute_static_thread_mgmt_se6 = se_mask[6];
65 m->compute_static_thread_mgmt_se7 = se_mask[7];
66
67 pr_debug("update cu mask to %#x %#x %#x %#x %#x %#x %#x %#x\n",
68 m->compute_static_thread_mgmt_se0,
69 m->compute_static_thread_mgmt_se1,
70 m->compute_static_thread_mgmt_se2,
71 m->compute_static_thread_mgmt_se3,
72 m->compute_static_thread_mgmt_se4,
73 m->compute_static_thread_mgmt_se5,
74 m->compute_static_thread_mgmt_se6,
75 m->compute_static_thread_mgmt_se7);
76 }
77
set_priority(struct v9_mqd * m,struct queue_properties * q)78 static void set_priority(struct v9_mqd *m, struct queue_properties *q)
79 {
80 m->cp_hqd_pipe_priority = pipe_priority_map[q->priority];
81 m->cp_hqd_queue_priority = q->priority;
82 }
83
allocate_mqd(struct kfd_dev * kfd,struct queue_properties * q)84 static struct kfd_mem_obj *allocate_mqd(struct kfd_dev *kfd,
85 struct queue_properties *q)
86 {
87 int retval;
88 struct kfd_mem_obj *mqd_mem_obj = NULL;
89
90 /* For V9 only, due to a HW bug, the control stack of a user mode
91 * compute queue needs to be allocated just behind the page boundary
92 * of its regular MQD buffer. So we allocate an enlarged MQD buffer:
93 * the first page of the buffer serves as the regular MQD buffer
94 * purpose and the remaining is for control stack. Although the two
95 * parts are in the same buffer object, they need different memory
96 * types: MQD part needs UC (uncached) as usual, while control stack
97 * needs NC (non coherent), which is different from the UC type which
98 * is used when control stack is allocated in user space.
99 *
100 * Because of all those, we use the gtt allocation function instead
101 * of sub-allocation function for this enlarged MQD buffer. Moreover,
102 * in order to achieve two memory types in a single buffer object, we
103 * pass a special bo flag AMDGPU_GEM_CREATE_CP_MQD_GFX9 to instruct
104 * amdgpu memory functions to do so.
105 */
106 if (kfd->cwsr_enabled && (q->type == KFD_QUEUE_TYPE_COMPUTE)) {
107 mqd_mem_obj = kzalloc(sizeof(struct kfd_mem_obj), GFP_KERNEL);
108 if (!mqd_mem_obj)
109 return NULL;
110 retval = amdgpu_amdkfd_alloc_gtt_mem(kfd->kgd,
111 ALIGN(q->ctl_stack_size, PAGE_SIZE) +
112 ALIGN(sizeof(struct v9_mqd), PAGE_SIZE),
113 &(mqd_mem_obj->gtt_mem),
114 &(mqd_mem_obj->gpu_addr),
115 (void *)&(mqd_mem_obj->cpu_ptr), true);
116
117 if (retval) {
118 kfree(mqd_mem_obj);
119 return NULL;
120 }
121 } else {
122 retval = kfd_gtt_sa_allocate(kfd, sizeof(struct v9_mqd),
123 &mqd_mem_obj);
124 if (retval)
125 return NULL;
126 }
127
128 return mqd_mem_obj;
129 }
130
init_mqd(struct mqd_manager * mm,void ** mqd,struct kfd_mem_obj * mqd_mem_obj,uint64_t * gart_addr,struct queue_properties * q)131 static void init_mqd(struct mqd_manager *mm, void **mqd,
132 struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
133 struct queue_properties *q)
134 {
135 uint64_t addr;
136 struct v9_mqd *m;
137
138 m = (struct v9_mqd *) mqd_mem_obj->cpu_ptr;
139 addr = mqd_mem_obj->gpu_addr;
140
141 memset(m, 0, sizeof(struct v9_mqd));
142
143 m->header = 0xC0310800;
144 m->compute_pipelinestat_enable = 1;
145 m->compute_static_thread_mgmt_se0 = 0xFFFFFFFF;
146 m->compute_static_thread_mgmt_se1 = 0xFFFFFFFF;
147 m->compute_static_thread_mgmt_se2 = 0xFFFFFFFF;
148 m->compute_static_thread_mgmt_se3 = 0xFFFFFFFF;
149 m->compute_static_thread_mgmt_se4 = 0xFFFFFFFF;
150 m->compute_static_thread_mgmt_se5 = 0xFFFFFFFF;
151 m->compute_static_thread_mgmt_se6 = 0xFFFFFFFF;
152 m->compute_static_thread_mgmt_se7 = 0xFFFFFFFF;
153
154 m->cp_hqd_persistent_state = CP_HQD_PERSISTENT_STATE__PRELOAD_REQ_MASK |
155 0x53 << CP_HQD_PERSISTENT_STATE__PRELOAD_SIZE__SHIFT;
156
157 m->cp_mqd_control = 1 << CP_MQD_CONTROL__PRIV_STATE__SHIFT;
158
159 m->cp_mqd_base_addr_lo = lower_32_bits(addr);
160 m->cp_mqd_base_addr_hi = upper_32_bits(addr);
161
162 m->cp_hqd_quantum = 1 << CP_HQD_QUANTUM__QUANTUM_EN__SHIFT |
163 1 << CP_HQD_QUANTUM__QUANTUM_SCALE__SHIFT |
164 1 << CP_HQD_QUANTUM__QUANTUM_DURATION__SHIFT;
165
166 if (q->format == KFD_QUEUE_FORMAT_AQL) {
167 m->cp_hqd_aql_control =
168 1 << CP_HQD_AQL_CONTROL__CONTROL0__SHIFT;
169 }
170
171 if (q->tba_addr) {
172 m->compute_pgm_rsrc2 |=
173 (1 << COMPUTE_PGM_RSRC2__TRAP_PRESENT__SHIFT);
174 }
175
176 if (mm->dev->cwsr_enabled && q->ctx_save_restore_area_address) {
177 m->cp_hqd_persistent_state |=
178 (1 << CP_HQD_PERSISTENT_STATE__QSWITCH_MODE__SHIFT);
179 m->cp_hqd_ctx_save_base_addr_lo =
180 lower_32_bits(q->ctx_save_restore_area_address);
181 m->cp_hqd_ctx_save_base_addr_hi =
182 upper_32_bits(q->ctx_save_restore_area_address);
183 m->cp_hqd_ctx_save_size = q->ctx_save_restore_area_size;
184 m->cp_hqd_cntl_stack_size = q->ctl_stack_size;
185 m->cp_hqd_cntl_stack_offset = q->ctl_stack_size;
186 m->cp_hqd_wg_state_offset = q->ctl_stack_size;
187 }
188
189 *mqd = m;
190 if (gart_addr)
191 *gart_addr = addr;
192 mm->update_mqd(mm, m, q);
193 }
194
load_mqd(struct mqd_manager * mm,void * mqd,uint32_t pipe_id,uint32_t queue_id,struct queue_properties * p,struct mm_struct * mms)195 static int load_mqd(struct mqd_manager *mm, void *mqd,
196 uint32_t pipe_id, uint32_t queue_id,
197 struct queue_properties *p, struct mm_struct *mms)
198 {
199 /* AQL write pointer counts in 64B packets, PM4/CP counts in dwords. */
200 uint32_t wptr_shift = (p->format == KFD_QUEUE_FORMAT_AQL ? 4 : 0);
201
202 return mm->dev->kfd2kgd->hqd_load(mm->dev->kgd, mqd, pipe_id, queue_id,
203 (uint32_t __user *)p->write_ptr,
204 wptr_shift, 0, mms);
205 }
206
hiq_load_mqd_kiq(struct mqd_manager * mm,void * mqd,uint32_t pipe_id,uint32_t queue_id,struct queue_properties * p,struct mm_struct * mms)207 static int hiq_load_mqd_kiq(struct mqd_manager *mm, void *mqd,
208 uint32_t pipe_id, uint32_t queue_id,
209 struct queue_properties *p, struct mm_struct *mms)
210 {
211 return mm->dev->kfd2kgd->hiq_mqd_load(mm->dev->kgd, mqd, pipe_id,
212 queue_id, p->doorbell_off);
213 }
214
update_mqd(struct mqd_manager * mm,void * mqd,struct queue_properties * q)215 static void update_mqd(struct mqd_manager *mm, void *mqd,
216 struct queue_properties *q)
217 {
218 struct v9_mqd *m;
219
220 m = get_mqd(mqd);
221
222 m->cp_hqd_pq_control = 5 << CP_HQD_PQ_CONTROL__RPTR_BLOCK_SIZE__SHIFT;
223 m->cp_hqd_pq_control |= order_base_2(q->queue_size / 4) - 1;
224 pr_debug("cp_hqd_pq_control 0x%x\n", m->cp_hqd_pq_control);
225
226 m->cp_hqd_pq_base_lo = lower_32_bits((uint64_t)q->queue_address >> 8);
227 m->cp_hqd_pq_base_hi = upper_32_bits((uint64_t)q->queue_address >> 8);
228
229 m->cp_hqd_pq_rptr_report_addr_lo = lower_32_bits((uint64_t)q->read_ptr);
230 m->cp_hqd_pq_rptr_report_addr_hi = upper_32_bits((uint64_t)q->read_ptr);
231 m->cp_hqd_pq_wptr_poll_addr_lo = lower_32_bits((uint64_t)q->write_ptr);
232 m->cp_hqd_pq_wptr_poll_addr_hi = upper_32_bits((uint64_t)q->write_ptr);
233
234 m->cp_hqd_pq_doorbell_control =
235 q->doorbell_off <<
236 CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_OFFSET__SHIFT;
237 pr_debug("cp_hqd_pq_doorbell_control 0x%x\n",
238 m->cp_hqd_pq_doorbell_control);
239
240 m->cp_hqd_ib_control =
241 3 << CP_HQD_IB_CONTROL__MIN_IB_AVAIL_SIZE__SHIFT |
242 1 << CP_HQD_IB_CONTROL__IB_EXE_DISABLE__SHIFT;
243
244 /*
245 * HW does not clamp this field correctly. Maximum EOP queue size
246 * is constrained by per-SE EOP done signal count, which is 8-bit.
247 * Limit is 0xFF EOP entries (= 0x7F8 dwords). CP will not submit
248 * more than (EOP entry count - 1) so a queue size of 0x800 dwords
249 * is safe, giving a maximum field value of 0xA.
250 */
251 m->cp_hqd_eop_control = min(0xA,
252 order_base_2(q->eop_ring_buffer_size / 4) - 1);
253 m->cp_hqd_eop_base_addr_lo =
254 lower_32_bits(q->eop_ring_buffer_address >> 8);
255 m->cp_hqd_eop_base_addr_hi =
256 upper_32_bits(q->eop_ring_buffer_address >> 8);
257
258 m->cp_hqd_iq_timer = 0;
259
260 m->cp_hqd_vmid = q->vmid;
261
262 if (q->format == KFD_QUEUE_FORMAT_AQL) {
263 m->cp_hqd_pq_control |= CP_HQD_PQ_CONTROL__NO_UPDATE_RPTR_MASK |
264 2 << CP_HQD_PQ_CONTROL__SLOT_BASED_WPTR__SHIFT |
265 1 << CP_HQD_PQ_CONTROL__QUEUE_FULL_EN__SHIFT |
266 1 << CP_HQD_PQ_CONTROL__WPP_CLAMP_EN__SHIFT;
267 m->cp_hqd_pq_doorbell_control |= 1 <<
268 CP_HQD_PQ_DOORBELL_CONTROL__DOORBELL_BIF_DROP__SHIFT;
269 }
270 if (mm->dev->cwsr_enabled && q->ctx_save_restore_area_address)
271 m->cp_hqd_ctx_save_control = 0;
272
273 update_cu_mask(mm, mqd, q);
274 set_priority(m, q);
275
276 q->is_active = QUEUE_IS_ACTIVE(*q);
277 }
278
279
read_doorbell_id(void * mqd)280 static uint32_t read_doorbell_id(void *mqd)
281 {
282 struct v9_mqd *m = (struct v9_mqd *)mqd;
283
284 return m->queue_doorbell_id0;
285 }
286
destroy_mqd(struct mqd_manager * mm,void * mqd,enum kfd_preempt_type type,unsigned int timeout,uint32_t pipe_id,uint32_t queue_id)287 static int destroy_mqd(struct mqd_manager *mm, void *mqd,
288 enum kfd_preempt_type type,
289 unsigned int timeout, uint32_t pipe_id,
290 uint32_t queue_id)
291 {
292 return mm->dev->kfd2kgd->hqd_destroy
293 (mm->dev->kgd, mqd, type, timeout,
294 pipe_id, queue_id);
295 }
296
free_mqd(struct mqd_manager * mm,void * mqd,struct kfd_mem_obj * mqd_mem_obj)297 static void free_mqd(struct mqd_manager *mm, void *mqd,
298 struct kfd_mem_obj *mqd_mem_obj)
299 {
300 struct kfd_dev *kfd = mm->dev;
301
302 if (mqd_mem_obj->gtt_mem) {
303 amdgpu_amdkfd_free_gtt_mem(kfd->kgd, mqd_mem_obj->gtt_mem);
304 kfree(mqd_mem_obj);
305 } else {
306 kfd_gtt_sa_free(mm->dev, mqd_mem_obj);
307 }
308 }
309
is_occupied(struct mqd_manager * mm,void * mqd,uint64_t queue_address,uint32_t pipe_id,uint32_t queue_id)310 static bool is_occupied(struct mqd_manager *mm, void *mqd,
311 uint64_t queue_address, uint32_t pipe_id,
312 uint32_t queue_id)
313 {
314 return mm->dev->kfd2kgd->hqd_is_occupied(
315 mm->dev->kgd, queue_address,
316 pipe_id, queue_id);
317 }
318
get_wave_state(struct mqd_manager * mm,void * mqd,void __user * ctl_stack,u32 * ctl_stack_used_size,u32 * save_area_used_size)319 static int get_wave_state(struct mqd_manager *mm, void *mqd,
320 void __user *ctl_stack,
321 u32 *ctl_stack_used_size,
322 u32 *save_area_used_size)
323 {
324 struct v9_mqd *m;
325
326 /* Control stack is located one page after MQD. */
327 void *mqd_ctl_stack = (void *)((uintptr_t)mqd + PAGE_SIZE);
328
329 m = get_mqd(mqd);
330
331 *ctl_stack_used_size = m->cp_hqd_cntl_stack_size -
332 m->cp_hqd_cntl_stack_offset;
333 *save_area_used_size = m->cp_hqd_wg_state_offset -
334 m->cp_hqd_cntl_stack_size;
335
336 if (copy_to_user(ctl_stack, mqd_ctl_stack, m->cp_hqd_cntl_stack_size))
337 return -EFAULT;
338
339 return 0;
340 }
341
init_mqd_hiq(struct mqd_manager * mm,void ** mqd,struct kfd_mem_obj * mqd_mem_obj,uint64_t * gart_addr,struct queue_properties * q)342 static void init_mqd_hiq(struct mqd_manager *mm, void **mqd,
343 struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
344 struct queue_properties *q)
345 {
346 struct v9_mqd *m;
347
348 init_mqd(mm, mqd, mqd_mem_obj, gart_addr, q);
349
350 m = get_mqd(*mqd);
351
352 m->cp_hqd_pq_control |= 1 << CP_HQD_PQ_CONTROL__PRIV_STATE__SHIFT |
353 1 << CP_HQD_PQ_CONTROL__KMD_QUEUE__SHIFT;
354 }
355
init_mqd_sdma(struct mqd_manager * mm,void ** mqd,struct kfd_mem_obj * mqd_mem_obj,uint64_t * gart_addr,struct queue_properties * q)356 static void init_mqd_sdma(struct mqd_manager *mm, void **mqd,
357 struct kfd_mem_obj *mqd_mem_obj, uint64_t *gart_addr,
358 struct queue_properties *q)
359 {
360 struct v9_sdma_mqd *m;
361
362 m = (struct v9_sdma_mqd *) mqd_mem_obj->cpu_ptr;
363
364 memset(m, 0, sizeof(struct v9_sdma_mqd));
365
366 *mqd = m;
367 if (gart_addr)
368 *gart_addr = mqd_mem_obj->gpu_addr;
369
370 mm->update_mqd(mm, m, q);
371 }
372
load_mqd_sdma(struct mqd_manager * mm,void * mqd,uint32_t pipe_id,uint32_t queue_id,struct queue_properties * p,struct mm_struct * mms)373 static int load_mqd_sdma(struct mqd_manager *mm, void *mqd,
374 uint32_t pipe_id, uint32_t queue_id,
375 struct queue_properties *p, struct mm_struct *mms)
376 {
377 return mm->dev->kfd2kgd->hqd_sdma_load(mm->dev->kgd, mqd,
378 (uint32_t __user *)p->write_ptr,
379 mms);
380 }
381
382 #define SDMA_RLC_DUMMY_DEFAULT 0xf
383
update_mqd_sdma(struct mqd_manager * mm,void * mqd,struct queue_properties * q)384 static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
385 struct queue_properties *q)
386 {
387 struct v9_sdma_mqd *m;
388
389 m = get_sdma_mqd(mqd);
390 m->sdmax_rlcx_rb_cntl = order_base_2(q->queue_size / 4)
391 << SDMA0_RLC0_RB_CNTL__RB_SIZE__SHIFT |
392 q->vmid << SDMA0_RLC0_RB_CNTL__RB_VMID__SHIFT |
393 1 << SDMA0_RLC0_RB_CNTL__RPTR_WRITEBACK_ENABLE__SHIFT |
394 6 << SDMA0_RLC0_RB_CNTL__RPTR_WRITEBACK_TIMER__SHIFT;
395
396 m->sdmax_rlcx_rb_base = lower_32_bits(q->queue_address >> 8);
397 m->sdmax_rlcx_rb_base_hi = upper_32_bits(q->queue_address >> 8);
398 m->sdmax_rlcx_rb_rptr_addr_lo = lower_32_bits((uint64_t)q->read_ptr);
399 m->sdmax_rlcx_rb_rptr_addr_hi = upper_32_bits((uint64_t)q->read_ptr);
400 m->sdmax_rlcx_doorbell_offset =
401 q->doorbell_off << SDMA0_RLC0_DOORBELL_OFFSET__OFFSET__SHIFT;
402
403 m->sdma_engine_id = q->sdma_engine_id;
404 m->sdma_queue_id = q->sdma_queue_id;
405 m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
406
407 q->is_active = QUEUE_IS_ACTIVE(*q);
408 }
409
410 /*
411 * * preempt type here is ignored because there is only one way
412 * * to preempt sdma queue
413 */
destroy_mqd_sdma(struct mqd_manager * mm,void * mqd,enum kfd_preempt_type type,unsigned int timeout,uint32_t pipe_id,uint32_t queue_id)414 static int destroy_mqd_sdma(struct mqd_manager *mm, void *mqd,
415 enum kfd_preempt_type type,
416 unsigned int timeout, uint32_t pipe_id,
417 uint32_t queue_id)
418 {
419 return mm->dev->kfd2kgd->hqd_sdma_destroy(mm->dev->kgd, mqd, timeout);
420 }
421
is_occupied_sdma(struct mqd_manager * mm,void * mqd,uint64_t queue_address,uint32_t pipe_id,uint32_t queue_id)422 static bool is_occupied_sdma(struct mqd_manager *mm, void *mqd,
423 uint64_t queue_address, uint32_t pipe_id,
424 uint32_t queue_id)
425 {
426 return mm->dev->kfd2kgd->hqd_sdma_is_occupied(mm->dev->kgd, mqd);
427 }
428
429 #if defined(CONFIG_DEBUG_FS)
430
debugfs_show_mqd(struct seq_file * m,void * data)431 static int debugfs_show_mqd(struct seq_file *m, void *data)
432 {
433 seq_hex_dump(m, " ", DUMP_PREFIX_OFFSET, 32, 4,
434 data, sizeof(struct v9_mqd), false);
435 return 0;
436 }
437
debugfs_show_mqd_sdma(struct seq_file * m,void * data)438 static int debugfs_show_mqd_sdma(struct seq_file *m, void *data)
439 {
440 seq_hex_dump(m, " ", DUMP_PREFIX_OFFSET, 32, 4,
441 data, sizeof(struct v9_sdma_mqd), false);
442 return 0;
443 }
444
445 #endif
446
mqd_manager_init_v9(enum KFD_MQD_TYPE type,struct kfd_dev * dev)447 struct mqd_manager *mqd_manager_init_v9(enum KFD_MQD_TYPE type,
448 struct kfd_dev *dev)
449 {
450 struct mqd_manager *mqd;
451
452 if (WARN_ON(type >= KFD_MQD_TYPE_MAX))
453 return NULL;
454
455 mqd = kzalloc(sizeof(*mqd), GFP_KERNEL);
456 if (!mqd)
457 return NULL;
458
459 mqd->dev = dev;
460
461 switch (type) {
462 case KFD_MQD_TYPE_CP:
463 mqd->allocate_mqd = allocate_mqd;
464 mqd->init_mqd = init_mqd;
465 mqd->free_mqd = free_mqd;
466 mqd->load_mqd = load_mqd;
467 mqd->update_mqd = update_mqd;
468 mqd->destroy_mqd = destroy_mqd;
469 mqd->is_occupied = is_occupied;
470 mqd->get_wave_state = get_wave_state;
471 mqd->mqd_size = sizeof(struct v9_mqd);
472 #if defined(CONFIG_DEBUG_FS)
473 mqd->debugfs_show_mqd = debugfs_show_mqd;
474 #endif
475 break;
476 case KFD_MQD_TYPE_HIQ:
477 mqd->allocate_mqd = allocate_hiq_mqd;
478 mqd->init_mqd = init_mqd_hiq;
479 mqd->free_mqd = free_mqd_hiq_sdma;
480 mqd->load_mqd = hiq_load_mqd_kiq;
481 mqd->update_mqd = update_mqd;
482 mqd->destroy_mqd = destroy_mqd;
483 mqd->is_occupied = is_occupied;
484 mqd->mqd_size = sizeof(struct v9_mqd);
485 #if defined(CONFIG_DEBUG_FS)
486 mqd->debugfs_show_mqd = debugfs_show_mqd;
487 #endif
488 mqd->read_doorbell_id = read_doorbell_id;
489 break;
490 case KFD_MQD_TYPE_DIQ:
491 mqd->allocate_mqd = allocate_mqd;
492 mqd->init_mqd = init_mqd_hiq;
493 mqd->free_mqd = free_mqd;
494 mqd->load_mqd = load_mqd;
495 mqd->update_mqd = update_mqd;
496 mqd->destroy_mqd = destroy_mqd;
497 mqd->is_occupied = is_occupied;
498 mqd->mqd_size = sizeof(struct v9_mqd);
499 #if defined(CONFIG_DEBUG_FS)
500 mqd->debugfs_show_mqd = debugfs_show_mqd;
501 #endif
502 break;
503 case KFD_MQD_TYPE_SDMA:
504 mqd->allocate_mqd = allocate_sdma_mqd;
505 mqd->init_mqd = init_mqd_sdma;
506 mqd->free_mqd = free_mqd_hiq_sdma;
507 mqd->load_mqd = load_mqd_sdma;
508 mqd->update_mqd = update_mqd_sdma;
509 mqd->destroy_mqd = destroy_mqd_sdma;
510 mqd->is_occupied = is_occupied_sdma;
511 mqd->mqd_size = sizeof(struct v9_sdma_mqd);
512 #if defined(CONFIG_DEBUG_FS)
513 mqd->debugfs_show_mqd = debugfs_show_mqd_sdma;
514 #endif
515 break;
516 default:
517 kfree(mqd);
518 return NULL;
519 }
520
521 return mqd;
522 }
523