blob: d1541fabaf0a87d0e64f7e8fa6d158739b1276c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: psxface - Parser external interfaces
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * 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
44
45#include <acpi/acpi.h>
46#include <acpi/acparser.h>
47#include <acpi/acdispat.h>
48#include <acpi/acinterp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50
51#define _COMPONENT ACPI_PARSER
52 ACPI_MODULE_NAME ("psxface")
53
Robert Moore0c9938c2005-07-29 15:15:00 -070054/* Local Prototypes */
55
56static acpi_status
57acpi_ps_execute_pass (
58 struct acpi_parameter_info *info);
59
60static void
61acpi_ps_update_parameter_list (
62 struct acpi_parameter_info *info,
63 u16 action);
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66/*******************************************************************************
67 *
Robert Moore0c9938c2005-07-29 15:15:00 -070068 * FUNCTION: acpi_ps_execute_method
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 *
Robert Moore44f6c012005-04-18 22:49:35 -040070 * PARAMETERS: Info - Method info block, contains:
71 * Node - Method Node to execute
Robert Moore0c9938c2005-07-29 15:15:00 -070072 * obj_desc - Method object
Robert Moore44f6c012005-04-18 22:49:35 -040073 * Parameters - List of parameters to pass to the method,
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * terminated by NULL. Params itself may be
75 * NULL if no parameters are being passed.
Robert Moore44f6c012005-04-18 22:49:35 -040076 * 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.
Robert Moore0c9938c2005-07-29 15:15:00 -070081 * pass_number - Parse or execute pass
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 *
83 * RETURN: Status
84 *
85 * DESCRIPTION: Execute a control method
86 *
87 ******************************************************************************/
88
89acpi_status
Robert Moore0c9938c2005-07-29 15:15:00 -070090acpi_ps_execute_method (
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 struct acpi_parameter_info *info)
92{
93 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95
Robert Moore0c9938c2005-07-29 15:15:00 -070096 ACPI_FUNCTION_TRACE ("ps_execute_method");
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98
Robert Moore0c9938c2005-07-29 15:15:00 -070099 /* Validate the Info and method Node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 if (!info || !info->node) {
102 return_ACPI_STATUS (AE_NULL_ENTRY);
103 }
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* Init for new method, wait on concurrency semaphore */
106
Robert Moore0c9938c2005-07-29 15:15:00 -0700107 status = acpi_ds_begin_method_execution (info->node, info->obj_desc, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (ACPI_FAILURE (status)) {
109 return_ACPI_STATUS (status);
110 }
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /*
113 * Get a new owner_id for objects created by this method. Namespace
114 * objects (such as Operation Regions) can be created during the
115 * first pass parse.
116 */
Robert Moore0c9938c2005-07-29 15:15:00 -0700117 status = acpi_ut_allocate_owner_id (&info->obj_desc->method.owner_id);
Robert Mooref9f46012005-07-08 00:00:00 -0400118 if (ACPI_FAILURE (status)) {
Robert Moore0c9938c2005-07-29 15:15:00 -0700119 return_ACPI_STATUS (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
122 /*
Robert Moore0c9938c2005-07-29 15:15:00 -0700123 * The caller "owns" the parameters, so give each one an extra
124 * reference
125 */
126 acpi_ps_update_parameter_list (info, REF_INCREMENT);
127
128 /*
129 * 1) Perform the first pass parse of the method to enter any
130 * named objects that it creates into the namespace
131 */
132 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
133 "**** Begin Method Parse **** Entry=%p obj=%p\n",
134 info->node, info->obj_desc));
135
136 info->pass_number = 1;
137 status = acpi_ps_execute_pass (info);
138 if (ACPI_FAILURE (status)) {
139 goto cleanup;
140 }
141
142 /*
143 * 2) Execute the method. Performs second pass parse simultaneously
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 */
145 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
146 "**** Begin Method Execution **** Entry=%p obj=%p\n",
Robert Moore0c9938c2005-07-29 15:15:00 -0700147 info->node, info->obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Robert Moore0c9938c2005-07-29 15:15:00 -0700149 info->pass_number = 3;
150 status = acpi_ps_execute_pass (info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Robert Moore0c9938c2005-07-29 15:15:00 -0700152
153cleanup:
154 if (info->obj_desc->method.owner_id) {
155 acpi_ut_release_owner_id (&info->obj_desc->method.owner_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157
Robert Moore0c9938c2005-07-29 15:15:00 -0700158 /* Take away the extra reference that we gave the parameters above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Robert Moore0c9938c2005-07-29 15:15:00 -0700160 acpi_ps_update_parameter_list (info, REF_DECREMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Robert Moore0c9938c2005-07-29 15:15:00 -0700162 /* Exit now if error above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 if (ACPI_FAILURE (status)) {
165 return_ACPI_STATUS (status);
166 }
167
168 /*
169 * If the method has returned an object, signal this to the caller with
170 * a control exception code
171 */
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);
176
177 status = AE_CTRL_RETURN_VALUE;
178 }
179
180 return_ACPI_STATUS (status);
181}
182
183
Robert Moore0c9938c2005-07-29 15:15:00 -0700184/*******************************************************************************
185 *
186 * FUNCTION: acpi_ps_update_parameter_list
187 *
188 * PARAMETERS: Info - See struct acpi_parameter_info
189 * (Used: parameter_type and Parameters)
190 * Action - Add or Remove reference
191 *
192 * RETURN: Status
193 *
194 * DESCRIPTION: Update reference count on all method parameter objects
195 *
196 ******************************************************************************/
197
198static void
199acpi_ps_update_parameter_list (
200 struct acpi_parameter_info *info,
201 u16 action)
202{
203 acpi_native_uint i;
204
205
206 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
207 (info->parameters)) {
208 /* Update reference count for each parameter */
209
210 for (i = 0; info->parameters[i]; i++) {
211 /* Ignore errors, just do them all */
212
213 (void) acpi_ut_update_object_reference (info->parameters[i], action);
214 }
215 }
216}
217
218
219/*******************************************************************************
220 *
221 * FUNCTION: acpi_ps_execute_pass
222 *
223 * PARAMETERS: Info - See struct acpi_parameter_info
224 * (Used: pass_number, Node, and obj_desc)
225 *
226 * RETURN: Status
227 *
228 * DESCRIPTION: Single AML pass: Parse or Execute a control method
229 *
230 ******************************************************************************/
231
232static acpi_status
233acpi_ps_execute_pass (
234 struct acpi_parameter_info *info)
235{
236 acpi_status status;
237 union acpi_parse_object *op;
238 struct acpi_walk_state *walk_state;
239
240
241 ACPI_FUNCTION_TRACE ("ps_execute_pass");
242
243
244 /* Create and init a Root Node */
245
246 op = acpi_ps_create_scope_op ();
247 if (!op) {
248 return_ACPI_STATUS (AE_NO_MEMORY);
249 }
250
251 /* Create and initialize a new walk state */
252
253 walk_state = acpi_ds_create_walk_state (
254 info->obj_desc->method.owner_id, NULL, NULL, NULL);
255 if (!walk_state) {
256 status = AE_NO_MEMORY;
257 goto cleanup;
258 }
259
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,
264 info->pass_number);
265 if (ACPI_FAILURE (status)) {
266 acpi_ds_delete_walk_state (walk_state);
267 goto cleanup;
268 }
269
270 /* Parse the AML */
271
272 status = acpi_ps_parse_aml (walk_state);
273
274 /* Walk state was deleted by parse_aml */
275
276cleanup:
277 acpi_ps_delete_parse_tree (op);
278 return_ACPI_STATUS (status);
279}
280
281