Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd/drm2/linux drm: Fix dma fence stub so it wo...



details:   https://anonhg.NetBSD.org/src/rev/4864fda28454
branches:  trunk
changeset: 369782:4864fda28454
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Sep 01 01:54:38 2022 +0000

description:
drm: Fix dma fence stub so it works with locking operations.

diffstat:

 sys/external/bsd/drm2/include/linux/dma-fence.h |   5 +-
 sys/external/bsd/drm2/linux/linux_dma_fence.c   |  78 ++++++++++++++++--------
 sys/external/bsd/drm2/linux/linux_module.c      |   7 +-
 3 files changed, 59 insertions(+), 31 deletions(-)

diffs (175 lines):

diff -r ebbdebff67fd -r 4864fda28454 sys/external/bsd/drm2/include/linux/dma-fence.h
--- a/sys/external/bsd/drm2/include/linux/dma-fence.h   Thu Sep 01 01:54:28 2022 +0000
+++ b/sys/external/bsd/drm2/include/linux/dma-fence.h   Thu Sep 01 01:54:38 2022 +0000
@@ -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 @@
 
 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 *,
diff -r ebbdebff67fd -r 4864fda28454 sys/external/bsd/drm2/linux/linux_dma_fence.c
--- a/sys/external/bsd/drm2/linux/linux_dma_fence.c     Thu Sep 01 01:54:28 2022 +0000
+++ b/sys/external/bsd/drm2/linux/linux_dma_fence.c     Thu Sep 01 01:54:38 2022 +0000
@@ -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 @@
  */
 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 @@
        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 @@
 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);
 }
 
 /*
diff -r ebbdebff67fd -r 4864fda28454 sys/external/bsd/drm2/linux/linux_module.c
--- a/sys/external/bsd/drm2/linux/linux_module.c        Thu Sep 01 01:54:28 2022 +0000
+++ b/sys/external/bsd/drm2/linux/linux_module.c        Thu Sep 01 01:54:38 2022 +0000
@@ -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 @@
 #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_irq_work_init();
+       linux_dma_fences_init();
 
        return 0;
 
@@ -145,6 +147,7 @@
 linux_fini(void)
 {
 
+       linux_dma_fences_fini();
        linux_irq_work_fini();
        linux_kthread_fini();
        linux_wait_bit_fini();



Home | Main Index | Thread Index | Old Index