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/dist/drm/vmwgfx vmwgfx(4): Convert fen...



details:   https://anonhg.NetBSD.org/src/rev/e089e35999fe
branches:  trunk
changeset: 372022:e089e35999fe
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Tue Oct 25 23:34:05 2022 +0000

description:
vmwgfx(4): Convert fence_queue and fifo_queue to drm_waitqueue_t.

diffstat:

 sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.c     |  20 +++-
 sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h     |   4 +-
 sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c |   6 +-
 sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fence.c   |  46 +++++++-
 sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fifo.c    |  67 ++++++++++--
 sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_irq.c     |  94 ++++++++++++++---
 6 files changed, 197 insertions(+), 40 deletions(-)

diffs (truncated from 558 to 300 lines):

diff -r d1485c096f41 -r e089e35999fe sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.c
--- a/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.c        Tue Oct 25 23:33:44 2022 +0000
+++ b/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.c        Tue Oct 25 23:34:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmwgfx_drv.c,v 1.5 2022/02/17 01:21:02 riastradh Exp $ */
+/*     $NetBSD: vmwgfx_drv.c,v 1.6 2022/10/25 23:34:05 riastradh Exp $ */
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
@@ -28,7 +28,7 @@
  **************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_drv.c,v 1.5 2022/02/17 01:21:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_drv.c,v 1.6 2022/10/25 23:34:05 riastradh Exp $");
 
 #include <linux/console.h>
 #include <linux/dma-mapping.h>
@@ -655,8 +655,10 @@
                INIT_LIST_HEAD(&dev_priv->res_lru[i]);
        }
 
-       init_waitqueue_head(&dev_priv->fence_queue);
-       init_waitqueue_head(&dev_priv->fifo_queue);
+       DRM_INIT_WAITQUEUE(&dev_priv->fence_queue, "vmwgfence");
+       spin_lock_init(&dev_priv->fence_lock);
+       DRM_INIT_WAITQUEUE(&dev_priv->fifo_queue, "vmwgfifo");
+       spin_lock_init(&dev_priv->fifo_lock);
        dev_priv->fence_queue_waiters = 0;
        dev_priv->fifo_queue_waiters = 0;
 
@@ -963,6 +965,11 @@
 out_err4:
        memunmap(dev_priv->mmio_virt);
 out_err0:
+       spin_lock_destroy(&dev_priv->fifo_lock);
+       DRM_DESTROY_WAITQUEUE(&dev_priv->fifo_queue);
+       spin_lock_destroy(&dev_priv->fence_lock);
+       DRM_DESTROY_WAITQUEUE(&dev_priv->fence_queue);
+
        for (i = vmw_res_context; i < vmw_res_max; ++i)
                idr_destroy(&dev_priv->res_idr[i]);
 
@@ -1015,6 +1022,11 @@
        if (dev_priv->ctx.staged_bindings)
                vmw_binding_state_free(dev_priv->ctx.staged_bindings);
 
+       spin_lock_destroy(&dev_priv->fifo_lock);
+       DRM_DESTROY_WAITQUEUE(&dev_priv->fifo_queue);
+       spin_lock_destroy(&dev_priv->fence_lock);
+       DRM_DESTROY_WAITQUEUE(&dev_priv->fence_queue);
+
        for (i = vmw_res_context; i < vmw_res_max; ++i)
                idr_destroy(&dev_priv->res_idr[i]);
 
diff -r d1485c096f41 -r e089e35999fe sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h
--- a/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h        Tue Oct 25 23:33:44 2022 +0000
+++ b/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_drv.h        Tue Oct 25 23:34:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmwgfx_drv.h,v 1.6 2022/02/17 01:21:02 riastradh Exp $ */
+/*     $NetBSD: vmwgfx_drv.h,v 1.7 2022/10/25 23:34:05 riastradh Exp $ */
 
 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
 /**************************************************************************
@@ -538,7 +538,9 @@
 
        atomic_t marker_seq;
        drm_waitqueue_t fence_queue;
+       spinlock_t fence_lock;
        drm_waitqueue_t fifo_queue;
+       spinlock_t fifo_lock;
        spinlock_t waiter_lock;
        int fence_queue_waiters; /* Protected by waiter_lock */
        int goal_queue_waiters; /* Protected by waiter_lock */
diff -r d1485c096f41 -r e089e35999fe sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c
--- a/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c    Tue Oct 25 23:33:44 2022 +0000
+++ b/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_execbuf.c    Tue Oct 25 23:34:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmwgfx_execbuf.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $     */
+/*     $NetBSD: vmwgfx_execbuf.c,v 1.4 2022/10/25 23:34:05 riastradh Exp $     */
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
@@ -27,7 +27,7 @@
  *
  **************************************************************************/
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_execbuf.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_execbuf.c,v 1.4 2022/10/25 23:34:05 riastradh Exp $");
 
 #include <linux/sync_file.h>
 
@@ -3447,8 +3447,10 @@
 
                fence_rep.handle = fence_handle;
                fence_rep.seqno = fence->base.seqno;
+               spin_lock(&dev_priv->fence_lock);
                vmw_update_seqno(dev_priv, &dev_priv->fifo);
                fence_rep.passed_seqno = dev_priv->last_read_seqno;
+               spin_unlock(&dev_priv->fence_lock);
        }
 
        /*
diff -r d1485c096f41 -r e089e35999fe sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fence.c
--- a/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fence.c      Tue Oct 25 23:33:44 2022 +0000
+++ b/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fence.c      Tue Oct 25 23:34:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmwgfx_fence.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $       */
+/*     $NetBSD: vmwgfx_fence.c,v 1.4 2022/10/25 23:34:05 riastradh Exp $       */
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
@@ -28,12 +28,14 @@
  **************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_fence.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_fence.c,v 1.4 2022/10/25 23:34:05 riastradh Exp $");
 
 #include <linux/sched/signal.h>
 
 #include "vmwgfx_drv.h"
 
+#include <linux/nbsd-namespace.h>
+
 #define VMW_FENCE_WRAP (1 << 31)
 
 struct vmw_fence_manager {
@@ -158,7 +160,11 @@
 
 struct vmwgfx_wait_cb {
        struct dma_fence_cb base;
+#ifdef __NetBSD__
+       drm_waitqueue_t wq;
+#else
        struct task_struct *task;
+#endif
 };
 
 static void
@@ -167,7 +173,11 @@
        struct vmwgfx_wait_cb *wait =
                container_of(cb, struct vmwgfx_wait_cb, base);
 
+#ifdef __NetBSD__
+       DRM_SPIN_WAKEUP_ALL(&wait->wq, fence->lock);
+#else
        wake_up_process(wait->task);
+#endif
 }
 
 static void __vmw_fences_update(struct vmw_fence_manager *fman);
@@ -198,10 +208,26 @@
                goto out;
        }
 
-       cb.base.func = vmwgfx_wait_cb;
+#ifdef __NetBSD__
+       DRM_INIT_WAITQUEUE(&cb.wq, "vmwgfxwf");
+#else
        cb.task = current;
-       list_add(&cb.base.node, &f->cb_list);
+#endif
+       spin_unlock(f->lock);
+       ret = dma_fence_add_callback(f, &cb.base, vmwgfx_wait_cb);
+       spin_lock(f->lock);
+       if (ret)
+               goto out;
 
+#ifdef __NetBSD__
+#define        C       (__vmw_fences_update(fman), dma_fence_is_signaled_locked(f))
+       if (intr) {
+               DRM_SPIN_TIMED_WAIT_UNTIL(ret, &cb.wq, f->lock, timeout, C);
+       } else {
+               DRM_SPIN_TIMED_WAIT_NOINTR_UNTIL(ret, &cb.wq, f->lock, timeout,
+                   C);
+       }
+#else
        for (;;) {
                __vmw_fences_update(fman);
 
@@ -238,9 +264,16 @@
        __set_current_state(TASK_RUNNING);
        if (!list_empty(&cb.base.node))
                list_del(&cb.base.node);
+#endif
+       spin_unlock(f->lock);
+       dma_fence_remove_callback(f, &cb.base);
+       spin_lock(f->lock);
 
 out:
        spin_unlock(f->lock);
+#ifdef __NetBSD__
+       DRM_DESTROY_WAITQUEUE(&cb.wq);
+#endif
 
        vmw_seqno_waiter_remove(dev_priv);
 
@@ -878,8 +911,11 @@
        arg->signaled = vmw_fence_obj_signaled(fence);
 
        arg->signaled_flags = arg->flags;
+       spin_lock(&dev_priv->fence_lock);
+       const u32 seqno = dev_priv->last_read_seqno;
+       spin_unlock(&dev_priv->fence_lock);
        spin_lock(&fman->lock);
-       arg->passed_seqno = dev_priv->last_read_seqno;
+       arg->passed_seqno = seqno;
        spin_unlock(&fman->lock);
 
        ttm_base_object_unref(&base);
diff -r d1485c096f41 -r e089e35999fe sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fifo.c
--- a/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fifo.c       Tue Oct 25 23:33:44 2022 +0000
+++ b/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fifo.c       Tue Oct 25 23:34:05 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmwgfx_fifo.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $        */
+/*     $NetBSD: vmwgfx_fifo.c,v 1.4 2022/10/25 23:34:06 riastradh Exp $        */
 
 // SPDX-License-Identifier: GPL-2.0 OR MIT
 /**************************************************************************
@@ -28,7 +28,7 @@
  **************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vmwgfx_fifo.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmwgfx_fifo.c,v 1.4 2022/10/25 23:34:06 riastradh Exp $");
 
 #include <linux/sched/signal.h>
 
@@ -36,6 +36,8 @@
 
 #include "vmwgfx_drv.h"
 
+#include <linux/nbsd-namespace.h>
+
 struct vmw_temp_set_context {
        SVGA3dCmdHeader header;
        SVGA3dCmdDXTempSetContext body;
@@ -227,14 +229,20 @@
 {
        int ret = 0;
        unsigned long end_jiffies = jiffies + timeout;
+#ifdef __NetBSD__
+       assert_spin_locked(&dev_priv->fifo_lock);
+#else
        DEFINE_WAIT(__wait);
+#endif
 
        DRM_INFO("Fifo wait noirq.\n");
 
        for (;;) {
+#ifndef __NetBSD__
                prepare_to_wait(&dev_priv->fifo_queue, &__wait,
                                (interruptible) ?
                                TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
+#endif
                if (!vmw_fifo_is_full(dev_priv, bytes))
                        break;
                if (time_after_eq(jiffies, end_jiffies)) {
@@ -242,14 +250,40 @@
                        DRM_ERROR("SVGA device lockup.\n");
                        break;
                }
+#ifdef __NetBSD__
+               if (interruptible) {
+                       DRM_SPIN_TIMED_WAIT_UNTIL(ret, &dev_priv->fifo_queue,
+                           &dev_priv->fifo_lock, 1,
+                           !vmw_fifo_is_full(dev_priv, bytes));
+               } else {
+                       DRM_SPIN_TIMED_WAIT_NOINTR_UNTIL(ret,
+                           &dev_priv->fifo_queue,
+                           &dev_priv->fifo_lock, 1,
+                           !vmw_fifo_is_full(dev_priv, bytes));
+               }
+               if (ret) {
+                       if (ret > 0) /* success */
+                               ret = 0;
+                       break;
+               }
+               /*
+                * ret=0 means the wait timed out after one tick, so
+                * try again
+                */
+#else
                schedule_timeout(1);
                if (interruptible && signal_pending(current)) {
                        ret = -ERESTARTSYS;
                        break;
                }
+#endif
        }
+#ifdef __NetBSD__
+       DRM_SPIN_WAKEUP_ALL(&dev_priv->fifo_queue, &dev_priv->fifo_lock);
+#else
        finish_wait(&dev_priv->fifo_queue, &__wait);
        wake_up_all(&dev_priv->fifo_queue);
+#endif
        DRM_INFO("Fifo noirq exit.\n");
        return ret;
 }



Home | Main Index | Thread Index | Old Index