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 <linux/types.h> 27 #include <linux/printk.h> 28 #include <linux/bitops.h> 29 #include <linux/sched.h> 30 #include "kfd_priv.h" 31 #include "kfd_device_queue_manager.h" 32 #include "kfd_mqd_manager.h" 33 #include "cik_regs.h" 34 #include "kfd_kernel_queue.h" 35 36 /* Size of the per-pipe EOP queue */ 37 #define CIK_HPD_EOP_BYTES_LOG2 11 38 #define CIK_HPD_EOP_BYTES (1U << CIK_HPD_EOP_BYTES_LOG2) 39 40 static int set_pasid_vmid_mapping(struct device_queue_manager *dqm, 41 unsigned int pasid, unsigned int vmid); 42 43 static int create_compute_queue_nocpsch(struct device_queue_manager *dqm, 44 struct queue *q, 45 struct qcm_process_device *qpd); 46 47 static int execute_queues_cpsch(struct device_queue_manager *dqm, 48 enum kfd_unmap_queues_filter filter, 49 uint32_t filter_param); 50 static int unmap_queues_cpsch(struct device_queue_manager *dqm, 51 enum kfd_unmap_queues_filter filter, 52 uint32_t filter_param); 53 54 static int map_queues_cpsch(struct device_queue_manager *dqm); 55 56 static int create_sdma_queue_nocpsch(struct device_queue_manager *dqm, 57 struct queue *q, 58 struct qcm_process_device *qpd); 59 60 static void deallocate_sdma_queue(struct device_queue_manager *dqm, 61 unsigned int sdma_queue_id); 62 63 static inline 64 enum KFD_MQD_TYPE get_mqd_type_from_queue_type(enum kfd_queue_type type) 65 { 66 if (type == KFD_QUEUE_TYPE_SDMA) 67 return KFD_MQD_TYPE_SDMA; 68 return KFD_MQD_TYPE_CP; 69 } 70 71 static bool is_pipe_enabled(struct device_queue_manager *dqm, int mec, int pipe) 72 { 73 int i; 74 int pipe_offset = mec * dqm->dev->shared_resources.num_pipe_per_mec 75 + pipe * dqm->dev->shared_resources.num_queue_per_pipe; 76 77 /* queue is available for KFD usage if bit is 1 */ 78 for (i = 0; i < dqm->dev->shared_resources.num_queue_per_pipe; ++i) 79 if (test_bit(pipe_offset + i, 80 dqm->dev->shared_resources.queue_bitmap)) 81 return true; 82 return false; 83 } 84 85 unsigned int get_queues_num(struct device_queue_manager *dqm) 86 { 87 return bitmap_weight(dqm->dev->shared_resources.queue_bitmap, 88 KGD_MAX_QUEUES); 89 } 90 91 unsigned int get_queues_per_pipe(struct device_queue_manager *dqm) 92 { 93 return dqm->dev->shared_resources.num_queue_per_pipe; 94 } 95 96 unsigned int get_pipes_per_mec(struct device_queue_manager *dqm) 97 { 98 return dqm->dev->shared_resources.num_pipe_per_mec; 99 } 100 101 void program_sh_mem_settings(struct device_queue_manager *dqm, 102 struct qcm_process_device *qpd) 103 { 104 return dqm->dev->kfd2kgd->program_sh_mem_settings( 105 dqm->dev->kgd, qpd->vmid, 106 qpd->sh_mem_config, 107 qpd->sh_mem_ape1_base, 108 qpd->sh_mem_ape1_limit, 109 qpd->sh_mem_bases); 110 } 111 112 static int allocate_vmid(struct device_queue_manager *dqm, 113 struct qcm_process_device *qpd, 114 struct queue *q) 115 { 116 int bit, allocated_vmid; 117 118 if (dqm->vmid_bitmap == 0) 119 return -ENOMEM; 120 121 bit = find_first_bit((unsigned long *)&dqm->vmid_bitmap, 122 dqm->dev->vm_info.vmid_num_kfd); 123 clear_bit(bit, (unsigned long *)&dqm->vmid_bitmap); 124 125 allocated_vmid = bit + dqm->dev->vm_info.first_vmid_kfd; 126 pr_debug("vmid allocation %d\n", allocated_vmid); 127 qpd->vmid = allocated_vmid; 128 q->properties.vmid = allocated_vmid; 129 130 set_pasid_vmid_mapping(dqm, q->process->pasid, q->properties.vmid); 131 program_sh_mem_settings(dqm, qpd); 132 133 return 0; 134 } 135 136 static void deallocate_vmid(struct device_queue_manager *dqm, 137 struct qcm_process_device *qpd, 138 struct queue *q) 139 { 140 int bit = qpd->vmid - dqm->dev->vm_info.first_vmid_kfd; 141 142 /* Release the vmid mapping */ 143 set_pasid_vmid_mapping(dqm, 0, qpd->vmid); 144 145 set_bit(bit, (unsigned long *)&dqm->vmid_bitmap); 146 qpd->vmid = 0; 147 q->properties.vmid = 0; 148 } 149 150 static int create_queue_nocpsch(struct device_queue_manager *dqm, 151 struct queue *q, 152 struct qcm_process_device *qpd) 153 { 154 int retval; 155 156 print_queue(q); 157 158 mutex_lock(&dqm->lock); 159 160 if (dqm->total_queue_count >= max_num_of_queues_per_device) { 161 pr_warn("Can't create new usermode queue because %d queues were already created\n", 162 dqm->total_queue_count); 163 retval = -EPERM; 164 goto out_unlock; 165 } 166 167 if (list_empty(&qpd->queues_list)) { 168 retval = allocate_vmid(dqm, qpd, q); 169 if (retval) 170 goto out_unlock; 171 } 172 q->properties.vmid = qpd->vmid; 173 174 q->properties.tba_addr = qpd->tba_addr; 175 q->properties.tma_addr = qpd->tma_addr; 176 177 if (q->properties.type == KFD_QUEUE_TYPE_COMPUTE) 178 retval = create_compute_queue_nocpsch(dqm, q, qpd); 179 else if (q->properties.type == KFD_QUEUE_TYPE_SDMA) 180 retval = create_sdma_queue_nocpsch(dqm, q, qpd); 181 else 182 retval = -EINVAL; 183 184 if (retval) { 185 if (list_empty(&qpd->queues_list)) 186 deallocate_vmid(dqm, qpd, q); 187 goto out_unlock; 188 } 189 190 list_add(&q->list, &qpd->queues_list); 191 qpd->queue_count++; 192 if (q->properties.is_active) 193 dqm->queue_count++; 194 195 if (q->properties.type == KFD_QUEUE_TYPE_SDMA) 196 dqm->sdma_queue_count++; 197 198 /* 199 * Unconditionally increment this counter, regardless of the queue's 200 * type or whether the queue is active. 201 */ 202 dqm->total_queue_count++; 203 pr_debug("Total of %d queues are accountable so far\n", 204 dqm->total_queue_count); 205 206 out_unlock: 207 mutex_unlock(&dqm->lock); 208 return retval; 209 } 210 211 static int allocate_hqd(struct device_queue_manager *dqm, struct queue *q) 212 { 213 bool set; 214 int pipe, bit, i; 215 216 set = false; 217 218 for (pipe = dqm->next_pipe_to_allocate, i = 0; 219 i < get_pipes_per_mec(dqm); 220 pipe = ((pipe + 1) % get_pipes_per_mec(dqm)), ++i) { 221 222 if (!is_pipe_enabled(dqm, 0, pipe)) 223 continue; 224 225 if (dqm->allocated_queues[pipe] != 0) { 226 bit = find_first_bit( 227 (unsigned long *)&dqm->allocated_queues[pipe], 228 get_queues_per_pipe(dqm)); 229 230 clear_bit(bit, 231 (unsigned long *)&dqm->allocated_queues[pipe]); 232 q->pipe = pipe; 233 q->queue = bit; 234 set = true; 235 break; 236 } 237 } 238 239 if (!set) 240 return -EBUSY; 241 242 pr_debug("hqd slot - pipe %d, queue %d\n", q->pipe, q->queue); 243 /* horizontal hqd allocation */ 244 dqm->next_pipe_to_allocate = (pipe + 1) % get_pipes_per_mec(dqm); 245 246 return 0; 247 } 248 249 static inline void deallocate_hqd(struct device_queue_manager *dqm, 250 struct queue *q) 251 { 252 set_bit(q->queue, (unsigned long *)&dqm->allocated_queues[q->pipe]); 253 } 254 255 static int create_compute_queue_nocpsch(struct device_queue_manager *dqm, 256 struct queue *q, 257 struct qcm_process_device *qpd) 258 { 259 int retval; 260 struct mqd_manager *mqd; 261 262 mqd = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_COMPUTE); 263 if (!mqd) 264 return -ENOMEM; 265 266 retval = allocate_hqd(dqm, q); 267 if (retval) 268 return retval; 269 270 retval = mqd->init_mqd(mqd, &q->mqd, &q->mqd_mem_obj, 271 &q->gart_mqd_addr, &q->properties); 272 if (retval) 273 goto out_deallocate_hqd; 274 275 pr_debug("Loading mqd to hqd on pipe %d, queue %d\n", 276 q->pipe, q->queue); 277 278 dqm->dev->kfd2kgd->set_scratch_backing_va( 279 dqm->dev->kgd, qpd->sh_hidden_private_base, qpd->vmid); 280 281 if (!q->properties.is_active) 282 return 0; 283 284 retval = mqd->load_mqd(mqd, q->mqd, q->pipe, q->queue, &q->properties, 285 q->process->mm); 286 if (retval) 287 goto out_uninit_mqd; 288 289 return 0; 290 291 out_uninit_mqd: 292 mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj); 293 out_deallocate_hqd: 294 deallocate_hqd(dqm, q); 295 296 return retval; 297 } 298 299 /* Access to DQM has to be locked before calling destroy_queue_nocpsch_locked 300 * to avoid asynchronized access 301 */ 302 static int destroy_queue_nocpsch_locked(struct device_queue_manager *dqm, 303 struct qcm_process_device *qpd, 304 struct queue *q) 305 { 306 int retval; 307 struct mqd_manager *mqd; 308 309 mqd = dqm->ops.get_mqd_manager(dqm, 310 get_mqd_type_from_queue_type(q->properties.type)); 311 if (!mqd) 312 return -ENOMEM; 313 314 if (q->properties.type == KFD_QUEUE_TYPE_COMPUTE) { 315 deallocate_hqd(dqm, q); 316 } else if (q->properties.type == KFD_QUEUE_TYPE_SDMA) { 317 dqm->sdma_queue_count--; 318 deallocate_sdma_queue(dqm, q->sdma_id); 319 } else { 320 pr_debug("q->properties.type %d is invalid\n", 321 q->properties.type); 322 return -EINVAL; 323 } 324 dqm->total_queue_count--; 325 326 retval = mqd->destroy_mqd(mqd, q->mqd, 327 KFD_PREEMPT_TYPE_WAVEFRONT_RESET, 328 KFD_UNMAP_LATENCY_MS, 329 q->pipe, q->queue); 330 if (retval == -ETIME) 331 qpd->reset_wavefronts = true; 332 333 mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj); 334 335 list_del(&q->list); 336 if (list_empty(&qpd->queues_list)) { 337 if (qpd->reset_wavefronts) { 338 pr_warn("Resetting wave fronts (nocpsch) on dev %p\n", 339 dqm->dev); 340 /* dbgdev_wave_reset_wavefronts has to be called before 341 * deallocate_vmid(), i.e. when vmid is still in use. 342 */ 343 dbgdev_wave_reset_wavefronts(dqm->dev, 344 qpd->pqm->process); 345 qpd->reset_wavefronts = false; 346 } 347 348 deallocate_vmid(dqm, qpd, q); 349 } 350 qpd->queue_count--; 351 if (q->properties.is_active) 352 dqm->queue_count--; 353 354 return retval; 355 } 356 357 static int destroy_queue_nocpsch(struct device_queue_manager *dqm, 358 struct qcm_process_device *qpd, 359 struct queue *q) 360 { 361 int retval; 362 363 mutex_lock(&dqm->lock); 364 retval = destroy_queue_nocpsch_locked(dqm, qpd, q); 365 mutex_unlock(&dqm->lock); 366 367 return retval; 368 } 369 370 static int update_queue(struct device_queue_manager *dqm, struct queue *q) 371 { 372 int retval; 373 struct mqd_manager *mqd; 374 bool prev_active = false; 375 376 mutex_lock(&dqm->lock); 377 mqd = dqm->ops.get_mqd_manager(dqm, 378 get_mqd_type_from_queue_type(q->properties.type)); 379 if (!mqd) { 380 retval = -ENOMEM; 381 goto out_unlock; 382 } 383 384 /* Save previous activity state for counters */ 385 prev_active = q->properties.is_active; 386 387 /* Make sure the queue is unmapped before updating the MQD */ 388 if (sched_policy != KFD_SCHED_POLICY_NO_HWS) { 389 retval = unmap_queues_cpsch(dqm, 390 KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0); 391 if (retval) { 392 pr_err("unmap queue failed\n"); 393 goto out_unlock; 394 } 395 } else if (prev_active && 396 (q->properties.type == KFD_QUEUE_TYPE_COMPUTE || 397 q->properties.type == KFD_QUEUE_TYPE_SDMA)) { 398 retval = mqd->destroy_mqd(mqd, q->mqd, 399 KFD_PREEMPT_TYPE_WAVEFRONT_DRAIN, 400 KFD_UNMAP_LATENCY_MS, q->pipe, q->queue); 401 if (retval) { 402 pr_err("destroy mqd failed\n"); 403 goto out_unlock; 404 } 405 } 406 407 retval = mqd->update_mqd(mqd, q->mqd, &q->properties); 408 409 /* 410 * check active state vs. the previous state and modify 411 * counter accordingly. map_queues_cpsch uses the 412 * dqm->queue_count to determine whether a new runlist must be 413 * uploaded. 414 */ 415 if (q->properties.is_active && !prev_active) 416 dqm->queue_count++; 417 else if (!q->properties.is_active && prev_active) 418 dqm->queue_count--; 419 420 if (sched_policy != KFD_SCHED_POLICY_NO_HWS) 421 retval = map_queues_cpsch(dqm); 422 else if (q->properties.is_active && 423 (q->properties.type == KFD_QUEUE_TYPE_COMPUTE || 424 q->properties.type == KFD_QUEUE_TYPE_SDMA)) 425 retval = mqd->load_mqd(mqd, q->mqd, q->pipe, q->queue, 426 &q->properties, q->process->mm); 427 428 out_unlock: 429 mutex_unlock(&dqm->lock); 430 return retval; 431 } 432 433 static struct mqd_manager *get_mqd_manager( 434 struct device_queue_manager *dqm, enum KFD_MQD_TYPE type) 435 { 436 struct mqd_manager *mqd; 437 438 if (WARN_ON(type >= KFD_MQD_TYPE_MAX)) 439 return NULL; 440 441 pr_debug("mqd type %d\n", type); 442 443 mqd = dqm->mqds[type]; 444 if (!mqd) { 445 mqd = mqd_manager_init(type, dqm->dev); 446 if (!mqd) 447 pr_err("mqd manager is NULL"); 448 dqm->mqds[type] = mqd; 449 } 450 451 return mqd; 452 } 453 454 static int register_process(struct device_queue_manager *dqm, 455 struct qcm_process_device *qpd) 456 { 457 struct device_process_node *n; 458 int retval; 459 460 n = kzalloc(sizeof(*n), GFP_KERNEL); 461 if (!n) 462 return -ENOMEM; 463 464 n->qpd = qpd; 465 466 mutex_lock(&dqm->lock); 467 list_add(&n->list, &dqm->queues); 468 469 retval = dqm->asic_ops.update_qpd(dqm, qpd); 470 471 dqm->processes_count++; 472 473 mutex_unlock(&dqm->lock); 474 475 return retval; 476 } 477 478 static int unregister_process(struct device_queue_manager *dqm, 479 struct qcm_process_device *qpd) 480 { 481 int retval; 482 struct device_process_node *cur, *next; 483 484 pr_debug("qpd->queues_list is %s\n", 485 list_empty(&qpd->queues_list) ? "empty" : "not empty"); 486 487 retval = 0; 488 mutex_lock(&dqm->lock); 489 490 list_for_each_entry_safe(cur, next, &dqm->queues, list) { 491 if (qpd == cur->qpd) { 492 list_del(&cur->list); 493 kfree(cur); 494 dqm->processes_count--; 495 goto out; 496 } 497 } 498 /* qpd not found in dqm list */ 499 retval = 1; 500 out: 501 mutex_unlock(&dqm->lock); 502 return retval; 503 } 504 505 static int 506 set_pasid_vmid_mapping(struct device_queue_manager *dqm, unsigned int pasid, 507 unsigned int vmid) 508 { 509 uint32_t pasid_mapping; 510 511 pasid_mapping = (pasid == 0) ? 0 : 512 (uint32_t)pasid | 513 ATC_VMID_PASID_MAPPING_VALID; 514 515 return dqm->dev->kfd2kgd->set_pasid_vmid_mapping( 516 dqm->dev->kgd, pasid_mapping, 517 vmid); 518 } 519 520 static void init_interrupts(struct device_queue_manager *dqm) 521 { 522 unsigned int i; 523 524 for (i = 0 ; i < get_pipes_per_mec(dqm) ; i++) 525 if (is_pipe_enabled(dqm, 0, i)) 526 dqm->dev->kfd2kgd->init_interrupts(dqm->dev->kgd, i); 527 } 528 529 static int initialize_nocpsch(struct device_queue_manager *dqm) 530 { 531 int pipe, queue; 532 533 pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm)); 534 535 dqm->allocated_queues = kcalloc(get_pipes_per_mec(dqm), 536 sizeof(unsigned int), GFP_KERNEL); 537 if (!dqm->allocated_queues) 538 return -ENOMEM; 539 540 mutex_init(&dqm->lock); 541 INIT_LIST_HEAD(&dqm->queues); 542 dqm->queue_count = dqm->next_pipe_to_allocate = 0; 543 dqm->sdma_queue_count = 0; 544 545 for (pipe = 0; pipe < get_pipes_per_mec(dqm); pipe++) { 546 int pipe_offset = pipe * get_queues_per_pipe(dqm); 547 548 for (queue = 0; queue < get_queues_per_pipe(dqm); queue++) 549 if (test_bit(pipe_offset + queue, 550 dqm->dev->shared_resources.queue_bitmap)) 551 dqm->allocated_queues[pipe] |= 1 << queue; 552 } 553 554 dqm->vmid_bitmap = (1 << dqm->dev->vm_info.vmid_num_kfd) - 1; 555 dqm->sdma_bitmap = (1 << CIK_SDMA_QUEUES) - 1; 556 557 return 0; 558 } 559 560 static void uninitialize(struct device_queue_manager *dqm) 561 { 562 int i; 563 564 WARN_ON(dqm->queue_count > 0 || dqm->processes_count > 0); 565 566 kfree(dqm->allocated_queues); 567 for (i = 0 ; i < KFD_MQD_TYPE_MAX ; i++) 568 kfree(dqm->mqds[i]); 569 mutex_destroy(&dqm->lock); 570 kfd_gtt_sa_free(dqm->dev, dqm->pipeline_mem); 571 } 572 573 static int start_nocpsch(struct device_queue_manager *dqm) 574 { 575 init_interrupts(dqm); 576 return 0; 577 } 578 579 static int stop_nocpsch(struct device_queue_manager *dqm) 580 { 581 return 0; 582 } 583 584 static int allocate_sdma_queue(struct device_queue_manager *dqm, 585 unsigned int *sdma_queue_id) 586 { 587 int bit; 588 589 if (dqm->sdma_bitmap == 0) 590 return -ENOMEM; 591 592 bit = find_first_bit((unsigned long *)&dqm->sdma_bitmap, 593 CIK_SDMA_QUEUES); 594 595 clear_bit(bit, (unsigned long *)&dqm->sdma_bitmap); 596 *sdma_queue_id = bit; 597 598 return 0; 599 } 600 601 static void deallocate_sdma_queue(struct device_queue_manager *dqm, 602 unsigned int sdma_queue_id) 603 { 604 if (sdma_queue_id >= CIK_SDMA_QUEUES) 605 return; 606 set_bit(sdma_queue_id, (unsigned long *)&dqm->sdma_bitmap); 607 } 608 609 static int create_sdma_queue_nocpsch(struct device_queue_manager *dqm, 610 struct queue *q, 611 struct qcm_process_device *qpd) 612 { 613 struct mqd_manager *mqd; 614 int retval; 615 616 mqd = dqm->ops.get_mqd_manager(dqm, KFD_MQD_TYPE_SDMA); 617 if (!mqd) 618 return -ENOMEM; 619 620 retval = allocate_sdma_queue(dqm, &q->sdma_id); 621 if (retval) 622 return retval; 623 624 q->properties.sdma_queue_id = q->sdma_id / CIK_SDMA_QUEUES_PER_ENGINE; 625 q->properties.sdma_engine_id = q->sdma_id % CIK_SDMA_QUEUES_PER_ENGINE; 626 627 pr_debug("SDMA id is: %d\n", q->sdma_id); 628 pr_debug("SDMA queue id: %d\n", q->properties.sdma_queue_id); 629 pr_debug("SDMA engine id: %d\n", q->properties.sdma_engine_id); 630 631 dqm->asic_ops.init_sdma_vm(dqm, q, qpd); 632 retval = mqd->init_mqd(mqd, &q->mqd, &q->mqd_mem_obj, 633 &q->gart_mqd_addr, &q->properties); 634 if (retval) 635 goto out_deallocate_sdma_queue; 636 637 retval = mqd->load_mqd(mqd, q->mqd, 0, 0, &q->properties, NULL); 638 if (retval) 639 goto out_uninit_mqd; 640 641 return 0; 642 643 out_uninit_mqd: 644 mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj); 645 out_deallocate_sdma_queue: 646 deallocate_sdma_queue(dqm, q->sdma_id); 647 648 return retval; 649 } 650 651 /* 652 * Device Queue Manager implementation for cp scheduler 653 */ 654 655 static int set_sched_resources(struct device_queue_manager *dqm) 656 { 657 int i, mec; 658 struct scheduling_resources res; 659 660 res.vmid_mask = dqm->dev->shared_resources.compute_vmid_bitmap; 661 662 res.queue_mask = 0; 663 for (i = 0; i < KGD_MAX_QUEUES; ++i) { 664 mec = (i / dqm->dev->shared_resources.num_queue_per_pipe) 665 / dqm->dev->shared_resources.num_pipe_per_mec; 666 667 if (!test_bit(i, dqm->dev->shared_resources.queue_bitmap)) 668 continue; 669 670 /* only acquire queues from the first MEC */ 671 if (mec > 0) 672 continue; 673 674 /* This situation may be hit in the future if a new HW 675 * generation exposes more than 64 queues. If so, the 676 * definition of res.queue_mask needs updating 677 */ 678 if (WARN_ON(i >= (sizeof(res.queue_mask)*8))) { 679 pr_err("Invalid queue enabled by amdgpu: %d\n", i); 680 break; 681 } 682 683 res.queue_mask |= (1ull << i); 684 } 685 res.gws_mask = res.oac_mask = res.gds_heap_base = 686 res.gds_heap_size = 0; 687 688 pr_debug("Scheduling resources:\n" 689 "vmid mask: 0x%8X\n" 690 "queue mask: 0x%8llX\n", 691 res.vmid_mask, res.queue_mask); 692 693 return pm_send_set_resources(&dqm->packets, &res); 694 } 695 696 static int initialize_cpsch(struct device_queue_manager *dqm) 697 { 698 pr_debug("num of pipes: %d\n", get_pipes_per_mec(dqm)); 699 700 mutex_init(&dqm->lock); 701 INIT_LIST_HEAD(&dqm->queues); 702 dqm->queue_count = dqm->processes_count = 0; 703 dqm->sdma_queue_count = 0; 704 dqm->active_runlist = false; 705 dqm->sdma_bitmap = (1 << CIK_SDMA_QUEUES) - 1; 706 707 return 0; 708 } 709 710 static int start_cpsch(struct device_queue_manager *dqm) 711 { 712 int retval; 713 714 retval = 0; 715 716 retval = pm_init(&dqm->packets, dqm); 717 if (retval) 718 goto fail_packet_manager_init; 719 720 retval = set_sched_resources(dqm); 721 if (retval) 722 goto fail_set_sched_resources; 723 724 pr_debug("Allocating fence memory\n"); 725 726 /* allocate fence memory on the gart */ 727 retval = kfd_gtt_sa_allocate(dqm->dev, sizeof(*dqm->fence_addr), 728 &dqm->fence_mem); 729 730 if (retval) 731 goto fail_allocate_vidmem; 732 733 dqm->fence_addr = dqm->fence_mem->cpu_ptr; 734 dqm->fence_gpu_addr = dqm->fence_mem->gpu_addr; 735 736 init_interrupts(dqm); 737 738 mutex_lock(&dqm->lock); 739 execute_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0); 740 mutex_unlock(&dqm->lock); 741 742 return 0; 743 fail_allocate_vidmem: 744 fail_set_sched_resources: 745 pm_uninit(&dqm->packets); 746 fail_packet_manager_init: 747 return retval; 748 } 749 750 static int stop_cpsch(struct device_queue_manager *dqm) 751 { 752 mutex_lock(&dqm->lock); 753 unmap_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0); 754 mutex_unlock(&dqm->lock); 755 756 kfd_gtt_sa_free(dqm->dev, dqm->fence_mem); 757 pm_uninit(&dqm->packets); 758 759 return 0; 760 } 761 762 static int create_kernel_queue_cpsch(struct device_queue_manager *dqm, 763 struct kernel_queue *kq, 764 struct qcm_process_device *qpd) 765 { 766 mutex_lock(&dqm->lock); 767 if (dqm->total_queue_count >= max_num_of_queues_per_device) { 768 pr_warn("Can't create new kernel queue because %d queues were already created\n", 769 dqm->total_queue_count); 770 mutex_unlock(&dqm->lock); 771 return -EPERM; 772 } 773 774 /* 775 * Unconditionally increment this counter, regardless of the queue's 776 * type or whether the queue is active. 777 */ 778 dqm->total_queue_count++; 779 pr_debug("Total of %d queues are accountable so far\n", 780 dqm->total_queue_count); 781 782 list_add(&kq->list, &qpd->priv_queue_list); 783 dqm->queue_count++; 784 qpd->is_debug = true; 785 execute_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0); 786 mutex_unlock(&dqm->lock); 787 788 return 0; 789 } 790 791 static void destroy_kernel_queue_cpsch(struct device_queue_manager *dqm, 792 struct kernel_queue *kq, 793 struct qcm_process_device *qpd) 794 { 795 mutex_lock(&dqm->lock); 796 list_del(&kq->list); 797 dqm->queue_count--; 798 qpd->is_debug = false; 799 execute_queues_cpsch(dqm, KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES, 0); 800 /* 801 * Unconditionally decrement this counter, regardless of the queue's 802 * type. 803 */ 804 dqm->total_queue_count--; 805 pr_debug("Total of %d queues are accountable so far\n", 806 dqm->total_queue_count); 807 mutex_unlock(&dqm->lock); 808 } 809 810 static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q, 811 struct qcm_process_device *qpd) 812 { 813 int retval; 814 struct mqd_manager *mqd; 815 816 retval = 0; 817 818 mutex_lock(&dqm->lock); 819 820 if (dqm->total_queue_count >= max_num_of_queues_per_device) { 821 pr_warn("Can't create new usermode queue because %d queues were already created\n", 822 dqm->total_queue_count); 823 retval = -EPERM; 824 goto out_unlock; 825 } 826 827 if (q->properties.type == KFD_QUEUE_TYPE_SDMA) { 828 retval = allocate_sdma_queue(dqm, &q->sdma_id); 829 if (retval) 830 goto out_unlock; 831 q->properties.sdma_queue_id = 832 q->sdma_id / CIK_SDMA_QUEUES_PER_ENGINE; 833 q->properties.sdma_engine_id = 834 q->sdma_id % CIK_SDMA_QUEUES_PER_ENGINE; 835 } 836 mqd = dqm->ops.get_mqd_manager(dqm, 837 get_mqd_type_from_queue_type(q->properties.type)); 838 839 if (!mqd) { 840 retval = -ENOMEM; 841 goto out_deallocate_sdma_queue; 842 } 843 844 dqm->asic_ops.init_sdma_vm(dqm, q, qpd); 845 846 q->properties.tba_addr = qpd->tba_addr; 847 q->properties.tma_addr = qpd->tma_addr; 848 retval = mqd->init_mqd(mqd, &q->mqd, &q->mqd_mem_obj, 849 &q->gart_mqd_addr, &q->properties); 850 if (retval) 851 goto out_deallocate_sdma_queue; 852 853 list_add(&q->list, &qpd->queues_list); 854 qpd->queue_count++; 855 if (q->properties.is_active) { 856 dqm->queue_count++; 857 retval = execute_queues_cpsch(dqm, 858 KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0); 859 } 860 861 if (q->properties.type == KFD_QUEUE_TYPE_SDMA) 862 dqm->sdma_queue_count++; 863 /* 864 * Unconditionally increment this counter, regardless of the queue's 865 * type or whether the queue is active. 866 */ 867 dqm->total_queue_count++; 868 869 pr_debug("Total of %d queues are accountable so far\n", 870 dqm->total_queue_count); 871 872 mutex_unlock(&dqm->lock); 873 return retval; 874 875 out_deallocate_sdma_queue: 876 if (q->properties.type == KFD_QUEUE_TYPE_SDMA) 877 deallocate_sdma_queue(dqm, q->sdma_id); 878 out_unlock: 879 mutex_unlock(&dqm->lock); 880 return retval; 881 } 882 883 int amdkfd_fence_wait_timeout(unsigned int *fence_addr, 884 unsigned int fence_value, 885 unsigned int timeout_ms) 886 { 887 unsigned long end_jiffies = msecs_to_jiffies(timeout_ms) + jiffies; 888 889 while (*fence_addr != fence_value) { 890 if (time_after(jiffies, end_jiffies)) { 891 pr_err("qcm fence wait loop timeout expired\n"); 892 return -ETIME; 893 } 894 schedule(); 895 } 896 897 return 0; 898 } 899 900 static int unmap_sdma_queues(struct device_queue_manager *dqm, 901 unsigned int sdma_engine) 902 { 903 return pm_send_unmap_queue(&dqm->packets, KFD_QUEUE_TYPE_SDMA, 904 KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0, false, 905 sdma_engine); 906 } 907 908 /* dqm->lock mutex has to be locked before calling this function */ 909 static int map_queues_cpsch(struct device_queue_manager *dqm) 910 { 911 int retval; 912 913 if (dqm->queue_count <= 0 || dqm->processes_count <= 0) 914 return 0; 915 916 if (dqm->active_runlist) 917 return 0; 918 919 retval = pm_send_runlist(&dqm->packets, &dqm->queues); 920 if (retval) { 921 pr_err("failed to execute runlist\n"); 922 return retval; 923 } 924 dqm->active_runlist = true; 925 926 return retval; 927 } 928 929 /* dqm->lock mutex has to be locked before calling this function */ 930 static int unmap_queues_cpsch(struct device_queue_manager *dqm, 931 enum kfd_unmap_queues_filter filter, 932 uint32_t filter_param) 933 { 934 int retval = 0; 935 936 if (!dqm->active_runlist) 937 return retval; 938 939 pr_debug("Before destroying queues, sdma queue count is : %u\n", 940 dqm->sdma_queue_count); 941 942 if (dqm->sdma_queue_count > 0) { 943 unmap_sdma_queues(dqm, 0); 944 unmap_sdma_queues(dqm, 1); 945 } 946 947 retval = pm_send_unmap_queue(&dqm->packets, KFD_QUEUE_TYPE_COMPUTE, 948 filter, filter_param, false, 0); 949 if (retval) 950 return retval; 951 952 *dqm->fence_addr = KFD_FENCE_INIT; 953 pm_send_query_status(&dqm->packets, dqm->fence_gpu_addr, 954 KFD_FENCE_COMPLETED); 955 /* should be timed out */ 956 retval = amdkfd_fence_wait_timeout(dqm->fence_addr, KFD_FENCE_COMPLETED, 957 QUEUE_PREEMPT_DEFAULT_TIMEOUT_MS); 958 if (retval) 959 return retval; 960 961 pm_release_ib(&dqm->packets); 962 dqm->active_runlist = false; 963 964 return retval; 965 } 966 967 /* dqm->lock mutex has to be locked before calling this function */ 968 static int execute_queues_cpsch(struct device_queue_manager *dqm, 969 enum kfd_unmap_queues_filter filter, 970 uint32_t filter_param) 971 { 972 int retval; 973 974 retval = unmap_queues_cpsch(dqm, filter, filter_param); 975 if (retval) { 976 pr_err("The cp might be in an unrecoverable state due to an unsuccessful queues preemption\n"); 977 return retval; 978 } 979 980 return map_queues_cpsch(dqm); 981 } 982 983 static int destroy_queue_cpsch(struct device_queue_manager *dqm, 984 struct qcm_process_device *qpd, 985 struct queue *q) 986 { 987 int retval; 988 struct mqd_manager *mqd; 989 bool preempt_all_queues; 990 991 preempt_all_queues = false; 992 993 retval = 0; 994 995 /* remove queue from list to prevent rescheduling after preemption */ 996 mutex_lock(&dqm->lock); 997 998 if (qpd->is_debug) { 999 /* 1000 * error, currently we do not allow to destroy a queue 1001 * of a currently debugged process 1002 */ 1003 retval = -EBUSY; 1004 goto failed_try_destroy_debugged_queue; 1005 1006 } 1007 1008 mqd = dqm->ops.get_mqd_manager(dqm, 1009 get_mqd_type_from_queue_type(q->properties.type)); 1010 if (!mqd) { 1011 retval = -ENOMEM; 1012 goto failed; 1013 } 1014 1015 if (q->properties.type == KFD_QUEUE_TYPE_SDMA) { 1016 dqm->sdma_queue_count--; 1017 deallocate_sdma_queue(dqm, q->sdma_id); 1018 } 1019 1020 list_del(&q->list); 1021 qpd->queue_count--; 1022 if (q->properties.is_active) { 1023 dqm->queue_count--; 1024 retval = execute_queues_cpsch(dqm, 1025 KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES, 0); 1026 if (retval == -ETIME) 1027 qpd->reset_wavefronts = true; 1028 } 1029 1030 mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj); 1031 1032 /* 1033 * Unconditionally decrement this counter, regardless of the queue's 1034 * type 1035 */ 1036 dqm->total_queue_count--; 1037 pr_debug("Total of %d queues are accountable so far\n", 1038 dqm->total_queue_count); 1039 1040 mutex_unlock(&dqm->lock); 1041 1042 return retval; 1043 1044 failed: 1045 failed_try_destroy_debugged_queue: 1046 1047 mutex_unlock(&dqm->lock); 1048 return retval; 1049 } 1050 1051 /* 1052 * Low bits must be 0000/FFFF as required by HW, high bits must be 0 to 1053 * stay in user mode. 1054 */ 1055 #define APE1_FIXED_BITS_MASK 0xFFFF80000000FFFFULL 1056 /* APE1 limit is inclusive and 64K aligned. */ 1057 #define APE1_LIMIT_ALIGNMENT 0xFFFF 1058 1059 static bool set_cache_memory_policy(struct device_queue_manager *dqm, 1060 struct qcm_process_device *qpd, 1061 enum cache_policy default_policy, 1062 enum cache_policy alternate_policy, 1063 void __user *alternate_aperture_base, 1064 uint64_t alternate_aperture_size) 1065 { 1066 bool retval; 1067 1068 mutex_lock(&dqm->lock); 1069 1070 if (alternate_aperture_size == 0) { 1071 /* base > limit disables APE1 */ 1072 qpd->sh_mem_ape1_base = 1; 1073 qpd->sh_mem_ape1_limit = 0; 1074 } else { 1075 /* 1076 * In FSA64, APE1_Base[63:0] = { 16{SH_MEM_APE1_BASE[31]}, 1077 * SH_MEM_APE1_BASE[31:0], 0x0000 } 1078 * APE1_Limit[63:0] = { 16{SH_MEM_APE1_LIMIT[31]}, 1079 * SH_MEM_APE1_LIMIT[31:0], 0xFFFF } 1080 * Verify that the base and size parameters can be 1081 * represented in this format and convert them. 1082 * Additionally restrict APE1 to user-mode addresses. 1083 */ 1084 1085 uint64_t base = (uintptr_t)alternate_aperture_base; 1086 uint64_t limit = base + alternate_aperture_size - 1; 1087 1088 if (limit <= base || (base & APE1_FIXED_BITS_MASK) != 0 || 1089 (limit & APE1_FIXED_BITS_MASK) != APE1_LIMIT_ALIGNMENT) { 1090 retval = false; 1091 goto out; 1092 } 1093 1094 qpd->sh_mem_ape1_base = base >> 16; 1095 qpd->sh_mem_ape1_limit = limit >> 16; 1096 } 1097 1098 retval = dqm->asic_ops.set_cache_memory_policy( 1099 dqm, 1100 qpd, 1101 default_policy, 1102 alternate_policy, 1103 alternate_aperture_base, 1104 alternate_aperture_size); 1105 1106 if ((sched_policy == KFD_SCHED_POLICY_NO_HWS) && (qpd->vmid != 0)) 1107 program_sh_mem_settings(dqm, qpd); 1108 1109 pr_debug("sh_mem_config: 0x%x, ape1_base: 0x%x, ape1_limit: 0x%x\n", 1110 qpd->sh_mem_config, qpd->sh_mem_ape1_base, 1111 qpd->sh_mem_ape1_limit); 1112 1113 out: 1114 mutex_unlock(&dqm->lock); 1115 return retval; 1116 } 1117 1118 static int set_trap_handler(struct device_queue_manager *dqm, 1119 struct qcm_process_device *qpd, 1120 uint64_t tba_addr, 1121 uint64_t tma_addr) 1122 { 1123 uint64_t *tma; 1124 1125 if (dqm->dev->cwsr_enabled) { 1126 /* Jump from CWSR trap handler to user trap */ 1127 tma = (uint64_t *)(qpd->cwsr_kaddr + KFD_CWSR_TMA_OFFSET); 1128 tma[0] = tba_addr; 1129 tma[1] = tma_addr; 1130 } else { 1131 qpd->tba_addr = tba_addr; 1132 qpd->tma_addr = tma_addr; 1133 } 1134 1135 return 0; 1136 } 1137 1138 static int process_termination_nocpsch(struct device_queue_manager *dqm, 1139 struct qcm_process_device *qpd) 1140 { 1141 struct queue *q, *next; 1142 struct device_process_node *cur, *next_dpn; 1143 int retval = 0; 1144 1145 mutex_lock(&dqm->lock); 1146 1147 /* Clear all user mode queues */ 1148 list_for_each_entry_safe(q, next, &qpd->queues_list, list) { 1149 int ret; 1150 1151 ret = destroy_queue_nocpsch_locked(dqm, qpd, q); 1152 if (ret) 1153 retval = ret; 1154 } 1155 1156 /* Unregister process */ 1157 list_for_each_entry_safe(cur, next_dpn, &dqm->queues, list) { 1158 if (qpd == cur->qpd) { 1159 list_del(&cur->list); 1160 kfree(cur); 1161 dqm->processes_count--; 1162 break; 1163 } 1164 } 1165 1166 mutex_unlock(&dqm->lock); 1167 return retval; 1168 } 1169 1170 1171 static int process_termination_cpsch(struct device_queue_manager *dqm, 1172 struct qcm_process_device *qpd) 1173 { 1174 int retval; 1175 struct queue *q, *next; 1176 struct kernel_queue *kq, *kq_next; 1177 struct mqd_manager *mqd; 1178 struct device_process_node *cur, *next_dpn; 1179 enum kfd_unmap_queues_filter filter = 1180 KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES; 1181 1182 retval = 0; 1183 1184 mutex_lock(&dqm->lock); 1185 1186 /* Clean all kernel queues */ 1187 list_for_each_entry_safe(kq, kq_next, &qpd->priv_queue_list, list) { 1188 list_del(&kq->list); 1189 dqm->queue_count--; 1190 qpd->is_debug = false; 1191 dqm->total_queue_count--; 1192 filter = KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES; 1193 } 1194 1195 /* Clear all user mode queues */ 1196 list_for_each_entry(q, &qpd->queues_list, list) { 1197 if (q->properties.type == KFD_QUEUE_TYPE_SDMA) { 1198 dqm->sdma_queue_count--; 1199 deallocate_sdma_queue(dqm, q->sdma_id); 1200 } 1201 1202 if (q->properties.is_active) 1203 dqm->queue_count--; 1204 1205 dqm->total_queue_count--; 1206 } 1207 1208 /* Unregister process */ 1209 list_for_each_entry_safe(cur, next_dpn, &dqm->queues, list) { 1210 if (qpd == cur->qpd) { 1211 list_del(&cur->list); 1212 kfree(cur); 1213 dqm->processes_count--; 1214 break; 1215 } 1216 } 1217 1218 retval = execute_queues_cpsch(dqm, filter, 0); 1219 if (retval || qpd->reset_wavefronts) { 1220 pr_warn("Resetting wave fronts (cpsch) on dev %p\n", dqm->dev); 1221 dbgdev_wave_reset_wavefronts(dqm->dev, qpd->pqm->process); 1222 qpd->reset_wavefronts = false; 1223 } 1224 1225 /* lastly, free mqd resources */ 1226 list_for_each_entry_safe(q, next, &qpd->queues_list, list) { 1227 mqd = dqm->ops.get_mqd_manager(dqm, 1228 get_mqd_type_from_queue_type(q->properties.type)); 1229 if (!mqd) { 1230 retval = -ENOMEM; 1231 goto out; 1232 } 1233 list_del(&q->list); 1234 qpd->queue_count--; 1235 mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj); 1236 } 1237 1238 out: 1239 mutex_unlock(&dqm->lock); 1240 return retval; 1241 } 1242 1243 struct device_queue_manager *device_queue_manager_init(struct kfd_dev *dev) 1244 { 1245 struct device_queue_manager *dqm; 1246 1247 pr_debug("Loading device queue manager\n"); 1248 1249 dqm = kzalloc(sizeof(*dqm), GFP_KERNEL); 1250 if (!dqm) 1251 return NULL; 1252 1253 dqm->dev = dev; 1254 switch (sched_policy) { 1255 case KFD_SCHED_POLICY_HWS: 1256 case KFD_SCHED_POLICY_HWS_NO_OVERSUBSCRIPTION: 1257 /* initialize dqm for cp scheduling */ 1258 dqm->ops.create_queue = create_queue_cpsch; 1259 dqm->ops.initialize = initialize_cpsch; 1260 dqm->ops.start = start_cpsch; 1261 dqm->ops.stop = stop_cpsch; 1262 dqm->ops.destroy_queue = destroy_queue_cpsch; 1263 dqm->ops.update_queue = update_queue; 1264 dqm->ops.get_mqd_manager = get_mqd_manager; 1265 dqm->ops.register_process = register_process; 1266 dqm->ops.unregister_process = unregister_process; 1267 dqm->ops.uninitialize = uninitialize; 1268 dqm->ops.create_kernel_queue = create_kernel_queue_cpsch; 1269 dqm->ops.destroy_kernel_queue = destroy_kernel_queue_cpsch; 1270 dqm->ops.set_cache_memory_policy = set_cache_memory_policy; 1271 dqm->ops.set_trap_handler = set_trap_handler; 1272 dqm->ops.process_termination = process_termination_cpsch; 1273 break; 1274 case KFD_SCHED_POLICY_NO_HWS: 1275 /* initialize dqm for no cp scheduling */ 1276 dqm->ops.start = start_nocpsch; 1277 dqm->ops.stop = stop_nocpsch; 1278 dqm->ops.create_queue = create_queue_nocpsch; 1279 dqm->ops.destroy_queue = destroy_queue_nocpsch; 1280 dqm->ops.update_queue = update_queue; 1281 dqm->ops.get_mqd_manager = get_mqd_manager; 1282 dqm->ops.register_process = register_process; 1283 dqm->ops.unregister_process = unregister_process; 1284 dqm->ops.initialize = initialize_nocpsch; 1285 dqm->ops.uninitialize = uninitialize; 1286 dqm->ops.set_cache_memory_policy = set_cache_memory_policy; 1287 dqm->ops.set_trap_handler = set_trap_handler; 1288 dqm->ops.process_termination = process_termination_nocpsch; 1289 break; 1290 default: 1291 pr_err("Invalid scheduling policy %d\n", sched_policy); 1292 goto out_free; 1293 } 1294 1295 switch (dev->device_info->asic_family) { 1296 case CHIP_CARRIZO: 1297 device_queue_manager_init_vi(&dqm->asic_ops); 1298 break; 1299 1300 case CHIP_KAVERI: 1301 device_queue_manager_init_cik(&dqm->asic_ops); 1302 break; 1303 default: 1304 WARN(1, "Unexpected ASIC family %u", 1305 dev->device_info->asic_family); 1306 goto out_free; 1307 } 1308 1309 if (!dqm->ops.initialize(dqm)) 1310 return dqm; 1311 1312 out_free: 1313 kfree(dqm); 1314 return NULL; 1315 } 1316 1317 void device_queue_manager_uninit(struct device_queue_manager *dqm) 1318 { 1319 dqm->ops.uninitialize(dqm); 1320 kfree(dqm); 1321 } 1322 1323 #if defined(CONFIG_DEBUG_FS) 1324 1325 static void seq_reg_dump(struct seq_file *m, 1326 uint32_t (*dump)[2], uint32_t n_regs) 1327 { 1328 uint32_t i, count; 1329 1330 for (i = 0, count = 0; i < n_regs; i++) { 1331 if (count == 0 || 1332 dump[i-1][0] + sizeof(uint32_t) != dump[i][0]) { 1333 seq_printf(m, "%s %08x: %08x", 1334 i ? "\n" : "", 1335 dump[i][0], dump[i][1]); 1336 count = 7; 1337 } else { 1338 seq_printf(m, " %08x", dump[i][1]); 1339 count--; 1340 } 1341 } 1342 1343 seq_puts(m, "\n"); 1344 } 1345 1346 int dqm_debugfs_hqds(struct seq_file *m, void *data) 1347 { 1348 struct device_queue_manager *dqm = data; 1349 uint32_t (*dump)[2], n_regs; 1350 int pipe, queue; 1351 int r = 0; 1352 1353 for (pipe = 0; pipe < get_pipes_per_mec(dqm); pipe++) { 1354 int pipe_offset = pipe * get_queues_per_pipe(dqm); 1355 1356 for (queue = 0; queue < get_queues_per_pipe(dqm); queue++) { 1357 if (!test_bit(pipe_offset + queue, 1358 dqm->dev->shared_resources.queue_bitmap)) 1359 continue; 1360 1361 r = dqm->dev->kfd2kgd->hqd_dump( 1362 dqm->dev->kgd, pipe, queue, &dump, &n_regs); 1363 if (r) 1364 break; 1365 1366 seq_printf(m, " CP Pipe %d, Queue %d\n", 1367 pipe, queue); 1368 seq_reg_dump(m, dump, n_regs); 1369 1370 kfree(dump); 1371 } 1372 } 1373 1374 for (pipe = 0; pipe < CIK_SDMA_ENGINE_NUM; pipe++) { 1375 for (queue = 0; queue < CIK_SDMA_QUEUES_PER_ENGINE; queue++) { 1376 r = dqm->dev->kfd2kgd->hqd_sdma_dump( 1377 dqm->dev->kgd, pipe, queue, &dump, &n_regs); 1378 if (r) 1379 break; 1380 1381 seq_printf(m, " SDMA Engine %d, RLC %d\n", 1382 pipe, queue); 1383 seq_reg_dump(m, dump, n_regs); 1384 1385 kfree(dump); 1386 } 1387 } 1388 1389 return r; 1390 } 1391 1392 #endif 1393