Home | History | Annotate | Line # | Download | only in compiler
aslprepkg.c revision 1.1.1.14
      1       1.1  christos /******************************************************************************
      2       1.1  christos  *
      3       1.1  christos  * Module Name: aslprepkg - support for ACPI predefined name package objects
      4       1.1  christos  *
      5       1.1  christos  *****************************************************************************/
      6       1.1  christos 
      7       1.1  christos /*
      8  1.1.1.14  christos  * Copyright (C) 2000 - 2021, Intel Corp.
      9       1.1  christos  * All rights reserved.
     10       1.1  christos  *
     11       1.1  christos  * Redistribution and use in source and binary forms, with or without
     12       1.1  christos  * modification, are permitted provided that the following conditions
     13       1.1  christos  * are met:
     14       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15       1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16       1.1  christos  *    without modification.
     17       1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21       1.1  christos  *    binary redistribution.
     22       1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24       1.1  christos  *    from this software without specific prior written permission.
     25       1.1  christos  *
     26       1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27       1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.1  christos  * Software Foundation.
     29       1.1  christos  *
     30       1.1  christos  * NO WARRANTY
     31       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.14  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     34       1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42       1.1  christos  */
     43       1.1  christos 
     44       1.1  christos #include "aslcompiler.h"
     45       1.1  christos #include "aslcompiler.y.h"
     46       1.1  christos #include "acpredef.h"
     47       1.1  christos 
     48       1.1  christos 
     49       1.1  christos #define _COMPONENT          ACPI_COMPILER
     50       1.1  christos         ACPI_MODULE_NAME    ("aslprepkg")
     51       1.1  christos 
     52       1.1  christos 
     53       1.1  christos /* Local prototypes */
     54       1.1  christos 
     55   1.1.1.6  christos static ACPI_PARSE_OBJECT *
     56       1.1  christos ApCheckPackageElements (
     57       1.1  christos     const char                  *PredefinedName,
     58       1.1  christos     ACPI_PARSE_OBJECT           *Op,
     59       1.1  christos     UINT8                       Type1,
     60       1.1  christos     UINT32                      Count1,
     61       1.1  christos     UINT8                       Type2,
     62       1.1  christos     UINT32                      Count2);
     63       1.1  christos 
     64       1.1  christos static void
     65       1.1  christos ApCheckPackageList (
     66       1.1  christos     const char                  *PredefinedName,
     67       1.1  christos     ACPI_PARSE_OBJECT           *ParentOp,
     68       1.1  christos     const ACPI_PREDEFINED_INFO  *Package,
     69       1.1  christos     UINT32                      StartIndex,
     70       1.1  christos     UINT32                      Count);
     71       1.1  christos 
     72       1.1  christos static void
     73       1.1  christos ApPackageTooSmall (
     74       1.1  christos     const char                  *PredefinedName,
     75       1.1  christos     ACPI_PARSE_OBJECT           *Op,
     76       1.1  christos     UINT32                      Count,
     77       1.1  christos     UINT32                      ExpectedCount);
     78       1.1  christos 
     79       1.1  christos static void
     80       1.1  christos ApZeroLengthPackage (
     81       1.1  christos     const char                  *PredefinedName,
     82       1.1  christos     ACPI_PARSE_OBJECT           *Op);
     83       1.1  christos 
     84       1.1  christos static void
     85       1.1  christos ApPackageTooLarge (
     86       1.1  christos     const char                  *PredefinedName,
     87       1.1  christos     ACPI_PARSE_OBJECT           *Op,
     88       1.1  christos     UINT32                      Count,
     89       1.1  christos     UINT32                      ExpectedCount);
     90       1.1  christos 
     91   1.1.1.6  christos static void
     92   1.1.1.6  christos ApCustomPackage (
     93   1.1.1.6  christos     ACPI_PARSE_OBJECT           *ParentOp,
     94   1.1.1.6  christos     const ACPI_PREDEFINED_INFO  *Predefined);
     95   1.1.1.6  christos 
     96       1.1  christos 
     97       1.1  christos /*******************************************************************************
     98       1.1  christos  *
     99       1.1  christos  * FUNCTION:    ApCheckPackage
    100       1.1  christos  *
    101       1.1  christos  * PARAMETERS:  ParentOp            - Parser op for the package
    102       1.1  christos  *              Predefined          - Pointer to package-specific info for
    103       1.1  christos  *                                    the method
    104       1.1  christos  *
    105       1.1  christos  * RETURN:      None
    106       1.1  christos  *
    107       1.1  christos  * DESCRIPTION: Top-level validation for predefined name return package
    108       1.1  christos  *              objects.
    109       1.1  christos  *
    110       1.1  christos  ******************************************************************************/
    111       1.1  christos 
    112       1.1  christos void
    113       1.1  christos ApCheckPackage (
    114       1.1  christos     ACPI_PARSE_OBJECT           *ParentOp,
    115       1.1  christos     const ACPI_PREDEFINED_INFO  *Predefined)
    116       1.1  christos {
    117       1.1  christos     ACPI_PARSE_OBJECT           *Op;
    118       1.1  christos     const ACPI_PREDEFINED_INFO  *Package;
    119       1.1  christos     ACPI_STATUS                 Status;
    120       1.1  christos     UINT32                      ExpectedCount;
    121       1.1  christos     UINT32                      Count;
    122       1.1  christos     UINT32                      i;
    123       1.1  christos 
    124       1.1  christos 
    125       1.1  christos     /* The package info for this name is in the next table entry */
    126       1.1  christos 
    127       1.1  christos     Package = Predefined + 1;
    128       1.1  christos 
    129       1.1  christos     /* First child is the package length */
    130       1.1  christos 
    131       1.1  christos     Op = ParentOp->Asl.Child;
    132       1.1  christos     Count = (UINT32) Op->Asl.Value.Integer;
    133       1.1  christos 
    134       1.1  christos     /*
    135       1.1  christos      * Many of the variable-length top-level packages are allowed to simply
    136       1.1  christos      * have zero elements. This allows the BIOS to tell the host that even
    137       1.1  christos      * though the predefined name/method exists, the feature is not supported.
    138       1.1  christos      * Other package types require one or more elements. In any case, there
    139       1.1  christos      * is no need to continue validation.
    140       1.1  christos      */
    141       1.1  christos     if (!Count)
    142       1.1  christos     {
    143       1.1  christos         switch (Package->RetInfo.Type)
    144       1.1  christos         {
    145       1.1  christos         case ACPI_PTYPE1_FIXED:
    146       1.1  christos         case ACPI_PTYPE1_OPTION:
    147       1.1  christos         case ACPI_PTYPE2_PKG_COUNT:
    148       1.1  christos         case ACPI_PTYPE2_REV_FIXED:
    149       1.1  christos 
    150       1.1  christos             ApZeroLengthPackage (Predefined->Info.Name, ParentOp);
    151       1.1  christos             break;
    152       1.1  christos 
    153       1.1  christos         case ACPI_PTYPE1_VAR:
    154       1.1  christos         case ACPI_PTYPE2:
    155       1.1  christos         case ACPI_PTYPE2_COUNT:
    156       1.1  christos         case ACPI_PTYPE2_FIXED:
    157       1.1  christos         case ACPI_PTYPE2_MIN:
    158       1.1  christos         case ACPI_PTYPE2_FIX_VAR:
    159   1.1.1.4  christos         case ACPI_PTYPE2_VAR_VAR:
    160       1.1  christos         default:
    161       1.1  christos 
    162       1.1  christos             break;
    163       1.1  christos         }
    164       1.1  christos 
    165       1.1  christos         return;
    166       1.1  christos     }
    167       1.1  christos 
    168       1.1  christos     /* Get the first element of the package */
    169       1.1  christos 
    170       1.1  christos     Op = Op->Asl.Next;
    171       1.1  christos 
    172       1.1  christos     /* Decode the package type */
    173       1.1  christos 
    174       1.1  christos     switch (Package->RetInfo.Type)
    175       1.1  christos     {
    176   1.1.1.6  christos     case ACPI_PTYPE_CUSTOM:
    177   1.1.1.6  christos 
    178   1.1.1.6  christos         ApCustomPackage (ParentOp, Predefined);
    179   1.1.1.6  christos         break;
    180   1.1.1.6  christos 
    181       1.1  christos     case ACPI_PTYPE1_FIXED:
    182       1.1  christos         /*
    183   1.1.1.2  christos          * The package count is fixed and there are no subpackages
    184       1.1  christos          *
    185       1.1  christos          * If package is too small, exit.
    186       1.1  christos          * If package is larger than expected, issue warning but continue
    187       1.1  christos          */
    188       1.1  christos         ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    189       1.1  christos         if (Count < ExpectedCount)
    190       1.1  christos         {
    191       1.1  christos             goto PackageTooSmall;
    192       1.1  christos         }
    193       1.1  christos         else if (Count > ExpectedCount)
    194       1.1  christos         {
    195       1.1  christos             ApPackageTooLarge (Predefined->Info.Name, ParentOp,
    196       1.1  christos                 Count, ExpectedCount);
    197       1.1  christos         }
    198       1.1  christos 
    199       1.1  christos         /* Validate all elements of the package */
    200       1.1  christos 
    201       1.1  christos         ApCheckPackageElements (Predefined->Info.Name, Op,
    202       1.1  christos             Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
    203       1.1  christos             Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
    204       1.1  christos         break;
    205       1.1  christos 
    206       1.1  christos     case ACPI_PTYPE1_VAR:
    207       1.1  christos         /*
    208   1.1.1.2  christos          * The package count is variable, there are no subpackages,
    209       1.1  christos          * and all elements must be of the same type
    210       1.1  christos          */
    211       1.1  christos         for (i = 0; i < Count; i++)
    212       1.1  christos         {
    213  1.1.1.13  christos             if (!Op)
    214  1.1.1.13  christos             {
    215  1.1.1.13  christos                 /*
    216  1.1.1.13  christos                  * If we get to this point, it means that the package length
    217  1.1.1.13  christos                  * is larger than the initializer list. Stop processing the
    218  1.1.1.13  christos                  * package and return because we have run out of package
    219  1.1.1.13  christos                  * elements to analyze.
    220  1.1.1.13  christos                  */
    221  1.1.1.13  christos                 return;
    222  1.1.1.13  christos             }
    223  1.1.1.13  christos 
    224       1.1  christos             ApCheckObjectType (Predefined->Info.Name, Op,
    225       1.1  christos                 Package->RetInfo.ObjectType1, i);
    226       1.1  christos             Op = Op->Asl.Next;
    227       1.1  christos         }
    228       1.1  christos         break;
    229       1.1  christos 
    230       1.1  christos     case ACPI_PTYPE1_OPTION:
    231       1.1  christos         /*
    232   1.1.1.2  christos          * The package count is variable, there are no subpackages.
    233       1.1  christos          * There are a fixed number of required elements, and a variable
    234       1.1  christos          * number of optional elements.
    235       1.1  christos          *
    236       1.1  christos          * Check if package is at least as large as the minimum required
    237       1.1  christos          */
    238       1.1  christos         ExpectedCount = Package->RetInfo3.Count;
    239       1.1  christos         if (Count < ExpectedCount)
    240       1.1  christos         {
    241       1.1  christos             goto PackageTooSmall;
    242       1.1  christos         }
    243       1.1  christos 
    244       1.1  christos         /* Variable number of sub-objects */
    245       1.1  christos 
    246       1.1  christos         for (i = 0; i < Count; i++)
    247       1.1  christos         {
    248       1.1  christos             if (i < Package->RetInfo3.Count)
    249       1.1  christos             {
    250       1.1  christos                 /* These are the required package elements (0, 1, or 2) */
    251       1.1  christos 
    252       1.1  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    253       1.1  christos                     Package->RetInfo3.ObjectType[i], i);
    254       1.1  christos             }
    255       1.1  christos             else
    256       1.1  christos             {
    257       1.1  christos                 /* These are the optional package elements */
    258       1.1  christos 
    259       1.1  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    260       1.1  christos                     Package->RetInfo3.TailObjectType, i);
    261       1.1  christos             }
    262   1.1.1.5  christos 
    263       1.1  christos             Op = Op->Asl.Next;
    264       1.1  christos         }
    265       1.1  christos         break;
    266       1.1  christos 
    267       1.1  christos     case ACPI_PTYPE2_REV_FIXED:
    268       1.1  christos 
    269       1.1  christos         /* First element is the (Integer) revision */
    270       1.1  christos 
    271       1.1  christos         ApCheckObjectType (Predefined->Info.Name, Op,
    272       1.1  christos             ACPI_RTYPE_INTEGER, 0);
    273       1.1  christos 
    274       1.1  christos         Op = Op->Asl.Next;
    275       1.1  christos         Count--;
    276       1.1  christos 
    277   1.1.1.2  christos         /* Examine the subpackages */
    278       1.1  christos 
    279       1.1  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    280       1.1  christos             Package, 1, Count);
    281       1.1  christos         break;
    282       1.1  christos 
    283       1.1  christos     case ACPI_PTYPE2_PKG_COUNT:
    284       1.1  christos 
    285   1.1.1.2  christos         /* First element is the (Integer) count of subpackages to follow */
    286       1.1  christos 
    287       1.1  christos         Status = ApCheckObjectType (Predefined->Info.Name, Op,
    288       1.1  christos             ACPI_RTYPE_INTEGER, 0);
    289       1.1  christos 
    290       1.1  christos         /* We must have an integer count from above (otherwise, use Count) */
    291       1.1  christos 
    292       1.1  christos         if (ACPI_SUCCESS (Status))
    293       1.1  christos         {
    294       1.1  christos             /*
    295       1.1  christos              * Count cannot be larger than the parent package length, but
    296       1.1  christos              * allow it to be smaller. The >= accounts for the Integer above.
    297       1.1  christos              */
    298       1.1  christos             ExpectedCount = (UINT32) Op->Asl.Value.Integer;
    299       1.1  christos             if (ExpectedCount >= Count)
    300       1.1  christos             {
    301       1.1  christos                 goto PackageTooSmall;
    302       1.1  christos             }
    303       1.1  christos 
    304       1.1  christos             Count = ExpectedCount;
    305       1.1  christos         }
    306       1.1  christos 
    307       1.1  christos         Op = Op->Asl.Next;
    308       1.1  christos 
    309   1.1.1.2  christos         /* Examine the subpackages */
    310       1.1  christos 
    311       1.1  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    312       1.1  christos             Package, 1, Count);
    313       1.1  christos         break;
    314       1.1  christos 
    315   1.1.1.2  christos     case ACPI_PTYPE2_UUID_PAIR:
    316   1.1.1.2  christos 
    317   1.1.1.2  christos         /* The package contains a variable list of UUID Buffer/Package pairs */
    318   1.1.1.2  christos 
    319   1.1.1.2  christos         /* The length of the package must be even */
    320   1.1.1.2  christos 
    321   1.1.1.2  christos         if (Count & 1)
    322   1.1.1.2  christos         {
    323   1.1.1.9  christos             sprintf (AslGbl_MsgBuffer, "%4.4s: Package length, %d, must be even.",
    324   1.1.1.2  christos                 Predefined->Info.Name, Count);
    325   1.1.1.2  christos 
    326   1.1.1.2  christos             AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
    327   1.1.1.9  christos                 ParentOp->Asl.Child, AslGbl_MsgBuffer);
    328   1.1.1.2  christos         }
    329   1.1.1.2  christos 
    330   1.1.1.2  christos         /* Validate the alternating types */
    331   1.1.1.2  christos 
    332   1.1.1.2  christos         for (i = 0; i < Count; ++i)
    333   1.1.1.2  christos         {
    334   1.1.1.2  christos             if (i & 1)
    335   1.1.1.2  christos             {
    336   1.1.1.2  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    337   1.1.1.2  christos                     Package->RetInfo.ObjectType2, i);
    338   1.1.1.2  christos             }
    339   1.1.1.2  christos             else
    340   1.1.1.2  christos             {
    341   1.1.1.2  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    342   1.1.1.2  christos                     Package->RetInfo.ObjectType1, i);
    343   1.1.1.2  christos             }
    344   1.1.1.2  christos 
    345   1.1.1.2  christos             Op = Op->Asl.Next;
    346   1.1.1.2  christos         }
    347   1.1.1.2  christos 
    348   1.1.1.2  christos         break;
    349   1.1.1.2  christos 
    350   1.1.1.4  christos     case ACPI_PTYPE2_VAR_VAR:
    351   1.1.1.4  christos 
    352   1.1.1.4  christos         /* Check for minimum size (ints at beginning + 1 subpackage) */
    353   1.1.1.4  christos 
    354   1.1.1.4  christos         ExpectedCount = Package->RetInfo4.Count1 + 1;
    355   1.1.1.4  christos         if (Count < ExpectedCount)
    356   1.1.1.4  christos         {
    357   1.1.1.4  christos             goto PackageTooSmall;
    358   1.1.1.4  christos         }
    359   1.1.1.4  christos 
    360   1.1.1.4  christos         /* Check the non-package elements at beginning of main package */
    361   1.1.1.4  christos 
    362   1.1.1.4  christos         for (i = 0; i < Package->RetInfo4.Count1; ++i)
    363   1.1.1.4  christos         {
    364  1.1.1.11  christos             ApCheckObjectType (Predefined->Info.Name, Op,
    365   1.1.1.4  christos                 Package->RetInfo4.ObjectType1, i);
    366   1.1.1.4  christos             Op = Op->Asl.Next;
    367   1.1.1.4  christos         }
    368   1.1.1.4  christos 
    369   1.1.1.4  christos         /* Examine the variable-length list of subpackages */
    370   1.1.1.4  christos 
    371   1.1.1.4  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    372   1.1.1.4  christos             Package, Package->RetInfo4.Count1, Count);
    373   1.1.1.4  christos 
    374   1.1.1.4  christos         break;
    375   1.1.1.4  christos 
    376       1.1  christos     case ACPI_PTYPE2:
    377       1.1  christos     case ACPI_PTYPE2_FIXED:
    378       1.1  christos     case ACPI_PTYPE2_MIN:
    379       1.1  christos     case ACPI_PTYPE2_COUNT:
    380       1.1  christos     case ACPI_PTYPE2_FIX_VAR:
    381       1.1  christos         /*
    382       1.1  christos          * These types all return a single Package that consists of a
    383   1.1.1.2  christos          * variable number of subpackages.
    384       1.1  christos          */
    385       1.1  christos 
    386   1.1.1.2  christos         /* Examine the subpackages */
    387       1.1  christos 
    388       1.1  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    389       1.1  christos             Package, 0, Count);
    390       1.1  christos         break;
    391       1.1  christos 
    392       1.1  christos     default:
    393       1.1  christos         return;
    394       1.1  christos     }
    395       1.1  christos 
    396       1.1  christos     return;
    397       1.1  christos 
    398       1.1  christos PackageTooSmall:
    399       1.1  christos     ApPackageTooSmall (Predefined->Info.Name, ParentOp,
    400       1.1  christos         Count, ExpectedCount);
    401       1.1  christos }
    402       1.1  christos 
    403       1.1  christos 
    404       1.1  christos /*******************************************************************************
    405       1.1  christos  *
    406   1.1.1.6  christos  * FUNCTION:    ApCustomPackage
    407   1.1.1.6  christos  *
    408   1.1.1.6  christos  * PARAMETERS:  ParentOp            - Parse op for the package
    409   1.1.1.6  christos  *              Predefined          - Pointer to package-specific info for
    410   1.1.1.6  christos  *                                    the method
    411   1.1.1.6  christos  *
    412   1.1.1.6  christos  * RETURN:      None
    413   1.1.1.6  christos  *
    414   1.1.1.6  christos  * DESCRIPTION: Validate packages that don't fit into the standard model and
    415   1.1.1.6  christos  *              require custom code.
    416   1.1.1.6  christos  *
    417   1.1.1.6  christos  * NOTE: Currently used for the _BIX method only. When needed for two or more
    418   1.1.1.6  christos  * methods, probably a detect/dispatch mechanism will be required.
    419   1.1.1.6  christos  *
    420   1.1.1.6  christos  ******************************************************************************/
    421   1.1.1.6  christos 
    422   1.1.1.6  christos static void
    423   1.1.1.6  christos ApCustomPackage (
    424   1.1.1.6  christos     ACPI_PARSE_OBJECT           *ParentOp,
    425   1.1.1.6  christos     const ACPI_PREDEFINED_INFO  *Predefined)
    426   1.1.1.6  christos {
    427   1.1.1.6  christos     ACPI_PARSE_OBJECT           *Op;
    428   1.1.1.6  christos     UINT32                      Count;
    429   1.1.1.6  christos     UINT32                      ExpectedCount;
    430   1.1.1.6  christos     UINT32                      Version;
    431   1.1.1.6  christos 
    432   1.1.1.6  christos 
    433   1.1.1.6  christos     /* First child is the package length */
    434   1.1.1.6  christos 
    435   1.1.1.6  christos     Op = ParentOp->Asl.Child;
    436   1.1.1.6  christos     Count = (UINT32) Op->Asl.Value.Integer;
    437   1.1.1.6  christos 
    438   1.1.1.6  christos     /* Get the version number, must be Integer */
    439   1.1.1.6  christos 
    440   1.1.1.6  christos     Op = Op->Asl.Next;
    441   1.1.1.6  christos     Version = (UINT32) Op->Asl.Value.Integer;
    442   1.1.1.6  christos     if (Op->Asl.ParseOpcode != PARSEOP_INTEGER)
    443   1.1.1.6  christos     {
    444   1.1.1.9  christos         AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, AslGbl_MsgBuffer);
    445   1.1.1.6  christos         return;
    446   1.1.1.6  christos     }
    447   1.1.1.6  christos 
    448   1.1.1.6  christos     /* Validate count (# of elements) */
    449   1.1.1.6  christos 
    450   1.1.1.6  christos     ExpectedCount = 21;         /* Version 1 */
    451   1.1.1.6  christos     if (Version == 0)
    452   1.1.1.6  christos     {
    453   1.1.1.6  christos         ExpectedCount = 20;     /* Version 0 */
    454   1.1.1.6  christos     }
    455   1.1.1.6  christos 
    456   1.1.1.6  christos     if (Count < ExpectedCount)
    457   1.1.1.6  christos     {
    458   1.1.1.6  christos         ApPackageTooSmall (Predefined->Info.Name, ParentOp,
    459   1.1.1.6  christos             Count, ExpectedCount);
    460   1.1.1.6  christos         return;
    461   1.1.1.6  christos     }
    462   1.1.1.6  christos     else if (Count > ExpectedCount)
    463   1.1.1.6  christos     {
    464   1.1.1.6  christos         ApPackageTooLarge (Predefined->Info.Name, ParentOp,
    465   1.1.1.6  christos             Count, ExpectedCount);
    466   1.1.1.6  christos     }
    467   1.1.1.6  christos 
    468   1.1.1.6  christos     /* Validate all elements of the package */
    469   1.1.1.6  christos 
    470   1.1.1.6  christos     Op = ApCheckPackageElements (Predefined->Info.Name, Op,
    471   1.1.1.6  christos         ACPI_RTYPE_INTEGER, 16,
    472   1.1.1.6  christos         ACPI_RTYPE_STRING, 4);
    473   1.1.1.6  christos 
    474   1.1.1.6  christos     /* Version 1 has a single trailing integer */
    475   1.1.1.6  christos 
    476   1.1.1.6  christos     if (Version > 0)
    477   1.1.1.6  christos     {
    478   1.1.1.6  christos         ApCheckPackageElements (Predefined->Info.Name, Op,
    479   1.1.1.6  christos             ACPI_RTYPE_INTEGER, 1, 0, 0);
    480   1.1.1.6  christos     }
    481   1.1.1.6  christos }
    482   1.1.1.6  christos 
    483   1.1.1.6  christos 
    484   1.1.1.6  christos /*******************************************************************************
    485   1.1.1.6  christos  *
    486       1.1  christos  * FUNCTION:    ApCheckPackageElements
    487       1.1  christos  *
    488       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    489       1.1  christos  *              Op                  - Parser op for the package
    490       1.1  christos  *              Type1               - Object type for first group
    491       1.1  christos  *              Count1              - Count for first group
    492       1.1  christos  *              Type2               - Object type for second group
    493       1.1  christos  *              Count2              - Count for second group
    494       1.1  christos  *
    495   1.1.1.6  christos  * RETURN:      Next Op peer in the parse tree, after all specified elements
    496   1.1.1.6  christos  *              have been validated. Used for multiple validations (calls
    497   1.1.1.6  christos  *              to this function).
    498       1.1  christos  *
    499       1.1  christos  * DESCRIPTION: Validate all elements of a package. Works with packages that
    500       1.1  christos  *              are defined to contain up to two groups of different object
    501       1.1  christos  *              types.
    502       1.1  christos  *
    503       1.1  christos  ******************************************************************************/
    504       1.1  christos 
    505   1.1.1.6  christos static ACPI_PARSE_OBJECT *
    506       1.1  christos ApCheckPackageElements (
    507       1.1  christos     const char              *PredefinedName,
    508       1.1  christos     ACPI_PARSE_OBJECT       *Op,
    509       1.1  christos     UINT8                   Type1,
    510       1.1  christos     UINT32                  Count1,
    511       1.1  christos     UINT8                   Type2,
    512       1.1  christos     UINT32                  Count2)
    513       1.1  christos {
    514       1.1  christos     UINT32                  i;
    515       1.1  christos 
    516       1.1  christos 
    517       1.1  christos     /*
    518       1.1  christos      * Up to two groups of package elements are supported by the data
    519       1.1  christos      * structure. All elements in each group must be of the same type.
    520       1.1  christos      * The second group can have a count of zero.
    521       1.1  christos      *
    522       1.1  christos      * Aborts check upon a NULL package element, as this means (at compile
    523       1.1  christos      * time) that the remainder of the package elements are also NULL
    524       1.1  christos      * (This is the only way to create NULL package elements.)
    525       1.1  christos      */
    526       1.1  christos     for (i = 0; (i < Count1) && Op; i++)
    527       1.1  christos     {
    528       1.1  christos         ApCheckObjectType (PredefinedName, Op, Type1, i);
    529       1.1  christos         Op = Op->Asl.Next;
    530       1.1  christos     }
    531       1.1  christos 
    532       1.1  christos     for (i = 0; (i < Count2) && Op; i++)
    533       1.1  christos     {
    534       1.1  christos         ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
    535       1.1  christos         Op = Op->Asl.Next;
    536       1.1  christos     }
    537   1.1.1.6  christos 
    538   1.1.1.6  christos     return (Op);
    539       1.1  christos }
    540       1.1  christos 
    541       1.1  christos 
    542       1.1  christos /*******************************************************************************
    543       1.1  christos  *
    544       1.1  christos  * FUNCTION:    ApCheckPackageList
    545       1.1  christos  *
    546       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    547       1.1  christos  *              ParentOp            - Parser op of the parent package
    548       1.1  christos  *              Package             - Package info for this predefined name
    549       1.1  christos  *              StartIndex          - Index in parent package where list begins
    550       1.1  christos  *              ParentCount         - Element count of parent package
    551       1.1  christos  *
    552       1.1  christos  * RETURN:      None
    553       1.1  christos  *
    554       1.1  christos  * DESCRIPTION: Validate the individual package elements for a predefined name.
    555       1.1  christos  *              Handles the cases where the predefined name is defined as a
    556       1.1  christos  *              Package of Packages (subpackages). These are the types:
    557       1.1  christos  *
    558       1.1  christos  *              ACPI_PTYPE2
    559       1.1  christos  *              ACPI_PTYPE2_FIXED
    560       1.1  christos  *              ACPI_PTYPE2_MIN
    561       1.1  christos  *              ACPI_PTYPE2_COUNT
    562       1.1  christos  *              ACPI_PTYPE2_FIX_VAR
    563   1.1.1.4  christos  *              ACPI_PTYPE2_VAR_VAR
    564       1.1  christos  *
    565       1.1  christos  ******************************************************************************/
    566       1.1  christos 
    567       1.1  christos static void
    568       1.1  christos ApCheckPackageList (
    569       1.1  christos     const char                  *PredefinedName,
    570       1.1  christos     ACPI_PARSE_OBJECT           *ParentOp,
    571       1.1  christos     const ACPI_PREDEFINED_INFO  *Package,
    572       1.1  christos     UINT32                      StartIndex,
    573       1.1  christos     UINT32                      ParentCount)
    574       1.1  christos {
    575       1.1  christos     ACPI_PARSE_OBJECT           *SubPackageOp = ParentOp;
    576       1.1  christos     ACPI_PARSE_OBJECT           *Op;
    577       1.1  christos     ACPI_STATUS                 Status;
    578       1.1  christos     UINT32                      Count;
    579       1.1  christos     UINT32                      ExpectedCount;
    580       1.1  christos     UINT32                      i;
    581       1.1  christos     UINT32                      j;
    582       1.1  christos 
    583       1.1  christos 
    584       1.1  christos     /*
    585       1.1  christos      * Validate each subpackage in the parent Package
    586       1.1  christos      *
    587       1.1  christos      * Note: We ignore NULL package elements on the assumption that
    588       1.1  christos      * they will be initialized by the BIOS or other ASL code.
    589       1.1  christos      */
    590       1.1  christos     for (i = 0; (i < ParentCount) && SubPackageOp; i++)
    591       1.1  christos     {
    592       1.1  christos         /* Each object in the list must be of type Package */
    593       1.1  christos 
    594       1.1  christos         Status = ApCheckObjectType (PredefinedName, SubPackageOp,
    595       1.1  christos             ACPI_RTYPE_PACKAGE, i + StartIndex);
    596       1.1  christos         if (ACPI_FAILURE (Status))
    597       1.1  christos         {
    598       1.1  christos             goto NextSubpackage;
    599       1.1  christos         }
    600       1.1  christos 
    601       1.1  christos         /* Examine the different types of expected subpackages */
    602       1.1  christos 
    603       1.1  christos         Op = SubPackageOp->Asl.Child;
    604       1.1  christos 
    605       1.1  christos         /* First child is the package length */
    606       1.1  christos 
    607       1.1  christos         Count = (UINT32) Op->Asl.Value.Integer;
    608       1.1  christos         Op = Op->Asl.Next;
    609       1.1  christos 
    610   1.1.1.4  christos         /*
    611   1.1.1.4  christos          * Most subpackage must have at least one element, with
    612   1.1.1.4  christos          * only rare exceptions. (_RDI)
    613   1.1.1.4  christos          */
    614   1.1.1.4  christos         if (!Count &&
    615   1.1.1.4  christos             (Package->RetInfo.Type != ACPI_PTYPE2_VAR_VAR))
    616       1.1  christos         {
    617       1.1  christos             ApZeroLengthPackage (PredefinedName, SubPackageOp);
    618       1.1  christos             goto NextSubpackage;
    619       1.1  christos         }
    620       1.1  christos 
    621       1.1  christos         /*
    622       1.1  christos          * Decode the package type.
    623       1.1  christos          * PTYPE2 indicates that a "package of packages" is expected for
    624       1.1  christos          * this name. The various flavors of PTYPE2 indicate the number
    625       1.1  christos          * and format of the subpackages.
    626       1.1  christos          */
    627       1.1  christos         switch (Package->RetInfo.Type)
    628       1.1  christos         {
    629       1.1  christos         case ACPI_PTYPE2:
    630       1.1  christos         case ACPI_PTYPE2_PKG_COUNT:
    631       1.1  christos         case ACPI_PTYPE2_REV_FIXED:
    632       1.1  christos 
    633       1.1  christos             /* Each subpackage has a fixed number of elements */
    634       1.1  christos 
    635       1.1  christos             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    636       1.1  christos             if (Count < ExpectedCount)
    637       1.1  christos             {
    638       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    639       1.1  christos                     Count, ExpectedCount);
    640       1.1  christos                 break;
    641       1.1  christos             }
    642   1.1.1.2  christos             if (Count > ExpectedCount)
    643   1.1.1.2  christos             {
    644   1.1.1.2  christos                 ApPackageTooLarge (PredefinedName, SubPackageOp,
    645   1.1.1.2  christos                     Count, ExpectedCount);
    646   1.1.1.2  christos                 break;
    647   1.1.1.2  christos             }
    648       1.1  christos 
    649       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    650       1.1  christos                 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
    651       1.1  christos                 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
    652       1.1  christos             break;
    653       1.1  christos 
    654       1.1  christos         case ACPI_PTYPE2_FIX_VAR:
    655       1.1  christos             /*
    656       1.1  christos              * Each subpackage has a fixed number of elements and an
    657       1.1  christos              * optional element
    658       1.1  christos              */
    659       1.1  christos             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    660       1.1  christos             if (Count < ExpectedCount)
    661       1.1  christos             {
    662       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    663       1.1  christos                     Count, ExpectedCount);
    664       1.1  christos                 break;
    665       1.1  christos             }
    666       1.1  christos 
    667       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    668       1.1  christos                 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
    669       1.1  christos                 Package->RetInfo.ObjectType2,
    670       1.1  christos                 Count - Package->RetInfo.Count1);
    671       1.1  christos             break;
    672       1.1  christos 
    673   1.1.1.4  christos         case ACPI_PTYPE2_VAR_VAR:
    674   1.1.1.4  christos             /*
    675   1.1.1.4  christos              * Must have at least the minimum number elements.
    676   1.1.1.4  christos              * A zero PkgCount means the number of elements is variable.
    677   1.1.1.4  christos              */
    678   1.1.1.4  christos             ExpectedCount = Package->RetInfo4.PkgCount;
    679   1.1.1.4  christos             if (ExpectedCount && (Count < ExpectedCount))
    680   1.1.1.4  christos             {
    681   1.1.1.4  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    682   1.1.1.4  christos                     Count, 1);
    683   1.1.1.4  christos                 break;
    684   1.1.1.4  christos             }
    685   1.1.1.4  christos 
    686   1.1.1.4  christos             ApCheckPackageElements (PredefinedName, Op,
    687   1.1.1.4  christos                 Package->RetInfo4.SubObjectTypes,
    688   1.1.1.4  christos                 Package->RetInfo4.PkgCount,
    689   1.1.1.4  christos                 0, 0);
    690   1.1.1.4  christos             break;
    691   1.1.1.4  christos 
    692       1.1  christos         case ACPI_PTYPE2_FIXED:
    693       1.1  christos 
    694   1.1.1.2  christos             /* Each subpackage has a fixed length */
    695       1.1  christos 
    696       1.1  christos             ExpectedCount = Package->RetInfo2.Count;
    697       1.1  christos             if (Count < ExpectedCount)
    698       1.1  christos             {
    699       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    700       1.1  christos                     Count, ExpectedCount);
    701       1.1  christos                 break;
    702       1.1  christos             }
    703   1.1.1.2  christos             if (Count > ExpectedCount)
    704   1.1.1.2  christos             {
    705   1.1.1.2  christos                 ApPackageTooLarge (PredefinedName, SubPackageOp,
    706   1.1.1.2  christos                     Count, ExpectedCount);
    707   1.1.1.2  christos                 break;
    708   1.1.1.2  christos             }
    709       1.1  christos 
    710       1.1  christos             /* Check each object/type combination */
    711       1.1  christos 
    712       1.1  christos             for (j = 0; j < ExpectedCount; j++)
    713       1.1  christos             {
    714       1.1  christos                 ApCheckObjectType (PredefinedName, Op,
    715       1.1  christos                     Package->RetInfo2.ObjectType[j], j);
    716       1.1  christos 
    717       1.1  christos                 Op = Op->Asl.Next;
    718       1.1  christos             }
    719       1.1  christos             break;
    720       1.1  christos 
    721       1.1  christos         case ACPI_PTYPE2_MIN:
    722       1.1  christos 
    723   1.1.1.2  christos             /* Each subpackage has a variable but minimum length */
    724       1.1  christos 
    725       1.1  christos             ExpectedCount = Package->RetInfo.Count1;
    726       1.1  christos             if (Count < ExpectedCount)
    727       1.1  christos             {
    728       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    729       1.1  christos                     Count, ExpectedCount);
    730       1.1  christos                 break;
    731       1.1  christos             }
    732       1.1  christos 
    733   1.1.1.2  christos             /* Check the type of each subpackage element */
    734       1.1  christos 
    735       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    736       1.1  christos                 Package->RetInfo.ObjectType1, Count, 0, 0);
    737       1.1  christos             break;
    738       1.1  christos 
    739       1.1  christos         case ACPI_PTYPE2_COUNT:
    740       1.1  christos             /*
    741       1.1  christos              * First element is the (Integer) count of elements, including
    742       1.1  christos              * the count field (the ACPI name is NumElements)
    743       1.1  christos              */
    744       1.1  christos             Status = ApCheckObjectType (PredefinedName, Op,
    745       1.1  christos                 ACPI_RTYPE_INTEGER, 0);
    746       1.1  christos 
    747       1.1  christos             /* We must have an integer count from above (otherwise, use Count) */
    748       1.1  christos 
    749       1.1  christos             if (ACPI_SUCCESS (Status))
    750       1.1  christos             {
    751       1.1  christos                 /*
    752       1.1  christos                  * Make sure package is large enough for the Count and is
    753       1.1  christos                  * is as large as the minimum size
    754       1.1  christos                  */
    755       1.1  christos                 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
    756       1.1  christos 
    757       1.1  christos                 if (Count < ExpectedCount)
    758       1.1  christos                 {
    759       1.1  christos                     ApPackageTooSmall (PredefinedName, SubPackageOp,
    760       1.1  christos                         Count, ExpectedCount);
    761       1.1  christos                     break;
    762       1.1  christos                 }
    763       1.1  christos                 else if (Count > ExpectedCount)
    764       1.1  christos                 {
    765       1.1  christos                     ApPackageTooLarge (PredefinedName, SubPackageOp,
    766       1.1  christos                         Count, ExpectedCount);
    767       1.1  christos                 }
    768       1.1  christos 
    769       1.1  christos                 /* Some names of this type have a minimum length */
    770       1.1  christos 
    771       1.1  christos                 if (Count < Package->RetInfo.Count1)
    772       1.1  christos                 {
    773       1.1  christos                     ExpectedCount = Package->RetInfo.Count1;
    774       1.1  christos                     ApPackageTooSmall (PredefinedName, SubPackageOp,
    775       1.1  christos                         Count, ExpectedCount);
    776       1.1  christos                     break;
    777       1.1  christos                 }
    778       1.1  christos 
    779       1.1  christos                 Count = ExpectedCount;
    780       1.1  christos             }
    781       1.1  christos 
    782   1.1.1.2  christos             /* Check the type of each subpackage element */
    783       1.1  christos 
    784       1.1  christos             Op = Op->Asl.Next;
    785       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    786       1.1  christos                 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
    787       1.1  christos             break;
    788       1.1  christos 
    789       1.1  christos         default:
    790       1.1  christos             break;
    791       1.1  christos         }
    792       1.1  christos 
    793       1.1  christos NextSubpackage:
    794       1.1  christos         SubPackageOp = SubPackageOp->Asl.Next;
    795       1.1  christos     }
    796       1.1  christos }
    797       1.1  christos 
    798       1.1  christos 
    799       1.1  christos /*******************************************************************************
    800       1.1  christos  *
    801       1.1  christos  * FUNCTION:    ApPackageTooSmall
    802       1.1  christos  *
    803       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    804       1.1  christos  *              Op                  - Current parser op
    805       1.1  christos  *              Count               - Actual package element count
    806       1.1  christos  *              ExpectedCount       - Expected package element count
    807       1.1  christos  *
    808       1.1  christos  * RETURN:      None
    809       1.1  christos  *
    810       1.1  christos  * DESCRIPTION: Issue error message for a package that is smaller than
    811       1.1  christos  *              required.
    812       1.1  christos  *
    813       1.1  christos  ******************************************************************************/
    814       1.1  christos 
    815       1.1  christos static void
    816       1.1  christos ApPackageTooSmall (
    817       1.1  christos     const char                  *PredefinedName,
    818       1.1  christos     ACPI_PARSE_OBJECT           *Op,
    819       1.1  christos     UINT32                      Count,
    820       1.1  christos     UINT32                      ExpectedCount)
    821       1.1  christos {
    822       1.1  christos 
    823  1.1.1.13  christos     sprintf (AslGbl_MsgBuffer, "%4.4s: length %u, required minimum is %u",
    824       1.1  christos         PredefinedName, Count, ExpectedCount);
    825       1.1  christos 
    826   1.1.1.9  christos     AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, AslGbl_MsgBuffer);
    827       1.1  christos }
    828       1.1  christos 
    829       1.1  christos 
    830       1.1  christos /*******************************************************************************
    831       1.1  christos  *
    832       1.1  christos  * FUNCTION:    ApZeroLengthPackage
    833       1.1  christos  *
    834       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    835       1.1  christos  *              Op                  - Current parser op
    836       1.1  christos  *
    837       1.1  christos  * RETURN:      None
    838       1.1  christos  *
    839       1.1  christos  * DESCRIPTION: Issue error message for a zero-length package (a package that
    840       1.1  christos  *              is required to have a non-zero length). Variable length
    841       1.1  christos  *              packages seem to be allowed to have zero length, however.
    842       1.1  christos  *              Even if not allowed, BIOS code does it.
    843       1.1  christos  *
    844       1.1  christos  ******************************************************************************/
    845       1.1  christos 
    846       1.1  christos static void
    847       1.1  christos ApZeroLengthPackage (
    848       1.1  christos     const char                  *PredefinedName,
    849       1.1  christos     ACPI_PARSE_OBJECT           *Op)
    850       1.1  christos {
    851       1.1  christos 
    852  1.1.1.13  christos     sprintf (AslGbl_MsgBuffer, "%4.4s: length is zero", PredefinedName);
    853       1.1  christos 
    854   1.1.1.9  christos     AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, AslGbl_MsgBuffer);
    855       1.1  christos }
    856       1.1  christos 
    857       1.1  christos 
    858       1.1  christos /*******************************************************************************
    859       1.1  christos  *
    860       1.1  christos  * FUNCTION:    ApPackageTooLarge
    861       1.1  christos  *
    862       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    863       1.1  christos  *              Op                  - Current parser op
    864       1.1  christos  *              Count               - Actual package element count
    865       1.1  christos  *              ExpectedCount       - Expected package element count
    866       1.1  christos  *
    867       1.1  christos  * RETURN:      None
    868       1.1  christos  *
    869       1.1  christos  * DESCRIPTION: Issue a remark for a package that is larger than expected.
    870       1.1  christos  *
    871       1.1  christos  ******************************************************************************/
    872       1.1  christos 
    873       1.1  christos static void
    874       1.1  christos ApPackageTooLarge (
    875       1.1  christos     const char                  *PredefinedName,
    876       1.1  christos     ACPI_PARSE_OBJECT           *Op,
    877       1.1  christos     UINT32                      Count,
    878       1.1  christos     UINT32                      ExpectedCount)
    879       1.1  christos {
    880       1.1  christos 
    881  1.1.1.13  christos     sprintf (AslGbl_MsgBuffer, "%4.4s: length is %u, only %u required",
    882       1.1  christos         PredefinedName, Count, ExpectedCount);
    883       1.1  christos 
    884   1.1.1.9  christos     AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, AslGbl_MsgBuffer);
    885       1.1  christos }
    886