1 /******************************************************************************
3 * Module Name: psxface - Parser external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/acdispat.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/acnamesp.h>
52 #define _COMPONENT ACPI_PARSER
53 ACPI_MODULE_NAME ("psxface")
56 /*******************************************************************************
58 * FUNCTION: acpi_psx_execute
60 * PARAMETERS: Info - Method info block, contains:
61 * Node - Method Node to execute
62 * Parameters - List of parameters to pass to the method,
63 * terminated by NULL. Params itself may be
64 * NULL if no parameters are being passed.
65 * return_object - Where to put method's return value (if
66 * any). If NULL, no value is returned.
67 * parameter_type - Type of Parameter list
68 * return_object - Where to put method's return value (if
69 * any). If NULL, no value is returned.
73 * DESCRIPTION: Execute a control method
75 ******************************************************************************/
79 struct acpi_parameter_info *info)
82 union acpi_operand_object *obj_desc;
84 union acpi_parse_object *op;
85 struct acpi_walk_state *walk_state;
88 ACPI_FUNCTION_TRACE ("psx_execute");
91 /* Validate the Node and get the attached object */
93 if (!info || !info->node) {
94 return_ACPI_STATUS (AE_NULL_ENTRY);
97 obj_desc = acpi_ns_get_attached_object (info->node);
99 return_ACPI_STATUS (AE_NULL_OBJECT);
102 /* Init for new method, wait on concurrency semaphore */
104 status = acpi_ds_begin_method_execution (info->node, obj_desc, NULL);
105 if (ACPI_FAILURE (status)) {
106 return_ACPI_STATUS (status);
109 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
110 (info->parameters)) {
112 * The caller "owns" the parameters, so give each one an extra
115 for (i = 0; info->parameters[i]; i++) {
116 acpi_ut_add_reference (info->parameters[i]);
121 * 1) Perform the first pass parse of the method to enter any
122 * named objects that it creates into the namespace
124 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
125 "**** Begin Method Parse **** Entry=%p obj=%p\n",
126 info->node, obj_desc));
128 /* Create and init a Root Node */
130 op = acpi_ps_create_scope_op ();
132 status = AE_NO_MEMORY;
137 * Get a new owner_id for objects created by this method. Namespace
138 * objects (such as Operation Regions) can be created during the
141 obj_desc->method.owning_id = acpi_ut_allocate_owner_id (ACPI_OWNER_TYPE_METHOD);
143 /* Create and initialize a new walk state */
145 walk_state = acpi_ds_create_walk_state (obj_desc->method.owning_id,
148 status = AE_NO_MEMORY;
152 status = acpi_ds_init_aml_walk (walk_state, op, info->node,
153 obj_desc->method.aml_start,
154 obj_desc->method.aml_length, NULL, 1);
155 if (ACPI_FAILURE (status)) {
161 status = acpi_ps_parse_aml (walk_state);
162 acpi_ps_delete_parse_tree (op);
163 if (ACPI_FAILURE (status)) {
164 goto cleanup1; /* Walk state is already deleted */
168 * 2) Execute the method. Performs second pass parse simultaneously
170 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
171 "**** Begin Method Execution **** Entry=%p obj=%p\n",
172 info->node, obj_desc));
174 /* Create and init a Root Node */
176 op = acpi_ps_create_scope_op ();
178 status = AE_NO_MEMORY;
182 /* Init new op with the method name and pointer back to the NS node */
184 acpi_ps_set_name (op, info->node->name.integer);
185 op->common.node = info->node;
187 /* Create and initialize a new walk state */
189 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
191 status = AE_NO_MEMORY;
195 status = acpi_ds_init_aml_walk (walk_state, op, info->node,
196 obj_desc->method.aml_start,
197 obj_desc->method.aml_length, info, 3);
198 if (ACPI_FAILURE (status)) {
202 /* The walk of the parse tree is where we actually execute the method */
204 status = acpi_ps_parse_aml (walk_state);
205 goto cleanup2; /* Walk state already deleted */
209 acpi_ds_delete_walk_state (walk_state);
212 acpi_ps_delete_parse_tree (op);
215 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
216 (info->parameters)) {
217 /* Take away the extra reference that we gave the parameters above */
219 for (i = 0; info->parameters[i]; i++) {
220 /* Ignore errors, just do them all */
222 (void) acpi_ut_update_object_reference (
223 info->parameters[i], REF_DECREMENT);
227 if (ACPI_FAILURE (status)) {
228 return_ACPI_STATUS (status);
232 * If the method has returned an object, signal this to the caller with
233 * a control exception code
235 if (info->return_object) {
236 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned obj_desc=%p\n",
237 info->return_object));
238 ACPI_DUMP_STACK_ENTRY (info->return_object);
240 status = AE_CTRL_RETURN_VALUE;
243 return_ACPI_STATUS (status);