<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@等线";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:"\@宋体";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div class="WordSection1">
<p class="MsoNormal">Modprobe -r amdgpu get oops in amdgpu_vkms_sw_fini()<o:p></o:p></p>
<p class="MsoNormal">              for (i = 0; i < adev->mode_info.num_crtc; i++)<o:p></o:p></p>
<p class="MsoNormal">                             if (adev->mode_info.crtcs[i])<o:p></o:p></p>
<p class="MsoNormal">                                           hrtimer_cancel(&adev->mode_info.crtcs[i]->vblank_timer);<o:p></o:p></p>
<p class="MsoNormal">adev->mode_info.crtcs[i]->vblank_timer is not initiated as vkms init its own amdgpu_vkms_output-> vblank_hrtimer. This patch drop amdgpu_vkms_output-> vblank_hrtimer and try with adev->mode_info.crtcs[i]->vblank_timer to keep align with
 amdgpu_dm & dce_vx_0.c <o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b>From:</b> Deucher, Alexander <Alexander.Deucher@amd.com> <br>
<b>Sent:</b> 2021<span lang="ZH-CN" style="font-family:宋体">年</span>11<span lang="ZH-CN" style="font-family:宋体">月</span>23<span lang="ZH-CN" style="font-family:宋体">日</span> 0:43<br>
<b>To:</b> Chen, Guchun <Guchun.Chen@amd.com>; Cui, Flora <Flora.Cui@amd.com>; amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH 1/2] drm/amdgpu: fix vkms hrtimer settings<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p style="margin:15.0pt"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:green">[Public]<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">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.<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Alex<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Chen, Guchun <<a href="mailto:Guchun.Chen@amd.com">Guchun.Chen@amd.com</a>><br>
<b>Sent:</b> Monday, November 22, 2021 8:49 AM<br>
<b>To:</b> Cui, Flora <<a href="mailto:Flora.Cui@amd.com">Flora.Cui@amd.com</a>>;
<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a> <<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>>; Deucher, Alexander <<a href="mailto:Alexander.Deucher@amd.com">Alexander.Deucher@amd.com</a>><br>
<b>Subject:</b> RE: [PATCH 1/2] drm/amdgpu: fix vkms hrtimer settings</span> <o:p>
</o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">[Public]<br>
<br>
Series is:<br>
Reviewed-by: Guchun Chen <<a href="mailto:guchun.chen@amd.com">guchun.chen@amd.com</a>><br>
<br>
+Alex to comment this series as well.<br>
<br>
Regards,<br>
Guchun<br>
<br>
-----Original Message-----<br>
From: Cui, Flora <<a href="mailto:Flora.Cui@amd.com">Flora.Cui@amd.com</a>> <br>
Sent: Monday, November 22, 2021 5:04 PM<br>
To: <a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>; Chen, Guchun <<a href="mailto:Guchun.Chen@amd.com">Guchun.Chen@amd.com</a>><br>
Cc: Cui, Flora <<a href="mailto:Flora.Cui@amd.com">Flora.Cui@amd.com</a>><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 <<a href="mailto:flora.cui@amd.com">flora.cui@amd.com</a>><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<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>