uteval.c revision 1.3.2.2 1 /******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44 #define __UTEVAL_C__
45
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acnamesp.h"
49
50
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("uteval")
53
54
55 /*******************************************************************************
56 *
57 * FUNCTION: AcpiUtEvaluateObject
58 *
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
63 *
64 * RETURN: Status
65 *
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.
69 *
70 * NOTE: Internal function, no parameter validation
71 *
72 ******************************************************************************/
73
74 ACPI_STATUS
75 AcpiUtEvaluateObject (
76 ACPI_NAMESPACE_NODE *PrefixNode,
77 const char *Path,
78 UINT32 ExpectedReturnBtypes,
79 ACPI_OPERAND_OBJECT **ReturnDesc)
80 {
81 ACPI_EVALUATE_INFO *Info;
82 ACPI_STATUS Status;
83 UINT32 ReturnBtype;
84 char *UPath = __UNCONST(Path);
85
86
87 ACPI_FUNCTION_TRACE (UtEvaluateObject);
88
89
90 /* Allocate the evaluation information block */
91
92 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
93 if (!Info)
94 {
95 return_ACPI_STATUS (AE_NO_MEMORY);
96 }
97
98 Info->PrefixNode = PrefixNode;
99 Info->Pathname = UPath;
100
101 /* Evaluate the object/method */
102
103 Status = AcpiNsEvaluate (Info);
104 if (ACPI_FAILURE (Status))
105 {
106 if (Status == AE_NOT_FOUND)
107 {
108 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
109 AcpiUtGetNodeName (PrefixNode), UPath));
110 }
111 else
112 {
113 ACPI_ERROR_METHOD ("Method execution failed",
114 PrefixNode, Path, Status);
115 }
116
117 goto Cleanup;
118 }
119
120 /* Did we get a return object? */
121
122 if (!Info->ReturnObject)
123 {
124 if (ExpectedReturnBtypes)
125 {
126 ACPI_ERROR_METHOD ("No object was returned from",
127 PrefixNode, Path, AE_NOT_EXIST);
128
129 Status = AE_NOT_EXIST;
130 }
131
132 goto Cleanup;
133 }
134
135 /* Map the return object type to the bitmapped type */
136
137 switch ((Info->ReturnObject)->Common.Type)
138 {
139 case ACPI_TYPE_INTEGER:
140 ReturnBtype = ACPI_BTYPE_INTEGER;
141 break;
142
143 case ACPI_TYPE_BUFFER:
144 ReturnBtype = ACPI_BTYPE_BUFFER;
145 break;
146
147 case ACPI_TYPE_STRING:
148 ReturnBtype = ACPI_BTYPE_STRING;
149 break;
150
151 case ACPI_TYPE_PACKAGE:
152 ReturnBtype = ACPI_BTYPE_PACKAGE;
153 break;
154
155 default:
156 ReturnBtype = 0;
157 break;
158 }
159
160 if ((AcpiGbl_EnableInterpreterSlack) &&
161 (!ExpectedReturnBtypes))
162 {
163 /*
164 * We received a return object, but one was not expected. This can
165 * happen frequently if the "implicit return" feature is enabled.
166 * Just delete the return object and return AE_OK.
167 */
168 AcpiUtRemoveReference (Info->ReturnObject);
169 goto Cleanup;
170 }
171
172 /* Is the return object one of the expected types? */
173
174 if (!(ExpectedReturnBtypes & ReturnBtype))
175 {
176 ACPI_ERROR_METHOD ("Return object type is incorrect",
177 PrefixNode, Path, AE_TYPE);
178
179 ACPI_ERROR ((AE_INFO,
180 "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
181 Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
182 ExpectedReturnBtypes));
183
184 /* On error exit, we must delete the return object */
185
186 AcpiUtRemoveReference (Info->ReturnObject);
187 Status = AE_TYPE;
188 goto Cleanup;
189 }
190
191 /* Object type is OK, return it */
192
193 *ReturnDesc = Info->ReturnObject;
194
195 Cleanup:
196 ACPI_FREE (Info);
197 return_ACPI_STATUS (Status);
198 }
199
200
201 /*******************************************************************************
202 *
203 * FUNCTION: AcpiUtEvaluateNumericObject
204 *
205 * PARAMETERS: ObjectName - Object name to be evaluated
206 * DeviceNode - Node for the device
207 * Value - Where the value is returned
208 *
209 * RETURN: Status
210 *
211 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
212 * and stores result in *Value.
213 *
214 * NOTE: Internal function, no parameter validation
215 *
216 ******************************************************************************/
217
218 ACPI_STATUS
219 AcpiUtEvaluateNumericObject (
220 const char *ObjectName,
221 ACPI_NAMESPACE_NODE *DeviceNode,
222 UINT64 *Value)
223 {
224 ACPI_OPERAND_OBJECT *ObjDesc;
225 ACPI_STATUS Status;
226
227
228 ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
229
230
231 Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
232 ACPI_BTYPE_INTEGER, &ObjDesc);
233 if (ACPI_FAILURE (Status))
234 {
235 return_ACPI_STATUS (Status);
236 }
237
238 /* Get the returned Integer */
239
240 *Value = ObjDesc->Integer.Value;
241
242 /* On exit, we must delete the return object */
243
244 AcpiUtRemoveReference (ObjDesc);
245 return_ACPI_STATUS (Status);
246 }
247
248
249 /*******************************************************************************
250 *
251 * FUNCTION: AcpiUtExecute_STA
252 *
253 * PARAMETERS: DeviceNode - Node for the device
254 * Flags - Where the status flags are returned
255 *
256 * RETURN: Status
257 *
258 * DESCRIPTION: Executes _STA for selected device and stores results in
259 * *Flags.
260 *
261 * NOTE: Internal function, no parameter validation
262 *
263 ******************************************************************************/
264
265 ACPI_STATUS
266 AcpiUtExecute_STA (
267 ACPI_NAMESPACE_NODE *DeviceNode,
268 UINT32 *Flags)
269 {
270 ACPI_OPERAND_OBJECT *ObjDesc;
271 ACPI_STATUS Status;
272
273
274 ACPI_FUNCTION_TRACE (UtExecute_STA);
275
276
277 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
278 ACPI_BTYPE_INTEGER, &ObjDesc);
279 if (ACPI_FAILURE (Status))
280 {
281 if (AE_NOT_FOUND == Status)
282 {
283 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
284 "_STA on %4.4s was not found, assuming device is present\n",
285 AcpiUtGetNodeName (DeviceNode)));
286
287 *Flags = ACPI_UINT32_MAX;
288 Status = AE_OK;
289 }
290
291 return_ACPI_STATUS (Status);
292 }
293
294 /* Extract the status flags */
295
296 *Flags = (UINT32) ObjDesc->Integer.Value;
297
298 /* On exit, we must delete the return object */
299
300 AcpiUtRemoveReference (ObjDesc);
301 return_ACPI_STATUS (Status);
302 }
303
304
305 /*******************************************************************************
306 *
307 * FUNCTION: AcpiUtExecutePowerMethods
308 *
309 * PARAMETERS: DeviceNode - Node for the device
310 * MethodNames - Array of power method names
311 * MethodCount - Number of methods to execute
312 * OutValues - Where the power method values are returned
313 *
314 * RETURN: Status, OutValues
315 *
316 * DESCRIPTION: Executes the specified power methods for the device and returns
317 * the result(s).
318 *
319 * NOTE: Internal function, no parameter validation
320 *
321 ******************************************************************************/
322
323 ACPI_STATUS
324 AcpiUtExecutePowerMethods (
325 ACPI_NAMESPACE_NODE *DeviceNode,
326 const char **MethodNames,
327 UINT8 MethodCount,
328 UINT8 *OutValues)
329 {
330 ACPI_OPERAND_OBJECT *ObjDesc;
331 ACPI_STATUS Status;
332 ACPI_STATUS FinalStatus = AE_NOT_FOUND;
333 UINT32 i;
334
335
336 ACPI_FUNCTION_TRACE (UtExecutePowerMethods);
337
338
339 for (i = 0; i < MethodCount; i++)
340 {
341 /*
342 * Execute the power method (_SxD or _SxW). The only allowable
343 * return type is an Integer.
344 */
345 Status = AcpiUtEvaluateObject (DeviceNode,
346 ACPI_CAST_PTR (char, MethodNames[i]),
347 ACPI_BTYPE_INTEGER, &ObjDesc);
348 if (ACPI_SUCCESS (Status))
349 {
350 OutValues[i] = (UINT8) ObjDesc->Integer.Value;
351
352 /* Delete the return object */
353
354 AcpiUtRemoveReference (ObjDesc);
355 FinalStatus = AE_OK; /* At least one value is valid */
356 continue;
357 }
358
359 OutValues[i] = ACPI_UINT8_MAX;
360 if (Status == AE_NOT_FOUND)
361 {
362 continue; /* Ignore if not found */
363 }
364
365 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Failed %s on Device %4.4s, %s\n",
366 ACPI_CAST_PTR (char, MethodNames[i]),
367 AcpiUtGetNodeName (DeviceNode), AcpiFormatException (Status)));
368 }
369
370 return_ACPI_STATUS (FinalStatus);
371 }
372