<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<meta content="text/html; charset=UTF-8">
<style type="text/css" style="">
<!--
p
        {margin-top:0;
        margin-bottom:0}
-->
</style>
<div dir="ltr">
<div id="x_divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Reviewed-by: Monk Liu <monk.liu@amd.com><br>
</p>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>发件人:</b> Trigger Huang <trigger.huang@amd.com><br>
<b>发送时间:</b> 2017年2月16日 18:48:19<br>
<b>收件人:</b> amd-gfx@lists.freedesktop.org<br>
<b>抄送:</b> Liu, Monk; Yu, Xiangliang; Huang, Trigger<br>
<b>主题:</b> [PATCH] drm/amdgpu: Fix module unload hang by KIQ IRQ set</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">In some cases, manually insmod/rmmod amdgpu is necessary. When<br>
unloading amdgpu, the KIQ IRQ enable/disable function will case<br>
system hang. The root cause is, in the sequence of function<br>
amdgpu_fini, the sw_fini of IP block AMD_IP_BLOCK_TYPE_GFX will be<br>
invoked earlier than that of AMD_IP_BLOCK_TYPE_IH. So continue to use<br>
the variable freed by AMD_IP_BLOCK_TYPE_GFX will cause system hang.<br>
<br>
Signed-off-by: Trigger Huang <trigger.huang@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu.h   |  2 ++<br>
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 17 ++++++++---------<br>
 2 files changed, 10 insertions(+), 9 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
index 1db2e7b..be43d09 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
@@ -793,6 +793,8 @@ struct amdgpu_kiq {<br>
         struct amdgpu_bo        *eop_obj;<br>
         struct amdgpu_ring      ring;<br>
         struct amdgpu_irq_src   irq;<br>
+       u32                     me;<br>
+       u32                     pipe;<br>
 };<br>
 <br>
 /*<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
index 772c42b..04e2a5b 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c<br>
@@ -1390,12 +1390,15 @@ static int gfx_v8_0_kiq_init_ring(struct amdgpu_device *adev,<br>
         if (adev->gfx.mec2_fw) {<br>
                 ring->me = 2;<br>
                 ring->pipe = 0;<br>
+               adev->gfx.kiq.me = 2;<br>
+               adev->gfx.kiq.pipe = 0;<br>
         } else {<br>
                 ring->me = 1;<br>
                 ring->pipe = 1;<br>
+               adev->gfx.kiq.me = 1;<br>
+               adev->gfx.kiq.pipe = 1;<br>
         }<br>
 <br>
-       irq->data = ring;<br>
         ring->queue = 0;<br>
         sprintf(ring->name, "kiq %d.%d.%d", ring->me, ring->pipe, ring->queue);<br>
         r = amdgpu_ring_init(adev, ring, 1024,<br>
@@ -1410,7 +1413,6 @@ static void gfx_v8_0_kiq_free_ring(struct amdgpu_ring *ring,<br>
 {<br>
         amdgpu_wb_free(ring->adev, ring->adev->virt.reg_val_offs);<br>
         amdgpu_ring_fini(ring);<br>
-       irq->data = NULL;<br>
 }<br>
 <br>
 #define MEC_HPD_SIZE 2048<br>
@@ -6927,15 +6929,12 @@ static int gfx_v8_0_kiq_set_interrupt_state(struct amdgpu_device *adev,<br>
                                             enum amdgpu_interrupt_state state)<br>
 {<br>
         uint32_t tmp, target;<br>
-       struct amdgpu_ring *ring = (struct amdgpu_ring *)src->data;<br>
 <br>
-       BUG_ON(!ring || (ring->funcs->type != AMDGPU_RING_TYPE_KIQ));<br>
-<br>
-       if (ring->me == 1)<br>
+       if (adev->gfx.kiq.me == 1)<br>
                 target = mmCP_ME1_PIPE0_INT_CNTL;<br>
         else<br>
                 target = mmCP_ME2_PIPE0_INT_CNTL;<br>
-       target += ring->pipe;<br>
+       target += adev->gfx.kiq.pipe;<br>
 <br>
         switch (type) {<br>
         case AMDGPU_CP_KIQ_IRQ_DRIVER0:<br>
@@ -6973,7 +6972,7 @@ static int gfx_v8_0_kiq_irq(struct amdgpu_device *adev,<br>
                             struct amdgpu_iv_entry *entry)<br>
 {<br>
         u8 me_id, pipe_id, queue_id;<br>
-       struct amdgpu_ring *ring = (struct amdgpu_ring *)source->data;<br>
+       struct amdgpu_ring *ring = &(adev->gfx.kiq.ring);<br>
 <br>
         BUG_ON(!ring || (ring->funcs->type != AMDGPU_RING_TYPE_KIQ));<br>
 <br>
@@ -7380,4 +7379,4 @@ static void gfx_v8_0_compute_mqd_soft_fini(struct amdgpu_device *adev)<br>
 <br>
         ring = &adev->gfx.kiq.ring;<br>
         amdgpu_bo_free_kernel(&ring->mqd_obj, &ring->mqd_gpu_addr, (void **)&ring->mqd_ptr);<br>
-}<br>
\ No newline at end of file<br>
+}<br>
-- <br>
2.7.4<br>
<br>
</div>
</span></font>
</body>
</html>