[PATCH 12/17] drm/amdgpu: add vcn jpeg enc ib test

boyuan.zhang at amd.com boyuan.zhang at amd.com
Thu Jul 4 16:04:24 UTC 2019


From: Boyuan Zhang <boyuan.zhang at amd.com>

Add an IB test for jpeg encode.

Signed-off-by: Boyuan Zhang <boyuan.zhang at amd.com>
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 76 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c   |  2 +-
 3 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index 15687cbb798b..007207a2e798 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
@@ -883,3 +883,79 @@ int amdgpu_vcn_jpeg_enc_ring_test_ring(struct amdgpu_ring *ring)
 
 	return r;
 }
+
+static int amdgpu_vcn_jpeg_enc_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(adev->vcn.internal.jpeg_enc_scratch0, 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_job_submit_direct(job, ring, &f);
+	if (r)
+		goto err;
+
+	if (fence)
+		*fence = dma_fence_get(f);
+	dma_fence_put(f);
+
+	return 0;
+
+err:
+	amdgpu_job_free(job);
+	return r;
+}
+
+int amdgpu_vcn_jpeg_enc_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_enc_set_reg(ring, 1, &fence);
+	if (r)
+		goto error;
+
+	r = dma_fence_wait_timeout(fence, false, timeout);
+	if (r == 0) {
+		r = -ETIMEDOUT;
+		goto error;
+	} else if (r < 0) {
+		goto error;
+	} else {
+		r = 0;
+	}
+
+	for (i = 0; i < adev->usec_timeout; i++) {
+		tmp = RREG32(adev->vcn.external.jpeg_enc_scratch0);
+		if (tmp == 0xDEADBEEF)
+			break;
+		DRM_UDELAY(1);
+	}
+
+	if (i >= adev->usec_timeout)
+		r = -ETIMEDOUT;
+
+	dma_fence_put(fence);
+error:
+	return r;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
index 528d9d3fa91c..8a405bd48e86 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
@@ -113,5 +113,6 @@ int amdgpu_vcn_jpeg_ring_test_ring(struct amdgpu_ring *ring);
 int amdgpu_vcn_jpeg_ring_test_ib(struct amdgpu_ring *ring, long timeout);
 
 int amdgpu_vcn_jpeg_enc_ring_test_ring(struct amdgpu_ring *ring);
+int amdgpu_vcn_jpeg_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout);
 
 #endif
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
index abd708e0e304..b5c8011e7818 100644
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c
@@ -2193,7 +2193,7 @@ static const struct amdgpu_ring_funcs vcn_v2_0_jpeg_enc_ring_vm_funcs = {
 	.emit_fence = vcn_v2_0_jpeg_enc_ring_emit_fence,
 	.emit_vm_flush = vcn_v2_0_jpeg_enc_ring_emit_vm_flush,
 	.test_ring = amdgpu_vcn_jpeg_enc_ring_test_ring,
-	//.test_ib
+	.test_ib = amdgpu_vcn_jpeg_enc_ring_test_ib,
 	.insert_nop = vcn_v2_0_jpeg_enc_ring_nop,
 	.insert_start = vcn_v2_0_jpeg_enc_ring_insert_start,
 	.insert_end = vcn_v2_0_jpeg_enc_ring_insert_end,
-- 
2.17.1



More information about the amd-gfx mailing list