<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>Sorta. The switch from gate/ungate for instance is kinda mutually exclusive. The device won't be gated when calling gate or ungated when calling ungate. The other conditional writes are similar.</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> Deucher, Alexander<br>
<b>Sent:</b> Thursday, August 11, 2016 11:41<br>
<b>To:</b> 'Tom St Denis'; amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> StDenis, Tom<br>
<b>Subject:</b> RE: [PATCH 1/4] drm/amd/amdgpu: Cleanup register access in VCE v3</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">> -----Original Message-----<br>
> From: amd-gfx [<a href="mailto:amd-gfx-bounces@lists.freedesktop.org">mailto:amd-gfx-bounces@lists.freedesktop.org</a>] On Behalf<br>
> Of Tom St Denis<br>
> Sent: Thursday, August 11, 2016 10:33 AM<br>
> To: amd-gfx@lists.freedesktop.org<br>
> Cc: StDenis, Tom<br>
> Subject: [PATCH 1/4] drm/amd/amdgpu: Cleanup register access in VCE v3<br>
> <br>
> Signed-off-by: Tom St Denis <tom.stdenis@amd.com><br>
<br>
This potentially adds a bunch of unnecessary register writes which increases latency on VCE power up.<br>
<br>
Alex<br>
<br>
> ---<br>
> drivers/gpu/drm/amd/amdgpu/vce_v3_0.c | 145 ++++++++++-----------------<br>
> -------<br>
> 1 file changed, 43 insertions(+), 102 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> index 7e6bb45658f6..073cf9ed0674 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/vce_v3_0.c<br>
> @@ -110,22 +110,13 @@ static void vce_v3_0_ring_set_wptr(struct<br>
> amdgpu_ring *ring)<br>
> <br>
> static void vce_v3_0_override_vce_clock_gating(struct amdgpu_device<br>
> *adev, bool override)<br>
> {<br>
> - u32 tmp, data;<br>
> -<br>
> - tmp = data = RREG32(mmVCE_RB_ARB_CTRL);<br>
> - if (override)<br>
> - data |= VCE_RB_ARB_CTRL__VCE_CGTT_OVERRIDE_MASK;<br>
> - else<br>
> - data &=<br>
> ~VCE_RB_ARB_CTRL__VCE_CGTT_OVERRIDE_MASK;<br>
> -<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_RB_ARB_CTRL, data);<br>
> + WREG32_FIELD(VCE_RB_ARB_CTRL, VCE_CGTT_OVERRIDE, override<br>
> ? 1 : 0);<br>
> }<br>
> <br>
> static void vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device<br>
> *adev,<br>
> bool gated)<br>
> {<br>
> - u32 tmp, data;<br>
> + u32 data;<br>
> <br>
> /* Set Override to disable Clock Gating */<br>
> vce_v3_0_override_vce_clock_gating(adev, true);<br>
> @@ -136,65 +127,55 @@ static void<br>
> vce_v3_0_set_vce_sw_clock_gating(struct amdgpu_device *adev,<br>
> fly as necessary.<br>
> */<br>
> if (gated) {<br>
> - tmp = data = RREG32(mmVCE_CLOCK_GATING_B);<br>
> + data = RREG32(mmVCE_CLOCK_GATING_B);<br>
> data |= 0x1ff;<br>
> data &= ~0xef0000;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_CLOCK_GATING_B, data);<br>
> + WREG32(mmVCE_CLOCK_GATING_B, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_CLOCK_GATING);<br>
> + data = RREG32(mmVCE_UENC_CLOCK_GATING);<br>
> data |= 0x3ff000;<br>
> data &= ~0xffc00000;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_CLOCK_GATING, data);<br>
> + WREG32(mmVCE_UENC_CLOCK_GATING, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_CLOCK_GATING_2);<br>
> + data = RREG32(mmVCE_UENC_CLOCK_GATING_2);<br>
> data |= 0x2;<br>
> data &= ~0x00010000;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_CLOCK_GATING_2, data);<br>
> + WREG32(mmVCE_UENC_CLOCK_GATING_2, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);<br>
> + data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);<br>
> data |= 0x37f;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_REG_CLOCK_GATING,<br>
> data);<br>
> + WREG32(mmVCE_UENC_REG_CLOCK_GATING, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);<br>
> + data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);<br>
> data |=<br>
> VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK |<br>
> <br>
> VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK |<br>
> <br>
> VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK |<br>
> 0x8;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);<br>
> + WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);<br>
> } else {<br>
> - tmp = data = RREG32(mmVCE_CLOCK_GATING_B);<br>
> + data = RREG32(mmVCE_CLOCK_GATING_B);<br>
> data &= ~0x80010;<br>
> data |= 0xe70008;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_CLOCK_GATING_B, data);<br>
> + WREG32(mmVCE_CLOCK_GATING_B, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_CLOCK_GATING);<br>
> + data = RREG32(mmVCE_UENC_CLOCK_GATING);<br>
> data |= 0xffc00000;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_CLOCK_GATING, data);<br>
> + WREG32(mmVCE_UENC_CLOCK_GATING, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_CLOCK_GATING_2);<br>
> + data = RREG32(mmVCE_UENC_CLOCK_GATING_2);<br>
> data |= 0x10000;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_CLOCK_GATING_2, data);<br>
> + WREG32(mmVCE_UENC_CLOCK_GATING_2, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);<br>
> + data = RREG32(mmVCE_UENC_REG_CLOCK_GATING);<br>
> data &= ~0xffc00000;<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_REG_CLOCK_GATING,<br>
> data);<br>
> + WREG32(mmVCE_UENC_REG_CLOCK_GATING, data);<br>
> <br>
> - tmp = data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);<br>
> + data = RREG32(mmVCE_UENC_DMA_DCLK_CTRL);<br>
> data &=<br>
> ~(VCE_UENC_DMA_DCLK_CTRL__WRDMCLK_FORCEON_MASK |<br>
> <br>
> VCE_UENC_DMA_DCLK_CTRL__RDDMCLK_FORCEON_MASK |<br>
> <br>
> VCE_UENC_DMA_DCLK_CTRL__REGCLK_FORCEON_MASK |<br>
> 0x8);<br>
> - if (tmp != data)<br>
> - WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);<br>
> + WREG32(mmVCE_UENC_DMA_DCLK_CTRL, data);<br>
> }<br>
> vce_v3_0_override_vce_clock_gating(adev, false);<br>
> }<br>
> @@ -213,12 +194,9 @@ static int vce_v3_0_firmware_loaded(struct<br>
> amdgpu_device *adev)<br>
> }<br>
> <br>
> DRM_ERROR("VCE not responding, trying to reset the<br>
> 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>
> + WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);<br>
> mdelay(10);<br>
> - WREG32_P(mmVCE_SOFT_RESET, 0,<br>
> - ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> + WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);<br>
> mdelay(10);<br>
> }<br>
> <br>
> @@ -256,34 +234,22 @@ static int vce_v3_0_start(struct amdgpu_device<br>
> *adev)<br>
> if (adev->vce.harvest_config & (1 << idx))<br>
> continue;<br>
> <br>
> - if (idx == 0)<br>
> - WREG32_P(mmGRBM_GFX_INDEX, 0,<br>
> -<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> - else<br>
> - WREG32_P(mmGRBM_GFX_INDEX,<br>
> - GRBM_GFX_INDEX__VCE_INSTANCE_MASK,<br>
> -<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> -<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, idx);<br>
> vce_v3_0_mc_resume(adev, idx);<br>
> -<br>
> - WREG32_P(mmVCE_STATUS,<br>
> VCE_STATUS__JOB_BUSY_MASK,<br>
> - ~VCE_STATUS__JOB_BUSY_MASK);<br>
> + WREG32_FIELD(VCE_STATUS, JOB_BUSY, 1);<br>
> <br>
> if (adev->asic_type >= CHIP_STONEY)<br>
> WREG32_P(mmVCE_VCPU_CNTL, 1, ~0x200001);<br>
> else<br>
> - WREG32_P(mmVCE_VCPU_CNTL,<br>
> VCE_VCPU_CNTL__CLK_EN_MASK,<br>
> - ~VCE_VCPU_CNTL__CLK_EN_MASK);<br>
> -<br>
> - WREG32_P(mmVCE_SOFT_RESET, 0,<br>
> - ~VCE_SOFT_RESET__ECPU_SOFT_RESET_MASK);<br>
> + WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 1);<br>
> <br>
> + WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 0);<br>
> mdelay(100);<br>
> <br>
> r = vce_v3_0_firmware_loaded(adev);<br>
> <br>
> /* clear BUSY flag */<br>
> - WREG32_P(mmVCE_STATUS, 0,<br>
> ~VCE_STATUS__JOB_BUSY_MASK);<br>
> + WREG32_FIELD(VCE_STATUS, JOB_BUSY, 0);<br>
> <br>
> if (r) {<br>
> DRM_ERROR("VCE not responding, giving up!!!\n");<br>
> @@ -292,7 +258,7 @@ static int vce_v3_0_start(struct amdgpu_device<br>
> *adev)<br>
> }<br>
> }<br>
> <br>
> - WREG32_P(mmGRBM_GFX_INDEX, 0,<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, 0);<br>
> mutex_unlock(&adev->grbm_idx_mutex);<br>
> <br>
> return 0;<br>
> @@ -307,33 +273,25 @@ static int vce_v3_0_stop(struct amdgpu_device<br>
> *adev)<br>
> if (adev->vce.harvest_config & (1 << idx))<br>
> continue;<br>
> <br>
> - if (idx == 0)<br>
> - WREG32_P(mmGRBM_GFX_INDEX, 0,<br>
> -<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> - else<br>
> - WREG32_P(mmGRBM_GFX_INDEX,<br>
> - GRBM_GFX_INDEX__VCE_INSTANCE_MASK,<br>
> -<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, idx);<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>
> + WREG32_FIELD(VCE_VCPU_CNTL, CLK_EN, 0);<br>
> +<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>
> + WREG32_FIELD(VCE_SOFT_RESET, ECPU_SOFT_RESET, 1);<br>
> <br>
> /* clear BUSY flag */<br>
> - WREG32_P(mmVCE_STATUS, 0,<br>
> ~VCE_STATUS__JOB_BUSY_MASK);<br>
> + WREG32_FIELD(VCE_STATUS, JOB_BUSY, 0);<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,<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, 0);<br>
> mutex_unlock(&adev->grbm_idx_mutex);<br>
> <br>
> return 0;<br>
> @@ -561,9 +519,7 @@ static void vce_v3_0_mc_resume(struct<br>
> amdgpu_device *adev, int idx)<br>
> }<br>
> <br>
> WREG32_P(mmVCE_LMI_CTRL2, 0x0, ~0x100);<br>
> -<br>
> - WREG32_P(mmVCE_SYS_INT_EN,<br>
> VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK,<br>
> -<br>
> ~VCE_SYS_INT_EN__VCE_SYS_INT_TRAP_INTERRUPT_EN_MASK);<br>
> + WREG32_FIELD(VCE_SYS_INT_EN,<br>
> VCE_SYS_INT_TRAP_INTERRUPT_EN, 1);<br>
> }<br>
> <br>
> static bool vce_v3_0_is_idle(void *handle)<br>
> @@ -599,7 +555,6 @@ static int vce_v3_0_check_soft_reset(void *handle)<br>
> {<br>
> struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
> u32 srbm_soft_reset = 0;<br>
> - u32 tmp;<br>
> <br>
> /* According to VCE team , we should use VCE_STATUS instead<br>
> * SRBM_STATUS.VCE_BUSY bit for busy status checking.<br>
> @@ -614,23 +569,17 @@ static int vce_v3_0_check_soft_reset(void<br>
> *handle)<br>
> *<br>
> * VCE team suggest use bit 3--bit 6 for busy status check<br>
> */<br>
> - tmp = RREG32(mmGRBM_GFX_INDEX);<br>
> - tmp = REG_SET_FIELD(tmp, GRBM_GFX_INDEX, INSTANCE_INDEX,<br>
> 0);<br>
> - WREG32(mmGRBM_GFX_INDEX, tmp);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, INSTANCE_INDEX, 0);<br>
> if (RREG32(mmVCE_STATUS) &<br>
> AMDGPU_VCE_STATUS_BUSY_MASK) {<br>
> srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,<br>
> SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);<br>
> srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,<br>
> SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);<br>
> }<br>
> - tmp = RREG32(mmGRBM_GFX_INDEX);<br>
> - tmp = REG_SET_FIELD(tmp, GRBM_GFX_INDEX, INSTANCE_INDEX,<br>
> 0x10);<br>
> - WREG32(mmGRBM_GFX_INDEX, tmp);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, INSTANCE_INDEX, 0x10);<br>
> if (RREG32(mmVCE_STATUS) &<br>
> AMDGPU_VCE_STATUS_BUSY_MASK) {<br>
> srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,<br>
> SRBM_SOFT_RESET, SOFT_RESET_VCE0, 1);<br>
> srbm_soft_reset = REG_SET_FIELD(srbm_soft_reset,<br>
> SRBM_SOFT_RESET, SOFT_RESET_VCE1, 1);<br>
> }<br>
> - tmp = RREG32(mmGRBM_GFX_INDEX);<br>
> - tmp = REG_SET_FIELD(tmp, GRBM_GFX_INDEX, INSTANCE_INDEX,<br>
> 0);<br>
> - WREG32(mmGRBM_GFX_INDEX, tmp);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, INSTANCE_INDEX, 0);<br>
> <br>
> if (srbm_soft_reset) {<br>
> adev->ip_block_status[AMD_IP_BLOCK_TYPE_VCE].hang =<br>
> true;<br>
> @@ -718,9 +667,7 @@ static int vce_v3_0_process_interrupt(struct<br>
> amdgpu_device *adev,<br>
> {<br>
> DRM_DEBUG("IH: VCE\n");<br>
> <br>
> - WREG32_P(mmVCE_SYS_INT_STATUS,<br>
> -<br>
> VCE_SYS_INT_STATUS__VCE_SYS_INT_TRAP_INTERRUPT_INT_MAS<br>
> K,<br>
> -<br>
> ~VCE_SYS_INT_STATUS__VCE_SYS_INT_TRAP_INTERRUPT_INT_MA<br>
> SK);<br>
> + WREG32_FIELD(VCE_SYS_INT_STATUS,<br>
> VCE_SYS_INT_TRAP_INTERRUPT_INT, 1);<br>
> <br>
> switch (entry->src_data) {<br>
> case 0:<br>
> @@ -767,13 +714,7 @@ static int vce_v3_0_set_clockgating_state(void<br>
> *handle,<br>
> if (adev->vce.harvest_config & (1 << i))<br>
> continue;<br>
> <br>
> - if (i == 0)<br>
> - WREG32_P(mmGRBM_GFX_INDEX, 0,<br>
> -<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> - else<br>
> - WREG32_P(mmGRBM_GFX_INDEX,<br>
> -<br>
> GRBM_GFX_INDEX__VCE_INSTANCE_MASK,<br>
> -<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, i);<br>
> <br>
> if (enable) {<br>
> /* initialize VCE_CLOCK_GATING_A: Clock ON/OFF<br>
> delay */<br>
> @@ -792,7 +733,7 @@ static int vce_v3_0_set_clockgating_state(void<br>
> *handle,<br>
> vce_v3_0_set_vce_sw_clock_gating(adev, enable);<br>
> }<br>
> <br>
> - WREG32_P(mmGRBM_GFX_INDEX, 0,<br>
> ~GRBM_GFX_INDEX__VCE_INSTANCE_MASK);<br>
> + WREG32_FIELD(GRBM_GFX_INDEX, VCE_INSTANCE, 0);<br>
> mutex_unlock(&adev->grbm_idx_mutex);<br>
> <br>
> return 0;<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>
</div>
</span></font></div>
</div>
</body>
</html>