blob: a8bf3d713e2821db5c6e32588f4cc52f38e326bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exmutex - ASL Mutex Acquire/Release functions
5 *
6 *****************************************************************************/
7
8/*
Len Brown75a44ce2008-04-23 23:00:13 -04009 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acinterp.h>
Bob Moorec81da662007-02-02 19:48:18 +030047#include <acpi/acevents.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("exmutex")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040053static void
Len Brown4be44fc2005-08-05 00:44:28 -040054acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
55 struct acpi_thread_state *thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/*******************************************************************************
58 *
59 * FUNCTION: acpi_ex_unlink_mutex
60 *
61 * PARAMETERS: obj_desc - The mutex to be unlinked
62 *
Robert Moore44f6c012005-04-18 22:49:35 -040063 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 *
Bob Mooreb229cf92006-04-21 17:15:00 -040065 * DESCRIPTION: Remove a mutex from the "AcquiredMutex" list
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 *
67 ******************************************************************************/
68
Len Brown262a7a22007-05-09 23:01:59 -040069void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
Len Brown262a7a22007-05-09 23:01:59 -040071 struct acpi_thread_state *thread = obj_desc->mutex.owner_thread;
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (!thread) {
74 return;
75 }
76
77 /* Doubly linked list */
78
79 if (obj_desc->mutex.next) {
80 (obj_desc->mutex.next)->mutex.prev = obj_desc->mutex.prev;
81 }
82
83 if (obj_desc->mutex.prev) {
84 (obj_desc->mutex.prev)->mutex.next = obj_desc->mutex.next;
Len Brown4be44fc2005-08-05 00:44:28 -040085 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 thread->acquired_mutex_list = obj_desc->mutex.next;
87 }
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/*******************************************************************************
91 *
92 * FUNCTION: acpi_ex_link_mutex
93 *
Robert Moore44f6c012005-04-18 22:49:35 -040094 * PARAMETERS: obj_desc - The mutex to be linked
95 * Thread - Current executing thread object
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 *
Robert Moore44f6c012005-04-18 22:49:35 -040097 * RETURN: None
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 *
Bob Mooreb229cf92006-04-21 17:15:00 -040099 * DESCRIPTION: Add a mutex to the "AcquiredMutex" list for this walk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 ******************************************************************************/
102
Robert Moore44f6c012005-04-18 22:49:35 -0400103static void
Len Brown4be44fc2005-08-05 00:44:28 -0400104acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
105 struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Len Brown4be44fc2005-08-05 00:44:28 -0400107 union acpi_operand_object *list_head;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109 list_head = thread->acquired_mutex_list;
110
111 /* This object will be the first object in the list */
112
113 obj_desc->mutex.prev = NULL;
114 obj_desc->mutex.next = list_head;
115
116 /* Update old first object to point back to this object */
117
118 if (list_head) {
119 list_head->mutex.prev = obj_desc;
120 }
121
122 /* Update list head */
123
124 thread->acquired_mutex_list = obj_desc;
125}
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127/*******************************************************************************
128 *
Bob Mooreba886cd2008-04-10 19:06:37 +0400129 * FUNCTION: acpi_ex_acquire_mutex_object
130 *
131 * PARAMETERS: time_desc - Timeout in milliseconds
132 * obj_desc - Mutex object
133 * Thread - Current thread state
134 *
135 * RETURN: Status
136 *
Bob Moore91e38d12008-04-10 19:06:37 +0400137 * DESCRIPTION: Acquire an AML mutex, low-level interface. Provides a common
138 * path that supports multiple acquires by the same thread.
139 *
140 * MUTEX: Interpreter must be locked
141 *
142 * NOTE: This interface is called from three places:
143 * 1) From acpi_ex_acquire_mutex, via an AML Acquire() operator
144 * 2) From acpi_ex_acquire_global_lock when an AML Field access requires the
145 * global lock
146 * 3) From the external interface, acpi_acquire_global_lock
Bob Mooreba886cd2008-04-10 19:06:37 +0400147 *
148 ******************************************************************************/
149
150acpi_status
151acpi_ex_acquire_mutex_object(u16 timeout,
152 union acpi_operand_object *obj_desc,
153 acpi_thread_id thread_id)
154{
155 acpi_status status;
156
157 ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex_object, obj_desc);
158
Bob Mooref02e9fa2008-04-10 19:06:37 +0400159 if (!obj_desc) {
160 return_ACPI_STATUS(AE_BAD_PARAMETER);
161 }
162
Bob Mooreba886cd2008-04-10 19:06:37 +0400163 /* Support for multiple acquires by the owning thread */
164
165 if (obj_desc->mutex.thread_id == thread_id) {
166 /*
167 * The mutex is already owned by this thread, just increment the
168 * acquisition depth
169 */
170 obj_desc->mutex.acquisition_depth++;
171 return_ACPI_STATUS(AE_OK);
172 }
173
174 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
175
176 if (obj_desc == acpi_gbl_global_lock_mutex) {
177 status = acpi_ev_acquire_global_lock(timeout);
178 } else {
179 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex,
180 timeout);
181 }
182
183 if (ACPI_FAILURE(status)) {
184
185 /* Includes failure from a timeout on time_desc */
186
187 return_ACPI_STATUS(status);
188 }
189
Bob Moore91e38d12008-04-10 19:06:37 +0400190 /* Acquired the mutex: update mutex object */
Bob Mooreba886cd2008-04-10 19:06:37 +0400191
192 obj_desc->mutex.thread_id = thread_id;
193 obj_desc->mutex.acquisition_depth = 1;
194 obj_desc->mutex.original_sync_level = 0;
195 obj_desc->mutex.owner_thread = NULL; /* Used only for AML Acquire() */
196
197 return_ACPI_STATUS(AE_OK);
198}
199
200/*******************************************************************************
201 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 * FUNCTION: acpi_ex_acquire_mutex
203 *
Robert Moore44f6c012005-04-18 22:49:35 -0400204 * PARAMETERS: time_desc - Timeout integer
205 * obj_desc - Mutex object
206 * walk_state - Current method execution state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 *
208 * RETURN: Status
209 *
210 * DESCRIPTION: Acquire an AML mutex
211 *
212 ******************************************************************************/
213
214acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400215acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
216 union acpi_operand_object *obj_desc,
217 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Len Brown4be44fc2005-08-05 00:44:28 -0400219 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Bob Mooreb229cf92006-04-21 17:15:00 -0400221 ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex, obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400224 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
226
Bob Moore91e38d12008-04-10 19:06:37 +0400227 /* Must have a valid thread ID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 if (!walk_state->thread) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500230 ACPI_ERROR((AE_INFO,
231 "Cannot acquire Mutex [%4.4s], null thread info",
232 acpi_ut_get_node_name(obj_desc->mutex.node)));
Len Brown4be44fc2005-08-05 00:44:28 -0400233 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
236 /*
Bob Moore91e38d12008-04-10 19:06:37 +0400237 * Current sync level must be less than or equal to the sync level of the
Bob Moore967440e32006-06-23 17:04:00 -0400238 * mutex. This mechanism provides some deadlock prevention
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 */
240 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500241 ACPI_ERROR((AE_INFO,
Bob Moore967440e32006-06-23 17:04:00 -0400242 "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)",
243 acpi_ut_get_node_name(obj_desc->mutex.node),
244 walk_state->thread->current_sync_level));
Len Brown4be44fc2005-08-05 00:44:28 -0400245 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
Bob Mooreba886cd2008-04-10 19:06:37 +0400248 status = acpi_ex_acquire_mutex_object((u16) time_desc->integer.value,
249 obj_desc,
250 walk_state->thread->thread_id);
251 if (ACPI_SUCCESS(status) && obj_desc->mutex.acquisition_depth == 1) {
Bob Moore91e38d12008-04-10 19:06:37 +0400252
253 /* Save Thread object, original/current sync levels */
254
Bob Mooreba886cd2008-04-10 19:06:37 +0400255 obj_desc->mutex.owner_thread = walk_state->thread;
256 obj_desc->mutex.original_sync_level =
257 walk_state->thread->current_sync_level;
258 walk_state->thread->current_sync_level =
259 obj_desc->mutex.sync_level;
260
261 /* Link the mutex to the current thread for force-unlock at method exit */
262
263 acpi_ex_link_mutex(obj_desc, walk_state->thread);
264 }
265
266 return_ACPI_STATUS(status);
267}
268
269/*******************************************************************************
270 *
271 * FUNCTION: acpi_ex_release_mutex_object
272 *
273 * PARAMETERS: obj_desc - The object descriptor for this op
274 *
275 * RETURN: Status
276 *
277 * DESCRIPTION: Release a previously acquired Mutex, low level interface.
Bob Moore91e38d12008-04-10 19:06:37 +0400278 * Provides a common path that supports multiple releases (after
279 * previous multiple acquires) by the same thread.
280 *
281 * MUTEX: Interpreter must be locked
282 *
283 * NOTE: This interface is called from three places:
284 * 1) From acpi_ex_release_mutex, via an AML Acquire() operator
285 * 2) From acpi_ex_release_global_lock when an AML Field access requires the
286 * global lock
287 * 3) From the external interface, acpi_release_global_lock
Bob Mooreba886cd2008-04-10 19:06:37 +0400288 *
289 ******************************************************************************/
290
291acpi_status acpi_ex_release_mutex_object(union acpi_operand_object *obj_desc)
292{
293 acpi_status status = AE_OK;
294
295 ACPI_FUNCTION_TRACE(ex_release_mutex_object);
296
Bob Mooref02e9fa2008-04-10 19:06:37 +0400297 if (obj_desc->mutex.acquisition_depth == 0) {
298 return (AE_NOT_ACQUIRED);
299 }
300
Bob Mooreba886cd2008-04-10 19:06:37 +0400301 /* Match multiple Acquires with multiple Releases */
302
303 obj_desc->mutex.acquisition_depth--;
304 if (obj_desc->mutex.acquisition_depth != 0) {
305
306 /* Just decrement the depth and return */
307
308 return_ACPI_STATUS(AE_OK);
309 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Len Brown262a7a22007-05-09 23:01:59 -0400311 if (obj_desc->mutex.owner_thread) {
Bob Mooreba886cd2008-04-10 19:06:37 +0400312
313 /* Unlink the mutex from the owner's list */
314
315 acpi_ex_unlink_mutex(obj_desc);
316 obj_desc->mutex.owner_thread = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
318
Bob Mooreba886cd2008-04-10 19:06:37 +0400319 /* Release the mutex, special case for Global Lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Bob Mooreba886cd2008-04-10 19:06:37 +0400321 if (obj_desc == acpi_gbl_global_lock_mutex) {
322 status = acpi_ev_release_global_lock();
Bob Moorec81da662007-02-02 19:48:18 +0300323 } else {
Bob Mooreba886cd2008-04-10 19:06:37 +0400324 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
Bob Moorec81da662007-02-02 19:48:18 +0300325 }
326
Bob Moore91e38d12008-04-10 19:06:37 +0400327 /* Clear mutex info */
328
Harvey Harrisonb62151d2008-05-22 15:45:06 -0700329 obj_desc->mutex.thread_id = NULL;
Bob Mooreba886cd2008-04-10 19:06:37 +0400330 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333/*******************************************************************************
334 *
335 * FUNCTION: acpi_ex_release_mutex
336 *
337 * PARAMETERS: obj_desc - The object descriptor for this op
Robert Moore44f6c012005-04-18 22:49:35 -0400338 * walk_state - Current method execution state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 *
340 * RETURN: Status
341 *
342 * DESCRIPTION: Release a previously acquired Mutex.
343 *
344 ******************************************************************************/
345
346acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400347acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
348 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
Bob Moorec81da662007-02-02 19:48:18 +0300350 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Bob Mooreb229cf92006-04-21 17:15:00 -0400352 ACPI_FUNCTION_TRACE(ex_release_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400355 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 /* The mutex must have been previously acquired in order to release it */
359
Len Brown262a7a22007-05-09 23:01:59 -0400360 if (!obj_desc->mutex.owner_thread) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500361 ACPI_ERROR((AE_INFO,
362 "Cannot release Mutex [%4.4s], not acquired",
363 acpi_ut_get_node_name(obj_desc->mutex.node)));
Len Brown4be44fc2005-08-05 00:44:28 -0400364 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /*
368 * The Mutex is owned, but this thread must be the owner.
369 * Special case for Global Lock, any thread can release
370 */
Len Brown262a7a22007-05-09 23:01:59 -0400371 if ((obj_desc->mutex.owner_thread->thread_id !=
Len Brown4be44fc2005-08-05 00:44:28 -0400372 walk_state->thread->thread_id)
Bob Mooreba886cd2008-04-10 19:06:37 +0400373 && (obj_desc != acpi_gbl_global_lock_mutex)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500374 ACPI_ERROR((AE_INFO,
Martin Bligh965a3d42006-10-20 14:30:26 -0700375 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
376 (unsigned long)walk_state->thread->thread_id,
Bob Mooreb8e4d892006-01-27 16:43:00 -0500377 acpi_ut_get_node_name(obj_desc->mutex.node),
Len Brownfd350942007-05-09 23:34:35 -0400378 (unsigned long)obj_desc->mutex.owner_thread->
379 thread_id));
Len Brown4be44fc2005-08-05 00:44:28 -0400380 return_ACPI_STATUS(AE_AML_NOT_OWNER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382
Bob Moore91e38d12008-04-10 19:06:37 +0400383 /* Must have a valid thread ID */
Bob Mooreba886cd2008-04-10 19:06:37 +0400384
385 if (!walk_state->thread) {
386 ACPI_ERROR((AE_INFO,
387 "Cannot release Mutex [%4.4s], null thread info",
388 acpi_ut_get_node_name(obj_desc->mutex.node)));
389 return_ACPI_STATUS(AE_AML_INTERNAL);
390 }
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 /*
Bob Moorec81da662007-02-02 19:48:18 +0300393 * The sync level of the mutex must be less than or equal to the current
394 * sync level
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 */
396 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500397 ACPI_ERROR((AE_INFO,
Bob Mooref02e9fa2008-04-10 19:06:37 +0400398 "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %d current %d",
399 acpi_ut_get_node_name(obj_desc->mutex.node),
400 obj_desc->mutex.sync_level,
401 walk_state->thread->current_sync_level));
Len Brown4be44fc2005-08-05 00:44:28 -0400402 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
Bob Mooreba886cd2008-04-10 19:06:37 +0400405 status = acpi_ex_release_mutex_object(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Bob Mooref02e9fa2008-04-10 19:06:37 +0400407 if (obj_desc->mutex.acquisition_depth == 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400408
Bob Mooref02e9fa2008-04-10 19:06:37 +0400409 /* Restore the original sync_level */
410
411 walk_state->thread->current_sync_level =
412 obj_desc->mutex.original_sync_level;
413 }
Len Brown4be44fc2005-08-05 00:44:28 -0400414 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417/*******************************************************************************
418 *
419 * FUNCTION: acpi_ex_release_all_mutexes
420 *
Robert Moore44f6c012005-04-18 22:49:35 -0400421 * PARAMETERS: Thread - Current executing thread object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 *
423 * RETURN: Status
424 *
Robert Moore44f6c012005-04-18 22:49:35 -0400425 * DESCRIPTION: Release all mutexes held by this thread
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 *
Bob Mooref70a5e72007-02-02 19:48:21 +0300427 * NOTE: This function is called as the thread is exiting the interpreter.
428 * Mutexes are not released when an individual control method is exited, but
429 * only when the parent thread actually exits the interpreter. This allows one
430 * method to acquire a mutex, and a different method to release it, as long as
431 * this is performed underneath a single parent control method.
432 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 ******************************************************************************/
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Len Brown4be44fc2005-08-05 00:44:28 -0400437 union acpi_operand_object *next = thread->acquired_mutex_list;
Bob Moorec81da662007-02-02 19:48:18 +0300438 union acpi_operand_object *obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Len Brown4be44fc2005-08-05 00:44:28 -0400440 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442 /* Traverse the list of owned mutexes, releasing each one */
443
444 while (next) {
Bob Moorec81da662007-02-02 19:48:18 +0300445 obj_desc = next;
446 next = obj_desc->mutex.next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Bob Moorec81da662007-02-02 19:48:18 +0300448 obj_desc->mutex.prev = NULL;
449 obj_desc->mutex.next = NULL;
Bob Mooref70a5e72007-02-02 19:48:21 +0300450 obj_desc->mutex.acquisition_depth = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Bob Moorec81da662007-02-02 19:48:18 +0300452 /* Release the mutex, special case for Global Lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Bob Mooreba886cd2008-04-10 19:06:37 +0400454 if (obj_desc == acpi_gbl_global_lock_mutex) {
Bob Moorec81da662007-02-02 19:48:18 +0300455
456 /* Ignore errors */
457
458 (void)acpi_ev_release_global_lock();
459 } else {
460 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 /* Mark mutex unowned */
464
Len Brown262a7a22007-05-09 23:01:59 -0400465 obj_desc->mutex.owner_thread = NULL;
Harvey Harrisonb62151d2008-05-22 15:45:06 -0700466 obj_desc->mutex.thread_id = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 /* Update Thread sync_level (Last mutex is the important one) */
469
Bob Moorec81da662007-02-02 19:48:18 +0300470 thread->current_sync_level =
471 obj_desc->mutex.original_sync_level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473}