<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<p>sorry about sending duplicated review, email server seems not working properly.<br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of qingqing.wang@amd.com <qingqing.wang@amd.com><br>
<b>Sent:</b> Friday, September 15, 2017 3:05:56 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Wang, Ken<br>
<b>Subject:</b> [PATCH] drm/amdgpu: Add GPU reset functionality for Vega10</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">From: Ken Wang <Ken.Wang@amd.com><br>
<br>
Signed-off-by: Ken Wang <Ken.Wang@amd.com><br>
Change-Id: I6fd2c216a84747313f18db25a444be5ed43b4f4b<br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 7 +++++-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 10 +++++++-<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 3 +++<br>
drivers/gpu/drm/amd/amdgpu/psp_v10_0.c | 7 ++++++<br>
drivers/gpu/drm/amd/amdgpu/psp_v10_0.h | 2 ++<br>
drivers/gpu/drm/amd/amdgpu/psp_v3_1.c | 36 ++++++++++++++++++++++++++-<br>
drivers/gpu/drm/amd/amdgpu/psp_v3_1.h | 1 +<br>
drivers/gpu/drm/amd/amdgpu/soc15.c | 39 ++++++++++++++++++++----------<br>
8 files changed, 89 insertions(+), 16 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 fc1c5437..4196786 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -2883,7 +2883,7 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)<br>
int resched;<br>
bool need_full_reset, vram_lost = false;<br>
<br>
- if (!amdgpu_check_soft_reset(adev)) {<br>
+ if (!amdgpu_check_soft_reset(adev) && (adev->asic_type != CHIP_VEGA10)) {<br>
DRM_INFO("No hardware hang detected. Did some blocks stall?\n");<br>
return 0;<br>
}<br>
@@ -2910,6 +2910,10 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)<br>
<br>
need_full_reset = amdgpu_need_full_reset(adev);<br>
<br>
+ /* no soft reset for vega10 right now*/<br>
+ if (adev->asic_type == CHIP_VEGA10)<br>
+ need_full_reset = true;<br>
+<br>
if (!need_full_reset) {<br>
amdgpu_pre_soft_reset(adev);<br>
r = amdgpu_soft_reset(adev);<br>
@@ -2924,6 +2928,7 @@ int amdgpu_gpu_reset(struct amdgpu_device *adev)<br>
r = amdgpu_suspend(adev);<br>
<br>
retry:<br>
+<br>
amdgpu_atombios_scratch_regs_save(adev);<br>
r = amdgpu_asic_reset(adev);<br>
amdgpu_atombios_scratch_regs_restore(adev);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
index 8a1ee97..6942b89 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
@@ -62,6 +62,7 @@ static int psp_sw_init(void *handle)<br>
psp->cmd_submit = psp_v3_1_cmd_submit;<br>
psp->compare_sram_data = psp_v3_1_compare_sram_data;<br>
psp->smu_reload_quirk = psp_v3_1_smu_reload_quirk;<br>
+ psp->mode1_reset = psp_v3_1_mode1_reset;<br>
break;<br>
case CHIP_RAVEN:<br>
psp->init_microcode = psp_v10_0_init_microcode;<br>
@@ -72,6 +73,7 @@ static int psp_sw_init(void *handle)<br>
psp->ring_destroy = psp_v10_0_ring_destroy;<br>
psp->cmd_submit = psp_v10_0_cmd_submit;<br>
psp->compare_sram_data = psp_v10_0_compare_sram_data;<br>
+ psp->mode1_reset = psp_v10_0_mode1_reset;<br>
break;<br>
default:<br>
return -EINVAL;<br>
@@ -497,6 +499,12 @@ static int psp_resume(void *handle)<br>
return ret;<br>
}<br>
<br>
+static int psp_reset(void* handle)<br>
+{<br>
+ struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
+ return psp_mode1_reset(&adev->psp);<br>
+}<br>
+<br>
static bool psp_check_fw_loading_status(struct amdgpu_device *adev,<br>
enum AMDGPU_UCODE_ID ucode_type)<br>
{<br>
@@ -541,7 +549,7 @@ const struct amd_ip_funcs psp_ip_funcs = {<br>
.resume = psp_resume,<br>
.is_idle = NULL,<br>
.wait_for_idle = NULL,<br>
- .soft_reset = NULL,<br>
+ .soft_reset = psp_reset,<br>
.set_clockgating_state = psp_set_clockgating_state,<br>
.set_powergating_state = psp_set_powergating_state,<br>
};<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h<br>
index 1b7d12d..ce465455 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h<br>
@@ -76,6 +76,7 @@ struct psp_context<br>
struct amdgpu_firmware_info *ucode,<br>
enum AMDGPU_UCODE_ID ucode_type);<br>
bool (*smu_reload_quirk)(struct psp_context *psp);<br>
+ int (*mode1_reset)(struct psp_context *psp);<br>
<br>
/* fence buffer */<br>
struct amdgpu_bo *fw_pri_bo;<br>
@@ -139,6 +140,8 @@ struct amdgpu_psp_funcs {<br>
((psp)->bootloader_load_sos ? (psp)->bootloader_load_sos((psp)) : 0)<br>
#define psp_smu_reload_quirk(psp) \<br>
((psp)->smu_reload_quirk ? (psp)->smu_reload_quirk((psp)) : false)<br>
+#define psp_mode1_reset(psp) \<br>
+ ((psp)->mode1_reset ? (psp)->mode1_reset((psp)) : false)<br>
<br>
extern const struct amd_ip_funcs psp_ip_funcs;<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c<br>
index 6b324da..cbc43bb 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v10_0.c<br>
@@ -406,3 +406,10 @@ bool psp_v10_0_compare_sram_data(struct psp_context *psp,<br>
<br>
return true;<br>
}<br>
+<br>
+<br>
+int psp_v10_0_mode1_reset(struct psp_context *psp)<br>
+{<br>
+ DRM_INFO("psp mode 1 reset not supported now! \n");<br>
+ return -EINVAL;<br>
+}<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v10_0.h b/drivers/gpu/drm/amd/amdgpu/psp_v10_0.h<br>
index 3af3ad1..451e830 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/psp_v10_0.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v10_0.h<br>
@@ -45,4 +45,6 @@ extern int psp_v10_0_cmd_submit(struct psp_context *psp,<br>
extern bool psp_v10_0_compare_sram_data(struct psp_context *psp,<br>
struct amdgpu_firmware_info *ucode,<br>
enum AMDGPU_UCODE_ID ucode_type);<br>
+<br>
+extern int psp_v10_0_mode1_reset(struct psp_context *psp);<br>
#endif<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c<br>
index eb73931..01a896e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c<br>
@@ -517,7 +517,7 @@ bool psp_v3_1_compare_sram_data(struct psp_context *psp,<br>
ucode_size -= 4;<br>
}<br>
<br>
- return true;<br>
+ return true; <br>
}<br>
<br>
bool psp_v3_1_smu_reload_quirk(struct psp_context *psp)<br>
@@ -530,3 +530,37 @@ bool psp_v3_1_smu_reload_quirk(struct psp_context *psp)<br>
reg = RREG32_SOC15(NBIO, 0, mmPCIE_DATA2);<br>
return (reg & MP1_FIRMWARE_FLAGS__INTERRUPTS_ENABLED_MASK) ? true : false;<br>
}<br>
+<br>
+int psp_v3_1_mode1_reset(struct psp_context *psp)<br>
+{<br>
+ int ret;<br>
+ uint32_t offset;<br>
+ struct amdgpu_device *adev = psp->adev;<br>
+<br>
+ offset = SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_64);<br>
+<br>
+ ret = psp_wait_for(psp, offset, 0x80000000, 0x8000FFFF, false);<br>
+<br>
+ if (ret) {<br>
+ DRM_INFO("psp is not working correctly before mode1 reset!\n");<br>
+ return -EINVAL;<br>
+ }<br>
+<br>
+ /*send the mode 1 reset command*/<br>
+ WREG32(offset, 0x70000);<br>
+<br>
+ mdelay(1000);<br>
+<br>
+ offset = SOC15_REG_OFFSET(MP0, 0, mmMP0_SMN_C2PMSG_33);<br>
+<br>
+ ret = psp_wait_for(psp, offset, 0x80000000, 0x80000000, false);<br>
+<br>
+ if (ret) {<br>
+ DRM_INFO("psp mode 1 reset failed!\n");<br>
+ return -EINVAL;<br>
+ }<br>
+<br>
+ DRM_INFO("psp mode1 reset succeed \n");<br>
+<br>
+ return 0;<br>
+}<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.h b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.h<br>
index 5af2231..b05dbad 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.h<br>
@@ -53,4 +53,5 @@ extern bool psp_v3_1_compare_sram_data(struct psp_context *psp,<br>
struct amdgpu_firmware_info *ucode,<br>
enum AMDGPU_UCODE_ID ucode_type);<br>
extern bool psp_v3_1_smu_reload_quirk(struct psp_context *psp);<br>
+extern int psp_v3_1_mode1_reset(struct psp_context *psp);<br>
#endif<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/soc15.c b/drivers/gpu/drm/amd/amdgpu/soc15.c<br>
index a74d616..190be09 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/soc15.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/soc15.c<br>
@@ -407,18 +407,37 @@ static int soc15_read_register(struct amdgpu_device *adev, u32 se_num,<br>
return -EINVAL;<br>
}<br>
<br>
-static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev)<br>
+static int soc15_asic_reset(struct amdgpu_device *adev)<br>
{<br>
u32 i;<br>
+ u32 *pci_regs;<br>
+<br>
+ pci_regs = kmalloc(128 * sizeof(u32), GFP_KERNEL);<br>
+<br>
+ if (pci_regs == NULL)<br>
+ return -EINVAL;<br>
+<br>
+ amdgpu_atombios_scratch_regs_engine_hung(adev, true);<br>
<br>
- dev_info(adev->dev, "GPU pci config reset\n");<br>
+ dev_info(adev->dev, "GPU reset\n");<br>
<br>
/* disable BM */<br>
pci_clear_master(adev->pdev);<br>
- /* reset */<br>
- amdgpu_pci_config_reset(adev);<br>
<br>
- udelay(100);<br>
+ for (i = 0; i < 128; i++) {<br>
+ pci_read_config_dword(adev->pdev, i*4, &pci_regs[i]);<br>
+ }<br>
+<br>
+ for (i = 0; i < AMDGPU_MAX_IP_NUM; i++) {<br>
+ if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP){<br>
+ adev->ip_blocks[i].version->funcs->soft_reset((void *)adev);<br>
+ break;<br>
+ }<br>
+ }<br>
+<br>
+ for (i = 0; i < 128; i++) {<br>
+ pci_write_config_dword(adev->pdev, i*4, pci_regs[i]);<br>
+ }<br>
<br>
/* wait for asic to come out of reset */<br>
for (i = 0; i < adev->usec_timeout; i++) {<br>
@@ -430,16 +449,10 @@ static void soc15_gpu_pci_config_reset(struct amdgpu_device *adev)<br>
udelay(1);<br>
}<br>
<br>
-}<br>
-<br>
-static int soc15_asic_reset(struct amdgpu_device *adev)<br>
-{<br>
- amdgpu_atombios_scratch_regs_engine_hung(adev, true);<br>
-<br>
- soc15_gpu_pci_config_reset(adev);<br>
-<br>
amdgpu_atombios_scratch_regs_engine_hung(adev, false);<br>
<br>
+ kfree(pci_regs);<br>
+<br>
return 0;<br>
}<br>
<br>
-- <br>
2.7.4<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
</div>
</span></font>
</body>
</html>