blob: da9450bc60f7062e05f0f0ba385572525e5a4f23 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 *
5 *****************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
47#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("uteval")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040053static void
Len Brown4be44fc2005-08-05 00:44:28 -040054acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length);
Robert Moore44f6c012005-04-18 22:49:35 -040055
56static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040057acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
58 struct acpi_compatible_id *one_cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Bob Mooreb229cf92006-04-21 17:15:00 -040060/*
61 * Strings supported by the _OSI predefined (internal) method.
62 */
Len Brownae00d812007-05-29 18:43:33 -040063static char *acpi_interfaces_supported[] = {
Bob Mooreb229cf92006-04-21 17:15:00 -040064 /* Operating System Vendor Strings */
65
Bob Moore3c6394c2007-03-26 22:10:34 -040066 "Windows 2000", /* Windows 2000 */
67 "Windows 2001", /* Windows XP */
68 "Windows 2001 SP1", /* Windows XP SP1 */
69 "Windows 2001 SP2", /* Windows XP SP2 */
70 "Windows 2001.1", /* Windows Server 2003 */
71 "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */
72 "Windows 2006", /* Windows Vista - Added 03/2006 */
Bob Mooreb229cf92006-04-21 17:15:00 -040073
74 /* Feature Group Strings */
75
76 "Extended Address Space Descriptor"
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*******************************************************************************
85 *
86 * FUNCTION: acpi_ut_osi_implementation
87 *
88 * PARAMETERS: walk_state - Current walk state
89 *
90 * RETURN: Status
91 *
Bob Mooreb229cf92006-04-21 17:15:00 -040092 * DESCRIPTION: Implementation of the _OSI predefined control method
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 *
94 ******************************************************************************/
95
Len Brown4be44fc2005-08-05 00:44:28 -040096acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Bob Mooreb229cf92006-04-21 17:15:00 -040098 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -040099 union acpi_operand_object *string_desc;
100 union acpi_operand_object *return_desc;
Bob Moore67a119f2008-06-10 13:42:13 +0800101 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Bob Mooreb229cf92006-04-21 17:15:00 -0400103 ACPI_FUNCTION_TRACE(ut_osi_implementation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /* Validate the string input argument */
106
107 string_desc = walk_state->arguments[0].object;
108 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400109 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111
Bob Mooreb229cf92006-04-21 17:15:00 -0400112 /* Create a return object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Len Brown4be44fc2005-08-05 00:44:28 -0400114 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 if (!return_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400116 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
Bob Mooreb229cf92006-04-21 17:15:00 -0400119 /* Default return value is SUPPORTED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Bob Mooreb229cf92006-04-21 17:15:00 -0400121 return_desc->integer.value = ACPI_UINT32_MAX;
122 walk_state->return_desc = return_desc;
Bob Moore52fc0b02006-10-02 00:00:00 -0400123
Bob Mooreb229cf92006-04-21 17:15:00 -0400124 /* Compare input string to static table of supported interfaces */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Bob Mooreb229cf92006-04-21 17:15:00 -0400126 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
127 if (!ACPI_STRCMP
128 (string_desc->string.pointer,
129 acpi_interfaces_supported[i])) {
130
131 /* The interface is supported */
132
Bob Moorea8fadc92008-11-13 09:45:35 +0800133 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
135 }
136
Bob Mooreb229cf92006-04-21 17:15:00 -0400137 /*
138 * Did not match the string in the static table, call the host OSL to
139 * check for a match with one of the optional strings (such as
140 * "Module Device", "3.0 Thermal Model", etc.)
141 */
142 status = acpi_os_validate_interface(string_desc->string.pointer);
143 if (ACPI_SUCCESS(status)) {
144
145 /* The interface is supported */
146
Bob Moorea8fadc92008-11-13 09:45:35 +0800147 return_ACPI_STATUS(AE_OK);
Bob Mooreb229cf92006-04-21 17:15:00 -0400148 }
149
150 /* The interface is not supported */
151
152 return_desc->integer.value = 0;
Bob Moorea8fadc92008-11-13 09:45:35 +0800153 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154}
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/*******************************************************************************
157 *
Len Brownae00d812007-05-29 18:43:33 -0400158 * FUNCTION: acpi_osi_invalidate
159 *
160 * PARAMETERS: interface_string
161 *
162 * RETURN: Status
163 *
164 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
165 *
166 ******************************************************************************/
167
168acpi_status acpi_osi_invalidate(char *interface)
169{
170 int i;
171
172 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
173 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i])) {
174 *acpi_interfaces_supported[i] = '\0';
175 return AE_OK;
176 }
177 }
178 return AE_NOT_FOUND;
179}
180
181/*******************************************************************************
182 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 * FUNCTION: acpi_ut_evaluate_object
184 *
185 * PARAMETERS: prefix_node - Starting node
186 * Path - Path to object from starting node
187 * expected_return_types - Bitmap of allowed return types
188 * return_desc - Where a return value is stored
189 *
190 * RETURN: Status
191 *
192 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
193 * return object. Common code that simplifies accessing objects
194 * that have required return objects of fixed types.
195 *
196 * NOTE: Internal function, no parameter validation
197 *
198 ******************************************************************************/
199
200acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400201acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
202 char *path,
203 u32 expected_return_btypes,
204 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
Bob Moore41195322006-05-26 16:36:00 -0400206 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -0400207 acpi_status status;
208 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Mooreb229cf92006-04-21 17:15:00 -0400210 ACPI_FUNCTION_TRACE(ut_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Bob Moore41195322006-05-26 16:36:00 -0400212 /* Allocate the evaluation information block */
213
214 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
215 if (!info) {
216 return_ACPI_STATUS(AE_NO_MEMORY);
217 }
218
219 info->prefix_node = prefix_node;
220 info->pathname = path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* Evaluate the object/method */
223
Bob Moore41195322006-05-26 16:36:00 -0400224 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400225 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400227 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
228 "[%4.4s.%s] was not found\n",
229 acpi_ut_get_node_name(prefix_node),
230 path));
231 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500232 ACPI_ERROR_METHOD("Method execution failed",
233 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
Bob Moore41195322006-05-26 16:36:00 -0400236 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238
239 /* Did we get a return object? */
240
Bob Moore41195322006-05-26 16:36:00 -0400241 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (expected_return_btypes) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500243 ACPI_ERROR_METHOD("No object was returned from",
244 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Bob Moore41195322006-05-26 16:36:00 -0400246 status = AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248
Bob Moore41195322006-05-26 16:36:00 -0400249 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251
252 /* Map the return object type to the bitmapped type */
253
Bob Moore41195322006-05-26 16:36:00 -0400254 switch (ACPI_GET_OBJECT_TYPE(info->return_object)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 case ACPI_TYPE_INTEGER:
256 return_btype = ACPI_BTYPE_INTEGER;
257 break;
258
259 case ACPI_TYPE_BUFFER:
260 return_btype = ACPI_BTYPE_BUFFER;
261 break;
262
263 case ACPI_TYPE_STRING:
264 return_btype = ACPI_BTYPE_STRING;
265 break;
266
267 case ACPI_TYPE_PACKAGE:
268 return_btype = ACPI_BTYPE_PACKAGE;
269 break;
270
271 default:
272 return_btype = 0;
273 break;
274 }
275
Len Brown4be44fc2005-08-05 00:44:28 -0400276 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /*
278 * We received a return object, but one was not expected. This can
279 * happen frequently if the "implicit return" feature is enabled.
280 * Just delete the return object and return AE_OK.
281 */
Bob Moore41195322006-05-26 16:36:00 -0400282 acpi_ut_remove_reference(info->return_object);
283 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 }
285
286 /* Is the return object one of the expected types? */
287
288 if (!(expected_return_btypes & return_btype)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500289 ACPI_ERROR_METHOD("Return object type is incorrect",
290 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
Bob Mooreb8e4d892006-01-27 16:43:00 -0500292 ACPI_ERROR((AE_INFO,
293 "Type returned from %s was incorrect: %s, expected Btypes: %X",
294 path,
Bob Moore41195322006-05-26 16:36:00 -0400295 acpi_ut_get_object_type_name(info->return_object),
Bob Mooreb8e4d892006-01-27 16:43:00 -0500296 expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
298 /* On error exit, we must delete the return object */
299
Bob Moore41195322006-05-26 16:36:00 -0400300 acpi_ut_remove_reference(info->return_object);
301 status = AE_TYPE;
302 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
305 /* Object type is OK, return it */
306
Bob Moore41195322006-05-26 16:36:00 -0400307 *return_desc = info->return_object;
308
309 cleanup:
310 ACPI_FREE(info);
311 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/*******************************************************************************
315 *
316 * FUNCTION: acpi_ut_evaluate_numeric_object
317 *
Robert Moore44f6c012005-04-18 22:49:35 -0400318 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 * device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400320 * Address - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 *
322 * RETURN: Status
323 *
324 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
325 * and stores result in *Address.
326 *
327 * NOTE: Internal function, no parameter validation
328 *
329 ******************************************************************************/
330
331acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400332acpi_ut_evaluate_numeric_object(char *object_name,
333 struct acpi_namespace_node *device_node,
334 acpi_integer * address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Len Brown4be44fc2005-08-05 00:44:28 -0400336 union acpi_operand_object *obj_desc;
337 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Bob Mooreb229cf92006-04-21 17:15:00 -0400339 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Len Brown4be44fc2005-08-05 00:44:28 -0400341 status = acpi_ut_evaluate_object(device_node, object_name,
342 ACPI_BTYPE_INTEGER, &obj_desc);
343 if (ACPI_FAILURE(status)) {
344 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
347 /* Get the returned Integer */
348
349 *address = obj_desc->integer.value;
350
351 /* On exit, we must delete the return object */
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 acpi_ut_remove_reference(obj_desc);
354 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*******************************************************************************
358 *
359 * FUNCTION: acpi_ut_copy_id_string
360 *
361 * PARAMETERS: Destination - Where to copy the string
362 * Source - Source string
363 * max_length - Length of the destination buffer
364 *
365 * RETURN: None
366 *
367 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
368 * Performs removal of a leading asterisk if present -- workaround
369 * for a known issue on a bunch of machines.
370 *
371 ******************************************************************************/
372
373static void
Len Brown4be44fc2005-08-05 00:44:28 -0400374acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 /*
378 * Workaround for ID strings that have a leading asterisk. This construct
379 * is not allowed by the ACPI specification (ID strings must be
380 * alphanumeric), but enough existing machines have this embedded in their
381 * ID strings that the following code is useful.
382 */
383 if (*source == '*') {
384 source++;
385 }
386
387 /* Do the actual copy */
388
Len Brown4be44fc2005-08-05 00:44:28 -0400389 ACPI_STRNCPY(destination, source, max_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390}
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392/*******************************************************************************
393 *
394 * FUNCTION: acpi_ut_execute_HID
395 *
396 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400397 * Hid - Where the HID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 *
399 * RETURN: Status
400 *
401 * DESCRIPTION: Executes the _HID control method that returns the hardware
402 * ID of the device.
403 *
404 * NOTE: Internal function, no parameter validation
405 *
406 ******************************************************************************/
407
408acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400409acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200410 struct acpica_device_id *hid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Len Brown4be44fc2005-08-05 00:44:28 -0400412 union acpi_operand_object *obj_desc;
413 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Bob Mooreb229cf92006-04-21 17:15:00 -0400415 ACPI_FUNCTION_TRACE(ut_execute_HID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
418 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
419 &obj_desc);
420 if (ACPI_FAILURE(status)) {
421 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 }
423
Len Brown4be44fc2005-08-05 00:44:28 -0400424 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* Convert the Numeric HID to string */
427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
429 hid->value);
430 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /* Copy the String HID from the returned object */
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
434 sizeof(hid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 }
436
437 /* On exit, we must delete the return object */
438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 acpi_ut_remove_reference(obj_desc);
440 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441}
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443/*******************************************************************************
444 *
445 * FUNCTION: acpi_ut_translate_one_cid
446 *
447 * PARAMETERS: obj_desc - _CID object, must be integer or string
448 * one_cid - Where the CID string is returned
449 *
450 * RETURN: Status
451 *
452 * DESCRIPTION: Return a numeric or string _CID value as a string.
453 * (Compatible ID)
454 *
455 * NOTE: Assumes a maximum _CID string length of
456 * ACPI_MAX_CID_LENGTH.
457 *
458 ******************************************************************************/
459
460static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400461acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
462 struct acpi_compatible_id *one_cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
464
Len Brown4be44fc2005-08-05 00:44:28 -0400465 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 case ACPI_TYPE_INTEGER:
467
468 /* Convert the Numeric CID to string */
469
Len Brown4be44fc2005-08-05 00:44:28 -0400470 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
471 one_cid->value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return (AE_OK);
473
474 case ACPI_TYPE_STRING:
475
476 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
477 return (AE_AML_STRING_LIMIT);
478 }
479
480 /* Copy the String CID from the returned object */
481
Len Brown4be44fc2005-08-05 00:44:28 -0400482 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
483 ACPI_MAX_CID_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 return (AE_OK);
485
486 default:
487
488 return (AE_TYPE);
489 }
490}
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492/*******************************************************************************
493 *
494 * FUNCTION: acpi_ut_execute_CID
495 *
496 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400497 * return_cid_list - Where the CID list is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 *
499 * RETURN: Status
500 *
501 * DESCRIPTION: Executes the _CID control method that returns one or more
502 * compatible hardware IDs for the device.
503 *
504 * NOTE: Internal function, no parameter validation
505 *
506 ******************************************************************************/
507
508acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400509acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
510 struct acpi_compatible_id_list ** return_cid_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
Len Brown4be44fc2005-08-05 00:44:28 -0400512 union acpi_operand_object *obj_desc;
513 acpi_status status;
514 u32 count;
515 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 struct acpi_compatible_id_list *cid_list;
Bob Moore67a119f2008-06-10 13:42:13 +0800517 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518
Bob Mooreb229cf92006-04-21 17:15:00 -0400519 ACPI_FUNCTION_TRACE(ut_execute_CID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521 /* Evaluate the _CID method for this device */
522
Len Brown4be44fc2005-08-05 00:44:28 -0400523 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
524 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
525 | ACPI_BTYPE_PACKAGE, &obj_desc);
526 if (ACPI_FAILURE(status)) {
527 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 }
529
530 /* Get the number of _CIDs returned */
531
532 count = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400533 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 count = obj_desc->package.count;
535 }
536
537 /* Allocate a worst-case buffer for the _CIDs */
538
Len Brown4be44fc2005-08-05 00:44:28 -0400539 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
540 sizeof(struct acpi_compatible_id_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Bob Moore83135242006-10-03 00:00:00 -0400542 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 if (!cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400544 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 }
546
547 /* Init CID list */
548
549 cid_list->count = count;
550 cid_list->size = size;
551
552 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400553 * A _CID can return either a single compatible ID or a package of
554 * compatible IDs. Each compatible ID can be one of the following:
555 * 1) Integer (32 bit compressed EISA ID) or
556 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 */
558
559 /* The _CID object can be either a single CID or a package (list) of CIDs */
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 /* Translate each package element */
564
565 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400566 status =
567 acpi_ut_translate_one_cid(obj_desc->package.
568 elements[i],
569 &cid_list->id[i]);
570 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 break;
572 }
573 }
Len Brown4be44fc2005-08-05 00:44:28 -0400574 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 /* Only one CID, translate to a string */
576
Len Brown4be44fc2005-08-05 00:44:28 -0400577 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579
580 /* Cleanup on error */
581
Len Brown4be44fc2005-08-05 00:44:28 -0400582 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400583 ACPI_FREE(cid_list);
Len Brown4be44fc2005-08-05 00:44:28 -0400584 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 *return_cid_list = cid_list;
586 }
587
588 /* On exit, we must delete the _CID return object */
589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 acpi_ut_remove_reference(obj_desc);
591 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594/*******************************************************************************
595 *
596 * FUNCTION: acpi_ut_execute_UID
597 *
598 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400599 * Uid - Where the UID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 *
601 * RETURN: Status
602 *
603 * DESCRIPTION: Executes the _UID control method that returns the hardware
604 * ID of the device.
605 *
606 * NOTE: Internal function, no parameter validation
607 *
608 ******************************************************************************/
609
610acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400611acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200612 struct acpica_device_id *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
Len Brown4be44fc2005-08-05 00:44:28 -0400614 union acpi_operand_object *obj_desc;
615 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Bob Mooreb229cf92006-04-21 17:15:00 -0400617 ACPI_FUNCTION_TRACE(ut_execute_UID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Len Brown4be44fc2005-08-05 00:44:28 -0400619 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
620 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
621 &obj_desc);
622 if (ACPI_FAILURE(status)) {
623 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 /* Convert the Numeric UID to string */
629
Len Brown4be44fc2005-08-05 00:44:28 -0400630 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
631 uid->value);
632 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* Copy the String UID from the returned object */
634
Len Brown4be44fc2005-08-05 00:44:28 -0400635 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
636 sizeof(uid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638
639 /* On exit, we must delete the return object */
640
Len Brown4be44fc2005-08-05 00:44:28 -0400641 acpi_ut_remove_reference(obj_desc);
642 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643}
644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645/*******************************************************************************
646 *
647 * FUNCTION: acpi_ut_execute_STA
648 *
649 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400650 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 *
652 * RETURN: Status
653 *
654 * DESCRIPTION: Executes _STA for selected device and stores results in
655 * *Flags.
656 *
657 * NOTE: Internal function, no parameter validation
658 *
659 ******************************************************************************/
660
661acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400662acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Len Brown4be44fc2005-08-05 00:44:28 -0400664 union acpi_operand_object *obj_desc;
665 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Bob Mooreb229cf92006-04-21 17:15:00 -0400667 ACPI_FUNCTION_TRACE(ut_execute_STA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
670 ACPI_BTYPE_INTEGER, &obj_desc);
671 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 if (AE_NOT_FOUND == status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400673 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
674 "_STA on %4.4s was not found, assuming device is present\n",
675 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Bob Mooredefba1d2005-12-16 17:05:00 -0500677 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 status = AE_OK;
679 }
680
Len Brown4be44fc2005-08-05 00:44:28 -0400681 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
683
684 /* Extract the status flags */
685
686 *flags = (u32) obj_desc->integer.value;
687
688 /* On exit, we must delete the return object */
689
Len Brown4be44fc2005-08-05 00:44:28 -0400690 acpi_ut_remove_reference(obj_desc);
691 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694/*******************************************************************************
695 *
696 * FUNCTION: acpi_ut_execute_Sxds
697 *
698 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400699 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 *
701 * RETURN: Status
702 *
703 * DESCRIPTION: Executes _STA for selected device and stores results in
704 * *Flags.
705 *
706 * NOTE: Internal function, no parameter validation
707 *
708 ******************************************************************************/
709
710acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400711acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
Len Brown4be44fc2005-08-05 00:44:28 -0400713 union acpi_operand_object *obj_desc;
714 acpi_status status;
715 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Bob Mooreb229cf92006-04-21 17:15:00 -0400717 ACPI_FUNCTION_TRACE(ut_execute_sxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
719 for (i = 0; i < 4; i++) {
720 highest[i] = 0xFF;
Len Brown4be44fc2005-08-05 00:44:28 -0400721 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500722 ACPI_CAST_PTR(char,
723 acpi_gbl_highest_dstate_names
724 [i]),
725 ACPI_BTYPE_INTEGER, &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400726 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 if (status != AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400728 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
729 "%s on Device %4.4s, %s\n",
Bob Mooredefba1d2005-12-16 17:05:00 -0500730 ACPI_CAST_PTR(char,
731 acpi_gbl_highest_dstate_names
732 [i]),
Len Brown4be44fc2005-08-05 00:44:28 -0400733 acpi_ut_get_node_name
734 (device_node),
735 acpi_format_exception
736 (status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
Len Brown4be44fc2005-08-05 00:44:28 -0400740 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 /* Extract the Dstate value */
742
743 highest[i] = (u8) obj_desc->integer.value;
744
745 /* Delete the return object */
746
Len Brown4be44fc2005-08-05 00:44:28 -0400747 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
749 }
750
Len Brown4be44fc2005-08-05 00:44:28 -0400751 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752}