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