2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <dev/drm2/drmP.h>
34 #include <dev/drm2/radeon/radeon_drm.h>
35 #include "radeon_reg.h"
42 * IBs (Indirect Buffers) and areas of GPU accessible memory where
43 * commands are stored. You can put a pointer to the IB in the
44 * command ring and the hw will fetch the commands from the IB
45 * and execute them. Generally userspace acceleration drivers
46 * produce command buffers which are send to the kernel and
47 * put in IBs for execution by the requested ring.
49 static int radeon_debugfs_sa_init(struct radeon_device *rdev);
50 #endif /* FREEBSD_WIP */
53 * radeon_ib_get - request an IB (Indirect Buffer)
55 * @rdev: radeon_device pointer
56 * @ring: ring index the IB is associated with
57 * @ib: IB object returned
58 * @size: requested IB size
60 * Request an IB (all asics). IBs are allocated using the
62 * Returns 0 on success, error on failure.
64 int radeon_ib_get(struct radeon_device *rdev, int ring,
65 struct radeon_ib *ib, struct radeon_vm *vm,
70 r = radeon_sa_bo_new(rdev, &rdev->ring_tmp_bo, &ib->sa_bo, size, 256, true);
72 dev_err(rdev->dev, "failed to get a new IB (%d)\n", r);
76 r = radeon_semaphore_create(rdev, &ib->semaphore);
83 ib->ptr = radeon_sa_bo_cpu_addr(ib->sa_bo);
86 /* ib pool is bound at RADEON_VA_IB_OFFSET in virtual address
87 * space and soffset is the offset inside the pool bo
89 ib->gpu_addr = ib->sa_bo->soffset + RADEON_VA_IB_OFFSET;
91 ib->gpu_addr = radeon_sa_bo_gpu_addr(ib->sa_bo);
93 ib->is_const_ib = false;
94 for (i = 0; i < RADEON_NUM_RINGS; ++i)
95 ib->sync_to[i] = NULL;
101 * radeon_ib_free - free an IB (Indirect Buffer)
103 * @rdev: radeon_device pointer
104 * @ib: IB object to free
106 * Free an IB (all asics).
108 void radeon_ib_free(struct radeon_device *rdev, struct radeon_ib *ib)
110 radeon_semaphore_free(rdev, &ib->semaphore, ib->fence);
111 radeon_sa_bo_free(rdev, &ib->sa_bo, ib->fence);
112 radeon_fence_unref(&ib->fence);
116 * radeon_ib_schedule - schedule an IB (Indirect Buffer) on the ring
118 * @rdev: radeon_device pointer
119 * @ib: IB object to schedule
120 * @const_ib: Const IB to schedule (SI only)
122 * Schedule an IB on the associated ring (all asics).
123 * Returns 0 on success, error on failure.
125 * On SI, there are two parallel engines fed from the primary ring,
126 * the CE (Constant Engine) and the DE (Drawing Engine). Since
127 * resource descriptors have moved to memory, the CE allows you to
128 * prime the caches while the DE is updating register state so that
129 * the resource descriptors will be already in cache when the draw is
130 * processed. To accomplish this, the userspace driver submits two
131 * IBs, one for the CE and one for the DE. If there is a CE IB (called
132 * a CONST_IB), it will be put on the ring prior to the DE IB. Prior
133 * to SI there was just a DE IB.
135 int radeon_ib_schedule(struct radeon_device *rdev, struct radeon_ib *ib,
136 struct radeon_ib *const_ib)
138 struct radeon_ring *ring = &rdev->ring[ib->ring];
139 bool need_sync = false;
142 if (!ib->length_dw || !ring->ready) {
143 /* TODO: Nothings in the ib we should report. */
144 dev_err(rdev->dev, "couldn't schedule ib\n");
148 /* 64 dwords should be enough for fence too */
149 r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_RINGS * 8);
151 dev_err(rdev->dev, "scheduling IB failed (%d).\n", r);
154 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
155 struct radeon_fence *fence = ib->sync_to[i];
156 if (radeon_fence_need_sync(fence, ib->ring)) {
158 radeon_semaphore_sync_rings(rdev, ib->semaphore,
159 fence->ring, ib->ring);
160 radeon_fence_note_sync(fence, ib->ring);
163 /* immediately free semaphore when we don't need to sync */
165 radeon_semaphore_free(rdev, &ib->semaphore, NULL);
167 /* if we can't remember our last VM flush then flush now! */
168 /* XXX figure out why we have to flush for every IB */
169 if (ib->vm /*&& !ib->vm->last_flush*/) {
170 radeon_ring_vm_flush(rdev, ib->ring, ib->vm);
173 radeon_ring_ib_execute(rdev, const_ib->ring, const_ib);
174 radeon_semaphore_free(rdev, &const_ib->semaphore, NULL);
176 radeon_ring_ib_execute(rdev, ib->ring, ib);
177 r = radeon_fence_emit(rdev, &ib->fence, ib->ring);
179 dev_err(rdev->dev, "failed to emit fence for new IB (%d)\n", r);
180 radeon_ring_unlock_undo(rdev, ring);
184 const_ib->fence = radeon_fence_ref(ib->fence);
186 /* we just flushed the VM, remember that */
187 if (ib->vm && !ib->vm->last_flush) {
188 ib->vm->last_flush = radeon_fence_ref(ib->fence);
190 radeon_ring_unlock_commit(rdev, ring);
195 * radeon_ib_pool_init - Init the IB (Indirect Buffer) pool
197 * @rdev: radeon_device pointer
199 * Initialize the suballocator to manage a pool of memory
200 * for use as IBs (all asics).
201 * Returns 0 on success, error on failure.
203 int radeon_ib_pool_init(struct radeon_device *rdev)
207 if (rdev->ib_pool_ready) {
210 r = radeon_sa_bo_manager_init(rdev, &rdev->ring_tmp_bo,
211 RADEON_IB_POOL_SIZE*64*1024,
212 RADEON_GEM_DOMAIN_GTT);
217 r = radeon_sa_bo_manager_start(rdev, &rdev->ring_tmp_bo);
222 rdev->ib_pool_ready = true;
224 if (radeon_debugfs_sa_init(rdev)) {
225 dev_err(rdev->dev, "failed to register debugfs file for SA\n");
227 #endif /* FREEBSD_WIP */
232 * radeon_ib_pool_fini - Free the IB (Indirect Buffer) pool
234 * @rdev: radeon_device pointer
236 * Tear down the suballocator managing the pool of memory
237 * for use as IBs (all asics).
239 void radeon_ib_pool_fini(struct radeon_device *rdev)
241 if (rdev->ib_pool_ready) {
242 radeon_sa_bo_manager_suspend(rdev, &rdev->ring_tmp_bo);
243 radeon_sa_bo_manager_fini(rdev, &rdev->ring_tmp_bo);
244 rdev->ib_pool_ready = false;
249 * radeon_ib_ring_tests - test IBs on the rings
251 * @rdev: radeon_device pointer
253 * Test an IB (Indirect Buffer) on each ring.
254 * If the test fails, disable the ring.
255 * Returns 0 on success, error if the primary GFX ring
258 int radeon_ib_ring_tests(struct radeon_device *rdev)
263 for (i = 0; i < RADEON_NUM_RINGS; ++i) {
264 struct radeon_ring *ring = &rdev->ring[i];
269 r = radeon_ib_test(rdev, i, ring);
273 if (i == RADEON_RING_TYPE_GFX_INDEX) {
274 /* oh, oh, that's really bad */
275 DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r);
276 rdev->accel_working = false;
280 /* still not good, but we can live with it */
281 DRM_ERROR("radeon: failed testing IB on ring %d (%d).\n", i, r);
291 * Most engines on the GPU are fed via ring buffers. Ring
292 * buffers are areas of GPU accessible memory that the host
293 * writes commands into and the GPU reads commands out of.
294 * There is a rptr (read pointer) that determines where the
295 * GPU is currently reading, and a wptr (write pointer)
296 * which determines where the host has written. When the
297 * pointers are equal, the ring is idle. When the host
298 * writes commands to the ring buffer, it increments the
299 * wptr. The GPU then starts fetching commands and executes
300 * them until the pointers are equal again.
302 static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring);
303 #endif /* FREEBSD_WIP */
306 * radeon_ring_write - write a value to the ring
308 * @ring: radeon_ring structure holding ring information
309 * @v: dword (dw) value to write
311 * Write a value to the requested ring buffer (all asics).
313 void radeon_ring_write(struct radeon_ring *ring, uint32_t v)
316 if (ring->count_dw <= 0) {
317 DRM_ERROR("radeon: writing more dwords to the ring than expected!\n");
320 ring->ring[ring->wptr++] = v;
321 ring->wptr &= ring->ptr_mask;
323 ring->ring_free_dw--;
327 * radeon_ring_supports_scratch_reg - check if the ring supports
328 * writing to scratch registers
330 * @rdev: radeon_device pointer
331 * @ring: radeon_ring structure holding ring information
333 * Check if a specific ring supports writing to scratch registers (all asics).
334 * Returns true if the ring supports writing to scratch regs, false if not.
336 bool radeon_ring_supports_scratch_reg(struct radeon_device *rdev,
337 struct radeon_ring *ring)
340 case RADEON_RING_TYPE_GFX_INDEX:
341 case CAYMAN_RING_TYPE_CP1_INDEX:
342 case CAYMAN_RING_TYPE_CP2_INDEX:
350 * radeon_ring_free_size - update the free size
352 * @rdev: radeon_device pointer
353 * @ring: radeon_ring structure holding ring information
355 * Update the free dw slots in the ring buffer (all asics).
357 void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *ring)
361 if (rdev->wb.enabled)
362 rptr = le32_to_cpu(rdev->wb.wb[ring->rptr_offs/4]);
364 rptr = RREG32(ring->rptr_reg);
365 ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift;
366 /* This works because ring_size is a power of 2 */
367 ring->ring_free_dw = (ring->rptr + (ring->ring_size / 4));
368 ring->ring_free_dw -= ring->wptr;
369 ring->ring_free_dw &= ring->ptr_mask;
370 if (!ring->ring_free_dw) {
371 ring->ring_free_dw = ring->ring_size / 4;
376 * radeon_ring_alloc - allocate space on the ring buffer
378 * @rdev: radeon_device pointer
379 * @ring: radeon_ring structure holding ring information
380 * @ndw: number of dwords to allocate in the ring buffer
382 * Allocate @ndw dwords in the ring buffer (all asics).
383 * Returns 0 on success, error on failure.
385 int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
389 /* make sure we aren't trying to allocate more space than there is on the ring */
390 if (ndw > (ring->ring_size / 4))
392 /* Align requested size with padding so unlock_commit can
394 ndw = (ndw + ring->align_mask) & ~ring->align_mask;
395 while (ndw > (ring->ring_free_dw - 1)) {
396 radeon_ring_free_size(rdev, ring);
397 if (ndw < ring->ring_free_dw) {
400 r = radeon_fence_wait_next_locked(rdev, ring->idx);
404 ring->count_dw = ndw;
405 ring->wptr_old = ring->wptr;
410 * radeon_ring_lock - lock the ring and allocate space on it
412 * @rdev: radeon_device pointer
413 * @ring: radeon_ring structure holding ring information
414 * @ndw: number of dwords to allocate in the ring buffer
416 * Lock the ring and allocate @ndw dwords in the ring buffer
418 * Returns 0 on success, error on failure.
420 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
424 sx_xlock(&rdev->ring_lock);
425 r = radeon_ring_alloc(rdev, ring, ndw);
427 sx_xunlock(&rdev->ring_lock);
434 * radeon_ring_commit - tell the GPU to execute the new
435 * commands on the ring buffer
437 * @rdev: radeon_device pointer
438 * @ring: radeon_ring structure holding ring information
440 * Update the wptr (write pointer) to tell the GPU to
441 * execute new commands on the ring buffer (all asics).
443 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring)
445 /* We pad to match fetch size */
446 while (ring->wptr & ring->align_mask) {
447 radeon_ring_write(ring, ring->nop);
450 WREG32(ring->wptr_reg, (ring->wptr << ring->ptr_reg_shift) & ring->ptr_reg_mask);
451 (void)RREG32(ring->wptr_reg);
455 * radeon_ring_unlock_commit - tell the GPU to execute the new
456 * commands on the ring buffer and unlock it
458 * @rdev: radeon_device pointer
459 * @ring: radeon_ring structure holding ring information
461 * Call radeon_ring_commit() then unlock the ring (all asics).
463 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *ring)
465 radeon_ring_commit(rdev, ring);
466 sx_xunlock(&rdev->ring_lock);
470 * radeon_ring_undo - reset the wptr
472 * @ring: radeon_ring structure holding ring information
474 * Reset the driver's copy of the wptr (all asics).
476 void radeon_ring_undo(struct radeon_ring *ring)
478 ring->wptr = ring->wptr_old;
482 * radeon_ring_unlock_undo - reset the wptr and unlock the ring
484 * @ring: radeon_ring structure holding ring information
486 * Call radeon_ring_undo() then unlock the ring (all asics).
488 void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring)
490 radeon_ring_undo(ring);
491 sx_xunlock(&rdev->ring_lock);
495 * radeon_ring_force_activity - add some nop packets to the ring
497 * @rdev: radeon_device pointer
498 * @ring: radeon_ring structure holding ring information
500 * Add some nop packets to the ring to force activity (all asics).
501 * Used for lockup detection to see if the rptr is advancing.
503 void radeon_ring_force_activity(struct radeon_device *rdev, struct radeon_ring *ring)
507 radeon_ring_free_size(rdev, ring);
508 if (ring->rptr == ring->wptr) {
509 r = radeon_ring_alloc(rdev, ring, 1);
511 radeon_ring_write(ring, ring->nop);
512 radeon_ring_commit(rdev, ring);
518 * radeon_ring_lockup_update - update lockup variables
520 * @ring: radeon_ring structure holding ring information
522 * Update the last rptr value and timestamp (all asics).
524 void radeon_ring_lockup_update(struct radeon_ring *ring)
526 ring->last_rptr = ring->rptr;
527 ring->last_activity = jiffies;
531 * radeon_ring_test_lockup() - check if ring is lockedup by recording information
532 * @rdev: radeon device structure
533 * @ring: radeon_ring structure holding ring information
535 * We don't need to initialize the lockup tracking information as we will either
536 * have CP rptr to a different value of jiffies wrap around which will force
537 * initialization of the lockup tracking informations.
539 * A possible false positivie is if we get call after while and last_cp_rptr ==
540 * the current CP rptr, even if it's unlikely it might happen. To avoid this
541 * if the elapsed time since last call is bigger than 2 second than we return
542 * false and update the tracking information. Due to this the caller must call
543 * radeon_ring_test_lockup several time in less than 2sec for lockup to be reported
544 * the fencing code should be cautious about that.
546 * Caller should write to the ring to force CP to do something so we don't get
547 * false positive when CP is just gived nothing to do.
550 bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
552 unsigned long cjiffies, elapsed;
556 if (!time_after(cjiffies, ring->last_activity)) {
557 /* likely a wrap around */
558 radeon_ring_lockup_update(ring);
561 rptr = RREG32(ring->rptr_reg);
562 ring->rptr = (rptr & ring->ptr_reg_mask) >> ring->ptr_reg_shift;
563 if (ring->rptr != ring->last_rptr) {
564 /* CP is still working no lockup */
565 radeon_ring_lockup_update(ring);
568 elapsed = jiffies_to_msecs(cjiffies - ring->last_activity);
569 if (radeon_lockup_timeout && elapsed >= radeon_lockup_timeout) {
570 dev_err(rdev->dev, "GPU lockup CP stall for more than %lumsec\n", elapsed);
573 /* give a chance to the GPU ... */
578 * radeon_ring_backup - Back up the content of a ring
580 * @rdev: radeon_device pointer
581 * @ring: the ring we want to back up
583 * Saves all unprocessed commits from a ring, returns the number of dwords saved.
585 unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
588 unsigned size, ptr, i;
590 /* just in case lock the ring */
591 sx_xlock(&rdev->ring_lock);
594 if (ring->ring_obj == NULL) {
595 sx_xunlock(&rdev->ring_lock);
599 /* it doesn't make sense to save anything if all fences are signaled */
600 if (!radeon_fence_count_emitted(rdev, ring->idx)) {
601 sx_xunlock(&rdev->ring_lock);
605 /* calculate the number of dw on the ring */
606 if (ring->rptr_save_reg)
607 ptr = RREG32(ring->rptr_save_reg);
608 else if (rdev->wb.enabled)
609 ptr = le32_to_cpu(*ring->next_rptr_cpu_addr);
611 /* no way to read back the next rptr */
612 sx_xunlock(&rdev->ring_lock);
616 size = ring->wptr + (ring->ring_size / 4);
618 size &= ring->ptr_mask;
620 sx_xunlock(&rdev->ring_lock);
624 /* and then save the content of the ring */
625 *data = malloc(size * sizeof(uint32_t), DRM_MEM_DRIVER, M_NOWAIT);
627 sx_xunlock(&rdev->ring_lock);
630 for (i = 0; i < size; ++i) {
631 (*data)[i] = ring->ring[ptr++];
632 ptr &= ring->ptr_mask;
635 sx_xunlock(&rdev->ring_lock);
640 * radeon_ring_restore - append saved commands to the ring again
642 * @rdev: radeon_device pointer
643 * @ring: ring to append commands to
644 * @size: number of dwords we want to write
645 * @data: saved commands
647 * Allocates space on the ring and restore the previously saved commands.
649 int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
650 unsigned size, uint32_t *data)
657 /* restore the saved ring content */
658 r = radeon_ring_lock(rdev, ring, size);
662 for (i = 0; i < size; ++i) {
663 radeon_ring_write(ring, data[i]);
666 radeon_ring_unlock_commit(rdev, ring);
667 free(data, DRM_MEM_DRIVER);
672 * radeon_ring_init - init driver ring struct.
674 * @rdev: radeon_device pointer
675 * @ring: radeon_ring structure holding ring information
676 * @ring_size: size of the ring
677 * @rptr_offs: offset of the rptr writeback location in the WB buffer
678 * @rptr_reg: MMIO offset of the rptr register
679 * @wptr_reg: MMIO offset of the wptr register
680 * @ptr_reg_shift: bit offset of the rptr/wptr values
681 * @ptr_reg_mask: bit mask of the rptr/wptr values
682 * @nop: nop packet for this ring
684 * Initialize the driver information for the selected ring (all asics).
685 * Returns 0 on success, error on failure.
687 int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size,
688 unsigned rptr_offs, unsigned rptr_reg, unsigned wptr_reg,
689 u32 ptr_reg_shift, u32 ptr_reg_mask, u32 nop)
692 void *ring_ptr; /* FreeBSD: to please GCC 4.2. */
694 ring->ring_size = ring_size;
695 ring->rptr_offs = rptr_offs;
696 ring->rptr_reg = rptr_reg;
697 ring->wptr_reg = wptr_reg;
698 ring->ptr_reg_shift = ptr_reg_shift;
699 ring->ptr_reg_mask = ptr_reg_mask;
701 /* Allocate ring buffer */
702 if (ring->ring_obj == NULL) {
703 r = radeon_bo_create(rdev, ring->ring_size, PAGE_SIZE, true,
704 RADEON_GEM_DOMAIN_GTT,
705 NULL, &ring->ring_obj);
707 dev_err(rdev->dev, "(%d) ring create failed\n", r);
710 r = radeon_bo_reserve(ring->ring_obj, false);
711 if (unlikely(r != 0)) {
712 radeon_bo_unref(&ring->ring_obj);
715 r = radeon_bo_pin(ring->ring_obj, RADEON_GEM_DOMAIN_GTT,
718 radeon_bo_unreserve(ring->ring_obj);
719 radeon_bo_unref(&ring->ring_obj);
720 dev_err(rdev->dev, "(%d) ring pin failed\n", r);
723 ring_ptr = &ring->ring;
724 r = radeon_bo_kmap(ring->ring_obj,
726 radeon_bo_unreserve(ring->ring_obj);
728 dev_err(rdev->dev, "(%d) ring map failed\n", r);
729 radeon_bo_unref(&ring->ring_obj);
733 ring->ptr_mask = (ring->ring_size / 4) - 1;
734 ring->ring_free_dw = ring->ring_size / 4;
735 if (rdev->wb.enabled) {
736 u32 index = RADEON_WB_RING0_NEXT_RPTR + (ring->idx * 4);
737 ring->next_rptr_gpu_addr = rdev->wb.gpu_addr + index;
738 ring->next_rptr_cpu_addr = &rdev->wb.wb[index/4];
741 if (radeon_debugfs_ring_init(rdev, ring)) {
742 DRM_ERROR("Failed to register debugfs file for rings !\n");
744 #endif /* FREEBSD_WIP */
745 radeon_ring_lockup_update(ring);
750 * radeon_ring_fini - tear down the driver ring struct.
752 * @rdev: radeon_device pointer
753 * @ring: radeon_ring structure holding ring information
755 * Tear down the driver information for the selected ring (all asics).
757 void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *ring)
760 struct radeon_bo *ring_obj;
762 sx_xlock(&rdev->ring_lock);
763 ring_obj = ring->ring_obj;
766 ring->ring_obj = NULL;
767 sx_xunlock(&rdev->ring_lock);
770 r = radeon_bo_reserve(ring_obj, false);
771 if (likely(r == 0)) {
772 radeon_bo_kunmap(ring_obj);
773 radeon_bo_unpin(ring_obj);
774 radeon_bo_unreserve(ring_obj);
776 radeon_bo_unref(&ring_obj);
783 #if defined(CONFIG_DEBUG_FS)
785 static int radeon_debugfs_ring_info(struct seq_file *m, void *data)
787 struct drm_info_node *node = (struct drm_info_node *) m->private;
788 struct drm_device *dev = node->minor->dev;
789 struct radeon_device *rdev = dev->dev_private;
790 int ridx = *(int*)node->info_ent->data;
791 struct radeon_ring *ring = &rdev->ring[ridx];
792 unsigned count, i, j;
795 radeon_ring_free_size(rdev, ring);
796 count = (ring->ring_size / 4) - ring->ring_free_dw;
797 tmp = RREG32(ring->wptr_reg) >> ring->ptr_reg_shift;
798 seq_printf(m, "wptr(0x%04x): 0x%08x [%5d]\n", ring->wptr_reg, tmp, tmp);
799 tmp = RREG32(ring->rptr_reg) >> ring->ptr_reg_shift;
800 seq_printf(m, "rptr(0x%04x): 0x%08x [%5d]\n", ring->rptr_reg, tmp, tmp);
801 if (ring->rptr_save_reg) {
802 seq_printf(m, "rptr next(0x%04x): 0x%08x\n", ring->rptr_save_reg,
803 RREG32(ring->rptr_save_reg));
805 seq_printf(m, "driver's copy of the wptr: 0x%08x [%5d]\n", ring->wptr, ring->wptr);
806 seq_printf(m, "driver's copy of the rptr: 0x%08x [%5d]\n", ring->rptr, ring->rptr);
807 seq_printf(m, "last semaphore signal addr : 0x%016llx\n", ring->last_semaphore_signal_addr);
808 seq_printf(m, "last semaphore wait addr : 0x%016llx\n", ring->last_semaphore_wait_addr);
809 seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
810 seq_printf(m, "%u dwords in ring\n", count);
811 /* print 8 dw before current rptr as often it's the last executed
812 * packet that is the root issue
814 i = (ring->rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
815 for (j = 0; j <= (count + 32); j++) {
816 seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
817 i = (i + 1) & ring->ptr_mask;
822 static int radeon_ring_type_gfx_index = RADEON_RING_TYPE_GFX_INDEX;
823 static int cayman_ring_type_cp1_index = CAYMAN_RING_TYPE_CP1_INDEX;
824 static int cayman_ring_type_cp2_index = CAYMAN_RING_TYPE_CP2_INDEX;
825 static int radeon_ring_type_dma1_index = R600_RING_TYPE_DMA_INDEX;
826 static int radeon_ring_type_dma2_index = CAYMAN_RING_TYPE_DMA1_INDEX;
828 static struct drm_info_list radeon_debugfs_ring_info_list[] = {
829 {"radeon_ring_gfx", radeon_debugfs_ring_info, 0, &radeon_ring_type_gfx_index},
830 {"radeon_ring_cp1", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp1_index},
831 {"radeon_ring_cp2", radeon_debugfs_ring_info, 0, &cayman_ring_type_cp2_index},
832 {"radeon_ring_dma1", radeon_debugfs_ring_info, 0, &radeon_ring_type_dma1_index},
833 {"radeon_ring_dma2", radeon_debugfs_ring_info, 0, &radeon_ring_type_dma2_index},
836 static int radeon_debugfs_sa_info(struct seq_file *m, void *data)
838 struct drm_info_node *node = (struct drm_info_node *) m->private;
839 struct drm_device *dev = node->minor->dev;
840 struct radeon_device *rdev = dev->dev_private;
842 radeon_sa_bo_dump_debug_info(&rdev->ring_tmp_bo, m);
848 static struct drm_info_list radeon_debugfs_sa_list[] = {
849 {"radeon_sa_info", &radeon_debugfs_sa_info, 0, NULL},
855 static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring)
857 #if defined(CONFIG_DEBUG_FS)
859 for (i = 0; i < ARRAY_SIZE(radeon_debugfs_ring_info_list); ++i) {
860 struct drm_info_list *info = &radeon_debugfs_ring_info_list[i];
861 int ridx = *(int*)radeon_debugfs_ring_info_list[i].data;
864 if (&rdev->ring[ridx] != ring)
867 r = radeon_debugfs_add_files(rdev, info, 1);
875 static int radeon_debugfs_sa_init(struct radeon_device *rdev)
877 #if defined(CONFIG_DEBUG_FS)
878 return radeon_debugfs_add_files(rdev, radeon_debugfs_sa_list, 1);
883 #endif /* FREEBSD_WIP */