No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / namespace / nspredef.c
blob77d23699b316e9328f624764135ff4d3162571b5
1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
14 * 2. License
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
19 * property rights.
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
38 * conditions are met:
40 * 3. Conditions
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
64 * make.
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
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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
88 * PARTICULAR PURPOSE.
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
97 * LIMITED REMEDY.
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 ACPI_CREATE_PREDEFINED_TABLE
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acnamesp.h"
121 #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
140 * specification.
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 ******************************************************************************/
150 /* Local prototypes */
152 static ACPI_STATUS
153 AcpiNsCheckPackage (
154 ACPI_PREDEFINED_DATA *Data,
155 ACPI_OPERAND_OBJECT **ReturnObjectPtr);
157 static ACPI_STATUS
158 AcpiNsCheckPackageList (
159 ACPI_PREDEFINED_DATA *Data,
160 const ACPI_PREDEFINED_INFO *Package,
161 ACPI_OPERAND_OBJECT **Elements,
162 UINT32 Count);
164 static ACPI_STATUS
165 AcpiNsCheckPackageElements (
166 ACPI_PREDEFINED_DATA *Data,
167 ACPI_OPERAND_OBJECT **Elements,
168 UINT8 Type1,
169 UINT32 Count1,
170 UINT8 Type2,
171 UINT32 Count2,
172 UINT32 StartIndex);
174 static ACPI_STATUS
175 AcpiNsCheckObjectType (
176 ACPI_PREDEFINED_DATA *Data,
177 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
178 UINT32 ExpectedBtypes,
179 UINT32 PackageIndex);
181 static ACPI_STATUS
182 AcpiNsCheckReference (
183 ACPI_PREDEFINED_DATA *Data,
184 ACPI_OPERAND_OBJECT *ReturnObject);
186 static void
187 AcpiNsGetExpectedTypes (
188 char *Buffer,
189 UINT32 ExpectedBtypes);
192 * Names for the types that can be returned by the predefined objects.
193 * Used for warning messages. Must be in the same order as the ACPI_RTYPEs
195 static const char *AcpiRtypeNames[] =
197 "/Integer",
198 "/String",
199 "/Buffer",
200 "/Package",
201 "/Reference",
205 /*******************************************************************************
207 * FUNCTION: AcpiNsCheckPredefinedNames
209 * PARAMETERS: Node - Namespace node for the method/object
210 * UserParamCount - Number of parameters actually passed
211 * ReturnStatus - Status from the object evaluation
212 * ReturnObjectPtr - Pointer to the object returned from the
213 * evaluation of a method or object
215 * RETURN: Status
217 * DESCRIPTION: Check an ACPI name for a match in the predefined name list.
219 ******************************************************************************/
221 ACPI_STATUS
222 AcpiNsCheckPredefinedNames (
223 ACPI_NAMESPACE_NODE *Node,
224 UINT32 UserParamCount,
225 ACPI_STATUS ReturnStatus,
226 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
228 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
229 ACPI_STATUS Status = AE_OK;
230 const ACPI_PREDEFINED_INFO *Predefined;
231 char *Pathname;
232 ACPI_PREDEFINED_DATA *Data;
235 /* Match the name for this method/object against the predefined list */
237 Predefined = AcpiNsCheckForPredefinedName (Node);
239 /* Get the full pathname to the object, for use in warning messages */
241 Pathname = AcpiNsGetExternalPathname (Node);
242 if (!Pathname)
244 return (AE_OK); /* Could not get pathname, ignore */
248 * Check that the parameter count for this method matches the ASL
249 * definition. For predefined names, ensure that both the caller and
250 * the method itself are in accordance with the ACPI specification.
252 AcpiNsCheckParameterCount (Pathname, Node, UserParamCount, Predefined);
254 /* If not a predefined name, we cannot validate the return object */
256 if (!Predefined)
258 goto Cleanup;
262 * If the method failed or did not actually return an object, we cannot
263 * validate the return object
265 if ((ReturnStatus != AE_OK) && (ReturnStatus != AE_CTRL_RETURN_VALUE))
267 goto Cleanup;
271 * If there is no return value, check if we require a return value for
272 * this predefined name. Either one return value is expected, or none,
273 * for both methods and other objects.
275 * Exit now if there is no return object. Warning if one was expected.
277 if (!ReturnObject)
279 if ((Predefined->Info.ExpectedBtypes) &&
280 (!(Predefined->Info.ExpectedBtypes & ACPI_RTYPE_NONE)))
282 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
283 "Missing expected return value"));
285 Status = AE_AML_NO_RETURN_VALUE;
287 goto Cleanup;
291 * We have a return value, but if one wasn't expected, just exit, this is
292 * not a problem. For example, if the "Implicit Return" feature is
293 * enabled, methods will always return a value.
295 if (!Predefined->Info.ExpectedBtypes)
297 goto Cleanup;
300 /* Create the parameter data block for object validation */
302 Data = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PREDEFINED_DATA));
303 if (!Data)
305 goto Cleanup;
307 Data->Predefined = Predefined;
308 Data->NodeFlags = Node->Flags;
309 Data->Pathname = Pathname;
312 * Check that the type of the return object is what is expected for
313 * this predefined name
315 Status = AcpiNsCheckObjectType (Data, ReturnObjectPtr,
316 Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
317 if (ACPI_FAILURE (Status))
319 goto CheckValidationStatus;
322 /* For returned Package objects, check the type of all sub-objects */
324 if (ReturnObject->Common.Type == ACPI_TYPE_PACKAGE)
326 Status = AcpiNsCheckPackage (Data, ReturnObjectPtr);
330 CheckValidationStatus:
332 * If the object validation failed or if we successfully repaired one
333 * or more objects, mark the parent node to suppress further warning
334 * messages during the next evaluation of the same method/object.
336 if (ACPI_FAILURE (Status) || (Data->Flags & ACPI_OBJECT_REPAIRED))
338 Node->Flags |= ANOBJ_EVALUATED;
340 ACPI_FREE (Data);
343 Cleanup:
344 ACPI_FREE (Pathname);
345 return (Status);
349 /*******************************************************************************
351 * FUNCTION: AcpiNsCheckParameterCount
353 * PARAMETERS: Pathname - Full pathname to the node (for error msgs)
354 * Node - Namespace node for the method/object
355 * UserParamCount - Number of args passed in by the caller
356 * Predefined - Pointer to entry in predefined name table
358 * RETURN: None
360 * DESCRIPTION: Check that the declared (in ASL/AML) parameter count for a
361 * predefined name is what is expected (i.e., what is defined in
362 * the ACPI specification for this predefined name.)
364 ******************************************************************************/
366 void
367 AcpiNsCheckParameterCount (
368 char *Pathname,
369 ACPI_NAMESPACE_NODE *Node,
370 UINT32 UserParamCount,
371 const ACPI_PREDEFINED_INFO *Predefined)
373 UINT32 ParamCount;
374 UINT32 RequiredParamsCurrent;
375 UINT32 RequiredParamsOld;
378 /* Methods have 0-7 parameters. All other types have zero. */
380 ParamCount = 0;
381 if (Node->Type == ACPI_TYPE_METHOD)
383 ParamCount = Node->Object->Method.ParamCount;
386 if (!Predefined)
389 * Check the parameter count for non-predefined methods/objects.
391 * Warning if too few or too many arguments have been passed by the
392 * caller. An incorrect number of arguments may not cause the method
393 * to fail. However, the method will fail if there are too few
394 * arguments and the method attempts to use one of the missing ones.
396 if (UserParamCount < ParamCount)
398 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
399 "Insufficient arguments - needs %u, found %u",
400 ParamCount, UserParamCount));
402 else if (UserParamCount > ParamCount)
404 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
405 "Excess arguments - needs %u, found %u",
406 ParamCount, UserParamCount));
408 return;
412 * Validate the user-supplied parameter count.
413 * Allow two different legal argument counts (_SCP, etc.)
415 RequiredParamsCurrent = Predefined->Info.ParamCount & 0x0F;
416 RequiredParamsOld = Predefined->Info.ParamCount >> 4;
418 if (UserParamCount != ACPI_UINT32_MAX)
420 if ((UserParamCount != RequiredParamsCurrent) &&
421 (UserParamCount != RequiredParamsOld))
423 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, ACPI_WARN_ALWAYS,
424 "Parameter count mismatch - "
425 "caller passed %u, ACPI requires %u",
426 UserParamCount, RequiredParamsCurrent));
431 * Check that the ASL-defined parameter count is what is expected for
432 * this predefined name (parameter count as defined by the ACPI
433 * specification)
435 if ((ParamCount != RequiredParamsCurrent) &&
436 (ParamCount != RequiredParamsOld))
438 ACPI_WARN_PREDEFINED ((AE_INFO, Pathname, Node->Flags,
439 "Parameter count mismatch - ASL declared %u, ACPI requires %u",
440 ParamCount, RequiredParamsCurrent));
445 /*******************************************************************************
447 * FUNCTION: AcpiNsCheckForPredefinedName
449 * PARAMETERS: Node - Namespace node for the method/object
451 * RETURN: Pointer to entry in predefined table. NULL indicates not found.
453 * DESCRIPTION: Check an object name against the predefined object list.
455 ******************************************************************************/
457 const ACPI_PREDEFINED_INFO *
458 AcpiNsCheckForPredefinedName (
459 ACPI_NAMESPACE_NODE *Node)
461 const ACPI_PREDEFINED_INFO *ThisName;
464 /* Quick check for a predefined name, first character must be underscore */
466 if (Node->Name.Ascii[0] != '_')
468 return (NULL);
471 /* Search info table for a predefined method/object name */
473 ThisName = PredefinedNames;
474 while (ThisName->Info.Name[0])
476 if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Info.Name))
478 return (ThisName);
482 * Skip next entry in the table if this name returns a Package
483 * (next entry contains the package info)
485 if (ThisName->Info.ExpectedBtypes & ACPI_RTYPE_PACKAGE)
487 ThisName++;
490 ThisName++;
493 return (NULL); /* Not found */
497 /*******************************************************************************
499 * FUNCTION: AcpiNsCheckPackage
501 * PARAMETERS: Data - Pointer to validation data structure
502 * ReturnObjectPtr - Pointer to the object returned from the
503 * evaluation of a method or object
505 * RETURN: Status
507 * DESCRIPTION: Check a returned package object for the correct count and
508 * correct type of all sub-objects.
510 ******************************************************************************/
512 static ACPI_STATUS
513 AcpiNsCheckPackage (
514 ACPI_PREDEFINED_DATA *Data,
515 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
517 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
518 const ACPI_PREDEFINED_INFO *Package;
519 ACPI_OPERAND_OBJECT **Elements;
520 ACPI_STATUS Status = AE_OK;
521 UINT32 ExpectedCount;
522 UINT32 Count;
523 UINT32 i;
526 ACPI_FUNCTION_NAME (NsCheckPackage);
529 /* The package info for this name is in the next table entry */
531 Package = Data->Predefined + 1;
533 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES,
534 "%s Validating return Package of Type %X, Count %X\n",
535 Data->Pathname, Package->RetInfo.Type, ReturnObject->Package.Count));
537 /* Extract package count and elements array */
539 Elements = ReturnObject->Package.Elements;
540 Count = ReturnObject->Package.Count;
542 /* The package must have at least one element, else invalid */
544 if (!Count)
546 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
547 "Return Package has no elements (empty)"));
549 return (AE_AML_OPERAND_VALUE);
553 * Decode the type of the expected package contents
555 * PTYPE1 packages contain no subpackages
556 * PTYPE2 packages contain sub-packages
558 switch (Package->RetInfo.Type)
560 case ACPI_PTYPE1_FIXED:
563 * The package count is fixed and there are no sub-packages
565 * If package is too small, exit.
566 * If package is larger than expected, issue warning but continue
568 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
569 if (Count < ExpectedCount)
571 goto PackageTooSmall;
573 else if (Count > ExpectedCount)
575 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
576 "Return Package is larger than needed - "
577 "found %u, expected %u", Count, ExpectedCount));
580 /* Validate all elements of the returned package */
582 Status = AcpiNsCheckPackageElements (Data, Elements,
583 Package->RetInfo.ObjectType1, Package->RetInfo.Count1,
584 Package->RetInfo.ObjectType2, Package->RetInfo.Count2, 0);
585 break;
588 case ACPI_PTYPE1_VAR:
591 * The package count is variable, there are no sub-packages, and all
592 * elements must be of the same type
594 for (i = 0; i < Count; i++)
596 Status = AcpiNsCheckObjectType (Data, Elements,
597 Package->RetInfo.ObjectType1, i);
598 if (ACPI_FAILURE (Status))
600 return (Status);
602 Elements++;
604 break;
607 case ACPI_PTYPE1_OPTION:
610 * The package count is variable, there are no sub-packages. There are
611 * a fixed number of required elements, and a variable number of
612 * optional elements.
614 * Check if package is at least as large as the minimum required
616 ExpectedCount = Package->RetInfo3.Count;
617 if (Count < ExpectedCount)
619 goto PackageTooSmall;
622 /* Variable number of sub-objects */
624 for (i = 0; i < Count; i++)
626 if (i < Package->RetInfo3.Count)
628 /* These are the required package elements (0, 1, or 2) */
630 Status = AcpiNsCheckObjectType (Data, Elements,
631 Package->RetInfo3.ObjectType[i], i);
632 if (ACPI_FAILURE (Status))
634 return (Status);
637 else
639 /* These are the optional package elements */
641 Status = AcpiNsCheckObjectType (Data, Elements,
642 Package->RetInfo3.TailObjectType, i);
643 if (ACPI_FAILURE (Status))
645 return (Status);
648 Elements++;
650 break;
653 case ACPI_PTYPE2_REV_FIXED:
655 /* First element is the (Integer) revision */
657 Status = AcpiNsCheckObjectType (Data, Elements,
658 ACPI_RTYPE_INTEGER, 0);
659 if (ACPI_FAILURE (Status))
661 return (Status);
664 Elements++;
665 Count--;
667 /* Examine the sub-packages */
669 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
670 break;
673 case ACPI_PTYPE2_PKG_COUNT:
675 /* First element is the (Integer) count of sub-packages to follow */
677 Status = AcpiNsCheckObjectType (Data, Elements,
678 ACPI_RTYPE_INTEGER, 0);
679 if (ACPI_FAILURE (Status))
681 return (Status);
685 * Count cannot be larger than the parent package length, but allow it
686 * to be smaller. The >= accounts for the Integer above.
688 ExpectedCount = (UINT32) (*Elements)->Integer.Value;
689 if (ExpectedCount >= Count)
691 goto PackageTooSmall;
694 Count = ExpectedCount;
695 Elements++;
697 /* Examine the sub-packages */
699 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
700 break;
703 case ACPI_PTYPE2:
704 case ACPI_PTYPE2_FIXED:
705 case ACPI_PTYPE2_MIN:
706 case ACPI_PTYPE2_COUNT:
709 * These types all return a single Package that consists of a
710 * variable number of sub-Packages.
712 * First, ensure that the first element is a sub-Package. If not,
713 * the BIOS may have incorrectly returned the object as a single
714 * package instead of a Package of Packages (a common error if
715 * there is only one entry). We may be able to repair this by
716 * wrapping the returned Package with a new outer Package.
718 if ((*Elements)->Common.Type != ACPI_TYPE_PACKAGE)
720 /* Create the new outer package and populate it */
722 Status = AcpiNsRepairPackageList (Data, ReturnObjectPtr);
723 if (ACPI_FAILURE (Status))
725 return (Status);
728 /* Update locals to point to the new package (of 1 element) */
730 ReturnObject = *ReturnObjectPtr;
731 Elements = ReturnObject->Package.Elements;
732 Count = 1;
735 /* Examine the sub-packages */
737 Status = AcpiNsCheckPackageList (Data, Package, Elements, Count);
738 break;
741 default:
743 /* Should not get here if predefined info table is correct */
745 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
746 "Invalid internal return type in table entry: %X",
747 Package->RetInfo.Type));
749 return (AE_AML_INTERNAL);
752 return (Status);
755 PackageTooSmall:
757 /* Error exit for the case with an incorrect package count */
759 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
760 "Return Package is too small - found %u elements, expected %u",
761 Count, ExpectedCount));
763 return (AE_AML_OPERAND_VALUE);
767 /*******************************************************************************
769 * FUNCTION: AcpiNsCheckPackageList
771 * PARAMETERS: Data - Pointer to validation data structure
772 * Package - Pointer to package-specific info for method
773 * Elements - Element list of parent package. All elements
774 * of this list should be of type Package.
775 * Count - Count of subpackages
777 * RETURN: Status
779 * DESCRIPTION: Examine a list of subpackages
781 ******************************************************************************/
783 static ACPI_STATUS
784 AcpiNsCheckPackageList (
785 ACPI_PREDEFINED_DATA *Data,
786 const ACPI_PREDEFINED_INFO *Package,
787 ACPI_OPERAND_OBJECT **Elements,
788 UINT32 Count)
790 ACPI_OPERAND_OBJECT *SubPackage;
791 ACPI_OPERAND_OBJECT **SubElements;
792 ACPI_STATUS Status;
793 UINT32 ExpectedCount;
794 UINT32 i;
795 UINT32 j;
798 /* Validate each sub-Package in the parent Package */
800 for (i = 0; i < Count; i++)
802 SubPackage = *Elements;
803 SubElements = SubPackage->Package.Elements;
805 /* Each sub-object must be of type Package */
807 Status = AcpiNsCheckObjectType (Data, &SubPackage,
808 ACPI_RTYPE_PACKAGE, i);
809 if (ACPI_FAILURE (Status))
811 return (Status);
814 /* Examine the different types of expected sub-packages */
816 switch (Package->RetInfo.Type)
818 case ACPI_PTYPE2:
819 case ACPI_PTYPE2_PKG_COUNT:
820 case ACPI_PTYPE2_REV_FIXED:
822 /* Each subpackage has a fixed number of elements */
824 ExpectedCount = Package->RetInfo.Count1 + Package->RetInfo.Count2;
825 if (SubPackage->Package.Count < ExpectedCount)
827 goto PackageTooSmall;
830 Status = AcpiNsCheckPackageElements (Data, SubElements,
831 Package->RetInfo.ObjectType1,
832 Package->RetInfo.Count1,
833 Package->RetInfo.ObjectType2,
834 Package->RetInfo.Count2, 0);
835 if (ACPI_FAILURE (Status))
837 return (Status);
839 break;
842 case ACPI_PTYPE2_FIXED:
844 /* Each sub-package has a fixed length */
846 ExpectedCount = Package->RetInfo2.Count;
847 if (SubPackage->Package.Count < ExpectedCount)
849 goto PackageTooSmall;
852 /* Check the type of each sub-package element */
854 for (j = 0; j < ExpectedCount; j++)
856 Status = AcpiNsCheckObjectType (Data, &SubElements[j],
857 Package->RetInfo2.ObjectType[j], j);
858 if (ACPI_FAILURE (Status))
860 return (Status);
863 break;
866 case ACPI_PTYPE2_MIN:
868 /* Each sub-package has a variable but minimum length */
870 ExpectedCount = Package->RetInfo.Count1;
871 if (SubPackage->Package.Count < ExpectedCount)
873 goto PackageTooSmall;
876 /* Check the type of each sub-package element */
878 Status = AcpiNsCheckPackageElements (Data, SubElements,
879 Package->RetInfo.ObjectType1,
880 SubPackage->Package.Count, 0, 0, 0);
881 if (ACPI_FAILURE (Status))
883 return (Status);
885 break;
888 case ACPI_PTYPE2_COUNT:
891 * First element is the (Integer) count of elements, including
892 * the count field.
894 Status = AcpiNsCheckObjectType (Data, SubElements,
895 ACPI_RTYPE_INTEGER, 0);
896 if (ACPI_FAILURE (Status))
898 return (Status);
902 * Make sure package is large enough for the Count and is
903 * is as large as the minimum size
905 ExpectedCount = (UINT32) (*SubElements)->Integer.Value;
906 if (SubPackage->Package.Count < ExpectedCount)
908 goto PackageTooSmall;
910 if (SubPackage->Package.Count < Package->RetInfo.Count1)
912 ExpectedCount = Package->RetInfo.Count1;
913 goto PackageTooSmall;
916 /* Check the type of each sub-package element */
918 Status = AcpiNsCheckPackageElements (Data, (SubElements + 1),
919 Package->RetInfo.ObjectType1,
920 (ExpectedCount - 1), 0, 0, 1);
921 if (ACPI_FAILURE (Status))
923 return (Status);
925 break;
928 default: /* Should not get here, type was validated by caller */
930 return (AE_AML_INTERNAL);
933 Elements++;
936 return (AE_OK);
939 PackageTooSmall:
941 /* The sub-package count was smaller than required */
943 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
944 "Return Sub-Package[%u] is too small - found %u elements, expected %u",
945 i, SubPackage->Package.Count, ExpectedCount));
947 return (AE_AML_OPERAND_VALUE);
951 /*******************************************************************************
953 * FUNCTION: AcpiNsCheckPackageElements
955 * PARAMETERS: Data - Pointer to validation data structure
956 * Elements - Pointer to the package elements array
957 * Type1 - Object type for first group
958 * Count1 - Count for first group
959 * Type2 - Object type for second group
960 * Count2 - Count for second group
961 * StartIndex - Start of the first group of elements
963 * RETURN: Status
965 * DESCRIPTION: Check that all elements of a package are of the correct object
966 * type. Supports up to two groups of different object types.
968 ******************************************************************************/
970 static ACPI_STATUS
971 AcpiNsCheckPackageElements (
972 ACPI_PREDEFINED_DATA *Data,
973 ACPI_OPERAND_OBJECT **Elements,
974 UINT8 Type1,
975 UINT32 Count1,
976 UINT8 Type2,
977 UINT32 Count2,
978 UINT32 StartIndex)
980 ACPI_OPERAND_OBJECT **ThisElement = Elements;
981 ACPI_STATUS Status;
982 UINT32 i;
986 * Up to two groups of package elements are supported by the data
987 * structure. All elements in each group must be of the same type.
988 * The second group can have a count of zero.
990 for (i = 0; i < Count1; i++)
992 Status = AcpiNsCheckObjectType (Data, ThisElement,
993 Type1, i + StartIndex);
994 if (ACPI_FAILURE (Status))
996 return (Status);
998 ThisElement++;
1001 for (i = 0; i < Count2; i++)
1003 Status = AcpiNsCheckObjectType (Data, ThisElement,
1004 Type2, (i + Count1 + StartIndex));
1005 if (ACPI_FAILURE (Status))
1007 return (Status);
1009 ThisElement++;
1012 return (AE_OK);
1016 /*******************************************************************************
1018 * FUNCTION: AcpiNsCheckObjectType
1020 * PARAMETERS: Data - Pointer to validation data structure
1021 * ReturnObjectPtr - Pointer to the object returned from the
1022 * evaluation of a method or object
1023 * ExpectedBtypes - Bitmap of expected return type(s)
1024 * PackageIndex - Index of object within parent package (if
1025 * applicable - ACPI_NOT_PACKAGE_ELEMENT
1026 * otherwise)
1028 * RETURN: Status
1030 * DESCRIPTION: Check the type of the return object against the expected object
1031 * type(s). Use of Btype allows multiple expected object types.
1033 ******************************************************************************/
1035 static ACPI_STATUS
1036 AcpiNsCheckObjectType (
1037 ACPI_PREDEFINED_DATA *Data,
1038 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
1039 UINT32 ExpectedBtypes,
1040 UINT32 PackageIndex)
1042 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
1043 ACPI_STATUS Status = AE_OK;
1044 UINT32 ReturnBtype;
1045 char TypeBuffer[48]; /* Room for 5 types */
1049 * If we get a NULL ReturnObject here, it is a NULL package element,
1050 * and this is always an error.
1052 if (!ReturnObject)
1054 goto TypeErrorExit;
1057 /* A Namespace node should not get here, but make sure */
1059 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
1061 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1062 "Invalid return type - Found a Namespace node [%4.4s] type %s",
1063 ReturnObject->Node.Name.Ascii,
1064 AcpiUtGetTypeName (ReturnObject->Node.Type)));
1065 return (AE_AML_OPERAND_TYPE);
1069 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
1070 * The bitmapped type allows multiple possible return types.
1072 * Note, the cases below must handle all of the possible types returned
1073 * from all of the predefined names (including elements of returned
1074 * packages)
1076 switch (ReturnObject->Common.Type)
1078 case ACPI_TYPE_INTEGER:
1079 ReturnBtype = ACPI_RTYPE_INTEGER;
1080 break;
1082 case ACPI_TYPE_BUFFER:
1083 ReturnBtype = ACPI_RTYPE_BUFFER;
1084 break;
1086 case ACPI_TYPE_STRING:
1087 ReturnBtype = ACPI_RTYPE_STRING;
1088 break;
1090 case ACPI_TYPE_PACKAGE:
1091 ReturnBtype = ACPI_RTYPE_PACKAGE;
1092 break;
1094 case ACPI_TYPE_LOCAL_REFERENCE:
1095 ReturnBtype = ACPI_RTYPE_REFERENCE;
1096 break;
1098 default:
1099 /* Not one of the supported objects, must be incorrect */
1101 goto TypeErrorExit;
1104 /* Is the object one of the expected types? */
1106 if (!(ReturnBtype & ExpectedBtypes))
1108 /* Type mismatch -- attempt repair of the returned object */
1110 Status = AcpiNsRepairObject (Data, ExpectedBtypes,
1111 PackageIndex, ReturnObjectPtr);
1112 if (ACPI_SUCCESS (Status))
1114 return (AE_OK); /* Repair was successful */
1116 goto TypeErrorExit;
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);
1126 return (Status);
1129 TypeErrorExit:
1131 /* Create a string with all expected types for this predefined object */
1133 AcpiNsGetExpectedTypes (TypeBuffer, ExpectedBtypes);
1135 if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
1137 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1138 "Return type mismatch - found %s, expected %s",
1139 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1141 else
1143 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1144 "Return Package type mismatch at index %u - "
1145 "found %s, expected %s", PackageIndex,
1146 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
1149 return (AE_AML_OPERAND_TYPE);
1153 /*******************************************************************************
1155 * FUNCTION: AcpiNsCheckReference
1157 * PARAMETERS: Data - Pointer to validation data structure
1158 * ReturnObject - Object returned from the evaluation of a
1159 * method or object
1161 * RETURN: Status
1163 * DESCRIPTION: Check a returned reference object for the correct reference
1164 * type. The only reference type that can be returned from a
1165 * predefined method is a named reference. All others are invalid.
1167 ******************************************************************************/
1169 static ACPI_STATUS
1170 AcpiNsCheckReference (
1171 ACPI_PREDEFINED_DATA *Data,
1172 ACPI_OPERAND_OBJECT *ReturnObject)
1176 * Check the reference object for the correct reference type (opcode).
1177 * The only type of reference that can be converted to an ACPI_OBJECT is
1178 * a reference to a named object (reference class: NAME)
1180 if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
1182 return (AE_OK);
1185 ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
1186 "Return type mismatch - unexpected reference object type [%s] %2.2X",
1187 AcpiUtGetReferenceName (ReturnObject),
1188 ReturnObject->Reference.Class));
1190 return (AE_AML_OPERAND_TYPE);
1194 /*******************************************************************************
1196 * FUNCTION: AcpiNsGetExpectedTypes
1198 * PARAMETERS: Buffer - Pointer to where the string is returned
1199 * ExpectedBtypes - Bitmap of expected return type(s)
1201 * RETURN: Buffer is populated with type names.
1203 * DESCRIPTION: Translate the expected types bitmap into a string of ascii
1204 * names of expected types, for use in warning messages.
1206 ******************************************************************************/
1208 static void
1209 AcpiNsGetExpectedTypes (
1210 char *Buffer,
1211 UINT32 ExpectedBtypes)
1213 UINT32 ThisRtype;
1214 UINT32 i;
1215 UINT32 j;
1218 j = 1;
1219 Buffer[0] = 0;
1220 ThisRtype = ACPI_RTYPE_INTEGER;
1222 for (i = 0; i < ACPI_NUM_RTYPES; i++)
1224 /* If one of the expected types, concatenate the name of this type */
1226 if (ExpectedBtypes & ThisRtype)
1228 ACPI_STRCAT (Buffer, &AcpiRtypeNames[i][j]);
1229 j = 0; /* Use name separator from now on */
1231 ThisRtype <<= 1; /* Next Rtype */