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