All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations
@ 2016-07-26  8:00 Christian König
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2016-07-26  8:00 UTC (permalink / raw
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Christian König <christian.koenig@amd.com>

We often allocate, pin and map things at the same time in the kernel.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  4 ++
 2 files changed, 67 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 6f0873c..9357358 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -211,6 +211,69 @@ static void amdgpu_fill_placement_to_bo(struct amdgpu_bo *bo,
 	bo->placement.busy_placement = bo->placements;
 }
 
+/**
+ * amdgpu_bo_create_kernel - create BO for kernel use
+ *
+ * @adev: amdgpu device object
+ * @size: size for the new BO
+ * @align: alignment for the new BO
+ * @domain: where to place it
+ * @bo_ptr: resulting BO
+ * @gpu_addr: GPU addr of the pinned BO
+ * @cpu_addr: optional CPU address mapping
+ *
+ * Allocates and pins a BO for kernel internal use.
+ *
+ * Returns 0 on success, negative error code otherwise.
+ */
+int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
+			    unsigned long size, int align,
+			    u32 domain, struct amdgpu_bo **bo_ptr,
+			    u64 *gpu_addr, void **cpu_addr)
+{
+	int r;
+
+	r = amdgpu_bo_create(adev, size, align, true, domain,
+			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
+			     NULL, NULL, bo_ptr);
+	if (r) {
+		dev_err(adev->dev, "(%d) failed to allocate kernel bo\n", r);
+		return r;
+	}
+
+	r = amdgpu_bo_reserve(*bo_ptr, false);
+	if (r) {
+		dev_err(adev->dev, "(%d) failed to reserve kernel bo\n", r);
+		goto error_free;
+	}
+
+	r = amdgpu_bo_pin(*bo_ptr, domain, gpu_addr);
+	if (r) {
+		dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);
+		goto error_unreserve;
+	}
+
+	if (cpu_addr) {
+		r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);
+		if (r) {
+			dev_err(adev->dev, "(%d) kernel bo map failed\n", r);
+			goto error_unreserve;
+		}
+	}
+
+	amdgpu_bo_unreserve(*bo_ptr);
+
+	return 0;
+
+error_unreserve:
+	amdgpu_bo_unreserve(*bo_ptr);
+
+error_free:
+	amdgpu_bo_unref(bo_ptr);
+
+	return r;
+}
+
 int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 				unsigned long size, int byte_align,
 				bool kernel, u32 domain, u64 flags,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index bdb01d9..ae188a8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -139,6 +139,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 				struct ttm_placement *placement,
 			        struct reservation_object *resv,
 				struct amdgpu_bo **bo_ptr);
+int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
+			    unsigned long size, int align,
+			    u32 domain, struct amdgpu_bo **bo_ptr,
+			    u64 *gpu_addr, void **cpu_addr);
 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
 void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
 struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);
-- 
2.5.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] drm/amdgpu: pin shared GWS, GDS and OA resources
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
@ 2016-07-26  8:00   ` Christian König
  2016-07-26  8:00   ` [PATCH 3/6] drm/amdgpu: add more warning to amdgpu_bo_offset Christian König
                     ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2016-07-26  8:00 UTC (permalink / raw
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Christian König <christian.koenig@amd.com>

They can't move anyway, but just to be clean here.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 21 +++++++++------------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 21 +++++++++------------
 2 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
index 740b4be..f055d49 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c
@@ -4451,24 +4451,21 @@ static int gfx_v7_0_sw_init(void *handle)
 	}
 
 	/* reserve GDS, GWS and OA resource for gfx */
-	r = amdgpu_bo_create(adev, adev->gds.mem.gfx_partition_size,
-			PAGE_SIZE, true,
-			AMDGPU_GEM_DOMAIN_GDS, 0,
-			NULL, NULL, &adev->gds.gds_gfx_bo);
+	r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,
+				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,
+				    &adev->gds.gds_gfx_bo, NULL, NULL);
 	if (r)
 		return r;
 
-	r = amdgpu_bo_create(adev, adev->gds.gws.gfx_partition_size,
-		PAGE_SIZE, true,
-		AMDGPU_GEM_DOMAIN_GWS, 0,
-		NULL, NULL, &adev->gds.gws_gfx_bo);
+	r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,
+				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,
+				    &adev->gds.gws_gfx_bo, NULL, NULL);
 	if (r)
 		return r;
 
-	r = amdgpu_bo_create(adev, adev->gds.oa.gfx_partition_size,
-			PAGE_SIZE, true,
-			AMDGPU_GEM_DOMAIN_OA, 0,
-			NULL, NULL, &adev->gds.oa_gfx_bo);
+	r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,
+				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,
+				    &adev->gds.oa_gfx_bo, NULL, NULL);
 	if (r)
 		return r;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
index f58fc84..29c5633 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c
@@ -2075,24 +2075,21 @@ static int gfx_v8_0_sw_init(void *handle)
 	}
 
 	/* reserve GDS, GWS and OA resource for gfx */
-	r = amdgpu_bo_create(adev, adev->gds.mem.gfx_partition_size,
-			PAGE_SIZE, true,
-			AMDGPU_GEM_DOMAIN_GDS, 0, NULL,
-			NULL, &adev->gds.gds_gfx_bo);
+	r = amdgpu_bo_create_kernel(adev, adev->gds.mem.gfx_partition_size,
+				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GDS,
+				    &adev->gds.gds_gfx_bo, NULL, NULL);
 	if (r)
 		return r;
 
-	r = amdgpu_bo_create(adev, adev->gds.gws.gfx_partition_size,
-		PAGE_SIZE, true,
-		AMDGPU_GEM_DOMAIN_GWS, 0, NULL,
-		NULL, &adev->gds.gws_gfx_bo);
+	r = amdgpu_bo_create_kernel(adev, adev->gds.gws.gfx_partition_size,
+				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GWS,
+				    &adev->gds.gws_gfx_bo, NULL, NULL);
 	if (r)
 		return r;
 
-	r = amdgpu_bo_create(adev, adev->gds.oa.gfx_partition_size,
-			PAGE_SIZE, true,
-			AMDGPU_GEM_DOMAIN_OA, 0, NULL,
-			NULL, &adev->gds.oa_gfx_bo);
+	r = amdgpu_bo_create_kernel(adev, adev->gds.oa.gfx_partition_size,
+				    PAGE_SIZE, AMDGPU_GEM_DOMAIN_OA,
+				    &adev->gds.oa_gfx_bo, NULL, NULL);
 	if (r)
 		return r;
 
-- 
2.5.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] drm/amdgpu: add more warning to amdgpu_bo_offset
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
  2016-07-26  8:00   ` [PATCH 2/6] drm/amdgpu: pin shared GWS, GDS and OA resources Christian König
@ 2016-07-26  8:00   ` Christian König
  2016-07-26  8:00   ` [PATCH 4/6] drm/amdgpu: user amdgpu_bo_create_kernel for the UVD BO Christian König
                     ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2016-07-26  8:00 UTC (permalink / raw
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Christian König <christian.koenig@amd.com>

Warn when we try to get the address and the BO isn't locked or reserved.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 16 +---------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 9357358..67de19c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -737,3 +737,21 @@ void amdgpu_bo_fence(struct amdgpu_bo *bo, struct fence *fence,
 	else
 		reservation_object_add_excl_fence(resv, fence);
 }
+
+/**
+ * amdgpu_bo_gpu_offset - return GPU offset of bo
+ * @bo:	amdgpu object for which we query the offset
+ *
+ * Returns current GPU offset of the object.
+ *
+ * Note: object should either be pinned or reserved when calling this
+ * function, it might be useful to add check for this for debugging.
+ */
+u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
+{
+	WARN_ON_ONCE(bo->tbo.mem.mem_type == TTM_PL_SYSTEM);
+	WARN_ON_ONCE(!ww_mutex_is_locked(&bo->tbo.resv->lock) &&
+		     !bo->pin_count);
+
+	return bo->tbo.offset;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index ae188a8..d650b42 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -85,21 +85,6 @@ static inline void amdgpu_bo_unreserve(struct amdgpu_bo *bo)
 	ttm_bo_unreserve(&bo->tbo);
 }
 
-/**
- * amdgpu_bo_gpu_offset - return GPU offset of bo
- * @bo:	amdgpu object for which we query the offset
- *
- * Returns current GPU offset of the object.
- *
- * Note: object should either be pinned or reserved when calling this
- * function, it might be useful to add check for this for debugging.
- */
-static inline u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
-{
-	WARN_ON_ONCE(bo->tbo.mem.mem_type == TTM_PL_SYSTEM);
-	return bo->tbo.offset;
-}
-
 static inline unsigned long amdgpu_bo_size(struct amdgpu_bo *bo)
 {
 	return bo->tbo.num_pages << PAGE_SHIFT;
@@ -169,6 +154,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,
 int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo);
 void amdgpu_bo_fence(struct amdgpu_bo *bo, struct fence *fence,
 		     bool shared);
+u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo);
 
 /*
  * sub allocation
-- 
2.5.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] drm/amdgpu: user amdgpu_bo_create_kernel for the UVD BO
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
  2016-07-26  8:00   ` [PATCH 2/6] drm/amdgpu: pin shared GWS, GDS and OA resources Christian König
  2016-07-26  8:00   ` [PATCH 3/6] drm/amdgpu: add more warning to amdgpu_bo_offset Christian König
@ 2016-07-26  8:00   ` Christian König
  2016-07-26  8:00   ` [PATCH 5/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ih.c Christian König
                     ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2016-07-26  8:00 UTC (permalink / raw
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Christian König <christian.koenig@amd.com>

Saves us some code.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 31 +++----------------------------
 1 file changed, 3 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
index c371249..b39238a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c
@@ -194,39 +194,14 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)
 	bo_size = AMDGPU_GPU_PAGE_ALIGN(le32_to_cpu(hdr->ucode_size_bytes) + 8)
 		  +  AMDGPU_UVD_STACK_SIZE + AMDGPU_UVD_HEAP_SIZE
 		  +  AMDGPU_UVD_SESSION_SIZE * adev->uvd.max_handles;
-	r = amdgpu_bo_create(adev, bo_size, PAGE_SIZE, true,
-			     AMDGPU_GEM_DOMAIN_VRAM,
-			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
-			     NULL, NULL, &adev->uvd.vcpu_bo);
+	r = amdgpu_bo_create_kernel(adev, bo_size, PAGE_SIZE,
+				    AMDGPU_GEM_DOMAIN_VRAM, &adev->uvd.vcpu_bo,
+				    &adev->uvd.gpu_addr, &adev->uvd.cpu_addr);
 	if (r) {
 		dev_err(adev->dev, "(%d) failed to allocate UVD bo\n", r);
 		return r;
 	}
 
-	r = amdgpu_bo_reserve(adev->uvd.vcpu_bo, false);
-	if (r) {
-		amdgpu_bo_unref(&adev->uvd.vcpu_bo);
-		dev_err(adev->dev, "(%d) failed to reserve UVD bo\n", r);
-		return r;
-	}
-
-	r = amdgpu_bo_pin(adev->uvd.vcpu_bo, AMDGPU_GEM_DOMAIN_VRAM,
-			  &adev->uvd.gpu_addr);
-	if (r) {
-		amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
-		amdgpu_bo_unref(&adev->uvd.vcpu_bo);
-		dev_err(adev->dev, "(%d) UVD bo pin failed\n", r);
-		return r;
-	}
-
-	r = amdgpu_bo_kmap(adev->uvd.vcpu_bo, &adev->uvd.cpu_addr);
-	if (r) {
-		dev_err(adev->dev, "(%d) UVD map failed\n", r);
-		return r;
-	}
-
-	amdgpu_bo_unreserve(adev->uvd.vcpu_bo);
-
 	ring = &adev->uvd.ring;
 	rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL];
 	r = amd_sched_entity_init(&ring->sched, &adev->uvd.entity,
-- 
2.5.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ih.c
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
                     ` (2 preceding siblings ...)
  2016-07-26  8:00   ` [PATCH 4/6] drm/amdgpu: user amdgpu_bo_create_kernel for the UVD BO Christian König
@ 2016-07-26  8:00   ` Christian König
  2016-07-26  8:00   ` [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c Christian König
                     ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: Christian König @ 2016-07-26  8:00 UTC (permalink / raw
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Christian König <christian.koenig@amd.com>

Saves us quite a bunch of code.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
index 534fc04..5ebb3f4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ih.c
@@ -40,32 +40,15 @@ static int amdgpu_ih_ring_alloc(struct amdgpu_device *adev)
 
 	/* Allocate ring buffer */
 	if (adev->irq.ih.ring_obj == NULL) {
-		r = amdgpu_bo_create(adev, adev->irq.ih.ring_size,
-				     PAGE_SIZE, true,
-				     AMDGPU_GEM_DOMAIN_GTT, 0,
-				     NULL, NULL, &adev->irq.ih.ring_obj);
+		r = amdgpu_bo_create_kernel(adev, adev->irq.ih.ring_size,
+					    PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
+					    &adev->irq.ih.ring_obj,
+					    &adev->irq.ih.gpu_addr,
+					    (void **)&adev->irq.ih.ring);
 		if (r) {
 			DRM_ERROR("amdgpu: failed to create ih ring buffer (%d).\n", r);
 			return r;
 		}
-		r = amdgpu_bo_reserve(adev->irq.ih.ring_obj, false);
-		if (unlikely(r != 0))
-			return r;
-		r = amdgpu_bo_pin(adev->irq.ih.ring_obj,
-				  AMDGPU_GEM_DOMAIN_GTT,
-				  &adev->irq.ih.gpu_addr);
-		if (r) {
-			amdgpu_bo_unreserve(adev->irq.ih.ring_obj);
-			DRM_ERROR("amdgpu: failed to pin ih ring buffer (%d).\n", r);
-			return r;
-		}
-		r = amdgpu_bo_kmap(adev->irq.ih.ring_obj,
-				   (void **)&adev->irq.ih.ring);
-		amdgpu_bo_unreserve(adev->irq.ih.ring_obj);
-		if (r) {
-			DRM_ERROR("amdgpu: failed to map ih ring buffer (%d).\n", r);
-			return r;
-		}
 	}
 	return 0;
 }
-- 
2.5.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
                     ` (3 preceding siblings ...)
  2016-07-26  8:00   ` [PATCH 5/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ih.c Christian König
@ 2016-07-26  8:00   ` Christian König
       [not found]     ` <1469520017-8422-6-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
  2016-07-26  8:11   ` [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations zhoucm1
  2016-07-26 23:54   ` Edward O'Callaghan
  6 siblings, 1 reply; 9+ messages in thread
From: Christian König @ 2016-07-26  8:00 UTC (permalink / raw
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Christian König <christian.koenig@amd.com>

Saves us quite a bunch of code.

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
index 85aeb0a..242ba04 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
@@ -222,33 +222,16 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 
 	/* Allocate ring buffer */
 	if (ring->ring_obj == NULL) {
-		r = amdgpu_bo_create(adev, ring->ring_size, PAGE_SIZE, true,
-				     AMDGPU_GEM_DOMAIN_GTT, 0,
-				     NULL, NULL, &ring->ring_obj);
+		r = amdgpu_bo_create_kernel(adev, ring->ring_size, PAGE_SIZE,
+					    AMDGPU_GEM_DOMAIN_GTT,
+					    &ring->ring_obj,
+					    &ring->gpu_addr,
+					    (void **)&ring->ring);
 		if (r) {
 			dev_err(adev->dev, "(%d) ring create failed\n", r);
 			return r;
 		}
-		r = amdgpu_bo_reserve(ring->ring_obj, false);
-		if (unlikely(r != 0))
-			return r;
-		r = amdgpu_bo_pin(ring->ring_obj, AMDGPU_GEM_DOMAIN_GTT,
-					&ring->gpu_addr);
-		if (r) {
-			amdgpu_bo_unreserve(ring->ring_obj);
-			dev_err(adev->dev, "(%d) ring pin failed\n", r);
-			return r;
-		}
-		r = amdgpu_bo_kmap(ring->ring_obj,
-				       (void **)&ring->ring);
-
 		memset((void *)ring->ring, 0, ring->ring_size);
-
-		amdgpu_bo_unreserve(ring->ring_obj);
-		if (r) {
-			dev_err(adev->dev, "(%d) ring map failed\n", r);
-			return r;
-		}
 	}
 	ring->ptr_mask = (ring->ring_size / 4) - 1;
 	ring->max_dw = max_dw;
-- 
2.5.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
                     ` (4 preceding siblings ...)
  2016-07-26  8:00   ` [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c Christian König
@ 2016-07-26  8:11   ` zhoucm1
  2016-07-26 23:54   ` Edward O'Callaghan
  6 siblings, 0 replies; 9+ messages in thread
From: zhoucm1 @ 2016-07-26  8:11 UTC (permalink / raw
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

the set looks good to me, Reviewed-by: Chunming Zhou <david1.zhou@amd.com>

On 2016年07月26日 16:00, Christian König wrote:
> From: Christian König <christian.koenig@amd.com>
>
> We often allocate, pin and map things at the same time in the kernel.
>
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  4 ++
>   2 files changed, 67 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 6f0873c..9357358 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -211,6 +211,69 @@ static void amdgpu_fill_placement_to_bo(struct amdgpu_bo *bo,
>   	bo->placement.busy_placement = bo->placements;
>   }
>   
> +/**
> + * amdgpu_bo_create_kernel - create BO for kernel use
> + *
> + * @adev: amdgpu device object
> + * @size: size for the new BO
> + * @align: alignment for the new BO
> + * @domain: where to place it
> + * @bo_ptr: resulting BO
> + * @gpu_addr: GPU addr of the pinned BO
> + * @cpu_addr: optional CPU address mapping
> + *
> + * Allocates and pins a BO for kernel internal use.
> + *
> + * Returns 0 on success, negative error code otherwise.
> + */
> +int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
> +			    unsigned long size, int align,
> +			    u32 domain, struct amdgpu_bo **bo_ptr,
> +			    u64 *gpu_addr, void **cpu_addr)
> +{
> +	int r;
> +
> +	r = amdgpu_bo_create(adev, size, align, true, domain,
> +			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
> +			     NULL, NULL, bo_ptr);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) failed to allocate kernel bo\n", r);
> +		return r;
> +	}
> +
> +	r = amdgpu_bo_reserve(*bo_ptr, false);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) failed to reserve kernel bo\n", r);
> +		goto error_free;
> +	}
> +
> +	r = amdgpu_bo_pin(*bo_ptr, domain, gpu_addr);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);
> +		goto error_unreserve;
> +	}
> +
> +	if (cpu_addr) {
> +		r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);
> +		if (r) {
> +			dev_err(adev->dev, "(%d) kernel bo map failed\n", r);
> +			goto error_unreserve;
> +		}
> +	}
> +
> +	amdgpu_bo_unreserve(*bo_ptr);
> +
> +	return 0;
> +
> +error_unreserve:
> +	amdgpu_bo_unreserve(*bo_ptr);
> +
> +error_free:
> +	amdgpu_bo_unref(bo_ptr);
> +
> +	return r;
> +}
> +
>   int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
>   				unsigned long size, int byte_align,
>   				bool kernel, u32 domain, u64 flags,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index bdb01d9..ae188a8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -139,6 +139,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
>   				struct ttm_placement *placement,
>   			        struct reservation_object *resv,
>   				struct amdgpu_bo **bo_ptr);
> +int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
> +			    unsigned long size, int align,
> +			    u32 domain, struct amdgpu_bo **bo_ptr,
> +			    u64 *gpu_addr, void **cpu_addr);
>   int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
>   void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
>   struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations
       [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
                     ` (5 preceding siblings ...)
  2016-07-26  8:11   ` [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations zhoucm1
@ 2016-07-26 23:54   ` Edward O'Callaghan
  6 siblings, 0 replies; 9+ messages in thread
From: Edward O'Callaghan @ 2016-07-26 23:54 UTC (permalink / raw
  To: Christian König, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1.1: Type: text/plain, Size: 3600 bytes --]

This series is,

Reviewed-by: Edward O'Callaghan <funfunctor-dczkZgxz+BNUPWh3PAxdjQ@public.gmane.org>

On 07/26/2016 06:00 PM, Christian König wrote:
> From: Christian König <christian.koenig-5C7GfCeVMHo@public.gmane.org>
> 
> We often allocate, pin and map things at the same time in the kernel.
> 
> Signed-off-by: Christian König <christian.koenig-5C7GfCeVMHo@public.gmane.org>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 63 ++++++++++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  4 ++
>  2 files changed, 67 insertions(+)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index 6f0873c..9357358 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -211,6 +211,69 @@ static void amdgpu_fill_placement_to_bo(struct amdgpu_bo *bo,
>  	bo->placement.busy_placement = bo->placements;
>  }
>  
> +/**
> + * amdgpu_bo_create_kernel - create BO for kernel use
> + *
> + * @adev: amdgpu device object
> + * @size: size for the new BO
> + * @align: alignment for the new BO
> + * @domain: where to place it
> + * @bo_ptr: resulting BO
> + * @gpu_addr: GPU addr of the pinned BO
> + * @cpu_addr: optional CPU address mapping
> + *
> + * Allocates and pins a BO for kernel internal use.
> + *
> + * Returns 0 on success, negative error code otherwise.
> + */
> +int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
> +			    unsigned long size, int align,
> +			    u32 domain, struct amdgpu_bo **bo_ptr,
> +			    u64 *gpu_addr, void **cpu_addr)
> +{
> +	int r;
> +
> +	r = amdgpu_bo_create(adev, size, align, true, domain,
> +			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
> +			     NULL, NULL, bo_ptr);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) failed to allocate kernel bo\n", r);
> +		return r;
> +	}
> +
> +	r = amdgpu_bo_reserve(*bo_ptr, false);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) failed to reserve kernel bo\n", r);
> +		goto error_free;
> +	}
> +
> +	r = amdgpu_bo_pin(*bo_ptr, domain, gpu_addr);
> +	if (r) {
> +		dev_err(adev->dev, "(%d) kernel bo pin failed\n", r);
> +		goto error_unreserve;
> +	}
> +
> +	if (cpu_addr) {
> +		r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);
> +		if (r) {
> +			dev_err(adev->dev, "(%d) kernel bo map failed\n", r);
> +			goto error_unreserve;
> +		}
> +	}
> +
> +	amdgpu_bo_unreserve(*bo_ptr);
> +
> +	return 0;
> +
> +error_unreserve:
> +	amdgpu_bo_unreserve(*bo_ptr);
> +
> +error_free:
> +	amdgpu_bo_unref(bo_ptr);
> +
> +	return r;
> +}
> +
>  int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
>  				unsigned long size, int byte_align,
>  				bool kernel, u32 domain, u64 flags,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index bdb01d9..ae188a8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -139,6 +139,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
>  				struct ttm_placement *placement,
>  			        struct reservation_object *resv,
>  				struct amdgpu_bo **bo_ptr);
> +int amdgpu_bo_create_kernel(struct amdgpu_device *adev,
> +			    unsigned long size, int align,
> +			    u32 domain, struct amdgpu_bo **bo_ptr,
> +			    u64 *gpu_addr, void **cpu_addr);
>  int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);
>  void amdgpu_bo_kunmap(struct amdgpu_bo *bo);
>  struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);
> 


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

[-- Attachment #2: Type: text/plain, Size: 154 bytes --]

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c
       [not found]     ` <1469520017-8422-6-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
@ 2016-07-28  3:56       ` Deucher, Alexander
  0 siblings, 0 replies; 9+ messages in thread
From: Deucher, Alexander @ 2016-07-28  3:56 UTC (permalink / raw
  To: 'Christian König',
	amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org

> -----Original Message-----
> From: amd-gfx [mailto:amd-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Christian König
> Sent: Tuesday, July 26, 2016 4:00 AM
> To: amd-gfx@lists.freedesktop.org
> Subject: [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in
> amdgpu_ring.c
> 
> From: Christian König <christian.koenig@amd.com>
> 
> Saves us quite a bunch of code.
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>

For the series:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 27 +++++---------------------
> -
>  1 file changed, 5 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> index 85aeb0a..242ba04 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
> @@ -222,33 +222,16 @@ int amdgpu_ring_init(struct amdgpu_device *adev,
> struct amdgpu_ring *ring,
> 
>  	/* Allocate ring buffer */
>  	if (ring->ring_obj == NULL) {
> -		r = amdgpu_bo_create(adev, ring->ring_size, PAGE_SIZE,
> true,
> -				     AMDGPU_GEM_DOMAIN_GTT, 0,
> -				     NULL, NULL, &ring->ring_obj);
> +		r = amdgpu_bo_create_kernel(adev, ring->ring_size,
> PAGE_SIZE,
> +					    AMDGPU_GEM_DOMAIN_GTT,
> +					    &ring->ring_obj,
> +					    &ring->gpu_addr,
> +					    (void **)&ring->ring);
>  		if (r) {
>  			dev_err(adev->dev, "(%d) ring create failed\n", r);
>  			return r;
>  		}
> -		r = amdgpu_bo_reserve(ring->ring_obj, false);
> -		if (unlikely(r != 0))
> -			return r;
> -		r = amdgpu_bo_pin(ring->ring_obj,
> AMDGPU_GEM_DOMAIN_GTT,
> -					&ring->gpu_addr);
> -		if (r) {
> -			amdgpu_bo_unreserve(ring->ring_obj);
> -			dev_err(adev->dev, "(%d) ring pin failed\n", r);
> -			return r;
> -		}
> -		r = amdgpu_bo_kmap(ring->ring_obj,
> -				       (void **)&ring->ring);
> -
>  		memset((void *)ring->ring, 0, ring->ring_size);
> -
> -		amdgpu_bo_unreserve(ring->ring_obj);
> -		if (r) {
> -			dev_err(adev->dev, "(%d) ring map failed\n", r);
> -			return r;
> -		}
>  	}
>  	ring->ptr_mask = (ring->ring_size / 4) - 1;
>  	ring->max_dw = max_dw;
> --
> 2.5.0
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-07-28  3:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-26  8:00 [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations Christian König
     [not found] ` <1469520017-8422-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-07-26  8:00   ` [PATCH 2/6] drm/amdgpu: pin shared GWS, GDS and OA resources Christian König
2016-07-26  8:00   ` [PATCH 3/6] drm/amdgpu: add more warning to amdgpu_bo_offset Christian König
2016-07-26  8:00   ` [PATCH 4/6] drm/amdgpu: user amdgpu_bo_create_kernel for the UVD BO Christian König
2016-07-26  8:00   ` [PATCH 5/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ih.c Christian König
2016-07-26  8:00   ` [PATCH 6/6] drm/amdgpu: use amdgpu_bo_create_kernel in amdgpu_ring.c Christian König
     [not found]     ` <1469520017-8422-6-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2016-07-28  3:56       ` Deucher, Alexander
2016-07-26  8:11   ` [PATCH 1/6] drm/amdgpu: add new helper for in kernel allocations zhoucm1
2016-07-26 23:54   ` Edward O'Callaghan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.