[PATCH v2] drm/amdgpu: refactoring the runtime pm mode detection code
refactor the code of runtime pm mode detection to support amdgpu_runtime_pm =2 and 1 two cases Signed-off-by: Ma Jun Reviewed-by: Yang Wang --- v1->v2: - Fix logic and output info (Lijo) - Fix code style (Kevin) --- drivers/gpu/drm/amd/amdgpu/amdgpu.h| 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 75 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c| 48 +- 3 files changed, 77 insertions(+), 47 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 65c17c59c152..e0d7f4ee7e16 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1409,6 +1409,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev); bool amdgpu_device_supports_boco(struct drm_device *dev); bool amdgpu_device_supports_smart_shift(struct drm_device *dev); int amdgpu_device_supports_baco(struct drm_device *dev); +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev); bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev, struct amdgpu_device *peer_adev); int amdgpu_device_baco_enter(struct drm_device *dev); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index f830024cffca..2ea1f47df79c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -350,6 +350,81 @@ int amdgpu_device_supports_baco(struct drm_device *dev) return amdgpu_asic_supports_baco(adev); } +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev) +{ + struct drm_device *dev; + int bamaco_support; + + dev = adev_to_drm(adev); + + adev->pm.rpm_mode = AMDGPU_RUNPM_NONE; + bamaco_support = amdgpu_device_supports_baco(dev); + + switch (amdgpu_runtime_pm) { + case 2: + if (bamaco_support & MACO_SUPPORT) { + adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO; + dev_info(adev->dev, "Forcing BAMACO for runtime pm\n"); + } else if (bamaco_support == BACO_SUPPORT) { + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; + dev_info(adev->dev, "Requested mode BAMACO not available,fallback to use BACO\n"); + } + break; + case 1: + if (bamaco_support & BACO_SUPPORT) { + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; + dev_info(adev->dev, "Forcing BACO for runtime pm\n"); + } + break; + case -1: + case -2: + if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */ + adev->pm.rpm_mode = AMDGPU_RUNPM_PX; + dev_info(adev->dev, "Using ATPX for runtime pm\n"); + } else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */ + adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO; + dev_info(adev->dev, "Using BOCO for runtime pm\n"); + } else { + if (!bamaco_support) + goto no_runtime_pm; + + switch (adev->asic_type) { + case CHIP_VEGA20: + case CHIP_ARCTURUS: + /* BACO are not supported on vega20 and arctrus */ + break; + case CHIP_VEGA10: + /* enable BACO as runpm mode if noretry=0 */ + if (!adev->gmc.noretry) + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; + break; + default: + /* enable BACO as runpm mode on CI+ */ + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; + break; + } + + if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) { + if (bamaco_support & MACO_SUPPORT) { + adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO; + dev_info(adev->dev, "Using BAMACO for runtime pm\n"); + } else { + dev_info(adev->dev, "Using BACO for runtime pm\n"); + } + } + } + break; + case 0: + dev_info(adev->dev, "runtime pm is manually disabled\n"); + break; + default: + break; + } + +no_runtime_pm: + if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) + dev_info(adev->dev, "Runtime PM not available\n"); +} /** * amdgpu_device_supports_smart_shift - Is the device dGPU with * smart shift support diff --git a/dri
Re: [PATCH v2] drm/amdgpu: refactoring the runtime pm mode detection code
ping... Regards, Ma Jun On 4/3/2024 10:57 AM, Ma Jun wrote: > refactor the code of runtime pm mode detection to support > amdgpu_runtime_pm =2 and 1 two cases > > Signed-off-by: Ma Jun > Reviewed-by: Yang Wang > --- > v1->v2: > - Fix logic and output info (Lijo) > - Fix code style (Kevin) > --- > drivers/gpu/drm/amd/amdgpu/amdgpu.h| 1 + > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 75 ++ > drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c| 48 +- > 3 files changed, 77 insertions(+), 47 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > index 65c17c59c152..e0d7f4ee7e16 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -1409,6 +1409,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev); > bool amdgpu_device_supports_boco(struct drm_device *dev); > bool amdgpu_device_supports_smart_shift(struct drm_device *dev); > int amdgpu_device_supports_baco(struct drm_device *dev); > +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev); > bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev, > struct amdgpu_device *peer_adev); > int amdgpu_device_baco_enter(struct drm_device *dev); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index f830024cffca..2ea1f47df79c 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -350,6 +350,81 @@ int amdgpu_device_supports_baco(struct drm_device *dev) > return amdgpu_asic_supports_baco(adev); > } > > +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev) > +{ > + struct drm_device *dev; > + int bamaco_support; > + > + dev = adev_to_drm(adev); > + > + adev->pm.rpm_mode = AMDGPU_RUNPM_NONE; > + bamaco_support = amdgpu_device_supports_baco(dev); > + > + switch (amdgpu_runtime_pm) { > + case 2: > + if (bamaco_support & MACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO; > + dev_info(adev->dev, "Forcing BAMACO for runtime pm\n"); > + } else if (bamaco_support == BACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + dev_info(adev->dev, "Requested mode BAMACO not > available,fallback to use BACO\n"); > + } > + break; > + case 1: > + if (bamaco_support & BACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + dev_info(adev->dev, "Forcing BACO for runtime pm\n"); > + } > + break; > + case -1: > + case -2: > + if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime > mode */ > + adev->pm.rpm_mode = AMDGPU_RUNPM_PX; > + dev_info(adev->dev, "Using ATPX for runtime pm\n"); > + } else if (amdgpu_device_supports_boco(dev)) { /* enable boco > as runtime mode */ > + adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO; > + dev_info(adev->dev, "Using BOCO for runtime pm\n"); > + } else { > + if (!bamaco_support) > + goto no_runtime_pm; > + > + switch (adev->asic_type) { > + case CHIP_VEGA20: > + case CHIP_ARCTURUS: > + /* BACO are not supported on vega20 and arctrus > */ > + break; > + case CHIP_VEGA10: > + /* enable BACO as runpm mode if noretry=0 */ > + if (!adev->gmc.noretry) > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + break; > + default: > + /* enable BACO as runpm mode on CI+ */ > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + break; > + } > + > + if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) { > + if (bamaco_support & MACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO; > + dev_info(adev->dev, "Using BAMACO for > runtime pm\n"); > + } else { > + dev_info(adev->dev, "Using BACO for > runtime pm\n"); > + } > + } > + } > + break; > + case 0: > + dev_info(adev->dev, "runtime pm is manually disabled\n"); > + break; > + default: > + break; > + } > + > +no_runtime_pm: > + if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) > + de
Re: [PATCH v2] drm/amdgpu: refactoring the runtime pm mode detection code
On 4/3/2024 8:27 AM, Ma Jun wrote: > refactor the code of runtime pm mode detection to support > amdgpu_runtime_pm =2 and 1 two cases > > Signed-off-by: Ma Jun > Reviewed-by: Yang Wang Reviewed-by: Lijo Lazar Thanks, Lijo > --- > v1->v2: > - Fix logic and output info (Lijo) > - Fix code style (Kevin) > --- > drivers/gpu/drm/amd/amdgpu/amdgpu.h| 1 + > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 75 ++ > drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c| 48 +- > 3 files changed, 77 insertions(+), 47 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > index 65c17c59c152..e0d7f4ee7e16 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h > @@ -1409,6 +1409,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev); > bool amdgpu_device_supports_boco(struct drm_device *dev); > bool amdgpu_device_supports_smart_shift(struct drm_device *dev); > int amdgpu_device_supports_baco(struct drm_device *dev); > +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev); > bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev, > struct amdgpu_device *peer_adev); > int amdgpu_device_baco_enter(struct drm_device *dev); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index f830024cffca..2ea1f47df79c 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -350,6 +350,81 @@ int amdgpu_device_supports_baco(struct drm_device *dev) > return amdgpu_asic_supports_baco(adev); > } > > +void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev) > +{ > + struct drm_device *dev; > + int bamaco_support; > + > + dev = adev_to_drm(adev); > + > + adev->pm.rpm_mode = AMDGPU_RUNPM_NONE; > + bamaco_support = amdgpu_device_supports_baco(dev); > + > + switch (amdgpu_runtime_pm) { > + case 2: > + if (bamaco_support & MACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO; > + dev_info(adev->dev, "Forcing BAMACO for runtime pm\n"); > + } else if (bamaco_support == BACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + dev_info(adev->dev, "Requested mode BAMACO not > available,fallback to use BACO\n"); > + } > + break; > + case 1: > + if (bamaco_support & BACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + dev_info(adev->dev, "Forcing BACO for runtime pm\n"); > + } > + break; > + case -1: > + case -2: > + if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime > mode */ > + adev->pm.rpm_mode = AMDGPU_RUNPM_PX; > + dev_info(adev->dev, "Using ATPX for runtime pm\n"); > + } else if (amdgpu_device_supports_boco(dev)) { /* enable boco > as runtime mode */ > + adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO; > + dev_info(adev->dev, "Using BOCO for runtime pm\n"); > + } else { > + if (!bamaco_support) > + goto no_runtime_pm; > + > + switch (adev->asic_type) { > + case CHIP_VEGA20: > + case CHIP_ARCTURUS: > + /* BACO are not supported on vega20 and arctrus > */ > + break; > + case CHIP_VEGA10: > + /* enable BACO as runpm mode if noretry=0 */ > + if (!adev->gmc.noretry) > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + break; > + default: > + /* enable BACO as runpm mode on CI+ */ > + adev->pm.rpm_mode = AMDGPU_RUNPM_BACO; > + break; > + } > + > + if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) { > + if (bamaco_support & MACO_SUPPORT) { > + adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO; > + dev_info(adev->dev, "Using BAMACO for > runtime pm\n"); > + } else { > + dev_info(adev->dev, "Using BACO for > runtime pm\n"); > + } > + } > + } > + break; > + case 0: > + dev_info(adev->dev, "runtime pm is manually disabled\n"); > + break; > + default: > + break; > + } > + > +no_runtime_pm: > + if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE) >