Lines Matching full:ring

40  * Most engines on the GPU are fed via ring buffers.  Ring
46 * pointers are equal, the ring is idle. When the host
47 * writes commands to the ring buffer, it increments the
53 * amdgpu_ring_alloc - allocate space on the ring buffer
56 * @ring: amdgpu_ring structure holding ring information
57 * @ndw: number of dwords to allocate in the ring buffer
59 * Allocate @ndw dwords in the ring buffer (all asics).
62 int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw) in amdgpu_ring_alloc() argument
66 ndw = (ndw + ring->funcs->align_mask) & ~ring->funcs->align_mask; in amdgpu_ring_alloc()
71 if (WARN_ON_ONCE(ndw > ring->max_dw)) in amdgpu_ring_alloc()
74 ring->count_dw = ndw; in amdgpu_ring_alloc()
75 ring->wptr_old = ring->wptr; in amdgpu_ring_alloc()
77 if (ring->funcs->begin_use) in amdgpu_ring_alloc()
78 ring->funcs->begin_use(ring); in amdgpu_ring_alloc()
85 * @ring: amdgpu_ring structure holding ring information
90 void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count) in amdgpu_ring_insert_nop() argument
95 amdgpu_ring_write(ring, ring->funcs->nop); in amdgpu_ring_insert_nop()
100 * @ring: amdgpu_ring structure holding ring information
105 void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib) in amdgpu_ring_generic_pad_ib() argument
107 while (ib->length_dw & ring->funcs->align_mask) in amdgpu_ring_generic_pad_ib()
108 ib->ptr[ib->length_dw++] = ring->funcs->nop; in amdgpu_ring_generic_pad_ib()
113 * commands on the ring buffer
116 * @ring: amdgpu_ring structure holding ring information
119 * execute new commands on the ring buffer (all asics).
121 void amdgpu_ring_commit(struct amdgpu_ring *ring) in amdgpu_ring_commit() argument
126 count = ring->funcs->align_mask + 1 - in amdgpu_ring_commit()
127 (ring->wptr & ring->funcs->align_mask); in amdgpu_ring_commit()
128 count %= ring->funcs->align_mask + 1; in amdgpu_ring_commit()
129 ring->funcs->insert_nop(ring, count); in amdgpu_ring_commit()
132 amdgpu_ring_set_wptr(ring); in amdgpu_ring_commit()
134 if (ring->funcs->end_use) in amdgpu_ring_commit()
135 ring->funcs->end_use(ring); in amdgpu_ring_commit()
141 * @ring: amdgpu_ring structure holding ring information
145 void amdgpu_ring_undo(struct amdgpu_ring *ring) in amdgpu_ring_undo() argument
147 ring->wptr = ring->wptr_old; in amdgpu_ring_undo()
149 if (ring->funcs->end_use) in amdgpu_ring_undo()
150 ring->funcs->end_use(ring); in amdgpu_ring_undo()
154 * amdgpu_ring_init - init driver ring struct.
157 * @ring: amdgpu_ring structure holding ring information
158 * @max_ndw: maximum number of dw for ring alloc
159 * @nop: nop packet for this ring
161 * Initialize the driver information for the selected ring (all asics).
164 int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, in amdgpu_ring_init() argument
177 * KIQ tasks get submitted directly to the ring. in amdgpu_ring_init()
179 if (ring->funcs->type == AMDGPU_RING_TYPE_KIQ) in amdgpu_ring_init()
181 else if (ring == &adev->sdma.instance[0].page) in amdgpu_ring_init()
184 if (ring->adev == NULL) { in amdgpu_ring_init()
188 ring->adev = adev; in amdgpu_ring_init()
189 ring->idx = adev->num_rings++; in amdgpu_ring_init()
190 adev->rings[ring->idx] = ring; in amdgpu_ring_init()
191 r = amdgpu_fence_driver_init_ring(ring, sched_hw_submission); in amdgpu_ring_init()
196 r = amdgpu_device_wb_get(adev, &ring->rptr_offs); in amdgpu_ring_init()
198 dev_err(adev->dev, "(%d) ring rptr_offs wb alloc failed\n", r); in amdgpu_ring_init()
202 r = amdgpu_device_wb_get(adev, &ring->wptr_offs); in amdgpu_ring_init()
204 dev_err(adev->dev, "(%d) ring wptr_offs wb alloc failed\n", r); in amdgpu_ring_init()
208 r = amdgpu_device_wb_get(adev, &ring->fence_offs); in amdgpu_ring_init()
210 dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r); in amdgpu_ring_init()
214 r = amdgpu_device_wb_get(adev, &ring->trail_fence_offs); in amdgpu_ring_init()
217 "(%d) ring trail_fence_offs wb alloc failed\n", r); in amdgpu_ring_init()
220 ring->trail_fence_gpu_addr = in amdgpu_ring_init()
221 adev->wb.gpu_addr + (ring->trail_fence_offs * 4); in amdgpu_ring_init()
222 ring->trail_fence_cpu_addr = &adev->wb.wb[ring->trail_fence_offs]; in amdgpu_ring_init()
224 r = amdgpu_device_wb_get(adev, &ring->cond_exe_offs); in amdgpu_ring_init()
226 dev_err(adev->dev, "(%d) ring cond_exec_polling wb alloc failed\n", r); in amdgpu_ring_init()
229 ring->cond_exe_gpu_addr = adev->wb.gpu_addr + (ring->cond_exe_offs * 4); in amdgpu_ring_init()
230 ring->cond_exe_cpu_addr = &adev->wb.wb[ring->cond_exe_offs]; in amdgpu_ring_init()
232 *ring->cond_exe_cpu_addr = 1; in amdgpu_ring_init()
234 r = amdgpu_fence_driver_start_ring(ring, irq_src, irq_type); in amdgpu_ring_init()
240 ring->ring_size = roundup_pow_of_two(max_dw * 4 * sched_hw_submission); in amdgpu_ring_init()
242 ring->buf_mask = (ring->ring_size / 4) - 1; in amdgpu_ring_init()
243 ring->ptr_mask = ring->funcs->support_64bit_ptrs ? in amdgpu_ring_init()
244 0xffffffffffffffff : ring->buf_mask; in amdgpu_ring_init()
245 /* Allocate ring buffer */ in amdgpu_ring_init()
246 if (ring->ring_obj == NULL) { in amdgpu_ring_init()
247 r = amdgpu_bo_create_kernel(adev, ring->ring_size + ring->funcs->extra_dw, PAGE_SIZE, in amdgpu_ring_init()
249 &ring->ring_obj, in amdgpu_ring_init()
250 &ring->gpu_addr, in amdgpu_ring_init()
251 (void **)&ring->ring); in amdgpu_ring_init()
253 dev_err(adev->dev, "(%d) ring create failed\n", r); in amdgpu_ring_init()
256 amdgpu_ring_clear_ring(ring); in amdgpu_ring_init()
259 ring->max_dw = max_dw; in amdgpu_ring_init()
260 ring->priority = DRM_SCHED_PRIORITY_NORMAL; in amdgpu_ring_init()
261 mutex_init(&ring->priority_mutex); in amdgpu_ring_init()
263 if (!ring->no_scheduler) { in amdgpu_ring_init()
264 hw_ip = ring->funcs->type; in amdgpu_ring_init()
267 &ring->sched; in amdgpu_ring_init()
271 atomic_set(&ring->num_jobs[i], 0); in amdgpu_ring_init()
277 * amdgpu_ring_fini - tear down the driver ring struct.
280 * @ring: amdgpu_ring structure holding ring information
282 * Tear down the driver information for the selected ring (all asics).
284 void amdgpu_ring_fini(struct amdgpu_ring *ring) in amdgpu_ring_fini() argument
287 /* Not to finish a ring which is not initialized */ in amdgpu_ring_fini()
288 if (!(ring->adev) || !(ring->adev->rings[ring->idx])) in amdgpu_ring_fini()
291 ring->sched.ready = false; in amdgpu_ring_fini()
293 amdgpu_device_wb_free(ring->adev, ring->rptr_offs); in amdgpu_ring_fini()
294 amdgpu_device_wb_free(ring->adev, ring->wptr_offs); in amdgpu_ring_fini()
296 amdgpu_device_wb_free(ring->adev, ring->cond_exe_offs); in amdgpu_ring_fini()
297 amdgpu_device_wb_free(ring->adev, ring->fence_offs); in amdgpu_ring_fini()
299 amdgpu_bo_free_kernel(&ring->ring_obj, in amdgpu_ring_fini()
300 &ring->gpu_addr, in amdgpu_ring_fini()
301 (void **)&ring->ring); in amdgpu_ring_fini()
303 dma_fence_put(ring->vmid_wait); in amdgpu_ring_fini()
304 ring->vmid_wait = NULL; in amdgpu_ring_fini()
305 ring->me = 0; in amdgpu_ring_fini()
307 ring->adev->rings[ring->idx] = NULL; in amdgpu_ring_fini()
311 * amdgpu_ring_emit_reg_write_reg_wait_helper - ring helper
322 void amdgpu_ring_emit_reg_write_reg_wait_helper(struct amdgpu_ring *ring, in amdgpu_ring_emit_reg_write_reg_wait_helper() argument
326 amdgpu_ring_emit_wreg(ring, reg0, ref); in amdgpu_ring_emit_reg_write_reg_wait_helper()
327 amdgpu_ring_emit_reg_wait(ring, reg1, mask, mask); in amdgpu_ring_emit_reg_write_reg_wait_helper()
331 * amdgpu_ring_soft_recovery - try to soft recover a ring lockup
333 * @ring: ring to try the recovery on
337 * Tries to get a ring proceeding again when it is stuck.
339 bool amdgpu_ring_soft_recovery(struct amdgpu_ring *ring, unsigned int vmid, in amdgpu_ring_soft_recovery() argument
344 if (amdgpu_sriov_vf(ring->adev) || !ring->funcs->soft_recovery || !fence) in amdgpu_ring_soft_recovery()
347 atomic_inc(&ring->adev->gpu_reset_counter); in amdgpu_ring_soft_recovery()
350 ring->funcs->soft_recovery(ring, vmid); in amdgpu_ring_soft_recovery()
365 * followed by n-words of ring data
370 struct amdgpu_ring *ring = file_inode(f)->i_private; in amdgpu_debugfs_ring_read() local
380 early[0] = amdgpu_ring_get_rptr(ring) & ring->buf_mask; in amdgpu_debugfs_ring_read()
381 early[1] = amdgpu_ring_get_wptr(ring) & ring->buf_mask; in amdgpu_debugfs_ring_read()
382 early[2] = ring->wptr & ring->buf_mask; in amdgpu_debugfs_ring_read()
395 if (*pos >= (ring->ring_size + 12)) in amdgpu_debugfs_ring_read()
398 value = ring->ring[(*pos - 12)/4]; in amdgpu_debugfs_ring_read()
420 struct amdgpu_ring *ring) in amdgpu_debugfs_ring_init() argument
427 sprintf(name, "amdgpu_ring_%s", ring->name); in amdgpu_debugfs_ring_init()
431 ring, &amdgpu_debugfs_ring_fops); in amdgpu_debugfs_ring_init()
435 i_size_write(ent->d_inode, ring->ring_size + 12); in amdgpu_debugfs_ring_init()
436 ring->ent = ent; in amdgpu_debugfs_ring_init()
442 * amdgpu_ring_test_helper - tests ring and set sched readiness status
444 * @ring: ring to try the recovery on
446 * Tests ring and set sched readiness status
450 int amdgpu_ring_test_helper(struct amdgpu_ring *ring) in amdgpu_ring_test_helper() argument
452 struct amdgpu_device *adev = ring->adev; in amdgpu_ring_test_helper()
455 r = amdgpu_ring_test_ring(ring); in amdgpu_ring_test_helper()
457 DRM_DEV_ERROR(adev->dev, "ring %s test failed (%d)\n", in amdgpu_ring_test_helper()
458 ring->name, r); in amdgpu_ring_test_helper()
460 DRM_DEV_DEBUG(adev->dev, "ring test on %s succeeded\n", in amdgpu_ring_test_helper()
461 ring->name); in amdgpu_ring_test_helper()
463 ring->sched.ready = !r; in amdgpu_ring_test_helper()