Skip to content

Commit

Permalink
dma-buf: wait for map to complete for static attachments
Browse files Browse the repository at this point in the history
We have previously done that in the individual drivers but it is
more defensive to move that into the common code.

Dynamic attachments should wait for map operations to complete by themselves.

Signed-off-by: Christian König <[email protected]>
Reviewed-by: Daniel Vetter <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
ChristianKoenigAMD committed Apr 7, 2022
1 parent 0cc848a commit 46b35b3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 45 deletions.
18 changes: 15 additions & 3 deletions drivers/dma-buf/dma-buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,24 @@ static struct sg_table * __map_dma_buf(struct dma_buf_attachment *attach,
enum dma_data_direction direction)
{
struct sg_table *sg_table;
signed long ret;

sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
if (IS_ERR_OR_NULL(sg_table))
return sg_table;

if (!dma_buf_attachment_is_dynamic(attach)) {
ret = dma_resv_wait_timeout(attach->dmabuf->resv,
DMA_RESV_USAGE_KERNEL, true,
MAX_SCHEDULE_TIMEOUT);
if (ret < 0) {
attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
direction);
return ERR_PTR(ret);
}
}

if (!IS_ERR_OR_NULL(sg_table))
mangle_sg_table(sg_table);

mangle_sg_table(sg_table);
return sg_table;
}

Expand Down
14 changes: 1 addition & 13 deletions drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,9 @@ static int amdgpu_dma_buf_pin(struct dma_buf_attachment *attach)
{
struct drm_gem_object *obj = attach->dmabuf->priv;
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
int r;

/* pin buffer into GTT */
r = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
if (r)
return r;

if (bo->tbo.moving) {
r = dma_fence_wait(bo->tbo.moving, true);
if (r) {
amdgpu_bo_unpin(bo);
return r;
}
}
return 0;
return amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
}

/**
Expand Down
17 changes: 1 addition & 16 deletions drivers/gpu/drm/nouveau/nouveau_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,7 @@ int nouveau_gem_prime_pin(struct drm_gem_object *obj)
if (ret)
return -EINVAL;

ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL);
if (ret)
goto error;

if (nvbo->bo.moving)
ret = dma_fence_wait(nvbo->bo.moving, true);

ttm_bo_unreserve(&nvbo->bo);
if (ret)
goto error;

return ret;

error:
nouveau_bo_unpin(nvbo);
return ret;
return 0;
}

void nouveau_gem_prime_unpin(struct drm_gem_object *obj)
Expand Down
16 changes: 3 additions & 13 deletions drivers/gpu/drm/radeon/radeon_prime.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,9 @@ int radeon_gem_prime_pin(struct drm_gem_object *obj)

/* pin buffer into GTT */
ret = radeon_bo_pin(bo, RADEON_GEM_DOMAIN_GTT, NULL);
if (unlikely(ret))
goto error;

if (bo->tbo.moving) {
ret = dma_fence_wait(bo->tbo.moving, false);
if (unlikely(ret)) {
radeon_bo_unpin(bo);
goto error;
}
}

bo->prime_shared_count++;
error:
if (likely(ret == 0))
bo->prime_shared_count++;

radeon_bo_unreserve(bo);
return ret;
}
Expand Down

0 comments on commit 46b35b3

Please sign in to comment.