[PATCH 4/7] drm/radeon: Pin buffers while they are vmap'ed

Christian König christian.koenig at amd.com
Thu Nov 12 17:16:55 UTC 2020


Am 12.11.20 um 14:21 schrieb Thomas Zimmermann:
> In order to avoid eviction of vmap'ed buffers, pin them in their GEM
> object's vmap implementation. Unpin them in the vunmap implementation.
> This is needed to make generic fbdev support work reliably. Without,
> the buffer object could be evicted while fbdev flushed its shadow buffer.
>
> In difference to the PRIME pin/unpin functions, the vmap code does not
> modify the BOs prime_shared_count, so a vmap-pinned BO does not count as
> shared.
>
> The actual pin location is not important as the vmap call returns
> information on how to access the buffer. Callers that require a
> specific location should explicitly pin the BO before vmapping it.

Well is the buffer supposed to be scanned out?

If yes then the pin location is actually rather important since the 
hardware can only scan out from VRAM.

Regards,
Christian.

>
> Signed-off-by: Thomas Zimmermann <tzimmermann at suse.de>
> ---
>   drivers/gpu/drm/radeon/radeon_gem.c | 51 +++++++++++++++++++++++++++--
>   1 file changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
> index d2876ce3bc9e..eaf7fc9a7b07 100644
> --- a/drivers/gpu/drm/radeon/radeon_gem.c
> +++ b/drivers/gpu/drm/radeon/radeon_gem.c
> @@ -226,6 +226,53 @@ static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r)
>   	return r;
>   }
>   
> +static int radeon_gem_object_vmap(struct drm_gem_object *obj, struct dma_buf_map *map)
> +{
> +	static const uint32_t any_domain = RADEON_GEM_DOMAIN_VRAM |
> +					   RADEON_GEM_DOMAIN_GTT |
> +					   RADEON_GEM_DOMAIN_CPU;
> +
> +	struct radeon_bo *bo = gem_to_radeon_bo(obj);
> +	int ret;
> +
> +	ret = radeon_bo_reserve(bo, false);
> +	if (ret)
> +		return ret;
> +
> +	/* pin buffer at its current location */
> +	ret = radeon_bo_pin(bo, any_domain, NULL);
> +	if (ret)
> +		goto err_radeon_bo_unreserve;
> +
> +	ret = drm_gem_ttm_vmap(obj, map);
> +	if (ret)
> +		goto err_radeon_bo_unpin;
> +
> +	radeon_bo_unreserve(bo);
> +
> +	return 0;
> +
> +err_radeon_bo_unpin:
> +	radeon_bo_unpin(bo);
> +err_radeon_bo_unreserve:
> +	radeon_bo_unreserve(bo);
> +	return ret;
> +}
> +
> +static void radeon_gem_object_vunmap(struct drm_gem_object *obj, struct dma_buf_map *map)
> +{
> +	struct radeon_bo *bo = gem_to_radeon_bo(obj);
> +	int ret;
> +
> +	ret = radeon_bo_reserve(bo, false);
> +	if (ret)
> +		return;
> +
> +	drm_gem_ttm_vunmap(obj, map);
> +	radeon_bo_unpin(bo);
> +	radeon_bo_unreserve(bo);
> +}
> +
>   static const struct drm_gem_object_funcs radeon_gem_object_funcs = {
>   	.free = radeon_gem_object_free,
>   	.open = radeon_gem_object_open,
> @@ -234,8 +281,8 @@ static const struct drm_gem_object_funcs radeon_gem_object_funcs = {
>   	.pin = radeon_gem_prime_pin,
>   	.unpin = radeon_gem_prime_unpin,
>   	.get_sg_table = radeon_gem_prime_get_sg_table,
> -	.vmap = drm_gem_ttm_vmap,
> -	.vunmap = drm_gem_ttm_vunmap,
> +	.vmap = radeon_gem_object_vmap,
> +	.vunmap = radeon_gem_object_vunmap,
>   };
>   
>   /*



More information about the amd-gfx mailing list