<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">>"<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">adev->gfx.bready_for_off"
 used for ?</span></span><br>
</p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0">This flag should only be set by gfx ip after gfx cg/pg feature enabled.</p>
<p style="margin-top:0; margin-bottom:0">Other clients can't enable gfx off feature <span>before this flag is set.</span></p>
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">>"adev->gfx.bready_for_off
 == 0"</span></span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">For
 disable gfx off feature, we don't need to care this flag.</span></span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><br>
</span></span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"></span></span></span><br>
</p>
<p style="margin-top:0; margin-bottom:0">Best Regards</p>
<p style="margin-top:0; margin-bottom:0">Rex<br>
</p>
<br>
<div style="color:rgb(0,0,0)">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> Quan, Evan<br>
<b>Sent:</b> Monday, July 30, 2018 11:12 AM<br>
<b>To:</b> Zhu, Rex; amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH 1/4] drm/amdgpu: Add amdgpu_gfx_off_ctrl function</font>
<div> </div>
</div>
<meta content="text/html; charset=iso-8859-1">
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); font-family: Calibri, Helvetica, sans-serif, "EmojiFont", "Apple Color Emoji", "Segoe UI Emoji", NotoColorEmoji, "Segoe UI Symbol", "Android Emoji", EmojiSymbols;">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p style="margin-top:0; margin-bottom:0"><br>
</p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+      
 if (adev->gfx.bready_for_off && !adev->gfx.bin_off</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+                               && !adev->gfx.disable_gfx_off_request) {</span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+              
 if (!amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, true))</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+                       adev->gfx.bin_off = true;</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+       } else if (!enable && adev->gfx.bin_off) {</span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">What is "<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">adev->gfx.bready_for_off"
 used for ? Do we need to consider "<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">adev->gfx.bready_for_off == 0" case here?</span></span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+               if (!amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, false))</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+                       adev->gfx.bin_off = false;</span><br style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">
<span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">+       }</span><br>
</span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><br>
</span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">Regards,</span></span></p>
<p style="margin-top:0; margin-bottom:0"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px"><span style="color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:14.6667px">Evan</span></span></p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Rex Zhu <rex.zhu@amd.com><br>
<b>Sent:</b> Sunday, July 29, 2018 7:35:47 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org<br>
<b>Cc:</b> Zhu, Rex<br>
<b>Subject:</b> [PATCH 1/4] drm/amdgpu: Add amdgpu_gfx_off_ctrl function</font>
<div> </div>
</div>
<div class="x_BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="x_PlainText">This funciton as the entry of gfx off ctrl feature.<br>
we arbitrat gfx off feature enable/disable in this<br>
function.<br>
<br>
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  7 ++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c    | 52 ++++++++++++++++++++++++++++++<br>
 3 files changed, 60 insertions(+)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
index 5b7bb58..318961d 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
@@ -988,6 +988,11 @@ struct amdgpu_gfx {<br>
         /* NGG */<br>
         struct amdgpu_ngg               ngg;<br>
 <br>
+       /* gfx off */<br>
+       bool                            bready_for_off;<br>
+       bool                            bin_off;<br>
+       struct mutex                    gfx_off_ctrl_mutex;<br>
+       uint32_t                        disable_gfx_off_request;<br>
         /* pipe reservation */<br>
         struct mutex                    pipe_reserve_mutex;<br>
         DECLARE_BITMAP                  (pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);<br>
@@ -1815,6 +1820,8 @@ void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,<br>
                                              const u32 array_size);<br>
 <br>
 bool amdgpu_device_is_px(struct drm_device *dev);<br>
+void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev,<br>
+                               enum amd_ip_block_type client, bool enable);<br>
 /* atpx handler */<br>
 #if defined(CONFIG_VGA_SWITCHEROO)<br>
 void amdgpu_register_atpx_handler(void);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
index 745f760..b40ce6f 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -2367,6 +2367,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,<br>
         mutex_init(&adev->gfx.gpu_clock_mutex);<br>
         mutex_init(&adev->srbm_mutex);<br>
         mutex_init(&adev->gfx.pipe_reserve_mutex);<br>
+       mutex_init(&adev->gfx.gfx_off_ctrl_mutex);<br>
         mutex_init(&adev->grbm_idx_mutex);<br>
         mutex_init(&adev->mn_lock);<br>
         mutex_init(&adev->virt.vf_errors.lock);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
index 239bf2a..68fe9c8 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c<br>
@@ -340,3 +340,55 @@ void amdgpu_gfx_compute_mqd_sw_fini(struct amdgpu_device *adev)<br>
                               &ring->mqd_gpu_addr,<br>
                               &ring->mqd_ptr);<br>
 }<br>
+<br>
+/* amdgpu_gfx_off_ctrl - Handle gfx off feature enable/disable<br>
+ *<br>
+ * @adev: amdgpu_device pointer<br>
+ * @enum amd_ip_block_type gfx ip decide when to set ready for gfx off feature<br>
+ * other clients send disable gfx off feature request<br>
+ * @bool enable<br>
+ *<br>
+ * if gfx ip is ready for power off gfx ip, and no other clients's request for<br>
+ * disable gfx off feature, driver will call smu to enable gfx off immediately.<br>
+ * otherwise, driver will wait until the clients cancel the requests.<br>
+ */<br>
+<br>
+void amdgpu_gfx_off_ctrl(struct amdgpu_device *adev, enum amd_ip_block_type client, bool enable)<br>
+{<br>
+       if (!(adev->powerplay.pp_feature & PP_GFXOFF_MASK))<br>
+               return; /* gfx off feature is not supported or disabled by user via module parameter */<br>
+<br>
+       if (!adev->powerplay.pp_funcs->set_powergating_by_smu)<br>
+               return; /* currently gfx off feature need smu support*/<br>
+<br>
+       mutex_lock(&adev->gfx.gfx_off_ctrl_mutex);<br>
+       if (client == AMD_IP_BLOCK_TYPE_GFX) {<br>
+               adev->gfx.bready_for_off = enable ? true : false; /*true, gfx ip is ready to enable gfx off feature */<br>
+       } else {<br>
+               if (!enable) /* false : reveive one disable gfx off requests from other clients*/<br>
+                       adev->gfx.disable_gfx_off_request++;<br>
+               else if (adev->gfx.disable_gfx_off_request > 0)<br>
+                       adev->gfx.disable_gfx_off_request--;<br>
+       }<br>
+<br>
+/* *<br>
+ * we can enable gfx off feature when meet the following conditions:<br>
+ * 1. gfx off feature is supported by hw<br>
+ * 2. gfx ip is ready to enable gfx off feature<br>
+ * 3. no other clients have requests to disable gfx off<br>
+ * 4. gfx off feature is not enabled<br>
+ * For disable gfx off feature<br>
+ * 1. gfx off feature is supported by hw<br>
+ * 2. receive disable gfx off requests<br>
+ * 3. gfx off feature is enabled<br>
+ */<br>
+       if (adev->gfx.bready_for_off && !adev->gfx.bin_off<br>
+                               && !adev->gfx.disable_gfx_off_request) {<br>
+               if (!amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, true))<br>
+                       adev->gfx.bin_off = true;<br>
+       } else if (!enable && adev->gfx.bin_off) {<br>
+               if (!amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_GFX, false))<br>
+                       adev->gfx.bin_off = false;<br>
+       }<br>
+       mutex_unlock(&adev->gfx.gfx_off_ctrl_mutex);<br>
+}<br>
-- <br>
1.9.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" id="LPlnk886781" class="x_OWAAutoLink" previewremoved="true">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a>
<div id="LPBorder_GT_15329201729380.3302477536537516" style="margin-bottom:20px; overflow:auto; width:100%; text-indent:0px">
<table id="LPContainer_15329201729290.557243803333892" style="width:90%; background-color:rgb(255,255,255); overflow:auto; padding-top:20px; padding-bottom:20px; margin-top:20px; border-top:1px dotted rgb(200,200,200); border-bottom:1px dotted rgb(200,200,200)" cellspacing="0">
<tbody>
<tr style="border-spacing:0px" valign="top">
<td id="x_TextCell_15329201729320.5856508556754785" colspan="2" style="vertical-align: top; padding: 0px; display: table-cell; position: relative;">
<div id="LPRemovePreviewContainer_15329201729320.8037375547458883"></div>
<div id="LPTitle_15329201729330.8257753121147637" style="top:0px; color:rgb(0,120,215); font-weight:400; font-size:21px; font-family:wf_segoe-ui_light,"Segoe UI Light","Segoe WP Light","Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; line-height:21px">
<a id="LPUrlAnchor_15329201729340.18268190718998456" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx" target="_blank" style="text-decoration:none">amd-gfx Info Page - freedesktop.org</a></div>
<div id="LPMetadata_15329201729350.9576148436869616" style="margin:10px 0px 16px; color:rgb(102,102,102); font-weight:400; font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; font-size:14px; line-height:14px">
lists.freedesktop.org</div>
<div id="LPDescription_15329201729360.08722428468077426" style="display:block; color:rgb(102,102,102); font-weight:400; font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif; font-size:14px; line-height:20px; max-height:100px; overflow:hidden">
Subscribing to amd-gfx: Subscribe to amd-gfx by filling out the following form. Use of all freedesktop.org lists is subject to our Code of Conduct.</div>
</td>
</tr>
</tbody>
</table>
</div>
<br>
<br>
</div>
</span></font></div>
</div>
</div>
</div>
</div>
</body>
</html>