1a05eeebfSFrançois Tigeot /**
2a05eeebfSFrançois Tigeot * \file drm_lock.c
3a05eeebfSFrançois Tigeot * IOCTLs for locking
4a05eeebfSFrançois Tigeot *
5a05eeebfSFrançois Tigeot * \author Rickard E. (Rik) Faith <faith@valinux.com>
6a05eeebfSFrançois Tigeot * \author Gareth Hughes <gareth@valinux.com>
7a05eeebfSFrançois Tigeot */
8a05eeebfSFrançois Tigeot
9a05eeebfSFrançois Tigeot /*
10a05eeebfSFrançois Tigeot * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
11a05eeebfSFrançois Tigeot *
127f3c3d6fSHasso Tepper * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
137f3c3d6fSHasso Tepper * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
147f3c3d6fSHasso Tepper * All Rights Reserved.
157f3c3d6fSHasso Tepper *
167f3c3d6fSHasso Tepper * Permission is hereby granted, free of charge, to any person obtaining a
177f3c3d6fSHasso Tepper * copy of this software and associated documentation files (the "Software"),
187f3c3d6fSHasso Tepper * to deal in the Software without restriction, including without limitation
197f3c3d6fSHasso Tepper * the rights to use, copy, modify, merge, publish, distribute, sublicense,
207f3c3d6fSHasso Tepper * and/or sell copies of the Software, and to permit persons to whom the
217f3c3d6fSHasso Tepper * Software is furnished to do so, subject to the following conditions:
227f3c3d6fSHasso Tepper *
237f3c3d6fSHasso Tepper * The above copyright notice and this permission notice (including the next
247f3c3d6fSHasso Tepper * paragraph) shall be included in all copies or substantial portions of the
257f3c3d6fSHasso Tepper * Software.
267f3c3d6fSHasso Tepper *
277f3c3d6fSHasso Tepper * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
287f3c3d6fSHasso Tepper * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
297f3c3d6fSHasso Tepper * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
307f3c3d6fSHasso Tepper * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
317f3c3d6fSHasso Tepper * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
327f3c3d6fSHasso Tepper * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
337f3c3d6fSHasso Tepper * OTHER DEALINGS IN THE SOFTWARE.
347f3c3d6fSHasso Tepper */
357f3c3d6fSHasso Tepper
36a05eeebfSFrançois Tigeot #include <linux/export.h>
37*a85cb24fSFrançois Tigeot #include <linux/sched/signal.h>
38*a85cb24fSFrançois Tigeot
3918e26a6dSFrançois Tigeot #include <drm/drmP.h>
4024edb884SFrançois Tigeot #include "drm_legacy.h"
41a05eeebfSFrançois Tigeot #include "drm_internal.h"
427f3c3d6fSHasso Tepper
43a05eeebfSFrançois Tigeot #if 0
44a05eeebfSFrançois Tigeot static int drm_lock_take(struct drm_lock_data *lock_data, unsigned int context);
45a05eeebfSFrançois Tigeot
46a05eeebfSFrançois Tigeot /**
47a05eeebfSFrançois Tigeot * Take the heavyweight lock.
48a05eeebfSFrançois Tigeot *
49a05eeebfSFrançois Tigeot * \param lock lock pointer.
50a05eeebfSFrançois Tigeot * \param context locking context.
51a05eeebfSFrançois Tigeot * \return one if the lock is held, or zero otherwise.
52a05eeebfSFrançois Tigeot *
53a05eeebfSFrançois Tigeot * Attempt to mark the lock as held by the given context, via the \p cmpxchg instruction.
54a05eeebfSFrançois Tigeot */
55a05eeebfSFrançois Tigeot static
56a05eeebfSFrançois Tigeot int drm_lock_take(struct drm_lock_data *lock_data,
57a05eeebfSFrançois Tigeot unsigned int context)
58b3705d71SHasso Tepper {
59a05eeebfSFrançois Tigeot unsigned int old, new, prev;
60b3705d71SHasso Tepper volatile unsigned int *lock = &lock_data->hw_lock->lock;
617f3c3d6fSHasso Tepper
62a05eeebfSFrançois Tigeot spin_lock_bh(&lock_data->spinlock);
637f3c3d6fSHasso Tepper do {
647f3c3d6fSHasso Tepper old = *lock;
65b3705d71SHasso Tepper if (old & _DRM_LOCK_HELD)
66b3705d71SHasso Tepper new = old | _DRM_LOCK_CONT;
67a05eeebfSFrançois Tigeot else {
68a05eeebfSFrançois Tigeot new = context | _DRM_LOCK_HELD |
69a05eeebfSFrançois Tigeot ((lock_data->user_waiters + lock_data->kernel_waiters > 1) ?
70a05eeebfSFrançois Tigeot _DRM_LOCK_CONT : 0);
71a05eeebfSFrançois Tigeot }
72a05eeebfSFrançois Tigeot prev = cmpxchg(lock, old, new);
73a05eeebfSFrançois Tigeot } while (prev != old);
74a05eeebfSFrançois Tigeot spin_unlock_bh(&lock_data->spinlock);
757f3c3d6fSHasso Tepper
767f3c3d6fSHasso Tepper if (_DRM_LOCKING_CONTEXT(old) == context) {
777f3c3d6fSHasso Tepper if (old & _DRM_LOCK_HELD) {
787f3c3d6fSHasso Tepper if (context != DRM_KERNEL_CONTEXT) {
797f3c3d6fSHasso Tepper DRM_ERROR("%d holds heavyweight lock\n",
807f3c3d6fSHasso Tepper context);
817f3c3d6fSHasso Tepper }
827f3c3d6fSHasso Tepper return 0;
837f3c3d6fSHasso Tepper }
847f3c3d6fSHasso Tepper }
85a05eeebfSFrançois Tigeot
86a05eeebfSFrançois Tigeot if ((_DRM_LOCKING_CONTEXT(new)) == context && (new & _DRM_LOCK_HELD)) {
877f3c3d6fSHasso Tepper /* Have lock */
887f3c3d6fSHasso Tepper return 1;
897f3c3d6fSHasso Tepper }
907f3c3d6fSHasso Tepper return 0;
917f3c3d6fSHasso Tepper }
927f3c3d6fSHasso Tepper
93a05eeebfSFrançois Tigeot /**
94a05eeebfSFrançois Tigeot * This takes a lock forcibly and hands it to context. Should ONLY be used
95a05eeebfSFrançois Tigeot * inside *_unlock to give lock to kernel before calling *_dma_schedule.
96a05eeebfSFrançois Tigeot *
97a05eeebfSFrançois Tigeot * \param dev DRM device.
98a05eeebfSFrançois Tigeot * \param lock lock pointer.
99a05eeebfSFrançois Tigeot * \param context locking context.
100a05eeebfSFrançois Tigeot * \return always one.
101a05eeebfSFrançois Tigeot *
102a05eeebfSFrançois Tigeot * Resets the lock file pointer.
103a05eeebfSFrançois Tigeot * Marks the lock as held by the given context, via the \p cmpxchg instruction.
104a05eeebfSFrançois Tigeot */
105a05eeebfSFrançois Tigeot static int drm_lock_transfer(struct drm_lock_data *lock_data,
106a05eeebfSFrançois Tigeot unsigned int context)
1077f3c3d6fSHasso Tepper {
108a05eeebfSFrançois Tigeot unsigned int old, new, prev;
109b3705d71SHasso Tepper volatile unsigned int *lock = &lock_data->hw_lock->lock;
1107f3c3d6fSHasso Tepper
111b3705d71SHasso Tepper lock_data->file_priv = NULL;
1127f3c3d6fSHasso Tepper do {
1137f3c3d6fSHasso Tepper old = *lock;
1147f3c3d6fSHasso Tepper new = context | _DRM_LOCK_HELD;
115a05eeebfSFrançois Tigeot prev = cmpxchg(lock, old, new);
116a05eeebfSFrançois Tigeot } while (prev != old);
1177f3c3d6fSHasso Tepper return 1;
1187f3c3d6fSHasso Tepper }
1197f3c3d6fSHasso Tepper
1201dedbd3bSFrançois Tigeot static int drm_legacy_lock_free(struct drm_lock_data *lock_data,
1211dedbd3bSFrançois Tigeot unsigned int context)
1227f3c3d6fSHasso Tepper {
123a05eeebfSFrançois Tigeot unsigned int old, new, prev;
124b3705d71SHasso Tepper volatile unsigned int *lock = &lock_data->hw_lock->lock;
1257f3c3d6fSHasso Tepper
126a05eeebfSFrançois Tigeot spin_lock_bh(&lock_data->spinlock);
127a05eeebfSFrançois Tigeot if (lock_data->kernel_waiters != 0) {
128a05eeebfSFrançois Tigeot drm_lock_transfer(lock_data, 0);
129a05eeebfSFrançois Tigeot lock_data->idle_has_lock = 1;
130a05eeebfSFrançois Tigeot spin_unlock_bh(&lock_data->spinlock);
131a05eeebfSFrançois Tigeot return 1;
132a05eeebfSFrançois Tigeot }
133a05eeebfSFrançois Tigeot spin_unlock_bh(&lock_data->spinlock);
134a05eeebfSFrançois Tigeot
1357f3c3d6fSHasso Tepper do {
1367f3c3d6fSHasso Tepper old = *lock;
137a05eeebfSFrançois Tigeot new = _DRM_LOCKING_CONTEXT(old);
138a05eeebfSFrançois Tigeot prev = cmpxchg(lock, old, new);
139a05eeebfSFrançois Tigeot } while (prev != old);
1407f3c3d6fSHasso Tepper
1417f3c3d6fSHasso Tepper if (_DRM_LOCK_IS_HELD(old) && _DRM_LOCKING_CONTEXT(old) != context) {
1427f3c3d6fSHasso Tepper DRM_ERROR("%d freed heavyweight lock held by %d\n",
1437f3c3d6fSHasso Tepper context, _DRM_LOCKING_CONTEXT(old));
1447f3c3d6fSHasso Tepper return 1;
1457f3c3d6fSHasso Tepper }
146c6f73aabSFrançois Tigeot wake_up_interruptible(&lock_data->lock_queue);
1471dedbd3bSFrançois Tigeot return 0;
1481dedbd3bSFrançois Tigeot }
149c6f73aabSFrançois Tigeot #endif
1501dedbd3bSFrançois Tigeot
1511dedbd3bSFrançois Tigeot /**
1521dedbd3bSFrançois Tigeot * Lock ioctl.
1531dedbd3bSFrançois Tigeot *
1541dedbd3bSFrançois Tigeot * \param inode device inode.
1551dedbd3bSFrançois Tigeot * \param file_priv DRM file private.
1561dedbd3bSFrançois Tigeot * \param cmd command.
1571dedbd3bSFrançois Tigeot * \param arg user argument, pointing to a drm_lock structure.
1581dedbd3bSFrançois Tigeot * \return zero on success or negative number on failure.
1591dedbd3bSFrançois Tigeot *
1601dedbd3bSFrançois Tigeot * Add the current task to the lock wait queue, and attempt to take to lock.
1611dedbd3bSFrançois Tigeot */
drm_legacy_lock(struct drm_device * dev,void * data,struct drm_file * file_priv)1621dedbd3bSFrançois Tigeot int drm_legacy_lock(struct drm_device *dev, void *data,
1631dedbd3bSFrançois Tigeot struct drm_file *file_priv)
1641dedbd3bSFrançois Tigeot {
1651dedbd3bSFrançois Tigeot #if 0
1661dedbd3bSFrançois Tigeot DECLARE_WAITQUEUE(entry, current);
1671dedbd3bSFrançois Tigeot struct drm_lock *lock = data;
1681dedbd3bSFrançois Tigeot struct drm_master *master = file_priv->master;
1691dedbd3bSFrançois Tigeot int ret = 0;
1701dedbd3bSFrançois Tigeot
1711dedbd3bSFrançois Tigeot if (!drm_core_check_feature(dev, DRIVER_LEGACY))
1721dedbd3bSFrançois Tigeot return -EINVAL;
1731dedbd3bSFrançois Tigeot
1741dedbd3bSFrançois Tigeot ++file_priv->lock_count;
1751dedbd3bSFrançois Tigeot
1761dedbd3bSFrançois Tigeot if (lock->context == DRM_KERNEL_CONTEXT) {
1771dedbd3bSFrançois Tigeot DRM_ERROR("Process %d using kernel context %d\n",
1781dedbd3bSFrançois Tigeot task_pid_nr(current), lock->context);
1791dedbd3bSFrançois Tigeot return -EINVAL;
1801dedbd3bSFrançois Tigeot }
1811dedbd3bSFrançois Tigeot
1821dedbd3bSFrançois Tigeot DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
1831dedbd3bSFrançois Tigeot lock->context, task_pid_nr(current),
1844be47400SFrançois Tigeot master->lock.hw_lock ? master->lock.hw_lock->lock : -1,
1854be47400SFrançois Tigeot lock->flags);
1861dedbd3bSFrançois Tigeot
1871dedbd3bSFrançois Tigeot add_wait_queue(&master->lock.lock_queue, &entry);
1881dedbd3bSFrançois Tigeot spin_lock_bh(&master->lock.spinlock);
1891dedbd3bSFrançois Tigeot master->lock.user_waiters++;
1901dedbd3bSFrançois Tigeot spin_unlock_bh(&master->lock.spinlock);
1911dedbd3bSFrançois Tigeot
1921dedbd3bSFrançois Tigeot for (;;) {
1931dedbd3bSFrançois Tigeot __set_current_state(TASK_INTERRUPTIBLE);
1941dedbd3bSFrançois Tigeot if (!master->lock.hw_lock) {
1951dedbd3bSFrançois Tigeot /* Device has been unregistered */
1961dedbd3bSFrançois Tigeot send_sig(SIGTERM, current, 0);
1971dedbd3bSFrançois Tigeot ret = -EINTR;
1981dedbd3bSFrançois Tigeot break;
1991dedbd3bSFrançois Tigeot }
2001dedbd3bSFrançois Tigeot if (drm_lock_take(&master->lock, lock->context)) {
2011dedbd3bSFrançois Tigeot master->lock.file_priv = file_priv;
2021dedbd3bSFrançois Tigeot master->lock.lock_time = jiffies;
2031dedbd3bSFrançois Tigeot break; /* Got lock */
2041dedbd3bSFrançois Tigeot }
2051dedbd3bSFrançois Tigeot
2061dedbd3bSFrançois Tigeot /* Contention */
2071dedbd3bSFrançois Tigeot mutex_unlock(&drm_global_mutex);
2081dedbd3bSFrançois Tigeot schedule();
2091dedbd3bSFrançois Tigeot mutex_lock(&drm_global_mutex);
2101dedbd3bSFrançois Tigeot if (signal_pending(current)) {
2111dedbd3bSFrançois Tigeot ret = -EINTR;
2121dedbd3bSFrançois Tigeot break;
2131dedbd3bSFrançois Tigeot }
2141dedbd3bSFrançois Tigeot }
2151dedbd3bSFrançois Tigeot spin_lock_bh(&master->lock.spinlock);
2161dedbd3bSFrançois Tigeot master->lock.user_waiters--;
2171dedbd3bSFrançois Tigeot spin_unlock_bh(&master->lock.spinlock);
2181dedbd3bSFrançois Tigeot __set_current_state(TASK_RUNNING);
2191dedbd3bSFrançois Tigeot remove_wait_queue(&master->lock.lock_queue, &entry);
2201dedbd3bSFrançois Tigeot
2211dedbd3bSFrançois Tigeot DRM_DEBUG("%d %s\n", lock->context,
2221dedbd3bSFrançois Tigeot ret ? "interrupted" : "has lock");
2231dedbd3bSFrançois Tigeot if (ret) return ret;
2241dedbd3bSFrançois Tigeot
2251dedbd3bSFrançois Tigeot /* don't set the block all signals on the master process for now
2261dedbd3bSFrançois Tigeot * really probably not the correct answer but lets us debug xkb
2271dedbd3bSFrançois Tigeot * xserver for now */
2281dedbd3bSFrançois Tigeot if (!drm_is_current_master(file_priv)) {
2291dedbd3bSFrançois Tigeot dev->sigdata.context = lock->context;
2301dedbd3bSFrançois Tigeot dev->sigdata.lock = master->lock.hw_lock;
2311dedbd3bSFrançois Tigeot }
2321dedbd3bSFrançois Tigeot
2331dedbd3bSFrançois Tigeot if (dev->driver->dma_quiescent && (lock->flags & _DRM_LOCK_QUIESCENT))
2341dedbd3bSFrançois Tigeot {
2351dedbd3bSFrançois Tigeot if (dev->driver->dma_quiescent(dev)) {
2361dedbd3bSFrançois Tigeot DRM_DEBUG("%d waiting for DMA quiescent\n",
2371dedbd3bSFrançois Tigeot lock->context);
2381dedbd3bSFrançois Tigeot return -EBUSY;
2391dedbd3bSFrançois Tigeot }
2401dedbd3bSFrançois Tigeot }
2411dedbd3bSFrançois Tigeot #endif
2421dedbd3bSFrançois Tigeot
2437f3c3d6fSHasso Tepper return 0;
2447f3c3d6fSHasso Tepper }
245a05eeebfSFrançois Tigeot
246a05eeebfSFrançois Tigeot /**
2471dedbd3bSFrançois Tigeot * Unlock ioctl.
2481dedbd3bSFrançois Tigeot *
2491dedbd3bSFrançois Tigeot * \param inode device inode.
2501dedbd3bSFrançois Tigeot * \param file_priv DRM file private.
2511dedbd3bSFrançois Tigeot * \param cmd command.
2521dedbd3bSFrançois Tigeot * \param arg user argument, pointing to a drm_lock structure.
2531dedbd3bSFrançois Tigeot * \return zero on success or negative number on failure.
2541dedbd3bSFrançois Tigeot *
2551dedbd3bSFrançois Tigeot * Transfer and free the lock.
2561dedbd3bSFrançois Tigeot */
drm_legacy_unlock(struct drm_device * dev,void * data,struct drm_file * file_priv)2571dedbd3bSFrançois Tigeot int drm_legacy_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
2581dedbd3bSFrançois Tigeot {
2591dedbd3bSFrançois Tigeot #if 0
2601dedbd3bSFrançois Tigeot struct drm_lock *lock = data;
2611dedbd3bSFrançois Tigeot struct drm_master *master = file_priv->master;
2621dedbd3bSFrançois Tigeot
2631dedbd3bSFrançois Tigeot if (!drm_core_check_feature(dev, DRIVER_LEGACY))
2641dedbd3bSFrançois Tigeot return -EINVAL;
2651dedbd3bSFrançois Tigeot
2661dedbd3bSFrançois Tigeot if (lock->context == DRM_KERNEL_CONTEXT) {
2671dedbd3bSFrançois Tigeot DRM_ERROR("Process %d using kernel context %d\n",
2681dedbd3bSFrançois Tigeot task_pid_nr(current), lock->context);
2691dedbd3bSFrançois Tigeot return -EINVAL;
2701dedbd3bSFrançois Tigeot }
2711dedbd3bSFrançois Tigeot
2721dedbd3bSFrançois Tigeot if (drm_legacy_lock_free(&master->lock, lock->context)) {
2731dedbd3bSFrançois Tigeot /* FIXME: Should really bail out here. */
2741dedbd3bSFrançois Tigeot }
2751dedbd3bSFrançois Tigeot #endif
2761dedbd3bSFrançois Tigeot
2771dedbd3bSFrançois Tigeot return 0;
2781dedbd3bSFrançois Tigeot }
2791dedbd3bSFrançois Tigeot
2801dedbd3bSFrançois Tigeot #if 0
2811dedbd3bSFrançois Tigeot /**
282a05eeebfSFrançois Tigeot * This function returns immediately and takes the hw lock
283a05eeebfSFrançois Tigeot * with the kernel context if it is free, otherwise it gets the highest priority when and if
284a05eeebfSFrançois Tigeot * it is eventually released.
285a05eeebfSFrançois Tigeot *
286a05eeebfSFrançois Tigeot * This guarantees that the kernel will _eventually_ have the lock _unless_ it is held
287a05eeebfSFrançois Tigeot * by a blocked process. (In the latter case an explicit wait for the hardware lock would cause
288a05eeebfSFrançois Tigeot * a deadlock, which is why the "idlelock" was invented).
289a05eeebfSFrançois Tigeot *
290a05eeebfSFrançois Tigeot * This should be sufficient to wait for GPU idle without
291a05eeebfSFrançois Tigeot * having to worry about starvation.
292a05eeebfSFrançois Tigeot */
293a05eeebfSFrançois Tigeot
294a05eeebfSFrançois Tigeot void drm_legacy_idlelock_take(struct drm_lock_data *lock_data)
295a05eeebfSFrançois Tigeot {
296a05eeebfSFrançois Tigeot int ret;
297a05eeebfSFrançois Tigeot
298a05eeebfSFrançois Tigeot spin_lock_bh(&lock_data->spinlock);
299a05eeebfSFrançois Tigeot lock_data->kernel_waiters++;
300a05eeebfSFrançois Tigeot if (!lock_data->idle_has_lock) {
301a05eeebfSFrançois Tigeot
302a05eeebfSFrançois Tigeot spin_unlock_bh(&lock_data->spinlock);
303a05eeebfSFrançois Tigeot ret = drm_lock_take(lock_data, DRM_KERNEL_CONTEXT);
304a05eeebfSFrançois Tigeot spin_lock_bh(&lock_data->spinlock);
305a05eeebfSFrançois Tigeot
306a05eeebfSFrançois Tigeot if (ret == 1)
307a05eeebfSFrançois Tigeot lock_data->idle_has_lock = 1;
308a05eeebfSFrançois Tigeot }
309a05eeebfSFrançois Tigeot spin_unlock_bh(&lock_data->spinlock);
310a05eeebfSFrançois Tigeot }
311a05eeebfSFrançois Tigeot EXPORT_SYMBOL(drm_legacy_idlelock_take);
312a05eeebfSFrançois Tigeot
313a05eeebfSFrançois Tigeot void drm_legacy_idlelock_release(struct drm_lock_data *lock_data)
314a05eeebfSFrançois Tigeot {
315a05eeebfSFrançois Tigeot unsigned int old, prev;
316a05eeebfSFrançois Tigeot volatile unsigned int *lock = &lock_data->hw_lock->lock;
317a05eeebfSFrançois Tigeot
318a05eeebfSFrançois Tigeot spin_lock_bh(&lock_data->spinlock);
319a05eeebfSFrançois Tigeot if (--lock_data->kernel_waiters == 0) {
320a05eeebfSFrançois Tigeot if (lock_data->idle_has_lock) {
321a05eeebfSFrançois Tigeot do {
322a05eeebfSFrançois Tigeot old = *lock;
323a05eeebfSFrançois Tigeot prev = cmpxchg(lock, old, DRM_KERNEL_CONTEXT);
324a05eeebfSFrançois Tigeot } while (prev != old);
325a05eeebfSFrançois Tigeot wake_up_interruptible(&lock_data->lock_queue);
326a05eeebfSFrançois Tigeot lock_data->idle_has_lock = 0;
327a05eeebfSFrançois Tigeot }
328a05eeebfSFrançois Tigeot }
329a05eeebfSFrançois Tigeot spin_unlock_bh(&lock_data->spinlock);
330a05eeebfSFrançois Tigeot }
331a05eeebfSFrançois Tigeot EXPORT_SYMBOL(drm_legacy_idlelock_release);
332a05eeebfSFrançois Tigeot
3331dedbd3bSFrançois Tigeot static int drm_legacy_i_have_hw_lock(struct drm_device *dev,
334a05eeebfSFrançois Tigeot struct drm_file *file_priv)
335a05eeebfSFrançois Tigeot {
336a05eeebfSFrançois Tigeot struct drm_master *master = file_priv->master;
337a05eeebfSFrançois Tigeot return (file_priv->lock_count && master->lock.hw_lock &&
338a05eeebfSFrançois Tigeot _DRM_LOCK_IS_HELD(master->lock.hw_lock->lock) &&
339a05eeebfSFrançois Tigeot master->lock.file_priv == file_priv);
3401dedbd3bSFrançois Tigeot }
341a05eeebfSFrançois Tigeot #endif
3421dedbd3bSFrançois Tigeot
drm_legacy_lock_release(struct drm_device * dev,struct file * filp)3431dedbd3bSFrançois Tigeot void drm_legacy_lock_release(struct drm_device *dev, struct file *filp)
3441dedbd3bSFrançois Tigeot {
3451dedbd3bSFrançois Tigeot #if 0
3461dedbd3bSFrançois Tigeot struct drm_file *file_priv = filp->private_data;
3471dedbd3bSFrançois Tigeot
3481dedbd3bSFrançois Tigeot /* if the master has gone away we can't do anything with the lock */
3491dedbd3bSFrançois Tigeot if (!dev->master)
3501dedbd3bSFrançois Tigeot return;
3511dedbd3bSFrançois Tigeot
3521dedbd3bSFrançois Tigeot if (drm_legacy_i_have_hw_lock(dev, file_priv)) {
3531dedbd3bSFrançois Tigeot DRM_DEBUG("File %p released, freeing lock for context %d\n",
3541dedbd3bSFrançois Tigeot filp, _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
3551dedbd3bSFrançois Tigeot drm_legacy_lock_free(&file_priv->master->lock,
3561dedbd3bSFrançois Tigeot _DRM_LOCKING_CONTEXT(file_priv->master->lock.hw_lock->lock));
3571dedbd3bSFrançois Tigeot }
3581dedbd3bSFrançois Tigeot #endif
359a05eeebfSFrançois Tigeot }
360