Lines Matching refs:ring

44  * command ring and the hw will fetch the commands from the IB
47 * put in IBs for execution by the requested ring.
56 * @ring: ring index the IB is associated with
64 int radeon_ib_get(struct radeon_device *rdev, int ring,
81 ib->ring = ring;
116 * radeon_ib_schedule - schedule an IB (Indirect Buffer) on the ring
122 * Schedule an IB on the associated ring (all asics).
125 * On SI, there are two parallel engines fed from the primary ring,
132 * a CONST_IB), it will be put on the ring prior to the DE IB. Prior
138 struct radeon_ring *ring = &rdev->ring[ib->ring];
142 if (!ib->length_dw || !ring->ready) {
149 r = radeon_ring_lock(rdev, ring, 64 + RADEON_NUM_RINGS * 8);
156 if (radeon_fence_need_sync(fence, ib->ring)) {
159 fence->ring, ib->ring);
160 radeon_fence_note_sync(fence, ib->ring);
170 radeon_ring_vm_flush(rdev, ib->ring, ib->vm);
173 radeon_ring_ib_execute(rdev, const_ib->ring, const_ib);
176 radeon_ring_ib_execute(rdev, ib->ring, ib);
177 r = radeon_fence_emit(rdev, &ib->fence, ib->ring);
180 radeon_ring_unlock_undo(rdev, ring);
190 radeon_ring_unlock_commit(rdev, ring);
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
264 struct radeon_ring *ring = &rdev->ring[i];
266 if (!ring->ready)
269 r = radeon_ib_test(rdev, i, ring);
271 ring->ready = false;
275 DRM_ERROR("radeon: failed testing IB on GFX ring (%d).\n", r);
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
297 * pointers are equal, the ring is idle. When the host
298 * writes commands to the ring buffer, it increments the
302 static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring);
306 * radeon_ring_write - write a value to the ring
308 * @ring: radeon_ring structure holding ring information
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;
322 ring->count_dw--;
323 ring->ring_free_dw--;
327 * radeon_ring_supports_scratch_reg - check if the ring supports
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.
337 struct radeon_ring *ring)
339 switch (ring->idx) {
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)
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;
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
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).
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))
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
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
420 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
425 r = radeon_ring_alloc(rdev, ring, ndw);
435 * commands on the ring buffer
438 * @ring: radeon_ring structure holding ring information
441 * execute new commands on the ring buffer (all asics).
443 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring)
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);
456 * commands on the ring buffer and unlock it
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);
472 * @ring: radeon_ring structure holding ring information
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);
495 * radeon_ring_force_activity - add some nop packets to the ring
498 * @ring: radeon_ring structure holding ring information
500 * Add some nop packets to the ring to force activity (all asics).
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);
520 * @ring: radeon_ring structure holding ring information
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
533 * @ring: radeon_ring structure holding ring information
546 * Caller should write to the ring to force CP to do something so we don't get
550 bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
556 if (!time_after(cjiffies, ring->last_activity)) {
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) {
565 radeon_ring_lockup_update(ring);
568 elapsed = jiffies_to_msecs(cjiffies - ring->last_activity);
578 * radeon_ring_backup - Back up the content of a ring
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,
590 /* just in case lock the ring */
594 if (ring->ring_obj == NULL) {
600 if (!radeon_fence_count_emitted(rdev, ring->idx)) {
605 /* calculate the number of dw on the ring */
606 if (ring->rptr_save_reg)
607 ptr = RREG32(ring->rptr_save_reg);
609 ptr = le32_to_cpu(*ring->next_rptr_cpu_addr);
616 size = ring->wptr + (ring->ring_size / 4);
618 size &= ring->ptr_mask;
624 /* and then save the content of the ring */
631 (*data)[i] = ring->ring[ptr++];
632 ptr &= ring->ptr_mask;
640 * radeon_ring_restore - append saved commands to the ring again
643 * @ring: ring to append commands to
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,
657 /* restore the saved ring content */
658 r = radeon_ring_lock(rdev, ring, size);
663 radeon_ring_write(ring, data[i]);
666 radeon_ring_unlock_commit(rdev, ring);
672 * radeon_ring_init - init driver ring struct.
675 * @ring: radeon_ring structure holding ring information
676 * @ring_size: size of the ring
682 * @nop: nop packet for this ring
684 * Initialize the driver information for the selected ring (all asics).
687 int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size,
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;
700 ring->nop = nop;
701 /* Allocate ring buffer */
702 if (ring->ring_obj == NULL) {
703 r = radeon_bo_create(rdev, ring->ring_size, PAGE_SIZE, true,
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);
712 radeon_bo_unref(&ring->ring_obj);
715 r = radeon_bo_pin(ring->ring_obj, RADEON_GEM_DOMAIN_GTT,
716 &ring->gpu_addr);
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;
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)) {
745 radeon_ring_lockup_update(ring);
750 * radeon_ring_fini - tear down the driver ring struct.
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)
763 ring_obj = ring->ring_obj;
764 ring->ready = false;
765 ring->ring = NULL;
766 ring->ring_obj = NULL;
791 struct radeon_ring *ring = &rdev->ring[ridx];
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);
814 i = (ring->rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
816 seq_printf(m, "r[%5d]=0x%08x\n", i, ring->ring[i]);
817 i = (i + 1) & ring->ptr_mask;
855 static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring)
864 if (&rdev->ring[ridx] != ring)