| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: linux_dma_fence.c,v 1.20 2021/12/19 12:07:38 riastradh Exp $ */ | | 1 | /* $NetBSD: linux_dma_fence.c,v 1.21 2021/12/19 12:09:19 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2018 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.20 2021/12/19 12:07:38 riastradh Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.21 2021/12/19 12:09:19 riastradh Exp $"); |
34 | | | 34 | |
35 | #include <sys/atomic.h> | | 35 | #include <sys/atomic.h> |
36 | #include <sys/condvar.h> | | 36 | #include <sys/condvar.h> |
37 | #include <sys/queue.h> | | 37 | #include <sys/queue.h> |
38 | | | 38 | |
39 | #include <linux/atomic.h> | | 39 | #include <linux/atomic.h> |
40 | #include <linux/dma-fence.h> | | 40 | #include <linux/dma-fence.h> |
41 | #include <linux/errno.h> | | 41 | #include <linux/errno.h> |
42 | #include <linux/kref.h> | | 42 | #include <linux/kref.h> |
43 | #include <linux/sched.h> | | 43 | #include <linux/sched.h> |
44 | #include <linux/spinlock.h> | | 44 | #include <linux/spinlock.h> |
45 | | | 45 | |
46 | /* | | 46 | /* |
| @@ -403,30 +403,35 @@ dma_fence_add_callback(struct dma_fence | | | @@ -403,30 +403,35 @@ dma_fence_add_callback(struct dma_fence |
403 | | | 403 | |
404 | /* Acquire the lock. */ | | 404 | /* Acquire the lock. */ |
405 | spin_lock(fence->lock); | | 405 | spin_lock(fence->lock); |
406 | | | 406 | |
407 | /* Ensure signalling is enabled, or fail if we can't. */ | | 407 | /* Ensure signalling is enabled, or fail if we can't. */ |
408 | ret = dma_fence_ensure_signal_enabled(fence); | | 408 | ret = dma_fence_ensure_signal_enabled(fence); |
409 | if (ret) | | 409 | if (ret) |
410 | goto out1; | | 410 | goto out1; |
411 | | | 411 | |
412 | /* Insert the callback. */ | | 412 | /* Insert the callback. */ |
413 | fcb->func = fn; | | 413 | fcb->func = fn; |
414 | TAILQ_INSERT_TAIL(&fence->f_callbacks, fcb, fcb_entry); | | 414 | TAILQ_INSERT_TAIL(&fence->f_callbacks, fcb, fcb_entry); |
415 | fcb->fcb_onqueue = true; | | 415 | fcb->fcb_onqueue = true; |
| | | 416 | ret = 0; |
416 | | | 417 | |
417 | /* Release the lock and we're done. */ | | 418 | /* Release the lock and we're done. */ |
418 | out1: spin_unlock(fence->lock); | | 419 | out1: spin_unlock(fence->lock); |
419 | out0: return ret; | | 420 | out0: if (ret) { |
| | | 421 | fcb->func = NULL; |
| | | 422 | fcb->fcb_onqueue = false; |
| | | 423 | } |
| | | 424 | return ret; |
420 | } | | 425 | } |
421 | | | 426 | |
422 | /* | | 427 | /* |
423 | * dma_fence_remove_callback(fence, fcb) | | 428 | * dma_fence_remove_callback(fence, fcb) |
424 | * | | 429 | * |
425 | * Remove the callback fcb from fence. Return true if it was | | 430 | * Remove the callback fcb from fence. Return true if it was |
426 | * removed from the list, or false if it had already run and so | | 431 | * removed from the list, or false if it had already run and so |
427 | * was no longer queued anyway. Caller must have already called | | 432 | * was no longer queued anyway. Caller must have already called |
428 | * dma_fence_add_callback(fence, fcb). | | 433 | * dma_fence_add_callback(fence, fcb). |
429 | */ | | 434 | */ |
430 | bool | | 435 | bool |
431 | dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *fcb) | | 436 | dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *fcb) |
432 | { | | 437 | { |