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: Merge vbl_lock into event_lock.



details:   https://anonhg.NetBSD.org/src/rev/17fcf2804423
branches:  trunk
changeset: 1028808:17fcf2804423
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 12:05:08 2021 +0000

description:
drm: Merge vbl_lock into event_lock.

These aren't functionally very different, and most uses of vbl_lock
were inserted as local changes to make proper condition variables
anyway.  Requiring both locks made cv_wait difficult because it only
unlocks and relocks one at a time, and this also led to annoying lock
order reversal.

diffstat:

 sys/external/bsd/drm2/dist/drm/drm_atomic_helper.c         |   11 +-
 sys/external/bsd/drm2/dist/drm/drm_irq.c                   |   11 +-
 sys/external/bsd/drm2/dist/drm/drm_vblank.c                |  100 +++++++-----
 sys/external/bsd/drm2/dist/drm/i915/display/intel_sprite.c |   19 +-
 sys/external/bsd/drm2/dist/include/drm/drm_device.h        |    4 +-
 sys/external/bsd/drm2/dist/include/drm/drm_vblank.h        |    3 +-
 6 files changed, 85 insertions(+), 63 deletions(-)

diffs (truncated from 545 to 300 lines):

diff -r 5fd887410d5f -r 17fcf2804423 sys/external/bsd/drm2/dist/drm/drm_atomic_helper.c
--- a/sys/external/bsd/drm2/dist/drm/drm_atomic_helper.c        Sun Dec 19 12:04:59 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_atomic_helper.c        Sun Dec 19 12:05:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_atomic_helper.c,v 1.8 2021/12/19 00:55:43 riastradh Exp $  */
+/*     $NetBSD: drm_atomic_helper.c,v 1.9 2021/12/19 12:05:08 riastradh Exp $  */
 
 /*
  * Copyright (C) 2014 Red Hat
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_atomic_helper.c,v 1.8 2021/12/19 00:55:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_atomic_helper.c,v 1.9 2021/12/19 12:05:08 riastradh Exp $");
 
 #include <linux/dma-fence.h>
 #include <linux/ktime.h>
@@ -1466,12 +1466,13 @@
                        continue;
 
 #ifdef __NetBSD__
-               spin_lock(&dev->vbl_lock);
-               DRM_SPIN_WAIT_ON(ret, &dev->vblank[i].queue, &dev->vbl_lock,
+               spin_lock(&dev->event_lock);
+               DRM_SPIN_WAIT_ON(ret, &dev->vblank[i].queue,
+                   &dev->event_lock,
                    msecs_to_jiffies(50),
                    (old_state->crtcs[i].last_vblank_count !=
                        drm_crtc_vblank_count(crtc)));
-               spin_unlock(&dev->vbl_lock);
+               spin_unlock(&dev->event_lock);
 #else
                ret = wait_event_timeout(dev->vblank[i].queue,
                                old_state->crtcs[i].last_vblank_count !=
diff -r 5fd887410d5f -r 17fcf2804423 sys/external/bsd/drm2/dist/drm/drm_irq.c
--- a/sys/external/bsd/drm2/dist/drm/drm_irq.c  Sun Dec 19 12:04:59 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_irq.c  Sun Dec 19 12:05:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_irq.c,v 1.17 2021/12/18 23:44:57 riastradh Exp $   */
+/*     $NetBSD: drm_irq.c,v 1.18 2021/12/19 12:05:08 riastradh Exp $   */
 
 /*
  * drm_irq.c IRQ and vblank support
@@ -55,7 +55,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_irq.c,v 1.17 2021/12/18 23:44:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_irq.c,v 1.18 2021/12/19 12:05:08 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/interrupt.h>   /* For task queue support */
@@ -215,7 +215,7 @@
         * disabled when uninstalling the irq handler.
         */
        if (dev->num_crtcs) {
-               spin_lock_irqsave(&dev->vbl_lock, irqflags);
+               spin_lock_irqsave(&dev->event_lock, irqflags);
                for (i = 0; i < dev->num_crtcs; i++) {
                        struct drm_vblank_crtc *vblank = &dev->vblank[i];
 
@@ -226,12 +226,13 @@
 
                        drm_vblank_disable_and_save(dev, i);
 #ifdef __NetBSD__
-                       DRM_SPIN_WAKEUP_ONE(&vblank->queue, &dev->vbl_lock);
+                       DRM_SPIN_WAKEUP_ONE(&vblank->queue,
+                           &dev->event_lock);
 #else
                        wake_up(&vblank->queue);
 #endif
                }
-               spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+               spin_unlock_irqrestore(&dev->event_lock, irqflags);
        }
 
        if (!irq_enabled)
diff -r 5fd887410d5f -r 17fcf2804423 sys/external/bsd/drm2/dist/drm/drm_vblank.c
--- a/sys/external/bsd/drm2/dist/drm/drm_vblank.c       Sun Dec 19 12:04:59 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_vblank.c       Sun Dec 19 12:05:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_vblank.c,v 1.11 2021/12/19 11:55:47 riastradh Exp $        */
+/*     $NetBSD: drm_vblank.c,v 1.12 2021/12/19 12:05:08 riastradh Exp $        */
 
 /*
  * drm_irq.c IRQ and vblank support
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_vblank.c,v 1.11 2021/12/19 11:55:47 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_vblank.c,v 1.12 2021/12/19 12:05:08 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/moduleparam.h>
@@ -76,7 +76,7 @@
  * vblanks after a timer has expired, which can be configured through the
  * ``vblankoffdelay`` module parameter.
  *
- * Lock order: event_lock -> vbl_lock -> vblank_time_lock
+ * Lock order: event_lock -> vblank_time_lock
  */
 
 /* Retry timestamp calculation up to 3 times to satisfy
@@ -169,7 +169,7 @@
        ktime_t t_vblank;
        int count = DRM_TIMESTAMP_MAXRETRIES;
 
-       assert_spin_locked(&dev->vbl_lock);
+       assert_spin_locked(&dev->event_lock);
 
        spin_lock(&dev->vblank_time_lock);
 
@@ -222,7 +222,7 @@
        int framedur_ns = vblank->framedur_ns;
        u32 max_vblank_count = drm_max_vblank_count(dev, pipe);
 
-       assert_spin_locked(&dev->vbl_lock);
+       assert_spin_locked(&dev->event_lock);
 
        /*
         * Interrupts were disabled prior to this call, so deal with counter
@@ -337,24 +337,35 @@
  * This is mostly useful for hardware that can obtain the scanout position, but
  * doesn't have a hardware frame counter.
  */
-u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
+static u64 drm_crtc_accurate_vblank_count_locked(struct drm_crtc *crtc)
 {
        struct drm_device *dev = crtc->dev;
        unsigned int pipe = drm_crtc_index(crtc);
        u64 vblank;
        unsigned long flags;
 
+       assert_spin_locked(&dev->event_lock);
+
        WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && !dev->driver->get_vblank_timestamp,
                  "This function requires support for accurate vblank timestamps.");
 
-       spin_lock(&dev->vbl_lock);
        spin_lock_irqsave(&dev->vblank_time_lock, flags);
 
        drm_update_vblank_count(dev, pipe, false);
        vblank = drm_vblank_count(dev, pipe);
 
        spin_unlock_irqrestore(&dev->vblank_time_lock, flags);
-       spin_unlock(&dev->vbl_lock);
+
+       return vblank;
+}
+
+u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc)
+{
+       u64 vblank;
+
+       spin_lock(&crtc->dev->event_lock);
+       vblank = drm_crtc_accurate_vblank_count_locked(crtc);
+       spin_unlock(&crtc->dev->event_lock);
 
        return vblank;
 }
@@ -388,7 +399,7 @@
        struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
        unsigned long irqflags;
 
-       assert_spin_locked(&dev->vbl_lock);
+       assert_spin_locked(&dev->event_lock);
 
        /* Prevent vblank irq processing while disabling vblank irqs,
         * so no updates of timestamps or count can happen after we've
@@ -425,7 +436,7 @@
 {
 
        BUG_ON(vblank != &dev->vblank[pipe]);
-       assert_spin_locked(&dev->vbl_lock);
+       assert_spin_locked(&dev->event_lock);
 
        if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) {
                DRM_DEBUG("disabling vblank on crtc %u\n", pipe);
@@ -440,12 +451,12 @@
        unsigned int pipe = vblank->pipe;
        unsigned long irqflags;
 
-       spin_lock_irqsave(&dev->vbl_lock, irqflags);
+       spin_lock_irqsave(&dev->event_lock, irqflags);
        if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) {
                DRM_DEBUG("disabling vblank on crtc %u\n", pipe);
                drm_vblank_disable_and_save(dev, pipe);
        }
-       spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+       spin_unlock_irqrestore(&dev->event_lock, irqflags);
 }
 
 void drm_vblank_cleanup(struct drm_device *dev)
@@ -488,7 +499,6 @@
        int ret = -ENOMEM;
        unsigned int i;
 
-       spin_lock_init(&dev->vbl_lock);
        spin_lock_init(&dev->vblank_time_lock);
 
        dev->num_crtcs = num_crtcs;
@@ -960,7 +970,7 @@
        assert_spin_locked(&dev->event_lock);
 
        e->pipe = pipe;
-       e->sequence = drm_crtc_accurate_vblank_count(crtc) + 1;
+       e->sequence = drm_crtc_accurate_vblank_count_locked(crtc) + 1;
        list_add_tail(&e->base.link, &dev->vblank_event_list);
 }
 EXPORT_SYMBOL(drm_crtc_arm_vblank_event);
@@ -1016,7 +1026,7 @@
        struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
        int ret = 0;
 
-       assert_spin_locked(&dev->vbl_lock);
+       assert_spin_locked(&dev->event_lock);
 
        spin_lock(&dev->vblank_time_lock);
 
@@ -1048,19 +1058,19 @@
        return ret;
 }
 
-static int drm_vblank_get(struct drm_device *dev, unsigned int pipe)
+static int drm_vblank_get_locked(struct drm_device *dev, unsigned int pipe)
 {
        struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
-       unsigned long irqflags;
        int ret = 0;
 
+       assert_spin_locked(&dev->event_lock);
+
        if (!dev->num_crtcs)
                return -EINVAL;
 
        if (WARN_ON(pipe >= dev->num_crtcs))
                return -EINVAL;
 
-       spin_lock_irqsave(&dev->vbl_lock, irqflags);
        /* Going from 0->1 means we have to enable interrupts again */
        if (atomic_add_return(1, &vblank->refcount) == 1) {
                ret = drm_vblank_enable(dev, pipe);
@@ -1070,7 +1080,17 @@
                        ret = -EINVAL;
                }
        }
-       spin_unlock_irqrestore(&dev->vbl_lock, irqflags);
+
+       return ret;
+}
+
+static int drm_vblank_get(struct drm_device *dev, unsigned int pipe)
+{
+       int ret;
+
+       spin_lock(&dev->event_lock);
+       ret = drm_vblank_get_locked(dev, pipe);
+       spin_unlock(&dev->event_lock);
 
        return ret;
 }
@@ -1091,11 +1111,17 @@
 }
 EXPORT_SYMBOL(drm_crtc_vblank_get);
 
+int drm_crtc_vblank_get_locked(struct drm_crtc *crtc)
+{
+       return drm_vblank_get_locked(crtc->dev, drm_crtc_index(crtc));
+}
+EXPORT_SYMBOL(drm_crtc_vblank_get_locked);
+
 static void drm_vblank_put_locked(struct drm_device *dev, unsigned int pipe)
 {
        struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 
-       assert_spin_locked(&dev->vbl_lock);
+       assert_spin_locked(&dev->event_lock);
 
        if (WARN_ON(pipe >= dev->num_crtcs))
                return;
@@ -1179,12 +1205,12 @@
        if (WARN(ret, "vblank not available on crtc %i, ret=%i\n", pipe, ret))
                return;
 
-       spin_lock(&dev->vbl_lock);
+       spin_lock(&dev->event_lock);
        last = drm_vblank_count(dev, pipe);
-       DRM_SPIN_TIMED_WAIT_UNTIL(ret, &vblank->queue, &dev->vbl_lock,
+       DRM_SPIN_TIMED_WAIT_UNTIL(ret, &vblank->queue, &dev->event_lock,
            msecs_to_jiffies(100),
            last != drm_vblank_count(dev, pipe));
-       spin_unlock(&dev->vbl_lock);
+       spin_unlock(&dev->event_lock);
 
        WARN(ret == 0, "vblank wait timed out on crtc %i\n", pipe);
 
@@ -1233,7 +1259,6 @@
 



Home | Main Index | Thread Index | Old Index