xref: /titanic_44/usr/src/uts/intel/io/acpica/namespace/nsprepkg.c (revision cb56572868bfc488bbd3ab847b09db2a25554d44)
1*cb565728SJerry Jelinek /******************************************************************************
2*cb565728SJerry Jelinek  *
3*cb565728SJerry Jelinek  * Module Name: nsprepkg - Validation of package objects for predefined names
4*cb565728SJerry Jelinek  *
5*cb565728SJerry Jelinek  *****************************************************************************/
6*cb565728SJerry Jelinek 
7*cb565728SJerry Jelinek /*
8*cb565728SJerry Jelinek  * Copyright (C) 2000 - 2016, Intel Corp.
9*cb565728SJerry Jelinek  * All rights reserved.
10*cb565728SJerry Jelinek  *
11*cb565728SJerry Jelinek  * Redistribution and use in source and binary forms, with or without
12*cb565728SJerry Jelinek  * modification, are permitted provided that the following conditions
13*cb565728SJerry Jelinek  * are met:
14*cb565728SJerry Jelinek  * 1. Redistributions of source code must retain the above copyright
15*cb565728SJerry Jelinek  *    notice, this list of conditions, and the following disclaimer,
16*cb565728SJerry Jelinek  *    without modification.
17*cb565728SJerry Jelinek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*cb565728SJerry Jelinek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*cb565728SJerry Jelinek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*cb565728SJerry Jelinek  *    including a substantially similar Disclaimer requirement for further
21*cb565728SJerry Jelinek  *    binary redistribution.
22*cb565728SJerry Jelinek  * 3. Neither the names of the above-listed copyright holders nor the names
23*cb565728SJerry Jelinek  *    of any contributors may be used to endorse or promote products derived
24*cb565728SJerry Jelinek  *    from this software without specific prior written permission.
25*cb565728SJerry Jelinek  *
26*cb565728SJerry Jelinek  * Alternatively, this software may be distributed under the terms of the
27*cb565728SJerry Jelinek  * GNU General Public License ("GPL") version 2 as published by the Free
28*cb565728SJerry Jelinek  * Software Foundation.
29*cb565728SJerry Jelinek  *
30*cb565728SJerry Jelinek  * NO WARRANTY
31*cb565728SJerry Jelinek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*cb565728SJerry Jelinek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*cb565728SJerry Jelinek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*cb565728SJerry Jelinek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*cb565728SJerry Jelinek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*cb565728SJerry Jelinek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*cb565728SJerry Jelinek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*cb565728SJerry Jelinek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*cb565728SJerry Jelinek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*cb565728SJerry Jelinek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*cb565728SJerry Jelinek  * POSSIBILITY OF SUCH DAMAGES.
42*cb565728SJerry Jelinek  */
43*cb565728SJerry Jelinek 
44*cb565728SJerry Jelinek #include "acpi.h"
45*cb565728SJerry Jelinek #include "accommon.h"
46*cb565728SJerry Jelinek #include "acnamesp.h"
47*cb565728SJerry Jelinek #include "acpredef.h"
48*cb565728SJerry Jelinek 
49*cb565728SJerry Jelinek 
50*cb565728SJerry Jelinek #define _COMPONENT          ACPI_NAMESPACE
51*cb565728SJerry Jelinek         ACPI_MODULE_NAME    ("nsprepkg")
52*cb565728SJerry Jelinek 
53*cb565728SJerry Jelinek 
54*cb565728SJerry Jelinek /* Local prototypes */
55*cb565728SJerry Jelinek 
56*cb565728SJerry Jelinek static ACPI_STATUS
57*cb565728SJerry Jelinek AcpiNsCheckPackageList (
58*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
59*cb565728SJerry Jelinek     const ACPI_PREDEFINED_INFO  *Package,
60*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements,
61*cb565728SJerry Jelinek     UINT32                      Count);
62*cb565728SJerry Jelinek 
63*cb565728SJerry Jelinek static ACPI_STATUS
64*cb565728SJerry Jelinek AcpiNsCheckPackageElements (
65*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
66*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements,
67*cb565728SJerry Jelinek     UINT8                       Type1,
68*cb565728SJerry Jelinek     UINT32                      Count1,
69*cb565728SJerry Jelinek     UINT8                       Type2,
70*cb565728SJerry Jelinek     UINT32                      Count2,
71*cb565728SJerry Jelinek     UINT32                      StartIndex);
72*cb565728SJerry Jelinek 
73*cb565728SJerry Jelinek static ACPI_STATUS
74*cb565728SJerry Jelinek AcpiNsCustomPackage (
75*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
76*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements,
77*cb565728SJerry Jelinek     UINT32                      Count);
78*cb565728SJerry Jelinek 
79*cb565728SJerry Jelinek 
80*cb565728SJerry Jelinek /*******************************************************************************
81*cb565728SJerry Jelinek  *
82*cb565728SJerry Jelinek  * FUNCTION:    AcpiNsCheckPackage
83*cb565728SJerry Jelinek  *
84*cb565728SJerry Jelinek  * PARAMETERS:  Info                - Method execution information block
85*cb565728SJerry Jelinek  *              ReturnObjectPtr     - Pointer to the object returned from the
86*cb565728SJerry Jelinek  *                                    evaluation of a method or object
87*cb565728SJerry Jelinek  *
88*cb565728SJerry Jelinek  * RETURN:      Status
89*cb565728SJerry Jelinek  *
90*cb565728SJerry Jelinek  * DESCRIPTION: Check a returned package object for the correct count and
91*cb565728SJerry Jelinek  *              correct type of all sub-objects.
92*cb565728SJerry Jelinek  *
93*cb565728SJerry Jelinek  ******************************************************************************/
94*cb565728SJerry Jelinek 
95*cb565728SJerry Jelinek ACPI_STATUS
AcpiNsCheckPackage(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT ** ReturnObjectPtr)96*cb565728SJerry Jelinek AcpiNsCheckPackage (
97*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
98*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **ReturnObjectPtr)
99*cb565728SJerry Jelinek {
100*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         *ReturnObject = *ReturnObjectPtr;
101*cb565728SJerry Jelinek     const ACPI_PREDEFINED_INFO  *Package;
102*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements;
103*cb565728SJerry Jelinek     ACPI_STATUS                 Status = AE_OK;
104*cb565728SJerry Jelinek     UINT32                      ExpectedCount;
105*cb565728SJerry Jelinek     UINT32                      Count;
106*cb565728SJerry Jelinek     UINT32                      i;
107*cb565728SJerry Jelinek 
108*cb565728SJerry Jelinek 
109*cb565728SJerry Jelinek     ACPI_FUNCTION_NAME (NsCheckPackage);
110*cb565728SJerry Jelinek 
111*cb565728SJerry Jelinek 
112*cb565728SJerry Jelinek     /* The package info for this name is in the next table entry */
113*cb565728SJerry Jelinek 
114*cb565728SJerry Jelinek     Package = Info->Predefined + 1;
115*cb565728SJerry Jelinek 
116*cb565728SJerry Jelinek     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
117*cb565728SJerry Jelinek         "%s Validating return Package of Type %X, Count %X\n",
118*cb565728SJerry Jelinek         Info->FullPathname, Package->RetInfo.Type,
119*cb565728SJerry Jelinek         ReturnObject->Package.Count));
120*cb565728SJerry Jelinek 
121*cb565728SJerry Jelinek     /*
122*cb565728SJerry Jelinek      * For variable-length Packages, we can safely remove all embedded
123*cb565728SJerry Jelinek      * and trailing NULL package elements
124*cb565728SJerry Jelinek      */
125*cb565728SJerry Jelinek     AcpiNsRemoveNullElements (Info, Package->RetInfo.Type, ReturnObject);
126*cb565728SJerry Jelinek 
127*cb565728SJerry Jelinek     /* Extract package count and elements array */
128*cb565728SJerry Jelinek 
129*cb565728SJerry Jelinek     Elements = ReturnObject->Package.Elements;
130*cb565728SJerry Jelinek     Count = ReturnObject->Package.Count;
131*cb565728SJerry Jelinek 
132*cb565728SJerry Jelinek     /*
133*cb565728SJerry Jelinek      * Most packages must have at least one element. The only exception
134*cb565728SJerry Jelinek      * is the variable-length package (ACPI_PTYPE1_VAR).
135*cb565728SJerry Jelinek      */
136*cb565728SJerry Jelinek     if (!Count)
137*cb565728SJerry Jelinek     {
138*cb565728SJerry Jelinek         if (Package->RetInfo.Type == ACPI_PTYPE1_VAR)
139*cb565728SJerry Jelinek         {
140*cb565728SJerry Jelinek             return (AE_OK);
141*cb565728SJerry Jelinek         }
142*cb565728SJerry Jelinek 
143*cb565728SJerry Jelinek         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
144*cb565728SJerry Jelinek             "Return Package has no elements (empty)"));
145*cb565728SJerry Jelinek 
146*cb565728SJerry Jelinek         return (AE_AML_OPERAND_VALUE);
147*cb565728SJerry Jelinek     }
148*cb565728SJerry Jelinek 
149*cb565728SJerry Jelinek     /*
150*cb565728SJerry Jelinek      * Decode the type of the expected package contents
151*cb565728SJerry Jelinek      *
152*cb565728SJerry Jelinek      * PTYPE1 packages contain no subpackages
153*cb565728SJerry Jelinek      * PTYPE2 packages contain subpackages
154*cb565728SJerry Jelinek      */
155*cb565728SJerry Jelinek     switch (Package->RetInfo.Type)
156*cb565728SJerry Jelinek     {
157*cb565728SJerry Jelinek     case ACPI_PTYPE_CUSTOM:
158*cb565728SJerry Jelinek 
159*cb565728SJerry Jelinek         Status = AcpiNsCustomPackage (Info, Elements, Count);
160*cb565728SJerry Jelinek         break;
161*cb565728SJerry Jelinek 
162*cb565728SJerry Jelinek     case ACPI_PTYPE1_FIXED:
163*cb565728SJerry Jelinek         /*
164*cb565728SJerry Jelinek          * The package count is fixed and there are no subpackages
165*cb565728SJerry Jelinek          *
166*cb565728SJerry Jelinek          * If package is too small, exit.
167*cb565728SJerry Jelinek          * If package is larger than expected, issue warning but continue
168*cb565728SJerry Jelinek          */
169*cb565728SJerry Jelinek         ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
170*cb565728SJerry Jelinek         if (Count < ExpectedCount)
171*cb565728SJerry Jelinek         {
172*cb565728SJerry Jelinek             goto PackageTooSmall;
173*cb565728SJerry Jelinek         }
174*cb565728SJerry Jelinek         else if (Count > ExpectedCount)
175*cb565728SJerry Jelinek         {
176*cb565728SJerry Jelinek             ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
177*cb565728SJerry Jelinek                 "%s: Return Package is larger than needed - "
178*cb565728SJerry Jelinek                 "found %u, expected %u\n",
179*cb565728SJerry Jelinek                 Info->FullPathname, Count, ExpectedCount));
180*cb565728SJerry Jelinek         }
181*cb565728SJerry Jelinek 
182*cb565728SJerry Jelinek         /* Validate all elements of the returned package */
183*cb565728SJerry Jelinek 
184*cb565728SJerry Jelinek         Status = AcpiNsCheckPackageElements (Info, Elements,
185*cb565728SJerry Jelinek             Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
186*cb565728SJerry Jelinek             Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
187*cb565728SJerry Jelinek         break;
188*cb565728SJerry Jelinek 
189*cb565728SJerry Jelinek     case ACPI_PTYPE1_VAR:
190*cb565728SJerry Jelinek         /*
191*cb565728SJerry Jelinek          * The package count is variable, there are no subpackages, and all
192*cb565728SJerry Jelinek          * elements must be of the same type
193*cb565728SJerry Jelinek          */
194*cb565728SJerry Jelinek         for (i = 0; i < Count; i++)
195*cb565728SJerry Jelinek         {
196*cb565728SJerry Jelinek             Status = AcpiNsCheckObjectType (Info, Elements,
197*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType1, i);
198*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
199*cb565728SJerry Jelinek             {
200*cb565728SJerry Jelinek                 return (Status);
201*cb565728SJerry Jelinek             }
202*cb565728SJerry Jelinek 
203*cb565728SJerry Jelinek             Elements++;
204*cb565728SJerry Jelinek         }
205*cb565728SJerry Jelinek         break;
206*cb565728SJerry Jelinek 
207*cb565728SJerry Jelinek     case ACPI_PTYPE1_OPTION:
208*cb565728SJerry Jelinek         /*
209*cb565728SJerry Jelinek          * The package count is variable, there are no subpackages. There are
210*cb565728SJerry Jelinek          * a fixed number of required elements, and a variable number of
211*cb565728SJerry Jelinek          * optional elements.
212*cb565728SJerry Jelinek          *
213*cb565728SJerry Jelinek          * Check if package is at least as large as the minimum required
214*cb565728SJerry Jelinek          */
215*cb565728SJerry Jelinek         ExpectedCount = Package->RetInfo3.Count;
216*cb565728SJerry Jelinek         if (Count < ExpectedCount)
217*cb565728SJerry Jelinek         {
218*cb565728SJerry Jelinek             goto PackageTooSmall;
219*cb565728SJerry Jelinek         }
220*cb565728SJerry Jelinek 
221*cb565728SJerry Jelinek         /* Variable number of sub-objects */
222*cb565728SJerry Jelinek 
223*cb565728SJerry Jelinek         for (i = 0; i < Count; i++)
224*cb565728SJerry Jelinek         {
225*cb565728SJerry Jelinek             if (i < Package->RetInfo3.Count)
226*cb565728SJerry Jelinek             {
227*cb565728SJerry Jelinek                 /* These are the required package elements (0, 1, or 2) */
228*cb565728SJerry Jelinek 
229*cb565728SJerry Jelinek                 Status = AcpiNsCheckObjectType (Info, Elements,
230*cb565728SJerry Jelinek                     Package->RetInfo3.ObjectType[i], i);
231*cb565728SJerry Jelinek                 if (ACPI_FAILURE (Status))
232*cb565728SJerry Jelinek                 {
233*cb565728SJerry Jelinek                     return (Status);
234*cb565728SJerry Jelinek                 }
235*cb565728SJerry Jelinek             }
236*cb565728SJerry Jelinek             else
237*cb565728SJerry Jelinek             {
238*cb565728SJerry Jelinek                 /* These are the optional package elements */
239*cb565728SJerry Jelinek 
240*cb565728SJerry Jelinek                 Status = AcpiNsCheckObjectType (Info, Elements,
241*cb565728SJerry Jelinek                     Package->RetInfo3.TailObjectType, i);
242*cb565728SJerry Jelinek                 if (ACPI_FAILURE (Status))
243*cb565728SJerry Jelinek                 {
244*cb565728SJerry Jelinek                     return (Status);
245*cb565728SJerry Jelinek                 }
246*cb565728SJerry Jelinek             }
247*cb565728SJerry Jelinek 
248*cb565728SJerry Jelinek             Elements++;
249*cb565728SJerry Jelinek         }
250*cb565728SJerry Jelinek         break;
251*cb565728SJerry Jelinek 
252*cb565728SJerry Jelinek     case ACPI_PTYPE2_REV_FIXED:
253*cb565728SJerry Jelinek 
254*cb565728SJerry Jelinek         /* First element is the (Integer) revision */
255*cb565728SJerry Jelinek 
256*cb565728SJerry Jelinek         Status = AcpiNsCheckObjectType (
257*cb565728SJerry Jelinek             Info, Elements, ACPI_RTYPE_INTEGER, 0);
258*cb565728SJerry Jelinek         if (ACPI_FAILURE (Status))
259*cb565728SJerry Jelinek         {
260*cb565728SJerry Jelinek             return (Status);
261*cb565728SJerry Jelinek         }
262*cb565728SJerry Jelinek 
263*cb565728SJerry Jelinek         Elements++;
264*cb565728SJerry Jelinek         Count--;
265*cb565728SJerry Jelinek 
266*cb565728SJerry Jelinek         /* Examine the subpackages */
267*cb565728SJerry Jelinek 
268*cb565728SJerry Jelinek         Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
269*cb565728SJerry Jelinek         break;
270*cb565728SJerry Jelinek 
271*cb565728SJerry Jelinek     case ACPI_PTYPE2_PKG_COUNT:
272*cb565728SJerry Jelinek 
273*cb565728SJerry Jelinek         /* First element is the (Integer) count of subpackages to follow */
274*cb565728SJerry Jelinek 
275*cb565728SJerry Jelinek         Status = AcpiNsCheckObjectType (
276*cb565728SJerry Jelinek             Info, Elements, ACPI_RTYPE_INTEGER, 0);
277*cb565728SJerry Jelinek         if (ACPI_FAILURE (Status))
278*cb565728SJerry Jelinek         {
279*cb565728SJerry Jelinek             return (Status);
280*cb565728SJerry Jelinek         }
281*cb565728SJerry Jelinek 
282*cb565728SJerry Jelinek         /*
283*cb565728SJerry Jelinek          * Count cannot be larger than the parent package length, but allow it
284*cb565728SJerry Jelinek          * to be smaller. The >= accounts for the Integer above.
285*cb565728SJerry Jelinek          */
286*cb565728SJerry Jelinek         ExpectedCount = (UINT32) (*Elements)->Integer.Value;
287*cb565728SJerry Jelinek         if (ExpectedCount >= Count)
288*cb565728SJerry Jelinek         {
289*cb565728SJerry Jelinek             goto PackageTooSmall;
290*cb565728SJerry Jelinek         }
291*cb565728SJerry Jelinek 
292*cb565728SJerry Jelinek         Count = ExpectedCount;
293*cb565728SJerry Jelinek         Elements++;
294*cb565728SJerry Jelinek 
295*cb565728SJerry Jelinek         /* Examine the subpackages */
296*cb565728SJerry Jelinek 
297*cb565728SJerry Jelinek         Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
298*cb565728SJerry Jelinek         break;
299*cb565728SJerry Jelinek 
300*cb565728SJerry Jelinek     case ACPI_PTYPE2:
301*cb565728SJerry Jelinek     case ACPI_PTYPE2_FIXED:
302*cb565728SJerry Jelinek     case ACPI_PTYPE2_MIN:
303*cb565728SJerry Jelinek     case ACPI_PTYPE2_COUNT:
304*cb565728SJerry Jelinek     case ACPI_PTYPE2_FIX_VAR:
305*cb565728SJerry Jelinek         /*
306*cb565728SJerry Jelinek          * These types all return a single Package that consists of a
307*cb565728SJerry Jelinek          * variable number of subpackages.
308*cb565728SJerry Jelinek          *
309*cb565728SJerry Jelinek          * First, ensure that the first element is a subpackage. If not,
310*cb565728SJerry Jelinek          * the BIOS may have incorrectly returned the object as a single
311*cb565728SJerry Jelinek          * package instead of a Package of Packages (a common error if
312*cb565728SJerry Jelinek          * there is only one entry). We may be able to repair this by
313*cb565728SJerry Jelinek          * wrapping the returned Package with a new outer Package.
314*cb565728SJerry Jelinek          */
315*cb565728SJerry Jelinek         if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
316*cb565728SJerry Jelinek         {
317*cb565728SJerry Jelinek             /* Create the new outer package and populate it */
318*cb565728SJerry Jelinek 
319*cb565728SJerry Jelinek             Status = AcpiNsWrapWithPackage (
320*cb565728SJerry Jelinek                 Info, ReturnObject, ReturnObjectPtr);
321*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
322*cb565728SJerry Jelinek             {
323*cb565728SJerry Jelinek                 return (Status);
324*cb565728SJerry Jelinek             }
325*cb565728SJerry Jelinek 
326*cb565728SJerry Jelinek             /* Update locals to point to the new package (of 1 element) */
327*cb565728SJerry Jelinek 
328*cb565728SJerry Jelinek             ReturnObject = *ReturnObjectPtr;
329*cb565728SJerry Jelinek             Elements = ReturnObject->Package.Elements;
330*cb565728SJerry Jelinek             Count = 1;
331*cb565728SJerry Jelinek         }
332*cb565728SJerry Jelinek 
333*cb565728SJerry Jelinek         /* Examine the subpackages */
334*cb565728SJerry Jelinek 
335*cb565728SJerry Jelinek         Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
336*cb565728SJerry Jelinek         break;
337*cb565728SJerry Jelinek 
338*cb565728SJerry Jelinek     case ACPI_PTYPE2_VAR_VAR:
339*cb565728SJerry Jelinek         /*
340*cb565728SJerry Jelinek          * Returns a variable list of packages, each with a variable list
341*cb565728SJerry Jelinek          * of objects.
342*cb565728SJerry Jelinek          */
343*cb565728SJerry Jelinek         break;
344*cb565728SJerry Jelinek 
345*cb565728SJerry Jelinek     case ACPI_PTYPE2_UUID_PAIR:
346*cb565728SJerry Jelinek 
347*cb565728SJerry Jelinek         /* The package must contain pairs of (UUID + type) */
348*cb565728SJerry Jelinek 
349*cb565728SJerry Jelinek         if (Count & 1)
350*cb565728SJerry Jelinek         {
351*cb565728SJerry Jelinek             ExpectedCount = Count + 1;
352*cb565728SJerry Jelinek             goto PackageTooSmall;
353*cb565728SJerry Jelinek         }
354*cb565728SJerry Jelinek 
355*cb565728SJerry Jelinek         while (Count > 0)
356*cb565728SJerry Jelinek         {
357*cb565728SJerry Jelinek             Status = AcpiNsCheckObjectType(Info, Elements,
358*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType1, 0);
359*cb565728SJerry Jelinek             if (ACPI_FAILURE(Status))
360*cb565728SJerry Jelinek             {
361*cb565728SJerry Jelinek                 return (Status);
362*cb565728SJerry Jelinek             }
363*cb565728SJerry Jelinek 
364*cb565728SJerry Jelinek             /* Validate length of the UUID buffer */
365*cb565728SJerry Jelinek 
366*cb565728SJerry Jelinek             if ((*Elements)->Buffer.Length != 16)
367*cb565728SJerry Jelinek             {
368*cb565728SJerry Jelinek                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
369*cb565728SJerry Jelinek                     Info->NodeFlags, "Invalid length for UUID Buffer"));
370*cb565728SJerry Jelinek                 return (AE_AML_OPERAND_VALUE);
371*cb565728SJerry Jelinek             }
372*cb565728SJerry Jelinek 
373*cb565728SJerry Jelinek             Status = AcpiNsCheckObjectType(Info, Elements + 1,
374*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType2, 0);
375*cb565728SJerry Jelinek             if (ACPI_FAILURE(Status))
376*cb565728SJerry Jelinek             {
377*cb565728SJerry Jelinek                 return (Status);
378*cb565728SJerry Jelinek             }
379*cb565728SJerry Jelinek 
380*cb565728SJerry Jelinek             Elements += 2;
381*cb565728SJerry Jelinek             Count -= 2;
382*cb565728SJerry Jelinek         }
383*cb565728SJerry Jelinek         break;
384*cb565728SJerry Jelinek 
385*cb565728SJerry Jelinek     default:
386*cb565728SJerry Jelinek 
387*cb565728SJerry Jelinek         /* Should not get here if predefined info table is correct */
388*cb565728SJerry Jelinek 
389*cb565728SJerry Jelinek         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
390*cb565728SJerry Jelinek             "Invalid internal return type in table entry: %X",
391*cb565728SJerry Jelinek             Package->RetInfo.Type));
392*cb565728SJerry Jelinek 
393*cb565728SJerry Jelinek         return (AE_AML_INTERNAL);
394*cb565728SJerry Jelinek     }
395*cb565728SJerry Jelinek 
396*cb565728SJerry Jelinek     return (Status);
397*cb565728SJerry Jelinek 
398*cb565728SJerry Jelinek 
399*cb565728SJerry Jelinek PackageTooSmall:
400*cb565728SJerry Jelinek 
401*cb565728SJerry Jelinek     /* Error exit for the case with an incorrect package count */
402*cb565728SJerry Jelinek 
403*cb565728SJerry Jelinek     ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
404*cb565728SJerry Jelinek         "Return Package is too small - found %u elements, expected %u",
405*cb565728SJerry Jelinek         Count, ExpectedCount));
406*cb565728SJerry Jelinek 
407*cb565728SJerry Jelinek     return (AE_AML_OPERAND_VALUE);
408*cb565728SJerry Jelinek }
409*cb565728SJerry Jelinek 
410*cb565728SJerry Jelinek 
411*cb565728SJerry Jelinek /*******************************************************************************
412*cb565728SJerry Jelinek  *
413*cb565728SJerry Jelinek  * FUNCTION:    AcpiNsCheckPackageList
414*cb565728SJerry Jelinek  *
415*cb565728SJerry Jelinek  * PARAMETERS:  Info            - Method execution information block
416*cb565728SJerry Jelinek  *              Package         - Pointer to package-specific info for method
417*cb565728SJerry Jelinek  *              Elements        - Element list of parent package. All elements
418*cb565728SJerry Jelinek  *                                of this list should be of type Package.
419*cb565728SJerry Jelinek  *              Count           - Count of subpackages
420*cb565728SJerry Jelinek  *
421*cb565728SJerry Jelinek  * RETURN:      Status
422*cb565728SJerry Jelinek  *
423*cb565728SJerry Jelinek  * DESCRIPTION: Examine a list of subpackages
424*cb565728SJerry Jelinek  *
425*cb565728SJerry Jelinek  ******************************************************************************/
426*cb565728SJerry Jelinek 
427*cb565728SJerry Jelinek static ACPI_STATUS
AcpiNsCheckPackageList(ACPI_EVALUATE_INFO * Info,const ACPI_PREDEFINED_INFO * Package,ACPI_OPERAND_OBJECT ** Elements,UINT32 Count)428*cb565728SJerry Jelinek AcpiNsCheckPackageList (
429*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
430*cb565728SJerry Jelinek     const ACPI_PREDEFINED_INFO  *Package,
431*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements,
432*cb565728SJerry Jelinek     UINT32                      Count)
433*cb565728SJerry Jelinek {
434*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         *SubPackage;
435*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **SubElements;
436*cb565728SJerry Jelinek     ACPI_STATUS                 Status;
437*cb565728SJerry Jelinek     UINT32                      ExpectedCount;
438*cb565728SJerry Jelinek     UINT32                      i;
439*cb565728SJerry Jelinek     UINT32                      j;
440*cb565728SJerry Jelinek 
441*cb565728SJerry Jelinek 
442*cb565728SJerry Jelinek     /*
443*cb565728SJerry Jelinek      * Validate each subpackage in the parent Package
444*cb565728SJerry Jelinek      *
445*cb565728SJerry Jelinek      * NOTE: assumes list of subpackages contains no NULL elements.
446*cb565728SJerry Jelinek      * Any NULL elements should have been removed by earlier call
447*cb565728SJerry Jelinek      * to AcpiNsRemoveNullElements.
448*cb565728SJerry Jelinek      */
449*cb565728SJerry Jelinek     for (i = 0; i < Count; i++)
450*cb565728SJerry Jelinek     {
451*cb565728SJerry Jelinek         SubPackage = *Elements;
452*cb565728SJerry Jelinek         SubElements = SubPackage->Package.Elements;
453*cb565728SJerry Jelinek         Info->ParentPackage = SubPackage;
454*cb565728SJerry Jelinek 
455*cb565728SJerry Jelinek         /* Each sub-object must be of type Package */
456*cb565728SJerry Jelinek 
457*cb565728SJerry Jelinek         Status = AcpiNsCheckObjectType (Info, &SubPackage,
458*cb565728SJerry Jelinek             ACPI_RTYPE_PACKAGE, i);
459*cb565728SJerry Jelinek         if (ACPI_FAILURE (Status))
460*cb565728SJerry Jelinek         {
461*cb565728SJerry Jelinek             return (Status);
462*cb565728SJerry Jelinek         }
463*cb565728SJerry Jelinek 
464*cb565728SJerry Jelinek         /* Examine the different types of expected subpackages */
465*cb565728SJerry Jelinek 
466*cb565728SJerry Jelinek         Info->ParentPackage = SubPackage;
467*cb565728SJerry Jelinek         switch (Package->RetInfo.Type)
468*cb565728SJerry Jelinek         {
469*cb565728SJerry Jelinek         case ACPI_PTYPE2:
470*cb565728SJerry Jelinek         case ACPI_PTYPE2_PKG_COUNT:
471*cb565728SJerry Jelinek         case ACPI_PTYPE2_REV_FIXED:
472*cb565728SJerry Jelinek 
473*cb565728SJerry Jelinek             /* Each subpackage has a fixed number of elements */
474*cb565728SJerry Jelinek 
475*cb565728SJerry Jelinek             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
476*cb565728SJerry Jelinek             if (SubPackage->Package.Count < ExpectedCount)
477*cb565728SJerry Jelinek             {
478*cb565728SJerry Jelinek                 goto PackageTooSmall;
479*cb565728SJerry Jelinek             }
480*cb565728SJerry Jelinek 
481*cb565728SJerry Jelinek             Status = AcpiNsCheckPackageElements (Info, SubElements,
482*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType1,
483*cb565728SJerry Jelinek                 Package->RetInfo.Count1,
484*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType2,
485*cb565728SJerry Jelinek                 Package->RetInfo.Count2, 0);
486*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
487*cb565728SJerry Jelinek             {
488*cb565728SJerry Jelinek                 return (Status);
489*cb565728SJerry Jelinek             }
490*cb565728SJerry Jelinek             break;
491*cb565728SJerry Jelinek 
492*cb565728SJerry Jelinek         case ACPI_PTYPE2_FIX_VAR:
493*cb565728SJerry Jelinek             /*
494*cb565728SJerry Jelinek              * Each subpackage has a fixed number of elements and an
495*cb565728SJerry Jelinek              * optional element
496*cb565728SJerry Jelinek              */
497*cb565728SJerry Jelinek             ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
498*cb565728SJerry Jelinek             if (SubPackage->Package.Count < ExpectedCount)
499*cb565728SJerry Jelinek             {
500*cb565728SJerry Jelinek                 goto PackageTooSmall;
501*cb565728SJerry Jelinek             }
502*cb565728SJerry Jelinek 
503*cb565728SJerry Jelinek             Status = AcpiNsCheckPackageElements (Info, SubElements,
504*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType1,
505*cb565728SJerry Jelinek                 Package->RetInfo.Count1,
506*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType2,
507*cb565728SJerry Jelinek                 SubPackage->Package.Count - Package->RetInfo.Count1, 0);
508*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
509*cb565728SJerry Jelinek             {
510*cb565728SJerry Jelinek                 return (Status);
511*cb565728SJerry Jelinek             }
512*cb565728SJerry Jelinek             break;
513*cb565728SJerry Jelinek 
514*cb565728SJerry Jelinek         case ACPI_PTYPE2_VAR_VAR:
515*cb565728SJerry Jelinek             /*
516*cb565728SJerry Jelinek              * Each subpackage has a fixed or variable number of elements
517*cb565728SJerry Jelinek              */
518*cb565728SJerry Jelinek             break;
519*cb565728SJerry Jelinek 
520*cb565728SJerry Jelinek         case ACPI_PTYPE2_FIXED:
521*cb565728SJerry Jelinek 
522*cb565728SJerry Jelinek             /* Each subpackage has a fixed length */
523*cb565728SJerry Jelinek 
524*cb565728SJerry Jelinek             ExpectedCount = Package->RetInfo2.Count;
525*cb565728SJerry Jelinek             if (SubPackage->Package.Count < ExpectedCount)
526*cb565728SJerry Jelinek             {
527*cb565728SJerry Jelinek                 goto PackageTooSmall;
528*cb565728SJerry Jelinek             }
529*cb565728SJerry Jelinek 
530*cb565728SJerry Jelinek             /* Check the type of each subpackage element */
531*cb565728SJerry Jelinek 
532*cb565728SJerry Jelinek             for (j = 0; j < ExpectedCount; j++)
533*cb565728SJerry Jelinek             {
534*cb565728SJerry Jelinek                 Status = AcpiNsCheckObjectType (Info, &SubElements[j],
535*cb565728SJerry Jelinek                     Package->RetInfo2.ObjectType[j], j);
536*cb565728SJerry Jelinek                 if (ACPI_FAILURE (Status))
537*cb565728SJerry Jelinek                 {
538*cb565728SJerry Jelinek                     return (Status);
539*cb565728SJerry Jelinek                 }
540*cb565728SJerry Jelinek             }
541*cb565728SJerry Jelinek             break;
542*cb565728SJerry Jelinek 
543*cb565728SJerry Jelinek         case ACPI_PTYPE2_MIN:
544*cb565728SJerry Jelinek 
545*cb565728SJerry Jelinek             /* Each subpackage has a variable but minimum length */
546*cb565728SJerry Jelinek 
547*cb565728SJerry Jelinek             ExpectedCount = Package->RetInfo.Count1;
548*cb565728SJerry Jelinek             if (SubPackage->Package.Count < ExpectedCount)
549*cb565728SJerry Jelinek             {
550*cb565728SJerry Jelinek                 goto PackageTooSmall;
551*cb565728SJerry Jelinek             }
552*cb565728SJerry Jelinek 
553*cb565728SJerry Jelinek             /* Check the type of each subpackage element */
554*cb565728SJerry Jelinek 
555*cb565728SJerry Jelinek             Status = AcpiNsCheckPackageElements (Info, SubElements,
556*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType1,
557*cb565728SJerry Jelinek                 SubPackage->Package.Count, 0, 0, 0);
558*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
559*cb565728SJerry Jelinek             {
560*cb565728SJerry Jelinek                 return (Status);
561*cb565728SJerry Jelinek             }
562*cb565728SJerry Jelinek             break;
563*cb565728SJerry Jelinek 
564*cb565728SJerry Jelinek         case ACPI_PTYPE2_COUNT:
565*cb565728SJerry Jelinek             /*
566*cb565728SJerry Jelinek              * First element is the (Integer) count of elements, including
567*cb565728SJerry Jelinek              * the count field (the ACPI name is NumElements)
568*cb565728SJerry Jelinek              */
569*cb565728SJerry Jelinek             Status = AcpiNsCheckObjectType (Info, SubElements,
570*cb565728SJerry Jelinek                 ACPI_RTYPE_INTEGER, 0);
571*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
572*cb565728SJerry Jelinek             {
573*cb565728SJerry Jelinek                 return (Status);
574*cb565728SJerry Jelinek             }
575*cb565728SJerry Jelinek 
576*cb565728SJerry Jelinek             /*
577*cb565728SJerry Jelinek              * Make sure package is large enough for the Count and is
578*cb565728SJerry Jelinek              * is as large as the minimum size
579*cb565728SJerry Jelinek              */
580*cb565728SJerry Jelinek             ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
581*cb565728SJerry Jelinek             if (SubPackage->Package.Count < ExpectedCount)
582*cb565728SJerry Jelinek             {
583*cb565728SJerry Jelinek                 goto PackageTooSmall;
584*cb565728SJerry Jelinek             }
585*cb565728SJerry Jelinek 
586*cb565728SJerry Jelinek             if (SubPackage->Package.Count < Package->RetInfo.Count1)
587*cb565728SJerry Jelinek             {
588*cb565728SJerry Jelinek                 ExpectedCount = Package->RetInfo.Count1;
589*cb565728SJerry Jelinek                 goto PackageTooSmall;
590*cb565728SJerry Jelinek             }
591*cb565728SJerry Jelinek 
592*cb565728SJerry Jelinek             if (ExpectedCount == 0)
593*cb565728SJerry Jelinek             {
594*cb565728SJerry Jelinek                 /*
595*cb565728SJerry Jelinek                  * Either the NumEntries element was originally zero or it was
596*cb565728SJerry Jelinek                  * a NULL element and repaired to an Integer of value zero.
597*cb565728SJerry Jelinek                  * In either case, repair it by setting NumEntries to be the
598*cb565728SJerry Jelinek                  * actual size of the subpackage.
599*cb565728SJerry Jelinek                  */
600*cb565728SJerry Jelinek                 ExpectedCount = SubPackage->Package.Count;
601*cb565728SJerry Jelinek                 (*SubElements)->Integer.Value = ExpectedCount;
602*cb565728SJerry Jelinek             }
603*cb565728SJerry Jelinek 
604*cb565728SJerry Jelinek             /* Check the type of each subpackage element */
605*cb565728SJerry Jelinek 
606*cb565728SJerry Jelinek             Status = AcpiNsCheckPackageElements (Info, (SubElements + 1),
607*cb565728SJerry Jelinek                 Package->RetInfo.ObjectType1,
608*cb565728SJerry Jelinek                 (ExpectedCount - 1), 0, 0, 1);
609*cb565728SJerry Jelinek             if (ACPI_FAILURE (Status))
610*cb565728SJerry Jelinek             {
611*cb565728SJerry Jelinek                 return (Status);
612*cb565728SJerry Jelinek             }
613*cb565728SJerry Jelinek             break;
614*cb565728SJerry Jelinek 
615*cb565728SJerry Jelinek         default: /* Should not get here, type was validated by caller */
616*cb565728SJerry Jelinek 
617*cb565728SJerry Jelinek             return (AE_AML_INTERNAL);
618*cb565728SJerry Jelinek         }
619*cb565728SJerry Jelinek 
620*cb565728SJerry Jelinek         Elements++;
621*cb565728SJerry Jelinek     }
622*cb565728SJerry Jelinek 
623*cb565728SJerry Jelinek     return (AE_OK);
624*cb565728SJerry Jelinek 
625*cb565728SJerry Jelinek 
626*cb565728SJerry Jelinek PackageTooSmall:
627*cb565728SJerry Jelinek 
628*cb565728SJerry Jelinek     /* The subpackage count was smaller than required */
629*cb565728SJerry Jelinek 
630*cb565728SJerry Jelinek     ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
631*cb565728SJerry Jelinek         "Return SubPackage[%u] is too small - found %u elements, expected %u",
632*cb565728SJerry Jelinek         i, SubPackage->Package.Count, ExpectedCount));
633*cb565728SJerry Jelinek 
634*cb565728SJerry Jelinek     return (AE_AML_OPERAND_VALUE);
635*cb565728SJerry Jelinek }
636*cb565728SJerry Jelinek 
637*cb565728SJerry Jelinek 
638*cb565728SJerry Jelinek /*******************************************************************************
639*cb565728SJerry Jelinek  *
640*cb565728SJerry Jelinek  * FUNCTION:    AcpiNsCustomPackage
641*cb565728SJerry Jelinek  *
642*cb565728SJerry Jelinek  * PARAMETERS:  Info                - Method execution information block
643*cb565728SJerry Jelinek  *              Elements            - Pointer to the package elements array
644*cb565728SJerry Jelinek  *              Count               - Element count for the package
645*cb565728SJerry Jelinek  *
646*cb565728SJerry Jelinek  * RETURN:      Status
647*cb565728SJerry Jelinek  *
648*cb565728SJerry Jelinek  * DESCRIPTION: Check a returned package object for the correct count and
649*cb565728SJerry Jelinek  *              correct type of all sub-objects.
650*cb565728SJerry Jelinek  *
651*cb565728SJerry Jelinek  * NOTE: Currently used for the _BIX method only. When needed for two or more
652*cb565728SJerry Jelinek  * methods, probably a detect/dispatch mechanism will be required.
653*cb565728SJerry Jelinek  *
654*cb565728SJerry Jelinek  ******************************************************************************/
655*cb565728SJerry Jelinek 
656*cb565728SJerry Jelinek static ACPI_STATUS
AcpiNsCustomPackage(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT ** Elements,UINT32 Count)657*cb565728SJerry Jelinek AcpiNsCustomPackage (
658*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
659*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements,
660*cb565728SJerry Jelinek     UINT32                      Count)
661*cb565728SJerry Jelinek {
662*cb565728SJerry Jelinek     UINT32                      ExpectedCount;
663*cb565728SJerry Jelinek     UINT32                      Version;
664*cb565728SJerry Jelinek     ACPI_STATUS                 Status = AE_OK;
665*cb565728SJerry Jelinek 
666*cb565728SJerry Jelinek 
667*cb565728SJerry Jelinek     ACPI_FUNCTION_NAME (NsCustomPackage);
668*cb565728SJerry Jelinek 
669*cb565728SJerry Jelinek 
670*cb565728SJerry Jelinek     /* Get version number, must be Integer */
671*cb565728SJerry Jelinek 
672*cb565728SJerry Jelinek     if ((*Elements)->Common.Type != ACPI_TYPE_INTEGER)
673*cb565728SJerry Jelinek     {
674*cb565728SJerry Jelinek         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
675*cb565728SJerry Jelinek             "Return Package has invalid object type for version number"));
676*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
677*cb565728SJerry Jelinek     }
678*cb565728SJerry Jelinek 
679*cb565728SJerry Jelinek     Version = (UINT32) (*Elements)->Integer.Value;
680*cb565728SJerry Jelinek     ExpectedCount = 21;         /* Version 1 */
681*cb565728SJerry Jelinek 
682*cb565728SJerry Jelinek     if (Version == 0)
683*cb565728SJerry Jelinek     {
684*cb565728SJerry Jelinek         ExpectedCount = 20;     /* Version 0 */
685*cb565728SJerry Jelinek     }
686*cb565728SJerry Jelinek 
687*cb565728SJerry Jelinek     if (Count < ExpectedCount)
688*cb565728SJerry Jelinek     {
689*cb565728SJerry Jelinek         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
690*cb565728SJerry Jelinek             "Return Package is too small - found %u elements, expected %u",
691*cb565728SJerry Jelinek             Count, ExpectedCount));
692*cb565728SJerry Jelinek         return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
693*cb565728SJerry Jelinek     }
694*cb565728SJerry Jelinek     else if (Count > ExpectedCount)
695*cb565728SJerry Jelinek     {
696*cb565728SJerry Jelinek         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
697*cb565728SJerry Jelinek             "%s: Return Package is larger than needed - "
698*cb565728SJerry Jelinek             "found %u, expected %u\n",
699*cb565728SJerry Jelinek             Info->FullPathname, Count, ExpectedCount));
700*cb565728SJerry Jelinek     }
701*cb565728SJerry Jelinek 
702*cb565728SJerry Jelinek     /* Validate all elements of the returned package */
703*cb565728SJerry Jelinek 
704*cb565728SJerry Jelinek     Status = AcpiNsCheckPackageElements (Info, Elements,
705*cb565728SJerry Jelinek         ACPI_RTYPE_INTEGER, 16,
706*cb565728SJerry Jelinek         ACPI_RTYPE_STRING, 4, 0);
707*cb565728SJerry Jelinek     if (ACPI_FAILURE (Status))
708*cb565728SJerry Jelinek     {
709*cb565728SJerry Jelinek         return_ACPI_STATUS (Status);
710*cb565728SJerry Jelinek     }
711*cb565728SJerry Jelinek 
712*cb565728SJerry Jelinek     /* Version 1 has a single trailing integer */
713*cb565728SJerry Jelinek 
714*cb565728SJerry Jelinek     if (Version > 0)
715*cb565728SJerry Jelinek     {
716*cb565728SJerry Jelinek         Status = AcpiNsCheckPackageElements (Info, Elements + 20,
717*cb565728SJerry Jelinek             ACPI_RTYPE_INTEGER, 1, 0, 0, 20);
718*cb565728SJerry Jelinek     }
719*cb565728SJerry Jelinek 
720*cb565728SJerry Jelinek     return_ACPI_STATUS (Status);
721*cb565728SJerry Jelinek }
722*cb565728SJerry Jelinek 
723*cb565728SJerry Jelinek 
724*cb565728SJerry Jelinek /*******************************************************************************
725*cb565728SJerry Jelinek  *
726*cb565728SJerry Jelinek  * FUNCTION:    AcpiNsCheckPackageElements
727*cb565728SJerry Jelinek  *
728*cb565728SJerry Jelinek  * PARAMETERS:  Info            - Method execution information block
729*cb565728SJerry Jelinek  *              Elements        - Pointer to the package elements array
730*cb565728SJerry Jelinek  *              Type1           - Object type for first group
731*cb565728SJerry Jelinek  *              Count1          - Count for first group
732*cb565728SJerry Jelinek  *              Type2           - Object type for second group
733*cb565728SJerry Jelinek  *              Count2          - Count for second group
734*cb565728SJerry Jelinek  *              StartIndex      - Start of the first group of elements
735*cb565728SJerry Jelinek  *
736*cb565728SJerry Jelinek  * RETURN:      Status
737*cb565728SJerry Jelinek  *
738*cb565728SJerry Jelinek  * DESCRIPTION: Check that all elements of a package are of the correct object
739*cb565728SJerry Jelinek  *              type. Supports up to two groups of different object types.
740*cb565728SJerry Jelinek  *
741*cb565728SJerry Jelinek  ******************************************************************************/
742*cb565728SJerry Jelinek 
743*cb565728SJerry Jelinek static ACPI_STATUS
AcpiNsCheckPackageElements(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT ** Elements,UINT8 Type1,UINT32 Count1,UINT8 Type2,UINT32 Count2,UINT32 StartIndex)744*cb565728SJerry Jelinek AcpiNsCheckPackageElements (
745*cb565728SJerry Jelinek     ACPI_EVALUATE_INFO          *Info,
746*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **Elements,
747*cb565728SJerry Jelinek     UINT8                       Type1,
748*cb565728SJerry Jelinek     UINT32                      Count1,
749*cb565728SJerry Jelinek     UINT8                       Type2,
750*cb565728SJerry Jelinek     UINT32                      Count2,
751*cb565728SJerry Jelinek     UINT32                      StartIndex)
752*cb565728SJerry Jelinek {
753*cb565728SJerry Jelinek     ACPI_OPERAND_OBJECT         **ThisElement = Elements;
754*cb565728SJerry Jelinek     ACPI_STATUS                 Status;
755*cb565728SJerry Jelinek     UINT32                      i;
756*cb565728SJerry Jelinek 
757*cb565728SJerry Jelinek 
758*cb565728SJerry Jelinek     /*
759*cb565728SJerry Jelinek      * Up to two groups of package elements are supported by the data
760*cb565728SJerry Jelinek      * structure. All elements in each group must be of the same type.
761*cb565728SJerry Jelinek      * The second group can have a count of zero.
762*cb565728SJerry Jelinek      */
763*cb565728SJerry Jelinek     for (i = 0; i < Count1; i++)
764*cb565728SJerry Jelinek     {
765*cb565728SJerry Jelinek         Status = AcpiNsCheckObjectType (Info, ThisElement,
766*cb565728SJerry Jelinek             Type1, i + StartIndex);
767*cb565728SJerry Jelinek         if (ACPI_FAILURE (Status))
768*cb565728SJerry Jelinek         {
769*cb565728SJerry Jelinek             return (Status);
770*cb565728SJerry Jelinek         }
771*cb565728SJerry Jelinek 
772*cb565728SJerry Jelinek         ThisElement++;
773*cb565728SJerry Jelinek     }
774*cb565728SJerry Jelinek 
775*cb565728SJerry Jelinek     for (i = 0; i < Count2; i++)
776*cb565728SJerry Jelinek     {
777*cb565728SJerry Jelinek         Status = AcpiNsCheckObjectType (Info, ThisElement,
778*cb565728SJerry Jelinek             Type2, (i + Count1 + StartIndex));
779*cb565728SJerry Jelinek         if (ACPI_FAILURE (Status))
780*cb565728SJerry Jelinek         {
781*cb565728SJerry Jelinek             return (Status);
782*cb565728SJerry Jelinek         }
783*cb565728SJerry Jelinek 
784*cb565728SJerry Jelinek         ThisElement++;
785*cb565728SJerry Jelinek     }
786*cb565728SJerry Jelinek 
787*cb565728SJerry Jelinek     return (AE_OK);
788*cb565728SJerry Jelinek }
789