Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | |
| 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: exmutex - ASL Mutex Acquire/Release functions |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
Bob Moore | 6c9deb7 | 2007-02-02 19:48:24 +0300 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2007, R. Byron Moore |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> |
| 46 | #include <acpi/acinterp.h> |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 47 | #include <acpi/acevents.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("exmutex") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 52 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 53 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 54 | acpi_ex_link_mutex(union acpi_operand_object *obj_desc, |
| 55 | struct acpi_thread_state *thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 57 | /******************************************************************************* |
| 58 | * |
| 59 | * FUNCTION: acpi_ex_unlink_mutex |
| 60 | * |
| 61 | * PARAMETERS: obj_desc - The mutex to be unlinked |
| 62 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 63 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 65 | * DESCRIPTION: Remove a mutex from the "AcquiredMutex" list |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | * |
| 67 | ******************************************************************************/ |
| 68 | |
Len Brown | 262a7a2 | 2007-05-09 23:01:59 -0400 | [diff] [blame] | 69 | void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
Len Brown | 262a7a2 | 2007-05-09 23:01:59 -0400 | [diff] [blame] | 71 | struct acpi_thread_state *thread = obj_desc->mutex.owner_thread; |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | 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 Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 85 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | thread->acquired_mutex_list = obj_desc->mutex.next; |
| 87 | } |
| 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | /******************************************************************************* |
| 91 | * |
| 92 | * FUNCTION: acpi_ex_link_mutex |
| 93 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 94 | * PARAMETERS: obj_desc - The mutex to be linked |
| 95 | * Thread - Current executing thread object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 97 | * RETURN: None |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 99 | * DESCRIPTION: Add a mutex to the "AcquiredMutex" list for this walk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * |
| 101 | ******************************************************************************/ |
| 102 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 103 | static void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | acpi_ex_link_mutex(union acpi_operand_object *obj_desc, |
| 105 | struct acpi_thread_state *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | union acpi_operand_object *list_head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /******************************************************************************* |
| 128 | * |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 129 | * 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 | * |
| 137 | * DESCRIPTION: Acquire an AML mutex, low-level interface |
| 138 | * |
| 139 | ******************************************************************************/ |
| 140 | |
| 141 | acpi_status |
| 142 | acpi_ex_acquire_mutex_object(u16 timeout, |
| 143 | union acpi_operand_object *obj_desc, |
| 144 | acpi_thread_id thread_id) |
| 145 | { |
| 146 | acpi_status status; |
| 147 | |
| 148 | ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex_object, obj_desc); |
| 149 | |
| 150 | /* Support for multiple acquires by the owning thread */ |
| 151 | |
| 152 | if (obj_desc->mutex.thread_id == thread_id) { |
| 153 | /* |
| 154 | * The mutex is already owned by this thread, just increment the |
| 155 | * acquisition depth |
| 156 | */ |
| 157 | obj_desc->mutex.acquisition_depth++; |
| 158 | return_ACPI_STATUS(AE_OK); |
| 159 | } |
| 160 | |
| 161 | /* Acquire the mutex, wait if necessary. Special case for Global Lock */ |
| 162 | |
| 163 | if (obj_desc == acpi_gbl_global_lock_mutex) { |
| 164 | status = acpi_ev_acquire_global_lock(timeout); |
| 165 | } else { |
| 166 | status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex, |
| 167 | timeout); |
| 168 | } |
| 169 | |
| 170 | if (ACPI_FAILURE(status)) { |
| 171 | |
| 172 | /* Includes failure from a timeout on time_desc */ |
| 173 | |
| 174 | return_ACPI_STATUS(status); |
| 175 | } |
| 176 | |
| 177 | /* Have the mutex: update mutex and save the sync_level */ |
| 178 | |
| 179 | obj_desc->mutex.thread_id = thread_id; |
| 180 | obj_desc->mutex.acquisition_depth = 1; |
| 181 | obj_desc->mutex.original_sync_level = 0; |
| 182 | obj_desc->mutex.owner_thread = NULL; /* Used only for AML Acquire() */ |
| 183 | |
| 184 | return_ACPI_STATUS(AE_OK); |
| 185 | } |
| 186 | |
| 187 | /******************************************************************************* |
| 188 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | * FUNCTION: acpi_ex_acquire_mutex |
| 190 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 191 | * PARAMETERS: time_desc - Timeout integer |
| 192 | * obj_desc - Mutex object |
| 193 | * walk_state - Current method execution state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | * |
| 195 | * RETURN: Status |
| 196 | * |
| 197 | * DESCRIPTION: Acquire an AML mutex |
| 198 | * |
| 199 | ******************************************************************************/ |
| 200 | |
| 201 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | acpi_ex_acquire_mutex(union acpi_operand_object *time_desc, |
| 203 | union acpi_operand_object *obj_desc, |
| 204 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 208 | ACPI_FUNCTION_TRACE_PTR(ex_acquire_mutex, obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 214 | /* Sanity check: we must have a valid thread ID */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | if (!walk_state->thread) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 217 | ACPI_ERROR((AE_INFO, |
| 218 | "Cannot acquire Mutex [%4.4s], null thread info", |
| 219 | acpi_ut_get_node_name(obj_desc->mutex.node))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | return_ACPI_STATUS(AE_AML_INTERNAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 224 | * Current Sync level must be less than or equal to the sync level of the |
Bob Moore | 967440e | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 225 | * mutex. This mechanism provides some deadlock prevention |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | */ |
| 227 | if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 228 | ACPI_ERROR((AE_INFO, |
Bob Moore | 967440e | 2006-06-23 17:04:00 -0400 | [diff] [blame] | 229 | "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)", |
| 230 | acpi_ut_get_node_name(obj_desc->mutex.node), |
| 231 | walk_state->thread->current_sync_level)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 232 | return_ACPI_STATUS(AE_AML_MUTEX_ORDER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 235 | status = acpi_ex_acquire_mutex_object((u16) time_desc->integer.value, |
| 236 | obj_desc, |
| 237 | walk_state->thread->thread_id); |
| 238 | if (ACPI_SUCCESS(status) && obj_desc->mutex.acquisition_depth == 1) { |
| 239 | obj_desc->mutex.owner_thread = walk_state->thread; |
| 240 | obj_desc->mutex.original_sync_level = |
| 241 | walk_state->thread->current_sync_level; |
| 242 | walk_state->thread->current_sync_level = |
| 243 | obj_desc->mutex.sync_level; |
| 244 | |
| 245 | /* Link the mutex to the current thread for force-unlock at method exit */ |
| 246 | |
| 247 | acpi_ex_link_mutex(obj_desc, walk_state->thread); |
| 248 | } |
| 249 | |
| 250 | return_ACPI_STATUS(status); |
| 251 | } |
| 252 | |
| 253 | /******************************************************************************* |
| 254 | * |
| 255 | * FUNCTION: acpi_ex_release_mutex_object |
| 256 | * |
| 257 | * PARAMETERS: obj_desc - The object descriptor for this op |
| 258 | * |
| 259 | * RETURN: Status |
| 260 | * |
| 261 | * DESCRIPTION: Release a previously acquired Mutex, low level interface. |
| 262 | * |
| 263 | ******************************************************************************/ |
| 264 | |
| 265 | acpi_status acpi_ex_release_mutex_object(union acpi_operand_object *obj_desc) |
| 266 | { |
| 267 | acpi_status status = AE_OK; |
| 268 | |
| 269 | ACPI_FUNCTION_TRACE(ex_release_mutex_object); |
| 270 | |
| 271 | /* Match multiple Acquires with multiple Releases */ |
| 272 | |
| 273 | obj_desc->mutex.acquisition_depth--; |
| 274 | if (obj_desc->mutex.acquisition_depth != 0) { |
| 275 | |
| 276 | /* Just decrement the depth and return */ |
| 277 | |
| 278 | return_ACPI_STATUS(AE_OK); |
| 279 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | |
Len Brown | 262a7a2 | 2007-05-09 23:01:59 -0400 | [diff] [blame] | 281 | if (obj_desc->mutex.owner_thread) { |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 282 | |
| 283 | /* Unlink the mutex from the owner's list */ |
| 284 | |
| 285 | acpi_ex_unlink_mutex(obj_desc); |
| 286 | obj_desc->mutex.owner_thread = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 289 | /* Release the mutex, special case for Global Lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 291 | if (obj_desc == acpi_gbl_global_lock_mutex) { |
| 292 | status = acpi_ev_release_global_lock(); |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 293 | } else { |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 294 | acpi_os_release_mutex(obj_desc->mutex.os_mutex); |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 295 | } |
| 296 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 297 | obj_desc->mutex.thread_id = 0; |
| 298 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /******************************************************************************* |
| 302 | * |
| 303 | * FUNCTION: acpi_ex_release_mutex |
| 304 | * |
| 305 | * PARAMETERS: obj_desc - The object descriptor for this op |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 306 | * walk_state - Current method execution state |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | * |
| 308 | * RETURN: Status |
| 309 | * |
| 310 | * DESCRIPTION: Release a previously acquired Mutex. |
| 311 | * |
| 312 | ******************************************************************************/ |
| 313 | |
| 314 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 315 | acpi_ex_release_mutex(union acpi_operand_object *obj_desc, |
| 316 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 318 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 320 | ACPI_FUNCTION_TRACE(ex_release_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 323 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /* The mutex must have been previously acquired in order to release it */ |
| 327 | |
Len Brown | 262a7a2 | 2007-05-09 23:01:59 -0400 | [diff] [blame] | 328 | if (!obj_desc->mutex.owner_thread) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 329 | ACPI_ERROR((AE_INFO, |
| 330 | "Cannot release Mutex [%4.4s], not acquired", |
| 331 | acpi_ut_get_node_name(obj_desc->mutex.node))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | /* |
| 336 | * The Mutex is owned, but this thread must be the owner. |
| 337 | * Special case for Global Lock, any thread can release |
| 338 | */ |
Len Brown | 262a7a2 | 2007-05-09 23:01:59 -0400 | [diff] [blame] | 339 | if ((obj_desc->mutex.owner_thread->thread_id != |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | walk_state->thread->thread_id) |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 341 | && (obj_desc != acpi_gbl_global_lock_mutex)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 342 | ACPI_ERROR((AE_INFO, |
Martin Bligh | 965a3d4 | 2006-10-20 14:30:26 -0700 | [diff] [blame] | 343 | "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", |
| 344 | (unsigned long)walk_state->thread->thread_id, |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 345 | acpi_ut_get_node_name(obj_desc->mutex.node), |
Len Brown | fd35094 | 2007-05-09 23:34:35 -0400 | [diff] [blame] | 346 | (unsigned long)obj_desc->mutex.owner_thread-> |
| 347 | thread_id)); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | return_ACPI_STATUS(AE_AML_NOT_OWNER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 351 | /* Sanity check: we must have a valid thread ID */ |
| 352 | |
| 353 | if (!walk_state->thread) { |
| 354 | ACPI_ERROR((AE_INFO, |
| 355 | "Cannot release Mutex [%4.4s], null thread info", |
| 356 | acpi_ut_get_node_name(obj_desc->mutex.node))); |
| 357 | return_ACPI_STATUS(AE_AML_INTERNAL); |
| 358 | } |
| 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | /* |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 361 | * The sync level of the mutex must be less than or equal to the current |
| 362 | * sync level |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | */ |
| 364 | if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 365 | ACPI_ERROR((AE_INFO, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 366 | "Cannot release Mutex [%4.4s], incorrect SyncLevel", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 367 | acpi_ut_get_node_name(obj_desc->mutex.node))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 368 | return_ACPI_STATUS(AE_AML_MUTEX_ORDER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 371 | status = acpi_ex_release_mutex_object(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 373 | /* Restore sync_level */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 374 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | walk_state->thread->current_sync_level = |
| 376 | obj_desc->mutex.original_sync_level; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 377 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /******************************************************************************* |
| 381 | * |
| 382 | * FUNCTION: acpi_ex_release_all_mutexes |
| 383 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 384 | * PARAMETERS: Thread - Current executing thread object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | * |
| 386 | * RETURN: Status |
| 387 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 388 | * DESCRIPTION: Release all mutexes held by this thread |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | * |
Bob Moore | f70a5e7 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 390 | * NOTE: This function is called as the thread is exiting the interpreter. |
| 391 | * Mutexes are not released when an individual control method is exited, but |
| 392 | * only when the parent thread actually exits the interpreter. This allows one |
| 393 | * method to acquire a mutex, and a different method to release it, as long as |
| 394 | * this is performed underneath a single parent control method. |
| 395 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | ******************************************************************************/ |
| 397 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 398 | void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 400 | union acpi_operand_object *next = thread->acquired_mutex_list; |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 401 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 403 | ACPI_FUNCTION_ENTRY(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
| 405 | /* Traverse the list of owned mutexes, releasing each one */ |
| 406 | |
| 407 | while (next) { |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 408 | obj_desc = next; |
| 409 | next = obj_desc->mutex.next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 411 | obj_desc->mutex.prev = NULL; |
| 412 | obj_desc->mutex.next = NULL; |
Bob Moore | f70a5e7 | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 413 | obj_desc->mutex.acquisition_depth = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 415 | /* Release the mutex, special case for Global Lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 417 | if (obj_desc == acpi_gbl_global_lock_mutex) { |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 418 | |
| 419 | /* Ignore errors */ |
| 420 | |
| 421 | (void)acpi_ev_release_global_lock(); |
| 422 | } else { |
| 423 | acpi_os_release_mutex(obj_desc->mutex.os_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | /* Mark mutex unowned */ |
| 427 | |
Len Brown | 262a7a2 | 2007-05-09 23:01:59 -0400 | [diff] [blame] | 428 | obj_desc->mutex.owner_thread = NULL; |
Bob Moore | ba886cd | 2008-04-10 19:06:37 +0400 | [diff] [blame^] | 429 | obj_desc->mutex.thread_id = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | /* Update Thread sync_level (Last mutex is the important one) */ |
| 432 | |
Bob Moore | c81da66 | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 433 | thread->current_sync_level = |
| 434 | obj_desc->mutex.original_sync_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | } |