FreeBSD/sys/contrib/dev/acpica/components/parser/psargs.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiPsGetNextArg
 *
 * PARAMETERS:  WalkState           - Current state
 *              ParserState         - Current parser state object
 *              ArgType             - The argument type (AML_*_ARG)
 *              ReturnArg           - Where the next arg is returned
 *
 * RETURN:      Status, and an op object containing the next argument.
 *
 * DESCRIPTION: Get next argument (including complex list arguments that require
 *              pushing the parser stack)
 *
 ******************************************************************************/
AcpiPsGetNextArg
PARAMETERS:  WalkState           - Current state
ParserState         - Current parser state object
ArgType             - The argument type (AML_*_ARG)
ReturnArg           - Where the next arg is returned

Status, and an op object containing the next argument.

Get next argument (including complex list arguments that require
pushing the parser stack)
AcpiPsGetNextArg PARAMETERS : WalkState - Current state ParserState - Current parser state object ArgType - The argument type ( AML_ * _ARG ) ReturnArg - Where the next arg is returned Status and an op object containing the next argument . Get next argument ( including complex list arguments that require pushing the parser stack )
ACPI_STATUS
AcpiPsGetNextArg (
    ACPI_WALK_STATE         *WalkState,
    ACPI_PARSE_STATE        *ParserState,
    UINT32                  ArgType,
    ACPI_PARSE_OBJECT       **ReturnArg)
{
    ACPI_PARSE_OBJECT       *Arg = NULL;
    ACPI_PARSE_OBJECT       *Prev = NULL;
    ACPI_PARSE_OBJECT       *Field;
    UINT32                  Subop;
    ACPI_STATUS             Status = AE_OK;
    ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
    switch (ArgType)
    {
    case ARGP_BYTEDATA:
    case ARGP_WORDDATA:
    case ARGP_DWORDDATA:
    case ARGP_CHARLIST:
    case ARGP_NAME:
    case ARGP_NAMESTRING:
        Arg = AcpiPsAllocOp (AML_BYTE_OP, ParserState->Aml);
        if (!Arg)
        {
            return_ACPI_STATUS (AE_NO_MEMORY);
        }
        AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
        break;
    case ARGP_PKGLENGTH:
        ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
        break;
    case ARGP_FIELDLIST:
        if (ParserState->Aml < ParserState->PkgEnd)
        {
            while (ParserState->Aml < ParserState->PkgEnd)
            {
                Field = AcpiPsGetNextField (ParserState);
                if (!Field)
                {
                    return_ACPI_STATUS (AE_NO_MEMORY);
                }
                if (Prev)
                {
                    Prev->Common.Next = Field;
                }
                else
                {
                    Arg = Field;
                }
                Prev = Field;
            }
            ParserState->Aml = ParserState->PkgEnd;
        }
        break;
    case ARGP_BYTELIST:
        if (ParserState->Aml < ParserState->PkgEnd)
        {
            Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP,
                ParserState->Aml);
            if (!Arg)
            {
                return_ACPI_STATUS (AE_NO_MEMORY);
            }
            Arg->Common.Value.Size = (UINT32)
                ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
            Arg->Named.Data = ParserState->Aml;
            ParserState->Aml = ParserState->PkgEnd;
        }
        break;
    case ARGP_TARGET:
    case ARGP_SUPERNAME:
    case ARGP_SIMPLENAME:
    case ARGP_NAME_OR_REF:
        Subop = AcpiPsPeekOpcode (ParserState);
        if (Subop == 0                  ||
            AcpiPsIsLeadingChar (Subop) ||
            ACPI_IS_ROOT_PREFIX (Subop) ||
            ACPI_IS_PARENT_PREFIX (Subop))
        {
            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);
            if (!Arg)
            {
                return_ACPI_STATUS (AE_NO_MEMORY);
            }
            if (WalkState->Opcode == AML_UNLOAD_OP)
            {
                Status = AcpiPsGetNextNamepath (WalkState, ParserState,
                    Arg, ACPI_POSSIBLE_METHOD_CALL);
                if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
                {
                    AcpiPsFreeOp (Arg);
                    Arg = NULL;
                }
            }
            else
            {
                Status = AcpiPsGetNextNamepath (WalkState, ParserState,
                    Arg, ACPI_NOT_METHOD_CALL);
            }
        }
        else
        {
            WalkState->ArgCount = 1;
        }
        break;
    case ARGP_DATAOBJ:
    case ARGP_TERMARG:
        WalkState->ArgCount = 1;
        break;
    case ARGP_DATAOBJLIST:
    case ARGP_TERMLIST:
    case ARGP_OBJLIST:
        if (ParserState->Aml < ParserState->PkgEnd)
        {
            WalkState->ArgCount = ACPI_VAR_ARGS;
        }
        break;
    default:
        ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));
        Status = AE_AML_OPERAND_TYPE;
        break;
    }
    *ReturnArg = Arg;
    return_ACPI_STATUS (Status);
}
ACPI_STATUS AcpiPsGetNextArg ( ACPI_WALK_STATE * WalkState , ACPI_PARSE_STATE * ParserState , UINT32 ArgType , ACPI_PARSE_OBJECT * * ReturnArg ) { ACPI_PARSE_OBJECT * Arg = NULL ; ACPI_PARSE_OBJECT * Prev = NULL ; ACPI_PARSE_OBJECT * Field ; UINT32 Subop ; ACPI_STATUS Status = AE_OK ; ACPI_FUNCTION_TRACE_PTR ( PsGetNextArg , ParserState ) ; switch ( ArgType ) { case ARGP_BYTEDATA : case ARGP_WORDDATA : case ARGP_DWORDDATA : case ARGP_CHARLIST : case ARGP_NAME : case ARGP_NAMESTRING : Arg = AcpiPsAllocOp ( AML_BYTE_OP , ParserState -> Aml ) ; if ( ! Arg ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } AcpiPsGetNextSimpleArg ( ParserState , ArgType , Arg ) ; break ; case ARGP_PKGLENGTH : ParserState -> PkgEnd = AcpiPsGetNextPackageEnd ( ParserState ) ; break ; case ARGP_FIELDLIST : if ( ParserState -> Aml < ParserState -> PkgEnd ) { while ( ParserState -> Aml < ParserState -> PkgEnd ) { Field = AcpiPsGetNextField ( ParserState ) ; if ( ! Field ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } if ( Prev ) { Prev -> Common . Next = Field ; } else { Arg = Field ; } Prev = Field ; } ParserState -> Aml = ParserState -> PkgEnd ; } break ; case ARGP_BYTELIST : if ( ParserState -> Aml < ParserState -> PkgEnd ) { Arg = AcpiPsAllocOp ( AML_INT_BYTELIST_OP , ParserState -> Aml ) ; if ( ! Arg ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } Arg -> Common . Value . Size = ( UINT32 ) ACPI_PTR_DIFF ( ParserState -> PkgEnd , ParserState -> Aml ) ; Arg -> Named . Data = ParserState -> Aml ; ParserState -> Aml = ParserState -> PkgEnd ; } break ; case ARGP_TARGET : case ARGP_SUPERNAME : case ARGP_SIMPLENAME : case ARGP_NAME_OR_REF : Subop = AcpiPsPeekOpcode ( ParserState ) ; if ( Subop == 0 || AcpiPsIsLeadingChar ( Subop ) || ACPI_IS_ROOT_PREFIX ( Subop ) || ACPI_IS_PARENT_PREFIX ( Subop ) ) { Arg = AcpiPsAllocOp ( AML_INT_NAMEPATH_OP , ParserState -> Aml ) ; if ( ! Arg ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } if ( WalkState -> Opcode == AML_UNLOAD_OP ) { Status = AcpiPsGetNextNamepath ( WalkState , ParserState , Arg , ACPI_POSSIBLE_METHOD_CALL ) ; if ( Arg -> Common . AmlOpcode == AML_INT_METHODCALL_OP ) { AcpiPsFreeOp ( Arg ) ; Arg = NULL ; } } else { Status = AcpiPsGetNextNamepath ( WalkState , ParserState , Arg , ACPI_NOT_METHOD_CALL ) ; } } else { WalkState -> ArgCount = 1 ; } break ; case ARGP_DATAOBJ : case ARGP_TERMARG : WalkState -> ArgCount = 1 ; break ; case ARGP_DATAOBJLIST : case ARGP_TERMLIST : case ARGP_OBJLIST : if ( ParserState -> Aml < ParserState -> PkgEnd ) { WalkState -> ArgCount = ACPI_VAR_ARGS ; } break ; default : ACPI_ERROR ( ( AE_INFO , " " , ArgType ) ) ; Status = AE_AML_OPERAND_TYPE ; break ; } * ReturnArg = Arg ; return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiPsGetNextArg
 PARAMETERS:  WalkState           - Current state
              ParserState         - Current parser state object
              ArgType             - The argument type (AML_*_ARG)
              ReturnArg           - Where the next arg is returned
FUNCTION : AcpiPsGetNextArg PARAMETERS : WalkState - Current state ParserState - Current parser state object ArgType - The argument type ( AML_ * _ARG ) ReturnArg - Where the next arg is returned
/* Constants, strings, and namestrings are all the same size */ /* Package length, nothing returned */ /* Non-empty list */ /* Skip to End of byte data */ /* Non-empty list */ /* Fill in bytelist data */ /* Skip to End of byte data */ /* NullName or NameString */ /* To support SuperName arg of Unload */ /*
                 * If the SuperName argument is a method call, we have
                 * already restored the AML pointer, just free this Arg
                 */ /* Single complex argument, nothing returned */ /* Single complex argument, nothing returned */ /* Non-empty list of variable arguments, nothing returned */