drm/amdgpu: add vcn jpeg ib test
authorBoyuan Zhang <boyuan.zhang@amd.com>
Wed, 30 May 2018 19:56:43 +0000 (15:56 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 15 Jun 2018 17:20:38 +0000 (12:20 -0500)
Add an ib test for vcn jpeg.

Signed-off-by: Boyuan Zhang <boyuan.zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c

index 0b97a72cc2021018d23e8ffcbab915d0675d49a6..3f2a5e73e69ff54bc5f238441c96461856d46a27 100644 (file)
@@ -618,3 +618,89 @@ int amdgpu_vcn_jpeg_ring_test_ring(struct amdgpu_ring *ring)
 
        return r;
 }
+
+static int amdgpu_vcn_jpeg_set_reg(struct amdgpu_ring *ring, uint32_t handle,
+               struct dma_fence **fence)
+{
+       struct amdgpu_device *adev = ring->adev;
+       struct amdgpu_job *job;
+       struct amdgpu_ib *ib;
+       struct dma_fence *f = NULL;
+       const unsigned ib_size_dw = 16;
+       int i, r;
+
+       r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4, &job);
+       if (r)
+               return r;
+
+       ib = &job->ibs[0];
+
+       ib->ptr[0] = PACKETJ(SOC15_REG_OFFSET(UVD, 0, mmUVD_JPEG_PITCH), 0, 0, PACKETJ_TYPE0);
+       ib->ptr[1] = 0xDEADBEEF;
+       for (i = 2; i < 16; i += 2) {
+               ib->ptr[i] = PACKETJ(0, 0, 0, PACKETJ_TYPE6);
+               ib->ptr[i+1] = 0;
+       }
+       ib->length_dw = 16;
+
+       r = amdgpu_ib_schedule(ring, 1, ib, NULL, &f);
+       job->fence = dma_fence_get(f);
+       if (r)
+               goto err;
+
+       amdgpu_job_free(job);
+       if (fence)
+               *fence = dma_fence_get(f);
+       dma_fence_put(f);
+
+       return 0;
+
+err:
+       amdgpu_job_free(job);
+       return r;
+}
+
+int amdgpu_vcn_jpeg_ring_test_ib(struct amdgpu_ring *ring, long timeout)
+{
+       struct amdgpu_device *adev = ring->adev;
+       uint32_t tmp = 0;
+       unsigned i;
+       struct dma_fence *fence = NULL;
+       long r = 0;
+
+       r = amdgpu_vcn_jpeg_set_reg(ring, 1, &fence);
+       if (r) {
+               DRM_ERROR("amdgpu: failed to set jpeg register (%ld).\n", r);
+               goto error;
+       }
+
+       r = dma_fence_wait_timeout(fence, false, timeout);
+       if (r == 0) {
+               DRM_ERROR("amdgpu: IB test timed out.\n");
+               r = -ETIMEDOUT;
+               goto error;
+       } else if (r < 0) {
+               DRM_ERROR("amdgpu: fence wait failed (%ld).\n", r);
+               goto error;
+       } else
+               r = 0;
+
+       for (i = 0; i < adev->usec_timeout; i++) {
+               tmp = RREG32(SOC15_REG_OFFSET(UVD, 0, mmUVD_JPEG_PITCH));
+               if (tmp == 0xDEADBEEF)
+                       break;
+               DRM_UDELAY(1);
+       }
+
+       if (i < adev->usec_timeout)
+               DRM_DEBUG("ib test on ring %d succeeded\n", ring->idx);
+       else {
+               DRM_ERROR("ib test failed (0x%08X)\n", tmp);
+               r = -EINVAL;
+       }
+
+       dma_fence_put(fence);
+
+error:
+       return r;
+}
index 0447faefb95abf70f73029933af9543738c56dc6..0b0b8638d73fba480c6431995862b63e22065f26 100644 (file)
@@ -85,5 +85,6 @@ int amdgpu_vcn_enc_ring_test_ring(struct amdgpu_ring *ring);
 int amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout);
 
 int amdgpu_vcn_jpeg_ring_test_ring(struct amdgpu_ring *ring);
+int amdgpu_vcn_jpeg_ring_test_ib(struct amdgpu_ring *ring, long timeout);
 
 #endif
index 5fc58de0c4026a319e4166342e69ad32b7b35b77..b82c92084b6f413731d73e230f84b97d31c5b3cc 100644 (file)
@@ -1713,7 +1713,7 @@ static const struct amdgpu_ring_funcs vcn_v1_0_jpeg_ring_vm_funcs = {
        .emit_fence = vcn_v1_0_jpeg_ring_emit_fence,
        .emit_vm_flush = vcn_v1_0_jpeg_ring_emit_vm_flush,
        .test_ring = amdgpu_vcn_jpeg_ring_test_ring,
-       //.test_ib
+       .test_ib = amdgpu_vcn_jpeg_ring_test_ib,
        .insert_nop = vcn_v1_0_jpeg_ring_nop,
        .insert_start = vcn_v1_0_jpeg_ring_insert_start,
        .insert_end = vcn_v1_0_jpeg_ring_insert_end,