blob: d830b29b85b120ceb87f793f4ddde61db98fbd4f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: psargs - Parse AML opcode arguments
4 *
5 *****************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
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;
Bob Moore67a119f2008-06-10 13:42:13 +080079 u32 byte_count;
Bob Moorec51a4de2005-11-17 13:07:00 -050080 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);
Bob Moore67a119f2008-06-10 13:42:13 +080089 parser_state->aml += ((acpi_size) 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;
Lin Mingbc7a36a2008-04-10 19:06:42 +0400238 u8 *start = parser_state->aml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Bob Mooreb229cf92006-04-21 17:15:00 -0400240 ACPI_FUNCTION_TRACE(ps_get_next_namepath);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Len Brown4be44fc2005-08-05 00:44:28 -0400242 path = acpi_ps_get_next_namestring(parser_state);
Bob Mooredefba1d2005-12-16 17:05:00 -0500243 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Bob Mooredefba1d2005-12-16 17:05:00 -0500245 /* Null path case is allowed, just exit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
Bob Mooredefba1d2005-12-16 17:05:00 -0500247 if (!path) {
248 arg->common.value.name = path;
249 return_ACPI_STATUS(AE_OK);
250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 /*
Lin Ming14808822008-04-10 19:06:38 +0400253 * Lookup the name in the internal namespace, starting with the current
254 * scope. We don't want to add anything new to the namespace here,
255 * however, so we use MODE_EXECUTE.
Bob Mooredefba1d2005-12-16 17:05:00 -0500256 * Allow searching of the parent tree, but don't open a new scope -
257 * we just want to lookup the object (must be mode EXECUTE to perform
258 * the upsearch)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 */
Lin Ming14808822008-04-10 19:06:38 +0400260 status = acpi_ns_lookup(walk_state->scope_info, path,
261 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
262 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
263 NULL, &node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Bob Mooredefba1d2005-12-16 17:05:00 -0500265 /*
266 * If this name is a control method invocation, we must
267 * setup the method call
268 */
269 if (ACPI_SUCCESS(status) &&
270 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
Bob Moore84105652008-06-10 14:29:26 +0800271 if (walk_state->opcode == AML_UNLOAD_OP) {
Lin Mingbc7a36a2008-04-10 19:06:42 +0400272 /*
273 * acpi_ps_get_next_namestring has increased the AML pointer,
274 * so we need to restore the saved AML pointer for method call.
275 */
276 walk_state->parser_state.aml = start;
277 walk_state->arg_count = 1;
278 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
279 return_ACPI_STATUS(AE_OK);
280 }
Bob Moore52fc0b02006-10-02 00:00:00 -0400281
Bob Mooredefba1d2005-12-16 17:05:00 -0500282 /* This name is actually a control method invocation */
283
284 method_desc = acpi_ns_get_attached_object(node);
285 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
286 "Control Method - %p Desc %p Path=%p\n", node,
287 method_desc, path));
288
289 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
290 if (!name_op) {
291 return_ACPI_STATUS(AE_NO_MEMORY);
292 }
293
294 /* Change Arg into a METHOD CALL and attach name to it */
295
296 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
297 name_op->common.value.name = path;
298
299 /* Point METHODCALL/NAME to the METHOD Node */
300
301 name_op->common.node = node;
302 acpi_ps_append_arg(arg, name_op);
303
304 if (!method_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500305 ACPI_ERROR((AE_INFO,
306 "Control Method %p has no attached object",
307 node));
Bob Mooredefba1d2005-12-16 17:05:00 -0500308 return_ACPI_STATUS(AE_AML_INTERNAL);
309 }
310
311 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
312 "Control Method - %p Args %X\n",
313 node, method_desc->method.param_count));
314
315 /* Get the number of arguments to expect */
316
317 walk_state->arg_count = method_desc->method.param_count;
318 return_ACPI_STATUS(AE_OK);
319 }
320
321 /*
322 * Special handling if the name was not found during the lookup -
323 * some not_found cases are allowed
324 */
325 if (status == AE_NOT_FOUND) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400326
Bob Mooredefba1d2005-12-16 17:05:00 -0500327 /* 1) not_found is ok during load pass 1/2 (allow forward references) */
328
329 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
330 ACPI_PARSE_EXECUTE) {
331 status = AE_OK;
332 }
333
334 /* 2) not_found during a cond_ref_of(x) is ok by definition */
335
336 else if (walk_state->op->common.aml_opcode ==
337 AML_COND_REF_OF_OP) {
338 status = AE_OK;
339 }
340
341 /*
342 * 3) not_found while building a Package is ok at this point, we
343 * may flag as an error later if slack mode is not enabled.
344 * (Some ASL code depends on allowing this behavior)
345 */
346 else if ((arg->common.parent) &&
347 ((arg->common.parent->common.aml_opcode ==
348 AML_PACKAGE_OP)
349 || (arg->common.parent->common.aml_opcode ==
350 AML_VAR_PACKAGE_OP))) {
351 status = AE_OK;
352 }
353 }
354
355 /* Final exception check (may have been changed from code above) */
356
357 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500358 ACPI_ERROR_NAMESPACE(path, status);
Bob Mooredefba1d2005-12-16 17:05:00 -0500359
360 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
361 ACPI_PARSE_EXECUTE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400362
Bob Mooredefba1d2005-12-16 17:05:00 -0500363 /* Report a control method execution error */
364
365 status = acpi_ds_method_error(status, walk_state);
366 }
367 }
368
369 /* Save the namepath */
370
371 arg->common.value.name = path;
Len Brown4be44fc2005-08-05 00:44:28 -0400372 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/*******************************************************************************
376 *
377 * FUNCTION: acpi_ps_get_next_simple_arg
378 *
379 * PARAMETERS: parser_state - Current parser state object
380 * arg_type - The argument type (AML_*_ARG)
381 * Arg - Where the argument is returned
382 *
383 * RETURN: None
384 *
385 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
386 *
387 ******************************************************************************/
388
389void
Len Brown4be44fc2005-08-05 00:44:28 -0400390acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
391 u32 arg_type, union acpi_parse_object *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Bob Moorec51a4de2005-11-17 13:07:00 -0500393 u32 length;
394 u16 opcode;
395 u8 *aml = parser_state->aml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Bob Mooreb229cf92006-04-21 17:15:00 -0400397 ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 switch (arg_type) {
400 case ARGP_BYTEDATA:
401
Bob Moorec51a4de2005-11-17 13:07:00 -0500402 /* Get 1 byte from the AML stream */
403
404 opcode = AML_BYTE_OP;
405 arg->common.value.integer = (acpi_integer) * aml;
406 length = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 break;
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 case ARGP_WORDDATA:
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 /* Get 2 bytes from the AML stream */
412
Bob Moorec51a4de2005-11-17 13:07:00 -0500413 opcode = AML_WORD_OP;
414 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
415 length = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 break;
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 case ARGP_DWORDDATA:
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 /* Get 4 bytes from the AML stream */
421
Bob Moorec51a4de2005-11-17 13:07:00 -0500422 opcode = AML_DWORD_OP;
423 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
424 length = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 break;
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 case ARGP_QWORDDATA:
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* Get 8 bytes from the AML stream */
430
Bob Moorec51a4de2005-11-17 13:07:00 -0500431 opcode = AML_QWORD_OP;
432 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
433 length = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 break;
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 case ARGP_CHARLIST:
437
Bob Moorec51a4de2005-11-17 13:07:00 -0500438 /* Get a pointer to the string, point past the string */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Bob Moorec51a4de2005-11-17 13:07:00 -0500440 opcode = AML_STRING_OP;
441 arg->common.value.string = ACPI_CAST_PTR(char, aml);
442
443 /* Find the null terminator */
444
445 length = 0;
446 while (aml[length]) {
447 length++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
Bob Moorec51a4de2005-11-17 13:07:00 -0500449 length++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 break;
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 case ARGP_NAME:
453 case ARGP_NAMESTRING:
454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
456 arg->common.value.name =
457 acpi_ps_get_next_namestring(parser_state);
Bob Moorec51a4de2005-11-17 13:07:00 -0500458 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 default:
461
Bob Mooreb229cf92006-04-21 17:15:00 -0400462 ACPI_ERROR((AE_INFO, "Invalid ArgType %X", arg_type));
Bob Moorec51a4de2005-11-17 13:07:00 -0500463 return_VOID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 }
465
Bob Moorec51a4de2005-11-17 13:07:00 -0500466 acpi_ps_init_op(arg, opcode);
467 parser_state->aml += length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 return_VOID;
469}
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471/*******************************************************************************
472 *
473 * FUNCTION: acpi_ps_get_next_field
474 *
475 * PARAMETERS: parser_state - Current parser state object
476 *
477 * RETURN: A newly allocated FIELD op
478 *
479 * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
480 *
481 ******************************************************************************/
482
Len Brown4be44fc2005-08-05 00:44:28 -0400483static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
484 *parser_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Len Brown4be44fc2005-08-05 00:44:28 -0400486 u32 aml_offset = (u32)
487 ACPI_PTR_DIFF(parser_state->aml,
488 parser_state->aml_start);
489 union acpi_parse_object *field;
490 u16 opcode;
491 u32 name;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Bob Mooreb229cf92006-04-21 17:15:00 -0400493 ACPI_FUNCTION_TRACE(ps_get_next_field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Robert Moore44f6c012005-04-18 22:49:35 -0400495 /* Determine field type */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Len Brown4be44fc2005-08-05 00:44:28 -0400497 switch (ACPI_GET8(parser_state->aml)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 default:
499
500 opcode = AML_INT_NAMEDFIELD_OP;
501 break;
502
503 case 0x00:
504
505 opcode = AML_INT_RESERVEDFIELD_OP;
506 parser_state->aml++;
507 break;
508
509 case 0x01:
510
511 opcode = AML_INT_ACCESSFIELD_OP;
512 parser_state->aml++;
513 break;
514 }
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 /* Allocate a new field op */
517
Len Brown4be44fc2005-08-05 00:44:28 -0400518 field = acpi_ps_alloc_op(opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (!field) {
Len Brown4be44fc2005-08-05 00:44:28 -0400520 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522
523 field->common.aml_offset = aml_offset;
524
525 /* Decode the field type */
526
527 switch (opcode) {
528 case AML_INT_NAMEDFIELD_OP:
529
530 /* Get the 4-character name */
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
533 acpi_ps_set_name(field, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 parser_state->aml += ACPI_NAME_SIZE;
535
536 /* Get the length which is encoded as a package length */
537
Len Brown4be44fc2005-08-05 00:44:28 -0400538 field->common.value.size =
539 acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 break;
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 case AML_INT_RESERVEDFIELD_OP:
543
544 /* Get the length which is encoded as a package length */
545
Len Brown4be44fc2005-08-05 00:44:28 -0400546 field->common.value.size =
547 acpi_ps_get_next_package_length(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 break;
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 case AML_INT_ACCESSFIELD_OP:
551
552 /*
553 * Get access_type and access_attrib and merge into the field Op
554 * access_type is first operand, access_attribute is second
555 */
Len Brown4be44fc2005-08-05 00:44:28 -0400556 field->common.value.integer =
Bob Moorec51a4de2005-11-17 13:07:00 -0500557 (((u32) ACPI_GET8(parser_state->aml) << 8));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 parser_state->aml++;
Len Brown4be44fc2005-08-05 00:44:28 -0400559 field->common.value.integer |= ACPI_GET8(parser_state->aml);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 parser_state->aml++;
561 break;
562
563 default:
564
565 /* Opcode was set in previous switch */
566 break;
567 }
568
Len Brown4be44fc2005-08-05 00:44:28 -0400569 return_PTR(field);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572/*******************************************************************************
573 *
574 * FUNCTION: acpi_ps_get_next_arg
575 *
Robert Moore44f6c012005-04-18 22:49:35 -0400576 * PARAMETERS: walk_state - Current state
577 * parser_state - Current parser state object
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 * arg_type - The argument type (AML_*_ARG)
Robert Moore44f6c012005-04-18 22:49:35 -0400579 * return_arg - Where the next arg is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 *
581 * RETURN: Status, and an op object containing the next argument.
582 *
583 * DESCRIPTION: Get next argument (including complex list arguments that require
584 * pushing the parser stack)
585 *
586 ******************************************************************************/
587
588acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400589acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
590 struct acpi_parse_state *parser_state,
591 u32 arg_type, union acpi_parse_object **return_arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
Len Brown4be44fc2005-08-05 00:44:28 -0400593 union acpi_parse_object *arg = NULL;
594 union acpi_parse_object *prev = NULL;
595 union acpi_parse_object *field;
596 u32 subop;
597 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Bob Mooreb229cf92006-04-21 17:15:00 -0400599 ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 switch (arg_type) {
602 case ARGP_BYTEDATA:
603 case ARGP_WORDDATA:
604 case ARGP_DWORDDATA:
605 case ARGP_CHARLIST:
606 case ARGP_NAME:
607 case ARGP_NAMESTRING:
608
Robert Moore44f6c012005-04-18 22:49:35 -0400609 /* Constants, strings, and namestrings are all the same size */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 arg = acpi_ps_alloc_op(AML_BYTE_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400613 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
Len Brown4be44fc2005-08-05 00:44:28 -0400615 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 break;
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 case ARGP_PKGLENGTH:
619
620 /* Package length, nothing returned */
621
Len Brown4be44fc2005-08-05 00:44:28 -0400622 parser_state->pkg_end =
623 acpi_ps_get_next_package_end(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 break;
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 case ARGP_FIELDLIST:
627
628 if (parser_state->aml < parser_state->pkg_end) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* Non-empty list */
631
632 while (parser_state->aml < parser_state->pkg_end) {
Len Brown4be44fc2005-08-05 00:44:28 -0400633 field = acpi_ps_get_next_field(parser_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (!field) {
Len Brown4be44fc2005-08-05 00:44:28 -0400635 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637
638 if (prev) {
639 prev->common.next = field;
Len Brown4be44fc2005-08-05 00:44:28 -0400640 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 arg = field;
642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 prev = field;
644 }
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_BYTELIST:
653
654 if (parser_state->aml < parser_state->pkg_end) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 /* Non-empty list */
657
Len Brown4be44fc2005-08-05 00:44:28 -0400658 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400660 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
663 /* Fill in bytelist data */
664
Robert Moore44f6c012005-04-18 22:49:35 -0400665 arg->common.value.size = (u32)
Len Brown4be44fc2005-08-05 00:44:28 -0400666 ACPI_PTR_DIFF(parser_state->pkg_end,
667 parser_state->aml);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 arg->named.data = parser_state->aml;
669
670 /* Skip to End of byte data */
671
672 parser_state->aml = parser_state->pkg_end;
673 }
674 break;
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 case ARGP_TARGET:
677 case ARGP_SUPERNAME:
678 case ARGP_SIMPLENAME:
679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 subop = acpi_ps_peek_opcode(parser_state);
681 if (subop == 0 ||
682 acpi_ps_is_leading_char(subop) ||
683 acpi_ps_is_prefix_char(subop)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /* null_name or name_string */
686
Len Brown4be44fc2005-08-05 00:44:28 -0400687 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 if (!arg) {
Len Brown4be44fc2005-08-05 00:44:28 -0400689 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691
Lin Mingbc7a36a2008-04-10 19:06:42 +0400692 /* To support super_name arg of Unload */
693
Bob Moore84105652008-06-10 14:29:26 +0800694 if (walk_state->opcode == AML_UNLOAD_OP) {
Lin Mingbc7a36a2008-04-10 19:06:42 +0400695 status =
696 acpi_ps_get_next_namepath(walk_state,
697 parser_state, arg,
698 1);
699
700 /*
701 * If the super_name arg of Unload is a method call,
702 * we have restored the AML pointer, just free this Arg
703 */
704 if (arg->common.aml_opcode ==
705 AML_INT_METHODCALL_OP) {
706 acpi_ps_free_op(arg);
707 arg = NULL;
708 }
709 } else {
710 status =
711 acpi_ps_get_next_namepath(walk_state,
712 parser_state, arg,
713 0);
714 }
Len Brown4be44fc2005-08-05 00:44:28 -0400715 } else {
Robert Moore44f6c012005-04-18 22:49:35 -0400716 /* Single complex argument, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
718 walk_state->arg_count = 1;
719 }
720 break;
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 case ARGP_DATAOBJ:
723 case ARGP_TERMARG:
724
Robert Moore44f6c012005-04-18 22:49:35 -0400725 /* Single complex argument, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 walk_state->arg_count = 1;
728 break;
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 case ARGP_DATAOBJLIST:
731 case ARGP_TERMLIST:
732 case ARGP_OBJLIST:
733
734 if (parser_state->aml < parser_state->pkg_end) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400735
Robert Moore44f6c012005-04-18 22:49:35 -0400736 /* Non-empty list of variable arguments, nothing returned */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 walk_state->arg_count = ACPI_VAR_ARGS;
739 }
740 break;
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 default:
743
Bob Mooreb229cf92006-04-21 17:15:00 -0400744 ACPI_ERROR((AE_INFO, "Invalid ArgType: %X", arg_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 status = AE_AML_OPERAND_TYPE;
746 break;
747 }
748
749 *return_arg = arg;
Len Brown4be44fc2005-08-05 00:44:28 -0400750 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751}