1 /******************************************************************************
3 * Module Name: psargs - Parse AML opcode arguments
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define _COMPONENT ACPI_PARSER
33 MODULE_NAME ("psargs")
36 /*******************************************************************************
38 * FUNCTION: Acpi_ps_get_next_package_length
40 * PARAMETERS: Parser_state - Current parser state object
42 * RETURN: Decoded package length. On completion, the AML pointer points
43 * past the length byte or bytes.
45 * DESCRIPTION: Decode and return a package length field
47 ******************************************************************************/
50 acpi_ps_get_next_package_length (
51 acpi_parse_state *parser_state)
57 FUNCTION_TRACE ("Ps_get_next_package_length");
60 encoded_length = (u32) GET8 (parser_state->aml);
64 switch (encoded_length >> 6) /* bits 6-7 contain encoding scheme */ {
65 case 0: /* 1-byte encoding (bits 0-5) */
67 length = (encoded_length & 0x3F);
71 case 1: /* 2-byte encoding (next byte + bits 0-3) */
73 length = ((GET8 (parser_state->aml) << 04) |
74 (encoded_length & 0x0F));
79 case 2: /* 3-byte encoding (next 2 bytes + bits 0-3) */
81 length = ((GET8 (parser_state->aml + 1) << 12) |
82 (GET8 (parser_state->aml) << 04) |
83 (encoded_length & 0x0F));
84 parser_state->aml += 2;
88 case 3: /* 4-byte encoding (next 3 bytes + bits 0-3) */
90 length = ((GET8 (parser_state->aml + 2) << 20) |
91 (GET8 (parser_state->aml + 1) << 12) |
92 (GET8 (parser_state->aml) << 04) |
93 (encoded_length & 0x0F));
94 parser_state->aml += 3;
98 return_VALUE (length);
102 /*******************************************************************************
104 * FUNCTION: Acpi_ps_get_next_package_end
106 * PARAMETERS: Parser_state - Current parser state object
108 * RETURN: Pointer to end-of-package +1
110 * DESCRIPTION: Get next package length and return a pointer past the end of
111 * the package. Consumes the package length field
113 ******************************************************************************/
116 acpi_ps_get_next_package_end (
117 acpi_parse_state *parser_state)
119 u8 *start = parser_state->aml;
123 FUNCTION_TRACE ("Ps_get_next_package_end");
126 length = (NATIVE_UINT) acpi_ps_get_next_package_length (parser_state);
128 return_PTR (start + length); /* end of package */
132 /*******************************************************************************
134 * FUNCTION: Acpi_ps_get_next_namestring
136 * PARAMETERS: Parser_state - Current parser state object
138 * RETURN: Pointer to the start of the name string (pointer points into
141 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
142 * prefix characters. Set parser state to point past the string.
143 * (Name is consumed from the AML.)
145 ******************************************************************************/
148 acpi_ps_get_next_namestring (
149 acpi_parse_state *parser_state)
151 u8 *start = parser_state->aml;
152 u8 *end = parser_state->aml;
156 FUNCTION_TRACE ("Ps_get_next_namestring");
159 /* Handle multiple prefix characters */
161 while (acpi_ps_is_prefix_char (GET8 (end))) {
162 /* include prefix '\\' or '^' */
167 /* Decode the path */
169 switch (GET8 (end)) {
181 case AML_DUAL_NAME_PREFIX:
183 /* two name segments */
189 case AML_MULTI_NAME_PREFIX_OP:
191 /* multiple name segments */
193 length = (u32) GET8 (end + 1) * 4;
200 /* single name segment */
201 /* assert (Acpi_ps_is_lead (GET8 (End))); */
207 parser_state->aml = (u8*) end;
209 return_PTR ((NATIVE_CHAR *) start);
213 /*******************************************************************************
215 * FUNCTION: Acpi_ps_get_next_namepath
217 * PARAMETERS: Parser_state - Current parser state object
218 * Arg - Where the namepath will be stored
219 * Arg_count - If the namepath points to a control method
220 * the method's argument is returned here.
221 * Method_call - Whether the namepath can be the start
226 * DESCRIPTION: Get next name (if method call, push appropriate # args). Names
227 * are looked up in either the parsed or internal namespace to
228 * determine if the name represents a control method. If a method
229 * is found, the number of arguments to the method is returned.
230 * This information is critical for parsing to continue correctly.
232 ******************************************************************************/
238 acpi_ps_get_next_namepath (
239 acpi_parse_state *parser_state,
240 acpi_parse_object *arg,
245 acpi_parse_object *name_op;
246 acpi_parse_object *op;
247 acpi_parse_object *count;
250 FUNCTION_TRACE ("Ps_get_next_namepath");
253 path = acpi_ps_get_next_namestring (parser_state);
254 if (!path || !method_call) {
255 /* Null name case, create a null namepath object */
257 acpi_ps_init_op (arg, AML_INT_NAMEPATH_OP);
258 arg->value.name = path;
263 if (acpi_gbl_parsed_namespace_root) {
265 * Lookup the name in the parsed namespace
269 op = acpi_ps_find (acpi_ps_get_parent_scope (parser_state),
270 path, AML_METHOD_OP, 0);
274 if (op->opcode == AML_METHOD_OP) {
276 * The name refers to a control method, so this namepath is a
277 * method invocation. We need to 1) Get the number of arguments
278 * associated with this method, and 2) Change the NAMEPATH
279 * object into a METHODCALL object.
281 count = acpi_ps_get_arg (op, 0);
282 if (count && count->opcode == AML_BYTE_OP) {
283 name_op = acpi_ps_alloc_op (AML_INT_NAMEPATH_OP);
285 /* Change arg into a METHOD CALL and attach the name */
287 acpi_ps_init_op (arg, AML_INT_METHODCALL_OP);
289 name_op->value.name = path;
291 /* Point METHODCALL/NAME to the METHOD Node */
293 name_op->node = (acpi_namespace_node *) op;
294 acpi_ps_append_arg (arg, name_op);
296 *arg_count = (u32) count->value.integer &
297 METHOD_FLAGS_ARG_COUNT;
305 * Else this is normal named object reference.
306 * Just init the NAMEPATH object with the pathname.
313 * Either we didn't find the object in the namespace, or the object is
314 * something other than a control method. Just initialize the Op with the
317 acpi_ps_init_op (arg, AML_INT_NAMEPATH_OP);
318 arg->value.name = path;
329 acpi_ps_get_next_namepath (
330 acpi_parse_state *parser_state,
331 acpi_parse_object *arg,
336 acpi_parse_object *name_op;
338 acpi_namespace_node *method_node = NULL;
339 acpi_namespace_node *node;
340 acpi_generic_state scope_info;
343 FUNCTION_TRACE ("Ps_get_next_namepath");
346 path = acpi_ps_get_next_namestring (parser_state);
347 if (!path || !method_call) {
348 /* Null name case, create a null namepath object */
350 acpi_ps_init_op (arg, AML_INT_NAMEPATH_OP);
351 arg->value.name = path;
358 * Lookup the name in the internal namespace
360 scope_info.scope.node = NULL;
361 node = parser_state->start_node;
363 scope_info.scope.node = node;
367 * Lookup object. We don't want to add anything new to the namespace
368 * here, however. So we use MODE_EXECUTE. Allow searching of the
369 * parent tree, but don't open a new scope -- we just want to lookup the
370 * object (MUST BE mode EXECUTE to perform upsearch)
372 status = acpi_ns_lookup (&scope_info, path, ACPI_TYPE_ANY, IMODE_EXECUTE,
373 NS_SEARCH_PARENT | NS_DONT_OPEN_SCOPE, NULL,
375 if (ACPI_SUCCESS (status)) {
376 if (node->type == ACPI_TYPE_METHOD) {
378 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "method - %p Path=%p\n",
381 name_op = acpi_ps_alloc_op (AML_INT_NAMEPATH_OP);
383 /* Change arg into a METHOD CALL and attach name to it */
385 acpi_ps_init_op (arg, AML_INT_METHODCALL_OP);
387 name_op->value.name = path;
389 /* Point METHODCALL/NAME to the METHOD Node */
391 name_op->node = method_node;
392 acpi_ps_append_arg (arg, name_op);
394 if (!method_node->object) {
398 *arg_count = (method_node->object)->method.param_count;
405 * Else this is normal named object reference.
406 * Just init the NAMEPATH object with the pathname.
413 * Either we didn't find the object in the namespace, or the object is
414 * something other than a control method. Just initialize the Op with the
417 acpi_ps_init_op (arg, AML_INT_NAMEPATH_OP);
418 arg->value.name = path;
426 /*******************************************************************************
428 * FUNCTION: Acpi_ps_get_next_simple_arg
430 * PARAMETERS: Parser_state - Current parser state object
431 * Arg_type - The argument type (AML_*_ARG)
432 * Arg - Where the argument is returned
436 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
438 ******************************************************************************/
441 acpi_ps_get_next_simple_arg (
442 acpi_parse_state *parser_state,
444 acpi_parse_object *arg)
447 FUNCTION_TRACE_U32 ("Ps_get_next_simple_arg", arg_type);
454 acpi_ps_init_op (arg, AML_BYTE_OP);
455 arg->value.integer = (u32) GET8 (parser_state->aml);
462 acpi_ps_init_op (arg, AML_WORD_OP);
464 /* Get 2 bytes from the AML stream */
466 MOVE_UNALIGNED16_TO_32 (&arg->value.integer, parser_state->aml);
467 parser_state->aml += 2;
473 acpi_ps_init_op (arg, AML_DWORD_OP);
475 /* Get 4 bytes from the AML stream */
477 MOVE_UNALIGNED32_TO_32 (&arg->value.integer, parser_state->aml);
478 parser_state->aml += 4;
484 acpi_ps_init_op (arg, AML_QWORD_OP);
486 /* Get 8 bytes from the AML stream */
488 MOVE_UNALIGNED64_TO_64 (&arg->value.integer, parser_state->aml);
489 parser_state->aml += 8;
495 acpi_ps_init_op (arg, AML_STRING_OP);
496 arg->value.string = (char*) parser_state->aml;
498 while (GET8 (parser_state->aml) != '\0') {
506 case ARGP_NAMESTRING:
508 acpi_ps_init_op (arg, AML_INT_NAMEPATH_OP);
509 arg->value.name = acpi_ps_get_next_namestring (parser_state);
517 /*******************************************************************************
519 * FUNCTION: Acpi_ps_get_next_field
521 * PARAMETERS: Parser_state - Current parser state object
523 * RETURN: A newly allocated FIELD op
525 * DESCRIPTION: Get next field (Named_field, Reserved_field, or Access_field)
527 ******************************************************************************/
530 acpi_ps_get_next_field (
531 acpi_parse_state *parser_state)
533 u32 aml_offset = parser_state->aml -
534 parser_state->aml_start;
535 acpi_parse_object *field;
540 FUNCTION_TRACE ("Ps_get_next_field");
543 /* determine field type */
545 switch (GET8 (parser_state->aml)) {
549 opcode = AML_INT_NAMEDFIELD_OP;
555 opcode = AML_INT_RESERVEDFIELD_OP;
562 opcode = AML_INT_ACCESSFIELD_OP;
568 /* Allocate a new field op */
570 field = acpi_ps_alloc_op (opcode);
572 field->aml_offset = aml_offset;
574 /* Decode the field type */
577 case AML_INT_NAMEDFIELD_OP:
579 /* Get the 4-character name */
581 MOVE_UNALIGNED32_TO_32 (&name, parser_state->aml);
582 acpi_ps_set_name (field, name);
583 parser_state->aml += 4;
585 /* Get the length which is encoded as a package length */
587 field->value.size = acpi_ps_get_next_package_length (parser_state);
591 case AML_INT_RESERVEDFIELD_OP:
593 /* Get the length which is encoded as a package length */
595 field->value.size = acpi_ps_get_next_package_length (parser_state);
599 case AML_INT_ACCESSFIELD_OP:
601 /* Get Access_type and Access_atrib and merge into the field Op */
603 field->value.integer = ((GET8 (parser_state->aml) << 8) |
604 GET8 (parser_state->aml));
605 parser_state->aml += 2;
614 /*******************************************************************************
616 * FUNCTION: Acpi_ps_get_next_arg
618 * PARAMETERS: Parser_state - Current parser state object
619 * Arg_type - The argument type (AML_*_ARG)
620 * Arg_count - If the argument points to a control method
621 * the method's argument is returned here.
623 * RETURN: An op object containing the next argument.
625 * DESCRIPTION: Get next argument (including complex list arguments that require
626 * pushing the parser stack)
628 ******************************************************************************/
631 acpi_ps_get_next_arg (
632 acpi_parse_state *parser_state,
636 acpi_parse_object *arg = NULL;
637 acpi_parse_object *prev = NULL;
638 acpi_parse_object *field;
642 FUNCTION_TRACE_PTR ("Ps_get_next_arg", parser_state);
651 case ARGP_NAMESTRING:
653 /* constants, strings, and namestrings are all the same size */
655 arg = acpi_ps_alloc_op (AML_BYTE_OP);
657 acpi_ps_get_next_simple_arg (parser_state, arg_type, arg);
664 /* package length, nothing returned */
666 parser_state->pkg_end = acpi_ps_get_next_package_end (parser_state);
672 if (parser_state->aml < parser_state->pkg_end) {
675 while (parser_state->aml < parser_state->pkg_end) {
676 field = acpi_ps_get_next_field (parser_state);
692 /* skip to End of byte data */
694 parser_state->aml = parser_state->pkg_end;
701 if (parser_state->aml < parser_state->pkg_end) {
704 arg = acpi_ps_alloc_op (AML_INT_BYTELIST_OP);
706 /* fill in bytelist data */
708 arg->value.size = (parser_state->pkg_end - parser_state->aml);
709 ((acpi_parse2_object *) arg)->data = parser_state->aml;
712 /* skip to End of byte data */
714 parser_state->aml = parser_state->pkg_end;
720 case ARGP_SUPERNAME: {
721 subop = acpi_ps_peek_opcode (parser_state);
723 acpi_ps_is_leading_char (subop) ||
724 acpi_ps_is_prefix_char (subop)) {
725 /* Null_name or Name_string */
727 arg = acpi_ps_alloc_op (AML_INT_NAMEPATH_OP);
729 acpi_ps_get_next_namepath (parser_state, arg, arg_count, 0);
734 /* single complex argument, nothing returned */
745 /* single complex argument, nothing returned */
751 case ARGP_DATAOBJLIST:
755 if (parser_state->aml < parser_state->pkg_end) {
756 /* non-empty list of variable arguments, nothing returned */
758 *arg_count = ACPI_VAR_ARGS;