]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/device-ti-proprietary-open.git/blob - jacinto6/sgx_src/eurasia_km/services4/srvkm/env/linux/mutex.c
jacinto6: sgx: update DDK version to 1.12/2701748
[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / srvkm / env / linux / mutex.c
1 /*************************************************************************/ /*!
2 @Title          Linux mutex interface
3 @Copyright      Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License        Dual MIT/GPLv2
6 The contents of this file are subject to the MIT license as set out below.
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
30 This License is also included in this distribution in the file called
31 "MIT-COPYING".
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */ /**************************************************************************/
42 #include <linux/version.h>
43 #include <linux/errno.h>
44 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
45 #include <linux/mutex.h>
46 #else
47 #include <asm/semaphore.h>
48 #endif
49 #include <linux/module.h>
51 #include <img_defs.h>
52 #include <services.h>
54 #include "mutex.h"
57 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
59 IMG_VOID LinuxInitMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
60 {
61     mutex_init(psPVRSRVMutex);
62 }
64 IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
65 {
66     mutex_lock(psPVRSRVMutex);
67 }
69 IMG_VOID LinuxLockMutexNested(PVRSRV_LINUX_MUTEX *psPVRSRVMutex, unsigned int uiLockClass)
70 {
71         mutex_lock_nested(psPVRSRVMutex, uiLockClass);
72 }
74 PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
75 {
76     if(mutex_lock_interruptible(psPVRSRVMutex) == -EINTR)
77     {
78         return PVRSRV_ERROR_MUTEX_INTERRUPTIBLE_ERROR;
79     }
80     else
81     {
82         return PVRSRV_OK;
83     }
84 }
86 IMG_INT32 LinuxTryLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
87 {
88     return mutex_trylock(psPVRSRVMutex);
89 }
91 IMG_VOID LinuxUnLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
92 {
93     mutex_unlock(psPVRSRVMutex);
94 }
96 IMG_BOOL LinuxIsLockedMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
97 {
98     return (mutex_is_locked(psPVRSRVMutex)) ? IMG_TRUE : IMG_FALSE;
99 }
102 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) */
105 IMG_VOID LinuxInitMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
107     init_MUTEX(&psPVRSRVMutex->sSemaphore);
108     atomic_set(&psPVRSRVMutex->Count, 0);
111 IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
113     down(&psPVRSRVMutex->sSemaphore);
114     atomic_dec(&psPVRSRVMutex->Count);
117 IMG_VOID LinuxLockMutexNested(PVRSRV_LINUX_MUTEX *psPVRSRVMutex, unsigned int uiLockClass)
119         LinuxLockMutex(psPVRSRVMutex);
122 PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
124     if(down_interruptible(&psPVRSRVMutex->sSemaphore) == -EINTR)
125     {
126         /* The process was sent a signal while waiting for the semaphore
127          * (e.g. a kill signal from userspace)
128          */
129         return PVRSRV_ERROR_MUTEX_INTERRUPTIBLE_ERROR;
130     }else{
131         atomic_dec(&psPVRSRVMutex->Count);
132         return PVRSRV_OK;
133     }
136 IMG_INT32 LinuxTryLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
138     IMG_INT32 Status = down_trylock(&psPVRSRVMutex->sSemaphore);
139     if(Status == 0)
140     {
141         atomic_dec(&psPVRSRVMutex->Count);
142     }
144     return Status == 0;
147 IMG_VOID LinuxUnLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
149     atomic_inc(&psPVRSRVMutex->Count);
150     up(&psPVRSRVMutex->sSemaphore);
153 IMG_BOOL LinuxIsLockedMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex)
155     IMG_INT32 iCount;
156     
157     iCount = atomic_read(&psPVRSRVMutex->Count);
159     return (IMG_BOOL)iCount;
162 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) */