diff options
| author | riastradh <riastradh@NetBSD.org> | 2022-09-01 01:54:38 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2022-09-01 01:54:38 +0000 |
| commit | 596f9901da32b0ec91a0fa0090a284048c025ecd (patch) | |
| tree | ac2de4877ecd31a6b48ae6fb8f51446650b423e1 /sys | |
| parent | 9c3b488cfafb80791376e45ddeb17d4cfc93335b (diff) | |
drm: Fix dma fence stub so it works with locking operations.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/external/bsd/drm2/include/linux/dma-fence.h | 5 | ||||
| -rw-r--r-- | sys/external/bsd/drm2/linux/linux_dma_fence.c | 78 | ||||
| -rw-r--r-- | sys/external/bsd/drm2/linux/linux_module.c | 7 |
3 files changed, 59 insertions, 31 deletions
diff --git a/sys/external/bsd/drm2/include/linux/dma-fence.h b/sys/external/bsd/drm2/include/linux/dma-fence.h index 0dce8eed867..26cecc5820d 100644 --- a/sys/external/bsd/drm2/include/linux/dma-fence.h +++ b/sys/external/bsd/drm2/include/linux/dma-fence.h @@ -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 *, diff --git a/sys/external/bsd/drm2/linux/linux_dma_fence.c b/sys/external/bsd/drm2/linux/linux_dma_fence.c index 32d57b2977f..34831ad3012 100644 --- a/sys/external/bsd/drm2/linux/linux_dma_fence.c +++ b/sys/external/bsd/drm2/linux/linux_dma_fence.c @@ -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_done, */ 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, struct dma_fence *b) 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_fence_stub_ops = { 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 --git a/sys/external/bsd/drm2/linux/linux_module.c b/sys/external/bsd/drm2/linux/linux_module.c index 4858e68b4df..63480eb9263 100644 --- a/sys/external/bsd/drm2/linux/linux_module.c +++ b/sys/external/bsd/drm2/linux/linux_module.c @@ -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.c,v 1.13 2021/12/19 12:23:07 riastradh #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(); |
