ACPI_STATUS AcpiNsConvertToInteger ( ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject) { ACPI_OPERAND_OBJECT *NewObject; ACPI_STATUS Status; UINT64 Value = 0; UINT32 i; switch (OriginalObject->Common.Type) { case ACPI_TYPE_STRING: /* String-to-Integer conversion */ Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer, ACPI_ANY_BASE, AcpiGbl_IntegerByteWidth, &Value); if (ACPI_FAILURE (Status)) { return (Status); } break; case ACPI_TYPE_BUFFER: /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */ if (OriginalObject->Buffer.Length > 8) { return (AE_AML_OPERAND_TYPE); } /* Extract each buffer byte to create the integer */ for (i = 0; i < OriginalObject->Buffer.Length; i++) { Value |= ((UINT64) OriginalObject->Buffer.Pointer[i] << (i * 8)); } break; default: return (AE_AML_OPERAND_TYPE); } NewObject = AcpiUtCreateIntegerObject (Value); if (!NewObject) { return (AE_NO_MEMORY); } *ReturnObject = NewObject; return (AE_OK); }
ACPI_STATUS AcpiExOpcode_0A_0T_1R ( ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *ReturnDesc = NULL; ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R, AcpiPsGetOpcodeName (WalkState->Opcode)); /* Examine the AML opcode */ switch (WalkState->Opcode) { case AML_TIMER_OP: /* Timer () */ /* Create a return object of type Integer */ ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ()); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } break; default: /* Unknown opcode */ ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", WalkState->Opcode)); Status = AE_AML_BAD_OPCODE; break; } Cleanup: /* Delete return object on error */ if ((ACPI_FAILURE (Status)) || WalkState->ResultObj) { AcpiUtRemoveReference (ReturnDesc); WalkState->ResultObj = NULL; } else { /* Save the return value */ WalkState->ResultObj = ReturnDesc; } return_ACPI_STATUS (Status); }
static ACPI_STATUS AcpiNsConvertToPackage ( ACPI_OPERAND_OBJECT *OriginalObject, ACPI_OPERAND_OBJECT **ReturnObject) { ACPI_OPERAND_OBJECT *NewObject; ACPI_OPERAND_OBJECT **Elements; UINT32 Length; UINT8 *Buffer; switch (OriginalObject->Common.Type) { case ACPI_TYPE_BUFFER: /* Buffer-to-Package conversion */ Length = OriginalObject->Buffer.Length; NewObject = AcpiUtCreatePackageObject (Length); if (!NewObject) { return (AE_NO_MEMORY); } /* Convert each buffer byte to an integer package element */ Elements = NewObject->Package.Elements; Buffer = OriginalObject->Buffer.Pointer; while (Length--) { *Elements = AcpiUtCreateIntegerObject ((UINT64) *Buffer); if (!*Elements) { AcpiUtRemoveReference (NewObject); return (AE_NO_MEMORY); } Elements++; Buffer++; } break; default: return (AE_AML_OPERAND_TYPE); } *ReturnObject = NewObject; return (AE_OK); }
void AeDoObjectOverrides ( void) { ACPI_OPERAND_OBJECT *ObjDesc; ACPI_WALK_STATE *WalkState; int i; if (!InitFile) { return; } /* Create needed objects to be reused for each init entry */ ObjDesc = AcpiUtCreateIntegerObject (0); WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); NameBuffer[0] = '\\'; /* Read the entire file line-by-line */ while (fgets (LineBuffer, AE_FILE_BUFFER_SIZE, InitFile) != NULL) { if (sscanf (LineBuffer, "%s %s\n", &NameBuffer[1], ValueBuffer) != 2) { goto CleanupAndExit; } /* Add a root prefix if not present in the string */ i = 0; if (NameBuffer[1] == '\\') { i = 1; } AeDoOneOverride (&NameBuffer[i], ValueBuffer, ObjDesc, WalkState); } /* Cleanup */ CleanupAndExit: fclose (InitFile); AcpiDsDeleteWalkState (WalkState); AcpiUtRemoveReference (ObjDesc); }
ACPI_STATUS AcpiExOpcode_6A_0T_1R ( ACPI_WALK_STATE *WalkState) { ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; ACPI_OPERAND_OBJECT *ReturnDesc = NULL; ACPI_STATUS Status = AE_OK; UINT64 Index; ACPI_OPERAND_OBJECT *ThisElement; ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R, AcpiPsGetOpcodeName (WalkState->Opcode)); switch (WalkState->Opcode) { case AML_MATCH_OP: /* * Match (SearchPkg[0], MatchOp1[1], MatchObj1[2], * MatchOp2[3], MatchObj2[4], StartIndex[5]) */ /* Validate both Match Term Operators (MTR, MEQ, etc.) */ if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) || (Operand[3]->Integer.Value > MAX_MATCH_OPERATOR)) { ACPI_ERROR ((AE_INFO, "Match operator out of range")); Status = AE_AML_OPERAND_VALUE; goto Cleanup; } /* Get the package StartIndex, validate against the package length */ Index = Operand[5]->Integer.Value; if (Index >= Operand[0]->Package.Count) { ACPI_ERROR ((AE_INFO, "Index (0x%8.8X%8.8X) beyond package end (0x%X)", ACPI_FORMAT_UINT64 (Index), Operand[0]->Package.Count)); Status = AE_AML_PACKAGE_LIMIT; goto Cleanup; } /* Create an integer for the return value */ /* Default return value is ACPI_UINT64_MAX if no match found */ ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } /* * Examine each element until a match is found. Both match conditions * must be satisfied for a match to occur. Within the loop, * "continue" signifies that the current element does not match * and the next should be examined. * * Upon finding a match, the loop will terminate via "break" at * the bottom. If it terminates "normally", MatchValue will be * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no * match was found. */ for ( ; Index < Operand[0]->Package.Count; Index++) { /* Get the current package element */ ThisElement = Operand[0]->Package.Elements[Index]; /* Treat any uninitialized (NULL) elements as non-matching */ if (!ThisElement) { continue; } /* * Both match conditions must be satisfied. Execution of a continue * (proceed to next iteration of enclosing for loop) signifies a * non-match. */ if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value, ThisElement, Operand[2])) { continue; } if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value, ThisElement, Operand[4])) { continue; } /* Match found: Index is the return value */ ReturnDesc->Integer.Value = Index; break; } break; case AML_LOAD_TABLE_OP: Status = AcpiExLoadTableOp (WalkState, &ReturnDesc); break; default: ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", WalkState->Opcode)); Status = AE_AML_BAD_OPCODE; goto Cleanup; } Cleanup: /* Delete return object on error */ if (ACPI_FAILURE (Status)) { AcpiUtRemoveReference (ReturnDesc); } /* Save return object on success */ else { WalkState->ResultObj = ReturnDesc; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExOpcode_1A_0T_1R ( ACPI_WALK_STATE *WalkState) { ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; ACPI_OPERAND_OBJECT *TempDesc; ACPI_OPERAND_OBJECT *ReturnDesc = NULL; ACPI_STATUS Status = AE_OK; UINT32 Type; UINT64 Value; ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R, AcpiPsGetOpcodeName (WalkState->Opcode)); /* Examine the AML opcode */ switch (WalkState->Opcode) { case AML_LNOT_OP: /* LNot (Operand) */ ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } /* * Set result to ONES (TRUE) if Value == 0. Note: * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above. */ if (!Operand[0]->Integer.Value) { ReturnDesc->Integer.Value = ACPI_UINT64_MAX; } break; case AML_DECREMENT_OP: /* Decrement (Operand) */ case AML_INCREMENT_OP: /* Increment (Operand) */ /* * Create a new integer. Can't just get the base integer and * increment it because it may be an Arg or Field. */ ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } /* * Since we are expecting a Reference operand, it can be either a * NS Node or an internal object. */ TempDesc = Operand[0]; if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND) { /* Internal reference object - prevent deletion */ AcpiUtAddReference (TempDesc); } /* * Convert the Reference operand to an Integer (This removes a * reference on the Operand[0] object) * * NOTE: We use LNOT_OP here in order to force resolution of the * reference operand to an actual integer. */ Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState); if (ACPI_FAILURE (Status)) { ACPI_EXCEPTION ((AE_INFO, Status, "While resolving operands for [%s]", AcpiPsGetOpcodeName (WalkState->Opcode))); goto Cleanup; } /* * TempDesc is now guaranteed to be an Integer object -- * Perform the actual increment or decrement */ if (WalkState->Opcode == AML_INCREMENT_OP) { ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1; } else { ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1; } /* Finished with this Integer object */ AcpiUtRemoveReference (TempDesc); /* * Store the result back (indirectly) through the original * Reference object */ Status = AcpiExStore (ReturnDesc, Operand[0], WalkState); break; case AML_OBJECT_TYPE_OP: /* ObjectType (SourceObject) */ /* * Note: The operand is not resolved at this point because we want to * get the associated object, not its value. For example, we don't * want to resolve a FieldUnit to its value, we want the actual * FieldUnit object. */ /* Get the type of the base object */ Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL); if (ACPI_FAILURE (Status)) { goto Cleanup; } /* Allocate a descriptor to hold the type. */ ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } break; case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */ /* * Note: The operand is not resolved at this point because we want to * get the associated object, not its value. */ /* Get the base object */ Status = AcpiExResolveMultiple ( WalkState, Operand[0], &Type, &TempDesc); if (ACPI_FAILURE (Status)) { goto Cleanup; } /* * The type of the base object must be integer, buffer, string, or * package. All others are not supported. * * NOTE: Integer is not specifically supported by the ACPI spec, * but is supported implicitly via implicit operand conversion. * rather than bother with conversion, we just use the byte width * global (4 or 8 bytes). */ switch (Type) { case ACPI_TYPE_INTEGER: Value = AcpiGbl_IntegerByteWidth; break; case ACPI_TYPE_STRING: Value = TempDesc->String.Length; break; case ACPI_TYPE_BUFFER: /* Buffer arguments may not be evaluated at this point */ Status = AcpiDsGetBufferArguments (TempDesc); Value = TempDesc->Buffer.Length; break; case ACPI_TYPE_PACKAGE: /* Package arguments may not be evaluated at this point */ Status = AcpiDsGetPackageArguments (TempDesc); Value = TempDesc->Package.Count; break; default: ACPI_ERROR ((AE_INFO, "Operand must be Buffer/Integer/String/Package" " - found type %s", AcpiUtGetTypeName (Type))); Status = AE_AML_OPERAND_TYPE; goto Cleanup; } if (ACPI_FAILURE (Status)) { goto Cleanup; } /* * Now that we have the size of the object, create a result * object to hold the value */ ReturnDesc = AcpiUtCreateIntegerObject (Value); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } break; case AML_REF_OF_OP: /* RefOf (SourceObject) */ Status = AcpiExGetObjectReference ( Operand[0], &ReturnDesc, WalkState); if (ACPI_FAILURE (Status)) { goto Cleanup; } break; case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */ /* Check for a method local or argument, or standalone String */ if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED) { TempDesc = AcpiNsGetAttachedObject ( (ACPI_NAMESPACE_NODE *) Operand[0]); if (TempDesc && ((TempDesc->Common.Type == ACPI_TYPE_STRING) || (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE))) { Operand[0] = TempDesc; AcpiUtAddReference (TempDesc); } else { Status = AE_AML_OPERAND_TYPE; goto Cleanup; } } else { switch ((Operand[0])->Common.Type) { case ACPI_TYPE_LOCAL_REFERENCE: /* * This is a DerefOf (LocalX | ArgX) * * Must resolve/dereference the local/arg reference first */ switch (Operand[0]->Reference.Class) { case ACPI_REFCLASS_LOCAL: case ACPI_REFCLASS_ARG: /* Set Operand[0] to the value of the local/arg */ Status = AcpiDsMethodDataGetValue ( Operand[0]->Reference.Class, Operand[0]->Reference.Value, WalkState, &TempDesc); if (ACPI_FAILURE (Status)) { goto Cleanup; } /* * Delete our reference to the input object and * point to the object just retrieved */ AcpiUtRemoveReference (Operand[0]); Operand[0] = TempDesc; break; case ACPI_REFCLASS_REFOF: /* Get the object to which the reference refers */ TempDesc = Operand[0]->Reference.Object; AcpiUtRemoveReference (Operand[0]); Operand[0] = TempDesc; break; default: /* Must be an Index op - handled below */ break; } break; case ACPI_TYPE_STRING: break; default: Status = AE_AML_OPERAND_TYPE; goto Cleanup; } } if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED) { if ((Operand[0])->Common.Type == ACPI_TYPE_STRING) { /* * This is a DerefOf (String). The string is a reference * to a named ACPI object. * * 1) Find the owning Node * 2) Dereference the node to an actual object. Could be a * Field, so we need to resolve the node to a value. */ Status = AcpiNsGetNodeUnlocked (WalkState->ScopeInfo->Scope.Node, Operand[0]->String.Pointer, ACPI_NS_SEARCH_PARENT, ACPI_CAST_INDIRECT_PTR ( ACPI_NAMESPACE_NODE, &ReturnDesc)); if (ACPI_FAILURE (Status)) { goto Cleanup; } Status = AcpiExResolveNodeToValue ( ACPI_CAST_INDIRECT_PTR ( ACPI_NAMESPACE_NODE, &ReturnDesc), WalkState); goto Cleanup; } } /* Operand[0] may have changed from the code above */ if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED) { /* * This is a DerefOf (ObjectReference) * Get the actual object from the Node (This is the dereference). * This case may only happen when a LocalX or ArgX is * dereferenced above. */ ReturnDesc = AcpiNsGetAttachedObject ( (ACPI_NAMESPACE_NODE *) Operand[0]); AcpiUtAddReference (ReturnDesc); } else { /* * This must be a reference object produced by either the * Index() or RefOf() operator */ switch (Operand[0]->Reference.Class) { case ACPI_REFCLASS_INDEX: /* * The target type for the Index operator must be * either a Buffer or a Package */ switch (Operand[0]->Reference.TargetType) { case ACPI_TYPE_BUFFER_FIELD: TempDesc = Operand[0]->Reference.Object; /* * Create a new object that contains one element of the * buffer -- the element pointed to by the index. * * NOTE: index into a buffer is NOT a pointer to a * sub-buffer of the main buffer, it is only a pointer to a * single element (byte) of the buffer! * * Since we are returning the value of the buffer at the * indexed location, we don't need to add an additional * reference to the buffer itself. */ ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]); if (!ReturnDesc) { Status = AE_NO_MEMORY; goto Cleanup; } break; case ACPI_TYPE_PACKAGE: /* * Return the referenced element of the package. We must * add another reference to the referenced object, however. */ ReturnDesc = *(Operand[0]->Reference.Where); if (!ReturnDesc) { /* * Element is NULL, do not allow the dereference. * This provides compatibility with other ACPI * implementations. */ return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT); } AcpiUtAddReference (ReturnDesc); break; default: ACPI_ERROR ((AE_INFO, "Unknown Index TargetType 0x%X in reference object %p", Operand[0]->Reference.TargetType, Operand[0])); Status = AE_AML_OPERAND_TYPE; goto Cleanup; } break; case ACPI_REFCLASS_REFOF: ReturnDesc = Operand[0]->Reference.Object; if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) == ACPI_DESC_TYPE_NAMED) { ReturnDesc = AcpiNsGetAttachedObject ( (ACPI_NAMESPACE_NODE *) ReturnDesc); if (!ReturnDesc) { break; } /* * June 2013: * BufferFields/FieldUnits require additional resolution */ switch (ReturnDesc->Common.Type) { case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: Status = AcpiExReadDataFromField ( WalkState, ReturnDesc, &TempDesc); if (ACPI_FAILURE (Status)) { goto Cleanup; } ReturnDesc = TempDesc; break; default: /* Add another reference to the object */ AcpiUtAddReference (ReturnDesc); break; } } break; default: ACPI_ERROR ((AE_INFO, "Unknown class in reference(%p) - 0x%2.2X", Operand[0], Operand[0]->Reference.Class)); Status = AE_TYPE; goto Cleanup; } } break; default: ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", WalkState->Opcode)); Status = AE_AML_BAD_OPCODE; goto Cleanup; } Cleanup: /* Delete return object on error */ if (ACPI_FAILURE (Status)) { AcpiUtRemoveReference (ReturnDesc); } /* Save return object on success */ else { WalkState->ResultObj = ReturnDesc; } return_ACPI_STATUS (Status); }
void AcpiDbSetMethodData ( char *TypeArg, char *IndexArg, char *ValueArg) { char Type; UINT32 Index; UINT32 Value; ACPI_WALK_STATE *WalkState; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_STATUS Status; ACPI_NAMESPACE_NODE *Node; /* Validate TypeArg */ AcpiUtStrupr (TypeArg); Type = TypeArg[0]; if ((Type != 'L') && (Type != 'A') && (Type != 'N')) { AcpiOsPrintf ("Invalid SET operand: %s\n", TypeArg); return; } Value = ACPI_STRTOUL (ValueArg, NULL, 16); if (Type == 'N') { Node = AcpiDbConvertToNode (IndexArg); if (Node->Type != ACPI_TYPE_INTEGER) { AcpiOsPrintf ("Can only set Integer nodes\n"); return; } ObjDesc = Node->Object; ObjDesc->Integer.Value = Value; return; } /* Get the index and value */ Index = ACPI_STRTOUL (IndexArg, NULL, 16); WalkState = AcpiDsGetCurrentWalkState (AcpiGbl_CurrentWalkList); if (!WalkState) { AcpiOsPrintf ("There is no method currently executing\n"); return; } /* Create and initialize the new object */ ObjDesc = AcpiUtCreateIntegerObject ((UINT64) Value); if (!ObjDesc) { AcpiOsPrintf ("Could not create an internal object\n"); return; } /* Store the new object into the target */ switch (Type) { case 'A': /* Set a method argument */ if (Index > ACPI_METHOD_MAX_ARG) { AcpiOsPrintf ("Arg%u - Invalid argument name\n", Index); goto Cleanup; } Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_ARG, Index, ObjDesc, WalkState); if (ACPI_FAILURE (Status)) { goto Cleanup; } ObjDesc = WalkState->Arguments[Index].Object; AcpiOsPrintf ("Arg%u: ", Index); AcpiDmDisplayInternalObject (ObjDesc, WalkState); break; case 'L': /* Set a method local */ if (Index > ACPI_METHOD_MAX_LOCAL) { AcpiOsPrintf ("Local%u - Invalid local variable name\n", Index); goto Cleanup; } Status = AcpiDsStoreObjectToLocal (ACPI_REFCLASS_LOCAL, Index, ObjDesc, WalkState); if (ACPI_FAILURE (Status)) { goto Cleanup; } ObjDesc = WalkState->LocalVariables[Index].Object; AcpiOsPrintf ("Local%u: ", Index); AcpiDmDisplayInternalObject (ObjDesc, WalkState); break; default: break; } Cleanup: AcpiUtRemoveReference (ObjDesc); }
ACPI_STATUS AcpiExConvertToInteger ( ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc, UINT32 Flags) { ACPI_OPERAND_OBJECT *ReturnDesc; UINT8 *Pointer; UINT64 Result; UINT32 i; UINT32 Count; ACPI_STATUS Status; ACPI_FUNCTION_TRACE_PTR (ExConvertToInteger, ObjDesc); switch (ObjDesc->Common.Type) { case ACPI_TYPE_INTEGER: /* No conversion necessary */ *ResultDesc = ObjDesc; return_ACPI_STATUS (AE_OK); case ACPI_TYPE_BUFFER: case ACPI_TYPE_STRING: /* Note: Takes advantage of common buffer/string fields */ Pointer = ObjDesc->Buffer.Pointer; Count = ObjDesc->Buffer.Length; break; default: return_ACPI_STATUS (AE_TYPE); } /* * Convert the buffer/string to an integer. Note that both buffers and * strings are treated as raw data - we don't convert ascii to hex for * strings. * * There are two terminating conditions for the loop: * 1) The size of an integer has been reached, or * 2) The end of the buffer or string has been reached */ Result = 0; /* String conversion is different than Buffer conversion */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_STRING: /* * Convert string to an integer - for most cases, the string must be * hexadecimal as per the ACPI specification. The only exception (as * of ACPI 3.0) is that the ToInteger() operator allows both decimal * and hexadecimal strings (hex prefixed with "0x"). */ Status = AcpiUtStrtoul64 ((char *) Pointer, Flags, &Result); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } break; case ACPI_TYPE_BUFFER: /* Check for zero-length buffer */ if (!Count) { return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); } /* Transfer no more than an integer's worth of data */ if (Count > AcpiGbl_IntegerByteWidth) { Count = AcpiGbl_IntegerByteWidth; } /* * Convert buffer to an integer - we simply grab enough raw data * from the buffer to fill an integer */ for (i = 0; i < Count; i++) { /* * Get next byte and shift it into the Result. * Little endian is used, meaning that the first byte of the buffer * is the LSB of the integer */ Result |= (((UINT64) Pointer[i]) << (i * 8)); } break; default: /* No other types can get here */ break; } /* Create a new integer */ ReturnDesc = AcpiUtCreateIntegerObject (Result); if (!ReturnDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", ACPI_FORMAT_UINT64 (Result))); /* Save the Result */ (void) AcpiExTruncateFor32bitTable (ReturnDesc); *ResultDesc = ReturnDesc; return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiPsParseAml ( ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status; ACPI_THREAD_STATE *Thread; ACPI_THREAD_STATE *PrevWalkList = AcpiGbl_CurrentWalkList; ACPI_WALK_STATE *PreviousWalkState; ACPI_FUNCTION_TRACE (PsParseAml); ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Entered with WalkState=%p Aml=%p size=%X\n", WalkState, WalkState->ParserState.Aml, WalkState->ParserState.AmlSize)); if (!WalkState->ParserState.Aml) { return_ACPI_STATUS (AE_NULL_OBJECT); } /* Create and initialize a new thread state */ Thread = AcpiUtCreateThreadState (); if (!Thread) { if (WalkState->MethodDesc) { /* Executing a control method - additional cleanup */ AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); } AcpiDsDeleteWalkState (WalkState); return_ACPI_STATUS (AE_NO_MEMORY); } WalkState->Thread = Thread; /* * If executing a method, the starting SyncLevel is this method's * SyncLevel */ if (WalkState->MethodDesc) { WalkState->Thread->CurrentSyncLevel = WalkState->MethodDesc->Method.SyncLevel; } AcpiDsPushWalkState (WalkState, Thread); /* * This global allows the AML debugger to get a handle to the currently * executing control method. */ AcpiGbl_CurrentWalkList = Thread; /* * Execute the walk loop as long as there is a valid Walk State. This * handles nested control method invocations without recursion. */ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "State=%p\n", WalkState)); Status = AE_OK; while (WalkState) { if (ACPI_SUCCESS (Status)) { /* * The ParseLoop executes AML until the method terminates * or calls another method. */ Status = AcpiPsParseLoop (WalkState); } ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Completed one call to walk loop, %s State=%p\n", AcpiFormatException (Status), WalkState)); if (Status == AE_CTRL_TRANSFER) { /* * A method call was detected. * Transfer control to the called control method */ Status = AcpiDsCallControlMethod (Thread, WalkState, NULL); if (ACPI_FAILURE (Status)) { Status = AcpiDsMethodError (Status, WalkState); } /* * If the transfer to the new method method call worked, a new walk * state was created -- get it */ WalkState = AcpiDsGetCurrentWalkState (Thread); continue; } else if (Status == AE_CTRL_TERMINATE) { Status = AE_OK; } else if ((Status != AE_OK) && (WalkState->MethodDesc)) { /* Either the method parse or actual execution failed */ ACPI_ERROR_METHOD ("Method parse/execution failed", WalkState->MethodNode, NULL, Status); /* Check for possible multi-thread reentrancy problem */ if ((Status == AE_ALREADY_EXISTS) && (!(WalkState->MethodDesc->Method.InfoFlags & ACPI_METHOD_SERIALIZED))) { /* * Method is not serialized and tried to create an object * twice. The probable cause is that the method cannot * handle reentrancy. Mark as "pending serialized" now, and * then mark "serialized" when the last thread exits. */ WalkState->MethodDesc->Method.InfoFlags |= ACPI_METHOD_SERIALIZED_PENDING; } } /* We are done with this walk, move on to the parent if any */ WalkState = AcpiDsPopWalkState (Thread); /* Reset the current scope to the beginning of scope stack */ AcpiDsScopeStackClear (WalkState); /* * If we just returned from the execution of a control method or if we * encountered an error during the method parse phase, there's lots of * cleanup to do */ if (((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) || (ACPI_FAILURE (Status))) { AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); } /* Delete this walk state and all linked control states */ AcpiPsCleanupScope (&WalkState->ParserState); PreviousWalkState = WalkState; ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "ReturnValue=%p, ImplicitValue=%p State=%p\n", WalkState->ReturnDesc, WalkState->ImplicitReturnObj, WalkState)); /* Check if we have restarted a preempted walk */ WalkState = AcpiDsGetCurrentWalkState (Thread); if (WalkState) { if (ACPI_SUCCESS (Status)) { /* * There is another walk state, restart it. * If the method return value is not used by the parent, * The object is deleted */ if (!PreviousWalkState->ReturnDesc) { /* * In slack mode execution, if there is no return value * we should implicitly return zero (0) as a default value. */ if (AcpiGbl_EnableInterpreterSlack && !PreviousWalkState->ImplicitReturnObj) { PreviousWalkState->ImplicitReturnObj = AcpiUtCreateIntegerObject ((UINT64) 0); if (!PreviousWalkState->ImplicitReturnObj) { return_ACPI_STATUS (AE_NO_MEMORY); } } /* Restart the calling control method */ Status = AcpiDsRestartControlMethod (WalkState, PreviousWalkState->ImplicitReturnObj); } else { /* * We have a valid return value, delete any implicit * return value. */ AcpiDsClearImplicitReturn (PreviousWalkState); Status = AcpiDsRestartControlMethod (WalkState, PreviousWalkState->ReturnDesc); } if (ACPI_SUCCESS (Status)) { WalkState->WalkType |= ACPI_WALK_METHOD_RESTART; } } else { /* On error, delete any return object or implicit return */ AcpiUtRemoveReference (PreviousWalkState->ReturnDesc); AcpiDsClearImplicitReturn (PreviousWalkState); } } /* * Just completed a 1st-level method, save the final internal return * value (if any) */ else if (PreviousWalkState->CallerReturnDesc) { if (PreviousWalkState->ImplicitReturnObj) { *(PreviousWalkState->CallerReturnDesc) = PreviousWalkState->ImplicitReturnObj; } else { /* NULL if no return value */ *(PreviousWalkState->CallerReturnDesc) = PreviousWalkState->ReturnDesc; } } else { if (PreviousWalkState->ReturnDesc) { /* Caller doesn't want it, must delete it */ AcpiUtRemoveReference (PreviousWalkState->ReturnDesc); } if (PreviousWalkState->ImplicitReturnObj) { /* Caller doesn't want it, must delete it */ AcpiUtRemoveReference (PreviousWalkState->ImplicitReturnObj); } } AcpiDsDeleteWalkState (PreviousWalkState); } /* Normal exit */ AcpiExReleaseAllMutexes (Thread); AcpiUtDeleteGenericState (ACPI_CAST_PTR (ACPI_GENERIC_STATE, Thread)); AcpiGbl_CurrentWalkList = PrevWalkList; return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExLoadTableOp ( ACPI_WALK_STATE *WalkState, ACPI_OPERAND_OBJECT **ReturnDesc) { ACPI_STATUS Status; ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; ACPI_NAMESPACE_NODE *ParentNode; ACPI_NAMESPACE_NODE *StartNode; ACPI_NAMESPACE_NODE *ParameterNode = NULL; ACPI_OPERAND_OBJECT *DdbHandle; ACPI_TABLE_HEADER *Table; UINT32 TableIndex; ACPI_FUNCTION_TRACE (ExLoadTableOp); /* Validate lengths for the SignatureString, OEMIDString, OEMTableID */ if ((Operand[0]->String.Length > ACPI_NAME_SIZE) || (Operand[1]->String.Length > ACPI_OEM_ID_SIZE) || (Operand[2]->String.Length > ACPI_OEM_TABLE_ID_SIZE)) { return_ACPI_STATUS (AE_BAD_PARAMETER); } /* Find the ACPI table in the RSDT/XSDT */ Status = AcpiTbFindTable (Operand[0]->String.Pointer, Operand[1]->String.Pointer, Operand[2]->String.Pointer, &TableIndex); if (ACPI_FAILURE (Status)) { if (Status != AE_NOT_FOUND) { return_ACPI_STATUS (Status); } /* Table not found, return an Integer=0 and AE_OK */ DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0); if (!DdbHandle) { return_ACPI_STATUS (AE_NO_MEMORY); } *ReturnDesc = DdbHandle; return_ACPI_STATUS (AE_OK); } /* Default nodes */ StartNode = WalkState->ScopeInfo->Scope.Node; ParentNode = AcpiGbl_RootNode; /* RootPath (optional parameter) */ if (Operand[3]->String.Length > 0) { /* * Find the node referenced by the RootPathString. This is the * location within the namespace where the table will be loaded. */ Status = AcpiNsGetNode (StartNode, Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT, &ParentNode); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* ParameterPath (optional parameter) */ if (Operand[4]->String.Length > 0) { if ((Operand[4]->String.Pointer[0] != '\\') && (Operand[4]->String.Pointer[0] != '^')) { /* * Path is not absolute, so it will be relative to the node * referenced by the RootPathString (or the NS root if omitted) */ StartNode = ParentNode; } /* Find the node referenced by the ParameterPathString */ Status = AcpiNsGetNode (StartNode, Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT, &ParameterNode); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* Load the table into the namespace */ Status = AcpiExAddTable (TableIndex, ParentNode, &DdbHandle); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Parameter Data (optional) */ if (ParameterNode) { /* Store the parameter data into the optional parameter object */ Status = AcpiExStore (Operand[5], ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState); if (ACPI_FAILURE (Status)) { (void) AcpiExUnloadTable (DdbHandle); AcpiUtRemoveReference (DdbHandle); return_ACPI_STATUS (Status); } } Status = AcpiGetTableByIndex (TableIndex, &Table); if (ACPI_SUCCESS (Status)) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Dynamic OEM Table Load:")); AcpiTbPrintTableHeader (0, Table); } /* Invoke table handler if present */ if (AcpiGbl_TableHandler) { (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table, AcpiGbl_TableHandlerContext); } *ReturnDesc = DdbHandle; return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiDsMethodDataGetValue ( UINT8 Type, UINT32 Index, ACPI_WALK_STATE *WalkState, ACPI_OPERAND_OBJECT **DestDesc) { ACPI_STATUS Status; ACPI_NAMESPACE_NODE *Node; ACPI_OPERAND_OBJECT *Object; ACPI_FUNCTION_TRACE (DsMethodDataGetValue); /* Validate the object descriptor */ if (!DestDesc) { ACPI_ERROR ((AE_INFO, "Null object descriptor pointer")); return_ACPI_STATUS (AE_BAD_PARAMETER); } /* Get the namespace node for the arg/local */ Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Get the object from the node */ Object = Node->Object; /* Examine the returned object, it must be valid. */ if (!Object) { /* * Index points to uninitialized object. * This means that either 1) The expected argument was * not passed to the method, or 2) A local variable * was referenced by the method (via the ASL) * before it was initialized. Either case is an error. */ /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */ if (AcpiGbl_EnableInterpreterSlack) { Object = AcpiUtCreateIntegerObject ((UINT64) 0); if (!Object) { return_ACPI_STATUS (AE_NO_MEMORY); } Node->Object = Object; } /* Otherwise, return the error */ else switch (Type) { case ACPI_REFCLASS_ARG: ACPI_ERROR ((AE_INFO, "Uninitialized Arg[%u] at node %p", Index, Node)); return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); case ACPI_REFCLASS_LOCAL: /* * No error message for this case, will be trapped again later to * detect and ignore cases of Store(LocalX,LocalX) */ return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); default: ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type)); return_ACPI_STATUS (AE_AML_INTERNAL); } } /* * The Index points to an initialized and valid object. * Return an additional reference to the object */ *DestDesc = Object; AcpiUtAddReference (Object); return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiEvExecuteRegMethod ( ACPI_OPERAND_OBJECT *RegionObj, UINT32 Function) { ACPI_EVALUATE_INFO *Info; ACPI_OPERAND_OBJECT *Args[3]; ACPI_OPERAND_OBJECT *RegionObj2; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (EvExecuteRegMethod); RegionObj2 = AcpiNsGetSecondaryObject (RegionObj); if (!RegionObj2) { return_ACPI_STATUS (AE_NOT_EXIST); } if (RegionObj2->Extra.Method_REG == NULL) { return_ACPI_STATUS (AE_OK); } /* Allocate and initialize the evaluation information block */ Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); if (!Info) { return_ACPI_STATUS (AE_NO_MEMORY); } Info->PrefixNode = RegionObj2->Extra.Method_REG; Info->RelativePathname = NULL; Info->Parameters = Args; Info->Flags = ACPI_IGNORE_RETURN_VALUE; /* * The _REG method has two arguments: * * Arg0 - Integer: * Operation region space ID Same value as RegionObj->Region.SpaceId * * Arg1 - Integer: * connection status 1 for connecting the handler, 0 for disconnecting * the handler (Passed as a parameter) */ Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId); if (!Args[0]) { Status = AE_NO_MEMORY; goto Cleanup1; } Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function); if (!Args[1]) { Status = AE_NO_MEMORY; goto Cleanup2; } Args[2] = NULL; /* Terminate list */ /* Execute the method, no return value */ ACPI_DEBUG_EXEC ( AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL)); Status = AcpiNsEvaluate (Info); AcpiUtRemoveReference (Args[1]); Cleanup2: AcpiUtRemoveReference (Args[0]); Cleanup1: ACPI_FREE (Info); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiPsExecuteMethod ( ACPI_EVALUATE_INFO *Info) { ACPI_STATUS Status; ACPI_PARSE_OBJECT *Op; ACPI_WALK_STATE *WalkState; ACPI_FUNCTION_TRACE (PsExecuteMethod); /* Quick validation of DSDT header */ AcpiTbCheckDsdtHeader (); /* Validate the Info and method Node */ if (!Info || !Info->Node) { return_ACPI_STATUS (AE_NULL_ENTRY); } /* Init for new method, wait on concurrency semaphore */ Status = AcpiDsBeginMethodExecution (Info->Node, Info->ObjDesc, NULL); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * The caller "owns" the parameters, so give each one an extra reference */ AcpiPsUpdateParameterList (Info, REF_INCREMENT); /* * Execute the method. Performs parse simultaneously */ ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n", Info->Node->Name.Ascii, Info->Node, Info->ObjDesc)); /* Create and init a Root Node */ Op = AcpiPsCreateScopeOp (Info->ObjDesc->Method.AmlStart); if (!Op) { Status = AE_NO_MEMORY; goto Cleanup; } /* Create and initialize a new walk state */ Info->PassNumber = ACPI_IMODE_EXECUTE; WalkState = AcpiDsCreateWalkState ( Info->ObjDesc->Method.OwnerId, NULL, NULL, NULL); if (!WalkState) { Status = AE_NO_MEMORY; goto Cleanup; } Status = AcpiDsInitAmlWalk (WalkState, Op, Info->Node, Info->ObjDesc->Method.AmlStart, Info->ObjDesc->Method.AmlLength, Info, Info->PassNumber); if (ACPI_FAILURE (Status)) { AcpiDsDeleteWalkState (WalkState); goto Cleanup; } if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_MODULE_LEVEL) { WalkState->ParseFlags |= ACPI_PARSE_MODULE_LEVEL; } /* Invoke an internal method if necessary */ if (Info->ObjDesc->Method.InfoFlags & ACPI_METHOD_INTERNAL_ONLY) { Status = Info->ObjDesc->Method.Dispatch.Implementation (WalkState); Info->ReturnObject = WalkState->ReturnDesc; /* Cleanup states */ AcpiDsScopeStackClear (WalkState); AcpiPsCleanupScope (&WalkState->ParserState); AcpiDsTerminateControlMethod (WalkState->MethodDesc, WalkState); AcpiDsDeleteWalkState (WalkState); goto Cleanup; } /* * Start method evaluation with an implicit return of zero. * This is done for Windows compatibility. */ if (AcpiGbl_EnableInterpreterSlack) { WalkState->ImplicitReturnObj = AcpiUtCreateIntegerObject ((UINT64) 0); if (!WalkState->ImplicitReturnObj) { Status = AE_NO_MEMORY; AcpiDsDeleteWalkState (WalkState); goto Cleanup; } } /* Parse the AML */ Status = AcpiPsParseAml (WalkState); /* WalkState was deleted by ParseAml */ Cleanup: AcpiPsDeleteParseTree (Op); /* Take away the extra reference that we gave the parameters above */ AcpiPsUpdateParameterList (Info, REF_DECREMENT); /* Exit now if error above */ if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * If the method has returned an object, signal this to the caller with * a control exception code */ if (Info->ReturnObject) { ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n", Info->ReturnObject)); ACPI_DUMP_STACK_ENTRY (Info->ReturnObject); Status = AE_CTRL_RETURN_VALUE; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiEvExecuteRegMethod ( ACPI_OPERAND_OBJECT *RegionObj, UINT32 Function) { ACPI_EVALUATE_INFO *Info; ACPI_OPERAND_OBJECT *Args[3]; ACPI_OPERAND_OBJECT *RegionObj2; const ACPI_NAME *RegNamePtr = ACPI_CAST_PTR (ACPI_NAME, METHOD_NAME__REG); ACPI_NAMESPACE_NODE *MethodNode; ACPI_NAMESPACE_NODE *Node; ACPI_STATUS Status; ACPI_FUNCTION_TRACE (EvExecuteRegMethod); if (!AcpiGbl_NamespaceInitialized || RegionObj->Region.Handler == NULL) { return_ACPI_STATUS (AE_OK); } RegionObj2 = AcpiNsGetSecondaryObject (RegionObj); if (!RegionObj2) { return_ACPI_STATUS (AE_NOT_EXIST); } /* * Find any "_REG" method associated with this region definition. * The method should always be updated as this function may be * invoked after a namespace change. */ Node = RegionObj->Region.Node->Parent; Status = AcpiNsSearchOneScope ( *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode); if (ACPI_SUCCESS (Status)) { /* * The _REG method is optional and there can be only one per * region definition. This will be executed when the handler is * attached or removed. */ RegionObj2->Extra.Method_REG = MethodNode; } if (RegionObj2->Extra.Method_REG == NULL) { return_ACPI_STATUS (AE_OK); } /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */ if ((Function == ACPI_REG_CONNECT && RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED) || (Function == ACPI_REG_DISCONNECT && !(RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED))) { return_ACPI_STATUS (AE_OK); } /* Allocate and initialize the evaluation information block */ Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); if (!Info) { return_ACPI_STATUS (AE_NO_MEMORY); } Info->PrefixNode = RegionObj2->Extra.Method_REG; Info->RelativePathname = NULL; Info->Parameters = Args; Info->Flags = ACPI_IGNORE_RETURN_VALUE; /* * The _REG method has two arguments: * * Arg0 - Integer: * Operation region space ID Same value as RegionObj->Region.SpaceId * * Arg1 - Integer: * connection status 1 for connecting the handler, 0 for disconnecting * the handler (Passed as a parameter) */ Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId); if (!Args[0]) { Status = AE_NO_MEMORY; goto Cleanup1; } Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function); if (!Args[1]) { Status = AE_NO_MEMORY; goto Cleanup2; } Args[2] = NULL; /* Terminate list */ /* Execute the method, no return value */ ACPI_DEBUG_EXEC ( AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL)); Status = AcpiNsEvaluate (Info); AcpiUtRemoveReference (Args[1]); if (ACPI_FAILURE (Status)) { goto Cleanup2; } if (Function == ACPI_REG_CONNECT) { RegionObj->Common.Flags |= AOPOBJ_REG_CONNECTED; } else { RegionObj->Common.Flags &= ~AOPOBJ_REG_CONNECTED; } Cleanup2: AcpiUtRemoveReference (Args[0]); Cleanup1: ACPI_FREE (Info); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExLoadTableOp ( ACPI_WALK_STATE *WalkState, ACPI_OPERAND_OBJECT **ReturnDesc) { ACPI_STATUS Status; ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0]; ACPI_NAMESPACE_NODE *ParentNode; ACPI_NAMESPACE_NODE *StartNode; ACPI_NAMESPACE_NODE *ParameterNode = NULL; ACPI_OPERAND_OBJECT *DdbHandle; UINT32 TableIndex; ACPI_FUNCTION_TRACE (ExLoadTableOp); /* Find the ACPI table in the RSDT/XSDT */ AcpiExExitInterpreter (); Status = AcpiTbFindTable ( Operand[0]->String.Pointer, Operand[1]->String.Pointer, Operand[2]->String.Pointer, &TableIndex); AcpiExEnterInterpreter (); if (ACPI_FAILURE (Status)) { if (Status != AE_NOT_FOUND) { return_ACPI_STATUS (Status); } /* Table not found, return an Integer=0 and AE_OK */ DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0); if (!DdbHandle) { return_ACPI_STATUS (AE_NO_MEMORY); } *ReturnDesc = DdbHandle; return_ACPI_STATUS (AE_OK); } /* Default nodes */ StartNode = WalkState->ScopeInfo->Scope.Node; ParentNode = AcpiGbl_RootNode; /* RootPath (optional parameter) */ if (Operand[3]->String.Length > 0) { /* * Find the node referenced by the RootPathString. This is the * location within the namespace where the table will be loaded. */ Status = AcpiNsGetNodeUnlocked (StartNode, Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT, &ParentNode); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* ParameterPath (optional parameter) */ if (Operand[4]->String.Length > 0) { if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) && (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX)) { /* * Path is not absolute, so it will be relative to the node * referenced by the RootPathString (or the NS root if omitted) */ StartNode = ParentNode; } /* Find the node referenced by the ParameterPathString */ Status = AcpiNsGetNodeUnlocked (StartNode, Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT, &ParameterNode); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* Load the table into the namespace */ ACPI_INFO (("Dynamic OEM Table Load:")); AcpiExExitInterpreter (); Status = AcpiTbLoadTable (TableIndex, ParentNode); AcpiExEnterInterpreter (); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } Status = AcpiExAddTable (TableIndex, &DdbHandle); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Parameter Data (optional) */ if (ParameterNode) { /* Store the parameter data into the optional parameter object */ Status = AcpiExStore (Operand[5], ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState); if (ACPI_FAILURE (Status)) { (void) AcpiExUnloadTable (DdbHandle); AcpiUtRemoveReference (DdbHandle); return_ACPI_STATUS (Status); } } *ReturnDesc = DdbHandle; return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiNsRepairNullElement ( ACPI_EVALUATE_INFO *Info, UINT32 ExpectedBtypes, UINT32 PackageIndex, ACPI_OPERAND_OBJECT **ReturnObjectPtr) { ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; ACPI_OPERAND_OBJECT *NewObject; ACPI_FUNCTION_NAME (NsRepairNullElement); /* No repair needed if return object is non-NULL */ if (ReturnObject) { return (AE_OK); } /* * Attempt to repair a NULL element of a Package object. This applies to * predefined names that return a fixed-length package and each element * is required. It does not apply to variable-length packages where NULL * elements are allowed, especially at the end of the package. */ if (ExpectedBtypes & ACPI_RTYPE_INTEGER) { /* Need an Integer - create a zero-value integer */ NewObject = AcpiUtCreateIntegerObject ((UINT64) 0); } else if (ExpectedBtypes & ACPI_RTYPE_STRING) { /* Need a String - create a NULL string */ NewObject = AcpiUtCreateStringObject (0); } else if (ExpectedBtypes & ACPI_RTYPE_BUFFER) { /* Need a Buffer - create a zero-length buffer */ NewObject = AcpiUtCreateBufferObject (0); } else { /* Error for all other expected types */ return (AE_AML_OPERAND_TYPE); } if (!NewObject) { return (AE_NO_MEMORY); } /* Set the reference count according to the parent Package object */ NewObject->Common.ReferenceCount = Info->ParentPackage->Common.ReferenceCount; ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR, "%s: Converted NULL package element to expected %s at index %u\n", Info->FullPathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex)); *ReturnObjectPtr = NewObject; Info->ReturnFlags |= ACPI_OBJECT_REPAIRED; return (AE_OK); }
ACPI_STATUS AcpiExReadDataFromField ( ACPI_WALK_STATE *WalkState, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **RetBufferDesc) { ACPI_STATUS Status; ACPI_OPERAND_OBJECT *BufferDesc; ACPI_SIZE Length; void *Buffer; UINT32 Function; ACPI_FUNCTION_TRACE_PTR (ExReadDataFromField, ObjDesc); /* Parameter validation */ if (!ObjDesc) { return_ACPI_STATUS (AE_AML_NO_OPERAND); } if (!RetBufferDesc) { return_ACPI_STATUS (AE_BAD_PARAMETER); } if (ObjDesc->Common.Type == ACPI_TYPE_BUFFER_FIELD) { /* * If the BufferField arguments have not been previously evaluated, * evaluate them now and save the results. */ if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) { Status = AcpiDsGetBufferFieldArguments (ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } } else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) && (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS || ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS || ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_IPMI)) { /* * This is an SMBus, GSBus or IPMI read. We must create a buffer to hold * the data and then directly access the region handler. * * Note: SMBus and GSBus protocol value is passed in upper 16-bits of Function */ if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS) { Length = ACPI_SMBUS_BUFFER_SIZE; Function = ACPI_READ | (ObjDesc->Field.Attribute << 16); } else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) { Length = ACPI_GSBUS_BUFFER_SIZE; Function = ACPI_READ | (ObjDesc->Field.Attribute << 16); } else /* IPMI */ { Length = ACPI_IPMI_BUFFER_SIZE; Function = ACPI_READ; } BufferDesc = AcpiUtCreateBufferObject (Length); if (!BufferDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* Call the region handler for the read */ Status = AcpiExAccessRegion (ObjDesc, 0, ACPI_CAST_PTR (UINT64, BufferDesc->Buffer.Pointer), Function); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); goto Exit; } /* * Allocate a buffer for the contents of the field. * * If the field is larger than the current integer width, create * a BUFFER to hold it. Otherwise, use an INTEGER. This allows * the use of arithmetic operators on the returned value if the * field size is equal or smaller than an Integer. * * Note: Field.length is in bits. */ Length = (ACPI_SIZE) ACPI_ROUND_BITS_UP_TO_BYTES (ObjDesc->Field.BitLength); if (Length > AcpiGbl_IntegerByteWidth) { /* Field is too large for an Integer, create a Buffer instead */ BufferDesc = AcpiUtCreateBufferObject (Length); if (!BufferDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } Buffer = BufferDesc->Buffer.Pointer; } else { /* Field will fit within an Integer (normal case) */ BufferDesc = AcpiUtCreateIntegerObject ((UINT64) 0); if (!BufferDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } Length = AcpiGbl_IntegerByteWidth; Buffer = &BufferDesc->Integer.Value; } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "FieldRead [TO]: Obj %p, Type %X, Buf %p, ByteLen %X\n", ObjDesc, ObjDesc->Common.Type, Buffer, (UINT32) Length)); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "FieldRead [FROM]: BitLen %X, BitOff %X, ByteOff %X\n", ObjDesc->CommonField.BitLength, ObjDesc->CommonField.StartFieldBitOffset, ObjDesc->CommonField.BaseByteOffset)); /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* Read from the field */ Status = AcpiExExtractFromField (ObjDesc, Buffer, (UINT32) Length); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); Exit: if (ACPI_FAILURE (Status)) { AcpiUtRemoveReference (BufferDesc); } else { *RetBufferDesc = BufferDesc; } return_ACPI_STATUS (Status); }