diff options
Diffstat (limited to 'drivers/gpu/pvr/mutex.c')
-rw-r--r-- | drivers/gpu/pvr/mutex.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/drivers/gpu/pvr/mutex.c b/drivers/gpu/pvr/mutex.c new file mode 100644 index 00000000000..09963ad9f00 --- /dev/null +++ b/drivers/gpu/pvr/mutex.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /********************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved. | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify it | ||
6 | * under the terms and conditions of the GNU General Public License, | ||
7 | * version 2, as published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful but, except | ||
10 | * as otherwise stated in writing, without any warranty; without even the | ||
11 | * implied warranty of merchantability or fitness for a particular purpose. | ||
12 | * See the GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along with | ||
15 | * this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. | ||
17 | * | ||
18 | * The full GNU General Public License is included in this distribution in | ||
19 | * the file called "COPYING". | ||
20 | * | ||
21 | * Contact Information: | ||
22 | * Imagination Technologies Ltd. <gpl-support@imgtec.com> | ||
23 | * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK | ||
24 | * | ||
25 | ******************************************************************************/ | ||
26 | |||
27 | #include <linux/version.h> | ||
28 | #include <linux/errno.h> | ||
29 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) | ||
30 | #include <linux/mutex.h> | ||
31 | #else | ||
32 | #include <asm/semaphore.h> | ||
33 | #endif | ||
34 | #include <linux/module.h> | ||
35 | |||
36 | #include <img_defs.h> | ||
37 | #include <services.h> | ||
38 | |||
39 | #include "mutex.h" | ||
40 | |||
41 | |||
42 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) | ||
43 | |||
44 | IMG_VOID LinuxInitMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
45 | { | ||
46 | mutex_init(psPVRSRVMutex); | ||
47 | } | ||
48 | |||
49 | IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
50 | { | ||
51 | mutex_lock(psPVRSRVMutex); | ||
52 | } | ||
53 | |||
54 | PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
55 | { | ||
56 | if(mutex_lock_interruptible(psPVRSRVMutex) == -EINTR) | ||
57 | { | ||
58 | return PVRSRV_ERROR_MUTEX_INTERRUPTIBLE_ERROR; | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | return PVRSRV_OK; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | IMG_INT32 LinuxTryLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
67 | { | ||
68 | return mutex_trylock(psPVRSRVMutex); | ||
69 | } | ||
70 | |||
71 | IMG_VOID LinuxUnLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
72 | { | ||
73 | mutex_unlock(psPVRSRVMutex); | ||
74 | } | ||
75 | |||
76 | IMG_BOOL LinuxIsLockedMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
77 | { | ||
78 | return (mutex_is_locked(psPVRSRVMutex)) ? IMG_TRUE : IMG_FALSE; | ||
79 | } | ||
80 | |||
81 | |||
82 | #else | ||
83 | |||
84 | |||
85 | IMG_VOID LinuxInitMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
86 | { | ||
87 | init_MUTEX(&psPVRSRVMutex->sSemaphore); | ||
88 | atomic_set(&psPVRSRVMutex->Count, 0); | ||
89 | } | ||
90 | |||
91 | IMG_VOID LinuxLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
92 | { | ||
93 | down(&psPVRSRVMutex->sSemaphore); | ||
94 | atomic_dec(&psPVRSRVMutex->Count); | ||
95 | } | ||
96 | |||
97 | PVRSRV_ERROR LinuxLockMutexInterruptible(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
98 | { | ||
99 | if(down_interruptible(&psPVRSRVMutex->sSemaphore) == -EINTR) | ||
100 | { | ||
101 | |||
102 | return PVRSRV_ERROR_MUTEX_INTERRUPTIBLE_ERROR; | ||
103 | }else{ | ||
104 | atomic_dec(&psPVRSRVMutex->Count); | ||
105 | return PVRSRV_OK; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | IMG_INT32 LinuxTryLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
110 | { | ||
111 | IMG_INT32 Status = down_trylock(&psPVRSRVMutex->sSemaphore); | ||
112 | if(Status == 0) | ||
113 | { | ||
114 | atomic_dec(&psPVRSRVMutex->Count); | ||
115 | } | ||
116 | |||
117 | return Status; | ||
118 | } | ||
119 | |||
120 | IMG_VOID LinuxUnLockMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
121 | { | ||
122 | atomic_inc(&psPVRSRVMutex->Count); | ||
123 | up(&psPVRSRVMutex->sSemaphore); | ||
124 | } | ||
125 | |||
126 | IMG_BOOL LinuxIsLockedMutex(PVRSRV_LINUX_MUTEX *psPVRSRVMutex) | ||
127 | { | ||
128 | IMG_INT32 iCount; | ||
129 | |||
130 | iCount = atomic_read(&psPVRSRVMutex->Count); | ||
131 | |||
132 | return (IMG_BOOL)iCount; | ||
133 | } | ||
134 | |||
135 | #endif | ||
136 | |||