blob: 442880f5600ec77ea28ca1e6d6120b8e6e185924 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: psargs - Parse AML opcode arguments
4 *
5 *****************************************************************************/
6
7/*
Bob Moore6c9deb72007-02-02 19:48:24 +03008 * Copyright (C) 2000 - 2007, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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>
Bob Mooredefba1d2005-12-16 17:05:00 -050048#include <acpi/acdispat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_PARSER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("psargs")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Robert Moore44f6c012005-04-18 22:49:35 -040053/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040054static u32
Len Brown4be44fc2005-08-05 00:44:28 -040055acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
Robert Moore44f6c012005-04-18 22:49:35 -040056
Len Brown4be44fc2005-08-05 00:44:28 -040057static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
58 *parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*******************************************************************************
61 *
62 * FUNCTION: acpi_ps_get_next_package_length
63 *
64 * PARAMETERS: parser_state - Current parser state object
65 *
Bob Moorec51a4de2005-11-17 13:07:00 -050066 * RETURN: Decoded package length. On completion, the AML pointer points
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 * past the length byte or bytes.
68 *
Bob Moorec51a4de2005-11-17 13:07:00 -050069 * DESCRIPTION: Decode and return a package length field.
70 * Note: Largest package length is 28 bits, from ACPI specification
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 *
72 ******************************************************************************/
73
Robert Moore44f6c012005-04-18 22:49:35 -040074static u32
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Bob Moorec51a4de2005-11-17 13:07:00 -050077 u8 *aml = parser_state->aml;
78 u32 package_length = 0;
79 acpi_native_uint byte_count;
80 u8 byte_zero_mask = 0x3F; /* Default [0:5] */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Bob Mooreb229cf92006-04-21 17:15:00 -040082 ACPI_FUNCTION_TRACE(ps_get_next_package_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Bob Moorec51a4de2005-11-17 13:07:00 -050084 /*
85 * Byte 0 bits [6:7] contain the number of additional bytes
86 * used to encode the package length, either 0,1,2, or 3
87 */
88 byte_count = (aml[0] >> 6);
89 parser_state->aml += (byte_count + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Bob Moorec51a4de2005-11-17 13:07:00 -050091 /* Get bytes 3, 2, 1 as needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Bob Moorec51a4de2005-11-17 13:07:00 -050093 while (byte_count) {
94 /*
95 * Final bit positions for the package length bytes:
96 * Byte3->[20:27]
97 * Byte2->[12:19]
98 * Byte1->[04:11]
99 * Byte0->[00:03]
100 */
101 package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Bob Moorec51a4de2005-11-17 13:07:00 -0500103 byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */
104 byte_count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 }
106
Bob Moorec51a4de2005-11-17 13:07:00 -0500107 /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
108
109 package_length |= (aml[0] & byte_zero_mask);
110 return_UINT32(package_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*******************************************************************************
114 *
115 * FUNCTION: acpi_ps_get_next_package_end
116 *
117 * PARAMETERS: parser_state - Current parser state object
118 *
119 * RETURN: Pointer to end-of-package +1
120 *
121 * DESCRIPTION: Get next package length and return a pointer past the end of
122 * the package. Consumes the package length field
123 *
124 ******************************************************************************/
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Len Brown4be44fc2005-08-05 00:44:28 -0400128 u8 *start = parser_state->aml;
Bob Moorec51a4de2005-11-17 13:07:00 -0500129 u32 package_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Bob Mooreb229cf92006-04-21 17:15:00 -0400131 ACPI_FUNCTION_TRACE(ps_get_next_package_end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Bob Moorec51a4de2005-11-17 13:07:00 -0500133 /* Function below updates parser_state->Aml */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Bob Moorec51a4de2005-11-17 13:07:00 -0500135 package_length = acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Bob Moorec51a4de2005-11-17 13:07:00 -0500137 return_PTR(start + package_length); /* end of package */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138}
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140/*******************************************************************************
141 *
142 * FUNCTION: acpi_ps_get_next_namestring
143 *
144 * PARAMETERS: parser_state - Current parser state object
145 *
146 * RETURN: Pointer to the start of the name string (pointer points into
147 * the AML.
148 *
149 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
150 * prefix characters. Set parser state to point past the string.
151 * (Name is consumed from the AML.)
152 *
153 ******************************************************************************/
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Len Brown4be44fc2005-08-05 00:44:28 -0400157 u8 *start = parser_state->aml;
158 u8 *end = parser_state->aml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Bob Mooreb229cf92006-04-21 17:15:00 -0400160 ACPI_FUNCTION_TRACE(ps_get_next_namestring);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Bob Moorec51a4de2005-11-17 13:07:00 -0500162 /* Point past any namestring prefix characters (backslash or carat) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Bob Moorec51a4de2005-11-17 13:07:00 -0500164 while (acpi_ps_is_prefix_char(*end)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 end++;
166 }
167
Bob Moorec51a4de2005-11-17 13:07:00 -0500168 /* Decode the path prefix character */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Bob Moorec51a4de2005-11-17 13:07:00 -0500170 switch (*end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 case 0:
172
173 /* null_name */
174
175 if (end == start) {
176 start = NULL;
177 }
178 end++;
179 break;
180
181 case AML_DUAL_NAME_PREFIX:
182
183 /* Two name segments */
184
185 end += 1 + (2 * ACPI_NAME_SIZE);
186 break;
187
188 case AML_MULTI_NAME_PREFIX_OP:
189
Bob Moorec51a4de2005-11-17 13:07:00 -0500190 /* Multiple name segments, 4 chars each, count in next byte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Bob Moorec51a4de2005-11-17 13:07:00 -0500192 end += 2 + (*(end + 1) * ACPI_NAME_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194
195 default:
196
197 /* Single name segment */
198
199 end += ACPI_NAME_SIZE;
200 break;
201 }
202
Bob Moorec51a4de2005-11-17 13:07:00 -0500203 parser_state->aml = end;
Len Brown4be44fc2005-08-05 00:44:28 -0400204 return_PTR((char *)start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/*******************************************************************************
208 *
209 * FUNCTION: acpi_ps_get_next_namepath
210 *
211 * PARAMETERS: parser_state - Current parser state object
212 * Arg - Where the namepath will be stored
213 * arg_count - If the namepath points to a control method
214 * the method's argument is returned here.
Bob Mooredefba1d2005-12-16 17:05:00 -0500215 * possible_method_call - Whether the namepath can possibly be the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 * start of a method call
217 *
218 * RETURN: Status
219 *
220 * DESCRIPTION: Get next name (if method call, return # of required args).
221 * Names are looked up in the internal namespace to determine
222 * if the name represents a control method. If a method
223 * is found, the number of arguments to the method is returned.
224 * This information is critical for parsing to continue correctly.
225 *
226 ******************************************************************************/
227
228acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400229acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
230 struct acpi_parse_state *parser_state,
Bob Mooredefba1d2005-12-16 17:05:00 -0500231 union acpi_parse_object *arg, u8 possible_method_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Lin Ming14808822008-04-10 19:06:38 +0400233 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400234 char *path;
235 union acpi_parse_object *name_op;
Len Brown4be44fc2005-08-05 00:44:28 -0400236 union acpi_operand_object *method_desc;
237 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Bob Mooreb229cf92006-04-21 17:15:00 -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);
Bob Mooredefba1d2005-12-16 17:05:00 -0500242 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Bob Mooredefba1d2005-12-16 17:05:00 -0500244 /* Null path case is allowed, just exit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Bob Mooredefba1d2005-12-16 17:05:00 -0500246 if (!path) {
247 arg->common.value.name = path;
248 return_ACPI_STATUS(AE_OK);
249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /*
Lin Ming14808822008-04-10 19:06:38 +0400252 * Lookup the name in the internal namespace, starting with the current
253 * scope. We don't want to add anything new to the namespace here,
254 * however, so we use MODE_EXECUTE.
Bob Mooredefba1d2005-12-16 17:05:00 -0500255 * Allow searching of the parent tree, but don't open a new scope -
256 * we just want to lookup the object (must be mode EXECUTE to perform
257 * the upsearch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 */
Lin Ming14808822008-04-10 19:06:38 +0400259 status = acpi_ns_lookup(walk_state->scope_info, path,
260 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
261 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
262 NULL, &node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Bob Mooredefba1d2005-12-16 17:05:00 -0500264 /*
265 * If this name is a control method invocation, we must
266 * setup the method call
267 */
268 if (ACPI_SUCCESS(status) &&
269 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400270
Bob Mooredefba1d2005-12-16 17:05:00 -0500271 /* This name is actually a control method invocation */
272
273 method_desc = acpi_ns_get_attached_object(node);
274 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
275 "Control Method - %p Desc %p Path=%p\n", node,
276 method_desc, path));
277
278 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
279 if (!name_op) {
280 return_ACPI_STATUS(AE_NO_MEMORY);
281 }
282
283 /* Change Arg into a METHOD CALL and attach name to it */
284
285 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
286 name_op->common.value.name = path;
287
288 /* Point METHODCALL/NAME to the METHOD Node */
289
290 name_op->common.node = node;
291 acpi_ps_append_arg(arg, name_op);
292
293 if (!method_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500294 ACPI_ERROR((AE_INFO,
295 "Control Method %p has no attached object",
296 node));
Bob Mooredefba1d2005-12-16 17:05:00 -0500297 return_ACPI_STATUS(AE_AML_INTERNAL);
298 }
299
300 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
301 "Control Method - %p Args %X\n",
302 node, method_desc->method.param_count));
303
304 /* Get the number of arguments to expect */
305
306 walk_state->arg_count = method_desc->method.param_count;
307 return_ACPI_STATUS(AE_OK);
308 }
309
310 /*
311 * Special handling if the name was not found during the lookup -
312 * some not_found cases are allowed
313 */
314 if (status == AE_NOT_FOUND) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400315
Bob Mooredefba1d2005-12-16 17:05:00 -0500316 /* 1) not_found is ok during load pass 1/2 (allow forward references) */
317
318 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
319 ACPI_PARSE_EXECUTE) {
320 status = AE_OK;
321 }
322
323 /* 2) not_found during a cond_ref_of(x) is ok by definition */
324
325 else if (walk_state->op->common.aml_opcode ==
326 AML_COND_REF_OF_OP) {
327 status = AE_OK;
328 }
329
330 /*
331 * 3) not_found while building a Package is ok at this point, we
332 * may flag as an error later if slack mode is not enabled.
333 * (Some ASL code depends on allowing this behavior)
334 */
335 else if ((arg->common.parent) &&
336 ((arg->common.parent->common.aml_opcode ==
337 AML_PACKAGE_OP)
338 || (arg->common.parent->common.aml_opcode ==
339 AML_VAR_PACKAGE_OP))) {
340 status = AE_OK;
341 }
342 }
343
344 /* Final exception check (may have been changed from code above) */
345
346 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500347 ACPI_ERROR_NAMESPACE(path, status);
Bob Mooredefba1d2005-12-16 17:05:00 -0500348
349 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
350 ACPI_PARSE_EXECUTE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400351
Bob Mooredefba1d2005-12-16 17:05:00 -0500352 /* Report a control method execution error */
353
354 status = acpi_ds_method_error(status, walk_state);
355 }
356 }
357
358 /* Save the namepath */
359
360 arg->common.value.name = path;
Len Brown4be44fc2005-08-05 00:44:28 -0400361 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364/*******************************************************************************
365 *
366 * FUNCTION: acpi_ps_get_next_simple_arg
367 *
368 * PARAMETERS: parser_state - Current parser state object
369 * arg_type - The argument type (AML_*_ARG)
370 * Arg - Where the argument is returned
371 *
372 * RETURN: None
373 *
374 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
375 *
376 ******************************************************************************/
377
378void
Len Brown4be44fc2005-08-05 00:44:28 -0400379acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
380 u32 arg_type, union acpi_parse_object *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Bob Moorec51a4de2005-11-17 13:07:00 -0500382 u32 length;
383 u16 opcode;
384 u8 *aml = parser_state->aml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Bob Mooreb229cf92006-04-21 17:15:00 -0400386 ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 switch (arg_type) {
389 case ARGP_BYTEDATA:
390
Bob Moorec51a4de2005-11-17 13:07:00 -0500391 /* Get 1 byte from the AML stream */
392
393 opcode = AML_BYTE_OP;
394 arg->common.value.integer = (acpi_integer) * aml;
395 length = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 break;
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 case ARGP_WORDDATA:
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 /* Get 2 bytes from the AML stream */
401
Bob Moorec51a4de2005-11-17 13:07:00 -0500402 opcode = AML_WORD_OP;
403 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
404 length = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 break;
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 case ARGP_DWORDDATA:
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 /* Get 4 bytes from the AML stream */
410
Bob Moorec51a4de2005-11-17 13:07:00 -0500411 opcode = AML_DWORD_OP;
412 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
413 length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 break;
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 case ARGP_QWORDDATA:
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* Get 8 bytes from the AML stream */
419
Bob Moorec51a4de2005-11-17 13:07:00 -0500420 opcode = AML_QWORD_OP;
421 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
422 length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 break;
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 case ARGP_CHARLIST:
426
Bob Moorec51a4de2005-11-17 13:07:00 -0500427 /* Get a pointer to the string, point past the string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
Bob Moorec51a4de2005-11-17 13:07:00 -0500429 opcode = AML_STRING_OP;
430 arg->common.value.string = ACPI_CAST_PTR(char, aml);
431
432 /* Find the null terminator */
433
434 length = 0;
435 while (aml[length]) {
436 length++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
Bob Moorec51a4de2005-11-17 13:07:00 -0500438 length++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 break;
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 case ARGP_NAME:
442 case ARGP_NAMESTRING:
443
Len Brown4be44fc2005-08-05 00:44:28 -0400444 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
445 arg->common.value.name =
446 acpi_ps_get_next_namestring(parser_state);
Bob Moorec51a4de2005-11-17 13:07:00 -0500447 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 default:
450
Bob Mooreb229cf92006-04-21 17:15:00 -0400451 ACPI_ERROR((AE_INFO, "Invalid ArgType %X", arg_type));
Bob Moorec51a4de2005-11-17 13:07:00 -0500452 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
454
Bob Moorec51a4de2005-11-17 13:07:00 -0500455 acpi_ps_init_op(arg, opcode);
456 parser_state->aml += length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return_VOID;
458}
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460/*******************************************************************************
461 *
462 * FUNCTION: acpi_ps_get_next_field
463 *
464 * PARAMETERS: parser_state - Current parser state object
465 *
466 * RETURN: A newly allocated FIELD op
467 *
468 * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
469 *
470 ******************************************************************************/
471
Len Brown4be44fc2005-08-05 00:44:28 -0400472static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
473 *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Len Brown4be44fc2005-08-05 00:44:28 -0400475 u32 aml_offset = (u32)
476 ACPI_PTR_DIFF(parser_state->aml,
477 parser_state->aml_start);
478 union acpi_parse_object *field;
479 u16 opcode;
480 u32 name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Bob Mooreb229cf92006-04-21 17:15:00 -0400482 ACPI_FUNCTION_TRACE(ps_get_next_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Robert Moore44f6c012005-04-18 22:49:35 -0400484 /* Determine field type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Len Brown4be44fc2005-08-05 00:44:28 -0400486 switch (ACPI_GET8(parser_state->aml)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 default:
488
489 opcode = AML_INT_NAMEDFIELD_OP;
490 break;
491
492 case 0x00:
493
494 opcode = AML_INT_RESERVEDFIELD_OP;
495 parser_state->aml++;
496 break;
497
498 case 0x01:
499
500 opcode = AML_INT_ACCESSFIELD_OP;
501 parser_state->aml++;
502 break;
503 }
504
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 /* Allocate a new field op */
506
Len Brown4be44fc2005-08-05 00:44:28 -0400507 field = acpi_ps_alloc_op(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (!field) {
Len Brown4be44fc2005-08-05 00:44:28 -0400509 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511
512 field->common.aml_offset = aml_offset;
513
514 /* Decode the field type */
515
516 switch (opcode) {
517 case AML_INT_NAMEDFIELD_OP:
518
519 /* Get the 4-character name */
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
522 acpi_ps_set_name(field, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 parser_state->aml += ACPI_NAME_SIZE;
524
525 /* Get the length which is encoded as a package length */
526
Len Brown4be44fc2005-08-05 00:44:28 -0400527 field->common.value.size =
528 acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 break;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 case AML_INT_RESERVEDFIELD_OP:
532
533 /* Get the length which is encoded as a package length */
534
Len Brown4be44fc2005-08-05 00:44:28 -0400535 field->common.value.size =
536 acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 break;
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 case AML_INT_ACCESSFIELD_OP:
540
541 /*
542 * Get access_type and access_attrib and merge into the field Op
543 * access_type is first operand, access_attribute is second
544 */
Len Brown4be44fc2005-08-05 00:44:28 -0400545 field->common.value.integer =
Bob Moorec51a4de2005-11-17 13:07:00 -0500546 (((u32) ACPI_GET8(parser_state->aml) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 parser_state->aml++;
Len Brown4be44fc2005-08-05 00:44:28 -0400548 field->common.value.integer |= ACPI_GET8(parser_state->aml);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 parser_state->aml++;
550 break;
551
552 default:
553
554 /* Opcode was set in previous switch */
555 break;
556 }
557
Len Brown4be44fc2005-08-05 00:44:28 -0400558 return_PTR(field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561/*******************************************************************************
562 *
563 * FUNCTION: acpi_ps_get_next_arg
564 *
Robert Moore44f6c012005-04-18 22:49:35 -0400565 * PARAMETERS: walk_state - Current state
566 * parser_state - Current parser state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 * arg_type - The argument type (AML_*_ARG)
Robert Moore44f6c012005-04-18 22:49:35 -0400568 * return_arg - Where the next arg is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 *
570 * RETURN: Status, and an op object containing the next argument.
571 *
572 * DESCRIPTION: Get next argument (including complex list arguments that require
573 * pushing the parser stack)
574 *
575 ******************************************************************************/
576
577acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400578acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
579 struct acpi_parse_state *parser_state,
580 u32 arg_type, union acpi_parse_object **return_arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Len Brown4be44fc2005-08-05 00:44:28 -0400582 union acpi_parse_object *arg = NULL;
583 union acpi_parse_object *prev = NULL;
584 union acpi_parse_object *field;
585 u32 subop;
586 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Bob Mooreb229cf92006-04-21 17:15:00 -0400588 ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 switch (arg_type) {
591 case ARGP_BYTEDATA:
592 case ARGP_WORDDATA:
593 case ARGP_DWORDDATA:
594 case ARGP_CHARLIST:
595 case ARGP_NAME:
596 case ARGP_NAMESTRING:
597
Robert Moore44f6c012005-04-18 22:49:35 -0400598 /* Constants, strings, and namestrings are all the same size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Len Brown4be44fc2005-08-05 00:44:28 -0400600 arg = acpi_ps_alloc_op(AML_BYTE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400602 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Len Brown4be44fc2005-08-05 00:44:28 -0400604 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 break;
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 case ARGP_PKGLENGTH:
608
609 /* Package length, nothing returned */
610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 parser_state->pkg_end =
612 acpi_ps_get_next_package_end(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 break;
614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 case ARGP_FIELDLIST:
616
617 if (parser_state->aml < parser_state->pkg_end) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 /* Non-empty list */
620
621 while (parser_state->aml < parser_state->pkg_end) {
Len Brown4be44fc2005-08-05 00:44:28 -0400622 field = acpi_ps_get_next_field(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (!field) {
Len Brown4be44fc2005-08-05 00:44:28 -0400624 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 }
626
627 if (prev) {
628 prev->common.next = field;
Len Brown4be44fc2005-08-05 00:44:28 -0400629 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 arg = field;
631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 prev = field;
633 }
634
635 /* Skip to End of byte data */
636
637 parser_state->aml = parser_state->pkg_end;
638 }
639 break;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 case ARGP_BYTELIST:
642
643 if (parser_state->aml < parser_state->pkg_end) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 /* Non-empty list */
646
Len Brown4be44fc2005-08-05 00:44:28 -0400647 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400649 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651
652 /* Fill in bytelist data */
653
Robert Moore44f6c012005-04-18 22:49:35 -0400654 arg->common.value.size = (u32)
Len Brown4be44fc2005-08-05 00:44:28 -0400655 ACPI_PTR_DIFF(parser_state->pkg_end,
656 parser_state->aml);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 arg->named.data = parser_state->aml;
658
659 /* Skip to End of byte data */
660
661 parser_state->aml = parser_state->pkg_end;
662 }
663 break;
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 case ARGP_TARGET:
666 case ARGP_SUPERNAME:
667 case ARGP_SIMPLENAME:
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 subop = acpi_ps_peek_opcode(parser_state);
670 if (subop == 0 ||
671 acpi_ps_is_leading_char(subop) ||
672 acpi_ps_is_prefix_char(subop)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 /* null_name or name_string */
675
Len Brown4be44fc2005-08-05 00:44:28 -0400676 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400678 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 }
680
Len Brown4be44fc2005-08-05 00:44:28 -0400681 status =
682 acpi_ps_get_next_namepath(walk_state, parser_state,
683 arg, 0);
684 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400685 /* Single complex argument, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 walk_state->arg_count = 1;
688 }
689 break;
690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 case ARGP_DATAOBJ:
692 case ARGP_TERMARG:
693
Robert Moore44f6c012005-04-18 22:49:35 -0400694 /* Single complex argument, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 walk_state->arg_count = 1;
697 break;
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 case ARGP_DATAOBJLIST:
700 case ARGP_TERMLIST:
701 case ARGP_OBJLIST:
702
703 if (parser_state->aml < parser_state->pkg_end) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400704
Robert Moore44f6c012005-04-18 22:49:35 -0400705 /* Non-empty list of variable arguments, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
707 walk_state->arg_count = ACPI_VAR_ARGS;
708 }
709 break;
710
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 default:
712
Bob Mooreb229cf92006-04-21 17:15:00 -0400713 ACPI_ERROR((AE_INFO, "Invalid ArgType: %X", arg_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 status = AE_AML_OPERAND_TYPE;
715 break;
716 }
717
718 *return_arg = arg;
Len Brown4be44fc2005-08-05 00:44:28 -0400719 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}