blob: 352747e49c7a623930fd17491533a436394099ad [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>
45#include <acpi/acnamesp.h>
46#include <acpi/acinterp.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("uteval")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040052static void
Len Brown4be44fc2005-08-05 00:44:28 -040053acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length);
Robert Moore44f6c012005-04-18 22:49:35 -040054
55static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
57 struct acpi_compatible_id *one_cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Bob Mooreb229cf92006-04-21 17:15:00 -040059/*
60 * Strings supported by the _OSI predefined (internal) method.
61 */
Len Brownae00d812007-05-29 18:43:33 -040062static char *acpi_interfaces_supported[] = {
Bob Mooreb229cf92006-04-21 17:15:00 -040063 /* Operating System Vendor Strings */
64
Bob Moore3c6394c2007-03-26 22:10:34 -040065 "Windows 2000", /* Windows 2000 */
66 "Windows 2001", /* Windows XP */
67 "Windows 2001 SP1", /* Windows XP SP1 */
68 "Windows 2001 SP2", /* Windows XP SP2 */
69 "Windows 2001.1", /* Windows Server 2003 */
70 "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */
71 "Windows 2006", /* Windows Vista - Added 03/2006 */
Bob Mooreb229cf92006-04-21 17:15:00 -040072
73 /* Feature Group Strings */
74
75 "Extended Address Space Descriptor"
76 /*
77 * All "optional" feature group strings (features that are implemented
78 * by the host) should be implemented in the host version of
79 * acpi_os_validate_interface and should not be added here.
80 */
81};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083/*******************************************************************************
84 *
85 * FUNCTION: acpi_ut_osi_implementation
86 *
87 * PARAMETERS: walk_state - Current walk state
88 *
89 * RETURN: Status
90 *
Bob Mooreb229cf92006-04-21 17:15:00 -040091 * DESCRIPTION: Implementation of the _OSI predefined control method
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 *
93 ******************************************************************************/
94
Len Brown4be44fc2005-08-05 00:44:28 -040095acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070096{
Bob Mooreb229cf92006-04-21 17:15:00 -040097 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -040098 union acpi_operand_object *string_desc;
99 union acpi_operand_object *return_desc;
Bob Moore67a119f2008-06-10 13:42:13 +0800100 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Bob Mooreb229cf92006-04-21 17:15:00 -0400102 ACPI_FUNCTION_TRACE(ut_osi_implementation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 /* Validate the string input argument */
105
106 string_desc = walk_state->arguments[0].object;
107 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400108 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110
Bob Mooreb229cf92006-04-21 17:15:00 -0400111 /* Create a return object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Len Brown4be44fc2005-08-05 00:44:28 -0400113 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 if (!return_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400115 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 }
117
Bob Mooreb229cf92006-04-21 17:15:00 -0400118 /* Default return value is SUPPORTED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Bob Mooreb229cf92006-04-21 17:15:00 -0400120 return_desc->integer.value = ACPI_UINT32_MAX;
121 walk_state->return_desc = return_desc;
Bob Moore52fc0b02006-10-02 00:00:00 -0400122
Bob Mooreb229cf92006-04-21 17:15:00 -0400123 /* Compare input string to static table of supported interfaces */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Bob Mooreb229cf92006-04-21 17:15:00 -0400125 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
126 if (!ACPI_STRCMP
127 (string_desc->string.pointer,
128 acpi_interfaces_supported[i])) {
129
130 /* The interface is supported */
131
132 return_ACPI_STATUS(AE_CTRL_TERMINATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 }
134 }
135
Bob Mooreb229cf92006-04-21 17:15:00 -0400136 /*
137 * Did not match the string in the static table, call the host OSL to
138 * check for a match with one of the optional strings (such as
139 * "Module Device", "3.0 Thermal Model", etc.)
140 */
141 status = acpi_os_validate_interface(string_desc->string.pointer);
142 if (ACPI_SUCCESS(status)) {
143
144 /* The interface is supported */
145
146 return_ACPI_STATUS(AE_CTRL_TERMINATE);
147 }
148
149 /* The interface is not supported */
150
151 return_desc->integer.value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400152 return_ACPI_STATUS(AE_CTRL_TERMINATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153}
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155/*******************************************************************************
156 *
Len Brownae00d812007-05-29 18:43:33 -0400157 * FUNCTION: acpi_osi_invalidate
158 *
159 * PARAMETERS: interface_string
160 *
161 * RETURN: Status
162 *
163 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
164 *
165 ******************************************************************************/
166
167acpi_status acpi_osi_invalidate(char *interface)
168{
169 int i;
170
171 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
172 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i])) {
173 *acpi_interfaces_supported[i] = '\0';
174 return AE_OK;
175 }
176 }
177 return AE_NOT_FOUND;
178}
179
180/*******************************************************************************
181 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 * FUNCTION: acpi_ut_evaluate_object
183 *
184 * PARAMETERS: prefix_node - Starting node
185 * Path - Path to object from starting node
186 * expected_return_types - Bitmap of allowed return types
187 * return_desc - Where a return value is stored
188 *
189 * RETURN: Status
190 *
191 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
192 * return object. Common code that simplifies accessing objects
193 * that have required return objects of fixed types.
194 *
195 * NOTE: Internal function, no parameter validation
196 *
197 ******************************************************************************/
198
199acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400200acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
201 char *path,
202 u32 expected_return_btypes,
203 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Bob Moore41195322006-05-26 16:36:00 -0400205 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -0400206 acpi_status status;
207 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Bob Mooreb229cf92006-04-21 17:15:00 -0400209 ACPI_FUNCTION_TRACE(ut_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Bob Moore41195322006-05-26 16:36:00 -0400211 /* Allocate the evaluation information block */
212
213 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
214 if (!info) {
215 return_ACPI_STATUS(AE_NO_MEMORY);
216 }
217
218 info->prefix_node = prefix_node;
219 info->pathname = path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 /* Evaluate the object/method */
222
Bob Moore41195322006-05-26 16:36:00 -0400223 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400224 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400226 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
227 "[%4.4s.%s] was not found\n",
228 acpi_ut_get_node_name(prefix_node),
229 path));
230 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500231 ACPI_ERROR_METHOD("Method execution failed",
232 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
234
Bob Moore41195322006-05-26 16:36:00 -0400235 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237
238 /* Did we get a return object? */
239
Bob Moore41195322006-05-26 16:36:00 -0400240 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (expected_return_btypes) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500242 ACPI_ERROR_METHOD("No object was returned from",
243 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Bob Moore41195322006-05-26 16:36:00 -0400245 status = AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 }
247
Bob Moore41195322006-05-26 16:36:00 -0400248 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 }
250
251 /* Map the return object type to the bitmapped type */
252
Bob Moore41195322006-05-26 16:36:00 -0400253 switch (ACPI_GET_OBJECT_TYPE(info->return_object)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 case ACPI_TYPE_INTEGER:
255 return_btype = ACPI_BTYPE_INTEGER;
256 break;
257
258 case ACPI_TYPE_BUFFER:
259 return_btype = ACPI_BTYPE_BUFFER;
260 break;
261
262 case ACPI_TYPE_STRING:
263 return_btype = ACPI_BTYPE_STRING;
264 break;
265
266 case ACPI_TYPE_PACKAGE:
267 return_btype = ACPI_BTYPE_PACKAGE;
268 break;
269
270 default:
271 return_btype = 0;
272 break;
273 }
274
Len Brown4be44fc2005-08-05 00:44:28 -0400275 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /*
277 * We received a return object, but one was not expected. This can
278 * happen frequently if the "implicit return" feature is enabled.
279 * Just delete the return object and return AE_OK.
280 */
Bob Moore41195322006-05-26 16:36:00 -0400281 acpi_ut_remove_reference(info->return_object);
282 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 }
284
285 /* Is the return object one of the expected types? */
286
287 if (!(expected_return_btypes & return_btype)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500288 ACPI_ERROR_METHOD("Return object type is incorrect",
289 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Bob Mooreb8e4d892006-01-27 16:43:00 -0500291 ACPI_ERROR((AE_INFO,
292 "Type returned from %s was incorrect: %s, expected Btypes: %X",
293 path,
Bob Moore41195322006-05-26 16:36:00 -0400294 acpi_ut_get_object_type_name(info->return_object),
Bob Mooreb8e4d892006-01-27 16:43:00 -0500295 expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 /* On error exit, we must delete the return object */
298
Bob Moore41195322006-05-26 16:36:00 -0400299 acpi_ut_remove_reference(info->return_object);
300 status = AE_TYPE;
301 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
304 /* Object type is OK, return it */
305
Bob Moore41195322006-05-26 16:36:00 -0400306 *return_desc = info->return_object;
307
308 cleanup:
309 ACPI_FREE(info);
310 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/*******************************************************************************
314 *
315 * FUNCTION: acpi_ut_evaluate_numeric_object
316 *
Robert Moore44f6c012005-04-18 22:49:35 -0400317 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 * device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400319 * Address - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 *
321 * RETURN: Status
322 *
323 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
324 * and stores result in *Address.
325 *
326 * NOTE: Internal function, no parameter validation
327 *
328 ******************************************************************************/
329
330acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400331acpi_ut_evaluate_numeric_object(char *object_name,
332 struct acpi_namespace_node *device_node,
333 acpi_integer * address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Len Brown4be44fc2005-08-05 00:44:28 -0400335 union acpi_operand_object *obj_desc;
336 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Bob Mooreb229cf92006-04-21 17:15:00 -0400338 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Len Brown4be44fc2005-08-05 00:44:28 -0400340 status = acpi_ut_evaluate_object(device_node, object_name,
341 ACPI_BTYPE_INTEGER, &obj_desc);
342 if (ACPI_FAILURE(status)) {
343 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345
346 /* Get the returned Integer */
347
348 *address = obj_desc->integer.value;
349
350 /* On exit, we must delete the return object */
351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 acpi_ut_remove_reference(obj_desc);
353 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356/*******************************************************************************
357 *
358 * FUNCTION: acpi_ut_copy_id_string
359 *
360 * PARAMETERS: Destination - Where to copy the string
361 * Source - Source string
362 * max_length - Length of the destination buffer
363 *
364 * RETURN: None
365 *
366 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
367 * Performs removal of a leading asterisk if present -- workaround
368 * for a known issue on a bunch of machines.
369 *
370 ******************************************************************************/
371
372static void
Len Brown4be44fc2005-08-05 00:44:28 -0400373acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /*
377 * Workaround for ID strings that have a leading asterisk. This construct
378 * is not allowed by the ACPI specification (ID strings must be
379 * alphanumeric), but enough existing machines have this embedded in their
380 * ID strings that the following code is useful.
381 */
382 if (*source == '*') {
383 source++;
384 }
385
386 /* Do the actual copy */
387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 ACPI_STRNCPY(destination, source, max_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391/*******************************************************************************
392 *
393 * FUNCTION: acpi_ut_execute_HID
394 *
395 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400396 * Hid - Where the HID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 *
398 * RETURN: Status
399 *
400 * DESCRIPTION: Executes the _HID control method that returns the hardware
401 * ID of the device.
402 *
403 * NOTE: Internal function, no parameter validation
404 *
405 ******************************************************************************/
406
407acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400408acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200409 struct acpica_device_id *hid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Len Brown4be44fc2005-08-05 00:44:28 -0400411 union acpi_operand_object *obj_desc;
412 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Bob Mooreb229cf92006-04-21 17:15:00 -0400414 ACPI_FUNCTION_TRACE(ut_execute_HID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Len Brown4be44fc2005-08-05 00:44:28 -0400416 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
417 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
418 &obj_desc);
419 if (ACPI_FAILURE(status)) {
420 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 }
422
Len Brown4be44fc2005-08-05 00:44:28 -0400423 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 /* Convert the Numeric HID to string */
426
Len Brown4be44fc2005-08-05 00:44:28 -0400427 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
428 hid->value);
429 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 /* Copy the String HID from the returned object */
431
Len Brown4be44fc2005-08-05 00:44:28 -0400432 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
433 sizeof(hid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 }
435
436 /* On exit, we must delete the return object */
437
Len Brown4be44fc2005-08-05 00:44:28 -0400438 acpi_ut_remove_reference(obj_desc);
439 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442/*******************************************************************************
443 *
444 * FUNCTION: acpi_ut_translate_one_cid
445 *
446 * PARAMETERS: obj_desc - _CID object, must be integer or string
447 * one_cid - Where the CID string is returned
448 *
449 * RETURN: Status
450 *
451 * DESCRIPTION: Return a numeric or string _CID value as a string.
452 * (Compatible ID)
453 *
454 * NOTE: Assumes a maximum _CID string length of
455 * ACPI_MAX_CID_LENGTH.
456 *
457 ******************************************************************************/
458
459static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400460acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
461 struct acpi_compatible_id *one_cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 case ACPI_TYPE_INTEGER:
466
467 /* Convert the Numeric CID to string */
468
Len Brown4be44fc2005-08-05 00:44:28 -0400469 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
470 one_cid->value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 return (AE_OK);
472
473 case ACPI_TYPE_STRING:
474
475 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
476 return (AE_AML_STRING_LIMIT);
477 }
478
479 /* Copy the String CID from the returned object */
480
Len Brown4be44fc2005-08-05 00:44:28 -0400481 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
482 ACPI_MAX_CID_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return (AE_OK);
484
485 default:
486
487 return (AE_TYPE);
488 }
489}
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491/*******************************************************************************
492 *
493 * FUNCTION: acpi_ut_execute_CID
494 *
495 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400496 * return_cid_list - Where the CID list is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 *
498 * RETURN: Status
499 *
500 * DESCRIPTION: Executes the _CID control method that returns one or more
501 * compatible hardware IDs for the device.
502 *
503 * NOTE: Internal function, no parameter validation
504 *
505 ******************************************************************************/
506
507acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400508acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
509 struct acpi_compatible_id_list ** return_cid_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Len Brown4be44fc2005-08-05 00:44:28 -0400511 union acpi_operand_object *obj_desc;
512 acpi_status status;
513 u32 count;
514 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 struct acpi_compatible_id_list *cid_list;
Bob Moore67a119f2008-06-10 13:42:13 +0800516 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Bob Mooreb229cf92006-04-21 17:15:00 -0400518 ACPI_FUNCTION_TRACE(ut_execute_CID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 /* Evaluate the _CID method for this device */
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
523 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
524 | ACPI_BTYPE_PACKAGE, &obj_desc);
525 if (ACPI_FAILURE(status)) {
526 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 }
528
529 /* Get the number of _CIDs returned */
530
531 count = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400532 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 count = obj_desc->package.count;
534 }
535
536 /* Allocate a worst-case buffer for the _CIDs */
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
539 sizeof(struct acpi_compatible_id_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Bob Moore83135242006-10-03 00:00:00 -0400541 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 if (!cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400543 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 }
545
546 /* Init CID list */
547
548 cid_list->count = count;
549 cid_list->size = size;
550
551 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400552 * A _CID can return either a single compatible ID or a package of
553 * compatible IDs. Each compatible ID can be one of the following:
554 * 1) Integer (32 bit compressed EISA ID) or
555 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 */
557
558 /* The _CID object can be either a single CID or a package (list) of CIDs */
559
Len Brown4be44fc2005-08-05 00:44:28 -0400560 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /* Translate each package element */
563
564 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400565 status =
566 acpi_ut_translate_one_cid(obj_desc->package.
567 elements[i],
568 &cid_list->id[i]);
569 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 break;
571 }
572 }
Len Brown4be44fc2005-08-05 00:44:28 -0400573 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 /* Only one CID, translate to a string */
575
Len Brown4be44fc2005-08-05 00:44:28 -0400576 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578
579 /* Cleanup on error */
580
Len Brown4be44fc2005-08-05 00:44:28 -0400581 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400582 ACPI_FREE(cid_list);
Len Brown4be44fc2005-08-05 00:44:28 -0400583 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 *return_cid_list = cid_list;
585 }
586
587 /* On exit, we must delete the _CID return object */
588
Len Brown4be44fc2005-08-05 00:44:28 -0400589 acpi_ut_remove_reference(obj_desc);
590 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591}
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593/*******************************************************************************
594 *
595 * FUNCTION: acpi_ut_execute_UID
596 *
597 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400598 * Uid - Where the UID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 *
600 * RETURN: Status
601 *
602 * DESCRIPTION: Executes the _UID control method that returns the hardware
603 * ID of the device.
604 *
605 * NOTE: Internal function, no parameter validation
606 *
607 ******************************************************************************/
608
609acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400610acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200611 struct acpica_device_id *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612{
Len Brown4be44fc2005-08-05 00:44:28 -0400613 union acpi_operand_object *obj_desc;
614 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Bob Mooreb229cf92006-04-21 17:15:00 -0400616 ACPI_FUNCTION_TRACE(ut_execute_UID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Len Brown4be44fc2005-08-05 00:44:28 -0400618 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
619 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
620 &obj_desc);
621 if (ACPI_FAILURE(status)) {
622 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 }
624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 /* Convert the Numeric UID to string */
628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
630 uid->value);
631 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 /* Copy the String UID from the returned object */
633
Len Brown4be44fc2005-08-05 00:44:28 -0400634 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
635 sizeof(uid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637
638 /* On exit, we must delete the return object */
639
Len Brown4be44fc2005-08-05 00:44:28 -0400640 acpi_ut_remove_reference(obj_desc);
641 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642}
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644/*******************************************************************************
645 *
646 * FUNCTION: acpi_ut_execute_STA
647 *
648 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400649 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 *
651 * RETURN: Status
652 *
653 * DESCRIPTION: Executes _STA for selected device and stores results in
654 * *Flags.
655 *
656 * NOTE: Internal function, no parameter validation
657 *
658 ******************************************************************************/
659
660acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400661acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662{
Len Brown4be44fc2005-08-05 00:44:28 -0400663 union acpi_operand_object *obj_desc;
664 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Bob Mooreb229cf92006-04-21 17:15:00 -0400666 ACPI_FUNCTION_TRACE(ut_execute_STA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Len Brown4be44fc2005-08-05 00:44:28 -0400668 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
669 ACPI_BTYPE_INTEGER, &obj_desc);
670 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 if (AE_NOT_FOUND == status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400672 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
673 "_STA on %4.4s was not found, assuming device is present\n",
674 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Bob Mooredefba1d2005-12-16 17:05:00 -0500676 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 status = AE_OK;
678 }
679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682
683 /* Extract the status flags */
684
685 *flags = (u32) obj_desc->integer.value;
686
687 /* On exit, we must delete the return object */
688
Len Brown4be44fc2005-08-05 00:44:28 -0400689 acpi_ut_remove_reference(obj_desc);
690 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693/*******************************************************************************
694 *
695 * FUNCTION: acpi_ut_execute_Sxds
696 *
697 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400698 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 *
700 * RETURN: Status
701 *
702 * DESCRIPTION: Executes _STA for selected device and stores results in
703 * *Flags.
704 *
705 * NOTE: Internal function, no parameter validation
706 *
707 ******************************************************************************/
708
709acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400710acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Len Brown4be44fc2005-08-05 00:44:28 -0400712 union acpi_operand_object *obj_desc;
713 acpi_status status;
714 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Bob Mooreb229cf92006-04-21 17:15:00 -0400716 ACPI_FUNCTION_TRACE(ut_execute_sxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 for (i = 0; i < 4; i++) {
719 highest[i] = 0xFF;
Len Brown4be44fc2005-08-05 00:44:28 -0400720 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500721 ACPI_CAST_PTR(char,
722 acpi_gbl_highest_dstate_names
723 [i]),
724 ACPI_BTYPE_INTEGER, &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400725 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 if (status != AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400727 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
728 "%s on Device %4.4s, %s\n",
Bob Mooredefba1d2005-12-16 17:05:00 -0500729 ACPI_CAST_PTR(char,
730 acpi_gbl_highest_dstate_names
731 [i]),
Len Brown4be44fc2005-08-05 00:44:28 -0400732 acpi_ut_get_node_name
733 (device_node),
734 acpi_format_exception
735 (status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
Len Brown4be44fc2005-08-05 00:44:28 -0400737 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
Len Brown4be44fc2005-08-05 00:44:28 -0400739 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 /* Extract the Dstate value */
741
742 highest[i] = (u8) obj_desc->integer.value;
743
744 /* Delete the return object */
745
Len Brown4be44fc2005-08-05 00:44:28 -0400746 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
748 }
749
Len Brown4be44fc2005-08-05 00:44:28 -0400750 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751}