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