5 * \author Rickard E. (Rik) Faith <faith@valinux.com>
6 * \author Gareth Hughes <gareth@valinux.com>
10 * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
12 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14 * All Rights Reserved.
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
23 * The above copyright notice and this permission notice (including the next
24 * paragraph) shall be included in all copies or substantial portions of the
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
36 #define __NO_VERSION__
40 int DRM(noop)(struct inode *inode, struct file *filp, unsigned int cmd,
48 * Take the heavyweight lock.
50 * \param lock lock pointer.
51 * \param context locking context.
52 * \return one if the lock is held, or zero otherwise.
54 * Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
56 int DRM(lock_take)(__volatile__ unsigned int *lock, unsigned int context)
58 unsigned int old, new, prev;
62 if (old & _DRM_LOCK_HELD) new = old | _DRM_LOCK_CONT;
63 else new = context | _DRM_LOCK_HELD;
64 prev = cmpxchg(lock, old, new);
65 } while (prev != old);
66 if (_DRM_LOCKING_CONTEXT(old) == context) {
67 if (old & _DRM_LOCK_HELD) {
68 if (context != DRM_KERNEL_CONTEXT) {
69 DRM_ERROR("%d holds heavyweight lock\n",
75 if (new == (context | _DRM_LOCK_HELD)) {
83 * This takes a lock forcibly and hands it to context. Should ONLY be used
84 * inside *_unlock to give lock to kernel before calling *_dma_schedule.
86 * \param dev DRM device.
87 * \param lock lock pointer.
88 * \param context locking context.
91 * Resets the lock file pointer.
92 * Marks the lock as held by the given context, via the \p cmpxchg instruction.
94 int DRM(lock_transfer)(drm_device_t *dev,
95 __volatile__ unsigned int *lock, unsigned int context)
97 unsigned int old, new, prev;
99 dev->lock.filp = NULL;
102 new = context | _DRM_LOCK_HELD;
103 prev = cmpxchg(lock, old, new);
104 } while (prev != old);
111 * \param dev DRM device.
113 * \param context context.
115 * Resets the lock file pointer.
116 * Marks the lock as not held, via the \p cmpxchg instruction. Wakes any task
117 * waiting on the lock queue.
119 int DRM(lock_free)(drm_device_t *dev,
120 __volatile__ unsigned int *lock, unsigned int context)
122 unsigned int old, new, prev;
124 dev->lock.filp = NULL;
128 prev = cmpxchg(lock, old, new);
129 } while (prev != old);
130 if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
131 DRM_ERROR("%d freed heavyweight lock held by %d\n",
133 _DRM_LOCKING_CONTEXT(old));
136 wake_up_interruptible(&dev->lock.lock_queue);
141 * If we get here, it means that the process has called DRM_IOCTL_LOCK
142 * without calling DRM_IOCTL_UNLOCK.
144 * If the lock is not held, then let the signal proceed as usual. If the lock
145 * is held, then set the contended flag and keep the signal blocked.
147 * \param priv pointer to a drm_sigdata structure.
148 * \return one if the signal should be delivered normally, or zero if the
149 * signal should be blocked.
151 int DRM(notifier)(void *priv)
153 drm_sigdata_t *s = (drm_sigdata_t *)priv;
154 unsigned int old, new, prev;
157 /* Allow signal delivery if lock isn't held */
158 if (!s->lock || !_DRM_LOCK_IS_HELD(s->lock->lock)
159 || _DRM_LOCKING_CONTEXT(s->lock->lock) != s->context) return 1;
161 /* Otherwise, set flag to force call to
165 new = old | _DRM_LOCK_CONT;
166 prev = cmpxchg(&s->lock->lock, old, new);
167 } while (prev != old);