1 /* 2 * Copyright 2009 Jerome Glisse. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 19 * USE OR OTHER DEALINGS IN THE SOFTWARE. 20 * 21 * The above copyright notice and this permission notice (including the 22 * next paragraph) shall be included in all copies or substantial portions 23 * of the Software. 24 * 25 */ 26 /* 27 * Authors: 28 * Jerome Glisse <glisse@freedesktop.org> 29 * Dave Airlie 30 */ 31 #include <linux/seq_file.h> 32 #include <linux/atomic.h> 33 #include <linux/wait.h> 34 #include <linux/kref.h> 35 #include <linux/slab.h> 36 #include <linux/firmware.h> 37 #include <drm/drmP.h> 38 #include "amdgpu.h" 39 #include "amdgpu_trace.h" 40 41 /* 42 * Fences 43 * Fences mark an event in the GPUs pipeline and are used 44 * for GPU/CPU synchronization. When the fence is written, 45 * it is expected that all buffers associated with that fence 46 * are no longer in use by the associated ring on the GPU and 47 * that the the relevant GPU caches have been flushed. 48 */ 49 50 struct amdgpu_fence { 51 struct dma_fence base; 52 53 /* RB, DMA, etc. */ 54 struct amdgpu_ring *ring; 55 }; 56 57 static struct pool amdgpu_fence_slab; 58 59 int amdgpu_fence_slab_init(void) 60 { 61 #ifdef __linux__ 62 amdgpu_fence_slab = kmem_cache_create( 63 "amdgpu_fence", sizeof(struct amdgpu_fence), 0, 64 SLAB_HWCACHE_ALIGN, NULL); 65 if (!amdgpu_fence_slab) 66 return -ENOMEM; 67 #else 68 pool_init(&amdgpu_fence_slab, sizeof(struct amdgpu_fence), 69 0, IPL_TTY, 0, "amdgpu_fence", NULL); 70 #endif 71 return 0; 72 } 73 74 void amdgpu_fence_slab_fini(void) 75 { 76 rcu_barrier(); 77 #ifdef __linux__ 78 kmem_cache_destroy(amdgpu_fence_slab); 79 #else 80 pool_destroy(&amdgpu_fence_slab); 81 #endif 82 } 83 /* 84 * Cast helper 85 */ 86 static const struct dma_fence_ops amdgpu_fence_ops; 87 static inline struct amdgpu_fence *to_amdgpu_fence(struct dma_fence *f) 88 { 89 struct amdgpu_fence *__f = container_of(f, struct amdgpu_fence, base); 90 91 if (__f->base.ops == &amdgpu_fence_ops) 92 return __f; 93 94 return NULL; 95 } 96 97 /** 98 * amdgpu_fence_write - write a fence value 99 * 100 * @ring: ring the fence is associated with 101 * @seq: sequence number to write 102 * 103 * Writes a fence value to memory (all asics). 104 */ 105 static void amdgpu_fence_write(struct amdgpu_ring *ring, u32 seq) 106 { 107 struct amdgpu_fence_driver *drv = &ring->fence_drv; 108 109 if (drv->cpu_addr) 110 *drv->cpu_addr = cpu_to_le32(seq); 111 } 112 113 /** 114 * amdgpu_fence_read - read a fence value 115 * 116 * @ring: ring the fence is associated with 117 * 118 * Reads a fence value from memory (all asics). 119 * Returns the value of the fence read from memory. 120 */ 121 static u32 amdgpu_fence_read(struct amdgpu_ring *ring) 122 { 123 struct amdgpu_fence_driver *drv = &ring->fence_drv; 124 u32 seq = 0; 125 126 if (drv->cpu_addr) 127 seq = le32_to_cpu(*drv->cpu_addr); 128 else 129 seq = atomic_read(&drv->last_seq); 130 131 return seq; 132 } 133 134 /** 135 * amdgpu_fence_emit - emit a fence on the requested ring 136 * 137 * @ring: ring the fence is associated with 138 * @f: resulting fence object 139 * 140 * Emits a fence command on the requested ring (all asics). 141 * Returns 0 on success, -ENOMEM on failure. 142 */ 143 int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, 144 unsigned flags) 145 { 146 struct amdgpu_device *adev = ring->adev; 147 struct amdgpu_fence *fence; 148 struct dma_fence *old, **ptr; 149 uint32_t seq; 150 151 #ifdef __linux__ 152 fence = kmem_cache_alloc(amdgpu_fence_slab, GFP_KERNEL); 153 #else 154 fence = pool_get(&amdgpu_fence_slab, PR_WAITOK); 155 #endif 156 if (fence == NULL) 157 return -ENOMEM; 158 159 seq = ++ring->fence_drv.sync_seq; 160 fence->ring = ring; 161 dma_fence_init(&fence->base, &amdgpu_fence_ops, 162 &ring->fence_drv.lock, 163 adev->fence_context + ring->idx, 164 seq); 165 amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr, 166 seq, flags | AMDGPU_FENCE_FLAG_INT); 167 168 ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask]; 169 /* This function can't be called concurrently anyway, otherwise 170 * emitting the fence would mess up the hardware ring buffer. 171 */ 172 old = rcu_dereference_protected(*ptr, 1); 173 if (old && !dma_fence_is_signaled(old)) { 174 DRM_INFO("rcu slot is busy\n"); 175 dma_fence_wait(old, false); 176 } 177 178 rcu_assign_pointer(*ptr, dma_fence_get(&fence->base)); 179 180 *f = &fence->base; 181 182 return 0; 183 } 184 185 /** 186 * amdgpu_fence_emit_polling - emit a fence on the requeste ring 187 * 188 * @ring: ring the fence is associated with 189 * @s: resulting sequence number 190 * 191 * Emits a fence command on the requested ring (all asics). 192 * Used For polling fence. 193 * Returns 0 on success, -ENOMEM on failure. 194 */ 195 int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s) 196 { 197 uint32_t seq; 198 199 if (!s) 200 return -EINVAL; 201 202 seq = ++ring->fence_drv.sync_seq; 203 amdgpu_ring_emit_fence(ring, ring->fence_drv.gpu_addr, 204 seq, 0); 205 206 *s = seq; 207 208 return 0; 209 } 210 211 /** 212 * amdgpu_fence_schedule_fallback - schedule fallback check 213 * 214 * @ring: pointer to struct amdgpu_ring 215 * 216 * Start a timer as fallback to our interrupts. 217 */ 218 static void amdgpu_fence_schedule_fallback(struct amdgpu_ring *ring) 219 { 220 mod_timer(&ring->fence_drv.fallback_timer, 221 jiffies + AMDGPU_FENCE_JIFFIES_TIMEOUT); 222 } 223 224 /** 225 * amdgpu_fence_process - check for fence activity 226 * 227 * @ring: pointer to struct amdgpu_ring 228 * 229 * Checks the current fence value and calculates the last 230 * signalled fence value. Wakes the fence queue if the 231 * sequence number has increased. 232 */ 233 void amdgpu_fence_process(struct amdgpu_ring *ring) 234 { 235 struct amdgpu_fence_driver *drv = &ring->fence_drv; 236 uint32_t seq, last_seq; 237 int r; 238 239 do { 240 last_seq = atomic_read(&ring->fence_drv.last_seq); 241 seq = amdgpu_fence_read(ring); 242 243 } while (atomic_cmpxchg(&drv->last_seq, last_seq, seq) != last_seq); 244 245 if (seq != ring->fence_drv.sync_seq) 246 amdgpu_fence_schedule_fallback(ring); 247 248 if (unlikely(seq == last_seq)) 249 return; 250 251 last_seq &= drv->num_fences_mask; 252 seq &= drv->num_fences_mask; 253 254 do { 255 struct dma_fence *fence, **ptr; 256 257 ++last_seq; 258 last_seq &= drv->num_fences_mask; 259 ptr = &drv->fences[last_seq]; 260 261 /* There is always exactly one thread signaling this fence slot */ 262 fence = rcu_dereference_protected(*ptr, 1); 263 RCU_INIT_POINTER(*ptr, NULL); 264 265 if (!fence) 266 continue; 267 268 r = dma_fence_signal(fence); 269 if (!r) 270 DMA_FENCE_TRACE(fence, "signaled from irq context\n"); 271 else 272 BUG(); 273 274 dma_fence_put(fence); 275 } while (last_seq != seq); 276 } 277 278 /** 279 * amdgpu_fence_fallback - fallback for hardware interrupts 280 * 281 * @work: delayed work item 282 * 283 * Checks for fence activity. 284 */ 285 static void amdgpu_fence_fallback(void *arg) 286 { 287 struct amdgpu_ring *ring = arg; 288 289 amdgpu_fence_process(ring); 290 } 291 292 /** 293 * amdgpu_fence_wait_empty - wait for all fences to signal 294 * 295 * @adev: amdgpu device pointer 296 * @ring: ring index the fence is associated with 297 * 298 * Wait for all fences on the requested ring to signal (all asics). 299 * Returns 0 if the fences have passed, error for all other cases. 300 */ 301 int amdgpu_fence_wait_empty(struct amdgpu_ring *ring) 302 { 303 uint64_t seq = READ_ONCE(ring->fence_drv.sync_seq); 304 struct dma_fence *fence, **ptr; 305 int r; 306 307 if (!seq) 308 return 0; 309 310 ptr = &ring->fence_drv.fences[seq & ring->fence_drv.num_fences_mask]; 311 rcu_read_lock(); 312 fence = rcu_dereference(*ptr); 313 if (!fence || !dma_fence_get_rcu(fence)) { 314 rcu_read_unlock(); 315 return 0; 316 } 317 rcu_read_unlock(); 318 319 r = dma_fence_wait(fence, false); 320 dma_fence_put(fence); 321 return r; 322 } 323 324 /** 325 * amdgpu_fence_wait_polling - busy wait for givn sequence number 326 * 327 * @ring: ring index the fence is associated with 328 * @wait_seq: sequence number to wait 329 * @timeout: the timeout for waiting in usecs 330 * 331 * Wait for all fences on the requested ring to signal (all asics). 332 * Returns left time if no timeout, 0 or minus if timeout. 333 */ 334 signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring, 335 uint32_t wait_seq, 336 signed long timeout) 337 { 338 uint32_t seq; 339 340 do { 341 seq = amdgpu_fence_read(ring); 342 udelay(5); 343 timeout -= 5; 344 } while ((int32_t)(wait_seq - seq) > 0 && timeout > 0); 345 346 return timeout > 0 ? timeout : 0; 347 } 348 /** 349 * amdgpu_fence_count_emitted - get the count of emitted fences 350 * 351 * @ring: ring the fence is associated with 352 * 353 * Get the number of fences emitted on the requested ring (all asics). 354 * Returns the number of emitted fences on the ring. Used by the 355 * dynpm code to ring track activity. 356 */ 357 unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring) 358 { 359 uint64_t emitted; 360 361 /* We are not protected by ring lock when reading the last sequence 362 * but it's ok to report slightly wrong fence count here. 363 */ 364 amdgpu_fence_process(ring); 365 emitted = 0x100000000ull; 366 emitted -= atomic_read(&ring->fence_drv.last_seq); 367 emitted += READ_ONCE(ring->fence_drv.sync_seq); 368 return lower_32_bits(emitted); 369 } 370 371 /** 372 * amdgpu_fence_driver_start_ring - make the fence driver 373 * ready for use on the requested ring. 374 * 375 * @ring: ring to start the fence driver on 376 * @irq_src: interrupt source to use for this ring 377 * @irq_type: interrupt type to use for this ring 378 * 379 * Make the fence driver ready for processing (all asics). 380 * Not all asics have all rings, so each asic will only 381 * start the fence driver on the rings it has. 382 * Returns 0 for success, errors for failure. 383 */ 384 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, 385 struct amdgpu_irq_src *irq_src, 386 unsigned irq_type) 387 { 388 struct amdgpu_device *adev = ring->adev; 389 uint64_t index; 390 391 if (ring->funcs->type != AMDGPU_RING_TYPE_UVD) { 392 ring->fence_drv.cpu_addr = &adev->wb.wb[ring->fence_offs]; 393 ring->fence_drv.gpu_addr = adev->wb.gpu_addr + (ring->fence_offs * 4); 394 } else { 395 /* put fence directly behind firmware */ 396 index = roundup2(adev->uvd.fw->size, 8); 397 ring->fence_drv.cpu_addr = adev->uvd.inst[ring->me].cpu_addr + index; 398 ring->fence_drv.gpu_addr = adev->uvd.inst[ring->me].gpu_addr + index; 399 } 400 amdgpu_fence_write(ring, atomic_read(&ring->fence_drv.last_seq)); 401 amdgpu_irq_get(adev, irq_src, irq_type); 402 403 ring->fence_drv.irq_src = irq_src; 404 ring->fence_drv.irq_type = irq_type; 405 ring->fence_drv.initialized = true; 406 407 dev_dbg(adev->dev, "fence driver on ring %d use gpu addr 0x%016llx, " 408 "cpu addr 0x%p\n", ring->idx, 409 ring->fence_drv.gpu_addr, ring->fence_drv.cpu_addr); 410 return 0; 411 } 412 413 /** 414 * amdgpu_fence_driver_init_ring - init the fence driver 415 * for the requested ring. 416 * 417 * @ring: ring to init the fence driver on 418 * @num_hw_submission: number of entries on the hardware queue 419 * 420 * Init the fence driver for the requested ring (all asics). 421 * Helper function for amdgpu_fence_driver_init(). 422 */ 423 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring, 424 unsigned num_hw_submission) 425 { 426 long timeout; 427 int r; 428 429 /* Check that num_hw_submission is a power of two */ 430 if ((num_hw_submission & (num_hw_submission - 1)) != 0) 431 return -EINVAL; 432 433 ring->fence_drv.cpu_addr = NULL; 434 ring->fence_drv.gpu_addr = 0; 435 ring->fence_drv.sync_seq = 0; 436 atomic_set(&ring->fence_drv.last_seq, 0); 437 ring->fence_drv.initialized = false; 438 439 #ifdef __linux__ 440 timer_setup(&ring->fence_drv.fallback_timer, amdgpu_fence_fallback, 0); 441 #else 442 timeout_set(&ring->fence_drv.fallback_timer, amdgpu_fence_fallback, 443 ring); 444 #endif 445 446 ring->fence_drv.num_fences_mask = num_hw_submission * 2 - 1; 447 mtx_init(&ring->fence_drv.lock, IPL_TTY); 448 ring->fence_drv.fences = kcalloc(num_hw_submission * 2, sizeof(void *), 449 GFP_KERNEL); 450 if (!ring->fence_drv.fences) 451 return -ENOMEM; 452 453 /* No need to setup the GPU scheduler for KIQ ring */ 454 if (ring->funcs->type != AMDGPU_RING_TYPE_KIQ) { 455 /* for non-sriov case, no timeout enforce on compute ring */ 456 if ((ring->funcs->type == AMDGPU_RING_TYPE_COMPUTE) 457 && !amdgpu_sriov_vf(ring->adev)) 458 timeout = MAX_SCHEDULE_TIMEOUT; 459 else 460 timeout = msecs_to_jiffies(amdgpu_lockup_timeout); 461 462 r = drm_sched_init(&ring->sched, &amdgpu_sched_ops, 463 num_hw_submission, amdgpu_job_hang_limit, 464 timeout, ring->name); 465 if (r) { 466 DRM_ERROR("Failed to create scheduler on ring %s.\n", 467 ring->name); 468 return r; 469 } 470 } 471 472 return 0; 473 } 474 475 /** 476 * amdgpu_fence_driver_init - init the fence driver 477 * for all possible rings. 478 * 479 * @adev: amdgpu device pointer 480 * 481 * Init the fence driver for all possible rings (all asics). 482 * Not all asics have all rings, so each asic will only 483 * start the fence driver on the rings it has using 484 * amdgpu_fence_driver_start_ring(). 485 * Returns 0 for success. 486 */ 487 int amdgpu_fence_driver_init(struct amdgpu_device *adev) 488 { 489 if (amdgpu_debugfs_fence_init(adev)) 490 dev_err(adev->dev, "fence debugfs file creation failed\n"); 491 492 return 0; 493 } 494 495 /** 496 * amdgpu_fence_driver_fini - tear down the fence driver 497 * for all possible rings. 498 * 499 * @adev: amdgpu device pointer 500 * 501 * Tear down the fence driver for all possible rings (all asics). 502 */ 503 void amdgpu_fence_driver_fini(struct amdgpu_device *adev) 504 { 505 unsigned i, j; 506 int r; 507 508 for (i = 0; i < AMDGPU_MAX_RINGS; i++) { 509 struct amdgpu_ring *ring = adev->rings[i]; 510 511 if (!ring || !ring->fence_drv.initialized) 512 continue; 513 r = amdgpu_fence_wait_empty(ring); 514 if (r) { 515 /* no need to trigger GPU reset as we are unloading */ 516 amdgpu_fence_driver_force_completion(ring); 517 } 518 amdgpu_irq_put(adev, ring->fence_drv.irq_src, 519 ring->fence_drv.irq_type); 520 drm_sched_fini(&ring->sched); 521 del_timer_sync(&ring->fence_drv.fallback_timer); 522 for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j) 523 dma_fence_put(ring->fence_drv.fences[j]); 524 kfree(ring->fence_drv.fences); 525 ring->fence_drv.fences = NULL; 526 ring->fence_drv.initialized = false; 527 } 528 } 529 530 /** 531 * amdgpu_fence_driver_suspend - suspend the fence driver 532 * for all possible rings. 533 * 534 * @adev: amdgpu device pointer 535 * 536 * Suspend the fence driver for all possible rings (all asics). 537 */ 538 void amdgpu_fence_driver_suspend(struct amdgpu_device *adev) 539 { 540 int i, r; 541 542 for (i = 0; i < AMDGPU_MAX_RINGS; i++) { 543 struct amdgpu_ring *ring = adev->rings[i]; 544 if (!ring || !ring->fence_drv.initialized) 545 continue; 546 547 /* wait for gpu to finish processing current batch */ 548 r = amdgpu_fence_wait_empty(ring); 549 if (r) { 550 /* delay GPU reset to resume */ 551 amdgpu_fence_driver_force_completion(ring); 552 } 553 554 /* disable the interrupt */ 555 amdgpu_irq_put(adev, ring->fence_drv.irq_src, 556 ring->fence_drv.irq_type); 557 } 558 } 559 560 /** 561 * amdgpu_fence_driver_resume - resume the fence driver 562 * for all possible rings. 563 * 564 * @adev: amdgpu device pointer 565 * 566 * Resume the fence driver for all possible rings (all asics). 567 * Not all asics have all rings, so each asic will only 568 * start the fence driver on the rings it has using 569 * amdgpu_fence_driver_start_ring(). 570 * Returns 0 for success. 571 */ 572 void amdgpu_fence_driver_resume(struct amdgpu_device *adev) 573 { 574 int i; 575 576 for (i = 0; i < AMDGPU_MAX_RINGS; i++) { 577 struct amdgpu_ring *ring = adev->rings[i]; 578 if (!ring || !ring->fence_drv.initialized) 579 continue; 580 581 /* enable the interrupt */ 582 amdgpu_irq_get(adev, ring->fence_drv.irq_src, 583 ring->fence_drv.irq_type); 584 } 585 } 586 587 /** 588 * amdgpu_fence_driver_force_completion - force signal latest fence of ring 589 * 590 * @ring: fence of the ring to signal 591 * 592 */ 593 void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring) 594 { 595 amdgpu_fence_write(ring, ring->fence_drv.sync_seq); 596 amdgpu_fence_process(ring); 597 } 598 599 /* 600 * Common fence implementation 601 */ 602 603 static const char *amdgpu_fence_get_driver_name(struct dma_fence *fence) 604 { 605 return "amdgpu"; 606 } 607 608 static const char *amdgpu_fence_get_timeline_name(struct dma_fence *f) 609 { 610 struct amdgpu_fence *fence = to_amdgpu_fence(f); 611 return (const char *)fence->ring->name; 612 } 613 614 /** 615 * amdgpu_fence_enable_signaling - enable signalling on fence 616 * @fence: fence 617 * 618 * This function is called with fence_queue lock held, and adds a callback 619 * to fence_queue that checks if this fence is signaled, and if so it 620 * signals the fence and removes itself. 621 */ 622 static bool amdgpu_fence_enable_signaling(struct dma_fence *f) 623 { 624 struct amdgpu_fence *fence = to_amdgpu_fence(f); 625 struct amdgpu_ring *ring = fence->ring; 626 627 if (!timer_pending(&ring->fence_drv.fallback_timer)) 628 amdgpu_fence_schedule_fallback(ring); 629 630 DMA_FENCE_TRACE(&fence->base, "armed on ring %i!\n", ring->idx); 631 632 return true; 633 } 634 635 /** 636 * amdgpu_fence_free - free up the fence memory 637 * 638 * @rcu: RCU callback head 639 * 640 * Free up the fence memory after the RCU grace period. 641 */ 642 static void amdgpu_fence_free(struct rcu_head *rcu) 643 { 644 struct dma_fence *f = container_of(rcu, struct dma_fence, rcu); 645 struct amdgpu_fence *fence = to_amdgpu_fence(f); 646 #ifdef __linux__ 647 kmem_cache_free(amdgpu_fence_slab, fence); 648 #else 649 pool_put(&amdgpu_fence_slab, fence); 650 #endif 651 } 652 653 /** 654 * amdgpu_fence_release - callback that fence can be freed 655 * 656 * @fence: fence 657 * 658 * This function is called when the reference count becomes zero. 659 * It just RCU schedules freeing up the fence. 660 */ 661 static void amdgpu_fence_release(struct dma_fence *f) 662 { 663 call_rcu(&f->rcu, amdgpu_fence_free); 664 } 665 666 static const struct dma_fence_ops amdgpu_fence_ops = { 667 .get_driver_name = amdgpu_fence_get_driver_name, 668 .get_timeline_name = amdgpu_fence_get_timeline_name, 669 .enable_signaling = amdgpu_fence_enable_signaling, 670 .release = amdgpu_fence_release, 671 }; 672 673 /* 674 * Fence debugfs 675 */ 676 #if defined(CONFIG_DEBUG_FS) 677 static int amdgpu_debugfs_fence_info(struct seq_file *m, void *data) 678 { 679 struct drm_info_node *node = (struct drm_info_node *)m->private; 680 struct drm_device *dev = node->minor->dev; 681 struct amdgpu_device *adev = dev->dev_private; 682 int i; 683 684 for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { 685 struct amdgpu_ring *ring = adev->rings[i]; 686 if (!ring || !ring->fence_drv.initialized) 687 continue; 688 689 amdgpu_fence_process(ring); 690 691 seq_printf(m, "--- ring %d (%s) ---\n", i, ring->name); 692 seq_printf(m, "Last signaled fence 0x%08x\n", 693 atomic_read(&ring->fence_drv.last_seq)); 694 seq_printf(m, "Last emitted 0x%08x\n", 695 ring->fence_drv.sync_seq); 696 697 if (ring->funcs->type != AMDGPU_RING_TYPE_GFX) 698 continue; 699 700 /* set in CP_VMID_PREEMPT and preemption occurred */ 701 seq_printf(m, "Last preempted 0x%08x\n", 702 le32_to_cpu(*(ring->fence_drv.cpu_addr + 2))); 703 /* set in CP_VMID_RESET and reset occurred */ 704 seq_printf(m, "Last reset 0x%08x\n", 705 le32_to_cpu(*(ring->fence_drv.cpu_addr + 4))); 706 /* Both preemption and reset occurred */ 707 seq_printf(m, "Last both 0x%08x\n", 708 le32_to_cpu(*(ring->fence_drv.cpu_addr + 6))); 709 } 710 return 0; 711 } 712 713 /** 714 * amdgpu_debugfs_gpu_recover - manually trigger a gpu reset & recover 715 * 716 * Manually trigger a gpu reset at the next fence wait. 717 */ 718 static int amdgpu_debugfs_gpu_recover(struct seq_file *m, void *data) 719 { 720 struct drm_info_node *node = (struct drm_info_node *) m->private; 721 struct drm_device *dev = node->minor->dev; 722 struct amdgpu_device *adev = dev->dev_private; 723 724 seq_printf(m, "gpu recover\n"); 725 amdgpu_device_gpu_recover(adev, NULL, true); 726 727 return 0; 728 } 729 730 static const struct drm_info_list amdgpu_debugfs_fence_list[] = { 731 {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL}, 732 {"amdgpu_gpu_recover", &amdgpu_debugfs_gpu_recover, 0, NULL} 733 }; 734 735 static const struct drm_info_list amdgpu_debugfs_fence_list_sriov[] = { 736 {"amdgpu_fence_info", &amdgpu_debugfs_fence_info, 0, NULL}, 737 }; 738 #endif 739 740 int amdgpu_debugfs_fence_init(struct amdgpu_device *adev) 741 { 742 #if defined(CONFIG_DEBUG_FS) 743 if (amdgpu_sriov_vf(adev)) 744 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list_sriov, 1); 745 return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_fence_list, 2); 746 #else 747 return 0; 748 #endif 749 } 750 751