1 /******************************************************************************
3 * Module Name: aslprepkg - support for ACPI predefined name package objects
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include "aslcompiler.y.h"
46 #include <contrib/dev/acpica/include/acpredef.h>
49 #define _COMPONENT ACPI_COMPILER
50 ACPI_MODULE_NAME ("aslprepkg")
53 /* Local prototypes */
56 ApCheckPackageElements (
57 const char *PredefinedName,
58 ACPI_PARSE_OBJECT *Op,
66 const char *PredefinedName,
67 ACPI_PARSE_OBJECT *ParentOp,
68 const ACPI_PREDEFINED_INFO *Package,
74 const char *PredefinedName,
75 ACPI_PARSE_OBJECT *Op,
77 UINT32 ExpectedCount);
81 const char *PredefinedName,
82 ACPI_PARSE_OBJECT *Op);
86 const char *PredefinedName,
87 ACPI_PARSE_OBJECT *Op,
89 UINT32 ExpectedCount);
92 /*******************************************************************************
94 * FUNCTION: ApCheckPackage
96 * PARAMETERS: ParentOp - Parser op for the package
97 * Predefined - Pointer to package-specific info for
102 * DESCRIPTION: Top-level validation for predefined name return package
105 ******************************************************************************/
109 ACPI_PARSE_OBJECT *ParentOp,
110 const ACPI_PREDEFINED_INFO *Predefined)
112 ACPI_PARSE_OBJECT *Op;
113 const ACPI_PREDEFINED_INFO *Package;
115 UINT32 ExpectedCount;
120 /* The package info for this name is in the next table entry */
122 Package = Predefined + 1;
124 /* First child is the package length */
126 Op = ParentOp->Asl.Child;
127 Count = (UINT32) Op->Asl.Value.Integer;
130 * Many of the variable-length top-level packages are allowed to simply
131 * have zero elements. This allows the BIOS to tell the host that even
132 * though the predefined name/method exists, the feature is not supported.
133 * Other package types require one or more elements. In any case, there
134 * is no need to continue validation.
138 switch (Package->RetInfo.Type)
140 case ACPI_PTYPE1_FIXED:
141 case ACPI_PTYPE1_OPTION:
142 case ACPI_PTYPE2_PKG_COUNT:
143 case ACPI_PTYPE2_REV_FIXED:
145 ApZeroLengthPackage (Predefined->Info.Name, ParentOp);
148 case ACPI_PTYPE1_VAR:
150 case ACPI_PTYPE2_COUNT:
151 case ACPI_PTYPE2_FIXED:
152 case ACPI_PTYPE2_MIN:
153 case ACPI_PTYPE2_FIX_VAR:
154 case ACPI_PTYPE2_VAR_VAR:
163 /* Get the first element of the package */
167 /* Decode the package type */
169 switch (Package->RetInfo.Type)
171 case ACPI_PTYPE1_FIXED:
173 * The package count is fixed and there are no subpackages
175 * If package is too small, exit.
176 * If package is larger than expected, issue warning but continue
178 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
179 if (Count < ExpectedCount)
181 goto PackageTooSmall;
183 else if (Count > ExpectedCount)
185 ApPackageTooLarge (Predefined->Info.Name, ParentOp,
186 Count, ExpectedCount);
189 /* Validate all elements of the package */
191 ApCheckPackageElements (Predefined->Info.Name, Op,
192 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
193 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
196 case ACPI_PTYPE1_VAR:
198 * The package count is variable, there are no subpackages,
199 * and all elements must be of the same type
201 for (i = 0; i < Count; i++)
203 ApCheckObjectType (Predefined->Info.Name, Op,
204 Package->RetInfo.ObjectType1, i);
209 case ACPI_PTYPE1_OPTION:
211 * The package count is variable, there are no subpackages.
212 * There are a fixed number of required elements, and a variable
213 * number of optional elements.
215 * Check if package is at least as large as the minimum required
217 ExpectedCount = Package->RetInfo3.Count;
218 if (Count < ExpectedCount)
220 goto PackageTooSmall;
223 /* Variable number of sub-objects */
225 for (i = 0; i < Count; i++)
227 if (i < Package->RetInfo3.Count)
229 /* These are the required package elements (0, 1, or 2) */
231 ApCheckObjectType (Predefined->Info.Name, Op,
232 Package->RetInfo3.ObjectType[i], i);
236 /* These are the optional package elements */
238 ApCheckObjectType (Predefined->Info.Name, Op,
239 Package->RetInfo3.TailObjectType, i);
245 case ACPI_PTYPE2_REV_FIXED:
247 /* First element is the (Integer) revision */
249 ApCheckObjectType (Predefined->Info.Name, Op,
250 ACPI_RTYPE_INTEGER, 0);
255 /* Examine the subpackages */
257 ApCheckPackageList (Predefined->Info.Name, Op,
261 case ACPI_PTYPE2_PKG_COUNT:
263 /* First element is the (Integer) count of subpackages to follow */
265 Status = ApCheckObjectType (Predefined->Info.Name, Op,
266 ACPI_RTYPE_INTEGER, 0);
268 /* We must have an integer count from above (otherwise, use Count) */
270 if (ACPI_SUCCESS (Status))
273 * Count cannot be larger than the parent package length, but
274 * allow it to be smaller. The >= accounts for the Integer above.
276 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
277 if (ExpectedCount >= Count)
279 goto PackageTooSmall;
282 Count = ExpectedCount;
287 /* Examine the subpackages */
289 ApCheckPackageList (Predefined->Info.Name, Op,
293 case ACPI_PTYPE2_UUID_PAIR:
295 /* The package contains a variable list of UUID Buffer/Package pairs */
297 /* The length of the package must be even */
301 sprintf (MsgBuffer, "%4.4s: Package length, %d, must be even.",
302 Predefined->Info.Name, Count);
304 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
305 ParentOp->Asl.Child, MsgBuffer);
308 /* Validate the alternating types */
310 for (i = 0; i < Count; ++i)
314 ApCheckObjectType (Predefined->Info.Name, Op,
315 Package->RetInfo.ObjectType2, i);
319 ApCheckObjectType (Predefined->Info.Name, Op,
320 Package->RetInfo.ObjectType1, i);
328 case ACPI_PTYPE2_VAR_VAR:
330 /* Check for minimum size (ints at beginning + 1 subpackage) */
332 ExpectedCount = Package->RetInfo4.Count1 + 1;
333 if (Count < ExpectedCount)
335 goto PackageTooSmall;
338 /* Check the non-package elements at beginning of main package */
340 for (i = 0; i < Package->RetInfo4.Count1; ++i)
342 Status = ApCheckObjectType (Predefined->Info.Name, Op,
343 Package->RetInfo4.ObjectType1, i);
347 /* Examine the variable-length list of subpackages */
349 ApCheckPackageList (Predefined->Info.Name, Op,
350 Package, Package->RetInfo4.Count1, Count);
355 case ACPI_PTYPE2_FIXED:
356 case ACPI_PTYPE2_MIN:
357 case ACPI_PTYPE2_COUNT:
358 case ACPI_PTYPE2_FIX_VAR:
360 * These types all return a single Package that consists of a
361 * variable number of subpackages.
364 /* Examine the subpackages */
366 ApCheckPackageList (Predefined->Info.Name, Op,
377 ApPackageTooSmall (Predefined->Info.Name, ParentOp,
378 Count, ExpectedCount);
382 /*******************************************************************************
384 * FUNCTION: ApCheckPackageElements
386 * PARAMETERS: PredefinedName - Name of the predefined object
387 * Op - Parser op for the package
388 * Type1 - Object type for first group
389 * Count1 - Count for first group
390 * Type2 - Object type for second group
391 * Count2 - Count for second group
395 * DESCRIPTION: Validate all elements of a package. Works with packages that
396 * are defined to contain up to two groups of different object
399 ******************************************************************************/
402 ApCheckPackageElements (
403 const char *PredefinedName,
404 ACPI_PARSE_OBJECT *Op,
414 * Up to two groups of package elements are supported by the data
415 * structure. All elements in each group must be of the same type.
416 * The second group can have a count of zero.
418 * Aborts check upon a NULL package element, as this means (at compile
419 * time) that the remainder of the package elements are also NULL
420 * (This is the only way to create NULL package elements.)
422 for (i = 0; (i < Count1) && Op; i++)
424 ApCheckObjectType (PredefinedName, Op, Type1, i);
428 for (i = 0; (i < Count2) && Op; i++)
430 ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
436 /*******************************************************************************
438 * FUNCTION: ApCheckPackageList
440 * PARAMETERS: PredefinedName - Name of the predefined object
441 * ParentOp - Parser op of the parent package
442 * Package - Package info for this predefined name
443 * StartIndex - Index in parent package where list begins
444 * ParentCount - Element count of parent package
448 * DESCRIPTION: Validate the individual package elements for a predefined name.
449 * Handles the cases where the predefined name is defined as a
450 * Package of Packages (subpackages). These are the types:
456 * ACPI_PTYPE2_FIX_VAR
457 * ACPI_PTYPE2_VAR_VAR
459 ******************************************************************************/
463 const char *PredefinedName,
464 ACPI_PARSE_OBJECT *ParentOp,
465 const ACPI_PREDEFINED_INFO *Package,
469 ACPI_PARSE_OBJECT *SubPackageOp = ParentOp;
470 ACPI_PARSE_OBJECT *Op;
473 UINT32 ExpectedCount;
479 * Validate each subpackage in the parent Package
481 * Note: We ignore NULL package elements on the assumption that
482 * they will be initialized by the BIOS or other ASL code.
484 for (i = 0; (i < ParentCount) && SubPackageOp; i++)
486 /* Each object in the list must be of type Package */
488 Status = ApCheckObjectType (PredefinedName, SubPackageOp,
489 ACPI_RTYPE_PACKAGE, i + StartIndex);
490 if (ACPI_FAILURE (Status))
495 /* Examine the different types of expected subpackages */
497 Op = SubPackageOp->Asl.Child;
499 /* First child is the package length */
501 Count = (UINT32) Op->Asl.Value.Integer;
505 * Most subpackage must have at least one element, with
506 * only rare exceptions. (_RDI)
509 (Package->RetInfo.Type != ACPI_PTYPE2_VAR_VAR))
511 ApZeroLengthPackage (PredefinedName, SubPackageOp);
516 * Decode the package type.
517 * PTYPE2 indicates that a "package of packages" is expected for
518 * this name. The various flavors of PTYPE2 indicate the number
519 * and format of the subpackages.
521 switch (Package->RetInfo.Type)
524 case ACPI_PTYPE2_PKG_COUNT:
525 case ACPI_PTYPE2_REV_FIXED:
527 /* Each subpackage has a fixed number of elements */
529 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
530 if (Count < ExpectedCount)
532 ApPackageTooSmall (PredefinedName, SubPackageOp,
533 Count, ExpectedCount);
536 if (Count > ExpectedCount)
538 ApPackageTooLarge (PredefinedName, SubPackageOp,
539 Count, ExpectedCount);
543 ApCheckPackageElements (PredefinedName, Op,
544 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
545 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
548 case ACPI_PTYPE2_FIX_VAR:
550 * Each subpackage has a fixed number of elements and an
553 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
554 if (Count < ExpectedCount)
556 ApPackageTooSmall (PredefinedName, SubPackageOp,
557 Count, ExpectedCount);
561 ApCheckPackageElements (PredefinedName, Op,
562 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
563 Package->RetInfo.ObjectType2,
564 Count - Package->RetInfo.Count1);
567 case ACPI_PTYPE2_VAR_VAR:
569 * Must have at least the minimum number elements.
570 * A zero PkgCount means the number of elements is variable.
572 ExpectedCount = Package->RetInfo4.PkgCount;
573 if (ExpectedCount && (Count < ExpectedCount))
575 ApPackageTooSmall (PredefinedName, SubPackageOp,
580 ApCheckPackageElements (PredefinedName, Op,
581 Package->RetInfo4.SubObjectTypes,
582 Package->RetInfo4.PkgCount,
586 case ACPI_PTYPE2_FIXED:
588 /* Each subpackage has a fixed length */
590 ExpectedCount = Package->RetInfo2.Count;
591 if (Count < ExpectedCount)
593 ApPackageTooSmall (PredefinedName, SubPackageOp,
594 Count, ExpectedCount);
597 if (Count > ExpectedCount)
599 ApPackageTooLarge (PredefinedName, SubPackageOp,
600 Count, ExpectedCount);
604 /* Check each object/type combination */
606 for (j = 0; j < ExpectedCount; j++)
608 ApCheckObjectType (PredefinedName, Op,
609 Package->RetInfo2.ObjectType[j], j);
615 case ACPI_PTYPE2_MIN:
617 /* Each subpackage has a variable but minimum length */
619 ExpectedCount = Package->RetInfo.Count1;
620 if (Count < ExpectedCount)
622 ApPackageTooSmall (PredefinedName, SubPackageOp,
623 Count, ExpectedCount);
627 /* Check the type of each subpackage element */
629 ApCheckPackageElements (PredefinedName, Op,
630 Package->RetInfo.ObjectType1, Count, 0, 0);
633 case ACPI_PTYPE2_COUNT:
635 * First element is the (Integer) count of elements, including
636 * the count field (the ACPI name is NumElements)
638 Status = ApCheckObjectType (PredefinedName, Op,
639 ACPI_RTYPE_INTEGER, 0);
641 /* We must have an integer count from above (otherwise, use Count) */
643 if (ACPI_SUCCESS (Status))
646 * Make sure package is large enough for the Count and is
647 * is as large as the minimum size
649 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
651 if (Count < ExpectedCount)
653 ApPackageTooSmall (PredefinedName, SubPackageOp,
654 Count, ExpectedCount);
657 else if (Count > ExpectedCount)
659 ApPackageTooLarge (PredefinedName, SubPackageOp,
660 Count, ExpectedCount);
663 /* Some names of this type have a minimum length */
665 if (Count < Package->RetInfo.Count1)
667 ExpectedCount = Package->RetInfo.Count1;
668 ApPackageTooSmall (PredefinedName, SubPackageOp,
669 Count, ExpectedCount);
673 Count = ExpectedCount;
676 /* Check the type of each subpackage element */
679 ApCheckPackageElements (PredefinedName, Op,
680 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
688 SubPackageOp = SubPackageOp->Asl.Next;
693 /*******************************************************************************
695 * FUNCTION: ApPackageTooSmall
697 * PARAMETERS: PredefinedName - Name of the predefined object
698 * Op - Current parser op
699 * Count - Actual package element count
700 * ExpectedCount - Expected package element count
704 * DESCRIPTION: Issue error message for a package that is smaller than
707 ******************************************************************************/
711 const char *PredefinedName,
712 ACPI_PARSE_OBJECT *Op,
714 UINT32 ExpectedCount)
717 sprintf (MsgBuffer, "%s: length %u, required minimum is %u",
718 PredefinedName, Count, ExpectedCount);
720 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
724 /*******************************************************************************
726 * FUNCTION: ApZeroLengthPackage
728 * PARAMETERS: PredefinedName - Name of the predefined object
729 * Op - Current parser op
733 * DESCRIPTION: Issue error message for a zero-length package (a package that
734 * is required to have a non-zero length). Variable length
735 * packages seem to be allowed to have zero length, however.
736 * Even if not allowed, BIOS code does it.
738 ******************************************************************************/
741 ApZeroLengthPackage (
742 const char *PredefinedName,
743 ACPI_PARSE_OBJECT *Op)
746 sprintf (MsgBuffer, "%s: length is zero", PredefinedName);
748 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
752 /*******************************************************************************
754 * FUNCTION: ApPackageTooLarge
756 * PARAMETERS: PredefinedName - Name of the predefined object
757 * Op - Current parser op
758 * Count - Actual package element count
759 * ExpectedCount - Expected package element count
763 * DESCRIPTION: Issue a remark for a package that is larger than expected.
765 ******************************************************************************/
769 const char *PredefinedName,
770 ACPI_PARSE_OBJECT *Op,
772 UINT32 ExpectedCount)
775 sprintf (MsgBuffer, "%s: length is %u, only %u required",
776 PredefinedName, Count, ExpectedCount);
778 AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);