blob: 006b16c260176d36a1ff445137ff48678ff8be5c [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.
Bob Moore7f071902009-03-19 09:37:47 +080062 *
63 * March 2009: Removed "Linux" as this host no longer wants to respond true
64 * for this string. Basically, the only safe OS strings are windows-related
65 * and in many or most cases represent the only test path within the
66 * BIOS-provided ASL code.
67 *
68 * The second element of each entry is used to track the newest version of
69 * Windows that the BIOS has requested.
Bob Mooreb229cf92006-04-21 17:15:00 -040070 */
Bob Moore7f071902009-03-19 09:37:47 +080071static struct acpi_interface_info acpi_interfaces_supported[] = {
Bob Mooreb229cf92006-04-21 17:15:00 -040072 /* Operating System Vendor Strings */
73
Bob Moore7f071902009-03-19 09:37:47 +080074 {"Windows 2000", ACPI_OSI_WIN_2000}, /* Windows 2000 */
75 {"Windows 2001", ACPI_OSI_WIN_XP}, /* Windows XP */
76 {"Windows 2001 SP1", ACPI_OSI_WIN_XP_SP1}, /* Windows XP SP1 */
77 {"Windows 2001.1", ACPI_OSI_WINSRV_2003}, /* Windows Server 2003 */
78 {"Windows 2001 SP2", ACPI_OSI_WIN_XP_SP2}, /* Windows XP SP2 */
79 {"Windows 2001.1 SP1", ACPI_OSI_WINSRV_2003_SP1}, /* Windows Server 2003 SP1 - Added 03/2006 */
80 {"Windows 2006", ACPI_OSI_WIN_VISTA}, /* Windows Vista - Added 03/2006 */
Bob Mooreb229cf92006-04-21 17:15:00 -040081
82 /* Feature Group Strings */
83
Bob Moore7f071902009-03-19 09:37:47 +080084 {"Extended Address Space Descriptor", 0}
85
86 /*
87 * All "optional" feature group strings (features that are implemented
88 * by the host) should be implemented in the host version of
89 * acpi_os_validate_interface and should not be added here.
90 */
Bob Mooreb229cf92006-04-21 17:15:00 -040091};
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/*******************************************************************************
94 *
95 * FUNCTION: acpi_ut_osi_implementation
96 *
97 * PARAMETERS: walk_state - Current walk state
98 *
99 * RETURN: Status
100 *
Bob Mooreb229cf92006-04-21 17:15:00 -0400101 * DESCRIPTION: Implementation of the _OSI predefined control method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 *
103 ******************************************************************************/
104
Len Brown4be44fc2005-08-05 00:44:28 -0400105acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Bob Mooreb229cf92006-04-21 17:15:00 -0400107 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400108 union acpi_operand_object *string_desc;
109 union acpi_operand_object *return_desc;
Bob Moorec114e4b2009-02-23 11:00:00 +0800110 u32 return_value;
Bob Moore67a119f2008-06-10 13:42:13 +0800111 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Bob Mooreb229cf92006-04-21 17:15:00 -0400113 ACPI_FUNCTION_TRACE(ut_osi_implementation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* Validate the string input argument */
116
117 string_desc = walk_state->arguments[0].object;
118 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400119 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
Bob Mooreb229cf92006-04-21 17:15:00 -0400122 /* Create a return object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Len Brown4be44fc2005-08-05 00:44:28 -0400124 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (!return_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400126 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
Bob Moorec114e4b2009-02-23 11:00:00 +0800129 /* Default return value is 0, NOT SUPPORTED */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Bob Moorec114e4b2009-02-23 11:00:00 +0800131 return_value = 0;
Bob Moore52fc0b02006-10-02 00:00:00 -0400132
Bob Mooreb229cf92006-04-21 17:15:00 -0400133 /* Compare input string to static table of supported interfaces */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Bob Mooreb229cf92006-04-21 17:15:00 -0400135 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
Bob Mooreec41f192009-02-18 15:03:30 +0800136 if (!ACPI_STRCMP(string_desc->string.pointer,
Bob Moore7f071902009-03-19 09:37:47 +0800137 acpi_interfaces_supported[i].name)) {
138 /*
139 * The interface is supported.
140 * Update the osi_data if necessary. We keep track of the latest
141 * version of Windows that has been requested by the BIOS.
142 */
143 if (acpi_interfaces_supported[i].value >
144 acpi_gbl_osi_data) {
145 acpi_gbl_osi_data =
146 acpi_interfaces_supported[i].value;
147 }
Bob Moorec114e4b2009-02-23 11:00:00 +0800148
149 return_value = ACPI_UINT32_MAX;
150 goto exit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152 }
153
Bob Mooreb229cf92006-04-21 17:15:00 -0400154 /*
155 * Did not match the string in the static table, call the host OSL to
156 * check for a match with one of the optional strings (such as
157 * "Module Device", "3.0 Thermal Model", etc.)
158 */
159 status = acpi_os_validate_interface(string_desc->string.pointer);
160 if (ACPI_SUCCESS(status)) {
Bob Moorec114e4b2009-02-23 11:00:00 +0800161
162 /* The interface is supported */
163
164 return_value = ACPI_UINT32_MAX;
Bob Mooreb229cf92006-04-21 17:15:00 -0400165 }
166
Bob Moorec114e4b2009-02-23 11:00:00 +0800167exit:
168 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INFO,
169 "ACPI: BIOS _OSI(%s) is %ssupported\n",
170 string_desc->string.pointer, return_value == 0 ? "not " : ""));
Bob Mooreb229cf92006-04-21 17:15:00 -0400171
Bob Moorec114e4b2009-02-23 11:00:00 +0800172 /* Complete the return value */
173
174 return_desc->integer.value = return_value;
175 walk_state->return_desc = return_desc;
176 return_ACPI_STATUS (AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/*******************************************************************************
180 *
Len Brownae00d812007-05-29 18:43:33 -0400181 * FUNCTION: acpi_osi_invalidate
182 *
183 * PARAMETERS: interface_string
184 *
185 * RETURN: Status
186 *
187 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
188 *
189 ******************************************************************************/
190
191acpi_status acpi_osi_invalidate(char *interface)
192{
193 int i;
194
195 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
Bob Moore7f071902009-03-19 09:37:47 +0800196 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i].name)) {
197 *acpi_interfaces_supported[i].name = '\0';
Len Brownae00d812007-05-29 18:43:33 -0400198 return AE_OK;
199 }
200 }
201 return AE_NOT_FOUND;
202}
203
204/*******************************************************************************
205 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 * FUNCTION: acpi_ut_evaluate_object
207 *
208 * PARAMETERS: prefix_node - Starting node
209 * Path - Path to object from starting node
210 * expected_return_types - Bitmap of allowed return types
211 * return_desc - Where a return value is stored
212 *
213 * RETURN: Status
214 *
215 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
216 * return object. Common code that simplifies accessing objects
217 * that have required return objects of fixed types.
218 *
219 * NOTE: Internal function, no parameter validation
220 *
221 ******************************************************************************/
222
223acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400224acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
225 char *path,
226 u32 expected_return_btypes,
227 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
Bob Moore41195322006-05-26 16:36:00 -0400229 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -0400230 acpi_status status;
231 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Bob Mooreb229cf92006-04-21 17:15:00 -0400233 ACPI_FUNCTION_TRACE(ut_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Bob Moore41195322006-05-26 16:36:00 -0400235 /* Allocate the evaluation information block */
236
237 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
238 if (!info) {
239 return_ACPI_STATUS(AE_NO_MEMORY);
240 }
241
242 info->prefix_node = prefix_node;
243 info->pathname = path;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 /* Evaluate the object/method */
246
Bob Moore41195322006-05-26 16:36:00 -0400247 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400248 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400250 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
251 "[%4.4s.%s] was not found\n",
252 acpi_ut_get_node_name(prefix_node),
253 path));
254 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500255 ACPI_ERROR_METHOD("Method execution failed",
256 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258
Bob Moore41195322006-05-26 16:36:00 -0400259 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261
262 /* Did we get a return object? */
263
Bob Moore41195322006-05-26 16:36:00 -0400264 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (expected_return_btypes) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500266 ACPI_ERROR_METHOD("No object was returned from",
267 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Bob Moore41195322006-05-26 16:36:00 -0400269 status = AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 }
271
Bob Moore41195322006-05-26 16:36:00 -0400272 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 /* Map the return object type to the bitmapped type */
276
Bob Moore3371c192009-02-18 14:44:03 +0800277 switch ((info->return_object)->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 case ACPI_TYPE_INTEGER:
279 return_btype = ACPI_BTYPE_INTEGER;
280 break;
281
282 case ACPI_TYPE_BUFFER:
283 return_btype = ACPI_BTYPE_BUFFER;
284 break;
285
286 case ACPI_TYPE_STRING:
287 return_btype = ACPI_BTYPE_STRING;
288 break;
289
290 case ACPI_TYPE_PACKAGE:
291 return_btype = ACPI_BTYPE_PACKAGE;
292 break;
293
294 default:
295 return_btype = 0;
296 break;
297 }
298
Len Brown4be44fc2005-08-05 00:44:28 -0400299 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 /*
301 * We received a return object, but one was not expected. This can
302 * happen frequently if the "implicit return" feature is enabled.
303 * Just delete the return object and return AE_OK.
304 */
Bob Moore41195322006-05-26 16:36:00 -0400305 acpi_ut_remove_reference(info->return_object);
306 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308
309 /* Is the return object one of the expected types? */
310
311 if (!(expected_return_btypes & return_btype)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500312 ACPI_ERROR_METHOD("Return object type is incorrect",
313 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Bob Mooreb8e4d892006-01-27 16:43:00 -0500315 ACPI_ERROR((AE_INFO,
316 "Type returned from %s was incorrect: %s, expected Btypes: %X",
317 path,
Bob Moore41195322006-05-26 16:36:00 -0400318 acpi_ut_get_object_type_name(info->return_object),
Bob Mooreb8e4d892006-01-27 16:43:00 -0500319 expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 /* On error exit, we must delete the return object */
322
Bob Moore41195322006-05-26 16:36:00 -0400323 acpi_ut_remove_reference(info->return_object);
324 status = AE_TYPE;
325 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327
328 /* Object type is OK, return it */
329
Bob Moore41195322006-05-26 16:36:00 -0400330 *return_desc = info->return_object;
331
332 cleanup:
333 ACPI_FREE(info);
334 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/*******************************************************************************
338 *
339 * FUNCTION: acpi_ut_evaluate_numeric_object
340 *
Robert Moore44f6c012005-04-18 22:49:35 -0400341 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 * device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400343 * Address - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 *
345 * RETURN: Status
346 *
347 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
348 * and stores result in *Address.
349 *
350 * NOTE: Internal function, no parameter validation
351 *
352 ******************************************************************************/
353
354acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400355acpi_ut_evaluate_numeric_object(char *object_name,
356 struct acpi_namespace_node *device_node,
357 acpi_integer * address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Len Brown4be44fc2005-08-05 00:44:28 -0400359 union acpi_operand_object *obj_desc;
360 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Bob Mooreb229cf92006-04-21 17:15:00 -0400362 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Len Brown4be44fc2005-08-05 00:44:28 -0400364 status = acpi_ut_evaluate_object(device_node, object_name,
365 ACPI_BTYPE_INTEGER, &obj_desc);
366 if (ACPI_FAILURE(status)) {
367 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
370 /* Get the returned Integer */
371
372 *address = obj_desc->integer.value;
373
374 /* On exit, we must delete the return object */
375
Len Brown4be44fc2005-08-05 00:44:28 -0400376 acpi_ut_remove_reference(obj_desc);
377 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380/*******************************************************************************
381 *
382 * FUNCTION: acpi_ut_copy_id_string
383 *
384 * PARAMETERS: Destination - Where to copy the string
385 * Source - Source string
386 * max_length - Length of the destination buffer
387 *
388 * RETURN: None
389 *
390 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
391 * Performs removal of a leading asterisk if present -- workaround
392 * for a known issue on a bunch of machines.
393 *
394 ******************************************************************************/
395
396static void
Len Brown4be44fc2005-08-05 00:44:28 -0400397acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 /*
401 * Workaround for ID strings that have a leading asterisk. This construct
402 * is not allowed by the ACPI specification (ID strings must be
403 * alphanumeric), but enough existing machines have this embedded in their
404 * ID strings that the following code is useful.
405 */
406 if (*source == '*') {
407 source++;
408 }
409
410 /* Do the actual copy */
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 ACPI_STRNCPY(destination, source, max_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415/*******************************************************************************
416 *
417 * FUNCTION: acpi_ut_execute_HID
418 *
419 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400420 * Hid - Where the HID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 *
422 * RETURN: Status
423 *
424 * DESCRIPTION: Executes the _HID control method that returns the hardware
425 * ID of the device.
426 *
427 * NOTE: Internal function, no parameter validation
428 *
429 ******************************************************************************/
430
431acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400432acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200433 struct acpica_device_id *hid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
Len Brown4be44fc2005-08-05 00:44:28 -0400435 union acpi_operand_object *obj_desc;
436 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Bob Mooreb229cf92006-04-21 17:15:00 -0400438 ACPI_FUNCTION_TRACE(ut_execute_HID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Len Brown4be44fc2005-08-05 00:44:28 -0400440 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
441 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
442 &obj_desc);
443 if (ACPI_FAILURE(status)) {
444 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
Bob Moore3371c192009-02-18 14:44:03 +0800447 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 /* Convert the Numeric HID to string */
450
Len Brown4be44fc2005-08-05 00:44:28 -0400451 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
452 hid->value);
453 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 /* Copy the String HID from the returned object */
455
Len Brown4be44fc2005-08-05 00:44:28 -0400456 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
457 sizeof(hid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459
460 /* On exit, we must delete the return object */
461
Len Brown4be44fc2005-08-05 00:44:28 -0400462 acpi_ut_remove_reference(obj_desc);
463 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464}
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466/*******************************************************************************
467 *
468 * FUNCTION: acpi_ut_translate_one_cid
469 *
470 * PARAMETERS: obj_desc - _CID object, must be integer or string
471 * one_cid - Where the CID string is returned
472 *
473 * RETURN: Status
474 *
475 * DESCRIPTION: Return a numeric or string _CID value as a string.
476 * (Compatible ID)
477 *
478 * NOTE: Assumes a maximum _CID string length of
479 * ACPI_MAX_CID_LENGTH.
480 *
481 ******************************************************************************/
482
483static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400484acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
485 struct acpi_compatible_id *one_cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
487
Bob Moore3371c192009-02-18 14:44:03 +0800488 switch (obj_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 case ACPI_TYPE_INTEGER:
490
491 /* Convert the Numeric CID to string */
492
Len Brown4be44fc2005-08-05 00:44:28 -0400493 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
494 one_cid->value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 return (AE_OK);
496
497 case ACPI_TYPE_STRING:
498
499 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
500 return (AE_AML_STRING_LIMIT);
501 }
502
503 /* Copy the String CID from the returned object */
504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
506 ACPI_MAX_CID_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 return (AE_OK);
508
509 default:
510
511 return (AE_TYPE);
512 }
513}
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515/*******************************************************************************
516 *
517 * FUNCTION: acpi_ut_execute_CID
518 *
519 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400520 * return_cid_list - Where the CID list is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 *
522 * RETURN: Status
523 *
524 * DESCRIPTION: Executes the _CID control method that returns one or more
525 * compatible hardware IDs for the device.
526 *
527 * NOTE: Internal function, no parameter validation
528 *
529 ******************************************************************************/
530
531acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400532acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
533 struct acpi_compatible_id_list ** return_cid_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Len Brown4be44fc2005-08-05 00:44:28 -0400535 union acpi_operand_object *obj_desc;
536 acpi_status status;
537 u32 count;
538 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 struct acpi_compatible_id_list *cid_list;
Bob Moore67a119f2008-06-10 13:42:13 +0800540 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Bob Mooreb229cf92006-04-21 17:15:00 -0400542 ACPI_FUNCTION_TRACE(ut_execute_CID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /* Evaluate the _CID method for this device */
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
547 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
548 | ACPI_BTYPE_PACKAGE, &obj_desc);
549 if (ACPI_FAILURE(status)) {
550 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
553 /* Get the number of _CIDs returned */
554
555 count = 1;
Bob Moore3371c192009-02-18 14:44:03 +0800556 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 count = obj_desc->package.count;
558 }
559
560 /* Allocate a worst-case buffer for the _CIDs */
561
Len Brown4be44fc2005-08-05 00:44:28 -0400562 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
563 sizeof(struct acpi_compatible_id_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
Bob Moore83135242006-10-03 00:00:00 -0400565 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if (!cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400567 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569
570 /* Init CID list */
571
572 cid_list->count = count;
573 cid_list->size = size;
574
575 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400576 * A _CID can return either a single compatible ID or a package of
577 * compatible IDs. Each compatible ID can be one of the following:
578 * 1) Integer (32 bit compressed EISA ID) or
579 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 */
581
582 /* The _CID object can be either a single CID or a package (list) of CIDs */
583
Bob Moore3371c192009-02-18 14:44:03 +0800584 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /* Translate each package element */
587
588 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400589 status =
590 acpi_ut_translate_one_cid(obj_desc->package.
591 elements[i],
592 &cid_list->id[i]);
593 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 break;
595 }
596 }
Len Brown4be44fc2005-08-05 00:44:28 -0400597 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 /* Only one CID, translate to a string */
599
Len Brown4be44fc2005-08-05 00:44:28 -0400600 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602
603 /* Cleanup on error */
604
Len Brown4be44fc2005-08-05 00:44:28 -0400605 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400606 ACPI_FREE(cid_list);
Len Brown4be44fc2005-08-05 00:44:28 -0400607 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 *return_cid_list = cid_list;
609 }
610
611 /* On exit, we must delete the _CID return object */
612
Len Brown4be44fc2005-08-05 00:44:28 -0400613 acpi_ut_remove_reference(obj_desc);
614 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615}
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617/*******************************************************************************
618 *
619 * FUNCTION: acpi_ut_execute_UID
620 *
621 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400622 * Uid - Where the UID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 *
624 * RETURN: Status
625 *
626 * DESCRIPTION: Executes the _UID control method that returns the hardware
627 * ID of the device.
628 *
629 * NOTE: Internal function, no parameter validation
630 *
631 ******************************************************************************/
632
633acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400634acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
Thomas Renninger8c8eb782007-07-23 14:43:32 +0200635 struct acpica_device_id *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Len Brown4be44fc2005-08-05 00:44:28 -0400637 union acpi_operand_object *obj_desc;
638 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Bob Mooreb229cf92006-04-21 17:15:00 -0400640 ACPI_FUNCTION_TRACE(ut_execute_UID);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Len Brown4be44fc2005-08-05 00:44:28 -0400642 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
643 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
644 &obj_desc);
645 if (ACPI_FAILURE(status)) {
646 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
Bob Moore3371c192009-02-18 14:44:03 +0800649 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* Convert the Numeric UID to string */
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
654 uid->value);
655 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /* Copy the String UID from the returned object */
657
Len Brown4be44fc2005-08-05 00:44:28 -0400658 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
659 sizeof(uid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 }
661
662 /* On exit, we must delete the return object */
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664 acpi_ut_remove_reference(obj_desc);
665 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668/*******************************************************************************
669 *
670 * FUNCTION: acpi_ut_execute_STA
671 *
672 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400673 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 *
675 * RETURN: Status
676 *
677 * DESCRIPTION: Executes _STA for selected device and stores results in
678 * *Flags.
679 *
680 * NOTE: Internal function, no parameter validation
681 *
682 ******************************************************************************/
683
684acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400685acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686{
Len Brown4be44fc2005-08-05 00:44:28 -0400687 union acpi_operand_object *obj_desc;
688 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
Bob Mooreb229cf92006-04-21 17:15:00 -0400690 ACPI_FUNCTION_TRACE(ut_execute_STA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Len Brown4be44fc2005-08-05 00:44:28 -0400692 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
693 ACPI_BTYPE_INTEGER, &obj_desc);
694 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (AE_NOT_FOUND == status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400696 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
697 "_STA on %4.4s was not found, assuming device is present\n",
698 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Bob Mooredefba1d2005-12-16 17:05:00 -0500700 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 status = AE_OK;
702 }
703
Len Brown4be44fc2005-08-05 00:44:28 -0400704 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 }
706
707 /* Extract the status flags */
708
709 *flags = (u32) obj_desc->integer.value;
710
711 /* On exit, we must delete the return object */
712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 acpi_ut_remove_reference(obj_desc);
714 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715}
716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717/*******************************************************************************
718 *
719 * FUNCTION: acpi_ut_execute_Sxds
720 *
721 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400722 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 *
724 * RETURN: Status
725 *
726 * DESCRIPTION: Executes _STA for selected device and stores results in
727 * *Flags.
728 *
729 * NOTE: Internal function, no parameter validation
730 *
731 ******************************************************************************/
732
733acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400734acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735{
Len Brown4be44fc2005-08-05 00:44:28 -0400736 union acpi_operand_object *obj_desc;
737 acpi_status status;
738 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Bob Mooreb229cf92006-04-21 17:15:00 -0400740 ACPI_FUNCTION_TRACE(ut_execute_sxds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741
742 for (i = 0; i < 4; i++) {
743 highest[i] = 0xFF;
Len Brown4be44fc2005-08-05 00:44:28 -0400744 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500745 ACPI_CAST_PTR(char,
746 acpi_gbl_highest_dstate_names
747 [i]),
748 ACPI_BTYPE_INTEGER, &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400749 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 if (status != AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400751 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
752 "%s on Device %4.4s, %s\n",
Bob Mooredefba1d2005-12-16 17:05:00 -0500753 ACPI_CAST_PTR(char,
754 acpi_gbl_highest_dstate_names
755 [i]),
Len Brown4be44fc2005-08-05 00:44:28 -0400756 acpi_ut_get_node_name
757 (device_node),
758 acpi_format_exception
759 (status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
Len Brown4be44fc2005-08-05 00:44:28 -0400761 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 }
Len Brown4be44fc2005-08-05 00:44:28 -0400763 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 /* Extract the Dstate value */
765
766 highest[i] = (u8) obj_desc->integer.value;
767
768 /* Delete the return object */
769
Len Brown4be44fc2005-08-05 00:44:28 -0400770 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772 }
773
Len Brown4be44fc2005-08-05 00:44:28 -0400774 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775}