1 /******************************************************************************
3 * Module Name: psargs - Parse AML opcode arguments
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/psargs.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
121 #include "acparser.h"
123 #include "acnamesp.h"
125 #define _COMPONENT ACPI_PARSER
126 ACPI_MODULE_NAME ("psargs")
129 /*******************************************************************************
131 * FUNCTION: AcpiPsGetNextPackageLength
133 * PARAMETERS: ParserState - Current parser state object
135 * RETURN: Decoded package length. On completion, the AML pointer points
136 * past the length byte or bytes.
138 * DESCRIPTION: Decode and return a package length field
140 ******************************************************************************/
143 AcpiPsGetNextPackageLength (
144 ACPI_PARSE_STATE *ParserState)
146 UINT32 EncodedLength;
150 ACPI_FUNCTION_TRACE ("PsGetNextPackageLength");
153 EncodedLength = (UINT32) ACPI_GET8 (ParserState->Aml);
157 switch (EncodedLength >> 6) /* bits 6-7 contain encoding scheme */
159 case 0: /* 1-byte encoding (bits 0-5) */
161 Length = (EncodedLength & 0x3F);
165 case 1: /* 2-byte encoding (next byte + bits 0-3) */
167 Length = ((ACPI_GET8 (ParserState->Aml) << 04) |
168 (EncodedLength & 0x0F));
173 case 2: /* 3-byte encoding (next 2 bytes + bits 0-3) */
175 Length = ((ACPI_GET8 (ParserState->Aml + 1) << 12) |
176 (ACPI_GET8 (ParserState->Aml) << 04) |
177 (EncodedLength & 0x0F));
178 ParserState->Aml += 2;
182 case 3: /* 4-byte encoding (next 3 bytes + bits 0-3) */
184 Length = ((ACPI_GET8 (ParserState->Aml + 2) << 20) |
185 (ACPI_GET8 (ParserState->Aml + 1) << 12) |
186 (ACPI_GET8 (ParserState->Aml) << 04) |
187 (EncodedLength & 0x0F));
188 ParserState->Aml += 3;
193 /* Can't get here, only 2 bits / 4 cases */
197 return_VALUE (Length);
201 /*******************************************************************************
203 * FUNCTION: AcpiPsGetNextPackageEnd
205 * PARAMETERS: ParserState - Current parser state object
207 * RETURN: Pointer to end-of-package +1
209 * DESCRIPTION: Get next package length and return a pointer past the end of
210 * the package. Consumes the package length field
212 ******************************************************************************/
215 AcpiPsGetNextPackageEnd (
216 ACPI_PARSE_STATE *ParserState)
218 UINT8 *Start = ParserState->Aml;
219 ACPI_NATIVE_UINT Length;
222 ACPI_FUNCTION_TRACE ("PsGetNextPackageEnd");
225 /* Function below changes ParserState->Aml */
227 Length = (ACPI_NATIVE_UINT) AcpiPsGetNextPackageLength (ParserState);
229 return_PTR (Start + Length); /* end of package */
233 /*******************************************************************************
235 * FUNCTION: AcpiPsGetNextNamestring
237 * PARAMETERS: ParserState - Current parser state object
239 * RETURN: Pointer to the start of the name string (pointer points into
242 * DESCRIPTION: Get next raw namestring within the AML stream. Handles all name
243 * prefix characters. Set parser state to point past the string.
244 * (Name is consumed from the AML.)
246 ******************************************************************************/
249 AcpiPsGetNextNamestring (
250 ACPI_PARSE_STATE *ParserState)
252 UINT8 *Start = ParserState->Aml;
253 UINT8 *End = ParserState->Aml;
256 ACPI_FUNCTION_TRACE ("PsGetNextNamestring");
259 /* Handle multiple prefix characters */
261 while (AcpiPsIsPrefixChar (ACPI_GET8 (End)))
263 /* Include prefix '\\' or '^' */
268 /* Decode the path */
270 switch (ACPI_GET8 (End))
283 case AML_DUAL_NAME_PREFIX:
285 /* Two name segments */
287 End += 1 + (2 * ACPI_NAME_SIZE);
290 case AML_MULTI_NAME_PREFIX_OP:
292 /* Multiple name segments, 4 chars each */
294 End += 2 + ((ACPI_SIZE) ACPI_GET8 (End + 1) * ACPI_NAME_SIZE);
299 /* Single name segment */
301 End += ACPI_NAME_SIZE;
305 ParserState->Aml = (UINT8*) End;
306 return_PTR ((char *) Start);
310 /*******************************************************************************
312 * FUNCTION: AcpiPsGetNextNamepath
314 * PARAMETERS: ParserState - Current parser state object
315 * Arg - Where the namepath will be stored
316 * ArgCount - If the namepath points to a control method
317 * the method's argument is returned here.
318 * MethodCall - Whether the namepath can possibly be the
319 * start of a method call
323 * DESCRIPTION: Get next name (if method call, return # of required args).
324 * Names are looked up in the internal namespace to determine
325 * if the name represents a control method. If a method
326 * is found, the number of arguments to the method is returned.
327 * This information is critical for parsing to continue correctly.
329 ******************************************************************************/
332 AcpiPsGetNextNamepath (
333 ACPI_WALK_STATE *WalkState,
334 ACPI_PARSE_STATE *ParserState,
335 ACPI_PARSE_OBJECT *Arg,
339 ACPI_PARSE_OBJECT *NameOp;
340 ACPI_STATUS Status = AE_OK;
341 ACPI_OPERAND_OBJECT *MethodDesc;
342 ACPI_NAMESPACE_NODE *Node;
343 ACPI_GENERIC_STATE ScopeInfo;
346 ACPI_FUNCTION_TRACE ("PsGetNextNamepath");
349 Path = AcpiPsGetNextNamestring (ParserState);
351 /* Null path case is allowed */
356 * Lookup the name in the internal namespace
358 ScopeInfo.Scope.Node = NULL;
359 Node = ParserState->StartNode;
362 ScopeInfo.Scope.Node = Node;
366 * Lookup object. We don't want to add anything new to the namespace
367 * here, however. So we use MODE_EXECUTE. Allow searching of the
368 * parent tree, but don't open a new scope -- we just want to lookup the
369 * object (MUST BE mode EXECUTE to perform upsearch)
371 Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
372 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
373 if (ACPI_SUCCESS (Status) && MethodCall)
375 if (Node->Type == ACPI_TYPE_METHOD)
378 * This name is actually a control method invocation
380 MethodDesc = AcpiNsGetAttachedObject (Node);
381 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
382 "Control Method - %p Desc %p Path=%p\n",
383 Node, MethodDesc, Path));
385 NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
388 return_ACPI_STATUS (AE_NO_MEMORY);
391 /* Change arg into a METHOD CALL and attach name to it */
393 AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
394 NameOp->Common.Value.Name = Path;
396 /* Point METHODCALL/NAME to the METHOD Node */
398 NameOp->Common.Node = Node;
399 AcpiPsAppendArg (Arg, NameOp);
403 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
404 "Control Method - %p has no attached object\n",
406 return_ACPI_STATUS (AE_AML_INTERNAL);
409 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
410 "Control Method - %p Args %X\n",
411 Node, MethodDesc->Method.ParamCount));
413 /* Get the number of arguments to expect */
415 WalkState->ArgCount = MethodDesc->Method.ParamCount;
416 return_ACPI_STATUS (AE_OK);
420 * Else this is normal named object reference.
421 * Just init the NAMEPATH object with the pathname.
426 if (ACPI_FAILURE (Status))
429 * 1) Any error other than NOT_FOUND is always severe
430 * 2) NOT_FOUND is only important if we are executing a method.
431 * 3) If executing a CondRefOf opcode, NOT_FOUND is ok.
433 if ((((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) == ACPI_PARSE_EXECUTE) &&
434 (Status == AE_NOT_FOUND) &&
435 (WalkState->Op->Common.AmlOpcode != AML_COND_REF_OF_OP)) ||
437 (Status != AE_NOT_FOUND))
439 ACPI_REPORT_NSERROR (Path, Status);
444 * We got a NOT_FOUND during table load or we encountered
445 * a CondRefOf(x) where the target does not exist.
446 * -- either case is ok
454 * Regardless of success/failure above,
455 * Just initialize the Op with the pathname.
457 AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
458 Arg->Common.Value.Name = Path;
460 return_ACPI_STATUS (Status);
464 /*******************************************************************************
466 * FUNCTION: AcpiPsGetNextSimpleArg
468 * PARAMETERS: ParserState - Current parser state object
469 * ArgType - The argument type (AML_*_ARG)
470 * Arg - Where the argument is returned
474 * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
476 ******************************************************************************/
479 AcpiPsGetNextSimpleArg (
480 ACPI_PARSE_STATE *ParserState,
482 ACPI_PARSE_OBJECT *Arg)
485 ACPI_FUNCTION_TRACE_U32 ("PsGetNextSimpleArg", ArgType);
492 AcpiPsInitOp (Arg, AML_BYTE_OP);
493 Arg->Common.Value.Integer = (UINT32) ACPI_GET8 (ParserState->Aml);
500 AcpiPsInitOp (Arg, AML_WORD_OP);
502 /* Get 2 bytes from the AML stream */
504 ACPI_MOVE_UNALIGNED16_TO_32 (&Arg->Common.Value.Integer, ParserState->Aml);
505 ParserState->Aml += 2;
511 AcpiPsInitOp (Arg, AML_DWORD_OP);
513 /* Get 4 bytes from the AML stream */
515 ACPI_MOVE_UNALIGNED32_TO_32 (&Arg->Common.Value.Integer, ParserState->Aml);
516 ParserState->Aml += 4;
522 AcpiPsInitOp (Arg, AML_QWORD_OP);
524 /* Get 8 bytes from the AML stream */
526 ACPI_MOVE_UNALIGNED64_TO_64 (&Arg->Common.Value.Integer, ParserState->Aml);
527 ParserState->Aml += 8;
533 AcpiPsInitOp (Arg, AML_STRING_OP);
534 Arg->Common.Value.String = (char *) ParserState->Aml;
536 while (ACPI_GET8 (ParserState->Aml) != '\0')
545 case ARGP_NAMESTRING:
547 AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
548 Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
554 ACPI_REPORT_ERROR (("Invalid ArgType %X\n", ArgType));
562 /*******************************************************************************
564 * FUNCTION: AcpiPsGetNextField
566 * PARAMETERS: ParserState - Current parser state object
568 * RETURN: A newly allocated FIELD op
570 * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
572 ******************************************************************************/
576 ACPI_PARSE_STATE *ParserState)
578 UINT32 AmlOffset = ACPI_PTR_DIFF (ParserState->Aml,
579 ParserState->AmlStart);
580 ACPI_PARSE_OBJECT *Field;
585 ACPI_FUNCTION_TRACE ("PsGetNextField");
588 /* determine field type */
590 switch (ACPI_GET8 (ParserState->Aml))
594 Opcode = AML_INT_NAMEDFIELD_OP;
599 Opcode = AML_INT_RESERVEDFIELD_OP;
605 Opcode = AML_INT_ACCESSFIELD_OP;
611 /* Allocate a new field op */
613 Field = AcpiPsAllocOp (Opcode);
619 Field->Common.AmlOffset = AmlOffset;
621 /* Decode the field type */
625 case AML_INT_NAMEDFIELD_OP:
627 /* Get the 4-character name */
629 ACPI_MOVE_UNALIGNED32_TO_32 (&Name, ParserState->Aml);
630 AcpiPsSetName (Field, Name);
631 ParserState->Aml += ACPI_NAME_SIZE;
633 /* Get the length which is encoded as a package length */
635 Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
639 case AML_INT_RESERVEDFIELD_OP:
641 /* Get the length which is encoded as a package length */
643 Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
647 case AML_INT_ACCESSFIELD_OP:
650 * Get AccessType and AccessAttrib and merge into the field Op
651 * AccessType is first operand, AccessAttribute is second
653 Field->Common.Value.Integer32 = (ACPI_GET8 (ParserState->Aml) << 8);
655 Field->Common.Value.Integer32 |= ACPI_GET8 (ParserState->Aml);
661 /* Opcode was set in previous switch */
669 /*******************************************************************************
671 * FUNCTION: AcpiPsGetNextArg
673 * PARAMETERS: ParserState - Current parser state object
674 * ArgType - The argument type (AML_*_ARG)
675 * ArgCount - If the argument points to a control method
676 * the method's argument is returned here.
678 * RETURN: Status, and an op object containing the next argument.
680 * DESCRIPTION: Get next argument (including complex list arguments that require
681 * pushing the parser stack)
683 ******************************************************************************/
687 ACPI_WALK_STATE *WalkState,
688 ACPI_PARSE_STATE *ParserState,
690 ACPI_PARSE_OBJECT **ReturnArg)
692 ACPI_PARSE_OBJECT *Arg = NULL;
693 ACPI_PARSE_OBJECT *Prev = NULL;
694 ACPI_PARSE_OBJECT *Field;
696 ACPI_STATUS Status = AE_OK;
699 ACPI_FUNCTION_TRACE_PTR ("PsGetNextArg", ParserState);
709 case ARGP_NAMESTRING:
711 /* constants, strings, and namestrings are all the same size */
713 Arg = AcpiPsAllocOp (AML_BYTE_OP);
716 return_ACPI_STATUS (AE_NO_MEMORY);
718 AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
724 /* Package length, nothing returned */
726 ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
732 if (ParserState->Aml < ParserState->PkgEnd)
736 while (ParserState->Aml < ParserState->PkgEnd)
738 Field = AcpiPsGetNextField (ParserState);
741 return_ACPI_STATUS (AE_NO_MEMORY);
746 Prev->Common.Next = Field;
756 /* Skip to End of byte data */
758 ParserState->Aml = ParserState->PkgEnd;
765 if (ParserState->Aml < ParserState->PkgEnd)
769 Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
772 return_ACPI_STATUS (AE_NO_MEMORY);
775 /* Fill in bytelist data */
777 Arg->Common.Value.Size = ACPI_PTR_DIFF (ParserState->PkgEnd,
779 Arg->Named.Data = ParserState->Aml;
781 /* Skip to End of byte data */
783 ParserState->Aml = ParserState->PkgEnd;
790 case ARGP_SIMPLENAME:
792 Subop = AcpiPsPeekOpcode (ParserState);
794 AcpiPsIsLeadingChar (Subop) ||
795 AcpiPsIsPrefixChar (Subop))
797 /* NullName or NameString */
799 Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
802 return_ACPI_STATUS (AE_NO_MEMORY);
805 Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 0);
809 /* single complex argument, nothing returned */
811 WalkState->ArgCount = 1;
819 /* single complex argument, nothing returned */
821 WalkState->ArgCount = 1;
825 case ARGP_DATAOBJLIST:
829 if (ParserState->Aml < ParserState->PkgEnd)
831 /* non-empty list of variable arguments, nothing returned */
833 WalkState->ArgCount = ACPI_VAR_ARGS;
840 ACPI_REPORT_ERROR (("Invalid ArgType: %X\n", ArgType));
841 Status = AE_AML_OPERAND_TYPE;
846 return_ACPI_STATUS (Status);