<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-CA" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<p style="font-family:Arial;font-size:11pt;color:#0078D7;margin:5pt;" align="Left">
[AMD Official Use Only - Internal Distribution Only]<br>
</p>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Reviewed-by: Leo Liu <leo.liu@amd.com><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> amd-gfx <amd-gfx-bounces@lists.freedesktop.org>
<b>On Behalf Of </b>Jiang, Sonny<br>
<b>Sent:</b> February 18, 2021 9:34 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH] drm/amdgpu/vcn3.0: add wptr/rptr reset/update for share memory<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="margin:5.0pt"><span style="font-family:"Arial",sans-serif;color:#0078D7">[AMD Official Use Only - Internal Distribution Only]<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p style="margin:5.0pt"><span style="font-family:"Arial",sans-serif;color:#0078D7">[AMD Official Use Only - Internal Distribution Only]<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Ping. <o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Jiang, Sonny <<a href="mailto:Sonny.Jiang@amd.com">Sonny.Jiang@amd.com</a>><br>
<b>Sent:</b> Wednesday, February 10, 2021 8:31 PM<br>
<b>To:</b> <a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a> <<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>><br>
<b>Cc:</b> Jiang, Sonny <<a href="mailto:Sonny.Jiang@amd.com">Sonny.Jiang@amd.com</a>><br>
<b>Subject:</b> [PATCH] drm/amdgpu/vcn3.0: add wptr/rptr reset/update for share memory</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Because of dpg, the rptr/wptr need to be saved on fw shared memory,<br>
and restore them back in RBC_RB_RPTR/WPTR in kernel at power up.<br>
<br>
Signed-off-by: Sonny Jiang <<a href="mailto:sonny.jiang@amd.com">sonny.jiang@amd.com</a>><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 12 +++++++++++-<br>
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 24 +++++++++++++++++++++++-<br>
2 files changed, 34 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h<br>
index 13aa417f6be7..a19c0c35e2d8 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h<br>
@@ -155,6 +155,7 @@<br>
} \<br>
} while (0)<br>
<br>
+#define AMDGPU_VCN_FW_SHARED_FLAG_0_RB (1 << 6)<br>
#define AMDGPU_VCN_MULTI_QUEUE_FLAG (1 << 8)<br>
#define AMDGPU_VCN_SW_RING_FLAG (1 << 9)<br>
<br>
@@ -243,6 +244,12 @@ struct amdgpu_vcn {<br>
int inst_idx, struct dpg_pause_state *new_state);<br>
};<br>
<br>
+struct amdgpu_fw_shared_rb_ptrs_struct {<br>
+ /* to WA DPG R/W ptr issues.*/<br>
+ uint32_t rptr;<br>
+ uint32_t wptr;<br>
+};<br>
+<br>
struct amdgpu_fw_shared_multi_queue {<br>
uint8_t decode_queue_mode;<br>
uint8_t encode_generalpurpose_queue_mode;<br>
@@ -258,9 +265,12 @@ struct amdgpu_fw_shared_sw_ring {<br>
<br>
struct amdgpu_fw_shared {<br>
uint32_t present_flag_0;<br>
- uint8_t pad[53];<br>
+ uint8_t pad[44];<br>
+ struct amdgpu_fw_shared_rb_ptrs_struct rb;<br>
+ uint8_t power;<br>
struct amdgpu_fw_shared_multi_queue multi_queue;<br>
struct amdgpu_fw_shared_sw_ring sw_ring;<br>
+ uint8_t padding[13];<br>
} __attribute__((__packed__));<br>
<br>
struct amdgpu_vcn_decode_buffer {<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c<br>
index def583916294..b61d1ba1aa9d 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c<br>
@@ -238,7 +238,8 @@ static int vcn_v3_0_sw_init(void *handle)<br>
<br>
fw_shared = adev->vcn.inst[i].fw_shared_cpu_addr;<br>
fw_shared->present_flag_0 |= cpu_to_le32(AMDGPU_VCN_SW_RING_FLAG) |<br>
- cpu_to_le32(AMDGPU_VCN_MULTI_QUEUE_FLAG);<br>
+ cpu_to_le32(AMDGPU_VCN_MULTI_QUEUE_FLAG) |<br>
+ cpu_to_le32(AMDGPU_VCN_FW_SHARED_FLAG_0_RB);<br>
fw_shared->sw_ring.is_enabled = cpu_to_le32(DEC_SW_RING_ENABLED);<br>
}<br>
<br>
@@ -1074,7 +1075,13 @@ static int vcn_v3_0_start_dpg_mode(struct amdgpu_device *adev, int inst_idx, boo<br>
WREG32_SOC15(VCN, inst_idx, mmUVD_RBC_RB_WPTR,<br>
lower_32_bits(ring->wptr));<br>
<br>
+ /* Reset FW shared memory RBC WPTR/RPTR */<br>
+ fw_shared->rb.rptr = 0;<br>
+ fw_shared->rb.wptr = lower_32_bits(ring->wptr);<br>
+<br>
+ /*resetting done, fw can check RB ring */<br>
fw_shared->multi_queue.decode_queue_mode &= cpu_to_le32(~FW_QUEUE_RING_RESET);<br>
+<br>
/* Unstall DPG */<br>
WREG32_P(SOC15_REG_OFFSET(VCN, inst_idx, mmUVD_POWER_STATUS),<br>
0, ~UVD_POWER_STATUS__STALL_DPG_POWER_UP_MASK);<br>
@@ -1239,9 +1246,11 @@ static int vcn_v3_0_start(struct amdgpu_device *adev)<br>
/* Initialize the ring buffer's read and write pointers */<br>
WREG32_SOC15(VCN, i, mmUVD_RBC_RB_RPTR, 0);<br>
<br>
+ WREG32_SOC15(VCN, i, mmUVD_SCRATCH2, 0);<br>
ring->wptr = RREG32_SOC15(VCN, i, mmUVD_RBC_RB_RPTR);<br>
WREG32_SOC15(VCN, i, mmUVD_RBC_RB_WPTR,<br>
lower_32_bits(ring->wptr));<br>
+ fw_shared->rb.wptr = lower_32_bits(ring->wptr);<br>
fw_shared->multi_queue.decode_queue_mode &= cpu_to_le32(~FW_QUEUE_RING_RESET);<br>
<br>
fw_shared->multi_queue.encode_generalpurpose_queue_mode |= cpu_to_le32(FW_QUEUE_RING_RESET);<br>
@@ -1662,6 +1671,10 @@ static int vcn_v3_0_pause_dpg_mode(struct amdgpu_device *adev,<br>
WREG32_SOC15(VCN, inst_idx, mmUVD_RB_WPTR2, lower_32_bits(ring->wptr));<br>
fw_shared->multi_queue.encode_lowlatency_queue_mode &= cpu_to_le32(~FW_QUEUE_RING_RESET);<br>
<br>
+ /* restore wptr/rptr with pointers saved in FW shared memory*/<br>
+ WREG32_SOC15(VCN, inst_idx, mmUVD_RBC_RB_RPTR, fw_shared->rb.rptr);<br>
+ WREG32_SOC15(VCN, inst_idx, mmUVD_RBC_RB_WPTR, fw_shared->rb.wptr);<br>
+<br>
/* Unstall DPG */<br>
WREG32_P(SOC15_REG_OFFSET(VCN, inst_idx, mmUVD_POWER_STATUS),<br>
0, ~UVD_POWER_STATUS__STALL_DPG_POWER_UP_MASK);<br>
@@ -1721,6 +1734,15 @@ static uint64_t vcn_v3_0_dec_ring_get_wptr(struct amdgpu_ring *ring)<br>
static void vcn_v3_0_dec_ring_set_wptr(struct amdgpu_ring *ring)<br>
{<br>
struct amdgpu_device *adev = ring->adev;<br>
+ volatile struct amdgpu_fw_shared *fw_shared;<br>
+<br>
+ if (adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) {<br>
+ /*whenever update RBC_RB_WPTR, we save the wptr in shared rb.wptr and scratch2 */<br>
+ fw_shared = adev->vcn.inst[ring->me].fw_shared_cpu_addr;<br>
+ fw_shared->rb.wptr = lower_32_bits(ring->wptr);<br>
+ WREG32_SOC15(VCN, ring->me, mmUVD_SCRATCH2,<br>
+ lower_32_bits(ring->wptr));<br>
+ }<br>
<br>
if (ring->use_doorbell) {<br>
adev->wb.wb[ring->wptr_offs] = lower_32_bits(ring->wptr);<br>
-- <br>
2.25.1<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>