blob: 3fce7519c6902fcad2c65e9cda915611496d1087 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 *
5 *****************************************************************************/
6
7/*
Bob Moore7735ca02017-02-08 11:00:08 +08008 * Copyright (C) 2000 - 2017, 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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
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
Len Brownae00d812007-05-29 18:43:33 -040051/*******************************************************************************
52 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * FUNCTION: acpi_ut_evaluate_object
54 *
55 * PARAMETERS: prefix_node - Starting node
Bob Mooreba494be2012-07-12 09:40:10 +080056 * path - Path to object from starting node
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * expected_return_types - Bitmap of allowed return types
58 * return_desc - Where a return value is stored
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
Bob Moore15b8dd52009-06-29 13:39:29 +080063 * return object. Common code that simplifies accessing objects
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * that have required return objects of fixed types.
65 *
66 * NOTE: Internal function, no parameter validation
67 *
68 ******************************************************************************/
69
70acpi_status
Bob Mooreb6872ff2013-06-08 00:58:00 +000071acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
Bob Moore0dfaaa32016-03-24 09:40:40 +080072 const char *path,
Len Brown4be44fc2005-08-05 00:44:28 -040073 u32 expected_return_btypes,
74 union acpi_operand_object **return_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Bob Moore41195322006-05-26 16:36:00 -040076 struct acpi_evaluate_info *info;
Len Brown4be44fc2005-08-05 00:44:28 -040077 acpi_status status;
78 u32 return_btype;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Bob Mooreb229cf92006-04-21 17:15:00 -040080 ACPI_FUNCTION_TRACE(ut_evaluate_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Bob Moore41195322006-05-26 16:36:00 -040082 /* Allocate the evaluation information block */
83
84 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
85 if (!info) {
86 return_ACPI_STATUS(AE_NO_MEMORY);
87 }
88
89 info->prefix_node = prefix_node;
Bob Moore29a241c2013-05-30 10:00:01 +080090 info->relative_pathname = path;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /* Evaluate the object/method */
93
Bob Moore41195322006-05-26 16:36:00 -040094 status = acpi_ns_evaluate(info);
Len Brown4be44fc2005-08-05 00:44:28 -040095 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 if (status == AE_NOT_FOUND) {
Len Brown4be44fc2005-08-05 00:44:28 -040097 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
98 "[%4.4s.%s] was not found\n",
99 acpi_ut_get_node_name(prefix_node),
100 path));
101 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500102 ACPI_ERROR_METHOD("Method execution failed",
103 prefix_node, path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
Bob Moore41195322006-05-26 16:36:00 -0400106 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
109 /* Did we get a return object? */
110
Bob Moore41195322006-05-26 16:36:00 -0400111 if (!info->return_object) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 if (expected_return_btypes) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500113 ACPI_ERROR_METHOD("No object was returned from",
114 prefix_node, path, AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Bob Moore41195322006-05-26 16:36:00 -0400116 status = AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118
Bob Moore41195322006-05-26 16:36:00 -0400119 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
122 /* Map the return object type to the bitmapped type */
123
Bob Moore3371c192009-02-18 14:44:03 +0800124 switch ((info->return_object)->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 case ACPI_TYPE_INTEGER:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return_btype = ACPI_BTYPE_INTEGER;
128 break;
129
130 case ACPI_TYPE_BUFFER:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 return_btype = ACPI_BTYPE_BUFFER;
133 break;
134
135 case ACPI_TYPE_STRING:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return_btype = ACPI_BTYPE_STRING;
138 break;
139
140 case ACPI_TYPE_PACKAGE:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 return_btype = ACPI_BTYPE_PACKAGE;
143 break;
144
145 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 return_btype = 0;
148 break;
149 }
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /*
Bob Moore15b8dd52009-06-29 13:39:29 +0800153 * We received a return object, but one was not expected. This can
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 * happen frequently if the "implicit return" feature is enabled.
155 * Just delete the return object and return AE_OK.
156 */
Bob Moore41195322006-05-26 16:36:00 -0400157 acpi_ut_remove_reference(info->return_object);
158 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
161 /* Is the return object one of the expected types? */
162
163 if (!(expected_return_btypes & return_btype)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500164 ACPI_ERROR_METHOD("Return object type is incorrect",
165 prefix_node, path, AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Bob Mooreb8e4d892006-01-27 16:43:00 -0500167 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800168 "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500169 path,
Bob Moore41195322006-05-26 16:36:00 -0400170 acpi_ut_get_object_type_name(info->return_object),
Bob Mooreb8e4d892006-01-27 16:43:00 -0500171 expected_return_btypes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 /* On error exit, we must delete the return object */
174
Bob Moore41195322006-05-26 16:36:00 -0400175 acpi_ut_remove_reference(info->return_object);
176 status = AE_TYPE;
177 goto cleanup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179
180 /* Object type is OK, return it */
181
Bob Moore41195322006-05-26 16:36:00 -0400182 *return_desc = info->return_object;
183
Lv Zheng10622bf2013-10-29 09:30:02 +0800184cleanup:
Bob Moore41195322006-05-26 16:36:00 -0400185 ACPI_FREE(info);
186 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187}
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/*******************************************************************************
190 *
191 * FUNCTION: acpi_ut_evaluate_numeric_object
192 *
Robert Moore44f6c012005-04-18 22:49:35 -0400193 * PARAMETERS: object_name - Object name to be evaluated
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 * device_node - Node for the device
Bob Mooreba494be2012-07-12 09:40:10 +0800195 * value - Where the value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 *
197 * RETURN: Status
198 *
199 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
Bob Moore15b8dd52009-06-29 13:39:29 +0800200 * and stores result in *Value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 *
202 * NOTE: Internal function, no parameter validation
203 *
204 ******************************************************************************/
205
206acpi_status
Bob Moore0dfaaa32016-03-24 09:40:40 +0800207acpi_ut_evaluate_numeric_object(const char *object_name,
Len Brown4be44fc2005-08-05 00:44:28 -0400208 struct acpi_namespace_node *device_node,
Bob Moore5df7e6c2010-01-21 10:06:32 +0800209 u64 *value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Len Brown4be44fc2005-08-05 00:44:28 -0400211 union acpi_operand_object *obj_desc;
212 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Bob Mooreb229cf92006-04-21 17:15:00 -0400214 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 status = acpi_ut_evaluate_object(device_node, object_name,
217 ACPI_BTYPE_INTEGER, &obj_desc);
218 if (ACPI_FAILURE(status)) {
219 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
221
222 /* Get the returned Integer */
223
Bob Moore15b8dd52009-06-29 13:39:29 +0800224 *value = obj_desc->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /* On exit, we must delete the return object */
227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 acpi_ut_remove_reference(obj_desc);
229 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232/*******************************************************************************
233 *
234 * FUNCTION: acpi_ut_execute_STA
235 *
236 * PARAMETERS: device_node - Node for the device
Bob Mooreba494be2012-07-12 09:40:10 +0800237 * flags - Where the status flags are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 *
239 * RETURN: Status
240 *
241 * DESCRIPTION: Executes _STA for selected device and stores results in
Bob Moorea7d5caf2013-07-17 09:48:15 +0800242 * *Flags. If _STA does not exist, then the device is assumed
243 * to be present/functional/enabled (as per the ACPI spec).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 *
245 * NOTE: Internal function, no parameter validation
246 *
247 ******************************************************************************/
248
249acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400250acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Len Brown4be44fc2005-08-05 00:44:28 -0400252 union acpi_operand_object *obj_desc;
253 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Bob Mooreb229cf92006-04-21 17:15:00 -0400255 ACPI_FUNCTION_TRACE(ut_execute_STA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
258 ACPI_BTYPE_INTEGER, &obj_desc);
259 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 if (AE_NOT_FOUND == status) {
Bob Moorea7d5caf2013-07-17 09:48:15 +0800261 /*
262 * if _STA does not exist, then (as per the ACPI specification),
263 * the returned flags will indicate that the device is present,
264 * functional, and enabled.
265 */
Len Brown4be44fc2005-08-05 00:44:28 -0400266 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
267 "_STA on %4.4s was not found, assuming device is present\n",
268 acpi_ut_get_node_name(device_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Bob Mooredefba1d2005-12-16 17:05:00 -0500270 *flags = ACPI_UINT32_MAX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 status = AE_OK;
272 }
273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276
277 /* Extract the status flags */
278
279 *flags = (u32) obj_desc->integer.value;
280
281 /* On exit, we must delete the return object */
282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 acpi_ut_remove_reference(obj_desc);
284 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287/*******************************************************************************
288 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800289 * FUNCTION: acpi_ut_execute_power_methods
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 *
291 * PARAMETERS: device_node - Node for the device
Bob Moore15b8dd52009-06-29 13:39:29 +0800292 * method_names - Array of power method names
293 * method_count - Number of methods to execute
294 * out_values - Where the power method values are returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800296 * RETURN: Status, out_values
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800298 * DESCRIPTION: Executes the specified power methods for the device and returns
299 * the result(s).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 *
301 * NOTE: Internal function, no parameter validation
302 *
Bob Moore15b8dd52009-06-29 13:39:29 +0800303******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
305acpi_status
Bob Moore15b8dd52009-06-29 13:39:29 +0800306acpi_ut_execute_power_methods(struct acpi_namespace_node *device_node,
307 const char **method_names,
308 u8 method_count, u8 *out_values)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Len Brown4be44fc2005-08-05 00:44:28 -0400310 union acpi_operand_object *obj_desc;
311 acpi_status status;
Bob Moore15b8dd52009-06-29 13:39:29 +0800312 acpi_status final_status = AE_NOT_FOUND;
Len Brown4be44fc2005-08-05 00:44:28 -0400313 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Bob Moore15b8dd52009-06-29 13:39:29 +0800315 ACPI_FUNCTION_TRACE(ut_execute_power_methods);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Bob Moore15b8dd52009-06-29 13:39:29 +0800317 for (i = 0; i < method_count; i++) {
318 /*
319 * Execute the power method (_sx_d or _sx_w). The only allowable
320 * return type is an Integer.
321 */
Len Brown4be44fc2005-08-05 00:44:28 -0400322 status = acpi_ut_evaluate_object(device_node,
Bob Mooredefba1d2005-12-16 17:05:00 -0500323 ACPI_CAST_PTR(char,
Bob Moore15b8dd52009-06-29 13:39:29 +0800324 method_names[i]),
Bob Mooredefba1d2005-12-16 17:05:00 -0500325 ACPI_BTYPE_INTEGER, &obj_desc);
Bob Moore15b8dd52009-06-29 13:39:29 +0800326 if (ACPI_SUCCESS(status)) {
327 out_values[i] = (u8)obj_desc->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 /* Delete the return object */
330
Len Brown4be44fc2005-08-05 00:44:28 -0400331 acpi_ut_remove_reference(obj_desc);
Bob Moore15b8dd52009-06-29 13:39:29 +0800332 final_status = AE_OK; /* At least one value is valid */
333 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 }
Bob Moore15b8dd52009-06-29 13:39:29 +0800335
336 out_values[i] = ACPI_UINT8_MAX;
337 if (status == AE_NOT_FOUND) {
338 continue; /* Ignore if not found */
339 }
340
341 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
342 "Failed %s on Device %4.4s, %s\n",
343 ACPI_CAST_PTR(char, method_names[i]),
344 acpi_ut_get_node_name(device_node),
345 acpi_format_exception(status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347
Bob Moore15b8dd52009-06-29 13:39:29 +0800348 return_ACPI_STATUS(final_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}