141251f8519e285dda4230128cff882e9fb8b553
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
))
196 case ACPI_PTYPE1_OPTION
:
198 * The package count is variable, there are no subpackages. There are
199 * a fixed number of required elements, and a variable number of
202 * Check if package is at least as large as the minimum required
204 ExpectedCount
= Package
->RetInfo3
.Count
;
205 if (Count
< ExpectedCount
)
207 goto PackageTooSmall
;
210 /* Variable number of sub-objects */
212 for (i
= 0; i
< Count
; i
++)
214 if (i
< Package
->RetInfo3
.Count
)
216 /* These are the required package elements (0, 1, or 2) */
218 Status
= AcpiNsCheckObjectType (Info
, Elements
,
219 Package
->RetInfo3
.ObjectType
[i
], i
);
220 if (ACPI_FAILURE (Status
))
227 /* These are the optional package elements */
229 Status
= AcpiNsCheckObjectType (Info
, Elements
,
230 Package
->RetInfo3
.TailObjectType
, i
);
231 if (ACPI_FAILURE (Status
))
241 case ACPI_PTYPE2_REV_FIXED
:
243 /* First element is the (Integer) revision */
245 Status
= AcpiNsCheckObjectType (
246 Info
, Elements
, ACPI_RTYPE_INTEGER
, 0);
247 if (ACPI_FAILURE (Status
))
255 /* Examine the subpackages */
257 Status
= AcpiNsCheckPackageList (Info
, Package
, Elements
, Count
);
260 case ACPI_PTYPE2_PKG_COUNT
:
262 /* First element is the (Integer) count of subpackages to follow */
264 Status
= AcpiNsCheckObjectType (
265 Info
, Elements
, ACPI_RTYPE_INTEGER
, 0);
266 if (ACPI_FAILURE (Status
))
272 * Count cannot be larger than the parent package length, but allow it
273 * to be smaller. The >= accounts for the Integer above.
275 ExpectedCount
= (UINT32
) (*Elements
)->Integer
.Value
;
276 if (ExpectedCount
>= Count
)
278 goto PackageTooSmall
;
281 Count
= ExpectedCount
;
284 /* Examine the subpackages */
286 Status
= AcpiNsCheckPackageList (Info
, Package
, Elements
, Count
);
290 case ACPI_PTYPE2_FIXED
:
291 case ACPI_PTYPE2_MIN
:
292 case ACPI_PTYPE2_COUNT
:
293 case ACPI_PTYPE2_FIX_VAR
:
295 * These types all return a single Package that consists of a
296 * variable number of subpackages.
298 * First, ensure that the first element is a subpackage. If not,
299 * the BIOS may have incorrectly returned the object as a single
300 * package instead of a Package of Packages (a common error if
301 * there is only one entry). We may be able to repair this by
302 * wrapping the returned Package with a new outer Package.
304 if (*Elements
&& ((*Elements
)->Common
.Type
!= ACPI_TYPE_PACKAGE
))
306 /* Create the new outer package and populate it */
308 Status
= AcpiNsWrapWithPackage (
309 Info
, ReturnObject
, ReturnObjectPtr
);
310 if (ACPI_FAILURE (Status
))
315 /* Update locals to point to the new package (of 1 element) */
317 ReturnObject
= *ReturnObjectPtr
;
318 Elements
= ReturnObject
->Package
.Elements
;
322 /* Examine the subpackages */
324 Status
= AcpiNsCheckPackageList (Info
, Package
, Elements
, Count
);
327 case ACPI_PTYPE2_VAR_VAR
:
329 * Returns a variable list of packages, each with a variable list
334 case ACPI_PTYPE2_UUID_PAIR
:
336 /* The package must contain pairs of (UUID + type) */
340 ExpectedCount
= Count
+ 1;
341 goto PackageTooSmall
;
346 Status
= AcpiNsCheckObjectType(Info
, Elements
,
347 Package
->RetInfo
.ObjectType1
, 0);
348 if (ACPI_FAILURE(Status
))
353 /* Validate length of the UUID buffer */
355 if ((*Elements
)->Buffer
.Length
!= 16)
357 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
,
358 Info
->NodeFlags
, "Invalid length for UUID Buffer"));
359 return (AE_AML_OPERAND_VALUE
);
362 Status
= AcpiNsCheckObjectType(Info
, Elements
+ 1,
363 Package
->RetInfo
.ObjectType2
, 0);
364 if (ACPI_FAILURE(Status
))
376 /* Should not get here if predefined info table is correct */
378 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
379 "Invalid internal return type in table entry: %X",
380 Package
->RetInfo
.Type
));
382 return (AE_AML_INTERNAL
);
390 /* Error exit for the case with an incorrect package count */
392 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
393 "Return Package is too small - found %u elements, expected %u",
394 Count
, ExpectedCount
));
396 return (AE_AML_OPERAND_VALUE
);
400 /*******************************************************************************
402 * FUNCTION: AcpiNsCheckPackageList
404 * PARAMETERS: Info - Method execution information block
405 * Package - Pointer to package-specific info for method
406 * Elements - Element list of parent package. All elements
407 * of this list should be of type Package.
408 * Count - Count of subpackages
412 * DESCRIPTION: Examine a list of subpackages
414 ******************************************************************************/
417 AcpiNsCheckPackageList (
418 ACPI_EVALUATE_INFO
*Info
,
419 const ACPI_PREDEFINED_INFO
*Package
,
420 ACPI_OPERAND_OBJECT
**Elements
,
423 ACPI_OPERAND_OBJECT
*SubPackage
;
424 ACPI_OPERAND_OBJECT
**SubElements
;
426 UINT32 ExpectedCount
;
432 * Validate each subpackage in the parent Package
434 * NOTE: assumes list of subpackages contains no NULL elements.
435 * Any NULL elements should have been removed by earlier call
436 * to AcpiNsRemoveNullElements.
438 for (i
= 0; i
< Count
; i
++)
440 SubPackage
= *Elements
;
441 SubElements
= SubPackage
->Package
.Elements
;
442 Info
->ParentPackage
= SubPackage
;
444 /* Each sub-object must be of type Package */
446 Status
= AcpiNsCheckObjectType (Info
, &SubPackage
,
447 ACPI_RTYPE_PACKAGE
, i
);
448 if (ACPI_FAILURE (Status
))
453 /* Examine the different types of expected subpackages */
455 Info
->ParentPackage
= SubPackage
;
456 switch (Package
->RetInfo
.Type
)
459 case ACPI_PTYPE2_PKG_COUNT
:
460 case ACPI_PTYPE2_REV_FIXED
:
462 /* Each subpackage has a fixed number of elements */
464 ExpectedCount
= Package
->RetInfo
.Count1
+ Package
->RetInfo
.Count2
;
465 if (SubPackage
->Package
.Count
< ExpectedCount
)
467 goto PackageTooSmall
;
470 Status
= AcpiNsCheckPackageElements (Info
, SubElements
,
471 Package
->RetInfo
.ObjectType1
,
472 Package
->RetInfo
.Count1
,
473 Package
->RetInfo
.ObjectType2
,
474 Package
->RetInfo
.Count2
, 0);
475 if (ACPI_FAILURE (Status
))
481 case ACPI_PTYPE2_FIX_VAR
:
483 * Each subpackage has a fixed number of elements and an
486 ExpectedCount
= Package
->RetInfo
.Count1
+ Package
->RetInfo
.Count2
;
487 if (SubPackage
->Package
.Count
< ExpectedCount
)
489 goto PackageTooSmall
;
492 Status
= AcpiNsCheckPackageElements (Info
, SubElements
,
493 Package
->RetInfo
.ObjectType1
,
494 Package
->RetInfo
.Count1
,
495 Package
->RetInfo
.ObjectType2
,
496 SubPackage
->Package
.Count
- Package
->RetInfo
.Count1
, 0);
497 if (ACPI_FAILURE (Status
))
503 case ACPI_PTYPE2_VAR_VAR
:
505 * Each subpackage has a fixed or variable number of elements
509 case ACPI_PTYPE2_FIXED
:
511 /* Each subpackage has a fixed length */
513 ExpectedCount
= Package
->RetInfo2
.Count
;
514 if (SubPackage
->Package
.Count
< ExpectedCount
)
516 goto PackageTooSmall
;
519 /* Check the type of each subpackage element */
521 for (j
= 0; j
< ExpectedCount
; j
++)
523 Status
= AcpiNsCheckObjectType (Info
, &SubElements
[j
],
524 Package
->RetInfo2
.ObjectType
[j
], j
);
525 if (ACPI_FAILURE (Status
))
532 case ACPI_PTYPE2_MIN
:
534 /* Each subpackage has a variable but minimum length */
536 ExpectedCount
= Package
->RetInfo
.Count1
;
537 if (SubPackage
->Package
.Count
< ExpectedCount
)
539 goto PackageTooSmall
;
542 /* Check the type of each subpackage element */
544 Status
= AcpiNsCheckPackageElements (Info
, SubElements
,
545 Package
->RetInfo
.ObjectType1
,
546 SubPackage
->Package
.Count
, 0, 0, 0);
547 if (ACPI_FAILURE (Status
))
553 case ACPI_PTYPE2_COUNT
:
555 * First element is the (Integer) count of elements, including
556 * the count field (the ACPI name is NumElements)
558 Status
= AcpiNsCheckObjectType (Info
, SubElements
,
559 ACPI_RTYPE_INTEGER
, 0);
560 if (ACPI_FAILURE (Status
))
566 * Make sure package is large enough for the Count and is
567 * is as large as the minimum size
569 ExpectedCount
= (UINT32
) (*SubElements
)->Integer
.Value
;
570 if (SubPackage
->Package
.Count
< ExpectedCount
)
572 goto PackageTooSmall
;
575 if (SubPackage
->Package
.Count
< Package
->RetInfo
.Count1
)
577 ExpectedCount
= Package
->RetInfo
.Count1
;
578 goto PackageTooSmall
;
581 if (ExpectedCount
== 0)
584 * Either the NumEntries element was originally zero or it was
585 * a NULL element and repaired to an Integer of value zero.
586 * In either case, repair it by setting NumEntries to be the
587 * actual size of the subpackage.
589 ExpectedCount
= SubPackage
->Package
.Count
;
590 (*SubElements
)->Integer
.Value
= ExpectedCount
;
593 /* Check the type of each subpackage element */
595 Status
= AcpiNsCheckPackageElements (Info
, (SubElements
+ 1),
596 Package
->RetInfo
.ObjectType1
,
597 (ExpectedCount
- 1), 0, 0, 1);
598 if (ACPI_FAILURE (Status
))
604 default: /* Should not get here, type was validated by caller */
606 return (AE_AML_INTERNAL
);
617 /* The subpackage count was smaller than required */
619 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
620 "Return SubPackage[%u] is too small - found %u elements, expected %u",
621 i
, SubPackage
->Package
.Count
, ExpectedCount
));
623 return (AE_AML_OPERAND_VALUE
);
627 /*******************************************************************************
629 * FUNCTION: AcpiNsCheckPackageElements
631 * PARAMETERS: Info - Method execution information block
632 * Elements - Pointer to the package elements array
633 * Type1 - Object type for first group
634 * Count1 - Count for first group
635 * Type2 - Object type for second group
636 * Count2 - Count for second group
637 * StartIndex - Start of the first group of elements
641 * DESCRIPTION: Check that all elements of a package are of the correct object
642 * type. Supports up to two groups of different object types.
644 ******************************************************************************/
647 AcpiNsCheckPackageElements (
648 ACPI_EVALUATE_INFO
*Info
,
649 ACPI_OPERAND_OBJECT
**Elements
,
656 ACPI_OPERAND_OBJECT
**ThisElement
= Elements
;
662 * Up to two groups of package elements are supported by the data
663 * structure. All elements in each group must be of the same type.
664 * The second group can have a count of zero.
666 for (i
= 0; i
< Count1
; i
++)
668 Status
= AcpiNsCheckObjectType (Info
, ThisElement
,
669 Type1
, i
+ StartIndex
);
670 if (ACPI_FAILURE (Status
))
678 for (i
= 0; i
< Count2
; i
++)
680 Status
= AcpiNsCheckObjectType (Info
, ThisElement
,
681 Type2
, (i
+ Count1
+ StartIndex
));
682 if (ACPI_FAILURE (Status
))