<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Yup, I fixed that in my worktree already.  </p>
<p><br>
</p>
<p>Tom</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Zhu, Rex<br>
<b>Sent:</b> Thursday, July 28, 2016 08:59<br>
<b>To:</b> StDenis, Tom; Alex Deucher<br>
<b>Cc:</b> amd-gfx list<br>
<b>Subject:</b> Re: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>you mean </p>
<div>+    if (cz_hwmgr->uvd_power_gated == bgate) {<br>
         return 0;<br>
+    }</div>
<p></p>
<p><br>
</p>
<p>I didn't pay any attention at first.</p>
<p><br>
</p>
<p>Best Regards</p>
<p>Rex<br>
</p>
<p><br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> StDenis, Tom<br>
<b>Sent:</b> Thursday, July 28, 2016 8:44:11 PM<br>
<b>To:</b> Zhu, Rex; Alex Deucher<br>
<b>Cc:</b> amd-gfx list<br>
<b>Subject:</b> Re: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hi Rex,</p>
<p><br>
</p>
<p>Thanks.  BTW I fixed the one liner {} in the PP code (removed the {} braces) in my worktree after I sent that in case anyone notices that :-)</p>
<p><br>
</p>
<p>Tom</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Zhu, Rex<br>
<b>Sent:</b> Thursday, July 28, 2016 08:43<br>
<b>To:</b> StDenis, Tom; Alex Deucher<br>
<b>Cc:</b> amd-gfx list<br>
<b>Subject:</b> Re: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Looks good to me. </p>
<p><br>
</p>
<p>Best Regards</p>
<p>Rex<br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> StDenis, Tom<br>
<b>Sent:</b> Thursday, July 28, 2016 8:19:52 PM<br>
<b>To:</b> Zhu, Rex; Alex Deucher<br>
<b>Cc:</b> amd-gfx list<br>
<b>Subject:</b> Re: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Nevermind I moved the locking into amdgpu_pm.c and that did the trick.  </p>
<p><br>
</p>
<p>Attached is a patch that contains all the changes.  If you guys want to give it a quick once-through I can then start splitting it up per Alex's comments.</p>
<p><br>
</p>
<p>Tom</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="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 StDenis, Tom <Tom.StDenis@amd.com><br>
<b>Sent:</b> Thursday, July 28, 2016 07:10<br>
<b>To:</b> Zhu, Rex; Alex Deucher<br>
<b>Cc:</b> amd-gfx list<br>
<b>Subject:</b> Re: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init</font>
<div> </div>
</div>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; background-color:#FFFFFF; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Quick question, how am I meant to get access to pm.mutex from powerplay?</p>
<p><br>
</p>
<p>I need a lock I can see around the SMU calls and in the amdgpu side (for userspace locking).</p>
<p><br>
</p>
<p>Tom</p>
<br>
<br>
<div style="color:rgb(0,0,0)">
<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> Zhu, Rex<br>
<b>Sent:</b> Thursday, July 28, 2016 03:43<br>
<b>To:</b> Alex Deucher; Tom St Denis<br>
<b>Cc:</b> StDenis, Tom; amd-gfx list<br>
<b>Subject:</b> RE: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt">
<div class="PlainText"><br>
From: amd-gfx [<a href="mailto:amd-gfx-bounces@lists.freedesktop.org">mailto:amd-gfx-bounces@lists.freedesktop.org</a>] On Behalf Of Alex Deucher<br>
Sent: Thursday, July 28, 2016 1:46 PM<br>
To: Tom St Denis<br>
Cc: StDenis, Tom; amd-gfx list<br>
Subject: Re: [PATCH 4/4] drm/amd/powerplay: Prevent UVD powerdown before init<br>
<br>
On Tue, Jul 26, 2016 at 11:38 AM, Tom St Denis <tstdenis82@gmail.com> wrote:<br>
> Because of the ip_blocks init order powerplay would power down the UVD <br>
> block before UVD start is called.  This results in a VCPU hang.<br>
><br>
> This patch prevents power down before UVD is initialized.<br>
><br>
> Also correct the power up order so clocking is set after power is <br>
> ungated.<br>
><br>
> With this applied comparable clock/power behaviour to powerplay=0 with <br>
> DPM is observed.<br>
><br>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
<br>
This patch needs to be split into several patches and reworked a bit.<br>
Also, don't include amdgpu.h in powerplay.  We have cgs for access to registers and data from adev, etc.  The idea is to minimize the dependencies between components.  We shouldn't be accessing adev directly in powerplay.  A couple more comments inline.<br>
<br>
<br>
Rex:  I also think so. <br>
1. We can move <br>
+                       WREG32(mmUVD_POWER_STATUS,<br>
+                               UVD_POWER_STATUS__UVD_PG_EN_MASK |<br>
+                               UVD_POWER_STATUS__UVD_PG_MODE_MASK);<br>
+               else<br>
+                       WREG32(mmUVD_POWER_STATUS,<br>
+                               UVD_POWER_STATUS__UVD_PG_EN_MASK);<br>
to uvd_v6_0_start.  no need to visit adev in powerplay and dpm.  And uvd test also can pass.<br>
<br>
2.  for the lock, we can just use pm.mutex.<br>
<br>
3.  please also delete enable_clock_power_gatings_tasks in resume_action_chain in a separate patch for powerplay.<br>
    <br>
4.  do we need to add cg_state, pg_state? <br>
<br>
<br>
<br>
Best Regards<br>
Rex<br>
<br>
<br>
> ---<br>
>  drivers/gpu/drm/amd/amdgpu/amdgpu.h                |  6 ++++++<br>
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c            |  5 -----<br>
>  drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c              |  8 ++++---<br>
>  drivers/gpu/drm/amd/amdgpu/vi.c                    | 12 ++++-------<br>
>  .../drm/amd/powerplay/hwmgr/cz_clockpowergating.c  | 25 ++++++++++++++++++----<br>
>  drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c     |  7 ++++++<br>
>  6 files changed, 43 insertions(+), 20 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h <br>
> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> index d0460ea2f85b..5616b16e6c0a 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> @@ -1692,6 +1692,7 @@ struct amdgpu_uvd {<br>
>         uint32_t                srbm_soft_reset;<br>
>         int                     cg_state, pg_state;<br>
>         struct mutex            pg_lock;<br>
> +       bool                    is_init;<br>
>  };<br>
><br>
>  /*<br>
> @@ -2518,5 +2519,10 @@ int amdgpu_dm_display_resume(struct <br>
> amdgpu_device *adev );  static inline int <br>
> amdgpu_dm_display_resume(struct amdgpu_device *adev) { return 0; }  <br>
> #endif<br>
><br>
> +struct amdgpu_cgs_device {<br>
> +       struct cgs_device base;<br>
> +       struct amdgpu_device *adev;<br>
> +};<br>
> +<br>
>  #include "amdgpu_object.h"<br>
>  #endif<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c <br>
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c<br>
> index ee95e950a19b..d553e399a835 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c<br>
> @@ -33,11 +33,6 @@<br>
>  #include "atom.h"<br>
>  #include "amdgpu_ucode.h"<br>
><br>
> -struct amdgpu_cgs_device {<br>
> -       struct cgs_device base;<br>
> -       struct amdgpu_device *adev;<br>
> -};<br>
> -<br>
>  #define CGS_FUNC_ADEV                                                  \<br>
>         struct amdgpu_device *adev =                                    \<br>
>                 ((struct amdgpu_cgs_device *)cgs_device)->adev diff <br>
> --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c <br>
> b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> index 422d5300b92e..3b93327c5e25 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> @@ -389,9 +389,9 @@ static int uvd_v6_0_start(struct amdgpu_device *adev)<br>
>         uint32_t mp_swap_cntl;<br>
>         int i, j, r;<br>
><br>
> -       /* is power gated? then we can't start (TODO: re-enable power) */<br>
> -       if (adev->uvd.pg_state)<br>
> -               return -EINVAL;<br>
> +       /* is power gated? then we can't start but don't return an error */<br>
> +       if (adev->uvd.is_init && adev->uvd.pg_state)<br>
> +               return 0;<br>
><br>
>         /* set CG state to -1 for unset */<br>
>         adev->uvd.cg_state = -1;<br>
> @@ -662,6 +662,8 @@ static int uvd_v6_0_ring_test_ring(struct amdgpu_ring *ring)<br>
>                           ring->idx, tmp);<br>
>                 r = -EINVAL;<br>
>         }<br>
> +       if (!r)<br>
> +               adev->uvd.is_init = true;<br>
>         return r;<br>
>  }<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c <br>
> b/drivers/gpu/drm/amd/amdgpu/vi.c index 78fea940d120..f4fdde0641b0 <br>
> 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/vi.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/vi.c<br>
> @@ -1583,10 +1583,8 @@ static int vi_common_early_init(void *handle)<br>
>                 if (adev->rev_id != 0x00) {<br>
>                         adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |<br>
>                                 AMD_PG_SUPPORT_GFX_SMG |<br>
> -                               AMD_PG_SUPPORT_GFX_PIPELINE;<br>
> -                       /* powerplay UVD PG doesn't work yet */<br>
> -                       if (!amdgpu_powerplay)<br>
> -                               adev->pg_flags |= AMD_PG_SUPPORT_UVD;<br>
> +                               AMD_PG_SUPPORT_GFX_PIPELINE |<br>
> +                               AMD_PG_SUPPORT_UVD;<br>
<br>
This should be a separate patch.<br>
<br>
>                 }<br>
>                 adev->external_rev_id = adev->rev_id + 0x1;<br>
>                 break;<br>
> @@ -1608,10 +1606,8 @@ static int vi_common_early_init(void *handle)<br>
>                         AMD_CG_SUPPORT_SDMA_LS;<br>
>                 adev->pg_flags |= AMD_PG_SUPPORT_GFX_PG |<br>
>                         AMD_PG_SUPPORT_GFX_SMG |<br>
> -                       AMD_PG_SUPPORT_GFX_PIPELINE;<br>
> -               /* powerplay UVD PG doesn't work yet */<br>
> -               if (!amdgpu_powerplay)<br>
> -                       adev->pg_flags |= AMD_PG_SUPPORT_UVD;<br>
> +                       AMD_PG_SUPPORT_GFX_PIPELINE |<br>
> +                       AMD_PG_SUPPORT_UVD;<br>
<br>
Same with this.<br>
<br>
>                 adev->external_rev_id = adev->rev_id + 0x1;<br>
>                 break;<br>
>         default:<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_clockpowergating.c <br>
> b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_clockpowergating.c<br>
> index 2da548f6337e..baa7366fad53 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_clockpowergating.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_clockpowergating.c<br>
> @@ -21,9 +21,13 @@<br>
>   *<br>
>   */<br>
><br>
> +#include "amdgpu.h"<br>
>  #include "hwmgr.h"<br>
>  #include "cz_clockpowergating.h"<br>
>  #include "cz_ppsmc.h"<br>
> +#include "cgs_linux.h"<br>
> +#include "uvd/uvd_6_0_d.h"<br>
> +#include "uvd/uvd_6_0_sh_mask.h"<br>
><br>
>  /* PhyID -> Status Mapping in DDI_PHY_GEN_STATUS<br>
>      0    GFX0L (3:0),                  (27:24),<br>
> @@ -160,12 +164,24 @@ int cz_enable_disable_vce_dpm(struct pp_hwmgr <br>
> *hwmgr, bool enable)  int cz_dpm_powergate_uvd(struct pp_hwmgr *hwmgr, <br>
> bool bgate)  {<br>
>         struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr <br>
> *)(hwmgr->backend);<br>
> +       struct amdgpu_cgs_device *cgs_dev = hwmgr->device;<br>
> +       struct amdgpu_device *adev = cgs_dev->adev;<br>
><br>
> -       if (cz_hwmgr->uvd_power_gated == bgate)<br>
> +       if (!adev->uvd.is_init)<br>
>                 return 0;<br>
><br>
> +       mutex_lock(&adev->uvd.pg_lock);<br>
> +<br>
> +       if (cz_hwmgr->uvd_power_gated == bgate) {<br>
> +               mutex_unlock(&adev->uvd.pg_lock);<br>
> +               return 0;<br>
> +       }<br>
> +<br>
> +       adev->uvd.pg_state = bgate;<br>
>         cz_hwmgr->uvd_power_gated = bgate;<br>
><br>
> +       WREG32(mmUVD_POWER_STATUS, UVD_POWER_STATUS__UVD_PG_EN_MASK);<br>
> +<br>
<br>
Could this be moved to the uvd 6 module?<br>
<br>
<br>
<br>
<br>
>         if (bgate) {<br>
>                 cgs_set_clockgating_state(hwmgr->device,<br>
>                                                 AMD_IP_BLOCK_TYPE_UVD, <br>
> @@ -177,14 +193,15 @@ int cz_dpm_powergate_uvd(struct pp_hwmgr *hwmgr, bool bgate)<br>
>                 cz_dpm_powerdown_uvd(hwmgr);<br>
>         } else {<br>
>                 cz_dpm_powerup_uvd(hwmgr);<br>
> -               cgs_set_clockgating_state(hwmgr->device,<br>
> -                                               AMD_IP_BLOCK_TYPE_UVD,<br>
> -                                               AMD_PG_STATE_GATE);<br>
>                 cgs_set_powergating_state(hwmgr->device,<br>
>                                                 AMD_IP_BLOCK_TYPE_UVD,<br>
>                                                 AMD_CG_STATE_UNGATE);<br>
> +               cgs_set_clockgating_state(hwmgr->device,<br>
> +                                               AMD_IP_BLOCK_TYPE_UVD,<br>
> +                                               AMD_PG_STATE_GATE);<br>
<br>
I think this is a standalone fix and should be split into a separate patch.<br>
<br>
>                 cz_dpm_update_uvd_dpm(hwmgr, false);<br>
>         }<br>
> +       mutex_unlock(&adev->uvd.pg_lock);<br>
><br>
>         return 0;<br>
>  }<br>
> diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c <br>
> b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> index 9bf622e123b6..bed0013674a1 100644<br>
> --- a/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> +++ b/drivers/gpu/drm/amd/powerplay/hwmgr/cz_hwmgr.c<br>
> @@ -39,6 +39,7 @@<br>
>  #include "power_state.h"<br>
>  #include "cz_clockpowergating.h"<br>
>  #include "pp_debug.h"<br>
> +#include "amdgpu.h"<br>
><br>
>  #define ixSMUSVI_NB_CURRENTVID 0xD8230044  #define <br>
> CURRENT_NB_VID_MASK 0xff000000 @@ -1356,6 +1357,12 @@ static int <br>
> cz_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,<br>
><br>
>  int cz_dpm_powerdown_uvd(struct pp_hwmgr *hwmgr)  {<br>
> +       struct amdgpu_cgs_device *cgs_dev = hwmgr->device;<br>
> +       struct amdgpu_device *adev = cgs_dev->adev;<br>
> +<br>
> +       if (!adev->uvd.is_init)<br>
> +               return 0;<br>
> +<br>
>         if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,<br>
>                                          PHM_PlatformCaps_UVDPowerGating))<br>
>                 return smum_send_msg_to_smc(hwmgr->smumgr,<br>
> --<br>
> 2.9.2<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>
_______________________________________________<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></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>