diff options
author | monk.liu <monk.liu@amd.com> | 2016-11-04 16:16:09 -0400 |
---|---|---|
committer | Sumit Semwal <sumit.semwal@linaro.org> | 2016-11-08 13:42:00 -0500 |
commit | 7392b4bb702b05749539ff0936e94976248240c9 (patch) | |
tree | 7aa0026cdcaf873f24434f67167e9be18a607e0c | |
parent | c5ec903d8e8e9a9684ebb5ceef87f6a890d712b1 (diff) |
dma-buf: return index of the first signaled fence (v2)
Return the index of the first signaled fence. This information
is useful in some APIs like Vulkan.
v2: rebase on drm-next (fence -> dma_fence)
Signed-off-by: monk.liu <monk.liu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
[sumits: fix warnings]
Link: http://patchwork.freedesktop.org/patch/msgid/1478290570-30982-1-git-send-email-alexander.deucher@amd.com
-rw-r--r-- | drivers/dma-buf/dma-fence.c | 21 | ||||
-rw-r--r-- | include/linux/dma-fence.h | 3 |
2 files changed, 18 insertions, 6 deletions
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 3a7bf009c21c..cda40cbd8c43 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c | |||
@@ -403,14 +403,18 @@ out: | |||
403 | EXPORT_SYMBOL(dma_fence_default_wait); | 403 | EXPORT_SYMBOL(dma_fence_default_wait); |
404 | 404 | ||
405 | static bool | 405 | static bool |
406 | dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count) | 406 | dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count, |
407 | uint32_t *idx) | ||
407 | { | 408 | { |
408 | int i; | 409 | int i; |
409 | 410 | ||
410 | for (i = 0; i < count; ++i) { | 411 | for (i = 0; i < count; ++i) { |
411 | struct dma_fence *fence = fences[i]; | 412 | struct dma_fence *fence = fences[i]; |
412 | if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) | 413 | if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags)) { |
414 | if (idx) | ||
415 | *idx = i; | ||
413 | return true; | 416 | return true; |
417 | } | ||
414 | } | 418 | } |
415 | return false; | 419 | return false; |
416 | } | 420 | } |
@@ -422,6 +426,8 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count) | |||
422 | * @count: [in] number of fences to wait on | 426 | * @count: [in] number of fences to wait on |
423 | * @intr: [in] if true, do an interruptible wait | 427 | * @intr: [in] if true, do an interruptible wait |
424 | * @timeout: [in] timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT | 428 | * @timeout: [in] timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT |
429 | * @idx: [out] the first signaled fence index, meaningful only on | ||
430 | * positive return | ||
425 | * | 431 | * |
426 | * Returns -EINVAL on custom fence wait implementation, -ERESTARTSYS if | 432 | * Returns -EINVAL on custom fence wait implementation, -ERESTARTSYS if |
427 | * interrupted, 0 if the wait timed out, or the remaining timeout in jiffies | 433 | * interrupted, 0 if the wait timed out, or the remaining timeout in jiffies |
@@ -433,7 +439,7 @@ dma_fence_test_signaled_any(struct dma_fence **fences, uint32_t count) | |||
433 | */ | 439 | */ |
434 | signed long | 440 | signed long |
435 | dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, | 441 | dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, |
436 | bool intr, signed long timeout) | 442 | bool intr, signed long timeout, uint32_t *idx) |
437 | { | 443 | { |
438 | struct default_wait_cb *cb; | 444 | struct default_wait_cb *cb; |
439 | signed long ret = timeout; | 445 | signed long ret = timeout; |
@@ -444,8 +450,11 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, | |||
444 | 450 | ||
445 | if (timeout == 0) { | 451 | if (timeout == 0) { |
446 | for (i = 0; i < count; ++i) | 452 | for (i = 0; i < count; ++i) |
447 | if (dma_fence_is_signaled(fences[i])) | 453 | if (dma_fence_is_signaled(fences[i])) { |
454 | if (idx) | ||
455 | *idx = i; | ||
448 | return 1; | 456 | return 1; |
457 | } | ||
449 | 458 | ||
450 | return 0; | 459 | return 0; |
451 | } | 460 | } |
@@ -468,6 +477,8 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, | |||
468 | if (dma_fence_add_callback(fence, &cb[i].base, | 477 | if (dma_fence_add_callback(fence, &cb[i].base, |
469 | dma_fence_default_wait_cb)) { | 478 | dma_fence_default_wait_cb)) { |
470 | /* This fence is already signaled */ | 479 | /* This fence is already signaled */ |
480 | if (idx) | ||
481 | *idx = i; | ||
471 | goto fence_rm_cb; | 482 | goto fence_rm_cb; |
472 | } | 483 | } |
473 | } | 484 | } |
@@ -478,7 +489,7 @@ dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, | |||
478 | else | 489 | else |
479 | set_current_state(TASK_UNINTERRUPTIBLE); | 490 | set_current_state(TASK_UNINTERRUPTIBLE); |
480 | 491 | ||
481 | if (dma_fence_test_signaled_any(fences, count)) | 492 | if (dma_fence_test_signaled_any(fences, count, idx)) |
482 | break; | 493 | break; |
483 | 494 | ||
484 | ret = schedule_timeout(ret); | 495 | ret = schedule_timeout(ret); |
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index ba60c043a5d3..fcf4b1971eba 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h | |||
@@ -382,7 +382,8 @@ signed long dma_fence_wait_timeout(struct dma_fence *, | |||
382 | bool intr, signed long timeout); | 382 | bool intr, signed long timeout); |
383 | signed long dma_fence_wait_any_timeout(struct dma_fence **fences, | 383 | signed long dma_fence_wait_any_timeout(struct dma_fence **fences, |
384 | uint32_t count, | 384 | uint32_t count, |
385 | bool intr, signed long timeout); | 385 | bool intr, signed long timeout, |
386 | uint32_t *idx); | ||
386 | 387 | ||
387 | /** | 388 | /** |
388 | * dma_fence_wait - sleep until the fence gets signaled | 389 | * dma_fence_wait - sleep until the fence gets signaled |