On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / drivers / acpi / acpica / uteval.c
blob5d54e36ab4536eb151acf54cf4a11c89dd9796de
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 */
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 */
76 /* Feature Group Strings */
78 {"Extended Address Space Descriptor", 0}
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.
87 /*******************************************************************************
89 * FUNCTION: acpi_ut_osi_implementation
91 * PARAMETERS: walk_state - Current walk state
93 * RETURN: Status
95 * DESCRIPTION: Implementation of the _OSI predefined control method
97 ******************************************************************************/
99 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
101 acpi_status status;
102 union acpi_operand_object *string_desc;
103 union acpi_operand_object *return_desc;
104 u32 return_value;
105 u32 i;
107 ACPI_FUNCTION_TRACE(ut_osi_implementation);
109 /* Validate the string input argument */
111 string_desc = walk_state->arguments[0].object;
112 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
113 return_ACPI_STATUS(AE_TYPE);
116 /* Create a return object */
118 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
119 if (!return_desc) {
120 return_ACPI_STATUS(AE_NO_MEMORY);
123 /* Default return value is 0, NOT SUPPORTED */
125 return_value = 0;
127 /* Compare input string to static table of supported interfaces */
129 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
130 if (!ACPI_STRCMP(string_desc->string.pointer,
131 acpi_interfaces_supported[i].name)) {
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.
137 if (acpi_interfaces_supported[i].value >
138 acpi_gbl_osi_data) {
139 acpi_gbl_osi_data =
140 acpi_interfaces_supported[i].value;
143 return_value = ACPI_UINT32_MAX;
144 goto exit;
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.)
153 status = acpi_os_validate_interface(string_desc->string.pointer);
154 if (ACPI_SUCCESS(status)) {
156 /* The interface is supported */
158 return_value = ACPI_UINT32_MAX;
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 " : ""));
166 /* Complete the return value */
168 return_desc->integer.value = return_value;
169 walk_state->return_desc = return_desc;
170 return_ACPI_STATUS (AE_OK);
173 /*******************************************************************************
175 * FUNCTION: acpi_osi_invalidate
177 * PARAMETERS: interface_string
179 * RETURN: Status
181 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
183 ******************************************************************************/
185 acpi_status acpi_osi_invalidate(char *interface)
187 int i;
189 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
190 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) {
191 *acpi_interfaces_supported[i].name = '\0';
192 return AE_OK;
195 return AE_NOT_FOUND;
198 /*******************************************************************************
200 * FUNCTION: acpi_ut_evaluate_object
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
207 * RETURN: Status
209 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
210 * return object. Common code that simplifies accessing objects
211 * that have required return objects of fixed types.
213 * NOTE: Internal function, no parameter validation
215 ******************************************************************************/
217 acpi_status
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)
223 struct acpi_evaluate_info *info;
224 acpi_status status;
225 u32 return_btype;
227 ACPI_FUNCTION_TRACE(ut_evaluate_object);
229 /* Allocate the evaluation information block */
231 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
232 if (!info) {
233 return_ACPI_STATUS(AE_NO_MEMORY);
236 info->prefix_node = prefix_node;
237 info->pathname = path;
239 /* Evaluate the object/method */
241 status = acpi_ns_evaluate(info);
242 if (ACPI_FAILURE(status)) {
243 if (status == AE_NOT_FOUND) {
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 {
249 ACPI_ERROR_METHOD("Method execution failed",
250 prefix_node, path, status);
253 goto cleanup;
256 /* Did we get a return object? */
258 if (!info->return_object) {
259 if (expected_return_btypes) {
260 ACPI_ERROR_METHOD("No object was returned from",
261 prefix_node, path, AE_NOT_EXIST);
263 status = AE_NOT_EXIST;
266 goto cleanup;
269 /* Map the return object type to the bitmapped type */
271 switch ((info->return_object)->common.type) {
272 case ACPI_TYPE_INTEGER:
273 return_btype = ACPI_BTYPE_INTEGER;
274 break;
276 case ACPI_TYPE_BUFFER:
277 return_btype = ACPI_BTYPE_BUFFER;
278 break;
280 case ACPI_TYPE_STRING:
281 return_btype = ACPI_BTYPE_STRING;
282 break;
284 case ACPI_TYPE_PACKAGE:
285 return_btype = ACPI_BTYPE_PACKAGE;
286 break;
288 default:
289 return_btype = 0;
290 break;
293 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
295 * We received a return object, but one was not expected. This can
296 * happen frequently if the "implicit return" feature is enabled.
297 * Just delete the return object and return AE_OK.
299 acpi_ut_remove_reference(info->return_object);
300 goto cleanup;
303 /* Is the return object one of the expected types? */
305 if (!(expected_return_btypes & return_btype)) {
306 ACPI_ERROR_METHOD("Return object type is incorrect",
307 prefix_node, path, AE_TYPE);
309 ACPI_ERROR((AE_INFO,
310 "Type returned from %s was incorrect: %s, expected Btypes: %X",
311 path,
312 acpi_ut_get_object_type_name(info->return_object),
313 expected_return_btypes));
315 /* On error exit, we must delete the return object */
317 acpi_ut_remove_reference(info->return_object);
318 status = AE_TYPE;
319 goto cleanup;
322 /* Object type is OK, return it */
324 *return_desc = info->return_object;
326 cleanup:
327 ACPI_FREE(info);
328 return_ACPI_STATUS(status);
331 /*******************************************************************************
333 * FUNCTION: acpi_ut_evaluate_numeric_object
335 * PARAMETERS: object_name - Object name to be evaluated
336 * device_node - Node for the device
337 * Value - Where the value is returned
339 * RETURN: Status
341 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
342 * and stores result in *Value.
344 * NOTE: Internal function, no parameter validation
346 ******************************************************************************/
348 acpi_status
349 acpi_ut_evaluate_numeric_object(char *object_name,
350 struct acpi_namespace_node *device_node,
351 acpi_integer *value)
353 union acpi_operand_object *obj_desc;
354 acpi_status status;
356 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
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);
364 /* Get the returned Integer */
366 *value = obj_desc->integer.value;
368 /* On exit, we must delete the return object */
370 acpi_ut_remove_reference(obj_desc);
371 return_ACPI_STATUS(status);
374 /*******************************************************************************
376 * FUNCTION: acpi_ut_execute_STA
378 * PARAMETERS: device_node - Node for the device
379 * Flags - Where the status flags are returned
381 * RETURN: Status
383 * DESCRIPTION: Executes _STA for selected device and stores results in
384 * *Flags.
386 * NOTE: Internal function, no parameter validation
388 ******************************************************************************/
390 acpi_status
391 acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
393 union acpi_operand_object *obj_desc;
394 acpi_status status;
396 ACPI_FUNCTION_TRACE(ut_execute_STA);
398 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
399 ACPI_BTYPE_INTEGER, &obj_desc);
400 if (ACPI_FAILURE(status)) {
401 if (AE_NOT_FOUND == status) {
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)));
406 *flags = ACPI_UINT32_MAX;
407 status = AE_OK;
410 return_ACPI_STATUS(status);
413 /* Extract the status flags */
415 *flags = (u32) obj_desc->integer.value;
417 /* On exit, we must delete the return object */
419 acpi_ut_remove_reference(obj_desc);
420 return_ACPI_STATUS(status);
423 /*******************************************************************************
425 * FUNCTION: acpi_ut_execute_power_methods
427 * PARAMETERS: device_node - Node for the device
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
432 * RETURN: Status, out_values
434 * DESCRIPTION: Executes the specified power methods for the device and returns
435 * the result(s).
437 * NOTE: Internal function, no parameter validation
439 ******************************************************************************/
441 acpi_status
442 acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
443 const char **method_names,
444 u8 method_count, u8 *out_values)
446 union acpi_operand_object *obj_desc;
447 acpi_status status;
448 acpi_status final_status = AE_NOT_FOUND;
449 u32 i;
451 ACPI_FUNCTION_TRACE(ut_execute_power_methods);
453 for (i = 0; i < method_count; i++) {
455 * Execute the power method (_sx_d or _sx_w). The only allowable
456 * return type is an Integer.
458 status = acpi_ut_evaluate_object(device_node,
459 ACPI_CAST_PTR(char,
460 method_names[i]),
461 ACPI_BTYPE_INTEGER, &obj_desc);
462 if (ACPI_SUCCESS(status)) {
463 out_values[i] = (u8)obj_desc->integer.value;
465 /* Delete the return object */
467 acpi_ut_remove_reference(obj_desc);
468 final_status = AE_OK; /* At least one value is valid */
469 continue;
472 out_values[i] = ACPI_UINT8_MAX;
473 if (status == AE_NOT_FOUND) {
474 continue; /* Ignore if not found */
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)));
484 return_ACPI_STATUS(final_status);