Module Name: src Committed By: riastradh Date: Sun Dec 19 12:07:39 UTC 2021
Modified Files: src/sys/external/bsd/drm2/linux: linux_dma_fence.c Log Message: drm: Rework enable-signal logic to match Linux. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/sys/external/bsd/drm2/linux/linux_dma_fence.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/drm2/linux/linux_dma_fence.c diff -u src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.19 src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.20 --- src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.19 Sun Dec 19 12:02:40 2021 +++ src/sys/external/bsd/drm2/linux/linux_dma_fence.c Sun Dec 19 12:07:38 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: linux_dma_fence.c,v 1.19 2021/12/19 12:02:40 riastradh Exp $ */ +/* $NetBSD: linux_dma_fence.c,v 1.20 2021/12/19 12:07:38 riastradh Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.19 2021/12/19 12:02:40 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.20 2021/12/19 12:07:38 riastradh Exp $"); #include <sys/atomic.h> #include <sys/condvar.h> @@ -344,27 +344,31 @@ dma_fence_put(struct dma_fence *fence) static int dma_fence_ensure_signal_enabled(struct dma_fence *fence) { + bool already_enabled; KASSERT(dma_fence_referenced_p(fence)); KASSERT(spin_is_locked(fence->lock)); + /* Determine whether signalling was enabled, and enable it. */ + already_enabled = test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, + &fence->flags); + /* If the fence was already signalled, fail with -ENOENT. */ if (fence->flags & (1u << DMA_FENCE_FLAG_SIGNALED_BIT)) return -ENOENT; /* - * If the enable signaling callback has been called, success. - * Otherwise, set the bit indicating it. + * Otherwise, if it wasn't enabled yet, try to enable + * signalling, or fail if the fence doesn't support that. */ - if (test_and_set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &fence->flags)) - return 0; - - /* Otherwise, note that we've called it and call it. */ - KASSERT(fence->ops->enable_signaling); - if (!(*fence->ops->enable_signaling)(fence)) { - /* If it failed, signal and return -ENOENT. */ - dma_fence_signal_locked(fence); - return -ENOENT; + if (!already_enabled) { + if (fence->ops->enable_signaling == NULL) + return -ENOENT; + if (!(*fence->ops->enable_signaling)(fence)) { + /* If it failed, signal and return -ENOENT. */ + dma_fence_signal_locked(fence); + return -ENOENT; + } } /* Success! */