blob: f4dc374a0eec1715f650737d1cfbaba9ff265e9b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acnamesp.h>
46#include <acpi/acinterp.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("uteval")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040052static void
Len Brown4be44fc2005-08-05 00:44:28 -040053acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length);
Robert Moore44f6c012005-04-18 22:49:35 -040054
55static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040056acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
57 struct acpi_compatible_id *one_cid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ut_osi_implementation
62 *
63 * PARAMETERS: walk_state - Current walk state
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Implementation of _OSI predefined control method
68 * Supported = _OSI (String)
69 *
70 ******************************************************************************/
71
Len Brown4be44fc2005-08-05 00:44:28 -040072acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Len Brown4be44fc2005-08-05 00:44:28 -040074 union acpi_operand_object *string_desc;
75 union acpi_operand_object *return_desc;
76 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Len Brown4be44fc2005-08-05 00:44:28 -040078 ACPI_FUNCTION_TRACE("ut_osi_implementation");
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 /* Validate the string input argument */
81
82 string_desc = walk_state->arguments[0].object;
83 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
Len Brown4be44fc2005-08-05 00:44:28 -040084 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 }
86
87 /* Create a return object (Default value = 0) */
88
Len Brown4be44fc2005-08-05 00:44:28 -040089 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 if (!return_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -040091 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
93
94 /* Compare input string to table of supported strings */
95
96 for (i = 0; i < ACPI_NUM_OSI_STRINGS; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -040097 if (!ACPI_STRCMP(string_desc->string.pointer,
Bob Mooredefba1d2005-12-16 17:05:00 -050098 ACPI_CAST_PTR(char,
99 acpi_gbl_valid_osi_strings[i])))
100 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 /* This string is supported */
102
103 return_desc->integer.value = 0xFFFFFFFF;
104 break;
105 }
106 }
107
108 walk_state->return_desc = return_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400109 return_ACPI_STATUS(AE_CTRL_TERMINATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*******************************************************************************
113 *
114 * FUNCTION: acpi_ut_evaluate_object
115 *
116 * PARAMETERS: prefix_node - Starting node
117 * Path - Path to object from starting node
118 * expected_return_types - Bitmap of allowed return types
119 * return_desc - Where a return value is stored
120 *
121 * RETURN: Status
122 *
123 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
124 * return object. Common code that simplifies accessing objects
125 * that have required return objects of fixed types.
126 *
127 * NOTE: Internal function, no parameter validation
128 *
129 ******************************************************************************/
130
131acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400132acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
133 char *path,
134 u32 expected_return_btypes,
135 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Len Brown4be44fc2005-08-05 00:44:28 -0400137 struct acpi_parameter_info info;
138 acpi_status status;
139 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_FUNCTION_TRACE("ut_evaluate_object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 info.node = prefix_node;
144 info.parameters = NULL;
145 info.parameter_type = ACPI_PARAM_ARGS;
146
147 /* Evaluate the object/method */
148
Len Brown4be44fc2005-08-05 00:44:28 -0400149 status = acpi_ns_evaluate_relative(path, &info);
150 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
153 "[%4.4s.%s] was not found\n",
154 acpi_ut_get_node_name(prefix_node),
155 path));
156 } else {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500157 ACPI_REPORT_MTERROR("Method execution failed",
158 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
Len Brown4be44fc2005-08-05 00:44:28 -0400161 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163
164 /* Did we get a return object? */
165
166 if (!info.return_object) {
167 if (expected_return_btypes) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500168 ACPI_REPORT_MTERROR("No object was returned from",
169 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 }
176
177 /* Map the return object type to the bitmapped type */
178
Len Brown4be44fc2005-08-05 00:44:28 -0400179 switch (ACPI_GET_OBJECT_TYPE(info.return_object)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 case ACPI_TYPE_INTEGER:
181 return_btype = ACPI_BTYPE_INTEGER;
182 break;
183
184 case ACPI_TYPE_BUFFER:
185 return_btype = ACPI_BTYPE_BUFFER;
186 break;
187
188 case ACPI_TYPE_STRING:
189 return_btype = ACPI_BTYPE_STRING;
190 break;
191
192 case ACPI_TYPE_PACKAGE:
193 return_btype = ACPI_BTYPE_PACKAGE;
194 break;
195
196 default:
197 return_btype = 0;
198 break;
199 }
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 /*
203 * We received a return object, but one was not expected. This can
204 * happen frequently if the "implicit return" feature is enabled.
205 * Just delete the return object and return AE_OK.
206 */
Len Brown4be44fc2005-08-05 00:44:28 -0400207 acpi_ut_remove_reference(info.return_object);
208 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210
211 /* Is the return object one of the expected types? */
212
213 if (!(expected_return_btypes & return_btype)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500214 ACPI_REPORT_MTERROR("Return object type is incorrect",
215 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Bob Moore4a90c7e2006-01-13 16:22:00 -0500217 ACPI_REPORT_ERROR(("Type returned from %s was incorrect: %s, expected Btypes: %X\n", path, acpi_ut_get_object_type_name(info.return_object), expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 /* On error exit, we must delete the return object */
220
Len Brown4be44fc2005-08-05 00:44:28 -0400221 acpi_ut_remove_reference(info.return_object);
222 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224
225 /* Object type is OK, return it */
226
227 *return_desc = info.return_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400228 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231/*******************************************************************************
232 *
233 * FUNCTION: acpi_ut_evaluate_numeric_object
234 *
Robert Moore44f6c012005-04-18 22:49:35 -0400235 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 * device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400237 * Address - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 *
239 * RETURN: Status
240 *
241 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
242 * and stores result in *Address.
243 *
244 * NOTE: Internal function, no parameter validation
245 *
246 ******************************************************************************/
247
248acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400249acpi_ut_evaluate_numeric_object(char *object_name,
250 struct acpi_namespace_node *device_node,
251 acpi_integer * address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Len Brown4be44fc2005-08-05 00:44:28 -0400253 union acpi_operand_object *obj_desc;
254 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 ACPI_FUNCTION_TRACE("ut_evaluate_numeric_object");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 status = acpi_ut_evaluate_object(device_node, object_name,
259 ACPI_BTYPE_INTEGER, &obj_desc);
260 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 }
263
264 /* Get the returned Integer */
265
266 *address = obj_desc->integer.value;
267
268 /* On exit, we must delete the return object */
269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 acpi_ut_remove_reference(obj_desc);
271 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272}
273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274/*******************************************************************************
275 *
276 * FUNCTION: acpi_ut_copy_id_string
277 *
278 * PARAMETERS: Destination - Where to copy the string
279 * Source - Source string
280 * max_length - Length of the destination buffer
281 *
282 * RETURN: None
283 *
284 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
285 * Performs removal of a leading asterisk if present -- workaround
286 * for a known issue on a bunch of machines.
287 *
288 ******************************************************************************/
289
290static void
Len Brown4be44fc2005-08-05 00:44:28 -0400291acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 /*
295 * Workaround for ID strings that have a leading asterisk. This construct
296 * is not allowed by the ACPI specification (ID strings must be
297 * alphanumeric), but enough existing machines have this embedded in their
298 * ID strings that the following code is useful.
299 */
300 if (*source == '*') {
301 source++;
302 }
303
304 /* Do the actual copy */
305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 ACPI_STRNCPY(destination, source, max_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309/*******************************************************************************
310 *
311 * FUNCTION: acpi_ut_execute_HID
312 *
313 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400314 * Hid - Where the HID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 *
316 * RETURN: Status
317 *
318 * DESCRIPTION: Executes the _HID control method that returns the hardware
319 * ID of the device.
320 *
321 * NOTE: Internal function, no parameter validation
322 *
323 ******************************************************************************/
324
325acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400326acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
327 struct acpi_device_id *hid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328{
Len Brown4be44fc2005-08-05 00:44:28 -0400329 union acpi_operand_object *obj_desc;
330 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 ACPI_FUNCTION_TRACE("ut_execute_HID");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Len Brown4be44fc2005-08-05 00:44:28 -0400334 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
335 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
336 &obj_desc);
337 if (ACPI_FAILURE(status)) {
338 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
340
Len Brown4be44fc2005-08-05 00:44:28 -0400341 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 /* Convert the Numeric HID to string */
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
345 hid->value);
346 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* Copy the String HID from the returned object */
348
Len Brown4be44fc2005-08-05 00:44:28 -0400349 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
350 sizeof(hid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352
353 /* On exit, we must delete the return object */
354
Len Brown4be44fc2005-08-05 00:44:28 -0400355 acpi_ut_remove_reference(obj_desc);
356 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359/*******************************************************************************
360 *
361 * FUNCTION: acpi_ut_translate_one_cid
362 *
363 * PARAMETERS: obj_desc - _CID object, must be integer or string
364 * one_cid - Where the CID string is returned
365 *
366 * RETURN: Status
367 *
368 * DESCRIPTION: Return a numeric or string _CID value as a string.
369 * (Compatible ID)
370 *
371 * NOTE: Assumes a maximum _CID string length of
372 * ACPI_MAX_CID_LENGTH.
373 *
374 ******************************************************************************/
375
376static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400377acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
378 struct acpi_compatible_id *one_cid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 case ACPI_TYPE_INTEGER:
383
384 /* Convert the Numeric CID to string */
385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
387 one_cid->value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 return (AE_OK);
389
390 case ACPI_TYPE_STRING:
391
392 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
393 return (AE_AML_STRING_LIMIT);
394 }
395
396 /* Copy the String CID from the returned object */
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
399 ACPI_MAX_CID_LENGTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 return (AE_OK);
401
402 default:
403
404 return (AE_TYPE);
405 }
406}
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408/*******************************************************************************
409 *
410 * FUNCTION: acpi_ut_execute_CID
411 *
412 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400413 * return_cid_list - Where the CID list is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 *
415 * RETURN: Status
416 *
417 * DESCRIPTION: Executes the _CID control method that returns one or more
418 * compatible hardware IDs for the device.
419 *
420 * NOTE: Internal function, no parameter validation
421 *
422 ******************************************************************************/
423
424acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400425acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
426 struct acpi_compatible_id_list ** return_cid_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
Len Brown4be44fc2005-08-05 00:44:28 -0400428 union acpi_operand_object *obj_desc;
429 acpi_status status;
430 u32 count;
431 u32 size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 struct acpi_compatible_id_list *cid_list;
Len Brown4be44fc2005-08-05 00:44:28 -0400433 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Len Brown4be44fc2005-08-05 00:44:28 -0400435 ACPI_FUNCTION_TRACE("ut_execute_CID");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437 /* Evaluate the _CID method for this device */
438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
440 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
441 | ACPI_BTYPE_PACKAGE, &obj_desc);
442 if (ACPI_FAILURE(status)) {
443 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 }
445
446 /* Get the number of _CIDs returned */
447
448 count = 1;
Len Brown4be44fc2005-08-05 00:44:28 -0400449 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 count = obj_desc->package.count;
451 }
452
453 /* Allocate a worst-case buffer for the _CIDs */
454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
456 sizeof(struct acpi_compatible_id_list));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Len Brown4be44fc2005-08-05 00:44:28 -0400458 cid_list = ACPI_MEM_CALLOCATE((acpi_size) size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 if (!cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400460 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 }
462
463 /* Init CID list */
464
465 cid_list->count = count;
466 cid_list->size = size;
467
468 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400469 * A _CID can return either a single compatible ID or a package of
470 * compatible IDs. Each compatible ID can be one of the following:
471 * 1) Integer (32 bit compressed EISA ID) or
472 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 */
474
475 /* The _CID object can be either a single CID or a package (list) of CIDs */
476
Len Brown4be44fc2005-08-05 00:44:28 -0400477 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 /* Translate each package element */
479
480 for (i = 0; i < count; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400481 status =
482 acpi_ut_translate_one_cid(obj_desc->package.
483 elements[i],
484 &cid_list->id[i]);
485 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
487 }
488 }
Len Brown4be44fc2005-08-05 00:44:28 -0400489 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* Only one CID, translate to a string */
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494
495 /* Cleanup on error */
496
Len Brown4be44fc2005-08-05 00:44:28 -0400497 if (ACPI_FAILURE(status)) {
498 ACPI_MEM_FREE(cid_list);
499 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 *return_cid_list = cid_list;
501 }
502
503 /* On exit, we must delete the _CID return object */
504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 acpi_ut_remove_reference(obj_desc);
506 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509/*******************************************************************************
510 *
511 * FUNCTION: acpi_ut_execute_UID
512 *
513 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400514 * Uid - Where the UID is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 *
516 * RETURN: Status
517 *
518 * DESCRIPTION: Executes the _UID control method that returns the hardware
519 * ID of the device.
520 *
521 * NOTE: Internal function, no parameter validation
522 *
523 ******************************************************************************/
524
525acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400526acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
527 struct acpi_device_id *uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Len Brown4be44fc2005-08-05 00:44:28 -0400529 union acpi_operand_object *obj_desc;
530 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Len Brown4be44fc2005-08-05 00:44:28 -0400532 ACPI_FUNCTION_TRACE("ut_execute_UID");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Len Brown4be44fc2005-08-05 00:44:28 -0400534 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
535 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
536 &obj_desc);
537 if (ACPI_FAILURE(status)) {
538 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /* Convert the Numeric UID to string */
543
Len Brown4be44fc2005-08-05 00:44:28 -0400544 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
545 uid->value);
546 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 /* Copy the String UID from the returned object */
548
Len Brown4be44fc2005-08-05 00:44:28 -0400549 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
550 sizeof(uid->value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
553 /* On exit, we must delete the return object */
554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 acpi_ut_remove_reference(obj_desc);
556 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559/*******************************************************************************
560 *
561 * FUNCTION: acpi_ut_execute_STA
562 *
563 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400564 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 *
566 * RETURN: Status
567 *
568 * DESCRIPTION: Executes _STA for selected device and stores results in
569 * *Flags.
570 *
571 * NOTE: Internal function, no parameter validation
572 *
573 ******************************************************************************/
574
575acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400576acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
Len Brown4be44fc2005-08-05 00:44:28 -0400578 union acpi_operand_object *obj_desc;
579 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Len Brown4be44fc2005-08-05 00:44:28 -0400581 ACPI_FUNCTION_TRACE("ut_execute_STA");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Len Brown4be44fc2005-08-05 00:44:28 -0400583 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
584 ACPI_BTYPE_INTEGER, &obj_desc);
585 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 if (AE_NOT_FOUND == status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400587 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
588 "_STA on %4.4s was not found, assuming device is present\n",
589 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Bob Mooredefba1d2005-12-16 17:05:00 -0500591 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 status = AE_OK;
593 }
594
Len Brown4be44fc2005-08-05 00:44:28 -0400595 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 }
597
598 /* Extract the status flags */
599
600 *flags = (u32) obj_desc->integer.value;
601
602 /* On exit, we must delete the return object */
603
Len Brown4be44fc2005-08-05 00:44:28 -0400604 acpi_ut_remove_reference(obj_desc);
605 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606}
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608/*******************************************************************************
609 *
610 * FUNCTION: acpi_ut_execute_Sxds
611 *
612 * PARAMETERS: device_node - Node for the device
Robert Moore44f6c012005-04-18 22:49:35 -0400613 * Flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 *
615 * RETURN: Status
616 *
617 * DESCRIPTION: Executes _STA for selected device and stores results in
618 * *Flags.
619 *
620 * NOTE: Internal function, no parameter validation
621 *
622 ******************************************************************************/
623
624acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400625acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626{
Len Brown4be44fc2005-08-05 00:44:28 -0400627 union acpi_operand_object *obj_desc;
628 acpi_status status;
629 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 ACPI_FUNCTION_TRACE("ut_execute_Sxds");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 for (i = 0; i < 4; i++) {
634 highest[i] = 0xFF;
Len Brown4be44fc2005-08-05 00:44:28 -0400635 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500636 ACPI_CAST_PTR(char,
637 acpi_gbl_highest_dstate_names
638 [i]),
639 ACPI_BTYPE_INTEGER, &obj_desc);
Len Brown4be44fc2005-08-05 00:44:28 -0400640 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 if (status != AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -0400642 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
643 "%s on Device %4.4s, %s\n",
Bob Mooredefba1d2005-12-16 17:05:00 -0500644 ACPI_CAST_PTR(char,
645 acpi_gbl_highest_dstate_names
646 [i]),
Len Brown4be44fc2005-08-05 00:44:28 -0400647 acpi_ut_get_node_name
648 (device_node),
649 acpi_format_exception
650 (status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Len Brown4be44fc2005-08-05 00:44:28 -0400652 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
Len Brown4be44fc2005-08-05 00:44:28 -0400654 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 /* Extract the Dstate value */
656
657 highest[i] = (u8) obj_desc->integer.value;
658
659 /* Delete the return object */
660
Len Brown4be44fc2005-08-05 00:44:28 -0400661 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 }
663 }
664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}