Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/psargs.c need to be fixed.

0001 /******************************************************************************
0002  *
0003  * Module Name: psargs - Parse AML opcode arguments
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __PSARGS_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "acparser.h"
0121 #include "amlcode.h"
0122 #include "acnamesp.h"
0123 #include "acdispat.h"
0124 
0125 #define _COMPONENT          ACPI_PARSER
0126         ACPI_MODULE_NAME    ("psargs")
0127 
0128 /* Local prototypes */
0129 
0130 static UINT32
0131 AcpiPsGetNextPackageLength (
0132     ACPI_PARSE_STATE        *ParserState);
0133 
0134 static ACPI_PARSE_OBJECT *
0135 AcpiPsGetNextField (
0136     ACPI_PARSE_STATE        *ParserState);
0137 
0138 
0139 /*******************************************************************************
0140  *
0141  * FUNCTION:    AcpiPsGetNextPackageLength
0142  *
0143  * PARAMETERS:  ParserState         - Current parser state object
0144  *
0145  * RETURN:      Decoded package length. On completion, the AML pointer points
0146  *              past the length byte or bytes.
0147  *
0148  * DESCRIPTION: Decode and return a package length field.
0149  *              Note: Largest package length is 28 bits, from ACPI specification
0150  *
0151  ******************************************************************************/
0152 
0153 static UINT32
0154 AcpiPsGetNextPackageLength (
0155     ACPI_PARSE_STATE        *ParserState)
0156 {
0157     UINT8                   *Aml = ParserState->Aml;
0158     UINT32                  PackageLength = 0;
0159     UINT32                  ByteCount;
0160     UINT8                   ByteZeroMask = 0x3F; /* Default [0:5] */
0161 
0162 
0163     ACPI_FUNCTION_TRACE (PsGetNextPackageLength);
0164 
0165 
0166     /*
0167      * Byte 0 bits [6:7] contain the number of additional bytes
0168      * used to encode the package length, either 0,1,2, or 3
0169      */
0170     ByteCount = (Aml[0] >> 6);
0171     ParserState->Aml += ((ACPI_SIZE) ByteCount + 1);
0172 
0173     /* Get bytes 3, 2, 1 as needed */
0174 
0175     while (ByteCount)
0176     {
0177         /*
0178          * Final bit positions for the package length bytes:
0179          *      Byte3->[20:27]
0180          *      Byte2->[12:19]
0181          *      Byte1->[04:11]
0182          *      Byte0->[00:03]
0183          */
0184         PackageLength |= (Aml[ByteCount] << ((ByteCount << 3) - 4));
0185 
0186         ByteZeroMask = 0x0F; /* Use bits [0:3] of byte 0 */
0187         ByteCount--;
0188     }
0189 
0190     /* Byte 0 is a special case, either bits [0:3] or [0:5] are used */
0191 
0192     PackageLength |= (Aml[0] & ByteZeroMask);
0193     return_UINT32 (PackageLength);
0194 }
0195 
0196 
0197 /*******************************************************************************
0198  *
0199  * FUNCTION:    AcpiPsGetNextPackageEnd
0200  *
0201  * PARAMETERS:  ParserState         - Current parser state object
0202  *
0203  * RETURN:      Pointer to end-of-package +1
0204  *
0205  * DESCRIPTION: Get next package length and return a pointer past the end of
0206  *              the package.  Consumes the package length field
0207  *
0208  ******************************************************************************/
0209 
0210 UINT8 *
0211 AcpiPsGetNextPackageEnd (
0212     ACPI_PARSE_STATE        *ParserState)
0213 {
0214     UINT8                   *Start = ParserState->Aml;
0215     UINT32                  PackageLength;
0216 
0217 
0218     ACPI_FUNCTION_TRACE (PsGetNextPackageEnd);
0219 
0220 
0221     /* Function below updates ParserState->Aml */
0222 
0223     PackageLength = AcpiPsGetNextPackageLength (ParserState);
0224 
0225     return_PTR (Start + PackageLength); /* end of package */
0226 }
0227 
0228 
0229 /*******************************************************************************
0230  *
0231  * FUNCTION:    AcpiPsGetNextNamestring
0232  *
0233  * PARAMETERS:  ParserState         - Current parser state object
0234  *
0235  * RETURN:      Pointer to the start of the name string (pointer points into
0236  *              the AML.
0237  *
0238  * DESCRIPTION: Get next raw namestring within the AML stream.  Handles all name
0239  *              prefix characters.  Set parser state to point past the string.
0240  *              (Name is consumed from the AML.)
0241  *
0242  ******************************************************************************/
0243 
0244 char *
0245 AcpiPsGetNextNamestring (
0246     ACPI_PARSE_STATE        *ParserState)
0247 {
0248     UINT8                   *Start = ParserState->Aml;
0249     UINT8                   *End = ParserState->Aml;
0250 
0251 
0252     ACPI_FUNCTION_TRACE (PsGetNextNamestring);
0253 
0254 
0255     /* Point past any namestring prefix characters (backslash or carat) */
0256 
0257     while (AcpiPsIsPrefixChar (*End))
0258     {
0259         End++;
0260     }
0261 
0262     /* Decode the path prefix character */
0263 
0264     switch (*End)
0265     {
0266     case 0:
0267 
0268         /* NullName */
0269 
0270         if (End == Start)
0271         {
0272             Start = NULL;
0273         }
0274         End++;
0275         break;
0276 
0277     case AML_DUAL_NAME_PREFIX:
0278 
0279         /* Two name segments */
0280 
0281         End += 1 + (2 * ACPI_NAME_SIZE);
0282         break;
0283 
0284     case AML_MULTI_NAME_PREFIX_OP:
0285 
0286         /* Multiple name segments, 4 chars each, count in next byte */
0287 
0288         End += 2 + (*(End + 1) * ACPI_NAME_SIZE);
0289         break;
0290 
0291     default:
0292 
0293         /* Single name segment */
0294 
0295         End += ACPI_NAME_SIZE;
0296         break;
0297     }
0298 
0299     ParserState->Aml = End;
0300     return_PTR ((char *) Start);
0301 }
0302 
0303 
0304 /*******************************************************************************
0305  *
0306  * FUNCTION:    AcpiPsGetNextNamepath
0307  *
0308  * PARAMETERS:  ParserState         - Current parser state object
0309  *              Arg                 - Where the namepath will be stored
0310  *              ArgCount            - If the namepath points to a control method
0311  *                                    the method's argument is returned here.
0312  *              PossibleMethodCall  - Whether the namepath can possibly be the
0313  *                                    start of a method call
0314  *
0315  * RETURN:      Status
0316  *
0317  * DESCRIPTION: Get next name (if method call, return # of required args).
0318  *              Names are looked up in the internal namespace to determine
0319  *              if the name represents a control method.  If a method
0320  *              is found, the number of arguments to the method is returned.
0321  *              This information is critical for parsing to continue correctly.
0322  *
0323  ******************************************************************************/
0324 
0325 ACPI_STATUS
0326 AcpiPsGetNextNamepath (
0327     ACPI_WALK_STATE         *WalkState,
0328     ACPI_PARSE_STATE        *ParserState,
0329     ACPI_PARSE_OBJECT       *Arg,
0330     BOOLEAN                 PossibleMethodCall)
0331 {
0332     ACPI_STATUS             Status;
0333     char                    *Path;
0334     ACPI_PARSE_OBJECT       *NameOp;
0335     ACPI_OPERAND_OBJECT     *MethodDesc;
0336     ACPI_NAMESPACE_NODE     *Node;
0337     UINT8                   *Start = ParserState->Aml;
0338 
0339 
0340     ACPI_FUNCTION_TRACE (PsGetNextNamepath);
0341 
0342 
0343     Path = AcpiPsGetNextNamestring (ParserState);
0344     AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
0345 
0346     /* Null path case is allowed, just exit */
0347 
0348     if (!Path)
0349     {
0350         Arg->Common.Value.Name = Path;
0351         return_ACPI_STATUS (AE_OK);
0352     }
0353 
0354     /*
0355      * Lookup the name in the internal namespace, starting with the current
0356      * scope. We don't want to add anything new to the namespace here,
0357      * however, so we use MODE_EXECUTE.
0358      * Allow searching of the parent tree, but don't open a new scope -
0359      * we just want to lookup the object (must be mode EXECUTE to perform
0360      * the upsearch)
0361      */
0362     Status = AcpiNsLookup (WalkState->ScopeInfo, Path,
0363                 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0364                 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);
0365 
0366     /*
0367      * If this name is a control method invocation, we must
0368      * setup the method call
0369      */
0370     if (ACPI_SUCCESS (Status) &&
0371         PossibleMethodCall &&
0372         (Node->Type == ACPI_TYPE_METHOD))
0373     {
0374         if (WalkState->Opcode == AML_UNLOAD_OP)
0375         {
0376             /*
0377              * AcpiPsGetNextNamestring has increased the AML pointer,
0378              * so we need to restore the saved AML pointer for method call.
0379              */
0380             WalkState->ParserState.Aml = Start;
0381             WalkState->ArgCount = 1;
0382             AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
0383             return_ACPI_STATUS (AE_OK);
0384         }
0385 
0386         /* This name is actually a control method invocation */
0387 
0388         MethodDesc = AcpiNsGetAttachedObject (Node);
0389         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0390             "Control Method - %p Desc %p Path=%p\n", Node, MethodDesc, Path));
0391 
0392         NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
0393         if (!NameOp)
0394         {
0395             return_ACPI_STATUS (AE_NO_MEMORY);
0396         }
0397 
0398         /* Change Arg into a METHOD CALL and attach name to it */
0399 
0400         AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
0401         NameOp->Common.Value.Name = Path;
0402 
0403         /* Point METHODCALL/NAME to the METHOD Node */
0404 
0405         NameOp->Common.Node = Node;
0406         AcpiPsAppendArg (Arg, NameOp);
0407 
0408         if (!MethodDesc)
0409         {
0410             ACPI_ERROR ((AE_INFO,
0411                 "Control Method %p has no attached object",
0412                 Node));
0413             return_ACPI_STATUS (AE_AML_INTERNAL);
0414         }
0415 
0416         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
0417             "Control Method - %p Args %X\n",
0418             Node, MethodDesc->Method.ParamCount));
0419 
0420         /* Get the number of arguments to expect */
0421 
0422         WalkState->ArgCount = MethodDesc->Method.ParamCount;
0423         return_ACPI_STATUS (AE_OK);
0424     }
0425 
0426     /*
0427      * Special handling if the name was not found during the lookup -
0428      * some NotFound cases are allowed
0429      */
0430     if (Status == AE_NOT_FOUND)
0431     {
0432         /* 1) NotFound is ok during load pass 1/2 (allow forward references) */
0433 
0434         if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=
0435                 ACPI_PARSE_EXECUTE)
0436         {
0437             Status = AE_OK;
0438         }
0439 
0440         /* 2) NotFound during a CondRefOf(x) is ok by definition */
0441 
0442         else if (WalkState->Op->Common.AmlOpcode == AML_COND_REF_OF_OP)
0443         {
0444             Status = AE_OK;
0445         }
0446 
0447         /*
0448          * 3) NotFound while building a Package is ok at this point, we
0449          * may flag as an error later if slack mode is not enabled.
0450          * (Some ASL code depends on allowing this behavior)
0451          */
0452         else if ((Arg->Common.Parent) &&
0453             ((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
0454              (Arg->Common.Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP)))
0455         {
0456             Status = AE_OK;
0457         }
0458     }
0459 
0460     /* Final exception check (may have been changed from code above) */
0461 
0462     if (ACPI_FAILURE (Status))
0463     {
0464         ACPI_ERROR_NAMESPACE (Path, Status);
0465 
0466         if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==
0467                 ACPI_PARSE_EXECUTE)
0468         {
0469             /* Report a control method execution error */
0470 
0471             Status = AcpiDsMethodError (Status, WalkState);
0472         }
0473     }
0474 
0475     /* Save the namepath */
0476 
0477     Arg->Common.Value.Name = Path;
0478     return_ACPI_STATUS (Status);
0479 }
0480 
0481 
0482 /*******************************************************************************
0483  *
0484  * FUNCTION:    AcpiPsGetNextSimpleArg
0485  *
0486  * PARAMETERS:  ParserState         - Current parser state object
0487  *              ArgType             - The argument type (AML_*_ARG)
0488  *              Arg                 - Where the argument is returned
0489  *
0490  * RETURN:      None
0491  *
0492  * DESCRIPTION: Get the next simple argument (constant, string, or namestring)
0493  *
0494  ******************************************************************************/
0495 
0496 void
0497 AcpiPsGetNextSimpleArg (
0498     ACPI_PARSE_STATE        *ParserState,
0499     UINT32                  ArgType,
0500     ACPI_PARSE_OBJECT       *Arg)
0501 {
0502     UINT32                  Length;
0503     UINT16                  Opcode;
0504     UINT8                   *Aml = ParserState->Aml;
0505 
0506 
0507     ACPI_FUNCTION_TRACE_U32 (PsGetNextSimpleArg, ArgType);
0508 
0509 
0510     switch (ArgType)
0511     {
0512     case ARGP_BYTEDATA:
0513 
0514         /* Get 1 byte from the AML stream */
0515 
0516         Opcode = AML_BYTE_OP;
0517         Arg->Common.Value.Integer = (ACPI_INTEGER) *Aml;
0518         Length = 1;
0519         break;
0520 
0521 
0522     case ARGP_WORDDATA:
0523 
0524         /* Get 2 bytes from the AML stream */
0525 
0526         Opcode = AML_WORD_OP;
0527         ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);
0528         Length = 2;
0529         break;
0530 
0531 
0532     case ARGP_DWORDDATA:
0533 
0534         /* Get 4 bytes from the AML stream */
0535 
0536         Opcode = AML_DWORD_OP;
0537         ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);
0538         Length = 4;
0539         break;
0540 
0541 
0542     case ARGP_QWORDDATA:
0543 
0544         /* Get 8 bytes from the AML stream */
0545 
0546         Opcode = AML_QWORD_OP;
0547         ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);
0548         Length = 8;
0549         break;
0550 
0551 
0552     case ARGP_CHARLIST:
0553 
0554         /* Get a pointer to the string, point past the string */
0555 
0556         Opcode = AML_STRING_OP;
0557         Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);
0558 
0559         /* Find the null terminator */
0560 
0561         Length = 0;
0562         while (Aml[Length])
0563         {
0564             Length++;
0565         }
0566         Length++;
0567         break;
0568 
0569 
0570     case ARGP_NAME:
0571     case ARGP_NAMESTRING:
0572 
0573         AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);
0574         Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);
0575         return_VOID;
0576 
0577 
0578     default:
0579 
0580         ACPI_ERROR ((AE_INFO, "Invalid ArgType %X", ArgType));
0581         return_VOID;
0582     }
0583 
0584     AcpiPsInitOp (Arg, Opcode);
0585     ParserState->Aml += Length;
0586     return_VOID;
0587 }
0588 
0589 
0590 /*******************************************************************************
0591  *
0592  * FUNCTION:    AcpiPsGetNextField
0593  *
0594  * PARAMETERS:  ParserState         - Current parser state object
0595  *
0596  * RETURN:      A newly allocated FIELD op
0597  *
0598  * DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)
0599  *
0600  ******************************************************************************/
0601 
0602 static ACPI_PARSE_OBJECT *
0603 AcpiPsGetNextField (
0604     ACPI_PARSE_STATE        *ParserState)
0605 {
0606     UINT32                  AmlOffset = (UINT32)
0607                                 ACPI_PTR_DIFF (ParserState->Aml,
0608                                                ParserState->AmlStart);
0609     ACPI_PARSE_OBJECT       *Field;
0610     UINT16                  Opcode;
0611     UINT32                  Name;
0612 
0613 
0614     ACPI_FUNCTION_TRACE (PsGetNextField);
0615 
0616 
0617     /* Determine field type */
0618 
0619     switch (ACPI_GET8 (ParserState->Aml))
0620     {
0621     default:
0622 
0623         Opcode = AML_INT_NAMEDFIELD_OP;
0624         break;
0625 
0626     case 0x00:
0627 
0628         Opcode = AML_INT_RESERVEDFIELD_OP;
0629         ParserState->Aml++;
0630         break;
0631 
0632     case 0x01:
0633 
0634         Opcode = AML_INT_ACCESSFIELD_OP;
0635         ParserState->Aml++;
0636         break;
0637     }
0638 
0639     /* Allocate a new field op */
0640 
0641     Field = AcpiPsAllocOp (Opcode);
0642     if (!Field)
0643     {
0644         return_PTR (NULL);
0645     }
0646 
0647     Field->Common.AmlOffset = AmlOffset;
0648 
0649     /* Decode the field type */
0650 
0651     switch (Opcode)
0652     {
0653     case AML_INT_NAMEDFIELD_OP:
0654 
0655         /* Get the 4-character name */
0656 
0657         ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);
0658         AcpiPsSetName (Field, Name);
0659         ParserState->Aml += ACPI_NAME_SIZE;
0660 
0661         /* Get the length which is encoded as a package length */
0662 
0663         Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
0664         break;
0665 
0666 
0667     case AML_INT_RESERVEDFIELD_OP:
0668 
0669         /* Get the length which is encoded as a package length */
0670 
0671         Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);
0672         break;
0673 
0674 
0675     case AML_INT_ACCESSFIELD_OP:
0676 
0677         /*
0678          * Get AccessType and AccessAttrib and merge into the field Op
0679          * AccessType is first operand, AccessAttribute is second
0680          */
0681         Field->Common.Value.Integer = (((UINT32) ACPI_GET8 (ParserState->Aml) << 8));
0682         ParserState->Aml++;
0683         Field->Common.Value.Integer |= ACPI_GET8 (ParserState->Aml);
0684         ParserState->Aml++;
0685         break;
0686 
0687     default:
0688 
0689         /* Opcode was set in previous switch */
0690         break;
0691     }
0692 
0693     return_PTR (Field);
0694 }
0695 
0696 
0697 /*******************************************************************************
0698  *
0699  * FUNCTION:    AcpiPsGetNextArg
0700  *
0701  * PARAMETERS:  WalkState           - Current state
0702  *              ParserState         - Current parser state object
0703  *              ArgType             - The argument type (AML_*_ARG)
0704  *              ReturnArg           - Where the next arg is returned
0705  *
0706  * RETURN:      Status, and an op object containing the next argument.
0707  *
0708  * DESCRIPTION: Get next argument (including complex list arguments that require
0709  *              pushing the parser stack)
0710  *
0711  ******************************************************************************/
0712 
0713 ACPI_STATUS
0714 AcpiPsGetNextArg (
0715     ACPI_WALK_STATE         *WalkState,
0716     ACPI_PARSE_STATE        *ParserState,
0717     UINT32                  ArgType,
0718     ACPI_PARSE_OBJECT       **ReturnArg)
0719 {
0720     ACPI_PARSE_OBJECT       *Arg = NULL;
0721     ACPI_PARSE_OBJECT       *Prev = NULL;
0722     ACPI_PARSE_OBJECT       *Field;
0723     UINT32                  Subop;
0724     ACPI_STATUS             Status = AE_OK;
0725 
0726 
0727     ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
0728 
0729 
0730     switch (ArgType)
0731     {
0732     case ARGP_BYTEDATA:
0733     case ARGP_WORDDATA:
0734     case ARGP_DWORDDATA:
0735     case ARGP_CHARLIST:
0736     case ARGP_NAME:
0737     case ARGP_NAMESTRING:
0738 
0739         /* Constants, strings, and namestrings are all the same size */
0740 
0741         Arg = AcpiPsAllocOp (AML_BYTE_OP);
0742         if (!Arg)
0743         {
0744             return_ACPI_STATUS (AE_NO_MEMORY);
0745         }
0746         AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);
0747         break;
0748 
0749 
0750     case ARGP_PKGLENGTH:
0751 
0752         /* Package length, nothing returned */
0753 
0754         ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);
0755         break;
0756 
0757 
0758     case ARGP_FIELDLIST:
0759 
0760         if (ParserState->Aml < ParserState->PkgEnd)
0761         {
0762             /* Non-empty list */
0763 
0764             while (ParserState->Aml < ParserState->PkgEnd)
0765             {
0766                 Field = AcpiPsGetNextField (ParserState);
0767                 if (!Field)
0768                 {
0769                     return_ACPI_STATUS (AE_NO_MEMORY);
0770                 }
0771 
0772                 if (Prev)
0773                 {
0774                     Prev->Common.Next = Field;
0775                 }
0776                 else
0777                 {
0778                     Arg = Field;
0779                 }
0780                 Prev = Field;
0781             }
0782 
0783             /* Skip to End of byte data */
0784 
0785             ParserState->Aml = ParserState->PkgEnd;
0786         }
0787         break;
0788 
0789 
0790     case ARGP_BYTELIST:
0791 
0792         if (ParserState->Aml < ParserState->PkgEnd)
0793         {
0794             /* Non-empty list */
0795 
0796             Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP);
0797             if (!Arg)
0798             {
0799                 return_ACPI_STATUS (AE_NO_MEMORY);
0800             }
0801 
0802             /* Fill in bytelist data */
0803 
0804             Arg->Common.Value.Size = (UINT32)
0805                 ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);
0806             Arg->Named.Data = ParserState->Aml;
0807 
0808             /* Skip to End of byte data */
0809 
0810             ParserState->Aml = ParserState->PkgEnd;
0811         }
0812         break;
0813 
0814 
0815     case ARGP_TARGET:
0816     case ARGP_SUPERNAME:
0817     case ARGP_SIMPLENAME:
0818 
0819         Subop = AcpiPsPeekOpcode (ParserState);
0820         if (Subop == 0                  ||
0821             AcpiPsIsLeadingChar (Subop) ||
0822             AcpiPsIsPrefixChar (Subop))
0823         {
0824             /* NullName or NameString */
0825 
0826             Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP);
0827             if (!Arg)
0828             {
0829                 return_ACPI_STATUS (AE_NO_MEMORY);
0830             }
0831 
0832             /* To support SuperName arg of Unload */
0833 
0834             if (WalkState->Opcode == AML_UNLOAD_OP)
0835             {
0836                 Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 1);
0837 
0838                 /*
0839                  * If the SuperName arg of Unload is a method call,
0840                  * we have restored the AML pointer, just free this Arg
0841                  */
0842                 if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
0843                 {
0844                     AcpiPsFreeOp (Arg);
0845                     Arg = NULL;
0846                 }
0847             }
0848             else
0849             {
0850                 Status = AcpiPsGetNextNamepath (WalkState, ParserState, Arg, 0);
0851             }
0852         }
0853         else
0854         {
0855             /* Single complex argument, nothing returned */
0856 
0857             WalkState->ArgCount = 1;
0858         }
0859         break;
0860 
0861 
0862     case ARGP_DATAOBJ:
0863     case ARGP_TERMARG:
0864 
0865         /* Single complex argument, nothing returned */
0866 
0867         WalkState->ArgCount = 1;
0868         break;
0869 
0870 
0871     case ARGP_DATAOBJLIST:
0872     case ARGP_TERMLIST:
0873     case ARGP_OBJLIST:
0874 
0875         if (ParserState->Aml < ParserState->PkgEnd)
0876         {
0877             /* Non-empty list of variable arguments, nothing returned */
0878 
0879             WalkState->ArgCount = ACPI_VAR_ARGS;
0880         }
0881         break;
0882 
0883 
0884     default:
0885 
0886         ACPI_ERROR ((AE_INFO, "Invalid ArgType: %X", ArgType));
0887         Status = AE_AML_OPERAND_TYPE;
0888         break;
0889     }
0890 
0891     *ReturnArg = Arg;
0892     return_ACPI_STATUS (Status);
0893 }