blob: 6eae35febccd378f50c200003286fa82c27ead99 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: psargs - Parse AML opcode arguments
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acparser.h>
46#include <acpi/amlcode.h>
47#include <acpi/acnamesp.h>
48
49#define _COMPONENT ACPI_PARSER
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("psargs")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040053static u32
Len Brown4be44fc2005-08-05 00:44:28 -040054acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
Robert Moore44f6c012005-04-18 22:49:35 -040055
Len Brown4be44fc2005-08-05 00:44:28 -040056static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
57 *parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/*******************************************************************************
60 *
61 * FUNCTION: acpi_ps_get_next_package_length
62 *
63 * PARAMETERS: parser_state - Current parser state object
64 *
Bob Moorec51a4de2005-11-17 13:07:00 -050065 * RETURN: Decoded package length. On completion, the AML pointer points
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 * past the length byte or bytes.
67 *
Bob Moorec51a4de2005-11-17 13:07:00 -050068 * DESCRIPTION: Decode and return a package length field.
69 * Note: Largest package length is 28 bits, from ACPI specification
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 *
71 ******************************************************************************/
72
Robert Moore44f6c012005-04-18 22:49:35 -040073static u32
Len Brown4be44fc2005-08-05 00:44:28 -040074acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Bob Moorec51a4de2005-11-17 13:07:00 -050076 u8 *aml = parser_state->aml;
77 u32 package_length = 0;
78 acpi_native_uint byte_count;
79 u8 byte_zero_mask = 0x3F; /* Default [0:5] */
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Len Brown4be44fc2005-08-05 00:44:28 -040081 ACPI_FUNCTION_TRACE("ps_get_next_package_length");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Bob Moorec51a4de2005-11-17 13:07:00 -050083 /*
84 * Byte 0 bits [6:7] contain the number of additional bytes
85 * used to encode the package length, either 0,1,2, or 3
86 */
87 byte_count = (aml[0] >> 6);
88 parser_state->aml += (byte_count + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Moorec51a4de2005-11-17 13:07:00 -050090 /* Get bytes 3, 2, 1 as needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Bob Moorec51a4de2005-11-17 13:07:00 -050092 while (byte_count) {
93 /*
94 * Final bit positions for the package length bytes:
95 * Byte3->[20:27]
96 * Byte2->[12:19]
97 * Byte1->[04:11]
98 * Byte0->[00:03]
99 */
100 package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Bob Moorec51a4de2005-11-17 13:07:00 -0500102 byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */
103 byte_count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 }
105
Bob Moorec51a4de2005-11-17 13:07:00 -0500106 /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
107
108 package_length |= (aml[0] & byte_zero_mask);
109 return_UINT32(package_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*******************************************************************************
113 *
114 * FUNCTION: acpi_ps_get_next_package_end
115 *
116 * PARAMETERS: parser_state - Current parser state object
117 *
118 * RETURN: Pointer to end-of-package +1
119 *
120 * DESCRIPTION: Get next package length and return a pointer past the end of
121 * the package. Consumes the package length field
122 *
123 ******************************************************************************/
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Len Brown4be44fc2005-08-05 00:44:28 -0400127 u8 *start = parser_state->aml;
Bob Moorec51a4de2005-11-17 13:07:00 -0500128 u32 package_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 ACPI_FUNCTION_TRACE("ps_get_next_package_end");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Bob Moorec51a4de2005-11-17 13:07:00 -0500132 /* Function below updates parser_state->Aml */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Bob Moorec51a4de2005-11-17 13:07:00 -0500134 package_length = acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Bob Moorec51a4de2005-11-17 13:07:00 -0500136 return_PTR(start + package_length); /* end of package */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/*******************************************************************************
140 *
141 * FUNCTION: acpi_ps_get_next_namestring
142 *
143 * PARAMETERS: parser_state - Current parser state object
144 *
145 * RETURN: Pointer to the start of the name string (pointer points into
146 * the AML.
147 *
148 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
149 * prefix characters. Set parser state to point past the string.
150 * (Name is consumed from the AML.)
151 *
152 ******************************************************************************/
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Len Brown4be44fc2005-08-05 00:44:28 -0400156 u8 *start = parser_state->aml;
157 u8 *end = parser_state->aml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 ACPI_FUNCTION_TRACE("ps_get_next_namestring");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Bob Moorec51a4de2005-11-17 13:07:00 -0500161 /* Point past any namestring prefix characters (backslash or carat) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Bob Moorec51a4de2005-11-17 13:07:00 -0500163 while (acpi_ps_is_prefix_char(*end)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 end++;
165 }
166
Bob Moorec51a4de2005-11-17 13:07:00 -0500167 /* Decode the path prefix character */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
Bob Moorec51a4de2005-11-17 13:07:00 -0500169 switch (*end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case 0:
171
172 /* null_name */
173
174 if (end == start) {
175 start = NULL;
176 }
177 end++;
178 break;
179
180 case AML_DUAL_NAME_PREFIX:
181
182 /* Two name segments */
183
184 end += 1 + (2 * ACPI_NAME_SIZE);
185 break;
186
187 case AML_MULTI_NAME_PREFIX_OP:
188
Bob Moorec51a4de2005-11-17 13:07:00 -0500189 /* Multiple name segments, 4 chars each, count in next byte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Moorec51a4de2005-11-17 13:07:00 -0500191 end += 2 + (*(end + 1) * ACPI_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 break;
193
194 default:
195
196 /* Single name segment */
197
198 end += ACPI_NAME_SIZE;
199 break;
200 }
201
Bob Moorec51a4de2005-11-17 13:07:00 -0500202 parser_state->aml = end;
Len Brown4be44fc2005-08-05 00:44:28 -0400203 return_PTR((char *)start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206/*******************************************************************************
207 *
208 * FUNCTION: acpi_ps_get_next_namepath
209 *
210 * PARAMETERS: parser_state - Current parser state object
211 * Arg - Where the namepath will be stored
212 * arg_count - If the namepath points to a control method
213 * the method's argument is returned here.
214 * method_call - Whether the namepath can possibly be the
215 * start of a method call
216 *
217 * RETURN: Status
218 *
219 * DESCRIPTION: Get next name (if method call, return # of required args).
220 * Names are looked up in the internal namespace to determine
221 * if the name represents a control method. If a method
222 * is found, the number of arguments to the method is returned.
223 * This information is critical for parsing to continue correctly.
224 *
225 ******************************************************************************/
226
227acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400228acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
229 struct acpi_parse_state *parser_state,
230 union acpi_parse_object *arg, u8 method_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Len Brown4be44fc2005-08-05 00:44:28 -0400232 char *path;
233 union acpi_parse_object *name_op;
234 acpi_status status = AE_OK;
235 union acpi_operand_object *method_desc;
236 struct acpi_namespace_node *node;
237 union acpi_generic_state scope_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 ACPI_FUNCTION_TRACE("ps_get_next_namepath");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Len Brown4be44fc2005-08-05 00:44:28 -0400241 path = acpi_ps_get_next_namestring(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 /* Null path case is allowed */
244
245 if (path) {
246 /*
247 * Lookup the name in the internal namespace
248 */
249 scope_info.scope.node = NULL;
250 node = parser_state->start_node;
251 if (node) {
252 scope_info.scope.node = node;
253 }
254
255 /*
256 * Lookup object. We don't want to add anything new to the namespace
257 * here, however. So we use MODE_EXECUTE. Allow searching of the
258 * parent tree, but don't open a new scope -- we just want to lookup the
259 * object (MUST BE mode EXECUTE to perform upsearch)
260 */
Len Brown4be44fc2005-08-05 00:44:28 -0400261 status = acpi_ns_lookup(&scope_info, path, ACPI_TYPE_ANY,
262 ACPI_IMODE_EXECUTE,
263 ACPI_NS_SEARCH_PARENT |
264 ACPI_NS_DONT_OPEN_SCOPE, NULL, &node);
265 if (ACPI_SUCCESS(status) && method_call) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 if (node->type == ACPI_TYPE_METHOD) {
Robert Moore44f6c012005-04-18 22:49:35 -0400267 /* This name is actually a control method invocation */
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269 method_desc = acpi_ns_get_attached_object(node);
270 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
271 "Control Method - %p Desc %p Path=%p\n",
272 node, method_desc, path));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (!name_op) {
Len Brown4be44fc2005-08-05 00:44:28 -0400276 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 }
278
279 /* Change arg into a METHOD CALL and attach name to it */
280
Len Brown4be44fc2005-08-05 00:44:28 -0400281 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 name_op->common.value.name = path;
283
284 /* Point METHODCALL/NAME to the METHOD Node */
285
286 name_op->common.node = node;
Len Brown4be44fc2005-08-05 00:44:28 -0400287 acpi_ps_append_arg(arg, name_op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 if (!method_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400290 ACPI_REPORT_ERROR(("ps_get_next_namepath: Control Method %p has no attached object\n", node));
291 return_ACPI_STATUS(AE_AML_INTERNAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
295 "Control Method - %p Args %X\n",
296 node,
297 method_desc->method.
298 param_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 /* Get the number of arguments to expect */
301
Len Brown4be44fc2005-08-05 00:44:28 -0400302 walk_state->arg_count =
303 method_desc->method.param_count;
304 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306
307 /*
308 * Else this is normal named object reference.
309 * Just init the NAMEPATH object with the pathname.
310 * (See code below)
311 */
312 }
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 /*
316 * 1) Any error other than NOT_FOUND is always severe
317 * 2) NOT_FOUND is only important if we are executing a method.
318 * 3) If executing a cond_ref_of opcode, NOT_FOUND is ok.
319 */
Len Brown4be44fc2005-08-05 00:44:28 -0400320 if ((((walk_state->
321 parse_flags & ACPI_PARSE_MODE_MASK) ==
322 ACPI_PARSE_EXECUTE) && (status == AE_NOT_FOUND)
323 && (walk_state->op->common.aml_opcode !=
324 AML_COND_REF_OF_OP))
325 || (status != AE_NOT_FOUND)) {
326 ACPI_REPORT_NSERROR(path, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Len Brown4be44fc2005-08-05 00:44:28 -0400328 acpi_os_printf
329 ("search_node %p start_node %p return_node %p\n",
330 scope_info.scope.node,
331 parser_state->start_node, node);
Len Brown4be44fc2005-08-05 00:44:28 -0400332 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /*
334 * We got a NOT_FOUND during table load or we encountered
335 * a cond_ref_of(x) where the target does not exist.
Robert Moore44f6c012005-04-18 22:49:35 -0400336 * Either case is ok
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 */
338 status = AE_OK;
339 }
340 }
341 }
342
343 /*
344 * Regardless of success/failure above,
345 * Just initialize the Op with the pathname.
346 */
Len Brown4be44fc2005-08-05 00:44:28 -0400347 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 arg->common.value.name = path;
349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/*******************************************************************************
354 *
355 * FUNCTION: acpi_ps_get_next_simple_arg
356 *
357 * PARAMETERS: parser_state - Current parser state object
358 * arg_type - The argument type (AML_*_ARG)
359 * Arg - Where the argument is returned
360 *
361 * RETURN: None
362 *
363 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
364 *
365 ******************************************************************************/
366
367void
Len Brown4be44fc2005-08-05 00:44:28 -0400368acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
369 u32 arg_type, union acpi_parse_object *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370{
Bob Moorec51a4de2005-11-17 13:07:00 -0500371 u32 length;
372 u16 opcode;
373 u8 *aml = parser_state->aml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Len Brown4be44fc2005-08-05 00:44:28 -0400375 ACPI_FUNCTION_TRACE_U32("ps_get_next_simple_arg", arg_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 switch (arg_type) {
378 case ARGP_BYTEDATA:
379
Bob Moorec51a4de2005-11-17 13:07:00 -0500380 /* Get 1 byte from the AML stream */
381
382 opcode = AML_BYTE_OP;
383 arg->common.value.integer = (acpi_integer) * aml;
384 length = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 break;
386
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 case ARGP_WORDDATA:
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 /* Get 2 bytes from the AML stream */
390
Bob Moorec51a4de2005-11-17 13:07:00 -0500391 opcode = AML_WORD_OP;
392 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
393 length = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 break;
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 case ARGP_DWORDDATA:
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 /* Get 4 bytes from the AML stream */
399
Bob Moorec51a4de2005-11-17 13:07:00 -0500400 opcode = AML_DWORD_OP;
401 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
402 length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 break;
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 case ARGP_QWORDDATA:
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 /* Get 8 bytes from the AML stream */
408
Bob Moorec51a4de2005-11-17 13:07:00 -0500409 opcode = AML_QWORD_OP;
410 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
411 length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 break;
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 case ARGP_CHARLIST:
415
Bob Moorec51a4de2005-11-17 13:07:00 -0500416 /* Get a pointer to the string, point past the string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Bob Moorec51a4de2005-11-17 13:07:00 -0500418 opcode = AML_STRING_OP;
419 arg->common.value.string = ACPI_CAST_PTR(char, aml);
420
421 /* Find the null terminator */
422
423 length = 0;
424 while (aml[length]) {
425 length++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 }
Bob Moorec51a4de2005-11-17 13:07:00 -0500427 length++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 break;
429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 case ARGP_NAME:
431 case ARGP_NAMESTRING:
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
434 arg->common.value.name =
435 acpi_ps_get_next_namestring(parser_state);
Bob Moorec51a4de2005-11-17 13:07:00 -0500436 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 default:
439
Len Brown4be44fc2005-08-05 00:44:28 -0400440 ACPI_REPORT_ERROR(("Invalid arg_type %X\n", arg_type));
Bob Moorec51a4de2005-11-17 13:07:00 -0500441 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 }
443
Bob Moorec51a4de2005-11-17 13:07:00 -0500444 acpi_ps_init_op(arg, opcode);
445 parser_state->aml += length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return_VOID;
447}
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449/*******************************************************************************
450 *
451 * FUNCTION: acpi_ps_get_next_field
452 *
453 * PARAMETERS: parser_state - Current parser state object
454 *
455 * RETURN: A newly allocated FIELD op
456 *
457 * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
458 *
459 ******************************************************************************/
460
Len Brown4be44fc2005-08-05 00:44:28 -0400461static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
462 *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Len Brown4be44fc2005-08-05 00:44:28 -0400464 u32 aml_offset = (u32)
465 ACPI_PTR_DIFF(parser_state->aml,
466 parser_state->aml_start);
467 union acpi_parse_object *field;
468 u16 opcode;
469 u32 name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Len Brown4be44fc2005-08-05 00:44:28 -0400471 ACPI_FUNCTION_TRACE("ps_get_next_field");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Robert Moore44f6c012005-04-18 22:49:35 -0400473 /* Determine field type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Len Brown4be44fc2005-08-05 00:44:28 -0400475 switch (ACPI_GET8(parser_state->aml)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 default:
477
478 opcode = AML_INT_NAMEDFIELD_OP;
479 break;
480
481 case 0x00:
482
483 opcode = AML_INT_RESERVEDFIELD_OP;
484 parser_state->aml++;
485 break;
486
487 case 0x01:
488
489 opcode = AML_INT_ACCESSFIELD_OP;
490 parser_state->aml++;
491 break;
492 }
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 /* Allocate a new field op */
495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 field = acpi_ps_alloc_op(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 if (!field) {
Len Brown4be44fc2005-08-05 00:44:28 -0400498 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500
501 field->common.aml_offset = aml_offset;
502
503 /* Decode the field type */
504
505 switch (opcode) {
506 case AML_INT_NAMEDFIELD_OP:
507
508 /* Get the 4-character name */
509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
511 acpi_ps_set_name(field, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 parser_state->aml += ACPI_NAME_SIZE;
513
514 /* Get the length which is encoded as a package length */
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 field->common.value.size =
517 acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 case AML_INT_RESERVEDFIELD_OP:
521
522 /* Get the length which is encoded as a package length */
523
Len Brown4be44fc2005-08-05 00:44:28 -0400524 field->common.value.size =
525 acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 break;
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 case AML_INT_ACCESSFIELD_OP:
529
530 /*
531 * Get access_type and access_attrib and merge into the field Op
532 * access_type is first operand, access_attribute is second
533 */
Len Brown4be44fc2005-08-05 00:44:28 -0400534 field->common.value.integer =
Bob Moorec51a4de2005-11-17 13:07:00 -0500535 (((u32) ACPI_GET8(parser_state->aml) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 parser_state->aml++;
Len Brown4be44fc2005-08-05 00:44:28 -0400537 field->common.value.integer |= ACPI_GET8(parser_state->aml);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 parser_state->aml++;
539 break;
540
541 default:
542
543 /* Opcode was set in previous switch */
544 break;
545 }
546
Len Brown4be44fc2005-08-05 00:44:28 -0400547 return_PTR(field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548}
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550/*******************************************************************************
551 *
552 * FUNCTION: acpi_ps_get_next_arg
553 *
Robert Moore44f6c012005-04-18 22:49:35 -0400554 * PARAMETERS: walk_state - Current state
555 * parser_state - Current parser state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 * arg_type - The argument type (AML_*_ARG)
Robert Moore44f6c012005-04-18 22:49:35 -0400557 * return_arg - Where the next arg is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 *
559 * RETURN: Status, and an op object containing the next argument.
560 *
561 * DESCRIPTION: Get next argument (including complex list arguments that require
562 * pushing the parser stack)
563 *
564 ******************************************************************************/
565
566acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400567acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
568 struct acpi_parse_state *parser_state,
569 u32 arg_type, union acpi_parse_object **return_arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570{
Len Brown4be44fc2005-08-05 00:44:28 -0400571 union acpi_parse_object *arg = NULL;
572 union acpi_parse_object *prev = NULL;
573 union acpi_parse_object *field;
574 u32 subop;
575 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Len Brown4be44fc2005-08-05 00:44:28 -0400577 ACPI_FUNCTION_TRACE_PTR("ps_get_next_arg", parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 switch (arg_type) {
580 case ARGP_BYTEDATA:
581 case ARGP_WORDDATA:
582 case ARGP_DWORDDATA:
583 case ARGP_CHARLIST:
584 case ARGP_NAME:
585 case ARGP_NAMESTRING:
586
Robert Moore44f6c012005-04-18 22:49:35 -0400587 /* Constants, strings, and namestrings are all the same size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Len Brown4be44fc2005-08-05 00:44:28 -0400589 arg = acpi_ps_alloc_op(AML_BYTE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400591 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
Len Brown4be44fc2005-08-05 00:44:28 -0400593 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 break;
595
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 case ARGP_PKGLENGTH:
597
598 /* Package length, nothing returned */
599
Len Brown4be44fc2005-08-05 00:44:28 -0400600 parser_state->pkg_end =
601 acpi_ps_get_next_package_end(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 break;
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 case ARGP_FIELDLIST:
605
606 if (parser_state->aml < parser_state->pkg_end) {
607 /* Non-empty list */
608
609 while (parser_state->aml < parser_state->pkg_end) {
Len Brown4be44fc2005-08-05 00:44:28 -0400610 field = acpi_ps_get_next_field(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 if (!field) {
Len Brown4be44fc2005-08-05 00:44:28 -0400612 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
615 if (prev) {
616 prev->common.next = field;
Len Brown4be44fc2005-08-05 00:44:28 -0400617 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 arg = field;
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 prev = field;
621 }
622
623 /* Skip to End of byte data */
624
625 parser_state->aml = parser_state->pkg_end;
626 }
627 break;
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 case ARGP_BYTELIST:
630
631 if (parser_state->aml < parser_state->pkg_end) {
632 /* Non-empty list */
633
Len Brown4be44fc2005-08-05 00:44:28 -0400634 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400636 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638
639 /* Fill in bytelist data */
640
Robert Moore44f6c012005-04-18 22:49:35 -0400641 arg->common.value.size = (u32)
Len Brown4be44fc2005-08-05 00:44:28 -0400642 ACPI_PTR_DIFF(parser_state->pkg_end,
643 parser_state->aml);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 arg->named.data = parser_state->aml;
645
646 /* Skip to End of byte data */
647
648 parser_state->aml = parser_state->pkg_end;
649 }
650 break;
651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 case ARGP_TARGET:
653 case ARGP_SUPERNAME:
654 case ARGP_SIMPLENAME:
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 subop = acpi_ps_peek_opcode(parser_state);
657 if (subop == 0 ||
658 acpi_ps_is_leading_char(subop) ||
659 acpi_ps_is_prefix_char(subop)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 /* null_name or name_string */
661
Len Brown4be44fc2005-08-05 00:44:28 -0400662 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400664 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
666
Len Brown4be44fc2005-08-05 00:44:28 -0400667 status =
668 acpi_ps_get_next_namepath(walk_state, parser_state,
669 arg, 0);
670 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400671 /* Single complex argument, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 walk_state->arg_count = 1;
674 }
675 break;
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 case ARGP_DATAOBJ:
678 case ARGP_TERMARG:
679
Robert Moore44f6c012005-04-18 22:49:35 -0400680 /* Single complex argument, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 walk_state->arg_count = 1;
683 break;
684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 case ARGP_DATAOBJLIST:
686 case ARGP_TERMLIST:
687 case ARGP_OBJLIST:
688
689 if (parser_state->aml < parser_state->pkg_end) {
Robert Moore44f6c012005-04-18 22:49:35 -0400690 /* Non-empty list of variable arguments, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
692 walk_state->arg_count = ACPI_VAR_ARGS;
693 }
694 break;
695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 default:
697
Len Brown4be44fc2005-08-05 00:44:28 -0400698 ACPI_REPORT_ERROR(("Invalid arg_type: %X\n", arg_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 status = AE_AML_OPERAND_TYPE;
700 break;
701 }
702
703 *return_arg = arg;
Len Brown4be44fc2005-08-05 00:44:28 -0400704 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}