[PATCH 1/4] drm/amdgpu: introduce struct amdgpu_bo_dmabuf

Christian König christian.koenig at amd.com
Wed Mar 17 08:02:58 UTC 2021



Am 17.03.21 um 08:47 schrieb Nirmoy Das:
> Implement a new struct amdgpu_bo_dmabuf as subclass of
> struct amdgpu_bo and a function to create amdgpu_bo_dmabuf
> bo.
>
> Signed-off-by: Nirmoy Das <nirmoy.das at amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 30 ++++++++++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_object.h |  9 +++++++
>   2 files changed, 39 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> index fdf23e439b42..fa4686fe95c4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
> @@ -727,6 +727,36 @@ int amdgpu_bo_create_user(struct amdgpu_device *adev,
>   	*ubo_ptr = to_amdgpu_bo_user(bo_ptr);
>   	return r;
>   }
> +
> +/**
> + * amdgpu_bo_create_dmabuf - create an &amdgpu_bo_dmabuf buffer object
> + * @adev: amdgpu device object
> + * @bp: parameters to be used for the buffer object
> + * @ubo_ptr: pointer to the buffer object pointer
> + *
> + * Create a BO to be used by prime BO export;
> + *
> + * Returns:
> + * 0 for success or a negative error code on failure.
> + */
> +
> +int amdgpu_bo_create_dmabuf(struct amdgpu_device *adev,
> +			    struct amdgpu_bo_param *bp,
> +			    struct amdgpu_bo_dmabuf **dbo_ptr)
> +{
> +	struct amdgpu_bo *bo_ptr;
> +	int r;
> +
> +	bp->flags = bp->flags & ~AMDGPU_GEM_CREATE_SHADOW;
> +	bp->bo_ptr_size = sizeof(struct amdgpu_bo_dmabuf);
> +	r = amdgpu_bo_do_create(adev, bp, &bo_ptr);
> +	if (r)
> +		return r;
> +
> +	*dbo_ptr = to_amdgpu_bo_dmabuf(bo_ptr);
> +	return r;
> +}
> +
>   /**
>    * amdgpu_bo_validate - validate an &amdgpu_bo buffer object
>    * @bo: pointer to the buffer object
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> index 25411b2c4dd9..4b9339c3f3eb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
> @@ -38,6 +38,7 @@
>   #define AMDGPU_BO_MAX_PLACEMENTS	3
>   
>   #define to_amdgpu_bo_user(abo) container_of((abo), struct amdgpu_bo_user, bo)
> +#define to_amdgpu_bo_dmabuf(abo) container_of((abo), struct amdgpu_bo_dmabuf, bo)
>   
>   struct amdgpu_bo_param {
>   	unsigned long			size;
> @@ -119,6 +120,11 @@ struct amdgpu_bo_user {
>   
>   };
>   
> +struct amdgpu_bo_dmabuf {
> +	struct amdgpu_bo		bo;

That won't work like this. Imported DMA-bufs are also user BOs and can 
have tilling flags and metadata.

Christian.

> +	unsigned int			prime_shared_count;
> +};
> +
>   static inline struct amdgpu_bo *ttm_to_amdgpu_bo(struct ttm_buffer_object *tbo)
>   {
>   	return container_of(tbo, struct amdgpu_bo, tbo);
> @@ -265,6 +271,9 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,
>   int amdgpu_bo_create_user(struct amdgpu_device *adev,
>   			  struct amdgpu_bo_param *bp,
>   			  struct amdgpu_bo_user **ubo_ptr);
> +int amdgpu_bo_create_dmabuf(struct amdgpu_device *adev,
> +			    struct amdgpu_bo_param *bp,
> +			    struct amdgpu_bo_dmabuf **dbo_ptr);
>   void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,
>   			   void **cpu_addr);
>   int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);



More information about the amd-gfx mailing list