Skip to content

Commit c564b86

Browse files
huangruialexdeucher
authored andcommitted
drm/amdgpu: add TMR destory function for psp
TMR is required to be destoried with GFX_CMD_ID_DESTROY_TMR while the system goes to suspend. Otherwise, PSP may return the failure state (0xFFFF007) on Gfx-2-PSP command GFX_CMD_ID_SETUP_TMR after do multiple times suspend/resume. Signed-off-by: Huang Rui <[email protected]> Reviewed-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]> Cc: [email protected]
1 parent 20303ec commit c564b86

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

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

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,52 @@ static int psp_tmr_load(struct psp_context *psp)
372372
return ret;
373373
}
374374

375+
static void psp_prep_tmr_unload_cmd_buf(struct psp_context *psp,
376+
struct psp_gfx_cmd_resp *cmd)
377+
{
378+
if (amdgpu_sriov_vf(psp->adev))
379+
cmd->cmd_id = GFX_CMD_ID_DESTROY_VMR;
380+
else
381+
cmd->cmd_id = GFX_CMD_ID_DESTROY_TMR;
382+
}
383+
384+
static int psp_tmr_unload(struct psp_context *psp)
385+
{
386+
int ret;
387+
struct psp_gfx_cmd_resp *cmd;
388+
389+
cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);
390+
if (!cmd)
391+
return -ENOMEM;
392+
393+
psp_prep_tmr_unload_cmd_buf(psp, cmd);
394+
DRM_INFO("free PSP TMR buffer\n");
395+
396+
ret = psp_cmd_submit_buf(psp, NULL, cmd,
397+
psp->fence_buf_mc_addr);
398+
399+
kfree(cmd);
400+
401+
return ret;
402+
}
403+
404+
static int psp_tmr_terminate(struct psp_context *psp)
405+
{
406+
int ret;
407+
void *tmr_buf;
408+
void **pptr;
409+
410+
ret = psp_tmr_unload(psp);
411+
if (ret)
412+
return ret;
413+
414+
/* free TMR memory buffer */
415+
pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
416+
amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
417+
418+
return 0;
419+
}
420+
375421
static void psp_prep_asd_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,
376422
uint64_t asd_mc, uint32_t size)
377423
{
@@ -1779,8 +1825,6 @@ static int psp_hw_fini(void *handle)
17791825
{
17801826
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
17811827
struct psp_context *psp = &adev->psp;
1782-
void *tmr_buf;
1783-
void **pptr;
17841828

17851829
if (psp->adev->psp.ta_fw) {
17861830
psp_ras_terminate(psp);
@@ -1790,10 +1834,9 @@ static int psp_hw_fini(void *handle)
17901834

17911835
psp_asd_unload(psp);
17921836

1837+
psp_tmr_terminate(psp);
17931838
psp_ring_destroy(psp, PSP_RING_TYPE__KM);
17941839

1795-
pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
1796-
amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
17971840
amdgpu_bo_free_kernel(&psp->fw_pri_bo,
17981841
&psp->fw_pri_mc_addr, &psp->fw_pri_buf);
17991842
amdgpu_bo_free_kernel(&psp->fence_buf_bo,
@@ -1846,6 +1889,12 @@ static int psp_suspend(void *handle)
18461889
return ret;
18471890
}
18481891

1892+
ret = psp_tmr_terminate(psp);
1893+
if (ret) {
1894+
DRM_ERROR("Falied to terminate tmr\n");
1895+
return ret;
1896+
}
1897+
18491898
ret = psp_ring_stop(psp, PSP_RING_TYPE__KM);
18501899
if (ret) {
18511900
DRM_ERROR("PSP ring stop failed\n");

0 commit comments

Comments
 (0)