xref: /freebsd/sys/contrib/dev/acpica/compiler/aslprepkg.c (revision 6f1f1a6395c91c5a845727d7313921a6fe3d297b)
19c48c75eSJung-uk Kim /******************************************************************************
29c48c75eSJung-uk Kim  *
39c48c75eSJung-uk Kim  * Module Name: aslprepkg - support for ACPI predefined name package objects
49c48c75eSJung-uk Kim  *
59c48c75eSJung-uk Kim  *****************************************************************************/
69c48c75eSJung-uk Kim 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
1132ac4016SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
129c48c75eSJung-uk Kim  * All rights reserved.
139c48c75eSJung-uk Kim  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
1199c48c75eSJung-uk Kim  * Redistribution and use in source and binary forms, with or without
1209c48c75eSJung-uk Kim  * modification, are permitted provided that the following conditions
1219c48c75eSJung-uk Kim  * are met:
1229c48c75eSJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
1239c48c75eSJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
1249c48c75eSJung-uk Kim  *    without modification.
1259c48c75eSJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1269c48c75eSJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
1279c48c75eSJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
1289c48c75eSJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
1299c48c75eSJung-uk Kim  *    binary redistribution.
1309c48c75eSJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
1319c48c75eSJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
1329c48c75eSJung-uk Kim  *    from this software without specific prior written permission.
1339c48c75eSJung-uk Kim  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1479c48c75eSJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
1489c48c75eSJung-uk Kim  * Software Foundation.
1499c48c75eSJung-uk Kim  *
1500d84335fSJung-uk Kim  *****************************************************************************/
1519c48c75eSJung-uk Kim 
1529c48c75eSJung-uk Kim #include <contrib/dev/acpica/compiler/aslcompiler.h>
1539c48c75eSJung-uk Kim #include "aslcompiler.y.h"
1549c48c75eSJung-uk Kim #include <contrib/dev/acpica/include/acpredef.h>
1559c48c75eSJung-uk Kim 
1569c48c75eSJung-uk Kim 
1579c48c75eSJung-uk Kim #define _COMPONENT          ACPI_COMPILER
1589c48c75eSJung-uk Kim         ACPI_MODULE_NAME    ("aslprepkg")
1599c48c75eSJung-uk Kim 
1609c48c75eSJung-uk Kim 
1619c48c75eSJung-uk Kim /* Local prototypes */
1629c48c75eSJung-uk Kim 
163f8146b88SJung-uk Kim static ACPI_PARSE_OBJECT *
1649c48c75eSJung-uk Kim ApCheckPackageElements (
1659c48c75eSJung-uk Kim     const char                  *PredefinedName,
1669c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op,
1679c48c75eSJung-uk Kim     UINT8                       Type1,
1689c48c75eSJung-uk Kim     UINT32                      Count1,
1699c48c75eSJung-uk Kim     UINT8                       Type2,
1709c48c75eSJung-uk Kim     UINT32                      Count2);
1719c48c75eSJung-uk Kim 
1729c48c75eSJung-uk Kim static void
1739c48c75eSJung-uk Kim ApCheckPackageList (
1749c48c75eSJung-uk Kim     const char                  *PredefinedName,
1759c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *ParentOp,
1769c48c75eSJung-uk Kim     const ACPI_PREDEFINED_INFO  *Package,
1779c48c75eSJung-uk Kim     UINT32                      StartIndex,
1789c48c75eSJung-uk Kim     UINT32                      Count);
1799c48c75eSJung-uk Kim 
1809c48c75eSJung-uk Kim static void
1819c48c75eSJung-uk Kim ApPackageTooSmall (
1829c48c75eSJung-uk Kim     const char                  *PredefinedName,
1839c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op,
1849c48c75eSJung-uk Kim     UINT32                      Count,
1859c48c75eSJung-uk Kim     UINT32                      ExpectedCount);
1869c48c75eSJung-uk Kim 
1879c48c75eSJung-uk Kim static void
1889c48c75eSJung-uk Kim ApZeroLengthPackage (
1899c48c75eSJung-uk Kim     const char                  *PredefinedName,
1909c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op);
1919c48c75eSJung-uk Kim 
1929c48c75eSJung-uk Kim static void
1939c48c75eSJung-uk Kim ApPackageTooLarge (
1949c48c75eSJung-uk Kim     const char                  *PredefinedName,
1959c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op,
1969c48c75eSJung-uk Kim     UINT32                      Count,
1979c48c75eSJung-uk Kim     UINT32                      ExpectedCount);
1989c48c75eSJung-uk Kim 
199f8146b88SJung-uk Kim static void
200f8146b88SJung-uk Kim ApCustomPackage (
201f8146b88SJung-uk Kim     ACPI_PARSE_OBJECT           *ParentOp,
202f8146b88SJung-uk Kim     const ACPI_PREDEFINED_INFO  *Predefined);
203f8146b88SJung-uk Kim 
2049c48c75eSJung-uk Kim 
2059c48c75eSJung-uk Kim /*******************************************************************************
2069c48c75eSJung-uk Kim  *
2079c48c75eSJung-uk Kim  * FUNCTION:    ApCheckPackage
2089c48c75eSJung-uk Kim  *
2099c48c75eSJung-uk Kim  * PARAMETERS:  ParentOp            - Parser op for the package
210895f26a9SJung-uk Kim  *              Predefined          - Pointer to package-specific info for
211895f26a9SJung-uk Kim  *                                    the method
2129c48c75eSJung-uk Kim  *
2139c48c75eSJung-uk Kim  * RETURN:      None
2149c48c75eSJung-uk Kim  *
2159c48c75eSJung-uk Kim  * DESCRIPTION: Top-level validation for predefined name return package
2169c48c75eSJung-uk Kim  *              objects.
2179c48c75eSJung-uk Kim  *
2189c48c75eSJung-uk Kim  ******************************************************************************/
2199c48c75eSJung-uk Kim 
2209c48c75eSJung-uk Kim void
2219c48c75eSJung-uk Kim ApCheckPackage (
2229c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *ParentOp,
2239c48c75eSJung-uk Kim     const ACPI_PREDEFINED_INFO  *Predefined)
2249c48c75eSJung-uk Kim {
2259c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op;
2269c48c75eSJung-uk Kim     const ACPI_PREDEFINED_INFO  *Package;
2279c48c75eSJung-uk Kim     ACPI_STATUS                 Status;
2289c48c75eSJung-uk Kim     UINT32                      ExpectedCount;
2299c48c75eSJung-uk Kim     UINT32                      Count;
2309c48c75eSJung-uk Kim     UINT32                      i;
2319c48c75eSJung-uk Kim 
2329c48c75eSJung-uk Kim 
2339c48c75eSJung-uk Kim     /* The package info for this name is in the next table entry */
2349c48c75eSJung-uk Kim 
2359c48c75eSJung-uk Kim     Package = Predefined + 1;
2369c48c75eSJung-uk Kim 
2379c48c75eSJung-uk Kim     /* First child is the package length */
2389c48c75eSJung-uk Kim 
2399c48c75eSJung-uk Kim     Op = ParentOp->Asl.Child;
2409c48c75eSJung-uk Kim     Count = (UINT32) Op->Asl.Value.Integer;
2419c48c75eSJung-uk Kim 
2429c48c75eSJung-uk Kim     /*
2439c7c683cSJung-uk Kim      * Many of the variable-length top-level packages are allowed to simply
2449c7c683cSJung-uk Kim      * have zero elements. This allows the BIOS to tell the host that even
2459c7c683cSJung-uk Kim      * though the predefined name/method exists, the feature is not supported.
2469c7c683cSJung-uk Kim      * Other package types require one or more elements. In any case, there
2479c7c683cSJung-uk Kim      * is no need to continue validation.
2489c48c75eSJung-uk Kim      */
2499c48c75eSJung-uk Kim     if (!Count)
2509c48c75eSJung-uk Kim     {
2519c7c683cSJung-uk Kim         switch (Package->RetInfo.Type)
2529c48c75eSJung-uk Kim         {
2539c7c683cSJung-uk Kim         case ACPI_PTYPE1_FIXED:
2549c7c683cSJung-uk Kim         case ACPI_PTYPE1_OPTION:
2559c7c683cSJung-uk Kim         case ACPI_PTYPE2_PKG_COUNT:
2569c7c683cSJung-uk Kim         case ACPI_PTYPE2_REV_FIXED:
2579c7c683cSJung-uk Kim 
2589c48c75eSJung-uk Kim             ApZeroLengthPackage (Predefined->Info.Name, ParentOp);
2599c7c683cSJung-uk Kim             break;
2609c7c683cSJung-uk Kim 
2619c7c683cSJung-uk Kim         case ACPI_PTYPE1_VAR:
2629c7c683cSJung-uk Kim         case ACPI_PTYPE2:
2639c7c683cSJung-uk Kim         case ACPI_PTYPE2_COUNT:
2649c7c683cSJung-uk Kim         case ACPI_PTYPE2_FIXED:
2659c7c683cSJung-uk Kim         case ACPI_PTYPE2_MIN:
2669c7c683cSJung-uk Kim         case ACPI_PTYPE2_FIX_VAR:
267a371a5fdSJung-uk Kim         case ACPI_PTYPE2_VAR_VAR:
2689c7c683cSJung-uk Kim         default:
2699c7c683cSJung-uk Kim 
2709c7c683cSJung-uk Kim             break;
2719c48c75eSJung-uk Kim         }
2729c7c683cSJung-uk Kim 
2739c48c75eSJung-uk Kim         return;
2749c48c75eSJung-uk Kim     }
2759c48c75eSJung-uk Kim 
2769c48c75eSJung-uk Kim     /* Get the first element of the package */
2779c48c75eSJung-uk Kim 
2789c48c75eSJung-uk Kim     Op = Op->Asl.Next;
2799c48c75eSJung-uk Kim 
2809c48c75eSJung-uk Kim     /* Decode the package type */
2819c48c75eSJung-uk Kim 
2829c48c75eSJung-uk Kim     switch (Package->RetInfo.Type)
2839c48c75eSJung-uk Kim     {
284f8146b88SJung-uk Kim     case ACPI_PTYPE_CUSTOM:
285f8146b88SJung-uk Kim 
286f8146b88SJung-uk Kim         ApCustomPackage (ParentOp, Predefined);
287f8146b88SJung-uk Kim         break;
288f8146b88SJung-uk Kim 
2899c48c75eSJung-uk Kim     case ACPI_PTYPE1_FIXED:
2909c48c75eSJung-uk Kim         /*
291313a0c13SJung-uk Kim          * The package count is fixed and there are no subpackages
2929c48c75eSJung-uk Kim          *
2939c48c75eSJung-uk Kim          * If package is too small, exit.
2949c48c75eSJung-uk Kim          * If package is larger than expected, issue warning but continue
2959c48c75eSJung-uk Kim          */
2969c48c75eSJung-uk Kim         ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
2979c48c75eSJung-uk Kim         if (Count < ExpectedCount)
2989c48c75eSJung-uk Kim         {
2999c48c75eSJung-uk Kim             goto PackageTooSmall;
3009c48c75eSJung-uk Kim         }
3019c48c75eSJung-uk Kim         else if (Count > ExpectedCount)
3029c48c75eSJung-uk Kim         {
3039c48c75eSJung-uk Kim             ApPackageTooLarge (Predefined->Info.Name, ParentOp,
3049c48c75eSJung-uk Kim                 Count, ExpectedCount);
3059c48c75eSJung-uk Kim         }
3069c48c75eSJung-uk Kim 
3079c48c75eSJung-uk Kim         /* Validate all elements of the package */
3089c48c75eSJung-uk Kim 
3099c48c75eSJung-uk Kim         ApCheckPackageElements (Predefined->Info.Name, Op,
3109c48c75eSJung-uk Kim             Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
3119c48c75eSJung-uk Kim             Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
3129c48c75eSJung-uk Kim         break;
3139c48c75eSJung-uk Kim 
3149c48c75eSJung-uk Kim     case ACPI_PTYPE1_VAR:
3159c48c75eSJung-uk Kim         /*
316313a0c13SJung-uk Kim          * The package count is variable, there are no subpackages,
317895f26a9SJung-uk Kim          * and all elements must be of the same type
3189c48c75eSJung-uk Kim          */
3199c48c75eSJung-uk Kim         for (i = 0; i < Count; i++)
3209c48c75eSJung-uk Kim         {
3219c48c75eSJung-uk Kim             ApCheckObjectType (Predefined->Info.Name, Op,
3229c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType1, i);
3239c48c75eSJung-uk Kim             Op = Op->Asl.Next;
3249c48c75eSJung-uk Kim         }
3259c48c75eSJung-uk Kim         break;
3269c48c75eSJung-uk Kim 
3279c48c75eSJung-uk Kim     case ACPI_PTYPE1_OPTION:
3289c48c75eSJung-uk Kim         /*
329313a0c13SJung-uk Kim          * The package count is variable, there are no subpackages.
330895f26a9SJung-uk Kim          * There are a fixed number of required elements, and a variable
331895f26a9SJung-uk Kim          * number of optional elements.
3329c48c75eSJung-uk Kim          *
3339c48c75eSJung-uk Kim          * Check if package is at least as large as the minimum required
3349c48c75eSJung-uk Kim          */
3359c48c75eSJung-uk Kim         ExpectedCount = Package->RetInfo3.Count;
3369c48c75eSJung-uk Kim         if (Count < ExpectedCount)
3379c48c75eSJung-uk Kim         {
3389c48c75eSJung-uk Kim             goto PackageTooSmall;
3399c48c75eSJung-uk Kim         }
3409c48c75eSJung-uk Kim 
3419c48c75eSJung-uk Kim         /* Variable number of sub-objects */
3429c48c75eSJung-uk Kim 
3439c48c75eSJung-uk Kim         for (i = 0; i < Count; i++)
3449c48c75eSJung-uk Kim         {
3459c48c75eSJung-uk Kim             if (i < Package->RetInfo3.Count)
3469c48c75eSJung-uk Kim             {
3479c48c75eSJung-uk Kim                 /* These are the required package elements (0, 1, or 2) */
3489c48c75eSJung-uk Kim 
3499c48c75eSJung-uk Kim                 ApCheckObjectType (Predefined->Info.Name, Op,
3509c48c75eSJung-uk Kim                     Package->RetInfo3.ObjectType[i], i);
3519c48c75eSJung-uk Kim             }
3529c48c75eSJung-uk Kim             else
3539c48c75eSJung-uk Kim             {
3549c48c75eSJung-uk Kim                 /* These are the optional package elements */
3559c48c75eSJung-uk Kim 
3569c48c75eSJung-uk Kim                 ApCheckObjectType (Predefined->Info.Name, Op,
3579c48c75eSJung-uk Kim                     Package->RetInfo3.TailObjectType, i);
3589c48c75eSJung-uk Kim             }
359f8146b88SJung-uk Kim 
3609c48c75eSJung-uk Kim             Op = Op->Asl.Next;
3619c48c75eSJung-uk Kim         }
3629c48c75eSJung-uk Kim         break;
3639c48c75eSJung-uk Kim 
3649c48c75eSJung-uk Kim     case ACPI_PTYPE2_REV_FIXED:
3659c48c75eSJung-uk Kim 
3669c48c75eSJung-uk Kim         /* First element is the (Integer) revision */
3679c48c75eSJung-uk Kim 
3689c48c75eSJung-uk Kim         ApCheckObjectType (Predefined->Info.Name, Op,
3699c48c75eSJung-uk Kim             ACPI_RTYPE_INTEGER, 0);
3709c48c75eSJung-uk Kim 
3719c48c75eSJung-uk Kim         Op = Op->Asl.Next;
3729c48c75eSJung-uk Kim         Count--;
3739c48c75eSJung-uk Kim 
374313a0c13SJung-uk Kim         /* Examine the subpackages */
3759c48c75eSJung-uk Kim 
3769c48c75eSJung-uk Kim         ApCheckPackageList (Predefined->Info.Name, Op,
3779c48c75eSJung-uk Kim             Package, 1, Count);
3789c48c75eSJung-uk Kim         break;
3799c48c75eSJung-uk Kim 
3809c48c75eSJung-uk Kim     case ACPI_PTYPE2_PKG_COUNT:
3819c48c75eSJung-uk Kim 
382313a0c13SJung-uk Kim         /* First element is the (Integer) count of subpackages to follow */
3839c48c75eSJung-uk Kim 
3849c48c75eSJung-uk Kim         Status = ApCheckObjectType (Predefined->Info.Name, Op,
3859c48c75eSJung-uk Kim             ACPI_RTYPE_INTEGER, 0);
3869c48c75eSJung-uk Kim 
3879c48c75eSJung-uk Kim         /* We must have an integer count from above (otherwise, use Count) */
3889c48c75eSJung-uk Kim 
3899c48c75eSJung-uk Kim         if (ACPI_SUCCESS (Status))
3909c48c75eSJung-uk Kim         {
3919c48c75eSJung-uk Kim             /*
392895f26a9SJung-uk Kim              * Count cannot be larger than the parent package length, but
393895f26a9SJung-uk Kim              * allow it to be smaller. The >= accounts for the Integer above.
3949c48c75eSJung-uk Kim              */
3959c48c75eSJung-uk Kim             ExpectedCount = (UINT32) Op->Asl.Value.Integer;
3969c48c75eSJung-uk Kim             if (ExpectedCount >= Count)
3979c48c75eSJung-uk Kim             {
3989c48c75eSJung-uk Kim                 goto PackageTooSmall;
3999c48c75eSJung-uk Kim             }
4009c48c75eSJung-uk Kim 
4019c48c75eSJung-uk Kim             Count = ExpectedCount;
4029c48c75eSJung-uk Kim         }
4039c48c75eSJung-uk Kim 
4049c48c75eSJung-uk Kim         Op = Op->Asl.Next;
4059c48c75eSJung-uk Kim 
406313a0c13SJung-uk Kim         /* Examine the subpackages */
4079c48c75eSJung-uk Kim 
4089c48c75eSJung-uk Kim         ApCheckPackageList (Predefined->Info.Name, Op,
4099c48c75eSJung-uk Kim             Package, 1, Count);
4109c48c75eSJung-uk Kim         break;
4119c48c75eSJung-uk Kim 
412313a0c13SJung-uk Kim     case ACPI_PTYPE2_UUID_PAIR:
413313a0c13SJung-uk Kim 
414313a0c13SJung-uk Kim         /* The package contains a variable list of UUID Buffer/Package pairs */
415313a0c13SJung-uk Kim 
416313a0c13SJung-uk Kim         /* The length of the package must be even */
417313a0c13SJung-uk Kim 
418313a0c13SJung-uk Kim         if (Count & 1)
419313a0c13SJung-uk Kim         {
420*6f1f1a63SJung-uk Kim             sprintf (AslGbl_MsgBuffer, "%4.4s: Package length, %d, must be even.",
421313a0c13SJung-uk Kim                 Predefined->Info.Name, Count);
422313a0c13SJung-uk Kim 
423313a0c13SJung-uk Kim             AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
424*6f1f1a63SJung-uk Kim                 ParentOp->Asl.Child, AslGbl_MsgBuffer);
425313a0c13SJung-uk Kim         }
426313a0c13SJung-uk Kim 
427313a0c13SJung-uk Kim         /* Validate the alternating types */
428313a0c13SJung-uk Kim 
429313a0c13SJung-uk Kim         for (i = 0; i < Count; ++i)
430313a0c13SJung-uk Kim         {
431313a0c13SJung-uk Kim             if (i & 1)
432313a0c13SJung-uk Kim             {
433313a0c13SJung-uk Kim                 ApCheckObjectType (Predefined->Info.Name, Op,
434313a0c13SJung-uk Kim                     Package->RetInfo.ObjectType2, i);
435313a0c13SJung-uk Kim             }
436313a0c13SJung-uk Kim             else
437313a0c13SJung-uk Kim             {
438313a0c13SJung-uk Kim                 ApCheckObjectType (Predefined->Info.Name, Op,
439313a0c13SJung-uk Kim                     Package->RetInfo.ObjectType1, i);
440313a0c13SJung-uk Kim             }
441313a0c13SJung-uk Kim 
442313a0c13SJung-uk Kim             Op = Op->Asl.Next;
443313a0c13SJung-uk Kim         }
444313a0c13SJung-uk Kim 
445313a0c13SJung-uk Kim         break;
446313a0c13SJung-uk Kim 
447a371a5fdSJung-uk Kim     case ACPI_PTYPE2_VAR_VAR:
448a371a5fdSJung-uk Kim 
449a371a5fdSJung-uk Kim         /* Check for minimum size (ints at beginning + 1 subpackage) */
450a371a5fdSJung-uk Kim 
451a371a5fdSJung-uk Kim         ExpectedCount = Package->RetInfo4.Count1 + 1;
452a371a5fdSJung-uk Kim         if (Count < ExpectedCount)
453a371a5fdSJung-uk Kim         {
454a371a5fdSJung-uk Kim             goto PackageTooSmall;
455a371a5fdSJung-uk Kim         }
456a371a5fdSJung-uk Kim 
457a371a5fdSJung-uk Kim         /* Check the non-package elements at beginning of main package */
458a371a5fdSJung-uk Kim 
459a371a5fdSJung-uk Kim         for (i = 0; i < Package->RetInfo4.Count1; ++i)
460a371a5fdSJung-uk Kim         {
461a371a5fdSJung-uk Kim             Status = ApCheckObjectType (Predefined->Info.Name, Op,
462a371a5fdSJung-uk Kim                 Package->RetInfo4.ObjectType1, i);
463a371a5fdSJung-uk Kim             Op = Op->Asl.Next;
464a371a5fdSJung-uk Kim         }
465a371a5fdSJung-uk Kim 
466a371a5fdSJung-uk Kim         /* Examine the variable-length list of subpackages */
467a371a5fdSJung-uk Kim 
468a371a5fdSJung-uk Kim         ApCheckPackageList (Predefined->Info.Name, Op,
469a371a5fdSJung-uk Kim             Package, Package->RetInfo4.Count1, Count);
470a371a5fdSJung-uk Kim 
471a371a5fdSJung-uk Kim         break;
472a371a5fdSJung-uk Kim 
4739c48c75eSJung-uk Kim     case ACPI_PTYPE2:
4749c48c75eSJung-uk Kim     case ACPI_PTYPE2_FIXED:
4759c48c75eSJung-uk Kim     case ACPI_PTYPE2_MIN:
4769c48c75eSJung-uk Kim     case ACPI_PTYPE2_COUNT:
4779c48c75eSJung-uk Kim     case ACPI_PTYPE2_FIX_VAR:
4789c48c75eSJung-uk Kim         /*
4799c48c75eSJung-uk Kim          * These types all return a single Package that consists of a
480313a0c13SJung-uk Kim          * variable number of subpackages.
4819c48c75eSJung-uk Kim          */
4829c48c75eSJung-uk Kim 
483313a0c13SJung-uk Kim         /* Examine the subpackages */
4849c48c75eSJung-uk Kim 
4859c48c75eSJung-uk Kim         ApCheckPackageList (Predefined->Info.Name, Op,
4869c48c75eSJung-uk Kim             Package, 0, Count);
4879c48c75eSJung-uk Kim         break;
4889c48c75eSJung-uk Kim 
4899c48c75eSJung-uk Kim     default:
4909c48c75eSJung-uk Kim         return;
4919c48c75eSJung-uk Kim     }
4929c48c75eSJung-uk Kim 
4939c48c75eSJung-uk Kim     return;
4949c48c75eSJung-uk Kim 
4959c48c75eSJung-uk Kim PackageTooSmall:
4969c48c75eSJung-uk Kim     ApPackageTooSmall (Predefined->Info.Name, ParentOp,
4979c48c75eSJung-uk Kim         Count, ExpectedCount);
4989c48c75eSJung-uk Kim }
4999c48c75eSJung-uk Kim 
5009c48c75eSJung-uk Kim 
5019c48c75eSJung-uk Kim /*******************************************************************************
5029c48c75eSJung-uk Kim  *
503f8146b88SJung-uk Kim  * FUNCTION:    ApCustomPackage
504f8146b88SJung-uk Kim  *
505f8146b88SJung-uk Kim  * PARAMETERS:  ParentOp            - Parse op for the package
506f8146b88SJung-uk Kim  *              Predefined          - Pointer to package-specific info for
507f8146b88SJung-uk Kim  *                                    the method
508f8146b88SJung-uk Kim  *
509f8146b88SJung-uk Kim  * RETURN:      None
510f8146b88SJung-uk Kim  *
511f8146b88SJung-uk Kim  * DESCRIPTION: Validate packages that don't fit into the standard model and
512f8146b88SJung-uk Kim  *              require custom code.
513f8146b88SJung-uk Kim  *
514f8146b88SJung-uk Kim  * NOTE: Currently used for the _BIX method only. When needed for two or more
515f8146b88SJung-uk Kim  * methods, probably a detect/dispatch mechanism will be required.
516f8146b88SJung-uk Kim  *
517f8146b88SJung-uk Kim  ******************************************************************************/
518f8146b88SJung-uk Kim 
519f8146b88SJung-uk Kim static void
520f8146b88SJung-uk Kim ApCustomPackage (
521f8146b88SJung-uk Kim     ACPI_PARSE_OBJECT           *ParentOp,
522f8146b88SJung-uk Kim     const ACPI_PREDEFINED_INFO  *Predefined)
523f8146b88SJung-uk Kim {
524f8146b88SJung-uk Kim     ACPI_PARSE_OBJECT           *Op;
525f8146b88SJung-uk Kim     UINT32                      Count;
526f8146b88SJung-uk Kim     UINT32                      ExpectedCount;
527f8146b88SJung-uk Kim     UINT32                      Version;
528f8146b88SJung-uk Kim 
529f8146b88SJung-uk Kim 
530f8146b88SJung-uk Kim     /* First child is the package length */
531f8146b88SJung-uk Kim 
532f8146b88SJung-uk Kim     Op = ParentOp->Asl.Child;
533f8146b88SJung-uk Kim     Count = (UINT32) Op->Asl.Value.Integer;
534f8146b88SJung-uk Kim 
535f8146b88SJung-uk Kim     /* Get the version number, must be Integer */
536f8146b88SJung-uk Kim 
537f8146b88SJung-uk Kim     Op = Op->Asl.Next;
538f8146b88SJung-uk Kim     Version = (UINT32) Op->Asl.Value.Integer;
539f8146b88SJung-uk Kim     if (Op->Asl.ParseOpcode != PARSEOP_INTEGER)
540f8146b88SJung-uk Kim     {
541*6f1f1a63SJung-uk Kim         AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, AslGbl_MsgBuffer);
542f8146b88SJung-uk Kim         return;
543f8146b88SJung-uk Kim     }
544f8146b88SJung-uk Kim 
545f8146b88SJung-uk Kim     /* Validate count (# of elements) */
546f8146b88SJung-uk Kim 
547f8146b88SJung-uk Kim     ExpectedCount = 21;         /* Version 1 */
548f8146b88SJung-uk Kim     if (Version == 0)
549f8146b88SJung-uk Kim     {
550f8146b88SJung-uk Kim         ExpectedCount = 20;     /* Version 0 */
551f8146b88SJung-uk Kim     }
552f8146b88SJung-uk Kim 
553f8146b88SJung-uk Kim     if (Count < ExpectedCount)
554f8146b88SJung-uk Kim     {
555f8146b88SJung-uk Kim         ApPackageTooSmall (Predefined->Info.Name, ParentOp,
556f8146b88SJung-uk Kim             Count, ExpectedCount);
557f8146b88SJung-uk Kim         return;
558f8146b88SJung-uk Kim     }
559f8146b88SJung-uk Kim     else if (Count > ExpectedCount)
560f8146b88SJung-uk Kim     {
561f8146b88SJung-uk Kim         ApPackageTooLarge (Predefined->Info.Name, ParentOp,
562f8146b88SJung-uk Kim             Count, ExpectedCount);
563f8146b88SJung-uk Kim     }
564f8146b88SJung-uk Kim 
565f8146b88SJung-uk Kim     /* Validate all elements of the package */
566f8146b88SJung-uk Kim 
567f8146b88SJung-uk Kim     Op = ApCheckPackageElements (Predefined->Info.Name, Op,
568f8146b88SJung-uk Kim         ACPI_RTYPE_INTEGER, 16,
569f8146b88SJung-uk Kim         ACPI_RTYPE_STRING, 4);
570f8146b88SJung-uk Kim 
571f8146b88SJung-uk Kim     /* Version 1 has a single trailing integer */
572f8146b88SJung-uk Kim 
573f8146b88SJung-uk Kim     if (Version > 0)
574f8146b88SJung-uk Kim     {
575f8146b88SJung-uk Kim         ApCheckPackageElements (Predefined->Info.Name, Op,
576f8146b88SJung-uk Kim             ACPI_RTYPE_INTEGER, 1, 0, 0);
577f8146b88SJung-uk Kim     }
578f8146b88SJung-uk Kim }
579f8146b88SJung-uk Kim 
580f8146b88SJung-uk Kim 
581f8146b88SJung-uk Kim /*******************************************************************************
582f8146b88SJung-uk Kim  *
5839c48c75eSJung-uk Kim  * FUNCTION:    ApCheckPackageElements
5849c48c75eSJung-uk Kim  *
585895f26a9SJung-uk Kim  * PARAMETERS:  PredefinedName      - Name of the predefined object
5869c48c75eSJung-uk Kim  *              Op                  - Parser op for the package
5879c48c75eSJung-uk Kim  *              Type1               - Object type for first group
5889c48c75eSJung-uk Kim  *              Count1              - Count for first group
5899c48c75eSJung-uk Kim  *              Type2               - Object type for second group
5909c48c75eSJung-uk Kim  *              Count2              - Count for second group
5919c48c75eSJung-uk Kim  *
592f8146b88SJung-uk Kim  * RETURN:      Next Op peer in the parse tree, after all specified elements
593f8146b88SJung-uk Kim  *              have been validated. Used for multiple validations (calls
594f8146b88SJung-uk Kim  *              to this function).
5959c48c75eSJung-uk Kim  *
5969c48c75eSJung-uk Kim  * DESCRIPTION: Validate all elements of a package. Works with packages that
5979c48c75eSJung-uk Kim  *              are defined to contain up to two groups of different object
5989c48c75eSJung-uk Kim  *              types.
5999c48c75eSJung-uk Kim  *
6009c48c75eSJung-uk Kim  ******************************************************************************/
6019c48c75eSJung-uk Kim 
602f8146b88SJung-uk Kim static ACPI_PARSE_OBJECT *
6039c48c75eSJung-uk Kim ApCheckPackageElements (
6049c48c75eSJung-uk Kim     const char              *PredefinedName,
6059c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
6069c48c75eSJung-uk Kim     UINT8                   Type1,
6079c48c75eSJung-uk Kim     UINT32                  Count1,
6089c48c75eSJung-uk Kim     UINT8                   Type2,
6099c48c75eSJung-uk Kim     UINT32                  Count2)
6109c48c75eSJung-uk Kim {
6119c48c75eSJung-uk Kim     UINT32                  i;
6129c48c75eSJung-uk Kim 
6139c48c75eSJung-uk Kim 
6149c48c75eSJung-uk Kim     /*
6159c48c75eSJung-uk Kim      * Up to two groups of package elements are supported by the data
6169c48c75eSJung-uk Kim      * structure. All elements in each group must be of the same type.
6179c48c75eSJung-uk Kim      * The second group can have a count of zero.
6189c48c75eSJung-uk Kim      *
6199c48c75eSJung-uk Kim      * Aborts check upon a NULL package element, as this means (at compile
6209c48c75eSJung-uk Kim      * time) that the remainder of the package elements are also NULL
6219c48c75eSJung-uk Kim      * (This is the only way to create NULL package elements.)
6229c48c75eSJung-uk Kim      */
6239c48c75eSJung-uk Kim     for (i = 0; (i < Count1) && Op; i++)
6249c48c75eSJung-uk Kim     {
6259c48c75eSJung-uk Kim         ApCheckObjectType (PredefinedName, Op, Type1, i);
6269c48c75eSJung-uk Kim         Op = Op->Asl.Next;
6279c48c75eSJung-uk Kim     }
6289c48c75eSJung-uk Kim 
6299c48c75eSJung-uk Kim     for (i = 0; (i < Count2) && Op; i++)
6309c48c75eSJung-uk Kim     {
6319c48c75eSJung-uk Kim         ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
6329c48c75eSJung-uk Kim         Op = Op->Asl.Next;
6339c48c75eSJung-uk Kim     }
634f8146b88SJung-uk Kim 
635f8146b88SJung-uk Kim     return (Op);
6369c48c75eSJung-uk Kim }
6379c48c75eSJung-uk Kim 
6389c48c75eSJung-uk Kim 
6399c48c75eSJung-uk Kim /*******************************************************************************
6409c48c75eSJung-uk Kim  *
6419c48c75eSJung-uk Kim  * FUNCTION:    ApCheckPackageList
6429c48c75eSJung-uk Kim  *
6439c48c75eSJung-uk Kim  * PARAMETERS:  PredefinedName      - Name of the predefined object
6449c48c75eSJung-uk Kim  *              ParentOp            - Parser op of the parent package
6459c48c75eSJung-uk Kim  *              Package             - Package info for this predefined name
6469c48c75eSJung-uk Kim  *              StartIndex          - Index in parent package where list begins
6479c48c75eSJung-uk Kim  *              ParentCount         - Element count of parent package
6489c48c75eSJung-uk Kim  *
6499c48c75eSJung-uk Kim  * RETURN:      None
6509c48c75eSJung-uk Kim  *
6519c48c75eSJung-uk Kim  * DESCRIPTION: Validate the individual package elements for a predefined name.
6529c48c75eSJung-uk Kim  *              Handles the cases where the predefined name is defined as a
6539c48c75eSJung-uk Kim  *              Package of Packages (subpackages). These are the types:
6549c48c75eSJung-uk Kim  *
6559c48c75eSJung-uk Kim  *              ACPI_PTYPE2
6569c48c75eSJung-uk Kim  *              ACPI_PTYPE2_FIXED
6579c48c75eSJung-uk Kim  *              ACPI_PTYPE2_MIN
6589c48c75eSJung-uk Kim  *              ACPI_PTYPE2_COUNT
6599c48c75eSJung-uk Kim  *              ACPI_PTYPE2_FIX_VAR
660a371a5fdSJung-uk Kim  *              ACPI_PTYPE2_VAR_VAR
6619c48c75eSJung-uk Kim  *
6629c48c75eSJung-uk Kim  ******************************************************************************/
6639c48c75eSJung-uk Kim 
6649c48c75eSJung-uk Kim static void
6659c48c75eSJung-uk Kim ApCheckPackageList (
6669c48c75eSJung-uk Kim     const char                  *PredefinedName,
6679c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *ParentOp,
6689c48c75eSJung-uk Kim     const ACPI_PREDEFINED_INFO  *Package,
6699c48c75eSJung-uk Kim     UINT32                      StartIndex,
6709c48c75eSJung-uk Kim     UINT32                      ParentCount)
6719c48c75eSJung-uk Kim {
6729c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *SubPackageOp = ParentOp;
6739c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op;
6749c48c75eSJung-uk Kim     ACPI_STATUS                 Status;
6759c48c75eSJung-uk Kim     UINT32                      Count;
6769c48c75eSJung-uk Kim     UINT32                      ExpectedCount;
6779c48c75eSJung-uk Kim     UINT32                      i;
6789c48c75eSJung-uk Kim     UINT32                      j;
6799c48c75eSJung-uk Kim 
6809c48c75eSJung-uk Kim 
6819c48c75eSJung-uk Kim     /*
6829c48c75eSJung-uk Kim      * Validate each subpackage in the parent Package
6839c48c75eSJung-uk Kim      *
6849c48c75eSJung-uk Kim      * Note: We ignore NULL package elements on the assumption that
6859c48c75eSJung-uk Kim      * they will be initialized by the BIOS or other ASL code.
6869c48c75eSJung-uk Kim      */
6879c48c75eSJung-uk Kim     for (i = 0; (i < ParentCount) && SubPackageOp; i++)
6889c48c75eSJung-uk Kim     {
6899c48c75eSJung-uk Kim         /* Each object in the list must be of type Package */
6909c48c75eSJung-uk Kim 
6919c48c75eSJung-uk Kim         Status = ApCheckObjectType (PredefinedName, SubPackageOp,
6929c48c75eSJung-uk Kim             ACPI_RTYPE_PACKAGE, i + StartIndex);
6939c48c75eSJung-uk Kim         if (ACPI_FAILURE (Status))
6949c48c75eSJung-uk Kim         {
6959c48c75eSJung-uk Kim             goto NextSubpackage;
6969c48c75eSJung-uk Kim         }
6979c48c75eSJung-uk Kim 
6989c48c75eSJung-uk Kim         /* Examine the different types of expected subpackages */
6999c48c75eSJung-uk Kim 
7009c48c75eSJung-uk Kim         Op = SubPackageOp->Asl.Child;
7019c48c75eSJung-uk Kim 
7029c48c75eSJung-uk Kim         /* First child is the package length */
7039c48c75eSJung-uk Kim 
7049c48c75eSJung-uk Kim         Count = (UINT32) Op->Asl.Value.Integer;
7059c48c75eSJung-uk Kim         Op = Op->Asl.Next;
7069c48c75eSJung-uk Kim 
707a371a5fdSJung-uk Kim         /*
708a371a5fdSJung-uk Kim          * Most subpackage must have at least one element, with
709a371a5fdSJung-uk Kim          * only rare exceptions. (_RDI)
710a371a5fdSJung-uk Kim          */
711a371a5fdSJung-uk Kim         if (!Count &&
712a371a5fdSJung-uk Kim             (Package->RetInfo.Type != ACPI_PTYPE2_VAR_VAR))
7139c48c75eSJung-uk Kim         {
7149c48c75eSJung-uk Kim             ApZeroLengthPackage (PredefinedName, SubPackageOp);
7159c48c75eSJung-uk Kim             goto NextSubpackage;
7169c48c75eSJung-uk Kim         }
7179c48c75eSJung-uk Kim 
7189c48c75eSJung-uk Kim         /*
7199c48c75eSJung-uk Kim          * Decode the package type.
7209c48c75eSJung-uk Kim          * PTYPE2 indicates that a "package of packages" is expected for
7219c48c75eSJung-uk Kim          * this name. The various flavors of PTYPE2 indicate the number
7229c48c75eSJung-uk Kim          * and format of the subpackages.
7239c48c75eSJung-uk Kim          */
7249c48c75eSJung-uk Kim         switch (Package->RetInfo.Type)
7259c48c75eSJung-uk Kim         {
7269c48c75eSJung-uk Kim         case ACPI_PTYPE2:
7279c48c75eSJung-uk Kim         case ACPI_PTYPE2_PKG_COUNT:
7289c48c75eSJung-uk Kim         case ACPI_PTYPE2_REV_FIXED:
7299c48c75eSJung-uk Kim 
7309c48c75eSJung-uk Kim             /* Each subpackage has a fixed number of elements */
7319c48c75eSJung-uk Kim 
7329c48c75eSJung-uk Kim             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
7339c48c75eSJung-uk Kim             if (Count < ExpectedCount)
7349c48c75eSJung-uk Kim             {
7359c48c75eSJung-uk Kim                 ApPackageTooSmall (PredefinedName, SubPackageOp,
7369c48c75eSJung-uk Kim                     Count, ExpectedCount);
7379c48c75eSJung-uk Kim                 break;
7389c48c75eSJung-uk Kim             }
739313a0c13SJung-uk Kim             if (Count > ExpectedCount)
740313a0c13SJung-uk Kim             {
741313a0c13SJung-uk Kim                 ApPackageTooLarge (PredefinedName, SubPackageOp,
742313a0c13SJung-uk Kim                     Count, ExpectedCount);
743313a0c13SJung-uk Kim                 break;
744313a0c13SJung-uk Kim             }
7459c48c75eSJung-uk Kim 
7469c48c75eSJung-uk Kim             ApCheckPackageElements (PredefinedName, Op,
7479c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
7489c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
7499c48c75eSJung-uk Kim             break;
7509c48c75eSJung-uk Kim 
7519c48c75eSJung-uk Kim         case ACPI_PTYPE2_FIX_VAR:
7529c48c75eSJung-uk Kim             /*
7539c48c75eSJung-uk Kim              * Each subpackage has a fixed number of elements and an
7549c48c75eSJung-uk Kim              * optional element
7559c48c75eSJung-uk Kim              */
7569c48c75eSJung-uk Kim             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
7579c48c75eSJung-uk Kim             if (Count < ExpectedCount)
7589c48c75eSJung-uk Kim             {
7599c48c75eSJung-uk Kim                 ApPackageTooSmall (PredefinedName, SubPackageOp,
7609c48c75eSJung-uk Kim                     Count, ExpectedCount);
7619c48c75eSJung-uk Kim                 break;
7629c48c75eSJung-uk Kim             }
7639c48c75eSJung-uk Kim 
7649c48c75eSJung-uk Kim             ApCheckPackageElements (PredefinedName, Op,
7659c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
7669c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType2,
7679c48c75eSJung-uk Kim                 Count - Package->RetInfo.Count1);
7689c48c75eSJung-uk Kim             break;
7699c48c75eSJung-uk Kim 
770a371a5fdSJung-uk Kim         case ACPI_PTYPE2_VAR_VAR:
771a371a5fdSJung-uk Kim             /*
772a371a5fdSJung-uk Kim              * Must have at least the minimum number elements.
773a371a5fdSJung-uk Kim              * A zero PkgCount means the number of elements is variable.
774a371a5fdSJung-uk Kim              */
775a371a5fdSJung-uk Kim             ExpectedCount = Package->RetInfo4.PkgCount;
776a371a5fdSJung-uk Kim             if (ExpectedCount && (Count < ExpectedCount))
777a371a5fdSJung-uk Kim             {
778a371a5fdSJung-uk Kim                 ApPackageTooSmall (PredefinedName, SubPackageOp,
779a371a5fdSJung-uk Kim                     Count, 1);
780a371a5fdSJung-uk Kim                 break;
781a371a5fdSJung-uk Kim             }
782a371a5fdSJung-uk Kim 
783a371a5fdSJung-uk Kim             ApCheckPackageElements (PredefinedName, Op,
784a371a5fdSJung-uk Kim                 Package->RetInfo4.SubObjectTypes,
785a371a5fdSJung-uk Kim                 Package->RetInfo4.PkgCount,
786a371a5fdSJung-uk Kim                 0, 0);
787a371a5fdSJung-uk Kim             break;
788a371a5fdSJung-uk Kim 
7899c48c75eSJung-uk Kim         case ACPI_PTYPE2_FIXED:
7909c48c75eSJung-uk Kim 
791313a0c13SJung-uk Kim             /* Each subpackage has a fixed length */
7929c48c75eSJung-uk Kim 
7939c48c75eSJung-uk Kim             ExpectedCount = Package->RetInfo2.Count;
7949c48c75eSJung-uk Kim             if (Count < ExpectedCount)
7959c48c75eSJung-uk Kim             {
7969c48c75eSJung-uk Kim                 ApPackageTooSmall (PredefinedName, SubPackageOp,
7979c48c75eSJung-uk Kim                     Count, ExpectedCount);
7989c48c75eSJung-uk Kim                 break;
7999c48c75eSJung-uk Kim             }
800313a0c13SJung-uk Kim             if (Count > ExpectedCount)
801313a0c13SJung-uk Kim             {
802313a0c13SJung-uk Kim                 ApPackageTooLarge (PredefinedName, SubPackageOp,
803313a0c13SJung-uk Kim                     Count, ExpectedCount);
804313a0c13SJung-uk Kim                 break;
805313a0c13SJung-uk Kim             }
8069c48c75eSJung-uk Kim 
8079c48c75eSJung-uk Kim             /* Check each object/type combination */
8089c48c75eSJung-uk Kim 
8099c48c75eSJung-uk Kim             for (j = 0; j < ExpectedCount; j++)
8109c48c75eSJung-uk Kim             {
8119c48c75eSJung-uk Kim                 ApCheckObjectType (PredefinedName, Op,
8129c48c75eSJung-uk Kim                     Package->RetInfo2.ObjectType[j], j);
8139c48c75eSJung-uk Kim 
8149c48c75eSJung-uk Kim                 Op = Op->Asl.Next;
8159c48c75eSJung-uk Kim             }
8169c48c75eSJung-uk Kim             break;
8179c48c75eSJung-uk Kim 
8189c48c75eSJung-uk Kim         case ACPI_PTYPE2_MIN:
8199c48c75eSJung-uk Kim 
820313a0c13SJung-uk Kim             /* Each subpackage has a variable but minimum length */
8219c48c75eSJung-uk Kim 
8229c48c75eSJung-uk Kim             ExpectedCount = Package->RetInfo.Count1;
8239c48c75eSJung-uk Kim             if (Count < ExpectedCount)
8249c48c75eSJung-uk Kim             {
8259c48c75eSJung-uk Kim                 ApPackageTooSmall (PredefinedName, SubPackageOp,
8269c48c75eSJung-uk Kim                     Count, ExpectedCount);
8279c48c75eSJung-uk Kim                 break;
8289c48c75eSJung-uk Kim             }
8299c48c75eSJung-uk Kim 
830313a0c13SJung-uk Kim             /* Check the type of each subpackage element */
8319c48c75eSJung-uk Kim 
8329c48c75eSJung-uk Kim             ApCheckPackageElements (PredefinedName, Op,
8339c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType1, Count, 0, 0);
8349c48c75eSJung-uk Kim             break;
8359c48c75eSJung-uk Kim 
8369c48c75eSJung-uk Kim         case ACPI_PTYPE2_COUNT:
8379c48c75eSJung-uk Kim             /*
8389c48c75eSJung-uk Kim              * First element is the (Integer) count of elements, including
8399c48c75eSJung-uk Kim              * the count field (the ACPI name is NumElements)
8409c48c75eSJung-uk Kim              */
8419c48c75eSJung-uk Kim             Status = ApCheckObjectType (PredefinedName, Op,
8429c48c75eSJung-uk Kim                 ACPI_RTYPE_INTEGER, 0);
8439c48c75eSJung-uk Kim 
8449c48c75eSJung-uk Kim             /* We must have an integer count from above (otherwise, use Count) */
8459c48c75eSJung-uk Kim 
8469c48c75eSJung-uk Kim             if (ACPI_SUCCESS (Status))
8479c48c75eSJung-uk Kim             {
8489c48c75eSJung-uk Kim                 /*
8499c48c75eSJung-uk Kim                  * Make sure package is large enough for the Count and is
8509c48c75eSJung-uk Kim                  * is as large as the minimum size
8519c48c75eSJung-uk Kim                  */
8529c48c75eSJung-uk Kim                 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
8539c48c75eSJung-uk Kim 
8549c48c75eSJung-uk Kim                 if (Count < ExpectedCount)
8559c48c75eSJung-uk Kim                 {
8569c48c75eSJung-uk Kim                     ApPackageTooSmall (PredefinedName, SubPackageOp,
8579c48c75eSJung-uk Kim                         Count, ExpectedCount);
8589c48c75eSJung-uk Kim                     break;
8599c48c75eSJung-uk Kim                 }
8609c48c75eSJung-uk Kim                 else if (Count > ExpectedCount)
8619c48c75eSJung-uk Kim                 {
8629c48c75eSJung-uk Kim                     ApPackageTooLarge (PredefinedName, SubPackageOp,
8639c48c75eSJung-uk Kim                         Count, ExpectedCount);
8649c48c75eSJung-uk Kim                 }
8659c48c75eSJung-uk Kim 
8669c48c75eSJung-uk Kim                 /* Some names of this type have a minimum length */
8679c48c75eSJung-uk Kim 
8689c48c75eSJung-uk Kim                 if (Count < Package->RetInfo.Count1)
8699c48c75eSJung-uk Kim                 {
8709c48c75eSJung-uk Kim                     ExpectedCount = Package->RetInfo.Count1;
8719c48c75eSJung-uk Kim                     ApPackageTooSmall (PredefinedName, SubPackageOp,
8729c48c75eSJung-uk Kim                         Count, ExpectedCount);
8739c48c75eSJung-uk Kim                     break;
8749c48c75eSJung-uk Kim                 }
8759c48c75eSJung-uk Kim 
8769c48c75eSJung-uk Kim                 Count = ExpectedCount;
8779c48c75eSJung-uk Kim             }
8789c48c75eSJung-uk Kim 
879313a0c13SJung-uk Kim             /* Check the type of each subpackage element */
8809c48c75eSJung-uk Kim 
8819c48c75eSJung-uk Kim             Op = Op->Asl.Next;
8829c48c75eSJung-uk Kim             ApCheckPackageElements (PredefinedName, Op,
8839c48c75eSJung-uk Kim                 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
8849c48c75eSJung-uk Kim             break;
8859c48c75eSJung-uk Kim 
8869c48c75eSJung-uk Kim         default:
8879c48c75eSJung-uk Kim             break;
8889c48c75eSJung-uk Kim         }
8899c48c75eSJung-uk Kim 
8909c48c75eSJung-uk Kim NextSubpackage:
8919c48c75eSJung-uk Kim         SubPackageOp = SubPackageOp->Asl.Next;
8929c48c75eSJung-uk Kim     }
8939c48c75eSJung-uk Kim }
8949c48c75eSJung-uk Kim 
8959c48c75eSJung-uk Kim 
8969c48c75eSJung-uk Kim /*******************************************************************************
8979c48c75eSJung-uk Kim  *
8989c48c75eSJung-uk Kim  * FUNCTION:    ApPackageTooSmall
8999c48c75eSJung-uk Kim  *
9009c48c75eSJung-uk Kim  * PARAMETERS:  PredefinedName      - Name of the predefined object
9019c48c75eSJung-uk Kim  *              Op                  - Current parser op
9029c48c75eSJung-uk Kim  *              Count               - Actual package element count
9039c48c75eSJung-uk Kim  *              ExpectedCount       - Expected package element count
9049c48c75eSJung-uk Kim  *
9059c48c75eSJung-uk Kim  * RETURN:      None
9069c48c75eSJung-uk Kim  *
9079c48c75eSJung-uk Kim  * DESCRIPTION: Issue error message for a package that is smaller than
9089c48c75eSJung-uk Kim  *              required.
9099c48c75eSJung-uk Kim  *
9109c48c75eSJung-uk Kim  ******************************************************************************/
9119c48c75eSJung-uk Kim 
9129c48c75eSJung-uk Kim static void
9139c48c75eSJung-uk Kim ApPackageTooSmall (
9149c48c75eSJung-uk Kim     const char                  *PredefinedName,
9159c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op,
9169c48c75eSJung-uk Kim     UINT32                      Count,
9179c48c75eSJung-uk Kim     UINT32                      ExpectedCount)
9189c48c75eSJung-uk Kim {
9199c48c75eSJung-uk Kim 
920*6f1f1a63SJung-uk Kim     sprintf (AslGbl_MsgBuffer, "%s: length %u, required minimum is %u",
9219c48c75eSJung-uk Kim         PredefinedName, Count, ExpectedCount);
9229c48c75eSJung-uk Kim 
923*6f1f1a63SJung-uk Kim     AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, AslGbl_MsgBuffer);
9249c48c75eSJung-uk Kim }
9259c48c75eSJung-uk Kim 
9269c48c75eSJung-uk Kim 
9279c48c75eSJung-uk Kim /*******************************************************************************
9289c48c75eSJung-uk Kim  *
9299c48c75eSJung-uk Kim  * FUNCTION:    ApZeroLengthPackage
9309c48c75eSJung-uk Kim  *
9319c48c75eSJung-uk Kim  * PARAMETERS:  PredefinedName      - Name of the predefined object
9329c48c75eSJung-uk Kim  *              Op                  - Current parser op
9339c48c75eSJung-uk Kim  *
9349c48c75eSJung-uk Kim  * RETURN:      None
9359c48c75eSJung-uk Kim  *
9369c48c75eSJung-uk Kim  * DESCRIPTION: Issue error message for a zero-length package (a package that
9379c48c75eSJung-uk Kim  *              is required to have a non-zero length). Variable length
9389c48c75eSJung-uk Kim  *              packages seem to be allowed to have zero length, however.
9399c48c75eSJung-uk Kim  *              Even if not allowed, BIOS code does it.
9409c48c75eSJung-uk Kim  *
9419c48c75eSJung-uk Kim  ******************************************************************************/
9429c48c75eSJung-uk Kim 
9439c48c75eSJung-uk Kim static void
9449c48c75eSJung-uk Kim ApZeroLengthPackage (
9459c48c75eSJung-uk Kim     const char                  *PredefinedName,
9469c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op)
9479c48c75eSJung-uk Kim {
9489c48c75eSJung-uk Kim 
949*6f1f1a63SJung-uk Kim     sprintf (AslGbl_MsgBuffer, "%s: length is zero", PredefinedName);
9509c48c75eSJung-uk Kim 
951*6f1f1a63SJung-uk Kim     AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, AslGbl_MsgBuffer);
9529c48c75eSJung-uk Kim }
9539c48c75eSJung-uk Kim 
9549c48c75eSJung-uk Kim 
9559c48c75eSJung-uk Kim /*******************************************************************************
9569c48c75eSJung-uk Kim  *
9579c48c75eSJung-uk Kim  * FUNCTION:    ApPackageTooLarge
9589c48c75eSJung-uk Kim  *
9599c48c75eSJung-uk Kim  * PARAMETERS:  PredefinedName      - Name of the predefined object
9609c48c75eSJung-uk Kim  *              Op                  - Current parser op
9619c48c75eSJung-uk Kim  *              Count               - Actual package element count
9629c48c75eSJung-uk Kim  *              ExpectedCount       - Expected package element count
9639c48c75eSJung-uk Kim  *
9649c48c75eSJung-uk Kim  * RETURN:      None
9659c48c75eSJung-uk Kim  *
9669c48c75eSJung-uk Kim  * DESCRIPTION: Issue a remark for a package that is larger than expected.
9679c48c75eSJung-uk Kim  *
9689c48c75eSJung-uk Kim  ******************************************************************************/
9699c48c75eSJung-uk Kim 
9709c48c75eSJung-uk Kim static void
9719c48c75eSJung-uk Kim ApPackageTooLarge (
9729c48c75eSJung-uk Kim     const char                  *PredefinedName,
9739c48c75eSJung-uk Kim     ACPI_PARSE_OBJECT           *Op,
9749c48c75eSJung-uk Kim     UINT32                      Count,
9759c48c75eSJung-uk Kim     UINT32                      ExpectedCount)
9769c48c75eSJung-uk Kim {
9779c48c75eSJung-uk Kim 
978*6f1f1a63SJung-uk Kim     sprintf (AslGbl_MsgBuffer, "%s: length is %u, only %u required",
9799c48c75eSJung-uk Kim         PredefinedName, Count, ExpectedCount);
9809c48c75eSJung-uk Kim 
981*6f1f1a63SJung-uk Kim     AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, AslGbl_MsgBuffer);
9829c48c75eSJung-uk Kim }
983