Skip to contentSkip to conversation

drm/amdgpu: add wait_for helper for spirom update

PATCH In review Gao, Likun 2 participants 2 messages Jun 13, 2023 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Gao, Likun

author
#1 lore raw

PATCH 1/1 drm/amdgpu: add wait_for helper for spirom update

[AMD Official Use Only - General]

From: Likun Gao <[email protected]>
Sent: Tuesday, June 13, 2023 3:29 PM
To: brahma_sw_dev <[email protected]>
Cc: Zhang, Hawking <[email protected]>; Gao, Likun <[email protected]>
Subject: [PATCH] drm/amdgpu: add wait_for helper for spirom update

From: Likun Gao <[email protected]>

Spirom update typically requires extremely long duration for command execution, and special helper function to wait for it's completion.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 20 ++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  2 ++  drivers/gpu/drm/amd/amdgpu/psp_v13_0.c  |  9 +++++----  drivers/gpu/drm/amd/amdgpu/psp_v13_0.h  |  2 ++
 4 files changed, 29 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +19 -0
index a39d4ddf7743..fa06da014473 100644
@@ -560,6 +560,26 @@ int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
        return -ETIME;
 }
 
+int psp_wait_for_spirom_update(struct psp_context *psp, uint32_t reg_index,
+                              uint32_t reg_val, uint32_t mask, uint32_t msec_timeout) {
+       uint32_t val;
+       int i;
+       struct amdgpu_device *adev = psp->adev;
+
+       if (psp->adev->no_hw_access)
+               return 0;
+
+       for (i = 0; i < msec_timeout; i++) {
+               val = RREG32(reg_index);
+               if ((val & mask) == reg_val)
+                       return 0;
+               msleep(1);
+       }
+
+       return -ETIME;
+}
+
 static const char *psp_gfx_cmd_name(enum psp_gfx_cmd_id cmd_id)  {
        switch (cmd_id) {
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +2 -0
index cf4f60c66122..ec3f3fe5efff 100644
@@ -455,6 +455,8 @@ extern const struct amdgpu_ip_block_version psp_v13_0_4_ip_block;
 
 extern int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
                        uint32_t field_val, uint32_t mask, bool check_changed);
+extern int psp_wait_for_spirom_update(struct psp_context *psp, uint32_t reg_index,
+                       uint32_t field_val, uint32_t mask, uint32_t msec_timeout);
 
 int psp_gpu_reset(struct amdgpu_device *adev);  int psp_update_vcn_sram(struct amdgpu_device *adev, int inst_idx, diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c

index caee76ab7110..67e216373585 100644

drivers/gpu/drm/amd/amdgpu/psp_v13_0.c +5 -4
@@ -624,10 +624,11 @@ static int psp_v13_0_exec_spi_cmd(struct psp_context *psp, int cmd)
        WREG32_SOC15(MP0, 0, regMP0_SMN_C2PMSG_73, 1);
 
        if (cmd == C2PMSG_CMD_SPI_UPDATE_FLASH_IMAGE)
-               return 0;
-
-       ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMP0_SMN_C2PMSG_115),
-                               MBOX_READY_FLAG, MBOX_READY_MASK, false);
+               ret = psp_wait_for_spirom_update(psp, SOC15_REG_OFFSET(MP0, 0, regMP0_SMN_C2PMSG_115),
+                                                MBOX_READY_FLAG, MBOX_READY_MASK, PSP_SPIROM_UPDATE_TIMEOUT);
+       else
+               ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMP0_SMN_C2PMSG_115),
+                                  MBOX_READY_FLAG, MBOX_READY_MASK, false);
        if (ret) {
                dev_err(adev->dev, "SPI cmd %x timed out, ret = %d", cmd, ret);
                return ret;
drivers/gpu/drm/amd/amdgpu/psp_v13_0.h +2 -0
index b2414a729ca1..9eae5e23b2e5 100644
@@ -25,6 +25,8 @@
 
 #include "amdgpu_psp.h"
 
+#define PSP_SPIROM_UPDATE_TIMEOUT   60000   /* 60s */
+
 void psp_v13_0_set_psp_funcs(struct psp_context *psp);
 
 #endif

--
2.34.1

Reviewed-by on v1 1/1
#2 lore raw

[AMD Official Use Only - General]

Regards,
Hawking
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Gao, Likun
Sent: Tuesday, June 13, 2023 15:37
To: amd-gfx list <[email protected]>
Subject: [PATCH] drm/amdgpu: add wait_for helper for spirom update

[AMD Official Use Only - General]

[AMD Official Use Only - General]

From: Likun Gao <[email protected]>
Sent: Tuesday, June 13, 2023 3:29 PM
To: brahma_sw_dev <[email protected]>
Cc: Zhang, Hawking <[email protected]>; Gao, Likun <[email protected]>
Subject: [PATCH] drm/amdgpu: add wait_for helper for spirom update

From: Likun Gao <[email protected]>

Spirom update typically requires extremely long duration for command execution, and special helper function to wait for it's completion.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 20 ++++++++++++++++++++  drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  2 ++  drivers/gpu/drm/amd/amdgpu/psp_v13_0.c  |  9 +++++----  drivers/gpu/drm/amd/amdgpu/psp_v13_0.h  |  2 ++
 4 files changed, 29 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +19 -0
index a39d4ddf7743..fa06da014473 100644
@@ -560,6 +560,26 @@ int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
        return -ETIME;
 }
 
+int psp_wait_for_spirom_update(struct psp_context *psp, uint32_t reg_index,
+                              uint32_t reg_val, uint32_t mask, uint32_t msec_timeout) {
+       uint32_t val;
+       int i;
+       struct amdgpu_device *adev = psp->adev;
+
+       if (psp->adev->no_hw_access)
+               return 0;
+
+       for (i = 0; i < msec_timeout; i++) {
+               val = RREG32(reg_index);
+               if ((val & mask) == reg_val)
+                       return 0;
+               msleep(1);
+       }
+
+       return -ETIME;
+}
+
 static const char *psp_gfx_cmd_name(enum psp_gfx_cmd_id cmd_id)  {
        switch (cmd_id) {
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +2 -0
index cf4f60c66122..ec3f3fe5efff 100644
@@ -455,6 +455,8 @@ extern const struct amdgpu_ip_block_version psp_v13_0_4_ip_block;
 
 extern int psp_wait_for(struct psp_context *psp, uint32_t reg_index,
                        uint32_t field_val, uint32_t mask, bool check_changed);
+extern int psp_wait_for_spirom_update(struct psp_context *psp, uint32_t reg_index,
+                       uint32_t field_val, uint32_t mask, uint32_t msec_timeout);
 
 int psp_gpu_reset(struct amdgpu_device *adev);  int psp_update_vcn_sram(struct amdgpu_device *adev, int inst_idx, diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v13_0.c

index caee76ab7110..67e216373585 100644

drivers/gpu/drm/amd/amdgpu/psp_v13_0.c +5 -4
@@ -624,10 +624,11 @@ static int psp_v13_0_exec_spi_cmd(struct psp_context *psp, int cmd)
        WREG32_SOC15(MP0, 0, regMP0_SMN_C2PMSG_73, 1);
 
        if (cmd == C2PMSG_CMD_SPI_UPDATE_FLASH_IMAGE)
-               return 0;
-
-       ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMP0_SMN_C2PMSG_115),
-                               MBOX_READY_FLAG, MBOX_READY_MASK, false);
+               ret = psp_wait_for_spirom_update(psp, SOC15_REG_OFFSET(MP0, 0, regMP0_SMN_C2PMSG_115),
+                                                MBOX_READY_FLAG, MBOX_READY_MASK, PSP_SPIROM_UPDATE_TIMEOUT);
+       else
+               ret = psp_wait_for(psp, SOC15_REG_OFFSET(MP0, 0, regMP0_SMN_C2PMSG_115),
+                                  MBOX_READY_FLAG, MBOX_READY_MASK, false);
        if (ret) {
                dev_err(adev->dev, "SPI cmd %x timed out, ret = %d", cmd, ret);
                return ret;
drivers/gpu/drm/amd/amdgpu/psp_v13_0.h +2 -0
index b2414a729ca1..9eae5e23b2e5 100644
@@ -25,6 +25,8 @@
 
 #include "amdgpu_psp.h"
 
+#define PSP_SPIROM_UPDATE_TIMEOUT   60000   /* 60s */
+
 void psp_v13_0_set_psp_funcs(struct psp_context *psp);
 
 #endif

--
2.34.1