FreeBSD/sys/contrib/dev/acpica/components/executer/exstore.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiExStoreObjectToNode
 *
 * PARAMETERS:  SourceDesc              - Value to be stored
 *              Node                    - Named object to receive the value
 *              WalkState               - Current walk state
 *              ImplicitConversion      - Perform implicit conversion (yes/no)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Store the object to the named object.
 *
 * The assignment of an object to a named object is handled here.
 * The value passed in will replace the current value (if any)
 * with the input value.
 *
 * When storing into an object the data is converted to the
 * target object type then stored in the object. This means
 * that the target object type (for an initialized target) will
 * not be changed by a store operation. A CopyObject can change
 * the target type, however.
 *
 * The ImplicitConversion flag is set to NO/FALSE only when
 * storing to an ArgX -- as per the rules of the ACPI spec.
 *
 * Assumes parameters are already validated.
 *
 ******************************************************************************/
AcpiExStoreObjectToNode
PARAMETERS:  SourceDesc              - Value to be stored
Node                    - Named object to receive the value
WalkState               - Current walk state
ImplicitConversion      - Perform implicit conversion (yes/no)

Status

Store the object to the named object.

The assignment of an object to a named object is handled here.
The value passed in will replace the current value (if any)
with the input value.

When storing into an object the data is converted to the
target object type then stored in the object. This means
that the target object type (for an initialized target) will
not be changed by a store operation. A CopyObject can change
the target type, however.

The ImplicitConversion flag is set to NO/FALSE only when
storing to an ArgX -- as per the rules of the ACPI spec.

Assumes parameters are already validated.
AcpiExStoreObjectToNode PARAMETERS : SourceDesc - Value to be stored Node - Named object to receive the value WalkState - Current walk state ImplicitConversion - Perform implicit conversion ( yes / no ) Status Store the object to the named object . The assignment of an object to a named object is handled here . The value passed in will replace the current value ( if any ) with the input value . When storing into an object the data is converted to the target object type then stored in the object . This means that the target object type ( for an initialized target ) will not be changed by a store operation . A CopyObject can change the target type however . The ImplicitConversion flag is set to NO / FALSE only when storing to an ArgX -- as per the rules of the ACPI spec . Assumes parameters are already validated .
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);
    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)));
    if (WalkState->Opcode != AML_COPY_OP)
    {
        switch (TargetType)
        {
        case ACPI_TYPE_PACKAGE:
            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;
            }
        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;
        }
    }
    Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
    if (ACPI_FAILURE (Status))
    {
        return_ACPI_STATUS (Status);
    }
    switch (TargetType)
    {
    case ACPI_TYPE_INTEGER:
    case ACPI_TYPE_STRING:
    case ACPI_TYPE_BUFFER:
        if ((WalkState->Opcode == AML_COPY_OP) ||
            !ImplicitConversion)
        {
            Status = AcpiExStoreDirectToNode (SourceDesc, Node, WalkState);
            break;
        }
        Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
            &NewDesc, WalkState);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
        if (NewDesc != TargetDesc)
        {
            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:
        Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
            &WalkState->ResultObj);
        break;
    default:
        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 ) ; TargetType = AcpiNsGetType ( Node ) ; TargetDesc = AcpiNsGetAttachedObject ( Node ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_EXEC , " \n " , SourceDesc , AcpiUtGetObjectTypeName ( SourceDesc ) , Node , AcpiUtGetTypeName ( TargetType ) ) ) ; if ( WalkState -> Opcode != AML_COPY_OP ) { switch ( TargetType ) { case ACPI_TYPE_PACKAGE : if ( WalkState -> Opcode == AML_STORE_OP ) { if ( SourceDesc -> Common . Type != ACPI_TYPE_PACKAGE ) { ACPI_ERROR ( ( AE_INFO , " " " " , AcpiUtGetObjectTypeName ( SourceDesc ) ) ) ; return_ACPI_STATUS ( AE_AML_TARGET_TYPE ) ; } break ; } 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 , " " " " , AcpiUtGetTypeName ( Node -> Type ) , Node -> Name . Ascii ) ) ; return_ACPI_STATUS ( AE_AML_TARGET_TYPE ) ; default : break ; } } Status = AcpiExResolveObject ( & SourceDesc , TargetType , WalkState ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } switch ( TargetType ) { case ACPI_TYPE_INTEGER : case ACPI_TYPE_STRING : case ACPI_TYPE_BUFFER : if ( ( WalkState -> Opcode == AML_COPY_OP ) || ! ImplicitConversion ) { Status = AcpiExStoreDirectToNode ( SourceDesc , Node , WalkState ) ; break ; } Status = AcpiExStoreObjectToObject ( SourceDesc , TargetDesc , & NewDesc , WalkState ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } if ( NewDesc != TargetDesc ) { Status = AcpiNsAttachObject ( Node , NewDesc , NewDesc -> Common . Type ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_EXEC , " \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 : Status = AcpiExWriteDataToField ( SourceDesc , TargetDesc , & WalkState -> ResultObj ) ; break ; default : Status = AcpiExStoreDirectToNode ( SourceDesc , Node , WalkState ) ; break ; } return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiExStoreObjectToNode
 PARAMETERS:  SourceDesc              - Value to be stored
              Node                    - Named object to receive the value
              WalkState               - Current walk state
              ImplicitConversion      - Perform implicit conversion (yes/no)
FUNCTION : AcpiExStoreObjectToNode PARAMETERS : SourceDesc - Value to be stored Node - Named object to receive the value WalkState - Current walk state ImplicitConversion - Perform implicit conversion ( yes / no )
/* Get current type of the node, and object attached to Node */ /* Only limited target types possible for everything except CopyObject */ /*
         * 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)
         */ /*
             * Here, can only store a package to an existing package.
             * Storing a package to a Local/Arg is OK, and handled
             * elsewhere.
             */ /* Fallthrough */ /*
     * Resolve the source object to an actual value
     * (If it is a reference object)
     */ /* Do the actual store operation */ /*
         * The simple data types all support implicit source operand
         * conversion before the store.
         */ /*
             * However, CopyObject and Stores to ArgX do not perform
             * an implicit conversion, as per the ACPI specification.
             * A direct store is performed instead.
             */ /* Store with implicit source operand conversion support */ /*
             * 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.
             */ /*
         * 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.
         */ /*
         * 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).
         */