drm/amd/powerplay: optimize amdgpu_dpm_set_clockgating_by_smu() implementation
Subsystems (2)
PATCH 1/4 drm/amd/powerplay: optimize amdgpu_dpm_set_clockgating_by_smu() implementation
Cover the implementation details from outside(of power part).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 15 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 7 +++---- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 21 +++++++-------------- drivers/gpu/drm/amd/amdgpu/vi.c | 21 +++++++-------------- 4 files changed, 32 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +15 -0
@@ -1232,3 +1232,18 @@ int amdgpu_dpm_enable_mgpu_fan_boost(struct amdgpu_device *adev)return ret; } + +int amdgpu_dpm_set_clockgating_by_smu (struct amdgpu_device *adev, +uint32_t msg_id) +{ +void *pp_handle = adev->powerplay.pp_handle; +const struct amd_pm_funcs *pp_funcs = + adev->powerplay.pp_funcs; +int ret =0 ; + +if (pp_funcs && pp_funcs->set_clockgating_by_smu) + ret = pp_funcs->set_clockgating_by_smu (pp_handle, + msg_id); + +return ret; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +3 -4
@@ -341,10 +341,6 @@ enum amdgpu_pcie_gen { ((adev)->powerplay.pp_funcs->reset_power_profile_state (\ (adev)->powerplay.pp_handle, request)) -#define amdgpu_dpm_set_clockgating_by_smu (adev, msg_id) \ - ((adev)->powerplay.pp_funcs->set_clockgating_by_smu(\ - (adev)->powerplay.pp_handle, msg_id)) -#define amdgpu_dpm_get_power_profile_mode (adev, buf) \ ((adev)->powerplay.pp_funcs->get_power_profile_mode(\ (adev)->powerplay.pp_handle, buf))
@@ -546,4 +542,7 @@ int amdgpu_dpm_allow_xgmi_power_down(struct amdgpu_device *adev, bool en);int amdgpu_dpm_enable_mgpu_fan_boost (struct amdgpu_device *adev); +int amdgpu_dpm_set_clockgating_by_smu (struct amdgpu_device *adev, +uint32_t msg_id); +#endif
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +7 -14
@@ -5880,8 +5880,7 @@ static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_CG , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG |AMD_CG_SUPPORT_GFX_MGLS )) {
@@ -5902,8 +5901,7 @@ static int gfx_v8_0_tonga_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_MG , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }return 0 ;
@@ -5932,8 +5930,7 @@ static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_CG , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_3D_CGCG |AMD_CG_SUPPORT_GFX_3D_CGLS )) {
@@ -5952,8 +5949,7 @@ static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_3D , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags & (AMD_CG_SUPPORT_GFX_MGCG |AMD_CG_SUPPORT_GFX_MGLS )) {
@@ -5974,8 +5970,7 @@ static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_MG , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags &AMD_CG_SUPPORT_GFX_RLC_LS ) {
@@ -5990,8 +5985,7 @@ static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_RLC , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags &AMD_CG_SUPPORT_GFX_CP_LS ) {
@@ -6005,8 +5999,7 @@ static int gfx_v8_0_polaris_update_gfx_clock_gating(struct amdgpu_device *adev,PP_BLOCK_GFX_CP , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }return 0 ;
drivers/gpu/drm/amd/amdgpu/vi.c +7 -14
@@ -1507,8 +1507,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_MC , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags & (AMD_CG_SUPPORT_SDMA_LS |AMD_CG_SUPPORT_SDMA_MGCG )) {
@@ -1526,8 +1525,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_SDMA , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS |AMD_CG_SUPPORT_HDP_MGCG )) {
@@ -1545,8 +1543,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_HDP , pp_support_state, pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }
@@ -1560,8 +1557,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_BIF ,PP_STATE_SUPPORT_LS , pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags &AMD_CG_SUPPORT_BIF_MGCG ) {if (state ==AMD_CG_STATE_UNGATE )
@@ -1573,8 +1569,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_BIF ,PP_STATE_SUPPORT_CG , pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags &AMD_CG_SUPPORT_DRM_LS ) {
@@ -1588,8 +1583,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_DRM ,PP_STATE_SUPPORT_LS , pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }if (adev->cg_flags &AMD_CG_SUPPORT_ROM_MGCG ) {
@@ -1603,8 +1597,7 @@ static int vi_common_set_clockgating_state_by_smu(void *handle,PP_BLOCK_SYS_ROM ,PP_STATE_SUPPORT_CG , pp_state); -if (adev->powerplay.pp_funcs->set_clockgating_by_smu) -amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); +amdgpu_dpm_set_clockgating_by_smu (adev, msg_id); }return 0 ; }
Signature · 6 lines
2.28.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/4 drm/amd/powerplay: drop unnecessary pp_funcs checker
It's redundant. Also, the callers should not care about the implementation details.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 11 +++-------- drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c | 3 +-- 3 files changed, 6 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c +3 -8
@@ -136,9 +136,7 @@ static int acp_poweroff(struct generic_pm_domain *genpd)* 2. power off the acp tiles * 3. check and enter ulv state */ -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->set_powergating_by_smu) -amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_ACP , true); +amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_ACP , true); }return 0 ; }
@@ -157,8 +155,7 @@ static int acp_poweron(struct generic_pm_domain *genpd)* 2. turn on acp clock * 3. power on acp tiles */ -if (adev->powerplay.pp_funcs->set_powergating_by_smu) -amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_ACP , false); +amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_ACP , false); }return 0 ; }
@@ -529,9 +526,7 @@ static int acp_set_powergating_state(void *handle,struct amdgpu_device *adev = (struct amdgpu_device *)handle;bool enable = (state ==AMD_PG_STATE_GATE ); -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->set_powergating_by_smu) -amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_ACP , enable); +amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_ACP , enable);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +2 -3
@@ -5343,10 +5343,9 @@ static int gfx_v8_0_late_init(void *handle)static void gfx_v8_0_enable_gfx_static_mg_power_gating (struct amdgpu_device *adev,bool enable) { -if (((adev->asic_type ==CHIP_POLARIS11 ) || +if ((adev->asic_type ==CHIP_POLARIS11 ) || (adev->asic_type ==CHIP_POLARIS12 ) || - (adev->asic_type ==CHIP_VEGAM )) && - adev->powerplay.pp_funcs->set_powergating_by_smu) + (adev->asic_type ==CHIP_VEGAM ))/* Send msg to SMU via Powerplay */ amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_GFX , enable);
drivers/gpu/drm/amd/amdgpu/mmhub_v1_0.c +1 -2
@@ -304,8 +304,7 @@ static void mmhub_v1_0_update_power_gating(struct amdgpu_device *adev,return ;if (enable && adev->pg_flags &AMD_PG_SUPPORT_MMHUB ) { -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_powergating_by_smu) -amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_GMC , true); +amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_GMC , true); } }
Signature · 6 lines
2.28.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm/amd/powerplay: optimize i2c bus access implementation
In reply to Evan QuanThe caller needs not care about the internal details how the powerplay API implemented.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 15 +++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 3 +++ drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c | 15 ++------------- 3 files changed, 20 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +15 -0
@@ -1247,3 +1247,18 @@ int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,return ret; } + +int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev, +bool acquire) +{ +void *pp_handle = adev->powerplay.pp_handle; +const struct amd_pm_funcs *pp_funcs = + adev->powerplay.pp_funcs; +int ret = -EOPNOTSUPP ; + +if (pp_funcs && pp_funcs->smu_i2c_bus_access) + ret = pp_funcs->smu_i2c_bus_access (pp_handle, + acquire); + +return ret; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +3 -0
@@ -545,4 +545,7 @@ int amdgpu_dpm_enable_mgpu_fan_boost(struct amdgpu_device *adev);int amdgpu_dpm_set_clockgating_by_smu (struct amdgpu_device *adev,uint32_t msg_id); +int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev, +bool acquire); +#endif
drivers/gpu/drm/amd/amdgpu/smu_v11_0_i2c.c +2 -13
@@ -508,14 +508,9 @@ static bool smu_v11_0_i2c_bus_lock(struct i2c_adapter *control)struct amdgpu_device *adev =to_amdgpu_device (control);/* Send PPSMC_MSG_RequestI2CBus */ -if (!adev->powerplay.pp_funcs->smu_i2c_bus_access) - goto Fail; - - -if (!adev->powerplay.pp_funcs->smu_i2c_bus_access (adev->powerplay.pp_handle, true)) +if (!amdgpu_dpm_smu_i2c_bus_access (adev, true))return true; -Fail:return false; }
@@ -523,16 +518,10 @@ static bool smu_v11_0_i2c_bus_unlock(struct i2c_adapter *control) {struct amdgpu_device *adev =to_amdgpu_device (control); -/* Send PPSMC_MSG_RequestI2CBus */ -if (!adev->powerplay.pp_funcs->smu_i2c_bus_access) - goto Fail; -/* Send PPSMC_MSG_ReleaseI2CBus */ -if (!adev->powerplay.pp_funcs->smu_i2c_bus_access (adev->powerplay.pp_handle, - false)) +if (!amdgpu_dpm_smu_i2c_bus_access (adev, false))return true; -Fail:return false; }
Signature · 6 lines
2.28.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amd/powerplay: put those exposed power interfaces in amdgpu_dpm.c
In reply to Evan QuanAs other power interfaces.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 425 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 14 + drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 423 ----------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h | 8 - 4 files changed, 439 insertions(+), 431 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +425 -0
@@ -28,6 +28,11 @@#include "amdgpu_dpm.h" #include "atom.h" #include "amd_pcie.h" +#include "amdgpu_display.h" +#include "hwmgr.h" +#include <linux/power_supply.h> + +#define WIDTH_4K 3840void amdgpu_dpm_print_class_info (u32 class,u32 class2) {
@@ -1262,3 +1267,423 @@ int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev,return ret; } + +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) +{ +if (adev->pm.dpm_enabled) { +mutex_lock (&adev->pm.mutex); +if (power_supply_is_system_supplied () >0 ) + adev->pm.ac_power = true; +else + adev->pm.ac_power = false; +if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->enable_bapm) +amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); +mutex_unlock (&adev->pm.mutex); + +if (is_support_sw_smu (adev)) +smu_set_ac_dc (&adev->smu); + } +} + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size) +{ +int ret =0 ; + +if (!data || !size) +return -EINVAL ; + +if (is_support_sw_smu (adev)) + ret =smu_read_sensor (&adev->smu, sensor, data, size); +else { +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) + ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, + sensor, data, size); +else + ret = -EINVAL ; + } + +return ret; +} + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work) +{ +struct amdgpu_device *adev = + container_of(work, struct amdgpu_device, + pm.dpm.thermal.work); +/* switch to the thermal state */ +enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; +int temp, size =sizeof (temp); + +if (!adev->pm.dpm_enabled) +return ; + +if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , + (void *)&temp, &size)) { +if (temp < adev->pm.dpm.thermal.min_temp) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + }else { +if (adev->pm.dpm.thermal.high_to_low) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + } +mutex_lock (&adev->pm.mutex); +if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) + adev->pm.dpm.thermal_active = true; +else + adev->pm.dpm.thermal_active = false; + adev->pm.dpm.state = dpm_state; +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); +} + +static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, +enum amd_pm_state_type dpm_state) +{ +int i; +struct amdgpu_ps *ps; +u32 ui_class; +bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? + true : false; + +/* check if the vblank period is too short to adjust the mclk */ +if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { +if (amdgpu_dpm_vblank_too_short (adev)) + single_display = false; + } + +/* certain older asics have a separare 3D performance state, +* so try that first if the user selected performance +*/ +if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) + dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; +/* balanced states don't exist at the moment */ +if (dpm_state ==POWER_STATE_TYPE_BALANCED ) + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + +restart_search: +/* Pick the best power state based on current conditions */ +for (i =0 ; i < adev->pm.dpm.num_ps; i++) { + ps = &adev->pm.dpm.ps[i]; + ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; +switch (dpm_state) { +/* user states */ +case POWER_STATE_TYPE_BATTERY : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_BALANCED : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_PERFORMANCE : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +/* internal states */ +case POWER_STATE_TYPE_INTERNAL_UVD : +if (adev->pm.dpm.uvd_ps) +return adev->pm.dpm.uvd_ps; +else +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_SD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_BOOT : +return adev->pm.dpm.boot_ps; +case POWER_STATE_TYPE_INTERNAL_THERMAL : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ACPI : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ULV : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_3DPERF : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) +return ps; +break ; +default : +break ; + } + } +/* use a fallback state if we didn't match */ +switch (dpm_state) { +case POWER_STATE_TYPE_INTERNAL_UVD_SD : + dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (adev->pm.dpm.uvd_ps) { +return adev->pm.dpm.uvd_ps; + }else { + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search; + } +case POWER_STATE_TYPE_INTERNAL_THERMAL : + dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_ACPI : + dpm_state =POWER_STATE_TYPE_BATTERY ; + goto restart_search; +case POWER_STATE_TYPE_BATTERY : +case POWER_STATE_TYPE_BALANCED : +case POWER_STATE_TYPE_INTERNAL_3DPERF : + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search; +default : +break ; + } + +return NULL ; +} + +static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) +{ +struct amdgpu_ps *ps; +enum amd_pm_state_type dpm_state; +int ret; +bool equal = false; + +/* if dpm init failed */ +if (!adev->pm.dpm_enabled) +return ; + +if (adev->pm.dpm.user_state != adev->pm.dpm.state) { +/* add other state override checks here */ +if ((!adev->pm.dpm.thermal_active) && + (!adev->pm.dpm.uvd_active)) + adev->pm.dpm.state = adev->pm.dpm.user_state; + } + dpm_state = adev->pm.dpm.state; + + ps =amdgpu_dpm_pick_power_state (adev, dpm_state); +if (ps) + adev->pm.dpm.requested_ps = ps; +else +return ; + +if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { +printk ("switching from power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); +printk ("switching to power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); + } + +/* update whether vce is active */ + ps->vce_active = adev->pm.dpm.vce_active; +if (adev->powerplay.pp_funcs->display_configuration_changed) +amdgpu_dpm_display_configuration_changed (adev); + + ret =amdgpu_dpm_pre_set_power_state (adev); +if (ret) +return ; + +if (adev->powerplay.pp_funcs->check_state_equal) { +if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) + equal = false; + } + +if (equal) +return ; + +amdgpu_dpm_set_power_state (adev); +amdgpu_dpm_post_set_power_state (adev); + + adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; + adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; + +if (adev->powerplay.pp_funcs->force_performance_level) { +if (adev->pm.dpm.thermal_active) { +enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; +/* force low perf level for thermal */ +amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); +/* save the user's level */ + adev->pm.dpm.forced_level = level; + }else { +/* otherwise, user selected level */ +amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); + } + } +} + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) +{ +int i =0 ; + +if (!adev->pm.dpm_enabled) +return ; + +if (adev->mode_info.num_crtc) +amdgpu_display_bandwidth_update (adev); + +for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { +struct amdgpu_ring *ring = adev->rings[i]; +if (ring && ring->sched.ready) +amdgpu_fence_wait_empty (ring); + } + +if (is_support_sw_smu (adev)) { +struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; +smu_handle_task (&adev->smu, + smu_dpm->dpm_level, +AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , + true); + }else { +if (adev->powerplay.pp_funcs->dispatch_tasks) { +if (!amdgpu_device_has_dc_support (adev)) { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); + adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; + adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); + adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); +/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ +if (adev->pm.pm_display_cfg.vrefresh >120 ) + adev->pm.pm_display_cfg.min_vblank_time =0 ; +if (adev->powerplay.pp_funcs->display_configuration_change) + adev->powerplay.pp_funcs->display_configuration_change ( + adev->powerplay.pp_handle, + &adev->pm.pm_display_cfg); +mutex_unlock (&adev->pm.mutex); + } +amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); + }else { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); +amdgpu_dpm_change_power_state_locked (adev); +mutex_unlock (&adev->pm.mutex); + } + } +} + +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.uvd_active = true; + adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; + }else { + adev->pm.dpm.uvd_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); +if (ret) +DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + +/* enable/disable Low Memory PState for UVD (4k videos) */ +if (adev->asic_type ==CHIP_STONEY && + adev->uvd.decode_image_width >=WIDTH_4K ) { +struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; + +if (hwmgr && hwmgr->hwmgr_func && + hwmgr->hwmgr_func->update_nbdpm_pstate) + hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, + !enable, + true); + } + } +} + +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.vce_active = true; +/* XXX select vce level based on ring/task */ + adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; + }else { + adev->pm.dpm.vce_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); +if (ret) +DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + } +} + +void amdgpu_pm_print_power_states (struct amdgpu_device *adev) +{ +int i; + +if (adev->powerplay.pp_funcs->print_power_state ==NULL ) +return ; + +for (i =0 ; i < adev->pm.dpm.num_ps; i++) +amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); + +} + +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); +if (ret) +DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); +} + +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version) +{ +int r; + +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { + r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); +if (r) { +pr_err ("smu firmware loading failed\n" ); +return r; + } + *smu_version = adev->pm.fw_version; + } +return 0 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +14 -0
@@ -548,4 +548,18 @@ int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev,bool acquire); +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev); + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size); + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work); + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev); +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable); +void amdgpu_pm_print_power_states (struct amdgpu_device *adev); +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version); +#endif
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0 -423
455 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0 -8
@@ -79,18 +79,10 @@ struct amdgpu_device_attr_entry { amdgpu_get_##_name, NULL, \ _flags, ##__VA_ARGS__) -void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev); int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);int amdgpu_pm_virt_sysfs_init (struct amdgpu_device *adev);void amdgpu_pm_sysfs_fini (struct amdgpu_device *adev);void amdgpu_pm_virt_sysfs_fini (struct amdgpu_device *adev); -void amdgpu_pm_print_power_states (struct amdgpu_device *adev); -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version); -void amdgpu_pm_compute_clocks (struct amdgpu_device *adev); -void amdgpu_dpm_thermal_work_handler (struct work_struct *work); -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable); -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable);int amdgpu_debugfs_pm_init (struct amdgpu_device *adev);
Signature · 6 lines
2.28.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 4/4] drm/amd/powerplay: put those exposed power interfaces in amdgpu_dpm.c
more comments.
Quoted 157 lines · Evan Quan
As other power interfaces.
Change-Id I5e3b85ae21c4b1d0239f54fa75247b33cfdb7ddcSigned-off-by Evan Quan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 425 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 14 + drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 423 ----------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h | 8 - 4 files changed, 439 insertions(+), 431 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +131
-0@@ -28,6 +28,11 @@#include "amdgpu_dpm.h" #include "atom.h" #include "amd_pcie.h" +#include "amdgpu_display.h" +#include "hwmgr.h" +#include <linux/power_supply.h> + +#define WIDTH_4K 3840void amdgpu_dpm_print_class_info (u32 class,u32 class2) {@@ -1262,3 +1267,423 @@ int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev,return ret; } + +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) +{ +if (adev->pm.dpm_enabled) { +mutex_lock (&adev->pm.mutex); +if (power_supply_is_system_supplied () >0 ) + adev->pm.ac_power = true; +else + adev->pm.ac_power = false; +if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->enable_bapm) +amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); +mutex_unlock (&adev->pm.mutex); + +if (is_support_sw_smu (adev)) +smu_set_ac_dc (&adev->smu); + } +} + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size) +{ +int ret =0 ; + +if (!data || !size) +return -EINVAL ; + +if (is_support_sw_smu (adev)) + ret =smu_read_sensor (&adev->smu, sensor, data, size); +else { +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) + ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, + sensor, data, size); +else + ret = -EINVAL ; + } + +return ret; +} + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work) +{ +struct amdgpu_device *adev = + container_of(work, struct amdgpu_device, + pm.dpm.thermal.work); +/* switch to the thermal state */ +enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; +int temp, size =sizeof (temp); + +if (!adev->pm.dpm_enabled) +return ; + +if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , + (void *)&temp, &size)) { +if (temp < adev->pm.dpm.thermal.min_temp) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + }else { +if (adev->pm.dpm.thermal.high_to_low) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + } +mutex_lock (&adev->pm.mutex); +if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) + adev->pm.dpm.thermal_active = true; +else + adev->pm.dpm.thermal_active = false; + adev->pm.dpm.state = dpm_state; +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); +} + +static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, +enum amd_pm_state_type dpm_state) +{ +int i; +struct amdgpu_ps *ps; +u32 ui_class; +bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? + true : false; + +/* check if the vblank period is too short to adjust the mclk */ +if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { +if (amdgpu_dpm_vblank_too_short (adev)) + single_display = false; + } + +/* certain older asics have a separare 3D performance state, +* so try that first if the user selected performance +*/ +if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) + dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; +/* balanced states don't exist at the moment */ +if (dpm_state ==POWER_STATE_TYPE_BALANCED ) + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + +restart_search: +/* Pick the best power state based on current conditions */ +for (i =0 ; i < adev->pm.dpm.num_ps; i++) { + ps = &adev->pm.dpm.ps[i]; + ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; +switch (dpm_state) { +/* user states */ +case POWER_STATE_TYPE_BATTERY : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_BALANCED : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_PERFORMANCE : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display)
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1405
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+return ps; + }else +return ps; + } +break ; +/* internal states */ +case POWER_STATE_TYPE_INTERNAL_UVD : +if (adev->pm.dpm.uvd_ps) +return adev->pm.dpm.uvd_ps; +else
We don't need the "else" here.
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +54
-0+break ; +case POWER_STATE_TYPE_INTERNAL_UVD_SD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_BOOT : +return adev->pm.dpm.boot_ps; +case POWER_STATE_TYPE_INTERNAL_THERMAL : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ACPI : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ULV : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_3DPERF : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) +return ps; +break ; +default : +break ; + } + } +/* use a fallback state if we didn't match */ +switch (dpm_state) { +case POWER_STATE_TYPE_INTERNAL_UVD_SD : + dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (adev->pm.dpm.uvd_ps) { +return adev->pm.dpm.uvd_ps; + }else { + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search; + } +case POWER_STATE_TYPE_INTERNAL_THERMAL :
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1469
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_ACPI : + dpm_state =POWER_STATE_TYPE_BATTERY ; + goto restart_search; +case POWER_STATE_TYPE_BATTERY : +case POWER_STATE_TYPE_BALANCED : +case POWER_STATE_TYPE_INTERNAL_3DPERF : + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search;
I think it will be a good idea to move restart_search block to a function so we can easily
rule out any infinite loops with "goto restart_search" usages.
Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +21
-0+default : +break ; + } + +return NULL ; +} + +static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) +{ +struct amdgpu_ps *ps; +enum amd_pm_state_type dpm_state; +int ret; +bool equal = false; + +/* if dpm init failed */ +if (!adev->pm.dpm_enabled) +return ; + +if (adev->pm.dpm.user_state != adev->pm.dpm.state) { +/* add other state override checks here */ + if ((!adev->pm.dpm.thermal_active) &&
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1500
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ (!adev->pm.dpm.uvd_active)) + adev->pm.dpm.state = adev->pm.dpm.user_state; + } + dpm_state = adev->pm.dpm.state; + + ps =amdgpu_dpm_pick_power_state (adev, dpm_state); +if (ps) + adev->pm.dpm.requested_ps = ps; +else +return ;
nitpick:
if(!ns)
return;
adev->pm.dpm.requested_ps = ps;
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +9
-0+ +if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { +printk ("switching from power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); +printk ("switching to power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); + } + +/* update whether vce is active */
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1519
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ ps->vce_active = adev->pm.dpm.vce_active; +if (adev->powerplay.pp_funcs->display_configuration_changed) +amdgpu_dpm_display_configuration_changed (adev); + + ret =amdgpu_dpm_pre_set_power_state (adev); +if (ret) +return ; + +if (adev->powerplay.pp_funcs->check_state_equal) { +if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
We don't need that check as amdgpu_dpm_check_state_equal() should not modify (default)value of
"equal" on error.
Nirmoy
Quoted 669 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +170
-0+ equal = false; + } + +if (equal) +return ; + +amdgpu_dpm_set_power_state (adev); +amdgpu_dpm_post_set_power_state (adev); + + adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; + adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; + +if (adev->powerplay.pp_funcs->force_performance_level) { +if (adev->pm.dpm.thermal_active) { +enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; +/* force low perf level for thermal */ +amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); +/* save the user's level */ + adev->pm.dpm.forced_level = level; + }else { +/* otherwise, user selected level */ +amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); + } + } +} + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) +{ +int i =0 ; + +if (!adev->pm.dpm_enabled) +return ; + +if (adev->mode_info.num_crtc) +amdgpu_display_bandwidth_update (adev); + +for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { +struct amdgpu_ring *ring = adev->rings[i]; +if (ring && ring->sched.ready) +amdgpu_fence_wait_empty (ring); + } + +if (is_support_sw_smu (adev)) { +struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; +smu_handle_task (&adev->smu, + smu_dpm->dpm_level, +AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , + true); + }else { +if (adev->powerplay.pp_funcs->dispatch_tasks) { +if (!amdgpu_device_has_dc_support (adev)) { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); + adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; + adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); + adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); +/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ +if (adev->pm.pm_display_cfg.vrefresh >120 ) + adev->pm.pm_display_cfg.min_vblank_time =0 ; +if (adev->powerplay.pp_funcs->display_configuration_change) + adev->powerplay.pp_funcs->display_configuration_change ( + adev->powerplay.pp_handle, + &adev->pm.pm_display_cfg); +mutex_unlock (&adev->pm.mutex); + } +amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); + }else { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); +amdgpu_dpm_change_power_state_locked (adev); +mutex_unlock (&adev->pm.mutex); + } + } +} + +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.uvd_active = true; + adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; + }else { + adev->pm.dpm.uvd_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); +if (ret) +DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + +/* enable/disable Low Memory PState for UVD (4k videos) */ +if (adev->asic_type ==CHIP_STONEY && + adev->uvd.decode_image_width >=WIDTH_4K ) { +struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; + +if (hwmgr && hwmgr->hwmgr_func && + hwmgr->hwmgr_func->update_nbdpm_pstate) + hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, + !enable, + true); + } + } +} + +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.vce_active = true; +/* XXX select vce level based on ring/task */ + adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; + }else { + adev->pm.dpm.vce_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); +if (ret) +DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + } +} + +void amdgpu_pm_print_power_states (struct amdgpu_device *adev) +{ +int i; + +if (adev->powerplay.pp_funcs->print_power_state ==NULL ) +return ; + +for (i =0 ; i < adev->pm.dpm.num_ps; i++) +amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); + +} + +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); +if (ret) +DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); +} + +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version) +{ +int r; + +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { + r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); +if (r) { +pr_err ("smu firmware loading failed\n" ); +return r; + } + *smu_version = adev->pm.fw_version; + } +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +14
-0@@ -548,4 +548,18 @@ int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev,bool acquire); +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev); + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size); + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work); + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev); +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable); +void amdgpu_pm_print_power_states (struct amdgpu_device *adev); +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version); +#endif drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-423@@ -29,17 +29,14 @@#include "amdgpu_drv.h" #include "amdgpu_pm.h" #include "amdgpu_dpm.h" -#include "amdgpu_display.h" #include "amdgpu_smu.h" #include "atom.h" -#include <linux/power_supply.h> #include <linux/pci.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/nospec.h> #include <linux/pm_runtime.h> #include "hwmgr.h" -#define WIDTH_4K 3840static const struct cg_flag_name clocks[] = { {AMD_CG_SUPPORT_GFX_MGCG ,"Graphics Medium Grain Clock Gating" },@@ -81,45 +78,6 @@ static const struct hwmon_temp_label { {PP_TEMP_MEM, "mem"}, }; -void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) -{ -if (adev->pm.dpm_enabled) { -mutex_lock (&adev->pm.mutex); -if (power_supply_is_system_supplied () >0 ) - adev->pm.ac_power = true; -else - adev->pm.ac_power = false; -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->enable_bapm) -amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); -mutex_unlock (&adev->pm.mutex); - -if (is_support_sw_smu (adev)) -smu_set_ac_dc (&adev->smu); - } -} - -int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, -void *data,uint32_t *size) -{ -int ret =0 ; - -if (!data || !size) -return -EINVAL ; - -if (is_support_sw_smu (adev)) - ret =smu_read_sensor (&adev->smu, sensor, data, size); -else { -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) - ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, - sensor, data, size); -else - ret = -EINVAL ; - } - -return ret; -} -/** * DOC: power_dpm_state * @@ -3636,338 +3594,6 @@ static const struct attribute_group *hwmon_groups[] = { NULL }; -void amdgpu_dpm_thermal_work_handler (struct work_struct *work) -{ -struct amdgpu_device *adev = - container_of(work, struct amdgpu_device, - pm.dpm.thermal.work); -/* switch to the thermal state */ -enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; -int temp, size =sizeof (temp); - -if (!adev->pm.dpm_enabled) -return ; - -if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , - (void *)&temp, &size)) { -if (temp < adev->pm.dpm.thermal.min_temp) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - }else { -if (adev->pm.dpm.thermal.high_to_low) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - } -mutex_lock (&adev->pm.mutex); -if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) - adev->pm.dpm.thermal_active = true; -else - adev->pm.dpm.thermal_active = false; - adev->pm.dpm.state = dpm_state; -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); -} - -static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, -enum amd_pm_state_type dpm_state) -{ -int i; -struct amdgpu_ps *ps; -u32 ui_class; -bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? - true : false; - -/* check if the vblank period is too short to adjust the mclk */ -if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { -if (amdgpu_dpm_vblank_too_short (adev)) - single_display = false; - } - -/* certain older asics have a separare 3D performance state, -* so try that first if the user selected performance -*/ -if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) - dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; -/* balanced states don't exist at the moment */ -if (dpm_state ==POWER_STATE_TYPE_BALANCED ) - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - -restart_search: -/* Pick the best power state based on current conditions */ -for (i =0 ; i < adev->pm.dpm.num_ps; i++) { - ps = &adev->pm.dpm.ps[i]; - ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; -switch (dpm_state) { -/* user states */ -case POWER_STATE_TYPE_BATTERY : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_BALANCED : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_PERFORMANCE : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -/* internal states */ -case POWER_STATE_TYPE_INTERNAL_UVD : -if (adev->pm.dpm.uvd_ps) -return adev->pm.dpm.uvd_ps; -else -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_SD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_BOOT : -return adev->pm.dpm.boot_ps; -case POWER_STATE_TYPE_INTERNAL_THERMAL : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ACPI : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ULV : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_3DPERF : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) -return ps; -break ; -default : -break ; - } - } -/* use a fallback state if we didn't match */ -switch (dpm_state) { -case POWER_STATE_TYPE_INTERNAL_UVD_SD : - dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (adev->pm.dpm.uvd_ps) { -return adev->pm.dpm.uvd_ps; - }else { - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; - } -case POWER_STATE_TYPE_INTERNAL_THERMAL : - dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_ACPI : - dpm_state =POWER_STATE_TYPE_BATTERY ; - goto restart_search; -case POWER_STATE_TYPE_BATTERY : -case POWER_STATE_TYPE_BALANCED : -case POWER_STATE_TYPE_INTERNAL_3DPERF : - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; -default : -break ; - } - -return NULL ; -} - -static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) -{ -struct amdgpu_ps *ps; -enum amd_pm_state_type dpm_state; -int ret; -bool equal = false; - -/* if dpm init failed */ -if (!adev->pm.dpm_enabled) -return ; - -if (adev->pm.dpm.user_state != adev->pm.dpm.state) { -/* add other state override checks here */ -if ((!adev->pm.dpm.thermal_active) && - (!adev->pm.dpm.uvd_active)) - adev->pm.dpm.state = adev->pm.dpm.user_state; - } - dpm_state = adev->pm.dpm.state; - - ps =amdgpu_dpm_pick_power_state (adev, dpm_state); -if (ps) - adev->pm.dpm.requested_ps = ps; -else -return ; - -if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { -printk ("switching from power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); -printk ("switching to power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); - } - -/* update whether vce is active */ - ps->vce_active = adev->pm.dpm.vce_active; -if (adev->powerplay.pp_funcs->display_configuration_changed) -amdgpu_dpm_display_configuration_changed (adev); - - ret =amdgpu_dpm_pre_set_power_state (adev); -if (ret) -return ; - -if (adev->powerplay.pp_funcs->check_state_equal) { -if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) - equal = false; - } - -if (equal) -return ; - -amdgpu_dpm_set_power_state (adev); -amdgpu_dpm_post_set_power_state (adev); - - adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; - adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; - -if (adev->powerplay.pp_funcs->force_performance_level) { -if (adev->pm.dpm.thermal_active) { -enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; -/* force low perf level for thermal */ -amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); -/* save the user's level */ - adev->pm.dpm.forced_level = level; - }else { -/* otherwise, user selected level */ -amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); - } - } -} - -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.uvd_active = true; - adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; - }else { - adev->pm.dpm.uvd_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); -if (ret) -DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - -/* enable/disable Low Memory PState for UVD (4k videos) */ -if (adev->asic_type ==CHIP_STONEY && - adev->uvd.decode_image_width >=WIDTH_4K ) { -struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; - -if (hwmgr && hwmgr->hwmgr_func && - hwmgr->hwmgr_func->update_nbdpm_pstate) - hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, - !enable, - true); - } - } -} - -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.vce_active = true; -/* XXX select vce level based on ring/task */ - adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; - }else { - adev->pm.dpm.vce_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); -if (ret) -DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - } -} - -void amdgpu_pm_print_power_states (struct amdgpu_device *adev) -{ -int i; - -if (adev->powerplay.pp_funcs->print_power_state ==NULL ) -return ; - -for (i =0 ; i < adev->pm.dpm.num_ps; i++) -amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); - -} - -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); -if (ret) -DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); -} - -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version) -{ -int r; - -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { - r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); -if (r) { -pr_err ("smu firmware loading failed\n" ); -return r; - } - *smu_version = adev->pm.fw_version; - } -return 0 ; -} -int amdgpu_pm_sysfs_init (struct amdgpu_device *adev) {int ret;@@ -4028,55 +3654,6 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)amdgpu_device_attr_remove_groups (adev, &adev->pm.pm_attr_list); } -void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) -{ -int i =0 ; - -if (!adev->pm.dpm_enabled) -return ; - -if (adev->mode_info.num_crtc) -amdgpu_display_bandwidth_update (adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { -struct amdgpu_ring *ring = adev->rings[i]; -if (ring && ring->sched.ready) -amdgpu_fence_wait_empty (ring); - } - -if (is_support_sw_smu (adev)) { -struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; -smu_handle_task (&adev->smu, - smu_dpm->dpm_level, -AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , - true); - }else { -if (adev->powerplay.pp_funcs->dispatch_tasks) { -if (!amdgpu_device_has_dc_support (adev)) { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); - adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; - adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); - adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); -/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ -if (adev->pm.pm_display_cfg.vrefresh >120 ) - adev->pm.pm_display_cfg.min_vblank_time =0 ; -if (adev->powerplay.pp_funcs->display_configuration_change) - adev->powerplay.pp_funcs->display_configuration_change ( - adev->powerplay.pp_handle, - &adev->pm.pm_display_cfg); -mutex_unlock (&adev->pm.mutex); - } -amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); - }else { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); -amdgpu_dpm_change_power_state_locked (adev); -mutex_unlock (&adev->pm.mutex); - } - } -} -/* * Debugfs info */ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0
-1@@ -79,18 +79,10 @@ struct amdgpu_device_attr_entry { amdgpu_get_##_name, NULL, \ _flags, ##__VA_ARGS__) -void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev); int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);int amdgpu_pm_virt_sysfs_init (struct amdgpu_device *adev);void amdgpu_pm_sysfs_fini (struct amdgpu_device *adev);void amdgpu_pm_virt_sysfs_fini (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h struct amdgpu_device_attr_entry { · line 88
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0
-7-void amdgpu_pm_print_power_states (struct amdgpu_device *adev); -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version); -void amdgpu_pm_compute_clocks (struct amdgpu_device *adev); -void amdgpu_dpm_thermal_work_handler (struct work_struct *work); -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable); -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable);int amdgpu_debugfs_pm_init (struct amdgpu_device *adev);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Alex Deucher
Reviewed-byRe: [PATCH 4/4] drm/amd/powerplay: put those exposed power interfaces in amdgpu_dpm.c
Series is:
Nirmoy makes some good points below, but I think those should be a follow up patch as this patch is just moving code around; no actual changes.
Alex
Quoted 1,000 lines · Nirmoy
below for
more comments.
Quoted 157 lines · Evan Quan
As other power interfaces.
Change-Id I5e3b85ae21c4b1d0239f54fa75247b33cfdb7ddcSigned-off-by Evan Quan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 425 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 14 + drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 423 ----------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h | 8 - 4 files changed, 439 insertions(+), 431 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +131
-0@@ -28,6 +28,11 @@#include "amdgpu_dpm.h" #include "atom.h" #include "amd_pcie.h" +#include "amdgpu_display.h" +#include "hwmgr.h" +#include <linux/power_supply.h> + +#define WIDTH_4K 3840void amdgpu_dpm_print_class_info (u32 class,u32 class2) {@@ -1262,3 +1267,423 @@ int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev,return ret; } + +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) +{ +if (adev->pm.dpm_enabled) { +mutex_lock (&adev->pm.mutex); +if (power_supply_is_system_supplied () >0 ) + adev->pm.ac_power = true; +else + adev->pm.ac_power = false; +if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->enable_bapm) +amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); +mutex_unlock (&adev->pm.mutex); + +if (is_support_sw_smu (adev)) +smu_set_ac_dc (&adev->smu); + } +} + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size) +{ +int ret =0 ; + +if (!data || !size) +return -EINVAL ; + +if (is_support_sw_smu (adev)) + ret =smu_read_sensor (&adev->smu, sensor, data, size); +else { +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) + ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, + sensor, data, size); +else + ret = -EINVAL ; + } + +return ret; +} + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work) +{ +struct amdgpu_device *adev = + container_of(work, struct amdgpu_device, + pm.dpm.thermal.work); +/* switch to the thermal state */ +enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; +int temp, size =sizeof (temp); + +if (!adev->pm.dpm_enabled) +return ; + +if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , + (void *)&temp, &size)) { +if (temp < adev->pm.dpm.thermal.min_temp) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + }else { +if (adev->pm.dpm.thermal.high_to_low) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + } +mutex_lock (&adev->pm.mutex); +if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) + adev->pm.dpm.thermal_active = true; +else + adev->pm.dpm.thermal_active = false; + adev->pm.dpm.state = dpm_state; +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); +} + +static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, +enum amd_pm_state_type dpm_state) +{ +int i; +struct amdgpu_ps *ps; +u32 ui_class; +bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? + true : false; + +/* check if the vblank period is too short to adjust the mclk */ +if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { +if (amdgpu_dpm_vblank_too_short (adev)) + single_display = false; + } + +/* certain older asics have a separare 3D performance state, +* so try that first if the user selected performance +*/ +if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) + dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; +/* balanced states don't exist at the moment */ +if (dpm_state ==POWER_STATE_TYPE_BALANCED ) + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + +restart_search: +/* Pick the best power state based on current conditions */ +for (i =0 ; i < adev->pm.dpm.num_ps; i++) { + ps = &adev->pm.dpm.ps[i]; + ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; +switch (dpm_state) { +/* user states */ +case POWER_STATE_TYPE_BATTERY : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_BALANCED : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_PERFORMANCE : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1405
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+return ps; + }else +return ps; + } +break ; +/* internal states */ +case POWER_STATE_TYPE_INTERNAL_UVD : +if (adev->pm.dpm.uvd_ps) +return adev->pm.dpm.uvd_ps; +else We don't need the "else" here.
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +54
-0+break ; +case POWER_STATE_TYPE_INTERNAL_UVD_SD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_BOOT : +return adev->pm.dpm.boot_ps; +case POWER_STATE_TYPE_INTERNAL_THERMAL : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ACPI : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ULV : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_3DPERF : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) +return ps; +break ; +default : +break ; + } + } +/* use a fallback state if we didn't match */ +switch (dpm_state) { +case POWER_STATE_TYPE_INTERNAL_UVD_SD : + dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (adev->pm.dpm.uvd_ps) { +return adev->pm.dpm.uvd_ps; + }else { + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search; + } +case POWER_STATE_TYPE_INTERNAL_THERMAL :drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1469
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_ACPI : + dpm_state =POWER_STATE_TYPE_BATTERY ; + goto restart_search; +case POWER_STATE_TYPE_BATTERY : +case POWER_STATE_TYPE_BALANCED : +case POWER_STATE_TYPE_INTERNAL_3DPERF : + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search;I think it will be a good idea to move
restart_searchblock to a function so we can easilyrule out any infinite loops with "goto
restart_search" usages.Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +21
-0+default : +break ; + } + +return NULL ; +} + +static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) +{ +struct amdgpu_ps *ps; +enum amd_pm_state_type dpm_state; +int ret; +bool equal = false; + +/* if dpm init failed */ +if (!adev->pm.dpm_enabled) +return ; + +if (adev->pm.dpm.user_state != adev->pm.dpm.state) { +/* add other state override checks here */ + if ((!adev->pm.dpm.thermal_active) &&drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1500
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ (!adev->pm.dpm.uvd_active)) + adev->pm.dpm.state = adev->pm.dpm.user_state; + } + dpm_state = adev->pm.dpm.state; + + ps =amdgpu_dpm_pick_power_state (adev, dpm_state); +if (ps) + adev->pm.dpm.requested_ps = ps; +else +return ;nitpick:
if(!ns)
return;
adev->pm.dpm.requested_ps= ps;Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +9
-0+ +if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { +printk ("switching from power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); +printk ("switching to power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); + } + +/* update whether vce is active */ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1519
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ ps->vce_active = adev->pm.dpm.vce_active; +if (adev->powerplay.pp_funcs->display_configuration_changed) +amdgpu_dpm_display_configuration_changed (adev); + + ret =amdgpu_dpm_pre_set_power_state (adev); +if (ret) +return ; + +if (adev->powerplay.pp_funcs->check_state_equal) { +if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))We don't need that check as
amdgpu_dpm_check_state_equal()should not modify (default)value of"equal" on error.
Nirmoy
Quoted 677 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +170
-0+ equal = false; + } + +if (equal) +return ; + +amdgpu_dpm_set_power_state (adev); +amdgpu_dpm_post_set_power_state (adev); + + adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; + adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; + +if (adev->powerplay.pp_funcs->force_performance_level) { +if (adev->pm.dpm.thermal_active) { +enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; +/* force low perf level for thermal */ +amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); +/* save the user's level */ + adev->pm.dpm.forced_level = level; + }else { +/* otherwise, user selected level */ +amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); + } + } +} + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) +{ +int i =0 ; + +if (!adev->pm.dpm_enabled) +return ; + +if (adev->mode_info.num_crtc) +amdgpu_display_bandwidth_update (adev); + +for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { +struct amdgpu_ring *ring = adev->rings[i]; +if (ring && ring->sched.ready) +amdgpu_fence_wait_empty (ring); + } + +if (is_support_sw_smu (adev)) { +struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; +smu_handle_task (&adev->smu, + smu_dpm->dpm_level, +AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , + true); + }else { +if (adev->powerplay.pp_funcs->dispatch_tasks) { +if (!amdgpu_device_has_dc_support (adev)) { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); + adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; + adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); + adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); +/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ +if (adev->pm.pm_display_cfg.vrefresh >120 ) + adev->pm.pm_display_cfg.min_vblank_time =0 ; +if (adev->powerplay.pp_funcs->display_configuration_change) + adev->powerplay.pp_funcs->display_configuration_change ( + adev->powerplay.pp_handle, + &adev->pm.pm_display_cfg); +mutex_unlock (&adev->pm.mutex); + } +amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); + }else { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); +amdgpu_dpm_change_power_state_locked (adev); +mutex_unlock (&adev->pm.mutex); + } + } +} + +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.uvd_active = true; + adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; + }else { + adev->pm.dpm.uvd_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); +if (ret) +DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + +/* enable/disable Low Memory PState for UVD (4k videos) */ +if (adev->asic_type ==CHIP_STONEY && + adev->uvd.decode_image_width >=WIDTH_4K ) { +struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; + +if (hwmgr && hwmgr->hwmgr_func && + hwmgr->hwmgr_func->update_nbdpm_pstate) + hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, + !enable, + true); + } + } +} + +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.vce_active = true; +/* XXX select vce level based on ring/task */ + adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; + }else { + adev->pm.dpm.vce_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); +if (ret) +DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + } +} + +void amdgpu_pm_print_power_states (struct amdgpu_device *adev) +{ +int i; + +if (adev->powerplay.pp_funcs->print_power_state ==NULL ) +return ; + +for (i =0 ; i < adev->pm.dpm.num_ps; i++) +amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); + +} + +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); +if (ret) +DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); +} + +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version) +{ +int r; + +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { + r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); +if (r) { +pr_err ("smu firmware loading failed\n" ); +return r; + } + *smu_version = adev->pm.fw_version; + } +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +14
-0@@ -548,4 +548,18 @@ int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev,bool acquire); +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev); + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size); + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work); + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev); +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable); +void amdgpu_pm_print_power_states (struct amdgpu_device *adev); +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version); +#endif drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-423@@ -29,17 +29,14 @@#include "amdgpu_drv.h" #include "amdgpu_pm.h" #include "amdgpu_dpm.h" -#include "amdgpu_display.h" #include "amdgpu_smu.h" #include "atom.h" -#include <linux/power_supply.h> #include <linux/pci.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/nospec.h> #include <linux/pm_runtime.h> #include "hwmgr.h" -#define WIDTH_4K 3840static const struct cg_flag_name clocks[] = { {AMD_CG_SUPPORT_GFX_MGCG ,"Graphics Medium Grain Clock Gating" },@@ -81,45 +78,6 @@ static const struct hwmon_temp_label { {PP_TEMP_MEM, "mem"}, }; -void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) -{ -if (adev->pm.dpm_enabled) { -mutex_lock (&adev->pm.mutex); -if (power_supply_is_system_supplied () >0 ) - adev->pm.ac_power = true; -else - adev->pm.ac_power = false; -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->enable_bapm) -amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); -mutex_unlock (&adev->pm.mutex); - -if (is_support_sw_smu (adev)) -smu_set_ac_dc (&adev->smu); - } -} - -int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, -void *data,uint32_t *size) -{ -int ret =0 ; - -if (!data || !size) -return -EINVAL ; - -if (is_support_sw_smu (adev)) - ret =smu_read_sensor (&adev->smu, sensor, data, size); -else { -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) - ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, - sensor, data, size); -else - ret = -EINVAL ; - } - -return ret; -} -/** * DOC: power_dpm_state * @@ -3636,338 +3594,6 @@ static const struct attribute_group *hwmon_groups[] = { NULL }; -void amdgpu_dpm_thermal_work_handler (struct work_struct *work) -{ -struct amdgpu_device *adev = - container_of(work, struct amdgpu_device, - pm.dpm.thermal.work); -/* switch to the thermal state */ -enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; -int temp, size =sizeof (temp); - -if (!adev->pm.dpm_enabled) -return ; - -if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , - (void *)&temp, &size)) { -if (temp < adev->pm.dpm.thermal.min_temp) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - }else { -if (adev->pm.dpm.thermal.high_to_low) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - } -mutex_lock (&adev->pm.mutex); -if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) - adev->pm.dpm.thermal_active = true; -else - adev->pm.dpm.thermal_active = false; - adev->pm.dpm.state = dpm_state; -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); -} - -static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, -enum amd_pm_state_type dpm_state) -{ -int i; -struct amdgpu_ps *ps; -u32 ui_class; -bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? - true : false; - -/* check if the vblank period is too short to adjust the mclk */ -if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { -if (amdgpu_dpm_vblank_too_short (adev)) - single_display = false; - } - -/* certain older asics have a separare 3D performance state, -* so try that first if the user selected performance -*/ -if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) - dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; -/* balanced states don't exist at the moment */ -if (dpm_state ==POWER_STATE_TYPE_BALANCED ) - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - -restart_search: -/* Pick the best power state based on current conditions */ -for (i =0 ; i < adev->pm.dpm.num_ps; i++) { - ps = &adev->pm.dpm.ps[i]; - ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; -switch (dpm_state) { -/* user states */ -case POWER_STATE_TYPE_BATTERY : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_BALANCED : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_PERFORMANCE : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -/* internal states */ -case POWER_STATE_TYPE_INTERNAL_UVD : -if (adev->pm.dpm.uvd_ps) -return adev->pm.dpm.uvd_ps; -else -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_SD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_BOOT : -return adev->pm.dpm.boot_ps; -case POWER_STATE_TYPE_INTERNAL_THERMAL : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ACPI : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ULV : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_3DPERF : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) -return ps; -break ; -default : -break ; - } - } -/* use a fallback state if we didn't match */ -switch (dpm_state) { -case POWER_STATE_TYPE_INTERNAL_UVD_SD : - dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (adev->pm.dpm.uvd_ps) { -return adev->pm.dpm.uvd_ps; - }else { - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; - } -case POWER_STATE_TYPE_INTERNAL_THERMAL : - dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_ACPI : - dpm_state =POWER_STATE_TYPE_BATTERY ; - goto restart_search; -case POWER_STATE_TYPE_BATTERY : -case POWER_STATE_TYPE_BALANCED : -case POWER_STATE_TYPE_INTERNAL_3DPERF : - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; -default : -break ; - } - -return NULL ; -} - -static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) -{ -struct amdgpu_ps *ps; -enum amd_pm_state_type dpm_state; -int ret; -bool equal = false; - -/* if dpm init failed */ -if (!adev->pm.dpm_enabled) -return ; - -if (adev->pm.dpm.user_state != adev->pm.dpm.state) { -/* add other state override checks here */ -if ((!adev->pm.dpm.thermal_active) && - (!adev->pm.dpm.uvd_active)) - adev->pm.dpm.state = adev->pm.dpm.user_state; - } - dpm_state = adev->pm.dpm.state; - - ps =amdgpu_dpm_pick_power_state (adev, dpm_state); -if (ps) - adev->pm.dpm.requested_ps = ps; -else -return ; - -if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { -printk ("switching from power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); -printk ("switching to power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); - } - -/* update whether vce is active */ - ps->vce_active = adev->pm.dpm.vce_active; -if (adev->powerplay.pp_funcs->display_configuration_changed) -amdgpu_dpm_display_configuration_changed (adev); - - ret =amdgpu_dpm_pre_set_power_state (adev); -if (ret) -return ; - -if (adev->powerplay.pp_funcs->check_state_equal) { -if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) - equal = false; - } - -if (equal) -return ; - -amdgpu_dpm_set_power_state (adev); -amdgpu_dpm_post_set_power_state (adev); - - adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; - adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; - -if (adev->powerplay.pp_funcs->force_performance_level) { -if (adev->pm.dpm.thermal_active) { -enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; -/* force low perf level for thermal */ -amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); -/* save the user's level */ - adev->pm.dpm.forced_level = level; - }else { -/* otherwise, user selected level */ -amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); - } - } -} - -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.uvd_active = true; - adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; - }else { - adev->pm.dpm.uvd_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); -if (ret) -DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - -/* enable/disable Low Memory PState for UVD (4k videos) */ -if (adev->asic_type ==CHIP_STONEY && - adev->uvd.decode_image_width >=WIDTH_4K ) { -struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; - -if (hwmgr && hwmgr->hwmgr_func && - hwmgr->hwmgr_func->update_nbdpm_pstate) - hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, - !enable, - true); - } - } -} - -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.vce_active = true; -/* XXX select vce level based on ring/task */ - adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; - }else { - adev->pm.dpm.vce_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); -if (ret) -DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - } -} - -void amdgpu_pm_print_power_states (struct amdgpu_device *adev) -{ -int i; - -if (adev->powerplay.pp_funcs->print_power_state ==NULL ) -return ; - -for (i =0 ; i < adev->pm.dpm.num_ps; i++) -amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); - -} - -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); -if (ret) -DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); -} - -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version) -{ -int r; - -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { - r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); -if (r) { -pr_err ("smu firmware loading failed\n" ); -return r; - } - *smu_version = adev->pm.fw_version; - } -return 0 ; -} -int amdgpu_pm_sysfs_init (struct amdgpu_device *adev) {int ret;@@ -4028,55 +3654,6 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)amdgpu_device_attr_remove_groups (adev, &adev->pm.pm_attr_list); } -void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) -{ -int i =0 ; - -if (!adev->pm.dpm_enabled) -return ; - -if (adev->mode_info.num_crtc) -amdgpu_display_bandwidth_update (adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { -struct amdgpu_ring *ring = adev->rings[i]; -if (ring && ring->sched.ready) -amdgpu_fence_wait_empty (ring); - } - -if (is_support_sw_smu (adev)) { -struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; -smu_handle_task (&adev->smu, - smu_dpm->dpm_level, -AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , - true); - }else { -if (adev->powerplay.pp_funcs->dispatch_tasks) { -if (!amdgpu_device_has_dc_support (adev)) { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); - adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; - adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); - adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); -/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ -if (adev->pm.pm_display_cfg.vrefresh >120 ) - adev->pm.pm_display_cfg.min_vblank_time =0 ; -if (adev->powerplay.pp_funcs->display_configuration_change) - adev->powerplay.pp_funcs->display_configuration_change ( - adev->powerplay.pp_handle, - &adev->pm.pm_display_cfg); -mutex_unlock (&adev->pm.mutex); - } -amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); - }else { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); -amdgpu_dpm_change_power_state_locked (adev); -mutex_unlock (&adev->pm.mutex); - } - } -} -/* * Debugfs info */ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0
-8@@ -79,18 +79,10 @@ struct amdgpu_device_attr_entry { amdgpu_get_##_name, NULL, \ _flags, ##__VA_ARGS__) -void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev); int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);int amdgpu_pm_virt_sysfs_init (struct amdgpu_device *adev);void amdgpu_pm_sysfs_fini (struct amdgpu_device *adev);void amdgpu_pm_virt_sysfs_fini (struct amdgpu_device *adev); -void amdgpu_pm_print_power_states (struct amdgpu_device *adev); -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev,uint32_t *smu_version); -void amdgpu_pm_compute_clocks (struct amdgpu_device *adev); -void amdgpu_dpm_thermal_work_handler (struct work_struct *work); -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable); -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable);
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h struct amdgpu_device_attr_entry { · line 88
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0
-0int amdgpu_debugfs_pm_init (struct amdgpu_device *adev);_______________________________________________
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
Quan, Evan
Reviewed-by Alex DeucherRE: [PATCH 4/4] drm/amd/powerplay: put those exposed power interfaces in amdgpu_dpm.c
[AMD Official Use Only - Internal Distribution Only]
Yes, I would like to make another patch to address Nirmoy's comments. @Das, Nirmoy is that OK?
BR
Evan
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, August 13, 2020 9:54 PM
To: Das, Nirmoy <[email protected]>
Cc: Quan, Evan <[email protected]>; amd-gfx list <[email protected]>; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 4/4] drm/amd/powerplay: put those exposed power interfaces in amdgpu_dpm.c
Series is:
Alex
Quoted 1,000 lines · Nirmoy
below for
more comments.
Quoted 155 lines · Evan Quan
As other power interfaces.
Change-Id I5e3b85ae21c4b1d0239f54fa75247b33cfdb7ddcSigned-off-by Evan Quan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 425 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 14 + drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 423 ----------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h | 8 - 4 files changed, 439 insertions(+), 431 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +127
-0@@ -28,6 +28,11 @@#include "amdgpu_dpm.h" #include "atom.h" #include "amd_pcie.h" +#include "amdgpu_display.h" +#include "hwmgr.h" +#include <linux/power_supply.h> + +#define WIDTH_4K 3840void amdgpu_dpm_print_class_info (u32 class,u32 class2) {@@ -1262,3 +1267,423 @@ int amdgpu_dpm_smu_i2c_bus_access(structamdgpu_device *adev, return ret; } + +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) { +if (adev->pm.dpm_enabled) { +mutex_lock (&adev->pm.mutex); +if (power_supply_is_system_supplied () >0 ) + adev->pm.ac_power = true; +else + adev->pm.ac_power = false; +if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->enable_bapm) +amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); +mutex_unlock (&adev->pm.mutex); + +if (is_support_sw_smu (adev)) +smu_set_ac_dc (&adev->smu); + } +} + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size) { +int ret =0 ; + +if (!data || !size) +return -EINVAL ; + +if (is_support_sw_smu (adev)) + ret =smu_read_sensor (&adev->smu, sensor, data, size); +else { +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) + ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, + sensor, data, size); +else + ret = -EINVAL ; + } + +return ret; +} + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work) { +struct amdgpu_device *adev = + container_of(work, struct amdgpu_device, + pm.dpm.thermal.work); +/* switch to the thermal state */ +enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; +int temp, size =sizeof (temp); + +if (!adev->pm.dpm_enabled) +return ; + +if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , + (void *)&temp, &size)) { +if (temp < adev->pm.dpm.thermal.min_temp) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + }else { +if (adev->pm.dpm.thermal.high_to_low) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + } +mutex_lock (&adev->pm.mutex); +if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) + adev->pm.dpm.thermal_active = true; +else + adev->pm.dpm.thermal_active = false; + adev->pm.dpm.state = dpm_state; +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); } + +static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, +enum +amd_pm_state_type dpm_state) { +int i; +struct amdgpu_ps *ps; +u32 ui_class; +bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? + true : false; + +/* check if the vblank period is too short to adjust the mclk */ +if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { +if (amdgpu_dpm_vblank_too_short (adev)) + single_display = false; + } + +/* certain older asics have a separare 3D performance state, +* so try that first if the user selected performance +*/ +if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) + dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; +/* balanced states don't exist at the moment */ +if (dpm_state ==POWER_STATE_TYPE_BALANCED ) + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + +restart_search: +/* Pick the best power state based on current conditions */ +for (i =0 ; i < adev->pm.dpm.num_ps; i++) { + ps = &adev->pm.dpm.ps[i]; + ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; +switch (dpm_state) { +/* user states */ +case POWER_STATE_TYPE_BATTERY : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_BALANCED : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_PERFORMANCE : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct · line 1405
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+return ps; + }else +return ps; + } +break ; +/* internal states */ +case POWER_STATE_TYPE_INTERNAL_UVD : +if (adev->pm.dpm.uvd_ps) +return adev->pm.dpm.uvd_ps; +else We don't need the "else" here.
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +54
-0+break ; +case POWER_STATE_TYPE_INTERNAL_UVD_SD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_BOOT : +return adev->pm.dpm.boot_ps; +case POWER_STATE_TYPE_INTERNAL_THERMAL : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ACPI : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ULV : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_3DPERF : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) +return ps; +break ; +default : +break ; + } + } +/* use a fallback state if we didn't match */ +switch (dpm_state) { +case POWER_STATE_TYPE_INTERNAL_UVD_SD : + dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (adev->pm.dpm.uvd_ps) { +return adev->pm.dpm.uvd_ps; + }else { + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search; + } +case POWER_STATE_TYPE_INTERNAL_THERMAL :drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1469
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_ACPI : + dpm_state =POWER_STATE_TYPE_BATTERY ; + goto restart_search; +case POWER_STATE_TYPE_BATTERY : +case POWER_STATE_TYPE_BALANCED : +case POWER_STATE_TYPE_INTERNAL_3DPERF : + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search;I think it will be a good idea to move
restart_searchblock to a function so we can easilyrule out any infinite loops with "goto
restart_search" usages.Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +21
-0+default : +break ; + } + +return NULL ; +} + +static void amdgpu_dpm_change_power_state_locked (struct +amdgpu_device *adev) { +struct amdgpu_ps *ps; +enum amd_pm_state_type dpm_state; +int ret; +bool equal = false; + +/* if dpm init failed */ +if (!adev->pm.dpm_enabled) +return ; + +if (adev->pm.dpm.user_state != adev->pm.dpm.state) { +/* add other state override checks here */ + if ((!adev->pm.dpm.thermal_active) &&drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1500
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ (!adev->pm.dpm.uvd_active)) + adev->pm.dpm.state = adev->pm.dpm.user_state; + } + dpm_state = adev->pm.dpm.state; + + ps =amdgpu_dpm_pick_power_state (adev, dpm_state); +if (ps) + adev->pm.dpm.requested_ps = ps; +else +return ;nitpick:
if(!ns)
return;
adev->pm.dpm.requested_ps= ps;Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ +if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { +printk ("switching from power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); +printk ("switching to power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); + } + +/* update whether vce is active */ + ps->vce_active = adev->pm.dpm.vce_active;drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+if (adev->powerplay.pp_funcs->display_configuration_changed) +amdgpu_dpm_display_configuration_changed (adev); + + ret =amdgpu_dpm_pre_set_power_state (adev); +if (ret) +return ; + +if (adev->powerplay.pp_funcs->check_state_equal) { +if (0 !=amdgpu_dpm_check_state_equal (adev, + adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))We don't need that check as
amdgpu_dpm_check_state_equal()should not modify (default)value of"equal" on error.
Nirmoy
Quoted 678 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +170
-0+ equal = false; + } + +if (equal) +return ; + +amdgpu_dpm_set_power_state (adev); +amdgpu_dpm_post_set_power_state (adev); + + adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; + adev->pm.dpm.current_active_crtc_count = + adev->pm.dpm.new_active_crtc_count; + +if (adev->powerplay.pp_funcs->force_performance_level) { +if (adev->pm.dpm.thermal_active) { +enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; +/* force low perf level for thermal */ +amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); +/* save the user's level */ + adev->pm.dpm.forced_level = level; + }else { +/* otherwise, user selected level */ +amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); + } + } +} + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) { +int i =0 ; + +if (!adev->pm.dpm_enabled) +return ; + +if (adev->mode_info.num_crtc) +amdgpu_display_bandwidth_update (adev); + +for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { +struct amdgpu_ring *ring = adev->rings[i]; +if (ring && ring->sched.ready) +amdgpu_fence_wait_empty (ring); + } + +if (is_support_sw_smu (adev)) { +struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; +smu_handle_task (&adev->smu, + smu_dpm->dpm_level, +AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , + true); + }else { +if (adev->powerplay.pp_funcs->dispatch_tasks) { +if (!amdgpu_device_has_dc_support (adev)) { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); + adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; + adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); + adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); +/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ +if (adev->pm.pm_display_cfg.vrefresh >120 ) + adev->pm.pm_display_cfg.min_vblank_time =0 ; +if (adev->powerplay.pp_funcs->display_configuration_change) + adev->powerplay.pp_funcs->display_configuration_change ( + adev->powerplay.pp_handle, + &adev->pm.pm_display_cfg); +mutex_unlock (&adev->pm.mutex); + } +amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); + }else { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); +amdgpu_dpm_change_power_state_locked (adev); +mutex_unlock (&adev->pm.mutex); + } + } +} + +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.uvd_active = true; + adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; + }else { + adev->pm.dpm.uvd_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); +if (ret) +DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + +/* enable/disable Low Memory PState for UVD (4k videos) */ +if (adev->asic_type ==CHIP_STONEY && + adev->uvd.decode_image_width >=WIDTH_4K ) { +struct pp_hwmgr *hwmgr = + adev->powerplay.pp_handle; + +if (hwmgr && hwmgr->hwmgr_func && + hwmgr->hwmgr_func->update_nbdpm_pstate) + hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, + !enable, + true); + } + } +} + +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.vce_active = true; +/* XXX select vce level based on ring/task */ + adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; + }else { + adev->pm.dpm.vce_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); +if (ret) +DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + } +} + +void amdgpu_pm_print_power_states (struct amdgpu_device *adev) { +int i; + +if (adev->powerplay.pp_funcs->print_power_state ==NULL ) +return ; + +for (i =0 ; i < adev->pm.dpm.num_ps; i++) +amdgpu_dpm_print_power_state (adev, + &adev->pm.dpm.ps[i]); + +} + +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool +enable) { +int ret =0 ; + + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); +if (ret) +DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); } + +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev, +uint32_t *smu_version) { +int r; + +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { + r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); +if (r) { +pr_err ("smu firmware loading failed\n" ); +return r; + } + *smu_version = adev->pm.fw_version; + } +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +15
-0@@ -548,4 +548,18 @@ int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev,bool acquire); +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev); + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size); + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work); + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev);void +amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool +enable);void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev, +bool enable);void amdgpu_pm_print_power_states (struct +amdgpu_device *adev);int amdgpu_pm_load_smu_firmware (struct +amdgpu_device *adev,uint32_t *smu_version); +#endif drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-3@@ -29,17 +29,14 @@#include "amdgpu_drv.h" #include "amdgpu_pm.h" #include "amdgpu_dpm.h" -#include "amdgpu_display.h" #include "amdgpu_smu.h" #include "atom.h" -#include <linux/power_supply.h> #include <linux/pci.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/nospec.h> #include <linux/pm_runtime.h> #include "hwmgr.h" -#define WIDTH_4K 3840static const struct cg_flag_name clocks[] = { {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain ClockGating"}, @@ -81,45 +78,6 @@ static const struct hwmon_temp_label { {PP_TEMP_MEM, "mem"},};
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-413-void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev) -{ -if (adev->pm.dpm_enabled) { -mutex_lock (&adev->pm.mutex); -if (power_supply_is_system_supplied () >0 ) - adev->pm.ac_power = true; -else - adev->pm.ac_power = false; -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->enable_bapm) -amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); -mutex_unlock (&adev->pm.mutex); - -if (is_support_sw_smu (adev)) -smu_set_ac_dc (&adev->smu); - } -} - -int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, -void *data,uint32_t *size) -{ -int ret =0 ; - -if (!data || !size) -return -EINVAL ; - -if (is_support_sw_smu (adev)) - ret =smu_read_sensor (&adev->smu, sensor, data, size); -else { -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) - ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, - sensor, data, size); -else - ret = -EINVAL ; - } - -return ret; -} -/** * DOC: power_dpm_state * @@ -3636,338 +3594,6 @@ static const struct attribute_group *hwmon_groups[] = {NULL }; -void amdgpu_dpm_thermal_work_handler(struct work_struct *work) -{ -struct amdgpu_device *adev = - container_of(work, struct amdgpu_device, - pm.dpm.thermal.work); -/* switch to the thermal state */ -enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; -int temp, size =sizeof (temp); - -if (!adev->pm.dpm_enabled) -return ; - -if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , - (void *)&temp, &size)) { -if (temp < adev->pm.dpm.thermal.min_temp) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - }else { -if (adev->pm.dpm.thermal.high_to_low) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - } -mutex_lock (&adev->pm.mutex); -if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) - adev->pm.dpm.thermal_active = true; -else - adev->pm.dpm.thermal_active = false; - adev->pm.dpm.state = dpm_state; -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); -} - -static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, -enum amd_pm_state_type dpm_state) -{ -int i; -struct amdgpu_ps *ps; -u32 ui_class; -bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? - true : false; - -/* check if the vblank period is too short to adjust the mclk */ -if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { -if (amdgpu_dpm_vblank_too_short (adev)) - single_display = false; - } - -/* certain older asics have a separare 3D performance state, -* so try that first if the user selected performance -*/ -if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) - dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; -/* balanced states don't exist at the moment */ -if (dpm_state ==POWER_STATE_TYPE_BALANCED ) - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - -restart_search: -/* Pick the best power state based on current conditions */ -for (i =0 ; i < adev->pm.dpm.num_ps; i++) { - ps = &adev->pm.dpm.ps[i]; - ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; -switch (dpm_state) { -/* user states */ -case POWER_STATE_TYPE_BATTERY : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_BALANCED : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_PERFORMANCE : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -/* internal states */ -case POWER_STATE_TYPE_INTERNAL_UVD : -if (adev->pm.dpm.uvd_ps) -return adev->pm.dpm.uvd_ps; -else -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_SD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_BOOT : -return adev->pm.dpm.boot_ps; -case POWER_STATE_TYPE_INTERNAL_THERMAL : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ACPI : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ULV : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_3DPERF : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) -return ps; -break ; -default : -break ; - } - } -/* use a fallback state if we didn't match */ -switch (dpm_state) { -case POWER_STATE_TYPE_INTERNAL_UVD_SD : - dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (adev->pm.dpm.uvd_ps) { -return adev->pm.dpm.uvd_ps; - }else { - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; - } -case POWER_STATE_TYPE_INTERNAL_THERMAL : - dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_ACPI : - dpm_state =POWER_STATE_TYPE_BATTERY ; - goto restart_search; -case POWER_STATE_TYPE_BATTERY : -case POWER_STATE_TYPE_BALANCED : -case POWER_STATE_TYPE_INTERNAL_3DPERF : - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; -default : -break ; - } - -return NULL ; -} - -static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) -{ -struct amdgpu_ps *ps; -enum amd_pm_state_type dpm_state; -int ret; -bool equal = false; - -/* if dpm init failed */ -if (!adev->pm.dpm_enabled) -return ; - -if (adev->pm.dpm.user_state != adev->pm.dpm.state) { -/* add other state override checks here */ -if ((!adev->pm.dpm.thermal_active) && - (!adev->pm.dpm.uvd_active)) - adev->pm.dpm.state = adev->pm.dpm.user_state; - } - dpm_state = adev->pm.dpm.state; - - ps =amdgpu_dpm_pick_power_state (adev, dpm_state); -if (ps) - adev->pm.dpm.requested_ps = ps; -else -return ; - -if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { -printk ("switching from power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); -printk ("switching to power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); - } - -/* update whether vce is active */ - ps->vce_active = adev->pm.dpm.vce_active; -if (adev->powerplay.pp_funcs->display_configuration_changed) -amdgpu_dpm_display_configuration_changed (adev); - - ret =amdgpu_dpm_pre_set_power_state (adev); -if (ret) -return ; - -if (adev->powerplay.pp_funcs->check_state_equal) { -if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) - equal = false; - } - -if (equal) -return ; - -amdgpu_dpm_set_power_state (adev); -amdgpu_dpm_post_set_power_state (adev); - - adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; - adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; - -if (adev->powerplay.pp_funcs->force_performance_level) { -if (adev->pm.dpm.thermal_active) { -enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; -/* force low perf level for thermal */ -amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); -/* save the user's level */ - adev->pm.dpm.forced_level = level; - }else { -/* otherwise, user selected level */ -amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); - } - } -} - -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.uvd_active = true; - adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; - }else { - adev->pm.dpm.uvd_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); -if (ret) -DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - -/* enable/disable Low Memory PState for UVD (4k videos) */ -if (adev->asic_type ==CHIP_STONEY && - adev->uvd.decode_image_width >=WIDTH_4K ) { -struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; - -if (hwmgr && hwmgr->hwmgr_func && - hwmgr->hwmgr_func->update_nbdpm_pstate) - hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, - !enable, - true); - } - } -} - -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.vce_active = true; -/* XXX select vce level based on ring/task */ - adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; - }else { - adev->pm.dpm.vce_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); -if (ret) -DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - } -} - -void amdgpu_pm_print_power_states(struct amdgpu_device *adev) -{ -int i; - -if (adev->powerplay.pp_funcs->print_power_state ==NULL ) -return ; - -for (i =0 ; i < adev->pm.dpm.num_ps; i++) -amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); - -} - -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); -if (ret) -DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); -} - -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev, uint32_t *smu_version) -{ -int r; - -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { - r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); -if (r) { -pr_err ("smu firmware loading failed\n" ); -return r; - } - *smu_version = adev->pm.fw_version; - } -return 0 ; -} -int amdgpu_pm_sysfs_init (struct amdgpu_device *adev) {int ret;@@ -4028,55 +3654,6 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)amdgpu_device_attr_remove_groups (adev, &adev->pm.pm_attr_list); } -void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) -{ -int i =0 ; - -if (!adev->pm.dpm_enabled) -return ; - -if (adev->mode_info.num_crtc) -amdgpu_display_bandwidth_update (adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { -struct amdgpu_ring *ring = adev->rings[i]; -if (ring && ring->sched.ready) -amdgpu_fence_wait_empty (ring); - } - -if (is_support_sw_smu (adev)) { -struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; -smu_handle_task (&adev->smu, - smu_dpm->dpm_level, -AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , - true); - }else { -if (adev->powerplay.pp_funcs->dispatch_tasks) { -if (!amdgpu_device_has_dc_support (adev)) { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); - adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; - adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); - adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); -/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ -if (adev->pm.pm_display_cfg.vrefresh >120 ) - adev->pm.pm_display_cfg.min_vblank_time =0 ; -if (adev->powerplay.pp_funcs->display_configuration_change) - adev->powerplay.pp_funcs->display_configuration_change ( - adev->powerplay.pp_handle, - &adev->pm.pm_display_cfg); -mutex_unlock (&adev->pm.mutex); - } -amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); - }else { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); -amdgpu_dpm_change_power_state_locked (adev); -mutex_unlock (&adev->pm.mutex); - } - } -} -/* * Debugfs info */ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0
-1@@ -79,18 +79,10 @@ struct amdgpu_device_attr_entry { amdgpu_get_##_name, NULL, \ _flags, ##__VA_ARGS__) -void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev); int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);int amdgpu_pm_virt_sysfs_init (struct amdgpu_device *adev);void amdgpu_pm_sysfs_fini (struct amdgpu_device *adev);void amdgpu_pm_virt_sysfs_fini (struct amdgpu_device *adev); -void
amdgpu_pm_print_power_states(struct amdgpu_device *adev); -intamdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version); -voidamdgpu_pm_compute_clocks(struct amdgpu_device *adev); -voidamdgpu_dpm_thermal_work_handler(struct work_struct *work); -voidamdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable); -voidamdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable); -voidamdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);
Quoted 10 lines
Quoted 2 lines
int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
s.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cev an.quan%40amd.com%7Cf9fcda91b3c64a60a4ba08d83f904d77%7C3dd8961fe4884e6 08e11a82d994e183d%7C0%7C0%7C637329236297410452&sdata=dxfigPWqRxyc4 88M%2BE4L5RfbODakgzSRyYxnX0rA0Ak%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH 4/4] drm/amd/powerplay: put those exposed power interfaces in amdgpu_dpm.c
Quoted 4 lines · Evan
[AMD Official Use Only - Internal Distribution Only]
Yes, I would like to make another patch to address Nirmoy's comments. @Das, Nirmoy is that OK?
Yes.
Nirmoy
Quoted 10 lines
BR
Evan
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, August 13, 2020 9:54 PM
To: Das, Nirmoy <[email protected]>
Cc: Quan, Evan <[email protected]>; amd-gfx list <[email protected]>; Deucher, Alexander <[email protected]>
Subject: Re: [PATCH 4/4] drm/amd/powerplay: put those exposed power interfaces inamdgpu_dpm.c
Quoted 1,011 lines
Series is:
Alex
Quoted 1,005 lines · Nirmoy
below for
more comments.
Quoted 155 lines · Evan Quan
As other power interfaces.
Change-Id I5e3b85ae21c4b1d0239f54fa75247b33cfdb7ddcSigned-off-by Evan Quan <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c | 425 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h | 14 + drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c | 423 ----------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h | 8 - 4 files changed, 439 insertions(+), 431 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +127
-0@@ -28,6 +28,11 @@#include "amdgpu_dpm.h" #include "atom.h" #include "amd_pcie.h" +#include "amdgpu_display.h" +#include "hwmgr.h" +#include <linux/power_supply.h> + +#define WIDTH_4K 3840void amdgpu_dpm_print_class_info (u32 class,u32 class2) {@@ -1262,3 +1267,423 @@ int amdgpu_dpm_smu_i2c_bus_access(structamdgpu_device *adev, return ret; } + +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev) { +if (adev->pm.dpm_enabled) { +mutex_lock (&adev->pm.mutex); +if (power_supply_is_system_supplied () >0 ) + adev->pm.ac_power = true; +else + adev->pm.ac_power = false; +if (adev->powerplay.pp_funcs && + adev->powerplay.pp_funcs->enable_bapm) +amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); +mutex_unlock (&adev->pm.mutex); + +if (is_support_sw_smu (adev)) +smu_set_ac_dc (&adev->smu); + } +} + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size) { +int ret =0 ; + +if (!data || !size) +return -EINVAL ; + +if (is_support_sw_smu (adev)) + ret =smu_read_sensor (&adev->smu, sensor, data, size); +else { +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) + ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, + sensor, data, size); +else + ret = -EINVAL ; + } + +return ret; +} + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work) { +struct amdgpu_device *adev = + container_of(work, struct amdgpu_device, + pm.dpm.thermal.work); +/* switch to the thermal state */ +enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; +int temp, size =sizeof (temp); + +if (!adev->pm.dpm_enabled) +return ; + +if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , + (void *)&temp, &size)) { +if (temp < adev->pm.dpm.thermal.min_temp) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + }else { +if (adev->pm.dpm.thermal.high_to_low) +/* switch back the user state */ + dpm_state = adev->pm.dpm.user_state; + } +mutex_lock (&adev->pm.mutex); +if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) + adev->pm.dpm.thermal_active = true; +else + adev->pm.dpm.thermal_active = false; + adev->pm.dpm.state = dpm_state; +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); } + +static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, +enum +amd_pm_state_type dpm_state) { +int i; +struct amdgpu_ps *ps; +u32 ui_class; +bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? + true : false; + +/* check if the vblank period is too short to adjust the mclk */ +if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { +if (amdgpu_dpm_vblank_too_short (adev)) + single_display = false; + } + +/* certain older asics have a separare 3D performance state, +* so try that first if the user selected performance +*/ +if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) + dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; +/* balanced states don't exist at the moment */ +if (dpm_state ==POWER_STATE_TYPE_BALANCED ) + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + +restart_search: +/* Pick the best power state based on current conditions */ +for (i =0 ; i < adev->pm.dpm.num_ps; i++) { + ps = &adev->pm.dpm.ps[i]; + ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; +switch (dpm_state) { +/* user states */ +case POWER_STATE_TYPE_BATTERY : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_BALANCED : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display) +return ps; + }else +return ps; + } +break ; +case POWER_STATE_TYPE_PERFORMANCE : +if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { +if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { +if (single_display)drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct · line 1405
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+return ps; + }else +return ps; + } +break ; +/* internal states */ +case POWER_STATE_TYPE_INTERNAL_UVD : +if (adev->pm.dpm.uvd_ps) +return adev->pm.dpm.uvd_ps; +else We don't need the "else" here.
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +54
-0+break ; +case POWER_STATE_TYPE_INTERNAL_UVD_SD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_BOOT : +return adev->pm.dpm.boot_ps; +case POWER_STATE_TYPE_INTERNAL_THERMAL : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ACPI : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_ULV : +if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) +return ps; +break ; +case POWER_STATE_TYPE_INTERNAL_3DPERF : +if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) +return ps; +break ; +default : +break ; + } + } +/* use a fallback state if we didn't match */ +switch (dpm_state) { +case POWER_STATE_TYPE_INTERNAL_UVD_SD : + dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_UVD_HD : +case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : +case POWER_STATE_TYPE_INTERNAL_UVD_MVC : +if (adev->pm.dpm.uvd_ps) { +return adev->pm.dpm.uvd_ps; + }else { + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search; + } +case POWER_STATE_TYPE_INTERNAL_THERMAL :drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1469
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; + goto restart_search; +case POWER_STATE_TYPE_INTERNAL_ACPI : + dpm_state =POWER_STATE_TYPE_BATTERY ; + goto restart_search; +case POWER_STATE_TYPE_BATTERY : +case POWER_STATE_TYPE_BALANCED : +case POWER_STATE_TYPE_INTERNAL_3DPERF : + dpm_state =POWER_STATE_TYPE_PERFORMANCE ; + goto restart_search;I think it will be a good idea to move
restart_searchblock to a function so we can easilyrule out any infinite loops with "goto
restart_search" usages.Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +21
-0+default : +break ; + } + +return NULL ; +} + +static void amdgpu_dpm_change_power_state_locked (struct +amdgpu_device *adev) { +struct amdgpu_ps *ps; +enum amd_pm_state_type dpm_state; +int ret; +bool equal = false; + +/* if dpm init failed */ +if (!adev->pm.dpm_enabled) +return ; + +if (adev->pm.dpm.user_state != adev->pm.dpm.state) { +/* add other state override checks here */ + if ((!adev->pm.dpm.thermal_active) &&drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev, · line 1500
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ (!adev->pm.dpm.uvd_active)) + adev->pm.dpm.state = adev->pm.dpm.user_state; + } + dpm_state = adev->pm.dpm.state; + + ps =amdgpu_dpm_pick_power_state (adev, dpm_state); +if (ps) + adev->pm.dpm.requested_ps = ps; +else +return ;nitpick:
if(!ns)
return;
adev->pm.dpm.requested_ps= ps;Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+ +if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { +printk ("switching from power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); +printk ("switching to power state:\n" ); +amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); + } + +/* update whether vce is active */ + ps->vce_active = adev->pm.dpm.vce_active;drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c int amdgpu_dpm_smu_i2c_bus_access(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +10
-0+if (adev->powerplay.pp_funcs->display_configuration_changed) +amdgpu_dpm_display_configuration_changed (adev); + + ret =amdgpu_dpm_pre_set_power_state (adev); +if (ret) +return ; + +if (adev->powerplay.pp_funcs->check_state_equal) { +if (0 !=amdgpu_dpm_check_state_equal (adev, + adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))We don't need that check as
amdgpu_dpm_check_state_equal()should not modify (default)value of"equal" on error.
Nirmoy
Quoted 678 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.c +170
-0+ equal = false; + } + +if (equal) +return ; + +amdgpu_dpm_set_power_state (adev); +amdgpu_dpm_post_set_power_state (adev); + + adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; + adev->pm.dpm.current_active_crtc_count = + adev->pm.dpm.new_active_crtc_count; + +if (adev->powerplay.pp_funcs->force_performance_level) { +if (adev->pm.dpm.thermal_active) { +enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; +/* force low perf level for thermal */ +amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); +/* save the user's level */ + adev->pm.dpm.forced_level = level; + }else { +/* otherwise, user selected level */ +amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); + } + } +} + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev) { +int i =0 ; + +if (!adev->pm.dpm_enabled) +return ; + +if (adev->mode_info.num_crtc) +amdgpu_display_bandwidth_update (adev); + +for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { +struct amdgpu_ring *ring = adev->rings[i]; +if (ring && ring->sched.ready) +amdgpu_fence_wait_empty (ring); + } + +if (is_support_sw_smu (adev)) { +struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; +smu_handle_task (&adev->smu, + smu_dpm->dpm_level, +AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , + true); + }else { +if (adev->powerplay.pp_funcs->dispatch_tasks) { +if (!amdgpu_device_has_dc_support (adev)) { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); + adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; + adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); + adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); +/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ +if (adev->pm.pm_display_cfg.vrefresh >120 ) + adev->pm.pm_display_cfg.min_vblank_time =0 ; +if (adev->powerplay.pp_funcs->display_configuration_change) + adev->powerplay.pp_funcs->display_configuration_change ( + adev->powerplay.pp_handle, + &adev->pm.pm_display_cfg); +mutex_unlock (&adev->pm.mutex); + } +amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); + }else { +mutex_lock (&adev->pm.mutex); +amdgpu_dpm_get_active_displays (adev); +amdgpu_dpm_change_power_state_locked (adev); +mutex_unlock (&adev->pm.mutex); + } + } +} + +void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.uvd_active = true; + adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; + }else { + adev->pm.dpm.uvd_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); +if (ret) +DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + +/* enable/disable Low Memory PState for UVD (4k videos) */ +if (adev->asic_type ==CHIP_STONEY && + adev->uvd.decode_image_width >=WIDTH_4K ) { +struct pp_hwmgr *hwmgr = + adev->powerplay.pp_handle; + +if (hwmgr && hwmgr->hwmgr_func && + hwmgr->hwmgr_func->update_nbdpm_pstate) + hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, + !enable, + true); + } + } +} + +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) +{ +int ret =0 ; + +if (adev->family ==AMDGPU_FAMILY_SI ) { +mutex_lock (&adev->pm.mutex); +if (enable) { + adev->pm.dpm.vce_active = true; +/* XXX select vce level based on ring/task */ + adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; + }else { + adev->pm.dpm.vce_active = false; + } +mutex_unlock (&adev->pm.mutex); + +amdgpu_pm_compute_clocks (adev); + }else { + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); +if (ret) +DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); + } +} + +void amdgpu_pm_print_power_states (struct amdgpu_device *adev) { +int i; + +if (adev->powerplay.pp_funcs->print_power_state ==NULL ) +return ; + +for (i =0 ; i < adev->pm.dpm.num_ps; i++) +amdgpu_dpm_print_power_state (adev, + &adev->pm.dpm.ps[i]); + +} + +void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool +enable) { +int ret =0 ; + + ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); +if (ret) +DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , + enable ?"enable" :"disable" , ret); } + +int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev, +uint32_t *smu_version) { +int r; + +if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { + r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); +if (r) { +pr_err ("smu firmware loading failed\n" ); +return r; + } + *smu_version = adev->pm.fw_version; + } +return 0 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_dpm.h +15
-0@@ -548,4 +548,18 @@ int amdgpu_dpm_set_clockgating_by_smu(struct amdgpu_device *adev,int amdgpu_dpm_smu_i2c_bus_access (struct amdgpu_device *adev,bool acquire); +void amdgpu_pm_acpi_event_handler (struct amdgpu_device *adev); + +int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, +void *data,uint32_t *size); + +void amdgpu_dpm_thermal_work_handler (struct work_struct *work); + +void amdgpu_pm_compute_clocks (struct amdgpu_device *adev);void +amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable); +void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool +enable);void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev, +bool enable);void amdgpu_pm_print_power_states (struct +amdgpu_device *adev);int amdgpu_pm_load_smu_firmware (struct +amdgpu_device *adev,uint32_t *smu_version); +#endif drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-3@@ -29,17 +29,14 @@#include "amdgpu_drv.h" #include "amdgpu_pm.h" #include "amdgpu_dpm.h" -#include "amdgpu_display.h" #include "amdgpu_smu.h" #include "atom.h" -#include <linux/power_supply.h> #include <linux/pci.h> #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/nospec.h> #include <linux/pm_runtime.h> #include "hwmgr.h" -#define WIDTH_4K 3840static const struct cg_flag_name clocks[] = { {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain ClockGating"}, @@ -81,45 +78,6 @@ static const struct hwmon_temp_label { {PP_TEMP_MEM, "mem"},};
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c +0
-413-void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev) -{ -if (adev->pm.dpm_enabled) { -mutex_lock (&adev->pm.mutex); -if (power_supply_is_system_supplied () >0 ) - adev->pm.ac_power = true; -else - adev->pm.ac_power = false; -if (adev->powerplay.pp_funcs && - adev->powerplay.pp_funcs->enable_bapm) -amdgpu_dpm_enable_bapm (adev, adev->pm.ac_power); -mutex_unlock (&adev->pm.mutex); - -if (is_support_sw_smu (adev)) -smu_set_ac_dc (&adev->smu); - } -} - -int amdgpu_dpm_read_sensor (struct amdgpu_device *adev,enum amd_pp_sensors sensor, -void *data,uint32_t *size) -{ -int ret =0 ; - -if (!data || !size) -return -EINVAL ; - -if (is_support_sw_smu (adev)) - ret =smu_read_sensor (&adev->smu, sensor, data, size); -else { -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor) - ret = adev->powerplay.pp_funcs->read_sensor ((adev)->powerplay.pp_handle, - sensor, data, size); -else - ret = -EINVAL ; - } - -return ret; -} -/** * DOC: power_dpm_state * @@ -3636,338 +3594,6 @@ static const struct attribute_group *hwmon_groups[] = {NULL }; -void amdgpu_dpm_thermal_work_handler(struct work_struct *work) -{ -struct amdgpu_device *adev = - container_of(work, struct amdgpu_device, - pm.dpm.thermal.work); -/* switch to the thermal state */ -enum amd_pm_state_type dpm_state =POWER_STATE_TYPE_INTERNAL_THERMAL ; -int temp, size =sizeof (temp); - -if (!adev->pm.dpm_enabled) -return ; - -if (!amdgpu_dpm_read_sensor (adev,AMDGPU_PP_SENSOR_GPU_TEMP , - (void *)&temp, &size)) { -if (temp < adev->pm.dpm.thermal.min_temp) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - }else { -if (adev->pm.dpm.thermal.high_to_low) -/* switch back the user state */ - dpm_state = adev->pm.dpm.user_state; - } -mutex_lock (&adev->pm.mutex); -if (dpm_state ==POWER_STATE_TYPE_INTERNAL_THERMAL ) - adev->pm.dpm.thermal_active = true; -else - adev->pm.dpm.thermal_active = false; - adev->pm.dpm.state = dpm_state; -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); -} - -static struct amdgpu_ps *amdgpu_dpm_pick_power_state (struct amdgpu_device *adev, -enum amd_pm_state_type dpm_state) -{ -int i; -struct amdgpu_ps *ps; -u32 ui_class; -bool single_display = (adev->pm.dpm.new_active_crtc_count <2 ) ? - true : false; - -/* check if the vblank period is too short to adjust the mclk */ -if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { -if (amdgpu_dpm_vblank_too_short (adev)) - single_display = false; - } - -/* certain older asics have a separare 3D performance state, -* so try that first if the user selected performance -*/ -if (dpm_state ==POWER_STATE_TYPE_PERFORMANCE ) - dpm_state =POWER_STATE_TYPE_INTERNAL_3DPERF ; -/* balanced states don't exist at the moment */ -if (dpm_state ==POWER_STATE_TYPE_BALANCED ) - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - -restart_search: -/* Pick the best power state based on current conditions */ -for (i =0 ; i < adev->pm.dpm.num_ps; i++) { - ps = &adev->pm.dpm.ps[i]; - ui_class = ps->class &ATOM_PPLIB_CLASSIFICATION_UI_MASK ; -switch (dpm_state) { -/* user states */ -case POWER_STATE_TYPE_BATTERY : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BATTERY ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_BALANCED : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_BALANCED ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -case POWER_STATE_TYPE_PERFORMANCE : -if (ui_class ==ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE ) { -if (ps->caps &ATOM_PPLIB_SINGLE_DISPLAY_ONLY ) { -if (single_display) -return ps; - }else -return ps; - } -break ; -/* internal states */ -case POWER_STATE_TYPE_INTERNAL_UVD : -if (adev->pm.dpm.uvd_ps) -return adev->pm.dpm.uvd_ps; -else -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_SD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_SDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HDSTATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_HD2STATE ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_MVC ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_BOOT : -return adev->pm.dpm.boot_ps; -case POWER_STATE_TYPE_INTERNAL_THERMAL : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_THERMAL ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ACPI : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_ACPI ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_ULV : -if (ps->class2 &ATOM_PPLIB_CLASSIFICATION2_ULV ) -return ps; -break ; -case POWER_STATE_TYPE_INTERNAL_3DPERF : -if (ps->class &ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE ) -return ps; -break ; -default : -break ; - } - } -/* use a fallback state if we didn't match */ -switch (dpm_state) { -case POWER_STATE_TYPE_INTERNAL_UVD_SD : - dpm_state =POWER_STATE_TYPE_INTERNAL_UVD_HD ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_UVD_HD : -case POWER_STATE_TYPE_INTERNAL_UVD_HD2 : -case POWER_STATE_TYPE_INTERNAL_UVD_MVC : -if (adev->pm.dpm.uvd_ps) { -return adev->pm.dpm.uvd_ps; - }else { - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; - } -case POWER_STATE_TYPE_INTERNAL_THERMAL : - dpm_state =POWER_STATE_TYPE_INTERNAL_ACPI ; - goto restart_search; -case POWER_STATE_TYPE_INTERNAL_ACPI : - dpm_state =POWER_STATE_TYPE_BATTERY ; - goto restart_search; -case POWER_STATE_TYPE_BATTERY : -case POWER_STATE_TYPE_BALANCED : -case POWER_STATE_TYPE_INTERNAL_3DPERF : - dpm_state =POWER_STATE_TYPE_PERFORMANCE ; - goto restart_search; -default : -break ; - } - -return NULL ; -} - -static void amdgpu_dpm_change_power_state_locked (struct amdgpu_device *adev) -{ -struct amdgpu_ps *ps; -enum amd_pm_state_type dpm_state; -int ret; -bool equal = false; - -/* if dpm init failed */ -if (!adev->pm.dpm_enabled) -return ; - -if (adev->pm.dpm.user_state != adev->pm.dpm.state) { -/* add other state override checks here */ -if ((!adev->pm.dpm.thermal_active) && - (!adev->pm.dpm.uvd_active)) - adev->pm.dpm.state = adev->pm.dpm.user_state; - } - dpm_state = adev->pm.dpm.state; - - ps =amdgpu_dpm_pick_power_state (adev, dpm_state); -if (ps) - adev->pm.dpm.requested_ps = ps; -else -return ; - -if (amdgpu_dpm ==1 && adev->powerplay.pp_funcs->print_power_state) { -printk ("switching from power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.current_ps); -printk ("switching to power state:\n" ); -amdgpu_dpm_print_power_state (adev, adev->pm.dpm.requested_ps); - } - -/* update whether vce is active */ - ps->vce_active = adev->pm.dpm.vce_active; -if (adev->powerplay.pp_funcs->display_configuration_changed) -amdgpu_dpm_display_configuration_changed (adev); - - ret =amdgpu_dpm_pre_set_power_state (adev); -if (ret) -return ; - -if (adev->powerplay.pp_funcs->check_state_equal) { -if (0 !=amdgpu_dpm_check_state_equal (adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) - equal = false; - } - -if (equal) -return ; - -amdgpu_dpm_set_power_state (adev); -amdgpu_dpm_post_set_power_state (adev); - - adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; - adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; - -if (adev->powerplay.pp_funcs->force_performance_level) { -if (adev->pm.dpm.thermal_active) { -enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; -/* force low perf level for thermal */ -amdgpu_dpm_force_performance_level (adev,AMD_DPM_FORCED_LEVEL_LOW ); -/* save the user's level */ - adev->pm.dpm.forced_level = level; - }else { -/* otherwise, user selected level */ -amdgpu_dpm_force_performance_level (adev, adev->pm.dpm.forced_level); - } - } -} - -void amdgpu_dpm_enable_uvd (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.uvd_active = true; - adev->pm.dpm.state =POWER_STATE_TYPE_INTERNAL_UVD ; - }else { - adev->pm.dpm.uvd_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_UVD , !enable); -if (ret) -DRM_ERROR ("Dpm %s uvd failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - -/* enable/disable Low Memory PState for UVD (4k videos) */ -if (adev->asic_type ==CHIP_STONEY && - adev->uvd.decode_image_width >=WIDTH_4K ) { -struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle; - -if (hwmgr && hwmgr->hwmgr_func && - hwmgr->hwmgr_func->update_nbdpm_pstate) - hwmgr->hwmgr_func->update_nbdpm_pstate (hwmgr, - !enable, - true); - } - } -} - -void amdgpu_dpm_enable_vce (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - -if (adev->family ==AMDGPU_FAMILY_SI ) { -mutex_lock (&adev->pm.mutex); -if (enable) { - adev->pm.dpm.vce_active = true; -/* XXX select vce level based on ring/task */ - adev->pm.dpm.vce_level =AMD_VCE_LEVEL_AC_ALL ; - }else { - adev->pm.dpm.vce_active = false; - } -mutex_unlock (&adev->pm.mutex); - -amdgpu_pm_compute_clocks (adev); - }else { - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_VCE , !enable); -if (ret) -DRM_ERROR ("Dpm %s vce failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); - } -} - -void amdgpu_pm_print_power_states(struct amdgpu_device *adev) -{ -int i; - -if (adev->powerplay.pp_funcs->print_power_state ==NULL ) -return ; - -for (i =0 ; i < adev->pm.dpm.num_ps; i++) -amdgpu_dpm_print_power_state (adev, &adev->pm.dpm.ps[i]); - -} - -void amdgpu_dpm_enable_jpeg (struct amdgpu_device *adev,bool enable) -{ -int ret =0 ; - - ret =amdgpu_dpm_set_powergating_by_smu (adev,AMD_IP_BLOCK_TYPE_JPEG , !enable); -if (ret) -DRM_ERROR ("Dpm %s jpeg failed, ret = %d. \n" , - enable ?"enable" :"disable" , ret); -} - -int amdgpu_pm_load_smu_firmware (struct amdgpu_device *adev, uint32_t *smu_version) -{ -int r; - -if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) { - r = adev->powerplay.pp_funcs->load_firmware (adev->powerplay.pp_handle); -if (r) { -pr_err ("smu firmware loading failed\n" ); -return r; - } - *smu_version = adev->pm.fw_version; - } -return 0 ; -} -int amdgpu_pm_sysfs_init (struct amdgpu_device *adev) {int ret;@@ -4028,55 +3654,6 @@ void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)amdgpu_device_attr_remove_groups (adev, &adev->pm.pm_attr_list); } -void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) -{ -int i =0 ; - -if (!adev->pm.dpm_enabled) -return ; - -if (adev->mode_info.num_crtc) -amdgpu_display_bandwidth_update (adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; i++) { -struct amdgpu_ring *ring = adev->rings[i]; -if (ring && ring->sched.ready) -amdgpu_fence_wait_empty (ring); - } - -if (is_support_sw_smu (adev)) { -struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm; -smu_handle_task (&adev->smu, - smu_dpm->dpm_level, -AMD_PP_TASK_DISPLAY_CONFIG_CHANGE , - true); - }else { -if (adev->powerplay.pp_funcs->dispatch_tasks) { -if (!amdgpu_device_has_dc_support (adev)) { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); - adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; - adev->pm.pm_display_cfg.vrefresh =amdgpu_dpm_get_vrefresh (adev); - adev->pm.pm_display_cfg.min_vblank_time =amdgpu_dpm_get_vblank_time (adev); -/* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ -if (adev->pm.pm_display_cfg.vrefresh >120 ) - adev->pm.pm_display_cfg.min_vblank_time =0 ; -if (adev->powerplay.pp_funcs->display_configuration_change) - adev->powerplay.pp_funcs->display_configuration_change ( - adev->powerplay.pp_handle, - &adev->pm.pm_display_cfg); -mutex_unlock (&adev->pm.mutex); - } -amdgpu_dpm_dispatch_task (adev,AMD_PP_TASK_DISPLAY_CONFIG_CHANGE ,NULL ); - }else { -mutex_lock (&adev->pm.mutex); -amdgpu_dpm_get_active_displays (adev); -amdgpu_dpm_change_power_state_locked (adev); -mutex_unlock (&adev->pm.mutex); - } - } -} -/* * Debugfs info */ drivers/gpu/drm/amd/amdgpu/amdgpu_pm.h +0
-1@@ -79,18 +79,10 @@ struct amdgpu_device_attr_entry { amdgpu_get_##_name, NULL, \ _flags, ##__VA_ARGS__) -void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev); int amdgpu_pm_sysfs_init(struct amdgpu_device *adev);int amdgpu_pm_virt_sysfs_init (struct amdgpu_device *adev);void amdgpu_pm_sysfs_fini (struct amdgpu_device *adev);void amdgpu_pm_virt_sysfs_fini (struct amdgpu_device *adev); -void
amdgpu_pm_print_power_states(struct amdgpu_device *adev); -intamdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version); -voidamdgpu_pm_compute_clocks(struct amdgpu_device *adev); -voidamdgpu_dpm_thermal_work_handler(struct work_struct *work); -voidamdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable); -voidamdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable); -voidamdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable);Quoted 2 lines
int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flist
s.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Cev an.quan%40amd.com%7Cf9fcda91b3c64a60a4ba08d83f904d77%7C3dd8961fe4884e6 08e11a82d994e183d%7C0%7C0%7C637329236297410452&sdata=dxfigPWqRxyc4 88M%2BE4L5RfbODakgzSRyYxnX0rA0Ak%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx