1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __NSPREDEF_C__
118 #include <contrib/dev/acpica/include/acpi.h>
119 #include <contrib/dev/acpica/include/accommon.h>
120 #include <contrib/dev/acpica/include/acnamesp.h>
121 #include <contrib/dev/acpica/include/acpredef.h>
124 #define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nspredef")
128 /*******************************************************************************
130 * This module validates predefined ACPI objects that appear in the namespace,
131 * at the time they are evaluated (via AcpiEvaluateObject). The purpose of this
132 * validation is to detect problems with BIOS-exposed predefined ACPI objects
133 * before the results are returned to the ACPI-related drivers.
135 * There are several areas that are validated:
137 * 1) The number of input arguments as defined by the method/object in the
138 * ASL is validated against the ACPI specification.
139 * 2) The type of the return object (if any) is validated against the ACPI
141 * 3) For returned package objects, the count of package elements is
142 * validated, as well as the type of each package element. Nested
143 * packages are supported.
145 * For any problems found, a warning message is issued.
147 ******************************************************************************/
149 /* Local prototypes */
154 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
155 const ACPI_PREDEFINED_INFO *Predefined);
158 AcpiNsCheckPackageElements (
160 ACPI_OPERAND_OBJECT **Elements,
168 AcpiNsCheckObjectType (
170 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
171 UINT32 ExpectedBtypes,
172 UINT32 PackageIndex);
175 AcpiNsCheckReference (
177 ACPI_OPERAND_OBJECT *ReturnObject);
181 UINT32 ExpectedBtypes,
183 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
186 * Names for the types that can be returned by the predefined objects.
187 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
189 static const char *AcpiRtypeNames[] =
198 #define ACPI_NOT_PACKAGE ACPI_UINT32_MAX
201 /*******************************************************************************
203 * FUNCTION: AcpiNsCheckPredefinedNames
205 * PARAMETERS: Node - Namespace node for the method/object
206 * ReturnObjectPtr - Pointer to the object returned from the
207 * evaluation of a method or object
211 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
213 ******************************************************************************/
216 AcpiNsCheckPredefinedNames (
217 ACPI_NAMESPACE_NODE *Node,
218 UINT32 UserParamCount,
219 ACPI_STATUS ReturnStatus,
220 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
222 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
223 ACPI_STATUS Status = AE_OK;
224 const ACPI_PREDEFINED_INFO *Predefined;
228 /* Match the name for this method/object against the predefined list */
230 Predefined = AcpiNsCheckForPredefinedName (Node);
232 /* Get the full pathname to the object, for use in error messages */
234 Pathname = AcpiNsGetExternalPathname (Node);
237 return (AE_OK); /* Could not get pathname, ignore */
241 * Check that the parameter count for this method matches the ASL
242 * definition. For predefined names, ensure that both the caller and
243 * the method itself are in accordance with the ACPI specification.
245 AcpiNsCheckParameterCount (Pathname, Node, UserParamCount, Predefined);
247 /* If not a predefined name, we cannot validate the return object */
254 /* If the method failed, we cannot validate the return object */
256 if ((ReturnStatus != AE_OK) && (ReturnStatus != AE_CTRL_RETURN_VALUE))
262 * Only validate the return value on the first successful evaluation of
263 * the method. This ensures that any warnings will only be emitted during
264 * the very first evaluation of the method/object.
266 if (Node->Flags & ANOBJ_EVALUATED)
271 /* Mark the node as having been successfully evaluated */
273 Node->Flags |= ANOBJ_EVALUATED;
276 * If there is no return value, check if we require a return value for
277 * this predefined name. Either one return value is expected, or none,
278 * for both methods and other objects.
280 * Exit now if there is no return object. Warning if one was expected.
284 if ((Predefined->Info.ExpectedBtypes) &&
285 (!(Predefined->Info.ExpectedBtypes & ACPI_RTYPE_NONE)))
287 ACPI_ERROR ((AE_INFO,
288 "%s: Missing expected return value", Pathname));
290 Status = AE_AML_NO_RETURN_VALUE;
296 * We have a return value, but if one wasn't expected, just exit, this is
299 * For example, if the "Implicit Return" feature is enabled, methods will
300 * always return a value
302 if (!Predefined->Info.ExpectedBtypes)
308 * Check that the type of the return object is what is expected for
309 * this predefined name
311 Status = AcpiNsCheckObjectType (Pathname, ReturnObjectPtr,
312 Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE);
313 if (ACPI_FAILURE (Status))
318 /* For returned Package objects, check the type of all sub-objects */
320 if (ReturnObject->Common.Type == ACPI_TYPE_PACKAGE)
322 Status = AcpiNsCheckPackage (Pathname, ReturnObjectPtr, Predefined);
326 ACPI_FREE (Pathname);
331 /*******************************************************************************
333 * FUNCTION: AcpiNsCheckParameterCount
335 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
336 * Node - Namespace node for the method/object
337 * UserParamCount - Number of args passed in by the caller
338 * Predefined - Pointer to entry in predefined name table
342 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
343 * predefined name is what is expected (i.e., what is defined in
344 * the ACPI specification for this predefined name.)
346 ******************************************************************************/
349 AcpiNsCheckParameterCount (
351 ACPI_NAMESPACE_NODE *Node,
352 UINT32 UserParamCount,
353 const ACPI_PREDEFINED_INFO *Predefined)
356 UINT32 RequiredParamsCurrent;
357 UINT32 RequiredParamsOld;
360 /* Methods have 0-7 parameters. All other types have zero. */
363 if (Node->Type == ACPI_TYPE_METHOD)
365 ParamCount = Node->Object->Method.ParamCount;
368 /* Argument count check for non-predefined methods/objects */
373 * Warning if too few or too many arguments have been passed by the
374 * caller. An incorrect number of arguments may not cause the method
375 * to fail. However, the method will fail if there are too few
376 * arguments and the method attempts to use one of the missing ones.
378 if (UserParamCount < ParamCount)
380 ACPI_WARNING ((AE_INFO,
381 "%s: Insufficient arguments - needs %d, found %d",
382 Pathname, ParamCount, UserParamCount));
384 else if (UserParamCount > ParamCount)
386 ACPI_WARNING ((AE_INFO,
387 "%s: Excess arguments - needs %d, found %d",
388 Pathname, ParamCount, UserParamCount));
393 /* Allow two different legal argument counts (_SCP, etc.) */
395 RequiredParamsCurrent = Predefined->Info.ParamCount & 0x0F;
396 RequiredParamsOld = Predefined->Info.ParamCount >> 4;
398 if (UserParamCount != ACPI_UINT32_MAX)
400 /* Validate the user-supplied parameter count */
402 if ((UserParamCount != RequiredParamsCurrent) &&
403 (UserParamCount != RequiredParamsOld))
405 ACPI_WARNING ((AE_INFO,
406 "%s: Parameter count mismatch - "
407 "caller passed %d, ACPI requires %d",
408 Pathname, UserParamCount, RequiredParamsCurrent));
413 * Only validate the argument count on the first successful evaluation of
414 * the method. This ensures that any warnings will only be emitted during
415 * the very first evaluation of the method/object.
417 if (Node->Flags & ANOBJ_EVALUATED)
423 * Check that the ASL-defined parameter count is what is expected for
424 * this predefined name.
426 if ((ParamCount != RequiredParamsCurrent) &&
427 (ParamCount != RequiredParamsOld))
429 ACPI_WARNING ((AE_INFO,
430 "%s: Parameter count mismatch - ASL declared %d, ACPI requires %d",
431 Pathname, ParamCount, RequiredParamsCurrent));
436 /*******************************************************************************
438 * FUNCTION: AcpiNsCheckForPredefinedName
440 * PARAMETERS: Node - Namespace node for the method/object
442 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
444 * DESCRIPTION: Check an object name against the predefined object list.
446 ******************************************************************************/
448 const ACPI_PREDEFINED_INFO *
449 AcpiNsCheckForPredefinedName (
450 ACPI_NAMESPACE_NODE *Node)
452 const ACPI_PREDEFINED_INFO *ThisName;
455 /* Quick check for a predefined name, first character must be underscore */
457 if (Node->Name.Ascii[0] != '_')
462 /* Search info table for a predefined method/object name */
464 ThisName = PredefinedNames;
465 while (ThisName->Info.Name[0])
467 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Info.Name))
469 /* Return pointer to this table entry */
475 * Skip next entry in the table if this name returns a Package
476 * (next entry contains the package info)
478 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
490 /*******************************************************************************
492 * FUNCTION: AcpiNsCheckPackage
494 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
495 * ReturnObjectPtr - Pointer to the object returned from the
496 * evaluation of a method or object
497 * Predefined - Pointer to entry in predefined name table
501 * DESCRIPTION: Check a returned package object for the correct count and
502 * correct type of all sub-objects.
504 ******************************************************************************/
509 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
510 const ACPI_PREDEFINED_INFO *Predefined)
512 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
513 const ACPI_PREDEFINED_INFO *Package;
514 ACPI_OPERAND_OBJECT *SubPackage;
515 ACPI_OPERAND_OBJECT **Elements;
516 ACPI_OPERAND_OBJECT **SubElements;
518 UINT32 ExpectedCount;
524 ACPI_FUNCTION_NAME (NsCheckPackage);
527 /* The package info for this name is in the next table entry */
529 Package = Predefined + 1;
531 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
532 "%s Validating return Package of Type %X, Count %X\n",
533 Pathname, Package->RetInfo.Type, ReturnObject->Package.Count));
535 /* Extract package count and elements array */
537 Elements = ReturnObject->Package.Elements;
538 Count = ReturnObject->Package.Count;
540 /* The package must have at least one element, else invalid */
544 ACPI_WARNING ((AE_INFO,
545 "%s: Return Package has no elements (empty)", Pathname));
547 return (AE_AML_OPERAND_VALUE);
551 * Decode the type of the expected package contents
553 * PTYPE1 packages contain no subpackages
554 * PTYPE2 packages contain sub-packages
556 switch (Package->RetInfo.Type)
558 case ACPI_PTYPE1_FIXED:
561 * The package count is fixed and there are no sub-packages
563 * If package is too small, exit.
564 * If package is larger than expected, issue warning but continue
566 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
567 if (Count < ExpectedCount)
569 goto PackageTooSmall;
571 else if (Count > ExpectedCount)
573 ACPI_WARNING ((AE_INFO,
574 "%s: Return Package is larger than needed - "
575 "found %u, expected %u", Pathname, Count, ExpectedCount));
578 /* Validate all elements of the returned package */
580 Status = AcpiNsCheckPackageElements (Pathname, Elements,
581 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
582 Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
583 if (ACPI_FAILURE (Status))
590 case ACPI_PTYPE1_VAR:
593 * The package count is variable, there are no sub-packages, and all
594 * elements must be of the same type
596 for (i = 0; i < Count; i++)
598 Status = AcpiNsCheckObjectType (Pathname, Elements,
599 Package->RetInfo.ObjectType1, i);
600 if (ACPI_FAILURE (Status))
609 case ACPI_PTYPE1_OPTION:
612 * The package count is variable, there are no sub-packages. There are
613 * a fixed number of required elements, and a variable number of
616 * Check if package is at least as large as the minimum required
618 ExpectedCount = Package->RetInfo3.Count;
619 if (Count < ExpectedCount)
621 goto PackageTooSmall;
624 /* Variable number of sub-objects */
626 for (i = 0; i < Count; i++)
628 if (i < Package->RetInfo3.Count)
630 /* These are the required package elements (0, 1, or 2) */
632 Status = AcpiNsCheckObjectType (Pathname, Elements,
633 Package->RetInfo3.ObjectType[i], i);
634 if (ACPI_FAILURE (Status))
641 /* These are the optional package elements */
643 Status = AcpiNsCheckObjectType (Pathname, Elements,
644 Package->RetInfo3.TailObjectType, i);
645 if (ACPI_FAILURE (Status))
655 case ACPI_PTYPE2_PKG_COUNT:
657 /* First element is the (Integer) count of sub-packages to follow */
659 Status = AcpiNsCheckObjectType (Pathname, Elements,
660 ACPI_RTYPE_INTEGER, 0);
661 if (ACPI_FAILURE (Status))
667 * Count cannot be larger than the parent package length, but allow it
668 * to be smaller. The >= accounts for the Integer above.
670 ExpectedCount = (UINT32) (*Elements)->Integer.Value;
671 if (ExpectedCount >= Count)
673 goto PackageTooSmall;
676 Count = ExpectedCount;
679 /* Now we can walk the sub-packages */
681 /*lint -fallthrough */
685 case ACPI_PTYPE2_FIXED:
686 case ACPI_PTYPE2_MIN:
687 case ACPI_PTYPE2_COUNT:
690 * These types all return a single package that consists of a variable
691 * number of sub-packages
693 for (i = 0; i < Count; i++)
695 SubPackage = *Elements;
696 SubElements = SubPackage->Package.Elements;
698 /* Each sub-object must be of type Package */
700 Status = AcpiNsCheckObjectType (Pathname, &SubPackage,
701 ACPI_RTYPE_PACKAGE, i);
702 if (ACPI_FAILURE (Status))
707 /* Examine the different types of sub-packages */
709 switch (Package->RetInfo.Type)
712 case ACPI_PTYPE2_PKG_COUNT:
714 /* Each subpackage has a fixed number of elements */
717 Package->RetInfo.Count1 + Package->RetInfo.Count2;
718 if (SubPackage->Package.Count != ExpectedCount)
720 Count = SubPackage->Package.Count;
721 goto PackageTooSmall;
724 Status = AcpiNsCheckPackageElements (Pathname, SubElements,
725 Package->RetInfo.ObjectType1,
726 Package->RetInfo.Count1,
727 Package->RetInfo.ObjectType2,
728 Package->RetInfo.Count2, 0);
729 if (ACPI_FAILURE (Status))
735 case ACPI_PTYPE2_FIXED:
737 /* Each sub-package has a fixed length */
739 ExpectedCount = Package->RetInfo2.Count;
740 if (SubPackage->Package.Count < ExpectedCount)
742 Count = SubPackage->Package.Count;
743 goto PackageTooSmall;
746 /* Check the type of each sub-package element */
748 for (j = 0; j < ExpectedCount; j++)
750 Status = AcpiNsCheckObjectType (Pathname, &SubElements[j],
751 Package->RetInfo2.ObjectType[j], j);
752 if (ACPI_FAILURE (Status))
759 case ACPI_PTYPE2_MIN:
761 /* Each sub-package has a variable but minimum length */
763 ExpectedCount = Package->RetInfo.Count1;
764 if (SubPackage->Package.Count < ExpectedCount)
766 Count = SubPackage->Package.Count;
767 goto PackageTooSmall;
770 /* Check the type of each sub-package element */
772 Status = AcpiNsCheckPackageElements (Pathname, SubElements,
773 Package->RetInfo.ObjectType1,
774 SubPackage->Package.Count, 0, 0, 0);
775 if (ACPI_FAILURE (Status))
781 case ACPI_PTYPE2_COUNT:
783 /* First element is the (Integer) count of elements to follow */
785 Status = AcpiNsCheckObjectType (Pathname, SubElements,
786 ACPI_RTYPE_INTEGER, 0);
787 if (ACPI_FAILURE (Status))
792 /* Make sure package is large enough for the Count */
794 ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
795 if (SubPackage->Package.Count < ExpectedCount)
797 Count = SubPackage->Package.Count;
798 goto PackageTooSmall;
801 /* Check the type of each sub-package element */
803 Status = AcpiNsCheckPackageElements (Pathname,
805 Package->RetInfo.ObjectType1,
806 (ExpectedCount - 1), 0, 0, 1);
807 if (ACPI_FAILURE (Status))
824 /* Should not get here if predefined info table is correct */
826 ACPI_WARNING ((AE_INFO,
827 "%s: Invalid internal return type in table entry: %X",
828 Pathname, Package->RetInfo.Type));
830 return (AE_AML_INTERNAL);
838 /* Error exit for the case with an incorrect package count */
840 ACPI_WARNING ((AE_INFO, "%s: Return Package is too small - "
841 "found %u, expected %u", Pathname, Count, ExpectedCount));
843 return (AE_AML_OPERAND_VALUE);
847 /*******************************************************************************
849 * FUNCTION: AcpiNsCheckPackageElements
851 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
852 * Elements - Pointer to the package elements array
853 * Type1 - Object type for first group
854 * Count1 - Count for first group
855 * Type2 - Object type for second group
856 * Count2 - Count for second group
857 * StartIndex - Start of the first group of elements
861 * DESCRIPTION: Check that all elements of a package are of the correct object
862 * type. Supports up to two groups of different object types.
864 ******************************************************************************/
867 AcpiNsCheckPackageElements (
869 ACPI_OPERAND_OBJECT **Elements,
876 ACPI_OPERAND_OBJECT **ThisElement = Elements;
882 * Up to two groups of package elements are supported by the data
883 * structure. All elements in each group must be of the same type.
884 * The second group can have a count of zero.
886 for (i = 0; i < Count1; i++)
888 Status = AcpiNsCheckObjectType (Pathname, ThisElement,
889 Type1, i + StartIndex);
890 if (ACPI_FAILURE (Status))
897 for (i = 0; i < Count2; i++)
899 Status = AcpiNsCheckObjectType (Pathname, ThisElement,
900 Type2, (i + Count1 + StartIndex));
901 if (ACPI_FAILURE (Status))
912 /*******************************************************************************
914 * FUNCTION: AcpiNsCheckObjectType
916 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
917 * ReturnObjectPtr - Pointer to the object returned from the
918 * evaluation of a method or object
919 * ExpectedBtypes - Bitmap of expected return type(s)
920 * PackageIndex - Index of object within parent package (if
921 * applicable - ACPI_NOT_PACKAGE otherwise)
925 * DESCRIPTION: Check the type of the return object against the expected object
926 * type(s). Use of Btype allows multiple expected object types.
928 ******************************************************************************/
931 AcpiNsCheckObjectType (
933 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
934 UINT32 ExpectedBtypes,
937 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
938 ACPI_STATUS Status = AE_OK;
940 char TypeBuffer[48]; /* Room for 5 types */
947 * If we get a NULL ReturnObject here, it is a NULL package element,
948 * and this is always an error.
955 /* A Namespace node should not get here, but make sure */
957 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
959 ACPI_WARNING ((AE_INFO,
960 "%s: Invalid return type - Found a Namespace node [%4.4s] type %s",
961 Pathname, ReturnObject->Node.Name.Ascii,
962 AcpiUtGetTypeName (ReturnObject->Node.Type)));
963 return (AE_AML_OPERAND_TYPE);
967 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
968 * The bitmapped type allows multiple possible return types.
970 * Note, the cases below must handle all of the possible types returned
971 * from all of the predefined names (including elements of returned
974 switch (ReturnObject->Common.Type)
976 case ACPI_TYPE_INTEGER:
977 ReturnBtype = ACPI_RTYPE_INTEGER;
980 case ACPI_TYPE_BUFFER:
981 ReturnBtype = ACPI_RTYPE_BUFFER;
984 case ACPI_TYPE_STRING:
985 ReturnBtype = ACPI_RTYPE_STRING;
988 case ACPI_TYPE_PACKAGE:
989 ReturnBtype = ACPI_RTYPE_PACKAGE;
992 case ACPI_TYPE_LOCAL_REFERENCE:
993 ReturnBtype = ACPI_RTYPE_REFERENCE;
997 /* Not one of the supported objects, must be incorrect */
1002 /* Is the object one of the expected types? */
1004 if (!(ReturnBtype & ExpectedBtypes))
1006 /* Type mismatch -- attempt repair of the returned object */
1008 Status = AcpiNsRepairObject (ExpectedBtypes, PackageIndex,
1010 if (ACPI_SUCCESS (Status))
1017 /* For reference objects, check that the reference type is correct */
1019 if (ReturnObject->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
1021 Status = AcpiNsCheckReference (Pathname, ReturnObject);
1029 /* Create a string with all expected types for this predefined object */
1033 ThisRtype = ACPI_RTYPE_INTEGER;
1035 for (i = 0; i < ACPI_NUM_RTYPES; i++)
1037 /* If one of the expected types, concatenate the name of this type */
1039 if (ExpectedBtypes & ThisRtype)
1041 ACPI_STRCAT (TypeBuffer, &AcpiRtypeNames[i][j]);
1042 j = 0; /* Use name separator from now on */
1044 ThisRtype <<= 1; /* Next Rtype */
1047 if (PackageIndex == ACPI_NOT_PACKAGE)
1049 ACPI_WARNING ((AE_INFO,
1050 "%s: Return type mismatch - found %s, expected %s",
1051 Pathname, AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1055 ACPI_WARNING ((AE_INFO,
1056 "%s: Return Package type mismatch at index %u - "
1057 "found %s, expected %s", Pathname, PackageIndex,
1058 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1061 return (AE_AML_OPERAND_TYPE);
1065 /*******************************************************************************
1067 * FUNCTION: AcpiNsCheckReference
1069 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
1070 * ReturnObject - Object returned from the evaluation of a
1075 * DESCRIPTION: Check a returned reference object for the correct reference
1076 * type. The only reference type that can be returned from a
1077 * predefined method is a named reference. All others are invalid.
1079 ******************************************************************************/
1082 AcpiNsCheckReference (
1084 ACPI_OPERAND_OBJECT *ReturnObject)
1088 * Check the reference object for the correct reference type (opcode).
1089 * The only type of reference that can be converted to an ACPI_OBJECT is
1090 * a reference to a named object (reference class: NAME)
1092 if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
1097 ACPI_WARNING ((AE_INFO,
1098 "%s: Return type mismatch - "
1099 "unexpected reference object type [%s] %2.2X",
1100 Pathname, AcpiUtGetReferenceName (ReturnObject),
1101 ReturnObject->Reference.Class));
1103 return (AE_AML_OPERAND_TYPE);
1107 /*******************************************************************************
1109 * FUNCTION: AcpiNsRepairObject
1111 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
1112 * PackageIndex - Used to determine if target is in a package
1113 * ReturnObjectPtr - Pointer to the object returned from the
1114 * evaluation of a method or object
1116 * RETURN: Status. AE_OK if repair was successful.
1118 * DESCRIPTION: Attempt to repair/convert a return object of a type that was
1121 ******************************************************************************/
1124 AcpiNsRepairObject (
1125 UINT32 ExpectedBtypes,
1126 UINT32 PackageIndex,
1127 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
1129 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
1130 ACPI_OPERAND_OBJECT *NewObject;
1134 switch (ReturnObject->Common.Type)
1136 case ACPI_TYPE_BUFFER:
1138 if (!(ExpectedBtypes & ACPI_RTYPE_STRING))
1140 return (AE_AML_OPERAND_TYPE);
1144 * Have a Buffer, expected a String, convert. Use a ToString
1145 * conversion, no transform performed on the buffer data. The best
1146 * example of this is the _BIF method, where the string data from
1147 * the battery is often (incorrectly) returned as buffer object(s).
1150 while ((Length < ReturnObject->Buffer.Length) &&
1151 (ReturnObject->Buffer.Pointer[Length]))
1156 /* Allocate a new string object */
1158 NewObject = AcpiUtCreateStringObject (Length);
1161 return (AE_NO_MEMORY);
1165 * Copy the raw buffer data with no transform. String is already NULL
1166 * terminated at Length+1.
1168 ACPI_MEMCPY (NewObject->String.Pointer,
1169 ReturnObject->Buffer.Pointer, Length);
1171 /* Install the new return object */
1173 AcpiUtRemoveReference (ReturnObject);
1174 *ReturnObjectPtr = NewObject;
1177 * If the object is a package element, we need to:
1178 * 1. Decrement the reference count of the orignal object, it was
1179 * incremented when building the package
1180 * 2. Increment the reference count of the new object, it will be
1181 * decremented when releasing the package
1183 if (PackageIndex != ACPI_NOT_PACKAGE)
1185 AcpiUtRemoveReference (ReturnObject);
1186 AcpiUtAddReference (NewObject);
1194 return (AE_AML_OPERAND_TYPE);