blob: 5279b51e77874d7693fe8d276a1c5a3fbe4bd796 [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>
49#include <acpi/acnamesp.h>
50
51
52#define _COMPONENT ACPI_PARSER
53 ACPI_MODULE_NAME ("psxface")
54
55
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_psx_execute
59 *
Robert Moore44f6c012005-04-18 22:49:35 -040060 * PARAMETERS: Info - Method info block, contains:
61 * Node - Method Node to execute
62 * Parameters - List of parameters to pass to the method,
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 * terminated by NULL. Params itself may be
64 * NULL if no parameters are being passed.
Robert Moore44f6c012005-04-18 22:49:35 -040065 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 *
71 * RETURN: Status
72 *
73 * DESCRIPTION: Execute a control method
74 *
75 ******************************************************************************/
76
77acpi_status
78acpi_psx_execute (
79 struct acpi_parameter_info *info)
80{
81 acpi_status status;
82 union acpi_operand_object *obj_desc;
83 u32 i;
84 union acpi_parse_object *op;
85 struct acpi_walk_state *walk_state;
86
87
88 ACPI_FUNCTION_TRACE ("psx_execute");
89
90
91 /* Validate the Node and get the attached object */
92
93 if (!info || !info->node) {
94 return_ACPI_STATUS (AE_NULL_ENTRY);
95 }
96
97 obj_desc = acpi_ns_get_attached_object (info->node);
98 if (!obj_desc) {
99 return_ACPI_STATUS (AE_NULL_OBJECT);
100 }
101
102 /* Init for new method, wait on concurrency semaphore */
103
104 status = acpi_ds_begin_method_execution (info->node, obj_desc, NULL);
105 if (ACPI_FAILURE (status)) {
106 return_ACPI_STATUS (status);
107 }
108
109 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
110 (info->parameters)) {
111 /*
112 * The caller "owns" the parameters, so give each one an extra
113 * reference
114 */
115 for (i = 0; info->parameters[i]; i++) {
116 acpi_ut_add_reference (info->parameters[i]);
117 }
118 }
119
120 /*
121 * 1) Perform the first pass parse of the method to enter any
122 * named objects that it creates into the namespace
123 */
124 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
125 "**** Begin Method Parse **** Entry=%p obj=%p\n",
126 info->node, obj_desc));
127
128 /* Create and init a Root Node */
129
130 op = acpi_ps_create_scope_op ();
131 if (!op) {
132 status = AE_NO_MEMORY;
133 goto cleanup1;
134 }
135
136 /*
137 * Get a new owner_id for objects created by this method. Namespace
138 * objects (such as Operation Regions) can be created during the
139 * first pass parse.
140 */
Robert Mooref9f46012005-07-08 00:00:00 -0400141 status = acpi_ut_allocate_owner_id (&obj_desc->method.owner_id);
142 if (ACPI_FAILURE (status)) {
143 goto cleanup2;
144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* Create and initialize a new walk state */
147
Robert Mooref9f46012005-07-08 00:00:00 -0400148 walk_state = acpi_ds_create_walk_state (obj_desc->method.owner_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 NULL, NULL, NULL);
150 if (!walk_state) {
151 status = AE_NO_MEMORY;
152 goto cleanup2;
153 }
154
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)) {
159 goto cleanup3;
160 }
161
162 /* Parse the AML */
163
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 */
168 }
169
170 /*
171 * 2) Execute the method. Performs second pass parse simultaneously
172 */
173 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
174 "**** Begin Method Execution **** Entry=%p obj=%p\n",
175 info->node, obj_desc));
176
177 /* Create and init a Root Node */
178
179 op = acpi_ps_create_scope_op ();
180 if (!op) {
181 status = AE_NO_MEMORY;
182 goto cleanup1;
183 }
184
185 /* Init new op with the method name and pointer back to the NS node */
186
187 acpi_ps_set_name (op, info->node->name.integer);
188 op->common.node = info->node;
189
190 /* Create and initialize a new walk state */
191
192 walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL);
193 if (!walk_state) {
194 status = AE_NO_MEMORY;
195 goto cleanup2;
196 }
197
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)) {
202 goto cleanup3;
203 }
204
Robert Moore44f6c012005-04-18 22:49:35 -0400205 /* The walk of the parse tree is where we actually execute the method */
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 status = acpi_ps_parse_aml (walk_state);
208 goto cleanup2; /* Walk state already deleted */
209
210
211cleanup3:
212 acpi_ds_delete_walk_state (walk_state);
213
214cleanup2:
215 acpi_ps_delete_parse_tree (op);
216
217cleanup1:
218 if ((info->parameter_type == ACPI_PARAM_ARGS) &&
219 (info->parameters)) {
220 /* Take away the extra reference that we gave the parameters above */
221
222 for (i = 0; info->parameters[i]; i++) {
223 /* Ignore errors, just do them all */
224
Robert Moore44f6c012005-04-18 22:49:35 -0400225 (void) acpi_ut_update_object_reference (
226 info->parameters[i], REF_DECREMENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 }
228 }
229
230 if (ACPI_FAILURE (status)) {
231 return_ACPI_STATUS (status);
232 }
233
234 /*
235 * If the method has returned an object, signal this to the caller with
236 * a control exception code
237 */
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);
242
243 status = AE_CTRL_RETURN_VALUE;
244 }
245
246 return_ACPI_STATUS (status);
247}
248
249