Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:02

0001 /******************************************************************************
0002  *
0003  * Module Name: exmutex - ASL Mutex Acquire/Release functions
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acinterp.h"
0155 #include "acevents.h"
0156 
0157 #define _COMPONENT          ACPI_EXECUTER
0158         ACPI_MODULE_NAME    ("exmutex")
0159 
0160 /* Local prototypes */
0161 
0162 static void
0163 AcpiExLinkMutex (
0164     ACPI_OPERAND_OBJECT     *ObjDesc,
0165     ACPI_THREAD_STATE       *Thread);
0166 
0167 
0168 /*******************************************************************************
0169  *
0170  * FUNCTION:    AcpiExUnlinkMutex
0171  *
0172  * PARAMETERS:  ObjDesc             - The mutex to be unlinked
0173  *
0174  * RETURN:      None
0175  *
0176  * DESCRIPTION: Remove a mutex from the "AcquiredMutex" list
0177  *
0178  ******************************************************************************/
0179 
0180 void
0181 AcpiExUnlinkMutex (
0182     ACPI_OPERAND_OBJECT     *ObjDesc)
0183 {
0184     ACPI_THREAD_STATE       *Thread = ObjDesc->Mutex.OwnerThread;
0185 
0186 
0187     if (!Thread)
0188     {
0189         return;
0190     }
0191 
0192     /* Doubly linked list */
0193 
0194     if (ObjDesc->Mutex.Next)
0195     {
0196         (ObjDesc->Mutex.Next)->Mutex.Prev = ObjDesc->Mutex.Prev;
0197     }
0198 
0199     if (ObjDesc->Mutex.Prev)
0200     {
0201         (ObjDesc->Mutex.Prev)->Mutex.Next = ObjDesc->Mutex.Next;
0202 
0203         /*
0204          * Migrate the previous sync level associated with this mutex to
0205          * the previous mutex on the list so that it may be preserved.
0206          * This handles the case where several mutexes have been acquired
0207          * at the same level, but are not released in opposite order.
0208          */
0209         (ObjDesc->Mutex.Prev)->Mutex.OriginalSyncLevel =
0210             ObjDesc->Mutex.OriginalSyncLevel;
0211     }
0212     else
0213     {
0214         Thread->AcquiredMutexList = ObjDesc->Mutex.Next;
0215     }
0216 }
0217 
0218 
0219 /*******************************************************************************
0220  *
0221  * FUNCTION:    AcpiExLinkMutex
0222  *
0223  * PARAMETERS:  ObjDesc             - The mutex to be linked
0224  *              Thread              - Current executing thread object
0225  *
0226  * RETURN:      None
0227  *
0228  * DESCRIPTION: Add a mutex to the "AcquiredMutex" list for this walk
0229  *
0230  ******************************************************************************/
0231 
0232 static void
0233 AcpiExLinkMutex (
0234     ACPI_OPERAND_OBJECT     *ObjDesc,
0235     ACPI_THREAD_STATE       *Thread)
0236 {
0237     ACPI_OPERAND_OBJECT     *ListHead;
0238 
0239 
0240     ListHead = Thread->AcquiredMutexList;
0241 
0242     /* This object will be the first object in the list */
0243 
0244     ObjDesc->Mutex.Prev = NULL;
0245     ObjDesc->Mutex.Next = ListHead;
0246 
0247     /* Update old first object to point back to this object */
0248 
0249     if (ListHead)
0250     {
0251         ListHead->Mutex.Prev = ObjDesc;
0252     }
0253 
0254     /* Update list head */
0255 
0256     Thread->AcquiredMutexList = ObjDesc;
0257 }
0258 
0259 
0260 /*******************************************************************************
0261  *
0262  * FUNCTION:    AcpiExAcquireMutexObject
0263  *
0264  * PARAMETERS:  Timeout             - Timeout in milliseconds
0265  *              ObjDesc             - Mutex object
0266  *              ThreadId            - Current thread state
0267  *
0268  * RETURN:      Status
0269  *
0270  * DESCRIPTION: Acquire an AML mutex, low-level interface. Provides a common
0271  *              path that supports multiple acquires by the same thread.
0272  *
0273  * MUTEX:       Interpreter must be locked
0274  *
0275  * NOTE: This interface is called from three places:
0276  * 1) From AcpiExAcquireMutex, via an AML Acquire() operator
0277  * 2) From AcpiExAcquireGlobalLock when an AML Field access requires the
0278  *    global lock
0279  * 3) From the external interface, AcpiAcquireGlobalLock
0280  *
0281  ******************************************************************************/
0282 
0283 ACPI_STATUS
0284 AcpiExAcquireMutexObject (
0285     UINT16                  Timeout,
0286     ACPI_OPERAND_OBJECT     *ObjDesc,
0287     ACPI_THREAD_ID          ThreadId)
0288 {
0289     ACPI_STATUS             Status;
0290 
0291 
0292     ACPI_FUNCTION_TRACE_PTR (ExAcquireMutexObject, ObjDesc);
0293 
0294 
0295     if (!ObjDesc)
0296     {
0297         return_ACPI_STATUS (AE_BAD_PARAMETER);
0298     }
0299 
0300     /* Support for multiple acquires by the owning thread */
0301 
0302     if (ObjDesc->Mutex.ThreadId == ThreadId)
0303     {
0304         /*
0305          * The mutex is already owned by this thread, just increment the
0306          * acquisition depth
0307          */
0308         ObjDesc->Mutex.AcquisitionDepth++;
0309         return_ACPI_STATUS (AE_OK);
0310     }
0311 
0312     /* Acquire the mutex, wait if necessary. Special case for Global Lock */
0313 
0314     if (ObjDesc == AcpiGbl_GlobalLockMutex)
0315     {
0316         Status = AcpiEvAcquireGlobalLock (Timeout);
0317     }
0318     else
0319     {
0320         Status = AcpiExSystemWaitMutex (ObjDesc->Mutex.OsMutex, Timeout);
0321     }
0322 
0323     if (ACPI_FAILURE (Status))
0324     {
0325         /* Includes failure from a timeout on TimeDesc */
0326 
0327         return_ACPI_STATUS (Status);
0328     }
0329 
0330     /* Acquired the mutex: update mutex object */
0331 
0332     ObjDesc->Mutex.ThreadId = ThreadId;
0333     ObjDesc->Mutex.AcquisitionDepth = 1;
0334     ObjDesc->Mutex.OriginalSyncLevel = 0;
0335     ObjDesc->Mutex.OwnerThread = NULL;      /* Used only for AML Acquire() */
0336 
0337     return_ACPI_STATUS (AE_OK);
0338 }
0339 
0340 
0341 /*******************************************************************************
0342  *
0343  * FUNCTION:    AcpiExAcquireMutex
0344  *
0345  * PARAMETERS:  TimeDesc            - Timeout integer
0346  *              ObjDesc             - Mutex object
0347  *              WalkState           - Current method execution state
0348  *
0349  * RETURN:      Status
0350  *
0351  * DESCRIPTION: Acquire an AML mutex
0352  *
0353  ******************************************************************************/
0354 
0355 ACPI_STATUS
0356 AcpiExAcquireMutex (
0357     ACPI_OPERAND_OBJECT     *TimeDesc,
0358     ACPI_OPERAND_OBJECT     *ObjDesc,
0359     ACPI_WALK_STATE         *WalkState)
0360 {
0361     ACPI_STATUS             Status;
0362 
0363 
0364     ACPI_FUNCTION_TRACE_PTR (ExAcquireMutex, ObjDesc);
0365 
0366 
0367     if (!ObjDesc)
0368     {
0369         return_ACPI_STATUS (AE_BAD_PARAMETER);
0370     }
0371 
0372     /* Must have a valid thread state struct */
0373 
0374     if (!WalkState->Thread)
0375     {
0376         ACPI_ERROR ((AE_INFO,
0377             "Cannot acquire Mutex [%4.4s], null thread info",
0378             AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
0379         return_ACPI_STATUS (AE_AML_INTERNAL);
0380     }
0381 
0382     /*
0383      * Current sync level must be less than or equal to the sync level
0384      * of the mutex. This mechanism provides some deadlock prevention.
0385      */
0386     if (WalkState->Thread->CurrentSyncLevel > ObjDesc->Mutex.SyncLevel)
0387     {
0388         ACPI_ERROR ((AE_INFO,
0389             "Cannot acquire Mutex [%4.4s], "
0390             "current SyncLevel is too large (%u)",
0391             AcpiUtGetNodeName (ObjDesc->Mutex.Node),
0392             WalkState->Thread->CurrentSyncLevel));
0393         return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
0394     }
0395 
0396     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0397         "Acquiring: Mutex SyncLevel %u, Thread SyncLevel %u, "
0398         "Depth %u TID %p\n",
0399         ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel,
0400         ObjDesc->Mutex.AcquisitionDepth, WalkState->Thread));
0401 
0402     Status = AcpiExAcquireMutexObject ((UINT16) TimeDesc->Integer.Value,
0403         ObjDesc, WalkState->Thread->ThreadId);
0404 
0405     if (ACPI_SUCCESS (Status) && ObjDesc->Mutex.AcquisitionDepth == 1)
0406     {
0407         /* Save Thread object, original/current sync levels */
0408 
0409         ObjDesc->Mutex.OwnerThread = WalkState->Thread;
0410         ObjDesc->Mutex.OriginalSyncLevel =
0411             WalkState->Thread->CurrentSyncLevel;
0412         WalkState->Thread->CurrentSyncLevel =
0413             ObjDesc->Mutex.SyncLevel;
0414 
0415         /* Link the mutex to the current thread for force-unlock at method exit */
0416 
0417         AcpiExLinkMutex (ObjDesc, WalkState->Thread);
0418     }
0419 
0420     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0421         "Acquired: Mutex SyncLevel %u, Thread SyncLevel %u, Depth %u\n",
0422         ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel,
0423         ObjDesc->Mutex.AcquisitionDepth));
0424 
0425     return_ACPI_STATUS (Status);
0426 }
0427 
0428 
0429 /*******************************************************************************
0430  *
0431  * FUNCTION:    AcpiExReleaseMutexObject
0432  *
0433  * PARAMETERS:  ObjDesc             - The object descriptor for this op
0434  *
0435  * RETURN:      Status
0436  *
0437  * DESCRIPTION: Release a previously acquired Mutex, low level interface.
0438  *              Provides a common path that supports multiple releases (after
0439  *              previous multiple acquires) by the same thread.
0440  *
0441  * MUTEX:       Interpreter must be locked
0442  *
0443  * NOTE: This interface is called from three places:
0444  * 1) From AcpiExReleaseMutex, via an AML Acquire() operator
0445  * 2) From AcpiExReleaseGlobalLock when an AML Field access requires the
0446  *    global lock
0447  * 3) From the external interface, AcpiReleaseGlobalLock
0448  *
0449  ******************************************************************************/
0450 
0451 ACPI_STATUS
0452 AcpiExReleaseMutexObject (
0453     ACPI_OPERAND_OBJECT     *ObjDesc)
0454 {
0455     ACPI_STATUS             Status = AE_OK;
0456 
0457 
0458     ACPI_FUNCTION_TRACE (ExReleaseMutexObject);
0459 
0460 
0461     if (ObjDesc->Mutex.AcquisitionDepth == 0)
0462     {
0463         return_ACPI_STATUS (AE_NOT_ACQUIRED);
0464     }
0465 
0466     /* Match multiple Acquires with multiple Releases */
0467 
0468     ObjDesc->Mutex.AcquisitionDepth--;
0469     if (ObjDesc->Mutex.AcquisitionDepth != 0)
0470     {
0471         /* Just decrement the depth and return */
0472 
0473         return_ACPI_STATUS (AE_OK);
0474     }
0475 
0476     if (ObjDesc->Mutex.OwnerThread)
0477     {
0478         /* Unlink the mutex from the owner's list */
0479 
0480         AcpiExUnlinkMutex (ObjDesc);
0481         ObjDesc->Mutex.OwnerThread = NULL;
0482     }
0483 
0484     /* Release the mutex, special case for Global Lock */
0485 
0486     if (ObjDesc == AcpiGbl_GlobalLockMutex)
0487     {
0488         Status = AcpiEvReleaseGlobalLock ();
0489     }
0490     else
0491     {
0492         AcpiOsReleaseMutex (ObjDesc->Mutex.OsMutex);
0493     }
0494 
0495     /* Clear mutex info */
0496 
0497     ObjDesc->Mutex.ThreadId = 0;
0498     return_ACPI_STATUS (Status);
0499 }
0500 
0501 
0502 /*******************************************************************************
0503  *
0504  * FUNCTION:    AcpiExReleaseMutex
0505  *
0506  * PARAMETERS:  ObjDesc             - The object descriptor for this op
0507  *              WalkState           - Current method execution state
0508  *
0509  * RETURN:      Status
0510  *
0511  * DESCRIPTION: Release a previously acquired Mutex.
0512  *
0513  ******************************************************************************/
0514 
0515 ACPI_STATUS
0516 AcpiExReleaseMutex (
0517     ACPI_OPERAND_OBJECT     *ObjDesc,
0518     ACPI_WALK_STATE         *WalkState)
0519 {
0520     UINT8                   PreviousSyncLevel;
0521     ACPI_THREAD_STATE       *OwnerThread;
0522     ACPI_STATUS             Status = AE_OK;
0523 
0524 
0525     ACPI_FUNCTION_TRACE (ExReleaseMutex);
0526 
0527 
0528     if (!ObjDesc)
0529     {
0530         return_ACPI_STATUS (AE_BAD_PARAMETER);
0531     }
0532 
0533     OwnerThread = ObjDesc->Mutex.OwnerThread;
0534 
0535     /* The mutex must have been previously acquired in order to release it */
0536 
0537     if (!OwnerThread)
0538     {
0539         ACPI_ERROR ((AE_INFO,
0540             "Cannot release Mutex [%4.4s], not acquired",
0541             AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
0542         return_ACPI_STATUS (AE_AML_MUTEX_NOT_ACQUIRED);
0543     }
0544 
0545     /* Must have a valid thread ID */
0546 
0547     if (!WalkState->Thread)
0548     {
0549         ACPI_ERROR ((AE_INFO,
0550             "Cannot release Mutex [%4.4s], null thread info",
0551             AcpiUtGetNodeName (ObjDesc->Mutex.Node)));
0552         return_ACPI_STATUS (AE_AML_INTERNAL);
0553     }
0554 
0555     /*
0556      * The Mutex is owned, but this thread must be the owner.
0557      * Special case for Global Lock, any thread can release
0558      */
0559     if ((OwnerThread->ThreadId != WalkState->Thread->ThreadId) &&
0560         (ObjDesc != AcpiGbl_GlobalLockMutex))
0561     {
0562         ACPI_ERROR ((AE_INFO,
0563             "Thread %u cannot release Mutex [%4.4s] acquired by thread %u",
0564             (UINT32) WalkState->Thread->ThreadId,
0565             AcpiUtGetNodeName (ObjDesc->Mutex.Node),
0566             (UINT32) OwnerThread->ThreadId));
0567         return_ACPI_STATUS (AE_AML_NOT_OWNER);
0568     }
0569 
0570     /*
0571      * The sync level of the mutex must be equal to the current sync level. In
0572      * other words, the current level means that at least one mutex at that
0573      * level is currently being held. Attempting to release a mutex of a
0574      * different level can only mean that the mutex ordering rule is being
0575      * violated. This behavior is clarified in ACPI 4.0 specification.
0576      */
0577     if (ObjDesc->Mutex.SyncLevel != OwnerThread->CurrentSyncLevel)
0578     {
0579         ACPI_ERROR ((AE_INFO,
0580             "Cannot release Mutex [%4.4s], SyncLevel mismatch: "
0581             "mutex %u current %u",
0582             AcpiUtGetNodeName (ObjDesc->Mutex.Node),
0583             ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel));
0584         return_ACPI_STATUS (AE_AML_MUTEX_ORDER);
0585     }
0586 
0587     /*
0588      * Get the previous SyncLevel from the head of the acquired mutex list.
0589      * This handles the case where several mutexes at the same level have been
0590      * acquired, but are not released in reverse order.
0591      */
0592     PreviousSyncLevel =
0593         OwnerThread->AcquiredMutexList->Mutex.OriginalSyncLevel;
0594 
0595     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0596         "Releasing: Object SyncLevel %u, Thread SyncLevel %u, "
0597         "Prev SyncLevel %u, Depth %u TID %p\n",
0598         ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel,
0599         PreviousSyncLevel, ObjDesc->Mutex.AcquisitionDepth,
0600         WalkState->Thread));
0601 
0602     Status = AcpiExReleaseMutexObject (ObjDesc);
0603     if (ACPI_FAILURE (Status))
0604     {
0605         return_ACPI_STATUS (Status);
0606     }
0607 
0608     if (ObjDesc->Mutex.AcquisitionDepth == 0)
0609     {
0610         /* Restore the previous SyncLevel */
0611 
0612         OwnerThread->CurrentSyncLevel = PreviousSyncLevel;
0613     }
0614 
0615     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0616         "Released: Object SyncLevel %u, Thread SyncLevel, %u, "
0617         "Prev SyncLevel %u, Depth %u\n",
0618         ObjDesc->Mutex.SyncLevel, WalkState->Thread->CurrentSyncLevel,
0619         PreviousSyncLevel, ObjDesc->Mutex.AcquisitionDepth));
0620 
0621     return_ACPI_STATUS (Status);
0622 }
0623 
0624 
0625 /*******************************************************************************
0626  *
0627  * FUNCTION:    AcpiExReleaseAllMutexes
0628  *
0629  * PARAMETERS:  Thread              - Current executing thread object
0630  *
0631  * RETURN:      Status
0632  *
0633  * DESCRIPTION: Release all mutexes held by this thread
0634  *
0635  * NOTE: This function is called as the thread is exiting the interpreter.
0636  * Mutexes are not released when an individual control method is exited, but
0637  * only when the parent thread actually exits the interpreter. This allows one
0638  * method to acquire a mutex, and a different method to release it, as long as
0639  * this is performed underneath a single parent control method.
0640  *
0641  ******************************************************************************/
0642 
0643 void
0644 AcpiExReleaseAllMutexes (
0645     ACPI_THREAD_STATE       *Thread)
0646 {
0647     ACPI_OPERAND_OBJECT     *Next = Thread->AcquiredMutexList;
0648     ACPI_OPERAND_OBJECT     *ObjDesc;
0649 
0650 
0651     ACPI_FUNCTION_TRACE (ExReleaseAllMutexes);
0652 
0653 
0654     /* Traverse the list of owned mutexes, releasing each one */
0655 
0656     while (Next)
0657     {
0658         ObjDesc = Next;
0659         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0660             "Mutex [%4.4s] force-release, SyncLevel %u Depth %u\n",
0661             ObjDesc->Mutex.Node->Name.Ascii, ObjDesc->Mutex.SyncLevel,
0662             ObjDesc->Mutex.AcquisitionDepth));
0663 
0664         /* Release the mutex, special case for Global Lock */
0665 
0666         if (ObjDesc == AcpiGbl_GlobalLockMutex)
0667         {
0668             /* Ignore errors */
0669 
0670             (void) AcpiEvReleaseGlobalLock ();
0671         }
0672         else
0673         {
0674             AcpiOsReleaseMutex (ObjDesc->Mutex.OsMutex);
0675         }
0676 
0677         /* Update Thread SyncLevel (Last mutex is the important one) */
0678 
0679         Thread->CurrentSyncLevel = ObjDesc->Mutex.OriginalSyncLevel;
0680 
0681         /* Mark mutex unowned */
0682 
0683         Next = ObjDesc->Mutex.Next;
0684 
0685         ObjDesc->Mutex.Prev = NULL;
0686         ObjDesc->Mutex.Next = NULL;
0687         ObjDesc->Mutex.AcquisitionDepth = 0;
0688         ObjDesc->Mutex.OwnerThread = NULL;
0689         ObjDesc->Mutex.ThreadId = 0;
0690     }
0691 
0692     return_VOID;
0693 }