<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:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); display: inline !important;">Reviewed-by: David Nieto <david.nieto@amd.com></span><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> Skvortsov, Victor <Victor.Skvortsov@amd.com><br>
<b>Sent:</b> Thursday, December 16, 2021 11:42 AM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Deng, Emily <Emily.Deng@amd.com>; Liu, Monk <Monk.Liu@amd.com>; Ming, Davis <Davis.Ming@amd.com>; Liu, Shaoyun <Shaoyun.Liu@amd.com>; Zhou, Peng Ju <PengJu.Zhou@amd.com>; Chen, JingWen
 <JingWen.Chen2@amd.com>; Chen, Horace <Horace.Chen@amd.com>; Nieto, David M <David.Nieto@amd.com><br>
<b>Cc:</b> Skvortsov, Victor <Victor.Skvortsov@amd.com><br>
<b>Subject:</b> [PATCH v3 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Expand RLCG interface for new GC read & write commands.<br>
New interface will only be used if the PF enables the flag in pf2vf msg.<br>
<br>
v2: Added a description for the scratch registers<br>
<br>
Signed-off-by: Victor Skvortsov <victor.skvortsov@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 117 ++++++++++++++++++++------<br>
 1 file changed, 89 insertions(+), 28 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
index edb3e3b08eed..9189fb85a4dd 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c<br>
@@ -63,6 +63,13 @@<br>
 #define mmGCEA_PROBE_MAP                        0x070c<br>
 #define mmGCEA_PROBE_MAP_BASE_IDX               0<br>
 <br>
+#define GFX9_RLCG_GC_WRITE_OLD                 (0x8 << 28)<br>
+#define GFX9_RLCG_GC_WRITE                     (0x0 << 28)<br>
+#define GFX9_RLCG_GC_READ                      (0x1 << 28)<br>
+#define GFX9_RLCG_VFGATE_DISABLED              0x4000000<br>
+#define GFX9_RLCG_WRONG_OPERATION_TYPE         0x2000000<br>
+#define GFX9_RLCG_NOT_IN_RANGE                 0x1000000<br>
+<br>
 MODULE_FIRMWARE("amdgpu/vega10_ce.bin");<br>
 MODULE_FIRMWARE("amdgpu/vega10_pfp.bin");<br>
 MODULE_FIRMWARE("amdgpu/vega10_me.bin");<br>
@@ -739,7 +746,7 @@ static const u32 GFX_RLC_SRM_INDEX_CNTL_DATA_OFFSETS[] =<br>
         mmRLC_SRM_INDEX_CNTL_DATA_7 - mmRLC_SRM_INDEX_CNTL_DATA_0,<br>
 };<br>
 <br>
-static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 flag)<br>
+static u32 gfx_v9_0_rlcg_rw(struct amdgpu_device *adev, u32 offset, u32 v, uint32_t flag)<br>
 {<br>
         static void *scratch_reg0;<br>
         static void *scratch_reg1;<br>
@@ -748,21 +755,20 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f<br>
         static void *spare_int;<br>
         static uint32_t grbm_cntl;<br>
         static uint32_t grbm_idx;<br>
+       uint32_t i = 0;<br>
+       uint32_t retries = 50000;<br>
+       u32 ret = 0;<br>
+       u32 tmp;<br>
 <br>
         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;<br>
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;<br>
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;<br>
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;<br>
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;<br>
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;<br>
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;<br>
 <br>
         grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL;<br>
         grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX;<br>
 <br>
-       if (amdgpu_sriov_runtime(adev)) {<br>
-               pr_err("shouldn't call rlcg write register during runtime\n");<br>
-               return;<br>
-       }<br>
-<br>
         if (offset == grbm_cntl || offset == grbm_idx) {<br>
                 if (offset  == grbm_cntl)<br>
                         writel(v, scratch_reg2);<br>
@@ -771,41 +777,95 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f<br>
 <br>
                 writel(v, ((void __iomem *)adev->rmmio) + (offset * 4));<br>
         } else {<br>
-               uint32_t i = 0;<br>
-               uint32_t retries = 50000;<br>
-<br>
+               /*<br>
+                * SCRATCH_REG0   = read/write value<br>
+                * SCRATCH_REG1[30:28]   = command<br>
+                * SCRATCH_REG1[19:0]    = address in dword<br>
+                * SCRATCH_REG1[26:24]   = Error reporting<br>
+                */<br>
                 writel(v, scratch_reg0);<br>
-               writel(offset | 0x80000000, scratch_reg1);<br>
+               writel(offset | flag, scratch_reg1);<br>
                 writel(1, spare_int);<br>
-               for (i = 0; i < retries; i++) {<br>
-                       u32 tmp;<br>
 <br>
+               for (i = 0; i < retries; i++) {<br>
                         tmp = readl(scratch_reg1);<br>
-                       if (!(tmp & 0x80000000))<br>
+                       if (!(tmp & flag))<br>
                                 break;<br>
 <br>
                         udelay(10);<br>
                 }<br>
-               if (i >= retries)<br>
-                       pr_err("timeout: rlcg program reg:0x%05x failed !\n", offset);<br>
+<br>
+               if (i >= retries) {<br>
+                       if (amdgpu_sriov_reg_indirect_gc(adev)) {<br>
+                               if (tmp & GFX9_RLCG_VFGATE_DISABLED)<br>
+                                       pr_err("The vfgate is disabled, program reg:0x%05x failed!\n", offset);<br>
+                               else if (tmp & GFX9_RLCG_WRONG_OPERATION_TYPE)<br>
+                                       pr_err("Wrong operation type, program reg:0x%05x failed!\n", offset);<br>
+                               else if (tmp & GFX9_RLCG_NOT_IN_RANGE)<br>
+                                       pr_err("The register is not in range, program reg:0x%05x failed!\n", offset);<br>
+                               else<br>
+                                       pr_err("Unknown error type, program reg:0x%05x failed!\n", offset);<br>
+                       } else<br>
+                               pr_err("timeout: rlcg program reg:0x%05x failed!\n", offset);<br>
+               }<br>
         }<br>
 <br>
+       ret = readl(scratch_reg0);<br>
+<br>
+       return ret;<br>
+}<br>
+<br>
+static bool gfx_v9_0_get_rlcg_flag(struct amdgpu_device *adev, u32 acc_flags, u32 hwip,<br>
+                               int write, u32 *rlcg_flag)<br>
+{<br>
+<br>
+       switch (hwip) {<br>
+       case GC_HWIP:<br>
+               if (amdgpu_sriov_reg_indirect_gc(adev)) {<br>
+                       *rlcg_flag = write ? GFX9_RLCG_GC_WRITE : GFX9_RLCG_GC_READ;<br>
+<br>
+                       return true;<br>
+               /* only in new version, AMDGPU_REGS_NO_KIQ and AMDGPU_REGS_RLC enabled simultaneously */<br>
+               } else if ((acc_flags & AMDGPU_REGS_RLC) && !(acc_flags & AMDGPU_REGS_NO_KIQ) && write) {<br>
+                       *rlcg_flag = GFX9_RLCG_GC_WRITE_OLD;<br>
+                       return true;<br>
+               }<br>
+<br>
+               break;<br>
+       default:<br>
+               return false;<br>
+       }<br>
+<br>
+       return false;<br>
+}<br>
+<br>
+static u32 gfx_v9_0_sriov_rreg(struct amdgpu_device *adev, u32 offset, u32 acc_flags, u32 hwip)<br>
+{<br>
+       u32 rlcg_flag;<br>
+<br>
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 0, &rlcg_flag))<br>
+               return gfx_v9_0_rlcg_rw(adev, offset, 0, rlcg_flag);<br>
+<br>
+       if (acc_flags & AMDGPU_REGS_NO_KIQ)<br>
+               return RREG32_NO_KIQ(offset);<br>
+       else<br>
+               return RREG32(offset);<br>
 }<br>
 <br>
 static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,<br>
-                              u32 v, u32 acc_flags, u32 hwip)<br>
+                              u32 value, u32 acc_flags, u32 hwip)<br>
 {<br>
-       if ((acc_flags & AMDGPU_REGS_RLC) &&<br>
-           amdgpu_sriov_fullaccess(adev)) {<br>
-               gfx_v9_0_rlcg_w(adev, offset, v, acc_flags);<br>
+       u32 rlcg_flag;<br>
 <br>
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 1, &rlcg_flag)) {<br>
+               gfx_v9_0_rlcg_rw(adev, offset, value, rlcg_flag);<br>
                 return;<br>
         }<br>
 <br>
         if (acc_flags & AMDGPU_REGS_NO_KIQ)<br>
-               WREG32_NO_KIQ(offset, v);<br>
+               WREG32_NO_KIQ(offset, value);<br>
         else<br>
-               WREG32(offset, v);<br>
+               WREG32(offset, value);<br>
 }<br>
 <br>
 #define VEGA10_GB_ADDR_CONFIG_GOLDEN 0x2a114042<br>
@@ -5135,7 +5195,7 @@ static void gfx_v9_0_update_spm_vmid(struct amdgpu_device *adev, unsigned vmid)<br>
         if (amdgpu_sriov_is_pp_one_vf(adev))<br>
                 data = RREG32_NO_KIQ(reg);<br>
         else<br>
-               data = RREG32(reg);<br>
+               data = RREG32_SOC15(GC, 0, mmRLC_SPM_MC_CNTL);<br>
 <br>
         data &= ~RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK;<br>
         data |= (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;<br>
@@ -5191,6 +5251,7 @@ static const struct amdgpu_rlc_funcs gfx_v9_0_rlc_funcs = {<br>
         .start = gfx_v9_0_rlc_start,<br>
         .update_spm_vmid = gfx_v9_0_update_spm_vmid,<br>
         .sriov_wreg = gfx_v9_0_sriov_wreg,<br>
+       .sriov_rreg = gfx_v9_0_sriov_rreg,<br>
         .is_rlcg_access_range = gfx_v9_0_is_rlcg_access_range,<br>
 };<br>
 <br>
@@ -5796,16 +5857,16 @@ static void gfx_v9_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,<br>
 <br>
         switch (state) {<br>
         case AMDGPU_IRQ_STATE_DISABLE:<br>
-               mec_int_cntl = RREG32(mec_int_cntl_reg);<br>
+               mec_int_cntl = RREG32_SOC15_IP(GC,mec_int_cntl_reg);<br>
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,<br>
                                              TIME_STAMP_INT_ENABLE, 0);<br>
-               WREG32(mec_int_cntl_reg, mec_int_cntl);<br>
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);<br>
                 break;<br>
         case AMDGPU_IRQ_STATE_ENABLE:<br>
-               mec_int_cntl = RREG32(mec_int_cntl_reg);<br>
+               mec_int_cntl = RREG32_SOC15_IP(GC, mec_int_cntl_reg);<br>
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,<br>
                                              TIME_STAMP_INT_ENABLE, 1);<br>
-               WREG32(mec_int_cntl_reg, mec_int_cntl);<br>
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);<br>
                 break;<br>
         default:<br>
                 break;<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>