drm/amdgpu: add the interface of waiting multiple fences (v4)
v2: agd: rebase and squash in all the previous optimizations and
changes so everything compiles.
v3: squash in Slava's 32bit build fix
v4: rebase on drm-next (fence -> dma_fence),
squash in Monk's ioctl update patch
Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Monk Liu <monk.liu@amd.com>
Reviewed-by: Jammy Zhou <Jammy.Zhou@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
[sumits: fix checkpatch warnings]
Link: http://patchwork.freedesktop.org/patch/msgid/1478290570-30982-2-git-send-email-alexander.deucher@amd.com
This commit is contained in:
parent
7392b4bb70
commit
eef18a827a
5 changed files with 207 additions and 1 deletions
|
|
@ -1139,6 +1139,180 @@ int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* amdgpu_cs_get_fence - helper to get fence from drm_amdgpu_fence
|
||||
*
|
||||
* @adev: amdgpu device
|
||||
* @filp: file private
|
||||
* @user: drm_amdgpu_fence copied from user space
|
||||
*/
|
||||
static struct dma_fence *amdgpu_cs_get_fence(struct amdgpu_device *adev,
|
||||
struct drm_file *filp,
|
||||
struct drm_amdgpu_fence *user)
|
||||
{
|
||||
struct amdgpu_ring *ring;
|
||||
struct amdgpu_ctx *ctx;
|
||||
struct dma_fence *fence;
|
||||
int r;
|
||||
|
||||
r = amdgpu_cs_get_ring(adev, user->ip_type, user->ip_instance,
|
||||
user->ring, &ring);
|
||||
if (r)
|
||||
return ERR_PTR(r);
|
||||
|
||||
ctx = amdgpu_ctx_get(filp->driver_priv, user->ctx_id);
|
||||
if (ctx == NULL)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
fence = amdgpu_ctx_get_fence(ctx, ring, user->seq_no);
|
||||
amdgpu_ctx_put(ctx);
|
||||
|
||||
return fence;
|
||||
}
|
||||
|
||||
/**
|
||||
* amdgpu_cs_wait_all_fence - wait on all fences to signal
|
||||
*
|
||||
* @adev: amdgpu device
|
||||
* @filp: file private
|
||||
* @wait: wait parameters
|
||||
* @fences: array of drm_amdgpu_fence
|
||||
*/
|
||||
static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev,
|
||||
struct drm_file *filp,
|
||||
union drm_amdgpu_wait_fences *wait,
|
||||
struct drm_amdgpu_fence *fences)
|
||||
{
|
||||
uint32_t fence_count = wait->in.fence_count;
|
||||
unsigned int i;
|
||||
long r = 1;
|
||||
|
||||
for (i = 0; i < fence_count; i++) {
|
||||
struct dma_fence *fence;
|
||||
unsigned long timeout = amdgpu_gem_timeout(wait->in.timeout_ns);
|
||||
|
||||
fence = amdgpu_cs_get_fence(adev, filp, &fences[i]);
|
||||
if (IS_ERR(fence))
|
||||
return PTR_ERR(fence);
|
||||
else if (!fence)
|
||||
continue;
|
||||
|
||||
r = dma_fence_wait_timeout(fence, true, timeout);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (r == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
memset(wait, 0, sizeof(*wait));
|
||||
wait->out.status = (r > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* amdgpu_cs_wait_any_fence - wait on any fence to signal
|
||||
*
|
||||
* @adev: amdgpu device
|
||||
* @filp: file private
|
||||
* @wait: wait parameters
|
||||
* @fences: array of drm_amdgpu_fence
|
||||
*/
|
||||
static int amdgpu_cs_wait_any_fence(struct amdgpu_device *adev,
|
||||
struct drm_file *filp,
|
||||
union drm_amdgpu_wait_fences *wait,
|
||||
struct drm_amdgpu_fence *fences)
|
||||
{
|
||||
unsigned long timeout = amdgpu_gem_timeout(wait->in.timeout_ns);
|
||||
uint32_t fence_count = wait->in.fence_count;
|
||||
uint32_t first = ~0;
|
||||
struct dma_fence **array;
|
||||
unsigned int i;
|
||||
long r;
|
||||
|
||||
/* Prepare the fence array */
|
||||
array = kcalloc(fence_count, sizeof(struct dma_fence *), GFP_KERNEL);
|
||||
|
||||
if (array == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
for (i = 0; i < fence_count; i++) {
|
||||
struct dma_fence *fence;
|
||||
|
||||
fence = amdgpu_cs_get_fence(adev, filp, &fences[i]);
|
||||
if (IS_ERR(fence)) {
|
||||
r = PTR_ERR(fence);
|
||||
goto err_free_fence_array;
|
||||
} else if (fence) {
|
||||
array[i] = fence;
|
||||
} else { /* NULL, the fence has been already signaled */
|
||||
r = 1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
r = dma_fence_wait_any_timeout(array, fence_count, true, timeout,
|
||||
&first);
|
||||
if (r < 0)
|
||||
goto err_free_fence_array;
|
||||
|
||||
out:
|
||||
memset(wait, 0, sizeof(*wait));
|
||||
wait->out.status = (r > 0);
|
||||
wait->out.first_signaled = first;
|
||||
/* set return value 0 to indicate success */
|
||||
r = 0;
|
||||
|
||||
err_free_fence_array:
|
||||
for (i = 0; i < fence_count; i++)
|
||||
dma_fence_put(array[i]);
|
||||
kfree(array);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* amdgpu_cs_wait_fences_ioctl - wait for multiple command submissions to finish
|
||||
*
|
||||
* @dev: drm device
|
||||
* @data: data from userspace
|
||||
* @filp: file private
|
||||
*/
|
||||
int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data,
|
||||
struct drm_file *filp)
|
||||
{
|
||||
struct amdgpu_device *adev = dev->dev_private;
|
||||
union drm_amdgpu_wait_fences *wait = data;
|
||||
uint32_t fence_count = wait->in.fence_count;
|
||||
struct drm_amdgpu_fence *fences_user;
|
||||
struct drm_amdgpu_fence *fences;
|
||||
int r;
|
||||
|
||||
/* Get the fences from userspace */
|
||||
fences = kmalloc_array(fence_count, sizeof(struct drm_amdgpu_fence),
|
||||
GFP_KERNEL);
|
||||
if (fences == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
fences_user = (void __user *)(unsigned long)(wait->in.fences);
|
||||
if (copy_from_user(fences, fences_user,
|
||||
sizeof(struct drm_amdgpu_fence) * fence_count)) {
|
||||
r = -EFAULT;
|
||||
goto err_free_fences;
|
||||
}
|
||||
|
||||
if (wait->in.wait_all)
|
||||
r = amdgpu_cs_wait_all_fences(adev, filp, wait, fences);
|
||||
else
|
||||
r = amdgpu_cs_wait_any_fence(adev, filp, wait, fences);
|
||||
|
||||
err_free_fences:
|
||||
kfree(fences);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* amdgpu_cs_find_bo_va - find bo_va for VM address
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue