aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-01-04 09:12:22 -0500
committerSumit Semwal <sumit.semwal@linaro.org>2017-01-09 10:43:49 -0500
commita009e975da5c7d42a7f5eaadc54946eb5f76c9af (patch)
tree0ce04fe7768194d60fe9fac2a0baa5946869edd0
parentd6c99f4bf093a58d3ab47caaec74b81f18bc4e3f (diff)
dma-fence: Introduce drm_fence_set_error() helper
The dma_fence.error field (formerly known as dma_fence.status) is an optional field that may be set by drivers before calling dma_fence_signal(). The field can be used to indicate that the fence was completed in err rather than with success, and is visible to other consumers of the fence and to userspace via sync_file. This patch renames the field from status to error so that its meaning is hopefully more clear (and distinct from dma_fence_get_status() which is a composite between the error state and signal state) and adds a helper that validates the preconditions of when it is suitable to adjust the error field. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Link: http://patchwork.freedesktop.org/patch/msgid/20170104141222.6992-3-chris@chris-wilson.co.uk
-rw-r--r--drivers/dma-buf/dma-fence.c2
-rw-r--r--include/linux/dma-fence.h30
2 files changed, 26 insertions, 6 deletions
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c
index 5e66dfece03c..a1bfc098ea10 100644
--- a/drivers/dma-buf/dma-fence.c
+++ b/drivers/dma-buf/dma-fence.c
@@ -566,7 +566,7 @@ dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,
566 fence->context = context; 566 fence->context = context;
567 fence->seqno = seqno; 567 fence->seqno = seqno;
568 fence->flags = 0UL; 568 fence->flags = 0UL;
569 fence->status = 0; 569 fence->error = 0;
570 570
571 trace_dma_fence_init(fence); 571 trace_dma_fence_init(fence);
572} 572}
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h
index 19f7af905182..6048fa404e57 100644
--- a/include/linux/dma-fence.h
+++ b/include/linux/dma-fence.h
@@ -47,7 +47,7 @@ struct dma_fence_cb;
47 * can be compared to decide which fence would be signaled later. 47 * can be compared to decide which fence would be signaled later.
48 * @flags: A mask of DMA_FENCE_FLAG_* defined below 48 * @flags: A mask of DMA_FENCE_FLAG_* defined below
49 * @timestamp: Timestamp when the fence was signaled. 49 * @timestamp: Timestamp when the fence was signaled.
50 * @status: Optional, only valid if < 0, must be set before calling 50 * @error: Optional, only valid if < 0, must be set before calling
51 * dma_fence_signal, indicates that the fence has completed with an error. 51 * dma_fence_signal, indicates that the fence has completed with an error.
52 * 52 *
53 * the flags member must be manipulated and read using the appropriate 53 * the flags member must be manipulated and read using the appropriate
@@ -79,7 +79,7 @@ struct dma_fence {
79 unsigned seqno; 79 unsigned seqno;
80 unsigned long flags; 80 unsigned long flags;
81 ktime_t timestamp; 81 ktime_t timestamp;
82 int status; 82 int error;
83}; 83};
84 84
85enum dma_fence_flag_bits { 85enum dma_fence_flag_bits {
@@ -133,7 +133,7 @@ struct dma_fence_cb {
133 * or some failure occurred that made it impossible to enable 133 * or some failure occurred that made it impossible to enable
134 * signaling. True indicates successful enabling. 134 * signaling. True indicates successful enabling.
135 * 135 *
136 * fence->status may be set in enable_signaling, but only when false is 136 * fence->error may be set in enable_signaling, but only when false is
137 * returned. 137 * returned.
138 * 138 *
139 * Calling dma_fence_signal before enable_signaling is called allows 139 * Calling dma_fence_signal before enable_signaling is called allows
@@ -145,7 +145,7 @@ struct dma_fence_cb {
145 * the second time will be a noop since it was already signaled. 145 * the second time will be a noop since it was already signaled.
146 * 146 *
147 * Notes on signaled: 147 * Notes on signaled:
148 * May set fence->status if returning true. 148 * May set fence->error if returning true.
149 * 149 *
150 * Notes on wait: 150 * Notes on wait:
151 * Must not be NULL, set to dma_fence_default_wait for default implementation. 151 * Must not be NULL, set to dma_fence_default_wait for default implementation.
@@ -395,13 +395,33 @@ static inline struct dma_fence *dma_fence_later(struct dma_fence *f1,
395static inline int dma_fence_get_status_locked(struct dma_fence *fence) 395static inline int dma_fence_get_status_locked(struct dma_fence *fence)
396{ 396{
397 if (dma_fence_is_signaled_locked(fence)) 397 if (dma_fence_is_signaled_locked(fence))
398 return fence->status < 0 ? fence->status : 1; 398 return fence->error ?: 1;
399 else 399 else
400 return 0; 400 return 0;
401} 401}
402 402
403int dma_fence_get_status(struct dma_fence *fence); 403int dma_fence_get_status(struct dma_fence *fence);
404 404
405/**
406 * dma_fence_set_error - flag an error condition on the fence
407 * @fence: [in] the dma_fence
408 * @error: [in] the error to store
409 *
410 * Drivers can supply an optional error status condition before they signal
411 * the fence, to indicate that the fence was completed due to an error
412 * rather than success. This must be set before signaling (so that the value
413 * is visible before any waiters on the signal callback are woken). This
414 * helper exists to help catching erroneous setting of #dma_fence.error.
415 */
416static inline void dma_fence_set_error(struct dma_fence *fence,
417 int error)
418{
419 BUG_ON(test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fence->flags));
420 BUG_ON(error >= 0 || error < -MAX_ERRNO);
421
422 fence->error = error;
423}
424
405signed long dma_fence_wait_timeout(struct dma_fence *, 425signed long dma_fence_wait_timeout(struct dma_fence *,
406 bool intr, signed long timeout); 426 bool intr, signed long timeout);
407signed long dma_fence_wait_any_timeout(struct dma_fence **fences, 427signed long dma_fence_wait_any_timeout(struct dma_fence **fences,