Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: uteval - Object evaluation | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
75a44ce0 | 8 | * Copyright (C) 2000 - 2008, 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 | |
b229cf92 BM |
51 | /* |
52 | * Strings supported by the _OSI predefined (internal) method. | |
7f071903 BM |
53 | * |
54 | * March 2009: Removed "Linux" as this host no longer wants to respond true | |
55 | * for this string. Basically, the only safe OS strings are windows-related | |
56 | * and in many or most cases represent the only test path within the | |
57 | * BIOS-provided ASL code. | |
58 | * | |
59 | * The second element of each entry is used to track the newest version of | |
60 | * Windows that the BIOS has requested. | |
b229cf92 | 61 | */ |
7f071903 | 62 | static struct acpi_interface_info acpi_interfaces_supported[] = { |
b229cf92 BM |
63 | /* Operating System Vendor Strings */ |
64 | ||
7f071903 BM |
65 | {"Windows 2000", ACPI_OSI_WIN_2000}, /* Windows 2000 */ |
66 | {"Windows 2001", ACPI_OSI_WIN_XP}, /* Windows XP */ | |
67 | {"Windows 2001 SP1", ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */ | |
68 | {"Windows 2001.1", ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */ | |
69 | {"Windows 2001 SP2", ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */ | |
70 | {"Windows 2001.1 SP1", ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */ | |
71 | {"Windows 2006", ACPI_OSI_WIN_VISTA}, /* Windows Vista - Added 03/2006 */ | |
eb752552 BM |
72 | {"Windows 2006.1", ACPI_OSI_WINSRV_2008}, /* Windows Server 2008 - Added 09/2009 */ |
73 | {"Windows 2006 SP1", ACPI_OSI_WIN_VISTA_SP1}, /* Windows Vista SP1 - Added 09/2009 */ | |
74 | {"Windows 2009", ACPI_OSI_WIN_7}, /* Windows 7 and Server 2008 R2 - Added 09/2009 */ | |
b229cf92 BM |
75 | |
76 | /* Feature Group Strings */ | |
77 | ||
7f071903 BM |
78 | {"Extended Address Space Descriptor", 0} |
79 | ||
80 | /* | |
81 | * All "optional" feature group strings (features that are implemented | |
82 | * by the host) should be implemented in the host version of | |
83 | * acpi_os_validate_interface and should not be added here. | |
84 | */ | |
b229cf92 BM |
85 | }; |
86 | ||
1da177e4 LT |
87 | /******************************************************************************* |
88 | * | |
89 | * FUNCTION: acpi_ut_osi_implementation | |
90 | * | |
91 | * PARAMETERS: walk_state - Current walk state | |
92 | * | |
93 | * RETURN: Status | |
94 | * | |
b229cf92 | 95 | * DESCRIPTION: Implementation of the _OSI predefined control method |
1da177e4 LT |
96 | * |
97 | ******************************************************************************/ | |
98 | ||
4be44fcd | 99 | acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state) |
1da177e4 | 100 | { |
b229cf92 | 101 | acpi_status status; |
4be44fcd LB |
102 | union acpi_operand_object *string_desc; |
103 | union acpi_operand_object *return_desc; | |
c114e4b6 | 104 | u32 return_value; |
67a119f9 | 105 | u32 i; |
1da177e4 | 106 | |
b229cf92 | 107 | ACPI_FUNCTION_TRACE(ut_osi_implementation); |
1da177e4 LT |
108 | |
109 | /* Validate the string input argument */ | |
110 | ||
111 | string_desc = walk_state->arguments[0].object; | |
112 | if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) { | |
4be44fcd | 113 | return_ACPI_STATUS(AE_TYPE); |
1da177e4 LT |
114 | } |
115 | ||
b229cf92 | 116 | /* Create a return object */ |
1da177e4 | 117 | |
4be44fcd | 118 | return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
1da177e4 | 119 | if (!return_desc) { |
4be44fcd | 120 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
121 | } |
122 | ||
c114e4b6 | 123 | /* Default return value is 0, NOT SUPPORTED */ |
1da177e4 | 124 | |
c114e4b6 | 125 | return_value = 0; |
b229cf92 BM |
126 | |
127 | /* Compare input string to static table of supported interfaces */ | |
52fc0b02 | 128 | |
b229cf92 | 129 | for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) { |
ec41f193 | 130 | if (!ACPI_STRCMP(string_desc->string.pointer, |
7f071903 BM |
131 | acpi_interfaces_supported[i].name)) { |
132 | /* | |
133 | * The interface is supported. | |
134 | * Update the osi_data if necessary. We keep track of the latest | |
135 | * version of Windows that has been requested by the BIOS. | |
136 | */ | |
137 | if (acpi_interfaces_supported[i].value > | |
138 | acpi_gbl_osi_data) { | |
139 | acpi_gbl_osi_data = | |
140 | acpi_interfaces_supported[i].value; | |
141 | } | |
c114e4b6 BM |
142 | |
143 | return_value = ACPI_UINT32_MAX; | |
144 | goto exit; | |
1da177e4 LT |
145 | } |
146 | } | |
147 | ||
b229cf92 BM |
148 | /* |
149 | * Did not match the string in the static table, call the host OSL to | |
150 | * check for a match with one of the optional strings (such as | |
151 | * "Module Device", "3.0 Thermal Model", etc.) | |
152 | */ | |
153 | status = acpi_os_validate_interface(string_desc->string.pointer); | |
154 | if (ACPI_SUCCESS(status)) { | |
c114e4b6 BM |
155 | |
156 | /* The interface is supported */ | |
157 | ||
158 | return_value = ACPI_UINT32_MAX; | |
b229cf92 BM |
159 | } |
160 | ||
c114e4b6 BM |
161 | exit: |
162 | ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO, | |
163 | "ACPI: BIOS _OSI(%s) is %ssupported\n", | |
164 | string_desc->string.pointer, return_value == 0 ? "not " : "")); | |
165 | ||
166 | /* Complete the return value */ | |
b229cf92 | 167 | |
c114e4b6 BM |
168 | return_desc->integer.value = return_value; |
169 | walk_state->return_desc = return_desc; | |
170 | return_ACPI_STATUS (AE_OK); | |
1da177e4 LT |
171 | } |
172 | ||
ae00d812 LB |
173 | /******************************************************************************* |
174 | * | |
175 | * FUNCTION: acpi_osi_invalidate | |
176 | * | |
177 | * PARAMETERS: interface_string | |
178 | * | |
179 | * RETURN: Status | |
180 | * | |
181 | * DESCRIPTION: invalidate string in pre-defiend _OSI string list | |
182 | * | |
183 | ******************************************************************************/ | |
184 | ||
185 | acpi_status acpi_osi_invalidate(char *interface) | |
186 | { | |
187 | int i; | |
188 | ||
189 | for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) { | |
7f071903 BM |
190 | if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) { |
191 | *acpi_interfaces_supported[i].name = '\0'; | |
ae00d812 LB |
192 | return AE_OK; |
193 | } | |
194 | } | |
195 | return AE_NOT_FOUND; | |
196 | } | |
197 | ||
1da177e4 LT |
198 | /******************************************************************************* |
199 | * | |
200 | * FUNCTION: acpi_ut_evaluate_object | |
201 | * | |
202 | * PARAMETERS: prefix_node - Starting node | |
203 | * Path - Path to object from starting node | |
204 | * expected_return_types - Bitmap of allowed return types | |
205 | * return_desc - Where a return value is stored | |
206 | * | |
207 | * RETURN: Status | |
208 | * | |
209 | * DESCRIPTION: Evaluates a namespace object and verifies the type of the | |
15b8dd53 | 210 | * return object. Common code that simplifies accessing objects |
1da177e4 LT |
211 | * that have required return objects of fixed types. |
212 | * | |
213 | * NOTE: Internal function, no parameter validation | |
214 | * | |
215 | ******************************************************************************/ | |
216 | ||
217 | acpi_status | |
4be44fcd LB |
218 | acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node, |
219 | char *path, | |
220 | u32 expected_return_btypes, | |
221 | union acpi_operand_object **return_desc) | |
1da177e4 | 222 | { |
4119532c | 223 | struct acpi_evaluate_info *info; |
4be44fcd LB |
224 | acpi_status status; |
225 | u32 return_btype; | |
1da177e4 | 226 | |
b229cf92 | 227 | ACPI_FUNCTION_TRACE(ut_evaluate_object); |
1da177e4 | 228 | |
4119532c BM |
229 | /* Allocate the evaluation information block */ |
230 | ||
231 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | |
232 | if (!info) { | |
233 | return_ACPI_STATUS(AE_NO_MEMORY); | |
234 | } | |
235 | ||
236 | info->prefix_node = prefix_node; | |
237 | info->pathname = path; | |
1da177e4 LT |
238 | |
239 | /* Evaluate the object/method */ | |
240 | ||
4119532c | 241 | status = acpi_ns_evaluate(info); |
4be44fcd | 242 | if (ACPI_FAILURE(status)) { |
1da177e4 | 243 | if (status == AE_NOT_FOUND) { |
4be44fcd LB |
244 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
245 | "[%4.4s.%s] was not found\n", | |
246 | acpi_ut_get_node_name(prefix_node), | |
247 | path)); | |
248 | } else { | |
b8e4d893 BM |
249 | ACPI_ERROR_METHOD("Method execution failed", |
250 | prefix_node, path, status); | |
1da177e4 LT |
251 | } |
252 | ||
4119532c | 253 | goto cleanup; |
1da177e4 LT |
254 | } |
255 | ||
256 | /* Did we get a return object? */ | |
257 | ||
4119532c | 258 | if (!info->return_object) { |
1da177e4 | 259 | if (expected_return_btypes) { |
b8e4d893 BM |
260 | ACPI_ERROR_METHOD("No object was returned from", |
261 | prefix_node, path, AE_NOT_EXIST); | |
1da177e4 | 262 | |
4119532c | 263 | status = AE_NOT_EXIST; |
1da177e4 LT |
264 | } |
265 | ||
4119532c | 266 | goto cleanup; |
1da177e4 LT |
267 | } |
268 | ||
269 | /* Map the return object type to the bitmapped type */ | |
270 | ||
3371c19c | 271 | switch ((info->return_object)->common.type) { |
1da177e4 LT |
272 | case ACPI_TYPE_INTEGER: |
273 | return_btype = ACPI_BTYPE_INTEGER; | |
274 | break; | |
275 | ||
276 | case ACPI_TYPE_BUFFER: | |
277 | return_btype = ACPI_BTYPE_BUFFER; | |
278 | break; | |
279 | ||
280 | case ACPI_TYPE_STRING: | |
281 | return_btype = ACPI_BTYPE_STRING; | |
282 | break; | |
283 | ||
284 | case ACPI_TYPE_PACKAGE: | |
285 | return_btype = ACPI_BTYPE_PACKAGE; | |
286 | break; | |
287 | ||
288 | default: | |
289 | return_btype = 0; | |
290 | break; | |
291 | } | |
292 | ||
4be44fcd | 293 | if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) { |
1da177e4 | 294 | /* |
15b8dd53 | 295 | * We received a return object, but one was not expected. This can |
1da177e4 LT |
296 | * happen frequently if the "implicit return" feature is enabled. |
297 | * Just delete the return object and return AE_OK. | |
298 | */ | |
4119532c BM |
299 | acpi_ut_remove_reference(info->return_object); |
300 | goto cleanup; | |
1da177e4 LT |
301 | } |
302 | ||
303 | /* Is the return object one of the expected types? */ | |
304 | ||
305 | if (!(expected_return_btypes & return_btype)) { | |
b8e4d893 BM |
306 | ACPI_ERROR_METHOD("Return object type is incorrect", |
307 | prefix_node, path, AE_TYPE); | |
308 | ||
309 | ACPI_ERROR((AE_INFO, | |
310 | "Type returned from %s was incorrect: %s, expected Btypes: %X", | |
311 | path, | |
4119532c | 312 | acpi_ut_get_object_type_name(info->return_object), |
b8e4d893 | 313 | expected_return_btypes)); |
1da177e4 LT |
314 | |
315 | /* On error exit, we must delete the return object */ | |
316 | ||
4119532c BM |
317 | acpi_ut_remove_reference(info->return_object); |
318 | status = AE_TYPE; | |
319 | goto cleanup; | |
1da177e4 LT |
320 | } |
321 | ||
322 | /* Object type is OK, return it */ | |
323 | ||
4119532c BM |
324 | *return_desc = info->return_object; |
325 | ||
326 | cleanup: | |
327 | ACPI_FREE(info); | |
328 | return_ACPI_STATUS(status); | |
1da177e4 LT |
329 | } |
330 | ||
1da177e4 LT |
331 | /******************************************************************************* |
332 | * | |
333 | * FUNCTION: acpi_ut_evaluate_numeric_object | |
334 | * | |
44f6c012 | 335 | * PARAMETERS: object_name - Object name to be evaluated |
1da177e4 | 336 | * device_node - Node for the device |
15b8dd53 | 337 | * Value - Where the value is returned |
1da177e4 LT |
338 | * |
339 | * RETURN: Status | |
340 | * | |
341 | * DESCRIPTION: Evaluates a numeric namespace object for a selected device | |
15b8dd53 | 342 | * and stores result in *Value. |
1da177e4 LT |
343 | * |
344 | * NOTE: Internal function, no parameter validation | |
345 | * | |
346 | ******************************************************************************/ | |
347 | ||
348 | acpi_status | |
4be44fcd LB |
349 | acpi_ut_evaluate_numeric_object(char *object_name, |
350 | struct acpi_namespace_node *device_node, | |
15b8dd53 | 351 | acpi_integer *value) |
1da177e4 | 352 | { |
4be44fcd LB |
353 | union acpi_operand_object *obj_desc; |
354 | acpi_status status; | |
1da177e4 | 355 | |
b229cf92 | 356 | ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object); |
1da177e4 | 357 | |
4be44fcd LB |
358 | status = acpi_ut_evaluate_object(device_node, object_name, |
359 | ACPI_BTYPE_INTEGER, &obj_desc); | |
360 | if (ACPI_FAILURE(status)) { | |
361 | return_ACPI_STATUS(status); | |
1da177e4 LT |
362 | } |
363 | ||
364 | /* Get the returned Integer */ | |
365 | ||
15b8dd53 | 366 | *value = obj_desc->integer.value; |
1da177e4 LT |
367 | |
368 | /* On exit, we must delete the return object */ | |
369 | ||
4be44fcd LB |
370 | acpi_ut_remove_reference(obj_desc); |
371 | return_ACPI_STATUS(status); | |
1da177e4 LT |
372 | } |
373 | ||
1da177e4 LT |
374 | /******************************************************************************* |
375 | * | |
376 | * FUNCTION: acpi_ut_execute_STA | |
377 | * | |
378 | * PARAMETERS: device_node - Node for the device | |
44f6c012 | 379 | * Flags - Where the status flags are returned |
1da177e4 LT |
380 | * |
381 | * RETURN: Status | |
382 | * | |
383 | * DESCRIPTION: Executes _STA for selected device and stores results in | |
384 | * *Flags. | |
385 | * | |
386 | * NOTE: Internal function, no parameter validation | |
387 | * | |
388 | ******************************************************************************/ | |
389 | ||
390 | acpi_status | |
4be44fcd | 391 | acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags) |
1da177e4 | 392 | { |
4be44fcd LB |
393 | union acpi_operand_object *obj_desc; |
394 | acpi_status status; | |
1da177e4 | 395 | |
b229cf92 | 396 | ACPI_FUNCTION_TRACE(ut_execute_STA); |
1da177e4 | 397 | |
4be44fcd LB |
398 | status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA, |
399 | ACPI_BTYPE_INTEGER, &obj_desc); | |
400 | if (ACPI_FAILURE(status)) { | |
1da177e4 | 401 | if (AE_NOT_FOUND == status) { |
4be44fcd LB |
402 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
403 | "_STA on %4.4s was not found, assuming device is present\n", | |
404 | acpi_ut_get_node_name(device_node))); | |
1da177e4 | 405 | |
defba1d8 | 406 | *flags = ACPI_UINT32_MAX; |
1da177e4 LT |
407 | status = AE_OK; |
408 | } | |
409 | ||
4be44fcd | 410 | return_ACPI_STATUS(status); |
1da177e4 LT |
411 | } |
412 | ||
413 | /* Extract the status flags */ | |
414 | ||
415 | *flags = (u32) obj_desc->integer.value; | |
416 | ||
417 | /* On exit, we must delete the return object */ | |
418 | ||
4be44fcd LB |
419 | acpi_ut_remove_reference(obj_desc); |
420 | return_ACPI_STATUS(status); | |
1da177e4 LT |
421 | } |
422 | ||
1da177e4 LT |
423 | /******************************************************************************* |
424 | * | |
15b8dd53 | 425 | * FUNCTION: acpi_ut_execute_power_methods |
1da177e4 LT |
426 | * |
427 | * PARAMETERS: device_node - Node for the device | |
15b8dd53 BM |
428 | * method_names - Array of power method names |
429 | * method_count - Number of methods to execute | |
430 | * out_values - Where the power method values are returned | |
1da177e4 | 431 | * |
15b8dd53 | 432 | * RETURN: Status, out_values |
1da177e4 | 433 | * |
15b8dd53 BM |
434 | * DESCRIPTION: Executes the specified power methods for the device and returns |
435 | * the result(s). | |
1da177e4 LT |
436 | * |
437 | * NOTE: Internal function, no parameter validation | |
438 | * | |
15b8dd53 | 439 | ******************************************************************************/ |
1da177e4 LT |
440 | |
441 | acpi_status | |
15b8dd53 BM |
442 | acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node, |
443 | const char **method_names, | |
444 | u8 method_count, u8 *out_values) | |
1da177e4 | 445 | { |
4be44fcd LB |
446 | union acpi_operand_object *obj_desc; |
447 | acpi_status status; | |
15b8dd53 | 448 | acpi_status final_status = AE_NOT_FOUND; |
4be44fcd | 449 | u32 i; |
1da177e4 | 450 | |
15b8dd53 | 451 | ACPI_FUNCTION_TRACE(ut_execute_power_methods); |
1da177e4 | 452 | |
15b8dd53 BM |
453 | for (i = 0; i < method_count; i++) { |
454 | /* | |
455 | * Execute the power method (_sx_d or _sx_w). The only allowable | |
456 | * return type is an Integer. | |
457 | */ | |
4be44fcd | 458 | status = acpi_ut_evaluate_object(device_node, |
defba1d8 | 459 | ACPI_CAST_PTR(char, |
15b8dd53 | 460 | method_names[i]), |
defba1d8 | 461 | ACPI_BTYPE_INTEGER, &obj_desc); |
15b8dd53 BM |
462 | if (ACPI_SUCCESS(status)) { |
463 | out_values[i] = (u8)obj_desc->integer.value; | |
1da177e4 LT |
464 | |
465 | /* Delete the return object */ | |
466 | ||
4be44fcd | 467 | acpi_ut_remove_reference(obj_desc); |
15b8dd53 BM |
468 | final_status = AE_OK; /* At least one value is valid */ |
469 | continue; | |
1da177e4 | 470 | } |
15b8dd53 BM |
471 | |
472 | out_values[i] = ACPI_UINT8_MAX; | |
473 | if (status == AE_NOT_FOUND) { | |
474 | continue; /* Ignore if not found */ | |
475 | } | |
476 | ||
477 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, | |
478 | "Failed %s on Device %4.4s, %s\n", | |
479 | ACPI_CAST_PTR(char, method_names[i]), | |
480 | acpi_ut_get_node_name(device_node), | |
481 | acpi_format_exception(status))); | |
1da177e4 LT |
482 | } |
483 | ||
15b8dd53 | 484 | return_ACPI_STATUS(final_status); |
1da177e4 | 485 | } |