ACPI_STATUS AcpiUtMutexInitialize ( void) { UINT32 i; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (UtMutexInitialize); /* Create each of the predefined mutex objects */ for (i = 0; i < ACPI_NUM_MUTEX; i++) { Status = AcpiUtCreateMutex (i); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* Create the spinlocks for use at interrupt level or for speed */ Status = AcpiOsCreateLock (&AcpiGbl_GpeLock); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiOsCreateLock (&AcpiGbl_HardwareLock); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiOsCreateLock (&AcpiGbl_ReferenceCountLock); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Mutex for _OSI support */ Status = AcpiOsCreateMutex (&AcpiGbl_OsiMutex); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Create the reader/writer lock for namespace access */ Status = AcpiUtCreateRwLock (&AcpiGbl_NamespaceRwLock); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } return_ACPI_STATUS (Status); }
static ACPI_STATUS AcpiDsCreateMethodMutex ( ACPI_OPERAND_OBJECT *MethodDesc) { ACPI_OPERAND_OBJECT *MutexDesc; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (DsCreateMethodMutex); /* Create the new mutex object */ MutexDesc = AcpiUtCreateInternalObject (ACPI_TYPE_MUTEX); if (!MutexDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Create the actual OS Mutex */ Status = AcpiOsCreateMutex (&MutexDesc->Mutex.OsMutex); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } MutexDesc->Mutex.SyncLevel = MethodDesc->Method.SyncLevel; MethodDesc->Method.Mutex = MutexDesc; return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiUtCreateRwLock ( ACPI_RW_LOCK *Lock) { ACPI_STATUS Status; Lock->NumReaders = 0; Status = AcpiOsCreateMutex (&Lock->ReaderMutex); if (ACPI_FAILURE (Status)) { return (Status); } Status = AcpiOsCreateMutex (&Lock->WriterMutex); return (Status); }
ACPI_STATUS AcpiOsInitializeDebugger ( void) { ACPI_STATUS Status; /* Create command signals */ Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandReady); if (ACPI_FAILURE (Status)) { return (Status); } Status = AcpiOsCreateMutex (&AcpiGbl_DbCommandComplete); if (ACPI_FAILURE (Status)) { goto ErrorReady; } /* Initialize the states of the command signals */ Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandComplete, ACPI_WAIT_FOREVER); if (ACPI_FAILURE (Status)) { goto ErrorComplete; } Status = AcpiOsAcquireMutex (AcpiGbl_DbCommandReady, ACPI_WAIT_FOREVER); if (ACPI_FAILURE (Status)) { goto ErrorComplete; } AcpiGbl_DbCommandSignalsInitialized = TRUE; return (Status); ErrorComplete: AcpiOsDeleteMutex (AcpiGbl_DbCommandComplete); ErrorReady: AcpiOsDeleteMutex (AcpiGbl_DbCommandReady); return (Status); }
static ACPI_STATUS AcpiUtCreateMutex ( ACPI_MUTEX_HANDLE MutexId) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE_U32 (UtCreateMutex, MutexId); if (!AcpiGbl_MutexInfo[MutexId].Mutex) { Status = AcpiOsCreateMutex (&AcpiGbl_MutexInfo[MutexId].Mutex); AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED; AcpiGbl_MutexInfo[MutexId].UseCount = 0; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiNsRootInitialize ( void) { ACPI_STATUS Status; const ACPI_PREDEFINED_NAMES *InitVal = NULL; ACPI_NAMESPACE_NODE *NewNode; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_STRING Val = NULL; ACPI_FUNCTION_TRACE (NsRootInitialize); Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * The global root ptr is initially NULL, so a non-NULL value indicates * that AcpiNsRootInitialize() has already been called; just return. */ if (AcpiGbl_RootNode) { Status = AE_OK; goto UnlockAndExit; } /* * Tell the rest of the subsystem that the root is initialized * (This is OK because the namespace is locked) */ AcpiGbl_RootNode = &AcpiGbl_RootNodeStruct; /* Enter the pre-defined names in the name table */ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Entering predefined entries into namespace\n")); for (InitVal = AcpiGbl_PreDefinedNames; InitVal->Name; InitVal++) { /* _OSI is optional for now, will be permanent later */ if (!strcmp (InitVal->Name, "_OSI") && !AcpiGbl_CreateOsiMethod) { continue; } Status = AcpiNsLookup (NULL, ACPI_CAST_PTR (char, InitVal->Name), InitVal->Type, ACPI_IMODE_LOAD_PASS2, ACPI_NS_NO_UPSEARCH, NULL, &NewNode); if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, Status, "Could not create predefined name %s", InitVal->Name)); continue; } /* * Name entered successfully. If entry in PreDefinedNames[] specifies * an initial value, create the initial value. */ if (InitVal->Val) { Status = AcpiOsPredefinedOverride (InitVal, &Val); if (ACPI_FAILURE (Status)) { ACPI_ERROR ((AE_INFO, "Could not override predefined %s", InitVal->Name)); } if (!Val) { Val = InitVal->Val; } /* * Entry requests an initial value, allocate a * descriptor for it. */ ObjDesc = AcpiUtCreateInternalObject (InitVal->Type); if (!ObjDesc) { Status = AE_NO_MEMORY; goto UnlockAndExit; } /* * Convert value string from table entry to * internal representation. Only types actually * used for initial values are implemented here. */ switch (InitVal->Type) { case ACPI_TYPE_METHOD: ObjDesc->Method.ParamCount = (UINT8) ACPI_TO_INTEGER (Val); ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID; #if defined (ACPI_ASL_COMPILER) /* Save the parameter count for the iASL compiler */ NewNode->Value = ObjDesc->Method.ParamCount; #else /* Mark this as a very SPECIAL method */ ObjDesc->Method.InfoFlags = ACPI_METHOD_INTERNAL_ONLY; ObjDesc->Method.Dispatch.Implementation = AcpiUtOsiImplementation; #endif break; case ACPI_TYPE_INTEGER: ObjDesc->Integer.Value = ACPI_TO_INTEGER (Val); break; case ACPI_TYPE_STRING: /* Build an object around the static string */ ObjDesc->String.Length = (UINT32) strlen (Val); ObjDesc->String.Pointer = Val; ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER; break; case ACPI_TYPE_MUTEX: ObjDesc->Mutex.Node = NewNode; ObjDesc->Mutex.SyncLevel = (UINT8) (ACPI_TO_INTEGER (Val) - 1); /* Create a mutex */ Status = AcpiOsCreateMutex (&ObjDesc->Mutex.OsMutex); if (ACPI_FAILURE (Status)) { AcpiUtRemoveReference (ObjDesc); goto UnlockAndExit; } /* Special case for ACPI Global Lock */ if (strcmp (InitVal->Name, "_GL_") == 0) { AcpiGbl_GlobalLockMutex = ObjDesc; /* Create additional counting semaphore for global lock */ Status = AcpiOsCreateSemaphore ( 1, 0, &AcpiGbl_GlobalLockSemaphore); if (ACPI_FAILURE (Status)) { AcpiUtRemoveReference (ObjDesc); goto UnlockAndExit; } } break; default: ACPI_ERROR ((AE_INFO, "Unsupported initial type value 0x%X", InitVal->Type)); AcpiUtRemoveReference (ObjDesc); ObjDesc = NULL; continue; } /* Store pointer to value descriptor in the Node */ Status = AcpiNsAttachObject (NewNode, ObjDesc, ObjDesc->Common.Type); /* Remove local reference to the object */ AcpiUtRemoveReference (ObjDesc); } } UnlockAndExit: (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); /* Save a handle to "_GPE", it is always present */ if (ACPI_SUCCESS (Status)) { Status = AcpiNsGetNode (NULL, "\\_GPE", ACPI_NS_NO_UPSEARCH, &AcpiGbl_FadtGpeDevice); } return_ACPI_STATUS (Status); }
static ACPI_STATUS AcpiUtCopySimpleObject ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *DestDesc) { UINT16 ReferenceCount; ACPI_OPERAND_OBJECT *NextObject; ACPI_STATUS Status; ACPI_SIZE CopySize; /* Save fields from destination that we don't want to overwrite */ ReferenceCount = DestDesc->Common.ReferenceCount; NextObject = DestDesc->Common.NextObject; /* * Copy the entire source object over the destination object. * Note: Source can be either an operand object or namespace node. */ CopySize = sizeof (ACPI_OPERAND_OBJECT); if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED) { CopySize = sizeof (ACPI_NAMESPACE_NODE); } ACPI_MEMCPY (ACPI_CAST_PTR (char, DestDesc), ACPI_CAST_PTR (char, SourceDesc), CopySize); /* Restore the saved fields */ DestDesc->Common.ReferenceCount = ReferenceCount; DestDesc->Common.NextObject = NextObject; /* New object is not static, regardless of source */ DestDesc->Common.Flags &= ~AOPOBJ_STATIC_POINTER; /* Handle the objects with extra data */ switch (DestDesc->Common.Type) { case ACPI_TYPE_BUFFER: /* * Allocate and copy the actual buffer if and only if: * 1) There is a valid buffer pointer * 2) The buffer has a length > 0 */ if ((SourceDesc->Buffer.Pointer) && (SourceDesc->Buffer.Length)) { DestDesc->Buffer.Pointer = ACPI_ALLOCATE (SourceDesc->Buffer.Length); if (!DestDesc->Buffer.Pointer) { return (AE_NO_MEMORY); } /* Copy the actual buffer data */ ACPI_MEMCPY (DestDesc->Buffer.Pointer, SourceDesc->Buffer.Pointer, SourceDesc->Buffer.Length); } break; case ACPI_TYPE_STRING: /* * Allocate and copy the actual string if and only if: * 1) There is a valid string pointer * (Pointer to a NULL string is allowed) */ if (SourceDesc->String.Pointer) { DestDesc->String.Pointer = ACPI_ALLOCATE ((ACPI_SIZE) SourceDesc->String.Length + 1); if (!DestDesc->String.Pointer) { return (AE_NO_MEMORY); } /* Copy the actual string data */ ACPI_MEMCPY (DestDesc->String.Pointer, SourceDesc->String.Pointer, (ACPI_SIZE) SourceDesc->String.Length + 1); } break; case ACPI_TYPE_LOCAL_REFERENCE: /* * We copied the reference object, so we now must add a reference * to the object pointed to by the reference * * DDBHandle reference (from Load/LoadTable) is a special reference, * it does not have a Reference.Object, so does not need to * increase the reference count */ if (SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE) { break; } AcpiUtAddReference (SourceDesc->Reference.Object); break; case ACPI_TYPE_REGION: /* * We copied the Region Handler, so we now must add a reference */ if (DestDesc->Region.Handler) { AcpiUtAddReference (DestDesc->Region.Handler); } break; /* * For Mutex and Event objects, we cannot simply copy the underlying * OS object. We must create a new one. */ case ACPI_TYPE_MUTEX: Status = AcpiOsCreateMutex (&DestDesc->Mutex.OsMutex); if (ACPI_FAILURE (Status)) { return (Status); } break; case ACPI_TYPE_EVENT: Status = AcpiOsCreateSemaphore (ACPI_NO_UNIT_LIMIT, 0, &DestDesc->Event.OsSemaphore); if (ACPI_FAILURE (Status)) { return (Status); } break; default: /* Nothing to do for other simple objects */ break; } return (AE_OK); }