<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>do we need to check those status(lmi status,firmware loaded, vce status and etc) when vce suspend?</p>
<p><br>
</p>
<p>it is weird that we didn't implement vce suspend function as hw spec suggested.</p>
<p><br>
</p>
<p>Best Regards</p>
<p>Rex<br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Christian König <deathsimple@vodafone.de><br>
<b>Sent:</b> Thursday, August 18, 2016 9:27:57 PM<br>
<b>To:</b> Qu, Jim; amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH] drm/amd/amdgpu: S3 resumed failed after 4-5 times loop</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Am 18.08.2016 um 14:42 schrieb jimqu:<br>
> phenomenon: software hang when device resume back, read UVD fence is 0xffffffff<br>
> and read pcie pid is 0xffff.<br>
> the issue is caused by VCE reset when update cg setting. according to HW programming<br>
> guide, adjust update VCE cg sequence.<br>
><br>
> Change-Id: I18b12eea21c045908cdd23f93a0b196b87bfed6c<br>
> Signed-off-by: JimQu <Jim.Qu@amd.com><br>
<br>
You should probably note in the commit log that this only applies to <br>
systems with VCE2, e.g. CIK.<br>
<br>
Additional to that please make sure that it applies cleanly to the <br>
amd-staging-4.6 branch.<br>
<br>
With that made sure the patch is Reviewed-by: Christian König <br>
<christian.koenig@amd.com><br>
<br>
Regards,<br>
Christian.<br>
<br>
> ---<br>
>   drivers/gpu/drm/amd/amdgpu/vce_v2_0.c | 123 +++++++++++++++++++++++-----------<br>
>   1 file changed, 84 insertions(+), 39 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c<br>
> index 9e70df9..6ce7c07 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/vce_v2_0.c<br>
> @@ -40,10 +40,12 @@<br>
>   #define VCE_V2_0_FW_SIZE    (256 * 1024)<br>
>   #define VCE_V2_0_STACK_SIZE (64 * 1024)<br>
>   #define VCE_V2_0_DATA_SIZE  (23552 * AMDGPU_MAX_VCE_HANDLES)<br>
> +#define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK        0x02<br>
>   <br>
>   static void vce_v2_0_mc_resume(struct amdgpu_device *adev);<br>
>   static void vce_v2_0_set_ring_funcs(struct amdgpu_device *adev);<br>
>   static void vce_v2_0_set_irq_funcs(struct amdgpu_device *adev);<br>
> +static int vce_v2_0_wait_for_idle(void *handle);<br>
>   <br>
>   /**<br>
>    * vce_v2_0_ring_get_rptr - get read pointer<br>
> @@ -96,6 +98,49 @@ static void vce_v2_0_ring_set_wptr(struct amdgpu_ring *ring)<br>
>                WREG32(mmVCE_RB_WPTR2, ring->wptr);<br>
>   }<br>
>   <br>
> +static int vce_v2_0_lmi_clean(struct amdgpu_device *adev)<br>
> +{<br>
> +     int i, j;<br>
> +<br>
> +     for (i = 0; i < 10; ++i) {<br>
> +             for (j = 0; j < 100; ++j) {<br>
> +                     uint32_t status = RREG32(mmVCE_LMI_STATUS);<br>
> +<br>
> +                     if (status & 0x337f)<br>
> +                             return 0;<br>
> +                     mdelay(10);<br>
> +             }<br>
> +     }<br>
> +<br>
> +     return -ETIMEDOUT;<br>
> +}<br>
> +<br>
> +static int vce_v2_0_firmware_loaded(struct amdgpu_device *adev)<br>
> +{<br>
> +     int i, j;<br>
> +<br>
> +     for (i = 0; i < 10; ++i) {<br>
> +             for (j = 0; j < 100; ++j) {<br>
> +                     uint32_t status = RREG32(mmVCE_STATUS);<br>
> +<br>
> +                     if (status & VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK)<br>
> +                             return 0;<br>
> +                     mdelay(10);<br>
> +             }<br>
> +<br>
> +             DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");<br>
> +             WREG32_P(mmVCE_SOFT_RESET,<br>
> +                     VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,<br>
> +                     ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> +             mdelay(10);<br>
> +             WREG32_P(mmVCE_SOFT_RESET, 0,<br>
> +                     ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> +             mdelay(10);<br>
> +     }<br>
> +<br>
> +     return -ETIMEDOUT;<br>
> +}<br>
> +<br>
>   /**<br>
>    * vce_v2_0_start - start VCE block<br>
>    *<br>
> @@ -106,7 +151,7 @@ static void vce_v2_0_ring_set_wptr(struct amdgpu_ring *ring)<br>
>   static int vce_v2_0_start(struct amdgpu_device *adev)<br>
>   {<br>
>        struct amdgpu_ring *ring;<br>
> -     int i, j, r;<br>
> +     int r;<br>
>   <br>
>        vce_v2_0_mc_resume(adev);<br>
>   <br>
> @@ -137,26 +182,7 @@ static int vce_v2_0_start(struct amdgpu_device *adev)<br>
>   <br>
>        WREG32_P(mmVCE_SOFT_RESET, 0, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
>   <br>
> -     for (i = 0; i < 10; ++i) {<br>
> -             uint32_t status;<br>
> -             for (j = 0; j < 100; ++j) {<br>
> -                     status = RREG32(mmVCE_STATUS);<br>
> -                     if (status & 2)<br>
> -                             break;<br>
> -                     mdelay(10);<br>
> -             }<br>
> -             r = 0;<br>
> -             if (status & 2)<br>
> -                     break;<br>
> -<br>
> -             DRM_ERROR("VCE not responding, trying to reset the ECPU!!!\n");<br>
> -             WREG32_P(mmVCE_SOFT_RESET, VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,<br>
> -                             ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> -             mdelay(10);<br>
> -             WREG32_P(mmVCE_SOFT_RESET, 0, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> -             mdelay(10);<br>
> -             r = -1;<br>
> -     }<br>
> +     r = vce_v2_0_firmware_loaded(adev);<br>
>   <br>
>        /* clear BUSY flag */<br>
>        WREG32_P(mmVCE_STATUS, 0, ~1);<br>
> @@ -338,31 +364,50 @@ static void vce_v2_0_set_sw_cg(struct amdgpu_device *adev, bool gated)<br>
>   <br>
>   static void vce_v2_0_set_dyn_cg(struct amdgpu_device *adev, bool gated)<br>
>   {<br>
> -     u32 orig, tmp;<br>
> +     if (vce_v2_0_wait_for_idle(adev)) {<br>
> +             DRM_INFO("VCE is busy, Can't set clock gateing");<br>
> +             return;<br>
> +     }<br>
>   <br>
> -     tmp = RREG32(mmVCE_CLOCK_GATING_B);<br>
> -     tmp &= ~0x00060006;<br>
> +     WREG32_P(mmVCE_LMI_CTRL2, 0x100, ~0x100);<br>
> +<br>
> +     if (vce_v2_0_lmi_clean(adev)) {<br>
> +             DRM_INFO("LMI is busy, Can't set clock gateing");<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     WREG32_P(mmVCE_VCPU_CNTL, 0, ~VCE_VCPU_CNTL__CLK_EN_MASK);<br>
> +     WREG32_P(mmVCE_SOFT_RESET,<br>
> +              VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,<br>
> +              ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> +     WREG32(mmVCE_STATUS, 0);<br>
> +<br>
> +     if (gated)<br>
> +             WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);<br>
> +     /* LMI_MC/LMI_UMC always set in dynamic, set {CGC_*_GATE_MODE, CGC_*_SW_GATE} = {0, 0} */<br>
>        if (gated) {<br>
> -             tmp |= 0xe10000;<br>
> +             /* Force CLOCK OFF , set {CGC_*_GATE_MODE, CGC_*_SW_GATE} = {*, 1} */<br>
> +             WREG32(mmVCE_CLOCK_GATING_B, 0xe90010);<br>
>        } else {<br>
> -             tmp |= 0xe1;<br>
> -             tmp &= ~0xe10000;<br>
> +             /* Force CLOCK ON, set {CGC_*_GATE_MODE, CGC_*_SW_GATE} = {1, 0} */<br>
> +             WREG32(mmVCE_CLOCK_GATING_B, 0x800f1);<br>
>        }<br>
> -     WREG32(mmVCE_CLOCK_GATING_B, tmp);<br>
>   <br>
> -     orig = tmp = RREG32(mmVCE_UENC_CLOCK_GATING);<br>
> -     tmp &= ~0x1fe000;<br>
> -     tmp &= ~0xff000000;<br>
> -     if (tmp != orig)<br>
> -             WREG32(mmVCE_UENC_CLOCK_GATING, tmp);<br>
> +     /* Set VCE_UENC_CLOCK_GATING always in dynamic mode {*_FORCE_ON, *_FORCE_OFF} = {0, 0}*/;<br>
> +     WREG32(mmVCE_UENC_CLOCK_GATING, 0x40);<br>
>   <br>
> -     orig = tmp = RREG32(mmVCE_UENC_REG_CLOCK_GATING);<br>
> -     tmp &= ~0x3fc;<br>
> -     if (tmp != orig)<br>
> -             WREG32(mmVCE_UENC_REG_CLOCK_GATING, tmp);<br>
> +     /* set VCE_UENC_REG_CLOCK_GATING always in dynamic mode */<br>
> +     WREG32(mmVCE_UENC_REG_CLOCK_GATING, 0x00);<br>
>   <br>
> -     if (gated)<br>
> -             WREG32(mmVCE_CGTT_CLK_OVERRIDE, 0);<br>
> +     WREG32_P(mmVCE_LMI_CTRL2, 0, ~0x100);<br>
> +     if(!gated) {<br>
> +             WREG32_P(mmVCE_VCPU_CNTL, VCE_VCPU_CNTL__CLK_EN_MASK, ~VCE_VCPU_CNTL__CLK_EN_MASK);<br>
> +             mdelay(100);<br>
> +             WREG32_P(mmVCE_SOFT_RESET, 0, ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> +<br>
> +             vce_v2_0_firmware_loaded(adev);<br>
> +             WREG32_P(mmVCE_STATUS, 0, ~VCE_STATUS__JOB_BUSY_MASK);<br>
> +     }<br>
>   }<br>
>   <br>
>   static void vce_v2_0_disable_cg(struct amdgpu_device *adev)<br>
<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
</div>
</span></font>
</body>
</html>