2005-04-17 00:20:36 +02:00
|
|
|
/**
|
2005-09-25 06:28:13 +02:00
|
|
|
* \file drm_lock.c
|
2005-04-17 00:20:36 +02:00
|
|
|
* IOCTLs for locking
|
2005-09-25 06:28:13 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* \author Rickard E. (Rik) Faith <faith@valinux.com>
|
|
|
|
* \author Gareth Hughes <gareth@valinux.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
|
|
|
|
*
|
|
|
|
* Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
|
|
|
|
* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drmP.h"
|
|
|
|
|
2005-07-07 13:03:38 +02:00
|
|
|
static int drm_notifier(void *priv);
|
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
/**
|
2005-04-17 00:20:36 +02:00
|
|
|
* Lock ioctl.
|
|
|
|
*
|
|
|
|
* \param inode device inode.
|
2007-08-25 12:23:09 +02:00
|
|
|
* \param file_priv DRM file private.
|
2005-04-17 00:20:36 +02:00
|
|
|
* \param cmd command.
|
|
|
|
* \param arg user argument, pointing to a drm_lock structure.
|
|
|
|
* \return zero on success or negative number on failure.
|
|
|
|
*
|
|
|
|
* Add the current task to the lock wait queue, and attempt to take to lock.
|
|
|
|
*/
|
2007-09-03 04:06:45 +02:00
|
|
|
int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2005-09-25 06:28:13 +02:00
|
|
|
DECLARE_WAITQUEUE(entry, current);
|
2007-09-03 04:06:45 +02:00
|
|
|
struct drm_lock *lock = data;
|
2005-09-25 06:28:13 +02:00
|
|
|
int ret = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-08-25 12:23:09 +02:00
|
|
|
++file_priv->lock_count;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-09-03 04:06:45 +02:00
|
|
|
if (lock->context == DRM_KERNEL_CONTEXT) {
|
2005-09-25 06:28:13 +02:00
|
|
|
DRM_ERROR("Process %d using kernel context %d\n",
|
2007-10-19 08:40:40 +02:00
|
|
|
task_pid_nr(current), lock->context);
|
2005-09-25 06:28:13 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
|
2007-10-19 08:40:40 +02:00
|
|
|
lock->context, task_pid_nr(current),
|
2007-09-03 04:06:45 +02:00
|
|
|
dev->lock.hw_lock->lock, lock->flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE))
|
2007-09-03 04:06:45 +02:00
|
|
|
if (lock->context < 0)
|
2005-04-17 00:20:36 +02:00
|
|
|
return -EINVAL;
|
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
add_wait_queue(&dev->lock.lock_queue, &entry);
|
2007-03-23 03:28:33 +01:00
|
|
|
spin_lock(&dev->lock.spinlock);
|
|
|
|
dev->lock.user_waiters++;
|
|
|
|
spin_unlock(&dev->lock.spinlock);
|
2005-04-17 00:20:36 +02:00
|
|
|
for (;;) {
|
|
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2005-09-25 06:28:13 +02:00
|
|
|
if (!dev->lock.hw_lock) {
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Device has been unregistered */
|
|
|
|
ret = -EINTR;
|
|
|
|
break;
|
|
|
|
}
|
2007-09-03 04:06:45 +02:00
|
|
|
if (drm_lock_take(&dev->lock, lock->context)) {
|
2007-08-25 12:23:09 +02:00
|
|
|
dev->lock.file_priv = file_priv;
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->lock.lock_time = jiffies;
|
2005-09-25 06:28:13 +02:00
|
|
|
atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
|
|
|
|
break; /* Got lock */
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2005-09-25 06:28:13 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Contention */
|
|
|
|
schedule();
|
2005-09-25 06:28:13 +02:00
|
|
|
if (signal_pending(current)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-03-23 03:28:33 +01:00
|
|
|
spin_lock(&dev->lock.spinlock);
|
|
|
|
dev->lock.user_waiters--;
|
|
|
|
spin_unlock(&dev->lock.spinlock);
|
2005-04-17 00:20:36 +02:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-09-25 06:28:13 +02:00
|
|
|
remove_wait_queue(&dev->lock.lock_queue, &entry);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-09-03 04:06:45 +02:00
|
|
|
DRM_DEBUG("%d %s\n", lock->context,
|
|
|
|
ret ? "interrupted" : "has lock");
|
2007-03-23 03:28:33 +01:00
|
|
|
if (ret) return ret;
|
2006-01-02 11:32:48 +01:00
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
sigemptyset(&dev->sigmask);
|
|
|
|
sigaddset(&dev->sigmask, SIGSTOP);
|
|
|
|
sigaddset(&dev->sigmask, SIGTSTP);
|
|
|
|
sigaddset(&dev->sigmask, SIGTTIN);
|
|
|
|
sigaddset(&dev->sigmask, SIGTTOU);
|
2007-09-03 04:06:45 +02:00
|
|
|
dev->sigdata.context = lock->context;
|
2005-09-25 06:28:13 +02:00
|
|
|
dev->sigdata.lock = dev->lock.hw_lock;
|
|
|
|
block_all_signals(drm_notifier, &dev->sigdata, &dev->sigmask);
|
|
|
|
|
2007-09-03 04:06:45 +02:00
|
|
|
if (dev->driver->dma_ready && (lock->flags & _DRM_LOCK_READY))
|
2005-04-17 00:20:36 +02:00
|
|
|
dev->driver->dma_ready(dev);
|
2005-09-25 06:28:13 +02:00
|
|
|
|
2007-09-03 04:06:45 +02:00
|
|
|
if (dev->driver->dma_quiescent && (lock->flags & _DRM_LOCK_QUIESCENT))
|
|
|
|
{
|
2006-01-02 11:32:48 +01:00
|
|
|
if (dev->driver->dma_quiescent(dev)) {
|
2007-09-03 04:06:45 +02:00
|
|
|
DRM_DEBUG("%d waiting for DMA quiescent\n",
|
|
|
|
lock->context);
|
2007-08-25 11:22:43 +02:00
|
|
|
return -EBUSY;
|
2006-01-02 11:32:48 +01:00
|
|
|
}
|
|
|
|
}
|
2005-09-25 06:28:13 +02:00
|
|
|
|
|
|
|
if (dev->driver->kernel_context_switch &&
|
2007-09-03 04:06:45 +02:00
|
|
|
dev->last_context != lock->context) {
|
2005-09-25 06:28:13 +02:00
|
|
|
dev->driver->kernel_context_switch(dev, dev->last_context,
|
2007-09-03 04:06:45 +02:00
|
|
|
lock->context);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-03-23 03:28:33 +01:00
|
|
|
|
2006-01-02 11:32:48 +01:00
|
|
|
return 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
/**
|
2005-04-17 00:20:36 +02:00
|
|
|
* Unlock ioctl.
|
|
|
|
*
|
|
|
|
* \param inode device inode.
|
2007-08-25 12:23:09 +02:00
|
|
|
* \param file_priv DRM file private.
|
2005-04-17 00:20:36 +02:00
|
|
|
* \param cmd command.
|
|
|
|
* \param arg user argument, pointing to a drm_lock structure.
|
|
|
|
* \return zero on success or negative number on failure.
|
|
|
|
*
|
|
|
|
* Transfer and free the lock.
|
|
|
|
*/
|
2007-09-03 04:06:45 +02:00
|
|
|
int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-09-03 04:06:45 +02:00
|
|
|
struct drm_lock *lock = data;
|
2006-10-24 20:36:59 +02:00
|
|
|
unsigned long irqflags;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-09-03 04:06:45 +02:00
|
|
|
if (lock->context == DRM_KERNEL_CONTEXT) {
|
2005-09-25 06:28:13 +02:00
|
|
|
DRM_ERROR("Process %d using kernel context %d\n",
|
2007-10-19 08:40:40 +02:00
|
|
|
task_pid_nr(current), lock->context);
|
2005-04-17 00:20:36 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2006-10-24 15:08:16 +02:00
|
|
|
spin_lock_irqsave(&dev->tasklet_lock, irqflags);
|
|
|
|
|
|
|
|
if (dev->locked_tasklet_func) {
|
|
|
|
dev->locked_tasklet_func(dev);
|
|
|
|
|
|
|
|
dev->locked_tasklet_func = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&dev->tasklet_lock, irqflags);
|
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* kernel_context_switch isn't used by any of the x86 drm
|
|
|
|
* modules but is required by the Sparc driver.
|
|
|
|
*/
|
|
|
|
if (dev->driver->kernel_context_switch_unlock)
|
2006-12-19 07:49:44 +01:00
|
|
|
dev->driver->kernel_context_switch_unlock(dev);
|
2005-04-17 00:20:36 +02:00
|
|
|
else {
|
2007-09-03 04:06:45 +02:00
|
|
|
if (drm_lock_free(&dev->lock,lock->context)) {
|
2007-03-23 03:28:33 +01:00
|
|
|
/* FIXME: Should really bail out here. */
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unblock_all_signals();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Take the heavyweight lock.
|
|
|
|
*
|
|
|
|
* \param lock lock pointer.
|
|
|
|
* \param context locking context.
|
|
|
|
* \return one if the lock is held, or zero otherwise.
|
|
|
|
*
|
|
|
|
* Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
|
|
|
|
*/
|
2007-07-11 08:53:40 +02:00
|
|
|
int drm_lock_take(struct drm_lock_data *lock_data,
|
2007-03-23 03:28:33 +01:00
|
|
|
unsigned int context)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned int old, new, prev;
|
2007-03-23 03:28:33 +01:00
|
|
|
volatile unsigned int *lock = &lock_data->hw_lock->lock;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-03-23 03:28:33 +01:00
|
|
|
spin_lock(&lock_data->spinlock);
|
2005-04-17 00:20:36 +02:00
|
|
|
do {
|
|
|
|
old = *lock;
|
2005-09-25 06:28:13 +02:00
|
|
|
if (old & _DRM_LOCK_HELD)
|
|
|
|
new = old | _DRM_LOCK_CONT;
|
2007-03-23 03:28:33 +01:00
|
|
|
else {
|
|
|
|
new = context | _DRM_LOCK_HELD |
|
|
|
|
((lock_data->user_waiters + lock_data->kernel_waiters > 1) ?
|
|
|
|
_DRM_LOCK_CONT : 0);
|
|
|
|
}
|
2005-04-17 00:20:36 +02:00
|
|
|
prev = cmpxchg(lock, old, new);
|
|
|
|
} while (prev != old);
|
2007-03-23 03:28:33 +01:00
|
|
|
spin_unlock(&lock_data->spinlock);
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (_DRM_LOCKING_CONTEXT(old) == context) {
|
|
|
|
if (old & _DRM_LOCK_HELD) {
|
|
|
|
if (context != DRM_KERNEL_CONTEXT) {
|
|
|
|
DRM_ERROR("%d holds heavyweight lock\n",
|
|
|
|
context);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-03-23 03:28:33 +01:00
|
|
|
|
|
|
|
if ((_DRM_LOCKING_CONTEXT(new)) == context && (new & _DRM_LOCK_HELD)) {
|
2005-09-25 06:28:13 +02:00
|
|
|
/* Have lock */
|
2005-04-17 00:20:36 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This takes a lock forcibly and hands it to context. Should ONLY be used
|
2005-09-25 06:28:13 +02:00
|
|
|
* inside *_unlock to give lock to kernel before calling *_dma_schedule.
|
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* \param dev DRM device.
|
|
|
|
* \param lock lock pointer.
|
|
|
|
* \param context locking context.
|
|
|
|
* \return always one.
|
|
|
|
*
|
|
|
|
* Resets the lock file pointer.
|
|
|
|
* Marks the lock as held by the given context, via the \p cmpxchg instruction.
|
|
|
|
*/
|
2007-07-11 08:53:40 +02:00
|
|
|
static int drm_lock_transfer(struct drm_lock_data *lock_data,
|
2005-07-07 13:03:38 +02:00
|
|
|
unsigned int context)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned int old, new, prev;
|
2007-03-23 03:28:33 +01:00
|
|
|
volatile unsigned int *lock = &lock_data->hw_lock->lock;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-08-25 12:23:09 +02:00
|
|
|
lock_data->file_priv = NULL;
|
2005-04-17 00:20:36 +02:00
|
|
|
do {
|
2005-09-25 06:28:13 +02:00
|
|
|
old = *lock;
|
|
|
|
new = context | _DRM_LOCK_HELD;
|
2005-04-17 00:20:36 +02:00
|
|
|
prev = cmpxchg(lock, old, new);
|
|
|
|
} while (prev != old);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free lock.
|
2005-09-25 06:28:13 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* \param dev DRM device.
|
|
|
|
* \param lock lock.
|
|
|
|
* \param context context.
|
2005-09-25 06:28:13 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* Resets the lock file pointer.
|
|
|
|
* Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
|
|
|
|
* waiting on the lock queue.
|
|
|
|
*/
|
2007-07-11 08:53:40 +02:00
|
|
|
int drm_lock_free(struct drm_lock_data *lock_data, unsigned int context)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
unsigned int old, new, prev;
|
2007-03-23 03:28:33 +01:00
|
|
|
volatile unsigned int *lock = &lock_data->hw_lock->lock;
|
|
|
|
|
|
|
|
spin_lock(&lock_data->spinlock);
|
|
|
|
if (lock_data->kernel_waiters != 0) {
|
|
|
|
drm_lock_transfer(lock_data, 0);
|
|
|
|
lock_data->idle_has_lock = 1;
|
|
|
|
spin_unlock(&lock_data->spinlock);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
spin_unlock(&lock_data->spinlock);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
do {
|
2005-09-25 06:28:13 +02:00
|
|
|
old = *lock;
|
2007-03-23 03:28:33 +01:00
|
|
|
new = _DRM_LOCKING_CONTEXT(old);
|
2005-04-17 00:20:36 +02:00
|
|
|
prev = cmpxchg(lock, old, new);
|
|
|
|
} while (prev != old);
|
2007-03-23 03:28:33 +01:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
|
|
|
|
DRM_ERROR("%d freed heavyweight lock held by %d\n",
|
2005-09-25 06:28:13 +02:00
|
|
|
context, _DRM_LOCKING_CONTEXT(old));
|
2005-04-17 00:20:36 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2007-03-23 03:28:33 +01:00
|
|
|
wake_up_interruptible(&lock_data->lock_queue);
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we get here, it means that the process has called DRM_IOCTL_LOCK
|
|
|
|
* without calling DRM_IOCTL_UNLOCK.
|
|
|
|
*
|
|
|
|
* If the lock is not held, then let the signal proceed as usual. If the lock
|
|
|
|
* is held, then set the contended flag and keep the signal blocked.
|
|
|
|
*
|
|
|
|
* \param priv pointer to a drm_sigdata structure.
|
|
|
|
* \return one if the signal should be delivered normally, or zero if the
|
|
|
|
* signal should be blocked.
|
|
|
|
*/
|
2005-07-07 13:03:38 +02:00
|
|
|
static int drm_notifier(void *priv)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-07-11 08:53:40 +02:00
|
|
|
struct drm_sigdata *s = (struct drm_sigdata *) priv;
|
2005-09-25 06:28:13 +02:00
|
|
|
unsigned int old, new, prev;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
/* Allow signal delivery if lock isn't held */
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!s->lock || !_DRM_LOCK_IS_HELD(s->lock->lock)
|
2005-09-25 06:28:13 +02:00
|
|
|
|| _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context)
|
|
|
|
return 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-09-25 06:28:13 +02:00
|
|
|
/* Otherwise, set flag to force call to
|
|
|
|
drmUnlock */
|
2005-04-17 00:20:36 +02:00
|
|
|
do {
|
2005-09-25 06:28:13 +02:00
|
|
|
old = s->lock->lock;
|
|
|
|
new = old | _DRM_LOCK_CONT;
|
2005-04-17 00:20:36 +02:00
|
|
|
prev = cmpxchg(&s->lock->lock, old, new);
|
|
|
|
} while (prev != old);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-23 03:28:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function returns immediately and takes the hw lock
|
|
|
|
* with the kernel context if it is free, otherwise it gets the highest priority when and if
|
|
|
|
* it is eventually released.
|
|
|
|
*
|
|
|
|
* This guarantees that the kernel will _eventually_ have the lock _unless_ it is held
|
|
|
|
* by a blocked process. (In the latter case an explicit wait for the hardware lock would cause
|
|
|
|
* a deadlock, which is why the "idlelock" was invented).
|
|
|
|
*
|
|
|
|
* This should be sufficient to wait for GPU idle without
|
|
|
|
* having to worry about starvation.
|
|
|
|
*/
|
|
|
|
|
2007-07-11 08:53:40 +02:00
|
|
|
void drm_idlelock_take(struct drm_lock_data *lock_data)
|
2007-03-23 03:28:33 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
spin_lock(&lock_data->spinlock);
|
|
|
|
lock_data->kernel_waiters++;
|
|
|
|
if (!lock_data->idle_has_lock) {
|
|
|
|
|
|
|
|
spin_unlock(&lock_data->spinlock);
|
|
|
|
ret = drm_lock_take(lock_data, DRM_KERNEL_CONTEXT);
|
|
|
|
spin_lock(&lock_data->spinlock);
|
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
lock_data->idle_has_lock = 1;
|
|
|
|
}
|
|
|
|
spin_unlock(&lock_data->spinlock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_idlelock_take);
|
|
|
|
|
2007-07-11 08:53:40 +02:00
|
|
|
void drm_idlelock_release(struct drm_lock_data *lock_data)
|
2007-03-23 03:28:33 +01:00
|
|
|
{
|
|
|
|
unsigned int old, prev;
|
|
|
|
volatile unsigned int *lock = &lock_data->hw_lock->lock;
|
|
|
|
|
|
|
|
spin_lock(&lock_data->spinlock);
|
|
|
|
if (--lock_data->kernel_waiters == 0) {
|
|
|
|
if (lock_data->idle_has_lock) {
|
|
|
|
do {
|
|
|
|
old = *lock;
|
|
|
|
prev = cmpxchg(lock, old, DRM_KERNEL_CONTEXT);
|
|
|
|
} while (prev != old);
|
|
|
|
wake_up_interruptible(&lock_data->lock_queue);
|
|
|
|
lock_data->idle_has_lock = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
spin_unlock(&lock_data->spinlock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_idlelock_release);
|
|
|
|
|
|
|
|
|
2007-09-03 04:06:45 +02:00
|
|
|
int drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file_priv)
|
2007-03-23 03:28:33 +01:00
|
|
|
{
|
2007-08-25 12:23:09 +02:00
|
|
|
return (file_priv->lock_count && dev->lock.hw_lock &&
|
2007-03-23 03:28:33 +01:00
|
|
|
_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock) &&
|
2007-08-25 12:23:09 +02:00
|
|
|
dev->lock.file_priv == file_priv);
|
2007-03-23 03:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(drm_i_have_hw_lock);
|