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 status = acpi_ut_allocate_owner_id (&obj_desc->method.owner_id);
142 if (ACPI_FAILURE (status)) {
146 /* Create and initialize a new walk state */
148 walk_state = acpi_ds_create_walk_state (obj_desc->method.owner_id,
151 status = AE_NO_MEMORY;
155 status = acpi_ds_init_aml_walk (walk_state, op, info->node,
156 obj_desc->method.aml_start,
157 obj_desc->method.aml_length, NULL, 1);
158 if (ACPI_FAILURE (status)) {
164 status = acpi_ps_parse_aml (walk_state);
165 acpi_ps_delete_parse_tree (op);
166 if (ACPI_FAILURE (status)) {
167 goto cleanup1; /* Walk state is already deleted */
171 * 2) Execute the method. Performs second pass parse simultaneously
173 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
174 "**** Begin Method Execution **** Entry=%p obj=%p\n",
175 info->node, obj_desc));
177 /* Create and init a Root Node */
179 op = acpi_ps_create_scope_op ();
181 status = AE_NO_MEMORY;
185 /* Init new op with the method name and pointer back to the NS node */
187 acpi_ps_set_name (op, info->node->name.integer);
188 op->common.node = info->node;
190 /* Create and initialize a new walk state */
192 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
194 status = AE_NO_MEMORY;
198 status = acpi_ds_init_aml_walk (walk_state, op, info->node,
199 obj_desc->method.aml_start,
200 obj_desc->method.aml_length, info, 3);
201 if (ACPI_FAILURE (status)) {
205 /* The walk of the parse tree is where we actually execute the method */
207 status = acpi_ps_parse_aml (walk_state);
208 goto cleanup2; /* Walk state already deleted */
212 acpi_ds_delete_walk_state (walk_state);
215 acpi_ps_delete_parse_tree (op);
218 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
219 (info->parameters)) {
220 /* Take away the extra reference that we gave the parameters above */
222 for (i = 0; info->parameters[i]; i++) {
223 /* Ignore errors, just do them all */
225 (void) acpi_ut_update_object_reference (
226 info->parameters[i], REF_DECREMENT);
230 if (ACPI_FAILURE (status)) {
231 return_ACPI_STATUS (status);
235 * If the method has returned an object, signal this to the caller with
236 * a control exception code
238 if (info->return_object) {
239 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned obj_desc=%p\n",
240 info->return_object));
241 ACPI_DUMP_STACK_ENTRY (info->return_object);
243 status = AE_CTRL_RETURN_VALUE;
246 return_ACPI_STATUS (status);