Home | History | Annotate | Line # | Download | only in drm
drm_lock.c revision 1.1.2.4
      1  1.1.2.1  riastrad /*	$NetBSD: drm_lock.c,v 1.1.2.4 2014/01/15 13:53:53 riastradh Exp $	*/
      2  1.1.2.1  riastrad 
      3  1.1.2.1  riastrad /*-
      4  1.1.2.1  riastrad  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  1.1.2.1  riastrad  * All rights reserved.
      6  1.1.2.1  riastrad  *
      7  1.1.2.1  riastrad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.1  riastrad  * by Taylor R. Campbell.
      9  1.1.2.1  riastrad  *
     10  1.1.2.1  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.1  riastrad  * modification, are permitted provided that the following conditions
     12  1.1.2.1  riastrad  * are met:
     13  1.1.2.1  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.1  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.1  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.1  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.1  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.1  riastrad  *
     19  1.1.2.1  riastrad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.2.1  riastrad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.2.1  riastrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.2.1  riastrad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.2.1  riastrad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.2.1  riastrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.2.1  riastrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.2.1  riastrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.2.1  riastrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.2.1  riastrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.2.1  riastrad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.2.1  riastrad  */
     31  1.1.2.1  riastrad 
     32  1.1.2.1  riastrad /*
     33  1.1.2.4  riastrad  * DRM lock.  Each drm master has a heavy-weight lock to provide mutual
     34  1.1.2.4  riastrad  * exclusion for access to the hardware.  The lock can be held by the
     35  1.1.2.4  riastrad  * kernel or by a drm file; the kernel takes access only for unusual
     36  1.1.2.4  riastrad  * purposes, with drm_idlelock_take, mainly for idling the GPU when
     37  1.1.2.4  riastrad  * closing down.
     38  1.1.2.1  riastrad  *
     39  1.1.2.4  riastrad  * The physical memory storing the lock state is shared between
     40  1.1.2.4  riastrad  * userland and kernel: the pointer at dev->master->lock->hw_lock is
     41  1.1.2.4  riastrad  * mapped into both userland and kernel address spaces.  This way,
     42  1.1.2.4  riastrad  * userland can try to take the hardware lock without a system call,
     43  1.1.2.4  riastrad  * although if it fails then it will use the DRM_LOCK ioctl to block
     44  1.1.2.4  riastrad  * atomically until the lock is available.  All this means that the
     45  1.1.2.4  riastrad  * kernel must use atomic_ops to manage the lock state.
     46  1.1.2.1  riastrad  */
     47  1.1.2.1  riastrad 
     48  1.1.2.1  riastrad #include <sys/cdefs.h>
     49  1.1.2.1  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_lock.c,v 1.1.2.4 2014/01/15 13:53:53 riastradh Exp $");
     50  1.1.2.1  riastrad 
     51  1.1.2.1  riastrad #include <sys/types.h>
     52  1.1.2.1  riastrad #include <sys/errno.h>
     53  1.1.2.1  riastrad #include <sys/systm.h>
     54  1.1.2.1  riastrad 
     55  1.1.2.1  riastrad #include <drm/drmP.h>
     56  1.1.2.1  riastrad 
     57  1.1.2.1  riastrad static bool	drm_lock_acquire(struct drm_lock_data *, int);
     58  1.1.2.1  riastrad static void	drm_lock_release(struct drm_lock_data *, int);
     59  1.1.2.1  riastrad static int	drm_lock_block_signals(struct drm_device *, struct drm_lock *,
     60  1.1.2.1  riastrad 		    struct drm_file *);
     61  1.1.2.1  riastrad static void	drm_lock_unblock_signals(struct drm_device *,
     62  1.1.2.1  riastrad 		    struct drm_lock *, struct drm_file *);
     63  1.1.2.1  riastrad 
     64  1.1.2.1  riastrad /*
     65  1.1.2.1  riastrad  * Take the lock on behalf of userland.
     66  1.1.2.1  riastrad  */
     67  1.1.2.1  riastrad int
     68  1.1.2.1  riastrad drm_lock(struct drm_device *dev, void *data, struct drm_file *file)
     69  1.1.2.1  riastrad {
     70  1.1.2.1  riastrad 	struct drm_lock *lock_request = data;
     71  1.1.2.1  riastrad 	struct drm_master *master = file->master;
     72  1.1.2.1  riastrad 	int error;
     73  1.1.2.1  riastrad 
     74  1.1.2.4  riastrad 	/* Sanitize the drm global mutex bollocks until we get rid of it.  */
     75  1.1.2.1  riastrad 	KASSERT(mutex_is_locked(&drm_global_mutex));
     76  1.1.2.4  riastrad 	mutex_unlock(&drm_global_mutex);
     77  1.1.2.1  riastrad 
     78  1.1.2.1  riastrad 	/* Refuse to lock on behalf of the kernel.  */
     79  1.1.2.4  riastrad 	if (lock_request->context == DRM_KERNEL_CONTEXT) {
     80  1.1.2.4  riastrad 		error = -EINVAL;
     81  1.1.2.4  riastrad 		goto out0;
     82  1.1.2.4  riastrad 	}
     83  1.1.2.4  riastrad 
     84  1.1.2.4  riastrad 	/* Refuse to set the magic bits.  */
     85  1.1.2.4  riastrad 	if (lock_request->context !=
     86  1.1.2.4  riastrad 	    _DRM_LOCKING_CONTEXT(lock_request->context)) {
     87  1.1.2.4  riastrad 		error = -EINVAL;
     88  1.1.2.4  riastrad 		goto out0;
     89  1.1.2.4  riastrad 	}
     90  1.1.2.1  riastrad 
     91  1.1.2.1  riastrad 	/* Count it in the file and device statistics (XXX why here?).  */
     92  1.1.2.1  riastrad 	file->lock_count++;
     93  1.1.2.1  riastrad 	atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
     94  1.1.2.1  riastrad 
     95  1.1.2.1  riastrad 	/* Wait until the hardware lock is gone or we can acquire it.   */
     96  1.1.2.1  riastrad 	spin_lock(&master->lock.spinlock);
     97  1.1.2.4  riastrad 
     98  1.1.2.4  riastrad 	if (master->lock.user_waiters == UINT32_MAX) {
     99  1.1.2.4  riastrad 		error = -EBUSY;
    100  1.1.2.4  riastrad 		goto out1;
    101  1.1.2.4  riastrad 	}
    102  1.1.2.4  riastrad 
    103  1.1.2.4  riastrad 	master->lock.user_waiters++;
    104  1.1.2.1  riastrad 	DRM_SPIN_WAIT_UNTIL(error, &master->lock.lock_queue,
    105  1.1.2.1  riastrad 	    &master->lock.spinlock,
    106  1.1.2.1  riastrad 	    ((master->lock.hw_lock == NULL) ||
    107  1.1.2.4  riastrad 		drm_lock_acquire(&master->lock, lock_request->context)));
    108  1.1.2.4  riastrad 	KASSERT(0 < master->lock.user_waiters);
    109  1.1.2.4  riastrad 	master->lock.user_waiters--;
    110  1.1.2.1  riastrad 	if (error)
    111  1.1.2.4  riastrad 		goto out1;
    112  1.1.2.1  riastrad 
    113  1.1.2.1  riastrad 	/* If the lock is gone, give up.  */
    114  1.1.2.1  riastrad 	if (master->lock.hw_lock == NULL) {
    115  1.1.2.1  riastrad #if 0				/* XXX Linux sends SIGTERM, but why?  */
    116  1.1.2.1  riastrad 		mutex_enter(proc_lock);
    117  1.1.2.1  riastrad 		psignal(curproc, SIGTERM);
    118  1.1.2.1  riastrad 		mutex_exit(proc_lock);
    119  1.1.2.1  riastrad 		error = -EINTR;
    120  1.1.2.1  riastrad #else
    121  1.1.2.1  riastrad 		error = -ENXIO;
    122  1.1.2.1  riastrad #endif
    123  1.1.2.4  riastrad 		goto out1;
    124  1.1.2.1  riastrad 	}
    125  1.1.2.1  riastrad 
    126  1.1.2.1  riastrad 	/* Mark the lock as owned by file.  */
    127  1.1.2.1  riastrad 	master->lock.file_priv = file;
    128  1.1.2.1  riastrad 	master->lock.lock_time = jiffies; /* XXX Unused?  */
    129  1.1.2.1  riastrad 
    130  1.1.2.1  riastrad 	/* Block signals while the lock is held.  */
    131  1.1.2.1  riastrad 	error = drm_lock_block_signals(dev, lock_request, file);
    132  1.1.2.1  riastrad 	if (error)
    133  1.1.2.4  riastrad 		goto fail2;
    134  1.1.2.1  riastrad 
    135  1.1.2.1  riastrad 	/* Enter the DMA quiescent state if requested and available.  */
    136  1.1.2.4  riastrad 	/* XXX Drop the spin lock first...  */
    137  1.1.2.1  riastrad 	if (ISSET(lock_request->flags, _DRM_LOCK_QUIESCENT) &&
    138  1.1.2.1  riastrad 	    (dev->driver->dma_quiescent != NULL)) {
    139  1.1.2.1  riastrad 		error = (*dev->driver->dma_quiescent)(dev);
    140  1.1.2.1  riastrad 		if (error)
    141  1.1.2.4  riastrad 			goto fail3;
    142  1.1.2.1  riastrad 	}
    143  1.1.2.1  riastrad 
    144  1.1.2.1  riastrad 	/* Success!  */
    145  1.1.2.1  riastrad 	error = 0;
    146  1.1.2.4  riastrad 	goto out1;
    147  1.1.2.1  riastrad 
    148  1.1.2.4  riastrad fail3:	drm_lock_unblock_signals(dev, lock_request, file);
    149  1.1.2.4  riastrad fail2:	drm_lock_release(&master->lock, lock_request->context);
    150  1.1.2.1  riastrad 	master->lock.file_priv = NULL;
    151  1.1.2.4  riastrad out1:	spin_unlock(&master->lock.spinlock);
    152  1.1.2.4  riastrad out0:	mutex_lock(&drm_global_mutex);
    153  1.1.2.1  riastrad 	return error;
    154  1.1.2.1  riastrad }
    155  1.1.2.1  riastrad 
    156  1.1.2.1  riastrad /*
    157  1.1.2.1  riastrad  * Try to relinquish a lock that userland thinks it holds, per
    158  1.1.2.1  riastrad  * userland's request.  Fail if it doesn't actually hold the lock.
    159  1.1.2.1  riastrad  */
    160  1.1.2.1  riastrad int
    161  1.1.2.1  riastrad drm_unlock(struct drm_device *dev, void *data, struct drm_file *file)
    162  1.1.2.1  riastrad {
    163  1.1.2.1  riastrad 	struct drm_lock *lock_request = data;
    164  1.1.2.1  riastrad 	struct drm_master *master = file->master;
    165  1.1.2.1  riastrad 	int error;
    166  1.1.2.1  riastrad 
    167  1.1.2.4  riastrad 	/* Sanitize the drm global mutex bollocks until we get rid of it.  */
    168  1.1.2.1  riastrad 	KASSERT(mutex_is_locked(&drm_global_mutex));
    169  1.1.2.4  riastrad 	mutex_unlock(&drm_global_mutex);
    170  1.1.2.1  riastrad 
    171  1.1.2.1  riastrad 	/* Refuse to unlock on behalf of the kernel.  */
    172  1.1.2.4  riastrad 	if (lock_request->context == DRM_KERNEL_CONTEXT) {
    173  1.1.2.4  riastrad 		error = -EINVAL;
    174  1.1.2.4  riastrad 		goto out0;
    175  1.1.2.4  riastrad 	}
    176  1.1.2.1  riastrad 
    177  1.1.2.1  riastrad 	/* Count it in the device statistics.  */
    178  1.1.2.1  riastrad 	atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
    179  1.1.2.1  riastrad 
    180  1.1.2.1  riastrad 	/* Lock the internal spin lock to make changes.  */
    181  1.1.2.1  riastrad 	spin_lock(&master->lock.spinlock);
    182  1.1.2.1  riastrad 
    183  1.1.2.1  riastrad 	/* Make sure it's actually locked.  */
    184  1.1.2.1  riastrad 	if (!_DRM_LOCK_IS_HELD(master->lock.hw_lock->lock)) {
    185  1.1.2.1  riastrad 		error = -EINVAL;	/* XXX Right error?  */
    186  1.1.2.4  riastrad 		goto out1;
    187  1.1.2.1  riastrad 	}
    188  1.1.2.1  riastrad 
    189  1.1.2.1  riastrad 	/* Make sure it's locked in the right context.  */
    190  1.1.2.1  riastrad 	if (_DRM_LOCKING_CONTEXT(master->lock.hw_lock->lock) !=
    191  1.1.2.1  riastrad 	    lock_request->context) {
    192  1.1.2.1  riastrad 		error = -EACCES;	/* XXX Right error?  */
    193  1.1.2.4  riastrad 		goto out1;
    194  1.1.2.1  riastrad 	}
    195  1.1.2.1  riastrad 
    196  1.1.2.1  riastrad 	/* Make sure it's locked by us.  */
    197  1.1.2.1  riastrad 	if (master->lock.file_priv != file) {
    198  1.1.2.1  riastrad 		error = -EACCES;	/* XXX Right error?  */
    199  1.1.2.4  riastrad 		goto out1;
    200  1.1.2.1  riastrad 	}
    201  1.1.2.1  riastrad 
    202  1.1.2.1  riastrad 	/* Actually release the lock.  */
    203  1.1.2.1  riastrad 	drm_lock_release(&master->lock, lock_request->context);
    204  1.1.2.1  riastrad 
    205  1.1.2.1  riastrad 	/* Clear the lock's file pointer, just in case.  */
    206  1.1.2.1  riastrad 	master->lock.file_priv = NULL;
    207  1.1.2.1  riastrad 
    208  1.1.2.1  riastrad 	/* Unblock the signals we blocked in drm_lock.  */
    209  1.1.2.1  riastrad 	drm_lock_unblock_signals(dev, lock_request, file);
    210  1.1.2.1  riastrad 
    211  1.1.2.1  riastrad 	/* Success!  */
    212  1.1.2.1  riastrad 	error = 0;
    213  1.1.2.1  riastrad 
    214  1.1.2.4  riastrad out1:	spin_unlock(&master->lock.spinlock);
    215  1.1.2.4  riastrad out0:	mutex_lock(&drm_global_mutex);
    216  1.1.2.1  riastrad 	return error;
    217  1.1.2.1  riastrad }
    218  1.1.2.1  riastrad 
    219  1.1.2.1  riastrad /*
    220  1.1.2.2  riastrad  * Drop the lock.
    221  1.1.2.2  riastrad  *
    222  1.1.2.2  riastrad  * Return value is an artefact of Linux.  Caller must guarantee
    223  1.1.2.2  riastrad  * preconditions; failure is fatal.
    224  1.1.2.4  riastrad  *
    225  1.1.2.4  riastrad  * XXX Should we also unblock signals like drm_unlock does?
    226  1.1.2.2  riastrad  */
    227  1.1.2.2  riastrad int
    228  1.1.2.2  riastrad drm_lock_free(struct drm_lock_data *lock_data, unsigned int context)
    229  1.1.2.2  riastrad {
    230  1.1.2.2  riastrad 
    231  1.1.2.2  riastrad 	spin_lock(&lock_data->spinlock);
    232  1.1.2.2  riastrad 	drm_lock_release(lock_data, context);
    233  1.1.2.2  riastrad 	spin_unlock(&lock_data->spinlock);
    234  1.1.2.2  riastrad 
    235  1.1.2.2  riastrad 	return 0;
    236  1.1.2.2  riastrad }
    237  1.1.2.2  riastrad 
    238  1.1.2.2  riastrad /*
    239  1.1.2.1  riastrad  * Take the lock for the kernel's use.
    240  1.1.2.3  riastrad  *
    241  1.1.2.3  riastrad  * XXX This is unimplemented because it's not clear that the Linux code
    242  1.1.2.3  riastrad  * makes sense at all.  Linux's drm_idlelock_take never blocks, but it
    243  1.1.2.3  riastrad  * doesn't guarantee that the kernel holds the lock on return!  For
    244  1.1.2.3  riastrad  * now, I'll hope that the code paths relying on this don't matter yet.
    245  1.1.2.1  riastrad  */
    246  1.1.2.1  riastrad void
    247  1.1.2.1  riastrad drm_idlelock_take(struct drm_lock_data *lock_data __unused)
    248  1.1.2.1  riastrad {
    249  1.1.2.1  riastrad 	KASSERT(mutex_is_locked(&drm_global_mutex));
    250  1.1.2.1  riastrad 	panic("drm_idlelock_take is not yet implemented"); /* XXX */
    251  1.1.2.1  riastrad }
    252  1.1.2.1  riastrad 
    253  1.1.2.1  riastrad /*
    254  1.1.2.1  riastrad  * Release the lock from the kernel.
    255  1.1.2.1  riastrad  */
    256  1.1.2.1  riastrad void
    257  1.1.2.1  riastrad drm_idlelock_release(struct drm_lock_data *lock_data __unused)
    258  1.1.2.1  riastrad {
    259  1.1.2.1  riastrad 	KASSERT(mutex_is_locked(&drm_global_mutex));
    260  1.1.2.1  riastrad 	panic("drm_idlelock_release is not yet implemented"); /* XXX */
    261  1.1.2.1  riastrad }
    262  1.1.2.1  riastrad 
    263  1.1.2.1  riastrad /*
    264  1.1.2.2  riastrad  * Does this file hold this drm device's hardware lock?
    265  1.1.2.4  riastrad  *
    266  1.1.2.4  riastrad  * Used to decide whether to release the lock when the file is being
    267  1.1.2.4  riastrad  * closed.
    268  1.1.2.4  riastrad  *
    269  1.1.2.4  riastrad  * XXX I don't think this answers correctly in the case that the
    270  1.1.2.4  riastrad  * userland has taken the lock and it is uncontended.  But I don't
    271  1.1.2.4  riastrad  * think we can know what the correct answer is in that case.
    272  1.1.2.2  riastrad  */
    273  1.1.2.2  riastrad int
    274  1.1.2.2  riastrad drm_i_have_hw_lock(struct drm_device *dev, struct drm_file *file)
    275  1.1.2.2  riastrad {
    276  1.1.2.2  riastrad 	struct drm_lock_data *const lock_data = &file->master->lock;
    277  1.1.2.4  riastrad 	int answer = 0;
    278  1.1.2.2  riastrad 
    279  1.1.2.2  riastrad 	/* If this file has never locked anything, then no.  */
    280  1.1.2.2  riastrad 	if (file->lock_count == 0)
    281  1.1.2.2  riastrad 		return 0;
    282  1.1.2.2  riastrad 
    283  1.1.2.4  riastrad 	spin_lock(&lock_data->spinlock);
    284  1.1.2.4  riastrad 
    285  1.1.2.2  riastrad 	/* If there is no lock, then this file doesn't hold it.  */
    286  1.1.2.2  riastrad 	if (lock_data->hw_lock == NULL)
    287  1.1.2.4  riastrad 		goto out;
    288  1.1.2.2  riastrad 
    289  1.1.2.2  riastrad 	/* If this lock is not held, then this file doesn't hold it.   */
    290  1.1.2.2  riastrad 	if (!_DRM_LOCK_IS_HELD(lock_data->hw_lock->lock))
    291  1.1.2.4  riastrad 		goto out;
    292  1.1.2.2  riastrad 
    293  1.1.2.2  riastrad 	/*
    294  1.1.2.2  riastrad 	 * Otherwise, it boils down to whether this file is the owner
    295  1.1.2.2  riastrad 	 * or someone else.
    296  1.1.2.4  riastrad 	 *
    297  1.1.2.4  riastrad 	 * XXX This is not reliable!  Userland doesn't update this when
    298  1.1.2.4  riastrad 	 * it takes the lock...
    299  1.1.2.2  riastrad 	 */
    300  1.1.2.4  riastrad 	answer = (file == lock_data->file_priv);
    301  1.1.2.4  riastrad 
    302  1.1.2.4  riastrad out:	spin_unlock(&lock_data->spinlock);
    303  1.1.2.4  riastrad 	return answer;
    304  1.1.2.2  riastrad }
    305  1.1.2.2  riastrad 
    306  1.1.2.2  riastrad /*
    307  1.1.2.1  riastrad  * Try to acquire the lock.  Return true if successful, false if not.
    308  1.1.2.1  riastrad  *
    309  1.1.2.4  riastrad  * This is hairy because it races with userland, and if userland
    310  1.1.2.4  riastrad  * already holds the lock, we must tell it, by marking it
    311  1.1.2.4  riastrad  * _DRM_LOCK_CONT (contended), that it must call ioctl(DRM_UNLOCK) to
    312  1.1.2.4  riastrad  * release the lock so that we can wake waiters.
    313  1.1.2.4  riastrad  *
    314  1.1.2.4  riastrad  * XXX What happens if the process is interrupted?
    315  1.1.2.1  riastrad  */
    316  1.1.2.1  riastrad static bool
    317  1.1.2.1  riastrad drm_lock_acquire(struct drm_lock_data *lock_data, int context)
    318  1.1.2.1  riastrad {
    319  1.1.2.4  riastrad         volatile unsigned int *const lock = &lock_data->hw_lock->lock;
    320  1.1.2.4  riastrad 	unsigned int old, new;
    321  1.1.2.1  riastrad 
    322  1.1.2.1  riastrad 	KASSERT(spin_is_locked(&lock_data->spinlock));
    323  1.1.2.1  riastrad 
    324  1.1.2.4  riastrad 	do {
    325  1.1.2.4  riastrad 		old = *lock;
    326  1.1.2.4  riastrad 		if (!_DRM_LOCK_IS_HELD(old)) {
    327  1.1.2.4  riastrad 			new = (context | _DRM_LOCK_HELD);
    328  1.1.2.4  riastrad 			if ((0 < lock_data->user_waiters) ||
    329  1.1.2.4  riastrad 			    (0 < lock_data->kernel_waiters))
    330  1.1.2.4  riastrad 				new |= _DRM_LOCK_CONT;
    331  1.1.2.4  riastrad 		} else if (_DRM_LOCKING_CONTEXT(old) != context) {
    332  1.1.2.4  riastrad 			new = (old | _DRM_LOCK_CONT);
    333  1.1.2.4  riastrad 		} else {
    334  1.1.2.4  riastrad 			DRM_ERROR("%d already holds heavyweight lock\n",
    335  1.1.2.4  riastrad 			    context);
    336  1.1.2.4  riastrad 			return false;
    337  1.1.2.4  riastrad 		}
    338  1.1.2.4  riastrad 	} while (atomic_cas_uint(lock, old, new) != old);
    339  1.1.2.4  riastrad 
    340  1.1.2.4  riastrad 	return !_DRM_LOCK_IS_HELD(old);
    341  1.1.2.1  riastrad }
    342  1.1.2.1  riastrad 
    343  1.1.2.1  riastrad /*
    344  1.1.2.1  riastrad  * Release the lock held in the given context.  Wake any waiters,
    345  1.1.2.1  riastrad  * preferring kernel waiters over userland waiters.
    346  1.1.2.1  riastrad  *
    347  1.1.2.1  riastrad  * Lock's spinlock must be held and lock must be held in this context.
    348  1.1.2.1  riastrad  */
    349  1.1.2.1  riastrad static void
    350  1.1.2.1  riastrad drm_lock_release(struct drm_lock_data *lock_data, int context)
    351  1.1.2.1  riastrad {
    352  1.1.2.1  riastrad 
    353  1.1.2.1  riastrad 	(void)context;		/* ignore */
    354  1.1.2.1  riastrad 	KASSERT(spin_is_locked(&lock_data->spinlock));
    355  1.1.2.1  riastrad 	KASSERT(_DRM_LOCK_IS_HELD(lock_data->hw_lock->lock));
    356  1.1.2.1  riastrad 	KASSERT(_DRM_LOCKING_CONTEXT(lock_data->hw_lock->lock) == context);
    357  1.1.2.1  riastrad 
    358  1.1.2.4  riastrad 	lock_data->hw_lock->lock = 0;
    359  1.1.2.4  riastrad 	DRM_SPIN_WAKEUP_ONE(&lock_data->lock_queue, &lock_data->spinlock);
    360  1.1.2.1  riastrad }
    361  1.1.2.1  riastrad 
    362  1.1.2.1  riastrad /*
    363  1.1.2.1  riastrad  * Block signals for a process that holds a drm lock.
    364  1.1.2.1  riastrad  *
    365  1.1.2.1  riastrad  * XXX It's not processes but files that hold drm locks, so blocking
    366  1.1.2.1  riastrad  * signals in a process seems wrong, and it's not clear that blocking
    367  1.1.2.1  riastrad  * signals automatically is remotely sensible anyway.
    368  1.1.2.1  riastrad  */
    369  1.1.2.1  riastrad static int
    370  1.1.2.1  riastrad drm_lock_block_signals(struct drm_device *dev __unused,
    371  1.1.2.1  riastrad     struct drm_lock *lock_request __unused, struct drm_file *file __unused)
    372  1.1.2.1  riastrad {
    373  1.1.2.1  riastrad 	return 0;
    374  1.1.2.1  riastrad }
    375  1.1.2.1  riastrad 
    376  1.1.2.1  riastrad /*
    377  1.1.2.1  riastrad  * Unblock the signals that drm_lock_block_signals blocked.
    378  1.1.2.1  riastrad  */
    379  1.1.2.1  riastrad static void
    380  1.1.2.1  riastrad drm_lock_unblock_signals(struct drm_device *dev __unused,
    381  1.1.2.1  riastrad     struct drm_lock *lock_request __unused, struct drm_file *file __unused)
    382  1.1.2.1  riastrad {
    383  1.1.2.1  riastrad }
    384