FreeBSD/sys/contrib/dev/acpica/compiler/aslprepkg.c
/*******************************************************************************
 *
 * FUNCTION:    ApCheckPackageList
 *
 * PARAMETERS:  PredefinedName      - Name of the predefined object
 *              ParentOp            - Parser op of the parent package
 *              Package             - Package info for this predefined name
 *              StartIndex          - Index in parent package where list begins
 *              ParentCount         - Element count of parent package
 *
 * RETURN:      None
 *
 * DESCRIPTION: Validate the individual package elements for a predefined name.
 *              Handles the cases where the predefined name is defined as a
 *              Package of Packages (subpackages). These are the types:
 *
 *              ACPI_PTYPE2
 *              ACPI_PTYPE2_FIXED
 *              ACPI_PTYPE2_MIN
 *              ACPI_PTYPE2_COUNT
 *              ACPI_PTYPE2_FIX_VAR
 *              ACPI_PTYPE2_VAR_VAR
 *
 ******************************************************************************/


None

Validate the individual package elements for a predefined name.
Handles the cases where the predefined name is defined as a
Package of Packages (subpackages). These are the types.


None Validate the individual package elements for a predefined name . Handles the cases where the predefined name is defined as a Package of Packages ( subpackages ) . These are the types .
static void
ApCheckPackageList (
    const char                  *PredefinedName,
    ACPI_PARSE_OBJECT           *ParentOp,
    const ACPI_PREDEFINED_INFO  *Package,
    UINT32                      StartIndex,
    UINT32                      ParentCount)
{
    ACPI_PARSE_OBJECT           *SubPackageOp = ParentOp;
    ACPI_PARSE_OBJECT           *Op;
    ACPI_STATUS                 Status;
    UINT32                      Count;
    UINT32                      ExpectedCount;
    UINT32                      i;
    UINT32                      j;
    for (i = 0; (i < ParentCount) && SubPackageOp; i++)
    {
        Status = ApCheckObjectType (PredefinedName, SubPackageOp,
            ACPI_RTYPE_PACKAGE, i + StartIndex);
        if (ACPI_FAILURE (Status))
        {
            goto NextSubpackage;
        }
        Op = SubPackageOp->Asl.Child;
        Count = (UINT32) Op->Asl.Value.Integer;
        Op = Op->Asl.Next;
        if (!Count &&
            (Package->RetInfo.Type != ACPI_PTYPE2_VAR_VAR))
        {
            ApZeroLengthPackage (PredefinedName, SubPackageOp);
            goto NextSubpackage;
        }
        switch (Package->RetInfo.Type)
        {
        case ACPI_PTYPE2:
        case ACPI_PTYPE2_PKG_COUNT:
        case ACPI_PTYPE2_REV_FIXED:
            ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
            if (Count < ExpectedCount)
            {
                ApPackageTooSmall (PredefinedName, SubPackageOp,
                    Count, ExpectedCount);
                break;
            }
            if (Count > ExpectedCount)
            {
                ApPackageTooLarge (PredefinedName, SubPackageOp,
                    Count, ExpectedCount);
                break;
            }
            ApCheckPackageElements (PredefinedName, Op,
                Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
                Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
            break;
        case ACPI_PTYPE2_FIX_VAR:
            ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
            if (Count < ExpectedCount)
            {
                ApPackageTooSmall (PredefinedName, SubPackageOp,
                    Count, ExpectedCount);
                break;
            }
            ApCheckPackageElements (PredefinedName, Op,
                Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
                Package->RetInfo.ObjectType2,
                Count - Package->RetInfo.Count1);
            break;
        case ACPI_PTYPE2_VAR_VAR:
            ExpectedCount = Package->RetInfo4.PkgCount;
            if (ExpectedCount && (Count < ExpectedCount))
            {
                ApPackageTooSmall (PredefinedName, SubPackageOp,
                    Count, 1);
                break;
            }
            ApCheckPackageElements (PredefinedName, Op,
                Package->RetInfo4.SubObjectTypes,
                Package->RetInfo4.PkgCount,
                0, 0);
            break;
        case ACPI_PTYPE2_FIXED:
            ExpectedCount = Package->RetInfo2.Count;
            if (Count < ExpectedCount)
            {
                ApPackageTooSmall (PredefinedName, SubPackageOp,
                    Count, ExpectedCount);
                break;
            }
            if (Count > ExpectedCount)
            {
                ApPackageTooLarge (PredefinedName, SubPackageOp,
                    Count, ExpectedCount);
                break;
            }
            for (j = 0; j < ExpectedCount; j++)
            {
                ApCheckObjectType (PredefinedName, Op,
                    Package->RetInfo2.ObjectType[j], j);
                Op = Op->Asl.Next;
            }
            break;
        case ACPI_PTYPE2_MIN:
            ExpectedCount = Package->RetInfo.Count1;
            if (Count < ExpectedCount)
            {
                ApPackageTooSmall (PredefinedName, SubPackageOp,
                    Count, ExpectedCount);
                break;
            }
            ApCheckPackageElements (PredefinedName, Op,
                Package->RetInfo.ObjectType1, Count, 0, 0);
            break;
        case ACPI_PTYPE2_COUNT:
            Status = ApCheckObjectType (PredefinedName, Op,
                ACPI_RTYPE_INTEGER, 0);
            if (ACPI_SUCCESS (Status))
            {
                ExpectedCount = (UINT32) Op->Asl.Value.Integer;
                if (Count < ExpectedCount)
                {
                    ApPackageTooSmall (PredefinedName, SubPackageOp,
                        Count, ExpectedCount);
                    break;
                }
                else if (Count > ExpectedCount)
                {
                    ApPackageTooLarge (PredefinedName, SubPackageOp,
                        Count, ExpectedCount);
                }
                if (Count < Package->RetInfo.Count1)
                {
                    ExpectedCount = Package->RetInfo.Count1;
                    ApPackageTooSmall (PredefinedName, SubPackageOp,
                        Count, ExpectedCount);
                    break;
                }
                Count = ExpectedCount;
            }
            Op = Op->Asl.Next;
            ApCheckPackageElements (PredefinedName, Op,
                Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
            break;
        default:
            break;
        }
NextSubpackage:
        SubPackageOp = SubPackageOp->Asl.Next;
    }
}
static void ApCheckPackageList ( const char * PredefinedName , ACPI_PARSE_OBJECT * ParentOp , const ACPI_PREDEFINED_INFO * Package , UINT32 StartIndex , UINT32 ParentCount ) { ACPI_PARSE_OBJECT * SubPackageOp = ParentOp ; ACPI_PARSE_OBJECT * Op ; ACPI_STATUS Status ; UINT32 Count ; UINT32 ExpectedCount ; UINT32 i ; UINT32 j ; for ( i = 0 ; ( i < ParentCount ) && SubPackageOp ; i ++ ) { Status = ApCheckObjectType ( PredefinedName , SubPackageOp , ACPI_RTYPE_PACKAGE , i + StartIndex ) ; if ( ACPI_FAILURE ( Status ) ) { goto NextSubpackage ; } Op = SubPackageOp -> Asl . Child ; Count = ( UINT32 ) Op -> Asl . Value . Integer ; Op = Op -> Asl . Next ; if ( ! Count && ( Package -> RetInfo . Type != ACPI_PTYPE2_VAR_VAR ) ) { ApZeroLengthPackage ( PredefinedName , SubPackageOp ) ; goto NextSubpackage ; } switch ( Package -> RetInfo . Type ) { case ACPI_PTYPE2 : case ACPI_PTYPE2_PKG_COUNT : case ACPI_PTYPE2_REV_FIXED : ExpectedCount = Package -> RetInfo . Count1 + Package -> RetInfo . Count2 ; if ( Count < ExpectedCount ) { ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } if ( Count > ExpectedCount ) { ApPackageTooLarge ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } ApCheckPackageElements ( PredefinedName , Op , Package -> RetInfo . ObjectType1 , Package -> RetInfo . Count1 , Package -> RetInfo . ObjectType2 , Package -> RetInfo . Count2 ) ; break ; case ACPI_PTYPE2_FIX_VAR : ExpectedCount = Package -> RetInfo . Count1 + Package -> RetInfo . Count2 ; if ( Count < ExpectedCount ) { ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } ApCheckPackageElements ( PredefinedName , Op , Package -> RetInfo . ObjectType1 , Package -> RetInfo . Count1 , Package -> RetInfo . ObjectType2 , Count - Package -> RetInfo . Count1 ) ; break ; case ACPI_PTYPE2_VAR_VAR : ExpectedCount = Package -> RetInfo4 . PkgCount ; if ( ExpectedCount && ( Count < ExpectedCount ) ) { ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , 1 ) ; break ; } ApCheckPackageElements ( PredefinedName , Op , Package -> RetInfo4 . SubObjectTypes , Package -> RetInfo4 . PkgCount , 0 , 0 ) ; break ; case ACPI_PTYPE2_FIXED : ExpectedCount = Package -> RetInfo2 . Count ; if ( Count < ExpectedCount ) { ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } if ( Count > ExpectedCount ) { ApPackageTooLarge ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } for ( j = 0 ; j < ExpectedCount ; j ++ ) { ApCheckObjectType ( PredefinedName , Op , Package -> RetInfo2 . ObjectType [ j ] , j ) ; Op = Op -> Asl . Next ; } break ; case ACPI_PTYPE2_MIN : ExpectedCount = Package -> RetInfo . Count1 ; if ( Count < ExpectedCount ) { ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } ApCheckPackageElements ( PredefinedName , Op , Package -> RetInfo . ObjectType1 , Count , 0 , 0 ) ; break ; case ACPI_PTYPE2_COUNT : Status = ApCheckObjectType ( PredefinedName , Op , ACPI_RTYPE_INTEGER , 0 ) ; if ( ACPI_SUCCESS ( Status ) ) { ExpectedCount = ( UINT32 ) Op -> Asl . Value . Integer ; if ( Count < ExpectedCount ) { ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } else if ( Count > ExpectedCount ) { ApPackageTooLarge ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; } if ( Count < Package -> RetInfo . Count1 ) { ExpectedCount = Package -> RetInfo . Count1 ; ApPackageTooSmall ( PredefinedName , SubPackageOp , Count , ExpectedCount ) ; break ; } Count = ExpectedCount ; } Op = Op -> Asl . Next ; ApCheckPackageElements ( PredefinedName , Op , Package -> RetInfo . ObjectType1 , ( Count - 1 ) , 0 , 0 ) ; break ; default : break ; } NextSubpackage : SubPackageOp = SubPackageOp -> Asl . Next ; } }
FUNCTION:    ApCheckPackageList
 PARAMETERS:  PredefinedName      - Name of the predefined object
              ParentOp            - Parser op of the parent package
              Package             - Package info for this predefined name
              StartIndex          - Index in parent package where list begins
              ParentCount         - Element count of parent package
FUNCTION : ApCheckPackageList PARAMETERS : PredefinedName - Name of the predefined object ParentOp - Parser op of the parent package Package - Package info for this predefined name StartIndex - Index in parent package where list begins ParentCount - Element count of parent package
/*
     * Validate each subpackage in the parent Package
     *
     * Note: We ignore NULL package elements on the assumption that
     * they will be initialized by the BIOS or other ASL code.
     */ /* Each object in the list must be of type Package */ /* Examine the different types of expected subpackages */ /* First child is the package length */ /*
         * Most subpackage must have at least one element, with
         * only rare exceptions. (_RDI)
         */ /*
         * Decode the package type.
         * PTYPE2 indicates that a "package of packages" is expected for
         * this name. The various flavors of PTYPE2 indicate the number
         * and format of the subpackages.
         */ /* Each subpackage has a fixed number of elements */ /*
             * Each subpackage has a fixed number of elements and an
             * optional element
             */ /*
             * Must have at least the minimum number elements.
             * A zero PkgCount means the number of elements is variable.
             */ /* Each subpackage has a fixed length */ /* Check each object/type combination */ /* Each subpackage has a variable but minimum length */ /* Check the type of each subpackage element */ /*
             * First element is the (Integer) count of elements, including
             * the count field (the ACPI name is NumElements)
             */ /* We must have an integer count from above (otherwise, use Count) */ /*
                 * Make sure package is large enough for the Count and is
                 * is as large as the minimum size
                 */ /* Some names of this type have a minimum length */ /* Check the type of each subpackage element */