Path: blob/main/sys/contrib/dev/acpica/components/parser/psargs.c
48524 views
/******************************************************************************1*2* Module Name: psargs - Parse AML opcode arguments3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acparser.h>154#include <contrib/dev/acpica/include/amlcode.h>155#include <contrib/dev/acpica/include/acnamesp.h>156#include <contrib/dev/acpica/include/acdispat.h>157#include <contrib/dev/acpica/include/acconvert.h>158159#define _COMPONENT ACPI_PARSER160ACPI_MODULE_NAME ("psargs")161162/* Local prototypes */163164static UINT32165AcpiPsGetNextPackageLength (166ACPI_PARSE_STATE *ParserState);167168static ACPI_PARSE_OBJECT *169AcpiPsGetNextField (170ACPI_PARSE_STATE *ParserState);171172static void173AcpiPsFreeFieldList (174ACPI_PARSE_OBJECT *Start);175176177/*******************************************************************************178*179* FUNCTION: AcpiPsGetNextPackageLength180*181* PARAMETERS: ParserState - Current parser state object182*183* RETURN: Decoded package length. On completion, the AML pointer points184* past the length byte or bytes.185*186* DESCRIPTION: Decode and return a package length field.187* Note: Largest package length is 28 bits, from ACPI specification188*189******************************************************************************/190191static UINT32192AcpiPsGetNextPackageLength (193ACPI_PARSE_STATE *ParserState)194{195UINT8 *Aml = ParserState->Aml;196UINT32 PackageLength = 0;197UINT32 ByteCount;198UINT8 ByteZeroMask = 0x3F; /* Default [0:5] */199200201ACPI_FUNCTION_TRACE (PsGetNextPackageLength);202203204/*205* Byte 0 bits [6:7] contain the number of additional bytes206* used to encode the package length, either 0,1,2, or 3207*/208ByteCount = (Aml[0] >> 6);209ParserState->Aml += ((ACPI_SIZE) ByteCount + 1);210211/* Get bytes 3, 2, 1 as needed */212213while (ByteCount)214{215/*216* Final bit positions for the package length bytes:217* Byte3->[20:27]218* Byte2->[12:19]219* Byte1->[04:11]220* Byte0->[00:03]221*/222PackageLength |= (Aml[ByteCount] << ((ByteCount << 3) - 4));223224ByteZeroMask = 0x0F; /* Use bits [0:3] of byte 0 */225ByteCount--;226}227228/* Byte 0 is a special case, either bits [0:3] or [0:5] are used */229230PackageLength |= (Aml[0] & ByteZeroMask);231return_UINT32 (PackageLength);232}233234235/*******************************************************************************236*237* FUNCTION: AcpiPsGetNextPackageEnd238*239* PARAMETERS: ParserState - Current parser state object240*241* RETURN: Pointer to end-of-package +1242*243* DESCRIPTION: Get next package length and return a pointer past the end of244* the package. Consumes the package length field245*246******************************************************************************/247248UINT8 *249AcpiPsGetNextPackageEnd (250ACPI_PARSE_STATE *ParserState)251{252UINT8 *Start = ParserState->Aml;253UINT32 PackageLength;254255256ACPI_FUNCTION_TRACE (PsGetNextPackageEnd);257258259/* Function below updates ParserState->Aml */260261PackageLength = AcpiPsGetNextPackageLength (ParserState);262263return_PTR (Start + PackageLength); /* end of package */264}265266267/*******************************************************************************268*269* FUNCTION: AcpiPsGetNextNamestring270*271* PARAMETERS: ParserState - Current parser state object272*273* RETURN: Pointer to the start of the name string (pointer points into274* the AML.275*276* DESCRIPTION: Get next raw namestring within the AML stream. Handles all name277* prefix characters. Set parser state to point past the string.278* (Name is consumed from the AML.)279*280******************************************************************************/281282char *283AcpiPsGetNextNamestring (284ACPI_PARSE_STATE *ParserState)285{286UINT8 *Start = ParserState->Aml;287UINT8 *End = ParserState->Aml;288289290ACPI_FUNCTION_TRACE (PsGetNextNamestring);291292293/* Point past any namestring prefix characters (backslash or carat) */294295while (ACPI_IS_ROOT_PREFIX (*End) ||296ACPI_IS_PARENT_PREFIX (*End))297{298End++;299}300301/* Decode the path prefix character */302303switch (*End)304{305case 0:306307/* NullName */308309if (End == Start)310{311Start = NULL;312}313End++;314break;315316case AML_DUAL_NAME_PREFIX:317318/* Two name segments */319320End += 1 + (2 * ACPI_NAMESEG_SIZE);321break;322323case AML_MULTI_NAME_PREFIX:324325/* Multiple name segments, 4 chars each, count in next byte */326327End += 2 + (*(End + 1) * ACPI_NAMESEG_SIZE);328break;329330default:331332/* Single name segment */333334End += ACPI_NAMESEG_SIZE;335break;336}337338ParserState->Aml = End;339return_PTR ((char *) Start);340}341342343/*******************************************************************************344*345* FUNCTION: AcpiPsGetNextNamepath346*347* PARAMETERS: ParserState - Current parser state object348* Arg - Where the namepath will be stored349* ArgCount - If the namepath points to a control method350* the method's argument is returned here.351* PossibleMethodCall - Whether the namepath can possibly be the352* start of a method call353*354* RETURN: Status355*356* DESCRIPTION: Get next name (if method call, return # of required args).357* Names are looked up in the internal namespace to determine358* if the name represents a control method. If a method359* is found, the number of arguments to the method is returned.360* This information is critical for parsing to continue correctly.361*362******************************************************************************/363364ACPI_STATUS365AcpiPsGetNextNamepath (366ACPI_WALK_STATE *WalkState,367ACPI_PARSE_STATE *ParserState,368ACPI_PARSE_OBJECT *Arg,369BOOLEAN PossibleMethodCall)370{371ACPI_STATUS Status;372char *Path;373ACPI_PARSE_OBJECT *NameOp;374ACPI_OPERAND_OBJECT *MethodDesc;375ACPI_NAMESPACE_NODE *Node;376UINT8 *Start = ParserState->Aml;377378379ACPI_FUNCTION_TRACE (PsGetNextNamepath);380381382Path = AcpiPsGetNextNamestring (ParserState);383AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);384385/* Null path case is allowed, just exit */386387if (!Path)388{389Arg->Common.Value.Name = Path;390return_ACPI_STATUS (AE_OK);391}392393/*394* Lookup the name in the internal namespace, starting with the current395* scope. We don't want to add anything new to the namespace here,396* however, so we use MODE_EXECUTE.397* Allow searching of the parent tree, but don't open a new scope -398* we just want to lookup the object (must be mode EXECUTE to perform399* the upsearch)400*/401Status = AcpiNsLookup (WalkState->ScopeInfo, Path,402ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,403ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE, NULL, &Node);404405/*406* If this name is a control method invocation, we must407* setup the method call408*/409if (ACPI_SUCCESS (Status) &&410PossibleMethodCall &&411(Node->Type == ACPI_TYPE_METHOD))412{413if ((GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_SUPERNAME) ||414(GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) == ARGP_TARGET))415{416/*417* AcpiPsGetNextNamestring has increased the AML pointer past418* the method invocation namestring, so we need to restore the419* saved AML pointer back to the original method invocation420* namestring.421*/422WalkState->ParserState.Aml = Start;423WalkState->ArgCount = 1;424AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);425}426427/* This name is actually a control method invocation */428429MethodDesc = AcpiNsGetAttachedObject (Node);430ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,431"Control Method invocation %4.4s - %p Desc %p Path=%p\n",432Node->Name.Ascii, Node, MethodDesc, Path));433434NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Start);435if (!NameOp)436{437return_ACPI_STATUS (AE_NO_MEMORY);438}439440/* Change Arg into a METHOD CALL and attach name to it */441442AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);443NameOp->Common.Value.Name = Path;444445/* Point METHODCALL/NAME to the METHOD Node */446447NameOp->Common.Node = Node;448AcpiPsAppendArg (Arg, NameOp);449450if (!MethodDesc)451{452ACPI_ERROR ((AE_INFO,453"Control Method %p has no attached object",454Node));455return_ACPI_STATUS (AE_AML_INTERNAL);456}457458ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,459"Control Method - %p Args %X\n",460Node, MethodDesc->Method.ParamCount));461462/* Get the number of arguments to expect */463464WalkState->ArgCount = MethodDesc->Method.ParamCount;465return_ACPI_STATUS (AE_OK);466}467468/*469* Special handling if the name was not found during the lookup -470* some NotFound cases are allowed471*/472if (Status == AE_NOT_FOUND)473{474/* 1) NotFound is ok during load pass 1/2 (allow forward references) */475476if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) !=477ACPI_PARSE_EXECUTE)478{479Status = AE_OK;480}481482/* 2) NotFound during a CondRefOf(x) is ok by definition */483484else if (WalkState->Op->Common.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)485{486Status = AE_OK;487}488489/*490* 3) NotFound while building a Package is ok at this point, we491* may flag as an error later if slack mode is not enabled.492* (Some ASL code depends on allowing this behavior)493*/494else if ((Arg->Common.Parent) &&495((Arg->Common.Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||496(Arg->Common.Parent->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP)))497{498Status = AE_OK;499}500}501502/* Final exception check (may have been changed from code above) */503504if (ACPI_FAILURE (Status))505{506ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo, Path, Status);507508if ((WalkState->ParseFlags & ACPI_PARSE_MODE_MASK) ==509ACPI_PARSE_EXECUTE)510{511/* Report a control method execution error */512513Status = AcpiDsMethodError (Status, WalkState);514}515}516517/* Save the namepath */518519Arg->Common.Value.Name = Path;520return_ACPI_STATUS (Status);521}522523524/*******************************************************************************525*526* FUNCTION: AcpiPsGetNextSimpleArg527*528* PARAMETERS: ParserState - Current parser state object529* ArgType - The argument type (AML_*_ARG)530* Arg - Where the argument is returned531*532* RETURN: None533*534* DESCRIPTION: Get the next simple argument (constant, string, or namestring)535*536******************************************************************************/537538void539AcpiPsGetNextSimpleArg (540ACPI_PARSE_STATE *ParserState,541UINT32 ArgType,542ACPI_PARSE_OBJECT *Arg)543{544UINT32 Length;545UINT16 Opcode;546UINT8 *Aml = ParserState->Aml;547548549ACPI_FUNCTION_TRACE_U32 (PsGetNextSimpleArg, ArgType);550551552switch (ArgType)553{554case ARGP_BYTEDATA:555556/* Get 1 byte from the AML stream */557558Opcode = AML_BYTE_OP;559Arg->Common.Value.Integer = (UINT64) *Aml;560Length = 1;561break;562563case ARGP_WORDDATA:564565/* Get 2 bytes from the AML stream */566567Opcode = AML_WORD_OP;568ACPI_MOVE_16_TO_64 (&Arg->Common.Value.Integer, Aml);569Length = 2;570break;571572case ARGP_DWORDDATA:573574/* Get 4 bytes from the AML stream */575576Opcode = AML_DWORD_OP;577ACPI_MOVE_32_TO_64 (&Arg->Common.Value.Integer, Aml);578Length = 4;579break;580581case ARGP_QWORDDATA:582583/* Get 8 bytes from the AML stream */584585Opcode = AML_QWORD_OP;586ACPI_MOVE_64_TO_64 (&Arg->Common.Value.Integer, Aml);587Length = 8;588break;589590case ARGP_CHARLIST:591592/* Get a pointer to the string, point past the string */593594Opcode = AML_STRING_OP;595Arg->Common.Value.String = ACPI_CAST_PTR (char, Aml);596597/* Find the null terminator */598599Length = 0;600while (Aml[Length])601{602Length++;603}604Length++;605break;606607case ARGP_NAME:608case ARGP_NAMESTRING:609610AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP);611Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);612return_VOID;613614default:615616ACPI_ERROR ((AE_INFO, "Invalid ArgType 0x%X", ArgType));617return_VOID;618}619620AcpiPsInitOp (Arg, Opcode);621ParserState->Aml += Length;622return_VOID;623}624625626/*******************************************************************************627*628* FUNCTION: AcpiPsGetNextField629*630* PARAMETERS: ParserState - Current parser state object631*632* RETURN: A newly allocated FIELD op633*634* DESCRIPTION: Get next field (NamedField, ReservedField, or AccessField)635*636******************************************************************************/637638static ACPI_PARSE_OBJECT *639AcpiPsGetNextField (640ACPI_PARSE_STATE *ParserState)641{642UINT8 *Aml;643ACPI_PARSE_OBJECT *Field;644ACPI_PARSE_OBJECT *Arg = NULL;645UINT16 Opcode;646UINT32 Name;647UINT8 AccessType;648UINT8 AccessAttribute;649UINT8 AccessLength;650UINT32 PkgLength;651UINT8 *PkgEnd;652UINT32 BufferLength;653654655ACPI_FUNCTION_TRACE (PsGetNextField);656657658ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);659Aml = ParserState->Aml;660661/* Determine field type */662663switch (ACPI_GET8 (ParserState->Aml))664{665case AML_FIELD_OFFSET_OP:666667Opcode = AML_INT_RESERVEDFIELD_OP;668ParserState->Aml++;669break;670671case AML_FIELD_ACCESS_OP:672673Opcode = AML_INT_ACCESSFIELD_OP;674ParserState->Aml++;675break;676677case AML_FIELD_CONNECTION_OP:678679Opcode = AML_INT_CONNECTION_OP;680ParserState->Aml++;681break;682683case AML_FIELD_EXT_ACCESS_OP:684685Opcode = AML_INT_EXTACCESSFIELD_OP;686ParserState->Aml++;687break;688689default:690691Opcode = AML_INT_NAMEDFIELD_OP;692break;693}694695/* Allocate a new field op */696697Field = AcpiPsAllocOp (Opcode, Aml);698if (!Field)699{700return_PTR (NULL);701}702703/* Decode the field type */704705ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);706switch (Opcode)707{708case AML_INT_NAMEDFIELD_OP:709710/* Get the 4-character name */711712ACPI_MOVE_32_TO_32 (&Name, ParserState->Aml);713AcpiPsSetName (Field, Name);714ParserState->Aml += ACPI_NAMESEG_SIZE;715716717ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);718719#ifdef ACPI_ASL_COMPILER720/*721* Because the package length isn't represented as a parse tree object,722* take comments surrounding this and add to the previously created723* parse node.724*/725if (Field->Common.InlineComment)726{727Field->Common.NameComment = Field->Common.InlineComment;728}729Field->Common.InlineComment = AcpiGbl_CurrentInlineComment;730AcpiGbl_CurrentInlineComment = NULL;731#endif732733/* Get the length which is encoded as a package length */734735Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);736break;737738739case AML_INT_RESERVEDFIELD_OP:740741/* Get the length which is encoded as a package length */742743Field->Common.Value.Size = AcpiPsGetNextPackageLength (ParserState);744break;745746747case AML_INT_ACCESSFIELD_OP:748case AML_INT_EXTACCESSFIELD_OP:749750/*751* Get AccessType and AccessAttrib and merge into the field Op752* AccessType is first operand, AccessAttribute is second. stuff753* these bytes into the node integer value for convenience.754*/755756/* Get the two bytes (Type/Attribute) */757758AccessType = ACPI_GET8 (ParserState->Aml);759ParserState->Aml++;760AccessAttribute = ACPI_GET8 (ParserState->Aml);761ParserState->Aml++;762763Field->Common.Value.Integer = (UINT8) AccessType;764Field->Common.Value.Integer |= (UINT16) (AccessAttribute << 8);765766/* This opcode has a third byte, AccessLength */767768if (Opcode == AML_INT_EXTACCESSFIELD_OP)769{770AccessLength = ACPI_GET8 (ParserState->Aml);771ParserState->Aml++;772773Field->Common.Value.Integer |= (UINT32) (AccessLength << 16);774}775break;776777778case AML_INT_CONNECTION_OP:779780/*781* Argument for Connection operator can be either a Buffer782* (resource descriptor), or a NameString.783*/784Aml = ParserState->Aml;785if (ACPI_GET8 (ParserState->Aml) == AML_BUFFER_OP)786{787ParserState->Aml++;788789ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);790PkgEnd = ParserState->Aml;791PkgLength = AcpiPsGetNextPackageLength (ParserState);792PkgEnd += PkgLength;793794ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);795if (ParserState->Aml < PkgEnd)796{797/* Non-empty list */798799Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP, Aml);800if (!Arg)801{802AcpiPsFreeOp (Field);803return_PTR (NULL);804}805806/* Get the actual buffer length argument */807808Opcode = ACPI_GET8 (ParserState->Aml);809ParserState->Aml++;810811ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);812switch (Opcode)813{814case AML_BYTE_OP: /* AML_BYTEDATA_ARG */815816BufferLength = ACPI_GET8 (ParserState->Aml);817ParserState->Aml += 1;818break;819820case AML_WORD_OP: /* AML_WORDDATA_ARG */821822BufferLength = ACPI_GET16 (ParserState->Aml);823ParserState->Aml += 2;824break;825826case AML_DWORD_OP: /* AML_DWORDATA_ARG */827828BufferLength = ACPI_GET32 (ParserState->Aml);829ParserState->Aml += 4;830break;831832default:833834BufferLength = 0;835break;836}837838/* Fill in bytelist data */839840ASL_CV_CAPTURE_COMMENTS_ONLY (ParserState);841Arg->Named.Value.Size = BufferLength;842Arg->Named.Data = ParserState->Aml;843}844845/* Skip to End of byte data */846847ParserState->Aml = PkgEnd;848}849else850{851Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Aml);852if (!Arg)853{854AcpiPsFreeOp (Field);855return_PTR (NULL);856}857858/* Get the Namestring argument */859860Arg->Common.Value.Name = AcpiPsGetNextNamestring (ParserState);861}862863/* Link the buffer/namestring to parent (CONNECTION_OP) */864865AcpiPsAppendArg (Field, Arg);866break;867868869default:870871/* Opcode was set in previous switch */872break;873}874875return_PTR (Field);876}877878/*******************************************************************************879*880* FUNCTION: AcpiPsFreeFieldList881*882* PARAMETERS: Start - First Op in field list883*884* RETURN: None.885*886* DESCRIPTION: Free all Op objects inside a field list.887*888******************************************************************************/889890static void891AcpiPsFreeFieldList (892ACPI_PARSE_OBJECT *Start)893{894ACPI_PARSE_OBJECT *Current = Start;895ACPI_PARSE_OBJECT *Next;896ACPI_PARSE_OBJECT *Arg;897898while (Current)899{900Next = Current->Common.Next;901902/* AML_INT_CONNECTION_OP can have a single argument */903904Arg = AcpiPsGetArg (Current, 0);905if (Arg)906{907AcpiPsFreeOp (Arg);908}909910AcpiPsFreeOp(Current);911Current = Next;912}913}914915916/*******************************************************************************917*918* FUNCTION: AcpiPsGetNextArg919*920* PARAMETERS: WalkState - Current state921* ParserState - Current parser state object922* ArgType - The argument type (AML_*_ARG)923* ReturnArg - Where the next arg is returned924*925* RETURN: Status, and an op object containing the next argument.926*927* DESCRIPTION: Get next argument (including complex list arguments that require928* pushing the parser stack)929*930******************************************************************************/931932ACPI_STATUS933AcpiPsGetNextArg (934ACPI_WALK_STATE *WalkState,935ACPI_PARSE_STATE *ParserState,936UINT32 ArgType,937ACPI_PARSE_OBJECT **ReturnArg)938{939ACPI_PARSE_OBJECT *Arg = NULL;940ACPI_PARSE_OBJECT *Prev = NULL;941ACPI_PARSE_OBJECT *Field;942UINT32 Subop;943ACPI_STATUS Status = AE_OK;944945946ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);947948949ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,950"Expected argument type ARGP: %s (%2.2X)\n",951AcpiUtGetArgumentTypeName (ArgType), ArgType));952953switch (ArgType)954{955case ARGP_BYTEDATA:956case ARGP_WORDDATA:957case ARGP_DWORDDATA:958case ARGP_CHARLIST:959case ARGP_NAME:960case ARGP_NAMESTRING:961962/* Constants, strings, and namestrings are all the same size */963964Arg = AcpiPsAllocOp (AML_BYTE_OP, ParserState->Aml);965if (!Arg)966{967return_ACPI_STATUS (AE_NO_MEMORY);968}969970AcpiPsGetNextSimpleArg (ParserState, ArgType, Arg);971break;972973case ARGP_PKGLENGTH:974975/* Package length, nothing returned */976977ParserState->PkgEnd = AcpiPsGetNextPackageEnd (ParserState);978break;979980case ARGP_FIELDLIST:981982if (ParserState->Aml < ParserState->PkgEnd)983{984/* Non-empty list */985986while (ParserState->Aml < ParserState->PkgEnd)987{988Field = AcpiPsGetNextField (ParserState);989if (!Field)990{991if (Arg)992{993AcpiPsFreeFieldList(Arg);994}995996return_ACPI_STATUS (AE_NO_MEMORY);997}998999if (Prev)1000{1001Prev->Common.Next = Field;1002}1003else1004{1005Arg = Field;1006}1007Prev = Field;1008}10091010/* Skip to End of byte data */10111012ParserState->Aml = ParserState->PkgEnd;1013}1014break;10151016case ARGP_BYTELIST:10171018if (ParserState->Aml < ParserState->PkgEnd)1019{1020/* Non-empty list */10211022Arg = AcpiPsAllocOp (AML_INT_BYTELIST_OP,1023ParserState->Aml);1024if (!Arg)1025{1026return_ACPI_STATUS (AE_NO_MEMORY);1027}10281029/* Fill in bytelist data */10301031Arg->Common.Value.Size = (UINT32)1032ACPI_PTR_DIFF (ParserState->PkgEnd, ParserState->Aml);1033Arg->Named.Data = ParserState->Aml;10341035/* Skip to End of byte data */10361037ParserState->Aml = ParserState->PkgEnd;1038}1039break;10401041case ARGP_SIMPLENAME:1042case ARGP_NAME_OR_REF:10431044ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,1045"**** SimpleName/NameOrRef: %s (%2.2X)\n",1046AcpiUtGetArgumentTypeName (ArgType), ArgType));10471048Subop = AcpiPsPeekOpcode (ParserState);1049if (Subop == 0 ||1050AcpiPsIsLeadingChar (Subop) ||1051ACPI_IS_ROOT_PREFIX (Subop) ||1052ACPI_IS_PARENT_PREFIX (Subop))1053{1054/* NullName or NameString */10551056Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);1057if (!Arg)1058{1059return_ACPI_STATUS (AE_NO_MEMORY);1060}10611062Status = AcpiPsGetNextNamepath (WalkState, ParserState,1063Arg, ACPI_NOT_METHOD_CALL);1064if (ACPI_FAILURE(Status))1065{1066AcpiPsFreeOp (Arg);1067return_ACPI_STATUS (Status);1068}1069}1070else1071{1072/* Single complex argument, nothing returned */10731074WalkState->ArgCount = 1;1075}1076break;10771078case ARGP_TARGET:1079case ARGP_SUPERNAME:10801081ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,1082"**** Target/Supername: %s (%2.2X)\n",1083AcpiUtGetArgumentTypeName (ArgType), ArgType));10841085Subop = AcpiPsPeekOpcode (ParserState);1086if (Subop == 0 ||1087AcpiPsIsLeadingChar (Subop) ||1088ACPI_IS_ROOT_PREFIX (Subop) ||1089ACPI_IS_PARENT_PREFIX (Subop))1090{1091/* NULL target (zero). Convert to a NULL namepath */10921093Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);1094if (!Arg)1095{1096return_ACPI_STATUS (AE_NO_MEMORY);1097}10981099Status = AcpiPsGetNextNamepath (WalkState, ParserState,1100Arg, ACPI_POSSIBLE_METHOD_CALL);1101if (ACPI_FAILURE(Status))1102{1103AcpiPsFreeOp (Arg);1104return_ACPI_STATUS (Status);1105}11061107if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)1108{1109/* Free method call op and corresponding namestring sub-ob */11101111AcpiPsFreeOp (Arg->Common.Value.Arg);1112AcpiPsFreeOp (Arg);1113Arg = NULL;1114WalkState->ArgCount = 1;1115}1116}1117else1118{1119/* Single complex argument, nothing returned */11201121WalkState->ArgCount = 1;1122}1123break;11241125case ARGP_DATAOBJ:1126case ARGP_TERMARG:11271128ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,1129"**** TermArg/DataObj: %s (%2.2X)\n",1130AcpiUtGetArgumentTypeName (ArgType), ArgType));11311132/* Single complex argument, nothing returned */11331134WalkState->ArgCount = 1;1135break;11361137case ARGP_DATAOBJLIST:1138case ARGP_TERMLIST:1139case ARGP_OBJLIST:11401141if (ParserState->Aml < ParserState->PkgEnd)1142{1143/* Non-empty list of variable arguments, nothing returned */11441145WalkState->ArgCount = ACPI_VAR_ARGS;1146}1147break;11481149default:11501151ACPI_ERROR ((AE_INFO, "Invalid ArgType: 0x%X", ArgType));1152Status = AE_AML_OPERAND_TYPE;1153break;1154}11551156*ReturnArg = Arg;1157return_ACPI_STATUS (Status);1158}115911601161