Module Name: src
Committed By: riastradh
Date: Thu Sep 1 01:54:38 UTC 2022
Modified Files:
src/sys/external/bsd/drm2/include/linux: dma-fence.h
src/sys/external/bsd/drm2/linux: linux_dma_fence.c linux_module.c
Log Message:
drm: Fix dma fence stub so it works with locking operations.
To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 \
src/sys/external/bsd/drm2/include/linux/dma-fence.h
cvs rdiff -u -r1.40 -r1.41 src/sys/external/bsd/drm2/linux/linux_dma_fence.c
cvs rdiff -u -r1.13 -r1.14 src/sys/external/bsd/drm2/linux/linux_module.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.16 src/sys/external/bsd/drm2/include/linux/dma-fence.h:1.17
--- src/sys/external/bsd/drm2/include/linux/dma-fence.h:1.16 Sun Dec 19 12:39:24 2021
+++ src/sys/external/bsd/drm2/include/linux/dma-fence.h Thu Sep 1 01:54:38 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: dma-fence.h,v 1.16 2021/12/19 12:39:24 riastradh Exp $ */
+/* $NetBSD: dma-fence.h,v 1.17 2022/09/01 01:54:38 riastradh Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -115,6 +115,9 @@ struct dma_fence_cb {
extern int linux_dma_fence_trace;
+void linux_dma_fences_init(void);
+void linux_dma_fences_fini(void);
+
void dma_fence_init(struct dma_fence *, const struct dma_fence_ops *,
spinlock_t *, uint64_t, uint64_t);
void dma_fence_reset(struct dma_fence *, const struct dma_fence_ops *,
Index: src/sys/external/bsd/drm2/linux/linux_dma_fence.c
diff -u src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.40 src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.41
--- src/sys/external/bsd/drm2/linux/linux_dma_fence.c:1.40 Sat Apr 9 23:44:44 2022
+++ src/sys/external/bsd/drm2/linux/linux_dma_fence.c Thu Sep 1 01:54:38 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_dma_fence.c,v 1.40 2022/04/09 23:44:44 riastradh Exp $ */
+/* $NetBSD: linux_dma_fence.c,v 1.41 2022/09/01 01:54: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.40 2022/04/09 23:44:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_dma_fence.c,v 1.41 2022/09/01 01:54:38 riastradh Exp $");
#include <sys/atomic.h>
#include <sys/condvar.h>
@@ -95,6 +95,53 @@ SDT_PROBE_DEFINE2(sdt, drm, fence, wait_
*/
int linux_dma_fence_trace = 0;
+static spinlock_t dma_fence_stub_lock;
+static struct dma_fence dma_fence_stub;
+
+static const char *dma_fence_stub_name(struct dma_fence *f)
+{
+
+ KASSERT(f == &dma_fence_stub);
+ return "stub";
+}
+
+static void
+dma_fence_stub_release(struct dma_fence *f)
+{
+
+ KASSERT(f == &dma_fence_stub);
+ dma_fence_destroy(f);
+}
+
+static const struct dma_fence_ops dma_fence_stub_ops = {
+ .get_driver_name = dma_fence_stub_name,
+ .get_timeline_name = dma_fence_stub_name,
+ .release = dma_fence_stub_release,
+};
+
+/*
+ * linux_dma_fences_init(), linux_dma_fences_fini()
+ *
+ * Set up and tear down module state.
+ */
+void
+linux_dma_fences_init(void)
+{
+ int error __diagused;
+
+ dma_fence_init(&dma_fence_stub, &dma_fence_stub_ops,
+ &dma_fence_stub_lock, /*context*/0, /*seqno*/0);
+ error = dma_fence_signal(&dma_fence_stub);
+ KASSERTMSG(error == 0, "error=%d", error);
+}
+
+void
+linux_dma_fences_fini(void)
+{
+
+ dma_fence_put(&dma_fence_stub);
+}
+
/*
* dma_fence_referenced_p(fence)
*
@@ -305,17 +352,6 @@ dma_fence_is_later(struct dma_fence *a,
return __dma_fence_is_later(a->seqno, b->seqno, a->ops);
}
-static const char *dma_fence_stub_name(struct dma_fence *f)
-{
-
- return "stub";
-}
-
-static const struct dma_fence_ops dma_fence_stub_ops = {
- .get_driver_name = dma_fence_stub_name,
- .get_timeline_name = dma_fence_stub_name,
-};
-
/*
* dma_fence_get_stub()
*
@@ -324,22 +360,8 @@ static const struct dma_fence_ops dma_fe
struct dma_fence *
dma_fence_get_stub(void)
{
- /*
- * XXX This probably isn't good enough -- caller may try
- * operations on this that require the lock, which will
- * require us to create and destroy the lock on module
- * load/unload.
- */
- static struct dma_fence fence = {
- .refcount = {1}, /* always referenced */
- .flags = 1u << DMA_FENCE_FLAG_SIGNALED_BIT,
- .ops = &dma_fence_stub_ops,
-#ifdef DIAGNOSTIC
- .f_magic = FENCE_MAGIC_GOOD,
-#endif
- };
- return dma_fence_get(&fence);
+ return dma_fence_get(&dma_fence_stub);
}
/*
Index: src/sys/external/bsd/drm2/linux/linux_module.c
diff -u src/sys/external/bsd/drm2/linux/linux_module.c:1.13 src/sys/external/bsd/drm2/linux/linux_module.c:1.14
--- src/sys/external/bsd/drm2/linux/linux_module.c:1.13 Sun Dec 19 12:23:07 2021
+++ src/sys/external/bsd/drm2/linux/linux_module.c Thu Sep 1 01:54:38 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_module.c,v 1.13 2021/12/19 12:23:07 riastradh Exp $ */
+/* $NetBSD: linux_module.c,v 1.14 2022/09/01 01:54:38 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_module.c,v 1.13 2021/12/19 12:23:07 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_module.c,v 1.14 2022/09/01 01:54:38 riastradh Exp $");
#include <sys/module.h>
#ifndef _MODULE
@@ -38,6 +38,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_module
#endif
#include <linux/atomic.h>
+#include <linux/dma-fence.h>
#include <linux/highmem.h>
#include <linux/idr.h>
#include <linux/io.h>
@@ -112,6 +113,7 @@ linux_init(void)
}
linux_irq_work_init();
+ linux_dma_fences_init();
return 0;
@@ -145,6 +147,7 @@ static void
linux_fini(void)
{
+ linux_dma_fences_fini();
linux_irq_work_fini();
linux_kthread_fini();
linux_wait_bit_fini();