FreeBSD/sys/contrib/dev/acpica/components/executer/exstore.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiExStoreObjectToIndex
 *
 * PARAMETERS:  *SourceDesc             - Value to be stored
 *              *DestDesc               - Named object to receive the value
 *              WalkState               - Current walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Store the object to indexed Buffer or Package element
 *
 ******************************************************************************/
AcpiExStoreObjectToIndex
PARAMETERS:  *SourceDesc             - Value to be stored
*DestDesc               - Named object to receive the value
WalkState               - Current walk state

Status

Store the object to indexed Buffer or Package element
AcpiExStoreObjectToIndex PARAMETERS : * SourceDesc - Value to be stored * DestDesc - Named object to receive the value WalkState - Current walk state Status Store the object to indexed Buffer or Package element
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);
    switch (IndexDesc->Reference.TargetType)
    {
    case ACPI_TYPE_PACKAGE:
        ObjDesc = *(IndexDesc->Reference.Where);
        if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE &&
            SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
        {
            AcpiUtAddReference (SourceDesc);
            NewDesc = SourceDesc;
        }
        else
        {
            Status = AcpiUtCopyIobjectToIobject (
                SourceDesc, &NewDesc, WalkState);
            if (ACPI_FAILURE (Status))
            {
                return_ACPI_STATUS (Status);
            }
        }
        if (ObjDesc)
        {
            for (i = 0;
                 i < ((ACPI_OPERAND_OBJECT *)
                        IndexDesc->Reference.Object)->Common.ReferenceCount;
                 i++)
            {
                AcpiUtRemoveReference (ObjDesc);
            }
        }
        *(IndexDesc->Reference.Where) = NewDesc;
        for (i = 1;
             i < ((ACPI_OPERAND_OBJECT *)
                    IndexDesc->Reference.Object)->Common.ReferenceCount;
             i++)
        {
            AcpiUtAddReference (NewDesc);
        }
        break;
    case ACPI_TYPE_BUFFER_FIELD:
        ObjDesc = IndexDesc->Reference.Object;
        if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) &&
            (ObjDesc->Common.Type != ACPI_TYPE_STRING))
        {
            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
        }
        switch (SourceDesc->Common.Type)
        {
        case ACPI_TYPE_INTEGER:
            Value = (UINT8) (SourceDesc->Integer.Value);
            break;
        case ACPI_TYPE_BUFFER:
        case ACPI_TYPE_STRING:
            Value = SourceDesc->Buffer.Pointer[0];
            break;
        default:
            ACPI_ERROR ((AE_INFO,
                "Source must be type [Integer/Buffer/String], found [%s]",
                AcpiUtGetObjectTypeName (SourceDesc)));
            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
        }
        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);
}
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 ) ; switch ( IndexDesc -> Reference . TargetType ) { case ACPI_TYPE_PACKAGE : ObjDesc = * ( IndexDesc -> Reference . Where ) ; if ( SourceDesc -> Common . Type == ACPI_TYPE_LOCAL_REFERENCE && SourceDesc -> Reference . Class == ACPI_REFCLASS_TABLE ) { AcpiUtAddReference ( SourceDesc ) ; NewDesc = SourceDesc ; } else { Status = AcpiUtCopyIobjectToIobject ( SourceDesc , & NewDesc , WalkState ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } } if ( ObjDesc ) { for ( i = 0 ; i < ( ( ACPI_OPERAND_OBJECT * ) IndexDesc -> Reference . Object ) -> Common . ReferenceCount ; i ++ ) { AcpiUtRemoveReference ( ObjDesc ) ; } } * ( IndexDesc -> Reference . Where ) = NewDesc ; for ( i = 1 ; i < ( ( ACPI_OPERAND_OBJECT * ) IndexDesc -> Reference . Object ) -> Common . ReferenceCount ; i ++ ) { AcpiUtAddReference ( NewDesc ) ; } break ; case ACPI_TYPE_BUFFER_FIELD : ObjDesc = IndexDesc -> Reference . Object ; if ( ( ObjDesc -> Common . Type != ACPI_TYPE_BUFFER ) && ( ObjDesc -> Common . Type != ACPI_TYPE_STRING ) ) { return_ACPI_STATUS ( AE_AML_OPERAND_TYPE ) ; } switch ( SourceDesc -> Common . Type ) { case ACPI_TYPE_INTEGER : Value = ( UINT8 ) ( SourceDesc -> Integer . Value ) ; break ; case ACPI_TYPE_BUFFER : case ACPI_TYPE_STRING : Value = SourceDesc -> Buffer . Pointer [ 0 ] ; break ; default : ACPI_ERROR ( ( AE_INFO , " " , AcpiUtGetObjectTypeName ( SourceDesc ) ) ) ; return_ACPI_STATUS ( AE_AML_OPERAND_TYPE ) ; } ObjDesc -> Buffer . Pointer [ IndexDesc -> Reference . Value ] = Value ; break ; default : ACPI_ERROR ( ( AE_INFO , " " ) ) ; Status = AE_AML_TARGET_TYPE ; break ; } return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiExStoreObjectToIndex
 PARAMETERS:  *SourceDesc             - Value to be stored
              *DestDesc               - Named object to receive the value
              WalkState               - Current walk state
FUNCTION : AcpiExStoreObjectToIndex PARAMETERS : * SourceDesc - Value to be stored * DestDesc - Named object to receive the value WalkState - Current walk state
/*
     * Destination must be a reference pointer, and
     * must point to either a buffer or a 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
         */ /* This is a DDBHandle, just add a reference to it */ /* Normal object, copy it */ /* Decrement reference count by the ref count of the parent package */ /* Increment ref count by the ref count of the parent package-1 */ /*
         * 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.
         */ /*
         * The assignment of the individual elements will be slightly
         * different for each source type.
         */ /* Use the least-significant byte of the integer */ /* Note: Takes advantage of common string/buffer fields */ /* All other types are invalid */ /* Store the source value into the target buffer byte */