drm_lock.c revision d3d50737e566cade9a08d73d2af95105ac7cd960
d63ae51ba337165172a9b50fd5d84805ffe50044Tinderbox User * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Use is subject to license terms.
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * lock.c -- IOCTLs for locking -*- linux-c -*-
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6f710fce2d5a51b17bfc6f4a0b305c6b603c1304Brian Wellington * All Rights Reserved.
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * Permission is hereby granted, free of charge, to any person obtaining a
9ef9f6b8ae33e6e056ee721739028745dce71737David Lawrence * copy of this software and associated documentation files (the "Software"),
668bd3acee916de774c569449367fee199965ff4Brian Wellington * to deal in the Software without restriction, including without limitation
242bba8991b030b7764f0bdca3922d75c34ea51eAndreas Gustafsson * the rights to use, copy, modify, merge, publish, distribute, sublicense,
4162d3b36d1a3c25724c7e37ce839f67b2352bbbMark Andrews * and/or sell copies of the Software, and to permit persons to whom the
25a66b4e41e2b0a2af4840749bac80ae78c678bfMark Andrews * Software is furnished to do so, subject to the following conditions:
1893b56ef9f5f2bc2a0fbe80d3c6b69df1bdc7c2Michael Sawyer * The above copyright notice and this permission notice (including the next
e560fbdf77b08ff23ab71b107f022829bcd552dbMark Andrews * paragraph) shall be included in all copies or substantial portions of the
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
668bd3acee916de774c569449367fee199965ff4Brian Wellington * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
668bd3acee916de774c569449367fee199965ff4Brian Wellington * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
668f8d91db59f4dd89a0b54206f87879354339f5Brian Wellington * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
83a44df0a1dcc1760c7e4ad45eae801b5144592cBrian Wellington * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews * OTHER DEALINGS IN THE SOFTWARE.
07fffbc8c9ea9f56c80143c70355807a1aaeec21Michael Sawyer * Rickard E. (Rik) Faith <faith@valinux.com>
aa6054ec74819f754bcf19442ca9b39d948171adMichael Sawyer * Gareth Hughes <gareth@valinux.com>
24139527f3d0d3fe743bd867329a2edd529728a6Andreas Gustafssondrm_lock_take(drm_lock_data_t *lock_data, unsigned int context)
24139527f3d0d3fe743bd867329a2edd529728a6Andreas Gustafsson volatile unsigned int *lock = &lock_data->hw_lock->lock;
0e0e575ec135a983a53c501cf48734b823361ab4Brian Wellington } while (!atomic_cmpset_int(lock, old, new));
464c2c673b879071da66cab5a627baf35c5e0f90Evan Hunt /* Have lock */
7ca101656029196bba41ffff632f2c6903f48125Mark Andrews * This takes a lock forcibly and hands it to context. Should ONLY be used
ebbfa36a628b935891b2f8a2c5936aef48b87151Michael Sawyer * inside *_unlock to give lock to kernel before calling *_dma_schedule.
ebbfa36a628b935891b2f8a2c5936aef48b87151Michael Sawyerdrm_lock_transfer(drm_device_t *dev, drm_lock_data_t *lock_data,
ebbfa36a628b935891b2f8a2c5936aef48b87151Michael Sawyer volatile unsigned int *lock = &lock_data->hw_lock->lock;
ebbfa36a628b935891b2f8a2c5936aef48b87151Michael Sawyer } while (!atomic_cmpset_int(lock, old, new));
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrewsdrm_lock_free(drm_device_t *dev, volatile unsigned int *lock,
ce67023ae3ad39a77da5361d0187ab6f3f0219cbMark Andrews unsigned int context)
d302a620e0d49811874b9555ac2e4c6e05861a6bFrancis Dupont DRM_ERROR("%d freed heavyweight lock held by %d\n",
8fbd23c0aaacdde1348b6457c5db14c433096fd2Andreas Gustafsson DRM_COPYFROM_WITH_RETURN(&lock, (void *)data, sizeof (lock));
8fbd23c0aaacdde1348b6457c5db14c433096fd2Andreas Gustafsson if (lock.context == DRM_KERNEL_CONTEXT) {
8fbd23c0aaacdde1348b6457c5db14c433096fd2Andreas Gustafsson DRM_ERROR("Process %d using kernel context %d\n",
e60b3717f0e6f28d6fb2c5124ffb3bd31cc3a746Mark Andrews DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
e60b3717f0e6f28d6fb2c5124ffb3bd31cc3a746Mark Andrews lock.context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
8fbd23c0aaacdde1348b6457c5db14c433096fd2Andreas Gustafsson if (dev->driver->use_dma_queue && lock.context < 0)
92aa706a215dcc26e7ef89cddadaa124b83e06a1Andreas Gustafsson if (drm_lock_take(&dev->lock, lock.context)) {
7949dbdae1db33e6263d754e5940daa1dfba59f9Michael Sawyer break; /* Got lock */
e69ccf6d54db6e749470341e2c84996ecc77e5ecMichael Sawyer DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
b399f4e5684a66123e2f38e0f7e254f0f3ca0cc6Mark Andrews DRM_COPYFROM_WITH_RETURN(&lock, (void *)data, sizeof (lock));
7949dbdae1db33e6263d754e5940daa1dfba59f9Michael Sawyer DRM_DEBUG("%d (pid %d) requests unlock (0x%08x), flags = 0x%08x\n",
b399f4e5684a66123e2f38e0f7e254f0f3ca0cc6Mark Andrews lock.context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
78d78f05d91205cbde33ca87d24b8d13aa2d8d66Brian Wellington DRM_ERROR("Process %d using kernel context %d\n",
b399f4e5684a66123e2f38e0f7e254f0f3ca0cc6Mark Andrews atomic_inc_32(&dev->counts[_DRM_STAT_UNLOCKS]);