summaryrefslogtreecommitdiffstats
path: root/sys/dev/drm/drm_lock.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/drm/drm_lock.h')
-rw-r--r--sys/dev/drm/drm_lock.h107
1 files changed, 16 insertions, 91 deletions
diff --git a/sys/dev/drm/drm_lock.h b/sys/dev/drm/drm_lock.h
index e3b1f5e..de07146 100644
--- a/sys/dev/drm/drm_lock.h
+++ b/sys/dev/drm/drm_lock.h
@@ -31,16 +31,15 @@
* $FreeBSD$
*/
-#define __NO_VERSION__
#include "dev/drm/drmP.h"
-int DRM(block)( DRM_OS_IOCTL )
+int DRM(block)( DRM_IOCTL_ARGS )
{
DRM_DEBUG("\n");
return 0;
}
-int DRM(unblock)( DRM_OS_IOCTL )
+int DRM(unblock)( DRM_IOCTL_ARGS )
{
DRM_DEBUG("\n");
return 0;
@@ -49,26 +48,13 @@ int DRM(unblock)( DRM_OS_IOCTL )
int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
{
unsigned int old, new;
-#ifdef __linux__
- unsigned int prev;
-#endif /* __linux__ */
-
-#ifdef __FreeBSD__
- char failed;
-#endif /* __FreeBSD__ */
do {
old = *lock;
if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
else new = context | _DRM_LOCK_HELD;
-#ifdef __linux__
- prev = cmpxchg(lock, old, new);
- } while (prev != old);
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- _DRM_CAS(lock, old, new, failed);
- } while (failed);
-#endif /* __FreeBSD__ */
+ } while (!atomic_cmpset_int(lock, old, new));
+
if (_DRM_LOCKING_CONTEXT(old) == context) {
if (old & _DRM_LOCK_HELD) {
if (context != DRM_KERNEL_CONTEXT) {
@@ -91,25 +77,13 @@ int DRM(lock_transfer)(drm_device_t *dev,
__volatile__ unsigned int *lock, unsigned int context)
{
unsigned int old, new;
-#ifdef __linux__
- unsigned int prev;
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- char failed;
-#endif /* __FreeBSD__ */
dev->lock.pid = 0;
do {
old = *lock;
new = context | _DRM_LOCK_HELD;
-#ifdef __linux__
- prev = cmpxchg(lock, old, new);
- } while (prev != old);
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- _DRM_CAS(lock, old, new, failed);
- } while (failed);
-#endif /* __FreeBSD__ */
+ } while (!atomic_cmpset_int(lock, old, new));
+
return 1;
}
@@ -117,26 +91,14 @@ int DRM(lock_free)(drm_device_t *dev,
__volatile__ unsigned int *lock, unsigned int context)
{
unsigned int old, new;
-#ifdef __linux__
- unsigned int prev;
-#endif /* __linux__ */
pid_t pid = dev->lock.pid;
-#ifdef __FreeBSD__
- char failed;
-#endif /* __FreeBSD__ */
dev->lock.pid = 0;
do {
old = *lock;
new = 0;
-#ifdef __linux__
- prev = cmpxchg(lock, old, new);
- } while (prev != old);
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- _DRM_CAS(lock, old, new, failed);
- } while (failed);
-#endif /* __FreeBSD__ */
+ } while (!atomic_cmpset_int(lock, old, new));
+
if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
DRM_ERROR("%d freed heavyweight lock held by %d (pid %d)\n",
context,
@@ -144,18 +106,13 @@ int DRM(lock_free)(drm_device_t *dev,
pid);
return 1;
}
- DRM_OS_WAKEUP_INT(&dev->lock.lock_queue);
+ DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
return 0;
}
static int DRM(flush_queue)(drm_device_t *dev, int context)
{
-#ifdef __linux__
- DECLARE_WAITQUEUE(entry, current);
-#endif /* __linux__ */
-#ifdef __FreeBSD__
int error;
-#endif /* __FreeBSD__ */
int ret = 0;
drm_queue_t *q = dev->queuelist[context];
@@ -164,30 +121,11 @@ static int DRM(flush_queue)(drm_device_t *dev, int context)
atomic_inc(&q->use_count);
if (atomic_read(&q->use_count) > 1) {
atomic_inc(&q->block_write);
-#ifdef __linux__
- add_wait_queue(&q->flush_queue, &entry);
atomic_inc(&q->block_count);
- for (;;) {
- current->state = TASK_INTERRUPTIBLE;
- if (!DRM_BUFCOUNT(&q->waitlist)) break;
- schedule();
- if (signal_pending(current)) {
- ret = -EINTR; /* Can't restart */
- break;
- }
- }
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- atomic_inc(&q->block_count);
- error = tsleep(&q->flush_queue, PZERO|PCATCH, "drmfq", 0);
+ error = tsleep((void *)&q->flush_queue, PZERO|PCATCH, "drmfq", 0);
if (error)
return error;
-#endif /* __FreeBSD__ */
atomic_dec(&q->block_count);
-#ifdef __linux__
- current->state = TASK_RUNNING;
- remove_wait_queue(&q->flush_queue, &entry);
-#endif /* __linux__ */
}
atomic_dec(&q->use_count);
@@ -206,7 +144,7 @@ static int DRM(flush_unblock_queue)(drm_device_t *dev, int context)
if (atomic_read(&q->use_count) > 1) {
if (atomic_read(&q->block_write)) {
atomic_dec(&q->block_write);
- DRM_OS_WAKEUP_INT(&q->write_queue);
+ DRM_WAKEUP_INT((void *)&q->write_queue);
}
}
atomic_dec(&q->use_count);
@@ -253,15 +191,15 @@ int DRM(flush_unblock)(drm_device_t *dev, int context, drm_lock_flags_t flags)
return ret;
}
-int DRM(finish)( DRM_OS_IOCTL )
+int DRM(finish)( DRM_IOCTL_ARGS )
{
- DRM_OS_DEVICE;
+ DRM_DEVICE;
int ret = 0;
drm_lock_t lock;
DRM_DEBUG("\n");
- DRM_OS_KRNFROMUSR( lock, (drm_lock_t *)data, sizeof(lock) );
+ DRM_COPY_FROM_USER_IOCTL( lock, (drm_lock_t *)data, sizeof(lock) );
ret = DRM(flush_block_and_flush)(dev, lock.context, lock.flags);
DRM(flush_unblock)(dev, lock.context, lock.flags);
@@ -284,13 +222,6 @@ int DRM(notifier)(void *priv)
{
drm_sigdata_t *s = (drm_sigdata_t *)priv;
unsigned int old, new;
-#ifdef __linux__
- unsigned int prev;
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- char failed;
-#endif /* __FreeBSD__ */
-
/* Allow signal delivery if lock isn't held */
if (!_DRM_LOCK_IS_HELD(s->lock->lock)
@@ -301,14 +232,8 @@ int DRM(notifier)(void *priv)
do {
old = s->lock->lock;
new = old | _DRM_LOCK_CONT;
-#ifdef __linux__
- prev = cmpxchg(&s->lock->lock, old, new);
- } while (prev != old);
-#endif /* __linux__ */
-#ifdef __FreeBSD__
- _DRM_CAS(&s->lock->lock, old, new, failed);
- } while (failed);
-#endif /* __FreeBSD__ */
+ } while (!atomic_cmpset_int(&s->lock->lock, old, new));
+
return 0;
}
OpenPOWER on IntegriCloud