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