ACPICA: Major update for acpi_get_object_info external interface
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / acpi / acpica / uteval.c
blob5503307b8bb70c1c450ce9410c164a47f85dd1b7
1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2008, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acnamesp.h"
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("uteval")
52 * Strings supported by the _OSI predefined (internal) method.
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.
59 * The second element of each entry is used to track the newest version of
60 * Windows that the BIOS has requested.
62 static struct acpi_interface_info acpi_interfaces_supported[] = {
63 /* Operating System Vendor Strings */
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 */
73 /* Feature Group Strings */
75 {"Extended Address Space Descriptor", 0}
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.
84 /*******************************************************************************
86 * FUNCTION: acpi_ut_osi_implementation
88 * PARAMETERS: walk_state - Current walk state
90 * RETURN: Status
92 * DESCRIPTION: Implementation of the _OSI predefined control method
94 ******************************************************************************/
96 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
98 acpi_status status;
99 union acpi_operand_object *string_desc;
100 union acpi_operand_object *return_desc;
101 u32 return_value;
102 u32 i;
104 ACPI_FUNCTION_TRACE(ut_osi_implementation);
106 /* Validate the string input argument */
108 string_desc = walk_state->arguments[0].object;
109 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
110 return_ACPI_STATUS(AE_TYPE);
113 /* Create a return object */
115 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
116 if (!return_desc) {
117 return_ACPI_STATUS(AE_NO_MEMORY);
120 /* Default return value is 0, NOT SUPPORTED */
122 return_value = 0;
124 /* Compare input string to static table of supported interfaces */
126 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
127 if (!ACPI_STRCMP(string_desc->string.pointer,
128 acpi_interfaces_supported[i].name)) {
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.
134 if (acpi_interfaces_supported[i].value >
135 acpi_gbl_osi_data) {
136 acpi_gbl_osi_data =
137 acpi_interfaces_supported[i].value;
140 return_value = ACPI_UINT32_MAX;
141 goto exit;
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.)
150 status = acpi_os_validate_interface(string_desc->string.pointer);
151 if (ACPI_SUCCESS(status)) {
153 /* The interface is supported */
155 return_value = ACPI_UINT32_MAX;
158 exit:
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 " : ""));
163 /* Complete the return value */
165 return_desc->integer.value = return_value;
166 walk_state->return_desc = return_desc;
167 return_ACPI_STATUS (AE_OK);
170 /*******************************************************************************
172 * FUNCTION: acpi_osi_invalidate
174 * PARAMETERS: interface_string
176 * RETURN: Status
178 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
180 ******************************************************************************/
182 acpi_status acpi_osi_invalidate(char *interface)
184 int i;
186 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
187 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) {
188 *acpi_interfaces_supported[i].name = '\0';
189 return AE_OK;
192 return AE_NOT_FOUND;
195 /*******************************************************************************
197 * FUNCTION: acpi_ut_evaluate_object
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
204 * RETURN: Status
206 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
207 * return object. Common code that simplifies accessing objects
208 * that have required return objects of fixed types.
210 * NOTE: Internal function, no parameter validation
212 ******************************************************************************/
214 acpi_status
215 acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
216 char *path,
217 u32 expected_return_btypes,
218 union acpi_operand_object **return_desc)
220 struct acpi_evaluate_info *info;
221 acpi_status status;
222 u32 return_btype;
224 ACPI_FUNCTION_TRACE(ut_evaluate_object);
226 /* Allocate the evaluation information block */
228 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
229 if (!info) {
230 return_ACPI_STATUS(AE_NO_MEMORY);
233 info->prefix_node = prefix_node;
234 info->pathname = path;
236 /* Evaluate the object/method */
238 status = acpi_ns_evaluate(info);
239 if (ACPI_FAILURE(status)) {
240 if (status == AE_NOT_FOUND) {
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 {
246 ACPI_ERROR_METHOD("Method execution failed",
247 prefix_node, path, status);
250 goto cleanup;
253 /* Did we get a return object? */
255 if (!info->return_object) {
256 if (expected_return_btypes) {
257 ACPI_ERROR_METHOD("No object was returned from",
258 prefix_node, path, AE_NOT_EXIST);
260 status = AE_NOT_EXIST;
263 goto cleanup;
266 /* Map the return object type to the bitmapped type */
268 switch ((info->return_object)->common.type) {
269 case ACPI_TYPE_INTEGER:
270 return_btype = ACPI_BTYPE_INTEGER;
271 break;
273 case ACPI_TYPE_BUFFER:
274 return_btype = ACPI_BTYPE_BUFFER;
275 break;
277 case ACPI_TYPE_STRING:
278 return_btype = ACPI_BTYPE_STRING;
279 break;
281 case ACPI_TYPE_PACKAGE:
282 return_btype = ACPI_BTYPE_PACKAGE;
283 break;
285 default:
286 return_btype = 0;
287 break;
290 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
292 * We received a return object, but one was not expected. This can
293 * happen frequently if the "implicit return" feature is enabled.
294 * Just delete the return object and return AE_OK.
296 acpi_ut_remove_reference(info->return_object);
297 goto cleanup;
300 /* Is the return object one of the expected types? */
302 if (!(expected_return_btypes & return_btype)) {
303 ACPI_ERROR_METHOD("Return object type is incorrect",
304 prefix_node, path, AE_TYPE);
306 ACPI_ERROR((AE_INFO,
307 "Type returned from %s was incorrect: %s, expected Btypes: %X",
308 path,
309 acpi_ut_get_object_type_name(info->return_object),
310 expected_return_btypes));
312 /* On error exit, we must delete the return object */
314 acpi_ut_remove_reference(info->return_object);
315 status = AE_TYPE;
316 goto cleanup;
319 /* Object type is OK, return it */
321 *return_desc = info->return_object;
323 cleanup:
324 ACPI_FREE(info);
325 return_ACPI_STATUS(status);
328 /*******************************************************************************
330 * FUNCTION: acpi_ut_evaluate_numeric_object
332 * PARAMETERS: object_name - Object name to be evaluated
333 * device_node - Node for the device
334 * Value - Where the value is returned
336 * RETURN: Status
338 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
339 * and stores result in *Value.
341 * NOTE: Internal function, no parameter validation
343 ******************************************************************************/
345 acpi_status
346 acpi_ut_evaluate_numeric_object(char *object_name,
347 struct acpi_namespace_node *device_node,
348 acpi_integer *value)
350 union acpi_operand_object *obj_desc;
351 acpi_status status;
353 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
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);
361 /* Get the returned Integer */
363 *value = obj_desc->integer.value;
365 /* On exit, we must delete the return object */
367 acpi_ut_remove_reference(obj_desc);
368 return_ACPI_STATUS(status);
371 /*******************************************************************************
373 * FUNCTION: acpi_ut_execute_STA
375 * PARAMETERS: device_node - Node for the device
376 * Flags - Where the status flags are returned
378 * RETURN: Status
380 * DESCRIPTION: Executes _STA for selected device and stores results in
381 * *Flags.
383 * NOTE: Internal function, no parameter validation
385 ******************************************************************************/
387 acpi_status
388 acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
390 union acpi_operand_object *obj_desc;
391 acpi_status status;
393 ACPI_FUNCTION_TRACE(ut_execute_STA);
395 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
396 ACPI_BTYPE_INTEGER, &obj_desc);
397 if (ACPI_FAILURE(status)) {
398 if (AE_NOT_FOUND == status) {
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)));
403 *flags = ACPI_UINT32_MAX;
404 status = AE_OK;
407 return_ACPI_STATUS(status);
410 /* Extract the status flags */
412 *flags = (u32) obj_desc->integer.value;
414 /* On exit, we must delete the return object */
416 acpi_ut_remove_reference(obj_desc);
417 return_ACPI_STATUS(status);
420 /*******************************************************************************
422 * FUNCTION: acpi_ut_execute_power_methods
424 * PARAMETERS: device_node - Node for the device
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
429 * RETURN: Status, out_values
431 * DESCRIPTION: Executes the specified power methods for the device and returns
432 * the result(s).
434 * NOTE: Internal function, no parameter validation
436 ******************************************************************************/
438 acpi_status
439 acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
440 const char **method_names,
441 u8 method_count, u8 *out_values)
443 union acpi_operand_object *obj_desc;
444 acpi_status status;
445 acpi_status final_status = AE_NOT_FOUND;
446 u32 i;
448 ACPI_FUNCTION_TRACE(ut_execute_power_methods);
450 for (i = 0; i < method_count; i++) {
452 * Execute the power method (_sx_d or _sx_w). The only allowable
453 * return type is an Integer.
455 status = acpi_ut_evaluate_object(device_node,
456 ACPI_CAST_PTR(char,
457 method_names[i]),
458 ACPI_BTYPE_INTEGER, &obj_desc);
459 if (ACPI_SUCCESS(status)) {
460 out_values[i] = (u8)obj_desc->integer.value;
462 /* Delete the return object */
464 acpi_ut_remove_reference(obj_desc);
465 final_status = AE_OK; /* At least one value is valid */
466 continue;
469 out_values[i] = ACPI_UINT8_MAX;
470 if (status == AE_NOT_FOUND) {
471 continue; /* Ignore if not found */
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)));
481 return_ACPI_STATUS(final_status);