exmutex.c.patch

eocallaghan, 09/19/2010 04:25 AM

Download (6.95 KB)

View differences:

sys/contrib/dev/acpica-unix/executer/exmutex.c
9 9
 *
10 10
 * 1. Copyright Notice
11 11
 *
12
 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12
 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
13 13
 * All rights reserved.
14 14
 *
15 15
 * 2. License
......
168 168
        (ObjDesc->Mutex.Prev)->Mutex.Next = ObjDesc->Mutex.Next;
169 169

  
170 170
        /*
171
         * Migrate the previous sync level associated with this mutex to the
172
         * previous mutex on the list so that it may be preserved. This handles
173
         * the case where several mutexes have been acquired at the same level,
174
         * but are not released in opposite order.
171
         * Migrate the previous sync level associated with this mutex to
172
         * the previous mutex on the list so that it may be preserved.
173
         * This handles the case where several mutexes have been acquired
174
         * at the same level, but are not released in opposite order.
175 175
         */
176 176
        (ObjDesc->Mutex.Prev)->Mutex.OriginalSyncLevel =
177 177
            ObjDesc->Mutex.OriginalSyncLevel;
......
187 187
 *
188 188
 * FUNCTION:    AcpiExLinkMutex
189 189
 *
190
 * PARAMETERS:  ObjDesc         - The mutex to be linked
191
 *              Thread          - Current executing thread object
190
 * PARAMETERS:  ObjDesc             - The mutex to be linked
191
 *              Thread              - Current executing thread object
192 192
 *
193 193
 * RETURN:      None
194 194
 *
......
228 228
 *
229 229
 * FUNCTION:    AcpiExAcquireMutexObject
230 230
 *
231
 * PARAMETERS:  TimeDesc            - Timeout in milliseconds
231
 * PARAMETERS:  Timeout             - Timeout in milliseconds
232 232
 *              ObjDesc             - Mutex object
233
 *              Thread              - Current thread state
233
 *              ThreadId            - Current thread state
234 234
 *
235 235
 * RETURN:      Status
236 236
 *
......
337 337
        return_ACPI_STATUS (AE_BAD_PARAMETER);
338 338
    }
339 339

  
340
    /* Must have a valid thread ID */
340
    /* Must have a valid thread state struct */
341 341

  
342 342
    if (!WalkState->Thread)
343 343
    {
344
        ACPI_ERROR ((AE_INFO, "Cannot acquire Mutex [%4.4s], null thread info",
344
        ACPI_ERROR ((AE_INFO,
345
            "Cannot acquire Mutex [%4.4s], null thread info",
345 346
            AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
346 347
        return_ACPI_STATUS (AE_AML_INTERNAL);
347 348
    }
......
353 354
    if (WalkState->Thread->CurrentSyncLevel > ObjDesc->Mutex.SyncLevel)
354 355
    {
355 356
        ACPI_ERROR ((AE_INFO,
356
            "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)",
357
            "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%u)",
357 358
            AcpiUtGetNodeName (ObjDesc->Mutex.Node),
358 359
            WalkState->Thread->CurrentSyncLevel));
359 360
        return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
......
471 472
{
472 473
    ACPI_STATUS             Status = AE_OK;
473 474
    UINT8                   PreviousSyncLevel;
475
    ACPI_THREAD_STATE       *OwnerThread;
474 476

  
475 477

  
476 478
    ACPI_FUNCTION_TRACE (ExReleaseMutex);
......
481 483
        return_ACPI_STATUS (AE_BAD_PARAMETER);
482 484
    }
483 485

  
486
    OwnerThread = ObjDesc->Mutex.OwnerThread;
487

  
484 488
    /* The mutex must have been previously acquired in order to release it */
485 489

  
486
    if (!ObjDesc->Mutex.OwnerThread)
490
    if (!OwnerThread)
487 491
    {
488
        ACPI_ERROR ((AE_INFO, "Cannot release Mutex [%4.4s], not acquired",
492
        ACPI_ERROR ((AE_INFO,
493
            "Cannot release Mutex [%4.4s], not acquired",
489 494
            AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
490 495
        return_ACPI_STATUS (AE_AML_MUTEX_NOT_ACQUIRED);
491 496
    }
492 497

  
498
    /* Must have a valid thread ID */
499

  
500
    if (!WalkState->Thread)
501
    {
502
        ACPI_ERROR ((AE_INFO,
503
            "Cannot release Mutex [%4.4s], null thread info",
504
            AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
505
        return_ACPI_STATUS (AE_AML_INTERNAL);
506
    }
507

  
493 508
    /*
494 509
     * The Mutex is owned, but this thread must be the owner.
495 510
     * Special case for Global Lock, any thread can release
496 511
     */
497
    if ((ObjDesc->Mutex.OwnerThread->ThreadId != WalkState->Thread->ThreadId) &&
512
    if ((OwnerThread->ThreadId != WalkState->Thread->ThreadId) &&
498 513
        (ObjDesc != AcpiGbl_GlobalLockMutex))
499 514
    {
500 515
        ACPI_ERROR ((AE_INFO,
501 516
            "Thread %p cannot release Mutex [%4.4s] acquired by thread %p",
502 517
            ACPI_CAST_PTR (void, WalkState->Thread->ThreadId),
503 518
            AcpiUtGetNodeName (ObjDesc->Mutex.Node),
504
            ACPI_CAST_PTR (void, ObjDesc->Mutex.OwnerThread->ThreadId)));
519
            ACPI_CAST_PTR (void, OwnerThread->ThreadId)));
505 520
        return_ACPI_STATUS (AE_AML_NOT_OWNER);
506 521
    }
507 522

  
508
    /* Must have a valid thread ID */
509

  
510
    if (!WalkState->Thread)
511
    {
512
        ACPI_ERROR ((AE_INFO, "Cannot release Mutex [%4.4s], null thread info",
513
            AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
514
        return_ACPI_STATUS (AE_AML_INTERNAL);
515
    }
516

  
517 523
    /*
518 524
     * The sync level of the mutex must be equal to the current sync level. In
519 525
     * other words, the current level means that at least one mutex at that
......
521 527
     * different level can only mean that the mutex ordering rule is being
522 528
     * violated. This behavior is clarified in ACPI 4.0 specification.
523 529
     */
524
    if (ObjDesc->Mutex.SyncLevel != WalkState->Thread->CurrentSyncLevel)
530
    if (ObjDesc->Mutex.SyncLevel != OwnerThread->CurrentSyncLevel)
525 531
    {
526 532
        ACPI_ERROR ((AE_INFO,
527
            "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %d current %d",
533
            "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %u current %u",
528 534
            AcpiUtGetNodeName (ObjDesc->Mutex.Node),
529 535
            ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel));
530 536
        return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
......
536 542
     * acquired, but are not released in reverse order.
537 543
     */
538 544
    PreviousSyncLevel =
539
        WalkState->Thread->AcquiredMutexList->Mutex.OriginalSyncLevel;
545
        OwnerThread->AcquiredMutexList->Mutex.OriginalSyncLevel;
540 546

  
541 547
    Status = AcpiExReleaseMutexObject (ObjDesc);
542 548
    if (ACPI_FAILURE (Status))
......
548 554
    {
549 555
        /* Restore the previous SyncLevel */
550 556

  
551
        WalkState->Thread->CurrentSyncLevel = PreviousSyncLevel;
557
        OwnerThread->CurrentSyncLevel = PreviousSyncLevel;
552 558
    }
559

  
553 560
    return_ACPI_STATUS (Status);
554 561
}
555 562

  
......
558 565
 *
559 566
 * FUNCTION:    AcpiExReleaseAllMutexes
560 567
 *
561
 * PARAMETERS:  Thread          - Current executing thread object
568
 * PARAMETERS:  Thread              - Current executing thread object
562 569
 *
563 570
 * RETURN:      Status
564 571
 *
......
617 624
        Thread->CurrentSyncLevel = ObjDesc->Mutex.OriginalSyncLevel;
618 625
    }
619 626
}
620

  
621