FreeBSD/sys/contrib/dev/acpica/components/utilities/utresrc.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiUtWalkAmlResources
 *
 * PARAMETERS:  WalkState           - Current walk info
 * PARAMETERS:  Aml                 - Pointer to the raw AML resource template
 *              AmlLength           - Length of the entire template
 *              UserFunction        - Called once for each descriptor found. If
 *                                    NULL, a pointer to the EndTag is returned
 *              Context             - Passed to UserFunction
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Walk a raw AML resource list(buffer). User function called
 *              once for each resource found.
 *
 ******************************************************************************/
AcpiUtWalkAmlResources
PARAMETERS:  WalkState           - Current walk info
PARAMETERS:  Aml                 - Pointer to the raw AML resource template
AmlLength           - Length of the entire template
UserFunction        - Called once for each descriptor found. If
NULL, a pointer to the EndTag is returned
Context             - Passed to UserFunction

Status

Walk a raw AML resource list(buffer). User function called
once for each resource found.
AcpiUtWalkAmlResources PARAMETERS : WalkState - Current walk info PARAMETERS : Aml - Pointer to the raw AML resource template AmlLength - Length of the entire template UserFunction - Called once for each descriptor found . If NULL a pointer to the EndTag is returned Context - Passed to UserFunction Status Walk a raw AML resource list ( buffer ) . User function called once for each resource found .
ACPI_STATUS
AcpiUtWalkAmlResources (
    ACPI_WALK_STATE         *WalkState,
    UINT8                   *Aml,
    ACPI_SIZE               AmlLength,
    ACPI_WALK_AML_CALLBACK  UserFunction,
    void                    **Context)
{
    ACPI_STATUS             Status;
    UINT8                   *EndAml;
    UINT8                   ResourceIndex;
    UINT32                  Length;
    UINT32                  Offset = 0;
    UINT8                   EndTag[2] = {0x79, 0x00};
    ACPI_FUNCTION_TRACE (UtWalkAmlResources);
    if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
    {
        return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
    }
    EndAml = Aml + AmlLength;
    while (Aml < EndAml)
    {
        Status = AcpiUtValidateResource (WalkState, Aml, &ResourceIndex);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
        Length = AcpiUtGetDescriptorLength (Aml);
        if (UserFunction)
        {
            Status = UserFunction (
                Aml, Length, Offset, ResourceIndex, Context);
            if (ACPI_FAILURE (Status))
            {
                return_ACPI_STATUS (Status);
            }
        }
        if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)
        {
            if ((Aml + 1) >= EndAml)
            {
                return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
            }
            if (!UserFunction)
            {
                *Context = Aml;
            }
            return_ACPI_STATUS (AE_OK);
        }
        Aml += Length;
        Offset += Length;
    }
    if (UserFunction)
    {
        (void) AcpiUtValidateResource (WalkState, EndTag, &ResourceIndex);
        Status = UserFunction (EndTag, 2, Offset, ResourceIndex, Context);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
    }
    return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
}
ACPI_STATUS AcpiUtWalkAmlResources ( ACPI_WALK_STATE * WalkState , UINT8 * Aml , ACPI_SIZE AmlLength , ACPI_WALK_AML_CALLBACK UserFunction , void * * Context ) { ACPI_STATUS Status ; UINT8 * EndAml ; UINT8 ResourceIndex ; UINT32 Length ; UINT32 Offset = 0 ; UINT8 EndTag [ 2 ] = { 0x79 , 0x00 } ; ACPI_FUNCTION_TRACE ( UtWalkAmlResources ) ; if ( AmlLength < sizeof ( AML_RESOURCE_END_TAG ) ) { return_ACPI_STATUS ( AE_AML_NO_RESOURCE_END_TAG ) ; } EndAml = Aml + AmlLength ; while ( Aml < EndAml ) { Status = AcpiUtValidateResource ( WalkState , Aml , & ResourceIndex ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } Length = AcpiUtGetDescriptorLength ( Aml ) ; if ( UserFunction ) { Status = UserFunction ( Aml , Length , Offset , ResourceIndex , Context ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } } if ( AcpiUtGetResourceType ( Aml ) == ACPI_RESOURCE_NAME_END_TAG ) { if ( ( Aml + 1 ) >= EndAml ) { return_ACPI_STATUS ( AE_AML_NO_RESOURCE_END_TAG ) ; } if ( ! UserFunction ) { * Context = Aml ; } return_ACPI_STATUS ( AE_OK ) ; } Aml += Length ; Offset += Length ; } if ( UserFunction ) { ( void ) AcpiUtValidateResource ( WalkState , EndTag , & ResourceIndex ) ; Status = UserFunction ( EndTag , 2 , Offset , ResourceIndex , Context ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } } return_ACPI_STATUS ( AE_AML_NO_RESOURCE_END_TAG ) ; }
FUNCTION:    AcpiUtWalkAmlResources
 PARAMETERS:  WalkState           - Current walk info
 PARAMETERS:  Aml                 - Pointer to the raw AML resource template
              AmlLength           - Length of the entire template
              UserFunction        - Called once for each descriptor found.
FUNCTION : AcpiUtWalkAmlResources PARAMETERS : WalkState - Current walk info PARAMETERS : Aml - Pointer to the raw AML resource template AmlLength - Length of the entire template UserFunction - Called once for each descriptor found .
/* The absolute minimum resource template is one EndTag descriptor */ /* Point to the end of the resource template buffer */ /* Walk the byte list, abort on any invalid descriptor type or length */ /* Validate the Resource Type and Resource Length */ /*
             * Exit on failure. Cannot continue because the descriptor
             * length may be bogus also.
             */ /* Get the length of this descriptor */ /* Invoke the user function */ /* An EndTag descriptor terminates this resource template */ /*
             * There must be at least one more byte in the buffer for
             * the 2nd byte of the EndTag
             */ /* Return the pointer to the EndTag if requested */ /* Normal exit */ /* Did not find an EndTag descriptor */ /* Insert an EndTag anyway. AcpiRsGetListLength always leaves room */