[PATCH 3/5] drm/amdgpu/vcn: add test for dec vcn software ring
Christian König
ckoenig.leichtzumerken at gmail.com
Mon Nov 16 11:42:23 UTC 2020
Am 11.11.20 um 23:27 schrieb James Zhu:
> Add vcn software ring decode ring test and decode ib test.
>
> Signed-off-by: James Zhu <James.Zhu at amd.com>
> Reviewed-by: Leo Liu <leo.liu at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 138 ++++++++++++++++++++++++++++++--
> 1 file changed, 132 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> index 7e19a66..e3d54fa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
> @@ -456,6 +456,37 @@ int amdgpu_vcn_dec_ring_test_ring(struct amdgpu_ring *ring)
> return r;
> }
>
> +int amdgpu_vcn_dec_sw_ring_test_ring(struct amdgpu_ring *ring)
> +{
> + struct amdgpu_device *adev = ring->adev;
> + uint32_t rptr;
> + unsigned int i;
> + int r;
> +
> + if (amdgpu_sriov_vf(adev))
> + return 0;
> +
> + r = amdgpu_ring_alloc(ring, 16);
> + if (r)
> + return r;
> +
> + rptr = amdgpu_ring_get_rptr(ring);
> +
> + amdgpu_ring_write(ring, VCN_DEC_SW_CMD_END);
> + amdgpu_ring_commit(ring);
> +
> + for (i = 0; i < adev->usec_timeout; i++) {
> + if (amdgpu_ring_get_rptr(ring) != rptr)
> + break;
> + udelay(1);
> + }
> +
> + if (i >= adev->usec_timeout)
> + r = -ETIMEDOUT;
> +
> + return r;
> +}
> +
> static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring,
> struct amdgpu_bo *bo,
> struct dma_fence **fence)
> @@ -510,7 +541,10 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring,
> }
>
> static int amdgpu_vcn_dec_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,
> - struct dma_fence **fence)
> + struct dma_fence **fence,
> + int (*send_msg)(struct amdgpu_ring *,
> + struct amdgpu_bo *,
> + struct dma_fence **))
> {
> struct amdgpu_device *adev = ring->adev;
> struct amdgpu_bo *bo = NULL;
> @@ -540,13 +574,17 @@ static int amdgpu_vcn_dec_get_create_msg(struct amdgpu_ring *ring, uint32_t hand
> for (i = 14; i < 1024; ++i)
> msg[i] = cpu_to_le32(0x0);
>
> - return amdgpu_vcn_dec_send_msg(ring, bo, fence);
> + return send_msg(ring, bo, fence);
> }
>
> static int amdgpu_vcn_dec_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,
> - struct dma_fence **fence)
> + struct dma_fence **fence,
> + int (*send_msg)(struct amdgpu_ring *,
> + struct amdgpu_bo *,
> + struct dma_fence **))
> {
> struct amdgpu_device *adev = ring->adev;
> + struct amdgpu_send_msg *dec;
> struct amdgpu_bo *bo = NULL;
> uint32_t *msg;
> int r, i;
> @@ -566,19 +604,107 @@ static int amdgpu_vcn_dec_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han
> for (i = 6; i < 1024; ++i)
> msg[i] = cpu_to_le32(0x0);
>
> - return amdgpu_vcn_dec_send_msg(ring, bo, fence);
> + return send_msg(ring, bo, fence);
You can avoid the send_msg parameter altogether by just doing this in
the caller of the function.
Christian.
> }
>
> int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout)
> {
> + struct amdgpu_device *adev = ring->adev;
> struct dma_fence *fence;
> long r;
>
> - r = amdgpu_vcn_dec_get_create_msg(ring, 1, NULL);
> + r = amdgpu_vcn_dec_get_create_msg(ring, 1, NULL,
> + amdgpu_vcn_dec_send_msg);
> + if (r)
> + goto error;
> +
> + r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &fence,
> + amdgpu_vcn_dec_send_msg);
> + if (r)
> + goto error;
> +
> + r = dma_fence_wait_timeout(fence, false, timeout);
> + if (r == 0)
> + r = -ETIMEDOUT;
> + else if (r > 0)
> + r = 0;
> +
> + dma_fence_put(fence);
> +error:
> + return r;
> +}
> +
> +static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
> + struct amdgpu_bo *bo,
> + struct dma_fence **fence)
> +{
> + struct amdgpu_vcn_decode_buffer *decode_buffer = NULL;
> + const unsigned int ib_size_dw = 64;
> + struct amdgpu_device *adev = ring->adev;
> + struct dma_fence *f = NULL;
> + struct amdgpu_job *job;
> + struct amdgpu_ib *ib;
> + uint64_t addr;
> + int i, r;
> +
> + r = amdgpu_job_alloc_with_ib(adev, ib_size_dw * 4,
> + AMDGPU_IB_POOL_DIRECT, &job);
> + if (r)
> + goto err;
> +
> + ib = &job->ibs[0];
> + addr = amdgpu_bo_gpu_offset(bo);
> + ib->length_dw = 0;
> +
> + ib->ptr[ib->length_dw++] = sizeof(struct amdgpu_vcn_decode_buffer) + 8;
> + ib->ptr[ib->length_dw++] = cpu_to_le32(AMDGPU_VCN_IB_FLAG_DECODE_BUFFER);
> + decode_buffer = (struct amdgpu_vcn_decode_buffer *)&(ib->ptr[ib->length_dw]);
> + ib->length_dw += sizeof(struct amdgpu_vcn_decode_buffer) / 4;
> + memset(decode_buffer, 0, sizeof(struct amdgpu_vcn_decode_buffer));
> +
> + decode_buffer->valid_buf_flag |= cpu_to_le32(AMDGPU_VCN_CMD_FLAG_MSG_BUFFER);
> + decode_buffer->msg_buffer_address_hi = cpu_to_le32(addr >> 32);
> + decode_buffer->msg_buffer_address_lo = cpu_to_le32(addr);
> +
> + for (i = ib->length_dw; i < ib_size_dw; ++i)
> + ib->ptr[i] = 0x0;
> +
> + r = amdgpu_job_submit_direct(job, ring, &f);
> + if (r)
> + goto err_free;
> +
> + amdgpu_bo_fence(bo, f, false);
> + amdgpu_bo_unreserve(bo);
> + amdgpu_bo_unref(&bo);
> +
> + if (fence)
> + *fence = dma_fence_get(f);
> + dma_fence_put(f);
> +
> + return 0;
> +
> +err_free:
> + amdgpu_job_free(job);
> +
> +err:
> + amdgpu_bo_unreserve(bo);
> + amdgpu_bo_unref(&bo);
> + return r;
> +}
> +
> +int amdgpu_vcn_dec_sw_ring_test_ib(struct amdgpu_ring *ring, long timeout)
> +{
> + struct amdgpu_device *adev = ring->adev;
> + struct dma_fence *fence = NULL;
> + long r;
> +
> + r = amdgpu_vcn_dec_get_create_msg(ring, 1, NULL,
> + amdgpu_vcn_dec_sw_send_msg);
> if (r)
> goto error;
>
> - r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &fence);
> + r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &fence,
> + amdgpu_vcn_dec_sw_send_msg);
> if (r)
> goto error;
>
More information about the amd-gfx
mailing list