<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" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p><br>
</p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<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>From:</b> Monk Liu <Monk.Liu@amd.com><br>
<b>Sent:</b> Tuesday, July 18, 2017 1:56 PM<br>
<b>To:</b> amd-gfx-bounces@lists.freedesktop.org<br>
<b>Cc:</b> Liu, Monk; Yu, Xiangliang<br>
<b>Subject:</b> [PATCH] drm/amdgpu:fix gfx fence allocate size</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">1, for sriov, we need 8dw for the gfx fence due to CP<br>
behaviour<br>
2, cleanup wrong logic in wptr/rptr wb alloc and free<br>
<br>
Change-Id: Ifbfed17a4621dae57244942ffac7de1743de0294<br>
Signed-off-by: Monk Liu <Monk.Liu@amd.com><br>
Signed-off-by: Xiangliang Yu <Xiangliang.Yu@amd.com><br>
---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  2 ++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 32 ++++++++++++++++++++++++++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 26 ++++++++++++++++--------<br>
 3 files changed, 52 insertions(+), 8 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
index f6345b9..fe96236 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h<br>
@@ -1191,7 +1191,9 @@ struct amdgpu_wb {<br>
 int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);<br>
 void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);<br>
 int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb);<br>
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb);<br>
 void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb);<br>
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb);<br>
 <br>
 void amdgpu_get_pcie_info(struct amdgpu_device *adev);<br>
 <br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
index 7e11190..6050804 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -603,6 +603,21 @@ int amdgpu_wb_get_64bit(struct amdgpu_device *adev, u32 *wb)<br>
         }<br>
 }<br>
 <br>
+int amdgpu_wb_get_256Bit(struct amdgpu_device *adev, u32 *wb)<br>
+{<br>
+       int i = 0;<br>
+       unsigned long offset = bitmap_find_next_zero_area_off(adev->wb.used,<br>
+                               adev->wb.num_wb, 0, 8, 63, 0);<br>
+       if ((offset + 7) < adev->wb.num_wb) {<br>
+               for (i = 0; i < 8; i++)<br>
+                       __set_bit(offset + i, adev->wb.used);<br>
+               *wb = offset;<br>
+               return 0;<br>
+       } else {<br>
+               return -EINVAL;<br>
+       }<br>
+}<br>
+<br>
 /**<br>
  * amdgpu_wb_free - Free a wb entry<br>
  *<br>
@@ -634,6 +649,23 @@ void amdgpu_wb_free_64bit(struct amdgpu_device *adev, u32 wb)<br>
 }<br>
 <br>
 /**<br>
+ * amdgpu_wb_free_256bit - Free a wb entry<br>
+ *<br>
+ * @adev: amdgpu_device pointer<br>
+ * @wb: wb index<br>
+ *<br>
+ * Free a wb slot allocated for use by the driver (all asics)<br>
+ */<br>
+void amdgpu_wb_free_256bit(struct amdgpu_device *adev, u32 wb)<br>
+{<br>
+       int i = 0;<br>
+<br>
+       if ((wb + 7) < adev->wb.num_wb)<br>
+               for (i = 0; i < 8; i++)<br>
+                       __clear_bit(wb + i, adev->wb.used);<br>
+}<br>
+<br>
+/**<br>
  * amdgpu_vram_location - try to find VRAM location<br>
  * @adev: amdgpu device structure holding all necessary informations<br>
  * @mc: memory controller structure holding memory informations<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c<br>
index 75165e0..eea17ae 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c<br>
@@ -212,10 +212,19 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,<br>
 <br>
         }<br>
 <br>
-       r = amdgpu_wb_get(adev, &ring->fence_offs);<br>
-       if (r) {<br>
-               dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r);<br>
-               return r;<br>
+       if (amdgpu_sriov_vf(adev) && ring->funcs->type == AMDGPU_RING_TYPE_GFX) {<br>
+               r = amdgpu_wb_get_256Bit(adev, &ring->fence_offs);<br>
+               if (r) {<br>
+                       dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r);<br>
+                       return r;<br>
+               }<br>
+<br>
+       } else {<br>
+               r = amdgpu_wb_get(adev, &ring->fence_offs);<br>
+               if (r) {<br>
+                       dev_err(adev->dev, "(%d) ring fence_offs wb alloc failed\n", r);<br>
+                       return r;<br>
+               }<br>
         }<br>
 <br>
         r = amdgpu_wb_get(adev, &ring->cond_exe_offs);<br>
@@ -278,17 +287,18 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)<br>
         ring->ready = false;<br>
 <br>
         if (ring->funcs->support_64bit_ptrs) {<br>
-               amdgpu_wb_free_64bit(ring->adev, ring->cond_exe_offs);<br>
-               amdgpu_wb_free_64bit(ring->adev, ring->fence_offs);<br>
                 amdgpu_wb_free_64bit(ring->adev, ring->rptr_offs);<br>
                 amdgpu_wb_free_64bit(ring->adev, ring->wptr_offs);<br>
         } else {<br>
-               amdgpu_wb_free(ring->adev, ring->cond_exe_offs);<br>
-               amdgpu_wb_free(ring->adev, ring->fence_offs);<br>
                 amdgpu_wb_free(ring->adev, ring->rptr_offs);<br>
                 amdgpu_wb_free(ring->adev, ring->wptr_offs);<br>
         }<br>
 <br>
+       amdgpu_wb_free(ring->adev, ring->cond_exe_offs);<br>
+       if (amdgpu_sriov_vf(ring->adev) && ring->funcs->type == AMDGPU_RING_TYPE_GFX)<br>
+               amdgpu_wb_free_256bit(ring->adev, ring->fence_offs);<br>
+       else<br>
+               amdgpu_wb_free(ring->adev, ring->cond_exe_offs);<br>
 <br>
         amdgpu_bo_free_kernel(&ring->ring_obj,<br>
                               &ring->gpu_addr,<br>
-- <br>
2.7.4<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>