Re: [PATCH v3 5/5] drm/amdgpu: use amdgpu_bo_user bo for metadata and tiling flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 09.03.21 um 09:46 schrieb Nirmoy Das:
Tiling flag and metadata are only needed for BOs created by
amdgpu_gem_object_create(), so we can remove those from the
base class.

v2: * squash tiling_flags and metadata relared patches into one
     * use BUG_ON for non ttm_bo_type_device type when accessing
     tiling_flags and metadata._
v3: *include to_amdgpu_bo_user

CC: felix.kuehling@xxxxxxx
Signed-off-by: Nirmoy Das <nirmoy.das@xxxxxxx>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c |  2 -
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 51 +++++++++++++++-------
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  4 --
  3 files changed, 35 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index de6b3ca64b45..efa79719d453 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -498,8 +498,6 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
  		*dma_buf_kgd = (struct kgd_dev *)adev;
  	if (bo_size)
  		*bo_size = amdgpu_bo_size(bo);
-	if (metadata_size)
-		*metadata_size = bo->metadata_size;
  	if (metadata_buffer)
  		r = amdgpu_bo_get_metadata(bo, metadata_buffer, buffer_size,
  					   metadata_size, &metadata_flags);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index bd89d44a1f2f..ac0e1cd83858 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -77,6 +77,7 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(tbo->bdev);
  	struct amdgpu_bo *bo = ttm_to_amdgpu_bo(tbo);
+	struct amdgpu_bo_user *ubo;

  	if (bo->tbo.pin_count > 0)
  		amdgpu_bo_subtract_pin_size(bo);
@@ -94,7 +95,11 @@ static void amdgpu_bo_destroy(struct ttm_buffer_object *tbo)
  	}
  	amdgpu_bo_unref(&bo->parent);

-	kfree(bo->metadata);
+	if (bo->tbo.type == ttm_bo_type_device) {
+		ubo = to_amdgpu_bo_user(bo);
+		kfree(ubo->metadata);
+	}
+

At some point we might need to improve this and use something like amdgpu_bo_destroy_user(), but for now the patch is Reviewed-by: Christian König <christian.koenig@xxxxxxx>.

Thanks,
Christian.

  	kfree(bo);
  }

@@ -1160,12 +1165,15 @@ int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
  int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_bo_user *ubo;

+	BUG_ON(bo->tbo.type != ttm_bo_type_device);
  	if (adev->family <= AMDGPU_FAMILY_CZ &&
  	    AMDGPU_TILING_GET(tiling_flags, TILE_SPLIT) > 6)
  		return -EINVAL;

-	bo->tiling_flags = tiling_flags;
+	ubo = to_amdgpu_bo_user(bo);
+	ubo->tiling_flags = tiling_flags;
  	return 0;
  }

@@ -1179,10 +1187,14 @@ int amdgpu_bo_set_tiling_flags(struct amdgpu_bo *bo, u64 tiling_flags)
   */
  void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
  {
+	struct amdgpu_bo_user *ubo;
+
+	BUG_ON(bo->tbo.type != ttm_bo_type_device);
  	dma_resv_assert_held(bo->tbo.base.resv);
+	ubo = to_amdgpu_bo_user(bo);

  	if (tiling_flags)
-		*tiling_flags = bo->tiling_flags;
+		*tiling_flags = ubo->tiling_flags;
  }

  /**
@@ -1201,13 +1213,16 @@ void amdgpu_bo_get_tiling_flags(struct amdgpu_bo *bo, u64 *tiling_flags)
  int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
  			    uint32_t metadata_size, uint64_t flags)
  {
+	struct amdgpu_bo_user *ubo;
  	void *buffer;

+	BUG_ON(bo->tbo.type != ttm_bo_type_device);
+	ubo = to_amdgpu_bo_user(bo);
  	if (!metadata_size) {
-		if (bo->metadata_size) {
-			kfree(bo->metadata);
-			bo->metadata = NULL;
-			bo->metadata_size = 0;
+		if (ubo->metadata_size) {
+			kfree(ubo->metadata);
+			ubo->metadata = NULL;
+			ubo->metadata_size = 0;
  		}
  		return 0;
  	}
@@ -1219,10 +1234,10 @@ int amdgpu_bo_set_metadata (struct amdgpu_bo *bo, void *metadata,
  	if (buffer == NULL)
  		return -ENOMEM;

-	kfree(bo->metadata);
-	bo->metadata_flags = flags;
-	bo->metadata = buffer;
-	bo->metadata_size = metadata_size;
+	kfree(ubo->metadata);
+	ubo->metadata_flags = flags;
+	ubo->metadata = buffer;
+	ubo->metadata_size = metadata_size;

  	return 0;
  }
@@ -1246,21 +1261,25 @@ int amdgpu_bo_get_metadata(struct amdgpu_bo *bo, void *buffer,
  			   size_t buffer_size, uint32_t *metadata_size,
  			   uint64_t *flags)
  {
+	struct amdgpu_bo_user *ubo;
+
  	if (!buffer && !metadata_size)
  		return -EINVAL;

+	BUG_ON(bo->tbo.type != ttm_bo_type_device);
+	ubo = to_amdgpu_bo_user(bo);
  	if (buffer) {
-		if (buffer_size < bo->metadata_size)
+		if (buffer_size < ubo->metadata_size)
  			return -EINVAL;

-		if (bo->metadata_size)
-			memcpy(buffer, bo->metadata, bo->metadata_size);
+		if (ubo->metadata_size)
+			memcpy(buffer, ubo->metadata, ubo->metadata_size);
  	}

  	if (metadata_size)
-		*metadata_size = bo->metadata_size;
+		*metadata_size = ubo->metadata_size;
  	if (flags)
-		*flags = bo->metadata_flags;
+		*flags = ubo->metadata_flags;

  	return 0;
  }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
index 06b6fa35db99..25411b2c4dd9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
@@ -92,10 +92,6 @@ struct amdgpu_bo {
  	struct ttm_buffer_object	tbo;
  	struct ttm_bo_kmap_obj		kmap;
  	u64				flags;
-	u64				tiling_flags;
-	u64				metadata_flags;
-	void				*metadata;
-	u32				metadata_size;
  	unsigned			prime_shared_count;
  	/* per VM structure for page tables and with virtual addresses */
  	struct amdgpu_vm_bo_base	*vm_bo;
--
2.30.1


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




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux