ACPI_STATUS AcpiExReleaseMutexObject ( ACPI_OPERAND_OBJECT *ObjDesc) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE (ExReleaseMutexObject); if (ObjDesc->Mutex.AcquisitionDepth == 0) { return_ACPI_STATUS (AE_NOT_ACQUIRED); } /* Match multiple Acquires with multiple Releases */ ObjDesc->Mutex.AcquisitionDepth--; if (ObjDesc->Mutex.AcquisitionDepth != 0) { /* Just decrement the depth and return */ return_ACPI_STATUS (AE_OK); } if (ObjDesc->Mutex.OwnerThread) { /* Unlink the mutex from the owner's list */ AcpiExUnlinkMutex (ObjDesc); ObjDesc->Mutex.OwnerThread = NULL; } /* Release the mutex, special case for Global Lock */ if (ObjDesc == AcpiGbl_GlobalLockMutex) { Status = AcpiEvReleaseGlobalLock (); } else { AcpiOsReleaseMutex (ObjDesc->Mutex.OsMutex); } /* Clear mutex info */ ObjDesc->Mutex.ThreadId = 0; return_ACPI_STATUS (Status); }
static void AcpiUtDeleteInternalObj ( ACPI_OPERAND_OBJECT *Object) { void *ObjPointer = NULL; ACPI_OPERAND_OBJECT *HandlerDesc; ACPI_OPERAND_OBJECT *SecondDesc; ACPI_OPERAND_OBJECT *NextDesc; ACPI_OPERAND_OBJECT *StartDesc; ACPI_OPERAND_OBJECT **LastObjPtr; ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object); if (!Object) { return_VOID; } /* * Must delete or free any pointers within the object that are not * actual ACPI objects (for example, a raw buffer pointer). */ switch (Object->Common.Type) { case ACPI_TYPE_STRING: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n", Object, Object->String.Pointer)); /* Free the actual string buffer */ if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ ObjPointer = Object->String.Pointer; } break; case ACPI_TYPE_BUFFER: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n", Object, Object->Buffer.Pointer)); /* Free the actual buffer */ if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ ObjPointer = Object->Buffer.Pointer; } break; case ACPI_TYPE_PACKAGE: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n", Object->Package.Count)); /* * Elements of the package are not handled here, they are deleted * separately */ /* Free the (variable length) element pointer array */ ObjPointer = Object->Package.Elements; break; /* * These objects have a possible list of notify handlers. * Device object also may have a GPE block. */ case ACPI_TYPE_DEVICE: if (Object->Device.GpeBlock) { (void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock); } /*lint -fallthrough */ case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: /* Walk the address handler list for this object */ HandlerDesc = Object->CommonNotify.Handler; while (HandlerDesc) { NextDesc = HandlerDesc->AddressSpace.Next; AcpiUtRemoveReference (HandlerDesc); HandlerDesc = NextDesc; } break; case ACPI_TYPE_MUTEX: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Mutex %p, OS Mutex %p\n", Object, Object->Mutex.OsMutex)); if (Object == AcpiGbl_GlobalLockMutex) { /* Global Lock has extra semaphore */ (void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore); AcpiGbl_GlobalLockSemaphore = NULL; AcpiOsDeleteMutex (Object->Mutex.OsMutex); AcpiGbl_GlobalLockMutex = NULL; } else { AcpiExUnlinkMutex (Object); AcpiOsDeleteMutex (Object->Mutex.OsMutex); } break; case ACPI_TYPE_EVENT: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Event %p, OS Semaphore %p\n", Object, Object->Event.OsSemaphore)); (void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore); Object->Event.OsSemaphore = NULL; break; case ACPI_TYPE_METHOD: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Method %p\n", Object)); /* Delete the method mutex if it exists */ if (Object->Method.Mutex) { AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex); AcpiUtDeleteObjectDesc (Object->Method.Mutex); Object->Method.Mutex = NULL; } break; case ACPI_TYPE_REGION: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Region %p\n", Object)); /* * Update AddressRange list. However, only permanent regions * are installed in this list. (Not created within a method) */ if (!(Object->Region.Node->Flags & ANOBJ_TEMPORARY)) { AcpiUtRemoveAddressRange (Object->Region.SpaceId, Object->Region.Node); } SecondDesc = AcpiNsGetSecondaryObject (Object); if (SecondDesc) { /* * Free the RegionContext if and only if the handler is one of the * default handlers -- and therefore, we created the context object * locally, it was not created by an external caller. */ HandlerDesc = Object->Region.Handler; if (HandlerDesc) { NextDesc = HandlerDesc->AddressSpace.RegionList; StartDesc = NextDesc; LastObjPtr = &HandlerDesc->AddressSpace.RegionList; /* Remove the region object from the handler list */ while (NextDesc) { if (NextDesc == Object) { *LastObjPtr = NextDesc->Region.Next; break; } /* Walk the linked list of handlers */ LastObjPtr = &NextDesc->Region.Next; NextDesc = NextDesc->Region.Next; /* Prevent infinite loop if list is corrupted */ if (NextDesc == StartDesc) { ACPI_ERROR ((AE_INFO, "Circular region list in address handler object %p", HandlerDesc)); return_VOID; } } if (HandlerDesc->AddressSpace.HandlerFlags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) { /* Deactivate region and free region context */ if (HandlerDesc->AddressSpace.Setup) { (void) HandlerDesc->AddressSpace.Setup (Object, ACPI_REGION_DEACTIVATE, HandlerDesc->AddressSpace.Context, &SecondDesc->Extra.RegionContext); } } AcpiUtRemoveReference (HandlerDesc); } /* Now we can free the Extra object */ AcpiUtDeleteObjectDesc (SecondDesc); } break; case ACPI_TYPE_BUFFER_FIELD: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", Object)); SecondDesc = AcpiNsGetSecondaryObject (Object); if (SecondDesc) { AcpiUtDeleteObjectDesc (SecondDesc); } break; case ACPI_TYPE_LOCAL_BANK_FIELD: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Bank Field %p\n", Object)); SecondDesc = AcpiNsGetSecondaryObject (Object); if (SecondDesc) { AcpiUtDeleteObjectDesc (SecondDesc); } break; default: break; } /* Free any allocated memory (pointer within the object) found above */ if (ObjPointer) { ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n", ObjPointer)); ACPI_FREE (ObjPointer); } /* Now the object can be safely deleted */ ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n", Object, AcpiUtGetObjectTypeName (Object))); AcpiUtDeleteObjectDesc (Object); return_VOID; }
static void AcpiUtDeleteInternalObj ( ACPI_OPERAND_OBJECT *Object) { void *ObjPointer = NULL; ACPI_OPERAND_OBJECT *HandlerDesc; ACPI_OPERAND_OBJECT *SecondDesc; ACPI_OPERAND_OBJECT *NextDesc; ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object); if (!Object) { return_VOID; } /* * Must delete or free any pointers within the object that are not * actual ACPI objects (for example, a raw buffer pointer). */ switch (ACPI_GET_OBJECT_TYPE (Object)) { case ACPI_TYPE_STRING: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n", Object, Object->String.Pointer)); /* Free the actual string buffer */ if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ ObjPointer = Object->String.Pointer; } break; case ACPI_TYPE_BUFFER: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n", Object, Object->Buffer.Pointer)); /* Free the actual buffer */ if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER)) { /* But only if it is NOT a pointer into an ACPI table */ ObjPointer = Object->Buffer.Pointer; } break; case ACPI_TYPE_PACKAGE: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n", Object->Package.Count)); /* * Elements of the package are not handled here, they are deleted * separately */ /* Free the (variable length) element pointer array */ ObjPointer = Object->Package.Elements; break; case ACPI_TYPE_DEVICE: if (Object->Device.GpeBlock) { (void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock); } /* Walk the handler list for this device */ HandlerDesc = Object->Device.Handler; while (HandlerDesc) { NextDesc = HandlerDesc->AddressSpace.Next; AcpiUtRemoveReference (HandlerDesc); HandlerDesc = NextDesc; } break; case ACPI_TYPE_MUTEX: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Mutex %p, OS Mutex %p\n", Object, Object->Mutex.OsMutex)); if (Object == AcpiGbl_GlobalLockMutex) { /* Global Lock has extra semaphore */ (void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore); AcpiGbl_GlobalLockSemaphore = NULL; AcpiOsDeleteMutex (Object->Mutex.OsMutex); AcpiGbl_GlobalLockMutex = NULL; } else { AcpiExUnlinkMutex (Object); AcpiOsDeleteMutex (Object->Mutex.OsMutex); } break; case ACPI_TYPE_EVENT: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Event %p, OS Semaphore %p\n", Object, Object->Event.OsSemaphore)); (void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore); Object->Event.OsSemaphore = NULL; break; case ACPI_TYPE_METHOD: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Method %p\n", Object)); /* Delete the method mutex if it exists */ if (Object->Method.Mutex) { AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex); AcpiUtDeleteObjectDesc (Object->Method.Mutex); Object->Method.Mutex = NULL; } break; case ACPI_TYPE_REGION: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Region %p\n", Object)); SecondDesc = AcpiNsGetSecondaryObject (Object); if (SecondDesc) { /* * Free the RegionContext if and only if the handler is one of the * default handlers -- and therefore, we created the context object * locally, it was not created by an external caller. */ HandlerDesc = Object->Region.Handler; if (HandlerDesc) { if (HandlerDesc->AddressSpace.HandlerFlags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) { /* Deactivate region and free region context */ if (HandlerDesc->AddressSpace.Setup) { (void) HandlerDesc->AddressSpace.Setup (Object, ACPI_REGION_DEACTIVATE, HandlerDesc->AddressSpace.Context, &SecondDesc->Extra.RegionContext); } } AcpiUtRemoveReference (HandlerDesc); } /* Now we can free the Extra object */ AcpiUtDeleteObjectDesc (SecondDesc); } break; case ACPI_TYPE_BUFFER_FIELD: ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", Object)); SecondDesc = AcpiNsGetSecondaryObject (Object); if (SecondDesc) { AcpiUtDeleteObjectDesc (SecondDesc); } break; default: break; } /* Free any allocated memory (pointer within the object) found above */ if (ObjPointer) { ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n", ObjPointer)); ACPI_FREE (ObjPointer); } /* Now the object can be safely deleted */ ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n", Object, AcpiUtGetObjectTypeName (Object))); AcpiUtDeleteObjectDesc (Object); return_VOID; }
ACPI_STATUS AcpiExReleaseMutex ( ACPI_OPERAND_OBJECT *ObjDesc, ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE (ExReleaseMutex); if (!ObjDesc) { return_ACPI_STATUS (AE_BAD_PARAMETER); } /* The mutex must have been previously acquired in order to release it */ if (!ObjDesc->Mutex.OwnerThread) { ACPI_ERROR ((AE_INFO, "Cannot release Mutex [%4.4s], not acquired", AcpiUtGetNodeName (ObjDesc->Mutex.Node))); return_ACPI_STATUS (AE_AML_MUTEX_NOT_ACQUIRED); } /* Sanity check: we must have a valid thread ID */ if (!WalkState->Thread) { ACPI_ERROR ((AE_INFO, "Cannot release Mutex [%4.4s], null thread info", AcpiUtGetNodeName (ObjDesc->Mutex.Node))); return_ACPI_STATUS (AE_AML_INTERNAL); } /* * The Mutex is owned, but this thread must be the owner. * Special case for Global Lock, any thread can release */ if ((ObjDesc->Mutex.OwnerThread->ThreadId != WalkState->Thread->ThreadId) && (ObjDesc->Mutex.OsMutex != AcpiGbl_GlobalLockMutex)) { ACPI_ERROR ((AE_INFO, "Thread %X cannot release Mutex [%4.4s] acquired by thread %X", WalkState->Thread->ThreadId, AcpiUtGetNodeName (ObjDesc->Mutex.Node), ObjDesc->Mutex.OwnerThread->ThreadId)); return_ACPI_STATUS (AE_AML_NOT_OWNER); } /* * The sync level of the mutex must be less than or equal to the current * sync level */ if (ObjDesc->Mutex.SyncLevel > WalkState->Thread->CurrentSyncLevel) { ACPI_ERROR ((AE_INFO, "Cannot release Mutex [%4.4s], incorrect SyncLevel", AcpiUtGetNodeName (ObjDesc->Mutex.Node))); return_ACPI_STATUS (AE_AML_MUTEX_ORDER); } /* Match multiple Acquires with multiple Releases */ ObjDesc->Mutex.AcquisitionDepth--; if (ObjDesc->Mutex.AcquisitionDepth != 0) { /* Just decrement the depth and return */ return_ACPI_STATUS (AE_OK); } /* Unlink the mutex from the owner's list */ AcpiExUnlinkMutex (ObjDesc); /* Release the mutex, special case for Global Lock */ if (ObjDesc->Mutex.OsMutex == AcpiGbl_GlobalLockMutex) { Status = AcpiEvReleaseGlobalLock (); } else { AcpiOsReleaseMutex (ObjDesc->Mutex.OsMutex); } /* Update the mutex and restore SyncLevel */ ObjDesc->Mutex.OwnerThread = NULL; WalkState->Thread->CurrentSyncLevel = ObjDesc->Mutex.OriginalSyncLevel; return_ACPI_STATUS (Status); }