<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">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">Reviewed-by: Kevin Wang <kevin1.wang@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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Le Ma <le.ma@amd.com><br>
<b>Sent:</b> Friday, August 9, 2019 7:26 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Ma, Le <Le.Ma@amd.com><br>
<b>Subject:</b> [PATCH 3/4] drm/amdgpu: add mmhub clock gating for Arcturus</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Add 2 mmhub instances CG<br>
<br>
Change-Id: I76ab7a50cd9a40de3022f733787b42e4e5c4dbf5<br>
Signed-off-by: Le Ma <le.ma@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   |  12 +--<br>
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c | 126 ++++++++++++++++++++++++++++++++<br>
 drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.h |   3 +<br>
 3 files changed, 135 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
index cccb6e9..44ac122 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c<br>
@@ -1465,9 +1465,9 @@ static int gmc_v9_0_set_clockgating_state(void *handle,<br>
         struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
 <br>
         if (adev->asic_type == CHIP_ARCTURUS)<br>
-               return 0;<br>
-<br>
-       mmhub_v1_0_set_clockgating(adev, state);<br>
+               mmhub_v9_4_set_clockgating(adev, state);<br>
+       else<br>
+               mmhub_v1_0_set_clockgating(adev, state);<br>
 <br>
         athub_v1_0_set_clockgating(adev, state);<br>
 <br>
@@ -1479,9 +1479,9 @@ static void gmc_v9_0_get_clockgating_state(void *handle, u32 *flags)<br>
         struct amdgpu_device *adev = (struct amdgpu_device *)handle;<br>
 <br>
         if (adev->asic_type == CHIP_ARCTURUS)<br>
-               return;<br>
-<br>
-       mmhub_v1_0_get_clockgating(adev, flags);<br>
+               mmhub_v9_4_get_clockgating(adev, flags);<br>
+       else<br>
+               mmhub_v1_0_get_clockgating(adev, flags);<br>
 <br>
         athub_v1_0_get_clockgating(adev, flags);<br>
 }<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c<br>
index 33b0de5..e52e4d1 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.c<br>
@@ -515,3 +515,129 @@ void mmhub_v9_4_init(struct amdgpu_device *adev)<br>
                                     i * MMHUB_INSTANCE_REGISTER_OFFSET;<br>
         }<br>
 }<br>
+<br>
+static void mmhub_v9_4_update_medium_grain_clock_gating(struct amdgpu_device *adev,<br>
+                                                       bool enable)<br>
+{<br>
+       uint32_t def, data, def1, data1;<br>
+       int i, j;<br>
+       int dist = mmDAGB1_CNTL_MISC2 - mmDAGB0_CNTL_MISC2;<br>
+<br>
+       for (i = 0; i < MMHUB_NUM_INSTANCES; i++) {<br>
+               def = data = RREG32_SOC15_OFFSET(MMHUB, 0,<br>
+                                       mmATCL2_0_ATC_L2_MISC_CG,<br>
+                                       i * MMHUB_INSTANCE_REGISTER_OFFSET);<br>
+<br>
+               if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG))<br>
+                       data |= ATCL2_0_ATC_L2_MISC_CG__ENABLE_MASK;<br>
+               else<br>
+                       data &= ~ATCL2_0_ATC_L2_MISC_CG__ENABLE_MASK;<br>
+<br>
+               if (def != data)<br>
+                       WREG32_SOC15_OFFSET(MMHUB, 0, mmATCL2_0_ATC_L2_MISC_CG,<br>
+                               i * MMHUB_INSTANCE_REGISTER_OFFSET, data);<br>
+<br>
+               for (j = 0; j < 5; j++) {<br>
+                       def1 = data1 = RREG32_SOC15_OFFSET(MMHUB, 0,<br>
+                                       mmDAGB0_CNTL_MISC2,<br>
+                                       i * MMHUB_INSTANCE_REGISTER_OFFSET +<br>
+                                       j * dist);<br>
+                       if (enable &&<br>
+                           (adev->cg_flags & AMD_CG_SUPPORT_MC_MGCG)) {<br>
+                               data1 &=<br>
+                                   ~(DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);<br>
+                       } else {<br>
+                               data1 |=<br>
+                                   (DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |<br>
+                                   DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK);<br>
+                       }<br>
+<br>
+                       if (def1 != data1)<br>
+                               WREG32_SOC15_OFFSET(MMHUB, 0,<br>
+                                       mmDAGB0_CNTL_MISC2,<br>
+                                       i * MMHUB_INSTANCE_REGISTER_OFFSET +<br>
+                                       j * dist, data1);<br>
+<br>
+                       if (i == 1 && j == 3)<br>
+                               break;<br>
+               }<br>
+       }<br>
+}<br>
+<br>
+static void mmhub_v9_4_update_medium_grain_light_sleep(struct amdgpu_device *adev,<br>
+                                                      bool enable)<br>
+{<br>
+       uint32_t def, data;<br>
+       int i;<br>
+<br>
+       for (i = 0; i < MMHUB_NUM_INSTANCES; i++) {<br>
+               def = data = RREG32_SOC15_OFFSET(MMHUB, 0,<br>
+                                       mmATCL2_0_ATC_L2_MISC_CG,<br>
+                                       i * MMHUB_INSTANCE_REGISTER_OFFSET);<br>
+<br>
+               if (enable && (adev->cg_flags & AMD_CG_SUPPORT_MC_LS))<br>
+                       data |= ATCL2_0_ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK;<br>
+               else<br>
+                       data &= ~ATCL2_0_ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK;<br>
+<br>
+               if (def != data)<br>
+                       WREG32_SOC15_OFFSET(MMHUB, 0, mmATCL2_0_ATC_L2_MISC_CG,<br>
+                               i * MMHUB_INSTANCE_REGISTER_OFFSET, data);<br>
+       }<br>
+}<br>
+<br>
+int mmhub_v9_4_set_clockgating(struct amdgpu_device *adev,<br>
+                              enum amd_clockgating_state state)<br>
+{<br>
+       if (amdgpu_sriov_vf(adev))<br>
+               return 0;<br>
+<br>
+       switch (adev->asic_type) {<br>
+       case CHIP_ARCTURUS:<br>
+               mmhub_v9_4_update_medium_grain_clock_gating(adev,<br>
+                               state == AMD_CG_STATE_GATE ? true : false);<br>
+               mmhub_v9_4_update_medium_grain_light_sleep(adev,<br>
+                               state == AMD_CG_STATE_GATE ? true : false);<br>
+               break;<br>
+       default:<br>
+               break;<br>
+       }<br>
+<br>
+       return 0;<br>
+}<br>
+<br>
+/* TODO: get 2 mmhub instances CG state */<br>
+void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags)<br>
+{<br>
+       int data, data1;<br>
+<br>
+       if (amdgpu_sriov_vf(adev))<br>
+               *flags = 0;<br>
+<br>
+       /* AMD_CG_SUPPORT_MC_MGCG */<br>
+       data = RREG32_SOC15(MMHUB, 0, mmATCL2_0_ATC_L2_MISC_CG);<br>
+<br>
+       data1 = RREG32_SOC15(MMHUB, 0, mmATCL2_0_ATC_L2_MISC_CG);<br>
+<br>
+       if ((data & ATCL2_0_ATC_L2_MISC_CG__ENABLE_MASK) &&<br>
+           !(data1 & (DAGB0_CNTL_MISC2__DISABLE_WRREQ_CG_MASK |<br>
+                      DAGB0_CNTL_MISC2__DISABLE_WRRET_CG_MASK |<br>
+                      DAGB0_CNTL_MISC2__DISABLE_RDREQ_CG_MASK |<br>
+                      DAGB0_CNTL_MISC2__DISABLE_RDRET_CG_MASK |<br>
+                      DAGB0_CNTL_MISC2__DISABLE_TLBWR_CG_MASK |<br>
+                      DAGB0_CNTL_MISC2__DISABLE_TLBRD_CG_MASK)))<br>
+               *flags |= AMD_CG_SUPPORT_MC_MGCG;<br>
+<br>
+       /* AMD_CG_SUPPORT_MC_LS */<br>
+       if (data & ATCL2_0_ATC_L2_MISC_CG__MEM_LS_ENABLE_MASK)<br>
+               *flags |= AMD_CG_SUPPORT_MC_LS;<br>
+}<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.h b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.h<br>
index 9ba3dd8..d435cfc 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/mmhub_v9_4.h<br>
@@ -29,5 +29,8 @@ void mmhub_v9_4_gart_disable(struct amdgpu_device *adev);<br>
 void mmhub_v9_4_set_fault_enable_default(struct amdgpu_device *adev,<br>
                                          bool value);<br>
 void mmhub_v9_4_init(struct amdgpu_device *adev);<br>
+int mmhub_v9_4_set_clockgating(struct amdgpu_device *adev,<br>
+                              enum amd_clockgating_state state);<br>
+void mmhub_v9_4_get_clockgating(struct amdgpu_device *adev, u32 *flags);<br>
 <br>
 #endif<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></div>
</span></font></div>
</body>
</html>