Lines Matching refs:ring
38 * Most engines on the GPU are fed via ring buffers. Ring
44 * pointers are equal, the ring is idle. When the host
45 * writes commands to the ring buffer, it increments the
49 static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring);
52 * radeon_ring_supports_scratch_reg - check if the ring supports
56 * @ring: radeon_ring structure holding ring information
58 * Check if a specific ring supports writing to scratch registers (all asics).
59 * Returns true if the ring supports writing to scratch regs, false if not.
62 struct radeon_ring *ring)
64 switch (ring->idx) {
78 * @ring: radeon_ring structure holding ring information
80 * Update the free dw slots in the ring buffer (all asics).
82 void radeon_ring_free_size(struct radeon_device *rdev, struct radeon_ring *ring)
84 uint32_t rptr = radeon_ring_get_rptr(rdev, ring);
87 ring->ring_free_dw = rptr + (ring->ring_size / 4);
88 ring->ring_free_dw -= ring->wptr;
89 ring->ring_free_dw &= ring->ptr_mask;
90 if (!ring->ring_free_dw) {
91 /* this is an empty ring */
92 ring->ring_free_dw = ring->ring_size / 4;
94 radeon_ring_lockup_update(rdev, ring);
99 * radeon_ring_alloc - allocate space on the ring buffer
102 * @ring: radeon_ring structure holding ring information
103 * @ndw: number of dwords to allocate in the ring buffer
105 * Allocate @ndw dwords in the ring buffer (all asics).
108 int radeon_ring_alloc(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
112 /* make sure we aren't trying to allocate more space than there is on the ring */
113 if (ndw > (ring->ring_size / 4))
117 radeon_ring_free_size(rdev, ring);
118 ndw = (ndw + ring->align_mask) & ~ring->align_mask;
119 while (ndw > (ring->ring_free_dw - 1)) {
120 radeon_ring_free_size(rdev, ring);
121 if (ndw < ring->ring_free_dw) {
124 r = radeon_fence_wait_next(rdev, ring->idx);
128 ring->count_dw = ndw;
129 ring->wptr_old = ring->wptr;
134 * radeon_ring_lock - lock the ring and allocate space on it
137 * @ring: radeon_ring structure holding ring information
138 * @ndw: number of dwords to allocate in the ring buffer
140 * Lock the ring and allocate @ndw dwords in the ring buffer
144 int radeon_ring_lock(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ndw)
149 r = radeon_ring_alloc(rdev, ring, ndw);
159 * commands on the ring buffer
162 * @ring: radeon_ring structure holding ring information
166 * execute new commands on the ring buffer (all asics).
168 void radeon_ring_commit(struct radeon_device *rdev, struct radeon_ring *ring,
171 /* If we are emitting the HDP flush via the ring buffer, we need to
174 if (hdp_flush && rdev->asic->ring[ring->idx]->hdp_flush)
175 rdev->asic->ring[ring->idx]->hdp_flush(rdev, ring);
177 while (ring->wptr & ring->align_mask) {
178 radeon_ring_write(ring, ring->nop);
186 radeon_ring_set_wptr(rdev, ring);
192 * commands on the ring buffer and unlock it
195 * @ring: radeon_ring structure holding ring information
198 * Call radeon_ring_commit() then unlock the ring (all asics).
200 void radeon_ring_unlock_commit(struct radeon_device *rdev, struct radeon_ring *ring,
203 radeon_ring_commit(rdev, ring, hdp_flush);
210 * @ring: radeon_ring structure holding ring information
214 void radeon_ring_undo(struct radeon_ring *ring)
216 ring->wptr = ring->wptr_old;
220 * radeon_ring_unlock_undo - reset the wptr and unlock the ring
222 * @ring: radeon_ring structure holding ring information
224 * Call radeon_ring_undo() then unlock the ring (all asics).
226 void radeon_ring_unlock_undo(struct radeon_device *rdev, struct radeon_ring *ring)
228 radeon_ring_undo(ring);
235 * @ring: radeon_ring structure holding ring information
240 struct radeon_ring *ring)
242 atomic_set(&ring->last_rptr, radeon_ring_get_rptr(rdev, ring));
243 atomic64_set(&ring->last_activity, jiffies_64);
247 * radeon_ring_test_lockup() - check if ring is lockedup by recording information
249 * @ring: radeon_ring structure holding ring information
252 bool radeon_ring_test_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
254 uint32_t rptr = radeon_ring_get_rptr(rdev, ring);
255 uint64_t last = atomic64_read(&ring->last_activity);
258 if (rptr != atomic_read(&ring->last_rptr)) {
259 /* ring is still working, no lockup */
260 radeon_ring_lockup_update(rdev, ring);
266 dev_err(rdev->dev, "ring %d stalled for more than %llumsec\n",
267 ring->idx, elapsed);
275 * radeon_ring_backup - Back up the content of a ring
278 * @ring: the ring we want to back up
280 * Saves all unprocessed commits from a ring, returns the number of dwords saved.
282 unsigned radeon_ring_backup(struct radeon_device *rdev, struct radeon_ring *ring,
287 /* just in case lock the ring */
291 if (ring->ring_obj == NULL) {
297 if (!radeon_fence_count_emitted(rdev, ring->idx)) {
302 /* calculate the number of dw on the ring */
303 if (ring->rptr_save_reg)
304 ptr = RREG32(ring->rptr_save_reg);
306 ptr = le32_to_cpu(*ring->next_rptr_cpu_addr);
313 size = ring->wptr + (ring->ring_size / 4);
315 size &= ring->ptr_mask;
321 /* and then save the content of the ring */
328 (*data)[i] = ring->ring[ptr++];
329 ptr &= ring->ptr_mask;
337 * radeon_ring_restore - append saved commands to the ring again
340 * @ring: ring to append commands to
344 * Allocates space on the ring and restore the previously saved commands.
346 int radeon_ring_restore(struct radeon_device *rdev, struct radeon_ring *ring,
354 /* restore the saved ring content */
355 r = radeon_ring_lock(rdev, ring, size);
360 radeon_ring_write(ring, data[i]);
363 radeon_ring_unlock_commit(rdev, ring, false);
369 * radeon_ring_init - init driver ring struct.
372 * @ring: radeon_ring structure holding ring information
373 * @ring_size: size of the ring
375 * @nop: nop packet for this ring
377 * Initialize the driver information for the selected ring (all asics).
380 int radeon_ring_init(struct radeon_device *rdev, struct radeon_ring *ring, unsigned ring_size,
385 ring->ring_size = ring_size;
386 ring->rptr_offs = rptr_offs;
387 ring->nop = nop;
388 /* Allocate ring buffer */
389 if (ring->ring_obj == NULL) {
390 r = radeon_bo_create(rdev, ring->ring_size, PAGE_SIZE, true,
392 NULL, &ring->ring_obj);
394 dev_err(rdev->dev, "(%d) ring create failed\n", r);
397 r = radeon_bo_reserve(ring->ring_obj, false);
400 r = radeon_bo_pin(ring->ring_obj, RADEON_GEM_DOMAIN_GTT,
401 &ring->gpu_addr);
403 radeon_bo_unreserve(ring->ring_obj);
404 dev_err(rdev->dev, "(%d) ring pin failed\n", r);
407 r = radeon_bo_kmap(ring->ring_obj,
408 (void **)&ring->ring);
409 radeon_bo_unreserve(ring->ring_obj);
411 dev_err(rdev->dev, "(%d) ring map failed\n", r);
415 ring->ptr_mask = (ring->ring_size / 4) - 1;
416 ring->ring_free_dw = ring->ring_size / 4;
418 u32 index = RADEON_WB_RING0_NEXT_RPTR + (ring->idx * 4);
419 ring->next_rptr_gpu_addr = rdev->wb.gpu_addr + index;
420 ring->next_rptr_cpu_addr = &rdev->wb.wb[index/4];
422 if (radeon_debugfs_ring_init(rdev, ring)) {
425 radeon_ring_lockup_update(rdev, ring);
430 * radeon_ring_fini - tear down the driver ring struct.
433 * @ring: radeon_ring structure holding ring information
435 * Tear down the driver information for the selected ring (all asics).
437 void radeon_ring_fini(struct radeon_device *rdev, struct radeon_ring *ring)
443 ring_obj = ring->ring_obj;
444 ring->ready = false;
445 ring->ring = NULL;
446 ring->ring_obj = NULL;
471 struct radeon_ring *ring = &rdev->ring[ridx];
476 radeon_ring_free_size(rdev, ring);
477 count = (ring->ring_size / 4) - ring->ring_free_dw;
479 wptr = radeon_ring_get_wptr(rdev, ring);
483 rptr = radeon_ring_get_rptr(rdev, ring);
487 if (ring->rptr_save_reg) {
488 rptr_next = RREG32(ring->rptr_save_reg);
490 ring->rptr_save_reg, rptr_next, rptr_next);
495 ring->wptr, ring->wptr);
497 ring->last_semaphore_signal_addr);
499 ring->last_semaphore_wait_addr);
500 seq_printf(m, "%u free dwords in ring\n", ring->ring_free_dw);
501 seq_printf(m, "%u dwords in ring\n", count);
503 if (!ring->ring)
509 i = (rptr + ring->ptr_mask + 1 - 32) & ring->ptr_mask;
511 seq_printf(m, "r[%5d]=0x%08x", i, ring->ring[i]);
517 i = (i + 1) & ring->ptr_mask;
544 static int radeon_debugfs_ring_init(struct radeon_device *rdev, struct radeon_ring *ring)
553 if (&rdev->ring[ridx] != ring)