No empty .Rs/.Re
[netbsd-mini2440.git] / sys / external / intel-public / acpica / dist / utilities / uteval.c
blob28912b0cbd1bc0bbe717bca4733a2f41853bf616
1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
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 __UTEVAL_C__
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acnamesp.h"
123 #define _COMPONENT ACPI_UTILITIES
124 ACPI_MODULE_NAME ("uteval")
128 * Strings supported by the _OSI predefined (internal) method.
130 * March 2009: Removed "Linux" as this host no longer wants to respond true
131 * for this string. Basically, the only safe OS strings are windows-related
132 * and in many or most cases represent the only test path within the
133 * BIOS-provided ASL code.
135 * The second element of each entry is used to track the newest version of
136 * Windows that the BIOS has requested.
138 static const ACPI_INTERFACE_INFO AcpiInterfacesSupported[] =
140 /* Operating System Vendor Strings */
142 {"Windows 2000", ACPI_OSI_WIN_2000}, /* Windows 2000 */
143 {"Windows 2001", ACPI_OSI_WIN_XP}, /* Windows XP */
144 {"Windows 2001 SP1", ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */
145 {"Windows 2001.1", ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */
146 {"Windows 2001 SP2", ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */
147 {"Windows 2001.1 SP1", ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */
148 {"Windows 2006", ACPI_OSI_WIN_VISTA}, /* Windows Vista - Added 03/2006 */
150 /* Feature Group Strings */
152 {"Extended Address Space Descriptor", 0}
155 * All "optional" feature group strings (features that are implemented
156 * by the host) should be implemented in the host version of
157 * AcpiOsValidateInterface and should not be added here.
162 /*******************************************************************************
164 * FUNCTION: AcpiUtOsiImplementation
166 * PARAMETERS: WalkState - Current walk state
168 * RETURN: Status
170 * DESCRIPTION: Implementation of the _OSI predefined control method
172 ******************************************************************************/
174 ACPI_STATUS
175 AcpiUtOsiImplementation (
176 ACPI_WALK_STATE *WalkState)
178 ACPI_STATUS Status;
179 ACPI_OPERAND_OBJECT *StringDesc;
180 ACPI_OPERAND_OBJECT *ReturnDesc;
181 UINT32 ReturnValue;
182 UINT32 i;
185 ACPI_FUNCTION_TRACE (UtOsiImplementation);
188 /* Validate the string input argument */
190 StringDesc = WalkState->Arguments[0].Object;
191 if (!StringDesc || (StringDesc->Common.Type != ACPI_TYPE_STRING))
193 return_ACPI_STATUS (AE_TYPE);
196 /* Create a return object */
198 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
199 if (!ReturnDesc)
201 return_ACPI_STATUS (AE_NO_MEMORY);
204 /* Default return value is 0, NOT SUPPORTED */
206 ReturnValue = 0;
208 /* Compare input string to static table of supported interfaces */
210 for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiInterfacesSupported); i++)
212 if (!ACPI_STRCMP (StringDesc->String.Pointer,
213 AcpiInterfacesSupported[i].Name))
216 * The interface is supported.
217 * Update the OsiData if necessary. We keep track of the latest
218 * version of Windows that has been requested by the BIOS.
220 if (AcpiInterfacesSupported[i].Value > AcpiGbl_OsiData)
222 AcpiGbl_OsiData = AcpiInterfacesSupported[i].Value;
225 ReturnValue = ACPI_UINT32_MAX;
226 goto Exit;
231 * Did not match the string in the static table, call the host OSL to
232 * check for a match with one of the optional strings (such as
233 * "Module Device", "3.0 Thermal Model", etc.)
235 Status = AcpiOsValidateInterface (StringDesc->String.Pointer);
236 if (ACPI_SUCCESS (Status))
238 /* The interface is supported */
240 ReturnValue = ACPI_UINT32_MAX;
244 Exit:
245 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
246 "ACPI: BIOS _OSI(%s) is %ssupported\n",
247 StringDesc->String.Pointer, ReturnValue == 0 ? "not " : ""));
249 /* Complete the return value */
251 ReturnDesc->Integer.Value = ReturnValue;
252 WalkState->ReturnDesc = ReturnDesc;
253 return_ACPI_STATUS (AE_OK);
257 /*******************************************************************************
259 * FUNCTION: AcpiUtEvaluateObject
261 * PARAMETERS: PrefixNode - Starting node
262 * Path - Path to object from starting node
263 * ExpectedReturnTypes - Bitmap of allowed return types
264 * ReturnDesc - Where a return value is stored
266 * RETURN: Status
268 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
269 * return object. Common code that simplifies accessing objects
270 * that have required return objects of fixed types.
272 * NOTE: Internal function, no parameter validation
274 ******************************************************************************/
276 ACPI_STATUS
277 AcpiUtEvaluateObject (
278 ACPI_NAMESPACE_NODE *PrefixNode,
279 const char *Path,
280 UINT32 ExpectedReturnBtypes,
281 ACPI_OPERAND_OBJECT **ReturnDesc)
283 ACPI_EVALUATE_INFO *Info;
284 ACPI_STATUS Status;
285 UINT32 ReturnBtype;
286 char *UPath = __UNCONST(Path);
289 ACPI_FUNCTION_TRACE (UtEvaluateObject);
292 /* Allocate the evaluation information block */
294 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
295 if (!Info)
297 return_ACPI_STATUS (AE_NO_MEMORY);
300 Info->PrefixNode = PrefixNode;
301 Info->Pathname = UPath;
303 /* Evaluate the object/method */
305 Status = AcpiNsEvaluate (Info);
306 if (ACPI_FAILURE (Status))
308 if (Status == AE_NOT_FOUND)
310 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
311 AcpiUtGetNodeName (PrefixNode), UPath));
313 else
315 ACPI_ERROR_METHOD ("Method execution failed",
316 PrefixNode, Path, Status);
319 goto Cleanup;
322 /* Did we get a return object? */
324 if (!Info->ReturnObject)
326 if (ExpectedReturnBtypes)
328 ACPI_ERROR_METHOD ("No object was returned from",
329 PrefixNode, Path, AE_NOT_EXIST);
331 Status = AE_NOT_EXIST;
334 goto Cleanup;
337 /* Map the return object type to the bitmapped type */
339 switch ((Info->ReturnObject)->Common.Type)
341 case ACPI_TYPE_INTEGER:
342 ReturnBtype = ACPI_BTYPE_INTEGER;
343 break;
345 case ACPI_TYPE_BUFFER:
346 ReturnBtype = ACPI_BTYPE_BUFFER;
347 break;
349 case ACPI_TYPE_STRING:
350 ReturnBtype = ACPI_BTYPE_STRING;
351 break;
353 case ACPI_TYPE_PACKAGE:
354 ReturnBtype = ACPI_BTYPE_PACKAGE;
355 break;
357 default:
358 ReturnBtype = 0;
359 break;
362 if ((AcpiGbl_EnableInterpreterSlack) &&
363 (!ExpectedReturnBtypes))
366 * We received a return object, but one was not expected. This can
367 * happen frequently if the "implicit return" feature is enabled.
368 * Just delete the return object and return AE_OK.
370 AcpiUtRemoveReference (Info->ReturnObject);
371 goto Cleanup;
374 /* Is the return object one of the expected types? */
376 if (!(ExpectedReturnBtypes & ReturnBtype))
378 ACPI_ERROR_METHOD ("Return object type is incorrect",
379 PrefixNode, Path, AE_TYPE);
381 ACPI_ERROR ((AE_INFO,
382 "Type returned from %s was incorrect: %s, expected Btypes: %X",
383 Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
384 ExpectedReturnBtypes));
386 /* On error exit, we must delete the return object */
388 AcpiUtRemoveReference (Info->ReturnObject);
389 Status = AE_TYPE;
390 goto Cleanup;
393 /* Object type is OK, return it */
395 *ReturnDesc = Info->ReturnObject;
397 Cleanup:
398 ACPI_FREE (Info);
399 return_ACPI_STATUS (Status);
403 /*******************************************************************************
405 * FUNCTION: AcpiUtEvaluateNumericObject
407 * PARAMETERS: ObjectName - Object name to be evaluated
408 * DeviceNode - Node for the device
409 * Value - Where the value is returned
411 * RETURN: Status
413 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
414 * and stores result in *Value.
416 * NOTE: Internal function, no parameter validation
418 ******************************************************************************/
420 ACPI_STATUS
421 AcpiUtEvaluateNumericObject (
422 const char *ObjectName,
423 ACPI_NAMESPACE_NODE *DeviceNode,
424 ACPI_INTEGER *Value)
426 ACPI_OPERAND_OBJECT *ObjDesc;
427 ACPI_STATUS Status;
430 ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
433 Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
434 ACPI_BTYPE_INTEGER, &ObjDesc);
435 if (ACPI_FAILURE (Status))
437 return_ACPI_STATUS (Status);
440 /* Get the returned Integer */
442 *Value = ObjDesc->Integer.Value;
444 /* On exit, we must delete the return object */
446 AcpiUtRemoveReference (ObjDesc);
447 return_ACPI_STATUS (Status);
451 /*******************************************************************************
453 * FUNCTION: AcpiUtExecute_STA
455 * PARAMETERS: DeviceNode - Node for the device
456 * Flags - Where the status flags are returned
458 * RETURN: Status
460 * DESCRIPTION: Executes _STA for selected device and stores results in
461 * *Flags.
463 * NOTE: Internal function, no parameter validation
465 ******************************************************************************/
467 ACPI_STATUS
468 AcpiUtExecute_STA (
469 ACPI_NAMESPACE_NODE *DeviceNode,
470 UINT32 *Flags)
472 ACPI_OPERAND_OBJECT *ObjDesc;
473 ACPI_STATUS Status;
476 ACPI_FUNCTION_TRACE (UtExecute_STA);
479 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
480 ACPI_BTYPE_INTEGER, &ObjDesc);
481 if (ACPI_FAILURE (Status))
483 if (AE_NOT_FOUND == Status)
485 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
486 "_STA on %4.4s was not found, assuming device is present\n",
487 AcpiUtGetNodeName (DeviceNode)));
489 *Flags = ACPI_UINT32_MAX;
490 Status = AE_OK;
493 return_ACPI_STATUS (Status);
496 /* Extract the status flags */
498 *Flags = (UINT32) ObjDesc->Integer.Value;
500 /* On exit, we must delete the return object */
502 AcpiUtRemoveReference (ObjDesc);
503 return_ACPI_STATUS (Status);
507 /*******************************************************************************
509 * FUNCTION: AcpiUtExecutePowerMethods
511 * PARAMETERS: DeviceNode - Node for the device
512 * MethodNames - Array of power method names
513 * MethodCount - Number of methods to execute
514 * OutValues - Where the power method values are returned
516 * RETURN: Status, OutValues
518 * DESCRIPTION: Executes the specified power methods for the device and returns
519 * the result(s).
521 * NOTE: Internal function, no parameter validation
523 ******************************************************************************/
525 ACPI_STATUS
526 AcpiUtExecutePowerMethods (
527 ACPI_NAMESPACE_NODE *DeviceNode,
528 const char **MethodNames,
529 UINT8 MethodCount,
530 UINT8 *OutValues)
532 ACPI_OPERAND_OBJECT *ObjDesc;
533 ACPI_STATUS Status;
534 ACPI_STATUS FinalStatus = AE_NOT_FOUND;
535 UINT32 i;
538 ACPI_FUNCTION_TRACE (UtExecutePowerMethods);
541 for (i = 0; i < MethodCount; i++)
544 * Execute the power method (_SxD or _SxW). The only allowable
545 * return type is an Integer.
547 Status = AcpiUtEvaluateObject (DeviceNode,
548 ACPI_CAST_PTR (char, MethodNames[i]),
549 ACPI_BTYPE_INTEGER, &ObjDesc);
550 if (ACPI_SUCCESS (Status))
552 OutValues[i] = (UINT8) ObjDesc->Integer.Value;
554 /* Delete the return object */
556 AcpiUtRemoveReference (ObjDesc);
557 FinalStatus = AE_OK; /* At least one value is valid */
558 continue;
561 OutValues[i] = ACPI_UINT8_MAX;
562 if (Status == AE_NOT_FOUND)
564 continue; /* Ignore if not found */
567 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Failed %s on Device %4.4s, %s\n",
568 ACPI_CAST_PTR (char, MethodNames[i]),
569 AcpiUtGetNodeName (DeviceNode), AcpiFormatException (Status)));
572 return_ACPI_STATUS (FinalStatus);