blob: 9c4ae6f26b9d098ac6f45992f711e9b147f3e119 [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 Moorec114e4b2009-02-23 11:00:00 +0800101 u32 return_value;
Bob Moore67a119f2008-06-10 13:42:13 +0800102 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Bob Mooreb229cf92006-04-21 17:15:00 -0400104 ACPI_FUNCTION_TRACE(ut_osi_implementation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /* Validate the string input argument */
107
108 string_desc = walk_state->arguments[0].object;
109 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400110 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
112
Bob Mooreb229cf92006-04-21 17:15:00 -0400113 /* Create a return object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Len Brown4be44fc2005-08-05 00:44:28 -0400115 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (!return_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400117 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119
Bob Moorec114e4b2009-02-23 11:00:00 +0800120 /* Default return value is 0, NOT SUPPORTED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Bob Moorec114e4b2009-02-23 11:00:00 +0800122 return_value = 0;
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])) {
Bob Moorec114e4b2009-02-23 11:00:00 +0800130
131 /* The interface is supported */
132
133 return_value = ACPI_UINT32_MAX;
134 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136 }
137
Bob Mooreb229cf92006-04-21 17:15:00 -0400138 /*
139 * Did not match the string in the static table, call the host OSL to
140 * check for a match with one of the optional strings (such as
141 * "Module Device", "3.0 Thermal Model", etc.)
142 */
143 status = acpi_os_validate_interface(string_desc->string.pointer);
144 if (ACPI_SUCCESS(status)) {
Bob Moorec114e4b2009-02-23 11:00:00 +0800145
146 /* The interface is supported */
147
148 return_value = ACPI_UINT32_MAX;
Bob Mooreb229cf92006-04-21 17:15:00 -0400149 }
150
Bob Moorec114e4b2009-02-23 11:00:00 +0800151exit:
152 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
153 "ACPI: BIOS _OSI(%s) is %ssupported\n",
154 string_desc->string.pointer, return_value == 0 ? "not " : ""));
Bob Mooreb229cf92006-04-21 17:15:00 -0400155
Bob Moorec114e4b2009-02-23 11:00:00 +0800156 /* Complete the return value */
157
158 return_desc->integer.value = return_value;
159 walk_state->return_desc = return_desc;
160 return_ACPI_STATUS (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163/*******************************************************************************
164 *
Len Brownae00d812007-05-29 18:43:33 -0400165 * FUNCTION: acpi_osi_invalidate
166 *
167 * PARAMETERS: interface_string
168 *
169 * RETURN: Status
170 *
171 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
172 *
173 ******************************************************************************/
174
175acpi_status acpi_osi_invalidate(char *interface)
176{
177 int i;
178
179 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
180 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i])) {
181 *acpi_interfaces_supported[i] = '\0';
182 return AE_OK;
183 }
184 }
185 return AE_NOT_FOUND;
186}
187
188/*******************************************************************************
189 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 * FUNCTION: acpi_ut_evaluate_object
191 *
192 * PARAMETERS: prefix_node - Starting node
193 * Path - Path to object from starting node
194 * expected_return_types - Bitmap of allowed return types
195 * return_desc - Where a return value is stored
196 *
197 * RETURN: Status
198 *
199 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
200 * return object. Common code that simplifies accessing objects
201 * that have required return objects of fixed types.
202 *
203 * NOTE: Internal function, no parameter validation
204 *
205 ******************************************************************************/
206
207acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400208acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
209 char *path,
210 u32 expected_return_btypes,
211 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212{
Bob Moore41195322006-05-26 16:36:00 -0400213 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -0400214 acpi_status status;
215 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Bob Mooreb229cf92006-04-21 17:15:00 -0400217 ACPI_FUNCTION_TRACE(ut_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Bob Moore41195322006-05-26 16:36:00 -0400219 /* Allocate the evaluation information block */
220
221 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
222 if (!info) {
223 return_ACPI_STATUS(AE_NO_MEMORY);
224 }
225
226 info->prefix_node = prefix_node;
227 info->pathname = path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* Evaluate the object/method */
230
Bob Moore41195322006-05-26 16:36:00 -0400231 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400232 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400234 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
235 "[%4.4s.%s] was not found\n",
236 acpi_ut_get_node_name(prefix_node),
237 path));
238 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500239 ACPI_ERROR_METHOD("Method execution failed",
240 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 }
242
Bob Moore41195322006-05-26 16:36:00 -0400243 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245
246 /* Did we get a return object? */
247
Bob Moore41195322006-05-26 16:36:00 -0400248 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (expected_return_btypes) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500250 ACPI_ERROR_METHOD("No object was returned from",
251 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Bob Moore41195322006-05-26 16:36:00 -0400253 status = AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 }
255
Bob Moore41195322006-05-26 16:36:00 -0400256 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
259 /* Map the return object type to the bitmapped type */
260
Bob Moore3371c192009-02-18 14:44:03 +0800261 switch ((info->return_object)->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 case ACPI_TYPE_INTEGER:
263 return_btype = ACPI_BTYPE_INTEGER;
264 break;
265
266 case ACPI_TYPE_BUFFER:
267 return_btype = ACPI_BTYPE_BUFFER;
268 break;
269
270 case ACPI_TYPE_STRING:
271 return_btype = ACPI_BTYPE_STRING;
272 break;
273
274 case ACPI_TYPE_PACKAGE:
275 return_btype = ACPI_BTYPE_PACKAGE;
276 break;
277
278 default:
279 return_btype = 0;
280 break;
281 }
282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 /*
285 * We received a return object, but one was not expected. This can
286 * happen frequently if the "implicit return" feature is enabled.
287 * Just delete the return object and return AE_OK.
288 */
Bob Moore41195322006-05-26 16:36:00 -0400289 acpi_ut_remove_reference(info->return_object);
290 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 }
292
293 /* Is the return object one of the expected types? */
294
295 if (!(expected_return_btypes & return_btype)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500296 ACPI_ERROR_METHOD("Return object type is incorrect",
297 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Bob Mooreb8e4d892006-01-27 16:43:00 -0500299 ACPI_ERROR((AE_INFO,
300 "Type returned from %s was incorrect: %s, expected Btypes: %X",
301 path,
Bob Moore41195322006-05-26 16:36:00 -0400302 acpi_ut_get_object_type_name(info->return_object),
Bob Mooreb8e4d892006-01-27 16:43:00 -0500303 expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305 /* On error exit, we must delete the return object */
306
Bob Moore41195322006-05-26 16:36:00 -0400307 acpi_ut_remove_reference(info->return_object);
308 status = AE_TYPE;
309 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
312 /* Object type is OK, return it */
313
Bob Moore41195322006-05-26 16:36:00 -0400314 *return_desc = info->return_object;
315
316 cleanup:
317 ACPI_FREE(info);
318 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321/*******************************************************************************
322 *
323 * FUNCTION: acpi_ut_evaluate_numeric_object
324 *
Robert Moore44f6c012005-04-18 22:49:35 -0400325 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 * device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400327 * Address - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 *
329 * RETURN: Status
330 *
331 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
332 * and stores result in *Address.
333 *
334 * NOTE: Internal function, no parameter validation
335 *
336 ******************************************************************************/
337
338acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400339acpi_ut_evaluate_numeric_object(char *object_name,
340 struct acpi_namespace_node *device_node,
341 acpi_integer * address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342{
Len Brown4be44fc2005-08-05 00:44:28 -0400343 union acpi_operand_object *obj_desc;
344 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Bob Mooreb229cf92006-04-21 17:15:00 -0400346 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Len Brown4be44fc2005-08-05 00:44:28 -0400348 status = acpi_ut_evaluate_object(device_node, object_name,
349 ACPI_BTYPE_INTEGER, &obj_desc);
350 if (ACPI_FAILURE(status)) {
351 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 }
353
354 /* Get the returned Integer */
355
356 *address = obj_desc->integer.value;
357
358 /* On exit, we must delete the return object */
359
Len Brown4be44fc2005-08-05 00:44:28 -0400360 acpi_ut_remove_reference(obj_desc);
361 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364/*******************************************************************************
365 *
366 * FUNCTION: acpi_ut_copy_id_string
367 *
368 * PARAMETERS: Destination - Where to copy the string
369 * Source - Source string
370 * max_length - Length of the destination buffer
371 *
372 * RETURN: None
373 *
374 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
375 * Performs removal of a leading asterisk if present -- workaround
376 * for a known issue on a bunch of machines.
377 *
378 ******************************************************************************/
379
380static void
Len Brown4be44fc2005-08-05 00:44:28 -0400381acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 /*
385 * Workaround for ID strings that have a leading asterisk. This construct
386 * is not allowed by the ACPI specification (ID strings must be
387 * alphanumeric), but enough existing machines have this embedded in their
388 * ID strings that the following code is useful.
389 */
390 if (*source == '*') {
391 source++;
392 }
393
394 /* Do the actual copy */
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 ACPI_STRNCPY(destination, source, max_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399/*******************************************************************************
400 *
401 * FUNCTION: acpi_ut_execute_HID
402 *
403 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400404 * Hid - Where the HID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 *
406 * RETURN: Status
407 *
408 * DESCRIPTION: Executes the _HID control method that returns the hardware
409 * ID of the device.
410 *
411 * NOTE: Internal function, no parameter validation
412 *
413 ******************************************************************************/
414
415acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400416acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200417 struct acpica_device_id *hid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Len Brown4be44fc2005-08-05 00:44:28 -0400419 union acpi_operand_object *obj_desc;
420 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Bob Mooreb229cf92006-04-21 17:15:00 -0400422 ACPI_FUNCTION_TRACE(ut_execute_HID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Len Brown4be44fc2005-08-05 00:44:28 -0400424 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
425 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
426 &obj_desc);
427 if (ACPI_FAILURE(status)) {
428 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 }
430
Bob Moore3371c192009-02-18 14:44:03 +0800431 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 /* Convert the Numeric HID to string */
434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
436 hid->value);
437 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 /* Copy the String HID from the returned object */
439
Len Brown4be44fc2005-08-05 00:44:28 -0400440 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
441 sizeof(hid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443
444 /* On exit, we must delete the return object */
445
Len Brown4be44fc2005-08-05 00:44:28 -0400446 acpi_ut_remove_reference(obj_desc);
447 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448}
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450/*******************************************************************************
451 *
452 * FUNCTION: acpi_ut_translate_one_cid
453 *
454 * PARAMETERS: obj_desc - _CID object, must be integer or string
455 * one_cid - Where the CID string is returned
456 *
457 * RETURN: Status
458 *
459 * DESCRIPTION: Return a numeric or string _CID value as a string.
460 * (Compatible ID)
461 *
462 * NOTE: Assumes a maximum _CID string length of
463 * ACPI_MAX_CID_LENGTH.
464 *
465 ******************************************************************************/
466
467static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400468acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
469 struct acpi_compatible_id *one_cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
471
Bob Moore3371c192009-02-18 14:44:03 +0800472 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 case ACPI_TYPE_INTEGER:
474
475 /* Convert the Numeric CID to string */
476
Len Brown4be44fc2005-08-05 00:44:28 -0400477 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
478 one_cid->value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 return (AE_OK);
480
481 case ACPI_TYPE_STRING:
482
483 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
484 return (AE_AML_STRING_LIMIT);
485 }
486
487 /* Copy the String CID from the returned object */
488
Len Brown4be44fc2005-08-05 00:44:28 -0400489 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
490 ACPI_MAX_CID_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return (AE_OK);
492
493 default:
494
495 return (AE_TYPE);
496 }
497}
498
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499/*******************************************************************************
500 *
501 * FUNCTION: acpi_ut_execute_CID
502 *
503 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400504 * return_cid_list - Where the CID list is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 *
506 * RETURN: Status
507 *
508 * DESCRIPTION: Executes the _CID control method that returns one or more
509 * compatible hardware IDs for the device.
510 *
511 * NOTE: Internal function, no parameter validation
512 *
513 ******************************************************************************/
514
515acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400516acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
517 struct acpi_compatible_id_list ** return_cid_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Len Brown4be44fc2005-08-05 00:44:28 -0400519 union acpi_operand_object *obj_desc;
520 acpi_status status;
521 u32 count;
522 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 struct acpi_compatible_id_list *cid_list;
Bob Moore67a119f2008-06-10 13:42:13 +0800524 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Bob Mooreb229cf92006-04-21 17:15:00 -0400526 ACPI_FUNCTION_TRACE(ut_execute_CID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 /* Evaluate the _CID method for this device */
529
Len Brown4be44fc2005-08-05 00:44:28 -0400530 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
531 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
532 | ACPI_BTYPE_PACKAGE, &obj_desc);
533 if (ACPI_FAILURE(status)) {
534 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 }
536
537 /* Get the number of _CIDs returned */
538
539 count = 1;
Bob Moore3371c192009-02-18 14:44:03 +0800540 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 count = obj_desc->package.count;
542 }
543
544 /* Allocate a worst-case buffer for the _CIDs */
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
547 sizeof(struct acpi_compatible_id_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Bob Moore83135242006-10-03 00:00:00 -0400549 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (!cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400551 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553
554 /* Init CID list */
555
556 cid_list->count = count;
557 cid_list->size = size;
558
559 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400560 * A _CID can return either a single compatible ID or a package of
561 * compatible IDs. Each compatible ID can be one of the following:
562 * 1) Integer (32 bit compressed EISA ID) or
563 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 */
565
566 /* The _CID object can be either a single CID or a package (list) of CIDs */
567
Bob Moore3371c192009-02-18 14:44:03 +0800568 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 /* Translate each package element */
571
572 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400573 status =
574 acpi_ut_translate_one_cid(obj_desc->package.
575 elements[i],
576 &cid_list->id[i]);
577 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 break;
579 }
580 }
Len Brown4be44fc2005-08-05 00:44:28 -0400581 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 /* Only one CID, translate to a string */
583
Len Brown4be44fc2005-08-05 00:44:28 -0400584 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
587 /* Cleanup on error */
588
Len Brown4be44fc2005-08-05 00:44:28 -0400589 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400590 ACPI_FREE(cid_list);
Len Brown4be44fc2005-08-05 00:44:28 -0400591 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 *return_cid_list = cid_list;
593 }
594
595 /* On exit, we must delete the _CID return object */
596
Len Brown4be44fc2005-08-05 00:44:28 -0400597 acpi_ut_remove_reference(obj_desc);
598 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601/*******************************************************************************
602 *
603 * FUNCTION: acpi_ut_execute_UID
604 *
605 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400606 * Uid - Where the UID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 *
608 * RETURN: Status
609 *
610 * DESCRIPTION: Executes the _UID control method that returns the hardware
611 * ID of the device.
612 *
613 * NOTE: Internal function, no parameter validation
614 *
615 ******************************************************************************/
616
617acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400618acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200619 struct acpica_device_id *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Len Brown4be44fc2005-08-05 00:44:28 -0400621 union acpi_operand_object *obj_desc;
622 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Bob Mooreb229cf92006-04-21 17:15:00 -0400624 ACPI_FUNCTION_TRACE(ut_execute_UID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
627 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
628 &obj_desc);
629 if (ACPI_FAILURE(status)) {
630 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 }
632
Bob Moore3371c192009-02-18 14:44:03 +0800633 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400634
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 /* Convert the Numeric UID to string */
636
Len Brown4be44fc2005-08-05 00:44:28 -0400637 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
638 uid->value);
639 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 /* Copy the String UID from the returned object */
641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
643 sizeof(uid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645
646 /* On exit, we must delete the return object */
647
Len Brown4be44fc2005-08-05 00:44:28 -0400648 acpi_ut_remove_reference(obj_desc);
649 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652/*******************************************************************************
653 *
654 * FUNCTION: acpi_ut_execute_STA
655 *
656 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400657 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 *
659 * RETURN: Status
660 *
661 * DESCRIPTION: Executes _STA for selected device and stores results in
662 * *Flags.
663 *
664 * NOTE: Internal function, no parameter validation
665 *
666 ******************************************************************************/
667
668acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400669acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Len Brown4be44fc2005-08-05 00:44:28 -0400671 union acpi_operand_object *obj_desc;
672 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Bob Mooreb229cf92006-04-21 17:15:00 -0400674 ACPI_FUNCTION_TRACE(ut_execute_STA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Len Brown4be44fc2005-08-05 00:44:28 -0400676 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
677 ACPI_BTYPE_INTEGER, &obj_desc);
678 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if (AE_NOT_FOUND == status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400680 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
681 "_STA on %4.4s was not found, assuming device is present\n",
682 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Bob Mooredefba1d2005-12-16 17:05:00 -0500684 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 status = AE_OK;
686 }
687
Len Brown4be44fc2005-08-05 00:44:28 -0400688 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690
691 /* Extract the status flags */
692
693 *flags = (u32) obj_desc->integer.value;
694
695 /* On exit, we must delete the return object */
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 acpi_ut_remove_reference(obj_desc);
698 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701/*******************************************************************************
702 *
703 * FUNCTION: acpi_ut_execute_Sxds
704 *
705 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400706 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 *
708 * RETURN: Status
709 *
710 * DESCRIPTION: Executes _STA for selected device and stores results in
711 * *Flags.
712 *
713 * NOTE: Internal function, no parameter validation
714 *
715 ******************************************************************************/
716
717acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400718acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
Len Brown4be44fc2005-08-05 00:44:28 -0400720 union acpi_operand_object *obj_desc;
721 acpi_status status;
722 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Bob Mooreb229cf92006-04-21 17:15:00 -0400724 ACPI_FUNCTION_TRACE(ut_execute_sxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
726 for (i = 0; i < 4; i++) {
727 highest[i] = 0xFF;
Len Brown4be44fc2005-08-05 00:44:28 -0400728 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500729 ACPI_CAST_PTR(char,
730 acpi_gbl_highest_dstate_names
731 [i]),
732 ACPI_BTYPE_INTEGER, &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400733 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (status != AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400735 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
736 "%s on Device %4.4s, %s\n",
Bob Mooredefba1d2005-12-16 17:05:00 -0500737 ACPI_CAST_PTR(char,
738 acpi_gbl_highest_dstate_names
739 [i]),
Len Brown4be44fc2005-08-05 00:44:28 -0400740 acpi_ut_get_node_name
741 (device_node),
742 acpi_format_exception
743 (status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
Len Brown4be44fc2005-08-05 00:44:28 -0400745 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
Len Brown4be44fc2005-08-05 00:44:28 -0400747 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 /* Extract the Dstate value */
749
750 highest[i] = (u8) obj_desc->integer.value;
751
752 /* Delete the return object */
753
Len Brown4be44fc2005-08-05 00:44:28 -0400754 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756 }
757
Len Brown4be44fc2005-08-05 00:44:28 -0400758 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759}