Deleted Added
full compact
utmutex.c (151937) utmutex.c (167802)
1/*******************************************************************************
2 *
3 * Module Name: utmutex - local mutex support
1/*******************************************************************************
2 *
3 * Module Name: utmutex - local mutex support
4 * $Revision: 1.3 $
4 * $Revision: 1.12 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.

--- 127 unchanged lines hidden (view full) ---

148ACPI_STATUS
149AcpiUtMutexInitialize (
150 void)
151{
152 UINT32 i;
153 ACPI_STATUS Status;
154
155
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.

--- 127 unchanged lines hidden (view full) ---

148ACPI_STATUS
149AcpiUtMutexInitialize (
150 void)
151{
152 UINT32 i;
153 ACPI_STATUS Status;
154
155
156 ACPI_FUNCTION_TRACE ("UtMutexInitialize");
156 ACPI_FUNCTION_TRACE (UtMutexInitialize);
157
158
159 /*
160 * Create each of the predefined mutex objects
161 */
157
158
159 /*
160 * Create each of the predefined mutex objects
161 */
162 for (i = 0; i < NUM_MUTEX; i++)
162 for (i = 0; i < ACPI_NUM_MUTEX; i++)
163 {
164 Status = AcpiUtCreateMutex (i);
165 if (ACPI_FAILURE (Status))
166 {
167 return_ACPI_STATUS (Status);
168 }
169 }
170
163 {
164 Status = AcpiUtCreateMutex (i);
165 if (ACPI_FAILURE (Status))
166 {
167 return_ACPI_STATUS (Status);
168 }
169 }
170
171 /* Create the spinlocks for use at interrupt level */
172
171 Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
173 Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
174 if (ACPI_FAILURE (Status))
175 {
176 return_ACPI_STATUS (Status);
177 }
178
179 Status = AcpiOsCreateLock (&AcpiGbl_HardwareLock);
172 return_ACPI_STATUS (Status);
173}
174
175
176/*******************************************************************************
177 *
178 * FUNCTION: AcpiUtMutexTerminate
179 *

--- 7 unchanged lines hidden (view full) ---

187
188void
189AcpiUtMutexTerminate (
190 void)
191{
192 UINT32 i;
193
194
180 return_ACPI_STATUS (Status);
181}
182
183
184/*******************************************************************************
185 *
186 * FUNCTION: AcpiUtMutexTerminate
187 *

--- 7 unchanged lines hidden (view full) ---

195
196void
197AcpiUtMutexTerminate (
198 void)
199{
200 UINT32 i;
201
202
195 ACPI_FUNCTION_TRACE ("UtMutexTerminate");
203 ACPI_FUNCTION_TRACE (UtMutexTerminate);
196
197
198 /*
199 * Delete each predefined mutex object
200 */
204
205
206 /*
207 * Delete each predefined mutex object
208 */
201 for (i = 0; i < NUM_MUTEX; i++)
209 for (i = 0; i < ACPI_NUM_MUTEX; i++)
202 {
203 (void) AcpiUtDeleteMutex (i);
204 }
205
210 {
211 (void) AcpiUtDeleteMutex (i);
212 }
213
214 /* Delete the spinlocks */
215
206 AcpiOsDeleteLock (AcpiGbl_GpeLock);
216 AcpiOsDeleteLock (AcpiGbl_GpeLock);
217 AcpiOsDeleteLock (AcpiGbl_HardwareLock);
207 return_VOID;
208}
209
210
211/*******************************************************************************
212 *
213 * FUNCTION: AcpiUtCreateMutex
214 *

--- 7 unchanged lines hidden (view full) ---

222
223static ACPI_STATUS
224AcpiUtCreateMutex (
225 ACPI_MUTEX_HANDLE MutexId)
226{
227 ACPI_STATUS Status = AE_OK;
228
229
218 return_VOID;
219}
220
221
222/*******************************************************************************
223 *
224 * FUNCTION: AcpiUtCreateMutex
225 *

--- 7 unchanged lines hidden (view full) ---

233
234static ACPI_STATUS
235AcpiUtCreateMutex (
236 ACPI_MUTEX_HANDLE MutexId)
237{
238 ACPI_STATUS Status = AE_OK;
239
240
230 ACPI_FUNCTION_TRACE_U32 ("UtCreateMutex", MutexId);
241 ACPI_FUNCTION_TRACE_U32 (UtCreateMutex, MutexId);
231
232
242
243
233 if (MutexId > MAX_MUTEX)
244 if (MutexId > ACPI_MAX_MUTEX)
234 {
235 return_ACPI_STATUS (AE_BAD_PARAMETER);
236 }
237
238 if (!AcpiGbl_MutexInfo[MutexId].Mutex)
239 {
245 {
246 return_ACPI_STATUS (AE_BAD_PARAMETER);
247 }
248
249 if (!AcpiGbl_MutexInfo[MutexId].Mutex)
250 {
240 Status = AcpiOsCreateSemaphore (1, 1,
241 &AcpiGbl_MutexInfo[MutexId].Mutex);
251 Status = AcpiOsCreateMutex (&AcpiGbl_MutexInfo[MutexId].Mutex);
242 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
243 AcpiGbl_MutexInfo[MutexId].UseCount = 0;
244 }
245
246 return_ACPI_STATUS (Status);
247}
248
249

--- 8 unchanged lines hidden (view full) ---

258 * DESCRIPTION: Delete a mutex object.
259 *
260 ******************************************************************************/
261
262static ACPI_STATUS
263AcpiUtDeleteMutex (
264 ACPI_MUTEX_HANDLE MutexId)
265{
252 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
253 AcpiGbl_MutexInfo[MutexId].UseCount = 0;
254 }
255
256 return_ACPI_STATUS (Status);
257}
258
259

--- 8 unchanged lines hidden (view full) ---

268 * DESCRIPTION: Delete a mutex object.
269 *
270 ******************************************************************************/
271
272static ACPI_STATUS
273AcpiUtDeleteMutex (
274 ACPI_MUTEX_HANDLE MutexId)
275{
266 ACPI_STATUS Status;
267
276
277 ACPI_FUNCTION_TRACE_U32 (UtDeleteMutex, MutexId);
268
278
269 ACPI_FUNCTION_TRACE_U32 ("UtDeleteMutex", MutexId);
270
279
271
272 if (MutexId > MAX_MUTEX)
280 if (MutexId > ACPI_MAX_MUTEX)
273 {
274 return_ACPI_STATUS (AE_BAD_PARAMETER);
275 }
276
281 {
282 return_ACPI_STATUS (AE_BAD_PARAMETER);
283 }
284
277 Status = AcpiOsDeleteSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex);
285 AcpiOsDeleteMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
278
279 AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
280 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
281
286
287 AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
288 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
289
282 return_ACPI_STATUS (Status);
290 return_ACPI_STATUS (AE_OK);
283}
284
285
286/*******************************************************************************
287 *
288 * FUNCTION: AcpiUtAcquireMutex
289 *
290 * PARAMETERS: MutexID - ID of the mutex to be acquired

--- 4 unchanged lines hidden (view full) ---

295 *
296 ******************************************************************************/
297
298ACPI_STATUS
299AcpiUtAcquireMutex (
300 ACPI_MUTEX_HANDLE MutexId)
301{
302 ACPI_STATUS Status;
291}
292
293
294/*******************************************************************************
295 *
296 * FUNCTION: AcpiUtAcquireMutex
297 *
298 * PARAMETERS: MutexID - ID of the mutex to be acquired

--- 4 unchanged lines hidden (view full) ---

303 *
304 ******************************************************************************/
305
306ACPI_STATUS
307AcpiUtAcquireMutex (
308 ACPI_MUTEX_HANDLE MutexId)
309{
310 ACPI_STATUS Status;
303 UINT32 ThisThreadId;
311 ACPI_THREAD_ID ThisThreadId;
304
305
312
313
306 ACPI_FUNCTION_NAME ("UtAcquireMutex");
314 ACPI_FUNCTION_NAME (UtAcquireMutex);
307
308
315
316
309 if (MutexId > MAX_MUTEX)
317 if (MutexId > ACPI_MAX_MUTEX)
310 {
311 return (AE_BAD_PARAMETER);
312 }
313
314 ThisThreadId = AcpiOsGetThreadId ();
315
316#ifdef ACPI_MUTEX_DEBUG
317 {
318 UINT32 i;
319 /*
320 * Mutex debug code, for internal debugging only.
321 *
322 * Deadlock prevention. Check if this thread owns any mutexes of value
323 * greater than or equal to this one. If so, the thread has violated
324 * the mutex ordering rule. This indicates a coding error somewhere in
325 * the ACPI subsystem code.
326 */
318 {
319 return (AE_BAD_PARAMETER);
320 }
321
322 ThisThreadId = AcpiOsGetThreadId ();
323
324#ifdef ACPI_MUTEX_DEBUG
325 {
326 UINT32 i;
327 /*
328 * Mutex debug code, for internal debugging only.
329 *
330 * Deadlock prevention. Check if this thread owns any mutexes of value
331 * greater than or equal to this one. If so, the thread has violated
332 * the mutex ordering rule. This indicates a coding error somewhere in
333 * the ACPI subsystem code.
334 */
327 for (i = MutexId; i < MAX_MUTEX; i++)
335 for (i = MutexId; i < ACPI_MAX_MUTEX; i++)
328 {
329 if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
330 {
331 if (i == MutexId)
332 {
336 {
337 if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
338 {
339 if (i == MutexId)
340 {
333 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
334 "Mutex [%s] already acquired by this thread [%X]\n",
341 ACPI_ERROR ((AE_INFO,
342 "Mutex [%s] already acquired by this thread [%X]",
335 AcpiUtGetMutexName (MutexId), ThisThreadId));
336
337 return (AE_ALREADY_ACQUIRED);
338 }
339
343 AcpiUtGetMutexName (MutexId), ThisThreadId));
344
345 return (AE_ALREADY_ACQUIRED);
346 }
347
340 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
341 "Invalid acquire order: Thread %X owns [%s], wants [%s]\n",
348 ACPI_ERROR ((AE_INFO,
349 "Invalid acquire order: Thread %X owns [%s], wants [%s]",
342 ThisThreadId, AcpiUtGetMutexName (i),
343 AcpiUtGetMutexName (MutexId)));
344
345 return (AE_ACQUIRE_DEADLOCK);
346 }
347 }
348 }
349#endif
350
351 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
352 "Thread %X attempting to acquire Mutex [%s]\n",
353 ThisThreadId, AcpiUtGetMutexName (MutexId)));
354
350 ThisThreadId, AcpiUtGetMutexName (i),
351 AcpiUtGetMutexName (MutexId)));
352
353 return (AE_ACQUIRE_DEADLOCK);
354 }
355 }
356 }
357#endif
358
359 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
360 "Thread %X attempting to acquire Mutex [%s]\n",
361 ThisThreadId, AcpiUtGetMutexName (MutexId)));
362
355 Status = AcpiOsWaitSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex,
356 1, ACPI_WAIT_FOREVER);
363 Status = AcpiOsAcquireMutex (AcpiGbl_MutexInfo[MutexId].Mutex,
364 ACPI_WAIT_FOREVER);
357 if (ACPI_SUCCESS (Status))
358 {
359 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
360 ThisThreadId, AcpiUtGetMutexName (MutexId)));
361
362 AcpiGbl_MutexInfo[MutexId].UseCount++;
363 AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId;
364 }
365 else
366 {
365 if (ACPI_SUCCESS (Status))
366 {
367 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X acquired Mutex [%s]\n",
368 ThisThreadId, AcpiUtGetMutexName (MutexId)));
369
370 AcpiGbl_MutexInfo[MutexId].UseCount++;
371 AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId;
372 }
373 else
374 {
367 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
368 "Thread %X could not acquire Mutex [%s] %s\n",
369 ThisThreadId, AcpiUtGetMutexName (MutexId),
370 AcpiFormatException (Status)));
375 ACPI_EXCEPTION ((AE_INFO, Status,
376 "Thread %X could not acquire Mutex [%X]", ThisThreadId, MutexId));
371 }
372
373 return (Status);
374}
375
376
377/*******************************************************************************
378 *

--- 6 unchanged lines hidden (view full) ---

385 * DESCRIPTION: Release a mutex object.
386 *
387 ******************************************************************************/
388
389ACPI_STATUS
390AcpiUtReleaseMutex (
391 ACPI_MUTEX_HANDLE MutexId)
392{
377 }
378
379 return (Status);
380}
381
382
383/*******************************************************************************
384 *

--- 6 unchanged lines hidden (view full) ---

391 * DESCRIPTION: Release a mutex object.
392 *
393 ******************************************************************************/
394
395ACPI_STATUS
396AcpiUtReleaseMutex (
397 ACPI_MUTEX_HANDLE MutexId)
398{
393 ACPI_STATUS Status;
394 UINT32 ThisThreadId;
399 ACPI_THREAD_ID ThisThreadId;
395
396
400
401
397 ACPI_FUNCTION_NAME ("UtReleaseMutex");
402 ACPI_FUNCTION_NAME (UtReleaseMutex);
398
399
400 ThisThreadId = AcpiOsGetThreadId ();
401 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
402 "Thread %X releasing Mutex [%s]\n", ThisThreadId,
403 AcpiUtGetMutexName (MutexId)));
404
403
404
405 ThisThreadId = AcpiOsGetThreadId ();
406 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
407 "Thread %X releasing Mutex [%s]\n", ThisThreadId,
408 AcpiUtGetMutexName (MutexId)));
409
405 if (MutexId > MAX_MUTEX)
410 if (MutexId > ACPI_MAX_MUTEX)
406 {
407 return (AE_BAD_PARAMETER);
408 }
409
410 /*
411 * Mutex must be acquired in order to release it!
412 */
413 if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED)
414 {
411 {
412 return (AE_BAD_PARAMETER);
413 }
414
415 /*
416 * Mutex must be acquired in order to release it!
417 */
418 if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED)
419 {
415 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
416 "Mutex [%s] is not acquired, cannot release\n",
417 AcpiUtGetMutexName (MutexId)));
420 ACPI_ERROR ((AE_INFO,
421 "Mutex [%X] is not acquired, cannot release", MutexId));
418
419 return (AE_NOT_ACQUIRED);
420 }
421
422#ifdef ACPI_MUTEX_DEBUG
423 {
424 UINT32 i;
425 /*
426 * Mutex debug code, for internal debugging only.
427 *
428 * Deadlock prevention. Check if this thread owns any mutexes of value
429 * greater than this one. If so, the thread has violated the mutex
430 * ordering rule. This indicates a coding error somewhere in
431 * the ACPI subsystem code.
432 */
422
423 return (AE_NOT_ACQUIRED);
424 }
425
426#ifdef ACPI_MUTEX_DEBUG
427 {
428 UINT32 i;
429 /*
430 * Mutex debug code, for internal debugging only.
431 *
432 * Deadlock prevention. Check if this thread owns any mutexes of value
433 * greater than this one. If so, the thread has violated the mutex
434 * ordering rule. This indicates a coding error somewhere in
435 * the ACPI subsystem code.
436 */
433 for (i = MutexId; i < MAX_MUTEX; i++)
437 for (i = MutexId; i < ACPI_MAX_MUTEX; i++)
434 {
435 if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
436 {
437 if (i == MutexId)
438 {
439 continue;
440 }
441
438 {
439 if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
440 {
441 if (i == MutexId)
442 {
443 continue;
444 }
445
442 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
443 "Invalid release order: owns [%s], releasing [%s]\n",
446 ACPI_ERROR ((AE_INFO,
447 "Invalid release order: owns [%s], releasing [%s]",
444 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
445
446 return (AE_RELEASE_DEADLOCK);
447 }
448 }
449 }
450#endif
451
452 /* Mark unlocked FIRST */
453
454 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
455
448 AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
449
450 return (AE_RELEASE_DEADLOCK);
451 }
452 }
453 }
454#endif
455
456 /* Mark unlocked FIRST */
457
458 AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
459
456 Status = AcpiOsSignalSemaphore (AcpiGbl_MutexInfo[MutexId].Mutex, 1);
457
458 if (ACPI_FAILURE (Status))
459 {
460 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
461 "Thread %X could not release Mutex [%s] %s\n",
462 ThisThreadId, AcpiUtGetMutexName (MutexId),
463 AcpiFormatException (Status)));
464 }
465 else
466 {
467 ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %X released Mutex [%s]\n",
468 ThisThreadId, AcpiUtGetMutexName (MutexId)));
469 }
470
471 return (Status);
460 AcpiOsReleaseMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
461 return (AE_OK);
472}
473
474
462}
463
464