<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only - General]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
</div>
This<span style="color:#c0c0c0"> </span>patch<span style="color:#c0c0c0"> </span>
is<span style="color:#c0c0c0"> </span>Reviewed-by:<span style="color:#c0c0c0"> </span>
James<span style="color:#c0c0c0"> </span>Zhu<span style="color:#c0c0c0"> </span><James.Zhu@amd.com>
<div>
<div id="Signature">
<div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p><br>
</p>
</div>
</div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Sonny Jiang <sonny.jiang@amd.com><br>
<b>Sent:</b> Wednesday, July 13, 2022 11:59 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Jiang, Sonny <Sonny.Jiang@amd.com><br>
<b>Subject:</b> [PATCH v2] drm/amdgpu: limiting AV1 to first instance on VCN4 decode</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">AV1 is only supported on first instance.<br>
<br>
Signed-off-by: Sonny Jiang <sonny.jiang@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 131 ++++++++++++++++++++++++++<br>
1 file changed, 131 insertions(+)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c<br>
index 84ac2401895a..a91ffbf902d4 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c<br>
@@ -25,6 +25,7 @@<br>
#include "amdgpu.h"<br>
#include "amdgpu_vcn.h"<br>
#include "amdgpu_pm.h"<br>
+#include "amdgpu_cs.h"<br>
#include "soc15.h"<br>
#include "soc15d.h"<br>
#include "soc15_hw_ip.h"<br>
@@ -44,6 +45,9 @@<br>
#define VCN_VID_SOC_ADDRESS_2_0 0x1fb00<br>
#define VCN1_VID_SOC_ADDRESS_3_0 0x48300<br>
<br>
+#define RDECODE_MSG_CREATE 0x00000000<br>
+#define RDECODE_MESSAGE_CREATE 0x00000001<br>
+<br>
static int amdgpu_ih_clientid_vcns[] = {<br>
SOC15_IH_CLIENTID_VCN,<br>
SOC15_IH_CLIENTID_VCN1<br>
@@ -1323,6 +1327,132 @@ static void vcn_v4_0_unified_ring_set_wptr(struct amdgpu_ring *ring)<br>
}<br>
}<br>
<br>
+static int vcn_v4_0_limit_sched(struct amdgpu_cs_parser *p)<br>
+{<br>
+ struct drm_gpu_scheduler **scheds;<br>
+<br>
+ /* The create msg must be in the first IB submitted */<br>
+ if (atomic_read(&p->entity->fence_seq))<br>
+ return -EINVAL;<br>
+<br>
+ scheds = p->adev->gpu_sched[AMDGPU_HW_IP_VCN_ENC]<br>
+ [AMDGPU_RING_PRIO_0].sched;<br>
+ drm_sched_entity_modify_sched(p->entity, scheds, 1);<br>
+ return 0;<br>
+}<br>
+<br>
+static int vcn_v4_0_dec_msg(struct amdgpu_cs_parser *p, uint64_t addr)<br>
+{<br>
+ struct ttm_operation_ctx ctx = { false, false };<br>
+ struct amdgpu_bo_va_mapping *map;<br>
+ uint32_t *msg, num_buffers;<br>
+ struct amdgpu_bo *bo;<br>
+ uint64_t start, end;<br>
+ unsigned int i;<br>
+ void *ptr;<br>
+ int r;<br>
+<br>
+ addr &= AMDGPU_GMC_HOLE_MASK;<br>
+ r = amdgpu_cs_find_mapping(p, addr, &bo, &map);<br>
+ if (r) {<br>
+ DRM_ERROR("Can't find BO for addr 0x%08llx\n", addr);<br>
+ return r;<br>
+ }<br>
+<br>
+ start = map->start * AMDGPU_GPU_PAGE_SIZE;<br>
+ end = (map->last + 1) * AMDGPU_GPU_PAGE_SIZE;<br>
+ if (addr & 0x7) {<br>
+ DRM_ERROR("VCN messages must be 8 byte aligned!\n");<br>
+ return -EINVAL;<br>
+ }<br>
+<br>
+ bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;<br>
+ amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);<br>
+ r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);<br>
+ if (r) {<br>
+ DRM_ERROR("Failed validating the VCN message BO (%d)!\n", r);<br>
+ return r;<br>
+ }<br>
+<br>
+ r = amdgpu_bo_kmap(bo, &ptr);<br>
+ if (r) {<br>
+ DRM_ERROR("Failed mapping the VCN message (%d)!\n", r);<br>
+ return r;<br>
+ }<br>
+<br>
+ msg = ptr + addr - start;<br>
+<br>
+ /* Check length */<br>
+ if (msg[1] > end - addr) {<br>
+ r = -EINVAL;<br>
+ goto out;<br>
+ }<br>
+<br>
+ if (msg[3] != RDECODE_MSG_CREATE)<br>
+ goto out;<br>
+<br>
+ num_buffers = msg[2];<br>
+ for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) {<br>
+ uint32_t offset, size, *create;<br>
+<br>
+ if (msg[0] != RDECODE_MESSAGE_CREATE)<br>
+ continue;<br>
+<br>
+ offset = msg[1];<br>
+ size = msg[2];<br>
+<br>
+ if (offset + size > end) {<br>
+ r = -EINVAL;<br>
+ goto out;<br>
+ }<br>
+<br>
+ create = ptr + addr + offset - start;<br>
+<br>
+ /* H246, HEVC and VP9 can run on any instance */<br>
+ if (create[0] == 0x7 || create[0] == 0x10 || create[0] == 0x11)<br>
+ continue;<br>
+<br>
+ r = vcn_v4_0_limit_sched(p);<br>
+ if (r)<br>
+ goto out;<br>
+ }<br>
+<br>
+out:<br>
+ amdgpu_bo_kunmap(bo);<br>
+ return r;<br>
+}<br>
+<br>
+#define RADEON_VCN_ENGINE_TYPE_DECODE (0x00000003)<br>
+<br>
+static int vcn_v4_0_ring_patch_cs_in_place(struct amdgpu_cs_parser *p,<br>
+ struct amdgpu_job *job,<br>
+ struct amdgpu_ib *ib)<br>
+{<br>
+ struct amdgpu_ring *ring = to_amdgpu_ring(p->entity->rq->sched);<br>
+ struct amdgpu_vcn_decode_buffer *decode_buffer = NULL;<br>
+ uint32_t val;<br>
+ int r = 0;<br>
+<br>
+ /* The first instance can decode anything */<br>
+ if (!ring->me)<br>
+ return r;<br>
+<br>
+ /* unified queue ib header has 8 double words. */<br>
+ if (ib->length_dw < 8)<br>
+ return r;<br>
+<br>
+ val = amdgpu_ib_get_value(ib, 6); //RADEON_VCN_ENGINE_TYPE<br>
+<br>
+ if (val == RADEON_VCN_ENGINE_TYPE_DECODE) {<br>
+ decode_buffer = (struct amdgpu_vcn_decode_buffer *)&ib->ptr[10];<br>
+<br>
+ if (decode_buffer->valid_buf_flag & 0x1)<br>
+ r = vcn_v4_0_dec_msg(p, ((u64)decode_buffer->msg_buffer_address_hi) << 32 |<br>
+ decode_buffer->msg_buffer_address_lo);<br>
+ }<br>
+ return r;<br>
+}<br>
+<br>
static const struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {<br>
.type = AMDGPU_RING_TYPE_VCN_ENC,<br>
.align_mask = 0x3f,<br>
@@ -1331,6 +1461,7 @@ static const struct amdgpu_ring_funcs vcn_v4_0_unified_ring_vm_funcs = {<br>
.get_rptr = vcn_v4_0_unified_ring_get_rptr,<br>
.get_wptr = vcn_v4_0_unified_ring_get_wptr,<br>
.set_wptr = vcn_v4_0_unified_ring_set_wptr,<br>
+ .patch_cs_in_place = vcn_v4_0_ring_patch_cs_in_place,<br>
.emit_frame_size =<br>
SOC15_FLUSH_GPU_TLB_NUM_WREG * 3 +<br>
SOC15_FLUSH_GPU_TLB_NUM_REG_WAIT * 4 +<br>
-- <br>
2.36.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>