Module Name:    src
Committed By:   riastradh
Date:           Sun Dec 19 10:58:04 UTC 2021

Modified Files:
        src/sys/external/bsd/drm2/include/linux: dma-fence.h
        src/sys/external/bsd/drm2/linux: linux_dma_fence.c

Log Message:
Teach dma_fence_any_wait_timeout to return index of signalled fence.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 \
    src/sys/external/bsd/drm2/include/linux/dma-fence.h
cvs rdiff -u -r1.10 -r1.11 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/include/linux/dma-fence.h
diff -u src/sys/external/bsd/drm2/include/linux/dma-fence.h:1.10 src/sys/external/bsd/drm2/include/linux/dma-fence.h:1.11
--- src/sys/external/bsd/drm2/include/linux/dma-fence.h:1.10	Sun Dec 19 10:50:03 2021
+++ src/sys/external/bsd/drm2/include/linux/dma-fence.h	Sun Dec 19 10:58:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: dma-fence.h,v 1.10 2021/12/19 10:50:03 riastradh Exp $	*/
+/*	$NetBSD: dma-fence.h,v 1.11 2021/12/19 10:58:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -139,7 +139,8 @@ int	dma_fence_signal(struct dma_fence *)
 int	dma_fence_signal_locked(struct dma_fence *);
 long	dma_fence_default_wait(struct dma_fence *, bool, long);
 long	dma_fence_wait(struct dma_fence *, bool);
-long	dma_fence_wait_any_timeout(struct dma_fence **, uint32_t, bool, long);
+long	dma_fence_wait_any_timeout(struct dma_fence **, uint32_t, bool, long,
+	    uint32_t *);
 long	dma_fence_wait_timeout(struct dma_fence *, bool, long);
 
 static inline void __printflike(2, 3)

Index: src/sys/external/bsd/drm2/linux/linux_dma_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.10 src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.11
--- src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.10	Sun Dec 19 10:50:03 2021
+++ src/sys/external/bsd/drm2/linux/linux_dma_fence.c	Sun Dec 19 10:58:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_dma_fence.c,v 1.10 2021/12/19 10:50:03 riastradh Exp $	*/
+/*	$NetBSD: linux_dma_fence.c,v 1.11 2021/12/19 10:58:04 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.10 2021/12/19 10:50:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.11 2021/12/19 10:58:04 riastradh Exp $");
 
 #include <sys/atomic.h>
 #include <sys/condvar.h>
@@ -589,6 +589,8 @@ struct wait_any {
 		kmutex_t	lock;
 		kcondvar_t	cv;
 		bool		done;
+		uint32_t	*ip;
+		struct wait_any	*cb;
 	}		*common;
 };
 
@@ -601,19 +603,22 @@ wait_any_cb(struct dma_fence *fence, str
 
 	mutex_enter(&cb->common->lock);
 	cb->common->done = true;
+	if (cb->common->ip)
+		*cb->common->ip = cb - cb->common->cb;
 	cv_broadcast(&cb->common->cv);
 	mutex_exit(&cb->common->lock);
 }
 
 /*
- * dma_fence_wait_any_timeout(fence, nfences, intr, timeout)
+ * dma_fence_wait_any_timeout(fence, nfences, intr, timeout, ip)
  *
  *	Wait for any of fences[0], fences[1], fences[2], ...,
- *	fences[nfences-1] to be signaled.
+ *	fences[nfences-1] to be signaled.  If ip is nonnull, set *ip to
+ *	the index of the first one.
  */
 long
 dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t nfences,
-    bool intr, long timeout)
+    bool intr, long timeout, uint32_t *ip)
 {
 	struct wait_any1 common;
 	struct wait_any *cb;
@@ -632,6 +637,8 @@ dma_fence_wait_any_timeout(struct dma_fe
 	mutex_init(&common.lock, MUTEX_DEFAULT, IPL_VM);
 	cv_init(&common.cv, "fence");
 	common.done = false;
+	common.ip = ip;
+	common.cb = cb;
 
 	/* Add a callback to each of the fences, or stop here if we can't.  */
 	for (i = 0; i < nfences; i++) {
@@ -649,8 +656,12 @@ dma_fence_wait_any_timeout(struct dma_fe
 	 * notified by one of the callbacks when they have.
 	 */
 	for (j = 0; j < nfences; j++) {
-		if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fences[j]->flags))
+		if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &fences[j]->flags)) {
+			if (ip)
+				*ip = j;
+			ret = 0;
 			goto out1;
+		}
 	}
 
 	/*

Reply via email to