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/drm Take a stab at implementing drm_id...



details:   https://anonhg.NetBSD.org/src/rev/ef4ec1866e79
branches:  trunk
changeset: 344507:ef4ec1866e79
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Apr 02 22:40:43 2016 +0000

description:
Take a stab at implementing drm_idlelock_take/release.

Evidently needed by VIA DRM/UMS.  Noted and tested by medfly/coypu.

diffstat:

 sys/external/bsd/drm2/drm/drm_lock.c |  49 ++++++++++++++++++++++++-----------
 1 files changed, 34 insertions(+), 15 deletions(-)

diffs (79 lines):

diff -r a0f00bf771b2 -r ef4ec1866e79 sys/external/bsd/drm2/drm/drm_lock.c
--- a/sys/external/bsd/drm2/drm/drm_lock.c      Sat Apr 02 22:37:03 2016 +0000
+++ b/sys/external/bsd/drm2/drm/drm_lock.c      Sat Apr 02 22:40:43 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_lock.c,v 1.3 2014/07/16 20:56:25 riastradh Exp $   */
+/*     $NetBSD: drm_lock.c,v 1.4 2016/04/02 22:40:43 riastradh Exp $   */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_lock.c,v 1.3 2014/07/16 20:56:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_lock.c,v 1.4 2016/04/02 22:40:43 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/errno.h>
@@ -232,28 +232,47 @@
 }
 
 /*
- * Take the lock for the kernel's use.
- *
- * XXX This is unimplemented because it's not clear that the Linux code
- * makes sense at all.  Linux's drm_idlelock_take never blocks, but it
- * doesn't guarantee that the kernel holds the lock on return!  For
- * now, I'll hope that the code paths relying on this don't matter yet.
+ * Try to acquire the lock.  Whether or not we acquire it, guarantee
+ * that whoever next releases it relinquishes it to the kernel, not to
+ * anyone else.
  */
 void
-drm_idlelock_take(struct drm_lock_data *lock_data __unused)
+drm_idlelock_take(struct drm_lock_data *lock_data)
 {
-       KASSERT(mutex_is_locked(&drm_global_mutex));
-       panic("drm_idlelock_take is not yet implemented"); /* XXX */
+
+       spin_lock(&lock_data->spinlock);
+       KASSERT(!lock_data->idle_has_lock);
+       KASSERT(lock_data->kernel_waiters < UINT32_MAX);
+       lock_data->kernel_waiters++;
+       /* Try to acquire the lock.  */
+       if (drm_lock_acquire(lock_data, DRM_KERNEL_CONTEXT)) {
+               lock_data->idle_has_lock = 1;
+       } else {
+               /*
+                * Recording that there are kernel waiters will prevent
+                * userland from acquiring the lock again when it is
+                * next released.
+                */
+       }
+       spin_unlock(&lock_data->spinlock);
 }
 
 /*
- * Release the lock from the kernel.
+ * Release whatever drm_idlelock_take managed to acquire.
  */
 void
-drm_idlelock_release(struct drm_lock_data *lock_data __unused)
+drm_idlelock_release(struct drm_lock_data *lock_data)
 {
-       KASSERT(mutex_is_locked(&drm_global_mutex));
-       panic("drm_idlelock_release is not yet implemented"); /* XXX */
+
+       spin_lock(&lock_data->spinlock);
+       KASSERT(0 < lock_data->kernel_waiters);
+       if (--lock_data->kernel_waiters == 0) {
+               if (lock_data->idle_has_lock) {
+                       /* We did acquire it.  Release it.  */
+                       drm_lock_release(lock_data, DRM_KERNEL_CONTEXT);
+               }
+       }
+       spin_unlock(&lock_data->spinlock);
 }
 
 /*



Home | Main Index | Thread Index | Old Index