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>
51 #define _COMPONENT ACPI_PARSER
52 ACPI_MODULE_NAME ("psxface")
54 /* Local Prototypes */
57 acpi_ps_execute_pass (
58 struct acpi_parameter_info *info);
61 acpi_ps_update_parameter_list (
62 struct acpi_parameter_info *info,
66 /*******************************************************************************
68 * FUNCTION: acpi_ps_execute_method
70 * PARAMETERS: Info - Method info block, contains:
71 * Node - Method Node to execute
72 * obj_desc - Method object
73 * Parameters - List of parameters to pass to the method,
74 * terminated by NULL. Params itself may be
75 * NULL if no parameters are being passed.
76 * return_object - Where to put method's return value (if
77 * any). If NULL, no value is returned.
78 * parameter_type - Type of Parameter list
79 * return_object - Where to put method's return value (if
80 * any). If NULL, no value is returned.
81 * pass_number - Parse or execute pass
85 * DESCRIPTION: Execute a control method
87 ******************************************************************************/
90 acpi_ps_execute_method (
91 struct acpi_parameter_info *info)
96 ACPI_FUNCTION_TRACE ("ps_execute_method");
99 /* Validate the Info and method Node */
101 if (!info || !info->node) {
102 return_ACPI_STATUS (AE_NULL_ENTRY);
105 /* Init for new method, wait on concurrency semaphore */
107 status = acpi_ds_begin_method_execution (info->node, info->obj_desc, NULL);
108 if (ACPI_FAILURE (status)) {
109 return_ACPI_STATUS (status);
113 * Get a new owner_id for objects created by this method. Namespace
114 * objects (such as Operation Regions) can be created during the
117 status = acpi_ut_allocate_owner_id (&info->obj_desc->method.owner_id);
118 if (ACPI_FAILURE (status)) {
119 return_ACPI_STATUS (status);
123 * The caller "owns" the parameters, so give each one an extra
126 acpi_ps_update_parameter_list (info, REF_INCREMENT);
129 * 1) Perform the first pass parse of the method to enter any
130 * named objects that it creates into the namespace
132 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
133 "**** Begin Method Parse **** Entry=%p obj=%p\n",
134 info->node, info->obj_desc));
136 info->pass_number = 1;
137 status = acpi_ps_execute_pass (info);
138 if (ACPI_FAILURE (status)) {
143 * 2) Execute the method. Performs second pass parse simultaneously
145 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
146 "**** Begin Method Execution **** Entry=%p obj=%p\n",
147 info->node, info->obj_desc));
149 info->pass_number = 3;
150 status = acpi_ps_execute_pass (info);
154 if (info->obj_desc->method.owner_id) {
155 acpi_ut_release_owner_id (&info->obj_desc->method.owner_id);
158 /* Take away the extra reference that we gave the parameters above */
160 acpi_ps_update_parameter_list (info, REF_DECREMENT);
162 /* Exit now if error above */
164 if (ACPI_FAILURE (status)) {
165 return_ACPI_STATUS (status);
169 * If the method has returned an object, signal this to the caller with
170 * a control exception code
172 if (info->return_object) {
173 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Method returned obj_desc=%p\n",
174 info->return_object));
175 ACPI_DUMP_STACK_ENTRY (info->return_object);
177 status = AE_CTRL_RETURN_VALUE;
180 return_ACPI_STATUS (status);
184 /*******************************************************************************
186 * FUNCTION: acpi_ps_update_parameter_list
188 * PARAMETERS: Info - See struct acpi_parameter_info
189 * (Used: parameter_type and Parameters)
190 * Action - Add or Remove reference
194 * DESCRIPTION: Update reference count on all method parameter objects
196 ******************************************************************************/
199 acpi_ps_update_parameter_list (
200 struct acpi_parameter_info *info,
206 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
207 (info->parameters)) {
208 /* Update reference count for each parameter */
210 for (i = 0; info->parameters[i]; i++) {
211 /* Ignore errors, just do them all */
213 (void) acpi_ut_update_object_reference (info->parameters[i], action);
219 /*******************************************************************************
221 * FUNCTION: acpi_ps_execute_pass
223 * PARAMETERS: Info - See struct acpi_parameter_info
224 * (Used: pass_number, Node, and obj_desc)
228 * DESCRIPTION: Single AML pass: Parse or Execute a control method
230 ******************************************************************************/
233 acpi_ps_execute_pass (
234 struct acpi_parameter_info *info)
237 union acpi_parse_object *op;
238 struct acpi_walk_state *walk_state;
241 ACPI_FUNCTION_TRACE ("ps_execute_pass");
244 /* Create and init a Root Node */
246 op = acpi_ps_create_scope_op ();
248 return_ACPI_STATUS (AE_NO_MEMORY);
251 /* Create and initialize a new walk state */
253 walk_state = acpi_ds_create_walk_state (
254 info->obj_desc->method.owner_id, NULL, NULL, NULL);
256 status = AE_NO_MEMORY;
260 status = acpi_ds_init_aml_walk (walk_state, op, info->node,
261 info->obj_desc->method.aml_start,
262 info->obj_desc->method.aml_length,
263 info->pass_number == 1 ? NULL : info,
265 if (ACPI_FAILURE (status)) {
266 acpi_ds_delete_walk_state (walk_state);
272 status = acpi_ps_parse_aml (walk_state);
274 /* Walk state was deleted by parse_aml */
277 acpi_ps_delete_parse_tree (op);
278 return_ACPI_STATUS (status);