<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div dir="auto">
<div><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">Am 27.06.2018 10:29 schrieb Junwei Zhang <Jerry.Zhang@amd.com>:<br type="attribution">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:11pt">
<div>Instead of calling gart memory on every bo pin,<br>
allocates it on demand<br>
<br>
v2: fix error handling<br>
v3: drop the change for kfd gtt bo mapping, not needed.<br>
<br>
Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com><br>
</div>
</span></font></div>
</blockquote>
</div>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">Looks good to me on first glance, but I'm on vacation and can't do a full review right now.</div>
<div dir="auto"><br>
</div>
<div dir="auto">One nit pick you could improve is to use "gart address space" instead of "gart memory" to avoid confusion.</div>
<div dir="auto"><br>
</div>
<div dir="auto">Christian.</div>
<div dir="auto"><br>
</div>
<div dir="auto">
<div class="gmail_extra">
<div class="gmail_quote">
<blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><font size="2"><span style="font-size:11pt">
<div>---<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c        |  6 ++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c     | 14 ++++++++++++--<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_display.c       |  6 ++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c            |  8 ++++++++<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c        | 15 +++++++++------<br>
 drivers/gpu/drm/amd/amdgpu/amdgpu_test.c          |  5 +++++<br>
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 13 +++++++++++--<br>
 7 files changed, 57 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
index 98e3bf8..e3ed08d 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c<br>
@@ -280,6 +280,12 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,<br>
                 goto allocate_mem_pin_bo_failed;<br>
         }<br>
 <br>
+       r = amdgpu_ttm_alloc_gart(&bo->tbo);<br>
+       if (r) {<!-- --><br>
+               dev_err(adev->dev, "%p bind failed\n", bo);<br>
+               goto allocate_mem_kmap_bo_failed;<br>
+       }<br>
+<br>
         r = amdgpu_bo_kmap(bo, &cpu_ptr_tmp);<br>
         if (r) {<!-- --><br>
                 dev_err(adev->dev,<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c<br>
index cb88d7e..3079ea8 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c<br>
@@ -96,11 +96,16 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,<br>
         if (unlikely(r != 0))<br>
                 goto out_cleanup;<br>
         r = amdgpu_bo_pin(sobj, sdomain);<br>
-       saddr = amdgpu_bo_gpu_offset(sobj);<br>
+       if (r) {<!-- --><br>
+               amdgpu_bo_unreserve(sobj);<br>
+               goto out_cleanup;<br>
+       }<br>
+       r = amdgpu_ttm_alloc_gart(&sobj->tbo);<br>
         amdgpu_bo_unreserve(sobj);<br>
         if (r) {<!-- --><br>
                 goto out_cleanup;<br>
         }<br>
+       saddr = amdgpu_bo_gpu_offset(sobj);<br>
         bp.domain = ddomain;<br>
         r = amdgpu_bo_create(adev, &bp, &dobj);<br>
         if (r) {<!-- --><br>
@@ -110,11 +115,16 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,<br>
         if (unlikely(r != 0))<br>
                 goto out_cleanup;<br>
         r = amdgpu_bo_pin(dobj, ddomain);<br>
-       daddr = amdgpu_bo_gpu_offset(dobj);<br>
+       if (r) {<!-- --><br>
+               amdgpu_bo_unreserve(sobj);<br>
+               goto out_cleanup;<br>
+       }<br>
+       r = amdgpu_ttm_alloc_gart(&dobj->tbo);<br>
         amdgpu_bo_unreserve(dobj);<br>
         if (r) {<!-- --><br>
                 goto out_cleanup;<br>
         }<br>
+       daddr = amdgpu_bo_gpu_offset(dobj);<br>
 <br>
         if (adev->mman.buffer_funcs) {<!-- --><br>
                 time = amdgpu_benchmark_do_move(adev, size, saddr, daddr, n);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c<br>
index 036b6f7..7d6a36b 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c<br>
@@ -194,6 +194,12 @@ int amdgpu_display_crtc_page_flip_target(struct drm_crtc *crtc,<br>
                 goto unreserve;<br>
         }<br>
 <br>
+       r = amdgpu_ttm_alloc_gart(&new_abo->tbo);<br>
+       if (unlikely(r != 0)) {<!-- --><br>
+               DRM_ERROR("%p bind failed\n", new_abo);<br>
+               goto unpin;<br>
+       }<br>
+<br>
         r = reservation_object_get_fences_rcu(new_abo->tbo.resv, &work->excl,<br>
                                               &work->shared_count,<br>
                                               &work->shared);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
index 462b7a1..cd68a2e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c<br>
@@ -173,6 +173,14 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev,<br>
                 amdgpu_bo_unreserve(abo);<br>
                 goto out_unref;<br>
         }<br>
+<br>
+       ret = amdgpu_ttm_alloc_gart(&abo->tbo);<br>
+       if (ret) {<!-- --><br>
+               amdgpu_bo_unreserve(abo);<br>
+               dev_err(adev->dev, "%p bind failed\n", abo);<br>
+               goto out_unref;<br>
+       }<br>
+<br>
         ret = amdgpu_bo_kmap(abo, NULL);<br>
         amdgpu_bo_unreserve(abo);<br>
         if (ret) {<!-- --><br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
index 79cdbf1..7f7c221 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
@@ -257,6 +257,13 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,<br>
                 dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);<br>
                 goto error_unreserve;<br>
         }<br>
+<br>
+       r = amdgpu_ttm_alloc_gart(&(*bo_ptr)->tbo);<br>
+       if (r) {<!-- --><br>
+               dev_err(adev->dev, "%p bind failed\n", *bo_ptr);<br>
+               goto error_unpin;<br>
+       }<br>
+<br>
         if (gpu_addr)<br>
                 *gpu_addr = amdgpu_bo_gpu_offset(*bo_ptr);<br>
 <br>
@@ -270,6 +277,8 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,<br>
 <br>
         return 0;<br>
 <br>
+error_unpin:<br>
+       amdgpu_bo_unpin(*bo_ptr);<br>
 error_unreserve:<br>
         amdgpu_bo_unreserve(*bo_ptr);<br>
 <br>
@@ -903,12 +912,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,<br>
                 goto error;<br>
         }<br>
 <br>
-       r = amdgpu_ttm_alloc_gart(&bo->tbo);<br>
-       if (unlikely(r)) {<!-- --><br>
-               dev_err(adev->dev, "%p bind failed\n", bo);<br>
-               goto error;<br>
-       }<br>
-<br>
         bo->pin_count = 1;<br>
 <br>
         domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c<br>
index 622affc..d6eeea1 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_test.c<br>
@@ -102,6 +102,11 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)<br>
                         DRM_ERROR("Failed to pin GTT object %d\n", i);<br>
                         goto out_lclean_unres;<br>
                 }<br>
+               r = amdgpu_ttm_alloc_gart(&gtt_obj[i]->tbo);<br>
+               if (r) {<!-- --><br>
+                       DRM_ERROR("%p bind failed\n", gtt_obj[i]);<br>
+                       goto out_lclean_unpin;<br>
+               }<br>
                 gart_addr = amdgpu_bo_gpu_offset(gtt_obj[i]);<br>
 <br>
                 r = amdgpu_bo_kmap(gtt_obj[i], &gtt_map);<br>
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
index 31652c1e..d433428 100644<br>
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c<br>
@@ -3110,13 +3110,22 @@ static int dm_plane_helper_prepare_fb(struct drm_plane *plane,<br>
                 domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
 <br>
         r = amdgpu_bo_pin(rbo, domain);<br>
-       amdgpu_bo_unreserve(rbo);<br>
-<br>
         if (unlikely(r != 0)) {<!-- --><br>
                 if (r != -ERESTARTSYS)<br>
                         DRM_ERROR("Failed to pin framebuffer with error %d\n", r);<br>
+               amdgpu_bo_unreserve(rbo);<br>
+               return r;<br>
+       }<br>
+<br>
+       r = amdgpu_ttm_alloc_gart(&rbo->tbo);<br>
+       if (unlikely(r != 0)) {<!-- --><br>
+               amdgpu_bo_unpin(rbo);<br>
+               amdgpu_bo_unreserve(rbo);<br>
+               DRM_ERROR("%p bind failed\n", rbo);<br>
                 return r;<br>
         }<br>
+       amdgpu_bo_unreserve(rbo);<br>
+<br>
         afb->address = amdgpu_bo_gpu_offset(rbo);<br>
 <br>
         amdgpu_bo_ref(rbo);<br>
-- <br>
1.9.1<br>
<br>
</div>
</span></font></div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</body>
</html>