exmutex.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 *
4 1.1.1.2.2.2 bouyer * Module Name: exmutex - ASL Mutex Acquire/Release functions
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 /*
9 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
10 1.1.1.2.2.2 bouyer * All rights reserved.
11 1.1.1.2.2.2 bouyer *
12 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
13 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
14 1.1.1.2.2.2 bouyer * are met:
15 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
16 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
17 1.1.1.2.2.2 bouyer * without modification.
18 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
20 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
21 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
22 1.1.1.2.2.2 bouyer * binary redistribution.
23 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
24 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
25 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
26 1.1.1.2.2.2 bouyer *
27 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
28 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
29 1.1.1.2.2.2 bouyer * Software Foundation.
30 1.1.1.2.2.2 bouyer *
31 1.1.1.2.2.2 bouyer * NO WARRANTY
32 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
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 __EXMUTEX_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 #include "acinterp.h"
50 1.1.1.2.2.2 bouyer #include "acevents.h"
51 1.1.1.2.2.2 bouyer
52 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_EXECUTER
53 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("exmutex")
54 1.1.1.2.2.2 bouyer
55 1.1.1.2.2.2 bouyer /* Local prototypes */
56 1.1.1.2.2.2 bouyer
57 1.1.1.2.2.2 bouyer static void
58 1.1.1.2.2.2 bouyer AcpiExLinkMutex (
59 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
60 1.1.1.2.2.2 bouyer ACPI_THREAD_STATE *Thread);
61 1.1.1.2.2.2 bouyer
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 * FUNCTION: AcpiExUnlinkMutex
66 1.1.1.2.2.2 bouyer *
67 1.1.1.2.2.2 bouyer * PARAMETERS: ObjDesc - The mutex to be unlinked
68 1.1.1.2.2.2 bouyer *
69 1.1.1.2.2.2 bouyer * RETURN: None
70 1.1.1.2.2.2 bouyer *
71 1.1.1.2.2.2 bouyer * DESCRIPTION: Remove a mutex from the "AcquiredMutex" list
72 1.1.1.2.2.2 bouyer *
73 1.1.1.2.2.2 bouyer ******************************************************************************/
74 1.1.1.2.2.2 bouyer
75 1.1.1.2.2.2 bouyer void
76 1.1.1.2.2.2 bouyer AcpiExUnlinkMutex (
77 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc)
78 1.1.1.2.2.2 bouyer {
79 1.1.1.2.2.2 bouyer ACPI_THREAD_STATE *Thread = ObjDesc->Mutex.OwnerThread;
80 1.1.1.2.2.2 bouyer
81 1.1.1.2.2.2 bouyer
82 1.1.1.2.2.2 bouyer if (!Thread)
83 1.1.1.2.2.2 bouyer {
84 1.1.1.2.2.2 bouyer return;
85 1.1.1.2.2.2 bouyer }
86 1.1.1.2.2.2 bouyer
87 1.1.1.2.2.2 bouyer /* Doubly linked list */
88 1.1.1.2.2.2 bouyer
89 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.Next)
90 1.1.1.2.2.2 bouyer {
91 1.1.1.2.2.2 bouyer (ObjDesc->Mutex.Next)->Mutex.Prev = ObjDesc->Mutex.Prev;
92 1.1.1.2.2.2 bouyer }
93 1.1.1.2.2.2 bouyer
94 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.Prev)
95 1.1.1.2.2.2 bouyer {
96 1.1.1.2.2.2 bouyer (ObjDesc->Mutex.Prev)->Mutex.Next = ObjDesc->Mutex.Next;
97 1.1.1.2.2.2 bouyer
98 1.1.1.2.2.2 bouyer /*
99 1.1.1.2.2.2 bouyer * Migrate the previous sync level associated with this mutex to
100 1.1.1.2.2.2 bouyer * the previous mutex on the list so that it may be preserved.
101 1.1.1.2.2.2 bouyer * This handles the case where several mutexes have been acquired
102 1.1.1.2.2.2 bouyer * at the same level, but are not released in opposite order.
103 1.1.1.2.2.2 bouyer */
104 1.1.1.2.2.2 bouyer (ObjDesc->Mutex.Prev)->Mutex.OriginalSyncLevel =
105 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OriginalSyncLevel;
106 1.1.1.2.2.2 bouyer }
107 1.1.1.2.2.2 bouyer else
108 1.1.1.2.2.2 bouyer {
109 1.1.1.2.2.2 bouyer Thread->AcquiredMutexList = ObjDesc->Mutex.Next;
110 1.1.1.2.2.2 bouyer }
111 1.1.1.2.2.2 bouyer }
112 1.1.1.2.2.2 bouyer
113 1.1.1.2.2.2 bouyer
114 1.1.1.2.2.2 bouyer /*******************************************************************************
115 1.1.1.2.2.2 bouyer *
116 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExLinkMutex
117 1.1.1.2.2.2 bouyer *
118 1.1.1.2.2.2 bouyer * PARAMETERS: ObjDesc - The mutex to be linked
119 1.1.1.2.2.2 bouyer * Thread - Current executing thread object
120 1.1.1.2.2.2 bouyer *
121 1.1.1.2.2.2 bouyer * RETURN: None
122 1.1.1.2.2.2 bouyer *
123 1.1.1.2.2.2 bouyer * DESCRIPTION: Add a mutex to the "AcquiredMutex" list for this walk
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 static void
128 1.1.1.2.2.2 bouyer AcpiExLinkMutex (
129 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
130 1.1.1.2.2.2 bouyer ACPI_THREAD_STATE *Thread)
131 1.1.1.2.2.2 bouyer {
132 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ListHead;
133 1.1.1.2.2.2 bouyer
134 1.1.1.2.2.2 bouyer
135 1.1.1.2.2.2 bouyer ListHead = Thread->AcquiredMutexList;
136 1.1.1.2.2.2 bouyer
137 1.1.1.2.2.2 bouyer /* This object will be the first object in the list */
138 1.1.1.2.2.2 bouyer
139 1.1.1.2.2.2 bouyer ObjDesc->Mutex.Prev = NULL;
140 1.1.1.2.2.2 bouyer ObjDesc->Mutex.Next = ListHead;
141 1.1.1.2.2.2 bouyer
142 1.1.1.2.2.2 bouyer /* Update old first object to point back to this object */
143 1.1.1.2.2.2 bouyer
144 1.1.1.2.2.2 bouyer if (ListHead)
145 1.1.1.2.2.2 bouyer {
146 1.1.1.2.2.2 bouyer ListHead->Mutex.Prev = ObjDesc;
147 1.1.1.2.2.2 bouyer }
148 1.1.1.2.2.2 bouyer
149 1.1.1.2.2.2 bouyer /* Update list head */
150 1.1.1.2.2.2 bouyer
151 1.1.1.2.2.2 bouyer Thread->AcquiredMutexList = ObjDesc;
152 1.1.1.2.2.2 bouyer }
153 1.1.1.2.2.2 bouyer
154 1.1.1.2.2.2 bouyer
155 1.1.1.2.2.2 bouyer /*******************************************************************************
156 1.1.1.2.2.2 bouyer *
157 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExAcquireMutexObject
158 1.1.1.2.2.2 bouyer *
159 1.1.1.2.2.2 bouyer * PARAMETERS: Timeout - Timeout in milliseconds
160 1.1.1.2.2.2 bouyer * ObjDesc - Mutex object
161 1.1.1.2.2.2 bouyer * ThreadId - Current thread state
162 1.1.1.2.2.2 bouyer *
163 1.1.1.2.2.2 bouyer * RETURN: Status
164 1.1.1.2.2.2 bouyer *
165 1.1.1.2.2.2 bouyer * DESCRIPTION: Acquire an AML mutex, low-level interface. Provides a common
166 1.1.1.2.2.2 bouyer * path that supports multiple acquires by the same thread.
167 1.1.1.2.2.2 bouyer *
168 1.1.1.2.2.2 bouyer * MUTEX: Interpreter must be locked
169 1.1.1.2.2.2 bouyer *
170 1.1.1.2.2.2 bouyer * NOTE: This interface is called from three places:
171 1.1.1.2.2.2 bouyer * 1) From AcpiExAcquireMutex, via an AML Acquire() operator
172 1.1.1.2.2.2 bouyer * 2) From AcpiExAcquireGlobalLock when an AML Field access requires the
173 1.1.1.2.2.2 bouyer * global lock
174 1.1.1.2.2.2 bouyer * 3) From the external interface, AcpiAcquireGlobalLock
175 1.1.1.2.2.2 bouyer *
176 1.1.1.2.2.2 bouyer ******************************************************************************/
177 1.1.1.2.2.2 bouyer
178 1.1.1.2.2.2 bouyer ACPI_STATUS
179 1.1.1.2.2.2 bouyer AcpiExAcquireMutexObject (
180 1.1.1.2.2.2 bouyer UINT16 Timeout,
181 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
182 1.1.1.2.2.2 bouyer ACPI_THREAD_ID ThreadId)
183 1.1.1.2.2.2 bouyer {
184 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
185 1.1.1.2.2.2 bouyer
186 1.1.1.2.2.2 bouyer
187 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (ExAcquireMutexObject, ObjDesc);
188 1.1.1.2.2.2 bouyer
189 1.1.1.2.2.2 bouyer
190 1.1.1.2.2.2 bouyer if (!ObjDesc)
191 1.1.1.2.2.2 bouyer {
192 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
193 1.1.1.2.2.2 bouyer }
194 1.1.1.2.2.2 bouyer
195 1.1.1.2.2.2 bouyer /* Support for multiple acquires by the owning thread */
196 1.1.1.2.2.2 bouyer
197 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.ThreadId == ThreadId)
198 1.1.1.2.2.2 bouyer {
199 1.1.1.2.2.2 bouyer /*
200 1.1.1.2.2.2 bouyer * The mutex is already owned by this thread, just increment the
201 1.1.1.2.2.2 bouyer * acquisition depth
202 1.1.1.2.2.2 bouyer */
203 1.1.1.2.2.2 bouyer ObjDesc->Mutex.AcquisitionDepth++;
204 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
205 1.1.1.2.2.2 bouyer }
206 1.1.1.2.2.2 bouyer
207 1.1.1.2.2.2 bouyer /* Acquire the mutex, wait if necessary. Special case for Global Lock */
208 1.1.1.2.2.2 bouyer
209 1.1.1.2.2.2 bouyer if (ObjDesc == AcpiGbl_GlobalLockMutex)
210 1.1.1.2.2.2 bouyer {
211 1.1.1.2.2.2 bouyer Status = AcpiEvAcquireGlobalLock (Timeout);
212 1.1.1.2.2.2 bouyer }
213 1.1.1.2.2.2 bouyer else
214 1.1.1.2.2.2 bouyer {
215 1.1.1.2.2.2 bouyer Status = AcpiExSystemWaitMutex (ObjDesc->Mutex.OsMutex,
216 1.1.1.2.2.2 bouyer Timeout);
217 1.1.1.2.2.2 bouyer }
218 1.1.1.2.2.2 bouyer
219 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
220 1.1.1.2.2.2 bouyer {
221 1.1.1.2.2.2 bouyer /* Includes failure from a timeout on TimeDesc */
222 1.1.1.2.2.2 bouyer
223 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
224 1.1.1.2.2.2 bouyer }
225 1.1.1.2.2.2 bouyer
226 1.1.1.2.2.2 bouyer /* Acquired the mutex: update mutex object */
227 1.1.1.2.2.2 bouyer
228 1.1.1.2.2.2 bouyer ObjDesc->Mutex.ThreadId = ThreadId;
229 1.1.1.2.2.2 bouyer ObjDesc->Mutex.AcquisitionDepth = 1;
230 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OriginalSyncLevel = 0;
231 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OwnerThread = NULL; /* Used only for AML Acquire() */
232 1.1.1.2.2.2 bouyer
233 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
234 1.1.1.2.2.2 bouyer }
235 1.1.1.2.2.2 bouyer
236 1.1.1.2.2.2 bouyer
237 1.1.1.2.2.2 bouyer /*******************************************************************************
238 1.1.1.2.2.2 bouyer *
239 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExAcquireMutex
240 1.1.1.2.2.2 bouyer *
241 1.1.1.2.2.2 bouyer * PARAMETERS: TimeDesc - Timeout integer
242 1.1.1.2.2.2 bouyer * ObjDesc - Mutex object
243 1.1.1.2.2.2 bouyer * WalkState - Current method execution state
244 1.1.1.2.2.2 bouyer *
245 1.1.1.2.2.2 bouyer * RETURN: Status
246 1.1.1.2.2.2 bouyer *
247 1.1.1.2.2.2 bouyer * DESCRIPTION: Acquire an AML mutex
248 1.1.1.2.2.2 bouyer *
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_STATUS
252 1.1.1.2.2.2 bouyer AcpiExAcquireMutex (
253 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *TimeDesc,
254 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
255 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
256 1.1.1.2.2.2 bouyer {
257 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
258 1.1.1.2.2.2 bouyer
259 1.1.1.2.2.2 bouyer
260 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE_PTR (ExAcquireMutex, ObjDesc);
261 1.1.1.2.2.2 bouyer
262 1.1.1.2.2.2 bouyer
263 1.1.1.2.2.2 bouyer if (!ObjDesc)
264 1.1.1.2.2.2 bouyer {
265 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
266 1.1.1.2.2.2 bouyer }
267 1.1.1.2.2.2 bouyer
268 1.1.1.2.2.2 bouyer /* Must have a valid thread state struct */
269 1.1.1.2.2.2 bouyer
270 1.1.1.2.2.2 bouyer if (!WalkState->Thread)
271 1.1.1.2.2.2 bouyer {
272 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
273 1.1.1.2.2.2 bouyer "Cannot acquire Mutex [%4.4s], null thread info",
274 1.1.1.2.2.2 bouyer AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
275 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_INTERNAL);
276 1.1.1.2.2.2 bouyer }
277 1.1.1.2.2.2 bouyer
278 1.1.1.2.2.2 bouyer /*
279 1.1.1.2.2.2 bouyer * Current sync level must be less than or equal to the sync level of the
280 1.1.1.2.2.2 bouyer * mutex. This mechanism provides some deadlock prevention
281 1.1.1.2.2.2 bouyer */
282 1.1.1.2.2.2 bouyer if (WalkState->Thread->CurrentSyncLevel > ObjDesc->Mutex.SyncLevel)
283 1.1.1.2.2.2 bouyer {
284 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
285 1.1.1.2.2.2 bouyer "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%u)",
286 1.1.1.2.2.2 bouyer AcpiUtGetNodeName (ObjDesc->Mutex.Node),
287 1.1.1.2.2.2 bouyer WalkState->Thread->CurrentSyncLevel));
288 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
289 1.1.1.2.2.2 bouyer }
290 1.1.1.2.2.2 bouyer
291 1.1.1.2.2.2 bouyer Status = AcpiExAcquireMutexObject ((UINT16) TimeDesc->Integer.Value,
292 1.1.1.2.2.2 bouyer ObjDesc, WalkState->Thread->ThreadId);
293 1.1.1.2.2.2 bouyer if (ACPI_SUCCESS (Status) && ObjDesc->Mutex.AcquisitionDepth == 1)
294 1.1.1.2.2.2 bouyer {
295 1.1.1.2.2.2 bouyer /* Save Thread object, original/current sync levels */
296 1.1.1.2.2.2 bouyer
297 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OwnerThread = WalkState->Thread;
298 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OriginalSyncLevel = WalkState->Thread->CurrentSyncLevel;
299 1.1.1.2.2.2 bouyer WalkState->Thread->CurrentSyncLevel = ObjDesc->Mutex.SyncLevel;
300 1.1.1.2.2.2 bouyer
301 1.1.1.2.2.2 bouyer /* Link the mutex to the current thread for force-unlock at method exit */
302 1.1.1.2.2.2 bouyer
303 1.1.1.2.2.2 bouyer AcpiExLinkMutex (ObjDesc, WalkState->Thread);
304 1.1.1.2.2.2 bouyer }
305 1.1.1.2.2.2 bouyer
306 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
307 1.1.1.2.2.2 bouyer }
308 1.1.1.2.2.2 bouyer
309 1.1.1.2.2.2 bouyer
310 1.1.1.2.2.2 bouyer /*******************************************************************************
311 1.1.1.2.2.2 bouyer *
312 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExReleaseMutexObject
313 1.1.1.2.2.2 bouyer *
314 1.1.1.2.2.2 bouyer * PARAMETERS: ObjDesc - The object descriptor for this op
315 1.1.1.2.2.2 bouyer *
316 1.1.1.2.2.2 bouyer * RETURN: Status
317 1.1.1.2.2.2 bouyer *
318 1.1.1.2.2.2 bouyer * DESCRIPTION: Release a previously acquired Mutex, low level interface.
319 1.1.1.2.2.2 bouyer * Provides a common path that supports multiple releases (after
320 1.1.1.2.2.2 bouyer * previous multiple acquires) by the same thread.
321 1.1.1.2.2.2 bouyer *
322 1.1.1.2.2.2 bouyer * MUTEX: Interpreter must be locked
323 1.1.1.2.2.2 bouyer *
324 1.1.1.2.2.2 bouyer * NOTE: This interface is called from three places:
325 1.1.1.2.2.2 bouyer * 1) From AcpiExReleaseMutex, via an AML Acquire() operator
326 1.1.1.2.2.2 bouyer * 2) From AcpiExReleaseGlobalLock when an AML Field access requires the
327 1.1.1.2.2.2 bouyer * global lock
328 1.1.1.2.2.2 bouyer * 3) From the external interface, AcpiReleaseGlobalLock
329 1.1.1.2.2.2 bouyer *
330 1.1.1.2.2.2 bouyer ******************************************************************************/
331 1.1.1.2.2.2 bouyer
332 1.1.1.2.2.2 bouyer ACPI_STATUS
333 1.1.1.2.2.2 bouyer AcpiExReleaseMutexObject (
334 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc)
335 1.1.1.2.2.2 bouyer {
336 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
337 1.1.1.2.2.2 bouyer
338 1.1.1.2.2.2 bouyer
339 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (ExReleaseMutexObject);
340 1.1.1.2.2.2 bouyer
341 1.1.1.2.2.2 bouyer
342 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.AcquisitionDepth == 0)
343 1.1.1.2.2.2 bouyer {
344 1.1.1.2.2.2 bouyer return (AE_NOT_ACQUIRED);
345 1.1.1.2.2.2 bouyer }
346 1.1.1.2.2.2 bouyer
347 1.1.1.2.2.2 bouyer /* Match multiple Acquires with multiple Releases */
348 1.1.1.2.2.2 bouyer
349 1.1.1.2.2.2 bouyer ObjDesc->Mutex.AcquisitionDepth--;
350 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.AcquisitionDepth != 0)
351 1.1.1.2.2.2 bouyer {
352 1.1.1.2.2.2 bouyer /* Just decrement the depth and return */
353 1.1.1.2.2.2 bouyer
354 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_OK);
355 1.1.1.2.2.2 bouyer }
356 1.1.1.2.2.2 bouyer
357 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.OwnerThread)
358 1.1.1.2.2.2 bouyer {
359 1.1.1.2.2.2 bouyer /* Unlink the mutex from the owner's list */
360 1.1.1.2.2.2 bouyer
361 1.1.1.2.2.2 bouyer AcpiExUnlinkMutex (ObjDesc);
362 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OwnerThread = NULL;
363 1.1.1.2.2.2 bouyer }
364 1.1.1.2.2.2 bouyer
365 1.1.1.2.2.2 bouyer /* Release the mutex, special case for Global Lock */
366 1.1.1.2.2.2 bouyer
367 1.1.1.2.2.2 bouyer if (ObjDesc == AcpiGbl_GlobalLockMutex)
368 1.1.1.2.2.2 bouyer {
369 1.1.1.2.2.2 bouyer Status = AcpiEvReleaseGlobalLock ();
370 1.1.1.2.2.2 bouyer }
371 1.1.1.2.2.2 bouyer else
372 1.1.1.2.2.2 bouyer {
373 1.1.1.2.2.2 bouyer AcpiOsReleaseMutex (ObjDesc->Mutex.OsMutex);
374 1.1.1.2.2.2 bouyer }
375 1.1.1.2.2.2 bouyer
376 1.1.1.2.2.2 bouyer /* Clear mutex info */
377 1.1.1.2.2.2 bouyer
378 1.1.1.2.2.2 bouyer ObjDesc->Mutex.ThreadId = 0;
379 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
380 1.1.1.2.2.2 bouyer }
381 1.1.1.2.2.2 bouyer
382 1.1.1.2.2.2 bouyer
383 1.1.1.2.2.2 bouyer /*******************************************************************************
384 1.1.1.2.2.2 bouyer *
385 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExReleaseMutex
386 1.1.1.2.2.2 bouyer *
387 1.1.1.2.2.2 bouyer * PARAMETERS: ObjDesc - The object descriptor for this op
388 1.1.1.2.2.2 bouyer * WalkState - Current method execution state
389 1.1.1.2.2.2 bouyer *
390 1.1.1.2.2.2 bouyer * RETURN: Status
391 1.1.1.2.2.2 bouyer *
392 1.1.1.2.2.2 bouyer * DESCRIPTION: Release a previously acquired Mutex.
393 1.1.1.2.2.2 bouyer *
394 1.1.1.2.2.2 bouyer ******************************************************************************/
395 1.1.1.2.2.2 bouyer
396 1.1.1.2.2.2 bouyer ACPI_STATUS
397 1.1.1.2.2.2 bouyer AcpiExReleaseMutex (
398 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc,
399 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState)
400 1.1.1.2.2.2 bouyer {
401 1.1.1.2.2.2 bouyer ACPI_STATUS Status = AE_OK;
402 1.1.1.2.2.2 bouyer UINT8 PreviousSyncLevel;
403 1.1.1.2.2.2 bouyer ACPI_THREAD_STATE *OwnerThread;
404 1.1.1.2.2.2 bouyer
405 1.1.1.2.2.2 bouyer
406 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (ExReleaseMutex);
407 1.1.1.2.2.2 bouyer
408 1.1.1.2.2.2 bouyer
409 1.1.1.2.2.2 bouyer if (!ObjDesc)
410 1.1.1.2.2.2 bouyer {
411 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_BAD_PARAMETER);
412 1.1.1.2.2.2 bouyer }
413 1.1.1.2.2.2 bouyer
414 1.1.1.2.2.2 bouyer OwnerThread = ObjDesc->Mutex.OwnerThread;
415 1.1.1.2.2.2 bouyer
416 1.1.1.2.2.2 bouyer /* The mutex must have been previously acquired in order to release it */
417 1.1.1.2.2.2 bouyer
418 1.1.1.2.2.2 bouyer if (!OwnerThread)
419 1.1.1.2.2.2 bouyer {
420 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
421 1.1.1.2.2.2 bouyer "Cannot release Mutex [%4.4s], not acquired",
422 1.1.1.2.2.2 bouyer AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
423 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_MUTEX_NOT_ACQUIRED);
424 1.1.1.2.2.2 bouyer }
425 1.1.1.2.2.2 bouyer
426 1.1.1.2.2.2 bouyer /* Must have a valid thread ID */
427 1.1.1.2.2.2 bouyer
428 1.1.1.2.2.2 bouyer if (!WalkState->Thread)
429 1.1.1.2.2.2 bouyer {
430 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
431 1.1.1.2.2.2 bouyer "Cannot release Mutex [%4.4s], null thread info",
432 1.1.1.2.2.2 bouyer AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
433 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_INTERNAL);
434 1.1.1.2.2.2 bouyer }
435 1.1.1.2.2.2 bouyer
436 1.1.1.2.2.2 bouyer /*
437 1.1.1.2.2.2 bouyer * The Mutex is owned, but this thread must be the owner.
438 1.1.1.2.2.2 bouyer * Special case for Global Lock, any thread can release
439 1.1.1.2.2.2 bouyer */
440 1.1.1.2.2.2 bouyer if ((OwnerThread->ThreadId != WalkState->Thread->ThreadId) &&
441 1.1.1.2.2.2 bouyer (ObjDesc != AcpiGbl_GlobalLockMutex))
442 1.1.1.2.2.2 bouyer {
443 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
444 1.1.1.2.2.2 bouyer "Thread %u cannot release Mutex [%4.4s] acquired by thread %u",
445 1.1.1.2.2.2 bouyer (UINT32) WalkState->Thread->ThreadId,
446 1.1.1.2.2.2 bouyer AcpiUtGetNodeName (ObjDesc->Mutex.Node),
447 1.1.1.2.2.2 bouyer (UINT32) OwnerThread->ThreadId));
448 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_NOT_OWNER);
449 1.1.1.2.2.2 bouyer }
450 1.1.1.2.2.2 bouyer
451 1.1.1.2.2.2 bouyer /*
452 1.1.1.2.2.2 bouyer * The sync level of the mutex must be equal to the current sync level. In
453 1.1.1.2.2.2 bouyer * other words, the current level means that at least one mutex at that
454 1.1.1.2.2.2 bouyer * level is currently being held. Attempting to release a mutex of a
455 1.1.1.2.2.2 bouyer * different level can only mean that the mutex ordering rule is being
456 1.1.1.2.2.2 bouyer * violated. This behavior is clarified in ACPI 4.0 specification.
457 1.1.1.2.2.2 bouyer */
458 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.SyncLevel != OwnerThread->CurrentSyncLevel)
459 1.1.1.2.2.2 bouyer {
460 1.1.1.2.2.2 bouyer ACPI_ERROR ((AE_INFO,
461 1.1.1.2.2.2 bouyer "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %u current %u",
462 1.1.1.2.2.2 bouyer AcpiUtGetNodeName (ObjDesc->Mutex.Node),
463 1.1.1.2.2.2 bouyer ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel));
464 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
465 1.1.1.2.2.2 bouyer }
466 1.1.1.2.2.2 bouyer
467 1.1.1.2.2.2 bouyer /*
468 1.1.1.2.2.2 bouyer * Get the previous SyncLevel from the head of the acquired mutex list.
469 1.1.1.2.2.2 bouyer * This handles the case where several mutexes at the same level have been
470 1.1.1.2.2.2 bouyer * acquired, but are not released in reverse order.
471 1.1.1.2.2.2 bouyer */
472 1.1.1.2.2.2 bouyer PreviousSyncLevel =
473 1.1.1.2.2.2 bouyer OwnerThread->AcquiredMutexList->Mutex.OriginalSyncLevel;
474 1.1.1.2.2.2 bouyer
475 1.1.1.2.2.2 bouyer Status = AcpiExReleaseMutexObject (ObjDesc);
476 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
477 1.1.1.2.2.2 bouyer {
478 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
479 1.1.1.2.2.2 bouyer }
480 1.1.1.2.2.2 bouyer
481 1.1.1.2.2.2 bouyer if (ObjDesc->Mutex.AcquisitionDepth == 0)
482 1.1.1.2.2.2 bouyer {
483 1.1.1.2.2.2 bouyer /* Restore the previous SyncLevel */
484 1.1.1.2.2.2 bouyer
485 1.1.1.2.2.2 bouyer OwnerThread->CurrentSyncLevel = PreviousSyncLevel;
486 1.1.1.2.2.2 bouyer }
487 1.1.1.2.2.2 bouyer
488 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
489 1.1.1.2.2.2 bouyer }
490 1.1.1.2.2.2 bouyer
491 1.1.1.2.2.2 bouyer
492 1.1.1.2.2.2 bouyer /*******************************************************************************
493 1.1.1.2.2.2 bouyer *
494 1.1.1.2.2.2 bouyer * FUNCTION: AcpiExReleaseAllMutexes
495 1.1.1.2.2.2 bouyer *
496 1.1.1.2.2.2 bouyer * PARAMETERS: Thread - Current executing thread object
497 1.1.1.2.2.2 bouyer *
498 1.1.1.2.2.2 bouyer * RETURN: Status
499 1.1.1.2.2.2 bouyer *
500 1.1.1.2.2.2 bouyer * DESCRIPTION: Release all mutexes held by this thread
501 1.1.1.2.2.2 bouyer *
502 1.1.1.2.2.2 bouyer * NOTE: This function is called as the thread is exiting the interpreter.
503 1.1.1.2.2.2 bouyer * Mutexes are not released when an individual control method is exited, but
504 1.1.1.2.2.2 bouyer * only when the parent thread actually exits the interpreter. This allows one
505 1.1.1.2.2.2 bouyer * method to acquire a mutex, and a different method to release it, as long as
506 1.1.1.2.2.2 bouyer * this is performed underneath a single parent control method.
507 1.1.1.2.2.2 bouyer *
508 1.1.1.2.2.2 bouyer ******************************************************************************/
509 1.1.1.2.2.2 bouyer
510 1.1.1.2.2.2 bouyer void
511 1.1.1.2.2.2 bouyer AcpiExReleaseAllMutexes (
512 1.1.1.2.2.2 bouyer ACPI_THREAD_STATE *Thread)
513 1.1.1.2.2.2 bouyer {
514 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *Next = Thread->AcquiredMutexList;
515 1.1.1.2.2.2 bouyer ACPI_OPERAND_OBJECT *ObjDesc;
516 1.1.1.2.2.2 bouyer
517 1.1.1.2.2.2 bouyer
518 1.1.1.2.2.2 bouyer ACPI_FUNCTION_ENTRY ();
519 1.1.1.2.2.2 bouyer
520 1.1.1.2.2.2 bouyer
521 1.1.1.2.2.2 bouyer /* Traverse the list of owned mutexes, releasing each one */
522 1.1.1.2.2.2 bouyer
523 1.1.1.2.2.2 bouyer while (Next)
524 1.1.1.2.2.2 bouyer {
525 1.1.1.2.2.2 bouyer ObjDesc = Next;
526 1.1.1.2.2.2 bouyer Next = ObjDesc->Mutex.Next;
527 1.1.1.2.2.2 bouyer
528 1.1.1.2.2.2 bouyer ObjDesc->Mutex.Prev = NULL;
529 1.1.1.2.2.2 bouyer ObjDesc->Mutex.Next = NULL;
530 1.1.1.2.2.2 bouyer ObjDesc->Mutex.AcquisitionDepth = 0;
531 1.1.1.2.2.2 bouyer
532 1.1.1.2.2.2 bouyer /* Release the mutex, special case for Global Lock */
533 1.1.1.2.2.2 bouyer
534 1.1.1.2.2.2 bouyer if (ObjDesc == AcpiGbl_GlobalLockMutex)
535 1.1.1.2.2.2 bouyer {
536 1.1.1.2.2.2 bouyer /* Ignore errors */
537 1.1.1.2.2.2 bouyer
538 1.1.1.2.2.2 bouyer (void) AcpiEvReleaseGlobalLock ();
539 1.1.1.2.2.2 bouyer }
540 1.1.1.2.2.2 bouyer else
541 1.1.1.2.2.2 bouyer {
542 1.1.1.2.2.2 bouyer AcpiOsReleaseMutex (ObjDesc->Mutex.OsMutex);
543 1.1.1.2.2.2 bouyer }
544 1.1.1.2.2.2 bouyer
545 1.1.1.2.2.2 bouyer /* Mark mutex unowned */
546 1.1.1.2.2.2 bouyer
547 1.1.1.2.2.2 bouyer ObjDesc->Mutex.OwnerThread = NULL;
548 1.1.1.2.2.2 bouyer ObjDesc->Mutex.ThreadId = 0;
549 1.1.1.2.2.2 bouyer
550 1.1.1.2.2.2 bouyer /* Update Thread SyncLevel (Last mutex is the important one) */
551 1.1.1.2.2.2 bouyer
552 1.1.1.2.2.2 bouyer Thread->CurrentSyncLevel = ObjDesc->Mutex.OriginalSyncLevel;
553 1.1.1.2.2.2 bouyer }
554 1.1.1.2.2.2 bouyer }
555