<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;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p>Yup it's held by both <span>amdgpu_dpm_enable_uvd() and <span>amdgpu_dpm_enable_vce()</span></span></p>
<p><span><span><br>
</span></span></p>
<p><span><span>Tom</span></span></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> Koenig, Christian<br>
<b>Sent:</b> Monday, January 9, 2017 05:32<br>
<b>To:</b> Huang, Ray; Deucher, Alexander; amd-gfx@lists.freedesktop.org; StDenis, Tom<br>
<b>Cc:</b> Zhu, Rex; Mao, David; Fu, Ping; Zhang, Hawking; Kuehling, Felix<br>
<b>Subject:</b> Re: [PART1 PATCH v4 7/8] drm/amdgpu: add get clockgating_state method for uvd v5&v6</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Am 09.01.2017 um 04:00 schrieb Huang Rui:<br>
> Signed-off-by: Huang Rui <ray.huang@amd.com><br>
> ---<br>
><br>
> Changes from V3 -> V4:<br>
> - use pm mutex to protect UVD clock gating status<br>
><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +<br>
> drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c | 37 +++++++++++++++++++++++++++++++++--<br>
> drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 37 +++++++++++++++++++++++++++++++++--<br>
> 3 files changed, 71 insertions(+), 4 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> index 530549b..31054c7 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
> @@ -1183,6 +1183,7 @@ struct amdgpu_uvd {<br>
> bool use_ctx_buf;<br>
> struct amd_sched_entity entity;<br>
> uint32_t srbm_soft_reset;<br>
> + bool is_powergated;<br>
> };<br>
> <br>
> /*<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c<br>
> index 03a35d9..e647d3e 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v5_0.c<br>
> @@ -781,16 +781,48 @@ static int uvd_v5_0_set_powergating_state(void *handle,<br>
> * the smc and the hw blocks<br>
> */<br>
> struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
> + int ret = 0;<br>
> <br>
> if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))<br>
> return 0;<br>
> <br>
> + mutex_lock(&adev->pm.mutex);<br>
<br>
Might be that I'm wrong, but didn't Tom said the mutex is taken anyway <br>
when this function is called?<br>
<br>
If that's true we would certainly run into problem when we try to <br>
acquire it again.<br>
<br>
Christian.<br>
<br>
> +<br>
> if (state == AMD_PG_STATE_GATE) {<br>
> + adev->uvd.is_powergated = true;<br>
> uvd_v5_0_stop(adev);<br>
> - return 0;<br>
> } else {<br>
> - return uvd_v5_0_start(adev);<br>
> + ret = uvd_v5_0_start(adev);<br>
> + if (ret)<br>
> + goto out;<br>
> + adev->uvd.is_powergated = false;<br>
> + }<br>
> +<br>
> +out:<br>
> + mutex_unlock(&adev->pm.mutex);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static void uvd_v5_0_get_clockgating_state(void *handle, u32 *flags)<br>
> +{<br>
> + struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
> + int data;<br>
> +<br>
> + mutex_lock(&adev->pm.mutex);<br>
> +<br>
> + if (adev->uvd.is_powergated) {<br>
> + DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");<br>
> + goto out;<br>
> }<br>
> +<br>
> + /* AMD_CG_SUPPORT_UVD_MGCG */<br>
> + data = RREG32(mmUVD_CGC_CTRL);<br>
> + if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)<br>
> + *flags |= AMD_CG_SUPPORT_UVD_MGCG;<br>
> +<br>
> +out:<br>
> + mutex_unlock(&adev->pm.mutex);<br>
> }<br>
> <br>
> static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {<br>
> @@ -808,6 +840,7 @@ static const struct amd_ip_funcs uvd_v5_0_ip_funcs = {<br>
> .soft_reset = uvd_v5_0_soft_reset,<br>
> .set_clockgating_state = uvd_v5_0_set_clockgating_state,<br>
> .set_powergating_state = uvd_v5_0_set_powergating_state,<br>
> + .get_clockgating_state = uvd_v5_0_get_clockgating_state,<br>
> };<br>
> <br>
> static const struct amdgpu_ring_funcs uvd_v5_0_ring_funcs = {<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> index 8779d4b..2585ae9 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> @@ -987,18 +987,50 @@ static int uvd_v6_0_set_powergating_state(void *handle,<br>
> * the smc and the hw blocks<br>
> */<br>
> struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
> + int ret = 0;<br>
> <br>
> if (!(adev->pg_flags & AMD_PG_SUPPORT_UVD))<br>
> return 0;<br>
> <br>
> WREG32(mmUVD_POWER_STATUS, UVD_POWER_STATUS__UVD_PG_EN_MASK);<br>
> <br>
> + mutex_lock(&adev->pm.mutex);<br>
> +<br>
> if (state == AMD_PG_STATE_GATE) {<br>
> + adev->uvd.is_powergated = true;<br>
> uvd_v6_0_stop(adev);<br>
> - return 0;<br>
> } else {<br>
> - return uvd_v6_0_start(adev);<br>
> + ret = uvd_v6_0_start(adev);<br>
> + if (ret)<br>
> + goto out;<br>
> + adev->uvd.is_powergated = false;<br>
> + }<br>
> +<br>
> +out:<br>
> + mutex_unlock(&adev->pm.mutex);<br>
> +<br>
> + return ret;<br>
> +}<br>
> +<br>
> +static void uvd_v6_0_get_clockgating_state(void *handle, u32 *flags)<br>
> +{<br>
> + struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
> + int data;<br>
> +<br>
> + mutex_lock(&adev->pm.mutex);<br>
> +<br>
> + if (adev->uvd.is_powergated) {<br>
> + DRM_INFO("Cannot get clockgating state when UVD is powergated.\n");<br>
> + goto out;<br>
> }<br>
> +<br>
> + /* AMD_CG_SUPPORT_UVD_MGCG */<br>
> + data = RREG32(mmUVD_CGC_CTRL);<br>
> + if (data & UVD_CGC_CTRL__DYN_CLOCK_MODE_MASK)<br>
> + *flags |= AMD_CG_SUPPORT_UVD_MGCG;<br>
> +<br>
> +out:<br>
> + mutex_unlock(&adev->pm.mutex);<br>
> }<br>
> <br>
> static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {<br>
> @@ -1019,6 +1051,7 @@ static const struct amd_ip_funcs uvd_v6_0_ip_funcs = {<br>
> .post_soft_reset = uvd_v6_0_post_soft_reset,<br>
> .set_clockgating_state = uvd_v6_0_set_clockgating_state,<br>
> .set_powergating_state = uvd_v6_0_set_powergating_state,<br>
> + .get_clockgating_state = uvd_v6_0_get_clockgating_state,<br>
> };<br>
> <br>
> static const struct amdgpu_ring_funcs uvd_v6_0_ring_phys_funcs = {<br>
<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>