utmutex.c revision 1.1.1.2.4.2 1 1.1.1.2.4.2 rmind /*******************************************************************************
2 1.1.1.2.4.2 rmind *
3 1.1.1.2.4.2 rmind * Module Name: utmutex - local mutex support
4 1.1.1.2.4.2 rmind *
5 1.1.1.2.4.2 rmind ******************************************************************************/
6 1.1.1.2.4.2 rmind
7 1.1.1.2.4.2 rmind /*
8 1.1.1.2.4.2 rmind * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.4.2 rmind * All rights reserved.
10 1.1.1.2.4.2 rmind *
11 1.1.1.2.4.2 rmind * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.4.2 rmind * modification, are permitted provided that the following conditions
13 1.1.1.2.4.2 rmind * are met:
14 1.1.1.2.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.4.2 rmind * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.4.2 rmind * without modification.
17 1.1.1.2.4.2 rmind * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.4.2 rmind * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.4.2 rmind * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.4.2 rmind * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.4.2 rmind * binary redistribution.
22 1.1.1.2.4.2 rmind * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.4.2 rmind * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.4.2 rmind * from this software without specific prior written permission.
25 1.1.1.2.4.2 rmind *
26 1.1.1.2.4.2 rmind * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.4.2 rmind * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.4.2 rmind * Software Foundation.
29 1.1.1.2.4.2 rmind *
30 1.1.1.2.4.2 rmind * NO WARRANTY
31 1.1.1.2.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.4.2 rmind * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.4.2 rmind * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.4.2 rmind * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.4.2 rmind * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.4.2 rmind * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.4.2 rmind * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.4.2 rmind * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.4.2 rmind */
43 1.1.1.2.4.2 rmind
44 1.1.1.2.4.2 rmind
45 1.1.1.2.4.2 rmind #define __UTMUTEX_C__
46 1.1.1.2.4.2 rmind
47 1.1.1.2.4.2 rmind #include "acpi.h"
48 1.1.1.2.4.2 rmind #include "accommon.h"
49 1.1.1.2.4.2 rmind
50 1.1.1.2.4.2 rmind #define _COMPONENT ACPI_UTILITIES
51 1.1.1.2.4.2 rmind ACPI_MODULE_NAME ("utmutex")
52 1.1.1.2.4.2 rmind
53 1.1.1.2.4.2 rmind /* Local prototypes */
54 1.1.1.2.4.2 rmind
55 1.1.1.2.4.2 rmind static ACPI_STATUS
56 1.1.1.2.4.2 rmind AcpiUtCreateMutex (
57 1.1.1.2.4.2 rmind ACPI_MUTEX_HANDLE MutexId);
58 1.1.1.2.4.2 rmind
59 1.1.1.2.4.2 rmind static void
60 1.1.1.2.4.2 rmind AcpiUtDeleteMutex (
61 1.1.1.2.4.2 rmind ACPI_MUTEX_HANDLE MutexId);
62 1.1.1.2.4.2 rmind
63 1.1.1.2.4.2 rmind
64 1.1.1.2.4.2 rmind /*******************************************************************************
65 1.1.1.2.4.2 rmind *
66 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtMutexInitialize
67 1.1.1.2.4.2 rmind *
68 1.1.1.2.4.2 rmind * PARAMETERS: None.
69 1.1.1.2.4.2 rmind *
70 1.1.1.2.4.2 rmind * RETURN: Status
71 1.1.1.2.4.2 rmind *
72 1.1.1.2.4.2 rmind * DESCRIPTION: Create the system mutex objects. This includes mutexes,
73 1.1.1.2.4.2 rmind * spin locks, and reader/writer locks.
74 1.1.1.2.4.2 rmind *
75 1.1.1.2.4.2 rmind ******************************************************************************/
76 1.1.1.2.4.2 rmind
77 1.1.1.2.4.2 rmind ACPI_STATUS
78 1.1.1.2.4.2 rmind AcpiUtMutexInitialize (
79 1.1.1.2.4.2 rmind void)
80 1.1.1.2.4.2 rmind {
81 1.1.1.2.4.2 rmind UINT32 i;
82 1.1.1.2.4.2 rmind ACPI_STATUS Status;
83 1.1.1.2.4.2 rmind
84 1.1.1.2.4.2 rmind
85 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (UtMutexInitialize);
86 1.1.1.2.4.2 rmind
87 1.1.1.2.4.2 rmind
88 1.1.1.2.4.2 rmind /* Create each of the predefined mutex objects */
89 1.1.1.2.4.2 rmind
90 1.1.1.2.4.2 rmind for (i = 0; i < ACPI_NUM_MUTEX; i++)
91 1.1.1.2.4.2 rmind {
92 1.1.1.2.4.2 rmind Status = AcpiUtCreateMutex (i);
93 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
94 1.1.1.2.4.2 rmind {
95 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
96 1.1.1.2.4.2 rmind }
97 1.1.1.2.4.2 rmind }
98 1.1.1.2.4.2 rmind
99 1.1.1.2.4.2 rmind /* Create the spinlocks for use at interrupt level */
100 1.1.1.2.4.2 rmind
101 1.1.1.2.4.2 rmind Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
102 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
103 1.1.1.2.4.2 rmind {
104 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
105 1.1.1.2.4.2 rmind }
106 1.1.1.2.4.2 rmind
107 1.1.1.2.4.2 rmind Status = AcpiOsCreateLock (&AcpiGbl_HardwareLock);
108 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
109 1.1.1.2.4.2 rmind {
110 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
111 1.1.1.2.4.2 rmind }
112 1.1.1.2.4.2 rmind
113 1.1.1.2.4.2 rmind /* Mutex for _OSI support */
114 1.1.1.2.4.2 rmind Status = AcpiOsCreateMutex (&AcpiGbl_OsiMutex);
115 1.1.1.2.4.2 rmind if (ACPI_FAILURE (Status))
116 1.1.1.2.4.2 rmind {
117 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
118 1.1.1.2.4.2 rmind }
119 1.1.1.2.4.2 rmind
120 1.1.1.2.4.2 rmind /* Create the reader/writer lock for namespace access */
121 1.1.1.2.4.2 rmind
122 1.1.1.2.4.2 rmind Status = AcpiUtCreateRwLock (&AcpiGbl_NamespaceRwLock);
123 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
124 1.1.1.2.4.2 rmind }
125 1.1.1.2.4.2 rmind
126 1.1.1.2.4.2 rmind
127 1.1.1.2.4.2 rmind /*******************************************************************************
128 1.1.1.2.4.2 rmind *
129 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtMutexTerminate
130 1.1.1.2.4.2 rmind *
131 1.1.1.2.4.2 rmind * PARAMETERS: None.
132 1.1.1.2.4.2 rmind *
133 1.1.1.2.4.2 rmind * RETURN: None.
134 1.1.1.2.4.2 rmind *
135 1.1.1.2.4.2 rmind * DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
136 1.1.1.2.4.2 rmind * spin locks, and reader/writer locks.
137 1.1.1.2.4.2 rmind *
138 1.1.1.2.4.2 rmind ******************************************************************************/
139 1.1.1.2.4.2 rmind
140 1.1.1.2.4.2 rmind void
141 1.1.1.2.4.2 rmind AcpiUtMutexTerminate (
142 1.1.1.2.4.2 rmind void)
143 1.1.1.2.4.2 rmind {
144 1.1.1.2.4.2 rmind UINT32 i;
145 1.1.1.2.4.2 rmind
146 1.1.1.2.4.2 rmind
147 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE (UtMutexTerminate);
148 1.1.1.2.4.2 rmind
149 1.1.1.2.4.2 rmind
150 1.1.1.2.4.2 rmind /* Delete each predefined mutex object */
151 1.1.1.2.4.2 rmind
152 1.1.1.2.4.2 rmind for (i = 0; i < ACPI_NUM_MUTEX; i++)
153 1.1.1.2.4.2 rmind {
154 1.1.1.2.4.2 rmind AcpiUtDeleteMutex (i);
155 1.1.1.2.4.2 rmind }
156 1.1.1.2.4.2 rmind
157 1.1.1.2.4.2 rmind AcpiOsDeleteMutex (AcpiGbl_OsiMutex);
158 1.1.1.2.4.2 rmind
159 1.1.1.2.4.2 rmind /* Delete the spinlocks */
160 1.1.1.2.4.2 rmind
161 1.1.1.2.4.2 rmind AcpiOsDeleteLock (AcpiGbl_GpeLock);
162 1.1.1.2.4.2 rmind AcpiOsDeleteLock (AcpiGbl_HardwareLock);
163 1.1.1.2.4.2 rmind
164 1.1.1.2.4.2 rmind /* Delete the reader/writer lock */
165 1.1.1.2.4.2 rmind
166 1.1.1.2.4.2 rmind AcpiUtDeleteRwLock (&AcpiGbl_NamespaceRwLock);
167 1.1.1.2.4.2 rmind return_VOID;
168 1.1.1.2.4.2 rmind }
169 1.1.1.2.4.2 rmind
170 1.1.1.2.4.2 rmind
171 1.1.1.2.4.2 rmind /*******************************************************************************
172 1.1.1.2.4.2 rmind *
173 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtCreateMutex
174 1.1.1.2.4.2 rmind *
175 1.1.1.2.4.2 rmind * PARAMETERS: MutexID - ID of the mutex to be created
176 1.1.1.2.4.2 rmind *
177 1.1.1.2.4.2 rmind * RETURN: Status
178 1.1.1.2.4.2 rmind *
179 1.1.1.2.4.2 rmind * DESCRIPTION: Create a mutex object.
180 1.1.1.2.4.2 rmind *
181 1.1.1.2.4.2 rmind ******************************************************************************/
182 1.1.1.2.4.2 rmind
183 1.1.1.2.4.2 rmind static ACPI_STATUS
184 1.1.1.2.4.2 rmind AcpiUtCreateMutex (
185 1.1.1.2.4.2 rmind ACPI_MUTEX_HANDLE MutexId)
186 1.1.1.2.4.2 rmind {
187 1.1.1.2.4.2 rmind ACPI_STATUS Status = AE_OK;
188 1.1.1.2.4.2 rmind
189 1.1.1.2.4.2 rmind
190 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE_U32 (UtCreateMutex, MutexId);
191 1.1.1.2.4.2 rmind
192 1.1.1.2.4.2 rmind
193 1.1.1.2.4.2 rmind if (!AcpiGbl_MutexInfo[MutexId].Mutex)
194 1.1.1.2.4.2 rmind {
195 1.1.1.2.4.2 rmind Status = AcpiOsCreateMutex (&AcpiGbl_MutexInfo[MutexId].Mutex);
196 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
197 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].UseCount = 0;
198 1.1.1.2.4.2 rmind }
199 1.1.1.2.4.2 rmind
200 1.1.1.2.4.2 rmind return_ACPI_STATUS (Status);
201 1.1.1.2.4.2 rmind }
202 1.1.1.2.4.2 rmind
203 1.1.1.2.4.2 rmind
204 1.1.1.2.4.2 rmind /*******************************************************************************
205 1.1.1.2.4.2 rmind *
206 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtDeleteMutex
207 1.1.1.2.4.2 rmind *
208 1.1.1.2.4.2 rmind * PARAMETERS: MutexID - ID of the mutex to be deleted
209 1.1.1.2.4.2 rmind *
210 1.1.1.2.4.2 rmind * RETURN: Status
211 1.1.1.2.4.2 rmind *
212 1.1.1.2.4.2 rmind * DESCRIPTION: Delete a mutex object.
213 1.1.1.2.4.2 rmind *
214 1.1.1.2.4.2 rmind ******************************************************************************/
215 1.1.1.2.4.2 rmind
216 1.1.1.2.4.2 rmind static void
217 1.1.1.2.4.2 rmind AcpiUtDeleteMutex (
218 1.1.1.2.4.2 rmind ACPI_MUTEX_HANDLE MutexId)
219 1.1.1.2.4.2 rmind {
220 1.1.1.2.4.2 rmind
221 1.1.1.2.4.2 rmind ACPI_FUNCTION_TRACE_U32 (UtDeleteMutex, MutexId);
222 1.1.1.2.4.2 rmind
223 1.1.1.2.4.2 rmind
224 1.1.1.2.4.2 rmind AcpiOsDeleteMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
225 1.1.1.2.4.2 rmind
226 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
227 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
228 1.1.1.2.4.2 rmind }
229 1.1.1.2.4.2 rmind
230 1.1.1.2.4.2 rmind
231 1.1.1.2.4.2 rmind /*******************************************************************************
232 1.1.1.2.4.2 rmind *
233 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtAcquireMutex
234 1.1.1.2.4.2 rmind *
235 1.1.1.2.4.2 rmind * PARAMETERS: MutexID - ID of the mutex to be acquired
236 1.1.1.2.4.2 rmind *
237 1.1.1.2.4.2 rmind * RETURN: Status
238 1.1.1.2.4.2 rmind *
239 1.1.1.2.4.2 rmind * DESCRIPTION: Acquire a mutex object.
240 1.1.1.2.4.2 rmind *
241 1.1.1.2.4.2 rmind ******************************************************************************/
242 1.1.1.2.4.2 rmind
243 1.1.1.2.4.2 rmind ACPI_STATUS
244 1.1.1.2.4.2 rmind AcpiUtAcquireMutex (
245 1.1.1.2.4.2 rmind ACPI_MUTEX_HANDLE MutexId)
246 1.1.1.2.4.2 rmind {
247 1.1.1.2.4.2 rmind ACPI_STATUS Status;
248 1.1.1.2.4.2 rmind ACPI_THREAD_ID ThisThreadId;
249 1.1.1.2.4.2 rmind
250 1.1.1.2.4.2 rmind
251 1.1.1.2.4.2 rmind ACPI_FUNCTION_NAME (UtAcquireMutex);
252 1.1.1.2.4.2 rmind
253 1.1.1.2.4.2 rmind
254 1.1.1.2.4.2 rmind if (MutexId > ACPI_MAX_MUTEX)
255 1.1.1.2.4.2 rmind {
256 1.1.1.2.4.2 rmind return (AE_BAD_PARAMETER);
257 1.1.1.2.4.2 rmind }
258 1.1.1.2.4.2 rmind
259 1.1.1.2.4.2 rmind ThisThreadId = AcpiOsGetThreadId ();
260 1.1.1.2.4.2 rmind
261 1.1.1.2.4.2 rmind #ifdef ACPI_MUTEX_DEBUG
262 1.1.1.2.4.2 rmind {
263 1.1.1.2.4.2 rmind UINT32 i;
264 1.1.1.2.4.2 rmind /*
265 1.1.1.2.4.2 rmind * Mutex debug code, for internal debugging only.
266 1.1.1.2.4.2 rmind *
267 1.1.1.2.4.2 rmind * Deadlock prevention. Check if this thread owns any mutexes of value
268 1.1.1.2.4.2 rmind * greater than or equal to this one. If so, the thread has violated
269 1.1.1.2.4.2 rmind * the mutex ordering rule. This indicates a coding error somewhere in
270 1.1.1.2.4.2 rmind * the ACPI subsystem code.
271 1.1.1.2.4.2 rmind */
272 1.1.1.2.4.2 rmind for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
273 1.1.1.2.4.2 rmind {
274 1.1.1.2.4.2 rmind if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
275 1.1.1.2.4.2 rmind {
276 1.1.1.2.4.2 rmind if (i == MutexId)
277 1.1.1.2.4.2 rmind {
278 1.1.1.2.4.2 rmind ACPI_ERROR ((AE_INFO,
279 1.1.1.2.4.2 rmind "Mutex [%s] already acquired by this thread [%u]",
280 1.1.1.2.4.2 rmind AcpiUtGetMutexName (MutexId),
281 1.1.1.2.4.2 rmind (UINT32) ThisThreadId));
282 1.1.1.2.4.2 rmind
283 1.1.1.2.4.2 rmind return (AE_ALREADY_ACQUIRED);
284 1.1.1.2.4.2 rmind }
285 1.1.1.2.4.2 rmind
286 1.1.1.2.4.2 rmind ACPI_ERROR ((AE_INFO,
287 1.1.1.2.4.2 rmind "Invalid acquire order: Thread %u owns [%s], wants [%s]",
288 1.1.1.2.4.2 rmind (UINT32) ThisThreadId, AcpiUtGetMutexName (i),
289 1.1.1.2.4.2 rmind AcpiUtGetMutexName (MutexId)));
290 1.1.1.2.4.2 rmind
291 1.1.1.2.4.2 rmind return (AE_ACQUIRE_DEADLOCK);
292 1.1.1.2.4.2 rmind }
293 1.1.1.2.4.2 rmind }
294 1.1.1.2.4.2 rmind }
295 1.1.1.2.4.2 rmind #endif
296 1.1.1.2.4.2 rmind
297 1.1.1.2.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
298 1.1.1.2.4.2 rmind "Thread %u attempting to acquire Mutex [%s]\n",
299 1.1.1.2.4.2 rmind (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
300 1.1.1.2.4.2 rmind
301 1.1.1.2.4.2 rmind Status = AcpiOsAcquireMutex (AcpiGbl_MutexInfo[MutexId].Mutex,
302 1.1.1.2.4.2 rmind ACPI_WAIT_FOREVER);
303 1.1.1.2.4.2 rmind if (ACPI_SUCCESS (Status))
304 1.1.1.2.4.2 rmind {
305 1.1.1.2.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u acquired Mutex [%s]\n",
306 1.1.1.2.4.2 rmind (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
307 1.1.1.2.4.2 rmind
308 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].UseCount++;
309 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId;
310 1.1.1.2.4.2 rmind }
311 1.1.1.2.4.2 rmind else
312 1.1.1.2.4.2 rmind {
313 1.1.1.2.4.2 rmind ACPI_EXCEPTION ((AE_INFO, Status,
314 1.1.1.2.4.2 rmind "Thread %u could not acquire Mutex [0x%X]",
315 1.1.1.2.4.2 rmind (UINT32) ThisThreadId, MutexId));
316 1.1.1.2.4.2 rmind }
317 1.1.1.2.4.2 rmind
318 1.1.1.2.4.2 rmind return (Status);
319 1.1.1.2.4.2 rmind }
320 1.1.1.2.4.2 rmind
321 1.1.1.2.4.2 rmind
322 1.1.1.2.4.2 rmind /*******************************************************************************
323 1.1.1.2.4.2 rmind *
324 1.1.1.2.4.2 rmind * FUNCTION: AcpiUtReleaseMutex
325 1.1.1.2.4.2 rmind *
326 1.1.1.2.4.2 rmind * PARAMETERS: MutexID - ID of the mutex to be released
327 1.1.1.2.4.2 rmind *
328 1.1.1.2.4.2 rmind * RETURN: Status
329 1.1.1.2.4.2 rmind *
330 1.1.1.2.4.2 rmind * DESCRIPTION: Release a mutex object.
331 1.1.1.2.4.2 rmind *
332 1.1.1.2.4.2 rmind ******************************************************************************/
333 1.1.1.2.4.2 rmind
334 1.1.1.2.4.2 rmind ACPI_STATUS
335 1.1.1.2.4.2 rmind AcpiUtReleaseMutex (
336 1.1.1.2.4.2 rmind ACPI_MUTEX_HANDLE MutexId)
337 1.1.1.2.4.2 rmind {
338 1.1.1.2.4.2 rmind ACPI_THREAD_ID ThisThreadId;
339 1.1.1.2.4.2 rmind
340 1.1.1.2.4.2 rmind
341 1.1.1.2.4.2 rmind ACPI_FUNCTION_NAME (UtReleaseMutex);
342 1.1.1.2.4.2 rmind
343 1.1.1.2.4.2 rmind
344 1.1.1.2.4.2 rmind ThisThreadId = AcpiOsGetThreadId ();
345 1.1.1.2.4.2 rmind ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u releasing Mutex [%s]\n",
346 1.1.1.2.4.2 rmind (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
347 1.1.1.2.4.2 rmind
348 1.1.1.2.4.2 rmind if (MutexId > ACPI_MAX_MUTEX)
349 1.1.1.2.4.2 rmind {
350 1.1.1.2.4.2 rmind return (AE_BAD_PARAMETER);
351 1.1.1.2.4.2 rmind }
352 1.1.1.2.4.2 rmind
353 1.1.1.2.4.2 rmind /*
354 1.1.1.2.4.2 rmind * Mutex must be acquired in order to release it!
355 1.1.1.2.4.2 rmind */
356 1.1.1.2.4.2 rmind if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED)
357 1.1.1.2.4.2 rmind {
358 1.1.1.2.4.2 rmind ACPI_ERROR ((AE_INFO,
359 1.1.1.2.4.2 rmind "Mutex [0x%X] is not acquired, cannot release", MutexId));
360 1.1.1.2.4.2 rmind
361 1.1.1.2.4.2 rmind return (AE_NOT_ACQUIRED);
362 1.1.1.2.4.2 rmind }
363 1.1.1.2.4.2 rmind
364 1.1.1.2.4.2 rmind #ifdef ACPI_MUTEX_DEBUG
365 1.1.1.2.4.2 rmind {
366 1.1.1.2.4.2 rmind UINT32 i;
367 1.1.1.2.4.2 rmind /*
368 1.1.1.2.4.2 rmind * Mutex debug code, for internal debugging only.
369 1.1.1.2.4.2 rmind *
370 1.1.1.2.4.2 rmind * Deadlock prevention. Check if this thread owns any mutexes of value
371 1.1.1.2.4.2 rmind * greater than this one. If so, the thread has violated the mutex
372 1.1.1.2.4.2 rmind * ordering rule. This indicates a coding error somewhere in
373 1.1.1.2.4.2 rmind * the ACPI subsystem code.
374 1.1.1.2.4.2 rmind */
375 1.1.1.2.4.2 rmind for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
376 1.1.1.2.4.2 rmind {
377 1.1.1.2.4.2 rmind if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
378 1.1.1.2.4.2 rmind {
379 1.1.1.2.4.2 rmind if (i == MutexId)
380 1.1.1.2.4.2 rmind {
381 1.1.1.2.4.2 rmind continue;
382 1.1.1.2.4.2 rmind }
383 1.1.1.2.4.2 rmind
384 1.1.1.2.4.2 rmind ACPI_ERROR ((AE_INFO,
385 1.1.1.2.4.2 rmind "Invalid release order: owns [%s], releasing [%s]",
386 1.1.1.2.4.2 rmind AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
387 1.1.1.2.4.2 rmind
388 1.1.1.2.4.2 rmind return (AE_RELEASE_DEADLOCK);
389 1.1.1.2.4.2 rmind }
390 1.1.1.2.4.2 rmind }
391 1.1.1.2.4.2 rmind }
392 1.1.1.2.4.2 rmind #endif
393 1.1.1.2.4.2 rmind
394 1.1.1.2.4.2 rmind /* Mark unlocked FIRST */
395 1.1.1.2.4.2 rmind
396 1.1.1.2.4.2 rmind AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
397 1.1.1.2.4.2 rmind
398 1.1.1.2.4.2 rmind AcpiOsReleaseMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
399 1.1.1.2.4.2 rmind return (AE_OK);
400 1.1.1.2.4.2 rmind }
401 1.1.1.2.4.2 rmind
402 1.1.1.2.4.2 rmind
403