Skip to content

Commit 1347853

Browse files
Ma Junalexdeucher
authored andcommitted
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 <Jun.Ma2@amd.com> Reviewed-by: Yang Wang <kevinyang.wang@amd.com> Reviewed-by: Lijo Lazar <lijo.lazar@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 6c6acc5 commit 1347853

3 files changed

Lines changed: 77 additions & 47 deletions

File tree

drivers/gpu/drm/amd/amdgpu/amdgpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ bool amdgpu_device_supports_px(struct drm_device *dev);
14091409
bool amdgpu_device_supports_boco(struct drm_device *dev);
14101410
bool amdgpu_device_supports_smart_shift(struct drm_device *dev);
14111411
int amdgpu_device_supports_baco(struct drm_device *dev);
1412+
void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev);
14121413
bool amdgpu_device_is_peer_accessible(struct amdgpu_device *adev,
14131414
struct amdgpu_device *peer_adev);
14141415
int amdgpu_device_baco_enter(struct drm_device *dev);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,81 @@ int amdgpu_device_supports_baco(struct drm_device *dev)
350350
return amdgpu_asic_supports_baco(adev);
351351
}
352352

353+
void amdgpu_device_detect_runtime_pm_mode(struct amdgpu_device *adev)
354+
{
355+
struct drm_device *dev;
356+
int bamaco_support;
357+
358+
dev = adev_to_drm(adev);
359+
360+
adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
361+
bamaco_support = amdgpu_device_supports_baco(dev);
362+
363+
switch (amdgpu_runtime_pm) {
364+
case 2:
365+
if (bamaco_support & MACO_SUPPORT) {
366+
adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
367+
dev_info(adev->dev, "Forcing BAMACO for runtime pm\n");
368+
} else if (bamaco_support == BACO_SUPPORT) {
369+
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
370+
dev_info(adev->dev, "Requested mode BAMACO not available,fallback to use BACO\n");
371+
}
372+
break;
373+
case 1:
374+
if (bamaco_support & BACO_SUPPORT) {
375+
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
376+
dev_info(adev->dev, "Forcing BACO for runtime pm\n");
377+
}
378+
break;
379+
case -1:
380+
case -2:
381+
if (amdgpu_device_supports_px(dev)) { /* enable PX as runtime mode */
382+
adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
383+
dev_info(adev->dev, "Using ATPX for runtime pm\n");
384+
} else if (amdgpu_device_supports_boco(dev)) { /* enable boco as runtime mode */
385+
adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
386+
dev_info(adev->dev, "Using BOCO for runtime pm\n");
387+
} else {
388+
if (!bamaco_support)
389+
goto no_runtime_pm;
390+
391+
switch (adev->asic_type) {
392+
case CHIP_VEGA20:
393+
case CHIP_ARCTURUS:
394+
/* BACO are not supported on vega20 and arctrus */
395+
break;
396+
case CHIP_VEGA10:
397+
/* enable BACO as runpm mode if noretry=0 */
398+
if (!adev->gmc.noretry)
399+
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
400+
break;
401+
default:
402+
/* enable BACO as runpm mode on CI+ */
403+
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
404+
break;
405+
}
406+
407+
if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
408+
if (bamaco_support & MACO_SUPPORT) {
409+
adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
410+
dev_info(adev->dev, "Using BAMACO for runtime pm\n");
411+
} else {
412+
dev_info(adev->dev, "Using BACO for runtime pm\n");
413+
}
414+
}
415+
}
416+
break;
417+
case 0:
418+
dev_info(adev->dev, "runtime pm is manually disabled\n");
419+
break;
420+
default:
421+
break;
422+
}
423+
424+
no_runtime_pm:
425+
if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
426+
dev_info(adev->dev, "Runtime PM not available\n");
427+
}
353428
/**
354429
* amdgpu_device_supports_smart_shift - Is the device dGPU with
355430
* smart shift support

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
133133
int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
134134
{
135135
struct drm_device *dev;
136-
int bamaco_support = 0;
137136
int r, acpi_status;
138137

139138
dev = adev_to_drm(adev);
@@ -150,52 +149,7 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
150149
goto out;
151150
}
152151

153-
adev->pm.rpm_mode = AMDGPU_RUNPM_NONE;
154-
if (amdgpu_device_supports_px(dev) &&
155-
(amdgpu_runtime_pm != 0)) { /* enable PX as runtime mode */
156-
adev->pm.rpm_mode = AMDGPU_RUNPM_PX;
157-
dev_info(adev->dev, "Using ATPX for runtime pm\n");
158-
} else if (amdgpu_device_supports_boco(dev) &&
159-
(amdgpu_runtime_pm != 0)) { /* enable boco as runtime mode */
160-
adev->pm.rpm_mode = AMDGPU_RUNPM_BOCO;
161-
dev_info(adev->dev, "Using BOCO for runtime pm\n");
162-
} else if (amdgpu_runtime_pm != 0) {
163-
bamaco_support = amdgpu_device_supports_baco(dev);
164-
165-
if (!bamaco_support)
166-
goto no_runtime_pm;
167-
168-
switch (adev->asic_type) {
169-
case CHIP_VEGA20:
170-
case CHIP_ARCTURUS:
171-
/* enable BACO as runpm mode if runpm=1 */
172-
if (amdgpu_runtime_pm > 0)
173-
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
174-
break;
175-
case CHIP_VEGA10:
176-
/* enable BACO as runpm mode if noretry=0 */
177-
if (!adev->gmc.noretry)
178-
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
179-
break;
180-
default:
181-
/* enable BACO as runpm mode on CI+ */
182-
adev->pm.rpm_mode = AMDGPU_RUNPM_BACO;
183-
break;
184-
}
185-
186-
if (adev->pm.rpm_mode == AMDGPU_RUNPM_BACO) {
187-
if (bamaco_support & MACO_SUPPORT) {
188-
adev->pm.rpm_mode = AMDGPU_RUNPM_BAMACO;
189-
dev_info(adev->dev, "Using BAMACO for runtime pm\n");
190-
} else {
191-
dev_info(adev->dev, "Using BACO for runtime pm\n");
192-
}
193-
}
194-
}
195-
196-
no_runtime_pm:
197-
if (adev->pm.rpm_mode == AMDGPU_RUNPM_NONE)
198-
dev_info(adev->dev, "NO pm mode for runtime pm\n");
152+
amdgpu_device_detect_runtime_pm_mode(adev);
199153

200154
/* Call ACPI methods: require modeset init
201155
* but failure is not fatal

0 commit comments

Comments
 (0)