Unify to set pg/cg state when suspend/fini
Subsystems (2)
cover Unify to set pg/cg state when suspend/fini
Unify to set power ungate and clock ungate state when suspend/fini. Just corresponding to the sequence of set cg pg gate state in late_init.
Tested on Tonga/Raven(gfx off enabled/disabled)
S3 test was passed 30 times.
Rex Zhu (3):
drm/amdgpu: Refine function name and function args drm/amdgpu: Set power ungate state before suspend/fini drm/amdgpu: Set clock ungate state before suspend/fini
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 104 ++++++++--------------------- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 4 -- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 19 ++++-- 3 files changed, 40 insertions(+), 87 deletions(-)
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1534240585-7557-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org
PATCH 1/3 drm/amdgpu: Refine function name and function args
there is no logical change in this patch.
1. change function names:
amdgpu_device_ip_late_set_pg/cg_state to amdgpu_device_set_pg/cg_state.
2. add a function argument cg/pg_state, so
we can enable/disable cg/pg through those functions
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 39 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +19 -20
@@ -1690,24 +1690,26 @@ static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev) }/** -* amdgpu_device_ip_late_set_cg_state - late init for clockgating +* amdgpu_device_set_cg_state - set clockgating for amdgpu device * * @adev: amdgpu_device pointer * -* Late initialization pass enabling clockgating for hardware IPs. * The list of all the hardware IPs that make up the asic is walked and the -* set_clockgating_state callbacks are run. This stage is run late -* in the init process. +* set_clockgating_state callbacks are run. +* Late initialization pass enabling clockgating for hardware IPs. +* Fini or suspend, pass disabling clockgating for hardware IPs. * Returns 0 on success, negative error code on failure. */ -static int amdgpu_device_ip_late_set_cg_state (struct amdgpu_device *adev) +static int amdgpu_device_set_cg_state (struct amdgpu_device *adev, +enum amd_clockgating_state state) { -int i =0 , r; +int i, j, r;if (amdgpu_emu_mode ==1 )return 0 ; -for (i =0 ; i < adev->num_ip_blocks; i++) { +for (j =0 ; j < adev->num_ip_blocks; j++) { + i = state ==AMD_CG_STATE_GATE ? j : adev->num_ip_blocks - j -1 ;if (!adev->ip_blocks[i].status.valid)continue ;/* skip CG for VCE/UVD, it's handled specially */
@@ -1717,7 +1719,7 @@ static int amdgpu_device_ip_late_set_cg_state(struct amdgpu_device *adev) adev->ip_blocks[i].version->funcs->set_clockgating_state) {/* enable clockgating to save power */ r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_GATE ); + state);if (r) {DRM_ERROR ("set_clockgating_state(gate) of IP block <%s> failed %d\n" , adev->ip_blocks[i].version->funcs->name, r);
@@ -1729,14 +1731,15 @@ static int amdgpu_device_ip_late_set_cg_state(struct amdgpu_device *adev)return 0 ; } -static int amdgpu_device_ip_late_set_pg_state (struct amdgpu_device *adev) +static int amdgpu_device_set_pg_state (struct amdgpu_device *adev,enum amd_powergating_state state) { -int i =0 , r; +int i, j, r;if (amdgpu_emu_mode ==1 )return 0 ; -for (i =0 ; i < adev->num_ip_blocks; i++) { +for (j =0 ; j < adev->num_ip_blocks; j++) { + i = state ==AMD_PG_STATE_GATE ? j : adev->num_ip_blocks - j -1 ;if (!adev->ip_blocks[i].status.valid)continue ;/* skip CG for VCE/UVD, it's handled specially */
@@ -1746,7 +1749,7 @@ static int amdgpu_device_ip_late_set_pg_state(struct amdgpu_device *adev) adev->ip_blocks[i].version->funcs->set_powergating_state) {/* enable powergating to save power */ r = adev->ip_blocks[i].version->funcs->set_powergating_state ((void *)adev, -AMD_PG_STATE_GATE ); + state);if (r) {DRM_ERROR ("set_powergating_state(gate) of IP block <%s> failed %d\n" , adev->ip_blocks[i].version->funcs->name, r);
@@ -1787,8 +1790,8 @@ static int amdgpu_device_ip_late_init(struct amdgpu_device *adev) } } -amdgpu_device_ip_late_set_cg_state (adev); -amdgpu_device_ip_late_set_pg_state (adev); +amdgpu_device_set_cg_state (adev,AMD_CG_STATE_GATE ); +amdgpu_device_set_pg_state (adev,AMD_PG_STATE_GATE );queue_delayed_work (system_wq, &adev->late_init_work,msecs_to_jiffies (AMDGPU_RESUME_MS ));
@@ -1906,13 +1909,9 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev) }/** -* amdgpu_device_ip_late_init_func_handler - work handler for clockgating -* -* @work: work_struct +* amdgpu_device_ip_late_init_func_handler - work handler for ib test * -* Work handler for amdgpu_device_ip_late_set_cg_state. We put the -* clockgating setup into a worker thread to speed up driver init and -* resume from suspend. +* @work: work_struct. */ static void amdgpu_device_ip_late_init_func_handler (struct work_struct *work) {
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/3 drm/amdgpu: Set power ungate state before suspend/fini
In reply to a message not in the archiveUnify to set power ungate state before suspend/fini. Remove the workaround code for gfx off feature in amdgpu_device.c.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 11 +++++------ drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 4 ---- drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -6
@@ -1817,6 +1817,8 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)int i, r;amdgpu_amdkfd_device_fini (adev); + +amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE );/* need to disable SMC first */ for (i =0 ; i < adev->num_ip_blocks; i++) {if (!adev->ip_blocks[i].status.hw)
@@ -1831,8 +1833,7 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev) adev->ip_blocks[i].version->funcs->name, r);return r; } -amdgpu_gfx_off_ctrl (adev, false); -cancel_delayed_work_sync (&adev->gfx.gfx_off_delay_work); + r = adev->ip_blocks[i].version->funcs->hw_fini ((void *)adev);/* XXX handle errors */ if (r) {
@@ -1955,6 +1956,8 @@ static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)if (amdgpu_sriov_vf (adev))amdgpu_virt_request_full_gpu (adev, false); +amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE ); +for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) {if (!adev->ip_blocks[i].status.valid)continue ;
@@ -2010,10 +2013,6 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)DRM_ERROR ("set_clockgating_state(ungate) SMC failed %d\n" , r); } -/* call smu to disable gfx off feature first when suspend */ -amdgpu_gfx_off_ctrl (adev, false); -cancel_delayed_work_sync (&adev->gfx.gfx_off_delay_work); -for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) {if (!adev->ip_blocks[i].status.valid)continue ;
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +0 -4
@@ -5164,10 +5164,6 @@ static int gfx_v8_0_hw_fini(void *handle)gfx_v8_0_cp_enable (adev, false);gfx_v8_0_rlc_stop (adev); -amdgpu_device_ip_set_powergating_state (adev, -AMD_IP_BLOCK_TYPE_GFX , -AMD_PG_STATE_UNGATE ); -return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +12 -7
@@ -3242,9 +3242,6 @@ static int gfx_v9_0_hw_fini(void *handle)struct amdgpu_device *adev = (struct amdgpu_device *)handle;int i; -amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_GFX , -AMD_PG_STATE_UNGATE ); -amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );
@@ -3763,6 +3760,10 @@ static int gfx_v9_0_set_powergating_state(void *handle,switch (adev->asic_type) {case CHIP_RAVEN : +if (!enable) { +amdgpu_gfx_off_ctrl (adev, false); +cancel_delayed_work_sync (&adev->gfx.gfx_off_delay_work); + }if (adev->pg_flags &AMD_PG_SUPPORT_RLC_SMU_HS ) {gfx_v9_0_enable_sck_slow_down_on_power_up (adev, true);gfx_v9_0_enable_sck_slow_down_on_power_down (adev, true);
@@ -3782,12 +3783,16 @@ static int gfx_v9_0_set_powergating_state(void *handle,/* update mgcg state */ gfx_v9_0_update_gfx_mg_power_gating (adev, enable); -/* set gfx off through smu */ -amdgpu_gfx_off_ctrl (adev, true); +if (enable) +amdgpu_gfx_off_ctrl (adev, true);break ;case CHIP_VEGA12 : -/* set gfx off through smu */ -amdgpu_gfx_off_ctrl (adev, true); +if (!enable) { +amdgpu_gfx_off_ctrl (adev, false); +cancel_delayed_work_sync (&adev->gfx.gfx_off_delay_work); + }else { +amdgpu_gfx_off_ctrl (adev, true); + }break ;default :break ;
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: Set clock ungate state before suspend/fini
In reply to a message not in the archiveAfter set power ungate state, set clock ungate state before driver suspend or fini.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 56 +++--------------------------- 1 file changed, 5 insertions(+), 51 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -51
@@ -1700,6 +1700,7 @@ static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)* Fini or suspend, pass disabling clockgating for hardware IPs. * Returns 0 on success, negative error code on failure. */ +static int amdgpu_device_set_cg_state (struct amdgpu_device *adev,enum amd_clockgating_state state) {
@@ -1819,21 +1820,13 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)amdgpu_amdkfd_device_fini (adev);amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE ); +amdgpu_device_set_cg_state (adev,AMD_CG_STATE_UNGATE ); +/* need to disable SMC first */ for (i =0 ; i < adev->num_ip_blocks; i++) {if (!adev->ip_blocks[i].status.hw)continue ; -if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_SMC && - adev->ip_blocks[i].version->funcs->set_clockgating_state) { -/* ungate blocks before hw fini so that we can shutdown the blocks safely */ - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); -return r; - } - +if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_SMC ) { r = adev->ip_blocks[i].version->funcs->hw_fini ((void *)adev);/* XXX handle errors */ if (r) {
@@ -1849,20 +1842,6 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)if (!adev->ip_blocks[i].status.hw)continue ; -if (adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_UVD && - adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_VCE && - adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_VCN && - adev->ip_blocks[i].version->funcs->set_clockgating_state) { -/* ungate blocks before hw fini so that we can shutdown the blocks safely */ - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); -return r; - } - } - r = adev->ip_blocks[i].version->funcs->hw_fini ((void *)adev);/* XXX handle errors */ if (r) {
@@ -1957,21 +1936,13 @@ static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)amdgpu_virt_request_full_gpu (adev, false);amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE ); +amdgpu_device_set_cg_state (adev,AMD_CG_STATE_UNGATE );for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) {if (!adev->ip_blocks[i].status.valid)continue ;/* displays are handled separately */ if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_DCE ) { -/* ungate blocks so that suspend can properly shut them down */ -if (adev->ip_blocks[i].version->funcs->set_clockgating_state) { - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); - } - }/* XXX handle errors */ r = adev->ip_blocks[i].version->funcs->suspend (adev);/* XXX handle errors */
@@ -2006,29 +1977,12 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)if (amdgpu_sriov_vf (adev))amdgpu_virt_request_full_gpu (adev, false); -/* ungate SMC block first */ - r =amdgpu_device_ip_set_clockgating_state (adev,AMD_IP_BLOCK_TYPE_SMC , -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) SMC failed %d\n" , r); - } -for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) {if (!adev->ip_blocks[i].status.valid)continue ;/* displays are handled in phase1 */ if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_DCE )continue ; -/* ungate blocks so that suspend can properly shut them down */ -if (adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_SMC && - adev->ip_blocks[i].version->funcs->set_clockgating_state) { - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); - } - }/* XXX handle errors */ r = adev->ip_blocks[i].version->funcs->suspend (adev);/* XXX handle errors */
Signature · 6 lines
1.9.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1534240585-7557-4-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org
Alex Deucher
Reviewed-byRe: [PATCH 3/3] drm/amdgpu: Set clock ungate state before suspend/fini
Quoted 5 lines · Rex Zhu
After set power ungate state, set clock ungate state before driver suspend or fini.
Signed-off-by Rex Zhu <[email protected]>
Nice cleanup! Series is:
Quoted 118 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 56 +++--------------------------- 1 file changed, 5 insertions(+), 51 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-52@@ -1700,6 +1700,7 @@ static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)* Fini or suspend, pass disabling clockgating for hardware IPs. * Returns 0 on success, negative error code on failure. */ +static int amdgpu_device_set_cg_state (struct amdgpu_device *adev,enum amd_clockgating_state state) {@@ -1819,21 +1820,13 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)amdgpu_amdkfd_device_fini (adev);amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE ); +amdgpu_device_set_cg_state (adev,AMD_CG_STATE_UNGATE ); +/* need to disable SMC first */ for (i =0 ; i < adev->num_ip_blocks; i++) {if (!adev->ip_blocks[i].status.hw)continue ; -if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_SMC && - adev->ip_blocks[i].version->funcs->set_clockgating_state) { -/* ungate blocks before hw fini so that we can shutdown the blocks safely */ - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); -return r; - } - +if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_SMC ) { r = adev->ip_blocks[i].version->funcs->hw_fini ((void *)adev);/* XXX handle errors */ if (r) {@@ -1849,20 +1842,6 @@ static int amdgpu_device_ip_fini(struct amdgpu_device *adev)if (!adev->ip_blocks[i].status.hw)continue ; -if (adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_UVD && - adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_VCE && - adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_VCN && - adev->ip_blocks[i].version->funcs->set_clockgating_state) { -/* ungate blocks before hw fini so that we can shutdown the blocks safely */ - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); -return r; - } - } - r = adev->ip_blocks[i].version->funcs->hw_fini ((void *)adev);/* XXX handle errors */ if (r) {@@ -1957,21 +1936,13 @@ static int amdgpu_device_ip_suspend_phase1(struct amdgpu_device *adev)amdgpu_virt_request_full_gpu (adev, false);amdgpu_device_set_pg_state (adev,AMD_PG_STATE_UNGATE ); +amdgpu_device_set_cg_state (adev,AMD_CG_STATE_UNGATE );for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) {if (!adev->ip_blocks[i].status.valid)continue ;/* displays are handled separately */ if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_DCE ) { -/* ungate blocks so that suspend can properly shut them down */ -if (adev->ip_blocks[i].version->funcs->set_clockgating_state) { - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); - } - }/* XXX handle errors */ r = adev->ip_blocks[i].version->funcs->suspend (adev);/* XXX handle errors */ @@ -2006,29 +1977,12 @@ static int amdgpu_device_ip_suspend_phase2(struct amdgpu_device *adev)if (amdgpu_sriov_vf (adev))amdgpu_virt_request_full_gpu (adev, false); -/* ungate SMC block first */ - r =amdgpu_device_ip_set_clockgating_state (adev,AMD_IP_BLOCK_TYPE_SMC , -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) SMC failed %d\n" , r); - } -for (i = adev->num_ip_blocks -1 ; i >=0 ; i--) {if (!adev->ip_blocks[i].status.valid)continue ;/* displays are handled in phase1 */ if (adev->ip_blocks[i].version->type ==AMD_IP_BLOCK_TYPE_DCE )continue ; -/* ungate blocks so that suspend can properly shut them down */ -if (adev->ip_blocks[i].version->type !=AMD_IP_BLOCK_TYPE_SMC && - adev->ip_blocks[i].version->funcs->set_clockgating_state) { - r = adev->ip_blocks[i].version->funcs->set_clockgating_state ((void *)adev, -AMD_CG_STATE_UNGATE ); -if (r) { -DRM_ERROR ("set_clockgating_state(ungate) of IP block <%s> failed %d\n" , - adev->ip_blocks[i].version->funcs->name, r); - } - }/* XXX handle errors */ r = adev->ip_blocks[i].version->funcs->suspend (adev);/* XXX handle errors */ --1.9.1
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx