1 /******************************************************************************
3 * Module Name: nsprepkg - Validation of package objects for predefined names
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsprepkg")
54 /* Local prototypes */
57 AcpiNsCheckPackageList (
58 ACPI_EVALUATE_INFO *Info,
59 const ACPI_PREDEFINED_INFO *Package,
60 ACPI_OPERAND_OBJECT **Elements,
64 AcpiNsCheckPackageElements (
65 ACPI_EVALUATE_INFO *Info,
66 ACPI_OPERAND_OBJECT **Elements,
74 /*******************************************************************************
76 * FUNCTION: AcpiNsCheckPackage
78 * PARAMETERS: Info - Method execution information block
79 * ReturnObjectPtr - Pointer to the object returned from the
80 * evaluation of a method or object
84 * DESCRIPTION: Check a returned package object for the correct count and
85 * correct type of all sub-objects.
87 ******************************************************************************/
91 ACPI_EVALUATE_INFO *Info,
92 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
94 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
95 const ACPI_PREDEFINED_INFO *Package;
96 ACPI_OPERAND_OBJECT **Elements;
97 ACPI_STATUS Status = AE_OK;
103 ACPI_FUNCTION_NAME (NsCheckPackage);
106 /* The package info for this name is in the next table entry */
108 Package = Info->Predefined + 1;
110 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
111 "%s Validating return Package of Type %X, Count %X\n",
112 Info->FullPathname, Package->RetInfo.Type,
113 ReturnObject->Package.Count));
116 * For variable-length Packages, we can safely remove all embedded
117 * and trailing NULL package elements
119 AcpiNsRemoveNullElements (Info, Package->RetInfo.Type, ReturnObject);
121 /* Extract package count and elements array */
123 Elements = ReturnObject->Package.Elements;
124 Count = ReturnObject->Package.Count;
127 * Most packages must have at least one element. The only exception
128 * is the variable-length package (ACPI_PTYPE1_VAR).
132 if (Package->RetInfo.Type == ACPI_PTYPE1_VAR)
137 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
138 "Return Package has no elements (empty)"));
140 return (AE_AML_OPERAND_VALUE);
144 * Decode the type of the expected package contents
146 * PTYPE1 packages contain no subpackages
147 * PTYPE2 packages contain subpackages
149 switch (Package->RetInfo.Type)
151 case ACPI_PTYPE1_FIXED:
153 * The package count is fixed and there are no subpackages
155 * If package is too small, exit.
156 * If package is larger than expected, issue warning but continue
158 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
159 if (Count < ExpectedCount)
161 goto PackageTooSmall;
163 else if (Count > ExpectedCount)
165 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
166 "%s: Return Package is larger than needed - "
167 "found %u, expected %u\n",
168 Info->FullPathname, Count, ExpectedCount));
171 /* Validate all elements of the returned package */
173 Status = AcpiNsCheckPackageElements (Info, Elements,
174 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
175 Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
178 case ACPI_PTYPE1_VAR:
180 * The package count is variable, there are no subpackages, and all
181 * elements must be of the same type
183 for (i = 0; i < Count; i++)
185 Status = AcpiNsCheckObjectType (Info, Elements,
186 Package->RetInfo.ObjectType1, i);
187 if (ACPI_FAILURE (Status))
195 case ACPI_PTYPE1_OPTION:
197 * The package count is variable, there are no subpackages. There are
198 * a fixed number of required elements, and a variable number of
201 * Check if package is at least as large as the minimum required
203 ExpectedCount = Package->RetInfo3.Count;
204 if (Count < ExpectedCount)
206 goto PackageTooSmall;
209 /* Variable number of sub-objects */
211 for (i = 0; i < Count; i++)
213 if (i < Package->RetInfo3.Count)
215 /* These are the required package elements (0, 1, or 2) */
217 Status = AcpiNsCheckObjectType (Info, Elements,
218 Package->RetInfo3.ObjectType[i], i);
219 if (ACPI_FAILURE (Status))
226 /* These are the optional package elements */
228 Status = AcpiNsCheckObjectType (Info, Elements,
229 Package->RetInfo3.TailObjectType, i);
230 if (ACPI_FAILURE (Status))
239 case ACPI_PTYPE2_REV_FIXED:
241 /* First element is the (Integer) revision */
243 Status = AcpiNsCheckObjectType (
244 Info, Elements, ACPI_RTYPE_INTEGER, 0);
245 if (ACPI_FAILURE (Status))
253 /* Examine the subpackages */
255 Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
258 case ACPI_PTYPE2_PKG_COUNT:
260 /* First element is the (Integer) count of subpackages to follow */
262 Status = AcpiNsCheckObjectType (
263 Info, Elements, ACPI_RTYPE_INTEGER, 0);
264 if (ACPI_FAILURE (Status))
270 * Count cannot be larger than the parent package length, but allow it
271 * to be smaller. The >= accounts for the Integer above.
273 ExpectedCount = (UINT32) (*Elements)->Integer.Value;
274 if (ExpectedCount >= Count)
276 goto PackageTooSmall;
279 Count = ExpectedCount;
282 /* Examine the subpackages */
284 Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
288 case ACPI_PTYPE2_FIXED:
289 case ACPI_PTYPE2_MIN:
290 case ACPI_PTYPE2_COUNT:
291 case ACPI_PTYPE2_FIX_VAR:
293 * These types all return a single Package that consists of a
294 * variable number of subpackages.
296 * First, ensure that the first element is a subpackage. If not,
297 * the BIOS may have incorrectly returned the object as a single
298 * package instead of a Package of Packages (a common error if
299 * there is only one entry). We may be able to repair this by
300 * wrapping the returned Package with a new outer Package.
302 if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
304 /* Create the new outer package and populate it */
306 Status = AcpiNsWrapWithPackage (
307 Info, ReturnObject, ReturnObjectPtr);
308 if (ACPI_FAILURE (Status))
313 /* Update locals to point to the new package (of 1 element) */
315 ReturnObject = *ReturnObjectPtr;
316 Elements = ReturnObject->Package.Elements;
320 /* Examine the subpackages */
322 Status = AcpiNsCheckPackageList (Info, Package, Elements, Count);
325 case ACPI_PTYPE2_VAR_VAR:
327 * Returns a variable list of packages, each with a variable list
332 case ACPI_PTYPE2_UUID_PAIR:
334 /* The package must contain pairs of (UUID + type) */
338 ExpectedCount = Count + 1;
339 goto PackageTooSmall;
344 Status = AcpiNsCheckObjectType(Info, Elements,
345 Package->RetInfo.ObjectType1, 0);
346 if (ACPI_FAILURE(Status))
351 /* Validate length of the UUID buffer */
353 if ((*Elements)->Buffer.Length != 16)
355 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
356 Info->NodeFlags, "Invalid length for UUID Buffer"));
357 return (AE_AML_OPERAND_VALUE);
360 Status = AcpiNsCheckObjectType(Info, Elements + 1,
361 Package->RetInfo.ObjectType2, 0);
362 if (ACPI_FAILURE(Status))
374 /* Should not get here if predefined info table is correct */
376 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
377 "Invalid internal return type in table entry: %X",
378 Package->RetInfo.Type));
380 return (AE_AML_INTERNAL);
388 /* Error exit for the case with an incorrect package count */
390 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
391 "Return Package is too small - found %u elements, expected %u",
392 Count, ExpectedCount));
394 return (AE_AML_OPERAND_VALUE);
398 /*******************************************************************************
400 * FUNCTION: AcpiNsCheckPackageList
402 * PARAMETERS: Info - Method execution information block
403 * Package - Pointer to package-specific info for method
404 * Elements - Element list of parent package. All elements
405 * of this list should be of type Package.
406 * Count - Count of subpackages
410 * DESCRIPTION: Examine a list of subpackages
412 ******************************************************************************/
415 AcpiNsCheckPackageList (
416 ACPI_EVALUATE_INFO *Info,
417 const ACPI_PREDEFINED_INFO *Package,
418 ACPI_OPERAND_OBJECT **Elements,
421 ACPI_OPERAND_OBJECT *SubPackage;
422 ACPI_OPERAND_OBJECT **SubElements;
424 UINT32 ExpectedCount;
430 * Validate each subpackage in the parent Package
432 * NOTE: assumes list of subpackages contains no NULL elements.
433 * Any NULL elements should have been removed by earlier call
434 * to AcpiNsRemoveNullElements.
436 for (i = 0; i < Count; i++)
438 SubPackage = *Elements;
439 SubElements = SubPackage->Package.Elements;
440 Info->ParentPackage = SubPackage;
442 /* Each sub-object must be of type Package */
444 Status = AcpiNsCheckObjectType (Info, &SubPackage,
445 ACPI_RTYPE_PACKAGE, i);
446 if (ACPI_FAILURE (Status))
451 /* Examine the different types of expected subpackages */
453 Info->ParentPackage = SubPackage;
454 switch (Package->RetInfo.Type)
457 case ACPI_PTYPE2_PKG_COUNT:
458 case ACPI_PTYPE2_REV_FIXED:
460 /* Each subpackage has a fixed number of elements */
462 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
463 if (SubPackage->Package.Count < ExpectedCount)
465 goto PackageTooSmall;
468 Status = AcpiNsCheckPackageElements (Info, SubElements,
469 Package->RetInfo.ObjectType1,
470 Package->RetInfo.Count1,
471 Package->RetInfo.ObjectType2,
472 Package->RetInfo.Count2, 0);
473 if (ACPI_FAILURE (Status))
479 case ACPI_PTYPE2_FIX_VAR:
481 * Each subpackage has a fixed number of elements and an
484 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
485 if (SubPackage->Package.Count < ExpectedCount)
487 goto PackageTooSmall;
490 Status = AcpiNsCheckPackageElements (Info, SubElements,
491 Package->RetInfo.ObjectType1,
492 Package->RetInfo.Count1,
493 Package->RetInfo.ObjectType2,
494 SubPackage->Package.Count - Package->RetInfo.Count1, 0);
495 if (ACPI_FAILURE (Status))
501 case ACPI_PTYPE2_VAR_VAR:
503 * Each subpackage has a fixed or variable number of elements
507 case ACPI_PTYPE2_FIXED:
509 /* Each subpackage has a fixed length */
511 ExpectedCount = Package->RetInfo2.Count;
512 if (SubPackage->Package.Count < ExpectedCount)
514 goto PackageTooSmall;
517 /* Check the type of each subpackage element */
519 for (j = 0; j < ExpectedCount; j++)
521 Status = AcpiNsCheckObjectType (Info, &SubElements[j],
522 Package->RetInfo2.ObjectType[j], j);
523 if (ACPI_FAILURE (Status))
530 case ACPI_PTYPE2_MIN:
532 /* Each subpackage has a variable but minimum length */
534 ExpectedCount = Package->RetInfo.Count1;
535 if (SubPackage->Package.Count < ExpectedCount)
537 goto PackageTooSmall;
540 /* Check the type of each subpackage element */
542 Status = AcpiNsCheckPackageElements (Info, SubElements,
543 Package->RetInfo.ObjectType1,
544 SubPackage->Package.Count, 0, 0, 0);
545 if (ACPI_FAILURE (Status))
551 case ACPI_PTYPE2_COUNT:
553 * First element is the (Integer) count of elements, including
554 * the count field (the ACPI name is NumElements)
556 Status = AcpiNsCheckObjectType (Info, SubElements,
557 ACPI_RTYPE_INTEGER, 0);
558 if (ACPI_FAILURE (Status))
564 * Make sure package is large enough for the Count and is
565 * is as large as the minimum size
567 ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
568 if (SubPackage->Package.Count < ExpectedCount)
570 goto PackageTooSmall;
572 if (SubPackage->Package.Count < Package->RetInfo.Count1)
574 ExpectedCount = Package->RetInfo.Count1;
575 goto PackageTooSmall;
577 if (ExpectedCount == 0)
580 * Either the NumEntries element was originally zero or it was
581 * a NULL element and repaired to an Integer of value zero.
582 * In either case, repair it by setting NumEntries to be the
583 * actual size of the subpackage.
585 ExpectedCount = SubPackage->Package.Count;
586 (*SubElements)->Integer.Value = ExpectedCount;
589 /* Check the type of each subpackage element */
591 Status = AcpiNsCheckPackageElements (Info, (SubElements + 1),
592 Package->RetInfo.ObjectType1,
593 (ExpectedCount - 1), 0, 0, 1);
594 if (ACPI_FAILURE (Status))
600 default: /* Should not get here, type was validated by caller */
602 return (AE_AML_INTERNAL);
613 /* The subpackage count was smaller than required */
615 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
616 "Return SubPackage[%u] is too small - found %u elements, expected %u",
617 i, SubPackage->Package.Count, ExpectedCount));
619 return (AE_AML_OPERAND_VALUE);
623 /*******************************************************************************
625 * FUNCTION: AcpiNsCheckPackageElements
627 * PARAMETERS: Info - Method execution information block
628 * Elements - Pointer to the package elements array
629 * Type1 - Object type for first group
630 * Count1 - Count for first group
631 * Type2 - Object type for second group
632 * Count2 - Count for second group
633 * StartIndex - Start of the first group of elements
637 * DESCRIPTION: Check that all elements of a package are of the correct object
638 * type. Supports up to two groups of different object types.
640 ******************************************************************************/
643 AcpiNsCheckPackageElements (
644 ACPI_EVALUATE_INFO *Info,
645 ACPI_OPERAND_OBJECT **Elements,
652 ACPI_OPERAND_OBJECT **ThisElement = Elements;
658 * Up to two groups of package elements are supported by the data
659 * structure. All elements in each group must be of the same type.
660 * The second group can have a count of zero.
662 for (i = 0; i < Count1; i++)
664 Status = AcpiNsCheckObjectType (Info, ThisElement,
665 Type1, i + StartIndex);
666 if (ACPI_FAILURE (Status))
673 for (i = 0; i < Count2; i++)
675 Status = AcpiNsCheckObjectType (Info, ThisElement,
676 Type2, (i + Count1 + StartIndex));
677 if (ACPI_FAILURE (Status))