From a9ac4482b30a6c0605139f2e6527c379f24e7486 Mon Sep 17 00:00:00 2001 From: Imre Deak Date: Wed, 31 Mar 2010 14:55:54 +0300 Subject: [PATCH] gpu: pvr: add pvr_lock/remove unneeded lock headers - Add a public interface for accessing this lock. It has been used as a public interface anyway and an upcoming patch needs to access it as well. - Remove headers becoming unnecessary by this refactoring. Note: Currently this lock provides for a course level locking protecting all HW and SW state tracking objects. We'll need to revise the use of the following additional locks in the driver. Their existance might not be justified, in which case we could just substitute them with pvr_lock: PVRSRVDvfsLock PVRSRVPowerLock Signed-off-by: Imre Deak --- pvr/event.c | 7 +++---- pvr/lock.h | 31 ------------------------------- pvr/mm.c | 2 -- pvr/mmap.c | 1 - pvr/module.c | 16 +++++++--------- pvr/mutex.h | 36 ------------------------------------ pvr/osfunc.c | 1 - pvr/pvr_bridge_k.c | 13 ++++++++----- pvr/pvr_bridge_km.h | 17 +++++++++++++++++ pvr/pvr_debug.c | 1 - 10 files changed, 35 insertions(+), 90 deletions(-) delete mode 100644 pvr/lock.h delete mode 100644 pvr/mutex.h diff --git a/pvr/event.c b/pvr/event.c index e538100..3dc4ab5 100644 --- a/pvr/event.c +++ b/pvr/event.c @@ -50,9 +50,8 @@ #include "mmap.h" #include "env_data.h" #include "proc.h" -#include "mutex.h" -#include "lock.h" #include "event.h" +#include "pvr_bridge_km.h" struct PVRSRV_LINUX_EVENT_OBJECT_LIST { rwlock_t sLock; @@ -249,12 +248,12 @@ enum PVRSRV_ERROR LinuxEventObjectWait(void *hOSEventObject, u32 ui32MSTimeout) if (psLinuxEventObject->ui32TimeStampPrevious != ui32TimeStamp) break; - mutex_unlock(&gPVRSRVLock); + pvr_unlock(); ui32TimeOutJiffies = (u32) schedule_timeout((s32) ui32TimeOutJiffies); - mutex_lock(&gPVRSRVLock); + pvr_lock(); #if defined(DEBUG) psLinuxEventObject->ui32Stats++; #endif diff --git a/pvr/lock.h b/pvr/lock.h deleted file mode 100644 index c3b6ff3..0000000 --- a/pvr/lock.h +++ /dev/null @@ -1,31 +0,0 @@ -/********************************************************************** - * - * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful but, except - * as otherwise stated in writing, without any warranty; without even the - * implied warranty of merchantability or fitness for a particular purpose. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - * The full GNU General Public License is included in this distribution in - * the file called "COPYING". - * - * Contact Information: - * Imagination Technologies Ltd. - * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK - * - ******************************************************************************/ -#ifndef __LOCK_H__ -#define __LOCK_H__ - -extern struct mutex gPVRSRVLock; - -#endif diff --git a/pvr/mm.c b/pvr/mm.c index 29bdd93..c0a92f2 100644 --- a/pvr/mm.c +++ b/pvr/mm.c @@ -44,8 +44,6 @@ #include "osfunc.h" #include "pvr_debug.h" #include "proc.h" -#include "mutex.h" -#include "lock.h" #if defined(DEBUG_LINUX_MEMORY_ALLOCATIONS) enum DEBUG_MEM_ALLOC_TYPE { diff --git a/pvr/mmap.c b/pvr/mmap.c index 7b3b784..240d121 100644 --- a/pvr/mmap.c +++ b/pvr/mmap.c @@ -46,7 +46,6 @@ #include "pvr_debug.h" #include "osfunc.h" #include "proc.h" -#include "mutex.h" #include "handle.h" #include "perproc.h" #include "env_perproc.h" diff --git a/pvr/module.c b/pvr/module.c index c630f4d..29062b2 100644 --- a/pvr/module.c +++ b/pvr/module.c @@ -43,7 +43,6 @@ #include "mutils.h" #include "mm.h" #include "mmap.h" -#include "mutex.h" #include "pvr_debug.h" #include "srvkm.h" #include "perproc.h" @@ -53,7 +52,6 @@ #include "proc.h" #include "pvrmodule.h" #include "private_data.h" -#include "lock.h" #define DRVNAME "pvrsrvkm" @@ -63,8 +61,6 @@ static int debug = DBGPRIV_WARNING; module_param(debug, int, 0); #endif -struct mutex gPVRSRVLock; - static int pvr_open(struct inode unref__ * inode, struct file *filp) { struct PVRSRV_FILE_PRIVATE_DATA *priv; @@ -73,7 +69,7 @@ static int pvr_open(struct inode unref__ * inode, struct file *filp) enum PVRSRV_ERROR err; u32 pid; - mutex_lock(&gPVRSRVLock); + pvr_lock(); pid = OSGetCurrentProcessIDKM(); @@ -93,7 +89,8 @@ static int pvr_open(struct inode unref__ * inode, struct file *filp) ret = 0; err_unlock: - mutex_unlock(&gPVRSRVLock); + pvr_unlock(); + return ret; } @@ -101,7 +98,7 @@ static int pvr_release(struct inode unref__ * inode, struct file *filp) { struct PVRSRV_FILE_PRIVATE_DATA *priv; - mutex_lock(&gPVRSRVLock); + pvr_lock(); priv = filp->private_data; @@ -111,7 +108,8 @@ static int pvr_release(struct inode unref__ * inode, struct file *filp) sizeof(*priv), priv, priv->hBlockAlloc); - mutex_unlock(&gPVRSRVLock); + pvr_unlock(); + return 0; } @@ -218,7 +216,7 @@ static int __init pvr_init(void) PVR_TRACE("pvr_init"); - mutex_init(&gPVRSRVLock); + pvr_init_lock(); #ifdef DEBUG PVRDebugSetLevel(debug); diff --git a/pvr/mutex.h b/pvr/mutex.h deleted file mode 100644 index cbd963a..0000000 --- a/pvr/mutex.h +++ /dev/null @@ -1,36 +0,0 @@ -/********************************************************************** - * - * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful but, except - * as otherwise stated in writing, without any warranty; without even the - * implied warranty of merchantability or fitness for a particular purpose. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - * The full GNU General Public License is included in this distribution in - * the file called "COPYING". - * - * Contact Information: - * Imagination Technologies Ltd. - * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK - * - ******************************************************************************/ - -#ifndef __INCLUDED_LINUX_MUTEX_H_ -#define __INCLUDED_LINUX_MUTEX_H_ - -#include - -#include - -extern struct mutex gPVRSRVLock; - -#endif diff --git a/pvr/osfunc.c b/pvr/osfunc.c index 07f1662..c0d0ba7 100644 --- a/pvr/osfunc.c +++ b/pvr/osfunc.c @@ -52,7 +52,6 @@ #include "mmap.h" #include "env_data.h" #include "proc.h" -#include "mutex.h" #include "event.h" #define EVENT_OBJECT_TIMEOUT_MS (100) diff --git a/pvr/pvr_bridge_k.c b/pvr/pvr_bridge_k.c index 9053a3e..7099647 100644 --- a/pvr/pvr_bridge_k.c +++ b/pvr/pvr_bridge_k.c @@ -29,7 +29,6 @@ #include "pvr_bridge.h" #include "pvr_bridge_km.h" #include "perproc.h" -#include "mutex.h" #include "syscommon.h" #include "pvr_debug.h" #include "proc.h" @@ -39,6 +38,8 @@ #include "bridged_pvr_bridge.h" +/* Global driver lock protecting all HW and SW state tracking objects. */ +struct mutex gPVRSRVLock; #if defined(DEBUG_BRIDGE_KM) static off_t printLinuxBridgeStats(char *buffer, size_t size, off_t off); @@ -71,7 +72,7 @@ static off_t printLinuxBridgeStats(char *buffer, size_t count, off_t off) struct PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY *psEntry; off_t Ret; - mutex_lock(&gPVRSRVLock); + pvr_lock(); if (!off) { if (count < 500) { @@ -116,7 +117,8 @@ static off_t printLinuxBridgeStats(char *buffer, size_t count, off_t off) psEntry->ui32CopyToUserTotalBytes); unlock_and_return: - mutex_unlock(&gPVRSRVLock); + pvr_unlock(); + return Ret; } #endif @@ -132,7 +134,7 @@ long PVRSRV_BridgeDispatchKM(struct file *file, unsigned int cmd, struct PVRSRV_PER_PROCESS_DATA *psPerProc; int err = -EFAULT; - mutex_lock(&gPVRSRVLock); + pvr_lock(); if (!OSAccessOK(PVR_VERIFY_WRITE, psBridgePackageUM, sizeof(struct PVRSRV_BRIDGE_PACKAGE))) { @@ -186,6 +188,7 @@ long PVRSRV_BridgeDispatchKM(struct file *file, unsigned int cmd, goto unlock_and_return; unlock_and_return: - mutex_unlock(&gPVRSRVLock); + pvr_unlock(); + return err; } diff --git a/pvr/pvr_bridge_km.h b/pvr/pvr_bridge_km.h index 0c60a42..dfae4f4 100644 --- a/pvr/pvr_bridge_km.h +++ b/pvr/pvr_bridge_km.h @@ -32,6 +32,23 @@ #include "pvr_bridge.h" #include "perproc.h" +extern struct mutex gPVRSRVLock; + +static inline void pvr_lock(void) +{ + mutex_lock(&gPVRSRVLock); +} + +static inline void pvr_unlock(void) +{ + mutex_unlock(&gPVRSRVLock); +} + +static inline void pvr_init_lock(void) +{ + mutex_init(&gPVRSRVLock); +} + enum PVRSRV_ERROR LinuxBridgeInit(void); void LinuxBridgeDeInit(void); diff --git a/pvr/pvr_debug.c b/pvr/pvr_debug.c index eec9075..5dff963 100644 --- a/pvr/pvr_debug.c +++ b/pvr/pvr_debug.c @@ -37,7 +37,6 @@ #include "servicesext.h" #include "pvr_debug.h" #include "proc.h" -#include "mutex.h" #include "syscommon.h" #include "sgxinfokm.h" #include "sgxutils.h" -- 2.39.5