Skip to contentSkip to conversation

drm/amdgpu: add amdgpu_bo_param

PATCH In review Chunming Zhou 4 participants 7 messages Apr 16, 2018 – Apr 17, 2018 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu: add amdgpu_bo_param

Change-Id Ib2aa98ee37a70f3cb0d61eef1d336e89187554d5
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 81 +++++++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  9 ++++
 2 files changed, 54 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +45 -36
index a160ef0332d6..b557b63bb648 100644
@@ -341,28 +341,26 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 	return false;
 }
 
-static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
-			       int byte_align, u32 domain,
-			       u64 flags, enum ttm_bo_type type,
-			       struct reservation_object *resv,
+static int amdgpu_bo_do_create(struct amdgpu_device *adev,
+			       struct amdgpu_bo_param *bp,
 			       struct amdgpu_bo **bo_ptr)
 {
 	struct ttm_operation_ctx ctx = {
-		.interruptible = (type != ttm_bo_type_kernel),
+		.interruptible = (bp->type != ttm_bo_type_kernel),
 		.no_wait_gpu = false,
-		.resv = resv,
+		.resv = bp->resv,
 		.flags = TTM_OPT_FLAG_ALLOW_RES_EVICT
 	};
 	struct amdgpu_bo *bo;
-	unsigned long page_align;
+	unsigned long page_align, size = bp->size;
 	size_t acc_size;
 	u32 domains, preferred_domains, allowed_domains;
 	int r;
 
-	page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	page_align = roundup(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;
 	size = ALIGN(size, PAGE_SIZE);
 
-	if (!amdgpu_bo_validate_size(adev, size, domain))
+	if (!amdgpu_bo_validate_size(adev, size, bp->domain))
 		return -ENOMEM;
 
 	*bo_ptr = NULL;
@@ -370,14 +368,14 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 	acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
 				       sizeof(struct amdgpu_bo));
 
-	preferred_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM |
-				      AMDGPU_GEM_DOMAIN_GTT |
-				      AMDGPU_GEM_DOMAIN_CPU |
-				      AMDGPU_GEM_DOMAIN_GDS |
-				      AMDGPU_GEM_DOMAIN_GWS |
-				      AMDGPU_GEM_DOMAIN_OA);
+	preferred_domains = bp->domain & (AMDGPU_GEM_DOMAIN_VRAM |
+					  AMDGPU_GEM_DOMAIN_GTT |
+					  AMDGPU_GEM_DOMAIN_CPU |
+					  AMDGPU_GEM_DOMAIN_GDS |
+					  AMDGPU_GEM_DOMAIN_GWS |
+					  AMDGPU_GEM_DOMAIN_OA);
 	allowed_domains = preferred_domains;
-	if (type != ttm_bo_type_kernel &&
+	if (bp->type != ttm_bo_type_kernel &&
 	    allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
 		allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
 	domains = preferred_domains;
@@ -391,7 +389,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 	bo->preferred_domains = preferred_domains;
 	bo->allowed_domains = allowed_domains;
 
-	bo->flags = flags;
+	bo->flags = bp->flags;
 
 #ifdef CONFIG_X86_32
 	/* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
@@ -423,13 +421,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 
 	bo->tbo.bdev = &adev->mman.bdev;
 	amdgpu_ttm_placement_from_domain(bo, domains);
-	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
+	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
 				 &bo->placement, page_align, &ctx, acc_size,
-				 NULL, resv, &amdgpu_ttm_bo_destroy);
-	if (unlikely(r && r != -ERESTARTSYS) && type == ttm_bo_type_device &&
-	    !(flags & AMDGPU_GEM_CREATE_NO_FALLBACK)) {
-		if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
-			flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+				 NULL, bp->resv, &amdgpu_ttm_bo_destroy);
+	if (unlikely(r && r != -ERESTARTSYS) && bp->type == ttm_bo_type_device &&
+	    !(bp->flags & AMDGPU_GEM_CREATE_NO_FALLBACK)) {
+		if (bp->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+			bp->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 			goto retry;
 		} else if (domains != allowed_domains) {
 			domains = allowed_domains;
@@ -447,10 +445,10 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 	else
 		amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
 
-	if (type == ttm_bo_type_kernel)
+	if (bp->type == ttm_bo_type_kernel)
 		bo->tbo.priority = 1;
 
-	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
 	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
 		struct dma_fence *fence;
 
@@ -463,20 +461,20 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 		bo->tbo.moving = dma_fence_get(fence);
 		dma_fence_put(fence);
 	}
-	if (!resv)
+	if (!bp->resv)
 		amdgpu_bo_unreserve(bo);
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
 
 	/* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
-	if (type == ttm_bo_type_device)
+	if (bp->type == ttm_bo_type_device)
 		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 
 	return 0;
 
 fail_unreserve:
-	if (!resv)
+	if (!bp->resv)
 		ww_mutex_unlock(&bo->tbo.resv->lock);
 	amdgpu_bo_unref(&bo);
 	return r;
@@ -486,16 +484,21 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 				   unsigned long size, int byte_align,
 				   struct amdgpu_bo *bo)
 {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = byte_align,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC |
+			AMDGPU_GEM_CREATE_SHADOW,
+		.type = ttm_bo_type_kernel,
+		.resv = bo->tbo.resv
+	};
 	int r;
 
 	if (bo->shadow)
 		return 0;
 
-	r = amdgpu_bo_do_create(adev, size, byte_align, AMDGPU_GEM_DOMAIN_GTT,
-				AMDGPU_GEM_CREATE_CPU_GTT_USWC |
-				AMDGPU_GEM_CREATE_SHADOW,
-				ttm_bo_type_kernel,
-				bo->tbo.resv, &bo->shadow);
+	r = amdgpu_bo_do_create(adev, &bp, &bo->shadow);
 	if (!r) {
 		bo->shadow->parent = amdgpu_bo_ref(bo);
 		mutex_lock(&adev->shadow_list_lock);
@@ -512,11 +515,17 @@ int amdgpu_bo_create(struct amdgpu_device *adev, unsigned long size,
 		     struct reservation_object *resv,
 		     struct amdgpu_bo **bo_ptr)
 {
-	uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = byte_align,
+		.domain = domain,
+		.flags = flags & ~AMDGPU_GEM_CREATE_SHADOW,
+		.type = type,
+		.resv = resv
+	};
 	int r;
 
-	r = amdgpu_bo_do_create(adev, size, byte_align, domain,
-				parent_flags, type, resv, bo_ptr);
+	r = amdgpu_bo_do_create(adev, &bp, bo_ptr);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +9 -0
index 1e9fe85abcbb..4bb6f0a8d799 100644
@@ -33,6 +33,15 @@
 
 #define AMDGPU_BO_INVALID_OFFSET	LONG_MAX
 
+struct amdgpu_bo_param {
+	unsigned long			size;
+	int				byte_align;
+	u32				domain;
+	u64				flags;
+	enum ttm_bo_type		type;
+	struct reservation_object	*resv;
+};
+
 /* bo virtual addresses in a vm */
 struct amdgpu_bo_va_mapping {
 	struct amdgpu_bo_va		*bo_va;
Signature · 6 lines
2.14.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): [email protected]

#2 lore raw

PATCH 2/2 drm/amdgpu: use amdgpu_bo_parm for amdgpu_bo_create

after that, we can easily add new parameter when need.

Change-Id I6e80039c3801f163129ecc605d931483fdbc91db
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c       | 12 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c    | 15 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c         | 16 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 11 +++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c       | 38 +++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h       |  6 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c        | 12 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_test.c         | 16 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c          | 15 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           | 24 ++++++++++-----
 11 files changed, 114 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -3
index 4d36203ffb11..f90405e572f9 100644
@@ -217,13 +217,19 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
 	struct amdgpu_bo *bo = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	int r;
 	uint64_t gpu_addr_tmp = 0;
 	void *cpu_ptr_tmp = NULL;
 
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
-			     AMDGPU_GEM_CREATE_CPU_GTT_USWC, ttm_bo_type_kernel,
-			     NULL, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
 	if (r) {
 		dev_err(adev->dev,
 			"failed to allocate BO for amdkfd (%d)\n", r);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -2
index 1d6e1479da38..b7bd24c35b25 100644
@@ -1004,6 +1004,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 	struct amdgpu_device *adev = get_amdgpu_device(kgd);
 	struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp;
 	int byte_align;
 	u32 alloc_domain;
 	u64 alloc_flags;
@@ -1069,8 +1070,13 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 	pr_debug("\tcreate BO VA 0x%llx size 0x%llx domain %s\n",
 			va, size, domain_string(alloc_domain));
 
-	ret = amdgpu_bo_create(adev, size, byte_align,
-				alloc_domain, alloc_flags, ttm_bo_type_device, NULL, &bo);
+	bp.size = size;
+	bp.byte_align = byte_align;
+	bp.domain = alloc_domain;
+	bp.flags = alloc_flags;
+	bp.type = ttm_bo_type_device;
+	bp.resv = NULL;
+	ret = amdgpu_bo_create(adev, &bp, &bo);
 	if (ret) {
 		pr_debug("Failed to create BO on domain %s. ret %d\n",
 				domain_string(alloc_domain), ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +11 -4
index 02b849be083b..96bdb454bdf6 100644
@@ -75,13 +75,20 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
 {
 	struct amdgpu_bo *dobj = NULL;
 	struct amdgpu_bo *sobj = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = sdomain,
+		.flags = 0,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	uint64_t saddr, daddr;
 	int r, n;
 	int time;
 
 	n = AMDGPU_BENCHMARK_ITERATIONS;
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE,sdomain, 0,
-			     ttm_bo_type_kernel, NULL, &sobj);
+	r = amdgpu_bo_create(adev, &bp, &sobj);
 	if (r) {
 		goto out_cleanup;
 	}
@@ -93,8 +100,8 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
 	if (r) {
 		goto out_cleanup;
 	}
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, ddomain, 0,
-			     ttm_bo_type_kernel, NULL, &dobj);
+	bp.domain = ddomain;
+	r = amdgpu_bo_create(adev, &bp, &dobj);
 	if (r) {
 		goto out_cleanup;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +10 -6
index cf0f186c6092..1f9b8ae7ad2b 100644
@@ -110,15 +110,19 @@ static void amdgpu_gart_dummy_page_fini(struct amdgpu_device *adev)
  */
 int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
 {
+	struct amdgpu_bo_param bp = {
+		.size = adev->gart.table_size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_VRAM,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	int r;
 
 	if (adev->gart.robj == NULL) {
-		r = amdgpu_bo_create(adev, adev->gart.table_size, PAGE_SIZE,
-				     AMDGPU_GEM_DOMAIN_VRAM,
-				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     ttm_bo_type_kernel, NULL,
-				     &adev->gart.robj);
+		r = amdgpu_bo_create(adev, &bp, &adev->gart.robj);
 		if (r) {
 			return r;
 		}
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +9 -2
index 28c2706e48d7..e8f947d3da53 100644
@@ -48,6 +48,14 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 			     struct drm_gem_object **obj)
 {
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = alignment,
+		.domain = initial_domain,
+		.flags = flags,
+		.type = type,
+		.resv = resv
+	};
 	int r;
 
 	*obj = NULL;
@@ -56,8 +64,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 		alignment = PAGE_SIZE;
 	}
 
-	r = amdgpu_bo_create(adev, size, alignment, initial_domain,
-			     flags, type, resv, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
 	if (r) {
 		DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
 			  size, initial_domain, alignment, r);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +18 -20
index b557b63bb648..a7a73ea18704 100644
@@ -191,14 +191,20 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
 			      u32 domain, struct amdgpu_bo **bo_ptr,
 			      u64 *gpu_addr, void **cpu_addr)
 {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = align,
+		.domain = domain,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	bool free = false;
 	int r;
 
 	if (!*bo_ptr) {
-		r = amdgpu_bo_create(adev, size, align, domain,
-				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     ttm_bo_type_kernel, NULL, bo_ptr);
+		r = amdgpu_bo_create(adev, &bp, bo_ptr);
 		if (r) {
 			dev_err(adev->dev, "(%d) failed to allocate kernel bo\n",
 				r);
@@ -509,34 +515,26 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 	return r;
 }
 
-int amdgpu_bo_create(struct amdgpu_device *adev, unsigned long size,
-		     int byte_align, u32 domain,
-		     u64 flags, enum ttm_bo_type type,
-		     struct reservation_object *resv,
+int amdgpu_bo_create(struct amdgpu_device *adev,
+		     struct amdgpu_bo_param *bp,
 		     struct amdgpu_bo **bo_ptr)
 {
-	struct amdgpu_bo_param bp = {
-		.size = size,
-		.byte_align = byte_align,
-		.domain = domain,
-		.flags = flags & ~AMDGPU_GEM_CREATE_SHADOW,
-		.type = type,
-		.resv = resv
-	};
+	u64 flags = bp->flags;
 	int r;
 
-	r = amdgpu_bo_do_create(adev, &bp, bo_ptr);
+	bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
+	r = amdgpu_bo_do_create(adev, bp, bo_ptr);
 	if (r)
 		return r;
 
 	if ((flags & AMDGPU_GEM_CREATE_SHADOW) && amdgpu_need_backup(adev)) {
-		if (!resv)
+		if (!bp->resv)
 			WARN_ON(reservation_object_lock((*bo_ptr)->tbo.resv,
 							NULL));
 
-		r = amdgpu_bo_create_shadow(adev, size, byte_align, (*bo_ptr));
+		r = amdgpu_bo_create_shadow(adev, bp->size, bp->byte_align, (*bo_ptr));
 
-		if (!resv)
+		if (!bp->resv)
 			reservation_object_unlock((*bo_ptr)->tbo.resv);
 
 		if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -4
index 4bb6f0a8d799..e9a21d991e77 100644
@@ -233,10 +233,8 @@ static inline bool amdgpu_bo_explicit_sync(struct amdgpu_bo *bo)
 	return bo->flags & AMDGPU_GEM_CREATE_EXPLICIT_SYNC;
 }
 
-int amdgpu_bo_create(struct amdgpu_device *adev, unsigned long size,
-		     int byte_align, u32 domain,
-		     u64 flags, enum ttm_bo_type type,
-		     struct reservation_object *resv,
+int amdgpu_bo_create(struct amdgpu_device *adev,
+		     struct amdgpu_bo_param *bp,
 		     struct amdgpu_bo **bo_ptr);
 int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
 			      unsigned long size, int align,
drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +9 -3
index 4b584cb75bf4..e0f1f2512780 100644
@@ -102,12 +102,18 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
 	struct reservation_object *resv = attach->dmabuf->resv;
 	struct amdgpu_device *adev = dev->dev_private;
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp = {
+		.size = attach->dmabuf->size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_CPU,
+		.flags = 0,
+		.type = ttm_bo_type_sg,
+		.resv = resv
+	};
 	int ret;
 
 	ww_mutex_lock(&resv->lock, NULL);
-	ret = amdgpu_bo_create(adev, attach->dmabuf->size, PAGE_SIZE,
-			       AMDGPU_GEM_DOMAIN_CPU, 0, ttm_bo_type_sg,
-			       resv, &bo);
+	ret = amdgpu_bo_create(adev, &bp, &bo);
 	if (ret)
 		goto error;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_test.c +11 -5
index 2dbe87591f81..57f27f096a9e 100644
@@ -33,6 +33,13 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
 	struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
 	struct amdgpu_bo *vram_obj = NULL;
 	struct amdgpu_bo **gtt_obj = NULL;
+	struct amdgpu_bo_param bp = {
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_VRAM,
+		.flags = 0,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	uint64_t gart_addr, vram_addr;
 	unsigned n, size;
 	int i, r;
@@ -58,9 +65,9 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
 		r = 1;
 		goto out_cleanup;
 	}
+	bp.size = size;
 
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM, 0,
-			     ttm_bo_type_kernel, NULL, &vram_obj);
+	r = amdgpu_bo_create(adev, &bp, &vram_obj);
 	if (r) {
 		DRM_ERROR("Failed to create VRAM object\n");
 		goto out_cleanup;
@@ -79,9 +86,8 @@ static void amdgpu_do_test_moves(struct amdgpu_device *adev)
 		void **vram_start, **vram_end;
 		struct dma_fence *fence = NULL;
 
-		r = amdgpu_bo_create(adev, size, PAGE_SIZE,
-				     AMDGPU_GEM_DOMAIN_GTT, 0,
-				     ttm_bo_type_kernel, NULL, gtt_obj + i);
+		bp.domain = AMDGPU_GEM_DOMAIN_GTT;
+		r = amdgpu_bo_create(adev, &bp, gtt_obj + i);
 		if (r) {
 			DRM_ERROR("Failed to create GTT object %d\n", i);
 			goto out_lclean;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10 -5
index 29efaac6e3ed..262baa98f8c4 100644
@@ -1316,6 +1316,15 @@ static void amdgpu_ttm_fw_reserve_vram_fini(struct amdgpu_device *adev)
 static int amdgpu_ttm_fw_reserve_vram_init(struct amdgpu_device *adev)
 {
 	struct ttm_operation_ctx ctx = { false, false };
+	struct amdgpu_bo_param bp = {
+		.size = adev->fw_vram_usage.size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_VRAM,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	int r = 0;
 	int i;
 	u64 vram_size = adev->gmc.visible_vram_size;
@@ -1329,11 +1338,7 @@ static int amdgpu_ttm_fw_reserve_vram_init(struct amdgpu_device *adev)
 	if (adev->fw_vram_usage.size > 0 &&
 		adev->fw_vram_usage.size <= vram_size) {
 
-		r = amdgpu_bo_create(adev, adev->fw_vram_usage.size, PAGE_SIZE,
-				     AMDGPU_GEM_DOMAIN_VRAM,
-				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     ttm_bo_type_kernel, NULL,
+		r = amdgpu_bo_create(adev, &bp,
 				     &adev->fw_vram_usage.reserved_bo);
 		if (r)
 			goto error_create;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +17 -7
index da55a78d7380..675fd8e59d59 100644
@@ -412,11 +412,15 @@ static int amdgpu_vm_alloc_levels(struct amdgpu_device *adev,
 		struct amdgpu_bo *pt;
 
 		if (!entry->base.bo) {
-			r = amdgpu_bo_create(adev,
-					     amdgpu_vm_bo_size(adev, level),
-					     AMDGPU_GPU_PAGE_SIZE,
-					     AMDGPU_GEM_DOMAIN_VRAM, flags,
-					     ttm_bo_type_kernel, resv, &pt);
+			struct amdgpu_bo_param bp = {
+				.size = amdgpu_vm_bo_size(adev, level),
+				.byte_align = AMDGPU_GPU_PAGE_SIZE,
+				.domain = AMDGPU_GEM_DOMAIN_VRAM,
+				.flags = flags,
+				.type = ttm_bo_type_kernel,
+				.resv = resv
+			};
+			r = amdgpu_bo_create(adev, &bp, &pt);
 			if (r)
 				return r;
 
@@ -2355,6 +2359,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
 int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		   int vm_context, unsigned int pasid)
 {
+	struct amdgpu_bo_param bp;
 	const unsigned align = min(AMDGPU_VM_PTB_ALIGN_SIZE,
 		AMDGPU_VM_PTE_COUNT(adev) * 8);
 	unsigned ring_instance;
@@ -2409,8 +2414,13 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm,
 		flags |= AMDGPU_GEM_CREATE_SHADOW;
 
 	size = amdgpu_vm_bo_size(adev, adev->vm_manager.root_level);
-	r = amdgpu_bo_create(adev, size, align, AMDGPU_GEM_DOMAIN_VRAM, flags,
-			     ttm_bo_type_kernel, NULL, &vm->root.base.bo);
+	bp.size = size;
+	bp.byte_align = align;
+	bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
+	bp.flags = flags;
+	bp.type = ttm_bo_type_kernel;
+	bp.resv = NULL;
+	r = amdgpu_bo_create(adev, &bp, &vm->root.base.bo);
 	if (r)
 		goto error_free_sched_entity;
 
Signature · 6 lines
2.14.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): [email protected]

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: use amdgpu_bo_parm for amdgpu_bo_create

Quoted 179 lines · Chunming Zhou

after that, we can easily add new parameter when need.

Change-Id I6e80039c3801f163129ecc605d931483fdbc91db
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c       | 12 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c    | 15 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c         | 16 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 11 +++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c       | 38 +++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h       |  6 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c        | 12 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_test.c         | 16 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c          | 15 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           | 24 ++++++++++-----
 11 files changed, 114 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -3
index 4d36203ffb11..f90405e572f9 100644
@@ -217,13 +217,19 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
 	struct amdgpu_bo *bo = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	int r;
 	uint64_t gpu_addr_tmp = 0;
 	void *cpu_ptr_tmp = NULL;
 
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
-			     AMDGPU_GEM_CREATE_CPU_GTT_USWC, ttm_bo_type_kernel,
-			     NULL, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
 	if (r) {
 		dev_err(adev->dev,
 			"failed to allocate BO for amdkfd (%d)\n", r);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -2
index 1d6e1479da38..b7bd24c35b25 100644
@@ -1004,6 +1004,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 	struct amdgpu_device *adev = get_amdgpu_device(kgd);
 	struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp;
 	int byte_align;
 	u32 alloc_domain;
 	u64 alloc_flags;
@@ -1069,8 +1070,13 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 	pr_debug("\tcreate BO VA 0x%llx size 0x%llx domain %s\n",
 			va, size, domain_string(alloc_domain));
 
-	ret = amdgpu_bo_create(adev, size, byte_align,
-				alloc_domain, alloc_flags, ttm_bo_type_device, NULL, &bo);
+	bp.size = size;
+	bp.byte_align = byte_align;
+	bp.domain = alloc_domain;
+	bp.flags = alloc_flags;
+	bp.type = ttm_bo_type_device;
+	bp.resv = NULL;
+	ret = amdgpu_bo_create(adev, &bp, &bo);
 	if (ret) {
 		pr_debug("Failed to create BO on domain %s. ret %d\n",
 				domain_string(alloc_domain), ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +11 -4
index 02b849be083b..96bdb454bdf6 100644
@@ -75,13 +75,20 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
 {
 	struct amdgpu_bo *dobj = NULL;
 	struct amdgpu_bo *sobj = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = sdomain,
+		.flags = 0,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	uint64_t saddr, daddr;
 	int r, n;
 	int time;
 
 	n = AMDGPU_BENCHMARK_ITERATIONS;
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE,sdomain, 0,
-			     ttm_bo_type_kernel, NULL, &sobj);
+	r = amdgpu_bo_create(adev, &bp, &sobj);
 	if (r) {
 		goto out_cleanup;
 	}
@@ -93,8 +100,8 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
 	if (r) {
 		goto out_cleanup;
 	}
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, ddomain, 0,
-			     ttm_bo_type_kernel, NULL, &dobj);
+	bp.domain = ddomain;
+	r = amdgpu_bo_create(adev, &bp, &dobj);
 	if (r) {
 		goto out_cleanup;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +10 -6
index cf0f186c6092..1f9b8ae7ad2b 100644
@@ -110,15 +110,19 @@ static void amdgpu_gart_dummy_page_fini(struct amdgpu_device *adev)
  */
 int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
 {
+	struct amdgpu_bo_param bp = {
+		.size = adev->gart.table_size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_VRAM,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
 	int r;
 
 	if (adev->gart.robj == NULL) {
-		r = amdgpu_bo_create(adev, adev->gart.table_size, PAGE_SIZE,
-				     AMDGPU_GEM_DOMAIN_VRAM,
-				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     ttm_bo_type_kernel, NULL,
-				     &adev->gart.robj);
+		r = amdgpu_bo_create(adev, &bp, &adev->gart.robj);
 		if (r) {
 			return r;
 		}
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +9 -2
index 28c2706e48d7..e8f947d3da53 100644
@@ -48,6 +48,14 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 			     struct drm_gem_object **obj)
 {
 	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = alignment,
+		.domain = initial_domain,
+		.flags = flags,
+		.type = type,
+		.resv = resv
+	};
 	int r;
 
 	*obj = NULL;
@@ -56,8 +64,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
 		alignment = PAGE_SIZE;
 	}
 
-	r = amdgpu_bo_create(adev, size, alignment, initial_domain,
-			     flags, type, resv, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
 	if (r) {
 		DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
 			  size, initial_domain, alignment, r);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index b557b63bb648..a7a73ea18704 100644
@@ -191,14 +191,20 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
 			      u32 domain, struct amdgpu_bo **bo_ptr,
 			      u64 *gpu_addr, void **cpu_addr)

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_reserved(struct amdgpu_device *adev, · line 202

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +9 -0
 {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = align,
+		.domain = domain,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};

Others looks good.
How about also use amdgpu_bo_param for amdgpu_bo_create_kernel function?

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

#5 lore raw

Re: [PATCH 2/2] drm/amdgpu: use amdgpu_bo_parm for amdgpu_bo_create

Am 16.04.2018 um 13:43 schrieb Huang Rui:

Quoted 184 lines · Chunming Zhou
Quoted 183 lines

after that, we can easily add new parameter when need.

Change-Id I6e80039c3801f163129ecc605d931483fdbc91db
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c       | 12 ++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c    | 15 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c         | 16 ++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 11 +++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c       | 38 +++++++++++-------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h       |  6 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c        | 12 ++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_test.c         | 16 ++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c          | 15 ++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           | 24 ++++++++++-----
  11 files changed, 114 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -3
index 4d36203ffb11..f90405e572f9 100644
@@ -217,13 +217,19 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
  	struct amdgpu_bo *bo = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
  	int r;
  	uint64_t gpu_addr_tmp = 0;
  	void *cpu_ptr_tmp = NULL;
 
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
-			     AMDGPU_GEM_CREATE_CPU_GTT_USWC, ttm_bo_type_kernel,
-			     NULL, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
  	if (r) {
  		dev_err(adev->dev,
  			"failed to allocate BO for amdkfd (%d)\n", r);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -2
index 1d6e1479da38..b7bd24c35b25 100644
@@ -1004,6 +1004,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
  	struct amdgpu_device *adev = get_amdgpu_device(kgd);
  	struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
  	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp;
  	int byte_align;
  	u32 alloc_domain;
  	u64 alloc_flags;
@@ -1069,8 +1070,13 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
  	pr_debug("\tcreate BO VA 0x%llx size 0x%llx domain %s\n",
  			va, size, domain_string(alloc_domain));
 
-	ret = amdgpu_bo_create(adev, size, byte_align,
-				alloc_domain, alloc_flags, ttm_bo_type_device, NULL, &bo);
+	bp.size = size;
+	bp.byte_align = byte_align;
+	bp.domain = alloc_domain;
+	bp.flags = alloc_flags;
+	bp.type = ttm_bo_type_device;
+	bp.resv = NULL;
+	ret = amdgpu_bo_create(adev, &bp, &bo);
  	if (ret) {
  		pr_debug("Failed to create BO on domain %s. ret %d\n",
  				domain_string(alloc_domain), ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +11 -4
index 02b849be083b..96bdb454bdf6 100644
@@ -75,13 +75,20 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
  {
  	struct amdgpu_bo *dobj = NULL;
  	struct amdgpu_bo *sobj = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = sdomain,
+		.flags = 0,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
  	uint64_t saddr, daddr;
  	int r, n;
  	int time;
 
  	n = AMDGPU_BENCHMARK_ITERATIONS;
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE,sdomain, 0,
-			     ttm_bo_type_kernel, NULL, &sobj);
+	r = amdgpu_bo_create(adev, &bp, &sobj);
  	if (r) {
  		goto out_cleanup;
  	}
@@ -93,8 +100,8 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
  	if (r) {
  		goto out_cleanup;
  	}
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, ddomain, 0,
-			     ttm_bo_type_kernel, NULL, &dobj);
+	bp.domain = ddomain;
+	r = amdgpu_bo_create(adev, &bp, &dobj);
  	if (r) {
  		goto out_cleanup;
  	}
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +10 -6
index cf0f186c6092..1f9b8ae7ad2b 100644
@@ -110,15 +110,19 @@ static void amdgpu_gart_dummy_page_fini(struct amdgpu_device *adev)
   */
  int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
  {
+	struct amdgpu_bo_param bp = {
+		.size = adev->gart.table_size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_VRAM,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
  	int r;
 
  	if (adev->gart.robj == NULL) {
-		r = amdgpu_bo_create(adev, adev->gart.table_size, PAGE_SIZE,
-				     AMDGPU_GEM_DOMAIN_VRAM,
-				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     ttm_bo_type_kernel, NULL,
-				     &adev->gart.robj);
+		r = amdgpu_bo_create(adev, &bp, &adev->gart.robj);
  		if (r) {
  			return r;
  		}
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +9 -2
index 28c2706e48d7..e8f947d3da53 100644
@@ -48,6 +48,14 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  			     struct drm_gem_object **obj)
  {
  	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = alignment,
+		.domain = initial_domain,
+		.flags = flags,
+		.type = type,
+		.resv = resv
+	};
  	int r;
 
  	*obj = NULL;
@@ -56,8 +64,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  		alignment = PAGE_SIZE;
  	}
 
-	r = amdgpu_bo_create(adev, size, alignment, initial_domain,
-			     flags, type, resv, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
  	if (r) {
  		DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
  			  size, initial_domain, alignment, r);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
index b557b63bb648..a7a73ea18704 100644
@@ -191,14 +191,20 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
  			      u32 domain, struct amdgpu_bo **bo_ptr,
  			      u64 *gpu_addr, void **cpu_addr)
  {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = align,
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_reserved(struct amdgpu_device *adev, · line 202

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
+		.domain = domain,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};

Others looks good.
How about also use amdgpu_bo_param for amdgpu_bo_create_kernel function?

I really wanted to keep the _kernel and _reserved variant simple enough to not need that.

Anyway patch is Reviewed-by: Christian König <[email protected]>.

Regards,
Christian.

Quoted 3 lines

Thanks,
Ray

_______________________________________________
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): d98bf0ab-8897-aebb-6487-18f082cefddc-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#7 lore raw

Re: [PATCH 2/2] drm/amdgpu: use amdgpu_bo_parm for amdgpu_bo_create

Quoted 194 lines · Christian

Am 16.04.2018 um 13:43 schrieb Huang Rui:

Quoted 184 lines · Chunming Zhou
Quoted 183 lines

after that, we can easily add new parameter when need.

Change-Id I6e80039c3801f163129ecc605d931483fdbc91db
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c       | 12 ++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 +++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c    | 15 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c         | 16 ++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c          | 11 +++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c       | 38 +++++++++++-------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h       |  6 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c        | 12 ++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_test.c         | 16 ++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c          | 15 ++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c           | 24 ++++++++++-----
  11 files changed, 114 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -3
index 4d36203ffb11..f90405e572f9 100644
@@ -217,13 +217,19 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size,
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
  	struct amdgpu_bo *bo = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
  	int r;
  	uint64_t gpu_addr_tmp = 0;
  	void *cpu_ptr_tmp = NULL;
 
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
-			     AMDGPU_GEM_CREATE_CPU_GTT_USWC, ttm_bo_type_kernel,
-			     NULL, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
  	if (r) {
  		dev_err(adev->dev,
  			"failed to allocate BO for amdkfd (%d)\n", r);
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +8 -2
index 1d6e1479da38..b7bd24c35b25 100644
@@ -1004,6 +1004,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
  	struct amdgpu_device *adev = get_amdgpu_device(kgd);
  	struct amdgpu_vm *avm = (struct amdgpu_vm *)vm;
  	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp;
  	int byte_align;
  	u32 alloc_domain;
  	u64 alloc_flags;
@@ -1069,8 +1070,13 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
  	pr_debug("\tcreate BO VA 0x%llx size 0x%llx domain %s\n",
  			va, size, domain_string(alloc_domain));
 
-	ret = amdgpu_bo_create(adev, size, byte_align,
-				alloc_domain, alloc_flags, ttm_bo_type_device, NULL, &bo);
+	bp.size = size;
+	bp.byte_align = byte_align;
+	bp.domain = alloc_domain;
+	bp.flags = alloc_flags;
+	bp.type = ttm_bo_type_device;
+	bp.resv = NULL;
+	ret = amdgpu_bo_create(adev, &bp, &bo);
  	if (ret) {
  		pr_debug("Failed to create BO on domain %s. ret %d\n",
  				domain_string(alloc_domain), ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +11 -4
index 02b849be083b..96bdb454bdf6 100644
@@ -75,13 +75,20 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
  {
  	struct amdgpu_bo *dobj = NULL;
  	struct amdgpu_bo *sobj = NULL;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = PAGE_SIZE,
+		.domain = sdomain,
+		.flags = 0,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
  	uint64_t saddr, daddr;
  	int r, n;
  	int time;
 
  	n = AMDGPU_BENCHMARK_ITERATIONS;
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE,sdomain, 0,
-			     ttm_bo_type_kernel, NULL, &sobj);
+	r = amdgpu_bo_create(adev, &bp, &sobj);
  	if (r) {
  		goto out_cleanup;
  	}
@@ -93,8 +100,8 @@ static void amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,
  	if (r) {
  		goto out_cleanup;
  	}
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, ddomain, 0,
-			     ttm_bo_type_kernel, NULL, &dobj);
+	bp.domain = ddomain;
+	r = amdgpu_bo_create(adev, &bp, &dobj);
  	if (r) {
  		goto out_cleanup;
  	}
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +10 -6
index cf0f186c6092..1f9b8ae7ad2b 100644
@@ -110,15 +110,19 @@ static void amdgpu_gart_dummy_page_fini(struct amdgpu_device *adev)
   */
  int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
  {
+	struct amdgpu_bo_param bp = {
+		.size = adev->gart.table_size,
+		.byte_align = PAGE_SIZE,
+		.domain = AMDGPU_GEM_DOMAIN_VRAM,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};
  	int r;
 
  	if (adev->gart.robj == NULL) {
-		r = amdgpu_bo_create(adev, adev->gart.table_size, PAGE_SIZE,
-				     AMDGPU_GEM_DOMAIN_VRAM,
-				     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-				     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-				     ttm_bo_type_kernel, NULL,
-				     &adev->gart.robj);
+		r = amdgpu_bo_create(adev, &bp, &adev->gart.robj);
  		if (r) {
  			return r;
  		}
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +9 -2
index 28c2706e48d7..e8f947d3da53 100644
@@ -48,6 +48,14 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  			     struct drm_gem_object **obj)
  {
  	struct amdgpu_bo *bo;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = alignment,
+		.domain = initial_domain,
+		.flags = flags,
+		.type = type,
+		.resv = resv
+	};
  	int r;
 
  	*obj = NULL;
@@ -56,8 +64,7 @@ int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
  		alignment = PAGE_SIZE;
  	}
 
-	r = amdgpu_bo_create(adev, size, alignment, initial_domain,
-			     flags, type, resv, &bo);
+	r = amdgpu_bo_create(adev, &bp, &bo);
  	if (r) {
  		DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
  			  size, initial_domain, alignment, r);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
index b557b63bb648..a7a73ea18704 100644
@@ -191,14 +191,20 @@ int amdgpu_bo_create_reserved(struct amdgpu_device *adev,
  			      u32 domain, struct amdgpu_bo **bo_ptr,
  			      u64 *gpu_addr, void **cpu_addr)
  {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = align,
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_create_reserved(struct amdgpu_device *adev, · line 202

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
+		.domain = domain,
+		.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
+		.type = ttm_bo_type_kernel,
+		.resv = NULL
+	};

Others looks good.
How about also use amdgpu_bo_param for amdgpu_bo_create_kernel function?

Quoted 3 lines

I really wanted to keep the _kernel and _reserved variant simple enough to not need that.

That's fine. I have no problem.

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

Reviewed-by
#8 lore raw
In reply to a message not in the archive
Quoted 2 lines · Chunming Zhou
Change-Id Ib2aa98ee37a70f3cb0d61eef1d336e89187554d5
Quoted 208 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 81 +++++++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  9 ++++
 2 files changed, 54 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +45 -36
index a160ef0332d6..b557b63bb648 100644
@@ -341,28 +341,26 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 	return false;
 }
 
-static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
-			       int byte_align, u32 domain,
-			       u64 flags, enum ttm_bo_type type,
-			       struct reservation_object *resv,
+static int amdgpu_bo_do_create(struct amdgpu_device *adev,
+			       struct amdgpu_bo_param *bp,
 			       struct amdgpu_bo **bo_ptr)
 {
 	struct ttm_operation_ctx ctx = {
-		.interruptible = (type != ttm_bo_type_kernel),
+		.interruptible = (bp->type != ttm_bo_type_kernel),
 		.no_wait_gpu = false,
-		.resv = resv,
+		.resv = bp->resv,
 		.flags = TTM_OPT_FLAG_ALLOW_RES_EVICT
 	};
 	struct amdgpu_bo *bo;
-	unsigned long page_align;
+	unsigned long page_align, size = bp->size;
 	size_t acc_size;
 	u32 domains, preferred_domains, allowed_domains;
 	int r;
 
-	page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	page_align = roundup(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;
 	size = ALIGN(size, PAGE_SIZE);
 
-	if (!amdgpu_bo_validate_size(adev, size, domain))
+	if (!amdgpu_bo_validate_size(adev, size, bp->domain))
 		return -ENOMEM;
 
 	*bo_ptr = NULL;
@@ -370,14 +368,14 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 	acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
 				       sizeof(struct amdgpu_bo));
 
-	preferred_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM |
-				      AMDGPU_GEM_DOMAIN_GTT |
-				      AMDGPU_GEM_DOMAIN_CPU |
-				      AMDGPU_GEM_DOMAIN_GDS |
-				      AMDGPU_GEM_DOMAIN_GWS |
-				      AMDGPU_GEM_DOMAIN_OA);
+	preferred_domains = bp->domain & (AMDGPU_GEM_DOMAIN_VRAM |
+					  AMDGPU_GEM_DOMAIN_GTT |
+					  AMDGPU_GEM_DOMAIN_CPU |
+					  AMDGPU_GEM_DOMAIN_GDS |
+					  AMDGPU_GEM_DOMAIN_GWS |
+					  AMDGPU_GEM_DOMAIN_OA);
 	allowed_domains = preferred_domains;
-	if (type != ttm_bo_type_kernel &&
+	if (bp->type != ttm_bo_type_kernel &&
 	    allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
 		allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
 	domains = preferred_domains;
@@ -391,7 +389,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 	bo->preferred_domains = preferred_domains;
 	bo->allowed_domains = allowed_domains;
 
-	bo->flags = flags;
+	bo->flags = bp->flags;
 
 #ifdef CONFIG_X86_32
 	/* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
@@ -423,13 +421,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 
 	bo->tbo.bdev = &adev->mman.bdev;
 	amdgpu_ttm_placement_from_domain(bo, domains);
-	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
+	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
 				 &bo->placement, page_align, &ctx, acc_size,
-				 NULL, resv, &amdgpu_ttm_bo_destroy);
-	if (unlikely(r && r != -ERESTARTSYS) && type == ttm_bo_type_device &&
-	    !(flags & AMDGPU_GEM_CREATE_NO_FALLBACK)) {
-		if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
-			flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+				 NULL, bp->resv, &amdgpu_ttm_bo_destroy);
+	if (unlikely(r && r != -ERESTARTSYS) && bp->type == ttm_bo_type_device &&
+	    !(bp->flags & AMDGPU_GEM_CREATE_NO_FALLBACK)) {
+		if (bp->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+			bp->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 			goto retry;
 		} else if (domains != allowed_domains) {
 			domains = allowed_domains;
@@ -447,10 +445,10 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 	else
 		amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
 
-	if (type == ttm_bo_type_kernel)
+	if (bp->type == ttm_bo_type_kernel)
 		bo->tbo.priority = 1;
 
-	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
 	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
 		struct dma_fence *fence;
 
@@ -463,20 +461,20 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 		bo->tbo.moving = dma_fence_get(fence);
 		dma_fence_put(fence);
 	}
-	if (!resv)
+	if (!bp->resv)
 		amdgpu_bo_unreserve(bo);
 	*bo_ptr = bo;
 
 	trace_amdgpu_bo_create(bo);
 
 	/* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
-	if (type == ttm_bo_type_device)
+	if (bp->type == ttm_bo_type_device)
 		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 
 	return 0;
 
 fail_unreserve:
-	if (!resv)
+	if (!bp->resv)
 		ww_mutex_unlock(&bo->tbo.resv->lock);
 	amdgpu_bo_unref(&bo);
 	return r;
@@ -486,16 +484,21 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 				   unsigned long size, int byte_align,
 				   struct amdgpu_bo *bo)
 {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = byte_align,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC |
+			AMDGPU_GEM_CREATE_SHADOW,
+		.type = ttm_bo_type_kernel,
+		.resv = bo->tbo.resv
+	};
 	int r;
 
 	if (bo->shadow)
 		return 0;
 
-	r = amdgpu_bo_do_create(adev, size, byte_align, AMDGPU_GEM_DOMAIN_GTT,
-				AMDGPU_GEM_CREATE_CPU_GTT_USWC |
-				AMDGPU_GEM_CREATE_SHADOW,
-				ttm_bo_type_kernel,
-				bo->tbo.resv, &bo->shadow);
+	r = amdgpu_bo_do_create(adev, &bp, &bo->shadow);
 	if (!r) {
 		bo->shadow->parent = amdgpu_bo_ref(bo);
 		mutex_lock(&adev->shadow_list_lock);
@@ -512,11 +515,17 @@ int amdgpu_bo_create(struct amdgpu_device *adev, unsigned long size,
 		     struct reservation_object *resv,
 		     struct amdgpu_bo **bo_ptr)
 {
-	uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = byte_align,
+		.domain = domain,
+		.flags = flags & ~AMDGPU_GEM_CREATE_SHADOW,
+		.type = type,
+		.resv = resv
+	};
 	int r;
 
-	r = amdgpu_bo_do_create(adev, size, byte_align, domain,
-				parent_flags, type, resv, bo_ptr);
+	r = amdgpu_bo_do_create(adev, &bp, bo_ptr);
 	if (r)
 		return r;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +9 -0
index 1e9fe85abcbb..4bb6f0a8d799 100644
@@ -33,6 +33,15 @@
 
 #define AMDGPU_BO_INVALID_OFFSET	LONG_MAX
 
+struct amdgpu_bo_param {
+	unsigned long			size;
+	int				byte_align;
+	u32				domain;
+	u64				flags;
+	enum ttm_bo_type		type;
+	struct reservation_object	*resv;
+};
+
 /* bo virtual addresses in a vm */
 struct amdgpu_bo_va_mapping {
 	struct amdgpu_bo_va		*bo_va;
Signature · 6 lines
2.14.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

Reviewed-by
#9 lore raw
In reply to a message not in the archive

Am 16.04.2018 um 13:13 schrieb Chunming Zhou:

Quoted 2 lines
Change-Id Ib2aa98ee37a70f3cb0d61eef1d336e89187554d5
Quoted 191 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 81 +++++++++++++++++-------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  9 ++++
  2 files changed, 54 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +45 -36
index a160ef0332d6..b557b63bb648 100644
@@ -341,28 +341,26 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
  	return false;
  }
 
-static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
-			       int byte_align, u32 domain,
-			       u64 flags, enum ttm_bo_type type,
-			       struct reservation_object *resv,
+static int amdgpu_bo_do_create(struct amdgpu_device *adev,
+			       struct amdgpu_bo_param *bp,
  			       struct amdgpu_bo **bo_ptr)
  {
  	struct ttm_operation_ctx ctx = {
-		.interruptible = (type != ttm_bo_type_kernel),
+		.interruptible = (bp->type != ttm_bo_type_kernel),
  		.no_wait_gpu = false,
-		.resv = resv,
+		.resv = bp->resv,
  		.flags = TTM_OPT_FLAG_ALLOW_RES_EVICT
  	};
  	struct amdgpu_bo *bo;
-	unsigned long page_align;
+	unsigned long page_align, size = bp->size;
  	size_t acc_size;
  	u32 domains, preferred_domains, allowed_domains;
  	int r;
 
-	page_align = roundup(byte_align, PAGE_SIZE) >> PAGE_SHIFT;
+	page_align = roundup(bp->byte_align, PAGE_SIZE) >> PAGE_SHIFT;
  	size = ALIGN(size, PAGE_SIZE);
 
-	if (!amdgpu_bo_validate_size(adev, size, domain))
+	if (!amdgpu_bo_validate_size(adev, size, bp->domain))
  		return -ENOMEM;
 
  	*bo_ptr = NULL;
@@ -370,14 +368,14 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
  	acc_size = ttm_bo_dma_acc_size(&adev->mman.bdev, size,
  				       sizeof(struct amdgpu_bo));
 
-	preferred_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM |
-				      AMDGPU_GEM_DOMAIN_GTT |
-				      AMDGPU_GEM_DOMAIN_CPU |
-				      AMDGPU_GEM_DOMAIN_GDS |
-				      AMDGPU_GEM_DOMAIN_GWS |
-				      AMDGPU_GEM_DOMAIN_OA);
+	preferred_domains = bp->domain & (AMDGPU_GEM_DOMAIN_VRAM |
+					  AMDGPU_GEM_DOMAIN_GTT |
+					  AMDGPU_GEM_DOMAIN_CPU |
+					  AMDGPU_GEM_DOMAIN_GDS |
+					  AMDGPU_GEM_DOMAIN_GWS |
+					  AMDGPU_GEM_DOMAIN_OA);
  	allowed_domains = preferred_domains;
-	if (type != ttm_bo_type_kernel &&
+	if (bp->type != ttm_bo_type_kernel &&
  	    allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
  		allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
  	domains = preferred_domains;
@@ -391,7 +389,7 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
  	bo->preferred_domains = preferred_domains;
  	bo->allowed_domains = allowed_domains;
 
-	bo->flags = flags;
+	bo->flags = bp->flags;
 
  #ifdef CONFIG_X86_32
  	/* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
@@ -423,13 +421,13 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
 
  	bo->tbo.bdev = &adev->mman.bdev;
  	amdgpu_ttm_placement_from_domain(bo, domains);
-	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type,
+	r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, bp->type,
  				 &bo->placement, page_align, &ctx, acc_size,
-				 NULL, resv, &amdgpu_ttm_bo_destroy);
-	if (unlikely(r && r != -ERESTARTSYS) && type == ttm_bo_type_device &&
-	    !(flags & AMDGPU_GEM_CREATE_NO_FALLBACK)) {
-		if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
-			flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+				 NULL, bp->resv, &amdgpu_ttm_bo_destroy);
+	if (unlikely(r && r != -ERESTARTSYS) && bp->type == ttm_bo_type_device &&
+	    !(bp->flags & AMDGPU_GEM_CREATE_NO_FALLBACK)) {
+		if (bp->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+			bp->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
  			goto retry;
  		} else if (domains != allowed_domains) {
  			domains = allowed_domains;
@@ -447,10 +445,10 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
  	else
  		amdgpu_cs_report_moved_bytes(adev, ctx.bytes_moved, 0);
 
-	if (type == ttm_bo_type_kernel)
+	if (bp->type == ttm_bo_type_kernel)
  		bo->tbo.priority = 1;
 
-	if (flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
+	if (bp->flags & AMDGPU_GEM_CREATE_VRAM_CLEARED &&
  	    bo->tbo.mem.placement & TTM_PL_FLAG_VRAM) {
  		struct dma_fence *fence;
 
@@ -463,20 +461,20 @@ static int amdgpu_bo_do_create(struct amdgpu_device *adev, unsigned long size,
  		bo->tbo.moving = dma_fence_get(fence);
  		dma_fence_put(fence);
  	}
-	if (!resv)
+	if (!bp->resv)
  		amdgpu_bo_unreserve(bo);
  	*bo_ptr = bo;
 
  	trace_amdgpu_bo_create(bo);
 
  	/* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
-	if (type == ttm_bo_type_device)
+	if (bp->type == ttm_bo_type_device)
  		bo->flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
 
  	return 0;
 
  fail_unreserve:
-	if (!resv)
+	if (!bp->resv)
  		ww_mutex_unlock(&bo->tbo.resv->lock);
  	amdgpu_bo_unref(&bo);
  	return r;
@@ -486,16 +484,21 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
  				   unsigned long size, int byte_align,
  				   struct amdgpu_bo *bo)
  {
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = byte_align,
+		.domain = AMDGPU_GEM_DOMAIN_GTT,
+		.flags = AMDGPU_GEM_CREATE_CPU_GTT_USWC |
+			AMDGPU_GEM_CREATE_SHADOW,
+		.type = ttm_bo_type_kernel,
+		.resv = bo->tbo.resv
+	};
  	int r;
 
  	if (bo->shadow)
  		return 0;
 
-	r = amdgpu_bo_do_create(adev, size, byte_align, AMDGPU_GEM_DOMAIN_GTT,
-				AMDGPU_GEM_CREATE_CPU_GTT_USWC |
-				AMDGPU_GEM_CREATE_SHADOW,
-				ttm_bo_type_kernel,
-				bo->tbo.resv, &bo->shadow);
+	r = amdgpu_bo_do_create(adev, &bp, &bo->shadow);
  	if (!r) {
  		bo->shadow->parent = amdgpu_bo_ref(bo);
  		mutex_lock(&adev->shadow_list_lock);
@@ -512,11 +515,17 @@ int amdgpu_bo_create(struct amdgpu_device *adev, unsigned long size,
  		     struct reservation_object *resv,
  		     struct amdgpu_bo **bo_ptr)
  {
-	uint64_t parent_flags = flags & ~AMDGPU_GEM_CREATE_SHADOW;
+	struct amdgpu_bo_param bp = {
+		.size = size,
+		.byte_align = byte_align,
+		.domain = domain,
+		.flags = flags & ~AMDGPU_GEM_CREATE_SHADOW,
+		.type = type,
+		.resv = resv
+	};
  	int r;
 
-	r = amdgpu_bo_do_create(adev, size, byte_align, domain,
-				parent_flags, type, resv, bo_ptr);
+	r = amdgpu_bo_do_create(adev, &bp, bo_ptr);
  	if (r)
  		return r;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +2 -0
index 1e9fe85abcbb..4bb6f0a8d799 100644
@@ -33,6 +33,15 @@
 
  #define AMDGPU_BO_INVALID_OFFSET	LONG_MAX
 
+struct amdgpu_bo_param {
+	unsigned long			size;

drivers/gpu/drm/amd/amdgpu/amdgpu_object.h line 47

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +7 -0
+	int				byte_align;
+	u32				domain;
+	u64				flags;
+	enum ttm_bo_type		type;
+	struct reservation_object	*resv;
+};
+
  /* bo virtual addresses in a vm */
  struct amdgpu_bo_va_mapping {
  	struct amdgpu_bo_va		*bo_va;

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