<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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>Thanks to Christian, I will update it.</p>
<p><br>
</p>
<p>Thanks</p>
<p>JimQu<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>发件人:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> 代表 Christian König <deathsimple@vodafone.de><br>
<b>发送时间:</b> 2016年7月14日 16:40:40<br>
<b>收件人:</b> Qu, Jim; amd-gfx@lists.freedesktop.org<br>
<b>主题:</b> Re: [PATCH] drm/amdgpu: S3 resume fail on Polaris10</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">Am 14.07.2016 um 07:48 schrieb jimqu:<br>
> Sometimes, driver can not return from fence waiting when doing VCE ring<br>
> ib test. The issue is a asic special and random issue. so adjust VCE suspend<br>
> and resume sequence.<br>
><br>
> Change-Id: I60d4ce413d787ae70e5c785aa5ac45d6644fbf69<br>
> Signed-off-by: JimQu <Jim.Qu@amd.com><br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 144 +++++++++++++++++++++++-----------<br>
> 1 file changed, 99 insertions(+), 45 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> index 30e8099..0f7957a 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> @@ -43,6 +43,7 @@<br>
> #define mmVCE_LMI_VCPU_CACHE_40BIT_BAR0 0x8616<br>
> #define mmVCE_LMI_VCPU_CACHE_40BIT_BAR1 0x8617<br>
> #define mmVCE_LMI_VCPU_CACHE_40BIT_BAR2 0x8618<br>
> +#define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02<br>
> <br>
> #define VCE_V3_0_FW_SIZE (384 * 1024)<br>
> #define VCE_V3_0_STACK_SIZE (64 * 1024)<br>
> @@ -51,6 +52,7 @@<br>
> static void vce_v3_0_mc_resume(struct amdgpu_device *adev, int idx);<br>
> static void vce_v3_0_set_ring_funcs(struct amdgpu_device *adev);<br>
> static void vce_v3_0_set_irq_funcs(struct amdgpu_device *adev);<br>
> +static int vce_v3_0_wait_for_idle(void *handle);<br>
> <br>
> /**<br>
> * vce_v3_0_ring_get_rptr - get read pointer<br>
> @@ -205,6 +207,32 @@ static void vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device *adev,<br>
> vce_v3_0_override_vce_clock_gating(adev, false);<br>
> }<br>
> <br>
> +static int vce_v3_0_firmware_loaded(struct amdgpu_device *adev)<br>
> +{<br>
> + int i, j;<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 & 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 -1;<br>
<br>
While at it you should probably return a better error code here.<br>
<br>
Something like -ETIMEDOUT or -EBUSY should do.<br>
<br>
> +}<br>
> +<br>
> /**<br>
> * vce_v3_0_start - start VCE block<br>
> *<br>
> @@ -215,11 +243,27 @@ static void vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device *adev,<br>
> static int vce_v3_0_start(struct amdgpu_device *adev)<br>
> {<br>
> struct amdgpu_ring *ring;<br>
> - int idx, i, j, r;<br>
> + int idx, r;<br>
> <br>
> mutex_lock(&adev->grbm_idx_mutex);<br>
> for (idx = 0; idx < 2; ++idx) {<br>
> <br>
> + ring = &adev->vce.ring[idx];<br>
> +<br>
> + if (idx == 0) {<br>
> + WREG32(mmVCE_RB_RPTR, ring->wptr);<br>
> + WREG32(mmVCE_RB_WPTR, ring->wptr);<br>
> + WREG32(mmVCE_RB_BASE_LO, ring->gpu_addr);<br>
> + WREG32(mmVCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));<br>
> + WREG32(mmVCE_RB_SIZE, ring->ring_size / 4);<br>
> + } else {<br>
> + WREG32(mmVCE_RB_RPTR2, ring->wptr);<br>
> + WREG32(mmVCE_RB_WPTR2, ring->wptr);<br>
> + WREG32(mmVCE_RB_BASE_LO2, ring->gpu_addr);<br>
> + WREG32(mmVCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));<br>
> + WREG32(mmVCE_RB_SIZE2, ring->ring_size / 4);<br>
> + }<br>
> +<br>
<br>
The ring index is independent from the instance, so this is clearly <br>
incorrect.<br>
<br>
If the ring buffer needs to be initialized before the firmware starts <br>
(which makes sense) then just move the register writes before the loop.<br>
<br>
Apart from that looks good to me.<br>
<br>
Regards,<br>
Christian.<br>
<br>
> if (adev->vce.harvest_config & (1 << idx))<br>
> continue;<br>
> <br>
> @@ -233,48 +277,24 @@ static int vce_v3_0_start(struct amdgpu_device *adev)<br>
> <br>
> vce_v3_0_mc_resume(adev, idx);<br>
> <br>
> - /* set BUSY flag */<br>
> - WREG32_P(mmVCE_STATUS, 1, ~1);<br>
> + WREG32_P(mmVCE_STATUS, VCE_STATUS__JOB_BUSY_MASK,<br>
> + ~VCE_STATUS__JOB_BUSY_MASK);<br>
> +<br>
> if (adev->asic_type >= CHIP_STONEY)<br>
> WREG32_P(mmVCE_VCPU_CNTL, 1, ~0x200001);<br>
> else<br>
> WREG32_P(mmVCE_VCPU_CNTL, VCE_VCPU_CNTL__CLK_EN_MASK,<br>
> ~VCE_VCPU_CNTL__CLK_EN_MASK);<br>
> <br>
> - WREG32_P(mmVCE_SOFT_RESET,<br>
> - VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,<br>
> - ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> -<br>
> - mdelay(100);<br>
> -<br>
> WREG32_P(mmVCE_SOFT_RESET, 0,<br>
> ~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,<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>
> - r = -1;<br>
> - }<br>
> + mdelay(100);<br>
> +<br>
> + r = vce_v3_0_firmware_loaded(adev);<br>
> <br>
> /* clear BUSY flag */<br>
> - WREG32_P(mmVCE_STATUS, 0, ~1);<br>
> + WREG32_P(mmVCE_STATUS, 0, ~VCE_STATUS__JOB_BUSY_MASK);<br>
> <br>
> /* Set Clock-Gating off */<br>
> if (adev->cg_flags & AMD_CG_SUPPORT_VCE_MGCG)<br>
> @@ -290,19 +310,46 @@ static int vce_v3_0_start(struct amdgpu_device *adev)<br>
> WREG32_P(mmGRBM_GFX_INDEX, 0, ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> mutex_unlock(&adev->grbm_idx_mutex);<br>
> <br>
> - ring = &adev->vce.ring[0];<br>
> - WREG32(mmVCE_RB_RPTR, ring->wptr);<br>
> - WREG32(mmVCE_RB_WPTR, ring->wptr);<br>
> - WREG32(mmVCE_RB_BASE_LO, ring->gpu_addr);<br>
> - WREG32(mmVCE_RB_BASE_HI, upper_32_bits(ring->gpu_addr));<br>
> - WREG32(mmVCE_RB_SIZE, ring->ring_size / 4);<br>
> + return 0;<br>
> +}<br>
> <br>
> - ring = &adev->vce.ring[1];<br>
> - WREG32(mmVCE_RB_RPTR2, ring->wptr);<br>
> - WREG32(mmVCE_RB_WPTR2, ring->wptr);<br>
> - WREG32(mmVCE_RB_BASE_LO2, ring->gpu_addr);<br>
> - WREG32(mmVCE_RB_BASE_HI2, upper_32_bits(ring->gpu_addr));<br>
> - WREG32(mmVCE_RB_SIZE2, ring->ring_size / 4);<br>
> +static int vce_v3_0_stop(struct amdgpu_device *adev)<br>
> +{<br>
> + int idx;<br>
> +<br>
> + mutex_lock(&adev->grbm_idx_mutex);<br>
> + for (idx = 0; idx < 2; ++idx) {<br>
> + if (adev->vce.harvest_config & (1 << idx))<br>
> + continue;<br>
> +<br>
> + if (idx == 0)<br>
> + WREG32_P(mmGRBM_GFX_INDEX, 0,<br>
> + ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + else<br>
> + WREG32_P(mmGRBM_GFX_INDEX,<br>
> + GRBM_GFX_INDEX__VCE_INSTANCE_MASK,<br>
> + ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> +<br>
> + if (adev->asic_type >= CHIP_STONEY)<br>
> + WREG32_P(mmVCE_VCPU_CNTL, 0, ~0x200001);<br>
> + else<br>
> + WREG32_P(mmVCE_VCPU_CNTL, 0,<br>
> + ~VCE_VCPU_CNTL__CLK_EN_MASK);<br>
> + /* hold on ECPU */<br>
> + WREG32_P(mmVCE_SOFT_RESET,<br>
> + VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK,<br>
> + ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> +<br>
> + /* clear BUSY flag */<br>
> + WREG32_P(mmVCE_STATUS, 0, ~VCE_STATUS__JOB_BUSY_MASK);<br>
> +<br>
> + /* Set Clock-Gating off */<br>
> + if (adev->cg_flags & AMD_CG_SUPPORT_VCE_MGCG)<br>
> + vce_v3_0_set_vce_sw_clock_gating(adev, false);<br>
> + }<br>
> +<br>
> + WREG32_P(mmGRBM_GFX_INDEX, 0, ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + mutex_unlock(&adev->grbm_idx_mutex);<br>
> <br>
> return 0;<br>
> }<br>
> @@ -441,7 +488,14 @@ static int vce_v3_0_hw_init(void *handle)<br>
> <br>
> static int vce_v3_0_hw_fini(void *handle)<br>
> {<br>
> - return 0;<br>
> + int r;<br>
> + struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
> +<br>
> + r = vce_v3_0_wait_for_idle(handle);<br>
> + if (r)<br>
> + return r;<br>
> +<br>
> + return vce_v3_0_stop(adev);<br>
> }<br>
> <br>
> static int vce_v3_0_suspend(void *handle)<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>