<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#317100;margin:15pt;" align="Left">
[AMD Public Use]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Series is:</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Huang Rui <ray.huang@amd.com><br>
<b>Sent:</b> Tuesday, June 30, 2020 6:30 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Huang, Ray <Ray.Huang@amd.com><br>
<b>Subject:</b> [PATCH 2/2] drm/amdgpu: add TMR destory function for psp</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">TMR is required to be destoried with GFX_CMD_ID_DESTROY_TMR while the<br>
system goes to suspend. Otherwise, PSP may return the failure state<br>
(0xFFFF007) on Gfx-2-PSP command GFX_CMD_ID_SETUP_TMR after do multiple<br>
times suspend/resume.<br>
<br>
Signed-off-by: Huang Rui <ray.huang@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 57 +++++++++++++++++++++++--<br>
1 file changed, 53 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
index e57a53d5ca96..23ebb50b1a19 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
@@ -430,6 +430,52 @@ static int psp_tmr_load(struct psp_context *psp)<br>
return ret;<br>
}<br>
<br>
+static void psp_prep_tmr_unload_cmd_buf(struct psp_context *psp,<br>
+ struct psp_gfx_cmd_resp *cmd)<br>
+{<br>
+ if (amdgpu_sriov_vf(psp->adev))<br>
+ cmd->cmd_id = GFX_CMD_ID_DESTROY_VMR;<br>
+ else<br>
+ cmd->cmd_id = GFX_CMD_ID_DESTROY_TMR;<br>
+}<br>
+<br>
+static int psp_tmr_unload(struct psp_context *psp)<br>
+{<br>
+ int ret;<br>
+ struct psp_gfx_cmd_resp *cmd;<br>
+<br>
+ cmd = kzalloc(sizeof(struct psp_gfx_cmd_resp), GFP_KERNEL);<br>
+ if (!cmd)<br>
+ return -ENOMEM;<br>
+<br>
+ psp_prep_tmr_unload_cmd_buf(psp, cmd);<br>
+ DRM_INFO("free PSP TMR buffer\n");<br>
+<br>
+ ret = psp_cmd_submit_buf(psp, NULL, cmd,<br>
+ psp->fence_buf_mc_addr);<br>
+<br>
+ kfree(cmd);<br>
+<br>
+ return ret;<br>
+}<br>
+<br>
+static int psp_tmr_terminate(struct psp_context *psp)<br>
+{<br>
+ int ret;<br>
+ void *tmr_buf;<br>
+ void **pptr;<br>
+<br>
+ ret = psp_tmr_unload(psp);<br>
+ if (ret)<br>
+ return ret;<br>
+<br>
+ /* free TMR memory buffer */<br>
+ pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;<br>
+ amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);<br>
+<br>
+ return 0;<br>
+}<br>
+<br>
static void psp_prep_asd_load_cmd_buf(struct psp_gfx_cmd_resp *cmd,<br>
uint64_t asd_mc, uint32_t size)<br>
{<br>
@@ -1866,8 +1912,6 @@ static int psp_hw_fini(void *handle)<br>
{<br>
struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
struct psp_context *psp = &adev->psp;<br>
- void *tmr_buf;<br>
- void **pptr;<br>
int ret;<br>
<br>
if (psp->adev->psp.ta_fw) {<br>
@@ -1883,10 +1927,9 @@ static int psp_hw_fini(void *handle)<br>
return ret;<br>
}<br>
<br>
+ psp_tmr_terminate(psp);<br>
psp_ring_destroy(psp, PSP_RING_TYPE__KM);<br>
<br>
- pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;<br>
- amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);<br>
amdgpu_bo_free_kernel(&psp->fw_pri_bo,<br>
&psp->fw_pri_mc_addr, &psp->fw_pri_buf);<br>
amdgpu_bo_free_kernel(&psp->fence_buf_bo,<br>
@@ -1939,6 +1982,12 @@ static int psp_suspend(void *handle)<br>
return ret;<br>
}<br>
<br>
+ ret = psp_tmr_terminate(psp);<br>
+ if (ret) {<br>
+ DRM_ERROR("Falied to terminate tmr\n");<br>
+ return ret;<br>
+ }<br>
+<br>
ret = psp_ring_stop(psp, PSP_RING_TYPE__KM);<br>
if (ret) {<br>
DRM_ERROR("PSP ring stop failed\n");<br>
-- <br>
2.25.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Calexander.deucher%40amd.com%7C282cd5829fbe4fca8ac708d81ce0cdbb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637291099162588481&sdata=UfOBa7Xaa6qvWClFnYB4OSngc8k0YyUmDCwtKmZ5BQQ%3D&reserved=0">https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&data=02%7C01%7Calexander.deucher%40amd.com%7C282cd5829fbe4fca8ac708d81ce0cdbb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637291099162588481&sdata=UfOBa7Xaa6qvWClFnYB4OSngc8k0YyUmDCwtKmZ5BQQ%3D&reserved=0</a><br>
</div>
</span></font></div>
</div>
</body>
</html>