1 /******************************************************************************
3 * Module Name: nsprepkg - Validation of package objects for predefined names
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2016, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "accommon.h"
118 #include "acnamesp.h"
119 #include "acpredef.h"
122 #define _COMPONENT ACPI_NAMESPACE
123 ACPI_MODULE_NAME ("nsprepkg")
126 /* Local prototypes */
129 AcpiNsCheckPackageList (
130 ACPI_EVALUATE_INFO
*Info
,
131 const ACPI_PREDEFINED_INFO
*Package
,
132 ACPI_OPERAND_OBJECT
**Elements
,
136 AcpiNsCheckPackageElements (
137 ACPI_EVALUATE_INFO
*Info
,
138 ACPI_OPERAND_OBJECT
**Elements
,
146 /*******************************************************************************
148 * FUNCTION: AcpiNsCheckPackage
150 * PARAMETERS: Info - Method execution information block
151 * ReturnObjectPtr - Pointer to the object returned from the
152 * evaluation of a method or object
156 * DESCRIPTION: Check a returned package object for the correct count and
157 * correct type of all sub-objects.
159 ******************************************************************************/
163 ACPI_EVALUATE_INFO
*Info
,
164 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
166 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
167 const ACPI_PREDEFINED_INFO
*Package
;
168 ACPI_OPERAND_OBJECT
**Elements
;
169 ACPI_STATUS Status
= AE_OK
;
170 UINT32 ExpectedCount
;
175 ACPI_FUNCTION_NAME (NsCheckPackage
);
178 /* The package info for this name is in the next table entry */
180 Package
= Info
->Predefined
+ 1;
182 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
183 "%s Validating return Package of Type %X, Count %X\n",
184 Info
->FullPathname
, Package
->RetInfo
.Type
,
185 ReturnObject
->Package
.Count
));
188 * For variable-length Packages, we can safely remove all embedded
189 * and trailing NULL package elements
191 AcpiNsRemoveNullElements (Info
, Package
->RetInfo
.Type
, ReturnObject
);
193 /* Extract package count and elements array */
195 Elements
= ReturnObject
->Package
.Elements
;
196 Count
= ReturnObject
->Package
.Count
;
199 * Most packages must have at least one element. The only exception
200 * is the variable-length package (ACPI_PTYPE1_VAR).
204 if (Package
->RetInfo
.Type
== ACPI_PTYPE1_VAR
)
209 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
210 "Return Package has no elements (empty)"));
212 return (AE_AML_OPERAND_VALUE
);
216 * Decode the type of the expected package contents
218 * PTYPE1 packages contain no subpackages
219 * PTYPE2 packages contain subpackages
221 switch (Package
->RetInfo
.Type
)
223 case ACPI_PTYPE1_FIXED
:
225 * The package count is fixed and there are no subpackages
227 * If package is too small, exit.
228 * If package is larger than expected, issue warning but continue
230 ExpectedCount
= Package
->RetInfo
.Count1
+ Package
->RetInfo
.Count2
;
231 if (Count
< ExpectedCount
)
233 goto PackageTooSmall
;
235 else if (Count
> ExpectedCount
)
237 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR
,
238 "%s: Return Package is larger than needed - "
239 "found %u, expected %u\n",
240 Info
->FullPathname
, Count
, ExpectedCount
));
243 /* Validate all elements of the returned package */
245 Status
= AcpiNsCheckPackageElements (Info
, Elements
,
246 Package
->RetInfo
.ObjectType1
, Package
->RetInfo
.Count1
,
247 Package
->RetInfo
.ObjectType2
, Package
->RetInfo
.Count2
, 0);
250 case ACPI_PTYPE1_VAR
:
252 * The package count is variable, there are no subpackages, and all
253 * elements must be of the same type
255 for (i
= 0; i
< Count
; i
++)
257 Status
= AcpiNsCheckObjectType (Info
, Elements
,
258 Package
->RetInfo
.ObjectType1
, i
);
259 if (ACPI_FAILURE (Status
))
267 case ACPI_PTYPE1_OPTION
:
269 * The package count is variable, there are no subpackages. There are
270 * a fixed number of required elements, and a variable number of
273 * Check if package is at least as large as the minimum required
275 ExpectedCount
= Package
->RetInfo3
.Count
;
276 if (Count
< ExpectedCount
)
278 goto PackageTooSmall
;
281 /* Variable number of sub-objects */
283 for (i
= 0; i
< Count
; i
++)
285 if (i
< Package
->RetInfo3
.Count
)
287 /* These are the required package elements (0, 1, or 2) */
289 Status
= AcpiNsCheckObjectType (Info
, Elements
,
290 Package
->RetInfo3
.ObjectType
[i
], i
);
291 if (ACPI_FAILURE (Status
))
298 /* These are the optional package elements */
300 Status
= AcpiNsCheckObjectType (Info
, Elements
,
301 Package
->RetInfo3
.TailObjectType
, i
);
302 if (ACPI_FAILURE (Status
))
311 case ACPI_PTYPE2_REV_FIXED
:
313 /* First element is the (Integer) revision */
315 Status
= AcpiNsCheckObjectType (
316 Info
, Elements
, ACPI_RTYPE_INTEGER
, 0);
317 if (ACPI_FAILURE (Status
))
325 /* Examine the subpackages */
327 Status
= AcpiNsCheckPackageList (Info
, Package
, Elements
, Count
);
330 case ACPI_PTYPE2_PKG_COUNT
:
332 /* First element is the (Integer) count of subpackages to follow */
334 Status
= AcpiNsCheckObjectType (
335 Info
, Elements
, ACPI_RTYPE_INTEGER
, 0);
336 if (ACPI_FAILURE (Status
))
342 * Count cannot be larger than the parent package length, but allow it
343 * to be smaller. The >= accounts for the Integer above.
345 ExpectedCount
= (UINT32
) (*Elements
)->Integer
.Value
;
346 if (ExpectedCount
>= Count
)
348 goto PackageTooSmall
;
351 Count
= ExpectedCount
;
354 /* Examine the subpackages */
356 Status
= AcpiNsCheckPackageList (Info
, Package
, Elements
, Count
);
360 case ACPI_PTYPE2_FIXED
:
361 case ACPI_PTYPE2_MIN
:
362 case ACPI_PTYPE2_COUNT
:
363 case ACPI_PTYPE2_FIX_VAR
:
365 * These types all return a single Package that consists of a
366 * variable number of subpackages.
368 * First, ensure that the first element is a subpackage. If not,
369 * the BIOS may have incorrectly returned the object as a single
370 * package instead of a Package of Packages (a common error if
371 * there is only one entry). We may be able to repair this by
372 * wrapping the returned Package with a new outer Package.
374 if (*Elements
&& ((*Elements
)->Common
.Type
!= ACPI_TYPE_PACKAGE
))
376 /* Create the new outer package and populate it */
378 Status
= AcpiNsWrapWithPackage (
379 Info
, ReturnObject
, ReturnObjectPtr
);
380 if (ACPI_FAILURE (Status
))
385 /* Update locals to point to the new package (of 1 element) */
387 ReturnObject
= *ReturnObjectPtr
;
388 Elements
= ReturnObject
->Package
.Elements
;
392 /* Examine the subpackages */
394 Status
= AcpiNsCheckPackageList (Info
, Package
, Elements
, Count
);
397 case ACPI_PTYPE2_VAR_VAR
:
399 * Returns a variable list of packages, each with a variable list
404 case ACPI_PTYPE2_UUID_PAIR
:
406 /* The package must contain pairs of (UUID + type) */
410 ExpectedCount
= Count
+ 1;
411 goto PackageTooSmall
;
416 Status
= AcpiNsCheckObjectType(Info
, Elements
,
417 Package
->RetInfo
.ObjectType1
, 0);
418 if (ACPI_FAILURE(Status
))
423 /* Validate length of the UUID buffer */
425 if ((*Elements
)->Buffer
.Length
!= 16)
427 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
,
428 Info
->NodeFlags
, "Invalid length for UUID Buffer"));
429 return (AE_AML_OPERAND_VALUE
);
432 Status
= AcpiNsCheckObjectType(Info
, Elements
+ 1,
433 Package
->RetInfo
.ObjectType2
, 0);
434 if (ACPI_FAILURE(Status
))
446 /* Should not get here if predefined info table is correct */
448 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
449 "Invalid internal return type in table entry: %X",
450 Package
->RetInfo
.Type
));
452 return (AE_AML_INTERNAL
);
460 /* Error exit for the case with an incorrect package count */
462 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
463 "Return Package is too small - found %u elements, expected %u",
464 Count
, ExpectedCount
));
466 return (AE_AML_OPERAND_VALUE
);
470 /*******************************************************************************
472 * FUNCTION: AcpiNsCheckPackageList
474 * PARAMETERS: Info - Method execution information block
475 * Package - Pointer to package-specific info for method
476 * Elements - Element list of parent package. All elements
477 * of this list should be of type Package.
478 * Count - Count of subpackages
482 * DESCRIPTION: Examine a list of subpackages
484 ******************************************************************************/
487 AcpiNsCheckPackageList (
488 ACPI_EVALUATE_INFO
*Info
,
489 const ACPI_PREDEFINED_INFO
*Package
,
490 ACPI_OPERAND_OBJECT
**Elements
,
493 ACPI_OPERAND_OBJECT
*SubPackage
;
494 ACPI_OPERAND_OBJECT
**SubElements
;
496 UINT32 ExpectedCount
;
502 * Validate each subpackage in the parent Package
504 * NOTE: assumes list of subpackages contains no NULL elements.
505 * Any NULL elements should have been removed by earlier call
506 * to AcpiNsRemoveNullElements.
508 for (i
= 0; i
< Count
; i
++)
510 SubPackage
= *Elements
;
511 SubElements
= SubPackage
->Package
.Elements
;
512 Info
->ParentPackage
= SubPackage
;
514 /* Each sub-object must be of type Package */
516 Status
= AcpiNsCheckObjectType (Info
, &SubPackage
,
517 ACPI_RTYPE_PACKAGE
, i
);
518 if (ACPI_FAILURE (Status
))
523 /* Examine the different types of expected subpackages */
525 Info
->ParentPackage
= SubPackage
;
526 switch (Package
->RetInfo
.Type
)
529 case ACPI_PTYPE2_PKG_COUNT
:
530 case ACPI_PTYPE2_REV_FIXED
:
532 /* Each subpackage has a fixed number of elements */
534 ExpectedCount
= Package
->RetInfo
.Count1
+ Package
->RetInfo
.Count2
;
535 if (SubPackage
->Package
.Count
< ExpectedCount
)
537 goto PackageTooSmall
;
540 Status
= AcpiNsCheckPackageElements (Info
, SubElements
,
541 Package
->RetInfo
.ObjectType1
,
542 Package
->RetInfo
.Count1
,
543 Package
->RetInfo
.ObjectType2
,
544 Package
->RetInfo
.Count2
, 0);
545 if (ACPI_FAILURE (Status
))
551 case ACPI_PTYPE2_FIX_VAR
:
553 * Each subpackage has a fixed number of elements and an
556 ExpectedCount
= Package
->RetInfo
.Count1
+ Package
->RetInfo
.Count2
;
557 if (SubPackage
->Package
.Count
< ExpectedCount
)
559 goto PackageTooSmall
;
562 Status
= AcpiNsCheckPackageElements (Info
, SubElements
,
563 Package
->RetInfo
.ObjectType1
,
564 Package
->RetInfo
.Count1
,
565 Package
->RetInfo
.ObjectType2
,
566 SubPackage
->Package
.Count
- Package
->RetInfo
.Count1
, 0);
567 if (ACPI_FAILURE (Status
))
573 case ACPI_PTYPE2_VAR_VAR
:
575 * Each subpackage has a fixed or variable number of elements
579 case ACPI_PTYPE2_FIXED
:
581 /* Each subpackage has a fixed length */
583 ExpectedCount
= Package
->RetInfo2
.Count
;
584 if (SubPackage
->Package
.Count
< ExpectedCount
)
586 goto PackageTooSmall
;
589 /* Check the type of each subpackage element */
591 for (j
= 0; j
< ExpectedCount
; j
++)
593 Status
= AcpiNsCheckObjectType (Info
, &SubElements
[j
],
594 Package
->RetInfo2
.ObjectType
[j
], j
);
595 if (ACPI_FAILURE (Status
))
602 case ACPI_PTYPE2_MIN
:
604 /* Each subpackage has a variable but minimum length */
606 ExpectedCount
= Package
->RetInfo
.Count1
;
607 if (SubPackage
->Package
.Count
< ExpectedCount
)
609 goto PackageTooSmall
;
612 /* Check the type of each subpackage element */
614 Status
= AcpiNsCheckPackageElements (Info
, SubElements
,
615 Package
->RetInfo
.ObjectType1
,
616 SubPackage
->Package
.Count
, 0, 0, 0);
617 if (ACPI_FAILURE (Status
))
623 case ACPI_PTYPE2_COUNT
:
625 * First element is the (Integer) count of elements, including
626 * the count field (the ACPI name is NumElements)
628 Status
= AcpiNsCheckObjectType (Info
, SubElements
,
629 ACPI_RTYPE_INTEGER
, 0);
630 if (ACPI_FAILURE (Status
))
636 * Make sure package is large enough for the Count and is
637 * is as large as the minimum size
639 ExpectedCount
= (UINT32
) (*SubElements
)->Integer
.Value
;
640 if (SubPackage
->Package
.Count
< ExpectedCount
)
642 goto PackageTooSmall
;
644 if (SubPackage
->Package
.Count
< Package
->RetInfo
.Count1
)
646 ExpectedCount
= Package
->RetInfo
.Count1
;
647 goto PackageTooSmall
;
649 if (ExpectedCount
== 0)
652 * Either the NumEntries element was originally zero or it was
653 * a NULL element and repaired to an Integer of value zero.
654 * In either case, repair it by setting NumEntries to be the
655 * actual size of the subpackage.
657 ExpectedCount
= SubPackage
->Package
.Count
;
658 (*SubElements
)->Integer
.Value
= ExpectedCount
;
661 /* Check the type of each subpackage element */
663 Status
= AcpiNsCheckPackageElements (Info
, (SubElements
+ 1),
664 Package
->RetInfo
.ObjectType1
,
665 (ExpectedCount
- 1), 0, 0, 1);
666 if (ACPI_FAILURE (Status
))
672 default: /* Should not get here, type was validated by caller */
674 return (AE_AML_INTERNAL
);
685 /* The subpackage count was smaller than required */
687 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
688 "Return SubPackage[%u] is too small - found %u elements, expected %u",
689 i
, SubPackage
->Package
.Count
, ExpectedCount
));
691 return (AE_AML_OPERAND_VALUE
);
695 /*******************************************************************************
697 * FUNCTION: AcpiNsCheckPackageElements
699 * PARAMETERS: Info - Method execution information block
700 * Elements - Pointer to the package elements array
701 * Type1 - Object type for first group
702 * Count1 - Count for first group
703 * Type2 - Object type for second group
704 * Count2 - Count for second group
705 * StartIndex - Start of the first group of elements
709 * DESCRIPTION: Check that all elements of a package are of the correct object
710 * type. Supports up to two groups of different object types.
712 ******************************************************************************/
715 AcpiNsCheckPackageElements (
716 ACPI_EVALUATE_INFO
*Info
,
717 ACPI_OPERAND_OBJECT
**Elements
,
724 ACPI_OPERAND_OBJECT
**ThisElement
= Elements
;
730 * Up to two groups of package elements are supported by the data
731 * structure. All elements in each group must be of the same type.
732 * The second group can have a count of zero.
734 for (i
= 0; i
< Count1
; i
++)
736 Status
= AcpiNsCheckObjectType (Info
, ThisElement
,
737 Type1
, i
+ StartIndex
);
738 if (ACPI_FAILURE (Status
))
745 for (i
= 0; i
< Count2
; i
++)
747 Status
= AcpiNsCheckObjectType (Info
, ThisElement
,
748 Type2
, (i
+ Count1
+ StartIndex
));
749 if (ACPI_FAILURE (Status
))