FreeBSD/sys/contrib/dev/acpica/components/executer/exprep.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiExPrepFieldValue
 *
 * PARAMETERS:  Info    - Contains all field creation info
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Construct an object of type ACPI_OPERAND_OBJECT with a
 *              subtype of DefField and connect it to the parent Node.
 *
 ******************************************************************************/
AcpiExPrepFieldValue
PARAMETERS:  Info    - Contains all field creation info

Status

Construct an object of type ACPI_OPERAND_OBJECT with a
subtype of DefField and connect it to the parent Node.
AcpiExPrepFieldValue PARAMETERS : Info - Contains all field creation info Status Construct an object of type ACPI_OPERAND_OBJECT with a subtype of DefField and connect it to the parent Node .
ACPI_STATUS
AcpiExPrepFieldValue (
    ACPI_CREATE_FIELD_INFO  *Info)
{
    ACPI_OPERAND_OBJECT     *ObjDesc;
    ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
    ACPI_STATUS             Status;
    UINT32                  AccessByteWidth;
    UINT32                  Type;
    ACPI_FUNCTION_TRACE (ExPrepFieldValue);
    if (Info->FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD)
    {
        if (!Info->RegionNode)
        {
            ACPI_ERROR ((AE_INFO, "Null RegionNode"));
            return_ACPI_STATUS (AE_AML_NO_OPERAND);
        }
        Type = AcpiNsGetType (Info->RegionNode);
        if (Type != ACPI_TYPE_REGION)
        {
            ACPI_ERROR ((AE_INFO, "Needed Region, found type 0x%X (%s)",
                Type, AcpiUtGetTypeName (Type)));
            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
        }
    }
    ObjDesc = AcpiUtCreateInternalObject (Info->FieldType);
    if (!ObjDesc)
    {
        return_ACPI_STATUS (AE_NO_MEMORY);
    }
    ObjDesc->CommonField.Node = Info->FieldNode;
    Status = AcpiExPrepCommonFieldObject (ObjDesc,
        Info->FieldFlags, Info->Attribute,
        Info->FieldBitPosition, Info->FieldBitLength);
    if (ACPI_FAILURE (Status))
    {
        AcpiUtDeleteObjectDesc (ObjDesc);
        return_ACPI_STATUS (Status);
    }
    switch (Info->FieldType)
    {
    case ACPI_TYPE_LOCAL_REGION_FIELD:
        ObjDesc->Field.RegionObj = AcpiNsGetAttachedObject (Info->RegionNode);
        ObjDesc->Field.AccessLength = Info->AccessLength;
        if (Info->ConnectionNode)
        {
            SecondDesc = Info->ConnectionNode->Object;
            if (!(SecondDesc->Common.Flags & AOPOBJ_DATA_VALID))
            {
                Status = AcpiDsGetBufferArguments (SecondDesc);
                if (ACPI_FAILURE (Status))
                {
                    AcpiUtDeleteObjectDesc (ObjDesc);
                    return_ACPI_STATUS (Status);
                }
            }
            ObjDesc->Field.ResourceBuffer =
                SecondDesc->Buffer.Pointer;
            ObjDesc->Field.ResourceLength =
                (UINT16) SecondDesc->Buffer.Length;
        }
        else if (Info->ResourceBuffer)
        {
            ObjDesc->Field.ResourceBuffer = Info->ResourceBuffer;
            ObjDesc->Field.ResourceLength = Info->ResourceLength;
        }
        ObjDesc->Field.PinNumberIndex = Info->PinNumberIndex;
        if ((ObjDesc->Field.RegionObj->Region.SpaceId == ACPI_ADR_SPACE_EC) &&
            (ObjDesc->CommonField.BitLength > 8))
        {
            AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES (
                ObjDesc->CommonField.BitLength);
            if (AccessByteWidth < 256)
            {
                ObjDesc->CommonField.AccessByteWidth =
                    (UINT8) AccessByteWidth;
            }
        }
        AcpiUtAddReference (ObjDesc->Field.RegionObj);
        ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
            "RegionField: BitOff %X, Off %X, Gran %X, Region %p\n",
            ObjDesc->Field.StartFieldBitOffset,
            ObjDesc->Field.BaseByteOffset,
            ObjDesc->Field.AccessByteWidth,
            ObjDesc->Field.RegionObj));
        break;
    case ACPI_TYPE_LOCAL_BANK_FIELD:
        ObjDesc->BankField.Value = Info->BankValue;
        ObjDesc->BankField.RegionObj =
            AcpiNsGetAttachedObject (Info->RegionNode);
        ObjDesc->BankField.BankObj =
            AcpiNsGetAttachedObject (Info->RegisterNode);
        AcpiUtAddReference (ObjDesc->BankField.RegionObj);
        AcpiUtAddReference (ObjDesc->BankField.BankObj);
        ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
            "Bank Field: BitOff %X, Off %X, Gran %X, Region %p, BankReg %p\n",
            ObjDesc->BankField.StartFieldBitOffset,
            ObjDesc->BankField.BaseByteOffset,
            ObjDesc->Field.AccessByteWidth,
            ObjDesc->BankField.RegionObj,
            ObjDesc->BankField.BankObj));
        SecondDesc = ObjDesc->Common.NextObject;
        SecondDesc->Extra.AmlStart = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
            Info->DataRegisterNode)->Named.Data;
        SecondDesc->Extra.AmlLength = ACPI_CAST_PTR (ACPI_PARSE_OBJECT,
            Info->DataRegisterNode)->Named.Length;
        break;
    case ACPI_TYPE_LOCAL_INDEX_FIELD:
        ObjDesc->IndexField.IndexObj =
            AcpiNsGetAttachedObject (Info->RegisterNode);
        ObjDesc->IndexField.DataObj =
            AcpiNsGetAttachedObject (Info->DataRegisterNode);
        if (!ObjDesc->IndexField.DataObj || !ObjDesc->IndexField.IndexObj)
        {
            ACPI_ERROR ((AE_INFO, "Null Index Object during field prep"));
            AcpiUtDeleteObjectDesc (ObjDesc);
            return_ACPI_STATUS (AE_AML_INTERNAL);
        }
        AcpiUtAddReference (ObjDesc->IndexField.DataObj);
        AcpiUtAddReference (ObjDesc->IndexField.IndexObj);
        ObjDesc->IndexField.Value = (UINT32) ACPI_ROUND_DOWN (
            ACPI_DIV_8 (Info->FieldBitPosition),
            ObjDesc->IndexField.AccessByteWidth);
        ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
            "IndexField: BitOff %X, Off %X, Value %X, "
            "Gran %X, Index %p, Data %p\n",
            ObjDesc->IndexField.StartFieldBitOffset,
            ObjDesc->IndexField.BaseByteOffset,
            ObjDesc->IndexField.Value,
            ObjDesc->Field.AccessByteWidth,
            ObjDesc->IndexField.IndexObj,
            ObjDesc->IndexField.DataObj));
        break;
    default:
        break;
    }
    Status = AcpiNsAttachObject (
        Info->FieldNode, ObjDesc, AcpiNsGetType (Info->FieldNode));
    ACPI_DEBUG_PRINT ((ACPI_DB_BFIELD,
        "Set NamedObj %p [%4.4s], ObjDesc %p\n",
        Info->FieldNode, AcpiUtGetNodeName (Info->FieldNode), ObjDesc));
    AcpiUtRemoveReference (ObjDesc);
    return_ACPI_STATUS (Status);
}
ACPI_STATUS AcpiExPrepFieldValue ( ACPI_CREATE_FIELD_INFO * Info ) { ACPI_OPERAND_OBJECT * ObjDesc ; ACPI_OPERAND_OBJECT * SecondDesc = NULL ; ACPI_STATUS Status ; UINT32 AccessByteWidth ; UINT32 Type ; ACPI_FUNCTION_TRACE ( ExPrepFieldValue ) ; if ( Info -> FieldType != ACPI_TYPE_LOCAL_INDEX_FIELD ) { if ( ! Info -> RegionNode ) { ACPI_ERROR ( ( AE_INFO , " " ) ) ; return_ACPI_STATUS ( AE_AML_NO_OPERAND ) ; } Type = AcpiNsGetType ( Info -> RegionNode ) ; if ( Type != ACPI_TYPE_REGION ) { ACPI_ERROR ( ( AE_INFO , " " , Type , AcpiUtGetTypeName ( Type ) ) ) ; return_ACPI_STATUS ( AE_AML_OPERAND_TYPE ) ; } } ObjDesc = AcpiUtCreateInternalObject ( Info -> FieldType ) ; if ( ! ObjDesc ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } ObjDesc -> CommonField . Node = Info -> FieldNode ; Status = AcpiExPrepCommonFieldObject ( ObjDesc , Info -> FieldFlags , Info -> Attribute , Info -> FieldBitPosition , Info -> FieldBitLength ) ; if ( ACPI_FAILURE ( Status ) ) { AcpiUtDeleteObjectDesc ( ObjDesc ) ; return_ACPI_STATUS ( Status ) ; } switch ( Info -> FieldType ) { case ACPI_TYPE_LOCAL_REGION_FIELD : ObjDesc -> Field . RegionObj = AcpiNsGetAttachedObject ( Info -> RegionNode ) ; ObjDesc -> Field . AccessLength = Info -> AccessLength ; if ( Info -> ConnectionNode ) { SecondDesc = Info -> ConnectionNode -> Object ; if ( ! ( SecondDesc -> Common . Flags & AOPOBJ_DATA_VALID ) ) { Status = AcpiDsGetBufferArguments ( SecondDesc ) ; if ( ACPI_FAILURE ( Status ) ) { AcpiUtDeleteObjectDesc ( ObjDesc ) ; return_ACPI_STATUS ( Status ) ; } } ObjDesc -> Field . ResourceBuffer = SecondDesc -> Buffer . Pointer ; ObjDesc -> Field . ResourceLength = ( UINT16 ) SecondDesc -> Buffer . Length ; } else if ( Info -> ResourceBuffer ) { ObjDesc -> Field . ResourceBuffer = Info -> ResourceBuffer ; ObjDesc -> Field . ResourceLength = Info -> ResourceLength ; } ObjDesc -> Field . PinNumberIndex = Info -> PinNumberIndex ; if ( ( ObjDesc -> Field . RegionObj -> Region . SpaceId == ACPI_ADR_SPACE_EC ) && ( ObjDesc -> CommonField . BitLength > 8 ) ) { AccessByteWidth = ACPI_ROUND_BITS_UP_TO_BYTES ( ObjDesc -> CommonField . BitLength ) ; if ( AccessByteWidth < 256 ) { ObjDesc -> CommonField . AccessByteWidth = ( UINT8 ) AccessByteWidth ; } } AcpiUtAddReference ( ObjDesc -> Field . RegionObj ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_BFIELD , " \n " , ObjDesc -> Field . StartFieldBitOffset , ObjDesc -> Field . BaseByteOffset , ObjDesc -> Field . AccessByteWidth , ObjDesc -> Field . RegionObj ) ) ; break ; case ACPI_TYPE_LOCAL_BANK_FIELD : ObjDesc -> BankField . Value = Info -> BankValue ; ObjDesc -> BankField . RegionObj = AcpiNsGetAttachedObject ( Info -> RegionNode ) ; ObjDesc -> BankField . BankObj = AcpiNsGetAttachedObject ( Info -> RegisterNode ) ; AcpiUtAddReference ( ObjDesc -> BankField . RegionObj ) ; AcpiUtAddReference ( ObjDesc -> BankField . BankObj ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_BFIELD , " \n " , ObjDesc -> BankField . StartFieldBitOffset , ObjDesc -> BankField . BaseByteOffset , ObjDesc -> Field . AccessByteWidth , ObjDesc -> BankField . RegionObj , ObjDesc -> BankField . BankObj ) ) ; SecondDesc = ObjDesc -> Common . NextObject ; SecondDesc -> Extra . AmlStart = ACPI_CAST_PTR ( ACPI_PARSE_OBJECT , Info -> DataRegisterNode ) -> Named . Data ; SecondDesc -> Extra . AmlLength = ACPI_CAST_PTR ( ACPI_PARSE_OBJECT , Info -> DataRegisterNode ) -> Named . Length ; break ; case ACPI_TYPE_LOCAL_INDEX_FIELD : ObjDesc -> IndexField . IndexObj = AcpiNsGetAttachedObject ( Info -> RegisterNode ) ; ObjDesc -> IndexField . DataObj = AcpiNsGetAttachedObject ( Info -> DataRegisterNode ) ; if ( ! ObjDesc -> IndexField . DataObj || ! ObjDesc -> IndexField . IndexObj ) { ACPI_ERROR ( ( AE_INFO , " " ) ) ; AcpiUtDeleteObjectDesc ( ObjDesc ) ; return_ACPI_STATUS ( AE_AML_INTERNAL ) ; } AcpiUtAddReference ( ObjDesc -> IndexField . DataObj ) ; AcpiUtAddReference ( ObjDesc -> IndexField . IndexObj ) ; ObjDesc -> IndexField . Value = ( UINT32 ) ACPI_ROUND_DOWN ( ACPI_DIV_8 ( Info -> FieldBitPosition ) , ObjDesc -> IndexField . AccessByteWidth ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_BFIELD , " " " \n " , ObjDesc -> IndexField . StartFieldBitOffset , ObjDesc -> IndexField . BaseByteOffset , ObjDesc -> IndexField . Value , ObjDesc -> Field . AccessByteWidth , ObjDesc -> IndexField . IndexObj , ObjDesc -> IndexField . DataObj ) ) ; break ; default : break ; } Status = AcpiNsAttachObject ( Info -> FieldNode , ObjDesc , AcpiNsGetType ( Info -> FieldNode ) ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_BFIELD , " \n " , Info -> FieldNode , AcpiUtGetNodeName ( Info -> FieldNode ) , ObjDesc ) ) ; AcpiUtRemoveReference ( ObjDesc ) ; return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiExPrepFieldValue
 PARAMETERS:  Info    - Contains all field creation info
FUNCTION : AcpiExPrepFieldValue PARAMETERS : Info - Contains all field creation info
/* Parameter validation */ /* Allocate a new field object */ /* Initialize areas of the object that are common to all fields */ /* Initialize areas of the object that are specific to the field type */ /* Fields specific to GenericSerialBus fields */ /* Allow full data read from EC address space */ /* Maximum byte width supported is 255 */ /* An additional reference for the container */ /* An additional reference for the attached objects */ /*
         * Remember location in AML stream of the field unit
         * opcode and operands -- since the BankValue
         * operands must be evaluated.
         */ /* Get the Index and Data registers */ /* An additional reference for the attached objects */ /*
         * April 2006: Changed to match MS behavior
         *
         * The value written to the Index register is the byte offset of the
         * target field in units of the granularity of the IndexField
         *
         * Previously, the value was calculated as an index in terms of the
         * width of the Data register, as below:
         *
         *      ObjDesc->IndexField.Value = (UINT32)
         *          (Info->FieldBitPosition / ACPI_MUL_8 (
         *              ObjDesc->Field.AccessByteWidth));
         *
         * February 2006: Tried value as a byte offset:
         *      ObjDesc->IndexField.Value = (UINT32)
         *          ACPI_DIV_8 (Info->FieldBitPosition);
         */ /* No other types should get here */ /*
     * Store the constructed descriptor (ObjDesc) into the parent Node,
     * preserving the current type of that NamedObj.
     */ /* Remove local reference to the object */