1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 #include <contrib/dev/acpica/include/acpredef.h>
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 * 1) We have a return value, but if one wasn't expected, just exit, this is
220 * not a problem. For example, if the "Implicit Return" feature is
221 * enabled, methods will always return a value.
223 * 2) If the return value can be of any type, then we cannot perform any
226 if ((!Predefined->Info.ExpectedBtypes) ||
227 (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL))
232 /* Create the parameter data block for object validation */
234 Data = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PREDEFINED_DATA));
239 Data->Predefined = Predefined;
240 Data->NodeFlags = Node->Flags;
241 Data->Pathname = Pathname;
244 * Check that the type of the main return object is what is expected
245 * for this predefined name
247 Status = AcpiNsCheckObjectType (Data, ReturnObjectPtr,
248 Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
249 if (ACPI_FAILURE (Status))
255 * For returned Package objects, check the type of all sub-objects.
256 * Note: Package may have been newly created by call above.
258 if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE)
260 Data->ParentPackage = *ReturnObjectPtr;
261 Status = AcpiNsCheckPackage (Data, ReturnObjectPtr);
262 if (ACPI_FAILURE (Status))
269 * The return object was OK, or it was successfully repaired above.
270 * Now make some additional checks such as verifying that package
271 * objects are sorted correctly (if required) or buffer objects have
272 * the correct data width (bytes vs. dwords). These repairs are
273 * performed on a per-name basis, i.e., the code is specific to
274 * particular predefined names.
276 Status = AcpiNsComplexRepairs (Data, Node, Status, ReturnObjectPtr);
280 * If the object validation failed or if we successfully repaired one
281 * or more objects, mark the parent node to suppress further warning
282 * messages during the next evaluation of the same method/object.
284 if (ACPI_FAILURE (Status) || (Data->Flags & ACPI_OBJECT_REPAIRED))
286 Node->Flags |= ANOBJ_EVALUATED;
291 ACPI_FREE (Pathname);
296 /*******************************************************************************
298 * FUNCTION: AcpiNsCheckParameterCount
300 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
301 * Node - Namespace node for the method/object
302 * UserParamCount - Number of args passed in by the caller
303 * Predefined - Pointer to entry in predefined name table
307 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
308 * predefined name is what is expected (i.e., what is defined in
309 * the ACPI specification for this predefined name.)
311 ******************************************************************************/
314 AcpiNsCheckParameterCount (
316 ACPI_NAMESPACE_NODE *Node,
317 UINT32 UserParamCount,
318 const ACPI_PREDEFINED_INFO *Predefined)
321 UINT32 RequiredParamsCurrent;
322 UINT32 RequiredParamsOld;
325 /* Methods have 0-7 parameters. All other types have zero. */
328 if (Node->Type == ACPI_TYPE_METHOD)
330 ParamCount = Node->Object->Method.ParamCount;
336 * Check the parameter count for non-predefined methods/objects.
338 * Warning if too few or too many arguments have been passed by the
339 * caller. An incorrect number of arguments may not cause the method
340 * to fail. However, the method will fail if there are too few
341 * arguments and the method attempts to use one of the missing ones.
343 if (UserParamCount < ParamCount)
345 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
346 "Insufficient arguments - needs %u, found %u",
347 ParamCount, UserParamCount));
349 else if (UserParamCount > ParamCount)
351 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
352 "Excess arguments - needs %u, found %u",
353 ParamCount, UserParamCount));
359 * Validate the user-supplied parameter count.
360 * Allow two different legal argument counts (_SCP, etc.)
362 RequiredParamsCurrent = Predefined->Info.ParamCount & 0x0F;
363 RequiredParamsOld = Predefined->Info.ParamCount >> 4;
365 if (UserParamCount != ACPI_UINT32_MAX)
367 if ((UserParamCount != RequiredParamsCurrent) &&
368 (UserParamCount != RequiredParamsOld))
370 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
371 "Parameter count mismatch - "
372 "caller passed %u, ACPI requires %u",
373 UserParamCount, RequiredParamsCurrent));
378 * Check that the ASL-defined parameter count is what is expected for
379 * this predefined name (parameter count as defined by the ACPI
382 if ((ParamCount != RequiredParamsCurrent) &&
383 (ParamCount != RequiredParamsOld))
385 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, Node->Flags,
386 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
387 ParamCount, RequiredParamsCurrent));
392 /*******************************************************************************
394 * FUNCTION: AcpiNsCheckForPredefinedName
396 * PARAMETERS: Node - Namespace node for the method/object
398 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
400 * DESCRIPTION: Check an object name against the predefined object list.
402 ******************************************************************************/
404 const ACPI_PREDEFINED_INFO *
405 AcpiNsCheckForPredefinedName (
406 ACPI_NAMESPACE_NODE *Node)
408 const ACPI_PREDEFINED_INFO *ThisName;
411 /* Quick check for a predefined name, first character must be underscore */
413 if (Node->Name.Ascii[0] != '_')
418 /* Search info table for a predefined method/object name */
420 ThisName = PredefinedNames;
421 while (ThisName->Info.Name[0])
423 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Info.Name))
429 * Skip next entry in the table if this name returns a Package
430 * (next entry contains the package info)
432 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
440 return (NULL); /* Not found */
444 /*******************************************************************************
446 * FUNCTION: AcpiNsCheckPackage
448 * PARAMETERS: Data - Pointer to validation data structure
449 * ReturnObjectPtr - Pointer to the object returned from the
450 * evaluation of a method or object
454 * DESCRIPTION: Check a returned package object for the correct count and
455 * correct type of all sub-objects.
457 ******************************************************************************/
461 ACPI_PREDEFINED_DATA *Data,
462 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
464 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
465 const ACPI_PREDEFINED_INFO *Package;
466 ACPI_OPERAND_OBJECT **Elements;
467 ACPI_STATUS Status = AE_OK;
468 UINT32 ExpectedCount;
473 ACPI_FUNCTION_NAME (NsCheckPackage);
476 /* The package info for this name is in the next table entry */
478 Package = Data->Predefined + 1;
480 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
481 "%s Validating return Package of Type %X, Count %X\n",
482 Data->Pathname, Package->RetInfo.Type, ReturnObject->Package.Count));
485 * For variable-length Packages, we can safely remove all embedded
486 * and trailing NULL package elements
488 AcpiNsRemoveNullElements (Data, Package->RetInfo.Type, ReturnObject);
490 /* Extract package count and elements array */
492 Elements = ReturnObject->Package.Elements;
493 Count = ReturnObject->Package.Count;
495 /* The package must have at least one element, else invalid */
499 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
500 "Return Package has no elements (empty)"));
502 return (AE_AML_OPERAND_VALUE);
506 * Decode the type of the expected package contents
508 * PTYPE1 packages contain no subpackages
509 * PTYPE2 packages contain sub-packages
511 switch (Package->RetInfo.Type)
513 case ACPI_PTYPE1_FIXED:
516 * The package count is fixed and there are no sub-packages
518 * If package is too small, exit.
519 * If package is larger than expected, issue warning but continue
521 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
522 if (Count < ExpectedCount)
524 goto PackageTooSmall;
526 else if (Count > ExpectedCount)
528 ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
529 "%s: Return Package is larger than needed - "
530 "found %u, expected %u\n",
531 Data->Pathname, Count, ExpectedCount));
534 /* Validate all elements of the returned package */
536 Status = AcpiNsCheckPackageElements (Data, Elements,
537 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
538 Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
542 case ACPI_PTYPE1_VAR:
545 * The package count is variable, there are no sub-packages, and all
546 * elements must be of the same type
548 for (i = 0; i < Count; i++)
550 Status = AcpiNsCheckObjectType (Data, Elements,
551 Package->RetInfo.ObjectType1, i);
552 if (ACPI_FAILURE (Status))
561 case ACPI_PTYPE1_OPTION:
564 * The package count is variable, there are no sub-packages. There are
565 * a fixed number of required elements, and a variable number of
568 * Check if package is at least as large as the minimum required
570 ExpectedCount = Package->RetInfo3.Count;
571 if (Count < ExpectedCount)
573 goto PackageTooSmall;
576 /* Variable number of sub-objects */
578 for (i = 0; i < Count; i++)
580 if (i < Package->RetInfo3.Count)
582 /* These are the required package elements (0, 1, or 2) */
584 Status = AcpiNsCheckObjectType (Data, Elements,
585 Package->RetInfo3.ObjectType[i], i);
586 if (ACPI_FAILURE (Status))
593 /* These are the optional package elements */
595 Status = AcpiNsCheckObjectType (Data, Elements,
596 Package->RetInfo3.TailObjectType, i);
597 if (ACPI_FAILURE (Status))
607 case ACPI_PTYPE2_REV_FIXED:
609 /* First element is the (Integer) revision */
611 Status = AcpiNsCheckObjectType (Data, Elements,
612 ACPI_RTYPE_INTEGER, 0);
613 if (ACPI_FAILURE (Status))
621 /* Examine the sub-packages */
623 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
627 case ACPI_PTYPE2_PKG_COUNT:
629 /* First element is the (Integer) count of sub-packages to follow */
631 Status = AcpiNsCheckObjectType (Data, Elements,
632 ACPI_RTYPE_INTEGER, 0);
633 if (ACPI_FAILURE (Status))
639 * Count cannot be larger than the parent package length, but allow it
640 * to be smaller. The >= accounts for the Integer above.
642 ExpectedCount = (UINT32) (*Elements)->Integer.Value;
643 if (ExpectedCount >= Count)
645 goto PackageTooSmall;
648 Count = ExpectedCount;
651 /* Examine the sub-packages */
653 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
658 case ACPI_PTYPE2_FIXED:
659 case ACPI_PTYPE2_MIN:
660 case ACPI_PTYPE2_COUNT:
663 * These types all return a single Package that consists of a
664 * variable number of sub-Packages.
666 * First, ensure that the first element is a sub-Package. If not,
667 * the BIOS may have incorrectly returned the object as a single
668 * package instead of a Package of Packages (a common error if
669 * there is only one entry). We may be able to repair this by
670 * wrapping the returned Package with a new outer Package.
672 if (*Elements && ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE))
674 /* Create the new outer package and populate it */
676 Status = AcpiNsRepairPackageList (Data, ReturnObjectPtr);
677 if (ACPI_FAILURE (Status))
682 /* Update locals to point to the new package (of 1 element) */
684 ReturnObject = *ReturnObjectPtr;
685 Elements = ReturnObject->Package.Elements;
689 /* Examine the sub-packages */
691 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
697 /* Should not get here if predefined info table is correct */
699 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
700 "Invalid internal return type in table entry: %X",
701 Package->RetInfo.Type));
703 return (AE_AML_INTERNAL);
711 /* Error exit for the case with an incorrect package count */
713 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
714 "Return Package is too small - found %u elements, expected %u",
715 Count, ExpectedCount));
717 return (AE_AML_OPERAND_VALUE);
721 /*******************************************************************************
723 * FUNCTION: AcpiNsCheckPackageList
725 * PARAMETERS: Data - Pointer to validation data structure
726 * Package - Pointer to package-specific info for method
727 * Elements - Element list of parent package. All elements
728 * of this list should be of type Package.
729 * Count - Count of subpackages
733 * DESCRIPTION: Examine a list of subpackages
735 ******************************************************************************/
738 AcpiNsCheckPackageList (
739 ACPI_PREDEFINED_DATA *Data,
740 const ACPI_PREDEFINED_INFO *Package,
741 ACPI_OPERAND_OBJECT **Elements,
744 ACPI_OPERAND_OBJECT *SubPackage;
745 ACPI_OPERAND_OBJECT **SubElements;
747 UINT32 ExpectedCount;
753 * Validate each sub-Package in the parent Package
755 * NOTE: assumes list of sub-packages contains no NULL elements.
756 * Any NULL elements should have been removed by earlier call
757 * to AcpiNsRemoveNullElements.
759 for (i = 0; i < Count; i++)
761 SubPackage = *Elements;
762 SubElements = SubPackage->Package.Elements;
763 Data->ParentPackage = SubPackage;
765 /* Each sub-object must be of type Package */
767 Status = AcpiNsCheckObjectType (Data, &SubPackage,
768 ACPI_RTYPE_PACKAGE, i);
769 if (ACPI_FAILURE (Status))
774 /* Examine the different types of expected sub-packages */
776 Data->ParentPackage = SubPackage;
777 switch (Package->RetInfo.Type)
780 case ACPI_PTYPE2_PKG_COUNT:
781 case ACPI_PTYPE2_REV_FIXED:
783 /* Each subpackage has a fixed number of elements */
785 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
786 if (SubPackage->Package.Count < ExpectedCount)
788 goto PackageTooSmall;
791 Status = AcpiNsCheckPackageElements (Data, SubElements,
792 Package->RetInfo.ObjectType1,
793 Package->RetInfo.Count1,
794 Package->RetInfo.ObjectType2,
795 Package->RetInfo.Count2, 0);
796 if (ACPI_FAILURE (Status))
803 case ACPI_PTYPE2_FIXED:
805 /* Each sub-package has a fixed length */
807 ExpectedCount = Package->RetInfo2.Count;
808 if (SubPackage->Package.Count < ExpectedCount)
810 goto PackageTooSmall;
813 /* Check the type of each sub-package element */
815 for (j = 0; j < ExpectedCount; j++)
817 Status = AcpiNsCheckObjectType (Data, &SubElements[j],
818 Package->RetInfo2.ObjectType[j], j);
819 if (ACPI_FAILURE (Status))
827 case ACPI_PTYPE2_MIN:
829 /* Each sub-package has a variable but minimum length */
831 ExpectedCount = Package->RetInfo.Count1;
832 if (SubPackage->Package.Count < ExpectedCount)
834 goto PackageTooSmall;
837 /* Check the type of each sub-package element */
839 Status = AcpiNsCheckPackageElements (Data, SubElements,
840 Package->RetInfo.ObjectType1,
841 SubPackage->Package.Count, 0, 0, 0);
842 if (ACPI_FAILURE (Status))
849 case ACPI_PTYPE2_COUNT:
852 * First element is the (Integer) count of elements, including
853 * the count field (the ACPI name is NumElements)
855 Status = AcpiNsCheckObjectType (Data, SubElements,
856 ACPI_RTYPE_INTEGER, 0);
857 if (ACPI_FAILURE (Status))
863 * Make sure package is large enough for the Count and is
864 * is as large as the minimum size
866 ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
867 if (SubPackage->Package.Count < ExpectedCount)
869 goto PackageTooSmall;
871 if (SubPackage->Package.Count < Package->RetInfo.Count1)
873 ExpectedCount = Package->RetInfo.Count1;
874 goto PackageTooSmall;
876 if (ExpectedCount == 0)
879 * Either the NumEntries element was originally zero or it was
880 * a NULL element and repaired to an Integer of value zero.
881 * In either case, repair it by setting NumEntries to be the
882 * actual size of the subpackage.
884 ExpectedCount = SubPackage->Package.Count;
885 (*SubElements)->Integer.Value = ExpectedCount;
888 /* Check the type of each sub-package element */
890 Status = AcpiNsCheckPackageElements (Data, (SubElements + 1),
891 Package->RetInfo.ObjectType1,
892 (ExpectedCount - 1), 0, 0, 1);
893 if (ACPI_FAILURE (Status))
900 default: /* Should not get here, type was validated by caller */
902 return (AE_AML_INTERNAL);
913 /* The sub-package count was smaller than required */
915 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
916 "Return Sub-Package[%u] is too small - found %u elements, expected %u",
917 i, SubPackage->Package.Count, ExpectedCount));
919 return (AE_AML_OPERAND_VALUE);
923 /*******************************************************************************
925 * FUNCTION: AcpiNsCheckPackageElements
927 * PARAMETERS: Data - Pointer to validation data structure
928 * Elements - Pointer to the package elements array
929 * Type1 - Object type for first group
930 * Count1 - Count for first group
931 * Type2 - Object type for second group
932 * Count2 - Count for second group
933 * StartIndex - Start of the first group of elements
937 * DESCRIPTION: Check that all elements of a package are of the correct object
938 * type. Supports up to two groups of different object types.
940 ******************************************************************************/
943 AcpiNsCheckPackageElements (
944 ACPI_PREDEFINED_DATA *Data,
945 ACPI_OPERAND_OBJECT **Elements,
952 ACPI_OPERAND_OBJECT **ThisElement = Elements;
958 * Up to two groups of package elements are supported by the data
959 * structure. All elements in each group must be of the same type.
960 * The second group can have a count of zero.
962 for (i = 0; i < Count1; i++)
964 Status = AcpiNsCheckObjectType (Data, ThisElement,
965 Type1, i + StartIndex);
966 if (ACPI_FAILURE (Status))
973 for (i = 0; i < Count2; i++)
975 Status = AcpiNsCheckObjectType (Data, ThisElement,
976 Type2, (i + Count1 + StartIndex));
977 if (ACPI_FAILURE (Status))
988 /*******************************************************************************
990 * FUNCTION: AcpiNsCheckObjectType
992 * PARAMETERS: Data - Pointer to validation data structure
993 * ReturnObjectPtr - Pointer to the object returned from the
994 * evaluation of a method or object
995 * ExpectedBtypes - Bitmap of expected return type(s)
996 * PackageIndex - Index of object within parent package (if
997 * applicable - ACPI_NOT_PACKAGE_ELEMENT
1002 * DESCRIPTION: Check the type of the return object against the expected object
1003 * type(s). Use of Btype allows multiple expected object types.
1005 ******************************************************************************/
1008 AcpiNsCheckObjectType (
1009 ACPI_PREDEFINED_DATA *Data,
1010 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
1011 UINT32 ExpectedBtypes,
1012 UINT32 PackageIndex)
1014 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
1015 ACPI_STATUS Status = AE_OK;
1017 char TypeBuffer[48]; /* Room for 5 types */
1021 * If we get a NULL ReturnObject here, it is a NULL package element.
1022 * Since all extraneous NULL package elements were removed earlier by a
1023 * call to AcpiNsRemoveNullElements, this is an unexpected NULL element.
1024 * We will attempt to repair it.
1028 Status = AcpiNsRepairNullElement (Data, ExpectedBtypes,
1029 PackageIndex, ReturnObjectPtr);
1030 if (ACPI_SUCCESS (Status))
1032 return (AE_OK); /* Repair was successful */
1037 /* A Namespace node should not get here, but make sure */
1039 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
1041 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1042 "Invalid return type - Found a Namespace node [%4.4s] type %s",
1043 ReturnObject->Node.Name.Ascii,
1044 AcpiUtGetTypeName (ReturnObject->Node.Type)));
1045 return (AE_AML_OPERAND_TYPE);
1049 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
1050 * The bitmapped type allows multiple possible return types.
1052 * Note, the cases below must handle all of the possible types returned
1053 * from all of the predefined names (including elements of returned
1056 switch (ReturnObject->Common.Type)
1058 case ACPI_TYPE_INTEGER:
1059 ReturnBtype = ACPI_RTYPE_INTEGER;
1062 case ACPI_TYPE_BUFFER:
1063 ReturnBtype = ACPI_RTYPE_BUFFER;
1066 case ACPI_TYPE_STRING:
1067 ReturnBtype = ACPI_RTYPE_STRING;
1070 case ACPI_TYPE_PACKAGE:
1071 ReturnBtype = ACPI_RTYPE_PACKAGE;
1074 case ACPI_TYPE_LOCAL_REFERENCE:
1075 ReturnBtype = ACPI_RTYPE_REFERENCE;
1079 /* Not one of the supported objects, must be incorrect */
1084 /* Is the object one of the expected types? */
1086 if (ReturnBtype & ExpectedBtypes)
1088 /* For reference objects, check that the reference type is correct */
1090 if (ReturnObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
1092 Status = AcpiNsCheckReference (Data, ReturnObject);
1098 /* Type mismatch -- attempt repair of the returned object */
1100 Status = AcpiNsRepairObject (Data, ExpectedBtypes,
1101 PackageIndex, ReturnObjectPtr);
1102 if (ACPI_SUCCESS (Status))
1104 return (AE_OK); /* Repair was successful */
1110 /* Create a string with all expected types for this predefined object */
1112 AcpiNsGetExpectedTypes (TypeBuffer, ExpectedBtypes);
1114 if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
1116 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1117 "Return type mismatch - found %s, expected %s",
1118 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1122 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1123 "Return Package type mismatch at index %u - "
1124 "found %s, expected %s", PackageIndex,
1125 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1128 return (AE_AML_OPERAND_TYPE);
1132 /*******************************************************************************
1134 * FUNCTION: AcpiNsCheckReference
1136 * PARAMETERS: Data - Pointer to validation data structure
1137 * ReturnObject - Object returned from the evaluation of a
1142 * DESCRIPTION: Check a returned reference object for the correct reference
1143 * type. The only reference type that can be returned from a
1144 * predefined method is a named reference. All others are invalid.
1146 ******************************************************************************/
1149 AcpiNsCheckReference (
1150 ACPI_PREDEFINED_DATA *Data,
1151 ACPI_OPERAND_OBJECT *ReturnObject)
1155 * Check the reference object for the correct reference type (opcode).
1156 * The only type of reference that can be converted to an ACPI_OBJECT is
1157 * a reference to a named object (reference class: NAME)
1159 if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
1164 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1165 "Return type mismatch - unexpected reference object type [%s] %2.2X",
1166 AcpiUtGetReferenceName (ReturnObject),
1167 ReturnObject->Reference.Class));
1169 return (AE_AML_OPERAND_TYPE);
1173 /*******************************************************************************
1175 * FUNCTION: AcpiNsGetExpectedTypes
1177 * PARAMETERS: Buffer - Pointer to where the string is returned
1178 * ExpectedBtypes - Bitmap of expected return type(s)
1180 * RETURN: Buffer is populated with type names.
1182 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
1183 * names of expected types, for use in warning messages.
1185 ******************************************************************************/
1188 AcpiNsGetExpectedTypes (
1190 UINT32 ExpectedBtypes)
1199 ThisRtype = ACPI_RTYPE_INTEGER;
1201 for (i = 0; i < ACPI_NUM_RTYPES; i++)
1203 /* If one of the expected types, concatenate the name of this type */
1205 if (ExpectedBtypes & ThisRtype)
1207 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
1208 j = 0; /* Use name separator from now on */
1210 ThisRtype <<= 1; /* Next Rtype */