1 /******************************************************************************
3 * Module Name: aslprepkg - support for ACPI predefined name package objects
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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 "aslcompiler.h"
45 #include "aslcompiler.y.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:
162 /* Get the first element of the package */
166 /* Decode the package type */
168 switch (Package->RetInfo.Type)
170 case ACPI_PTYPE1_FIXED:
172 * The package count is fixed and there are no subpackages
174 * If package is too small, exit.
175 * If package is larger than expected, issue warning but continue
177 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
178 if (Count < ExpectedCount)
180 goto PackageTooSmall;
182 else if (Count > ExpectedCount)
184 ApPackageTooLarge (Predefined->Info.Name, ParentOp,
185 Count, ExpectedCount);
188 /* Validate all elements of the package */
190 ApCheckPackageElements (Predefined->Info.Name, Op,
191 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
192 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
195 case ACPI_PTYPE1_VAR:
197 * The package count is variable, there are no subpackages,
198 * and all elements must be of the same type
200 for (i = 0; i < Count; i++)
202 ApCheckObjectType (Predefined->Info.Name, Op,
203 Package->RetInfo.ObjectType1, i);
208 case ACPI_PTYPE1_OPTION:
210 * The package count is variable, there are no subpackages.
211 * There are a fixed number of required elements, and a variable
212 * number of optional elements.
214 * Check if package is at least as large as the minimum required
216 ExpectedCount = Package->RetInfo3.Count;
217 if (Count < ExpectedCount)
219 goto PackageTooSmall;
222 /* Variable number of sub-objects */
224 for (i = 0; i < Count; i++)
226 if (i < Package->RetInfo3.Count)
228 /* These are the required package elements (0, 1, or 2) */
230 ApCheckObjectType (Predefined->Info.Name, Op,
231 Package->RetInfo3.ObjectType[i], i);
235 /* These are the optional package elements */
237 ApCheckObjectType (Predefined->Info.Name, Op,
238 Package->RetInfo3.TailObjectType, i);
244 case ACPI_PTYPE2_REV_FIXED:
246 /* First element is the (Integer) revision */
248 ApCheckObjectType (Predefined->Info.Name, Op,
249 ACPI_RTYPE_INTEGER, 0);
254 /* Examine the subpackages */
256 ApCheckPackageList (Predefined->Info.Name, Op,
260 case ACPI_PTYPE2_PKG_COUNT:
262 /* First element is the (Integer) count of subpackages to follow */
264 Status = ApCheckObjectType (Predefined->Info.Name, Op,
265 ACPI_RTYPE_INTEGER, 0);
267 /* We must have an integer count from above (otherwise, use Count) */
269 if (ACPI_SUCCESS (Status))
272 * Count cannot be larger than the parent package length, but
273 * allow it to be smaller. The >= accounts for the Integer above.
275 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
276 if (ExpectedCount >= Count)
278 goto PackageTooSmall;
281 Count = ExpectedCount;
286 /* Examine the subpackages */
288 ApCheckPackageList (Predefined->Info.Name, Op,
293 case ACPI_PTYPE2_FIXED:
294 case ACPI_PTYPE2_MIN:
295 case ACPI_PTYPE2_COUNT:
296 case ACPI_PTYPE2_FIX_VAR:
298 * These types all return a single Package that consists of a
299 * variable number of subpackages.
302 /* Examine the subpackages */
304 ApCheckPackageList (Predefined->Info.Name, Op,
315 ApPackageTooSmall (Predefined->Info.Name, ParentOp,
316 Count, ExpectedCount);
320 /*******************************************************************************
322 * FUNCTION: ApCheckPackageElements
324 * PARAMETERS: PredefinedName - Name of the predefined object
325 * Op - Parser op for the package
326 * Type1 - Object type for first group
327 * Count1 - Count for first group
328 * Type2 - Object type for second group
329 * Count2 - Count for second group
333 * DESCRIPTION: Validate all elements of a package. Works with packages that
334 * are defined to contain up to two groups of different object
337 ******************************************************************************/
340 ApCheckPackageElements (
341 const char *PredefinedName,
342 ACPI_PARSE_OBJECT *Op,
352 * Up to two groups of package elements are supported by the data
353 * structure. All elements in each group must be of the same type.
354 * The second group can have a count of zero.
356 * Aborts check upon a NULL package element, as this means (at compile
357 * time) that the remainder of the package elements are also NULL
358 * (This is the only way to create NULL package elements.)
360 for (i = 0; (i < Count1) && Op; i++)
362 ApCheckObjectType (PredefinedName, Op, Type1, i);
366 for (i = 0; (i < Count2) && Op; i++)
368 ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
374 /*******************************************************************************
376 * FUNCTION: ApCheckPackageList
378 * PARAMETERS: PredefinedName - Name of the predefined object
379 * ParentOp - Parser op of the parent package
380 * Package - Package info for this predefined name
381 * StartIndex - Index in parent package where list begins
382 * ParentCount - Element count of parent package
386 * DESCRIPTION: Validate the individual package elements for a predefined name.
387 * Handles the cases where the predefined name is defined as a
388 * Package of Packages (subpackages). These are the types:
394 * ACPI_PTYPE2_FIX_VAR
396 ******************************************************************************/
400 const char *PredefinedName,
401 ACPI_PARSE_OBJECT *ParentOp,
402 const ACPI_PREDEFINED_INFO *Package,
406 ACPI_PARSE_OBJECT *SubPackageOp = ParentOp;
407 ACPI_PARSE_OBJECT *Op;
410 UINT32 ExpectedCount;
416 * Validate each subpackage in the parent Package
418 * Note: We ignore NULL package elements on the assumption that
419 * they will be initialized by the BIOS or other ASL code.
421 for (i = 0; (i < ParentCount) && SubPackageOp; i++)
423 /* Each object in the list must be of type Package */
425 Status = ApCheckObjectType (PredefinedName, SubPackageOp,
426 ACPI_RTYPE_PACKAGE, i + StartIndex);
427 if (ACPI_FAILURE (Status))
432 /* Examine the different types of expected subpackages */
434 Op = SubPackageOp->Asl.Child;
436 /* First child is the package length */
438 Count = (UINT32) Op->Asl.Value.Integer;
441 /* The subpackage must have at least one element */
445 ApZeroLengthPackage (PredefinedName, SubPackageOp);
450 * Decode the package type.
451 * PTYPE2 indicates that a "package of packages" is expected for
452 * this name. The various flavors of PTYPE2 indicate the number
453 * and format of the subpackages.
455 switch (Package->RetInfo.Type)
458 case ACPI_PTYPE2_PKG_COUNT:
459 case ACPI_PTYPE2_REV_FIXED:
461 /* Each subpackage has a fixed number of elements */
463 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
464 if (Count < ExpectedCount)
466 ApPackageTooSmall (PredefinedName, SubPackageOp,
467 Count, ExpectedCount);
470 if (Count > ExpectedCount)
472 ApPackageTooLarge (PredefinedName, SubPackageOp,
473 Count, ExpectedCount);
477 ApCheckPackageElements (PredefinedName, Op,
478 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
479 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
482 case ACPI_PTYPE2_FIX_VAR:
484 * Each subpackage has a fixed number of elements and an
487 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
488 if (Count < ExpectedCount)
490 ApPackageTooSmall (PredefinedName, SubPackageOp,
491 Count, ExpectedCount);
495 ApCheckPackageElements (PredefinedName, Op,
496 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
497 Package->RetInfo.ObjectType2,
498 Count - Package->RetInfo.Count1);
501 case ACPI_PTYPE2_FIXED:
503 /* Each subpackage has a fixed length */
505 ExpectedCount = Package->RetInfo2.Count;
506 if (Count < ExpectedCount)
508 ApPackageTooSmall (PredefinedName, SubPackageOp,
509 Count, ExpectedCount);
512 if (Count > ExpectedCount)
514 ApPackageTooLarge (PredefinedName, SubPackageOp,
515 Count, ExpectedCount);
519 /* Check each object/type combination */
521 for (j = 0; j < ExpectedCount; j++)
523 ApCheckObjectType (PredefinedName, Op,
524 Package->RetInfo2.ObjectType[j], j);
530 case ACPI_PTYPE2_MIN:
532 /* Each subpackage has a variable but minimum length */
534 ExpectedCount = Package->RetInfo.Count1;
535 if (Count < ExpectedCount)
537 ApPackageTooSmall (PredefinedName, SubPackageOp,
538 Count, ExpectedCount);
542 /* Check the type of each subpackage element */
544 ApCheckPackageElements (PredefinedName, Op,
545 Package->RetInfo.ObjectType1, Count, 0, 0);
548 case ACPI_PTYPE2_COUNT:
550 * First element is the (Integer) count of elements, including
551 * the count field (the ACPI name is NumElements)
553 Status = ApCheckObjectType (PredefinedName, Op,
554 ACPI_RTYPE_INTEGER, 0);
556 /* We must have an integer count from above (otherwise, use Count) */
558 if (ACPI_SUCCESS (Status))
561 * Make sure package is large enough for the Count and is
562 * is as large as the minimum size
564 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
566 if (Count < ExpectedCount)
568 ApPackageTooSmall (PredefinedName, SubPackageOp,
569 Count, ExpectedCount);
572 else if (Count > ExpectedCount)
574 ApPackageTooLarge (PredefinedName, SubPackageOp,
575 Count, ExpectedCount);
578 /* Some names of this type have a minimum length */
580 if (Count < Package->RetInfo.Count1)
582 ExpectedCount = Package->RetInfo.Count1;
583 ApPackageTooSmall (PredefinedName, SubPackageOp,
584 Count, ExpectedCount);
588 Count = ExpectedCount;
591 /* Check the type of each subpackage element */
594 ApCheckPackageElements (PredefinedName, Op,
595 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
603 SubPackageOp = SubPackageOp->Asl.Next;
608 /*******************************************************************************
610 * FUNCTION: ApPackageTooSmall
612 * PARAMETERS: PredefinedName - Name of the predefined object
613 * Op - Current parser op
614 * Count - Actual package element count
615 * ExpectedCount - Expected package element count
619 * DESCRIPTION: Issue error message for a package that is smaller than
622 ******************************************************************************/
626 const char *PredefinedName,
627 ACPI_PARSE_OBJECT *Op,
629 UINT32 ExpectedCount)
632 sprintf (MsgBuffer, "%s: length %u, required minimum is %u",
633 PredefinedName, Count, ExpectedCount);
635 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
639 /*******************************************************************************
641 * FUNCTION: ApZeroLengthPackage
643 * PARAMETERS: PredefinedName - Name of the predefined object
644 * Op - Current parser op
648 * DESCRIPTION: Issue error message for a zero-length package (a package that
649 * is required to have a non-zero length). Variable length
650 * packages seem to be allowed to have zero length, however.
651 * Even if not allowed, BIOS code does it.
653 ******************************************************************************/
656 ApZeroLengthPackage (
657 const char *PredefinedName,
658 ACPI_PARSE_OBJECT *Op)
661 sprintf (MsgBuffer, "%s: length is zero", PredefinedName);
663 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
667 /*******************************************************************************
669 * FUNCTION: ApPackageTooLarge
671 * PARAMETERS: PredefinedName - Name of the predefined object
672 * Op - Current parser op
673 * Count - Actual package element count
674 * ExpectedCount - Expected package element count
678 * DESCRIPTION: Issue a remark for a package that is larger than expected.
680 ******************************************************************************/
684 const char *PredefinedName,
685 ACPI_PARSE_OBJECT *Op,
687 UINT32 ExpectedCount)
690 sprintf (MsgBuffer, "%s: length is %u, only %u required",
691 PredefinedName, Count, ExpectedCount);
693 AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);