FreeBSD/sys/contrib/dev/acpica/components/utilities/utmisc.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiUtWalkPackageTree
 *
 * PARAMETERS:  SourceObject        - The package to walk
 *              TargetObject        - Target object (if package is being copied)
 *              WalkCallback        - Called once for each package element
 *              Context             - Passed to the callback function
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Walk through a package
 *
 ******************************************************************************/
AcpiUtWalkPackageTree
PARAMETERS:  SourceObject        - The package to walk
TargetObject        - Target object (if package is being copied)
WalkCallback        - Called once for each package element
Context             - Passed to the callback function

Status

Walk through a package
AcpiUtWalkPackageTree PARAMETERS : SourceObject - The package to walk TargetObject - Target object ( if package is being copied ) WalkCallback - Called once for each package element Context - Passed to the callback function Status Walk through a package
ACPI_STATUS
AcpiUtWalkPackageTree (
    ACPI_OPERAND_OBJECT     *SourceObject,
    void                    *TargetObject,
    ACPI_PKG_CALLBACK       WalkCallback,
    void                    *Context)
{
    ACPI_STATUS             Status = AE_OK;
    ACPI_GENERIC_STATE      *StateList = NULL;
    ACPI_GENERIC_STATE      *State;
    UINT32                  ThisIndex;
    ACPI_OPERAND_OBJECT     *ThisSourceObj;
    ACPI_FUNCTION_TRACE (UtWalkPackageTree);
    State = AcpiUtCreatePkgState (SourceObject, TargetObject, 0);
    if (!State)
    {
        return_ACPI_STATUS (AE_NO_MEMORY);
    }
    while (State)
    {
        ThisIndex = State->Pkg.Index;
        ThisSourceObj = (ACPI_OPERAND_OBJECT *)
            State->Pkg.SourceObject->Package.Elements[ThisIndex];
        if ((!ThisSourceObj) ||
            (ACPI_GET_DESCRIPTOR_TYPE (ThisSourceObj) !=
                ACPI_DESC_TYPE_OPERAND) ||
            (ThisSourceObj->Common.Type != ACPI_TYPE_PACKAGE))
        {
            Status = WalkCallback (ACPI_COPY_TYPE_SIMPLE, ThisSourceObj,
                                    State, Context);
            if (ACPI_FAILURE (Status))
            {
                return_ACPI_STATUS (Status);
            }
            State->Pkg.Index++;
            while (State->Pkg.Index >=
                State->Pkg.SourceObject->Package.Count)
            {
                AcpiUtDeleteGenericState (State);
                State = AcpiUtPopGenericState (&StateList);
                if (!State)
                {
                    return_ACPI_STATUS (AE_OK);
                }
                State->Pkg.Index++;
            }
        }
        else
        {
            Status = WalkCallback (
                ACPI_COPY_TYPE_PACKAGE, ThisSourceObj, State, Context);
            if (ACPI_FAILURE (Status))
            {
                return_ACPI_STATUS (Status);
            }
            AcpiUtPushGenericState (&StateList, State);
            State = AcpiUtCreatePkgState (
                ThisSourceObj, State->Pkg.ThisTargetObj, 0);
            if (!State)
            {
                while (StateList)
                {
                    State = AcpiUtPopGenericState (&StateList);
                    AcpiUtDeleteGenericState (State);
                }
                return_ACPI_STATUS (AE_NO_MEMORY);
            }
        }
    }
    return_ACPI_STATUS (AE_AML_INTERNAL);
}
ACPI_STATUS AcpiUtWalkPackageTree ( ACPI_OPERAND_OBJECT * SourceObject , void * TargetObject , ACPI_PKG_CALLBACK WalkCallback , void * Context ) { ACPI_STATUS Status = AE_OK ; ACPI_GENERIC_STATE * StateList = NULL ; ACPI_GENERIC_STATE * State ; UINT32 ThisIndex ; ACPI_OPERAND_OBJECT * ThisSourceObj ; ACPI_FUNCTION_TRACE ( UtWalkPackageTree ) ; State = AcpiUtCreatePkgState ( SourceObject , TargetObject , 0 ) ; if ( ! State ) { return_ACPI_STATUS ( AE_NO_MEMORY ) ; } while ( State ) { ThisIndex = State -> Pkg . Index ; ThisSourceObj = ( ACPI_OPERAND_OBJECT * ) State -> Pkg . SourceObject -> Package . Elements [ ThisIndex ] ; if ( ( ! ThisSourceObj ) || ( ACPI_GET_DESCRIPTOR_TYPE ( ThisSourceObj ) != ACPI_DESC_TYPE_OPERAND ) || ( ThisSourceObj -> Common . Type != ACPI_TYPE_PACKAGE ) ) { Status = WalkCallback ( ACPI_COPY_TYPE_SIMPLE , ThisSourceObj , State , Context ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } State -> Pkg . Index ++ ; while ( State -> Pkg . Index >= State -> Pkg . SourceObject -> Package . Count ) { AcpiUtDeleteGenericState ( State ) ; State = AcpiUtPopGenericState ( & StateList ) ; if ( ! State ) { return_ACPI_STATUS ( AE_OK ) ; } State -> Pkg . Index ++ ; } } else { Status = WalkCallback ( ACPI_COPY_TYPE_PACKAGE , ThisSourceObj , State , Context ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } AcpiUtPushGenericState ( & StateList , State ) ; State = AcpiUtCreatePkgState ( ThisSourceObj , State -> Pkg . ThisTargetObj , 0 ) ; if ( ! State ) { while ( StateList ) { State = AcpiUtPopGenericState ( & StateList ) ; AcpiUtDeleteGenericState ( State ) ; } return_ACPI_STATUS ( AE_NO_MEMORY ) ; } } } return_ACPI_STATUS ( AE_AML_INTERNAL ) ; }
FUNCTION:    AcpiUtWalkPackageTree
 PARAMETERS:  SourceObject        - The package to walk
              TargetObject        - Target object (if package is being copied)
              WalkCallback        - Called once for each package element
              Context             - Passed to the callback function
FUNCTION : AcpiUtWalkPackageTree PARAMETERS : SourceObject - The package to walk TargetObject - Target object ( if package is being copied ) WalkCallback - Called once for each package element Context - Passed to the callback function
/* Get one element of the package */ /*
         * Check for:
         * 1) An uninitialized package element. It is completely
         *    legal to declare a package and leave it uninitialized
         * 2) Not an internal object - can be a namespace node instead
         * 3) Any type other than a package. Packages are handled in else
         *    case below.
         */ /*
                 * We've handled all of the objects at this level,  This means
                 * that we have just completed a package. That package may
                 * have contained one or more packages itself.
                 *
                 * Delete this state and pop the previous state (package).
                 */ /* Finished when there are no more states */ /*
                     * We have handled all of the objects in the top level
                     * package just add the length of the package objects
                     * and exit
                     */ /*
                 * Go back up a level and move the index past the just
                 * completed package object.
                 */ /* This is a subobject of type package */ /*
             * Push the current state and create a new one
             * The callback above returned a new target package object.
             */ /* Free any stacked Update State objects */ /* We should never get here */