Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: uteval - Object evaluation | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
25f044e6 | 8 | * Copyright (C) 2000 - 2013, Intel Corp. |
1da177e4 LT |
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 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acnamesp.h" | |
1da177e4 | 47 | |
1da177e4 | 48 | #define _COMPONENT ACPI_UTILITIES |
4be44fcd | 49 | ACPI_MODULE_NAME("uteval") |
1da177e4 | 50 | |
1da177e4 LT |
51 | /******************************************************************************* |
52 | * | |
53 | * FUNCTION: acpi_ut_evaluate_object | |
54 | * | |
55 | * PARAMETERS: prefix_node - Starting node | |
ba494bee | 56 | * path - Path to object from starting node |
1da177e4 LT |
57 | * expected_return_types - Bitmap of allowed return types |
58 | * return_desc - Where a return value is stored | |
59 | * | |
60 | * RETURN: Status | |
61 | * | |
62 | * DESCRIPTION: Evaluates a namespace object and verifies the type of the | |
15b8dd53 | 63 | * return object. Common code that simplifies accessing objects |
1da177e4 LT |
64 | * that have required return objects of fixed types. |
65 | * | |
66 | * NOTE: Internal function, no parameter validation | |
67 | * | |
68 | ******************************************************************************/ | |
69 | ||
70 | acpi_status | |
b6872ff9 | 71 | acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node, |
4be44fcd LB |
72 | char *path, |
73 | u32 expected_return_btypes, | |
74 | union acpi_operand_object **return_desc) | |
1da177e4 | 75 | { |
4119532c | 76 | struct acpi_evaluate_info *info; |
4be44fcd LB |
77 | acpi_status status; |
78 | u32 return_btype; | |
1da177e4 | 79 | |
b229cf92 | 80 | ACPI_FUNCTION_TRACE(ut_evaluate_object); |
1da177e4 | 81 | |
4119532c BM |
82 | /* Allocate the evaluation information block */ |
83 | ||
84 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | |
85 | if (!info) { | |
86 | return_ACPI_STATUS(AE_NO_MEMORY); | |
87 | } | |
88 | ||
89 | info->prefix_node = prefix_node; | |
29a241cc | 90 | info->relative_pathname = path; |
1da177e4 LT |
91 | |
92 | /* Evaluate the object/method */ | |
93 | ||
4119532c | 94 | status = acpi_ns_evaluate(info); |
4be44fcd | 95 | if (ACPI_FAILURE(status)) { |
1da177e4 | 96 | if (status == AE_NOT_FOUND) { |
4be44fcd LB |
97 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
98 | "[%4.4s.%s] was not found\n", | |
99 | acpi_ut_get_node_name(prefix_node), | |
100 | path)); | |
101 | } else { | |
b8e4d893 BM |
102 | ACPI_ERROR_METHOD("Method execution failed", |
103 | prefix_node, path, status); | |
1da177e4 LT |
104 | } |
105 | ||
4119532c | 106 | goto cleanup; |
1da177e4 LT |
107 | } |
108 | ||
109 | /* Did we get a return object? */ | |
110 | ||
4119532c | 111 | if (!info->return_object) { |
1da177e4 | 112 | if (expected_return_btypes) { |
b8e4d893 BM |
113 | ACPI_ERROR_METHOD("No object was returned from", |
114 | prefix_node, path, AE_NOT_EXIST); | |
1da177e4 | 115 | |
4119532c | 116 | status = AE_NOT_EXIST; |
1da177e4 LT |
117 | } |
118 | ||
4119532c | 119 | goto cleanup; |
1da177e4 LT |
120 | } |
121 | ||
122 | /* Map the return object type to the bitmapped type */ | |
123 | ||
3371c19c | 124 | switch ((info->return_object)->common.type) { |
1da177e4 | 125 | case ACPI_TYPE_INTEGER: |
1d1ea1b7 | 126 | |
1da177e4 LT |
127 | return_btype = ACPI_BTYPE_INTEGER; |
128 | break; | |
129 | ||
130 | case ACPI_TYPE_BUFFER: | |
1d1ea1b7 | 131 | |
1da177e4 LT |
132 | return_btype = ACPI_BTYPE_BUFFER; |
133 | break; | |
134 | ||
135 | case ACPI_TYPE_STRING: | |
1d1ea1b7 | 136 | |
1da177e4 LT |
137 | return_btype = ACPI_BTYPE_STRING; |
138 | break; | |
139 | ||
140 | case ACPI_TYPE_PACKAGE: | |
1d1ea1b7 | 141 | |
1da177e4 LT |
142 | return_btype = ACPI_BTYPE_PACKAGE; |
143 | break; | |
144 | ||
145 | default: | |
1d1ea1b7 | 146 | |
1da177e4 LT |
147 | return_btype = 0; |
148 | break; | |
149 | } | |
150 | ||
4be44fcd | 151 | if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) { |
1da177e4 | 152 | /* |
15b8dd53 | 153 | * We received a return object, but one was not expected. This can |
1da177e4 LT |
154 | * happen frequently if the "implicit return" feature is enabled. |
155 | * Just delete the return object and return AE_OK. | |
156 | */ | |
4119532c BM |
157 | acpi_ut_remove_reference(info->return_object); |
158 | goto cleanup; | |
1da177e4 LT |
159 | } |
160 | ||
161 | /* Is the return object one of the expected types? */ | |
162 | ||
163 | if (!(expected_return_btypes & return_btype)) { | |
b8e4d893 BM |
164 | ACPI_ERROR_METHOD("Return object type is incorrect", |
165 | prefix_node, path, AE_TYPE); | |
166 | ||
167 | ACPI_ERROR((AE_INFO, | |
f6a22b0b | 168 | "Type returned from %s was incorrect: %s, expected Btypes: 0x%X", |
b8e4d893 | 169 | path, |
4119532c | 170 | acpi_ut_get_object_type_name(info->return_object), |
b8e4d893 | 171 | expected_return_btypes)); |
1da177e4 LT |
172 | |
173 | /* On error exit, we must delete the return object */ | |
174 | ||
4119532c BM |
175 | acpi_ut_remove_reference(info->return_object); |
176 | status = AE_TYPE; | |
177 | goto cleanup; | |
1da177e4 LT |
178 | } |
179 | ||
180 | /* Object type is OK, return it */ | |
181 | ||
4119532c BM |
182 | *return_desc = info->return_object; |
183 | ||
184 | cleanup: | |
185 | ACPI_FREE(info); | |
186 | return_ACPI_STATUS(status); | |
1da177e4 LT |
187 | } |
188 | ||
1da177e4 LT |
189 | /******************************************************************************* |
190 | * | |
191 | * FUNCTION: acpi_ut_evaluate_numeric_object | |
192 | * | |
44f6c012 | 193 | * PARAMETERS: object_name - Object name to be evaluated |
1da177e4 | 194 | * device_node - Node for the device |
ba494bee | 195 | * value - Where the value is returned |
1da177e4 LT |
196 | * |
197 | * RETURN: Status | |
198 | * | |
199 | * DESCRIPTION: Evaluates a numeric namespace object for a selected device | |
15b8dd53 | 200 | * and stores result in *Value. |
1da177e4 LT |
201 | * |
202 | * NOTE: Internal function, no parameter validation | |
203 | * | |
204 | ******************************************************************************/ | |
205 | ||
206 | acpi_status | |
4be44fcd LB |
207 | acpi_ut_evaluate_numeric_object(char *object_name, |
208 | struct acpi_namespace_node *device_node, | |
5df7e6cb | 209 | u64 *value) |
1da177e4 | 210 | { |
4be44fcd LB |
211 | union acpi_operand_object *obj_desc; |
212 | acpi_status status; | |
1da177e4 | 213 | |
b229cf92 | 214 | ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object); |
1da177e4 | 215 | |
4be44fcd LB |
216 | status = acpi_ut_evaluate_object(device_node, object_name, |
217 | ACPI_BTYPE_INTEGER, &obj_desc); | |
218 | if (ACPI_FAILURE(status)) { | |
219 | return_ACPI_STATUS(status); | |
1da177e4 LT |
220 | } |
221 | ||
222 | /* Get the returned Integer */ | |
223 | ||
15b8dd53 | 224 | *value = obj_desc->integer.value; |
1da177e4 LT |
225 | |
226 | /* On exit, we must delete the return object */ | |
227 | ||
4be44fcd LB |
228 | acpi_ut_remove_reference(obj_desc); |
229 | return_ACPI_STATUS(status); | |
1da177e4 LT |
230 | } |
231 | ||
1da177e4 LT |
232 | /******************************************************************************* |
233 | * | |
234 | * FUNCTION: acpi_ut_execute_STA | |
235 | * | |
236 | * PARAMETERS: device_node - Node for the device | |
ba494bee | 237 | * flags - Where the status flags are returned |
1da177e4 LT |
238 | * |
239 | * RETURN: Status | |
240 | * | |
241 | * DESCRIPTION: Executes _STA for selected device and stores results in | |
242 | * *Flags. | |
243 | * | |
244 | * NOTE: Internal function, no parameter validation | |
245 | * | |
246 | ******************************************************************************/ | |
247 | ||
248 | acpi_status | |
4be44fcd | 249 | acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags) |
1da177e4 | 250 | { |
4be44fcd LB |
251 | union acpi_operand_object *obj_desc; |
252 | acpi_status status; | |
1da177e4 | 253 | |
b229cf92 | 254 | ACPI_FUNCTION_TRACE(ut_execute_STA); |
1da177e4 | 255 | |
4be44fcd LB |
256 | status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA, |
257 | ACPI_BTYPE_INTEGER, &obj_desc); | |
258 | if (ACPI_FAILURE(status)) { | |
1da177e4 | 259 | if (AE_NOT_FOUND == status) { |
4be44fcd LB |
260 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
261 | "_STA on %4.4s was not found, assuming device is present\n", | |
262 | acpi_ut_get_node_name(device_node))); | |
1da177e4 | 263 | |
defba1d8 | 264 | *flags = ACPI_UINT32_MAX; |
1da177e4 LT |
265 | status = AE_OK; |
266 | } | |
267 | ||
4be44fcd | 268 | return_ACPI_STATUS(status); |
1da177e4 LT |
269 | } |
270 | ||
271 | /* Extract the status flags */ | |
272 | ||
273 | *flags = (u32) obj_desc->integer.value; | |
274 | ||
275 | /* On exit, we must delete the return object */ | |
276 | ||
4be44fcd LB |
277 | acpi_ut_remove_reference(obj_desc); |
278 | return_ACPI_STATUS(status); | |
1da177e4 LT |
279 | } |
280 | ||
1da177e4 LT |
281 | /******************************************************************************* |
282 | * | |
15b8dd53 | 283 | * FUNCTION: acpi_ut_execute_power_methods |
1da177e4 LT |
284 | * |
285 | * PARAMETERS: device_node - Node for the device | |
15b8dd53 BM |
286 | * method_names - Array of power method names |
287 | * method_count - Number of methods to execute | |
288 | * out_values - Where the power method values are returned | |
1da177e4 | 289 | * |
15b8dd53 | 290 | * RETURN: Status, out_values |
1da177e4 | 291 | * |
15b8dd53 BM |
292 | * DESCRIPTION: Executes the specified power methods for the device and returns |
293 | * the result(s). | |
1da177e4 LT |
294 | * |
295 | * NOTE: Internal function, no parameter validation | |
296 | * | |
15b8dd53 | 297 | ******************************************************************************/ |
1da177e4 LT |
298 | |
299 | acpi_status | |
15b8dd53 BM |
300 | acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node, |
301 | const char **method_names, | |
302 | u8 method_count, u8 *out_values) | |
1da177e4 | 303 | { |
4be44fcd LB |
304 | union acpi_operand_object *obj_desc; |
305 | acpi_status status; | |
15b8dd53 | 306 | acpi_status final_status = AE_NOT_FOUND; |
4be44fcd | 307 | u32 i; |
1da177e4 | 308 | |
15b8dd53 | 309 | ACPI_FUNCTION_TRACE(ut_execute_power_methods); |
1da177e4 | 310 | |
15b8dd53 BM |
311 | for (i = 0; i < method_count; i++) { |
312 | /* | |
313 | * Execute the power method (_sx_d or _sx_w). The only allowable | |
314 | * return type is an Integer. | |
315 | */ | |
4be44fcd | 316 | status = acpi_ut_evaluate_object(device_node, |
defba1d8 | 317 | ACPI_CAST_PTR(char, |
15b8dd53 | 318 | method_names[i]), |
defba1d8 | 319 | ACPI_BTYPE_INTEGER, &obj_desc); |
15b8dd53 BM |
320 | if (ACPI_SUCCESS(status)) { |
321 | out_values[i] = (u8)obj_desc->integer.value; | |
1da177e4 LT |
322 | |
323 | /* Delete the return object */ | |
324 | ||
4be44fcd | 325 | acpi_ut_remove_reference(obj_desc); |
15b8dd53 BM |
326 | final_status = AE_OK; /* At least one value is valid */ |
327 | continue; | |
1da177e4 | 328 | } |
15b8dd53 BM |
329 | |
330 | out_values[i] = ACPI_UINT8_MAX; | |
331 | if (status == AE_NOT_FOUND) { | |
332 | continue; /* Ignore if not found */ | |
333 | } | |
334 | ||
335 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | |
336 | "Failed %s on Device %4.4s, %s\n", | |
337 | ACPI_CAST_PTR(char, method_names[i]), | |
338 | acpi_ut_get_node_name(device_node), | |
339 | acpi_format_exception(status))); | |
1da177e4 LT |
340 | } |
341 | ||
15b8dd53 | 342 | return_ACPI_STATUS(final_status); |
1da177e4 | 343 | } |