d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Use is subject to license terms.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * lock.c -- IOCTLs for locking -*- linux-c -*-
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Created: Tue Feb 2 08:37:54 1999 by faith@valinux.com
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * All Rights Reserved.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Permission is hereby granted, free of charge, to any person obtaining a
60405de4d8688d96dd05157c28db3ade5c9bc234kz * copy of this software and associated documentation files (the "Software"),
60405de4d8688d96dd05157c28db3ade5c9bc234kz * to deal in the Software without restriction, including without limitation
60405de4d8688d96dd05157c28db3ade5c9bc234kz * the rights to use, copy, modify, merge, publish, distribute, sublicense,
60405de4d8688d96dd05157c28db3ade5c9bc234kz * and/or sell copies of the Software, and to permit persons to whom the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Software is furnished to do so, subject to the following conditions:
60405de4d8688d96dd05157c28db3ade5c9bc234kz * The above copyright notice and this permission notice (including the next
60405de4d8688d96dd05157c28db3ade5c9bc234kz * paragraph) shall be included in all copies or substantial portions of the
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Software.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60405de4d8688d96dd05157c28db3ade5c9bc234kz * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60405de4d8688d96dd05157c28db3ade5c9bc234kz * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
60405de4d8688d96dd05157c28db3ade5c9bc234kz * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
60405de4d8688d96dd05157c28db3ade5c9bc234kz * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
60405de4d8688d96dd05157c28db3ade5c9bc234kz * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
60405de4d8688d96dd05157c28db3ade5c9bc234kz * OTHER DEALINGS IN THE SOFTWARE.
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Authors:
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Rickard E. (Rik) Faith <faith@valinux.com>
60405de4d8688d96dd05157c28db3ade5c9bc234kz * Gareth Hughes <gareth@valinux.com>
d0538f66491267879b7418b21ad78e3dcc2dcc83cgdrm_lock_take(drm_lock_data_t *lock_data, unsigned int context)
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China unsigned int old, new;
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China } while (!atomic_cmpset_int(lock, old, new));
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (0);
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China if (new == (context | _DRM_LOCK_HELD)) {
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China /* Have lock */
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (1);
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (0);
60405de4d8688d96dd05157c28db3ade5c9bc234kz * This takes a lock forcibly and hands it to context. Should ONLY be used
60405de4d8688d96dd05157c28db3ade5c9bc234kz * inside *_unlock to give lock to kernel before calling *_dma_schedule.
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing Chinadrm_lock_transfer(drm_device_t *dev, drm_lock_data_t *lock_data,
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China unsigned int context)
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China unsigned int old, new;
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China volatile unsigned int *lock = &lock_data->hw_lock->lock;
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China } while (!atomic_cmpset_int(lock, old, new));
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (1);
d0538f66491267879b7418b21ad78e3dcc2dcc83cgdrm_lock_free(drm_device_t *dev, volatile unsigned int *lock,
60405de4d8688d96dd05157c28db3ade5c9bc234kz unsigned int context)
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China unsigned int old, new;
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China } while (!atomic_cmpset_int(lock, old, new));
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (1);
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (0);
60405de4d8688d96dd05157c28db3ade5c9bc234kz/*ARGSUSED*/
d0538f66491267879b7418b21ad78e3dcc2dcc83cg DRM_COPYFROM_WITH_RETURN(&lock, (void *)data, sizeof (lock));
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China DRM_ERROR("Process %d using kernel context %d\n",
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China DRM_CURRENTPID, lock.context);
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China DRM_DEBUG("%d (pid %d) requests lock (0x%08x), flags = 0x%08x\n",
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China lock.context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
60405de4d8688d96dd05157c28db3ade5c9bc234kz for (;;) {
60405de4d8688d96dd05157c28db3ade5c9bc234kz break; /* Got lock */
60405de4d8688d96dd05157c28db3ade5c9bc234kz if (ret == 0) {
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China DRM_DEBUG("%d %s\n", lock.context, ret ? "interrupted" : "has lock");
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (0);
60405de4d8688d96dd05157c28db3ade5c9bc234kz/*ARGSUSED*/
d0538f66491267879b7418b21ad78e3dcc2dcc83cg DRM_COPYFROM_WITH_RETURN(&lock, (void *)data, sizeof (lock));
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China DRM_DEBUG("%d (pid %d) requests unlock (0x%08x), flags = 0x%08x\n",
d02310705313ee2fcefee164a4b26d1fa85e9d22miao chen - Sun Microsystems - Beijing China lock.context, DRM_CURRENTPID, dev->lock.hw_lock->lock,
d0538f66491267879b7418b21ad78e3dcc2dcc83cg if (drm_lock_free(dev, &dev->lock.hw_lock->lock, lock.context)) {
60405de4d8688d96dd05157c28db3ade5c9bc234kz return (0);