void AcpiDmDecodeInternalObject ( ACPI_OPERAND_OBJECT *ObjDesc) { UINT32 i; if (!ObjDesc) { AcpiOsPrintf (" Uninitialized"); return; } if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND) { AcpiOsPrintf (" %p", ObjDesc); return; } AcpiOsPrintf (" %s", AcpiUtGetObjectTypeName (ObjDesc)); switch (ACPI_GET_OBJECT_TYPE (ObjDesc)) { case ACPI_TYPE_INTEGER: AcpiOsPrintf (" %8.8X%8.8X", ACPI_HIDWORD (ObjDesc->Integer.Value), ACPI_LODWORD (ObjDesc->Integer.Value)); break; case ACPI_TYPE_STRING: AcpiOsPrintf ("(%d) \"%.24s", ObjDesc->String.Length, ObjDesc->String.Pointer); if (ObjDesc->String.Length > 24) { AcpiOsPrintf ("..."); } else { AcpiOsPrintf ("\""); } break; case ACPI_TYPE_BUFFER: AcpiOsPrintf ("(%d)", ObjDesc->Buffer.Length); for (i = 0; (i < 8) && (i < ObjDesc->Buffer.Length); i++) { AcpiOsPrintf (" %2.2X", ObjDesc->Buffer.Pointer[i]); } break; default: AcpiOsPrintf (" %p", ObjDesc); break; } }
static ACPI_STATUS AcpiNsCheckObjectType ( ACPI_PREDEFINED_DATA *Data, ACPI_OPERAND_OBJECT **ReturnObjectPtr, UINT32 ExpectedBtypes, UINT32 PackageIndex) { ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; ACPI_STATUS Status = AE_OK; UINT32 ReturnBtype; char TypeBuffer[48]; /* Room for 5 types */ /* * If we get a NULL ReturnObject here, it is a NULL package element. * Since all extraneous NULL package elements were removed earlier by a * call to AcpiNsRemoveNullElements, this is an unexpected NULL element. * We will attempt to repair it. */ if (!ReturnObject) { Status = AcpiNsRepairNullElement (Data, ExpectedBtypes, PackageIndex, ReturnObjectPtr); if (ACPI_SUCCESS (Status)) { return (AE_OK); /* Repair was successful */ } goto TypeErrorExit; } /* A Namespace node should not get here, but make sure */ if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED) { ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, "Invalid return type - Found a Namespace node [%4.4s] type %s", ReturnObject->Node.Name.Ascii, AcpiUtGetTypeName (ReturnObject->Node.Type))); return (AE_AML_OPERAND_TYPE); } /* * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. * The bitmapped type allows multiple possible return types. * * Note, the cases below must handle all of the possible types returned * from all of the predefined names (including elements of returned * packages) */ switch (ReturnObject->Common.Type) { case ACPI_TYPE_INTEGER: ReturnBtype = ACPI_RTYPE_INTEGER; break; case ACPI_TYPE_BUFFER: ReturnBtype = ACPI_RTYPE_BUFFER; break; case ACPI_TYPE_STRING: ReturnBtype = ACPI_RTYPE_STRING; break; case ACPI_TYPE_PACKAGE: ReturnBtype = ACPI_RTYPE_PACKAGE; break; case ACPI_TYPE_LOCAL_REFERENCE: ReturnBtype = ACPI_RTYPE_REFERENCE; break; default: /* Not one of the supported objects, must be incorrect */ goto TypeErrorExit; } /* Is the object one of the expected types? */ if (ReturnBtype & ExpectedBtypes) { /* For reference objects, check that the reference type is correct */ if (ReturnObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) { Status = AcpiNsCheckReference (Data, ReturnObject); } return (Status); } /* Type mismatch -- attempt repair of the returned object */ Status = AcpiNsRepairObject (Data, ExpectedBtypes, PackageIndex, ReturnObjectPtr); if (ACPI_SUCCESS (Status)) { return (AE_OK); /* Repair was successful */ } TypeErrorExit: /* Create a string with all expected types for this predefined object */ AcpiNsGetExpectedTypes (TypeBuffer, ExpectedBtypes); if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT) { ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, "Return type mismatch - found %s, expected %s", AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); } else { ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags, "Return Package type mismatch at index %u - " "found %s, expected %s", PackageIndex, AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); } return (AE_AML_OPERAND_TYPE); }
static ACPI_STATUS AcpiUtGetSimpleObjectSize ( ACPI_OPERAND_OBJECT *InternalObject, ACPI_SIZE *ObjLength) { ACPI_SIZE Length; ACPI_SIZE Size; ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject); /* Start with the length of the (external) Acpi object */ Length = sizeof (ACPI_OBJECT); /* A NULL object is allowed, can be a legal uninitialized package element */ if (!InternalObject) { /* * Object is NULL, just return the length of ACPI_OBJECT * (A NULL ACPI_OBJECT is an object of all zeroes.) */ *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length); return_ACPI_STATUS (AE_OK); } /* A Namespace Node should never appear here */ if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED) { /* A namespace node should never get here */ ACPI_ERROR ((AE_INFO, "Received a namespace node [%4.4s] " "where an operand object is required", ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, InternalObject)->Name.Ascii)); return_ACPI_STATUS (AE_AML_INTERNAL); } /* * The final length depends on the object type * Strings and Buffers are packed right up against the parent object and * must be accessed bytewise or there may be alignment problems on * certain processors */ switch (InternalObject->Common.Type) { case ACPI_TYPE_STRING: Length += (ACPI_SIZE) InternalObject->String.Length + 1; break; case ACPI_TYPE_BUFFER: Length += (ACPI_SIZE) InternalObject->Buffer.Length; break; case ACPI_TYPE_INTEGER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_POWER: /* No extra data for these types */ break; case ACPI_TYPE_LOCAL_REFERENCE: switch (InternalObject->Reference.Class) { case ACPI_REFCLASS_NAME: /* * Get the actual length of the full pathname to this object. * The reference will be converted to the pathname to the object */ Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node); if (!Size) { return_ACPI_STATUS (AE_BAD_PARAMETER); } Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size); break; default: /* * No other reference opcodes are supported. * Notably, Locals and Args are not supported, but this may be * required eventually. */ ACPI_ERROR ((AE_INFO, "Cannot convert to external object - " "unsupported Reference Class [%s] 0x%X in object %p", AcpiUtGetReferenceName (InternalObject), InternalObject->Reference.Class, InternalObject)); Status = AE_TYPE; break; } break; default: ACPI_ERROR ((AE_INFO, "Cannot convert to external object - " "unsupported type [%s] 0x%X in object %p", AcpiUtGetObjectTypeName (InternalObject), InternalObject->Common.Type, InternalObject)); Status = AE_TYPE; break; } /* * Account for the space required by the object rounded up to the next * multiple of the machine word size. This keeps each object aligned * on a machine word boundary. (preventing alignment faults on some * machines.) */ *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExGetObjectReference ( ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ReturnDesc, ACPI_WALK_STATE *WalkState) { ACPI_OPERAND_OBJECT *ReferenceObj; ACPI_OPERAND_OBJECT *ReferencedObj; ACPI_FUNCTION_TRACE_PTR (ExGetObjectReference, ObjDesc); *ReturnDesc = NULL; switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)) { case ACPI_DESC_TYPE_OPERAND: if (ObjDesc->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) { return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* * Must be a reference to a Local or Arg */ switch (ObjDesc->Reference.Class) { case ACPI_REFCLASS_LOCAL: case ACPI_REFCLASS_ARG: case ACPI_REFCLASS_DEBUG: /* The referenced object is the pseudo-node for the local/arg */ ReferencedObj = ObjDesc->Reference.Object; break; default: ACPI_ERROR ((AE_INFO, "Invalid Reference Class 0x%2.2X", ObjDesc->Reference.Class)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } break; case ACPI_DESC_TYPE_NAMED: /* * A named reference that has already been resolved to a Node */ ReferencedObj = ObjDesc; break; default: ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X", ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))); return_ACPI_STATUS (AE_TYPE); } /* Create a new reference object */ ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE); if (!ReferenceObj) { return_ACPI_STATUS (AE_NO_MEMORY); } ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF; ReferenceObj->Reference.Object = ReferencedObj; *ReturnDesc = ReferenceObj; ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p Type [%s], returning Reference %p\n", ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc)); return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiDsResultPush ( ACPI_OPERAND_OBJECT *Object, ACPI_WALK_STATE *WalkState) { ACPI_GENERIC_STATE *State; ACPI_STATUS Status; UINT32 Index; ACPI_FUNCTION_NAME (DsResultPush); if (WalkState->ResultCount > WalkState->ResultSize) { ACPI_ERROR ((AE_INFO, "Result stack is full")); return (AE_AML_INTERNAL); } else if (WalkState->ResultCount == WalkState->ResultSize) { /* Extend the result stack */ Status = AcpiDsResultStackPush (WalkState); if (ACPI_FAILURE (Status)) { ACPI_ERROR ((AE_INFO, "Failed to extend the result stack")); return (Status); } } if (!(WalkState->ResultCount < WalkState->ResultSize)) { ACPI_ERROR ((AE_INFO, "No free elements in result stack")); return (AE_AML_INTERNAL); } State = WalkState->Results; if (!State) { ACPI_ERROR ((AE_INFO, "No result stack frame during push")); return (AE_AML_INTERNAL); } if (!Object) { ACPI_ERROR ((AE_INFO, "Null Object! Obj=%p State=%p Num=%u", Object, WalkState, WalkState->ResultCount)); return (AE_BAD_PARAMETER); } /* Assign the address of object to the top free element of result stack */ Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM; State->Results.ObjDesc [Index] = Object; WalkState->ResultCount++; ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n", Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object), WalkState, WalkState->ResultCount, WalkState->CurrentResult)); return (AE_OK); }
ACPI_STATUS AcpiExStoreObjectToNode ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_NAMESPACE_NODE *Node, ACPI_WALK_STATE *WalkState, UINT8 ImplicitConversion) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *TargetDesc; ACPI_OPERAND_OBJECT *NewDesc; ACPI_OBJECT_TYPE TargetType; ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc); /* Get current type of the node, and object attached to Node */ TargetType = AcpiNsGetType (Node); TargetDesc = AcpiNsGetAttachedObject (Node); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p [%s] to node %p [%s]\n", SourceDesc, AcpiUtGetObjectTypeName (SourceDesc), Node, AcpiUtGetTypeName (TargetType))); /* Only limited target types possible for everything except CopyObject */ if (WalkState->Opcode != AML_COPY_OBJECT_OP) { /* * Only CopyObject allows all object types to be overwritten. For * TargetRef(s), there are restrictions on the object types that * are allowed. * * Allowable operations/typing for Store: * * 1) Simple Store * Integer --> Integer (Named/Local/Arg) * String --> String (Named/Local/Arg) * Buffer --> Buffer (Named/Local/Arg) * Package --> Package (Named/Local/Arg) * * 2) Store with implicit conversion * Integer --> String or Buffer (Named) * String --> Integer or Buffer (Named) * Buffer --> Integer or String (Named) */ switch (TargetType) { case ACPI_TYPE_PACKAGE: /* * Here, can only store a package to an existing package. * Storing a package to a Local/Arg is OK, and handled * elsewhere. */ if (WalkState->Opcode == AML_STORE_OP) { if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE) { ACPI_ERROR ((AE_INFO, "Cannot assign type [%s] to [Package] " "(source must be type Pkg)", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_TARGET_TYPE); } break; } /* Fallthrough */ case ACPI_TYPE_DEVICE: case ACPI_TYPE_EVENT: case ACPI_TYPE_MUTEX: case ACPI_TYPE_REGION: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_THERMAL: ACPI_ERROR ((AE_INFO, "Target must be [Buffer/Integer/String/Reference]" ", found [%s] (%4.4s)", AcpiUtGetTypeName (Node->Type), Node->Name.Ascii)); return_ACPI_STATUS (AE_AML_TARGET_TYPE); default: break; } } /* * Resolve the source object to an actual value * (If it is a reference object) */ Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Do the actual store operation */ switch (TargetType) { /* * The simple data types all support implicit source operand * conversion before the store. */ case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: if ((WalkState->Opcode == AML_COPY_OBJECT_OP) || !ImplicitConversion) { /* * However, CopyObject and Stores to ArgX do not perform * an implicit conversion, as per the ACPI specification. * A direct store is performed instead. */ Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState); break; } /* Store with implicit source operand conversion support */ Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (NewDesc != TargetDesc) { /* * Store the new NewDesc as the new value of the Name, and set * the Name's type to that of the value being stored in it. * SourceDesc reference count is incremented by AttachObject. * * Note: This may change the type of the node if an explicit * store has been performed such that the node/object type * has been changed. */ Status = AcpiNsAttachObject ( Node, NewDesc, NewDesc->Common.Type); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Store type [%s] into [%s] via Convert/Attach\n", AcpiUtGetObjectTypeName (SourceDesc), AcpiUtGetObjectTypeName (NewDesc))); } break; case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* * For all fields, always write the source data to the target * field. Any required implicit source operand conversion is * performed in the function below as necessary. Note, field * objects must retain their original type permanently. */ Status = AcpiExWriteDataToField (SourceDesc, TargetDesc, &WalkState->ResultObj); break; default: /* * CopyObject operator: No conversions for all other types. * Instead, directly store a copy of the source object. * * This is the ACPI spec-defined behavior for the CopyObject * operator. (Note, for this default case, all normal * Store/Target operations exited above with an error). */ Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState); break; } return_ACPI_STATUS (Status); }
void AcpiExDoDebugObject ( ACPI_OPERAND_OBJECT *SourceDesc, UINT32 Level, UINT32 Index) { UINT32 i; UINT32 Timer; ACPI_OPERAND_OBJECT *ObjectDesc; UINT32 Value; ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc); /* Output must be enabled via the DebugObject global or the DbgLevel */ if (!AcpiGbl_EnableAmlDebugObject && !(AcpiDbgLevel & ACPI_LV_DEBUG_OBJECT)) { return_VOID; } /* * We will emit the current timer value (in microseconds) with each * debug output. Only need the lower 26 bits. This allows for 67 * million microseconds or 67 seconds before rollover. */ Timer = ((UINT32) AcpiOsGetTimer () / 10); /* (100 nanoseconds to microseconds) */ Timer &= 0x03FFFFFF; /* * Print line header as long as we are not in the middle of an * object display */ if (!((Level > 0) && Index == 0)) { AcpiOsPrintf ("[ACPI Debug %.8u] %*s", Timer, Level, " "); } /* Display the index for package output only */ if (Index > 0) { AcpiOsPrintf ("(%.2u) ", Index-1); } if (!SourceDesc) { AcpiOsPrintf ("[Null Object]\n"); return_VOID; } if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND) { AcpiOsPrintf ("%s ", AcpiUtGetObjectTypeName (SourceDesc)); if (!AcpiUtValidInternalObject (SourceDesc)) { AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc); return_VOID; } } else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED) { AcpiOsPrintf ("%s: %p\n", AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type), SourceDesc); return_VOID; } else { return_VOID; } /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */ switch (SourceDesc->Common.Type) { case ACPI_TYPE_INTEGER: /* Output correct integer width */ if (AcpiGbl_IntegerByteWidth == 4) { AcpiOsPrintf ("0x%8.8X\n", (UINT32) SourceDesc->Integer.Value); } else { AcpiOsPrintf ("0x%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value)); } break; case ACPI_TYPE_BUFFER: AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length); AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer, (SourceDesc->Buffer.Length < 256) ? SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0); break; case ACPI_TYPE_STRING: AcpiOsPrintf ("[0x%.2X] \"%s\"\n", SourceDesc->String.Length, SourceDesc->String.Pointer); break; case ACPI_TYPE_PACKAGE: AcpiOsPrintf ("[Contains 0x%.2X Elements]\n", SourceDesc->Package.Count); /* Output the entire contents of the package */ for (i = 0; i < SourceDesc->Package.Count; i++) { AcpiExDoDebugObject (SourceDesc->Package.Elements[i], Level+4, i+1); } break; case ACPI_TYPE_LOCAL_REFERENCE: AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc)); /* Decode the reference */ switch (SourceDesc->Reference.Class) { case ACPI_REFCLASS_INDEX: AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value); break; case ACPI_REFCLASS_TABLE: /* Case for DdbHandle */ AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value); return_VOID; default: break; } AcpiOsPrintf (" "); /* Check for valid node first, then valid object */ if (SourceDesc->Reference.Node) { if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) != ACPI_DESC_TYPE_NAMED) { AcpiOsPrintf (" %p - Not a valid namespace node\n", SourceDesc->Reference.Node); } else { AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node, (SourceDesc->Reference.Node)->Name.Ascii); switch ((SourceDesc->Reference.Node)->Type) { /* These types have no attached object */ case ACPI_TYPE_DEVICE: AcpiOsPrintf ("Device\n"); break; case ACPI_TYPE_THERMAL: AcpiOsPrintf ("Thermal Zone\n"); break; default: AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object, Level+4, 0); break; } } } else if (SourceDesc->Reference.Object) { if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) == ACPI_DESC_TYPE_NAMED) { AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *) SourceDesc->Reference.Object)->Object, Level+4, 0); } else { ObjectDesc = SourceDesc->Reference.Object; Value = SourceDesc->Reference.Value; switch (ObjectDesc->Common.Type) { case ACPI_TYPE_BUFFER: AcpiOsPrintf ("Buffer[%u] = 0x%2.2X\n", Value, *SourceDesc->Reference.IndexPointer); break; case ACPI_TYPE_STRING: AcpiOsPrintf ("String[%u] = \"%c\" (0x%2.2X)\n", Value, *SourceDesc->Reference.IndexPointer, *SourceDesc->Reference.IndexPointer); break; case ACPI_TYPE_PACKAGE: AcpiOsPrintf ("Package[%u] = ", Value); AcpiExDoDebugObject (*SourceDesc->Reference.Where, Level+4, 0); break; default: AcpiOsPrintf ("Unknown Reference object type %X\n", ObjectDesc->Common.Type); break; } } } break; default: AcpiOsPrintf ("%p\n", SourceDesc); break; } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n")); return_VOID; }
ACPI_STATUS AcpiNsEvaluate ( ACPI_EVALUATE_INFO *Info) { ACPI_STATUS Status; ACPI_NAMESPACE_NODE *Node; ACPI_FUNCTION_TRACE (NsEvaluate); if (!Info) { return_ACPI_STATUS (AE_BAD_PARAMETER); } /* Initialize the return value to an invalid object */ Info->ReturnObject = NULL; Info->ParamCount = 0; /* * Get the actual namespace node for the target object. Handles these cases: * * 1) Null node, Pathname (absolute path) * 2) Node, Pathname (path relative to Node) * 3) Node, Null Pathname */ Status = AcpiNsGetNode (Info->PrefixNode, Info->Pathname, ACPI_NS_NO_UPSEARCH, &Info->ResolvedNode); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * For a method alias, we must grab the actual method node so that proper * scoping context will be established before execution. */ if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_LOCAL_METHOD_ALIAS) { Info->ResolvedNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Info->ResolvedNode->Object); } ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->Pathname, Info->ResolvedNode, AcpiNsGetAttachedObject (Info->ResolvedNode))); Node = Info->ResolvedNode; /* * Two major cases here: * * 1) The object is a control method -- execute it * 2) The object is not a method -- just return it's current value */ if (AcpiNsGetType (Info->ResolvedNode) == ACPI_TYPE_METHOD) { /* * 1) Object is a control method - execute it */ /* Verify that there is a method object associated with this node */ Info->ObjDesc = AcpiNsGetAttachedObject (Info->ResolvedNode); if (!Info->ObjDesc) { ACPI_ERROR ((AE_INFO, "Control method has no attached sub-object")); return_ACPI_STATUS (AE_NULL_OBJECT); } /* Count the number of arguments being passed to the method */ if (Info->Parameters) { while (Info->Parameters[Info->ParamCount]) { if (Info->ParamCount > ACPI_METHOD_MAX_ARG) { return_ACPI_STATUS (AE_LIMIT); } Info->ParamCount++; } } ACPI_DUMP_PATHNAME (Info->ResolvedNode, "ACPI: Execute Method", ACPI_LV_INFO, _COMPONENT); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n", Info->ObjDesc->Method.AmlStart + 1, Info->ObjDesc->Method.AmlLength - 1)); /* * Any namespace deletion must acquire both the namespace and * interpreter locks to ensure that no thread is using the portion of * the namespace that is being deleted. * * Execute the method via the interpreter. The interpreter is locked * here before calling into the AML parser */ AcpiExEnterInterpreter (); Status = AcpiPsExecuteMethod (Info); AcpiExExitInterpreter (); } else { /* * 2) Object is not a method, return its current value * * Disallow certain object types. For these, "evaluation" is undefined. */ switch (Info->ResolvedNode->Type) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_EVENT: case ACPI_TYPE_MUTEX: case ACPI_TYPE_REGION: case ACPI_TYPE_THERMAL: case ACPI_TYPE_LOCAL_SCOPE: ACPI_ERROR ((AE_INFO, "[%4.4s] Evaluation of object type [%s] is not supported", Info->ResolvedNode->Name.Ascii, AcpiUtGetTypeName (Info->ResolvedNode->Type))); return_ACPI_STATUS (AE_TYPE); default: break; } /* * Objects require additional resolution steps (e.g., the Node may be * a field that must be read, etc.) -- we can't just grab the object * out of the node. * * Use ResolveNodeToValue() to get the associated value. * * NOTE: we can get away with passing in NULL for a walk state because * ResolvedNode is guaranteed to not be a reference to either a method * local or a method argument (because this interface is never called * from a running method.) * * Even though we do not directly invoke the interpreter for object * resolution, we must lock it because we could access an opregion. * The opregion access code assumes that the interpreter is locked. */ AcpiExEnterInterpreter (); /* Function has a strange interface */ Status = AcpiExResolveNodeToValue (&Info->ResolvedNode, NULL); AcpiExExitInterpreter (); /* * If AcpiExResolveNodeToValue() succeeded, the return value was placed * in ResolvedNode. */ if (ACPI_SUCCESS (Status)) { Status = AE_CTRL_RETURN_VALUE; Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->ResolvedNode); ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n", Info->ReturnObject, AcpiUtGetObjectTypeName (Info->ReturnObject))); } } /* * Check input argument count against the ASL-defined count for a method. * Also check predefined names: argument count and return value against * the ACPI specification. Some incorrect return value types are repaired. */ (void) AcpiNsCheckPredefinedNames (Node, Info->ParamCount, Status, &Info->ReturnObject); /* Check if there is a return value that must be dealt with */ if (Status == AE_CTRL_RETURN_VALUE) { /* If caller does not want the return value, delete it */ if (Info->Flags & ACPI_IGNORE_RETURN_VALUE) { AcpiUtRemoveReference (Info->ReturnObject); Info->ReturnObject = NULL; } /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ Status = AE_OK; } ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed evaluation of object %s ***\n", Info->Pathname)); /* * Namespace was unlocked by the handling AcpiNs* function, so we * just return */ return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExStoreObjectToNode ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_NAMESPACE_NODE *Node, ACPI_WALK_STATE *WalkState, UINT8 ImplicitConversion) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *TargetDesc; ACPI_OPERAND_OBJECT *NewDesc; ACPI_OBJECT_TYPE TargetType; ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc); /* Get current type of the node, and object attached to Node */ TargetType = AcpiNsGetType (Node); TargetDesc = AcpiNsGetAttachedObject (Node); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p (%s) to node %p (%s)\n", SourceDesc, AcpiUtGetObjectTypeName (SourceDesc), Node, AcpiUtGetTypeName (TargetType))); /* * Resolve the source object to an actual value * (If it is a reference object) */ Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Do the actual store operation */ switch (TargetType) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * The simple data types all support implicit source operand * conversion before the store. */ if ((WalkState->Opcode == AML_COPY_OP) || !ImplicitConversion) { /* * However, CopyObject and Stores to ArgX do not perform * an implicit conversion, as per the ACPI specification. * A direct store is performed instead. */ Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState); break; } /* Store with implicit source operand conversion support */ Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (NewDesc != TargetDesc) { /* * Store the new NewDesc as the new value of the Name, and set * the Name's type to that of the value being stored in it. * SourceDesc reference count is incremented by AttachObject. * * Note: This may change the type of the node if an explicit * store has been performed such that the node/object type * has been changed. */ Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Store %s into %s via Convert/Attach\n", AcpiUtGetObjectTypeName (SourceDesc), AcpiUtGetObjectTypeName (NewDesc))); } break; case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* * For all fields, always write the source data to the target * field. Any required implicit source operand conversion is * performed in the function below as necessary. Note, field * objects must retain their original type permanently. */ Status = AcpiExWriteDataToField (SourceDesc, TargetDesc, &WalkState->ResultObj); break; default: /* * No conversions for all other types. Directly store a copy of * the source object. This is the ACPI spec-defined behavior for * the CopyObject operator. * * NOTE: For the Store operator, this is a departure from the * ACPI spec, which states "If conversion is impossible, abort * the running control method". Instead, this code implements * "If conversion is impossible, treat the Store operation as * a CopyObject". */ Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState); break; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExStoreObjectToNode ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_NAMESPACE_NODE *Node, ACPI_WALK_STATE *WalkState, UINT8 ImplicitConversion) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *TargetDesc; ACPI_OPERAND_OBJECT *NewDesc; ACPI_OBJECT_TYPE TargetType; ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc); /* Get current type of the node, and object attached to Node */ TargetType = AcpiNsGetType (Node); TargetDesc = AcpiNsGetAttachedObject (Node); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n", SourceDesc, AcpiUtGetObjectTypeName (SourceDesc), Node, AcpiUtGetTypeName (TargetType))); /* * Resolve the source object to an actual value * (If it is a reference object) */ Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* If no implicit conversion, drop into the default case below */ if ((!ImplicitConversion) || ((WalkState->Opcode == AML_COPY_OP) && (TargetType != ACPI_TYPE_LOCAL_REGION_FIELD) && (TargetType != ACPI_TYPE_LOCAL_BANK_FIELD) && (TargetType != ACPI_TYPE_LOCAL_INDEX_FIELD))) { /* * Force execution of default (no implicit conversion). Note: * CopyObject does not perform an implicit conversion, as per the ACPI * spec -- except in case of region/bank/index fields -- because these * objects must retain their original type permanently. */ TargetType = ACPI_TYPE_ANY; } /* Do the actual store operation */ switch (TargetType) { case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* For fields, copy the source data to the target field. */ Status = AcpiExWriteDataToField (SourceDesc, TargetDesc, &WalkState->ResultObj); break; case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * These target types are all of type Integer/String/Buffer, and * therefore support implicit conversion before the store. * * Copy and/or convert the source object to a new target object */ Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, &NewDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (NewDesc != TargetDesc) { /* * Store the new NewDesc as the new value of the Name, and set * the Name's type to that of the value being stored in it. * SourceDesc reference count is incremented by AttachObject. * * Note: This may change the type of the node if an explicit store * has been performed such that the node/object type has been * changed. */ Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Store %s into %s via Convert/Attach\n", AcpiUtGetObjectTypeName (SourceDesc), AcpiUtGetObjectTypeName (NewDesc))); } break; default: ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %s (%p) directly into node (%p) with no implicit conversion\n", AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node)); /* No conversions for all other types. Just attach the source object */ Status = AcpiNsAttachObject (Node, SourceDesc, SourceDesc->Common.Type); break; } return_ACPI_STATUS (Status); }
static ACPI_STATUS AcpiExSetupRegion ( ACPI_OPERAND_OBJECT *ObjDesc, UINT32 FieldDatumByteOffset) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *RgnDesc; UINT8 SpaceId; ACPI_FUNCTION_TRACE_U32 (ExSetupRegion, FieldDatumByteOffset); RgnDesc = ObjDesc->CommonField.RegionObj; /* We must have a valid region */ if (RgnDesc->Common.Type != ACPI_TYPE_REGION) { ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)", RgnDesc->Common.Type, AcpiUtGetObjectTypeName (RgnDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } SpaceId = RgnDesc->Region.SpaceId; /* Validate the Space ID */ if (!AcpiIsValidSpaceId (SpaceId)) { ACPI_ERROR ((AE_INFO, "Invalid/unknown Address Space ID: 0x%2.2X", SpaceId)); return_ACPI_STATUS (AE_AML_INVALID_SPACE_ID); } /* * If the Region Address and Length have not been previously evaluated, * evaluate them now and save the results. */ if (!(RgnDesc->Common.Flags & AOPOBJ_DATA_VALID)) { Status = AcpiDsGetRegionArguments (RgnDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* * Exit now for SMBus, GSBus or IPMI address space, it has a non-linear * address space and the request cannot be directly validated */ if (SpaceId == ACPI_ADR_SPACE_SMBUS || SpaceId == ACPI_ADR_SPACE_GSBUS || SpaceId == ACPI_ADR_SPACE_IPMI) { /* SMBus or IPMI has a non-linear address space */ return_ACPI_STATUS (AE_OK); } #ifdef ACPI_UNDER_DEVELOPMENT /* * If the Field access is AnyAcc, we can now compute the optimal * access (because we know know the length of the parent region) */ if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)) { if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } #endif /* * Validate the request. The entire request from the byte offset for a * length of one field datum (access width) must fit within the region. * (Region length is specified in bytes) */ if (RgnDesc->Region.Length < (ObjDesc->CommonField.BaseByteOffset + FieldDatumByteOffset + ObjDesc->CommonField.AccessByteWidth)) { if (AcpiGbl_EnableInterpreterSlack) { /* * Slack mode only: We will go ahead and allow access to this * field if it is within the region length rounded up to the next * access width boundary. ACPI_SIZE cast for 64-bit compile. */ if (ACPI_ROUND_UP (RgnDesc->Region.Length, ObjDesc->CommonField.AccessByteWidth) >= ((ACPI_SIZE) ObjDesc->CommonField.BaseByteOffset + ObjDesc->CommonField.AccessByteWidth + FieldDatumByteOffset)) { return_ACPI_STATUS (AE_OK); } } if (RgnDesc->Region.Length < ObjDesc->CommonField.AccessByteWidth) { /* * This is the case where the AccessType (AccWord, etc.) is wider * than the region itself. For example, a region of length one * byte, and a field with Dword access specified. */ ACPI_ERROR ((AE_INFO, "Field [%4.4s] access width (%u bytes) " "too large for region [%4.4s] (length %u)", AcpiUtGetNodeName (ObjDesc->CommonField.Node), ObjDesc->CommonField.AccessByteWidth, AcpiUtGetNodeName (RgnDesc->Region.Node), RgnDesc->Region.Length)); } /* * Offset rounded up to next multiple of field width * exceeds region length, indicate an error */ ACPI_ERROR ((AE_INFO, "Field [%4.4s] Base+Offset+Width %u+%u+%u " "is beyond end of region [%4.4s] (length %u)", AcpiUtGetNodeName (ObjDesc->CommonField.Node), ObjDesc->CommonField.BaseByteOffset, FieldDatumByteOffset, ObjDesc->CommonField.AccessByteWidth, AcpiUtGetNodeName (RgnDesc->Region.Node), RgnDesc->Region.Length)); return_ACPI_STATUS (AE_AML_REGION_LIMIT); } return_ACPI_STATUS (AE_OK); }
ACPI_STATUS AcpiExStoreObjectToObject ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *DestDesc, ACPI_OPERAND_OBJECT **NewDesc, ACPI_WALK_STATE *WalkState) { ACPI_OPERAND_OBJECT *ActualSrcDesc; ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToObject, SourceDesc); ActualSrcDesc = SourceDesc; if (!DestDesc) { /* * There is no destination object (An uninitialized node or * package element), so we can simply copy the source object * creating a new destination object */ Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, NewDesc, WalkState); return_ACPI_STATUS (Status); } if (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_GET_OBJECT_TYPE (DestDesc)) { /* * The source type does not match the type of the destination. * Perform the "implicit conversion" of the source to the current type * of the target as per the ACPI specification. * * If no conversion performed, ActualSrcDesc = SourceDesc. * Otherwise, ActualSrcDesc is a temporary object to hold the * converted object. */ Status = AcpiExConvertToTargetType (ACPI_GET_OBJECT_TYPE (DestDesc), SourceDesc, &ActualSrcDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (SourceDesc == ActualSrcDesc) { /* * No conversion was performed. Return the SourceDesc as the * new object. */ *NewDesc = SourceDesc; return_ACPI_STATUS (AE_OK); } } /* * We now have two objects of identical types, and we can perform a * copy of the *value* of the source object. */ switch (ACPI_GET_OBJECT_TYPE (DestDesc)) { case ACPI_TYPE_INTEGER: DestDesc->Integer.Value = ActualSrcDesc->Integer.Value; /* Truncate value if we are executing from a 32-bit ACPI table */ AcpiExTruncateFor32bitTable (DestDesc); break; case ACPI_TYPE_STRING: Status = AcpiExStoreStringToString (ActualSrcDesc, DestDesc); break; case ACPI_TYPE_BUFFER: Status = AcpiExStoreBufferToBuffer (ActualSrcDesc, DestDesc); break; case ACPI_TYPE_PACKAGE: Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, &DestDesc, WalkState); break; default: /* * All other types come here. */ ACPI_WARNING ((AE_INFO, "Store into type %s not implemented", AcpiUtGetObjectTypeName (DestDesc))); Status = AE_NOT_IMPLEMENTED; break; } if (ActualSrcDesc != SourceDesc) { /* Delete the intermediate (temporary) source object */ AcpiUtRemoveReference (ActualSrcDesc); } *NewDesc = DestDesc; return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExResolveObject ( ACPI_OPERAND_OBJECT **SourceDescPtr, ACPI_OBJECT_TYPE TargetType, ACPI_WALK_STATE *WalkState) { ACPI_OPERAND_OBJECT *SourceDesc = *SourceDescPtr; ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE (ExResolveObject); /* Ensure we have a Target that can be stored to */ switch (TargetType) { case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* * These cases all require only Integers or values that * can be converted to Integers (Strings or Buffers) */ case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* * Stores into a Field/Region or into a Integer/Buffer/String * are all essentially the same. This case handles the * "interchangeable" types Integer, String, and Buffer. */ if (ACPI_GET_OBJECT_TYPE (SourceDesc) == ACPI_TYPE_LOCAL_REFERENCE) { /* Resolve a reference object first */ Status = AcpiExResolveToValue (SourceDescPtr, WalkState); if (ACPI_FAILURE (Status)) { break; } } /* For CopyObject, no further validation necessary */ if (WalkState->Opcode == AML_COPY_OP) { break; } /* Must have a Integer, Buffer, or String */ if ((ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_INTEGER) && (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_BUFFER) && (ACPI_GET_OBJECT_TYPE (SourceDesc) != ACPI_TYPE_STRING) && !((ACPI_GET_OBJECT_TYPE (SourceDesc) == ACPI_TYPE_LOCAL_REFERENCE) && (SourceDesc->Reference.Opcode == AML_LOAD_OP))) { /* Conversion successful but still not a valid type */ ACPI_ERROR ((AE_INFO, "Cannot assign type %s to %s (must be type Int/Str/Buf)", AcpiUtGetObjectTypeName (SourceDesc), AcpiUtGetTypeName (TargetType))); Status = AE_AML_OPERAND_TYPE; } break; case ACPI_TYPE_LOCAL_ALIAS: case ACPI_TYPE_LOCAL_METHOD_ALIAS: /* * All aliases should have been resolved earlier, during the * operand resolution phase. */ ACPI_ERROR ((AE_INFO, "Store into an unresolved Alias object")); Status = AE_AML_INTERNAL; break; case ACPI_TYPE_PACKAGE: default: /* * All other types than Alias and the various Fields come here, * including the untyped case - ACPI_TYPE_ANY. */ break; } return_ACPI_STATUS (Status); }
ACPI_STATUS OpcAmlConstantWalk ( ACPI_PARSE_OBJECT *Op, UINT32 Level, void *Context) { ACPI_WALK_STATE *WalkState; ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_PARSE_OBJECT *RootOp; ACPI_PARSE_OBJECT *OriginalParentOp; UINT8 WalkType; /* * Only interested in subtrees that could possibly contain * expressions that can be evaluated at this time */ if ((!(Op->Asl.CompileFlags & NODE_COMPILE_TIME_CONST)) || (Op->Asl.CompileFlags & NODE_IS_TARGET)) { return (AE_OK); } /* Set the walk type based on the reduction used for this op */ if (Op->Asl.CompileFlags & NODE_IS_TERM_ARG) { /* Op is a TermArg, constant folding is merely optional */ if (!Gbl_FoldConstants) { return (AE_CTRL_DEPTH); } WalkType = ACPI_WALK_CONST_OPTIONAL; } else { /* Op is a DataObject, the expression MUST reduced to a constant */ WalkType = ACPI_WALK_CONST_REQUIRED; } /* Create a new walk state */ WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL); if (!WalkState) { return (AE_NO_MEMORY); } WalkState->NextOp = NULL; WalkState->Params = NULL; WalkState->WalkType = WalkType; WalkState->CallerReturnDesc = &ObjDesc; /* * Examine the entire subtree -- all nodes must be constants * or type 3/4/5 opcodes */ Status = TrWalkParseTree (Op, ASL_WALK_VISIT_DOWNWARD, OpcAmlCheckForConstant, NULL, WalkState); /* * Did we find an entire subtree that contains all constants and type 3/4/5 * opcodes? (Only AE_OK or AE_TYPE returned from above) */ if (Status == AE_TYPE) { /* Subtree cannot be reduced to a constant */ if (WalkState->WalkType == ACPI_WALK_CONST_OPTIONAL) { AcpiDsDeleteWalkState (WalkState); return (AE_OK); } /* Don't descend any further, and use a default "constant" value */ Status = AE_CTRL_DEPTH; } else { /* Subtree can be reduced */ /* Allocate a new temporary root for this subtree */ RootOp = TrAllocateNode (PARSEOP_INTEGER); if (!RootOp) { return (AE_NO_MEMORY); } RootOp->Common.AmlOpcode = AML_INT_EVAL_SUBTREE_OP; OriginalParentOp = Op->Common.Parent; Op->Common.Parent = RootOp; /* Hand off the subtree to the AML interpreter */ Status = TrWalkParseTree (Op, ASL_WALK_VISIT_TWICE, OpcAmlEvaluationWalk1, OpcAmlEvaluationWalk2, WalkState); Op->Common.Parent = OriginalParentOp; /* TBD: we really *should* release the RootOp node */ if (ACPI_SUCCESS (Status)) { TotalFolds++; /* Get the final result */ Status = AcpiDsResultPop (&ObjDesc, WalkState); } /* Check for error from the ACPICA core */ if (ACPI_FAILURE (Status)) { AslCoreSubsystemError (Op, Status, "Failure during constant evaluation", FALSE); } } if (ACPI_FAILURE (Status)) { /* We could not resolve the subtree for some reason */ AslError (ASL_ERROR, ASL_MSG_CONSTANT_EVALUATION, Op, Op->Asl.ParseOpName); /* Set the subtree value to ZERO anyway. Eliminates further errors */ OpcUpdateIntegerNode (Op, 0); } else { AslError (ASL_OPTIMIZATION, ASL_MSG_CONSTANT_FOLDED, Op, Op->Asl.ParseOpName); /* * Because we know we executed type 3/4/5 opcodes above, we know that * the result must be either an Integer, String, or Buffer. */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_INTEGER: OpcUpdateIntegerNode (Op, ObjDesc->Integer.Value); DbgPrint (ASL_PARSE_OUTPUT, "Constant expression reduced to (%s) %8.8X%8.8X\n", Op->Asl.ParseOpName, ACPI_FORMAT_UINT64 (Op->Common.Value.Integer)); break; case ACPI_TYPE_STRING: Op->Asl.ParseOpcode = PARSEOP_STRING_LITERAL; Op->Common.AmlOpcode = AML_STRING_OP; Op->Asl.AmlLength = ACPI_STRLEN (ObjDesc->String.Pointer) + 1; Op->Common.Value.String = ObjDesc->String.Pointer; DbgPrint (ASL_PARSE_OUTPUT, "Constant expression reduced to (STRING) %s\n", Op->Common.Value.String); break; case ACPI_TYPE_BUFFER: Op->Asl.ParseOpcode = PARSEOP_BUFFER; Op->Common.AmlOpcode = AML_BUFFER_OP; Op->Asl.CompileFlags = NODE_AML_PACKAGE; UtSetParseOpName (Op); /* Child node is the buffer length */ RootOp = TrAllocateNode (PARSEOP_INTEGER); RootOp->Asl.AmlOpcode = AML_DWORD_OP; RootOp->Asl.Value.Integer = ObjDesc->Buffer.Length; RootOp->Asl.Parent = Op; (void) OpcSetOptimalIntegerSize (RootOp); Op->Asl.Child = RootOp; Op = RootOp; UtSetParseOpName (Op); /* Peer to the child is the raw buffer data */ RootOp = TrAllocateNode (PARSEOP_RAW_DATA); RootOp->Asl.AmlOpcode = AML_RAW_DATA_BUFFER; RootOp->Asl.AmlLength = ObjDesc->Buffer.Length; RootOp->Asl.Value.String = (char *) ObjDesc->Buffer.Pointer; RootOp->Asl.Parent = Op->Asl.Parent; Op->Asl.Next = RootOp; Op = RootOp; DbgPrint (ASL_PARSE_OUTPUT, "Constant expression reduced to (BUFFER) length %X\n", ObjDesc->Buffer.Length); break; default: printf ("Unsupported return type: %s\n", AcpiUtGetObjectTypeName (ObjDesc)); break; } } UtSetParseOpName (Op); Op->Asl.Child = NULL; AcpiDsDeleteWalkState (WalkState); return (AE_CTRL_DEPTH); }
ACPI_STATUS AcpiExStore ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *DestDesc, ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *RefDesc = DestDesc; ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc); /* Validate parameters */ if (!SourceDesc || !DestDesc) { ACPI_ERROR ((AE_INFO, "Null parameter")); return_ACPI_STATUS (AE_AML_NO_OPERAND); } /* DestDesc can be either a namespace node or an ACPI object */ if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED) { /* * Dest is a namespace node, * Storing an object into a Named node. */ Status = AcpiExStoreObjectToNode (SourceDesc, (ACPI_NAMESPACE_NODE *) DestDesc, WalkState, ACPI_IMPLICIT_CONVERSION); return_ACPI_STATUS (Status); } /* Destination object must be a Reference or a Constant object */ switch (DestDesc->Common.Type) { case ACPI_TYPE_LOCAL_REFERENCE: break; case ACPI_TYPE_INTEGER: /* Allow stores to Constants -- a Noop as per ACPI spec */ if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT) { return_ACPI_STATUS (AE_OK); } /*lint -fallthrough */ default: /* Destination is not a Reference object */ ACPI_ERROR ((AE_INFO, "Target is not a Reference or Constant object - [%s] %p", AcpiUtGetObjectTypeName (DestDesc), DestDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* * Examine the Reference class. These cases are handled: * * 1) Store to Name (Change the object associated with a name) * 2) Store to an indexed area of a Buffer or Package * 3) Store to a Method Local or Arg * 4) Store to the debug object */ switch (RefDesc->Reference.Class) { case ACPI_REFCLASS_REFOF: /* Storing an object into a Name "container" */ Status = AcpiExStoreObjectToNode (SourceDesc, RefDesc->Reference.Object, WalkState, ACPI_IMPLICIT_CONVERSION); break; case ACPI_REFCLASS_INDEX: /* Storing to an Index (pointer into a packager or buffer) */ Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState); break; case ACPI_REFCLASS_LOCAL: case ACPI_REFCLASS_ARG: /* Store to a method local/arg */ Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Class, RefDesc->Reference.Value, SourceDesc, WalkState); break; case ACPI_REFCLASS_DEBUG: /* * Storing to the Debug object causes the value stored to be * displayed and otherwise has no effect -- see ACPI Specification */ ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Write to Debug Object: Object %p [%s] ****:\n\n", SourceDesc, AcpiUtGetObjectTypeName (SourceDesc))); ACPI_DEBUG_OBJECT (SourceDesc, 0, 0); break; default: ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X", RefDesc->Reference.Class)); ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_INFO); Status = AE_AML_INTERNAL; break; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExResolveNodeToValue ( ACPI_NAMESPACE_NODE **ObjectPtr, ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *SourceDesc; ACPI_OPERAND_OBJECT *ObjDesc = NULL; ACPI_NAMESPACE_NODE *Node; ACPI_OBJECT_TYPE EntryType; ACPI_FUNCTION_TRACE (ExResolveNodeToValue); /* * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the * object that is attached to the Node. */ Node = *ObjectPtr; SourceDesc = AcpiNsGetAttachedObject (Node); EntryType = AcpiNsGetType ((ACPI_HANDLE) Node); ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", Node, SourceDesc, AcpiUtGetTypeName (EntryType))); if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) || (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { /* There is always exactly one level of indirection */ Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object); SourceDesc = AcpiNsGetAttachedObject (Node); EntryType = AcpiNsGetType ((ACPI_HANDLE) Node); *ObjectPtr = Node; } /* * Several object types require no further processing: * 1) Device/Thermal objects don't have a "real" subobject, return the Node * 2) Method locals and arguments have a pseudo-Node * 3) 10/2007: Added method type to assist with Package construction. */ if ((EntryType == ACPI_TYPE_DEVICE) || (EntryType == ACPI_TYPE_THERMAL) || (EntryType == ACPI_TYPE_METHOD) || (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) { return_ACPI_STATUS (AE_OK); } if (!SourceDesc) { ACPI_ERROR ((AE_INFO, "No object attached to node %p", Node)); return_ACPI_STATUS (AE_AML_NO_OPERAND); } /* * Action is based on the type of the Node, which indicates the type * of the attached object or pointer */ switch (EntryType) { case ACPI_TYPE_PACKAGE: if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE) { ACPI_ERROR ((AE_INFO, "Object not a Package, type %s", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } Status = AcpiDsGetPackageArguments (SourceDesc); if (ACPI_SUCCESS (Status)) { /* Return an additional reference to the object */ ObjDesc = SourceDesc; AcpiUtAddReference (ObjDesc); } break; case ACPI_TYPE_BUFFER: if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER) { ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } Status = AcpiDsGetBufferArguments (SourceDesc); if (ACPI_SUCCESS (Status)) { /* Return an additional reference to the object */ ObjDesc = SourceDesc; AcpiUtAddReference (ObjDesc); } break; case ACPI_TYPE_STRING: if (SourceDesc->Common.Type != ACPI_TYPE_STRING) { ACPI_ERROR ((AE_INFO, "Object not a String, type %s", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* Return an additional reference to the object */ ObjDesc = SourceDesc; AcpiUtAddReference (ObjDesc); break; case ACPI_TYPE_INTEGER: if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER) { ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* Return an additional reference to the object */ ObjDesc = SourceDesc; AcpiUtAddReference (ObjDesc); break; case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead Node=%p SourceDesc=%p Type=%X\n", Node, SourceDesc, EntryType)); Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc); break; /* For these objects, just return the object attached to the Node */ case ACPI_TYPE_MUTEX: case ACPI_TYPE_POWER: case ACPI_TYPE_PROCESSOR: case ACPI_TYPE_EVENT: case ACPI_TYPE_REGION: /* Return an additional reference to the object */ ObjDesc = SourceDesc; AcpiUtAddReference (ObjDesc); break; /* TYPE_ANY is untyped, and thus there is no object associated with it */ case ACPI_TYPE_ANY: ACPI_ERROR ((AE_INFO, "Untyped entry %p, no attached object!", Node)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ case ACPI_TYPE_LOCAL_REFERENCE: switch (SourceDesc->Reference.Class) { case ACPI_REFCLASS_TABLE: /* This is a DdbHandle */ case ACPI_REFCLASS_REFOF: case ACPI_REFCLASS_INDEX: /* Return an additional reference to the object */ ObjDesc = SourceDesc; AcpiUtAddReference (ObjDesc); break; default: /* No named references are allowed here */ ACPI_ERROR ((AE_INFO, "Unsupported Reference type 0x%X", SourceDesc->Reference.Class)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } break; default: /* Default case is for unknown types */ ACPI_ERROR ((AE_INFO, "Node %p - Unknown object type 0x%X", Node, EntryType)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* switch (EntryType) */ /* Return the object descriptor */ *ObjectPtr = (void *) ObjDesc; return_ACPI_STATUS (Status); }
static ACPI_STATUS AcpiExStoreObjectToIndex ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *IndexDesc, ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_OPERAND_OBJECT *NewDesc; UINT8 Value = 0; UINT32 i; ACPI_FUNCTION_TRACE (ExStoreObjectToIndex); /* * Destination must be a reference pointer, and * must point to either a buffer or a package */ switch (IndexDesc->Reference.TargetType) { case ACPI_TYPE_PACKAGE: /* * Storing to a package element. Copy the object and replace * any existing object with the new object. No implicit * conversion is performed. * * The object at *(IndexDesc->Reference.Where) is the * element within the package that is to be modified. * The parent package object is at IndexDesc->Reference.Object */ ObjDesc = *(IndexDesc->Reference.Where); if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE && SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE) { /* This is a DDBHandle, just add a reference to it */ AcpiUtAddReference (SourceDesc); NewDesc = SourceDesc; } else { /* Normal object, copy it */ Status = AcpiUtCopyIobjectToIobject ( SourceDesc, &NewDesc, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } if (ObjDesc) { /* Decrement reference count by the ref count of the parent package */ for (i = 0; i < ((ACPI_OPERAND_OBJECT *) IndexDesc->Reference.Object)->Common.ReferenceCount; i++) { AcpiUtRemoveReference (ObjDesc); } } *(IndexDesc->Reference.Where) = NewDesc; /* Increment ref count by the ref count of the parent package-1 */ for (i = 1; i < ((ACPI_OPERAND_OBJECT *) IndexDesc->Reference.Object)->Common.ReferenceCount; i++) { AcpiUtAddReference (NewDesc); } break; case ACPI_TYPE_BUFFER_FIELD: /* * Store into a Buffer or String (not actually a real BufferField) * at a location defined by an Index. * * The first 8-bit element of the source object is written to the * 8-bit Buffer location defined by the Index destination object, * according to the ACPI 2.0 specification. */ /* * Make sure the target is a Buffer or String. An error should * not happen here, since the ReferenceObject was constructed * by the INDEX_OP code. */ ObjDesc = IndexDesc->Reference.Object; if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) && (ObjDesc->Common.Type != ACPI_TYPE_STRING)) { return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* * The assignment of the individual elements will be slightly * different for each source type. */ switch (SourceDesc->Common.Type) { case ACPI_TYPE_INTEGER: /* Use the least-significant byte of the integer */ Value = (UINT8) (SourceDesc->Integer.Value); break; case ACPI_TYPE_BUFFER: case ACPI_TYPE_STRING: /* Note: Takes advantage of common string/buffer fields */ Value = SourceDesc->Buffer.Pointer[0]; break; default: /* All other types are invalid */ ACPI_ERROR ((AE_INFO, "Source must be type [Integer/Buffer/String], found [%s]", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* Store the source value into the target buffer byte */ ObjDesc->Buffer.Pointer[IndexDesc->Reference.Value] = Value; break; default: ACPI_ERROR ((AE_INFO, "Target is not of type [Package/BufferField]")); Status = AE_AML_TARGET_TYPE; break; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExWriteDataToField ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc) { ACPI_STATUS Status; UINT32 Length; void *Buffer; ACPI_OPERAND_OBJECT *BufferDesc; UINT32 Function; UINT16 AccessorType; ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc); /* Parameter validation */ if (!SourceDesc || !ObjDesc) { return_ACPI_STATUS (AE_AML_NO_OPERAND); } 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 write. We will bypass the entire * field mechanism and handoff the buffer directly to the handler. * For these address spaces, the buffer is bi-directional; on a * write, return data is returned in the same buffer. * * Source must be a buffer of sufficient size: * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or * ACPI_IPMI_BUFFER_SIZE. * * Note: SMBus and GSBus protocol type is passed in upper 16-bits * of Function */ if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER) { ACPI_ERROR ((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires " "Buffer, found type %s", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS) { Length = ACPI_SMBUS_BUFFER_SIZE; Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16); } else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) { AccessorType = ObjDesc->Field.Attribute; Length = AcpiExGetSerialAccessLength ( AccessorType, ObjDesc->Field.AccessLength); /* * Add additional 2 bytes for the GenericSerialBus data buffer: * * Status; (Byte 0 of the data buffer) * Length; (Byte 1 of the data buffer) * Data[x-1]: (Bytes 2-x of the arbitrary length data buffer) */ Length += 2; Function = ACPI_WRITE | (AccessorType << 16); } else /* IPMI */ { Length = ACPI_IPMI_BUFFER_SIZE; Function = ACPI_WRITE; } if (SourceDesc->Buffer.Length < Length) { ACPI_ERROR ((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires " "Buffer of length %u, found length %u", Length, SourceDesc->Buffer.Length)); return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); } /* Create the bi-directional buffer */ BufferDesc = AcpiUtCreateBufferObject (Length); if (!BufferDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } Buffer = BufferDesc->Buffer.Pointer; memcpy (Buffer, SourceDesc->Buffer.Pointer, Length); /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* * Perform the write (returns status and perhaps data in the * same buffer) */ Status = AcpiExAccessRegion ( ObjDesc, 0, (UINT64 *) Buffer, Function); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); *ResultDesc = BufferDesc; return_ACPI_STATUS (Status); } else if ((ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REGION_FIELD) && (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO)) { /* * For GPIO (GeneralPurposeIo), we will bypass the entire field * mechanism and handoff the bit address and bit width directly to * the handler. The Address will be the bit offset * from the previous Connection() operator, making it effectively a * pin number index. The BitLength is the length of the field, which * is thus the number of pins. */ if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER) { return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "GPIO FieldWrite [FROM]: (%s:%X), Val %.8X [TO]: Pin %u Bits %u\n", AcpiUtGetTypeName (SourceDesc->Common.Type), SourceDesc->Common.Type, (UINT32) SourceDesc->Integer.Value, ObjDesc->Field.PinNumberIndex, ObjDesc->Field.BitLength)); Buffer = &SourceDesc->Integer.Value; /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* Perform the write */ Status = AcpiExAccessRegion ( ObjDesc, 0, (UINT64 *) Buffer, ACPI_WRITE); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); return_ACPI_STATUS (Status); } /* Get a pointer to the data to be written */ switch (SourceDesc->Common.Type) { case ACPI_TYPE_INTEGER: Buffer = &SourceDesc->Integer.Value; Length = sizeof (SourceDesc->Integer.Value); break; case ACPI_TYPE_BUFFER: Buffer = SourceDesc->Buffer.Pointer; Length = SourceDesc->Buffer.Length; break; case ACPI_TYPE_STRING: Buffer = SourceDesc->String.Pointer; Length = SourceDesc->String.Length; break; default: return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n", SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type), SourceDesc->Common.Type, Buffer, Length)); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n", ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type), ObjDesc->Common.Type, ObjDesc->CommonField.BitLength, ObjDesc->CommonField.StartFieldBitOffset, ObjDesc->CommonField.BaseByteOffset)); /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* Write to the field */ Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExConvertToTargetType ( ACPI_OBJECT_TYPE DestinationType, ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT **ResultDesc, ACPI_WALK_STATE *WalkState) { ACPI_STATUS Status = AE_OK; ACPI_FUNCTION_TRACE (ExConvertToTargetType); /* Default behavior */ *ResultDesc = SourceDesc; /* * If required by the target, * perform implicit conversion on the source before we store it. */ switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs)) { case ARGI_SIMPLE_TARGET: case ARGI_FIXED_TARGET: case ARGI_INTEGER_REF: /* Handles Increment, Decrement cases */ switch (DestinationType) { case ACPI_TYPE_LOCAL_REGION_FIELD: /* * Named field can always handle conversions */ break; default: /* No conversion allowed for these types */ if (DestinationType != SourceDesc->Common.Type) { ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Explicit operator, will store (%s) over existing type (%s)\n", AcpiUtGetObjectTypeName (SourceDesc), AcpiUtGetTypeName (DestinationType))); Status = AE_TYPE; } } break; case ARGI_TARGETREF: switch (DestinationType) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: /* * These types require an Integer operand. We can convert * a Buffer or a String to an Integer if necessary. */ Status = AcpiExConvertToInteger (SourceDesc, ResultDesc, 16); break; case ACPI_TYPE_STRING: /* * The operand must be a String. We can convert an * Integer or Buffer if necessary */ Status = AcpiExConvertToString (SourceDesc, ResultDesc, ACPI_IMPLICIT_CONVERT_HEX); break; case ACPI_TYPE_BUFFER: /* * The operand must be a Buffer. We can convert an * Integer or String if necessary */ Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc); break; default: ACPI_ERROR ((AE_INFO, "Bad destination type during conversion: 0x%X", DestinationType)); Status = AE_AML_INTERNAL; break; } break; case ARGI_REFERENCE: /* * CreateXxxxField cases - we are storing the field object into the name */ break; default: ACPI_ERROR ((AE_INFO, "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s", GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs), WalkState->Opcode, AcpiUtGetTypeName (DestinationType))); Status = AE_AML_INTERNAL; } /* * Source-to-Target conversion semantics: * * If conversion to the target type cannot be performed, then simply * overwrite the target with the new object and type. */ if (Status == AE_TYPE) { Status = AE_OK; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiRsCreatePciRoutingTable ( ACPI_OPERAND_OBJECT *PackageObject, ACPI_BUFFER *OutputBuffer) { UINT8 *Buffer; ACPI_OPERAND_OBJECT **TopObjectList; ACPI_OPERAND_OBJECT **SubObjectList; ACPI_OPERAND_OBJECT *ObjDesc; ACPI_SIZE BufferSizeNeeded = 0; UINT32 NumberOfElements; UINT32 Index; ACPI_PCI_ROUTING_TABLE *UserPrt; ACPI_NAMESPACE_NODE *Node; ACPI_STATUS Status; ACPI_BUFFER PathBuffer; ACPI_FUNCTION_TRACE (RsCreatePciRoutingTable); /* Params already validated, so we don't re-validate here */ /* Get the required buffer length */ Status = AcpiRsGetPciRoutingTableLength (PackageObject, &BufferSizeNeeded); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "BufferSizeNeeded = %X\n", (UINT32) BufferSizeNeeded)); /* Validate/Allocate/Clear caller buffer */ Status = AcpiUtInitializeBuffer (OutputBuffer, BufferSizeNeeded); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* * Loop through the ACPI_INTERNAL_OBJECTS - Each object should be a * package that in turn contains an UINT64 Address, a UINT8 Pin, * a Name, and a UINT8 SourceIndex. */ TopObjectList = PackageObject->Package.Elements; NumberOfElements = PackageObject->Package.Count; Buffer = OutputBuffer->Pointer; UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer); for (Index = 0; Index < NumberOfElements; Index++) { /* * Point UserPrt past this current structure * * NOTE: On the first iteration, UserPrt->Length will * be zero because we cleared the return buffer earlier */ Buffer += UserPrt->Length; UserPrt = ACPI_CAST_PTR (ACPI_PCI_ROUTING_TABLE, Buffer); /* * Fill in the Length field with the information we have at this point. * The minus four is to subtract the size of the UINT8 Source[4] member * because it is added below. */ UserPrt->Length = (sizeof (ACPI_PCI_ROUTING_TABLE) - 4); /* Each subpackage must be of length 4 */ if ((*TopObjectList)->Package.Count != 4) { ACPI_ERROR ((AE_INFO, "(PRT[%u]) Need package of length 4, found length %u", Index, (*TopObjectList)->Package.Count)); return_ACPI_STATUS (AE_AML_PACKAGE_LIMIT); } /* * Dereference the subpackage. * The SubObjectList will now point to an array of the four IRQ * elements: [Address, Pin, Source, SourceIndex] */ SubObjectList = (*TopObjectList)->Package.Elements; /* 1) First subobject: Dereference the PRT.Address */ ObjDesc = SubObjectList[0]; if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) { ACPI_ERROR ((AE_INFO, "(PRT[%u].Address) Need Integer, found %s", Index, AcpiUtGetObjectTypeName (ObjDesc))); return_ACPI_STATUS (AE_BAD_DATA); } UserPrt->Address = ObjDesc->Integer.Value; /* 2) Second subobject: Dereference the PRT.Pin */ ObjDesc = SubObjectList[1]; if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) { ACPI_ERROR ((AE_INFO, "(PRT[%u].Pin) Need Integer, found %s", Index, AcpiUtGetObjectTypeName (ObjDesc))); return_ACPI_STATUS (AE_BAD_DATA); } UserPrt->Pin = (UINT32) ObjDesc->Integer.Value; /* * 3) Third subobject: Dereference the PRT.SourceName * The name may be unresolved (slack mode), so allow a null object */ ObjDesc = SubObjectList[2]; if (ObjDesc) { switch (ObjDesc->Common.Type) { case ACPI_TYPE_LOCAL_REFERENCE: if (ObjDesc->Reference.Class != ACPI_REFCLASS_NAME) { ACPI_ERROR ((AE_INFO, "(PRT[%u].Source) Need name, found Reference Class 0x%X", Index, ObjDesc->Reference.Class)); return_ACPI_STATUS (AE_BAD_DATA); } Node = ObjDesc->Reference.Node; /* Use *remaining* length of the buffer as max for pathname */ PathBuffer.Length = OutputBuffer->Length - (UINT32) ((UINT8 *) UserPrt->Source - (UINT8 *) OutputBuffer->Pointer); PathBuffer.Pointer = UserPrt->Source; Status = AcpiNsHandleToPathname ((ACPI_HANDLE) Node, &PathBuffer); /* +1 to include null terminator */ UserPrt->Length += (UINT32) ACPI_STRLEN (UserPrt->Source) + 1; break; case ACPI_TYPE_STRING: ACPI_STRCPY (UserPrt->Source, ObjDesc->String.Pointer); /* * Add to the Length field the length of the string * (add 1 for terminator) */ UserPrt->Length += ObjDesc->String.Length + 1; break; case ACPI_TYPE_INTEGER: /* * If this is a number, then the Source Name is NULL, since the * entire buffer was zeroed out, we can leave this alone. * * Add to the Length field the length of the UINT32 NULL */ UserPrt->Length += sizeof (UINT32); break; default: ACPI_ERROR ((AE_INFO, "(PRT[%u].Source) Need Ref/String/Integer, found %s", Index, AcpiUtGetObjectTypeName (ObjDesc))); return_ACPI_STATUS (AE_BAD_DATA); } } /* Now align the current length */ UserPrt->Length = (UINT32) ACPI_ROUND_UP_TO_64BIT (UserPrt->Length); /* 4) Fourth subobject: Dereference the PRT.SourceIndex */ ObjDesc = SubObjectList[3]; if (!ObjDesc || ObjDesc->Common.Type != ACPI_TYPE_INTEGER) { ACPI_ERROR ((AE_INFO, "(PRT[%u].SourceIndex) Need Integer, found %s", Index, AcpiUtGetObjectTypeName (ObjDesc))); return_ACPI_STATUS (AE_BAD_DATA); } UserPrt->SourceIndex = (UINT32) ObjDesc->Integer.Value; /* Point to the next ACPI_OPERAND_OBJECT in the top level package */ TopObjectList++; } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "OutputBuffer %p Length %X\n", OutputBuffer->Pointer, (UINT32) OutputBuffer->Length)); return_ACPI_STATUS (AE_OK); }
static ACPI_STATUS AcpiDsInitBufferField ( UINT16 AmlOpcode, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT *BufferDesc, ACPI_OPERAND_OBJECT *OffsetDesc, ACPI_OPERAND_OBJECT *LengthDesc, ACPI_OPERAND_OBJECT *ResultDesc) { UINT32 Offset; UINT32 BitOffset; UINT32 BitCount; UINT8 FieldFlags; ACPI_STATUS Status; ACPI_FUNCTION_TRACE_PTR (DsInitBufferField, ObjDesc); /* Host object must be a Buffer */ if (BufferDesc->Common.Type != ACPI_TYPE_BUFFER) { ACPI_ERROR ((AE_INFO, "Target of Create Field is not a Buffer object - %s", AcpiUtGetObjectTypeName (BufferDesc))); Status = AE_AML_OPERAND_TYPE; goto Cleanup; } /* * The last parameter to all of these opcodes (ResultDesc) started * out as a NameString, and should therefore now be a NS node * after resolution in AcpiExResolveOperands(). */ if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED) { ACPI_ERROR ((AE_INFO, "(%s) destination not a NS Node [%s]", AcpiPsGetOpcodeName (AmlOpcode), AcpiUtGetDescriptorName (ResultDesc))); Status = AE_AML_OPERAND_TYPE; goto Cleanup; } Offset = (UINT32) OffsetDesc->Integer.Value; /* * Setup the Bit offsets and counts, according to the opcode */ switch (AmlOpcode) { case AML_CREATE_FIELD_OP: /* Offset is in bits, count is in bits */ FieldFlags = AML_FIELD_ACCESS_BYTE; BitOffset = Offset; BitCount = (UINT32) LengthDesc->Integer.Value; /* Must have a valid (>0) bit count */ if (BitCount == 0) { ACPI_ERROR ((AE_INFO, "Attempt to CreateField of length zero")); Status = AE_AML_OPERAND_VALUE; goto Cleanup; } break; case AML_CREATE_BIT_FIELD_OP: /* Offset is in bits, Field is one bit */ BitOffset = Offset; BitCount = 1; FieldFlags = AML_FIELD_ACCESS_BYTE; break; case AML_CREATE_BYTE_FIELD_OP: /* Offset is in bytes, field is one byte */ BitOffset = 8 * Offset; BitCount = 8; FieldFlags = AML_FIELD_ACCESS_BYTE; break; case AML_CREATE_WORD_FIELD_OP: /* Offset is in bytes, field is one word */ BitOffset = 8 * Offset; BitCount = 16; FieldFlags = AML_FIELD_ACCESS_WORD; break; case AML_CREATE_DWORD_FIELD_OP: /* Offset is in bytes, field is one dword */ BitOffset = 8 * Offset; BitCount = 32; FieldFlags = AML_FIELD_ACCESS_DWORD; break; case AML_CREATE_QWORD_FIELD_OP: /* Offset is in bytes, field is one qword */ BitOffset = 8 * Offset; BitCount = 64; FieldFlags = AML_FIELD_ACCESS_QWORD; break; default: ACPI_ERROR ((AE_INFO, "Unknown field creation opcode 0x%02X", AmlOpcode)); Status = AE_AML_BAD_OPCODE; goto Cleanup; } /* Entire field must fit within the current length of the buffer */ if ((BitOffset + BitCount) > (8 * (UINT32) BufferDesc->Buffer.Length)) { ACPI_ERROR ((AE_INFO, "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)", AcpiUtGetNodeName (ResultDesc), BitOffset + BitCount, AcpiUtGetNodeName (BufferDesc->Buffer.Node), 8 * (UINT32) BufferDesc->Buffer.Length)); Status = AE_AML_BUFFER_LIMIT; goto Cleanup; } /* * Initialize areas of the field object that are common to all fields * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK), * UPDATE_RULE = 0 (UPDATE_PRESERVE) */ Status = AcpiExPrepCommonFieldObject (ObjDesc, FieldFlags, 0, BitOffset, BitCount); if (ACPI_FAILURE (Status)) { goto Cleanup; } ObjDesc->BufferField.BufferObj = BufferDesc; /* Reference count for BufferDesc inherits ObjDesc count */ BufferDesc->Common.ReferenceCount = (UINT16) (BufferDesc->Common.ReferenceCount + ObjDesc->Common.ReferenceCount); Cleanup: /* Always delete the operands */ AcpiUtRemoveReference (OffsetDesc); AcpiUtRemoveReference (BufferDesc); if (AmlOpcode == AML_CREATE_FIELD_OP) { AcpiUtRemoveReference (LengthDesc); } /* On failure, delete the result descriptor */ if (ACPI_FAILURE (Status)) { AcpiUtRemoveReference (ResultDesc); /* Result descriptor */ } else { /* Now the address and length are valid for this BufferField */ ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID; } return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiExWriteDataToField ( ACPI_OPERAND_OBJECT *SourceDesc, ACPI_OPERAND_OBJECT *ObjDesc, ACPI_OPERAND_OBJECT **ResultDesc) { ACPI_STATUS Status; UINT32 Length; void *Buffer; ACPI_OPERAND_OBJECT *BufferDesc; UINT32 Function; ACPI_FUNCTION_TRACE_PTR (ExWriteDataToField, ObjDesc); /* Parameter validation */ if (!SourceDesc || !ObjDesc) { return_ACPI_STATUS (AE_AML_NO_OPERAND); } 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 write. We will bypass the entire field * mechanism and handoff the buffer directly to the handler. For * these address spaces, the buffer is bi-directional; on a write, * return data is returned in the same buffer. * * Source must be a buffer of sufficient size: * ACPI_SMBUS_BUFFER_SIZE, ACPI_GSBUS_BUFFER_SIZE, or ACPI_IPMI_BUFFER_SIZE. * * Note: SMBus and GSBus protocol type is passed in upper 16-bits of Function */ if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER) { ACPI_ERROR ((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires Buffer, found type %s", AcpiUtGetObjectTypeName (SourceDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_SMBUS) { Length = ACPI_SMBUS_BUFFER_SIZE; Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16); } else if (ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) { Length = ACPI_GSBUS_BUFFER_SIZE; Function = ACPI_WRITE | (ObjDesc->Field.Attribute << 16); } else /* IPMI */ { Length = ACPI_IPMI_BUFFER_SIZE; Function = ACPI_WRITE; } if (SourceDesc->Buffer.Length < Length) { ACPI_ERROR ((AE_INFO, "SMBus/IPMI/GenericSerialBus write requires Buffer of length %u, found length %u", Length, SourceDesc->Buffer.Length)); return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); } /* Create the bi-directional buffer */ BufferDesc = AcpiUtCreateBufferObject (Length); if (!BufferDesc) { return_ACPI_STATUS (AE_NO_MEMORY); } Buffer = BufferDesc->Buffer.Pointer; ACPI_MEMCPY (Buffer, SourceDesc->Buffer.Pointer, Length); /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* * Perform the write (returns status and perhaps data in the * same buffer) */ Status = AcpiExAccessRegion (ObjDesc, 0, (UINT64 *) Buffer, Function); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); *ResultDesc = BufferDesc; return_ACPI_STATUS (Status); } /* Get a pointer to the data to be written */ switch (SourceDesc->Common.Type) { case ACPI_TYPE_INTEGER: Buffer = &SourceDesc->Integer.Value; Length = sizeof (SourceDesc->Integer.Value); break; case ACPI_TYPE_BUFFER: Buffer = SourceDesc->Buffer.Pointer; Length = SourceDesc->Buffer.Length; break; case ACPI_TYPE_STRING: Buffer = SourceDesc->String.Pointer; Length = SourceDesc->String.Length; break; default: return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "FieldWrite [FROM]: Obj %p (%s:%X), Buf %p, ByteLen %X\n", SourceDesc, AcpiUtGetTypeName (SourceDesc->Common.Type), SourceDesc->Common.Type, Buffer, Length)); ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD, "FieldWrite [TO]: Obj %p (%s:%X), BitLen %X, BitOff %X, ByteOff %X\n", ObjDesc, AcpiUtGetTypeName (ObjDesc->Common.Type), ObjDesc->Common.Type, ObjDesc->CommonField.BitLength, ObjDesc->CommonField.StartFieldBitOffset, ObjDesc->CommonField.BaseByteOffset)); /* Lock entire transaction if requested */ AcpiExAcquireGlobalLock (ObjDesc->CommonField.FieldFlags); /* Write to the field */ Status = AcpiExInsertIntoField (ObjDesc, Buffer, Length); AcpiExReleaseGlobalLock (ObjDesc->CommonField.FieldFlags); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiNsCheckObjectType ( ACPI_EVALUATE_INFO *Info, ACPI_OPERAND_OBJECT **ReturnObjectPtr, UINT32 ExpectedBtypes, UINT32 PackageIndex) { ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; ACPI_STATUS Status = AE_OK; char TypeBuffer[96]; /* Room for 10 types */ /* A Namespace node should not get here, but make sure */ if (ReturnObject && ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED) { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, "Invalid return type - Found a Namespace node [%4.4s] type %s", ReturnObject->Node.Name.Ascii, AcpiUtGetTypeName (ReturnObject->Node.Type))); return (AE_AML_OPERAND_TYPE); } /* * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type. * The bitmapped type allows multiple possible return types. * * Note, the cases below must handle all of the possible types returned * from all of the predefined names (including elements of returned * packages) */ Info->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject); if (Info->ReturnBtype == ACPI_RTYPE_ANY) { /* Not one of the supported objects, must be incorrect */ goto TypeErrorExit; } /* For reference objects, check that the reference type is correct */ if ((Info->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE) { Status = AcpiNsCheckReference (Info, ReturnObject); return (Status); } /* Attempt simple repair of the returned object if necessary */ Status = AcpiNsSimpleRepair (Info, ExpectedBtypes, PackageIndex, ReturnObjectPtr); if (ACPI_SUCCESS (Status)) { return (AE_OK); /* Successful repair */ } TypeErrorExit: /* Create a string with all expected types for this predefined object */ AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes); if (!ReturnObject) { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, "Expected return object of type %s", TypeBuffer)); } else if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT) { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, "Return type mismatch - found %s, expected %s", AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); } else { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags, "Return Package type mismatch at index %u - " "found %s, expected %s", PackageIndex, AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer)); } return (AE_AML_OPERAND_TYPE); }
ACPI_STATUS AcpiNsSimpleRepair ( ACPI_EVALUATE_INFO *Info, UINT32 ExpectedBtypes, UINT32 PackageIndex, ACPI_OPERAND_OBJECT **ReturnObjectPtr) { ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr; ACPI_OPERAND_OBJECT *NewObject = NULL; ACPI_STATUS Status; const ACPI_SIMPLE_REPAIR_INFO *Predefined; ACPI_FUNCTION_NAME (NsSimpleRepair); /* * Special repairs for certain names that are in the repair table. * Check if this name is in the list of repairable names. */ Predefined = AcpiNsMatchSimpleRepair (Info->Node, Info->ReturnBtype, PackageIndex); if (Predefined) { if (!ReturnObject) { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS, "Missing expected return value")); } Status = Predefined->ObjectConverter (Info->Node, ReturnObject, &NewObject); if (ACPI_FAILURE (Status)) { /* A fatal error occurred during a conversion */ ACPI_EXCEPTION ((AE_INFO, Status, "During return object analysis")); return (Status); } if (NewObject) { goto ObjectRepaired; } } /* * Do not perform simple object repair unless the return type is not * expected. */ if (Info->ReturnBtype & ExpectedBtypes) { return (AE_OK); } /* * At this point, we know that the type of the returned object was not * one of the expected types for this predefined name. Attempt to * repair the object by converting it to one of the expected object * types for this predefined name. */ /* * If there is no return value, check if we require a return value for * this predefined name. Either one return value is expected, or none, * for both methods and other objects. * * Try to fix if there was no return object. Warning if failed to fix. */ if (!ReturnObject) { if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE))) { if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT) { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS, "Found unexpected NULL package element")); Status = AcpiNsRepairNullElement (Info, ExpectedBtypes, PackageIndex, ReturnObjectPtr); if (ACPI_SUCCESS (Status)) { return (AE_OK); /* Repair was successful */ } } else { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS, "Missing expected return value")); } return (AE_AML_NO_RETURN_VALUE); } } if (ExpectedBtypes & ACPI_RTYPE_INTEGER) { Status = AcpiNsConvertToInteger (ReturnObject, &NewObject); if (ACPI_SUCCESS (Status)) { goto ObjectRepaired; } } if (ExpectedBtypes & ACPI_RTYPE_STRING) { Status = AcpiNsConvertToString (ReturnObject, &NewObject); if (ACPI_SUCCESS (Status)) { goto ObjectRepaired; } } if (ExpectedBtypes & ACPI_RTYPE_BUFFER) { Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject); if (ACPI_SUCCESS (Status)) { goto ObjectRepaired; } } if (ExpectedBtypes & ACPI_RTYPE_PACKAGE) { /* * A package is expected. We will wrap the existing object with a * new package object. It is often the case that if a variable-length * package is required, but there is only a single object needed, the * BIOS will return that object instead of wrapping it with a Package * object. Note: after the wrapping, the package will be validated * for correct contents (expected object type or types). */ Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject); if (ACPI_SUCCESS (Status)) { /* * The original object just had its reference count * incremented for being inserted into the new package. */ *ReturnObjectPtr = NewObject; /* New Package object */ Info->ReturnFlags |= ACPI_OBJECT_REPAIRED; return (AE_OK); } } /* We cannot repair this object */ return (AE_AML_OPERAND_TYPE); ObjectRepaired: /* Object was successfully repaired */ if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT) { /* * The original object is a package element. We need to * decrement the reference count of the original object, * for removing it from the package. * * However, if the original object was just wrapped with a * package object as part of the repair, we don't need to * change the reference count. */ if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED)) { NewObject->Common.ReferenceCount = ReturnObject->Common.ReferenceCount; if (ReturnObject->Common.ReferenceCount > 1) { ReturnObject->Common.ReferenceCount--; } } ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR, "%s: Converted %s to expected %s at Package index %u\n", Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject), AcpiUtGetObjectTypeName (NewObject), PackageIndex)); } else { ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR, "%s: Converted %s to expected %s\n", Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject), AcpiUtGetObjectTypeName (NewObject))); } /* Delete old object, install the new return object */ AcpiUtRemoveReference (ReturnObject); *ReturnObjectPtr = NewObject; Info->ReturnFlags |= ACPI_OBJECT_REPAIRED; return (AE_OK); }
ACPI_STATUS AcpiDsResultPop ( ACPI_OPERAND_OBJECT **Object, ACPI_WALK_STATE *WalkState) { UINT32 Index; ACPI_GENERIC_STATE *State; ACPI_STATUS Status; ACPI_FUNCTION_NAME (DsResultPop); State = WalkState->Results; /* Incorrect state of result stack */ if (State && !WalkState->ResultCount) { ACPI_ERROR ((AE_INFO, "No results on result stack")); return (AE_AML_INTERNAL); } if (!State && WalkState->ResultCount) { ACPI_ERROR ((AE_INFO, "No result state for result stack")); return (AE_AML_INTERNAL); } /* Empty result stack */ if (!State) { ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState)); return (AE_AML_NO_RETURN_VALUE); } /* Return object of the top element and clean that top element result stack */ WalkState->ResultCount--; Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM; *Object = State->Results.ObjDesc [Index]; if (!*Object) { ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p", WalkState)); return (AE_AML_NO_RETURN_VALUE); } State->Results.ObjDesc [Index] = NULL; if (Index == 0) { Status = AcpiDsResultStackPop (WalkState); if (ACPI_FAILURE (Status)) { return (Status); } } ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object, AcpiUtGetObjectTypeName (*Object), Index, WalkState, WalkState->ResultCount)); return (AE_OK); }
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); }
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 **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 notify 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; LastObjPtr = &HandlerDesc->AddressSpace.RegionList; /* Remove the region object from the handler's list */ while (NextDesc) { if (NextDesc == Object) { *LastObjPtr = NextDesc->Region.Next; break; } /* Walk the linked list of handler */ LastObjPtr = &NextDesc->Region.Next; NextDesc = NextDesc->Region.Next; } 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; }
ACPI_STATUS AcpiExResolveOperands ( UINT16 Opcode, ACPI_OPERAND_OBJECT **StackPtr, ACPI_WALK_STATE *WalkState) { ACPI_OPERAND_OBJECT *ObjDesc; ACPI_STATUS Status = AE_OK; UINT8 ObjectType; UINT32 ArgTypes; const ACPI_OPCODE_INFO *OpInfo; UINT32 ThisArgType; ACPI_OBJECT_TYPE TypeNeeded; UINT16 TargetOp = 0; ACPI_FUNCTION_TRACE_U32 (ExResolveOperands, Opcode); OpInfo = AcpiPsGetOpcodeInfo (Opcode); if (OpInfo->Class == AML_CLASS_UNKNOWN) { return_ACPI_STATUS (AE_AML_BAD_OPCODE); } ArgTypes = OpInfo->RuntimeArgs; if (ArgTypes == ARGI_INVALID_OPCODE) { ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X", Opcode)); return_ACPI_STATUS (AE_AML_INTERNAL); } ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode %X [%s] RequiredOperandTypes=%8.8X\n", Opcode, OpInfo->Name, ArgTypes)); /* * Normal exit is with (ArgTypes == 0) at end of argument list. * Function will return an exception from within the loop upon * finding an entry which is not (or cannot be converted * to) the required type; if stack underflows; or upon * finding a NULL stack entry (which should not happen). */ while (GET_CURRENT_ARG_TYPE (ArgTypes)) { if (!StackPtr || !*StackPtr) { ACPI_ERROR ((AE_INFO, "Null stack entry at %p", StackPtr)); return_ACPI_STATUS (AE_AML_INTERNAL); } /* Extract useful items */ ObjDesc = *StackPtr; /* Decode the descriptor type */ switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)) { case ACPI_DESC_TYPE_NAMED: /* Namespace Node */ ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type; /* * Resolve an alias object. The construction of these objects * guarantees that there is only one level of alias indirection; * thus, the attached object is always the aliased namespace node */ if (ObjectType == ACPI_TYPE_LOCAL_ALIAS) { ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc); *StackPtr = ObjDesc; ObjectType = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type; } break; case ACPI_DESC_TYPE_OPERAND: /* ACPI internal object */ ObjectType = ObjDesc->Common.Type; /* Check for bad ACPI_OBJECT_TYPE */ if (!AcpiUtValidObjectType (ObjectType)) { ACPI_ERROR ((AE_INFO, "Bad operand object type [0x%X]", ObjectType)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } if (ObjectType == (UINT8) ACPI_TYPE_LOCAL_REFERENCE) { /* Validate the Reference */ switch (ObjDesc->Reference.Class) { case ACPI_REFCLASS_DEBUG: TargetOp = AML_DEBUG_OP; /*lint -fallthrough */ case ACPI_REFCLASS_ARG: case ACPI_REFCLASS_LOCAL: case ACPI_REFCLASS_INDEX: case ACPI_REFCLASS_REFOF: case ACPI_REFCLASS_TABLE: /* DdbHandle from LOAD_OP or LOAD_TABLE_OP */ case ACPI_REFCLASS_NAME: /* Reference to a named object */ ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Operand is a Reference, Class [%s] %2.2X\n", AcpiUtGetReferenceName (ObjDesc), ObjDesc->Reference.Class)); break; default: ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X in %p", ObjDesc->Reference.Class, ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } } break; default: /* Invalid descriptor */ ACPI_ERROR ((AE_INFO, "Invalid descriptor %p [%s]", ObjDesc, AcpiUtGetDescriptorName (ObjDesc))); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } /* Get one argument type, point to the next */ ThisArgType = GET_CURRENT_ARG_TYPE (ArgTypes); INCREMENT_ARG_LIST (ArgTypes); /* * Handle cases where the object does not need to be * resolved to a value */ switch (ThisArgType) { case ARGI_REF_OR_STRING: /* Can be a String or Reference */ if ((ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_OPERAND) && (ObjDesc->Common.Type == ACPI_TYPE_STRING)) { /* * String found - the string references a named object and * must be resolved to a node */ goto NextOperand; } /* * Else not a string - fall through to the normal Reference * case below */ /*lint -fallthrough */ case ARGI_REFERENCE: /* References: */ case ARGI_INTEGER_REF: case ARGI_OBJECT_REF: case ARGI_DEVICE_REF: case ARGI_TARGETREF: /* Allows implicit conversion rules before store */ case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */ case ARGI_SIMPLE_TARGET: /* Name, Local, or Arg - no implicit conversion */ /* * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE * A Namespace Node is OK as-is */ if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) == ACPI_DESC_TYPE_NAMED) { goto NextOperand; } Status = AcpiExCheckObjectType (ACPI_TYPE_LOCAL_REFERENCE, ObjectType, ObjDesc); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } goto NextOperand; case ARGI_DATAREFOBJ: /* Store operator only */ /* * We don't want to resolve IndexOp reference objects during * a store because this would be an implicit DeRefOf operation. * Instead, we just want to store the reference object. * -- All others must be resolved below. */ if ((Opcode == AML_STORE_OP) && ((*StackPtr)->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) && ((*StackPtr)->Reference.Class == ACPI_REFCLASS_INDEX)) { goto NextOperand; } break; default: /* All cases covered above */ break; } /* * Resolve this object to a value */ Status = AcpiExResolveToValue (StackPtr, WalkState); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } /* Get the resolved object */ ObjDesc = *StackPtr; /* * Check the resulting object (value) type */ switch (ThisArgType) { /* * For the simple cases, only one type of resolved object * is allowed */ case ARGI_MUTEX: /* Need an operand of type ACPI_TYPE_MUTEX */ TypeNeeded = ACPI_TYPE_MUTEX; break; case ARGI_EVENT: /* Need an operand of type ACPI_TYPE_EVENT */ TypeNeeded = ACPI_TYPE_EVENT; break; case ARGI_PACKAGE: /* Package */ /* Need an operand of type ACPI_TYPE_PACKAGE */ TypeNeeded = ACPI_TYPE_PACKAGE; break; case ARGI_ANYTYPE: /* Any operand type will do */ TypeNeeded = ACPI_TYPE_ANY; break; case ARGI_DDBHANDLE: /* Need an operand of type ACPI_TYPE_DDB_HANDLE */ TypeNeeded = ACPI_TYPE_LOCAL_REFERENCE; break; /* * The more complex cases allow multiple resolved object types */ case ARGI_INTEGER: /* * Need an operand of type ACPI_TYPE_INTEGER, * But we can implicitly convert from a STRING or BUFFER * Aka - "Implicit Source Operand Conversion" */ Status = AcpiExConvertToInteger (ObjDesc, StackPtr, 16); if (ACPI_FAILURE (Status)) { if (Status == AE_TYPE) { ACPI_ERROR ((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } return_ACPI_STATUS (Status); } if (ObjDesc != *StackPtr) { AcpiUtRemoveReference (ObjDesc); } goto NextOperand; case ARGI_BUFFER: /* * Need an operand of type ACPI_TYPE_BUFFER, * But we can implicitly convert from a STRING or INTEGER * Aka - "Implicit Source Operand Conversion" */ Status = AcpiExConvertToBuffer (ObjDesc, StackPtr); if (ACPI_FAILURE (Status)) { if (Status == AE_TYPE) { ACPI_ERROR ((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } return_ACPI_STATUS (Status); } if (ObjDesc != *StackPtr) { AcpiUtRemoveReference (ObjDesc); } goto NextOperand; case ARGI_STRING: /* * Need an operand of type ACPI_TYPE_STRING, * But we can implicitly convert from a BUFFER or INTEGER * Aka - "Implicit Source Operand Conversion" */ Status = AcpiExConvertToString (ObjDesc, StackPtr, ACPI_IMPLICIT_CONVERT_HEX); if (ACPI_FAILURE (Status)) { if (Status == AE_TYPE) { ACPI_ERROR ((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } return_ACPI_STATUS (Status); } if (ObjDesc != *StackPtr) { AcpiUtRemoveReference (ObjDesc); } goto NextOperand; case ARGI_COMPUTEDATA: /* Need an operand of type INTEGER, STRING or BUFFER */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* Valid operand */ break; default: ACPI_ERROR ((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } goto NextOperand; case ARGI_BUFFER_OR_STRING: /* Need an operand of type STRING or BUFFER */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* Valid operand */ break; case ACPI_TYPE_INTEGER: /* Highest priority conversion is to type Buffer */ Status = AcpiExConvertToBuffer (ObjDesc, StackPtr); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } if (ObjDesc != *StackPtr) { AcpiUtRemoveReference (ObjDesc); } break; default: ACPI_ERROR ((AE_INFO, "Needed [Integer/String/Buffer], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } goto NextOperand; case ARGI_DATAOBJECT: /* * ARGI_DATAOBJECT is only used by the SizeOf operator. * Need a buffer, string, package, or RefOf reference. * * The only reference allowed here is a direct reference to * a namespace node. */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_PACKAGE: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: case ACPI_TYPE_LOCAL_REFERENCE: /* Valid operand */ break; default: ACPI_ERROR ((AE_INFO, "Needed [Buffer/String/Package/Reference], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } goto NextOperand; case ARGI_COMPLEXOBJ: /* Need a buffer or package or (ACPI 2.0) String */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_PACKAGE: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: /* Valid operand */ break; default: ACPI_ERROR ((AE_INFO, "Needed [Buffer/String/Package], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } goto NextOperand; case ARGI_REGION_OR_BUFFER: /* Used by Load() only */ /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_BUFFER: case ACPI_TYPE_REGION: /* Valid operand */ break; default: ACPI_ERROR ((AE_INFO, "Needed [Region/Buffer], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } goto NextOperand; case ARGI_DATAREFOBJ: /* Used by the Store() operator only */ switch (ObjDesc->Common.Type) { case ACPI_TYPE_INTEGER: case ACPI_TYPE_PACKAGE: case ACPI_TYPE_STRING: case ACPI_TYPE_BUFFER: case ACPI_TYPE_BUFFER_FIELD: case ACPI_TYPE_LOCAL_REFERENCE: case ACPI_TYPE_LOCAL_REGION_FIELD: case ACPI_TYPE_LOCAL_BANK_FIELD: case ACPI_TYPE_LOCAL_INDEX_FIELD: case ACPI_TYPE_DDB_HANDLE: /* Valid operand */ break; default: if (AcpiGbl_EnableInterpreterSlack) { /* * Enable original behavior of Store(), allowing any and all * objects as the source operand. The ACPI spec does not * allow this, however. */ break; } if (TargetOp == AML_DEBUG_OP) { /* Allow store of any object to the Debug object */ break; } ACPI_ERROR ((AE_INFO, "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p", AcpiUtGetObjectTypeName (ObjDesc), ObjDesc)); return_ACPI_STATUS (AE_AML_OPERAND_TYPE); } goto NextOperand; default: /* Unknown type */ ACPI_ERROR ((AE_INFO, "Internal - Unknown ARGI (required operand) type 0x%X", ThisArgType)); return_ACPI_STATUS (AE_BAD_PARAMETER); } /* * Make sure that the original object was resolved to the * required object type (Simple cases only). */ Status = AcpiExCheckObjectType (TypeNeeded, (*StackPtr)->Common.Type, *StackPtr); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } NextOperand: /* * If more operands needed, decrement StackPtr to point * to next operand on stack */ if (GET_CURRENT_ARG_TYPE (ArgTypes)) { StackPtr--; } } ACPI_DUMP_OPERANDS (WalkState->Operands, AcpiPsGetOpcodeName (Opcode), WalkState->NumOperands); return_ACPI_STATUS (Status); }
ACPI_STATUS AcpiNsEvaluate ( ACPI_EVALUATE_INFO *Info) { ACPI_STATUS Status; ACPI_FUNCTION_TRACE (NsEvaluate); if (!Info) { return_ACPI_STATUS (AE_BAD_PARAMETER); } if (!Info->Node) { /* * Get the actual namespace node for the target object if we * need to. Handles these cases: * * 1) Null node, valid pathname from root (absolute path) * 2) Node and valid pathname (path relative to Node) * 3) Node, Null pathname */ Status = AcpiNsGetNode (Info->PrefixNode, Info->RelativePathname, ACPI_NS_NO_UPSEARCH, &Info->Node); if (ACPI_FAILURE (Status)) { return_ACPI_STATUS (Status); } } /* * For a method alias, we must grab the actual method node so that * proper scoping context will be established before execution. */ if (AcpiNsGetType (Info->Node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) { Info->Node = ACPI_CAST_PTR ( ACPI_NAMESPACE_NODE, Info->Node->Object); } /* Complete the info block initialization */ Info->ReturnObject = NULL; Info->NodeFlags = Info->Node->Flags; Info->ObjDesc = AcpiNsGetAttachedObject (Info->Node); ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n", Info->RelativePathname, Info->Node, AcpiNsGetAttachedObject (Info->Node))); /* Get info if we have a predefined name (_HID, etc.) */ Info->Predefined = AcpiUtMatchPredefinedMethod (Info->Node->Name.Ascii); /* Get the full pathname to the object, for use in warning messages */ Info->FullPathname = AcpiNsGetExternalPathname (Info->Node); if (!Info->FullPathname) { return_ACPI_STATUS (AE_NO_MEMORY); } /* Count the number of arguments being passed in */ Info->ParamCount = 0; if (Info->Parameters) { while (Info->Parameters[Info->ParamCount]) { Info->ParamCount++; } /* Warn on impossible argument count */ if (Info->ParamCount > ACPI_METHOD_NUM_ARGS) { ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, ACPI_WARN_ALWAYS, "Excess arguments (%u) - using only %u", Info->ParamCount, ACPI_METHOD_NUM_ARGS)); Info->ParamCount = ACPI_METHOD_NUM_ARGS; } } /* * For predefined names: Check that the declared argument count * matches the ACPI spec -- otherwise this is a BIOS error. */ AcpiNsCheckAcpiCompliance (Info->FullPathname, Info->Node, Info->Predefined); /* * For all names: Check that the incoming argument count for * this method/object matches the actual ASL/AML definition. */ AcpiNsCheckArgumentCount (Info->FullPathname, Info->Node, Info->ParamCount, Info->Predefined); /* For predefined names: Typecheck all incoming arguments */ AcpiNsCheckArgumentTypes (Info); /* * Three major evaluation cases: * * 1) Object types that cannot be evaluated by definition * 2) The object is a control method -- execute it * 3) The object is not a method -- just return it's current value */ switch (AcpiNsGetType (Info->Node)) { case ACPI_TYPE_DEVICE: case ACPI_TYPE_EVENT: case ACPI_TYPE_MUTEX: case ACPI_TYPE_REGION: case ACPI_TYPE_THERMAL: case ACPI_TYPE_LOCAL_SCOPE: /* * 1) Disallow evaluation of certain object types. For these, * object evaluation is undefined and not supported. */ ACPI_ERROR ((AE_INFO, "%s: Evaluation of object type [%s] is not supported", Info->FullPathname, AcpiUtGetTypeName (Info->Node->Type))); Status = AE_TYPE; goto Cleanup; case ACPI_TYPE_METHOD: /* * 2) Object is a control method - execute it */ /* Verify that there is a method object associated with this node */ if (!Info->ObjDesc) { ACPI_ERROR ((AE_INFO, "%s: Method has no attached sub-object", Info->FullPathname)); Status = AE_NULL_OBJECT; goto Cleanup; } ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Execute method [%s] at AML address %p length %X\n", Info->FullPathname, Info->ObjDesc->Method.AmlStart + 1, Info->ObjDesc->Method.AmlLength - 1)); /* * Any namespace deletion must acquire both the namespace and * interpreter locks to ensure that no thread is using the portion of * the namespace that is being deleted. * * Execute the method via the interpreter. The interpreter is locked * here before calling into the AML parser */ AcpiExEnterInterpreter (); Status = AcpiPsExecuteMethod (Info); AcpiExExitInterpreter (); break; default: /* * 3) All other non-method objects -- get the current object value */ /* * Some objects require additional resolution steps (e.g., the Node * may be a field that must be read, etc.) -- we can't just grab * the object out of the node. * * Use ResolveNodeToValue() to get the associated value. * * NOTE: we can get away with passing in NULL for a walk state because * the Node is guaranteed to not be a reference to either a method * local or a method argument (because this interface is never called * from a running method.) * * Even though we do not directly invoke the interpreter for object * resolution, we must lock it because we could access an OpRegion. * The OpRegion access code assumes that the interpreter is locked. */ AcpiExEnterInterpreter (); /* TBD: ResolveNodeToValue has a strange interface, fix */ Info->ReturnObject = ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Info->Node); Status = AcpiExResolveNodeToValue (ACPI_CAST_INDIRECT_PTR ( ACPI_NAMESPACE_NODE, &Info->ReturnObject), NULL); AcpiExExitInterpreter (); if (ACPI_FAILURE (Status)) { goto Cleanup; } ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returned object %p [%s]\n", Info->ReturnObject, AcpiUtGetObjectTypeName (Info->ReturnObject))); Status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */ break; } /* * For predefined names, check the return value against the ACPI * specification. Some incorrect return value types are repaired. */ (void) AcpiNsCheckReturnValue (Info->Node, Info, Info->ParamCount, Status, &Info->ReturnObject); /* Check if there is a return value that must be dealt with */ if (Status == AE_CTRL_RETURN_VALUE) { /* If caller does not want the return value, delete it */ if (Info->Flags & ACPI_IGNORE_RETURN_VALUE) { AcpiUtRemoveReference (Info->ReturnObject); Info->ReturnObject = NULL; } /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */ Status = AE_OK; } ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed evaluation of object %s ***\n", Info->RelativePathname)); Cleanup: /* * Namespace was unlocked by the handling AcpiNs* function, so we * just free the pathname and return */ ACPI_FREE (Info->FullPathname); Info->FullPathname = NULL; return_ACPI_STATUS (Status); }
static void AcpiExDoDebugObject ( ACPI_OPERAND_OBJECT *SourceDesc, UINT32 Level, UINT32 Index) { UINT32 i; ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc); /* Print line header as long as we are not in the middle of an object display */ if (!((Level > 0) && Index == 0)) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s", Level, " ")); } /* Display index for package output only */ if (Index > 0) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "(%.2u) ", Index -1)); } if (!SourceDesc) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[Null Object]\n")); return_VOID; } if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s ", AcpiUtGetObjectTypeName (SourceDesc))); if (!AcpiUtValidInternalObject (SourceDesc)) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p, Invalid Internal Object!\n", SourceDesc)); return_VOID; } } else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%s: %p\n", AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type), SourceDesc)); return_VOID; } else { return_VOID; } /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */ switch (SourceDesc->Common.Type) { case ACPI_TYPE_INTEGER: /* Output correct integer width */ if (AcpiGbl_IntegerByteWidth == 4) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n", (UINT32) SourceDesc->Integer.Value)); } else { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%8.8X%8.8X\n", ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value))); } break; case ACPI_TYPE_BUFFER: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length)); ACPI_DUMP_BUFFER (SourceDesc->Buffer.Pointer, (SourceDesc->Buffer.Length < 256) ? SourceDesc->Buffer.Length : 256); break; case ACPI_TYPE_STRING: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n", SourceDesc->String.Length, SourceDesc->String.Pointer)); break; case ACPI_TYPE_PACKAGE: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[Contains 0x%.2X Elements]\n", SourceDesc->Package.Count)); /* Output the entire contents of the package */ for (i = 0; i < SourceDesc->Package.Count; i++) { AcpiExDoDebugObject (SourceDesc->Package.Elements[i], Level+4, i+1); } break; case ACPI_TYPE_LOCAL_REFERENCE: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "[%s] ", AcpiUtGetReferenceName (SourceDesc))); /* Decode the reference */ switch (SourceDesc->Reference.Class) { case ACPI_REFCLASS_INDEX: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "0x%X\n", SourceDesc->Reference.Value)); break; case ACPI_REFCLASS_TABLE: /* Case for DdbHandle */ ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Table Index 0x%X\n", SourceDesc->Reference.Value)); return; default: break; } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, " ")); /* Check for valid node first, then valid object */ if (SourceDesc->Reference.Node) { if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) != ACPI_DESC_TYPE_NAMED) { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, " %p - Not a valid namespace node\n", SourceDesc->Reference.Node)); } else { ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "Node %p [%4.4s] ", SourceDesc->Reference.Node, (SourceDesc->Reference.Node)->Name.Ascii)); switch ((SourceDesc->Reference.Node)->Type) { /* These types have no attached object */ case ACPI_TYPE_DEVICE: AcpiOsPrintf ("Device\n"); break; case ACPI_TYPE_THERMAL: AcpiOsPrintf ("Thermal Zone\n"); break; default: AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object, Level+4, 0); break; } } } else if (SourceDesc->Reference.Object) { if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) == ACPI_DESC_TYPE_NAMED) { AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *) SourceDesc->Reference.Object)->Object, Level+4, 0); } else { AcpiExDoDebugObject (SourceDesc->Reference.Object, Level+4, 0); } } break; default: ACPI_DEBUG_PRINT_RAW ((ACPI_DB_DEBUG_OBJECT, "%p\n", SourceDesc)); break; } ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n")); return_VOID; }