Loading...
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/******************************************************************************
3 *
4 * Module Name: psargs - Parse AML opcode arguments
5 *
6 * Copyright (C) 2000 - 2023, Intel Corp.
7 *
8 *****************************************************************************/
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acparser.h"
13#include "amlcode.h"
14#include "acnamesp.h"
15#include "acdispat.h"
16#include "acconvert.h"
17
18#define _COMPONENT ACPI_PARSER
19ACPI_MODULE_NAME("psargs")
20
21/* Local prototypes */
22static u32
23acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
24
25static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
26 *parser_state);
27
28static void acpi_ps_free_field_list(union acpi_parse_object *start);
29
30/*******************************************************************************
31 *
32 * FUNCTION: acpi_ps_get_next_package_length
33 *
34 * PARAMETERS: parser_state - Current parser state object
35 *
36 * RETURN: Decoded package length. On completion, the AML pointer points
37 * past the length byte or bytes.
38 *
39 * DESCRIPTION: Decode and return a package length field.
40 * Note: Largest package length is 28 bits, from ACPI specification
41 *
42 ******************************************************************************/
43
44static u32
45acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
46{
47 u8 *aml = parser_state->aml;
48 u32 package_length = 0;
49 u32 byte_count;
50 u8 byte_zero_mask = 0x3F; /* Default [0:5] */
51
52 ACPI_FUNCTION_TRACE(ps_get_next_package_length);
53
54 /*
55 * Byte 0 bits [6:7] contain the number of additional bytes
56 * used to encode the package length, either 0,1,2, or 3
57 */
58 byte_count = (aml[0] >> 6);
59 parser_state->aml += ((acpi_size)byte_count + 1);
60
61 /* Get bytes 3, 2, 1 as needed */
62
63 while (byte_count) {
64 /*
65 * Final bit positions for the package length bytes:
66 * Byte3->[20:27]
67 * Byte2->[12:19]
68 * Byte1->[04:11]
69 * Byte0->[00:03]
70 */
71 package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
72
73 byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */
74 byte_count--;
75 }
76
77 /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
78
79 package_length |= (aml[0] & byte_zero_mask);
80 return_UINT32(package_length);
81}
82
83/*******************************************************************************
84 *
85 * FUNCTION: acpi_ps_get_next_package_end
86 *
87 * PARAMETERS: parser_state - Current parser state object
88 *
89 * RETURN: Pointer to end-of-package +1
90 *
91 * DESCRIPTION: Get next package length and return a pointer past the end of
92 * the package. Consumes the package length field
93 *
94 ******************************************************************************/
95
96u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
97{
98 u8 *start = parser_state->aml;
99 u32 package_length;
100
101 ACPI_FUNCTION_TRACE(ps_get_next_package_end);
102
103 /* Function below updates parser_state->Aml */
104
105 package_length = acpi_ps_get_next_package_length(parser_state);
106
107 return_PTR(start + package_length); /* end of package */
108}
109
110/*******************************************************************************
111 *
112 * FUNCTION: acpi_ps_get_next_namestring
113 *
114 * PARAMETERS: parser_state - Current parser state object
115 *
116 * RETURN: Pointer to the start of the name string (pointer points into
117 * the AML.
118 *
119 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
120 * prefix characters. Set parser state to point past the string.
121 * (Name is consumed from the AML.)
122 *
123 ******************************************************************************/
124
125char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
126{
127 u8 *start = parser_state->aml;
128 u8 *end = parser_state->aml;
129
130 ACPI_FUNCTION_TRACE(ps_get_next_namestring);
131
132 /* Point past any namestring prefix characters (backslash or carat) */
133
134 while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) {
135 end++;
136 }
137
138 /* Decode the path prefix character */
139
140 switch (*end) {
141 case 0:
142
143 /* null_name */
144
145 if (end == start) {
146 start = NULL;
147 }
148 end++;
149 break;
150
151 case AML_DUAL_NAME_PREFIX:
152
153 /* Two name segments */
154
155 end += 1 + (2 * ACPI_NAMESEG_SIZE);
156 break;
157
158 case AML_MULTI_NAME_PREFIX:
159
160 /* Multiple name segments, 4 chars each, count in next byte */
161
162 end += 2 + (*(end + 1) * ACPI_NAMESEG_SIZE);
163 break;
164
165 default:
166
167 /* Single name segment */
168
169 end += ACPI_NAMESEG_SIZE;
170 break;
171 }
172
173 parser_state->aml = end;
174 return_PTR((char *)start);
175}
176
177/*******************************************************************************
178 *
179 * FUNCTION: acpi_ps_get_next_namepath
180 *
181 * PARAMETERS: parser_state - Current parser state object
182 * arg - Where the namepath will be stored
183 * arg_count - If the namepath points to a control method
184 * the method's argument is returned here.
185 * possible_method_call - Whether the namepath can possibly be the
186 * start of a method call
187 *
188 * RETURN: Status
189 *
190 * DESCRIPTION: Get next name (if method call, return # of required args).
191 * Names are looked up in the internal namespace to determine
192 * if the name represents a control method. If a method
193 * is found, the number of arguments to the method is returned.
194 * This information is critical for parsing to continue correctly.
195 *
196 ******************************************************************************/
197
198acpi_status
199acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
200 struct acpi_parse_state *parser_state,
201 union acpi_parse_object *arg, u8 possible_method_call)
202{
203 acpi_status status;
204 char *path;
205 union acpi_parse_object *name_op;
206 union acpi_operand_object *method_desc;
207 struct acpi_namespace_node *node;
208 u8 *start = parser_state->aml;
209
210 ACPI_FUNCTION_TRACE(ps_get_next_namepath);
211
212 path = acpi_ps_get_next_namestring(parser_state);
213 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
214
215 /* Null path case is allowed, just exit */
216
217 if (!path) {
218 arg->common.value.name = path;
219 return_ACPI_STATUS(AE_OK);
220 }
221
222 /*
223 * Lookup the name in the internal namespace, starting with the current
224 * scope. We don't want to add anything new to the namespace here,
225 * however, so we use MODE_EXECUTE.
226 * Allow searching of the parent tree, but don't open a new scope -
227 * we just want to lookup the object (must be mode EXECUTE to perform
228 * the upsearch)
229 */
230 status = acpi_ns_lookup(walk_state->scope_info, path,
231 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
232 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
233 NULL, &node);
234
235 /*
236 * If this name is a control method invocation, we must
237 * setup the method call
238 */
239 if (ACPI_SUCCESS(status) &&
240 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
241 if ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
242 ARGP_SUPERNAME)
243 || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
244 ARGP_TARGET)) {
245 /*
246 * acpi_ps_get_next_namestring has increased the AML pointer past
247 * the method invocation namestring, so we need to restore the
248 * saved AML pointer back to the original method invocation
249 * namestring.
250 */
251 walk_state->parser_state.aml = start;
252 walk_state->arg_count = 1;
253 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
254 }
255
256 /* This name is actually a control method invocation */
257
258 method_desc = acpi_ns_get_attached_object(node);
259 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
260 "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
261 node->name.ascii, node, method_desc, path));
262
263 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start);
264 if (!name_op) {
265 return_ACPI_STATUS(AE_NO_MEMORY);
266 }
267
268 /* Change Arg into a METHOD CALL and attach name to it */
269
270 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
271 name_op->common.value.name = path;
272
273 /* Point METHODCALL/NAME to the METHOD Node */
274
275 name_op->common.node = node;
276 acpi_ps_append_arg(arg, name_op);
277
278 if (!method_desc) {
279 ACPI_ERROR((AE_INFO,
280 "Control Method %p has no attached object",
281 node));
282 return_ACPI_STATUS(AE_AML_INTERNAL);
283 }
284
285 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
286 "Control Method - %p Args %X\n",
287 node, method_desc->method.param_count));
288
289 /* Get the number of arguments to expect */
290
291 walk_state->arg_count = method_desc->method.param_count;
292 return_ACPI_STATUS(AE_OK);
293 }
294
295 /*
296 * Special handling if the name was not found during the lookup -
297 * some not_found cases are allowed
298 */
299 if (status == AE_NOT_FOUND) {
300
301 /* 1) not_found is ok during load pass 1/2 (allow forward references) */
302
303 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
304 ACPI_PARSE_EXECUTE) {
305 status = AE_OK;
306 }
307
308 /* 2) not_found during a cond_ref_of(x) is ok by definition */
309
310 else if (walk_state->op->common.aml_opcode ==
311 AML_CONDITIONAL_REF_OF_OP) {
312 status = AE_OK;
313 }
314
315 /*
316 * 3) not_found while building a Package is ok at this point, we
317 * may flag as an error later if slack mode is not enabled.
318 * (Some ASL code depends on allowing this behavior)
319 */
320 else if ((arg->common.parent) &&
321 ((arg->common.parent->common.aml_opcode ==
322 AML_PACKAGE_OP)
323 || (arg->common.parent->common.aml_opcode ==
324 AML_VARIABLE_PACKAGE_OP))) {
325 status = AE_OK;
326 }
327 }
328
329 /* Final exception check (may have been changed from code above) */
330
331 if (ACPI_FAILURE(status)) {
332 ACPI_ERROR_NAMESPACE(walk_state->scope_info, path, status);
333
334 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
335 ACPI_PARSE_EXECUTE) {
336
337 /* Report a control method execution error */
338
339 status = acpi_ds_method_error(status, walk_state);
340 }
341 }
342
343 /* Save the namepath */
344
345 arg->common.value.name = path;
346 return_ACPI_STATUS(status);
347}
348
349/*******************************************************************************
350 *
351 * FUNCTION: acpi_ps_get_next_simple_arg
352 *
353 * PARAMETERS: parser_state - Current parser state object
354 * arg_type - The argument type (AML_*_ARG)
355 * arg - Where the argument is returned
356 *
357 * RETURN: None
358 *
359 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
360 *
361 ******************************************************************************/
362
363void
364acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
365 u32 arg_type, union acpi_parse_object *arg)
366{
367 u32 length;
368 u16 opcode;
369 u8 *aml = parser_state->aml;
370
371 ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
372
373 switch (arg_type) {
374 case ARGP_BYTEDATA:
375
376 /* Get 1 byte from the AML stream */
377
378 opcode = AML_BYTE_OP;
379 arg->common.value.integer = (u64) *aml;
380 length = 1;
381 break;
382
383 case ARGP_WORDDATA:
384
385 /* Get 2 bytes from the AML stream */
386
387 opcode = AML_WORD_OP;
388 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
389 length = 2;
390 break;
391
392 case ARGP_DWORDDATA:
393
394 /* Get 4 bytes from the AML stream */
395
396 opcode = AML_DWORD_OP;
397 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
398 length = 4;
399 break;
400
401 case ARGP_QWORDDATA:
402
403 /* Get 8 bytes from the AML stream */
404
405 opcode = AML_QWORD_OP;
406 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
407 length = 8;
408 break;
409
410 case ARGP_CHARLIST:
411
412 /* Get a pointer to the string, point past the string */
413
414 opcode = AML_STRING_OP;
415 arg->common.value.string = ACPI_CAST_PTR(char, aml);
416
417 /* Find the null terminator */
418
419 length = 0;
420 while (aml[length]) {
421 length++;
422 }
423 length++;
424 break;
425
426 case ARGP_NAME:
427 case ARGP_NAMESTRING:
428
429 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
430 arg->common.value.name =
431 acpi_ps_get_next_namestring(parser_state);
432 return_VOID;
433
434 default:
435
436 ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
437 return_VOID;
438 }
439
440 acpi_ps_init_op(arg, opcode);
441 parser_state->aml += length;
442 return_VOID;
443}
444
445/*******************************************************************************
446 *
447 * FUNCTION: acpi_ps_get_next_field
448 *
449 * PARAMETERS: parser_state - Current parser state object
450 *
451 * RETURN: A newly allocated FIELD op
452 *
453 * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
454 *
455 ******************************************************************************/
456
457static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
458 *parser_state)
459{
460 u8 *aml;
461 union acpi_parse_object *field;
462 union acpi_parse_object *arg = NULL;
463 u16 opcode;
464 u32 name;
465 u8 access_type;
466 u8 access_attribute;
467 u8 access_length;
468 u32 pkg_length;
469 u8 *pkg_end;
470 u32 buffer_length;
471
472 ACPI_FUNCTION_TRACE(ps_get_next_field);
473
474 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
475 aml = parser_state->aml;
476
477 /* Determine field type */
478
479 switch (ACPI_GET8(parser_state->aml)) {
480 case AML_FIELD_OFFSET_OP:
481
482 opcode = AML_INT_RESERVEDFIELD_OP;
483 parser_state->aml++;
484 break;
485
486 case AML_FIELD_ACCESS_OP:
487
488 opcode = AML_INT_ACCESSFIELD_OP;
489 parser_state->aml++;
490 break;
491
492 case AML_FIELD_CONNECTION_OP:
493
494 opcode = AML_INT_CONNECTION_OP;
495 parser_state->aml++;
496 break;
497
498 case AML_FIELD_EXT_ACCESS_OP:
499
500 opcode = AML_INT_EXTACCESSFIELD_OP;
501 parser_state->aml++;
502 break;
503
504 default:
505
506 opcode = AML_INT_NAMEDFIELD_OP;
507 break;
508 }
509
510 /* Allocate a new field op */
511
512 field = acpi_ps_alloc_op(opcode, aml);
513 if (!field) {
514 return_PTR(NULL);
515 }
516
517 /* Decode the field type */
518
519 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
520 switch (opcode) {
521 case AML_INT_NAMEDFIELD_OP:
522
523 /* Get the 4-character name */
524
525 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
526 acpi_ps_set_name(field, name);
527 parser_state->aml += ACPI_NAMESEG_SIZE;
528
529 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
530
531#ifdef ACPI_ASL_COMPILER
532 /*
533 * Because the package length isn't represented as a parse tree object,
534 * take comments surrounding this and add to the previously created
535 * parse node.
536 */
537 if (field->common.inline_comment) {
538 field->common.name_comment =
539 field->common.inline_comment;
540 }
541 field->common.inline_comment = acpi_gbl_current_inline_comment;
542 acpi_gbl_current_inline_comment = NULL;
543#endif
544
545 /* Get the length which is encoded as a package length */
546
547 field->common.value.size =
548 acpi_ps_get_next_package_length(parser_state);
549 break;
550
551 case AML_INT_RESERVEDFIELD_OP:
552
553 /* Get the length which is encoded as a package length */
554
555 field->common.value.size =
556 acpi_ps_get_next_package_length(parser_state);
557 break;
558
559 case AML_INT_ACCESSFIELD_OP:
560 case AML_INT_EXTACCESSFIELD_OP:
561
562 /*
563 * Get access_type and access_attrib and merge into the field Op
564 * access_type is first operand, access_attribute is second. stuff
565 * these bytes into the node integer value for convenience.
566 */
567
568 /* Get the two bytes (Type/Attribute) */
569
570 access_type = ACPI_GET8(parser_state->aml);
571 parser_state->aml++;
572 access_attribute = ACPI_GET8(parser_state->aml);
573 parser_state->aml++;
574
575 field->common.value.integer = (u8)access_type;
576 field->common.value.integer |= (u16)(access_attribute << 8);
577
578 /* This opcode has a third byte, access_length */
579
580 if (opcode == AML_INT_EXTACCESSFIELD_OP) {
581 access_length = ACPI_GET8(parser_state->aml);
582 parser_state->aml++;
583
584 field->common.value.integer |=
585 (u32)(access_length << 16);
586 }
587 break;
588
589 case AML_INT_CONNECTION_OP:
590
591 /*
592 * Argument for Connection operator can be either a Buffer
593 * (resource descriptor), or a name_string.
594 */
595 aml = parser_state->aml;
596 if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
597 parser_state->aml++;
598
599 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
600 pkg_end = parser_state->aml;
601 pkg_length =
602 acpi_ps_get_next_package_length(parser_state);
603 pkg_end += pkg_length;
604
605 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
606 if (parser_state->aml < pkg_end) {
607
608 /* Non-empty list */
609
610 arg =
611 acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
612 if (!arg) {
613 acpi_ps_free_op(field);
614 return_PTR(NULL);
615 }
616
617 /* Get the actual buffer length argument */
618
619 opcode = ACPI_GET8(parser_state->aml);
620 parser_state->aml++;
621
622 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
623 switch (opcode) {
624 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
625
626 buffer_length =
627 ACPI_GET8(parser_state->aml);
628 parser_state->aml += 1;
629 break;
630
631 case AML_WORD_OP: /* AML_WORDDATA_ARG */
632
633 buffer_length =
634 ACPI_GET16(parser_state->aml);
635 parser_state->aml += 2;
636 break;
637
638 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
639
640 buffer_length =
641 ACPI_GET32(parser_state->aml);
642 parser_state->aml += 4;
643 break;
644
645 default:
646
647 buffer_length = 0;
648 break;
649 }
650
651 /* Fill in bytelist data */
652
653 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
654 arg->named.value.size = buffer_length;
655 arg->named.data = parser_state->aml;
656 }
657
658 /* Skip to End of byte data */
659
660 parser_state->aml = pkg_end;
661 } else {
662 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
663 if (!arg) {
664 acpi_ps_free_op(field);
665 return_PTR(NULL);
666 }
667
668 /* Get the Namestring argument */
669
670 arg->common.value.name =
671 acpi_ps_get_next_namestring(parser_state);
672 }
673
674 /* Link the buffer/namestring to parent (CONNECTION_OP) */
675
676 acpi_ps_append_arg(field, arg);
677 break;
678
679 default:
680
681 /* Opcode was set in previous switch */
682 break;
683 }
684
685 return_PTR(field);
686}
687
688/*******************************************************************************
689 *
690 * FUNCTION: acpi_ps_free_field_list
691 *
692 * PARAMETERS: start - First Op in field list
693 *
694 * RETURN: None.
695 *
696 * DESCRIPTION: Free all Op objects inside a field list.
697 *
698 ******************************************************************************/
699
700static void acpi_ps_free_field_list(union acpi_parse_object *start)
701{
702 union acpi_parse_object *cur = start;
703 union acpi_parse_object *next;
704 union acpi_parse_object *arg;
705
706 while (cur) {
707 next = cur->common.next;
708
709 /* AML_INT_CONNECTION_OP can have a single argument */
710
711 arg = acpi_ps_get_arg(cur, 0);
712 if (arg) {
713 acpi_ps_free_op(arg);
714 }
715
716 acpi_ps_free_op(cur);
717 cur = next;
718 }
719}
720
721/*******************************************************************************
722 *
723 * FUNCTION: acpi_ps_get_next_arg
724 *
725 * PARAMETERS: walk_state - Current state
726 * parser_state - Current parser state object
727 * arg_type - The argument type (AML_*_ARG)
728 * return_arg - Where the next arg is returned
729 *
730 * RETURN: Status, and an op object containing the next argument.
731 *
732 * DESCRIPTION: Get next argument (including complex list arguments that require
733 * pushing the parser stack)
734 *
735 ******************************************************************************/
736
737acpi_status
738acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
739 struct acpi_parse_state *parser_state,
740 u32 arg_type, union acpi_parse_object **return_arg)
741{
742 union acpi_parse_object *arg = NULL;
743 union acpi_parse_object *prev = NULL;
744 union acpi_parse_object *field;
745 u32 subop;
746 acpi_status status = AE_OK;
747
748 ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
749
750 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
751 "Expected argument type ARGP: %s (%2.2X)\n",
752 acpi_ut_get_argument_type_name(arg_type), arg_type));
753
754 switch (arg_type) {
755 case ARGP_BYTEDATA:
756 case ARGP_WORDDATA:
757 case ARGP_DWORDDATA:
758 case ARGP_CHARLIST:
759 case ARGP_NAME:
760 case ARGP_NAMESTRING:
761
762 /* Constants, strings, and namestrings are all the same size */
763
764 arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
765 if (!arg) {
766 return_ACPI_STATUS(AE_NO_MEMORY);
767 }
768
769 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
770 break;
771
772 case ARGP_PKGLENGTH:
773
774 /* Package length, nothing returned */
775
776 parser_state->pkg_end =
777 acpi_ps_get_next_package_end(parser_state);
778 break;
779
780 case ARGP_FIELDLIST:
781
782 if (parser_state->aml < parser_state->pkg_end) {
783
784 /* Non-empty list */
785
786 while (parser_state->aml < parser_state->pkg_end) {
787 field = acpi_ps_get_next_field(parser_state);
788 if (!field) {
789 if (arg) {
790 acpi_ps_free_field_list(arg);
791 }
792
793 return_ACPI_STATUS(AE_NO_MEMORY);
794 }
795
796 if (prev) {
797 prev->common.next = field;
798 } else {
799 arg = field;
800 }
801 prev = field;
802 }
803
804 /* Skip to End of byte data */
805
806 parser_state->aml = parser_state->pkg_end;
807 }
808 break;
809
810 case ARGP_BYTELIST:
811
812 if (parser_state->aml < parser_state->pkg_end) {
813
814 /* Non-empty list */
815
816 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
817 parser_state->aml);
818 if (!arg) {
819 return_ACPI_STATUS(AE_NO_MEMORY);
820 }
821
822 /* Fill in bytelist data */
823
824 arg->common.value.size = (u32)
825 ACPI_PTR_DIFF(parser_state->pkg_end,
826 parser_state->aml);
827 arg->named.data = parser_state->aml;
828
829 /* Skip to End of byte data */
830
831 parser_state->aml = parser_state->pkg_end;
832 }
833 break;
834
835 case ARGP_SIMPLENAME:
836 case ARGP_NAME_OR_REF:
837
838 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
839 "**** SimpleName/NameOrRef: %s (%2.2X)\n",
840 acpi_ut_get_argument_type_name(arg_type),
841 arg_type));
842
843 subop = acpi_ps_peek_opcode(parser_state);
844 if (subop == 0 ||
845 acpi_ps_is_leading_char(subop) ||
846 ACPI_IS_ROOT_PREFIX(subop) ||
847 ACPI_IS_PARENT_PREFIX(subop)) {
848
849 /* null_name or name_string */
850
851 arg =
852 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
853 parser_state->aml);
854 if (!arg) {
855 return_ACPI_STATUS(AE_NO_MEMORY);
856 }
857
858 status =
859 acpi_ps_get_next_namepath(walk_state, parser_state,
860 arg,
861 ACPI_NOT_METHOD_CALL);
862 if (ACPI_FAILURE(status)) {
863 acpi_ps_free_op(arg);
864 return_ACPI_STATUS(status);
865 }
866 } else {
867 /* Single complex argument, nothing returned */
868
869 walk_state->arg_count = 1;
870 }
871 break;
872
873 case ARGP_TARGET:
874 case ARGP_SUPERNAME:
875
876 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
877 "**** Target/Supername: %s (%2.2X)\n",
878 acpi_ut_get_argument_type_name(arg_type),
879 arg_type));
880
881 subop = acpi_ps_peek_opcode(parser_state);
882 if (subop == 0 ||
883 acpi_ps_is_leading_char(subop) ||
884 ACPI_IS_ROOT_PREFIX(subop) ||
885 ACPI_IS_PARENT_PREFIX(subop)) {
886
887 /* NULL target (zero). Convert to a NULL namepath */
888
889 arg =
890 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
891 parser_state->aml);
892 if (!arg) {
893 return_ACPI_STATUS(AE_NO_MEMORY);
894 }
895
896 status =
897 acpi_ps_get_next_namepath(walk_state, parser_state,
898 arg,
899 ACPI_POSSIBLE_METHOD_CALL);
900 if (ACPI_FAILURE(status)) {
901 acpi_ps_free_op(arg);
902 return_ACPI_STATUS(status);
903 }
904
905 if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) {
906
907 /* Free method call op and corresponding namestring sub-ob */
908
909 acpi_ps_free_op(arg->common.value.arg);
910 acpi_ps_free_op(arg);
911 arg = NULL;
912 walk_state->arg_count = 1;
913 }
914 } else {
915 /* Single complex argument, nothing returned */
916
917 walk_state->arg_count = 1;
918 }
919 break;
920
921 case ARGP_DATAOBJ:
922 case ARGP_TERMARG:
923
924 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
925 "**** TermArg/DataObj: %s (%2.2X)\n",
926 acpi_ut_get_argument_type_name(arg_type),
927 arg_type));
928
929 /* Single complex argument, nothing returned */
930
931 walk_state->arg_count = 1;
932 break;
933
934 case ARGP_DATAOBJLIST:
935 case ARGP_TERMLIST:
936 case ARGP_OBJLIST:
937
938 if (parser_state->aml < parser_state->pkg_end) {
939
940 /* Non-empty list of variable arguments, nothing returned */
941
942 walk_state->arg_count = ACPI_VAR_ARGS;
943 }
944 break;
945
946 default:
947
948 ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
949 status = AE_AML_OPERAND_TYPE;
950 break;
951 }
952
953 *return_arg = arg;
954 return_ACPI_STATUS(status);
955}
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/******************************************************************************
3 *
4 * Module Name: psargs - Parse AML opcode arguments
5 *
6 * Copyright (C) 2000 - 2019, Intel Corp.
7 *
8 *****************************************************************************/
9
10#include <acpi/acpi.h>
11#include "accommon.h"
12#include "acparser.h"
13#include "amlcode.h"
14#include "acnamesp.h"
15#include "acdispat.h"
16#include "acconvert.h"
17
18#define _COMPONENT ACPI_PARSER
19ACPI_MODULE_NAME("psargs")
20
21/* Local prototypes */
22static u32
23acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state);
24
25static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
26 *parser_state);
27
28/*******************************************************************************
29 *
30 * FUNCTION: acpi_ps_get_next_package_length
31 *
32 * PARAMETERS: parser_state - Current parser state object
33 *
34 * RETURN: Decoded package length. On completion, the AML pointer points
35 * past the length byte or bytes.
36 *
37 * DESCRIPTION: Decode and return a package length field.
38 * Note: Largest package length is 28 bits, from ACPI specification
39 *
40 ******************************************************************************/
41
42static u32
43acpi_ps_get_next_package_length(struct acpi_parse_state *parser_state)
44{
45 u8 *aml = parser_state->aml;
46 u32 package_length = 0;
47 u32 byte_count;
48 u8 byte_zero_mask = 0x3F; /* Default [0:5] */
49
50 ACPI_FUNCTION_TRACE(ps_get_next_package_length);
51
52 /*
53 * Byte 0 bits [6:7] contain the number of additional bytes
54 * used to encode the package length, either 0,1,2, or 3
55 */
56 byte_count = (aml[0] >> 6);
57 parser_state->aml += ((acpi_size)byte_count + 1);
58
59 /* Get bytes 3, 2, 1 as needed */
60
61 while (byte_count) {
62 /*
63 * Final bit positions for the package length bytes:
64 * Byte3->[20:27]
65 * Byte2->[12:19]
66 * Byte1->[04:11]
67 * Byte0->[00:03]
68 */
69 package_length |= (aml[byte_count] << ((byte_count << 3) - 4));
70
71 byte_zero_mask = 0x0F; /* Use bits [0:3] of byte 0 */
72 byte_count--;
73 }
74
75 /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
76
77 package_length |= (aml[0] & byte_zero_mask);
78 return_UINT32(package_length);
79}
80
81/*******************************************************************************
82 *
83 * FUNCTION: acpi_ps_get_next_package_end
84 *
85 * PARAMETERS: parser_state - Current parser state object
86 *
87 * RETURN: Pointer to end-of-package +1
88 *
89 * DESCRIPTION: Get next package length and return a pointer past the end of
90 * the package. Consumes the package length field
91 *
92 ******************************************************************************/
93
94u8 *acpi_ps_get_next_package_end(struct acpi_parse_state *parser_state)
95{
96 u8 *start = parser_state->aml;
97 u32 package_length;
98
99 ACPI_FUNCTION_TRACE(ps_get_next_package_end);
100
101 /* Function below updates parser_state->Aml */
102
103 package_length = acpi_ps_get_next_package_length(parser_state);
104
105 return_PTR(start + package_length); /* end of package */
106}
107
108/*******************************************************************************
109 *
110 * FUNCTION: acpi_ps_get_next_namestring
111 *
112 * PARAMETERS: parser_state - Current parser state object
113 *
114 * RETURN: Pointer to the start of the name string (pointer points into
115 * the AML.
116 *
117 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
118 * prefix characters. Set parser state to point past the string.
119 * (Name is consumed from the AML.)
120 *
121 ******************************************************************************/
122
123char *acpi_ps_get_next_namestring(struct acpi_parse_state *parser_state)
124{
125 u8 *start = parser_state->aml;
126 u8 *end = parser_state->aml;
127
128 ACPI_FUNCTION_TRACE(ps_get_next_namestring);
129
130 /* Point past any namestring prefix characters (backslash or carat) */
131
132 while (ACPI_IS_ROOT_PREFIX(*end) || ACPI_IS_PARENT_PREFIX(*end)) {
133 end++;
134 }
135
136 /* Decode the path prefix character */
137
138 switch (*end) {
139 case 0:
140
141 /* null_name */
142
143 if (end == start) {
144 start = NULL;
145 }
146 end++;
147 break;
148
149 case AML_DUAL_NAME_PREFIX:
150
151 /* Two name segments */
152
153 end += 1 + (2 * ACPI_NAMESEG_SIZE);
154 break;
155
156 case AML_MULTI_NAME_PREFIX:
157
158 /* Multiple name segments, 4 chars each, count in next byte */
159
160 end += 2 + (*(end + 1) * ACPI_NAMESEG_SIZE);
161 break;
162
163 default:
164
165 /* Single name segment */
166
167 end += ACPI_NAMESEG_SIZE;
168 break;
169 }
170
171 parser_state->aml = end;
172 return_PTR((char *)start);
173}
174
175/*******************************************************************************
176 *
177 * FUNCTION: acpi_ps_get_next_namepath
178 *
179 * PARAMETERS: parser_state - Current parser state object
180 * arg - Where the namepath will be stored
181 * arg_count - If the namepath points to a control method
182 * the method's argument is returned here.
183 * possible_method_call - Whether the namepath can possibly be the
184 * start of a method call
185 *
186 * RETURN: Status
187 *
188 * DESCRIPTION: Get next name (if method call, return # of required args).
189 * Names are looked up in the internal namespace to determine
190 * if the name represents a control method. If a method
191 * is found, the number of arguments to the method is returned.
192 * This information is critical for parsing to continue correctly.
193 *
194 ******************************************************************************/
195
196acpi_status
197acpi_ps_get_next_namepath(struct acpi_walk_state *walk_state,
198 struct acpi_parse_state *parser_state,
199 union acpi_parse_object *arg, u8 possible_method_call)
200{
201 acpi_status status;
202 char *path;
203 union acpi_parse_object *name_op;
204 union acpi_operand_object *method_desc;
205 struct acpi_namespace_node *node;
206 u8 *start = parser_state->aml;
207
208 ACPI_FUNCTION_TRACE(ps_get_next_namepath);
209
210 path = acpi_ps_get_next_namestring(parser_state);
211 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
212
213 /* Null path case is allowed, just exit */
214
215 if (!path) {
216 arg->common.value.name = path;
217 return_ACPI_STATUS(AE_OK);
218 }
219
220 /*
221 * Lookup the name in the internal namespace, starting with the current
222 * scope. We don't want to add anything new to the namespace here,
223 * however, so we use MODE_EXECUTE.
224 * Allow searching of the parent tree, but don't open a new scope -
225 * we just want to lookup the object (must be mode EXECUTE to perform
226 * the upsearch)
227 */
228 status = acpi_ns_lookup(walk_state->scope_info, path,
229 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
230 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
231 NULL, &node);
232
233 /*
234 * If this name is a control method invocation, we must
235 * setup the method call
236 */
237 if (ACPI_SUCCESS(status) &&
238 possible_method_call && (node->type == ACPI_TYPE_METHOD)) {
239 if ((GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
240 ARGP_SUPERNAME)
241 || (GET_CURRENT_ARG_TYPE(walk_state->arg_types) ==
242 ARGP_TARGET)) {
243 /*
244 * acpi_ps_get_next_namestring has increased the AML pointer past
245 * the method invocation namestring, so we need to restore the
246 * saved AML pointer back to the original method invocation
247 * namestring.
248 */
249 walk_state->parser_state.aml = start;
250 walk_state->arg_count = 1;
251 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
252 }
253
254 /* This name is actually a control method invocation */
255
256 method_desc = acpi_ns_get_attached_object(node);
257 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
258 "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
259 node->name.ascii, node, method_desc, path));
260
261 name_op = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, start);
262 if (!name_op) {
263 return_ACPI_STATUS(AE_NO_MEMORY);
264 }
265
266 /* Change Arg into a METHOD CALL and attach name to it */
267
268 acpi_ps_init_op(arg, AML_INT_METHODCALL_OP);
269 name_op->common.value.name = path;
270
271 /* Point METHODCALL/NAME to the METHOD Node */
272
273 name_op->common.node = node;
274 acpi_ps_append_arg(arg, name_op);
275
276 if (!method_desc) {
277 ACPI_ERROR((AE_INFO,
278 "Control Method %p has no attached object",
279 node));
280 return_ACPI_STATUS(AE_AML_INTERNAL);
281 }
282
283 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
284 "Control Method - %p Args %X\n",
285 node, method_desc->method.param_count));
286
287 /* Get the number of arguments to expect */
288
289 walk_state->arg_count = method_desc->method.param_count;
290 return_ACPI_STATUS(AE_OK);
291 }
292
293 /*
294 * Special handling if the name was not found during the lookup -
295 * some not_found cases are allowed
296 */
297 if (status == AE_NOT_FOUND) {
298
299 /* 1) not_found is ok during load pass 1/2 (allow forward references) */
300
301 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) !=
302 ACPI_PARSE_EXECUTE) {
303 status = AE_OK;
304 }
305
306 /* 2) not_found during a cond_ref_of(x) is ok by definition */
307
308 else if (walk_state->op->common.aml_opcode ==
309 AML_CONDITIONAL_REF_OF_OP) {
310 status = AE_OK;
311 }
312
313 /*
314 * 3) not_found while building a Package is ok at this point, we
315 * may flag as an error later if slack mode is not enabled.
316 * (Some ASL code depends on allowing this behavior)
317 */
318 else if ((arg->common.parent) &&
319 ((arg->common.parent->common.aml_opcode ==
320 AML_PACKAGE_OP)
321 || (arg->common.parent->common.aml_opcode ==
322 AML_VARIABLE_PACKAGE_OP))) {
323 status = AE_OK;
324 }
325 }
326
327 /* Final exception check (may have been changed from code above) */
328
329 if (ACPI_FAILURE(status)) {
330 ACPI_ERROR_NAMESPACE(walk_state->scope_info, path, status);
331
332 if ((walk_state->parse_flags & ACPI_PARSE_MODE_MASK) ==
333 ACPI_PARSE_EXECUTE) {
334
335 /* Report a control method execution error */
336
337 status = acpi_ds_method_error(status, walk_state);
338 }
339 }
340
341 /* Save the namepath */
342
343 arg->common.value.name = path;
344 return_ACPI_STATUS(status);
345}
346
347/*******************************************************************************
348 *
349 * FUNCTION: acpi_ps_get_next_simple_arg
350 *
351 * PARAMETERS: parser_state - Current parser state object
352 * arg_type - The argument type (AML_*_ARG)
353 * arg - Where the argument is returned
354 *
355 * RETURN: None
356 *
357 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
358 *
359 ******************************************************************************/
360
361void
362acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
363 u32 arg_type, union acpi_parse_object *arg)
364{
365 u32 length;
366 u16 opcode;
367 u8 *aml = parser_state->aml;
368
369 ACPI_FUNCTION_TRACE_U32(ps_get_next_simple_arg, arg_type);
370
371 switch (arg_type) {
372 case ARGP_BYTEDATA:
373
374 /* Get 1 byte from the AML stream */
375
376 opcode = AML_BYTE_OP;
377 arg->common.value.integer = (u64) *aml;
378 length = 1;
379 break;
380
381 case ARGP_WORDDATA:
382
383 /* Get 2 bytes from the AML stream */
384
385 opcode = AML_WORD_OP;
386 ACPI_MOVE_16_TO_64(&arg->common.value.integer, aml);
387 length = 2;
388 break;
389
390 case ARGP_DWORDDATA:
391
392 /* Get 4 bytes from the AML stream */
393
394 opcode = AML_DWORD_OP;
395 ACPI_MOVE_32_TO_64(&arg->common.value.integer, aml);
396 length = 4;
397 break;
398
399 case ARGP_QWORDDATA:
400
401 /* Get 8 bytes from the AML stream */
402
403 opcode = AML_QWORD_OP;
404 ACPI_MOVE_64_TO_64(&arg->common.value.integer, aml);
405 length = 8;
406 break;
407
408 case ARGP_CHARLIST:
409
410 /* Get a pointer to the string, point past the string */
411
412 opcode = AML_STRING_OP;
413 arg->common.value.string = ACPI_CAST_PTR(char, aml);
414
415 /* Find the null terminator */
416
417 length = 0;
418 while (aml[length]) {
419 length++;
420 }
421 length++;
422 break;
423
424 case ARGP_NAME:
425 case ARGP_NAMESTRING:
426
427 acpi_ps_init_op(arg, AML_INT_NAMEPATH_OP);
428 arg->common.value.name =
429 acpi_ps_get_next_namestring(parser_state);
430 return_VOID;
431
432 default:
433
434 ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
435 return_VOID;
436 }
437
438 acpi_ps_init_op(arg, opcode);
439 parser_state->aml += length;
440 return_VOID;
441}
442
443/*******************************************************************************
444 *
445 * FUNCTION: acpi_ps_get_next_field
446 *
447 * PARAMETERS: parser_state - Current parser state object
448 *
449 * RETURN: A newly allocated FIELD op
450 *
451 * DESCRIPTION: Get next field (named_field, reserved_field, or access_field)
452 *
453 ******************************************************************************/
454
455static union acpi_parse_object *acpi_ps_get_next_field(struct acpi_parse_state
456 *parser_state)
457{
458 u8 *aml;
459 union acpi_parse_object *field;
460 union acpi_parse_object *arg = NULL;
461 u16 opcode;
462 u32 name;
463 u8 access_type;
464 u8 access_attribute;
465 u8 access_length;
466 u32 pkg_length;
467 u8 *pkg_end;
468 u32 buffer_length;
469
470 ACPI_FUNCTION_TRACE(ps_get_next_field);
471
472 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
473 aml = parser_state->aml;
474
475 /* Determine field type */
476
477 switch (ACPI_GET8(parser_state->aml)) {
478 case AML_FIELD_OFFSET_OP:
479
480 opcode = AML_INT_RESERVEDFIELD_OP;
481 parser_state->aml++;
482 break;
483
484 case AML_FIELD_ACCESS_OP:
485
486 opcode = AML_INT_ACCESSFIELD_OP;
487 parser_state->aml++;
488 break;
489
490 case AML_FIELD_CONNECTION_OP:
491
492 opcode = AML_INT_CONNECTION_OP;
493 parser_state->aml++;
494 break;
495
496 case AML_FIELD_EXT_ACCESS_OP:
497
498 opcode = AML_INT_EXTACCESSFIELD_OP;
499 parser_state->aml++;
500 break;
501
502 default:
503
504 opcode = AML_INT_NAMEDFIELD_OP;
505 break;
506 }
507
508 /* Allocate a new field op */
509
510 field = acpi_ps_alloc_op(opcode, aml);
511 if (!field) {
512 return_PTR(NULL);
513 }
514
515 /* Decode the field type */
516
517 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
518 switch (opcode) {
519 case AML_INT_NAMEDFIELD_OP:
520
521 /* Get the 4-character name */
522
523 ACPI_MOVE_32_TO_32(&name, parser_state->aml);
524 acpi_ps_set_name(field, name);
525 parser_state->aml += ACPI_NAMESEG_SIZE;
526
527 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
528
529#ifdef ACPI_ASL_COMPILER
530 /*
531 * Because the package length isn't represented as a parse tree object,
532 * take comments surrounding this and add to the previously created
533 * parse node.
534 */
535 if (field->common.inline_comment) {
536 field->common.name_comment =
537 field->common.inline_comment;
538 }
539 field->common.inline_comment = acpi_gbl_current_inline_comment;
540 acpi_gbl_current_inline_comment = NULL;
541#endif
542
543 /* Get the length which is encoded as a package length */
544
545 field->common.value.size =
546 acpi_ps_get_next_package_length(parser_state);
547 break;
548
549 case AML_INT_RESERVEDFIELD_OP:
550
551 /* Get the length which is encoded as a package length */
552
553 field->common.value.size =
554 acpi_ps_get_next_package_length(parser_state);
555 break;
556
557 case AML_INT_ACCESSFIELD_OP:
558 case AML_INT_EXTACCESSFIELD_OP:
559
560 /*
561 * Get access_type and access_attrib and merge into the field Op
562 * access_type is first operand, access_attribute is second. stuff
563 * these bytes into the node integer value for convenience.
564 */
565
566 /* Get the two bytes (Type/Attribute) */
567
568 access_type = ACPI_GET8(parser_state->aml);
569 parser_state->aml++;
570 access_attribute = ACPI_GET8(parser_state->aml);
571 parser_state->aml++;
572
573 field->common.value.integer = (u8)access_type;
574 field->common.value.integer |= (u16)(access_attribute << 8);
575
576 /* This opcode has a third byte, access_length */
577
578 if (opcode == AML_INT_EXTACCESSFIELD_OP) {
579 access_length = ACPI_GET8(parser_state->aml);
580 parser_state->aml++;
581
582 field->common.value.integer |=
583 (u32)(access_length << 16);
584 }
585 break;
586
587 case AML_INT_CONNECTION_OP:
588
589 /*
590 * Argument for Connection operator can be either a Buffer
591 * (resource descriptor), or a name_string.
592 */
593 aml = parser_state->aml;
594 if (ACPI_GET8(parser_state->aml) == AML_BUFFER_OP) {
595 parser_state->aml++;
596
597 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
598 pkg_end = parser_state->aml;
599 pkg_length =
600 acpi_ps_get_next_package_length(parser_state);
601 pkg_end += pkg_length;
602
603 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
604 if (parser_state->aml < pkg_end) {
605
606 /* Non-empty list */
607
608 arg =
609 acpi_ps_alloc_op(AML_INT_BYTELIST_OP, aml);
610 if (!arg) {
611 acpi_ps_free_op(field);
612 return_PTR(NULL);
613 }
614
615 /* Get the actual buffer length argument */
616
617 opcode = ACPI_GET8(parser_state->aml);
618 parser_state->aml++;
619
620 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
621 switch (opcode) {
622 case AML_BYTE_OP: /* AML_BYTEDATA_ARG */
623
624 buffer_length =
625 ACPI_GET8(parser_state->aml);
626 parser_state->aml += 1;
627 break;
628
629 case AML_WORD_OP: /* AML_WORDDATA_ARG */
630
631 buffer_length =
632 ACPI_GET16(parser_state->aml);
633 parser_state->aml += 2;
634 break;
635
636 case AML_DWORD_OP: /* AML_DWORDATA_ARG */
637
638 buffer_length =
639 ACPI_GET32(parser_state->aml);
640 parser_state->aml += 4;
641 break;
642
643 default:
644
645 buffer_length = 0;
646 break;
647 }
648
649 /* Fill in bytelist data */
650
651 ASL_CV_CAPTURE_COMMENTS_ONLY(parser_state);
652 arg->named.value.size = buffer_length;
653 arg->named.data = parser_state->aml;
654 }
655
656 /* Skip to End of byte data */
657
658 parser_state->aml = pkg_end;
659 } else {
660 arg = acpi_ps_alloc_op(AML_INT_NAMEPATH_OP, aml);
661 if (!arg) {
662 acpi_ps_free_op(field);
663 return_PTR(NULL);
664 }
665
666 /* Get the Namestring argument */
667
668 arg->common.value.name =
669 acpi_ps_get_next_namestring(parser_state);
670 }
671
672 /* Link the buffer/namestring to parent (CONNECTION_OP) */
673
674 acpi_ps_append_arg(field, arg);
675 break;
676
677 default:
678
679 /* Opcode was set in previous switch */
680 break;
681 }
682
683 return_PTR(field);
684}
685
686/*******************************************************************************
687 *
688 * FUNCTION: acpi_ps_get_next_arg
689 *
690 * PARAMETERS: walk_state - Current state
691 * parser_state - Current parser state object
692 * arg_type - The argument type (AML_*_ARG)
693 * return_arg - Where the next arg is returned
694 *
695 * RETURN: Status, and an op object containing the next argument.
696 *
697 * DESCRIPTION: Get next argument (including complex list arguments that require
698 * pushing the parser stack)
699 *
700 ******************************************************************************/
701
702acpi_status
703acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
704 struct acpi_parse_state *parser_state,
705 u32 arg_type, union acpi_parse_object **return_arg)
706{
707 union acpi_parse_object *arg = NULL;
708 union acpi_parse_object *prev = NULL;
709 union acpi_parse_object *field;
710 u32 subop;
711 acpi_status status = AE_OK;
712
713 ACPI_FUNCTION_TRACE_PTR(ps_get_next_arg, parser_state);
714
715 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
716 "Expected argument type ARGP: %s (%2.2X)\n",
717 acpi_ut_get_argument_type_name(arg_type), arg_type));
718
719 switch (arg_type) {
720 case ARGP_BYTEDATA:
721 case ARGP_WORDDATA:
722 case ARGP_DWORDDATA:
723 case ARGP_CHARLIST:
724 case ARGP_NAME:
725 case ARGP_NAMESTRING:
726
727 /* Constants, strings, and namestrings are all the same size */
728
729 arg = acpi_ps_alloc_op(AML_BYTE_OP, parser_state->aml);
730 if (!arg) {
731 return_ACPI_STATUS(AE_NO_MEMORY);
732 }
733
734 acpi_ps_get_next_simple_arg(parser_state, arg_type, arg);
735 break;
736
737 case ARGP_PKGLENGTH:
738
739 /* Package length, nothing returned */
740
741 parser_state->pkg_end =
742 acpi_ps_get_next_package_end(parser_state);
743 break;
744
745 case ARGP_FIELDLIST:
746
747 if (parser_state->aml < parser_state->pkg_end) {
748
749 /* Non-empty list */
750
751 while (parser_state->aml < parser_state->pkg_end) {
752 field = acpi_ps_get_next_field(parser_state);
753 if (!field) {
754 return_ACPI_STATUS(AE_NO_MEMORY);
755 }
756
757 if (prev) {
758 prev->common.next = field;
759 } else {
760 arg = field;
761 }
762 prev = field;
763 }
764
765 /* Skip to End of byte data */
766
767 parser_state->aml = parser_state->pkg_end;
768 }
769 break;
770
771 case ARGP_BYTELIST:
772
773 if (parser_state->aml < parser_state->pkg_end) {
774
775 /* Non-empty list */
776
777 arg = acpi_ps_alloc_op(AML_INT_BYTELIST_OP,
778 parser_state->aml);
779 if (!arg) {
780 return_ACPI_STATUS(AE_NO_MEMORY);
781 }
782
783 /* Fill in bytelist data */
784
785 arg->common.value.size = (u32)
786 ACPI_PTR_DIFF(parser_state->pkg_end,
787 parser_state->aml);
788 arg->named.data = parser_state->aml;
789
790 /* Skip to End of byte data */
791
792 parser_state->aml = parser_state->pkg_end;
793 }
794 break;
795
796 case ARGP_SIMPLENAME:
797 case ARGP_NAME_OR_REF:
798
799 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
800 "**** SimpleName/NameOrRef: %s (%2.2X)\n",
801 acpi_ut_get_argument_type_name(arg_type),
802 arg_type));
803
804 subop = acpi_ps_peek_opcode(parser_state);
805 if (subop == 0 ||
806 acpi_ps_is_leading_char(subop) ||
807 ACPI_IS_ROOT_PREFIX(subop) ||
808 ACPI_IS_PARENT_PREFIX(subop)) {
809
810 /* null_name or name_string */
811
812 arg =
813 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
814 parser_state->aml);
815 if (!arg) {
816 return_ACPI_STATUS(AE_NO_MEMORY);
817 }
818
819 status =
820 acpi_ps_get_next_namepath(walk_state, parser_state,
821 arg,
822 ACPI_NOT_METHOD_CALL);
823 } else {
824 /* Single complex argument, nothing returned */
825
826 walk_state->arg_count = 1;
827 }
828 break;
829
830 case ARGP_TARGET:
831 case ARGP_SUPERNAME:
832
833 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
834 "**** Target/Supername: %s (%2.2X)\n",
835 acpi_ut_get_argument_type_name(arg_type),
836 arg_type));
837
838 subop = acpi_ps_peek_opcode(parser_state);
839 if (subop == 0 ||
840 acpi_ps_is_leading_char(subop) ||
841 ACPI_IS_ROOT_PREFIX(subop) ||
842 ACPI_IS_PARENT_PREFIX(subop)) {
843
844 /* NULL target (zero). Convert to a NULL namepath */
845
846 arg =
847 acpi_ps_alloc_op(AML_INT_NAMEPATH_OP,
848 parser_state->aml);
849 if (!arg) {
850 return_ACPI_STATUS(AE_NO_MEMORY);
851 }
852
853 status =
854 acpi_ps_get_next_namepath(walk_state, parser_state,
855 arg,
856 ACPI_POSSIBLE_METHOD_CALL);
857
858 if (arg->common.aml_opcode == AML_INT_METHODCALL_OP) {
859
860 /* Free method call op and corresponding namestring sub-ob */
861
862 acpi_ps_free_op(arg->common.value.arg);
863 acpi_ps_free_op(arg);
864 arg = NULL;
865 walk_state->arg_count = 1;
866 }
867 } else {
868 /* Single complex argument, nothing returned */
869
870 walk_state->arg_count = 1;
871 }
872 break;
873
874 case ARGP_DATAOBJ:
875 case ARGP_TERMARG:
876
877 ACPI_DEBUG_PRINT((ACPI_DB_PARSE,
878 "**** TermArg/DataObj: %s (%2.2X)\n",
879 acpi_ut_get_argument_type_name(arg_type),
880 arg_type));
881
882 /* Single complex argument, nothing returned */
883
884 walk_state->arg_count = 1;
885 break;
886
887 case ARGP_DATAOBJLIST:
888 case ARGP_TERMLIST:
889 case ARGP_OBJLIST:
890
891 if (parser_state->aml < parser_state->pkg_end) {
892
893 /* Non-empty list of variable arguments, nothing returned */
894
895 walk_state->arg_count = ACPI_VAR_ARGS;
896 }
897 break;
898
899 default:
900
901 ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
902 status = AE_AML_OPERAND_TYPE;
903 break;
904 }
905
906 *return_arg = arg;
907 return_ACPI_STATUS(status);
908}