1 /******************************************************************************
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, 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 ACPI_CREATE_PREDEFINED_TABLE
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
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 */
153 AcpiNsCheckReference (
154 ACPI_EVALUATE_INFO
*Info
,
155 ACPI_OPERAND_OBJECT
*ReturnObject
);
158 AcpiNsGetBitmappedType (
159 ACPI_OPERAND_OBJECT
*ReturnObject
);
162 /*******************************************************************************
164 * FUNCTION: AcpiNsCheckReturnValue
166 * PARAMETERS: Node - Namespace node for the method/object
167 * Info - Method execution information block
168 * UserParamCount - Number of parameters actually passed
169 * ReturnStatus - Status from the object evaluation
170 * ReturnObjectPtr - Pointer to the object returned from the
171 * evaluation of a method or object
175 * DESCRIPTION: Check the value returned from a predefined name.
177 ******************************************************************************/
180 AcpiNsCheckReturnValue (
181 ACPI_NAMESPACE_NODE
*Node
,
182 ACPI_EVALUATE_INFO
*Info
,
183 UINT32 UserParamCount
,
184 ACPI_STATUS ReturnStatus
,
185 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
)
188 const ACPI_PREDEFINED_INFO
*Predefined
;
191 /* If not a predefined name, we cannot validate the return object */
193 Predefined
= Info
->Predefined
;
200 * If the method failed or did not actually return an object, we cannot
201 * validate the return object
203 if ((ReturnStatus
!= AE_OK
) &&
204 (ReturnStatus
!= AE_CTRL_RETURN_VALUE
))
210 * Return value validation and possible repair.
212 * 1) Don't perform return value validation/repair if this feature
213 * has been disabled via a global option.
215 * 2) We have a return value, but if one wasn't expected, just exit,
216 * this is not a problem. For example, if the "Implicit Return"
217 * feature is enabled, methods will always return a value.
219 * 3) If the return value can be of any type, then we cannot perform
220 * any validation, just exit.
222 if (AcpiGbl_DisableAutoRepair
||
223 (!Predefined
->Info
.ExpectedBtypes
) ||
224 (Predefined
->Info
.ExpectedBtypes
== ACPI_RTYPE_ALL
))
230 * Check that the type of the main return object is what is expected
231 * for this predefined name
233 Status
= AcpiNsCheckObjectType (Info
, ReturnObjectPtr
,
234 Predefined
->Info
.ExpectedBtypes
, ACPI_NOT_PACKAGE_ELEMENT
);
235 if (ACPI_FAILURE (Status
))
242 * 4) If there is no return value and it is optional, just return
245 if (!(*ReturnObjectPtr
))
251 * For returned Package objects, check the type of all sub-objects.
252 * Note: Package may have been newly created by call above.
254 if ((*ReturnObjectPtr
)->Common
.Type
== ACPI_TYPE_PACKAGE
)
256 Info
->ParentPackage
= *ReturnObjectPtr
;
257 Status
= AcpiNsCheckPackage (Info
, ReturnObjectPtr
);
258 if (ACPI_FAILURE (Status
))
260 /* We might be able to fix some errors */
262 if ((Status
!= AE_AML_OPERAND_TYPE
) &&
263 (Status
!= AE_AML_OPERAND_VALUE
))
271 * The return object was OK, or it was successfully repaired above.
272 * Now make some additional checks such as verifying that package
273 * objects are sorted correctly (if required) or buffer objects have
274 * the correct data width (bytes vs. dwords). These repairs are
275 * performed on a per-name basis, i.e., the code is specific to
276 * particular predefined names.
278 Status
= AcpiNsComplexRepairs (Info
, Node
, Status
, ReturnObjectPtr
);
282 * If the object validation failed or if we successfully repaired one
283 * or more objects, mark the parent node to suppress further warning
284 * messages during the next evaluation of the same method/object.
286 if (ACPI_FAILURE (Status
) ||
287 (Info
->ReturnFlags
& ACPI_OBJECT_REPAIRED
))
289 Node
->Flags
|= ANOBJ_EVALUATED
;
296 /*******************************************************************************
298 * FUNCTION: AcpiNsCheckObjectType
300 * PARAMETERS: Info - Method execution information block
301 * ReturnObjectPtr - Pointer to the object returned from the
302 * evaluation of a method or object
303 * ExpectedBtypes - Bitmap of expected return type(s)
304 * PackageIndex - Index of object within parent package (if
305 * applicable - ACPI_NOT_PACKAGE_ELEMENT
310 * DESCRIPTION: Check the type of the return object against the expected object
311 * type(s). Use of Btype allows multiple expected object types.
313 ******************************************************************************/
316 AcpiNsCheckObjectType (
317 ACPI_EVALUATE_INFO
*Info
,
318 ACPI_OPERAND_OBJECT
**ReturnObjectPtr
,
319 UINT32 ExpectedBtypes
,
322 ACPI_OPERAND_OBJECT
*ReturnObject
= *ReturnObjectPtr
;
323 ACPI_STATUS Status
= AE_OK
;
324 char TypeBuffer
[48]; /* Room for 5 types */
327 /* A Namespace node should not get here, but make sure */
330 ACPI_GET_DESCRIPTOR_TYPE (ReturnObject
) == ACPI_DESC_TYPE_NAMED
)
332 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
333 "Invalid return type - Found a Namespace node [%4.4s] type %s",
334 ReturnObject
->Node
.Name
.Ascii
,
335 AcpiUtGetTypeName (ReturnObject
->Node
.Type
)));
336 return (AE_AML_OPERAND_TYPE
);
340 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
341 * The bitmapped type allows multiple possible return types.
343 * Note, the cases below must handle all of the possible types returned
344 * from all of the predefined names (including elements of returned
347 Info
->ReturnBtype
= AcpiNsGetBitmappedType (ReturnObject
);
348 if (Info
->ReturnBtype
== ACPI_RTYPE_ANY
)
350 /* Not one of the supported objects, must be incorrect */
354 /* For reference objects, check that the reference type is correct */
356 if ((Info
->ReturnBtype
& ExpectedBtypes
) == ACPI_RTYPE_REFERENCE
)
358 Status
= AcpiNsCheckReference (Info
, ReturnObject
);
362 /* Attempt simple repair of the returned object if necessary */
364 Status
= AcpiNsSimpleRepair (Info
, ExpectedBtypes
,
365 PackageIndex
, ReturnObjectPtr
);
366 if (ACPI_SUCCESS (Status
))
368 return (AE_OK
); /* Successful repair */
374 /* Create a string with all expected types for this predefined object */
376 AcpiUtGetExpectedReturnTypes (TypeBuffer
, ExpectedBtypes
);
380 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
381 "Expected return object of type %s",
384 else if (PackageIndex
== ACPI_NOT_PACKAGE_ELEMENT
)
386 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
387 "Return type mismatch - found %s, expected %s",
388 AcpiUtGetObjectTypeName (ReturnObject
), TypeBuffer
));
392 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
393 "Return Package type mismatch at index %u - "
394 "found %s, expected %s", PackageIndex
,
395 AcpiUtGetObjectTypeName (ReturnObject
), TypeBuffer
));
398 return (AE_AML_OPERAND_TYPE
);
402 /*******************************************************************************
404 * FUNCTION: AcpiNsCheckReference
406 * PARAMETERS: Info - Method execution information block
407 * ReturnObject - Object returned from the evaluation of a
412 * DESCRIPTION: Check a returned reference object for the correct reference
413 * type. The only reference type that can be returned from a
414 * predefined method is a named reference. All others are invalid.
416 ******************************************************************************/
419 AcpiNsCheckReference (
420 ACPI_EVALUATE_INFO
*Info
,
421 ACPI_OPERAND_OBJECT
*ReturnObject
)
425 * Check the reference object for the correct reference type (opcode).
426 * The only type of reference that can be converted to an ACPI_OBJECT is
427 * a reference to a named object (reference class: NAME)
429 if (ReturnObject
->Reference
.Class
== ACPI_REFCLASS_NAME
)
434 ACPI_WARN_PREDEFINED ((AE_INFO
, Info
->FullPathname
, Info
->NodeFlags
,
435 "Return type mismatch - unexpected reference object type [%s] %2.2X",
436 AcpiUtGetReferenceName (ReturnObject
),
437 ReturnObject
->Reference
.Class
));
439 return (AE_AML_OPERAND_TYPE
);
443 /*******************************************************************************
445 * FUNCTION: AcpiNsGetBitmappedType
447 * PARAMETERS: ReturnObject - Object returned from method/obj evaluation
449 * RETURN: Object return type. ACPI_RTYPE_ANY indicates that the object
450 * type is not supported. ACPI_RTYPE_NONE indicates that no
451 * object was returned (ReturnObject is NULL).
453 * DESCRIPTION: Convert object type into a bitmapped object return type.
455 ******************************************************************************/
458 AcpiNsGetBitmappedType (
459 ACPI_OPERAND_OBJECT
*ReturnObject
)
466 return (ACPI_RTYPE_NONE
);
469 /* Map ACPI_OBJECT_TYPE to internal bitmapped type */
471 switch (ReturnObject
->Common
.Type
)
473 case ACPI_TYPE_INTEGER
:
475 ReturnBtype
= ACPI_RTYPE_INTEGER
;
478 case ACPI_TYPE_BUFFER
:
480 ReturnBtype
= ACPI_RTYPE_BUFFER
;
483 case ACPI_TYPE_STRING
:
485 ReturnBtype
= ACPI_RTYPE_STRING
;
488 case ACPI_TYPE_PACKAGE
:
490 ReturnBtype
= ACPI_RTYPE_PACKAGE
;
493 case ACPI_TYPE_LOCAL_REFERENCE
:
495 ReturnBtype
= ACPI_RTYPE_REFERENCE
;
500 /* Not one of the supported objects, must be incorrect */
502 ReturnBtype
= ACPI_RTYPE_ANY
;
506 return (ReturnBtype
);