blob: ee2ee2c858f2eb3735eb136d85cfb225953f56fb [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: psxface - Parser external interfaces
5 *
Bob Moore840c02c2019-01-14 09:55:25 -08006 * Copyright (C) 2000 - 2019, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
12#include "acparser.h"
13#include "acdispat.h"
14#include "acinterp.h"
Lin Ming69ec87e2010-04-01 11:14:12 +080015#include "actables.h"
Lv Zhengab6c5732015-07-23 12:52:59 +080016#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#define _COMPONENT ACPI_PARSER
Len Brown4be44fc2005-08-05 00:44:28 -040019ACPI_MODULE_NAME("psxface")
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Robert Moore0c9938c2005-07-29 15:15:00 -070021/* Local Prototypes */
Robert Moore0c9938c2005-07-29 15:15:00 -070022static void
Bob Moore41195322006-05-26 16:36:00 -040023acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
25/*******************************************************************************
26 *
Bob Moore50eca3e2005-09-30 19:03:00 -040027 * FUNCTION: acpi_debug_trace
28 *
29 * PARAMETERS: method_name - Valid ACPI name string
30 * debug_level - Optional level mask. 0 to use default
31 * debug_layer - Optional layer mask. 0 to use default
Bob Mooreba494be2012-07-12 09:40:10 +080032 * flags - bit 1: one shot(1) or persistent(0)
Bob Moore50eca3e2005-09-30 19:03:00 -040033 *
34 * RETURN: Status
35 *
36 * DESCRIPTION: External interface to enable debug tracing during control
37 * method execution
38 *
39 ******************************************************************************/
40
41acpi_status
Lv Zhengab6c5732015-07-23 12:52:59 +080042acpi_debug_trace(const char *name, u32 debug_level, u32 debug_layer, u32 flags)
Bob Moore50eca3e2005-09-30 19:03:00 -040043{
44 acpi_status status;
45
46 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
47 if (ACPI_FAILURE(status)) {
48 return (status);
49 }
50
Lv Zhengab6c5732015-07-23 12:52:59 +080051 acpi_gbl_trace_method_name = name;
Bob Moore50eca3e2005-09-30 19:03:00 -040052 acpi_gbl_trace_flags = flags;
Lv Zhengab6c5732015-07-23 12:52:59 +080053 acpi_gbl_trace_dbg_level = debug_level;
54 acpi_gbl_trace_dbg_layer = debug_layer;
55 status = AE_OK;
Bob Moore50eca3e2005-09-30 19:03:00 -040056
57 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Lv Zhengab6c5732015-07-23 12:52:59 +080058 return (status);
Bob Moore50eca3e2005-09-30 19:03:00 -040059}
60
61/*******************************************************************************
62 *
Robert Moore0c9938c2005-07-29 15:15:00 -070063 * FUNCTION: acpi_ps_execute_method
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 *
Bob Mooreba494be2012-07-12 09:40:10 +080065 * PARAMETERS: info - Method info block, contains:
66 * node - Method Node to execute
Robert Moore0c9938c2005-07-29 15:15:00 -070067 * obj_desc - Method object
Bob Mooreba494be2012-07-12 09:40:10 +080068 * parameters - List of parameters to pass to the method,
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 * terminated by NULL. Params itself may be
70 * NULL if no parameters are being passed.
Robert Moore44f6c012005-04-18 22:49:35 -040071 * return_object - Where to put method's return value (if
72 * any). If NULL, no value is returned.
73 * parameter_type - Type of Parameter list
74 * return_object - Where to put method's return value (if
75 * any). If NULL, no value is returned.
Robert Moore0c9938c2005-07-29 15:15:00 -070076 * pass_number - Parse or execute pass
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 *
78 * RETURN: Status
79 *
80 * DESCRIPTION: Execute a control method
81 *
82 ******************************************************************************/
83
Lv Zhengf5c1e1c2016-05-05 12:57:53 +080084acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Len Brown4be44fc2005-08-05 00:44:28 -040086 acpi_status status;
Valery Podrezov9bc75cf2007-02-02 19:48:21 +030087 union acpi_parse_object *op;
88 struct acpi_walk_state *walk_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Mooreb229cf92006-04-21 17:15:00 -040090 ACPI_FUNCTION_TRACE(ps_execute_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Lin Ming729df0f2010-04-01 10:47:56 +080092 /* Quick validation of DSDT header */
93
94 acpi_tb_check_dsdt_header();
95
Robert Moore0c9938c2005-07-29 15:15:00 -070096 /* Validate the Info and method Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Bob Moore29a241c2013-05-30 10:00:01 +080098 if (!info || !info->node) {
Len Brown4be44fc2005-08-05 00:44:28 -040099 return_ACPI_STATUS(AE_NULL_ENTRY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 }
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /* Init for new method, wait on concurrency semaphore */
103
Len Brown4be44fc2005-08-05 00:44:28 -0400104 status =
Bob Moore29a241c2013-05-30 10:00:01 +0800105 acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400106 if (ACPI_FAILURE(status)) {
107 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 }
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /*
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300111 * The caller "owns" the parameters, so give each one an extra reference
Robert Moore0c9938c2005-07-29 15:15:00 -0700112 */
Len Brown4be44fc2005-08-05 00:44:28 -0400113 acpi_ps_update_parameter_list(info, REF_INCREMENT);
Robert Moore0c9938c2005-07-29 15:15:00 -0700114
115 /*
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300116 * Execute the method. Performs parse simultaneously
Robert Moore0c9938c2005-07-29 15:15:00 -0700117 */
Len Brown4be44fc2005-08-05 00:44:28 -0400118 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300119 "**** Begin Method Parse/Execute [%4.4s] **** Node=%p Obj=%p\n",
Bob Moore29a241c2013-05-30 10:00:01 +0800120 info->node->name.ascii, info->node, info->obj_desc));
Robert Moore0c9938c2005-07-29 15:15:00 -0700121
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300122 /* Create and init a Root Node */
123
Lv Zheng62eb9352015-07-23 12:52:24 +0800124 op = acpi_ps_create_scope_op(info->obj_desc->method.aml_start);
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300125 if (!op) {
126 status = AE_NO_MEMORY;
Robert Moore0c9938c2005-07-29 15:15:00 -0700127 goto cleanup;
128 }
129
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300130 /* Create and initialize a new walk state */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Bob Mooreec3153f2007-02-02 19:48:21 +0300132 info->pass_number = ACPI_IMODE_EXECUTE;
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300133 walk_state =
134 acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
135 NULL, NULL);
136 if (!walk_state) {
137 status = AE_NO_MEMORY;
138 goto cleanup;
139 }
140
Bob Moore29a241c2013-05-30 10:00:01 +0800141 status = acpi_ds_init_aml_walk(walk_state, op, info->node,
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300142 info->obj_desc->method.aml_start,
143 info->obj_desc->method.aml_length, info,
144 info->pass_number);
145 if (ACPI_FAILURE(status)) {
146 acpi_ds_delete_walk_state(walk_state);
147 goto cleanup;
148 }
149
Bob Moore4c1379d2018-12-13 12:30:33 -0800150 walk_state->method_pathname = info->full_pathname;
151 walk_state->method_is_nested = FALSE;
152
Lin Ming26294842011-01-12 09:19:43 +0800153 if (info->obj_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) {
Lin Ming7f0c8262009-08-13 14:03:15 +0800154 walk_state->parse_flags |= ACPI_PARSE_MODULE_LEVEL;
155 }
156
Bob Moorea8fadc92008-11-13 09:45:35 +0800157 /* Invoke an internal method if necessary */
158
Lin Ming26294842011-01-12 09:19:43 +0800159 if (info->obj_desc->method.info_flags & ACPI_METHOD_INTERNAL_ONLY) {
Lin Minge31c32c2009-12-11 15:28:27 +0800160 status =
Lin Ming26294842011-01-12 09:19:43 +0800161 info->obj_desc->method.dispatch.implementation(walk_state);
Bob Moorea8fadc92008-11-13 09:45:35 +0800162 info->return_object = walk_state->return_desc;
163
164 /* Cleanup states */
165
166 acpi_ds_scope_stack_clear(walk_state);
167 acpi_ps_cleanup_scope(&walk_state->parser_state);
168 acpi_ds_terminate_control_method(walk_state->method_desc,
169 walk_state);
170 acpi_ds_delete_walk_state(walk_state);
171 goto cleanup;
172 }
173
Lin Ming7a4b81312008-11-13 11:25:22 +0800174 /*
175 * Start method evaluation with an implicit return of zero.
176 * This is done for Windows compatibility.
177 */
178 if (acpi_gbl_enable_interpreter_slack) {
179 walk_state->implicit_return_obj =
Bob Mooredc95a272009-11-12 09:52:45 +0800180 acpi_ut_create_integer_object((u64) 0);
Lin Ming7a4b81312008-11-13 11:25:22 +0800181 if (!walk_state->implicit_return_obj) {
182 status = AE_NO_MEMORY;
183 acpi_ds_delete_walk_state(walk_state);
184 goto cleanup;
185 }
Lin Ming7a4b81312008-11-13 11:25:22 +0800186 }
187
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300188 /* Parse the AML */
189
190 status = acpi_ps_parse_aml(walk_state);
191
192 /* walk_state was deleted by parse_aml */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Lv Zheng10622bf2013-10-29 09:30:02 +0800194cleanup:
Valery Podrezov9bc75cf2007-02-02 19:48:21 +0300195 acpi_ps_delete_parse_tree(op);
196
Robert Moore0c9938c2005-07-29 15:15:00 -0700197 /* Take away the extra reference that we gave the parameters above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Len Brown4be44fc2005-08-05 00:44:28 -0400199 acpi_ps_update_parameter_list(info, REF_DECREMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Robert Moore0c9938c2005-07-29 15:15:00 -0700201 /* Exit now if error above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 if (ACPI_FAILURE(status)) {
204 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
207 /*
208 * If the method has returned an object, signal this to the caller with
209 * a control exception code
210 */
211 if (info->return_object) {
Bob Mooreb229cf92006-04-21 17:15:00 -0400212 ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Method returned ObjDesc=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400213 info->return_object));
214 ACPI_DUMP_STACK_ENTRY(info->return_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 status = AE_CTRL_RETURN_VALUE;
217 }
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Robert Moore0c9938c2005-07-29 15:15:00 -0700222/*******************************************************************************
223 *
Lv Zhengde56ba92016-09-07 14:06:54 +0800224 * FUNCTION: acpi_ps_execute_table
225 *
226 * PARAMETERS: info - Method info block, contains:
227 * node - Node to where the is entered into the
228 * namespace
229 * obj_desc - Pseudo method object describing the AML
230 * code of the entire table
231 * pass_number - Parse or execute pass
232 *
233 * RETURN: Status
234 *
235 * DESCRIPTION: Execute a table
236 *
237 ******************************************************************************/
238
239acpi_status acpi_ps_execute_table(struct acpi_evaluate_info *info)
240{
241 acpi_status status;
242 union acpi_parse_object *op = NULL;
243 struct acpi_walk_state *walk_state = NULL;
244
245 ACPI_FUNCTION_TRACE(ps_execute_table);
246
247 /* Create and init a Root Node */
248
249 op = acpi_ps_create_scope_op(info->obj_desc->method.aml_start);
250 if (!op) {
251 status = AE_NO_MEMORY;
252 goto cleanup;
253 }
254
255 /* Create and initialize a new walk state */
256
257 walk_state =
258 acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
259 NULL, NULL);
260 if (!walk_state) {
261 status = AE_NO_MEMORY;
262 goto cleanup;
263 }
264
265 status = acpi_ds_init_aml_walk(walk_state, op, info->node,
266 info->obj_desc->method.aml_start,
267 info->obj_desc->method.aml_length, info,
268 info->pass_number);
269 if (ACPI_FAILURE(status)) {
270 goto cleanup;
271 }
272
Bob Moore4c1379d2018-12-13 12:30:33 -0800273 walk_state->method_pathname = info->full_pathname;
274 walk_state->method_is_nested = FALSE;
275
Lv Zhengde56ba92016-09-07 14:06:54 +0800276 if (info->obj_desc->method.info_flags & ACPI_METHOD_MODULE_LEVEL) {
277 walk_state->parse_flags |= ACPI_PARSE_MODULE_LEVEL;
278 }
279
Lv Zheng7a0b71d2016-09-23 11:26:43 +0800280 /* Info->Node is the default location to load the table */
281
282 if (info->node && info->node != acpi_gbl_root_node) {
283 status =
284 acpi_ds_scope_stack_push(info->node, ACPI_TYPE_METHOD,
285 walk_state);
286 if (ACPI_FAILURE(status)) {
287 goto cleanup;
288 }
289 }
290
Lv Zhengde56ba92016-09-07 14:06:54 +0800291 /*
292 * Parse the AML, walk_state will be deleted by parse_aml
293 */
Lv Zheng74f51b82016-09-07 14:07:10 +0800294 acpi_ex_enter_interpreter();
Lv Zhengde56ba92016-09-07 14:06:54 +0800295 status = acpi_ps_parse_aml(walk_state);
Lv Zheng74f51b82016-09-07 14:07:10 +0800296 acpi_ex_exit_interpreter();
Lv Zhengde56ba92016-09-07 14:06:54 +0800297 walk_state = NULL;
298
299cleanup:
300 if (walk_state) {
301 acpi_ds_delete_walk_state(walk_state);
302 }
303 if (op) {
304 acpi_ps_delete_parse_tree(op);
305 }
306 return_ACPI_STATUS(status);
307}
308
309/*******************************************************************************
310 *
Robert Moore0c9938c2005-07-29 15:15:00 -0700311 * FUNCTION: acpi_ps_update_parameter_list
312 *
Bob Mooreba494be2012-07-12 09:40:10 +0800313 * PARAMETERS: info - See struct acpi_evaluate_info
Robert Moore0c9938c2005-07-29 15:15:00 -0700314 * (Used: parameter_type and Parameters)
Bob Mooreba494be2012-07-12 09:40:10 +0800315 * action - Add or Remove reference
Robert Moore0c9938c2005-07-29 15:15:00 -0700316 *
317 * RETURN: Status
318 *
319 * DESCRIPTION: Update reference count on all method parameter objects
320 *
321 ******************************************************************************/
322
323static void
Bob Moore41195322006-05-26 16:36:00 -0400324acpi_ps_update_parameter_list(struct acpi_evaluate_info *info, u16 action)
Robert Moore0c9938c2005-07-29 15:15:00 -0700325{
Bob Moore67a119f2008-06-10 13:42:13 +0800326 u32 i;
Robert Moore0c9938c2005-07-29 15:15:00 -0700327
Bob Moorec91d9242008-06-10 12:38:10 +0800328 if (info->parameters) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400329
Robert Moore0c9938c2005-07-29 15:15:00 -0700330 /* Update reference count for each parameter */
331
332 for (i = 0; info->parameters[i]; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400333
Robert Moore0c9938c2005-07-29 15:15:00 -0700334 /* Ignore errors, just do them all */
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 (void)acpi_ut_update_object_reference(info->
337 parameters[i],
338 action);
Robert Moore0c9938c2005-07-29 15:15:00 -0700339 }
340 }
341}