drm/amdgpu: Place NPS mode request on unload

If a user has requested NPS mode switch, place the request through PSP
during unload of the driver. For devices which are part of a hive, all
requests are placed together. If one of them fails, revert back to the
current NPS mode.

Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
Reviewed-by: Feifei Xu <Feifei.Xu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Lijo Lazar
2024-09-20 13:14:40 +05:30
committed by Alex Deucher
parent 01b64bc063
commit ee52489d12
5 changed files with 92 additions and 0 deletions

View File

@@ -1333,3 +1333,50 @@ int amdgpu_gmc_request_memory_partition(struct amdgpu_device *adev,
return psp_memory_partition(&adev->psp, nps_mode);
}
static inline bool amdgpu_gmc_need_nps_switch_req(struct amdgpu_device *adev,
int req_nps_mode,
int cur_nps_mode)
{
return (((BIT(req_nps_mode) & adev->gmc.supported_nps_modes) ==
BIT(req_nps_mode)) &&
req_nps_mode != cur_nps_mode);
}
void amdgpu_gmc_prepare_nps_mode_change(struct amdgpu_device *adev)
{
int req_nps_mode, cur_nps_mode, r;
struct amdgpu_hive_info *hive;
if (amdgpu_sriov_vf(adev) || !adev->gmc.supported_nps_modes ||
!adev->gmc.gmc_funcs->request_mem_partition_mode)
return;
cur_nps_mode = adev->gmc.gmc_funcs->query_mem_partition_mode(adev);
hive = amdgpu_get_xgmi_hive(adev);
if (hive) {
req_nps_mode = atomic_read(&hive->requested_nps_mode);
if (!amdgpu_gmc_need_nps_switch_req(adev, req_nps_mode,
cur_nps_mode)) {
amdgpu_put_xgmi_hive(hive);
return;
}
r = amdgpu_xgmi_request_nps_change(adev, hive, req_nps_mode);
amdgpu_put_xgmi_hive(hive);
goto out;
}
req_nps_mode = adev->gmc.requested_nps_mode;
if (!amdgpu_gmc_need_nps_switch_req(adev, req_nps_mode, cur_nps_mode))
return;
/* even if this fails, we should let driver unload w/o blocking */
r = adev->gmc.gmc_funcs->request_mem_partition_mode(adev, req_nps_mode);
out:
if (r)
dev_err(adev->dev, "NPS mode change request failed\n");
else
dev_info(
adev->dev,
"NPS mode change request done, reload driver to complete the change\n");
}