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,
292 case ACPI_PTYPE2_UUID_PAIR:
294 /* The package contains a variable list of UUID Buffer/Package pairs */
296 /* The length of the package must be even */
300 sprintf (MsgBuffer, "%4.4s: Package length, %d, must be even.",
301 Predefined->Info.Name, Count);
303 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH,
304 ParentOp->Asl.Child, MsgBuffer);
307 /* Validate the alternating types */
309 for (i = 0; i < Count; ++i)
313 ApCheckObjectType (Predefined->Info.Name, Op,
314 Package->RetInfo.ObjectType2, i);
318 ApCheckObjectType (Predefined->Info.Name, Op,
319 Package->RetInfo.ObjectType1, i);
328 case ACPI_PTYPE2_FIXED:
329 case ACPI_PTYPE2_MIN:
330 case ACPI_PTYPE2_COUNT:
331 case ACPI_PTYPE2_FIX_VAR:
333 * These types all return a single Package that consists of a
334 * variable number of subpackages.
337 /* Examine the subpackages */
339 ApCheckPackageList (Predefined->Info.Name, Op,
350 ApPackageTooSmall (Predefined->Info.Name, ParentOp,
351 Count, ExpectedCount);
355 /*******************************************************************************
357 * FUNCTION: ApCheckPackageElements
359 * PARAMETERS: PredefinedName - Name of the predefined object
360 * Op - Parser op for the package
361 * Type1 - Object type for first group
362 * Count1 - Count for first group
363 * Type2 - Object type for second group
364 * Count2 - Count for second group
368 * DESCRIPTION: Validate all elements of a package. Works with packages that
369 * are defined to contain up to two groups of different object
372 ******************************************************************************/
375 ApCheckPackageElements (
376 const char *PredefinedName,
377 ACPI_PARSE_OBJECT *Op,
387 * Up to two groups of package elements are supported by the data
388 * structure. All elements in each group must be of the same type.
389 * The second group can have a count of zero.
391 * Aborts check upon a NULL package element, as this means (at compile
392 * time) that the remainder of the package elements are also NULL
393 * (This is the only way to create NULL package elements.)
395 for (i = 0; (i < Count1) && Op; i++)
397 ApCheckObjectType (PredefinedName, Op, Type1, i);
401 for (i = 0; (i < Count2) && Op; i++)
403 ApCheckObjectType (PredefinedName, Op, Type2, (i + Count1));
409 /*******************************************************************************
411 * FUNCTION: ApCheckPackageList
413 * PARAMETERS: PredefinedName - Name of the predefined object
414 * ParentOp - Parser op of the parent package
415 * Package - Package info for this predefined name
416 * StartIndex - Index in parent package where list begins
417 * ParentCount - Element count of parent package
421 * DESCRIPTION: Validate the individual package elements for a predefined name.
422 * Handles the cases where the predefined name is defined as a
423 * Package of Packages (subpackages). These are the types:
429 * ACPI_PTYPE2_FIX_VAR
431 ******************************************************************************/
435 const char *PredefinedName,
436 ACPI_PARSE_OBJECT *ParentOp,
437 const ACPI_PREDEFINED_INFO *Package,
441 ACPI_PARSE_OBJECT *SubPackageOp = ParentOp;
442 ACPI_PARSE_OBJECT *Op;
445 UINT32 ExpectedCount;
451 * Validate each subpackage in the parent Package
453 * Note: We ignore NULL package elements on the assumption that
454 * they will be initialized by the BIOS or other ASL code.
456 for (i = 0; (i < ParentCount) && SubPackageOp; i++)
458 /* Each object in the list must be of type Package */
460 Status = ApCheckObjectType (PredefinedName, SubPackageOp,
461 ACPI_RTYPE_PACKAGE, i + StartIndex);
462 if (ACPI_FAILURE (Status))
467 /* Examine the different types of expected subpackages */
469 Op = SubPackageOp->Asl.Child;
471 /* First child is the package length */
473 Count = (UINT32) Op->Asl.Value.Integer;
476 /* The subpackage must have at least one element */
480 ApZeroLengthPackage (PredefinedName, SubPackageOp);
485 * Decode the package type.
486 * PTYPE2 indicates that a "package of packages" is expected for
487 * this name. The various flavors of PTYPE2 indicate the number
488 * and format of the subpackages.
490 switch (Package->RetInfo.Type)
493 case ACPI_PTYPE2_PKG_COUNT:
494 case ACPI_PTYPE2_REV_FIXED:
496 /* Each subpackage has a fixed number of elements */
498 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
499 if (Count < ExpectedCount)
501 ApPackageTooSmall (PredefinedName, SubPackageOp,
502 Count, ExpectedCount);
505 if (Count > ExpectedCount)
507 ApPackageTooLarge (PredefinedName, SubPackageOp,
508 Count, ExpectedCount);
512 ApCheckPackageElements (PredefinedName, Op,
513 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
514 Package->RetInfo.ObjectType2, Package->RetInfo.Count2);
517 case ACPI_PTYPE2_FIX_VAR:
519 * Each subpackage has a fixed number of elements and an
522 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
523 if (Count < ExpectedCount)
525 ApPackageTooSmall (PredefinedName, SubPackageOp,
526 Count, ExpectedCount);
530 ApCheckPackageElements (PredefinedName, Op,
531 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
532 Package->RetInfo.ObjectType2,
533 Count - Package->RetInfo.Count1);
536 case ACPI_PTYPE2_FIXED:
538 /* Each subpackage has a fixed length */
540 ExpectedCount = Package->RetInfo2.Count;
541 if (Count < ExpectedCount)
543 ApPackageTooSmall (PredefinedName, SubPackageOp,
544 Count, ExpectedCount);
547 if (Count > ExpectedCount)
549 ApPackageTooLarge (PredefinedName, SubPackageOp,
550 Count, ExpectedCount);
554 /* Check each object/type combination */
556 for (j = 0; j < ExpectedCount; j++)
558 ApCheckObjectType (PredefinedName, Op,
559 Package->RetInfo2.ObjectType[j], j);
565 case ACPI_PTYPE2_MIN:
567 /* Each subpackage has a variable but minimum length */
569 ExpectedCount = Package->RetInfo.Count1;
570 if (Count < ExpectedCount)
572 ApPackageTooSmall (PredefinedName, SubPackageOp,
573 Count, ExpectedCount);
577 /* Check the type of each subpackage element */
579 ApCheckPackageElements (PredefinedName, Op,
580 Package->RetInfo.ObjectType1, Count, 0, 0);
583 case ACPI_PTYPE2_COUNT:
585 * First element is the (Integer) count of elements, including
586 * the count field (the ACPI name is NumElements)
588 Status = ApCheckObjectType (PredefinedName, Op,
589 ACPI_RTYPE_INTEGER, 0);
591 /* We must have an integer count from above (otherwise, use Count) */
593 if (ACPI_SUCCESS (Status))
596 * Make sure package is large enough for the Count and is
597 * is as large as the minimum size
599 ExpectedCount = (UINT32) Op->Asl.Value.Integer;
601 if (Count < ExpectedCount)
603 ApPackageTooSmall (PredefinedName, SubPackageOp,
604 Count, ExpectedCount);
607 else if (Count > ExpectedCount)
609 ApPackageTooLarge (PredefinedName, SubPackageOp,
610 Count, ExpectedCount);
613 /* Some names of this type have a minimum length */
615 if (Count < Package->RetInfo.Count1)
617 ExpectedCount = Package->RetInfo.Count1;
618 ApPackageTooSmall (PredefinedName, SubPackageOp,
619 Count, ExpectedCount);
623 Count = ExpectedCount;
626 /* Check the type of each subpackage element */
629 ApCheckPackageElements (PredefinedName, Op,
630 Package->RetInfo.ObjectType1, (Count - 1), 0, 0);
638 SubPackageOp = SubPackageOp->Asl.Next;
643 /*******************************************************************************
645 * FUNCTION: ApPackageTooSmall
647 * PARAMETERS: PredefinedName - Name of the predefined object
648 * Op - Current parser op
649 * Count - Actual package element count
650 * ExpectedCount - Expected package element count
654 * DESCRIPTION: Issue error message for a package that is smaller than
657 ******************************************************************************/
661 const char *PredefinedName,
662 ACPI_PARSE_OBJECT *Op,
664 UINT32 ExpectedCount)
667 sprintf (MsgBuffer, "%s: length %u, required minimum is %u",
668 PredefinedName, Count, ExpectedCount);
670 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
674 /*******************************************************************************
676 * FUNCTION: ApZeroLengthPackage
678 * PARAMETERS: PredefinedName - Name of the predefined object
679 * Op - Current parser op
683 * DESCRIPTION: Issue error message for a zero-length package (a package that
684 * is required to have a non-zero length). Variable length
685 * packages seem to be allowed to have zero length, however.
686 * Even if not allowed, BIOS code does it.
688 ******************************************************************************/
691 ApZeroLengthPackage (
692 const char *PredefinedName,
693 ACPI_PARSE_OBJECT *Op)
696 sprintf (MsgBuffer, "%s: length is zero", PredefinedName);
698 AslError (ASL_ERROR, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);
702 /*******************************************************************************
704 * FUNCTION: ApPackageTooLarge
706 * PARAMETERS: PredefinedName - Name of the predefined object
707 * Op - Current parser op
708 * Count - Actual package element count
709 * ExpectedCount - Expected package element count
713 * DESCRIPTION: Issue a remark for a package that is larger than expected.
715 ******************************************************************************/
719 const char *PredefinedName,
720 ACPI_PARSE_OBJECT *Op,
722 UINT32 ExpectedCount)
725 sprintf (MsgBuffer, "%s: length is %u, only %u required",
726 PredefinedName, Count, ExpectedCount);
728 AslError (ASL_REMARK, ASL_MSG_RESERVED_PACKAGE_LENGTH, Op, MsgBuffer);