ACPI_STATUS AcpiEvaluateObject ( ACPI_HANDLE Handle, ACPI_STRING Pathname, ACPI_OBJECT_LIST *ExternalParams, ACPI_BUFFER *ReturnBuffer) { ACPI_STATUS Status; ACPI_EVALUATE_INFO *Info; ACPI_SIZE BufferSpaceNeeded; UINT32 i; ACPI_FUNCTION_TRACE (AcpiEvaluateObject); /* Allocate and initialize the evaluation information block */ Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); if (!Info) { return_ACPI_STATUS (AE_NO_MEMORY); } Info->Pathname = Pathname; /* Convert and validate the device handle */ Info->PrefixNode = AcpiNsValidateHandle (Handle); if (!Info->PrefixNode) { Status = AE_BAD_PARAMETER; goto Cleanup; } /* * If there are parameters to be passed to a control method, the external * objects must all be converted to internal objects */ if (ExternalParams && ExternalParams->Count) { /* * Allocate a new parameter block for the internal objects * Add 1 to count to allow for null terminated internal list */ Info->Parameters = ACPI_ALLOCATE_ZEROED ( ((ACPI_SIZE) ExternalParams->Count + 1) * sizeof (void *)); if (!Info->Parameters) { Status = AE_NO_MEMORY; goto Cleanup; } /* Convert each external object in the list to an internal object */ for (i = 0; i < ExternalParams->Count; i++) { Status = AcpiUtCopyEobjectToIobject ( &ExternalParams->Pointer[i], &Info->Parameters[i]); if (ACPI_FAILURE (Status)) { goto Cleanup; } } Info->Parameters[ExternalParams->Count] = NULL; } /* * Three major cases: * 1) Fully qualified pathname * 2) No handle, not fully qualified pathname (error) * 3) Valid handle */ if ((Pathname) && (AcpiNsValidRootPrefix (Pathname[0]))) { /* The path is fully qualified, just evaluate by name */ Info->PrefixNode = NULL; Status = AcpiNsEvaluate (Info); } else if (!Handle) { /* * A handle is optional iff a fully qualified pathname is specified. * Since we've already handled fully qualified names above, this is * an error */ if (!Pathname) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Both Handle and Pathname are NULL")); } else { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null Handle with relative pathname [%s]", Pathname)); } Status = AE_BAD_PARAMETER; } else { /* We have a namespace a node and a possible relative path */ Status = AcpiNsEvaluate (Info); } /* * If we are expecting a return value, and all went well above, * copy the return value to an external object. */ if (ReturnBuffer) { if (!Info->ReturnObject) { ReturnBuffer->Length = 0; } else { if (ACPI_GET_DESCRIPTOR_TYPE (Info->ReturnObject) == ACPI_DESC_TYPE_NAMED) { /* * If we received a NS Node as a return object, this means that * the object we are evaluating has nothing interesting to * return (such as a mutex, etc.) We return an error because * these types are essentially unsupported by this interface. * We don't check up front because this makes it easier to add * support for various types at a later date if necessary. */ Status = AE_TYPE; Info->ReturnObject = NULL; /* No need to delete a NS Node */ ReturnBuffer->Length = 0; } if (ACPI_SUCCESS (Status)) { /* Dereference Index and RefOf references */ AcpiNsResolveReferences (Info); /* Get the size of the returned object */ Status = AcpiUtGetObjectSize (Info->ReturnObject, &BufferSpaceNeeded); if (ACPI_SUCCESS (Status)) { /* Validate/Allocate/Clear caller buffer */ Status = AcpiUtInitializeBuffer (ReturnBuffer, BufferSpaceNeeded); if (ACPI_FAILURE (Status)) { /* * Caller's buffer is too small or a new one can't * be allocated */ ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Needed buffer size %X, %s\n", (UINT32) BufferSpaceNeeded, AcpiFormatException (Status))); } else { /* We have enough space for the object, build it */ Status = AcpiUtCopyIobjectToEobject (Info->ReturnObject, ReturnBuffer); } } } } } if (Info->ReturnObject) { /* * Delete the internal return object. NOTE: Interpreter must be * locked to avoid race condition. */ AcpiExEnterInterpreter (); /* Remove one reference on the return object (should delete it) */ AcpiUtRemoveReference (Info->ReturnObject); AcpiExExitInterpreter (); } Cleanup: /* Free the input parameter list (if we created one) */ if (Info->Parameters) { /* Free the allocated parameter block */ AcpiUtDeleteInternalObjectList (Info->Parameters); } ACPI_FREE (Info); return_ACPI_STATUS (Status); }
void AcpiNsGetInternalNameLength ( ACPI_NAMESTRING_INFO *Info) { const char *NextExternalChar; UINT32 i; ACPI_FUNCTION_ENTRY (); NextExternalChar = Info->ExternalName; Info->NumCarats = 0; Info->NumSegments = 0; Info->FullyQualified = FALSE; /* * For the internal name, the required length is 4 bytes per segment, plus * 1 each for RootPrefix, MultiNamePrefixOp, segment count, trailing null * (which is not really needed, but no there's harm in putting it there) * * strlen() + 1 covers the first NameSeg, which has no path separator */ if (AcpiNsValidRootPrefix (*NextExternalChar)) { Info->FullyQualified = TRUE; NextExternalChar++; /* Skip redundant RootPrefix, like \\_SB.PCI0.SBRG.EC0 */ while (AcpiNsValidRootPrefix (*NextExternalChar)) { NextExternalChar++; } } else { /* Handle Carat prefixes */ while (*NextExternalChar == '^') { Info->NumCarats++; NextExternalChar++; } } /* * Determine the number of ACPI name "segments" by counting the number of * path separators within the string. Start with one segment since the * segment count is [(# separators) + 1], and zero separators is ok. */ if (*NextExternalChar) { Info->NumSegments = 1; for (i = 0; NextExternalChar[i]; i++) { if (AcpiNsValidPathSeparator (NextExternalChar[i])) { Info->NumSegments++; } } } Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) + 4 + Info->NumCarats; Info->NextExternalChar = NextExternalChar; }
ACPI_STATUS AcpiGetHandle ( ACPI_HANDLE Parent, ACPI_STRING Pathname, ACPI_HANDLE *RetHandle) { ACPI_STATUS Status; ACPI_NAMESPACE_NODE *Node = NULL; ACPI_NAMESPACE_NODE *PrefixNode = NULL; ACPI_FUNCTION_ENTRY (); /* Parameter Validation */ if (!RetHandle || !Pathname) { return (AE_BAD_PARAMETER); } /* Convert a parent handle to a prefix node */ if (Parent) { PrefixNode = AcpiNsMapHandleToNode (Parent); if (!PrefixNode) { return (AE_BAD_PARAMETER); } } /* * Valid cases are: * 1) Fully qualified pathname * 2) Parent + Relative pathname * * Error for <null Parent + relative path> */ if (AcpiNsValidRootPrefix (Pathname[0])) { /* Pathname is fully qualified (starts with '\') */ /* Special case for root-only, since we can't search for it */ if (!ACPI_STRCMP (Pathname, ACPI_NS_ROOT_PATH)) { *RetHandle = AcpiNsConvertEntryToHandle (AcpiGbl_RootNode); return (AE_OK); } } else if (!PrefixNode) { /* Relative path with null prefix is disallowed */ return (AE_BAD_PARAMETER); } /* Find the Node and convert to a handle */ Status = AcpiNsGetNode (PrefixNode, Pathname, ACPI_NS_NO_UPSEARCH, &Node); if (ACPI_SUCCESS (Status)) { *RetHandle = AcpiNsConvertEntryToHandle (Node); } return (Status); }