Skip to contentSkip to conversation

drm/amdgpu/vcn: add session ctx buffer and flag

PATCH In review [email protected] 2 participants 3 messages Feb 22, 2025 – Feb 24, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu/vcn: add session ctx buffer and flag

From: Boyuan Zhang <[email protected]>

Define session context buffer addresses and corresponding flag

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +5 -1
index c92f683ee595..44f259b2a320 100644
@@ -227,6 +227,7 @@
 
 #define AMDGPU_VCN_IB_FLAG_DECODE_BUFFER	0x00000001
 #define AMDGPU_VCN_CMD_FLAG_MSG_BUFFER		0x00000001
+#define AMDGPU_VCN_CMD_FLAG_SESSION_CONTEXT_BUFFER 0x00100000
 
 #define VCN_CODEC_DISABLE_MASK_AV1  (1 << 0)
 #define VCN_CODEC_DISABLE_MASK_VP9  (1 << 1)
@@ -465,7 +466,10 @@ struct amdgpu_vcn_decode_buffer {
 	uint32_t valid_buf_flag;
 	uint32_t msg_buffer_address_hi;
 	uint32_t msg_buffer_address_lo;
-	uint32_t pad[30];
+	uint32_t pad1[4];
+	uint32_t session_ctx_buffer_address_hi;
+	uint32_t session_ctx_buffer_address_lo;
+	uint32_t pad2[24];
 };
 
 struct amdgpu_vcn_rb_metadata {
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 drm/amdgpu/vcn: send session ctx along with msg buffer

From: Boyuan Zhang <[email protected]>

Session context buffer is required to be sent along with message buffer

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 43 ++++++++++++++++++-------
 1 file changed, 31 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +31 -12
index 83faf6e6788a..8d2cce3ea7af 100644
@@ -602,18 +602,29 @@ 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 amdgpu_ib *ib)
+		struct amdgpu_ib *ib, struct amdgpu_ib *ctx)
 {
 	struct amdgpu_device *adev = ring->adev;
 	uint32_t *msg;
 	int r, i;
 
-	memset(ib, 0, sizeof(*ib));
-	r = amdgpu_ib_get(adev, NULL, AMDGPU_GPU_PAGE_SIZE * 2,
-			AMDGPU_IB_POOL_DIRECT,
-			ib);
-	if (r)
-		return r;
+	if (ctx) {
+		memset(ctx, 0, sizeof(*ctx));
+		r = amdgpu_ib_get(adev, NULL, AMDGPU_GPU_PAGE_SIZE * 32,
+				AMDGPU_IB_POOL_DIRECT,
+				ctx);
+		if (r)
+			return r;
+	}
+
+	if (ib) {
+		memset(ib, 0, sizeof(*ib));
+		r = amdgpu_ib_get(adev, NULL, AMDGPU_GPU_PAGE_SIZE * 2,
+				AMDGPU_IB_POOL_DIRECT,
+				ib);
+		if (r)
+			return r;
+	}
 
 	msg = (uint32_t *)AMDGPU_GPU_PAGE_ALIGN((unsigned long)ib->ptr);
 	msg[0] = cpu_to_le32(0x00000028);
@@ -669,7 +680,7 @@ int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 	struct amdgpu_ib ib;
 	long r;
 
-	r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib);
+	r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib, NULL);
 	if (r)
 		goto error;
 
@@ -727,6 +738,7 @@ static void amdgpu_vcn_unified_ring_ib_checksum(uint32_t **ib_checksum,
 
 static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 				      struct amdgpu_ib *ib_msg,
+				      struct amdgpu_ib *ib_ctx,
 				      struct dma_fence **fence)
 {
 	struct amdgpu_vcn_decode_buffer *decode_buffer = NULL;
@@ -735,6 +747,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 	struct dma_fence *f = NULL;
 	struct amdgpu_job *job;
 	struct amdgpu_ib *ib;
+	uint64_t addr_ctx = AMDGPU_GPU_PAGE_ALIGN(ib_ctx->gpu_addr);
 	uint64_t addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr);
 	uint32_t *ib_checksum;
 	uint32_t ib_pack_in_dw;
@@ -765,6 +778,10 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 	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_SESSION_CONTEXT_BUFFER);
+	decode_buffer->session_ctx_buffer_address_hi = cpu_to_le32(addr_ctx >> 32);
+	decode_buffer->session_ctx_buffer_address_lo = cpu_to_le32(addr_ctx);
+
 	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);
@@ -780,6 +797,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 		goto err_free;
 
 	amdgpu_ib_free(ib_msg, f);
+	amdgpu_ib_free(ib_ctx, f);
 
 	if (fence)
 		*fence = dma_fence_get(f);
@@ -791,27 +809,28 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
 	amdgpu_job_free(job);
 err:
 	amdgpu_ib_free(ib_msg, f);
+	amdgpu_ib_free(ib_ctx, f);
 	return r;
 }
 
 int amdgpu_vcn_dec_sw_ring_test_ib(struct amdgpu_ring *ring, long timeout)
 {
 	struct dma_fence *fence = NULL;
-	struct amdgpu_ib ib;
+	struct amdgpu_ib ib, ctx;
 	long r;
 
-	r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib);
+	r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib, &ctx);
 	if (r)
 		goto error;
 
-	r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, NULL);
+	r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &ctx, NULL);
 	if (r)
 		goto error;
 	r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &ib);
 	if (r)
 		goto error;
 
-	r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &fence);
+	r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &ctx, &fence);
 	if (r)
 		goto error;
 
Signature · 1 line
2.34.1
Reviewed-by Tested-by Yinjie Yao on v1 2/2
#2 lore raw

RE: [PATCH 2/2] drm/amdgpu/vcn: send session ctx along with msg buffer

[AMD Official Use Only - AMD Internal Distribution Only]

This series is

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of [email protected]
Sent: Friday, February 21, 2025 9:06 PM
To: [email protected]
Cc: Zhang, Boyuan <[email protected]>; Yao, Yinjie <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu/vcn: send session ctx along with msg buffer

From: Boyuan Zhang <[email protected]>

Session context buffer is required to be sent along with message buffer

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 43 ++++++++++++++++++-------
 1 file changed, 31 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +20 -8
index 83faf6e6788a..8d2cce3ea7af 100644
@@ -602,18 +602,29 @@ 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 amdgpu_ib *ib)
+               struct amdgpu_ib *ib, struct amdgpu_ib *ctx)
 {
        struct amdgpu_device *adev = ring->adev;
        uint32_t *msg;
        int r, i;
 
-       memset(ib, 0, sizeof(*ib));
-       r = amdgpu_ib_get(adev, NULL, AMDGPU_GPU_PAGE_SIZE * 2,
-                       AMDGPU_IB_POOL_DIRECT,
-                       ib);
-       if (r)
-               return r;
+       if (ctx) {
+               memset(ctx, 0, sizeof(*ctx));
+               r = amdgpu_ib_get(adev, NULL, AMDGPU_GPU_PAGE_SIZE * 32,
+                               AMDGPU_IB_POOL_DIRECT,
+                               ctx);
+               if (r)
+                       return r;
+       }
+
+       if (ib) {
+               memset(ib, 0, sizeof(*ib));
+               r = amdgpu_ib_get(adev, NULL, AMDGPU_GPU_PAGE_SIZE * 2,
+                               AMDGPU_IB_POOL_DIRECT,
+                               ib);
+               if (r)
+                       return r;
+       }
 
        msg = (uint32_t *)AMDGPU_GPU_PAGE_ALIGN((unsigned long)ib->ptr);
        msg[0] = cpu_to_le32(0x00000028);
@@ -669,7 +680,7 @@ int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout)
        struct amdgpu_ib ib;
        long r;
 
-       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib);
+       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib, NULL);
        if (r)
                goto error;
 
@@ -727,6 +738,7 @@ static void amdgpu_vcn_unified_ring_ib_checksum(uint32_t **ib_checksum,
 
 static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
                                      struct amdgpu_ib *ib_msg,
+                                     struct amdgpu_ib *ib_ctx,
                                      struct dma_fence **fence)
 {
        struct amdgpu_vcn_decode_buffer *decode_buffer = NULL; @@ -735,6 +747,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
        struct dma_fence *f = NULL;
        struct amdgpu_job *job;
        struct amdgpu_ib *ib;
+       uint64_t addr_ctx = AMDGPU_GPU_PAGE_ALIGN(ib_ctx->gpu_addr);
        uint64_t addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg->gpu_addr);
        uint32_t *ib_checksum;
        uint32_t ib_pack_in_dw;
@@ -765,6 +778,10 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
        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_SESSION_CONTEXT_BUFFER);
+       decode_buffer->session_ctx_buffer_address_hi = cpu_to_le32(addr_ctx >> 32);
+       decode_buffer->session_ctx_buffer_address_lo = cpu_to_le32(addr_ctx);
+
        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); @@ -780,6 +797,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
                goto err_free;

        amdgpu_ib_free(ib_msg, f);

+ amdgpu_ib_free(ib_ctx, f);

        if (fence)
                *fence = dma_fence_get(f);
@@ -791,27 +809,28 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,
        amdgpu_job_free(job);
 err:
        amdgpu_ib_free(ib_msg, f);
+       amdgpu_ib_free(ib_ctx, f);
        return r;

}

 int amdgpu_vcn_dec_sw_ring_test_ib(struct amdgpu_ring *ring, long timeout)  {
        struct dma_fence *fence = NULL;
-       struct amdgpu_ib ib;
+       struct amdgpu_ib ib, ctx;
        long r;

- r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib);

+       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib, &ctx);
        if (r)
                goto error;

- r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, NULL);

+       r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &ctx, NULL);
        if (r)
                goto error;
        r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &ib);
        if (r)
                goto error;

- r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &fence);

+       r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &ctx, &fence);
        if (r)
                goto error;

--
2.34.1