FreeBSD/sys/contrib/dev/acpica/components/parser/psargs.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiPsGetNextNamepath
 *
 * PARAMETERS:  ParserState         - Current parser state object
 *              Arg                 - Where the namepath will be stored
 *              ArgCount            - If the namepath points to a control method
 *                                    the method's argument is returned here.
 *              PossibleMethodCall  - Whether the namepath can possibly be the
 *                                    start of a method call
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get next name (if method call, return # of required args).
 *              Names are looked up in the internal namespace to determine
 *              if the name represents a control method. If a method
 *              is found, the number of arguments to the method is returned.
 *              This information is critical for parsing to continue correctly.
 *
 ******************************************************************************/
AcpiPsGetNextNamepath
PARAMETERS:  ParserState         - Current parser state object
Arg                 - Where the namepath will be stored
ArgCount            - If the namepath points to a control method
the method's argument is returned here.
PossibleMethodCall  - Whether the namepath can possibly be the
start of a method call

Status

Get next name (if method call, return # of required args).
Names are looked up in the internal namespace to determine
if the name represents a control method. If a method
is found, the number of arguments to the method is returned.
This information is critical for parsing to continue correctly.
AcpiPsGetNextNamepath PARAMETERS : ParserState - Current parser state object Arg - Where the namepath will be stored ArgCount - If the namepath points to a control method the method ' s argument is returned here . PossibleMethodCall - Whether the namepath can possibly be the start of a method call Status Get next name ( if method call return # of required args ) . Names are looked up in the internal namespace to determine if the name represents a control method . If a method is found the number of arguments to the method is returned . This information is critical for parsing to continue correctly .
ACPI_STATUS
AcpiPsGetNextNamepath (
    ACPI_WALK_STATE         *WalkState,
    ACPI_PARSE_STATE        *ParserState,
    ACPI_PARSE_OBJECT       *Arg,
    BOOLEAN                 PossibleMethodCall)
{
    ACPI_STATUS             Status;
    char                    *Path;
    ACPI_PARSE_OBJECT       *NameOp;
    ACPI_OPERAND_OBJECT     *MethodDesc;
    ACPI_NAMESPACE_NODE     *Node;
    UINT8                   *Start = ParserState->Aml;
    ACPI_FUNCTION_TRACE (PsGetNextNamepath);
    Path = AcpiPsGetNextNamestring (ParserState);
    AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
    if (!Path)
    {
        Arg->Common.Value.Name = Path;
        return_ACPI_STATUS (AE_OK);
    }
    Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
        ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
        ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
    if (ACPI_SUCCESS (Status) &&
        PossibleMethodCall &&
        (Node->Type == ACPI_TYPE_METHOD))
    {
        if (WalkState->Opcode == AML_UNLOAD_OP)
        {
            WalkState->ParserState.Aml = Start;
            WalkState->ArgCount = 1;
            AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
            return_ACPI_STATUS (AE_OK);
        }
        MethodDesc = AcpiNsGetAttachedObject (Node);
        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
            "Control Method - %p Desc %p Path=%p\n", Node, MethodDesc, Path));
        NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Start);
        if (!NameOp)
        {
            return_ACPI_STATUS (AE_NO_MEMORY);
        }
        AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
        NameOp->Common.Value.Name = Path;
        NameOp->Common.Node = Node;
        AcpiPsAppendArg (Arg, NameOp);
        if (!MethodDesc)
        {
            ACPI_ERROR ((AE_INFO,
                "Control Method %p has no attached object",
                Node));
            return_ACPI_STATUS (AE_AML_INTERNAL);
        }
        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
            "Control Method - %p Args %X\n",
            Node, MethodDesc->Method.ParamCount));
        WalkState->ArgCount = MethodDesc->Method.ParamCount;
        return_ACPI_STATUS (AE_OK);
    }
    if (Status == AE_NOT_FOUND)
    {
        if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=
            ACPI_PARSE_EXECUTE)
        {
            Status = AE_OK;
        }
        else if (WalkState->Op->Common.AmlOpcode == AML_COND_REF_OF_OP)
        {
            Status = AE_OK;
        }
        else if ((Arg->Common.Parent) &&
            ((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
             (Arg->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
        {
            Status = AE_OK;
        }
    }
    if (ACPI_FAILURE (Status))
    {
        ACPI_ERROR_NAMESPACE (Path, Status);
        if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
            ACPI_PARSE_EXECUTE)
        {
            Status = AcpiDsMethodError (Status, WalkState);
        }
    }
    Arg->Common.Value.Name = Path;
    return_ACPI_STATUS (Status);
}
ACPI_STATUS AcpiPsGetNextNamepath ( ACPI_WALK_STATE * WalkState , ACPI_PARSE_STATE * ParserState , ACPI_PARSE_OBJECT * Arg , BOOLEAN PossibleMethodCall ) { ACPI_STATUS Status ; char * Path ; ACPI_PARSE_OBJECT * NameOp ; ACPI_OPERAND_OBJECT * MethodDesc ; ACPI_NAMESPACE_NODE * Node ; UINT8 * Start = ParserState -> Aml ; ACPI_FUNCTION_TRACE ( PsGetNextNamepath ) ; Path = AcpiPsGetNextNamestring ( ParserState ) ; AcpiPsInitOp ( Arg , AML_INT_NAMEPATH_OP ) ; if ( ! Path ) { Arg -> Common . Value . Name = Path ; return_ACPI_STATUS ( AE_OK ) ; } Status = AcpiNsLookup ( WalkState -> ScopeInfo , Path , ACPI_TYPE_ANY , ACPI_IMODE_EXECUTE , ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE , NULL , & Node ) ; if ( ACPI_SUCCESS ( Status ) && PossibleMethodCall && ( Node -> Type == ACPI_TYPE_METHOD ) ) { if ( WalkState -> Opcode == AML_UNLOAD_OP ) { WalkState -> ParserState . Aml = Start ; WalkState -> ArgCount = 1 ; AcpiPsInitOp ( Arg , AML_INT_METHODCALL_OP ) ; return_ACPI_STATUS ( AE_OK ) ; } MethodDesc = AcpiNsGetAttachedObject ( Node ) ; ACPI_DEBUG_PRINT ( ( ACPI_DB_PARSE , " \n " , Node , MethodDesc , Path ) ) ; NameOp = AcpiPsAllocOp ( AML_INT_NAMEPATH_OP , Start ) ; if ( ! NameOp ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } AcpiPsInitOp ( Arg , AML_INT_METHODCALL_OP ) ; NameOp -> Common . Value . Name = Path ; NameOp -> Common . Node = Node ; AcpiPsAppendArg ( Arg , NameOp ) ; if ( ! MethodDesc ) { ACPI_ERROR ( ( AE_INFO , " " , Node ) ) ; return_ACPI_STATUS ( AE_AML_INTERNAL ) ; } ACPI_DEBUG_PRINT ( ( ACPI_DB_PARSE , " \n " , Node , MethodDesc -> Method . ParamCount ) ) ; WalkState -> ArgCount = MethodDesc -> Method . ParamCount ; return_ACPI_STATUS ( AE_OK ) ; } if ( Status == AE_NOT_FOUND ) { if ( ( WalkState -> ParseFlags & ACPI_PARSE_MODE_MASK ) != ACPI_PARSE_EXECUTE ) { Status = AE_OK ; } else if ( WalkState -> Op -> Common . AmlOpcode == AML_COND_REF_OF_OP ) { Status = AE_OK ; } else if ( ( Arg -> Common . Parent ) && ( ( Arg -> Common . Parent -> Common . AmlOpcode == AML_PACKAGE_OP ) || ( Arg -> Common . Parent -> Common . AmlOpcode == AML_VAR_PACKAGE_OP ) ) ) { Status = AE_OK ; } } if ( ACPI_FAILURE ( Status ) ) { ACPI_ERROR_NAMESPACE ( Path , Status ) ; if ( ( WalkState -> ParseFlags & ACPI_PARSE_MODE_MASK ) == ACPI_PARSE_EXECUTE ) { Status = AcpiDsMethodError ( Status , WalkState ) ; } } Arg -> Common . Value . Name = Path ; return_ACPI_STATUS ( Status ) ; }
FUNCTION:    AcpiPsGetNextNamepath
 PARAMETERS:  ParserState         - Current parser state object
              Arg                 - Where the namepath will be stored
              ArgCount            - If the namepath points to a control method
                                    the method's argument is returned here.
FUNCTION : AcpiPsGetNextNamepath PARAMETERS : ParserState - Current parser state object Arg - Where the namepath will be stored ArgCount - If the namepath points to a control method the method ' s argument is returned here .
/* Null path case is allowed, just exit */ /*
     * Lookup the name in the internal namespace, starting with the current
     * scope. We don't want to add anything new to the namespace here,
     * however, so we use MODE_EXECUTE.
     * Allow searching of the parent tree, but don't open a new scope -
     * we just want to lookup the object (must be mode EXECUTE to perform
     * the upsearch)
     */ /*
     * If this name is a control method invocation, we must
     * setup the method call
     */ /*
             * AcpiPsGetNextNamestring has increased the AML pointer,
             * so we need to restore the saved AML pointer for method call.
             */ /* This name is actually a control method invocation */ /* Change Arg into a METHOD CALL and attach name to it */ /* Point METHODCALL/NAME to the METHOD Node */ /* Get the number of arguments to expect */ /*
     * Special handling if the name was not found during the lookup -
     * some NotFound cases are allowed
     */ /* 1) NotFound is ok during load pass 1/2 (allow forward references) */ /* 2) NotFound during a CondRefOf(x) is ok by definition */ /*
         * 3) NotFound while building a Package is ok at this point, we
         * may flag as an error later if slack mode is not enabled.
         * (Some ASL code depends on allowing this behavior)
         */ /* Final exception check (may have been changed from code above) */ /* Report a control method execution error */ /* Save the namepath */