blob: 99bfbd23258b772184ce7e62cd6327c6b4bea360 [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
Len Brown3e0676a2009-02-03 18:04:39 -0500119 /* Default return value is 0, NOT-SUPPORTED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Len Brown3e0676a2009-02-03 18:04:39 -0500121 return_desc->integer.value = 0;
Bob Mooreb229cf92006-04-21 17:15:00 -0400122 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])) {
Len Brown3e0676a2009-02-03 18:04:39 -0500130 return_desc->integer.value = ACPI_UINT32_MAX;
131 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 }
133 }
134
Bob Mooreb229cf92006-04-21 17:15:00 -0400135 /*
136 * Did not match the string in the static table, call the host OSL to
137 * check for a match with one of the optional strings (such as
138 * "Module Device", "3.0 Thermal Model", etc.)
139 */
140 status = acpi_os_validate_interface(string_desc->string.pointer);
141 if (ACPI_SUCCESS(status)) {
Len Brown3e0676a2009-02-03 18:04:39 -0500142 return_desc->integer.value = ACPI_UINT32_MAX;
Bob Mooreb229cf92006-04-21 17:15:00 -0400143 }
144
Len Brown3e0676a2009-02-03 18:04:39 -0500145done:
146 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO, "ACPI: BIOS _OSI(%s) %ssupported\n",
147 string_desc->string.pointer,
148 return_desc->integer.value == 0 ? "not-" : ""));
Bob Mooreb229cf92006-04-21 17:15:00 -0400149
Bob Moorea8fadc92008-11-13 09:45:35 +0800150 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/*******************************************************************************
154 *
Len Brownae00d812007-05-29 18:43:33 -0400155 * FUNCTION: acpi_osi_invalidate
156 *
157 * PARAMETERS: interface_string
158 *
159 * RETURN: Status
160 *
161 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
162 *
163 ******************************************************************************/
164
165acpi_status acpi_osi_invalidate(char *interface)
166{
167 int i;
168
169 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
170 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i])) {
171 *acpi_interfaces_supported[i] = '\0';
172 return AE_OK;
173 }
174 }
175 return AE_NOT_FOUND;
176}
177
178/*******************************************************************************
179 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 * FUNCTION: acpi_ut_evaluate_object
181 *
182 * PARAMETERS: prefix_node - Starting node
183 * Path - Path to object from starting node
184 * expected_return_types - Bitmap of allowed return types
185 * return_desc - Where a return value is stored
186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
190 * return object. Common code that simplifies accessing objects
191 * that have required return objects of fixed types.
192 *
193 * NOTE: Internal function, no parameter validation
194 *
195 ******************************************************************************/
196
197acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400198acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
199 char *path,
200 u32 expected_return_btypes,
201 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202{
Bob Moore41195322006-05-26 16:36:00 -0400203 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -0400204 acpi_status status;
205 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Bob Mooreb229cf92006-04-21 17:15:00 -0400207 ACPI_FUNCTION_TRACE(ut_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Bob Moore41195322006-05-26 16:36:00 -0400209 /* Allocate the evaluation information block */
210
211 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
212 if (!info) {
213 return_ACPI_STATUS(AE_NO_MEMORY);
214 }
215
216 info->prefix_node = prefix_node;
217 info->pathname = path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 /* Evaluate the object/method */
220
Bob Moore41195322006-05-26 16:36:00 -0400221 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400222 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400224 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
225 "[%4.4s.%s] was not found\n",
226 acpi_ut_get_node_name(prefix_node),
227 path));
228 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500229 ACPI_ERROR_METHOD("Method execution failed",
230 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232
Bob Moore41195322006-05-26 16:36:00 -0400233 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
236 /* Did we get a return object? */
237
Bob Moore41195322006-05-26 16:36:00 -0400238 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (expected_return_btypes) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500240 ACPI_ERROR_METHOD("No object was returned from",
241 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Bob Moore41195322006-05-26 16:36:00 -0400243 status = AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245
Bob Moore41195322006-05-26 16:36:00 -0400246 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248
249 /* Map the return object type to the bitmapped type */
250
Bob Moore3371c192009-02-18 14:44:03 +0800251 switch ((info->return_object)->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 case ACPI_TYPE_INTEGER:
253 return_btype = ACPI_BTYPE_INTEGER;
254 break;
255
256 case ACPI_TYPE_BUFFER:
257 return_btype = ACPI_BTYPE_BUFFER;
258 break;
259
260 case ACPI_TYPE_STRING:
261 return_btype = ACPI_BTYPE_STRING;
262 break;
263
264 case ACPI_TYPE_PACKAGE:
265 return_btype = ACPI_BTYPE_PACKAGE;
266 break;
267
268 default:
269 return_btype = 0;
270 break;
271 }
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 /*
275 * We received a return object, but one was not expected. This can
276 * happen frequently if the "implicit return" feature is enabled.
277 * Just delete the return object and return AE_OK.
278 */
Bob Moore41195322006-05-26 16:36:00 -0400279 acpi_ut_remove_reference(info->return_object);
280 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
283 /* Is the return object one of the expected types? */
284
285 if (!(expected_return_btypes & return_btype)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500286 ACPI_ERROR_METHOD("Return object type is incorrect",
287 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Bob Mooreb8e4d892006-01-27 16:43:00 -0500289 ACPI_ERROR((AE_INFO,
290 "Type returned from %s was incorrect: %s, expected Btypes: %X",
291 path,
Bob Moore41195322006-05-26 16:36:00 -0400292 acpi_ut_get_object_type_name(info->return_object),
Bob Mooreb8e4d892006-01-27 16:43:00 -0500293 expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 /* On error exit, we must delete the return object */
296
Bob Moore41195322006-05-26 16:36:00 -0400297 acpi_ut_remove_reference(info->return_object);
298 status = AE_TYPE;
299 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
302 /* Object type is OK, return it */
303
Bob Moore41195322006-05-26 16:36:00 -0400304 *return_desc = info->return_object;
305
306 cleanup:
307 ACPI_FREE(info);
308 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311/*******************************************************************************
312 *
313 * FUNCTION: acpi_ut_evaluate_numeric_object
314 *
Robert Moore44f6c012005-04-18 22:49:35 -0400315 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 * device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400317 * Address - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 *
319 * RETURN: Status
320 *
321 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
322 * and stores result in *Address.
323 *
324 * NOTE: Internal function, no parameter validation
325 *
326 ******************************************************************************/
327
328acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400329acpi_ut_evaluate_numeric_object(char *object_name,
330 struct acpi_namespace_node *device_node,
331 acpi_integer * address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Len Brown4be44fc2005-08-05 00:44:28 -0400333 union acpi_operand_object *obj_desc;
334 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Bob Mooreb229cf92006-04-21 17:15:00 -0400336 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Len Brown4be44fc2005-08-05 00:44:28 -0400338 status = acpi_ut_evaluate_object(device_node, object_name,
339 ACPI_BTYPE_INTEGER, &obj_desc);
340 if (ACPI_FAILURE(status)) {
341 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
343
344 /* Get the returned Integer */
345
346 *address = obj_desc->integer.value;
347
348 /* On exit, we must delete the return object */
349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 acpi_ut_remove_reference(obj_desc);
351 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352}
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354/*******************************************************************************
355 *
356 * FUNCTION: acpi_ut_copy_id_string
357 *
358 * PARAMETERS: Destination - Where to copy the string
359 * Source - Source string
360 * max_length - Length of the destination buffer
361 *
362 * RETURN: None
363 *
364 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
365 * Performs removal of a leading asterisk if present -- workaround
366 * for a known issue on a bunch of machines.
367 *
368 ******************************************************************************/
369
370static void
Len Brown4be44fc2005-08-05 00:44:28 -0400371acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 /*
375 * Workaround for ID strings that have a leading asterisk. This construct
376 * is not allowed by the ACPI specification (ID strings must be
377 * alphanumeric), but enough existing machines have this embedded in their
378 * ID strings that the following code is useful.
379 */
380 if (*source == '*') {
381 source++;
382 }
383
384 /* Do the actual copy */
385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 ACPI_STRNCPY(destination, source, max_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387}
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389/*******************************************************************************
390 *
391 * FUNCTION: acpi_ut_execute_HID
392 *
393 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400394 * Hid - Where the HID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 *
396 * RETURN: Status
397 *
398 * DESCRIPTION: Executes the _HID control method that returns the hardware
399 * ID of the device.
400 *
401 * NOTE: Internal function, no parameter validation
402 *
403 ******************************************************************************/
404
405acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400406acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200407 struct acpica_device_id *hid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Len Brown4be44fc2005-08-05 00:44:28 -0400409 union acpi_operand_object *obj_desc;
410 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Bob Mooreb229cf92006-04-21 17:15:00 -0400412 ACPI_FUNCTION_TRACE(ut_execute_HID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Len Brown4be44fc2005-08-05 00:44:28 -0400414 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
415 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
416 &obj_desc);
417 if (ACPI_FAILURE(status)) {
418 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420
Bob Moore3371c192009-02-18 14:44:03 +0800421 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 /* Convert the Numeric HID to string */
424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
426 hid->value);
427 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 /* Copy the String HID from the returned object */
429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
431 sizeof(hid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
434 /* On exit, we must delete the return object */
435
Len Brown4be44fc2005-08-05 00:44:28 -0400436 acpi_ut_remove_reference(obj_desc);
437 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438}
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440/*******************************************************************************
441 *
442 * FUNCTION: acpi_ut_translate_one_cid
443 *
444 * PARAMETERS: obj_desc - _CID object, must be integer or string
445 * one_cid - Where the CID string is returned
446 *
447 * RETURN: Status
448 *
449 * DESCRIPTION: Return a numeric or string _CID value as a string.
450 * (Compatible ID)
451 *
452 * NOTE: Assumes a maximum _CID string length of
453 * ACPI_MAX_CID_LENGTH.
454 *
455 ******************************************************************************/
456
457static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400458acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
459 struct acpi_compatible_id *one_cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
461
Bob Moore3371c192009-02-18 14:44:03 +0800462 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 case ACPI_TYPE_INTEGER:
464
465 /* Convert the Numeric CID to string */
466
Len Brown4be44fc2005-08-05 00:44:28 -0400467 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
468 one_cid->value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return (AE_OK);
470
471 case ACPI_TYPE_STRING:
472
473 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
474 return (AE_AML_STRING_LIMIT);
475 }
476
477 /* Copy the String CID from the returned object */
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
480 ACPI_MAX_CID_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return (AE_OK);
482
483 default:
484
485 return (AE_TYPE);
486 }
487}
488
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489/*******************************************************************************
490 *
491 * FUNCTION: acpi_ut_execute_CID
492 *
493 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400494 * return_cid_list - Where the CID list is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 *
496 * RETURN: Status
497 *
498 * DESCRIPTION: Executes the _CID control method that returns one or more
499 * compatible hardware IDs for the device.
500 *
501 * NOTE: Internal function, no parameter validation
502 *
503 ******************************************************************************/
504
505acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400506acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
507 struct acpi_compatible_id_list ** return_cid_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
Len Brown4be44fc2005-08-05 00:44:28 -0400509 union acpi_operand_object *obj_desc;
510 acpi_status status;
511 u32 count;
512 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 struct acpi_compatible_id_list *cid_list;
Bob Moore67a119f2008-06-10 13:42:13 +0800514 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Bob Mooreb229cf92006-04-21 17:15:00 -0400516 ACPI_FUNCTION_TRACE(ut_execute_CID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 /* Evaluate the _CID method for this device */
519
Len Brown4be44fc2005-08-05 00:44:28 -0400520 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
521 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
522 | ACPI_BTYPE_PACKAGE, &obj_desc);
523 if (ACPI_FAILURE(status)) {
524 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
526
527 /* Get the number of _CIDs returned */
528
529 count = 1;
Bob Moore3371c192009-02-18 14:44:03 +0800530 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 count = obj_desc->package.count;
532 }
533
534 /* Allocate a worst-case buffer for the _CIDs */
535
Len Brown4be44fc2005-08-05 00:44:28 -0400536 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
537 sizeof(struct acpi_compatible_id_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Bob Moore83135242006-10-03 00:00:00 -0400539 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (!cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400541 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543
544 /* Init CID list */
545
546 cid_list->count = count;
547 cid_list->size = size;
548
549 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400550 * A _CID can return either a single compatible ID or a package of
551 * compatible IDs. Each compatible ID can be one of the following:
552 * 1) Integer (32 bit compressed EISA ID) or
553 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 */
555
556 /* The _CID object can be either a single CID or a package (list) of CIDs */
557
Bob Moore3371c192009-02-18 14:44:03 +0800558 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 /* Translate each package element */
561
562 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400563 status =
564 acpi_ut_translate_one_cid(obj_desc->package.
565 elements[i],
566 &cid_list->id[i]);
567 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 break;
569 }
570 }
Len Brown4be44fc2005-08-05 00:44:28 -0400571 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 /* Only one CID, translate to a string */
573
Len Brown4be44fc2005-08-05 00:44:28 -0400574 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
576
577 /* Cleanup on error */
578
Len Brown4be44fc2005-08-05 00:44:28 -0400579 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400580 ACPI_FREE(cid_list);
Len Brown4be44fc2005-08-05 00:44:28 -0400581 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 *return_cid_list = cid_list;
583 }
584
585 /* On exit, we must delete the _CID return object */
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 acpi_ut_remove_reference(obj_desc);
588 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591/*******************************************************************************
592 *
593 * FUNCTION: acpi_ut_execute_UID
594 *
595 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400596 * Uid - Where the UID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 *
598 * RETURN: Status
599 *
600 * DESCRIPTION: Executes the _UID control method that returns the hardware
601 * ID of the device.
602 *
603 * NOTE: Internal function, no parameter validation
604 *
605 ******************************************************************************/
606
607acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400608acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200609 struct acpica_device_id *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
Len Brown4be44fc2005-08-05 00:44:28 -0400611 union acpi_operand_object *obj_desc;
612 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Bob Mooreb229cf92006-04-21 17:15:00 -0400614 ACPI_FUNCTION_TRACE(ut_execute_UID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Len Brown4be44fc2005-08-05 00:44:28 -0400616 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
617 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
618 &obj_desc);
619 if (ACPI_FAILURE(status)) {
620 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622
Bob Moore3371c192009-02-18 14:44:03 +0800623 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 /* Convert the Numeric UID to string */
626
Len Brown4be44fc2005-08-05 00:44:28 -0400627 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
628 uid->value);
629 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* Copy the String UID from the returned object */
631
Len Brown4be44fc2005-08-05 00:44:28 -0400632 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
633 sizeof(uid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635
636 /* On exit, we must delete the return object */
637
Len Brown4be44fc2005-08-05 00:44:28 -0400638 acpi_ut_remove_reference(obj_desc);
639 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642/*******************************************************************************
643 *
644 * FUNCTION: acpi_ut_execute_STA
645 *
646 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400647 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 *
649 * RETURN: Status
650 *
651 * DESCRIPTION: Executes _STA for selected device and stores results in
652 * *Flags.
653 *
654 * NOTE: Internal function, no parameter validation
655 *
656 ******************************************************************************/
657
658acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400659acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Len Brown4be44fc2005-08-05 00:44:28 -0400661 union acpi_operand_object *obj_desc;
662 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Bob Mooreb229cf92006-04-21 17:15:00 -0400664 ACPI_FUNCTION_TRACE(ut_execute_STA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
667 ACPI_BTYPE_INTEGER, &obj_desc);
668 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (AE_NOT_FOUND == status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400670 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
671 "_STA on %4.4s was not found, assuming device is present\n",
672 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Bob Mooredefba1d2005-12-16 17:05:00 -0500674 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 status = AE_OK;
676 }
677
Len Brown4be44fc2005-08-05 00:44:28 -0400678 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 }
680
681 /* Extract the status flags */
682
683 *flags = (u32) obj_desc->integer.value;
684
685 /* On exit, we must delete the return object */
686
Len Brown4be44fc2005-08-05 00:44:28 -0400687 acpi_ut_remove_reference(obj_desc);
688 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691/*******************************************************************************
692 *
693 * FUNCTION: acpi_ut_execute_Sxds
694 *
695 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400696 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 *
698 * RETURN: Status
699 *
700 * DESCRIPTION: Executes _STA for selected device and stores results in
701 * *Flags.
702 *
703 * NOTE: Internal function, no parameter validation
704 *
705 ******************************************************************************/
706
707acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400708acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709{
Len Brown4be44fc2005-08-05 00:44:28 -0400710 union acpi_operand_object *obj_desc;
711 acpi_status status;
712 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Bob Mooreb229cf92006-04-21 17:15:00 -0400714 ACPI_FUNCTION_TRACE(ut_execute_sxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 for (i = 0; i < 4; i++) {
717 highest[i] = 0xFF;
Len Brown4be44fc2005-08-05 00:44:28 -0400718 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500719 ACPI_CAST_PTR(char,
720 acpi_gbl_highest_dstate_names
721 [i]),
722 ACPI_BTYPE_INTEGER, &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400723 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 if (status != AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400725 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
726 "%s on Device %4.4s, %s\n",
Bob Mooredefba1d2005-12-16 17:05:00 -0500727 ACPI_CAST_PTR(char,
728 acpi_gbl_highest_dstate_names
729 [i]),
Len Brown4be44fc2005-08-05 00:44:28 -0400730 acpi_ut_get_node_name
731 (device_node),
732 acpi_format_exception
733 (status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
Len Brown4be44fc2005-08-05 00:44:28 -0400735 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
Len Brown4be44fc2005-08-05 00:44:28 -0400737 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 /* Extract the Dstate value */
739
740 highest[i] = (u8) obj_desc->integer.value;
741
742 /* Delete the return object */
743
Len Brown4be44fc2005-08-05 00:44:28 -0400744 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 }
746 }
747
Len Brown4be44fc2005-08-05 00:44:28 -0400748 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749}