Path: blob/main/sys/contrib/dev/acpica/components/namespace/nsprepkg.c
48524 views
/******************************************************************************1*2* Module Name: nsprepkg - Validation of package objects for predefined names3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acnamesp.h>154#include <contrib/dev/acpica/include/acpredef.h>155156157#define _COMPONENT ACPI_NAMESPACE158ACPI_MODULE_NAME ("nsprepkg")159160161/* Local prototypes */162163static ACPI_STATUS164AcpiNsCheckPackageList (165ACPI_EVALUATE_INFO *Info,166const ACPI_PREDEFINED_INFO *Package,167ACPI_OPERAND_OBJECT **Elements,168UINT32 Count);169170static ACPI_STATUS171AcpiNsCheckPackageElements (172ACPI_EVALUATE_INFO *Info,173ACPI_OPERAND_OBJECT **Elements,174UINT8 Type1,175UINT32 Count1,176UINT8 Type2,177UINT32 Count2,178UINT32 StartIndex);179180static ACPI_STATUS181AcpiNsCustomPackage (182ACPI_EVALUATE_INFO *Info,183ACPI_OPERAND_OBJECT **Elements,184UINT32 Count);185186187/*******************************************************************************188*189* FUNCTION: AcpiNsCheckPackage190*191* PARAMETERS: Info - Method execution information block192* ReturnObjectPtr - Pointer to the object returned from the193* evaluation of a method or object194*195* RETURN: Status196*197* DESCRIPTION: Check a returned package object for the correct count and198* correct type of all sub-objects.199*200******************************************************************************/201202ACPI_STATUS203AcpiNsCheckPackage (204ACPI_EVALUATE_INFO *Info,205ACPI_OPERAND_OBJECT **ReturnObjectPtr)206{207ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;208const ACPI_PREDEFINED_INFO *Package;209ACPI_OPERAND_OBJECT **Elements;210ACPI_STATUS Status = AE_OK;211UINT32 ExpectedCount;212UINT32 Count;213UINT32 i;214215216ACPI_FUNCTION_TRACE (NsCheckPackage);217218219/* The package info for this name is in the next table entry */220221Package = Info->Predefined + 1;222223ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,224"%s Validating return Package of Type %X, Count %X\n",225Info->FullPathname, Package->RetInfo.Type,226ReturnObject->Package.Count));227228/*229* For variable-length Packages, we can safely remove all embedded230* and trailing NULL package elements231*/232AcpiNsRemoveNullElements (Info, Package->RetInfo.Type, ReturnObject);233234/* Extract package count and elements array */235236Elements = ReturnObject->Package.Elements;237Count = ReturnObject->Package.Count;238239/*240* Most packages must have at least one element. The only exception241* is the variable-length package (ACPI_PTYPE1_VAR).242*/243if (!Count)244{245if (Package->RetInfo.Type == ACPI_PTYPE1_VAR)246{247return_ACPI_STATUS (AE_OK);248}249250ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,251"Return Package has no elements (empty)"));252253return_ACPI_STATUS (AE_AML_OPERAND_VALUE);254}255256/*257* Decode the type of the expected package contents258*259* PTYPE1 packages contain no subpackages260* PTYPE2 packages contain subpackages261*/262switch (Package->RetInfo.Type)263{264case ACPI_PTYPE_CUSTOM:265266Status = AcpiNsCustomPackage (Info, Elements, Count);267break;268269case ACPI_PTYPE1_FIXED:270/*271* The package count is fixed and there are no subpackages272*273* If package is too small, exit.274* If package is larger than expected, issue warning but continue275*/276ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;277if (Count < ExpectedCount)278{279goto PackageTooSmall;280}281else if (Count > ExpectedCount)282{283ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,284"%s: Return Package is larger than needed - "285"found %u, expected %u\n",286Info->FullPathname, Count, ExpectedCount));287}288289/* Validate all elements of the returned package */290291Status = AcpiNsCheckPackageElements (Info, Elements,292Package->RetInfo.ObjectType1, Package->RetInfo.Count1,293Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);294break;295296case ACPI_PTYPE1_VAR:297/*298* The package count is variable, there are no subpackages, and all299* elements must be of the same type300*/301for (i = 0; i < Count; i++)302{303Status = AcpiNsCheckObjectType (Info, Elements,304Package->RetInfo.ObjectType1, i);305if (ACPI_FAILURE (Status))306{307return_ACPI_STATUS (Status);308}309310Elements++;311}312break;313314case ACPI_PTYPE1_OPTION:315/*316* The package count is variable, there are no subpackages. There are317* a fixed number of required elements, and a variable number of318* optional elements.319*320* Check if package is at least as large as the minimum required321*/322ExpectedCount = Package->RetInfo3.Count;323if (Count < ExpectedCount)324{325goto PackageTooSmall;326}327328/* Variable number of sub-objects */329330for (i = 0; i < Count; i++)331{332if (i < Package->RetInfo3.Count)333{334/* These are the required package elements (0, 1, or 2) */335336Status = AcpiNsCheckObjectType (Info, Elements,337Package->RetInfo3.ObjectType[i], i);338if (ACPI_FAILURE (Status))339{340return_ACPI_STATUS (Status);341}342}343else344{345/* These are the optional package elements */346347Status = AcpiNsCheckObjectType (Info, Elements,348Package->RetInfo3.TailObjectType, i);349if (ACPI_FAILURE (Status))350{351return_ACPI_STATUS (Status);352}353}354355Elements++;356}357break;358359case ACPI_PTYPE2_REV_FIXED:360361/* First element is the (Integer) revision */362363Status = AcpiNsCheckObjectType (364Info, Elements, ACPI_RTYPE_INTEGER, 0);365if (ACPI_FAILURE (Status))366{367return_ACPI_STATUS (Status);368}369370Elements++;371Count--;372373/* Examine the subpackages */374375Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);376break;377378case ACPI_PTYPE2_PKG_COUNT:379380/* First element is the (Integer) count of subpackages to follow */381382Status = AcpiNsCheckObjectType (383Info, Elements, ACPI_RTYPE_INTEGER, 0);384if (ACPI_FAILURE (Status))385{386return_ACPI_STATUS (Status);387}388389/*390* Count cannot be larger than the parent package length, but allow it391* to be smaller. The >= accounts for the Integer above.392*/393ExpectedCount = (UINT32) (*Elements)->Integer.Value;394if (ExpectedCount >= Count)395{396goto PackageTooSmall;397}398399Count = ExpectedCount;400Elements++;401402/* Examine the subpackages */403404Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);405break;406407case ACPI_PTYPE2:408case ACPI_PTYPE2_FIXED:409case ACPI_PTYPE2_MIN:410case ACPI_PTYPE2_COUNT:411case ACPI_PTYPE2_FIX_VAR:412/*413* These types all return a single Package that consists of a414* variable number of subpackages.415*416* First, ensure that the first element is a subpackage. If not,417* the BIOS may have incorrectly returned the object as a single418* package instead of a Package of Packages (a common error if419* there is only one entry). We may be able to repair this by420* wrapping the returned Package with a new outer Package.421*/422if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))423{424/* Create the new outer package and populate it */425426Status = AcpiNsWrapWithPackage (427Info, ReturnObject, ReturnObjectPtr);428if (ACPI_FAILURE (Status))429{430return_ACPI_STATUS (Status);431}432433/* Update locals to point to the new package (of 1 element) */434435ReturnObject = *ReturnObjectPtr;436Elements = ReturnObject->Package.Elements;437Count = 1;438}439440/* Examine the subpackages */441442Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);443break;444445case ACPI_PTYPE2_VAR_VAR:446/*447* Returns a variable list of packages, each with a variable list448* of objects.449*/450break;451452case ACPI_PTYPE2_UUID_PAIR:453454/* The package must contain pairs of (UUID + type) */455456if (Count & 1)457{458ExpectedCount = Count + 1;459goto PackageTooSmall;460}461462while (Count > 0)463{464Status = AcpiNsCheckObjectType(Info, Elements,465Package->RetInfo.ObjectType1, 0);466if (ACPI_FAILURE(Status))467{468return_ACPI_STATUS (Status);469}470471/* Validate length of the UUID buffer */472473if ((*Elements)->Buffer.Length != 16)474{475ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,476Info->NodeFlags, "Invalid length for UUID Buffer"));477return_ACPI_STATUS (AE_AML_OPERAND_VALUE);478}479480Status = AcpiNsCheckObjectType(Info, Elements + 1,481Package->RetInfo.ObjectType2, 0);482if (ACPI_FAILURE(Status))483{484return_ACPI_STATUS (Status);485}486487Elements += 2;488Count -= 2;489}490break;491492default:493494/* Should not get here if predefined info table is correct */495496ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,497"Invalid internal return type in table entry: %X",498Package->RetInfo.Type));499500return_ACPI_STATUS (AE_AML_INTERNAL);501}502503return_ACPI_STATUS (Status);504505506PackageTooSmall:507508/* Error exit for the case with an incorrect package count */509510ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,511"Return Package is too small - found %u elements, expected %u",512Count, ExpectedCount));513514return_ACPI_STATUS (AE_AML_OPERAND_VALUE);515}516517518/*******************************************************************************519*520* FUNCTION: AcpiNsCheckPackageList521*522* PARAMETERS: Info - Method execution information block523* Package - Pointer to package-specific info for method524* Elements - Element list of parent package. All elements525* of this list should be of type Package.526* Count - Count of subpackages527*528* RETURN: Status529*530* DESCRIPTION: Examine a list of subpackages531*532******************************************************************************/533534static ACPI_STATUS535AcpiNsCheckPackageList (536ACPI_EVALUATE_INFO *Info,537const ACPI_PREDEFINED_INFO *Package,538ACPI_OPERAND_OBJECT **Elements,539UINT32 Count)540{541ACPI_OPERAND_OBJECT *SubPackage;542ACPI_OPERAND_OBJECT **SubElements;543ACPI_STATUS Status;544UINT32 ExpectedCount;545UINT32 i;546UINT32 j;547548549/*550* Validate each subpackage in the parent Package551*552* NOTE: assumes list of subpackages contains no NULL elements.553* Any NULL elements should have been removed by earlier call554* to AcpiNsRemoveNullElements.555*/556for (i = 0; i < Count; i++)557{558SubPackage = *Elements;559SubElements = SubPackage->Package.Elements;560Info->ParentPackage = SubPackage;561562/* Each sub-object must be of type Package */563564Status = AcpiNsCheckObjectType (Info, &SubPackage,565ACPI_RTYPE_PACKAGE, i);566if (ACPI_FAILURE (Status))567{568return (Status);569}570571/* Examine the different types of expected subpackages */572573Info->ParentPackage = SubPackage;574switch (Package->RetInfo.Type)575{576case ACPI_PTYPE2:577case ACPI_PTYPE2_PKG_COUNT:578case ACPI_PTYPE2_REV_FIXED:579580/* Each subpackage has a fixed number of elements */581582ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;583if (SubPackage->Package.Count < ExpectedCount)584{585goto PackageTooSmall;586}587588Status = AcpiNsCheckPackageElements (Info, SubElements,589Package->RetInfo.ObjectType1,590Package->RetInfo.Count1,591Package->RetInfo.ObjectType2,592Package->RetInfo.Count2, 0);593if (ACPI_FAILURE (Status))594{595return (Status);596}597break;598599case ACPI_PTYPE2_FIX_VAR:600/*601* Each subpackage has a fixed number of elements and an602* optional element603*/604ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;605if (SubPackage->Package.Count < ExpectedCount)606{607goto PackageTooSmall;608}609610Status = AcpiNsCheckPackageElements (Info, SubElements,611Package->RetInfo.ObjectType1,612Package->RetInfo.Count1,613Package->RetInfo.ObjectType2,614SubPackage->Package.Count - Package->RetInfo.Count1, 0);615if (ACPI_FAILURE (Status))616{617return (Status);618}619break;620621case ACPI_PTYPE2_VAR_VAR:622/*623* Each subpackage has a fixed or variable number of elements624*/625break;626627case ACPI_PTYPE2_FIXED:628629/* Each subpackage has a fixed length */630631ExpectedCount = Package->RetInfo2.Count;632if (SubPackage->Package.Count < ExpectedCount)633{634goto PackageTooSmall;635}636637/* Check the type of each subpackage element */638639for (j = 0; j < ExpectedCount; j++)640{641Status = AcpiNsCheckObjectType (Info, &SubElements[j],642Package->RetInfo2.ObjectType[j], j);643if (ACPI_FAILURE (Status))644{645return (Status);646}647}648break;649650case ACPI_PTYPE2_MIN:651652/* Each subpackage has a variable but minimum length */653654ExpectedCount = Package->RetInfo.Count1;655if (SubPackage->Package.Count < ExpectedCount)656{657goto PackageTooSmall;658}659660/* Check the type of each subpackage element */661662Status = AcpiNsCheckPackageElements (Info, SubElements,663Package->RetInfo.ObjectType1,664SubPackage->Package.Count, 0, 0, 0);665if (ACPI_FAILURE (Status))666{667return (Status);668}669break;670671case ACPI_PTYPE2_COUNT:672/*673* First element is the (Integer) count of elements, including674* the count field (the ACPI name is NumElements)675*/676Status = AcpiNsCheckObjectType (Info, SubElements,677ACPI_RTYPE_INTEGER, 0);678if (ACPI_FAILURE (Status))679{680return (Status);681}682683/*684* Make sure package is large enough for the Count and is685* is as large as the minimum size686*/687ExpectedCount = (UINT32) (*SubElements)->Integer.Value;688if (SubPackage->Package.Count < ExpectedCount)689{690goto PackageTooSmall;691}692693if (SubPackage->Package.Count < Package->RetInfo.Count1)694{695ExpectedCount = Package->RetInfo.Count1;696goto PackageTooSmall;697}698699if (ExpectedCount == 0)700{701/*702* Either the NumEntries element was originally zero or it was703* a NULL element and repaired to an Integer of value zero.704* In either case, repair it by setting NumEntries to be the705* actual size of the subpackage.706*/707ExpectedCount = SubPackage->Package.Count;708(*SubElements)->Integer.Value = ExpectedCount;709}710711/* Check the type of each subpackage element */712713Status = AcpiNsCheckPackageElements (Info, (SubElements + 1),714Package->RetInfo.ObjectType1,715(ExpectedCount - 1), 0, 0, 1);716if (ACPI_FAILURE (Status))717{718return (Status);719}720break;721722default: /* Should not get here, type was validated by caller */723724ACPI_ERROR ((AE_INFO, "Invalid Package type: %X",725Package->RetInfo.Type));726return (AE_AML_INTERNAL);727}728729Elements++;730}731732return (AE_OK);733734735PackageTooSmall:736737/* The subpackage count was smaller than required */738739ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,740"Return SubPackage[%u] is too small - found %u elements, expected %u",741i, SubPackage->Package.Count, ExpectedCount));742743return (AE_AML_OPERAND_VALUE);744}745746747/*******************************************************************************748*749* FUNCTION: AcpiNsCustomPackage750*751* PARAMETERS: Info - Method execution information block752* Elements - Pointer to the package elements array753* Count - Element count for the package754*755* RETURN: Status756*757* DESCRIPTION: Check a returned package object for the correct count and758* correct type of all sub-objects.759*760* NOTE: Currently used for the _BIX method only. When needed for two or more761* methods, probably a detect/dispatch mechanism will be required.762*763******************************************************************************/764765static ACPI_STATUS766AcpiNsCustomPackage (767ACPI_EVALUATE_INFO *Info,768ACPI_OPERAND_OBJECT **Elements,769UINT32 Count)770{771UINT32 ExpectedCount;772UINT32 Version;773ACPI_STATUS Status = AE_OK;774775776ACPI_FUNCTION_NAME (NsCustomPackage);777778779/* Get version number, must be Integer */780781if ((*Elements)->Common.Type != ACPI_TYPE_INTEGER)782{783ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,784"Return Package has invalid object type for version number"));785return_ACPI_STATUS (AE_AML_OPERAND_TYPE);786}787788Version = (UINT32) (*Elements)->Integer.Value;789ExpectedCount = 21; /* Version 1 */790791if (Version == 0)792{793ExpectedCount = 20; /* Version 0 */794}795796if (Count < ExpectedCount)797{798ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,799"Return Package is too small - found %u elements, expected %u",800Count, ExpectedCount));801return_ACPI_STATUS (AE_AML_OPERAND_VALUE);802}803else if (Count > ExpectedCount)804{805ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,806"%s: Return Package is larger than needed - "807"found %u, expected %u\n",808Info->FullPathname, Count, ExpectedCount));809}810811/* Validate all elements of the returned package */812813Status = AcpiNsCheckPackageElements (Info, Elements,814ACPI_RTYPE_INTEGER, 16,815ACPI_RTYPE_STRING, 4, 0);816if (ACPI_FAILURE (Status))817{818return_ACPI_STATUS (Status);819}820821/* Version 1 has a single trailing integer */822823if (Version > 0)824{825Status = AcpiNsCheckPackageElements (Info, Elements + 20,826ACPI_RTYPE_INTEGER, 1, 0, 0, 20);827}828829return_ACPI_STATUS (Status);830}831832833/*******************************************************************************834*835* FUNCTION: AcpiNsCheckPackageElements836*837* PARAMETERS: Info - Method execution information block838* Elements - Pointer to the package elements array839* Type1 - Object type for first group840* Count1 - Count for first group841* Type2 - Object type for second group842* Count2 - Count for second group843* StartIndex - Start of the first group of elements844*845* RETURN: Status846*847* DESCRIPTION: Check that all elements of a package are of the correct object848* type. Supports up to two groups of different object types.849*850******************************************************************************/851852static ACPI_STATUS853AcpiNsCheckPackageElements (854ACPI_EVALUATE_INFO *Info,855ACPI_OPERAND_OBJECT **Elements,856UINT8 Type1,857UINT32 Count1,858UINT8 Type2,859UINT32 Count2,860UINT32 StartIndex)861{862ACPI_OPERAND_OBJECT **ThisElement = Elements;863ACPI_STATUS Status;864UINT32 i;865866867ACPI_FUNCTION_TRACE (NsCheckPackageElements);868869/*870* Up to two groups of package elements are supported by the data871* structure. All elements in each group must be of the same type.872* The second group can have a count of zero.873*/874for (i = 0; i < Count1; i++)875{876Status = AcpiNsCheckObjectType (Info, ThisElement,877Type1, i + StartIndex);878if (ACPI_FAILURE (Status))879{880return_ACPI_STATUS (Status);881}882883ThisElement++;884}885886for (i = 0; i < Count2; i++)887{888Status = AcpiNsCheckObjectType (Info, ThisElement,889Type2, (i + Count1 + StartIndex));890if (ACPI_FAILURE (Status))891{892return_ACPI_STATUS (Status);893}894895ThisElement++;896}897898return_ACPI_STATUS (AE_OK);899}900901902