Skip to contentSkip to conversation

drm/amdgpu: expose AMDGPU_GEM_CREATE_VRAM_CLEARED to user space

PATCH In review Flora Cui 3 participants 5 messages Jul 25, 2016 – Aug 3, 2016 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Flora Cui

author
#0 lore raw

PATCH v2 2/2 drm/amdgpu: expose AMDGPU_GEM_CREATE_VRAM_CLEARED to user space

V2: fix the return value for fill failure and validate bo before filling data

Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 33 ++++++++++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  2 ++
 2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +33 -0
index 6f0873c..59f3a75 100644
@@ -277,11 +277,44 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	if (unlikely(r != 0)) {
 		return r;
 	}
+
+	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+		struct fence *fence;
+
+		if (adev->mman.buffer_funcs_ring == NULL ||
+		   !adev->mman.buffer_funcs_ring->ready) {
+			r = -EBUSY;
+			goto fail_free;
+		}
+
+		r = amdgpu_bo_reserve(bo, false);
+		if (unlikely(r != 0))
+			goto fail_free;
+
+		amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);
+		r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+		if (unlikely(r != 0))
+			goto fail_unreserve;
+
+		amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+		amdgpu_bo_fence(bo, fence, false);
+		amdgpu_bo_unreserve(bo);
+		fence_put(bo->tbo.moving);
+		bo->tbo.moving = fence_get(fence);
+		fence_put(fence);
+	}
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
 
 	return 0;
+
+fail_unreserve:
+	amdgpu_bo_unreserve(bo);
+fail_free:
+	amdgpu_bo_unref(&bo);
+	return r;
 }
 
 int amdgpu_bo_create(struct amdgpu_device *adev,
include/uapi/drm/amdgpu_drm.h +2 -0
index 946f238..8df3816 100644
@@ -75,6 +75,8 @@
 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS		(1 << 1)
 /* Flag that USWC attributes should be used for GTT */
 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC		(1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED		(1 << 3)
 
 struct drm_amdgpu_gem_create_in  {
 	/** the requested memory size */
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1469427324-14908-2-git-send-email-Flora.Cui-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

ping...

Quoted 80 lines · Flora Cui

V2: fix the return value for fill failure and validate bo before filling data

Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 33 ++++++++++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  2 ++
 2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +33 -0
index 6f0873c..59f3a75 100644
@@ -277,11 +277,44 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	if (unlikely(r != 0)) {
 		return r;
 	}
+
+	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+		struct fence *fence;
+
+		if (adev->mman.buffer_funcs_ring == NULL ||
+		   !adev->mman.buffer_funcs_ring->ready) {
+			r = -EBUSY;
+			goto fail_free;
+		}
+
+		r = amdgpu_bo_reserve(bo, false);
+		if (unlikely(r != 0))
+			goto fail_free;
+
+		amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);
+		r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+		if (unlikely(r != 0))
+			goto fail_unreserve;
+
+		amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+		amdgpu_bo_fence(bo, fence, false);
+		amdgpu_bo_unreserve(bo);
+		fence_put(bo->tbo.moving);
+		bo->tbo.moving = fence_get(fence);
+		fence_put(fence);
+	}
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
 
 	return 0;
+
+fail_unreserve:
+	amdgpu_bo_unreserve(bo);
+fail_free:
+	amdgpu_bo_unref(&bo);
+	return r;
 }
 
 int amdgpu_bo_create(struct amdgpu_device *adev,
include/uapi/drm/amdgpu_drm.h +2 -0
index 946f238..8df3816 100644
@@ -75,6 +75,8 @@
 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS		(1 << 1)
 /* Flag that USWC attributes should be used for GTT */
 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC		(1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED		(1 << 3)
 
 struct drm_amdgpu_gem_create_in  {
 	/** the requested memory size */
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#3 lore raw

I'll push if no objection

Quoted 79 lines · Flora Cui

ping...

Quoted 76 lines · Flora Cui

V2: fix the return value for fill failure and validate bo before filling data

Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 33 ++++++++++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  2 ++
 2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +33 -0
index 6f0873c..59f3a75 100644
@@ -277,11 +277,44 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	if (unlikely(r != 0)) {
 		return r;
 	}
+
+	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+		struct fence *fence;
+
+		if (adev->mman.buffer_funcs_ring == NULL ||
+		   !adev->mman.buffer_funcs_ring->ready) {
+			r = -EBUSY;
+			goto fail_free;
+		}
+
+		r = amdgpu_bo_reserve(bo, false);
+		if (unlikely(r != 0))
+			goto fail_free;
+
+		amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);
+		r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+		if (unlikely(r != 0))
+			goto fail_unreserve;
+
+		amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+		amdgpu_bo_fence(bo, fence, false);
+		amdgpu_bo_unreserve(bo);
+		fence_put(bo->tbo.moving);
+		bo->tbo.moving = fence_get(fence);
+		fence_put(fence);
+	}
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
 
 	return 0;
+
+fail_unreserve:
+	amdgpu_bo_unreserve(bo);
+fail_free:
+	amdgpu_bo_unref(&bo);
+	return r;
 }
 
 int amdgpu_bo_create(struct amdgpu_device *adev,
include/uapi/drm/amdgpu_drm.h +2 -0
index 946f238..8df3816 100644
@@ -75,6 +75,8 @@
 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS		(1 << 1)
 /* Flag that USWC attributes should be used for GTT */
 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC		(1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED		(1 << 3)
 
 struct drm_amdgpu_gem_create_in  {
 	/** the requested memory size */
Signature · 1 line
1.9.1
Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Reviewed-by
#4 lore raw
Quoted 1 line · Flora Cui

I'll push if no objection

Quoted 88 lines · Flora Cui
Quoted 79 lines

ping...

Quoted 76 lines · Flora Cui

V2: fix the return value for fill failure and validate bo before filling data

Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 33 ++++++++++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  2 ++
 2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +33 -0
index 6f0873c..59f3a75 100644
@@ -277,11 +277,44 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
    if (unlikely(r != 0)) {
            return r;
    }
+
+   if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+       bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+           struct fence *fence;
+
+           if (adev->mman.buffer_funcs_ring == NULL ||
+              !adev->mman.buffer_funcs_ring->ready) {
+                   r = -EBUSY;
+                   goto fail_free;
+           }
+
+           r = amdgpu_bo_reserve(bo, false);
+           if (unlikely(r != 0))
+                   goto fail_free;
+
+           amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);
+           r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+           if (unlikely(r != 0))
+                   goto fail_unreserve;
+
+           amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+           amdgpu_bo_fence(bo, fence, false);
+           amdgpu_bo_unreserve(bo);
+           fence_put(bo->tbo.moving);
+           bo->tbo.moving = fence_get(fence);
+           fence_put(fence);
+   }
    *bo_ptr = bo;
 
    trace_amdgpu_bo_create(bo);
 
    return 0;
+
+fail_unreserve:
+   amdgpu_bo_unreserve(bo);
+fail_free:
+   amdgpu_bo_unref(&bo);
+   return r;
 }
 
 int amdgpu_bo_create(struct amdgpu_device *adev,
include/uapi/drm/amdgpu_drm.h +2 -1
index 946f238..8df3816 100644
@@ -75,6 +75,8 @@
 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS            (1 << 1)
 /* Flag that USWC attributes should be used for GTT */
 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC             (1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED             (1 << 3)
 
 struct drm_amdgpu_gem_create_in  {
    /** the requested memory size */
--

1.9.1

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CADnq5_OsCBC5ziCvrSLWfGm3LZc6y3+R+esbD71RZ25_Ky0MPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw

Am 01.08.2016 um 15:59 schrieb Alex Deucher:

Quoted 4 lines · Flora Cui
Quoted 1 line

I'll push if no objection

Sorry for the delay, been on vacation last week.

Patch is Reviewed-by: Christian König <[email protected]> as well.

Regards,
Christian.

Quoted 90 lines
Quoted 90 lines · Flora Cui
Quoted 87 lines

ping...

Quoted 76 lines · Flora Cui

V2: fix the return value for fill failure and validate bo before filling data

Change-Id I256178afa18c1a433fe60d8656d1c5cc5d55cf2f
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 33 ++++++++++++++++++++++++++++++
  include/uapi/drm/amdgpu_drm.h              |  2 ++
  2 files changed, 35 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +33 -0
index 6f0873c..59f3a75 100644
@@ -277,11 +277,44 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
     if (unlikely(r != 0)) {
             return r;
     }
+
+   if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+       bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
+           struct fence *fence;
+
+           if (adev->mman.buffer_funcs_ring == NULL ||
+              !adev->mman.buffer_funcs_ring->ready) {
+                   r = -EBUSY;
+                   goto fail_free;
+           }
+
+           r = amdgpu_bo_reserve(bo, false);
+           if (unlikely(r != 0))
+                   goto fail_free;
+
+           amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);
+           r = ttm_bo_validate(&bo->tbo, &bo->placement, false, false);
+           if (unlikely(r != 0))
+                   goto fail_unreserve;
+
+           amdgpu_fill_buffer(bo, 0, bo->tbo.resv, &fence);
+           amdgpu_bo_fence(bo, fence, false);
+           amdgpu_bo_unreserve(bo);
+           fence_put(bo->tbo.moving);
+           bo->tbo.moving = fence_get(fence);
+           fence_put(fence);
+   }
     *bo_ptr = bo;
 
     trace_amdgpu_bo_create(bo);
 
     return 0;
+
+fail_unreserve:
+   amdgpu_bo_unreserve(bo);
+fail_free:
+   amdgpu_bo_unref(&bo);
+   return r;
  }
 
  int amdgpu_bo_create(struct amdgpu_device *adev,
include/uapi/drm/amdgpu_drm.h +2 -1
index 946f238..8df3816 100644
@@ -75,6 +75,8 @@
  #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS            (1 << 1)
  /* Flag that USWC attributes should be used for GTT */
  #define AMDGPU_GEM_CREATE_CPU_GTT_USWC             (1 << 2)
+/* Flag that the memory should be in VRAM and cleared */
+#define AMDGPU_GEM_CREATE_VRAM_CLEARED             (1 << 3)
 
  struct drm_amdgpu_gem_create_in  {
     /** the requested memory size */
--

1.9.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

Quoted 8 lines
Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx