<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:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Can you explain how the current code is failing?  It's not immediately obvious to me.  I'm not opposed to this change, it's just not clear to me where the current code fails.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Alex</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<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> Chen, Guchun <Guchun.Chen@amd.com><br>
<b>Sent:</b> Monday, November 22, 2021 8:49 AM<br>
<b>To:</b> Cui, Flora <Flora.Cui@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>; Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Subject:</b> RE: [PATCH 1/2] drm/amdgpu: fix vkms hrtimer settings</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">[Public]<br>
<br>
Series is:<br>
Reviewed-by: Guchun Chen <guchun.chen@amd.com><br>
<br>
+Alex to comment this series as well.<br>
<br>
Regards,<br>
Guchun<br>
<br>
-----Original Message-----<br>
From: Cui, Flora <Flora.Cui@amd.com> <br>
Sent: Monday, November 22, 2021 5:04 PM<br>
To: amd-gfx@lists.freedesktop.org; Chen, Guchun <Guchun.Chen@amd.com><br>
Cc: Cui, Flora <Flora.Cui@amd.com><br>
Subject: [PATCH 1/2] drm/amdgpu: fix vkms hrtimer settings<br>
<br>
otherwise adev->mode_info.crtcs[] is NULL<br>
<br>
Signed-off-by: Flora Cui <flora.cui@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 38 ++++++++++++++++--------  drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h |  5 ++--<br>
 2 files changed, 28 insertions(+), 15 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
index ce982afeff91..6c62c45e3e3e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c<br>
@@ -16,6 +16,8 @@<br>
 #include "ivsrcid/ivsrcid_vislands30.h"<br>
 #include "amdgpu_vkms.h"<br>
 #include "amdgpu_display.h"<br>
+#include "atom.h"<br>
+#include "amdgpu_irq.h"<br>
 <br>
 /**<br>
  * DOC: amdgpu_vkms<br>
@@ -41,14 +43,13 @@ static const u32 amdgpu_vkms_formats[] = {<br>
 <br>
 static enum hrtimer_restart amdgpu_vkms_vblank_simulate(struct hrtimer *timer)  {<br>
-       struct amdgpu_vkms_output *output = container_of(timer,<br>
-                                                        struct amdgpu_vkms_output,<br>
-                                                        vblank_hrtimer);<br>
-       struct drm_crtc *crtc = &output->crtc;<br>
+       struct amdgpu_crtc *amdgpu_crtc = container_of(timer, struct amdgpu_crtc, vblank_timer);<br>
+       struct drm_crtc *crtc = &amdgpu_crtc->base;<br>
+       struct amdgpu_vkms_output *output = <br>
+drm_crtc_to_amdgpu_vkms_output(crtc);<br>
         u64 ret_overrun;<br>
         bool ret;<br>
 <br>
-       ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer,<br>
+       ret_overrun = hrtimer_forward_now(&amdgpu_crtc->vblank_timer,<br>
                                           output->period_ns);<br>
         WARN_ON(ret_overrun != 1);<br>
 <br>
@@ -65,22 +66,21 @@ static int amdgpu_vkms_enable_vblank(struct drm_crtc *crtc)<br>
         unsigned int pipe = drm_crtc_index(crtc);<br>
         struct drm_vblank_crtc *vblank = &dev->vblank[pipe];<br>
         struct amdgpu_vkms_output *out = drm_crtc_to_amdgpu_vkms_output(crtc);<br>
+       struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);<br>
 <br>
         drm_calc_timestamping_constants(crtc, &crtc->mode);<br>
 <br>
-       hrtimer_init(&out->vblank_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);<br>
-       out->vblank_hrtimer.function = &amdgpu_vkms_vblank_simulate;<br>
         out->period_ns = ktime_set(0, vblank->framedur_ns);<br>
-       hrtimer_start(&out->vblank_hrtimer, out->period_ns, HRTIMER_MODE_REL);<br>
+       hrtimer_start(&amdgpu_crtc->vblank_timer, out->period_ns, <br>
+HRTIMER_MODE_REL);<br>
 <br>
         return 0;<br>
 }<br>
 <br>
 static void amdgpu_vkms_disable_vblank(struct drm_crtc *crtc)  {<br>
-       struct amdgpu_vkms_output *out = drm_crtc_to_amdgpu_vkms_output(crtc);<br>
+       struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);<br>
 <br>
-       hrtimer_cancel(&out->vblank_hrtimer);<br>
+       hrtimer_cancel(&amdgpu_crtc->vblank_timer);<br>
 }<br>
 <br>
 static bool amdgpu_vkms_get_vblank_timestamp(struct drm_crtc *crtc, @@ -92,13 +92,14 @@ static bool amdgpu_vkms_get_vblank_timestamp(struct drm_crtc *crtc,<br>
         unsigned int pipe = crtc->index;<br>
         struct amdgpu_vkms_output *output = drm_crtc_to_amdgpu_vkms_output(crtc);<br>
         struct drm_vblank_crtc *vblank = &dev->vblank[pipe];<br>
+       struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);<br>
 <br>
         if (!READ_ONCE(vblank->enabled)) {<br>
                 *vblank_time = ktime_get();<br>
                 return true;<br>
         }<br>
 <br>
-       *vblank_time = READ_ONCE(output->vblank_hrtimer.node.expires);<br>
+       *vblank_time = READ_ONCE(amdgpu_crtc->vblank_timer.node.expires);<br>
 <br>
         if (WARN_ON(*vblank_time == vblank->time))<br>
                 return true;<br>
@@ -165,6 +166,8 @@ static const struct drm_crtc_helper_funcs amdgpu_vkms_crtc_helper_funcs = {  static int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,<br>
                           struct drm_plane *primary, struct drm_plane *cursor)  {<br>
+       struct amdgpu_device *adev = drm_to_adev(dev);<br>
+       struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);<br>
         int ret;<br>
 <br>
         ret = drm_crtc_init_with_planes(dev, crtc, primary, cursor, @@ -176,6 +179,17 @@ static int amdgpu_vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,<br>
 <br>
         drm_crtc_helper_add(crtc, &amdgpu_vkms_crtc_helper_funcs);<br>
 <br>
+       amdgpu_crtc->crtc_id = drm_crtc_index(crtc);<br>
+       adev->mode_info.crtcs[drm_crtc_index(crtc)] = amdgpu_crtc;<br>
+<br>
+       amdgpu_crtc->pll_id = ATOM_PPLL_INVALID;<br>
+       amdgpu_crtc->encoder = NULL;<br>
+       amdgpu_crtc->connector = NULL;<br>
+       amdgpu_crtc->vsync_timer_enabled = AMDGPU_IRQ_STATE_DISABLE;<br>
+<br>
+       hrtimer_init(&amdgpu_crtc->vblank_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);<br>
+       amdgpu_crtc->vblank_timer.function = &amdgpu_vkms_vblank_simulate;<br>
+<br>
         return ret;<br>
 }<br>
 <br>
@@ -401,7 +415,7 @@ int amdgpu_vkms_output_init(struct drm_device *dev,  {<br>
         struct drm_connector *connector = &output->connector;<br>
         struct drm_encoder *encoder = &output->encoder;<br>
-       struct drm_crtc *crtc = &output->crtc;<br>
+       struct drm_crtc *crtc = &output->crtc.base;<br>
         struct drm_plane *primary, *cursor = NULL;<br>
         int ret;<br>
 <br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
index 97f1b79c0724..4f8722ff37c2 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.h<br>
@@ -10,15 +10,14 @@<br>
 #define YRES_MAX  16384<br>
 <br>
 #define drm_crtc_to_amdgpu_vkms_output(target) \<br>
-       container_of(target, struct amdgpu_vkms_output, crtc)<br>
+       container_of(target, struct amdgpu_vkms_output, crtc.base)<br>
 <br>
 extern const struct amdgpu_ip_block_version amdgpu_vkms_ip_block;<br>
 <br>
 struct amdgpu_vkms_output {<br>
-       struct drm_crtc crtc;<br>
+       struct amdgpu_crtc crtc;<br>
         struct drm_encoder encoder;<br>
         struct drm_connector connector;<br>
-       struct hrtimer vblank_hrtimer;<br>
         ktime_t period_ns;<br>
         struct drm_pending_vblank_event *event;  };<br>
--<br>
2.25.1<br>
</div>
</span></font></div>
</div>
</body>
</html>