<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Hawking<o:p></o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Chai, Thomas <YiPeng.Chai@amd.com><br>
<b>Date: </b>Monday, September 5, 2022 at 14:35<br>
<b>To: </b>amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc: </b>Zhang, Hawking <Hawking.Zhang@amd.com>, Zhou1, Tao <Tao.Zhou1@amd.com><br>
<b>Subject: </b>RE: [PATCH V2] drm/amdgpu: TA unload messages are not actually sent to psp when amdgpu is uninstalled<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">[AMD Official Use Only - General]<br>
<br>
Ping....<br>
<br>
<br>
-----------------<br>
Best Regards,<br>
Thomas<br>
<br>
-----Original Message-----<br>
From: Chai, Thomas <YiPeng.Chai@amd.com> <br>
Sent: Thursday, September 1, 2022 4:40 PM<br>
To: amd-gfx@lists.freedesktop.org<br>
Cc: Chai, Thomas <YiPeng.Chai@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com>; Zhou1, Tao <Tao.Zhou1@amd.com>; Chai, Thomas <YiPeng.Chai@amd.com><br>
Subject: [PATCH V2] drm/amdgpu: TA unload messages are not actually sent to psp when amdgpu is uninstalled<br>
<br>
V1:<br>
  The psp_cmd_submit_buf function is called by psp_hw_fini to send TA unload messages to psp to terminate ras, asd and tmr. But when amdgpu is uninstalled, drm_dev_unplug is called earlier than psp_hw_fini in amdgpu_pci_remove, the calling order as follows:<br>
static void amdgpu_pci_remove(struct pci_dev *pdev) {<br>
        drm_dev_unplug<br>
        ......<br>
        amdgpu_driver_unload_kms->amdgpu_device_fini_hw->...<br>
                ->.hw_fini->psp_hw_fini->...<br>
                ->psp_ta_unload->psp_cmd_submit_buf<br>
        ......<br>
}<br>
The program will return when calling drm_dev_enter in psp_cmd_submit_buf.<br>
<br>
So the call to drm_dev_enter in psp_cmd_submit_buf should be removed, so that the TA unload messages can be sent to the psp when amdgpu is uninstalled.<br>
<br>
V2:<br>
1. Restore psp_cmd_submit_buf to its original code.<br>
2. Move drm_dev_unplug call after amdgpu_driver_unload_kms in<br>
   amdgpu_pci_remove.<br>
3. Since amdgpu_device_fini_hw is called by amdgpu_driver_unload_kms,<br>
   remove the unplug check to release device mmio resource in<br>
   amdgpu_device_fini_hw before calling drm_dev_unplug.<br>
<br>
Signed-off-by: YiPeng Chai <YiPeng.Chai@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 +--<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c    | 4 ++--<br>
 2 files changed, 3 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
index afaa1056e039..62b26f0e37b0 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -3969,8 +3969,7 @@ void amdgpu_device_fini_hw(struct amdgpu_device *adev)<br>
 <br>
         amdgpu_gart_dummy_page_fini(adev);<br>
 <br>
-       if (drm_dev_is_unplugged(adev_to_drm(adev)))<br>
-               amdgpu_device_unmap_mmio(adev);<br>
+       amdgpu_device_unmap_mmio(adev);<br>
 <br>
 }<br>
 <br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
index de7144b06e93..728a0933ea6f 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c<br>
@@ -2181,8 +2181,6 @@ amdgpu_pci_remove(struct pci_dev *pdev)<br>
         struct drm_device *dev = pci_get_drvdata(pdev);<br>
         struct amdgpu_device *adev = drm_to_adev(dev);<br>
 <br>
-       drm_dev_unplug(dev);<br>
-<br>
         if (adev->pm.rpm_mode != AMDGPU_RUNPM_NONE) {<br>
                 pm_runtime_get_sync(dev->dev);<br>
                 pm_runtime_forbid(dev->dev);<br>
@@ -2190,6 +2188,8 @@ amdgpu_pci_remove(struct pci_dev *pdev)<br>
 <br>
         amdgpu_driver_unload_kms(dev);<br>
 <br>
+       drm_dev_unplug(dev);<br>
+<br>
         /*<br>
          * Flush any in flight DMA operations from device.<br>
          * Clear the Bus Master Enable bit and then wait on the PCIe Device<br>
--<br>
2.25.1<o:p></o:p></span></p>
</div>
</div>
</body>
</html>