ACPICA: Major update for acpi_get_object_info external interface
[safe/jmp/linux-2.6] / drivers / acpi / acpica / uteval.c
1 /******************************************************************************
2  *
3  * Module Name: uteval - Object evaluation
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2008, Intel Corp.
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
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acnamesp.h"
47
48 #define _COMPONENT          ACPI_UTILITIES
49 ACPI_MODULE_NAME("uteval")
50
51 /*
52  * Strings supported by the _OSI predefined (internal) method.
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.
61  */
62 static struct acpi_interface_info acpi_interfaces_supported[] = {
63         /* Operating System Vendor Strings */
64
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
73         /* Feature Group Strings */
74
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          */
82 };
83
84 /*******************************************************************************
85  *
86  * FUNCTION:    acpi_ut_osi_implementation
87  *
88  * PARAMETERS:  walk_state          - Current walk state
89  *
90  * RETURN:      Status
91  *
92  * DESCRIPTION: Implementation of the _OSI predefined control method
93  *
94  ******************************************************************************/
95
96 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
97 {
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;
103
104         ACPI_FUNCTION_TRACE(ut_osi_implementation);
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)) {
110                 return_ACPI_STATUS(AE_TYPE);
111         }
112
113         /* Create a return object */
114
115         return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
116         if (!return_desc) {
117                 return_ACPI_STATUS(AE_NO_MEMORY);
118         }
119
120         /* Default return value is 0, NOT SUPPORTED */
121
122         return_value = 0;
123
124         /* Compare input string to static table of supported interfaces */
125
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)) {
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                         }
139
140                         return_value = ACPI_UINT32_MAX;
141                         goto exit;
142                 }
143         }
144
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)) {
152
153                 /* The interface is supported */
154
155                 return_value = ACPI_UINT32_MAX;
156         }
157
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 " : ""));
162
163         /* Complete the return value */
164
165         return_desc->integer.value = return_value;
166         walk_state->return_desc = return_desc;
167         return_ACPI_STATUS (AE_OK);
168 }
169
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
182 acpi_status acpi_osi_invalidate(char *interface)
183 {
184         int i;
185
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;
190                 }
191         }
192         return AE_NOT_FOUND;
193 }
194
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
207  *              return object. Common code that simplifies accessing objects
208  *              that have required return objects of fixed types.
209  *
210  *              NOTE: Internal function, no parameter validation
211  *
212  ******************************************************************************/
213
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)
219 {
220         struct acpi_evaluate_info *info;
221         acpi_status status;
222         u32 return_btype;
223
224         ACPI_FUNCTION_TRACE(ut_evaluate_object);
225
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;
235
236         /* Evaluate the object/method */
237
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);
248                 }
249
250                 goto cleanup;
251         }
252
253         /* Did we get a return object? */
254
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);
259
260                         status = AE_NOT_EXIST;
261                 }
262
263                 goto cleanup;
264         }
265
266         /* Map the return object type to the bitmapped type */
267
268         switch ((info->return_object)->common.type) {
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
290         if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
291                 /*
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.
295                  */
296                 acpi_ut_remove_reference(info->return_object);
297                 goto cleanup;
298         }
299
300         /* Is the return object one of the expected types? */
301
302         if (!(expected_return_btypes & return_btype)) {
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,
309                             acpi_ut_get_object_type_name(info->return_object),
310                             expected_return_btypes));
311
312                 /* On error exit, we must delete the return object */
313
314                 acpi_ut_remove_reference(info->return_object);
315                 status = AE_TYPE;
316                 goto cleanup;
317         }
318
319         /* Object type is OK, return it */
320
321         *return_desc = info->return_object;
322
323       cleanup:
324         ACPI_FREE(info);
325         return_ACPI_STATUS(status);
326 }
327
328 /*******************************************************************************
329  *
330  * FUNCTION:    acpi_ut_evaluate_numeric_object
331  *
332  * PARAMETERS:  object_name         - Object name to be evaluated
333  *              device_node         - Node for the device
334  *              Value               - Where the value is returned
335  *
336  * RETURN:      Status
337  *
338  * DESCRIPTION: Evaluates a numeric namespace object for a selected device
339  *              and stores result in *Value.
340  *
341  *              NOTE: Internal function, no parameter validation
342  *
343  ******************************************************************************/
344
345 acpi_status
346 acpi_ut_evaluate_numeric_object(char *object_name,
347                                 struct acpi_namespace_node *device_node,
348                                 acpi_integer *value)
349 {
350         union acpi_operand_object *obj_desc;
351         acpi_status status;
352
353         ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
354
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);
359         }
360
361         /* Get the returned Integer */
362
363         *value = obj_desc->integer.value;
364
365         /* On exit, we must delete the return object */
366
367         acpi_ut_remove_reference(obj_desc);
368         return_ACPI_STATUS(status);
369 }
370
371 /*******************************************************************************
372  *
373  * FUNCTION:    acpi_ut_execute_STA
374  *
375  * PARAMETERS:  device_node         - Node for the device
376  *              Flags               - Where the status flags are returned
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
387 acpi_status
388 acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
389 {
390         union acpi_operand_object *obj_desc;
391         acpi_status status;
392
393         ACPI_FUNCTION_TRACE(ut_execute_STA);
394
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)));
402
403                         *flags = ACPI_UINT32_MAX;
404                         status = AE_OK;
405                 }
406
407                 return_ACPI_STATUS(status);
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
416         acpi_ut_remove_reference(obj_desc);
417         return_ACPI_STATUS(status);
418 }
419
420 /*******************************************************************************
421  *
422  * FUNCTION:    acpi_ut_execute_power_methods
423  *
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
428  *
429  * RETURN:      Status, out_values
430  *
431  * DESCRIPTION: Executes the specified power methods for the device and returns
432  *              the result(s).
433  *
434  *              NOTE: Internal function, no parameter validation
435  *
436 ******************************************************************************/
437
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)
442 {
443         union acpi_operand_object *obj_desc;
444         acpi_status status;
445         acpi_status final_status = AE_NOT_FOUND;
446         u32 i;
447
448         ACPI_FUNCTION_TRACE(ut_execute_power_methods);
449
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                  */
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;
461
462                         /* Delete the return object */
463
464                         acpi_ut_remove_reference(obj_desc);
465                         final_status = AE_OK;   /* At least one value is valid */
466                         continue;
467                 }
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)));
479         }
480
481         return_ACPI_STATUS(final_status);
482 }