Home | History | Annotate | Line # | Download | only in namespace
nsprepkg.c revision 1.1.1.5
      1      1.1  christos /******************************************************************************
      2      1.1  christos  *
      3      1.1  christos  * Module Name: nsprepkg - Validation of package objects for predefined names
      4      1.1  christos  *
      5      1.1  christos  *****************************************************************************/
      6      1.1  christos 
      7      1.1  christos /*
      8  1.1.1.5  christos  * Copyright (C) 2000 - 2016, 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 "acpi.h"
     45      1.1  christos #include "accommon.h"
     46      1.1  christos #include "acnamesp.h"
     47      1.1  christos #include "acpredef.h"
     48      1.1  christos 
     49      1.1  christos 
     50      1.1  christos #define _COMPONENT          ACPI_NAMESPACE
     51      1.1  christos         ACPI_MODULE_NAME    ("nsprepkg")
     52      1.1  christos 
     53      1.1  christos 
     54      1.1  christos /* Local prototypes */
     55      1.1  christos 
     56      1.1  christos static ACPI_STATUS
     57      1.1  christos AcpiNsCheckPackageList (
     58      1.1  christos     ACPI_EVALUATE_INFO          *Info,
     59      1.1  christos     const ACPI_PREDEFINED_INFO  *Package,
     60      1.1  christos     ACPI_OPERAND_OBJECT         **Elements,
     61      1.1  christos     UINT32                      Count);
     62      1.1  christos 
     63      1.1  christos static ACPI_STATUS
     64      1.1  christos AcpiNsCheckPackageElements (
     65      1.1  christos     ACPI_EVALUATE_INFO          *Info,
     66      1.1  christos     ACPI_OPERAND_OBJECT         **Elements,
     67      1.1  christos     UINT8                       Type1,
     68      1.1  christos     UINT32                      Count1,
     69      1.1  christos     UINT8                       Type2,
     70      1.1  christos     UINT32                      Count2,
     71      1.1  christos     UINT32                      StartIndex);
     72      1.1  christos 
     73      1.1  christos 
     74      1.1  christos /*******************************************************************************
     75      1.1  christos  *
     76      1.1  christos  * FUNCTION:    AcpiNsCheckPackage
     77      1.1  christos  *
     78      1.1  christos  * PARAMETERS:  Info                - Method execution information block
     79      1.1  christos  *              ReturnObjectPtr     - Pointer to the object returned from the
     80      1.1  christos  *                                    evaluation of a method or object
     81      1.1  christos  *
     82      1.1  christos  * RETURN:      Status
     83      1.1  christos  *
     84      1.1  christos  * DESCRIPTION: Check a returned package object for the correct count and
     85      1.1  christos  *              correct type of all sub-objects.
     86      1.1  christos  *
     87      1.1  christos  ******************************************************************************/
     88      1.1  christos 
     89      1.1  christos ACPI_STATUS
     90      1.1  christos AcpiNsCheckPackage (
     91      1.1  christos     ACPI_EVALUATE_INFO          *Info,
     92      1.1  christos     ACPI_OPERAND_OBJECT         **ReturnObjectPtr)
     93      1.1  christos {
     94      1.1  christos     ACPI_OPERAND_OBJECT         *ReturnObject = *ReturnObjectPtr;
     95      1.1  christos     const ACPI_PREDEFINED_INFO  *Package;
     96      1.1  christos     ACPI_OPERAND_OBJECT         **Elements;
     97      1.1  christos     ACPI_STATUS                 Status = AE_OK;
     98      1.1  christos     UINT32                      ExpectedCount;
     99      1.1  christos     UINT32                      Count;
    100      1.1  christos     UINT32                      i;
    101      1.1  christos 
    102      1.1  christos 
    103      1.1  christos     ACPI_FUNCTION_NAME (NsCheckPackage);
    104      1.1  christos 
    105      1.1  christos 
    106      1.1  christos     /* The package info for this name is in the next table entry */
    107      1.1  christos 
    108      1.1  christos     Package = Info->Predefined + 1;
    109      1.1  christos 
    110      1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
    111      1.1  christos         "%s Validating return Package of Type %X, Count %X\n",
    112      1.1  christos         Info->FullPathname, Package->RetInfo.Type,
    113      1.1  christos         ReturnObject->Package.Count));
    114      1.1  christos 
    115      1.1  christos     /*
    116      1.1  christos      * For variable-length Packages, we can safely remove all embedded
    117      1.1  christos      * and trailing NULL package elements
    118      1.1  christos      */
    119      1.1  christos     AcpiNsRemoveNullElements (Info, Package->RetInfo.Type, ReturnObject);
    120      1.1  christos 
    121      1.1  christos     /* Extract package count and elements array */
    122      1.1  christos 
    123      1.1  christos     Elements = ReturnObject->Package.Elements;
    124      1.1  christos     Count = ReturnObject->Package.Count;
    125      1.1  christos 
    126      1.1  christos     /*
    127      1.1  christos      * Most packages must have at least one element. The only exception
    128      1.1  christos      * is the variable-length package (ACPI_PTYPE1_VAR).
    129      1.1  christos      */
    130      1.1  christos     if (!Count)
    131      1.1  christos     {
    132      1.1  christos         if (Package->RetInfo.Type == ACPI_PTYPE1_VAR)
    133      1.1  christos         {
    134      1.1  christos             return (AE_OK);
    135      1.1  christos         }
    136      1.1  christos 
    137      1.1  christos         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
    138      1.1  christos             "Return Package has no elements (empty)"));
    139      1.1  christos 
    140      1.1  christos         return (AE_AML_OPERAND_VALUE);
    141      1.1  christos     }
    142      1.1  christos 
    143      1.1  christos     /*
    144      1.1  christos      * Decode the type of the expected package contents
    145      1.1  christos      *
    146      1.1  christos      * PTYPE1 packages contain no subpackages
    147  1.1.1.2  christos      * PTYPE2 packages contain subpackages
    148      1.1  christos      */
    149      1.1  christos     switch (Package->RetInfo.Type)
    150      1.1  christos     {
    151      1.1  christos     case ACPI_PTYPE1_FIXED:
    152      1.1  christos         /*
    153  1.1.1.2  christos          * The package count is fixed and there are no subpackages
    154      1.1  christos          *
    155      1.1  christos          * If package is too small, exit.
    156      1.1  christos          * If package is larger than expected, issue warning but continue
    157      1.1  christos          */
    158      1.1  christos         ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    159      1.1  christos         if (Count < ExpectedCount)
    160      1.1  christos         {
    161      1.1  christos             goto PackageTooSmall;
    162      1.1  christos         }
    163      1.1  christos         else if (Count > ExpectedCount)
    164      1.1  christos         {
    165      1.1  christos             ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    166      1.1  christos                 "%s: Return Package is larger than needed - "
    167      1.1  christos                 "found %u, expected %u\n",
    168      1.1  christos                 Info->FullPathname, Count, ExpectedCount));
    169      1.1  christos         }
    170      1.1  christos 
    171      1.1  christos         /* Validate all elements of the returned package */
    172      1.1  christos 
    173      1.1  christos         Status = AcpiNsCheckPackageElements (Info, Elements,
    174  1.1.1.5  christos             Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
    175  1.1.1.5  christos             Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
    176      1.1  christos         break;
    177      1.1  christos 
    178      1.1  christos     case ACPI_PTYPE1_VAR:
    179      1.1  christos         /*
    180  1.1.1.2  christos          * The package count is variable, there are no subpackages, and all
    181      1.1  christos          * elements must be of the same type
    182      1.1  christos          */
    183      1.1  christos         for (i = 0; i < Count; i++)
    184      1.1  christos         {
    185      1.1  christos             Status = AcpiNsCheckObjectType (Info, Elements,
    186  1.1.1.5  christos                 Package->RetInfo.ObjectType1, i);
    187      1.1  christos             if (ACPI_FAILURE (Status))
    188      1.1  christos             {
    189      1.1  christos                 return (Status);
    190      1.1  christos             }
    191      1.1  christos             Elements++;
    192      1.1  christos         }
    193      1.1  christos         break;
    194      1.1  christos 
    195      1.1  christos     case ACPI_PTYPE1_OPTION:
    196      1.1  christos         /*
    197  1.1.1.2  christos          * The package count is variable, there are no subpackages. There are
    198      1.1  christos          * a fixed number of required elements, and a variable number of
    199      1.1  christos          * optional elements.
    200      1.1  christos          *
    201      1.1  christos          * Check if package is at least as large as the minimum required
    202      1.1  christos          */
    203      1.1  christos         ExpectedCount = Package->RetInfo3.Count;
    204      1.1  christos         if (Count < ExpectedCount)
    205      1.1  christos         {
    206      1.1  christos             goto PackageTooSmall;
    207      1.1  christos         }
    208      1.1  christos 
    209      1.1  christos         /* Variable number of sub-objects */
    210      1.1  christos 
    211      1.1  christos         for (i = 0; i < Count; i++)
    212      1.1  christos         {
    213      1.1  christos             if (i < Package->RetInfo3.Count)
    214      1.1  christos             {
    215      1.1  christos                 /* These are the required package elements (0, 1, or 2) */
    216      1.1  christos 
    217      1.1  christos                 Status = AcpiNsCheckObjectType (Info, Elements,
    218  1.1.1.5  christos                     Package->RetInfo3.ObjectType[i], i);
    219      1.1  christos                 if (ACPI_FAILURE (Status))
    220      1.1  christos                 {
    221      1.1  christos                     return (Status);
    222      1.1  christos                 }
    223      1.1  christos             }
    224      1.1  christos             else
    225      1.1  christos             {
    226      1.1  christos                 /* These are the optional package elements */
    227      1.1  christos 
    228      1.1  christos                 Status = AcpiNsCheckObjectType (Info, Elements,
    229  1.1.1.5  christos                     Package->RetInfo3.TailObjectType, i);
    230      1.1  christos                 if (ACPI_FAILURE (Status))
    231      1.1  christos                 {
    232      1.1  christos                     return (Status);
    233      1.1  christos                 }
    234      1.1  christos             }
    235      1.1  christos             Elements++;
    236      1.1  christos         }
    237      1.1  christos         break;
    238      1.1  christos 
    239      1.1  christos     case ACPI_PTYPE2_REV_FIXED:
    240      1.1  christos 
    241      1.1  christos         /* First element is the (Integer) revision */
    242      1.1  christos 
    243  1.1.1.5  christos         Status = AcpiNsCheckObjectType (
    244  1.1.1.5  christos             Info, Elements, ACPI_RTYPE_INTEGER, 0);
    245      1.1  christos         if (ACPI_FAILURE (Status))
    246      1.1  christos         {
    247      1.1  christos             return (Status);
    248      1.1  christos         }
    249      1.1  christos 
    250      1.1  christos         Elements++;
    251      1.1  christos         Count--;
    252      1.1  christos 
    253  1.1.1.2  christos         /* Examine the subpackages */
    254      1.1  christos 
    255      1.1  christos         Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
    256      1.1  christos         break;
    257      1.1  christos 
    258      1.1  christos     case ACPI_PTYPE2_PKG_COUNT:
    259      1.1  christos 
    260  1.1.1.2  christos         /* First element is the (Integer) count of subpackages to follow */
    261      1.1  christos 
    262  1.1.1.5  christos         Status = AcpiNsCheckObjectType (
    263  1.1.1.5  christos             Info, Elements, ACPI_RTYPE_INTEGER, 0);
    264      1.1  christos         if (ACPI_FAILURE (Status))
    265      1.1  christos         {
    266      1.1  christos             return (Status);
    267      1.1  christos         }
    268      1.1  christos 
    269      1.1  christos         /*
    270      1.1  christos          * Count cannot be larger than the parent package length, but allow it
    271      1.1  christos          * to be smaller. The >= accounts for the Integer above.
    272      1.1  christos          */
    273      1.1  christos         ExpectedCount = (UINT32) (*Elements)->Integer.Value;
    274      1.1  christos         if (ExpectedCount >= Count)
    275      1.1  christos         {
    276      1.1  christos             goto PackageTooSmall;
    277      1.1  christos         }
    278      1.1  christos 
    279      1.1  christos         Count = ExpectedCount;
    280      1.1  christos         Elements++;
    281      1.1  christos 
    282  1.1.1.2  christos         /* Examine the subpackages */
    283      1.1  christos 
    284      1.1  christos         Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
    285      1.1  christos         break;
    286      1.1  christos 
    287      1.1  christos     case ACPI_PTYPE2:
    288      1.1  christos     case ACPI_PTYPE2_FIXED:
    289      1.1  christos     case ACPI_PTYPE2_MIN:
    290      1.1  christos     case ACPI_PTYPE2_COUNT:
    291      1.1  christos     case ACPI_PTYPE2_FIX_VAR:
    292      1.1  christos         /*
    293      1.1  christos          * These types all return a single Package that consists of a
    294  1.1.1.2  christos          * variable number of subpackages.
    295      1.1  christos          *
    296  1.1.1.2  christos          * First, ensure that the first element is a subpackage. If not,
    297      1.1  christos          * the BIOS may have incorrectly returned the object as a single
    298      1.1  christos          * package instead of a Package of Packages (a common error if
    299      1.1  christos          * there is only one entry). We may be able to repair this by
    300      1.1  christos          * wrapping the returned Package with a new outer Package.
    301      1.1  christos          */
    302      1.1  christos         if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
    303      1.1  christos         {
    304      1.1  christos             /* Create the new outer package and populate it */
    305      1.1  christos 
    306  1.1.1.5  christos             Status = AcpiNsWrapWithPackage (
    307  1.1.1.5  christos                 Info, ReturnObject, ReturnObjectPtr);
    308      1.1  christos             if (ACPI_FAILURE (Status))
    309      1.1  christos             {
    310      1.1  christos                 return (Status);
    311      1.1  christos             }
    312      1.1  christos 
    313      1.1  christos             /* Update locals to point to the new package (of 1 element) */
    314      1.1  christos 
    315      1.1  christos             ReturnObject = *ReturnObjectPtr;
    316      1.1  christos             Elements = ReturnObject->Package.Elements;
    317      1.1  christos             Count = 1;
    318      1.1  christos         }
    319      1.1  christos 
    320  1.1.1.2  christos         /* Examine the subpackages */
    321      1.1  christos 
    322      1.1  christos         Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
    323      1.1  christos         break;
    324      1.1  christos 
    325  1.1.1.4  christos     case ACPI_PTYPE2_VAR_VAR:
    326  1.1.1.4  christos         /*
    327  1.1.1.4  christos          * Returns a variable list of packages, each with a variable list
    328  1.1.1.4  christos          * of objects.
    329  1.1.1.4  christos          */
    330  1.1.1.4  christos         break;
    331  1.1.1.4  christos 
    332  1.1.1.2  christos     case ACPI_PTYPE2_UUID_PAIR:
    333  1.1.1.2  christos 
    334  1.1.1.2  christos         /* The package must contain pairs of (UUID + type) */
    335  1.1.1.2  christos 
    336  1.1.1.2  christos         if (Count & 1)
    337  1.1.1.2  christos         {
    338  1.1.1.2  christos             ExpectedCount = Count + 1;
    339  1.1.1.2  christos             goto PackageTooSmall;
    340  1.1.1.2  christos         }
    341  1.1.1.2  christos 
    342  1.1.1.2  christos         while (Count > 0)
    343  1.1.1.2  christos         {
    344  1.1.1.2  christos             Status = AcpiNsCheckObjectType(Info, Elements,
    345  1.1.1.2  christos                         Package->RetInfo.ObjectType1, 0);
    346  1.1.1.2  christos             if (ACPI_FAILURE(Status))
    347  1.1.1.2  christos             {
    348  1.1.1.2  christos                 return (Status);
    349  1.1.1.2  christos             }
    350  1.1.1.2  christos 
    351  1.1.1.2  christos             /* Validate length of the UUID buffer */
    352  1.1.1.2  christos 
    353  1.1.1.2  christos             if ((*Elements)->Buffer.Length != 16)
    354  1.1.1.2  christos             {
    355  1.1.1.2  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    356  1.1.1.2  christos                     Info->NodeFlags, "Invalid length for UUID Buffer"));
    357  1.1.1.2  christos                 return (AE_AML_OPERAND_VALUE);
    358  1.1.1.2  christos             }
    359  1.1.1.2  christos 
    360  1.1.1.2  christos             Status = AcpiNsCheckObjectType(Info, Elements + 1,
    361  1.1.1.2  christos                         Package->RetInfo.ObjectType2, 0);
    362  1.1.1.2  christos             if (ACPI_FAILURE(Status))
    363  1.1.1.2  christos             {
    364  1.1.1.2  christos                 return (Status);
    365  1.1.1.2  christos             }
    366  1.1.1.2  christos 
    367  1.1.1.2  christos             Elements += 2;
    368  1.1.1.2  christos             Count -= 2;
    369  1.1.1.2  christos          }
    370  1.1.1.2  christos          break;
    371  1.1.1.2  christos 
    372      1.1  christos     default:
    373      1.1  christos 
    374      1.1  christos         /* Should not get here if predefined info table is correct */
    375      1.1  christos 
    376      1.1  christos         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
    377      1.1  christos             "Invalid internal return type in table entry: %X",
    378      1.1  christos             Package->RetInfo.Type));
    379      1.1  christos 
    380      1.1  christos         return (AE_AML_INTERNAL);
    381      1.1  christos     }
    382      1.1  christos 
    383      1.1  christos     return (Status);
    384      1.1  christos 
    385      1.1  christos 
    386      1.1  christos PackageTooSmall:
    387      1.1  christos 
    388      1.1  christos     /* Error exit for the case with an incorrect package count */
    389      1.1  christos 
    390      1.1  christos     ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
    391      1.1  christos         "Return Package is too small - found %u elements, expected %u",
    392      1.1  christos         Count, ExpectedCount));
    393      1.1  christos 
    394      1.1  christos     return (AE_AML_OPERAND_VALUE);
    395      1.1  christos }
    396      1.1  christos 
    397      1.1  christos 
    398      1.1  christos /*******************************************************************************
    399      1.1  christos  *
    400      1.1  christos  * FUNCTION:    AcpiNsCheckPackageList
    401      1.1  christos  *
    402      1.1  christos  * PARAMETERS:  Info            - Method execution information block
    403      1.1  christos  *              Package         - Pointer to package-specific info for method
    404      1.1  christos  *              Elements        - Element list of parent package. All elements
    405      1.1  christos  *                                of this list should be of type Package.
    406      1.1  christos  *              Count           - Count of subpackages
    407      1.1  christos  *
    408      1.1  christos  * RETURN:      Status
    409      1.1  christos  *
    410      1.1  christos  * DESCRIPTION: Examine a list of subpackages
    411      1.1  christos  *
    412      1.1  christos  ******************************************************************************/
    413      1.1  christos 
    414      1.1  christos static ACPI_STATUS
    415      1.1  christos AcpiNsCheckPackageList (
    416      1.1  christos     ACPI_EVALUATE_INFO          *Info,
    417      1.1  christos     const ACPI_PREDEFINED_INFO  *Package,
    418      1.1  christos     ACPI_OPERAND_OBJECT         **Elements,
    419      1.1  christos     UINT32                      Count)
    420      1.1  christos {
    421      1.1  christos     ACPI_OPERAND_OBJECT         *SubPackage;
    422      1.1  christos     ACPI_OPERAND_OBJECT         **SubElements;
    423      1.1  christos     ACPI_STATUS                 Status;
    424      1.1  christos     UINT32                      ExpectedCount;
    425      1.1  christos     UINT32                      i;
    426      1.1  christos     UINT32                      j;
    427      1.1  christos 
    428      1.1  christos 
    429      1.1  christos     /*
    430  1.1.1.2  christos      * Validate each subpackage in the parent Package
    431      1.1  christos      *
    432  1.1.1.2  christos      * NOTE: assumes list of subpackages contains no NULL elements.
    433      1.1  christos      * Any NULL elements should have been removed by earlier call
    434      1.1  christos      * to AcpiNsRemoveNullElements.
    435      1.1  christos      */
    436      1.1  christos     for (i = 0; i < Count; i++)
    437      1.1  christos     {
    438      1.1  christos         SubPackage = *Elements;
    439      1.1  christos         SubElements = SubPackage->Package.Elements;
    440      1.1  christos         Info->ParentPackage = SubPackage;
    441      1.1  christos 
    442      1.1  christos         /* Each sub-object must be of type Package */
    443      1.1  christos 
    444      1.1  christos         Status = AcpiNsCheckObjectType (Info, &SubPackage,
    445      1.1  christos                     ACPI_RTYPE_PACKAGE, i);
    446      1.1  christos         if (ACPI_FAILURE (Status))
    447      1.1  christos         {
    448      1.1  christos             return (Status);
    449      1.1  christos         }
    450      1.1  christos 
    451  1.1.1.2  christos         /* Examine the different types of expected subpackages */
    452      1.1  christos 
    453      1.1  christos         Info->ParentPackage = SubPackage;
    454      1.1  christos         switch (Package->RetInfo.Type)
    455      1.1  christos         {
    456      1.1  christos         case ACPI_PTYPE2:
    457      1.1  christos         case ACPI_PTYPE2_PKG_COUNT:
    458      1.1  christos         case ACPI_PTYPE2_REV_FIXED:
    459      1.1  christos 
    460      1.1  christos             /* Each subpackage has a fixed number of elements */
    461      1.1  christos 
    462      1.1  christos             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    463      1.1  christos             if (SubPackage->Package.Count < ExpectedCount)
    464      1.1  christos             {
    465      1.1  christos                 goto PackageTooSmall;
    466      1.1  christos             }
    467      1.1  christos 
    468      1.1  christos             Status = AcpiNsCheckPackageElements (Info, SubElements,
    469      1.1  christos                         Package->RetInfo.ObjectType1,
    470      1.1  christos                         Package->RetInfo.Count1,
    471      1.1  christos                         Package->RetInfo.ObjectType2,
    472      1.1  christos                         Package->RetInfo.Count2, 0);
    473      1.1  christos             if (ACPI_FAILURE (Status))
    474      1.1  christos             {
    475      1.1  christos                 return (Status);
    476      1.1  christos             }
    477      1.1  christos             break;
    478      1.1  christos 
    479      1.1  christos         case ACPI_PTYPE2_FIX_VAR:
    480      1.1  christos             /*
    481      1.1  christos              * Each subpackage has a fixed number of elements and an
    482      1.1  christos              * optional element
    483      1.1  christos              */
    484      1.1  christos             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
    485      1.1  christos             if (SubPackage->Package.Count < ExpectedCount)
    486      1.1  christos             {
    487      1.1  christos                 goto PackageTooSmall;
    488      1.1  christos             }
    489      1.1  christos 
    490      1.1  christos             Status = AcpiNsCheckPackageElements (Info, SubElements,
    491      1.1  christos                         Package->RetInfo.ObjectType1,
    492      1.1  christos                         Package->RetInfo.Count1,
    493      1.1  christos                         Package->RetInfo.ObjectType2,
    494      1.1  christos                         SubPackage->Package.Count - Package->RetInfo.Count1, 0);
    495      1.1  christos             if (ACPI_FAILURE (Status))
    496      1.1  christos             {
    497      1.1  christos                 return (Status);
    498      1.1  christos             }
    499      1.1  christos             break;
    500      1.1  christos 
    501  1.1.1.4  christos         case ACPI_PTYPE2_VAR_VAR:
    502  1.1.1.4  christos             /*
    503  1.1.1.4  christos              * Each subpackage has a fixed or variable number of elements
    504  1.1.1.4  christos              */
    505  1.1.1.4  christos             break;
    506  1.1.1.4  christos 
    507      1.1  christos         case ACPI_PTYPE2_FIXED:
    508      1.1  christos 
    509  1.1.1.2  christos             /* Each subpackage has a fixed length */
    510      1.1  christos 
    511      1.1  christos             ExpectedCount = Package->RetInfo2.Count;
    512      1.1  christos             if (SubPackage->Package.Count < ExpectedCount)
    513      1.1  christos             {
    514      1.1  christos                 goto PackageTooSmall;
    515      1.1  christos             }
    516      1.1  christos 
    517  1.1.1.2  christos             /* Check the type of each subpackage element */
    518      1.1  christos 
    519      1.1  christos             for (j = 0; j < ExpectedCount; j++)
    520      1.1  christos             {
    521      1.1  christos                 Status = AcpiNsCheckObjectType (Info, &SubElements[j],
    522      1.1  christos                             Package->RetInfo2.ObjectType[j], j);
    523      1.1  christos                 if (ACPI_FAILURE (Status))
    524      1.1  christos                 {
    525      1.1  christos                     return (Status);
    526      1.1  christos                 }
    527      1.1  christos             }
    528      1.1  christos             break;
    529      1.1  christos 
    530      1.1  christos         case ACPI_PTYPE2_MIN:
    531      1.1  christos 
    532  1.1.1.2  christos             /* Each subpackage has a variable but minimum length */
    533      1.1  christos 
    534      1.1  christos             ExpectedCount = Package->RetInfo.Count1;
    535      1.1  christos             if (SubPackage->Package.Count < ExpectedCount)
    536      1.1  christos             {
    537      1.1  christos                 goto PackageTooSmall;
    538      1.1  christos             }
    539      1.1  christos 
    540  1.1.1.2  christos             /* Check the type of each subpackage element */
    541      1.1  christos 
    542      1.1  christos             Status = AcpiNsCheckPackageElements (Info, SubElements,
    543      1.1  christos                         Package->RetInfo.ObjectType1,
    544      1.1  christos                         SubPackage->Package.Count, 0, 0, 0);
    545      1.1  christos             if (ACPI_FAILURE (Status))
    546      1.1  christos             {
    547      1.1  christos                 return (Status);
    548      1.1  christos             }
    549      1.1  christos             break;
    550      1.1  christos 
    551      1.1  christos         case ACPI_PTYPE2_COUNT:
    552      1.1  christos             /*
    553      1.1  christos              * First element is the (Integer) count of elements, including
    554      1.1  christos              * the count field (the ACPI name is NumElements)
    555      1.1  christos              */
    556      1.1  christos             Status = AcpiNsCheckObjectType (Info, SubElements,
    557      1.1  christos                         ACPI_RTYPE_INTEGER, 0);
    558      1.1  christos             if (ACPI_FAILURE (Status))
    559      1.1  christos             {
    560      1.1  christos                 return (Status);
    561      1.1  christos             }
    562      1.1  christos 
    563      1.1  christos             /*
    564      1.1  christos              * Make sure package is large enough for the Count and is
    565      1.1  christos              * is as large as the minimum size
    566      1.1  christos              */
    567      1.1  christos             ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
    568      1.1  christos             if (SubPackage->Package.Count < ExpectedCount)
    569      1.1  christos             {
    570      1.1  christos                 goto PackageTooSmall;
    571      1.1  christos             }
    572      1.1  christos             if (SubPackage->Package.Count < Package->RetInfo.Count1)
    573      1.1  christos             {
    574      1.1  christos                 ExpectedCount = Package->RetInfo.Count1;
    575      1.1  christos                 goto PackageTooSmall;
    576      1.1  christos             }
    577      1.1  christos             if (ExpectedCount == 0)
    578      1.1  christos             {
    579      1.1  christos                 /*
    580      1.1  christos                  * Either the NumEntries element was originally zero or it was
    581      1.1  christos                  * a NULL element and repaired to an Integer of value zero.
    582      1.1  christos                  * In either case, repair it by setting NumEntries to be the
    583      1.1  christos                  * actual size of the subpackage.
    584      1.1  christos                  */
    585      1.1  christos                 ExpectedCount = SubPackage->Package.Count;
    586      1.1  christos                 (*SubElements)->Integer.Value = ExpectedCount;
    587      1.1  christos             }
    588      1.1  christos 
    589  1.1.1.2  christos             /* Check the type of each subpackage element */
    590      1.1  christos 
    591      1.1  christos             Status = AcpiNsCheckPackageElements (Info, (SubElements + 1),
    592      1.1  christos                         Package->RetInfo.ObjectType1,
    593      1.1  christos                         (ExpectedCount - 1), 0, 0, 1);
    594      1.1  christos             if (ACPI_FAILURE (Status))
    595      1.1  christos             {
    596      1.1  christos                 return (Status);
    597      1.1  christos             }
    598      1.1  christos             break;
    599      1.1  christos 
    600      1.1  christos         default: /* Should not get here, type was validated by caller */
    601      1.1  christos 
    602      1.1  christos             return (AE_AML_INTERNAL);
    603      1.1  christos         }
    604      1.1  christos 
    605      1.1  christos         Elements++;
    606      1.1  christos     }
    607      1.1  christos 
    608      1.1  christos     return (AE_OK);
    609      1.1  christos 
    610      1.1  christos 
    611      1.1  christos PackageTooSmall:
    612      1.1  christos 
    613  1.1.1.2  christos     /* The subpackage count was smaller than required */
    614      1.1  christos 
    615      1.1  christos     ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
    616  1.1.1.2  christos         "Return SubPackage[%u] is too small - found %u elements, expected %u",
    617      1.1  christos         i, SubPackage->Package.Count, ExpectedCount));
    618      1.1  christos 
    619      1.1  christos     return (AE_AML_OPERAND_VALUE);
    620      1.1  christos }
    621      1.1  christos 
    622      1.1  christos 
    623      1.1  christos /*******************************************************************************
    624      1.1  christos  *
    625      1.1  christos  * FUNCTION:    AcpiNsCheckPackageElements
    626      1.1  christos  *
    627      1.1  christos  * PARAMETERS:  Info            - Method execution information block
    628      1.1  christos  *              Elements        - Pointer to the package elements array
    629      1.1  christos  *              Type1           - Object type for first group
    630      1.1  christos  *              Count1          - Count for first group
    631      1.1  christos  *              Type2           - Object type for second group
    632      1.1  christos  *              Count2          - Count for second group
    633      1.1  christos  *              StartIndex      - Start of the first group of elements
    634      1.1  christos  *
    635      1.1  christos  * RETURN:      Status
    636      1.1  christos  *
    637      1.1  christos  * DESCRIPTION: Check that all elements of a package are of the correct object
    638      1.1  christos  *              type. Supports up to two groups of different object types.
    639      1.1  christos  *
    640      1.1  christos  ******************************************************************************/
    641      1.1  christos 
    642      1.1  christos static ACPI_STATUS
    643      1.1  christos AcpiNsCheckPackageElements (
    644      1.1  christos     ACPI_EVALUATE_INFO          *Info,
    645      1.1  christos     ACPI_OPERAND_OBJECT         **Elements,
    646      1.1  christos     UINT8                       Type1,
    647      1.1  christos     UINT32                      Count1,
    648      1.1  christos     UINT8                       Type2,
    649      1.1  christos     UINT32                      Count2,
    650      1.1  christos     UINT32                      StartIndex)
    651      1.1  christos {
    652      1.1  christos     ACPI_OPERAND_OBJECT         **ThisElement = Elements;
    653      1.1  christos     ACPI_STATUS                 Status;
    654      1.1  christos     UINT32                      i;
    655      1.1  christos 
    656      1.1  christos 
    657      1.1  christos     /*
    658      1.1  christos      * Up to two groups of package elements are supported by the data
    659      1.1  christos      * structure. All elements in each group must be of the same type.
    660      1.1  christos      * The second group can have a count of zero.
    661      1.1  christos      */
    662      1.1  christos     for (i = 0; i < Count1; i++)
    663      1.1  christos     {
    664      1.1  christos         Status = AcpiNsCheckObjectType (Info, ThisElement,
    665      1.1  christos                     Type1, i + StartIndex);
    666      1.1  christos         if (ACPI_FAILURE (Status))
    667      1.1  christos         {
    668      1.1  christos             return (Status);
    669      1.1  christos         }
    670      1.1  christos         ThisElement++;
    671      1.1  christos     }
    672      1.1  christos 
    673      1.1  christos     for (i = 0; i < Count2; i++)
    674      1.1  christos     {
    675      1.1  christos         Status = AcpiNsCheckObjectType (Info, ThisElement,
    676      1.1  christos                     Type2, (i + Count1 + StartIndex));
    677      1.1  christos         if (ACPI_FAILURE (Status))
    678      1.1  christos         {
    679      1.1  christos             return (Status);
    680      1.1  christos         }
    681      1.1  christos         ThisElement++;
    682      1.1  christos     }
    683      1.1  christos 
    684      1.1  christos     return (AE_OK);
    685      1.1  christos }
    686