FreeBSD/sys/contrib/dev/acpica/components/parser/psargs.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiPsGetNextField
 *
 * PARAMETERS:  ParserState         - Current parser state object
 *
 * RETURN:      A newly allocated FIELD op
 *
 * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
 *
 ******************************************************************************/
AcpiPsGetNextField
PARAMETERS:  ParserState         - Current parser state object

A newly allocated FIELD op


AcpiPsGetNextField PARAMETERS : ParserState - Current parser state object A newly allocated FIELD op
static ACPI_PARSE_OBJECT *
AcpiPsGetNextField (
    ACPI_PARSE_STATE        *ParserState)
{
    UINT8                   *Aml;
    ACPI_PARSE_OBJECT       *Field;
    ACPI_PARSE_OBJECT       *Arg = NULL;
    UINT16                  Opcode;
    UINT32                  Name;
    UINT8                   AccessType;
    UINT8                   AccessAttribute;
    UINT8                   AccessLength;
    UINT32                  PkgLength;
    UINT8                   *PkgEnd;
    UINT32                  BufferLength;
    ACPI_FUNCTION_TRACE (PsGetNextField);
    Aml = ParserState->Aml;
    switch (ACPI_GET8 (ParserState->Aml))
    {
    case AML_FIELD_OFFSET_OP:
        Opcode = AML_INT_RESERVEDFIELD_OP;
        ParserState->Aml++;
        break;
    case AML_FIELD_ACCESS_OP:
        Opcode = AML_INT_ACCESSFIELD_OP;
        ParserState->Aml++;
        break;
    case AML_FIELD_CONNECTION_OP:
        Opcode = AML_INT_CONNECTION_OP;
        ParserState->Aml++;
        break;
    case AML_FIELD_EXT_ACCESS_OP:
        Opcode = AML_INT_EXTACCESSFIELD_OP;
        ParserState->Aml++;
        break;
    default:
        Opcode = AML_INT_NAMEDFIELD_OP;
        break;
    }
    Field = AcpiPsAllocOp (Opcode, Aml);
    if (!Field)
    {
        return_PTR (NULL);
    }
    switch (Opcode)
    {
    case AML_INT_NAMEDFIELD_OP:
        ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
        AcpiPsSetName (Field, Name);
        ParserState->Aml += ACPI_NAME_SIZE;
        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
        break;
    case AML_INT_RESERVEDFIELD_OP:
        Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
        break;
    case AML_INT_ACCESSFIELD_OP:
    case AML_INT_EXTACCESSFIELD_OP:
        AccessType = ACPI_GET8 (ParserState->Aml);
        ParserState->Aml++;
        AccessAttribute = ACPI_GET8 (ParserState->Aml);
        ParserState->Aml++;
        Field->Common.Value.Integer = (UINT8) AccessType;
        Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);
        if (Opcode == AML_INT_EXTACCESSFIELD_OP)
        {
            AccessLength = ACPI_GET8 (ParserState->Aml);
            ParserState->Aml++;
            Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);
        }
        break;
    case AML_INT_CONNECTION_OP:
        Aml = ParserState->Aml;
        if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)
        {
            ParserState->Aml++;
            PkgEnd = ParserState->Aml;
            PkgLength = AcpiPsGetNextPackageLength (ParserState);
            PkgEnd += PkgLength;
            if (ParserState->Aml < PkgEnd)
            {
                Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP, Aml);
                if (!Arg)
                {
                    AcpiPsFreeOp (Field);
                    return_PTR (NULL);
                }
                Opcode = ACPI_GET8 (ParserState->Aml);
                ParserState->Aml++;
                switch (Opcode)
                {
                case AML_BYTE_OP:       
                    BufferLength = ACPI_GET8 (ParserState->Aml);
                    ParserState->Aml += 1;
                    break;
                case AML_WORD_OP:       
                    BufferLength = ACPI_GET16 (ParserState->Aml);
                    ParserState->Aml += 2;
                    break;
                case AML_DWORD_OP:      
                    BufferLength = ACPI_GET32 (ParserState->Aml);
                    ParserState->Aml += 4;
                    break;
                default:
                    BufferLength = 0;
                    break;
                }
                Arg->Named.Value.Size = BufferLength;
                Arg->Named.Data = ParserState->Aml;
            }
            ParserState->Aml = PkgEnd;
        }
        else
        {
            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Aml);
            if (!Arg)
            {
                AcpiPsFreeOp (Field);
                return_PTR (NULL);
            }
            Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
        }
        AcpiPsAppendArg (Field, Arg);
        break;
    default:
        break;
    }
    return_PTR (Field);
}
static ACPI_PARSE_OBJECT * AcpiPsGetNextField ( ACPI_PARSE_STATE * ParserState ) { UINT8 * Aml ; ACPI_PARSE_OBJECT * Field ; ACPI_PARSE_OBJECT * Arg = NULL ; UINT16 Opcode ; UINT32 Name ; UINT8 AccessType ; UINT8 AccessAttribute ; UINT8 AccessLength ; UINT32 PkgLength ; UINT8 * PkgEnd ; UINT32 BufferLength ; ACPI_FUNCTION_TRACE ( PsGetNextField ) ; Aml = ParserState -> Aml ; switch ( ACPI_GET8 ( ParserState -> Aml ) ) { case AML_FIELD_OFFSET_OP : Opcode = AML_INT_RESERVEDFIELD_OP ; ParserState -> Aml ++ ; break ; case AML_FIELD_ACCESS_OP : Opcode = AML_INT_ACCESSFIELD_OP ; ParserState -> Aml ++ ; break ; case AML_FIELD_CONNECTION_OP : Opcode = AML_INT_CONNECTION_OP ; ParserState -> Aml ++ ; break ; case AML_FIELD_EXT_ACCESS_OP : Opcode = AML_INT_EXTACCESSFIELD_OP ; ParserState -> Aml ++ ; break ; default : Opcode = AML_INT_NAMEDFIELD_OP ; break ; } Field = AcpiPsAllocOp ( Opcode , Aml ) ; if ( ! Field ) { return_PTR ( NULL ) ; } switch ( Opcode ) { case AML_INT_NAMEDFIELD_OP : ACPI_MOVE_32_TO_32 ( & Name , ParserState -> Aml ) ; AcpiPsSetName ( Field , Name ) ; ParserState -> Aml += ACPI_NAME_SIZE ; Field -> Common . Value . Size = AcpiPsGetNextPackageLength ( ParserState ) ; break ; case AML_INT_RESERVEDFIELD_OP : Field -> Common . Value . Size = AcpiPsGetNextPackageLength ( ParserState ) ; break ; case AML_INT_ACCESSFIELD_OP : case AML_INT_EXTACCESSFIELD_OP : AccessType = ACPI_GET8 ( ParserState -> Aml ) ; ParserState -> Aml ++ ; AccessAttribute = ACPI_GET8 ( ParserState -> Aml ) ; ParserState -> Aml ++ ; Field -> Common . Value . Integer = ( UINT8 ) AccessType ; Field -> Common . Value . Integer |= ( UINT16 ) ( AccessAttribute << 8 ) ; if ( Opcode == AML_INT_EXTACCESSFIELD_OP ) { AccessLength = ACPI_GET8 ( ParserState -> Aml ) ; ParserState -> Aml ++ ; Field -> Common . Value . Integer |= ( UINT32 ) ( AccessLength << 16 ) ; } break ; case AML_INT_CONNECTION_OP : Aml = ParserState -> Aml ; if ( ACPI_GET8 ( ParserState -> Aml ) == AML_BUFFER_OP ) { ParserState -> Aml ++ ; PkgEnd = ParserState -> Aml ; PkgLength = AcpiPsGetNextPackageLength ( ParserState ) ; PkgEnd += PkgLength ; if ( ParserState -> Aml < PkgEnd ) { Arg = AcpiPsAllocOp ( AML_INT_BYTELIST_OP , Aml ) ; if ( ! Arg ) { AcpiPsFreeOp ( Field ) ; return_PTR ( NULL ) ; } Opcode = ACPI_GET8 ( ParserState -> Aml ) ; ParserState -> Aml ++ ; switch ( Opcode ) { case AML_BYTE_OP : BufferLength = ACPI_GET8 ( ParserState -> Aml ) ; ParserState -> Aml += 1 ; break ; case AML_WORD_OP : BufferLength = ACPI_GET16 ( ParserState -> Aml ) ; ParserState -> Aml += 2 ; break ; case AML_DWORD_OP : BufferLength = ACPI_GET32 ( ParserState -> Aml ) ; ParserState -> Aml += 4 ; break ; default : BufferLength = 0 ; break ; } Arg -> Named . Value . Size = BufferLength ; Arg -> Named . Data = ParserState -> Aml ; } ParserState -> Aml = PkgEnd ; } else { Arg = AcpiPsAllocOp ( AML_INT_NAMEPATH_OP , Aml ) ; if ( ! Arg ) { AcpiPsFreeOp ( Field ) ; return_PTR ( NULL ) ; } Arg -> Common . Value . Name = AcpiPsGetNextNamestring ( ParserState ) ; } AcpiPsAppendArg ( Field , Arg ) ; break ; default : break ; } return_PTR ( Field ) ; }
FUNCTION:    AcpiPsGetNextField
 PARAMETERS:  ParserState         - Current parser state object
FUNCTION : AcpiPsGetNextField PARAMETERS : ParserState - Current parser state object
/* Determine field type */ /* Allocate a new field op */ /* Decode the field type */ /* Get the 4-character name */ /* Get the length which is encoded as a package length */ /* Get the length which is encoded as a package length */ /*
         * Get AccessType and AccessAttrib and merge into the field Op
         * AccessType is first operand, AccessAttribute is second. stuff
         * these bytes into the node integer value for convenience.
         */ /* Get the two bytes (Type/Attribute) */ /* This opcode has a third byte, AccessLength */ /*
         * Argument for Connection operator can be either a Buffer
         * (resource descriptor), or a NameString.
         */ /* Non-empty list */ /* Get the actual buffer length argument */ /* AML_BYTEDATA_ARG */ /* AML_WORDDATA_ARG */ /* AML_DWORDATA_ARG */ /* Fill in bytelist data */ /* Skip to End of byte data */ /* Get the Namestring argument */ /* Link the buffer/namestring to parent (CONNECTION_OP) */ /* Opcode was set in previous switch */