aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/executer/exmutex.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/acpi/executer/exmutex.c')
-rw-r--r--drivers/acpi/executer/exmutex.c237
1 files changed, 166 insertions, 71 deletions
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 6748e3ef0997..c873ab40cd0e 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -6,7 +6,7 @@
6 *****************************************************************************/ 6 *****************************************************************************/
7 7
8/* 8/*
9 * Copyright (C) 2000 - 2007, R. Byron Moore 9 * Copyright (C) 2000 - 2008, Intel Corp.
10 * All rights reserved. 10 * All rights reserved.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
@@ -126,6 +126,79 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
126 126
127/******************************************************************************* 127/*******************************************************************************
128 * 128 *
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. 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
147 *
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
159 if (!obj_desc) {
160 return_ACPI_STATUS(AE_BAD_PARAMETER);
161 }
162
163 /* 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
190 /* Acquired the mutex: update mutex object */
191
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 *
129 * FUNCTION: acpi_ex_acquire_mutex 202 * FUNCTION: acpi_ex_acquire_mutex
130 * 203 *
131 * PARAMETERS: time_desc - Timeout integer 204 * PARAMETERS: time_desc - Timeout integer
@@ -151,7 +224,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
151 return_ACPI_STATUS(AE_BAD_PARAMETER); 224 return_ACPI_STATUS(AE_BAD_PARAMETER);
152 } 225 }
153 226
154 /* Sanity check: we must have a valid thread ID */ 227 /* Must have a valid thread ID */
155 228
156 if (!walk_state->thread) { 229 if (!walk_state->thread) {
157 ACPI_ERROR((AE_INFO, 230 ACPI_ERROR((AE_INFO,
@@ -161,7 +234,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
161 } 234 }
162 235
163 /* 236 /*
164 * Current Sync must be less than or equal to the sync level of the 237 * Current sync level must be less than or equal to the sync level of the
165 * mutex. This mechanism provides some deadlock prevention 238 * mutex. This mechanism provides some deadlock prevention
166 */ 239 */
167 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) { 240 if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
@@ -172,51 +245,89 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
172 return_ACPI_STATUS(AE_AML_MUTEX_ORDER); 245 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
173 } 246 }
174 247
175 /* Support for multiple acquires by the owning thread */ 248 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) {
176 252
177 if (obj_desc->mutex.owner_thread) { 253 /* Save Thread object, original/current sync levels */
178 if (obj_desc->mutex.owner_thread->thread_id == 254
179 walk_state->thread->thread_id) { 255 obj_desc->mutex.owner_thread = walk_state->thread;
180 /* 256 obj_desc->mutex.original_sync_level =
181 * The mutex is already owned by this thread, just increment the 257 walk_state->thread->current_sync_level;
182 * acquisition depth 258 walk_state->thread->current_sync_level =
183 */ 259 obj_desc->mutex.sync_level;
184 obj_desc->mutex.acquisition_depth++; 260
185 return_ACPI_STATUS(AE_OK); 261 /* Link the mutex to the current thread for force-unlock at method exit */
186 } 262
263 acpi_ex_link_mutex(obj_desc, walk_state->thread);
187 } 264 }
188 265
189 /* Acquire the mutex, wait if necessary. Special case for Global Lock */ 266 return_ACPI_STATUS(status);
267}
190 268
191 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 269/*******************************************************************************
192 status = 270 *
193 acpi_ev_acquire_global_lock((u16) time_desc->integer.value); 271 * FUNCTION: acpi_ex_release_mutex_object
194 } else { 272 *
195 status = acpi_ex_system_wait_mutex(obj_desc->mutex.os_mutex, 273 * PARAMETERS: obj_desc - The object descriptor for this op
196 (u16) time_desc->integer. 274 *
197 value); 275 * RETURN: Status
276 *
277 * DESCRIPTION: Release a previously acquired Mutex, low level interface.
278 * 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
288 *
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
297 if (obj_desc->mutex.acquisition_depth == 0) {
298 return (AE_NOT_ACQUIRED);
198 } 299 }
199 300
200 if (ACPI_FAILURE(status)) { 301 /* Match multiple Acquires with multiple Releases */
201 302
202 /* Includes failure from a timeout on time_desc */ 303 obj_desc->mutex.acquisition_depth--;
304 if (obj_desc->mutex.acquisition_depth != 0) {
203 305
204 return_ACPI_STATUS(status); 306 /* Just decrement the depth and return */
307
308 return_ACPI_STATUS(AE_OK);
205 } 309 }
206 310
207 /* Have the mutex: update mutex and walk info and save the sync_level */ 311 if (obj_desc->mutex.owner_thread) {
208 312
209 obj_desc->mutex.owner_thread = walk_state->thread; 313 /* Unlink the mutex from the owner's list */
210 obj_desc->mutex.acquisition_depth = 1;
211 obj_desc->mutex.original_sync_level =
212 walk_state->thread->current_sync_level;
213 314
214 walk_state->thread->current_sync_level = obj_desc->mutex.sync_level; 315 acpi_ex_unlink_mutex(obj_desc);
316 obj_desc->mutex.owner_thread = NULL;
317 }
215 318
216 /* Link the mutex to the current thread for force-unlock at method exit */ 319 /* Release the mutex, special case for Global Lock */
217 320
218 acpi_ex_link_mutex(obj_desc, walk_state->thread); 321 if (obj_desc == acpi_gbl_global_lock_mutex) {
219 return_ACPI_STATUS(AE_OK); 322 status = acpi_ev_release_global_lock();
323 } else {
324 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
325 }
326
327 /* Clear mutex info */
328
329 obj_desc->mutex.thread_id = 0;
330 return_ACPI_STATUS(status);
220} 331}
221 332
222/******************************************************************************* 333/*******************************************************************************
@@ -253,22 +364,13 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
253 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED); 364 return_ACPI_STATUS(AE_AML_MUTEX_NOT_ACQUIRED);
254 } 365 }
255 366
256 /* Sanity check: we must have a valid thread ID */
257
258 if (!walk_state->thread) {
259 ACPI_ERROR((AE_INFO,
260 "Cannot release Mutex [%4.4s], null thread info",
261 acpi_ut_get_node_name(obj_desc->mutex.node)));
262 return_ACPI_STATUS(AE_AML_INTERNAL);
263 }
264
265 /* 367 /*
266 * The Mutex is owned, but this thread must be the owner. 368 * The Mutex is owned, but this thread must be the owner.
267 * Special case for Global Lock, any thread can release 369 * Special case for Global Lock, any thread can release
268 */ 370 */
269 if ((obj_desc->mutex.owner_thread->thread_id != 371 if ((obj_desc->mutex.owner_thread->thread_id !=
270 walk_state->thread->thread_id) 372 walk_state->thread->thread_id)
271 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) { 373 && (obj_desc != acpi_gbl_global_lock_mutex)) {
272 ACPI_ERROR((AE_INFO, 374 ACPI_ERROR((AE_INFO,
273 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", 375 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
274 (unsigned long)walk_state->thread->thread_id, 376 (unsigned long)walk_state->thread->thread_id,
@@ -278,45 +380,37 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
278 return_ACPI_STATUS(AE_AML_NOT_OWNER); 380 return_ACPI_STATUS(AE_AML_NOT_OWNER);
279 } 381 }
280 382
383 /* Must have a valid thread ID */
384
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
281 /* 392 /*
282 * The sync level of the mutex must be less than or equal to the current 393 * The sync level of the mutex must be less than or equal to the current
283 * sync level 394 * sync level
284 */ 395 */
285 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) { 396 if (obj_desc->mutex.sync_level > walk_state->thread->current_sync_level) {
286 ACPI_ERROR((AE_INFO, 397 ACPI_ERROR((AE_INFO,
287 "Cannot release Mutex [%4.4s], incorrect SyncLevel", 398 "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %d current %d",
288 acpi_ut_get_node_name(obj_desc->mutex.node))); 399 acpi_ut_get_node_name(obj_desc->mutex.node),
400 obj_desc->mutex.sync_level,
401 walk_state->thread->current_sync_level));
289 return_ACPI_STATUS(AE_AML_MUTEX_ORDER); 402 return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
290 } 403 }
291 404
292 /* Match multiple Acquires with multiple Releases */ 405 status = acpi_ex_release_mutex_object(obj_desc);
293
294 obj_desc->mutex.acquisition_depth--;
295 if (obj_desc->mutex.acquisition_depth != 0) {
296
297 /* Just decrement the depth and return */
298
299 return_ACPI_STATUS(AE_OK);
300 }
301
302 /* Unlink the mutex from the owner's list */
303 406
304 acpi_ex_unlink_mutex(obj_desc); 407 if (obj_desc->mutex.acquisition_depth == 0) {
305 408
306 /* Release the mutex, special case for Global Lock */ 409 /* Restore the original sync_level */
307 410
308 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 411 walk_state->thread->current_sync_level =
309 status = acpi_ev_release_global_lock(); 412 obj_desc->mutex.original_sync_level;
310 } else {
311 acpi_os_release_mutex(obj_desc->mutex.os_mutex);
312 } 413 }
313
314 /* Update the mutex and restore sync_level */
315
316 obj_desc->mutex.owner_thread = NULL;
317 walk_state->thread->current_sync_level =
318 obj_desc->mutex.original_sync_level;
319
320 return_ACPI_STATUS(status); 414 return_ACPI_STATUS(status);
321} 415}
322 416
@@ -357,7 +451,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
357 451
358 /* Release the mutex, special case for Global Lock */ 452 /* Release the mutex, special case for Global Lock */
359 453
360 if (obj_desc->mutex.os_mutex == acpi_gbl_global_lock_mutex) { 454 if (obj_desc == acpi_gbl_global_lock_mutex) {
361 455
362 /* Ignore errors */ 456 /* Ignore errors */
363 457
@@ -369,6 +463,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
369 /* Mark mutex unowned */ 463 /* Mark mutex unowned */
370 464
371 obj_desc->mutex.owner_thread = NULL; 465 obj_desc->mutex.owner_thread = NULL;
466 obj_desc->mutex.thread_id = 0;
372 467
373 /* Update Thread sync_level (Last mutex is the important one) */ 468 /* Update Thread sync_level (Last mutex is the important one) */
374 469