]> err.no Git - linux-2.6/blob - drivers/acpi/parser/psxface.c
f6904bdf5739f6ef6f078b0fee7e00d61bba518e
[linux-2.6] / drivers / acpi / parser / psxface.c
1 /******************************************************************************
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 #include <acpi/acpi.h>
45 #include <acpi/acparser.h>
46 #include <acpi/acdispat.h>
47 #include <acpi/acinterp.h>
48
49 #define _COMPONENT          ACPI_PARSER
50 ACPI_MODULE_NAME("psxface")
51
52 /* Local Prototypes */
53 static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info);
54
55 static void
56 acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action);
57
58 /*******************************************************************************
59  *
60  * FUNCTION:    acpi_ps_execute_method
61  *
62  * PARAMETERS:  Info            - Method info block, contains:
63  *                  Node            - Method Node to execute
64  *                  obj_desc        - Method object
65  *                  Parameters      - List of parameters to pass to the method,
66  *                                    terminated by NULL. Params itself may be
67  *                                    NULL if no parameters are being passed.
68  *                  return_object   - Where to put method's return value (if
69  *                                    any). If NULL, no value is returned.
70  *                  parameter_type  - Type of Parameter list
71  *                  return_object   - Where to put method's return value (if
72  *                                    any). If NULL, no value is returned.
73  *                  pass_number     - Parse or execute pass
74  *
75  * RETURN:      Status
76  *
77  * DESCRIPTION: Execute a control method
78  *
79  ******************************************************************************/
80
81 acpi_status acpi_ps_execute_method(struct acpi_parameter_info *info)
82 {
83         acpi_status status;
84
85         ACPI_FUNCTION_TRACE("ps_execute_method");
86
87         /* Validate the Info and method Node */
88
89         if (!info || !info->node) {
90                 return_ACPI_STATUS(AE_NULL_ENTRY);
91         }
92
93         /* Init for new method, wait on concurrency semaphore */
94
95         status =
96             acpi_ds_begin_method_execution(info->node, info->obj_desc, NULL);
97         if (ACPI_FAILURE(status)) {
98                 return_ACPI_STATUS(status);
99         }
100
101         /*
102          * The caller "owns" the parameters, so give each one an extra
103          * reference
104          */
105         acpi_ps_update_parameter_list(info, REF_INCREMENT);
106
107         /*
108          * 1) Perform the first pass parse of the method to enter any
109          *    named objects that it creates into the namespace
110          */
111         ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
112                           "**** Begin Method Parse **** Entry=%p obj=%p\n",
113                           info->node, info->obj_desc));
114
115         info->pass_number = 1;
116         status = acpi_ps_execute_pass(info);
117         if (ACPI_FAILURE(status)) {
118                 goto cleanup;
119         }
120
121         /*
122          * 2) Execute the method. Performs second pass parse simultaneously
123          */
124         ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
125                           "**** Begin Method Execution **** Entry=%p obj=%p\n",
126                           info->node, info->obj_desc));
127
128         info->pass_number = 3;
129         status = acpi_ps_execute_pass(info);
130
131       cleanup:
132
133         /* Take away the extra reference that we gave the parameters above */
134
135         acpi_ps_update_parameter_list(info, REF_DECREMENT);
136
137         /* Exit now if error above */
138
139         if (ACPI_FAILURE(status)) {
140                 return_ACPI_STATUS(status);
141         }
142
143         /*
144          * If the method has returned an object, signal this to the caller with
145          * a control exception code
146          */
147         if (info->return_object) {
148                 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
149                                   "Method returned obj_desc=%p\n",
150                                   info->return_object));
151                 ACPI_DUMP_STACK_ENTRY(info->return_object);
152
153                 status = AE_CTRL_RETURN_VALUE;
154         }
155
156         return_ACPI_STATUS(status);
157 }
158
159 /*******************************************************************************
160  *
161  * FUNCTION:    acpi_ps_update_parameter_list
162  *
163  * PARAMETERS:  Info            - See struct acpi_parameter_info
164  *                                (Used: parameter_type and Parameters)
165  *              Action          - Add or Remove reference
166  *
167  * RETURN:      Status
168  *
169  * DESCRIPTION: Update reference count on all method parameter objects
170  *
171  ******************************************************************************/
172
173 static void
174 acpi_ps_update_parameter_list(struct acpi_parameter_info *info, u16 action)
175 {
176         acpi_native_uint i;
177
178         if ((info->parameter_type == ACPI_PARAM_ARGS) && (info->parameters)) {
179                 /* Update reference count for each parameter */
180
181                 for (i = 0; info->parameters[i]; i++) {
182                         /* Ignore errors, just do them all */
183
184                         (void)acpi_ut_update_object_reference(info->
185                                                               parameters[i],
186                                                               action);
187                 }
188         }
189 }
190
191 /*******************************************************************************
192  *
193  * FUNCTION:    acpi_ps_execute_pass
194  *
195  * PARAMETERS:  Info            - See struct acpi_parameter_info
196  *                                (Used: pass_number, Node, and obj_desc)
197  *
198  * RETURN:      Status
199  *
200  * DESCRIPTION: Single AML pass: Parse or Execute a control method
201  *
202  ******************************************************************************/
203
204 static acpi_status acpi_ps_execute_pass(struct acpi_parameter_info *info)
205 {
206         acpi_status status;
207         union acpi_parse_object *op;
208         struct acpi_walk_state *walk_state;
209
210         ACPI_FUNCTION_TRACE("ps_execute_pass");
211
212         /* Create and init a Root Node */
213
214         op = acpi_ps_create_scope_op();
215         if (!op) {
216                 return_ACPI_STATUS(AE_NO_MEMORY);
217         }
218
219         /* Create and initialize a new walk state */
220
221         walk_state =
222             acpi_ds_create_walk_state(info->obj_desc->method.owner_id, NULL,
223                                       NULL, NULL);
224         if (!walk_state) {
225                 status = AE_NO_MEMORY;
226                 goto cleanup;
227         }
228
229         status = acpi_ds_init_aml_walk(walk_state, op, info->node,
230                                        info->obj_desc->method.aml_start,
231                                        info->obj_desc->method.aml_length,
232                                        info->pass_number == 1 ? NULL : info,
233                                        info->pass_number);
234         if (ACPI_FAILURE(status)) {
235                 acpi_ds_delete_walk_state(walk_state);
236                 goto cleanup;
237         }
238
239         /* Parse the AML */
240
241         status = acpi_ps_parse_aml(walk_state);
242
243         /* Walk state was deleted by parse_aml */
244
245       cleanup:
246         acpi_ps_delete_parse_tree(op);
247         return_ACPI_STATUS(status);
248 }