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