1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("uteval")
55 /*******************************************************************************
57 * FUNCTION: AcpiUtEvaluateObject
59 * PARAMETERS: PrefixNode - Starting node
60 * Path - Path to object from starting node
61 * ExpectedReturnTypes - Bitmap of allowed return types
62 * ReturnDesc - Where a return value is stored
66 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
67 * return object. Common code that simplifies accessing objects
68 * that have required return objects of fixed types.
70 * NOTE: Internal function, no parameter validation
72 ******************************************************************************/
75 AcpiUtEvaluateObject (
76 ACPI_NAMESPACE_NODE *PrefixNode,
78 UINT32 ExpectedReturnBtypes,
79 ACPI_OPERAND_OBJECT **ReturnDesc)
81 ACPI_EVALUATE_INFO *Info;
86 ACPI_FUNCTION_TRACE (UtEvaluateObject);
89 /* Allocate the evaluation information block */
91 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
94 return_ACPI_STATUS (AE_NO_MEMORY);
97 Info->PrefixNode = PrefixNode;
98 Info->Pathname = Path;
100 /* Evaluate the object/method */
102 Status = AcpiNsEvaluate (Info);
103 if (ACPI_FAILURE (Status))
105 if (Status == AE_NOT_FOUND)
107 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
108 AcpiUtGetNodeName (PrefixNode), Path));
112 ACPI_ERROR_METHOD ("Method execution failed",
113 PrefixNode, Path, Status);
119 /* Did we get a return object? */
121 if (!Info->ReturnObject)
123 if (ExpectedReturnBtypes)
125 ACPI_ERROR_METHOD ("No object was returned from",
126 PrefixNode, Path, AE_NOT_EXIST);
128 Status = AE_NOT_EXIST;
134 /* Map the return object type to the bitmapped type */
136 switch ((Info->ReturnObject)->Common.Type)
138 case ACPI_TYPE_INTEGER:
139 ReturnBtype = ACPI_BTYPE_INTEGER;
142 case ACPI_TYPE_BUFFER:
143 ReturnBtype = ACPI_BTYPE_BUFFER;
146 case ACPI_TYPE_STRING:
147 ReturnBtype = ACPI_BTYPE_STRING;
150 case ACPI_TYPE_PACKAGE:
151 ReturnBtype = ACPI_BTYPE_PACKAGE;
159 if ((AcpiGbl_EnableInterpreterSlack) &&
160 (!ExpectedReturnBtypes))
163 * We received a return object, but one was not expected. This can
164 * happen frequently if the "implicit return" feature is enabled.
165 * Just delete the return object and return AE_OK.
167 AcpiUtRemoveReference (Info->ReturnObject);
171 /* Is the return object one of the expected types? */
173 if (!(ExpectedReturnBtypes & ReturnBtype))
175 ACPI_ERROR_METHOD ("Return object type is incorrect",
176 PrefixNode, Path, AE_TYPE);
178 ACPI_ERROR ((AE_INFO,
179 "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
180 Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
181 ExpectedReturnBtypes));
183 /* On error exit, we must delete the return object */
185 AcpiUtRemoveReference (Info->ReturnObject);
190 /* Object type is OK, return it */
192 *ReturnDesc = Info->ReturnObject;
196 return_ACPI_STATUS (Status);
200 /*******************************************************************************
202 * FUNCTION: AcpiUtEvaluateNumericObject
204 * PARAMETERS: ObjectName - Object name to be evaluated
205 * DeviceNode - Node for the device
206 * Value - Where the value is returned
210 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
211 * and stores result in *Value.
213 * NOTE: Internal function, no parameter validation
215 ******************************************************************************/
218 AcpiUtEvaluateNumericObject (
220 ACPI_NAMESPACE_NODE *DeviceNode,
223 ACPI_OPERAND_OBJECT *ObjDesc;
227 ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
230 Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
231 ACPI_BTYPE_INTEGER, &ObjDesc);
232 if (ACPI_FAILURE (Status))
234 return_ACPI_STATUS (Status);
237 /* Get the returned Integer */
239 *Value = ObjDesc->Integer.Value;
241 /* On exit, we must delete the return object */
243 AcpiUtRemoveReference (ObjDesc);
244 return_ACPI_STATUS (Status);
248 /*******************************************************************************
250 * FUNCTION: AcpiUtExecute_STA
252 * PARAMETERS: DeviceNode - Node for the device
253 * Flags - Where the status flags are returned
257 * DESCRIPTION: Executes _STA for selected device and stores results in
260 * NOTE: Internal function, no parameter validation
262 ******************************************************************************/
266 ACPI_NAMESPACE_NODE *DeviceNode,
269 ACPI_OPERAND_OBJECT *ObjDesc;
273 ACPI_FUNCTION_TRACE (UtExecute_STA);
276 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
277 ACPI_BTYPE_INTEGER, &ObjDesc);
278 if (ACPI_FAILURE (Status))
280 if (AE_NOT_FOUND == Status)
282 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
283 "_STA on %4.4s was not found, assuming device is present\n",
284 AcpiUtGetNodeName (DeviceNode)));
286 *Flags = ACPI_UINT32_MAX;
290 return_ACPI_STATUS (Status);
293 /* Extract the status flags */
295 *Flags = (UINT32) ObjDesc->Integer.Value;
297 /* On exit, we must delete the return object */
299 AcpiUtRemoveReference (ObjDesc);
300 return_ACPI_STATUS (Status);
304 /*******************************************************************************
306 * FUNCTION: AcpiUtExecutePowerMethods
308 * PARAMETERS: DeviceNode - Node for the device
309 * MethodNames - Array of power method names
310 * MethodCount - Number of methods to execute
311 * OutValues - Where the power method values are returned
313 * RETURN: Status, OutValues
315 * DESCRIPTION: Executes the specified power methods for the device and returns
318 * NOTE: Internal function, no parameter validation
320 ******************************************************************************/
323 AcpiUtExecutePowerMethods (
324 ACPI_NAMESPACE_NODE *DeviceNode,
325 const char **MethodNames,
329 ACPI_OPERAND_OBJECT *ObjDesc;
331 ACPI_STATUS FinalStatus = AE_NOT_FOUND;
335 ACPI_FUNCTION_TRACE (UtExecutePowerMethods);
338 for (i = 0; i < MethodCount; i++)
341 * Execute the power method (_SxD or _SxW). The only allowable
342 * return type is an Integer.
344 Status = AcpiUtEvaluateObject (DeviceNode,
345 ACPI_CAST_PTR (char, MethodNames[i]),
346 ACPI_BTYPE_INTEGER, &ObjDesc);
347 if (ACPI_SUCCESS (Status))
349 OutValues[i] = (UINT8) ObjDesc->Integer.Value;
351 /* Delete the return object */
353 AcpiUtRemoveReference (ObjDesc);
354 FinalStatus = AE_OK; /* At least one value is valid */
358 OutValues[i] = ACPI_UINT8_MAX;
359 if (Status == AE_NOT_FOUND)
361 continue; /* Ignore if not found */
364 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Failed %s on Device %4.4s, %s\n",
365 ACPI_CAST_PTR (char, MethodNames[i]),
366 AcpiUtGetNodeName (DeviceNode), AcpiFormatException (Status)));
369 return_ACPI_STATUS (FinalStatus);