1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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 #define ACPI_CREATE_PREDEFINED_TABLE
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nspredef")
56 /*******************************************************************************
58 * This module validates predefined ACPI objects that appear in the namespace,
59 * at the time they are evaluated (via AcpiEvaluateObject). The purpose of this
60 * validation is to detect problems with BIOS-exposed predefined ACPI objects
61 * before the results are returned to the ACPI-related drivers.
63 * There are several areas that are validated:
65 * 1) The number of input arguments as defined by the method/object in the
66 * ASL is validated against the ACPI specification.
67 * 2) The type of the return object (if any) is validated against the ACPI
69 * 3) For returned package objects, the count of package elements is
70 * validated, as well as the type of each package element. Nested
71 * packages are supported.
73 * For any problems found, a warning message is issued.
75 ******************************************************************************/
78 /* Local prototypes */
82 ACPI_PREDEFINED_DATA *Data,
83 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
86 AcpiNsCheckPackageList (
87 ACPI_PREDEFINED_DATA *Data,
88 const ACPI_PREDEFINED_INFO *Package,
89 ACPI_OPERAND_OBJECT **Elements,
93 AcpiNsCheckPackageElements (
94 ACPI_PREDEFINED_DATA *Data,
95 ACPI_OPERAND_OBJECT **Elements,
103 AcpiNsCheckObjectType (
104 ACPI_PREDEFINED_DATA *Data,
105 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
106 UINT32 ExpectedBtypes,
107 UINT32 PackageIndex);
110 AcpiNsCheckReference (
111 ACPI_PREDEFINED_DATA *Data,
112 ACPI_OPERAND_OBJECT *ReturnObject);
115 AcpiNsGetExpectedTypes (
117 UINT32 ExpectedBtypes);
120 * Names for the types that can be returned by the predefined objects.
121 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
123 static const char *AcpiRtypeNames[] =
133 /*******************************************************************************
135 * FUNCTION: AcpiNsCheckPredefinedNames
137 * PARAMETERS: Node - Namespace node for the method/object
138 * UserParamCount - Number of parameters actually passed
139 * ReturnStatus - Status from the object evaluation
140 * ReturnObjectPtr - Pointer to the object returned from the
141 * evaluation of a method or object
145 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
147 ******************************************************************************/
150 AcpiNsCheckPredefinedNames (
151 ACPI_NAMESPACE_NODE *Node,
152 UINT32 UserParamCount,
153 ACPI_STATUS ReturnStatus,
154 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
156 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
157 ACPI_STATUS Status = AE_OK;
158 const ACPI_PREDEFINED_INFO *Predefined;
160 ACPI_PREDEFINED_DATA *Data;
163 /* Match the name for this method/object against the predefined list */
165 Predefined = AcpiNsCheckForPredefinedName (Node);
167 /* Get the full pathname to the object, for use in warning messages */
169 Pathname = AcpiNsGetExternalPathname (Node);
172 return (AE_OK); /* Could not get pathname, ignore */
176 * Check that the parameter count for this method matches the ASL
177 * definition. For predefined names, ensure that both the caller and
178 * the method itself are in accordance with the ACPI specification.
180 AcpiNsCheckParameterCount (Pathname, Node, UserParamCount, Predefined);
182 /* If not a predefined name, we cannot validate the return object */
190 * If the method failed or did not actually return an object, we cannot
191 * validate the return object
193 if ((ReturnStatus != AE_OK) && (ReturnStatus != AE_CTRL_RETURN_VALUE))
199 * If there is no return value, check if we require a return value for
200 * this predefined name. Either one return value is expected, or none,
201 * for both methods and other objects.
203 * Exit now if there is no return object. Warning if one was expected.
207 if ((Predefined->Info.ExpectedBtypes) &&
208 (!(Predefined->Info.ExpectedBtypes & ACPI_RTYPE_NONE)))
210 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
211 "Missing expected return value"));
213 Status = AE_AML_NO_RETURN_VALUE;
219 * Return value validation and possible repair.
221 * 1) Don't perform return value validation/repair if this feature
222 * has been disabled via a global option.
224 * 2) We have a return value, but if one wasn't expected, just exit,
225 * this is not a problem. For example, if the "Implicit Return"
226 * feature is enabled, methods will always return a value.
228 * 3) If the return value can be of any type, then we cannot perform
229 * any validation, just exit.
231 if (AcpiGbl_DisableAutoRepair ||
232 (!Predefined->Info.ExpectedBtypes) ||
233 (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL))
238 /* Create the parameter data block for object validation */
240 Data = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PREDEFINED_DATA));
245 Data->Predefined = Predefined;
247 Data->NodeFlags = Node->Flags;
248 Data->Pathname = Pathname;
251 * Check that the type of the main return object is what is expected
252 * for this predefined name
254 Status = AcpiNsCheckObjectType (Data, ReturnObjectPtr,
255 Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
256 if (ACPI_FAILURE (Status))
262 * For returned Package objects, check the type of all sub-objects.
263 * Note: Package may have been newly created by call above.
265 if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE)
267 Data->ParentPackage = *ReturnObjectPtr;
268 Status = AcpiNsCheckPackage (Data, ReturnObjectPtr);
269 if (ACPI_FAILURE (Status))
276 * The return object was OK, or it was successfully repaired above.
277 * Now make some additional checks such as verifying that package
278 * objects are sorted correctly (if required) or buffer objects have
279 * the correct data width (bytes vs. dwords). These repairs are
280 * performed on a per-name basis, i.e., the code is specific to
281 * particular predefined names.
283 Status = AcpiNsComplexRepairs (Data, Node, Status, ReturnObjectPtr);
287 * If the object validation failed or if we successfully repaired one
288 * or more objects, mark the parent node to suppress further warning
289 * messages during the next evaluation of the same method/object.
291 if (ACPI_FAILURE (Status) || (Data->Flags & ACPI_OBJECT_REPAIRED))
293 Node->Flags |= ANOBJ_EVALUATED;
298 ACPI_FREE (Pathname);
303 /*******************************************************************************
305 * FUNCTION: AcpiNsCheckParameterCount
307 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
308 * Node - Namespace node for the method/object
309 * UserParamCount - Number of args passed in by the caller
310 * Predefined - Pointer to entry in predefined name table
314 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
315 * predefined name is what is expected (i.e., what is defined in
316 * the ACPI specification for this predefined name.)
318 ******************************************************************************/
321 AcpiNsCheckParameterCount (
323 ACPI_NAMESPACE_NODE *Node,
324 UINT32 UserParamCount,
325 const ACPI_PREDEFINED_INFO *Predefined)
328 UINT32 RequiredParamsCurrent;
329 UINT32 RequiredParamsOld;
332 /* Methods have 0-7 parameters. All other types have zero. */
335 if (Node->Type == ACPI_TYPE_METHOD)
337 ParamCount = Node->Object->Method.ParamCount;
343 * Check the parameter count for non-predefined methods/objects.
345 * Warning if too few or too many arguments have been passed by the
346 * caller. An incorrect number of arguments may not cause the method
347 * to fail. However, the method will fail if there are too few
348 * arguments and the method attempts to use one of the missing ones.
350 if (UserParamCount < ParamCount)
352 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
353 "Insufficient arguments - needs %u, found %u",
354 ParamCount, UserParamCount));
356 else if (UserParamCount > ParamCount)
358 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
359 "Excess arguments - needs %u, found %u",
360 ParamCount, UserParamCount));
366 * Validate the user-supplied parameter count.
367 * Allow two different legal argument counts (_SCP, etc.)
369 RequiredParamsCurrent = Predefined->Info.ParamCount & 0x0F;
370 RequiredParamsOld = Predefined->Info.ParamCount >> 4;
372 if (UserParamCount != ACPI_UINT32_MAX)
374 if ((UserParamCount != RequiredParamsCurrent) &&
375 (UserParamCount != RequiredParamsOld))
377 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
378 "Parameter count mismatch - "
379 "caller passed %u, ACPI requires %u",
380 UserParamCount, RequiredParamsCurrent));
385 * Check that the ASL-defined parameter count is what is expected for
386 * this predefined name (parameter count as defined by the ACPI
389 if ((ParamCount != RequiredParamsCurrent) &&
390 (ParamCount != RequiredParamsOld))
392 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, Node->Flags,
393 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
394 ParamCount, RequiredParamsCurrent));
399 /*******************************************************************************
401 * FUNCTION: AcpiNsCheckForPredefinedName
403 * PARAMETERS: Node - Namespace node for the method/object
405 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
407 * DESCRIPTION: Check an object name against the predefined object list.
409 ******************************************************************************/
411 const ACPI_PREDEFINED_INFO *
412 AcpiNsCheckForPredefinedName (
413 ACPI_NAMESPACE_NODE *Node)
415 const ACPI_PREDEFINED_INFO *ThisName;
418 /* Quick check for a predefined name, first character must be underscore */
420 if (Node->Name.Ascii[0] != '_')
425 /* Search info table for a predefined method/object name */
427 ThisName = PredefinedNames;
428 while (ThisName->Info.Name[0])
430 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Info.Name))
436 * Skip next entry in the table if this name returns a Package
437 * (next entry contains the package info)
439 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
447 return (NULL); /* Not found */
451 /*******************************************************************************
453 * FUNCTION: AcpiNsCheckPackage
455 * PARAMETERS: Data - Pointer to validation data structure
456 * ReturnObjectPtr - Pointer to the object returned from the
457 * evaluation of a method or object
461 * DESCRIPTION: Check a returned package object for the correct count and
462 * correct type of all sub-objects.
464 ******************************************************************************/
468 ACPI_PREDEFINED_DATA *Data,
469 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
471 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
472 const ACPI_PREDEFINED_INFO *Package;
473 ACPI_OPERAND_OBJECT **Elements;
474 ACPI_STATUS Status = AE_OK;
475 UINT32 ExpectedCount;
480 ACPI_FUNCTION_NAME (NsCheckPackage);
483 /* The package info for this name is in the next table entry */
485 Package = Data->Predefined + 1;
487 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
488 "%s Validating return Package of Type %X, Count %X\n",
489 Data->Pathname, Package->RetInfo.Type, ReturnObject->Package.Count));
492 * For variable-length Packages, we can safely remove all embedded
493 * and trailing NULL package elements
495 AcpiNsRemoveNullElements (Data, Package->RetInfo.Type, ReturnObject);
497 /* Extract package count and elements array */
499 Elements = ReturnObject->Package.Elements;
500 Count = ReturnObject->Package.Count;
502 /* The package must have at least one element, else invalid */
506 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
507 "Return Package has no elements (empty)"));
509 return (AE_AML_OPERAND_VALUE);
513 * Decode the type of the expected package contents
515 * PTYPE1 packages contain no subpackages
516 * PTYPE2 packages contain sub-packages
518 switch (Package->RetInfo.Type)
520 case ACPI_PTYPE1_FIXED:
523 * The package count is fixed and there are no sub-packages
525 * If package is too small, exit.
526 * If package is larger than expected, issue warning but continue
528 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
529 if (Count < ExpectedCount)
531 goto PackageTooSmall;
533 else if (Count > ExpectedCount)
535 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
536 "%s: Return Package is larger than needed - "
537 "found %u, expected %u\n",
538 Data->Pathname, Count, ExpectedCount));
541 /* Validate all elements of the returned package */
543 Status = AcpiNsCheckPackageElements (Data, Elements,
544 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
545 Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
549 case ACPI_PTYPE1_VAR:
552 * The package count is variable, there are no sub-packages, and all
553 * elements must be of the same type
555 for (i = 0; i < Count; i++)
557 Status = AcpiNsCheckObjectType (Data, Elements,
558 Package->RetInfo.ObjectType1, i);
559 if (ACPI_FAILURE (Status))
568 case ACPI_PTYPE1_OPTION:
571 * The package count is variable, there are no sub-packages. There are
572 * a fixed number of required elements, and a variable number of
575 * Check if package is at least as large as the minimum required
577 ExpectedCount = Package->RetInfo3.Count;
578 if (Count < ExpectedCount)
580 goto PackageTooSmall;
583 /* Variable number of sub-objects */
585 for (i = 0; i < Count; i++)
587 if (i < Package->RetInfo3.Count)
589 /* These are the required package elements (0, 1, or 2) */
591 Status = AcpiNsCheckObjectType (Data, Elements,
592 Package->RetInfo3.ObjectType[i], i);
593 if (ACPI_FAILURE (Status))
600 /* These are the optional package elements */
602 Status = AcpiNsCheckObjectType (Data, Elements,
603 Package->RetInfo3.TailObjectType, i);
604 if (ACPI_FAILURE (Status))
614 case ACPI_PTYPE2_REV_FIXED:
616 /* First element is the (Integer) revision */
618 Status = AcpiNsCheckObjectType (Data, Elements,
619 ACPI_RTYPE_INTEGER, 0);
620 if (ACPI_FAILURE (Status))
628 /* Examine the sub-packages */
630 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
634 case ACPI_PTYPE2_PKG_COUNT:
636 /* First element is the (Integer) count of sub-packages to follow */
638 Status = AcpiNsCheckObjectType (Data, Elements,
639 ACPI_RTYPE_INTEGER, 0);
640 if (ACPI_FAILURE (Status))
646 * Count cannot be larger than the parent package length, but allow it
647 * to be smaller. The >= accounts for the Integer above.
649 ExpectedCount = (UINT32) (*Elements)->Integer.Value;
650 if (ExpectedCount >= Count)
652 goto PackageTooSmall;
655 Count = ExpectedCount;
658 /* Examine the sub-packages */
660 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
665 case ACPI_PTYPE2_FIXED:
666 case ACPI_PTYPE2_MIN:
667 case ACPI_PTYPE2_COUNT:
668 case ACPI_PTYPE2_FIX_VAR:
671 * These types all return a single Package that consists of a
672 * variable number of sub-Packages.
674 * First, ensure that the first element is a sub-Package. If not,
675 * the BIOS may have incorrectly returned the object as a single
676 * package instead of a Package of Packages (a common error if
677 * there is only one entry). We may be able to repair this by
678 * wrapping the returned Package with a new outer Package.
680 if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
682 /* Create the new outer package and populate it */
684 Status = AcpiNsWrapWithPackage (Data, ReturnObject, ReturnObjectPtr);
685 if (ACPI_FAILURE (Status))
690 /* Update locals to point to the new package (of 1 element) */
692 ReturnObject = *ReturnObjectPtr;
693 Elements = ReturnObject->Package.Elements;
697 /* Examine the sub-packages */
699 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
705 /* Should not get here if predefined info table is correct */
707 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
708 "Invalid internal return type in table entry: %X",
709 Package->RetInfo.Type));
711 return (AE_AML_INTERNAL);
719 /* Error exit for the case with an incorrect package count */
721 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
722 "Return Package is too small - found %u elements, expected %u",
723 Count, ExpectedCount));
725 return (AE_AML_OPERAND_VALUE);
729 /*******************************************************************************
731 * FUNCTION: AcpiNsCheckPackageList
733 * PARAMETERS: Data - Pointer to validation data structure
734 * Package - Pointer to package-specific info for method
735 * Elements - Element list of parent package. All elements
736 * of this list should be of type Package.
737 * Count - Count of subpackages
741 * DESCRIPTION: Examine a list of subpackages
743 ******************************************************************************/
746 AcpiNsCheckPackageList (
747 ACPI_PREDEFINED_DATA *Data,
748 const ACPI_PREDEFINED_INFO *Package,
749 ACPI_OPERAND_OBJECT **Elements,
752 ACPI_OPERAND_OBJECT *SubPackage;
753 ACPI_OPERAND_OBJECT **SubElements;
755 UINT32 ExpectedCount;
761 * Validate each sub-Package in the parent Package
763 * NOTE: assumes list of sub-packages contains no NULL elements.
764 * Any NULL elements should have been removed by earlier call
765 * to AcpiNsRemoveNullElements.
767 for (i = 0; i < Count; i++)
769 SubPackage = *Elements;
770 SubElements = SubPackage->Package.Elements;
771 Data->ParentPackage = SubPackage;
773 /* Each sub-object must be of type Package */
775 Status = AcpiNsCheckObjectType (Data, &SubPackage,
776 ACPI_RTYPE_PACKAGE, i);
777 if (ACPI_FAILURE (Status))
782 /* Examine the different types of expected sub-packages */
784 Data->ParentPackage = SubPackage;
785 switch (Package->RetInfo.Type)
788 case ACPI_PTYPE2_PKG_COUNT:
789 case ACPI_PTYPE2_REV_FIXED:
791 /* Each subpackage has a fixed number of elements */
793 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
794 if (SubPackage->Package.Count < ExpectedCount)
796 goto PackageTooSmall;
799 Status = AcpiNsCheckPackageElements (Data, SubElements,
800 Package->RetInfo.ObjectType1,
801 Package->RetInfo.Count1,
802 Package->RetInfo.ObjectType2,
803 Package->RetInfo.Count2, 0);
804 if (ACPI_FAILURE (Status))
811 case ACPI_PTYPE2_FIX_VAR:
813 * Each subpackage has a fixed number of elements and an
816 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
817 if (SubPackage->Package.Count < ExpectedCount)
819 goto PackageTooSmall;
822 Status = AcpiNsCheckPackageElements (Data, SubElements,
823 Package->RetInfo.ObjectType1,
824 Package->RetInfo.Count1,
825 Package->RetInfo.ObjectType2,
826 SubPackage->Package.Count - Package->RetInfo.Count1, 0);
827 if (ACPI_FAILURE (Status))
834 case ACPI_PTYPE2_FIXED:
836 /* Each sub-package has a fixed length */
838 ExpectedCount = Package->RetInfo2.Count;
839 if (SubPackage->Package.Count < ExpectedCount)
841 goto PackageTooSmall;
844 /* Check the type of each sub-package element */
846 for (j = 0; j < ExpectedCount; j++)
848 Status = AcpiNsCheckObjectType (Data, &SubElements[j],
849 Package->RetInfo2.ObjectType[j], j);
850 if (ACPI_FAILURE (Status))
858 case ACPI_PTYPE2_MIN:
860 /* Each sub-package has a variable but minimum length */
862 ExpectedCount = Package->RetInfo.Count1;
863 if (SubPackage->Package.Count < ExpectedCount)
865 goto PackageTooSmall;
868 /* Check the type of each sub-package element */
870 Status = AcpiNsCheckPackageElements (Data, SubElements,
871 Package->RetInfo.ObjectType1,
872 SubPackage->Package.Count, 0, 0, 0);
873 if (ACPI_FAILURE (Status))
880 case ACPI_PTYPE2_COUNT:
883 * First element is the (Integer) count of elements, including
884 * the count field (the ACPI name is NumElements)
886 Status = AcpiNsCheckObjectType (Data, SubElements,
887 ACPI_RTYPE_INTEGER, 0);
888 if (ACPI_FAILURE (Status))
894 * Make sure package is large enough for the Count and is
895 * is as large as the minimum size
897 ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
898 if (SubPackage->Package.Count < ExpectedCount)
900 goto PackageTooSmall;
902 if (SubPackage->Package.Count < Package->RetInfo.Count1)
904 ExpectedCount = Package->RetInfo.Count1;
905 goto PackageTooSmall;
907 if (ExpectedCount == 0)
910 * Either the NumEntries element was originally zero or it was
911 * a NULL element and repaired to an Integer of value zero.
912 * In either case, repair it by setting NumEntries to be the
913 * actual size of the subpackage.
915 ExpectedCount = SubPackage->Package.Count;
916 (*SubElements)->Integer.Value = ExpectedCount;
919 /* Check the type of each sub-package element */
921 Status = AcpiNsCheckPackageElements (Data, (SubElements + 1),
922 Package->RetInfo.ObjectType1,
923 (ExpectedCount - 1), 0, 0, 1);
924 if (ACPI_FAILURE (Status))
931 default: /* Should not get here, type was validated by caller */
933 return (AE_AML_INTERNAL);
944 /* The sub-package count was smaller than required */
946 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
947 "Return Sub-Package[%u] is too small - found %u elements, expected %u",
948 i, SubPackage->Package.Count, ExpectedCount));
950 return (AE_AML_OPERAND_VALUE);
954 /*******************************************************************************
956 * FUNCTION: AcpiNsCheckPackageElements
958 * PARAMETERS: Data - Pointer to validation data structure
959 * Elements - Pointer to the package elements array
960 * Type1 - Object type for first group
961 * Count1 - Count for first group
962 * Type2 - Object type for second group
963 * Count2 - Count for second group
964 * StartIndex - Start of the first group of elements
968 * DESCRIPTION: Check that all elements of a package are of the correct object
969 * type. Supports up to two groups of different object types.
971 ******************************************************************************/
974 AcpiNsCheckPackageElements (
975 ACPI_PREDEFINED_DATA *Data,
976 ACPI_OPERAND_OBJECT **Elements,
983 ACPI_OPERAND_OBJECT **ThisElement = Elements;
989 * Up to two groups of package elements are supported by the data
990 * structure. All elements in each group must be of the same type.
991 * The second group can have a count of zero.
993 for (i = 0; i < Count1; i++)
995 Status = AcpiNsCheckObjectType (Data, ThisElement,
996 Type1, i + StartIndex);
997 if (ACPI_FAILURE (Status))
1004 for (i = 0; i < Count2; i++)
1006 Status = AcpiNsCheckObjectType (Data, ThisElement,
1007 Type2, (i + Count1 + StartIndex));
1008 if (ACPI_FAILURE (Status))
1019 /*******************************************************************************
1021 * FUNCTION: AcpiNsCheckObjectType
1023 * PARAMETERS: Data - Pointer to validation data structure
1024 * ReturnObjectPtr - Pointer to the object returned from the
1025 * evaluation of a method or object
1026 * ExpectedBtypes - Bitmap of expected return type(s)
1027 * PackageIndex - Index of object within parent package (if
1028 * applicable - ACPI_NOT_PACKAGE_ELEMENT
1033 * DESCRIPTION: Check the type of the return object against the expected object
1034 * type(s). Use of Btype allows multiple expected object types.
1036 ******************************************************************************/
1039 AcpiNsCheckObjectType (
1040 ACPI_PREDEFINED_DATA *Data,
1041 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
1042 UINT32 ExpectedBtypes,
1043 UINT32 PackageIndex)
1045 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
1046 ACPI_STATUS Status = AE_OK;
1048 char TypeBuffer[48]; /* Room for 5 types */
1052 * If we get a NULL ReturnObject here, it is a NULL package element.
1053 * Since all extraneous NULL package elements were removed earlier by a
1054 * call to AcpiNsRemoveNullElements, this is an unexpected NULL element.
1055 * We will attempt to repair it.
1059 Status = AcpiNsRepairNullElement (Data, ExpectedBtypes,
1060 PackageIndex, ReturnObjectPtr);
1061 if (ACPI_SUCCESS (Status))
1063 return (AE_OK); /* Repair was successful */
1068 /* A Namespace node should not get here, but make sure */
1070 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
1072 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1073 "Invalid return type - Found a Namespace node [%4.4s] type %s",
1074 ReturnObject->Node.Name.Ascii,
1075 AcpiUtGetTypeName (ReturnObject->Node.Type)));
1076 return (AE_AML_OPERAND_TYPE);
1080 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
1081 * The bitmapped type allows multiple possible return types.
1083 * Note, the cases below must handle all of the possible types returned
1084 * from all of the predefined names (including elements of returned
1087 switch (ReturnObject->Common.Type)
1089 case ACPI_TYPE_INTEGER:
1090 ReturnBtype = ACPI_RTYPE_INTEGER;
1093 case ACPI_TYPE_BUFFER:
1094 ReturnBtype = ACPI_RTYPE_BUFFER;
1097 case ACPI_TYPE_STRING:
1098 ReturnBtype = ACPI_RTYPE_STRING;
1101 case ACPI_TYPE_PACKAGE:
1102 ReturnBtype = ACPI_RTYPE_PACKAGE;
1105 case ACPI_TYPE_LOCAL_REFERENCE:
1106 ReturnBtype = ACPI_RTYPE_REFERENCE;
1110 /* Not one of the supported objects, must be incorrect */
1115 /* Is the object one of the expected types? */
1117 if (ReturnBtype & ExpectedBtypes)
1119 /* For reference objects, check that the reference type is correct */
1121 if (ReturnObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
1123 Status = AcpiNsCheckReference (Data, ReturnObject);
1129 /* Type mismatch -- attempt repair of the returned object */
1131 Status = AcpiNsRepairObject (Data, ExpectedBtypes,
1132 PackageIndex, ReturnObjectPtr);
1133 if (ACPI_SUCCESS (Status))
1135 return (AE_OK); /* Repair was successful */
1141 /* Create a string with all expected types for this predefined object */
1143 AcpiNsGetExpectedTypes (TypeBuffer, ExpectedBtypes);
1145 if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
1147 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1148 "Return type mismatch - found %s, expected %s",
1149 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1153 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1154 "Return Package type mismatch at index %u - "
1155 "found %s, expected %s", PackageIndex,
1156 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1159 return (AE_AML_OPERAND_TYPE);
1163 /*******************************************************************************
1165 * FUNCTION: AcpiNsCheckReference
1167 * PARAMETERS: Data - Pointer to validation data structure
1168 * ReturnObject - Object returned from the evaluation of a
1173 * DESCRIPTION: Check a returned reference object for the correct reference
1174 * type. The only reference type that can be returned from a
1175 * predefined method is a named reference. All others are invalid.
1177 ******************************************************************************/
1180 AcpiNsCheckReference (
1181 ACPI_PREDEFINED_DATA *Data,
1182 ACPI_OPERAND_OBJECT *ReturnObject)
1186 * Check the reference object for the correct reference type (opcode).
1187 * The only type of reference that can be converted to an ACPI_OBJECT is
1188 * a reference to a named object (reference class: NAME)
1190 if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
1195 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1196 "Return type mismatch - unexpected reference object type [%s] %2.2X",
1197 AcpiUtGetReferenceName (ReturnObject),
1198 ReturnObject->Reference.Class));
1200 return (AE_AML_OPERAND_TYPE);
1204 /*******************************************************************************
1206 * FUNCTION: AcpiNsGetExpectedTypes
1208 * PARAMETERS: Buffer - Pointer to where the string is returned
1209 * ExpectedBtypes - Bitmap of expected return type(s)
1211 * RETURN: Buffer is populated with type names.
1213 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
1214 * names of expected types, for use in warning messages.
1216 ******************************************************************************/
1219 AcpiNsGetExpectedTypes (
1221 UINT32 ExpectedBtypes)
1230 ThisRtype = ACPI_RTYPE_INTEGER;
1232 for (i = 0; i < ACPI_NUM_RTYPES; i++)
1234 /* If one of the expected types, concatenate the name of this type */
1236 if (ExpectedBtypes & ThisRtype)
1238 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
1239 j = 0; /* Use name separator from now on */
1241 ThisRtype <<= 1; /* Next Rtype */