Merge master.kernel.org:/pub/scm/linux/kernel/git/dtor/input
[pandora-kernel.git] / drivers / acpi / executer / exoparg6.c
1
2 /******************************************************************************
3  *
4  * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
5  *
6  *****************************************************************************/
7
8 /*
9  * Copyright (C) 2000 - 2005, R. Byron Moore
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions, and the following disclaimer,
17  *    without modification.
18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19  *    substantially similar to the "NO WARRANTY" disclaimer below
20  *    ("Disclaimer") and any redistribution must be conditioned upon
21  *    including a substantially similar Disclaimer requirement for further
22  *    binary redistribution.
23  * 3. Neither the names of the above-listed copyright holders nor the names
24  *    of any contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * Alternatively, this software may be distributed under the terms of the
28  * GNU General Public License ("GPL") version 2 as published by the Free
29  * Software Foundation.
30  *
31  * NO WARRANTY
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42  * POSSIBILITY OF SUCH DAMAGES.
43  */
44
45
46 #include <acpi/acpi.h>
47 #include <acpi/acinterp.h>
48 #include <acpi/acparser.h>
49 #include <acpi/amlcode.h>
50
51
52 #define _COMPONENT          ACPI_EXECUTER
53          ACPI_MODULE_NAME    ("exoparg6")
54
55
56 /*!
57  * Naming convention for AML interpreter execution routines.
58  *
59  * The routines that begin execution of AML opcodes are named with a common
60  * convention based upon the number of arguments, the number of target operands,
61  * and whether or not a value is returned:
62  *
63  *      AcpiExOpcode_xA_yT_zR
64  *
65  * Where:
66  *
67  * xA - ARGUMENTS:    The number of arguments (input operands) that are
68  *                    required for this opcode type (1 through 6 args).
69  * yT - TARGETS:      The number of targets (output operands) that are required
70  *                    for this opcode type (0, 1, or 2 targets).
71  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
72  *                    as the function return (0 or 1).
73  *
74  * The AcpiExOpcode* functions are called via the Dispatcher component with
75  * fully resolved operands.
76 !*/
77
78 /* Local prototypes */
79
80 static u8
81 acpi_ex_do_match (
82         u32                             match_op,
83         union acpi_operand_object       *package_obj,
84         union acpi_operand_object       *match_obj);
85
86
87 /*******************************************************************************
88  *
89  * FUNCTION:    acpi_ex_do_match
90  *
91  * PARAMETERS:  match_op        - The AML match operand
92  *              package_obj     - Object from the target package
93  *              match_obj       - Object to be matched
94  *
95  * RETURN:      TRUE if the match is successful, FALSE otherwise
96  *
97  * DESCRIPTION: Implements the low-level match for the ASL Match operator.
98  *              Package elements will be implicitly converted to the type of
99  *              the match object (Integer/Buffer/String).
100  *
101  ******************************************************************************/
102
103 static u8
104 acpi_ex_do_match (
105         u32                             match_op,
106         union acpi_operand_object       *package_obj,
107         union acpi_operand_object       *match_obj)
108 {
109         u8                              logical_result = TRUE;
110         acpi_status                     status;
111
112
113         /*
114          * Note: Since the package_obj/match_obj ordering is opposite to that of
115          * the standard logical operators, we have to reverse them when we call
116          * do_logical_op in order to make the implicit conversion rules work
117          * correctly. However, this means we have to flip the entire equation
118          * also. A bit ugly perhaps, but overall, better than fussing the
119          * parameters around at runtime, over and over again.
120          *
121          * Below, P[i] refers to the package element, M refers to the Match object.
122          */
123         switch (match_op) {
124         case MATCH_MTR:
125
126                 /* Always true */
127
128                 break;
129
130         case MATCH_MEQ:
131
132                 /*
133                  * True if equal: (P[i] == M)
134                  * Change to:     (M == P[i])
135                  */
136                 status = acpi_ex_do_logical_op (AML_LEQUAL_OP, match_obj, package_obj,
137                                  &logical_result);
138                 if (ACPI_FAILURE (status)) {
139                         return (FALSE);
140                 }
141                 break;
142
143         case MATCH_MLE:
144
145                 /*
146                  * True if less than or equal: (P[i] <= M) (P[i] not_greater than M)
147                  * Change to:                  (M >= P[i]) (M not_less than P[i])
148                  */
149                 status = acpi_ex_do_logical_op (AML_LLESS_OP, match_obj, package_obj,
150                                  &logical_result);
151                 if (ACPI_FAILURE (status)) {
152                         return (FALSE);
153                 }
154                 logical_result = (u8) !logical_result;
155                 break;
156
157         case MATCH_MLT:
158
159                 /*
160                  * True if less than: (P[i] < M)
161                  * Change to:         (M > P[i])
162                  */
163                 status = acpi_ex_do_logical_op (AML_LGREATER_OP, match_obj, package_obj,
164                                  &logical_result);
165                 if (ACPI_FAILURE (status)) {
166                         return (FALSE);
167                 }
168                 break;
169
170         case MATCH_MGE:
171
172                 /*
173                  * True if greater than or equal: (P[i] >= M) (P[i] not_less than M)
174                  * Change to:                     (M <= P[i]) (M not_greater than P[i])
175                  */
176                 status = acpi_ex_do_logical_op (AML_LGREATER_OP, match_obj, package_obj,
177                                  &logical_result);
178                 if (ACPI_FAILURE (status)) {
179                         return (FALSE);
180                 }
181                 logical_result = (u8)!logical_result;
182                 break;
183
184         case MATCH_MGT:
185
186                 /*
187                  * True if greater than: (P[i] > M)
188                  * Change to:            (M < P[i])
189                  */
190                 status = acpi_ex_do_logical_op (AML_LLESS_OP, match_obj, package_obj,
191                                  &logical_result);
192                 if (ACPI_FAILURE (status)) {
193                         return (FALSE);
194                 }
195                 break;
196
197         default:
198
199                 /* Undefined */
200
201                 return (FALSE);
202         }
203
204         return logical_result;
205 }
206
207
208 /*******************************************************************************
209  *
210  * FUNCTION:    acpi_ex_opcode_6A_0T_1R
211  *
212  * PARAMETERS:  walk_state          - Current walk state
213  *
214  * RETURN:      Status
215  *
216  * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
217  *
218  ******************************************************************************/
219
220 acpi_status
221 acpi_ex_opcode_6A_0T_1R (
222         struct acpi_walk_state          *walk_state)
223 {
224         union acpi_operand_object       **operand = &walk_state->operands[0];
225         union acpi_operand_object       *return_desc = NULL;
226         acpi_status                     status = AE_OK;
227         acpi_integer                    index;
228         union acpi_operand_object       *this_element;
229
230
231         ACPI_FUNCTION_TRACE_STR ("ex_opcode_6A_0T_1R",
232                 acpi_ps_get_opcode_name (walk_state->opcode));
233
234
235         switch (walk_state->opcode) {
236         case AML_MATCH_OP:
237                 /*
238                  * Match (search_pkg[0], match_op1[1], match_obj1[2],
239                  *                      match_op2[3], match_obj2[4], start_index[5])
240                  */
241
242                 /* Validate both Match Term Operators (MTR, MEQ, etc.) */
243
244                 if ((operand[1]->integer.value > MAX_MATCH_OPERATOR) ||
245                         (operand[3]->integer.value > MAX_MATCH_OPERATOR)) {
246                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Match operator out of range\n"));
247                         status = AE_AML_OPERAND_VALUE;
248                         goto cleanup;
249                 }
250
251                 /* Get the package start_index, validate against the package length */
252
253                 index = operand[5]->integer.value;
254                 if (index >= operand[0]->package.count) {
255                         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
256                                 "Index (%X%8.8X) beyond package end (%X)\n",
257                                 ACPI_FORMAT_UINT64 (index), operand[0]->package.count));
258                         status = AE_AML_PACKAGE_LIMIT;
259                         goto cleanup;
260                 }
261
262                 /* Create an integer for the return value */
263
264                 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
265                 if (!return_desc) {
266                         status = AE_NO_MEMORY;
267                         goto cleanup;
268
269                 }
270
271                 /* Default return value if no match found */
272
273                 return_desc->integer.value = ACPI_INTEGER_MAX;
274
275                 /*
276                  * Examine each element until a match is found. Both match conditions
277                  * must be satisfied for a match to occur. Within the loop,
278                  * "continue" signifies that the current element does not match
279                  * and the next should be examined.
280                  *
281                  * Upon finding a match, the loop will terminate via "break" at
282                  * the bottom.  If it terminates "normally", match_value will be
283                  * ACPI_INTEGER_MAX (Ones) (its initial value) indicating that no
284                  * match was found.
285                  */
286                 for ( ; index < operand[0]->package.count; index++) {
287                         /* Get the current package element */
288
289                         this_element = operand[0]->package.elements[index];
290
291                         /* Treat any uninitialized (NULL) elements as non-matching */
292
293                         if (!this_element) {
294                                 continue;
295                         }
296
297                         /*
298                          * Both match conditions must be satisfied. Execution of a continue
299                          * (proceed to next iteration of enclosing for loop) signifies a
300                          * non-match.
301                          */
302                         if (!acpi_ex_do_match ((u32) operand[1]->integer.value,
303                                            this_element, operand[2])) {
304                                 continue;
305                         }
306
307                         if (!acpi_ex_do_match ((u32) operand[3]->integer.value,
308                                            this_element, operand[4])) {
309                                 continue;
310                         }
311
312                         /* Match found: Index is the return value */
313
314                         return_desc->integer.value = index;
315                         break;
316                 }
317                 break;
318
319
320         case AML_LOAD_TABLE_OP:
321
322                 status = acpi_ex_load_table_op (walk_state, &return_desc);
323                 break;
324
325
326         default:
327
328                 ACPI_REPORT_ERROR (("acpi_ex_opcode_6A_0T_1R: Unknown opcode %X\n",
329                                 walk_state->opcode));
330                 status = AE_AML_BAD_OPCODE;
331                 goto cleanup;
332         }
333
334         walk_state->result_obj = return_desc;
335
336
337 cleanup:
338
339         /* Delete return object on error */
340
341         if (ACPI_FAILURE (status)) {
342                 acpi_ut_remove_reference (return_desc);
343         }
344
345         return_ACPI_STATUS (status);
346 }