[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / namespace / nspredef.c
1 /******************************************************************************
2 *
3 * Module Name: nspredef - Validation of ACPI predefined methods and objects
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
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.
20 *
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
27 *
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;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
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.
53 *
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.
65 *
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.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
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.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
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.
89 *
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.
98 *
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.
113 *
114 *****************************************************************************/
115
116 #define ACPI_CREATE_PREDEFINED_TABLE
117
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acnamesp.h"
121 #include "acpredef.h"
122
123
124 #define _COMPONENT ACPI_NAMESPACE
125 ACPI_MODULE_NAME ("nspredef")
126
127
128 /*******************************************************************************
129 *
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.
134 *
135 * There are several areas that are validated:
136 *
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.
144 *
145 * For any problems found, a warning message is issued.
146 *
147 ******************************************************************************/
148
149
150 /* Local prototypes */
151
152 static ACPI_STATUS
153 AcpiNsCheckReference (
154 ACPI_EVALUATE_INFO *Info,
155 ACPI_OPERAND_OBJECT *ReturnObject);
156
157 static UINT32
158 AcpiNsGetBitmappedType (
159 ACPI_OPERAND_OBJECT *ReturnObject);
160
161
162 /*******************************************************************************
163 *
164 * FUNCTION: AcpiNsCheckReturnValue
165 *
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
172 *
173 * RETURN: Status
174 *
175 * DESCRIPTION: Check the value returned from a predefined name.
176 *
177 ******************************************************************************/
178
179 ACPI_STATUS
180 AcpiNsCheckReturnValue (
181 ACPI_NAMESPACE_NODE *Node,
182 ACPI_EVALUATE_INFO *Info,
183 UINT32 UserParamCount,
184 ACPI_STATUS ReturnStatus,
185 ACPI_OPERAND_OBJECT **ReturnObjectPtr)
186 {
187 ACPI_STATUS Status;
188 const ACPI_PREDEFINED_INFO *Predefined;
189
190
191 /* If not a predefined name, we cannot validate the return object */
192
193 Predefined = Info->Predefined;
194 if (!Predefined)
195 {
196 return (AE_OK);
197 }
198
199 /*
200 * If the method failed or did not actually return an object, we cannot
201 * validate the return object
202 */
203 if ((ReturnStatus != AE_OK) &&
204 (ReturnStatus != AE_CTRL_RETURN_VALUE))
205 {
206 return (AE_OK);
207 }
208
209 /*
210 * Return value validation and possible repair.
211 *
212 * 1) Don't perform return value validation/repair if this feature
213 * has been disabled via a global option.
214 *
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.
218 *
219 * 3) If the return value can be of any type, then we cannot perform
220 * any validation, just exit.
221 */
222 if (AcpiGbl_DisableAutoRepair ||
223 (!Predefined->Info.ExpectedBtypes) ||
224 (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL))
225 {
226 return (AE_OK);
227 }
228
229 /*
230 * Check that the type of the main return object is what is expected
231 * for this predefined name
232 */
233 Status = AcpiNsCheckObjectType (Info, ReturnObjectPtr,
234 Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
235 if (ACPI_FAILURE (Status))
236 {
237 goto Exit;
238 }
239
240 /*
241 *
242 * 4) If there is no return value and it is optional, just return
243 * AE_OK (_WAK).
244 */
245 if (!(*ReturnObjectPtr))
246 {
247 goto Exit;
248 }
249
250 /*
251 * For returned Package objects, check the type of all sub-objects.
252 * Note: Package may have been newly created by call above.
253 */
254 if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE)
255 {
256 Info->ParentPackage = *ReturnObjectPtr;
257 Status = AcpiNsCheckPackage (Info, ReturnObjectPtr);
258 if (ACPI_FAILURE (Status))
259 {
260 /* We might be able to fix some errors */
261
262 if ((Status != AE_AML_OPERAND_TYPE) &&
263 (Status != AE_AML_OPERAND_VALUE))
264 {
265 goto Exit;
266 }
267 }
268 }
269
270 /*
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.
277 */
278 Status = AcpiNsComplexRepairs (Info, Node, Status, ReturnObjectPtr);
279
280 Exit:
281 /*
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.
285 */
286 if (ACPI_FAILURE (Status) ||
287 (Info->ReturnFlags & ACPI_OBJECT_REPAIRED))
288 {
289 Node->Flags |= ANOBJ_EVALUATED;
290 }
291
292 return (Status);
293 }
294
295
296 /*******************************************************************************
297 *
298 * FUNCTION: AcpiNsCheckObjectType
299 *
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
306 * otherwise)
307 *
308 * RETURN: Status
309 *
310 * DESCRIPTION: Check the type of the return object against the expected object
311 * type(s). Use of Btype allows multiple expected object types.
312 *
313 ******************************************************************************/
314
315 ACPI_STATUS
316 AcpiNsCheckObjectType (
317 ACPI_EVALUATE_INFO *Info,
318 ACPI_OPERAND_OBJECT **ReturnObjectPtr,
319 UINT32 ExpectedBtypes,
320 UINT32 PackageIndex)
321 {
322 ACPI_OPERAND_OBJECT *ReturnObject = *ReturnObjectPtr;
323 ACPI_STATUS Status = AE_OK;
324 char TypeBuffer[48]; /* Room for 5 types */
325
326
327 /* A Namespace node should not get here, but make sure */
328
329 if (ReturnObject &&
330 ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
331 {
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);
337 }
338
339 /*
340 * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
341 * The bitmapped type allows multiple possible return types.
342 *
343 * Note, the cases below must handle all of the possible types returned
344 * from all of the predefined names (including elements of returned
345 * packages)
346 */
347 Info->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject);
348 if (Info->ReturnBtype == ACPI_RTYPE_ANY)
349 {
350 /* Not one of the supported objects, must be incorrect */
351 goto TypeErrorExit;
352 }
353
354 /* For reference objects, check that the reference type is correct */
355
356 if ((Info->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE)
357 {
358 Status = AcpiNsCheckReference (Info, ReturnObject);
359 return (Status);
360 }
361
362 /* Attempt simple repair of the returned object if necessary */
363
364 Status = AcpiNsSimpleRepair (Info, ExpectedBtypes,
365 PackageIndex, ReturnObjectPtr);
366 if (ACPI_SUCCESS (Status))
367 {
368 return (AE_OK); /* Successful repair */
369 }
370
371
372 TypeErrorExit:
373
374 /* Create a string with all expected types for this predefined object */
375
376 AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes);
377
378 if (!ReturnObject)
379 {
380 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
381 "Expected return object of type %s",
382 TypeBuffer));
383 }
384 else if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
385 {
386 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
387 "Return type mismatch - found %s, expected %s",
388 AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
389 }
390 else
391 {
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));
396 }
397
398 return (AE_AML_OPERAND_TYPE);
399 }
400
401
402 /*******************************************************************************
403 *
404 * FUNCTION: AcpiNsCheckReference
405 *
406 * PARAMETERS: Info - Method execution information block
407 * ReturnObject - Object returned from the evaluation of a
408 * method or object
409 *
410 * RETURN: Status
411 *
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.
415 *
416 ******************************************************************************/
417
418 static ACPI_STATUS
419 AcpiNsCheckReference (
420 ACPI_EVALUATE_INFO *Info,
421 ACPI_OPERAND_OBJECT *ReturnObject)
422 {
423
424 /*
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)
428 */
429 if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
430 {
431 return (AE_OK);
432 }
433
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));
438
439 return (AE_AML_OPERAND_TYPE);
440 }
441
442
443 /*******************************************************************************
444 *
445 * FUNCTION: AcpiNsGetBitmappedType
446 *
447 * PARAMETERS: ReturnObject - Object returned from method/obj evaluation
448 *
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).
452 *
453 * DESCRIPTION: Convert object type into a bitmapped object return type.
454 *
455 ******************************************************************************/
456
457 static UINT32
458 AcpiNsGetBitmappedType (
459 ACPI_OPERAND_OBJECT *ReturnObject)
460 {
461 UINT32 ReturnBtype;
462
463
464 if (!ReturnObject)
465 {
466 return (ACPI_RTYPE_NONE);
467 }
468
469 /* Map ACPI_OBJECT_TYPE to internal bitmapped type */
470
471 switch (ReturnObject->Common.Type)
472 {
473 case ACPI_TYPE_INTEGER:
474
475 ReturnBtype = ACPI_RTYPE_INTEGER;
476 break;
477
478 case ACPI_TYPE_BUFFER:
479
480 ReturnBtype = ACPI_RTYPE_BUFFER;
481 break;
482
483 case ACPI_TYPE_STRING:
484
485 ReturnBtype = ACPI_RTYPE_STRING;
486 break;
487
488 case ACPI_TYPE_PACKAGE:
489
490 ReturnBtype = ACPI_RTYPE_PACKAGE;
491 break;
492
493 case ACPI_TYPE_LOCAL_REFERENCE:
494
495 ReturnBtype = ACPI_RTYPE_REFERENCE;
496 break;
497
498 default:
499
500 /* Not one of the supported objects, must be incorrect */
501
502 ReturnBtype = ACPI_RTYPE_ANY;
503 break;
504 }
505
506 return (ReturnBtype);
507 }