Home | History | Annotate | Line # | Download | only in compiler
aslprepkg.c revision 1.8.12.1
      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.8.12.1  pgoyette  * Copyright (C) 2000 - 2018, 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  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY 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.7  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.7  christos static void
     92       1.7  christos ApCustomPackage (
     93       1.7  christos     ACPI_PARSE_OBJECT           *ParentOp,
     94       1.7  christos     const ACPI_PREDEFINED_INFO  *Predefined);
     95       1.7  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.5  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.7  christos     case ACPI_PTYPE_CUSTOM:
    177       1.7  christos 
    178       1.7  christos         ApCustomPackage (ParentOp, Predefined);
    179       1.7  christos         break;
    180       1.7  christos 
    181       1.1  christos     case ACPI_PTYPE1_FIXED:
    182       1.1  christos         /*
    183       1.3  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.3  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  christos             ApCheckObjectType (Predefined->Info.Name, Op,
    214       1.1  christos                 Package->RetInfo.ObjectType1, i);
    215       1.1  christos             Op = Op->Asl.Next;
    216       1.1  christos         }
    217       1.1  christos         break;
    218       1.1  christos 
    219       1.1  christos     case ACPI_PTYPE1_OPTION:
    220       1.1  christos         /*
    221       1.3  christos          * The package count is variable, there are no subpackages.
    222       1.1  christos          * There are a fixed number of required elements, and a variable
    223       1.1  christos          * number of optional elements.
    224       1.1  christos          *
    225       1.1  christos          * Check if package is at least as large as the minimum required
    226       1.1  christos          */
    227       1.1  christos         ExpectedCount = Package->RetInfo3.Count;
    228       1.1  christos         if (Count < ExpectedCount)
    229       1.1  christos         {
    230       1.1  christos             goto PackageTooSmall;
    231       1.1  christos         }
    232       1.1  christos 
    233       1.1  christos         /* Variable number of sub-objects */
    234       1.1  christos 
    235       1.1  christos         for (i = 0; i < Count; i++)
    236       1.1  christos         {
    237       1.1  christos             if (i < Package->RetInfo3.Count)
    238       1.1  christos             {
    239       1.1  christos                 /* These are the required package elements (0, 1, or 2) */
    240       1.1  christos 
    241       1.1  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    242       1.1  christos                     Package->RetInfo3.ObjectType[i], i);
    243       1.1  christos             }
    244       1.1  christos             else
    245       1.1  christos             {
    246       1.1  christos                 /* These are the optional package elements */
    247       1.1  christos 
    248       1.1  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    249       1.1  christos                     Package->RetInfo3.TailObjectType, i);
    250       1.1  christos             }
    251       1.6  christos 
    252       1.1  christos             Op = Op->Asl.Next;
    253       1.1  christos         }
    254       1.1  christos         break;
    255       1.1  christos 
    256       1.1  christos     case ACPI_PTYPE2_REV_FIXED:
    257       1.1  christos 
    258       1.1  christos         /* First element is the (Integer) revision */
    259       1.1  christos 
    260       1.1  christos         ApCheckObjectType (Predefined->Info.Name, Op,
    261       1.1  christos             ACPI_RTYPE_INTEGER, 0);
    262       1.1  christos 
    263       1.1  christos         Op = Op->Asl.Next;
    264       1.1  christos         Count--;
    265       1.1  christos 
    266       1.3  christos         /* Examine the subpackages */
    267       1.1  christos 
    268       1.1  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    269       1.1  christos             Package, 1, Count);
    270       1.1  christos         break;
    271       1.1  christos 
    272       1.1  christos     case ACPI_PTYPE2_PKG_COUNT:
    273       1.1  christos 
    274       1.3  christos         /* First element is the (Integer) count of subpackages to follow */
    275       1.1  christos 
    276       1.1  christos         Status = ApCheckObjectType (Predefined->Info.Name, Op,
    277       1.1  christos             ACPI_RTYPE_INTEGER, 0);
    278       1.1  christos 
    279       1.1  christos         /* We must have an integer count from above (otherwise, use Count) */
    280       1.1  christos 
    281       1.1  christos         if (ACPI_SUCCESS (Status))
    282       1.1  christos         {
    283       1.1  christos             /*
    284       1.1  christos              * Count cannot be larger than the parent package length, but
    285       1.1  christos              * allow it to be smaller. The >= accounts for the Integer above.
    286       1.1  christos              */
    287       1.1  christos             ExpectedCount = (UINT32) Op->Asl.Value.Integer;
    288       1.1  christos             if (ExpectedCount >= Count)
    289       1.1  christos             {
    290       1.1  christos                 goto PackageTooSmall;
    291       1.1  christos             }
    292       1.1  christos 
    293       1.1  christos             Count = ExpectedCount;
    294       1.1  christos         }
    295       1.1  christos 
    296       1.1  christos         Op = Op->Asl.Next;
    297       1.1  christos 
    298       1.3  christos         /* Examine the subpackages */
    299       1.1  christos 
    300       1.1  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    301       1.1  christos             Package, 1, Count);
    302       1.1  christos         break;
    303       1.1  christos 
    304       1.3  christos     case ACPI_PTYPE2_UUID_PAIR:
    305       1.3  christos 
    306       1.3  christos         /* The package contains a variable list of UUID Buffer/Package pairs */
    307       1.3  christos 
    308       1.3  christos         /* The length of the package must be even */
    309       1.3  christos 
    310       1.3  christos         if (Count & 1)
    311       1.3  christos         {
    312       1.3  christos             sprintf (MsgBuffer, "%4.4s: Package length, %d, must be even.",
    313       1.3  christos                 Predefined->Info.Name, Count);
    314       1.3  christos 
    315       1.3  christos             AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
    316       1.3  christos                 ParentOp->Asl.Child, MsgBuffer);
    317       1.3  christos         }
    318       1.3  christos 
    319       1.3  christos         /* Validate the alternating types */
    320       1.3  christos 
    321       1.3  christos         for (i = 0; i < Count; ++i)
    322       1.3  christos         {
    323       1.3  christos             if (i & 1)
    324       1.3  christos             {
    325       1.3  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    326       1.3  christos                     Package->RetInfo.ObjectType2, i);
    327       1.3  christos             }
    328       1.3  christos             else
    329       1.3  christos             {
    330       1.3  christos                 ApCheckObjectType (Predefined->Info.Name, Op,
    331       1.3  christos                     Package->RetInfo.ObjectType1, i);
    332       1.3  christos             }
    333       1.3  christos 
    334       1.3  christos             Op = Op->Asl.Next;
    335       1.3  christos         }
    336       1.3  christos 
    337       1.3  christos         break;
    338       1.3  christos 
    339       1.5  christos     case ACPI_PTYPE2_VAR_VAR:
    340       1.5  christos 
    341       1.5  christos         /* Check for minimum size (ints at beginning + 1 subpackage) */
    342       1.5  christos 
    343       1.5  christos         ExpectedCount = Package->RetInfo4.Count1 + 1;
    344       1.5  christos         if (Count < ExpectedCount)
    345       1.5  christos         {
    346       1.5  christos             goto PackageTooSmall;
    347       1.5  christos         }
    348       1.5  christos 
    349       1.5  christos         /* Check the non-package elements at beginning of main package */
    350       1.5  christos 
    351       1.5  christos         for (i = 0; i < Package->RetInfo4.Count1; ++i)
    352       1.5  christos         {
    353       1.5  christos             Status = ApCheckObjectType (Predefined->Info.Name, Op,
    354       1.5  christos                 Package->RetInfo4.ObjectType1, i);
    355       1.5  christos             Op = Op->Asl.Next;
    356       1.5  christos         }
    357       1.5  christos 
    358       1.5  christos         /* Examine the variable-length list of subpackages */
    359       1.5  christos 
    360       1.5  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    361       1.5  christos             Package, Package->RetInfo4.Count1, Count);
    362       1.5  christos 
    363       1.5  christos         break;
    364       1.5  christos 
    365       1.1  christos     case ACPI_PTYPE2:
    366       1.1  christos     case ACPI_PTYPE2_FIXED:
    367       1.1  christos     case ACPI_PTYPE2_MIN:
    368       1.1  christos     case ACPI_PTYPE2_COUNT:
    369       1.1  christos     case ACPI_PTYPE2_FIX_VAR:
    370       1.1  christos         /*
    371       1.1  christos          * These types all return a single Package that consists of a
    372       1.3  christos          * variable number of subpackages.
    373       1.1  christos          */
    374       1.1  christos 
    375       1.3  christos         /* Examine the subpackages */
    376       1.1  christos 
    377       1.1  christos         ApCheckPackageList (Predefined->Info.Name, Op,
    378       1.1  christos             Package, 0, Count);
    379       1.1  christos         break;
    380       1.1  christos 
    381       1.1  christos     default:
    382       1.1  christos         return;
    383       1.1  christos     }
    384       1.1  christos 
    385       1.1  christos     return;
    386       1.1  christos 
    387       1.1  christos PackageTooSmall:
    388       1.1  christos     ApPackageTooSmall (Predefined->Info.Name, ParentOp,
    389       1.1  christos         Count, ExpectedCount);
    390       1.1  christos }
    391       1.1  christos 
    392       1.1  christos 
    393       1.1  christos /*******************************************************************************
    394       1.1  christos  *
    395       1.7  christos  * FUNCTION:    ApCustomPackage
    396       1.7  christos  *
    397       1.7  christos  * PARAMETERS:  ParentOp            - Parse op for the package
    398       1.7  christos  *              Predefined          - Pointer to package-specific info for
    399       1.7  christos  *                                    the method
    400       1.7  christos  *
    401       1.7  christos  * RETURN:      None
    402       1.7  christos  *
    403       1.7  christos  * DESCRIPTION: Validate packages that don't fit into the standard model and
    404       1.7  christos  *              require custom code.
    405       1.7  christos  *
    406       1.7  christos  * NOTE: Currently used for the _BIX method only. When needed for two or more
    407       1.7  christos  * methods, probably a detect/dispatch mechanism will be required.
    408       1.7  christos  *
    409       1.7  christos  ******************************************************************************/
    410       1.7  christos 
    411       1.7  christos static void
    412       1.7  christos ApCustomPackage (
    413       1.7  christos     ACPI_PARSE_OBJECT           *ParentOp,
    414       1.7  christos     const ACPI_PREDEFINED_INFO  *Predefined)
    415       1.7  christos {
    416       1.7  christos     ACPI_PARSE_OBJECT           *Op;
    417       1.7  christos     UINT32                      Count;
    418       1.7  christos     UINT32                      ExpectedCount;
    419       1.7  christos     UINT32                      Version;
    420       1.7  christos 
    421       1.7  christos 
    422       1.7  christos     /* First child is the package length */
    423       1.7  christos 
    424       1.7  christos     Op = ParentOp->Asl.Child;
    425       1.7  christos     Count = (UINT32) Op->Asl.Value.Integer;
    426       1.7  christos 
    427       1.7  christos     /* Get the version number, must be Integer */
    428       1.7  christos 
    429       1.7  christos     Op = Op->Asl.Next;
    430       1.7  christos     Version = (UINT32) Op->Asl.Value.Integer;
    431       1.7  christos     if (Op->Asl.ParseOpcode != PARSEOP_INTEGER)
    432       1.7  christos     {
    433       1.7  christos         AslError (ASL_ERROR, ASL_MSG_RESERVED_OPERAND_TYPE, Op, MsgBuffer);
    434       1.7  christos         return;
    435       1.7  christos     }
    436       1.7  christos 
    437       1.7  christos     /* Validate count (# of elements) */
    438       1.7  christos 
    439       1.7  christos     ExpectedCount = 21;         /* Version 1 */
    440       1.7  christos     if (Version == 0)
    441       1.7  christos     {
    442       1.7  christos         ExpectedCount = 20;     /* Version 0 */
    443       1.7  christos     }
    444       1.7  christos 
    445       1.7  christos     if (Count < ExpectedCount)
    446       1.7  christos     {
    447       1.7  christos         ApPackageTooSmall (Predefined->Info.Name, ParentOp,
    448       1.7  christos             Count, ExpectedCount);
    449       1.7  christos         return;
    450       1.7  christos     }
    451       1.7  christos     else if (Count > ExpectedCount)
    452       1.7  christos     {
    453       1.7  christos         ApPackageTooLarge (Predefined->Info.Name, ParentOp,
    454       1.7  christos             Count, ExpectedCount);
    455       1.7  christos     }
    456       1.7  christos 
    457       1.7  christos     /* Validate all elements of the package */
    458       1.7  christos 
    459       1.7  christos     Op = ApCheckPackageElements (Predefined->Info.Name, Op,
    460       1.7  christos         ACPI_RTYPE_INTEGER, 16,
    461       1.7  christos         ACPI_RTYPE_STRING, 4);
    462       1.7  christos 
    463       1.7  christos     /* Version 1 has a single trailing integer */
    464       1.7  christos 
    465       1.7  christos     if (Version > 0)
    466       1.7  christos     {
    467       1.7  christos         ApCheckPackageElements (Predefined->Info.Name, Op,
    468       1.7  christos             ACPI_RTYPE_INTEGER, 1, 0, 0);
    469       1.7  christos     }
    470       1.7  christos }
    471       1.7  christos 
    472       1.7  christos 
    473       1.7  christos /*******************************************************************************
    474       1.7  christos  *
    475       1.1  christos  * FUNCTION:    ApCheckPackageElements
    476       1.1  christos  *
    477       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    478       1.1  christos  *              Op                  - Parser op for the package
    479       1.1  christos  *              Type1               - Object type for first group
    480       1.1  christos  *              Count1              - Count for first group
    481       1.1  christos  *              Type2               - Object type for second group
    482       1.1  christos  *              Count2              - Count for second group
    483       1.1  christos  *
    484       1.7  christos  * RETURN:      Next Op peer in the parse tree, after all specified elements
    485       1.7  christos  *              have been validated. Used for multiple validations (calls
    486       1.7  christos  *              to this function).
    487       1.1  christos  *
    488       1.1  christos  * DESCRIPTION: Validate all elements of a package. Works with packages that
    489       1.1  christos  *              are defined to contain up to two groups of different object
    490       1.1  christos  *              types.
    491       1.1  christos  *
    492       1.1  christos  ******************************************************************************/
    493       1.1  christos 
    494       1.7  christos static ACPI_PARSE_OBJECT *
    495       1.1  christos ApCheckPackageElements (
    496       1.1  christos     const char              *PredefinedName,
    497       1.1  christos     ACPI_PARSE_OBJECT       *Op,
    498       1.1  christos     UINT8                   Type1,
    499       1.1  christos     UINT32                  Count1,
    500       1.1  christos     UINT8                   Type2,
    501       1.1  christos     UINT32                  Count2)
    502       1.1  christos {
    503       1.1  christos     UINT32                  i;
    504       1.1  christos 
    505       1.1  christos 
    506       1.1  christos     /*
    507       1.1  christos      * Up to two groups of package elements are supported by the data
    508       1.1  christos      * structure. All elements in each group must be of the same type.
    509       1.1  christos      * The second group can have a count of zero.
    510       1.1  christos      *
    511       1.1  christos      * Aborts check upon a NULL package element, as this means (at compile
    512       1.1  christos      * time) that the remainder of the package elements are also NULL
    513       1.1  christos      * (This is the only way to create NULL package elements.)
    514       1.1  christos      */
    515       1.1  christos     for (i = 0; (i < Count1) && Op; i++)
    516       1.1  christos     {
    517       1.1  christos         ApCheckObjectType (PredefinedName, Op, Type1, i);
    518       1.1  christos         Op = Op->Asl.Next;
    519       1.1  christos     }
    520       1.1  christos 
    521       1.1  christos     for (i = 0; (i < Count2) && Op; i++)
    522       1.1  christos     {
    523       1.1  christos         ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
    524       1.1  christos         Op = Op->Asl.Next;
    525       1.1  christos     }
    526       1.7  christos 
    527       1.7  christos     return (Op);
    528       1.1  christos }
    529       1.1  christos 
    530       1.1  christos 
    531       1.1  christos /*******************************************************************************
    532       1.1  christos  *
    533       1.1  christos  * FUNCTION:    ApCheckPackageList
    534       1.1  christos  *
    535       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    536       1.1  christos  *              ParentOp            - Parser op of the parent package
    537       1.1  christos  *              Package             - Package info for this predefined name
    538       1.1  christos  *              StartIndex          - Index in parent package where list begins
    539       1.1  christos  *              ParentCount         - Element count of parent package
    540       1.1  christos  *
    541       1.1  christos  * RETURN:      None
    542       1.1  christos  *
    543       1.1  christos  * DESCRIPTION: Validate the individual package elements for a predefined name.
    544       1.1  christos  *              Handles the cases where the predefined name is defined as a
    545       1.1  christos  *              Package of Packages (subpackages). These are the types:
    546       1.1  christos  *
    547       1.1  christos  *              ACPI_PTYPE2
    548       1.1  christos  *              ACPI_PTYPE2_FIXED
    549       1.1  christos  *              ACPI_PTYPE2_MIN
    550       1.1  christos  *              ACPI_PTYPE2_COUNT
    551       1.1  christos  *              ACPI_PTYPE2_FIX_VAR
    552       1.5  christos  *              ACPI_PTYPE2_VAR_VAR
    553       1.1  christos  *
    554       1.1  christos  ******************************************************************************/
    555       1.1  christos 
    556       1.1  christos static void
    557       1.1  christos ApCheckPackageList (
    558       1.1  christos     const char                  *PredefinedName,
    559       1.1  christos     ACPI_PARSE_OBJECT           *ParentOp,
    560       1.1  christos     const ACPI_PREDEFINED_INFO  *Package,
    561       1.1  christos     UINT32                      StartIndex,
    562       1.1  christos     UINT32                      ParentCount)
    563       1.1  christos {
    564       1.1  christos     ACPI_PARSE_OBJECT           *SubPackageOp = ParentOp;
    565       1.1  christos     ACPI_PARSE_OBJECT           *Op;
    566       1.1  christos     ACPI_STATUS                 Status;
    567       1.1  christos     UINT32                      Count;
    568       1.1  christos     UINT32                      ExpectedCount;
    569       1.1  christos     UINT32                      i;
    570       1.1  christos     UINT32                      j;
    571       1.1  christos 
    572       1.1  christos 
    573       1.1  christos     /*
    574       1.1  christos      * Validate each subpackage in the parent Package
    575       1.1  christos      *
    576       1.1  christos      * Note: We ignore NULL package elements on the assumption that
    577       1.1  christos      * they will be initialized by the BIOS or other ASL code.
    578       1.1  christos      */
    579       1.1  christos     for (i = 0; (i < ParentCount) && SubPackageOp; i++)
    580       1.1  christos     {
    581       1.1  christos         /* Each object in the list must be of type Package */
    582       1.1  christos 
    583       1.1  christos         Status = ApCheckObjectType (PredefinedName, SubPackageOp,
    584       1.1  christos             ACPI_RTYPE_PACKAGE, i + StartIndex);
    585       1.1  christos         if (ACPI_FAILURE (Status))
    586       1.1  christos         {
    587       1.1  christos             goto NextSubpackage;
    588       1.1  christos         }
    589       1.1  christos 
    590       1.1  christos         /* Examine the different types of expected subpackages */
    591       1.1  christos 
    592       1.1  christos         Op = SubPackageOp->Asl.Child;
    593       1.1  christos 
    594       1.1  christos         /* First child is the package length */
    595       1.1  christos 
    596       1.1  christos         Count = (UINT32) Op->Asl.Value.Integer;
    597       1.1  christos         Op = Op->Asl.Next;
    598       1.1  christos 
    599       1.5  christos         /*
    600       1.5  christos          * Most subpackage must have at least one element, with
    601       1.5  christos          * only rare exceptions. (_RDI)
    602       1.5  christos          */
    603       1.5  christos         if (!Count &&
    604       1.5  christos             (Package->RetInfo.Type != ACPI_PTYPE2_VAR_VAR))
    605       1.1  christos         {
    606       1.1  christos             ApZeroLengthPackage (PredefinedName, SubPackageOp);
    607       1.1  christos             goto NextSubpackage;
    608       1.1  christos         }
    609       1.1  christos 
    610       1.1  christos         /*
    611       1.1  christos          * Decode the package type.
    612       1.1  christos          * PTYPE2 indicates that a "package of packages" is expected for
    613       1.1  christos          * this name. The various flavors of PTYPE2 indicate the number
    614       1.1  christos          * and format of the subpackages.
    615       1.1  christos          */
    616       1.1  christos         switch (Package->RetInfo.Type)
    617       1.1  christos         {
    618       1.1  christos         case ACPI_PTYPE2:
    619       1.1  christos         case ACPI_PTYPE2_PKG_COUNT:
    620       1.1  christos         case ACPI_PTYPE2_REV_FIXED:
    621       1.1  christos 
    622       1.1  christos             /* Each subpackage has a fixed number of elements */
    623       1.1  christos 
    624       1.1  christos             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    625       1.1  christos             if (Count < ExpectedCount)
    626       1.1  christos             {
    627       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    628       1.1  christos                     Count, ExpectedCount);
    629       1.1  christos                 break;
    630       1.1  christos             }
    631       1.3  christos             if (Count > ExpectedCount)
    632       1.3  christos             {
    633       1.3  christos                 ApPackageTooLarge (PredefinedName, SubPackageOp,
    634       1.3  christos                     Count, ExpectedCount);
    635       1.3  christos                 break;
    636       1.3  christos             }
    637       1.1  christos 
    638       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    639       1.1  christos                 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
    640       1.1  christos                 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
    641       1.1  christos             break;
    642       1.1  christos 
    643       1.1  christos         case ACPI_PTYPE2_FIX_VAR:
    644       1.1  christos             /*
    645       1.1  christos              * Each subpackage has a fixed number of elements and an
    646       1.1  christos              * optional element
    647       1.1  christos              */
    648       1.1  christos             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    649       1.1  christos             if (Count < ExpectedCount)
    650       1.1  christos             {
    651       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    652       1.1  christos                     Count, ExpectedCount);
    653       1.1  christos                 break;
    654       1.1  christos             }
    655       1.1  christos 
    656       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    657       1.1  christos                 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
    658       1.1  christos                 Package->RetInfo.ObjectType2,
    659       1.1  christos                 Count - Package->RetInfo.Count1);
    660       1.1  christos             break;
    661       1.1  christos 
    662       1.5  christos         case ACPI_PTYPE2_VAR_VAR:
    663       1.5  christos             /*
    664       1.5  christos              * Must have at least the minimum number elements.
    665       1.5  christos              * A zero PkgCount means the number of elements is variable.
    666       1.5  christos              */
    667       1.5  christos             ExpectedCount = Package->RetInfo4.PkgCount;
    668       1.5  christos             if (ExpectedCount && (Count < ExpectedCount))
    669       1.5  christos             {
    670       1.5  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    671       1.5  christos                     Count, 1);
    672       1.5  christos                 break;
    673       1.5  christos             }
    674       1.5  christos 
    675       1.5  christos             ApCheckPackageElements (PredefinedName, Op,
    676       1.5  christos                 Package->RetInfo4.SubObjectTypes,
    677       1.5  christos                 Package->RetInfo4.PkgCount,
    678       1.5  christos                 0, 0);
    679       1.5  christos             break;
    680       1.5  christos 
    681       1.1  christos         case ACPI_PTYPE2_FIXED:
    682       1.1  christos 
    683       1.3  christos             /* Each subpackage has a fixed length */
    684       1.1  christos 
    685       1.1  christos             ExpectedCount = Package->RetInfo2.Count;
    686       1.1  christos             if (Count < ExpectedCount)
    687       1.1  christos             {
    688       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    689       1.1  christos                     Count, ExpectedCount);
    690       1.1  christos                 break;
    691       1.1  christos             }
    692       1.3  christos             if (Count > ExpectedCount)
    693       1.3  christos             {
    694       1.3  christos                 ApPackageTooLarge (PredefinedName, SubPackageOp,
    695       1.3  christos                     Count, ExpectedCount);
    696       1.3  christos                 break;
    697       1.3  christos             }
    698       1.1  christos 
    699       1.1  christos             /* Check each object/type combination */
    700       1.1  christos 
    701       1.1  christos             for (j = 0; j < ExpectedCount; j++)
    702       1.1  christos             {
    703       1.1  christos                 ApCheckObjectType (PredefinedName, Op,
    704       1.1  christos                     Package->RetInfo2.ObjectType[j], j);
    705       1.1  christos 
    706       1.1  christos                 Op = Op->Asl.Next;
    707       1.1  christos             }
    708       1.1  christos             break;
    709       1.1  christos 
    710       1.1  christos         case ACPI_PTYPE2_MIN:
    711       1.1  christos 
    712       1.3  christos             /* Each subpackage has a variable but minimum length */
    713       1.1  christos 
    714       1.1  christos             ExpectedCount = Package->RetInfo.Count1;
    715       1.1  christos             if (Count < ExpectedCount)
    716       1.1  christos             {
    717       1.1  christos                 ApPackageTooSmall (PredefinedName, SubPackageOp,
    718       1.1  christos                     Count, ExpectedCount);
    719       1.1  christos                 break;
    720       1.1  christos             }
    721       1.1  christos 
    722       1.3  christos             /* Check the type of each subpackage element */
    723       1.1  christos 
    724       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    725       1.1  christos                 Package->RetInfo.ObjectType1, Count, 0, 0);
    726       1.1  christos             break;
    727       1.1  christos 
    728       1.1  christos         case ACPI_PTYPE2_COUNT:
    729       1.1  christos             /*
    730       1.1  christos              * First element is the (Integer) count of elements, including
    731       1.1  christos              * the count field (the ACPI name is NumElements)
    732       1.1  christos              */
    733       1.1  christos             Status = ApCheckObjectType (PredefinedName, Op,
    734       1.1  christos                 ACPI_RTYPE_INTEGER, 0);
    735       1.1  christos 
    736       1.1  christos             /* We must have an integer count from above (otherwise, use Count) */
    737       1.1  christos 
    738       1.1  christos             if (ACPI_SUCCESS (Status))
    739       1.1  christos             {
    740       1.1  christos                 /*
    741       1.1  christos                  * Make sure package is large enough for the Count and is
    742       1.1  christos                  * is as large as the minimum size
    743       1.1  christos                  */
    744       1.1  christos                 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
    745       1.1  christos 
    746       1.1  christos                 if (Count < ExpectedCount)
    747       1.1  christos                 {
    748       1.1  christos                     ApPackageTooSmall (PredefinedName, SubPackageOp,
    749       1.1  christos                         Count, ExpectedCount);
    750       1.1  christos                     break;
    751       1.1  christos                 }
    752       1.1  christos                 else if (Count > ExpectedCount)
    753       1.1  christos                 {
    754       1.1  christos                     ApPackageTooLarge (PredefinedName, SubPackageOp,
    755       1.1  christos                         Count, ExpectedCount);
    756       1.1  christos                 }
    757       1.1  christos 
    758       1.1  christos                 /* Some names of this type have a minimum length */
    759       1.1  christos 
    760       1.1  christos                 if (Count < Package->RetInfo.Count1)
    761       1.1  christos                 {
    762       1.1  christos                     ExpectedCount = Package->RetInfo.Count1;
    763       1.1  christos                     ApPackageTooSmall (PredefinedName, SubPackageOp,
    764       1.1  christos                         Count, ExpectedCount);
    765       1.1  christos                     break;
    766       1.1  christos                 }
    767       1.1  christos 
    768       1.1  christos                 Count = ExpectedCount;
    769       1.1  christos             }
    770       1.1  christos 
    771       1.3  christos             /* Check the type of each subpackage element */
    772       1.1  christos 
    773       1.1  christos             Op = Op->Asl.Next;
    774       1.1  christos             ApCheckPackageElements (PredefinedName, Op,
    775       1.1  christos                 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
    776       1.1  christos             break;
    777       1.1  christos 
    778       1.1  christos         default:
    779       1.1  christos             break;
    780       1.1  christos         }
    781       1.1  christos 
    782       1.1  christos NextSubpackage:
    783       1.1  christos         SubPackageOp = SubPackageOp->Asl.Next;
    784       1.1  christos     }
    785       1.1  christos }
    786       1.1  christos 
    787       1.1  christos 
    788       1.1  christos /*******************************************************************************
    789       1.1  christos  *
    790       1.1  christos  * FUNCTION:    ApPackageTooSmall
    791       1.1  christos  *
    792       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    793       1.1  christos  *              Op                  - Current parser op
    794       1.1  christos  *              Count               - Actual package element count
    795       1.1  christos  *              ExpectedCount       - Expected package element count
    796       1.1  christos  *
    797       1.1  christos  * RETURN:      None
    798       1.1  christos  *
    799       1.1  christos  * DESCRIPTION: Issue error message for a package that is smaller than
    800       1.1  christos  *              required.
    801       1.1  christos  *
    802       1.1  christos  ******************************************************************************/
    803       1.1  christos 
    804       1.1  christos static void
    805       1.1  christos ApPackageTooSmall (
    806       1.1  christos     const char                  *PredefinedName,
    807       1.1  christos     ACPI_PARSE_OBJECT           *Op,
    808       1.1  christos     UINT32                      Count,
    809       1.1  christos     UINT32                      ExpectedCount)
    810       1.1  christos {
    811       1.1  christos 
    812       1.2  christos     snprintf (MsgBuffer, sizeof(MsgBuffer), "%s: length %u, required minimum is %u",
    813       1.1  christos         PredefinedName, Count, ExpectedCount);
    814       1.1  christos 
    815       1.1  christos     AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
    816       1.1  christos }
    817       1.1  christos 
    818       1.1  christos 
    819       1.1  christos /*******************************************************************************
    820       1.1  christos  *
    821       1.1  christos  * FUNCTION:    ApZeroLengthPackage
    822       1.1  christos  *
    823       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    824       1.1  christos  *              Op                  - Current parser op
    825       1.1  christos  *
    826       1.1  christos  * RETURN:      None
    827       1.1  christos  *
    828       1.1  christos  * DESCRIPTION: Issue error message for a zero-length package (a package that
    829       1.1  christos  *              is required to have a non-zero length). Variable length
    830       1.1  christos  *              packages seem to be allowed to have zero length, however.
    831       1.1  christos  *              Even if not allowed, BIOS code does it.
    832       1.1  christos  *
    833       1.1  christos  ******************************************************************************/
    834       1.1  christos 
    835       1.1  christos static void
    836       1.1  christos ApZeroLengthPackage (
    837       1.1  christos     const char                  *PredefinedName,
    838       1.1  christos     ACPI_PARSE_OBJECT           *Op)
    839       1.1  christos {
    840       1.1  christos 
    841       1.2  christos     snprintf (MsgBuffer, sizeof(MsgBuffer), "%s: length is zero", PredefinedName);
    842       1.1  christos 
    843       1.1  christos     AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
    844       1.1  christos }
    845       1.1  christos 
    846       1.1  christos 
    847       1.1  christos /*******************************************************************************
    848       1.1  christos  *
    849       1.1  christos  * FUNCTION:    ApPackageTooLarge
    850       1.1  christos  *
    851       1.1  christos  * PARAMETERS:  PredefinedName      - Name of the predefined object
    852       1.1  christos  *              Op                  - Current parser op
    853       1.1  christos  *              Count               - Actual package element count
    854       1.1  christos  *              ExpectedCount       - Expected package element count
    855       1.1  christos  *
    856       1.1  christos  * RETURN:      None
    857       1.1  christos  *
    858       1.1  christos  * DESCRIPTION: Issue a remark for a package that is larger than expected.
    859       1.1  christos  *
    860       1.1  christos  ******************************************************************************/
    861       1.1  christos 
    862       1.1  christos static void
    863       1.1  christos ApPackageTooLarge (
    864       1.1  christos     const char                  *PredefinedName,
    865       1.1  christos     ACPI_PARSE_OBJECT           *Op,
    866       1.1  christos     UINT32                      Count,
    867       1.1  christos     UINT32                      ExpectedCount)
    868       1.1  christos {
    869       1.1  christos 
    870       1.2  christos     snprintf (MsgBuffer, sizeof(MsgBuffer), "%s: length is %u, only %u required",
    871       1.1  christos         PredefinedName, Count, ExpectedCount);
    872       1.1  christos 
    873       1.1  christos     AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
    874       1.1  christos }
    875