Path: blob/main/sys/contrib/dev/acpica/components/dispatcher/dsfield.c
48521 views
/******************************************************************************1*2* Module Name: dsfield - Dispatcher field routines3*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/amlcode.h>154#include <contrib/dev/acpica/include/acdispat.h>155#include <contrib/dev/acpica/include/acinterp.h>156#include <contrib/dev/acpica/include/acnamesp.h>157#include <contrib/dev/acpica/include/acparser.h>158159#if !defined(ACPI_DB_APP) && defined(ACPI_EXEC_APP)160#include "aecommon.h"161#endif162163164#define _COMPONENT ACPI_DISPATCHER165ACPI_MODULE_NAME ("dsfield")166167/* Local prototypes */168169#ifdef ACPI_ASL_COMPILER170#include <contrib/dev/acpica/include/acdisasm.h>171172static ACPI_STATUS173AcpiDsCreateExternalRegion (174ACPI_STATUS LookupStatus,175ACPI_PARSE_OBJECT *Op,176char *Path,177ACPI_WALK_STATE *WalkState,178ACPI_NAMESPACE_NODE **Node);179#endif180181static ACPI_STATUS182AcpiDsGetFieldNames (183ACPI_CREATE_FIELD_INFO *Info,184ACPI_WALK_STATE *WalkState,185ACPI_PARSE_OBJECT *Arg);186187188#ifdef ACPI_ASL_COMPILER189/*******************************************************************************190*191* FUNCTION: AcpiDsCreateExternalRegion (iASL Disassembler only)192*193* PARAMETERS: LookupStatus - Status from NsLookup operation194* Op - Op containing the Field definition and args195* Path - Pathname of the region196* ` WalkState - Current method state197* Node - Where the new region node is returned198*199* RETURN: Status200*201* DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new202* region node/object.203*204******************************************************************************/205206static ACPI_STATUS207AcpiDsCreateExternalRegion (208ACPI_STATUS LookupStatus,209ACPI_PARSE_OBJECT *Op,210char *Path,211ACPI_WALK_STATE *WalkState,212ACPI_NAMESPACE_NODE **Node)213{214ACPI_STATUS Status;215ACPI_OPERAND_OBJECT *ObjDesc;216217218if (LookupStatus != AE_NOT_FOUND)219{220return (LookupStatus);221}222223/*224* Table disassembly:225* OperationRegion not found. Generate an External for it, and226* insert the name into the namespace.227*/228AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);229230Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,231ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);232if (ACPI_FAILURE (Status))233{234return (Status);235}236237/* Must create and install a region object for the new node */238239ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);240if (!ObjDesc)241{242return (AE_NO_MEMORY);243}244245ObjDesc->Region.Node = *Node;246Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);247return (Status);248}249#endif250251252/*******************************************************************************253*254* FUNCTION: AcpiDsCreateBufferField255*256* PARAMETERS: Op - Current parse op (CreateXXField)257* WalkState - Current state258*259* RETURN: Status260*261* DESCRIPTION: Execute the CreateField operators:262* CreateBitFieldOp,263* CreateByteFieldOp,264* CreateWordFieldOp,265* CreateDwordFieldOp,266* CreateQwordFieldOp,267* CreateFieldOp (all of which define a field in a buffer)268*269******************************************************************************/270271ACPI_STATUS272AcpiDsCreateBufferField (273ACPI_PARSE_OBJECT *Op,274ACPI_WALK_STATE *WalkState)275{276ACPI_PARSE_OBJECT *Arg;277ACPI_NAMESPACE_NODE *Node;278ACPI_STATUS Status;279ACPI_OPERAND_OBJECT *ObjDesc;280ACPI_OPERAND_OBJECT *SecondDesc = NULL;281UINT32 Flags;282283284ACPI_FUNCTION_TRACE (DsCreateBufferField);285286287/*288* Get the NameString argument (name of the new BufferField)289*/290if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)291{292/* For CreateField, name is the 4th argument */293294Arg = AcpiPsGetArg (Op, 3);295}296else297{298/* For all other CreateXXXField operators, name is the 3rd argument */299300Arg = AcpiPsGetArg (Op, 2);301}302303if (!Arg)304{305return_ACPI_STATUS (AE_AML_NO_OPERAND);306}307308if (WalkState->DeferredNode)309{310Node = WalkState->DeferredNode;311}312else313{314/* Execute flag should always be set when this function is entered */315316if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))317{318ACPI_ERROR ((AE_INFO,319"Parse execute mode is not set"));320return_ACPI_STATUS (AE_AML_INTERNAL);321}322323/* Creating new namespace node, should not already exist */324325Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |326ACPI_NS_ERROR_IF_FOUND;327328/*329* Mark node temporary if we are executing a normal control330* method. (Don't mark if this is a module-level code method)331*/332if (WalkState->MethodNode &&333!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))334{335Flags |= ACPI_NS_TEMPORARY;336}337338/* Enter the NameString into the namespace */339340Status = AcpiNsLookup (WalkState->ScopeInfo,341Arg->Common.Value.String, ACPI_TYPE_ANY,342ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);343if ((WalkState->ParseFlags & ACPI_PARSE_DISASSEMBLE) &&344Status == AE_ALREADY_EXISTS)345{346Status = AE_OK;347}348else if (ACPI_FAILURE (Status))349{350ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,351Arg->Common.Value.String, Status);352return_ACPI_STATUS (Status);353}354}355356/*357* We could put the returned object (Node) on the object stack for later,358* but for now, we will put it in the "op" object that the parser uses,359* so we can get it again at the end of this scope.360*/361Op->Common.Node = Node;362363/*364* If there is no object attached to the node, this node was just created365* and we need to create the field object. Otherwise, this was a lookup366* of an existing node and we don't want to create the field object again.367*/368ObjDesc = AcpiNsGetAttachedObject (Node);369if (ObjDesc)370{371return_ACPI_STATUS (AE_OK);372}373374/*375* The Field definition is not fully parsed at this time.376* (We must save the address of the AML for the buffer and index operands)377*/378379/* Create the buffer field object */380381ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);382if (!ObjDesc)383{384Status = AE_NO_MEMORY;385goto Cleanup;386}387388/*389* Remember location in AML stream of the field unit opcode and operands390* -- since the buffer and index operands must be evaluated.391*/392SecondDesc = ObjDesc->Common.NextObject;393SecondDesc->Extra.AmlStart = Op->Named.Data;394SecondDesc->Extra.AmlLength = Op->Named.Length;395ObjDesc->BufferField.Node = Node;396397/* Attach constructed field descriptors to parent node */398399Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);400if (ACPI_FAILURE (Status))401{402goto Cleanup;403}404405406Cleanup:407408/* Remove local reference to the object */409410AcpiUtRemoveReference (ObjDesc);411return_ACPI_STATUS (Status);412}413414415/*******************************************************************************416*417* FUNCTION: AcpiDsGetFieldNames418*419* PARAMETERS: Info - CreateField info structure420* WalkState - Current method state421* Arg - First parser arg for the field name list422*423* RETURN: Status424*425* DESCRIPTION: Process all named fields in a field declaration. Names are426* entered into the namespace.427*428******************************************************************************/429430static ACPI_STATUS431AcpiDsGetFieldNames (432ACPI_CREATE_FIELD_INFO *Info,433ACPI_WALK_STATE *WalkState,434ACPI_PARSE_OBJECT *Arg)435{436ACPI_STATUS Status;437UINT64 Position;438ACPI_PARSE_OBJECT *Child;439440#if !defined(ACPI_DB_APP) && defined(ACPI_EXEC_APP)441ACPI_OPERAND_OBJECT *ResultDesc;442ACPI_OPERAND_OBJECT *ObjDesc;443char *NamePath;444#endif445446447ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);448449450/* First field starts at bit zero */451452Info->FieldBitPosition = 0;453454/* Process all elements in the field list (of parse nodes) */455456while (Arg)457{458/*459* Four types of field elements are handled:460* 1) Name - Enters a new named field into the namespace461* 2) Offset - specifies a bit offset462* 3) AccessAs - changes the access mode/attributes463* 4) Connection - Associate a resource template with the field464*/465switch (Arg->Common.AmlOpcode)466{467case AML_INT_RESERVEDFIELD_OP:468469Position = (UINT64) Info->FieldBitPosition +470(UINT64) Arg->Common.Value.Size;471472if (Position > ACPI_UINT32_MAX)473{474ACPI_ERROR ((AE_INFO,475"Bit offset within field too large (> 0xFFFFFFFF)"));476return_ACPI_STATUS (AE_SUPPORT);477}478479Info->FieldBitPosition = (UINT32) Position;480break;481482case AML_INT_ACCESSFIELD_OP:483case AML_INT_EXTACCESSFIELD_OP:484/*485* Get new AccessType, AccessAttribute, and AccessLength fields486* -- to be used for all field units that follow, until the487* end-of-field or another AccessAs keyword is encountered.488* NOTE. These three bytes are encoded in the integer value489* of the parseop for convenience.490*491* In FieldFlags, preserve the flag bits other than the492* ACCESS_TYPE bits.493*/494495/* AccessType (ByteAcc, WordAcc, etc.) */496497Info->FieldFlags = (UINT8)498((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |499((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));500501/* AccessAttribute (AttribQuick, AttribByte, etc.) */502503Info->Attribute = (UINT8)504((Arg->Common.Value.Integer >> 8) & 0xFF);505506/* AccessLength (for serial/buffer protocols) */507508Info->AccessLength = (UINT8)509((Arg->Common.Value.Integer >> 16) & 0xFF);510break;511512case AML_INT_CONNECTION_OP:513/*514* Clear any previous connection. New connection is used for all515* fields that follow, similar to AccessAs516*/517Info->ResourceBuffer = NULL;518Info->ConnectionNode = NULL;519Info->PinNumberIndex = 0;520521/*522* A Connection() is either an actual resource descriptor (buffer)523* or a named reference to a resource template524*/525Child = Arg->Common.Value.Arg;526if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)527{528Info->ResourceBuffer = Child->Named.Data;529Info->ResourceLength = (UINT16) Child->Named.Value.Integer;530}531else532{533/* Lookup the Connection() namepath, it should already exist */534535Status = AcpiNsLookup (WalkState->ScopeInfo,536Child->Common.Value.Name, ACPI_TYPE_ANY,537ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,538WalkState, &Info->ConnectionNode);539if (ACPI_FAILURE (Status))540{541ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,542Child->Common.Value.Name, Status);543return_ACPI_STATUS (Status);544}545}546break;547548case AML_INT_NAMEDFIELD_OP:549550/* Lookup the name, it should already exist */551552Status = AcpiNsLookup (WalkState->ScopeInfo,553(char *) &Arg->Named.Name, Info->FieldType,554ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,555WalkState, &Info->FieldNode);556if (ACPI_FAILURE (Status))557{558ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,559(char *) &Arg->Named.Name, Status);560return_ACPI_STATUS (Status);561}562else563{564Arg->Common.Node = Info->FieldNode;565Info->FieldBitLength = Arg->Common.Value.Size;566567/*568* If there is no object attached to the node, this node was569* just created and we need to create the field object.570* Otherwise, this was a lookup of an existing node and we571* don't want to create the field object again.572*/573if (!AcpiNsGetAttachedObject (Info->FieldNode))574{575Status = AcpiExPrepFieldValue (Info);576if (ACPI_FAILURE (Status))577{578return_ACPI_STATUS (Status);579}580#if !defined(ACPI_DB_APP) && defined(ACPI_EXEC_APP)581NamePath = AcpiNsGetExternalPathname (Info->FieldNode);582if (ACPI_SUCCESS (AeLookupInitFileEntry (NamePath, &ObjDesc)))583{584AcpiExWriteDataToField (ObjDesc,585AcpiNsGetAttachedObject (Info->FieldNode),586&ResultDesc);587AcpiUtRemoveReference (ObjDesc);588}589ACPI_FREE (NamePath);590#endif591}592}593594/* Keep track of bit position for the next field */595596Position = (UINT64) Info->FieldBitPosition +597(UINT64) Arg->Common.Value.Size;598599if (Position > ACPI_UINT32_MAX)600{601ACPI_ERROR ((AE_INFO,602"Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",603ACPI_CAST_PTR (char, &Info->FieldNode->Name)));604return_ACPI_STATUS (AE_SUPPORT);605}606607Info->FieldBitPosition += Info->FieldBitLength;608Info->PinNumberIndex++; /* Index relative to previous Connection() */609break;610611default:612613ACPI_ERROR ((AE_INFO,614"Invalid opcode in field list: 0x%X",615Arg->Common.AmlOpcode));616return_ACPI_STATUS (AE_AML_BAD_OPCODE);617}618619Arg = Arg->Common.Next;620}621622return_ACPI_STATUS (AE_OK);623}624625626/*******************************************************************************627*628* FUNCTION: AcpiDsCreateField629*630* PARAMETERS: Op - Op containing the Field definition and args631* RegionNode - Object for the containing Operation Region632* ` WalkState - Current method state633*634* RETURN: Status635*636* DESCRIPTION: Create a new field in the specified operation region637*638******************************************************************************/639640ACPI_STATUS641AcpiDsCreateField (642ACPI_PARSE_OBJECT *Op,643ACPI_NAMESPACE_NODE *RegionNode,644ACPI_WALK_STATE *WalkState)645{646ACPI_STATUS Status;647ACPI_PARSE_OBJECT *Arg;648ACPI_CREATE_FIELD_INFO Info;649650651ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);652653654/* First arg is the name of the parent OpRegion (must already exist) */655656Arg = Op->Common.Value.Arg;657658if (!RegionNode)659{660Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,661ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,662ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);663#ifdef ACPI_ASL_COMPILER664Status = AcpiDsCreateExternalRegion (Status, Arg,665Arg->Common.Value.Name, WalkState, &RegionNode);666#endif667if (ACPI_FAILURE (Status))668{669ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,670Arg->Common.Value.Name, Status);671return_ACPI_STATUS (Status);672}673}674675memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));676677/* Second arg is the field flags */678679Arg = Arg->Common.Next;680Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;681Info.Attribute = 0;682683/* Each remaining arg is a Named Field */684685Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;686Info.RegionNode = RegionNode;687688Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);689if (ACPI_FAILURE (Status))690{691return_ACPI_STATUS (Status);692}693694if (Info.RegionNode->Object->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM)695{696RegionNode->Object->Field.InternalPccBuffer =697ACPI_ALLOCATE_ZEROED(Info.RegionNode->Object->Region.Length);698if (!RegionNode->Object->Field.InternalPccBuffer)699{700return_ACPI_STATUS (AE_NO_MEMORY);701}702}703704return_ACPI_STATUS (Status);705}706707708/*******************************************************************************709*710* FUNCTION: AcpiDsInitFieldObjects711*712* PARAMETERS: Op - Op containing the Field definition and args713* ` WalkState - Current method state714*715* RETURN: Status716*717* DESCRIPTION: For each "Field Unit" name in the argument list that is718* part of the field declaration, enter the name into the719* namespace.720*721******************************************************************************/722723ACPI_STATUS724AcpiDsInitFieldObjects (725ACPI_PARSE_OBJECT *Op,726ACPI_WALK_STATE *WalkState)727{728ACPI_STATUS Status;729ACPI_PARSE_OBJECT *Arg = NULL;730ACPI_NAMESPACE_NODE *Node;731UINT8 Type = 0;732UINT32 Flags;733734735ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);736737738/* Execute flag should always be set when this function is entered */739740if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))741{742if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)743{744/* BankField Op is deferred, just return OK */745746return_ACPI_STATUS (AE_OK);747}748749ACPI_ERROR ((AE_INFO,750"Parse deferred mode is not set"));751return_ACPI_STATUS (AE_AML_INTERNAL);752}753754/*755* Get the FieldList argument for this opcode. This is the start of the756* list of field elements.757*/758switch (WalkState->Opcode)759{760case AML_FIELD_OP:761762Arg = AcpiPsGetArg (Op, 2);763Type = ACPI_TYPE_LOCAL_REGION_FIELD;764break;765766case AML_BANK_FIELD_OP:767768Arg = AcpiPsGetArg (Op, 4);769Type = ACPI_TYPE_LOCAL_BANK_FIELD;770break;771772case AML_INDEX_FIELD_OP:773774Arg = AcpiPsGetArg (Op, 3);775Type = ACPI_TYPE_LOCAL_INDEX_FIELD;776break;777778default:779780return_ACPI_STATUS (AE_BAD_PARAMETER);781}782783/* Creating new namespace node(s), should not already exist */784785Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |786ACPI_NS_ERROR_IF_FOUND;787788/*789* Mark node(s) temporary if we are executing a normal control790* method. (Don't mark if this is a module-level code method)791*/792if (WalkState->MethodNode &&793!(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))794{795Flags |= ACPI_NS_TEMPORARY;796}797798#ifdef ACPI_EXEC_APP799Flags |= ACPI_NS_OVERRIDE_IF_FOUND;800#endif801/*802* Walk the list of entries in the FieldList803* Note: FieldList can be of zero length. In this case, Arg will be NULL.804*/805while (Arg)806{807/*808* Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested809* in the field names in order to enter them into the namespace.810*/811if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)812{813Status = AcpiNsLookup (WalkState->ScopeInfo,814(char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,815Flags, WalkState, &Node);816if (ACPI_FAILURE (Status))817{818ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,819(char *) &Arg->Named.Name, Status);820if (Status != AE_ALREADY_EXISTS)821{822return_ACPI_STATUS (Status);823}824825/* Name already exists, just ignore this error */826}827828Arg->Common.Node = Node;829}830831/* Get the next field element in the list */832833Arg = Arg->Common.Next;834}835836return_ACPI_STATUS (AE_OK);837}838839840/*******************************************************************************841*842* FUNCTION: AcpiDsCreateBankField843*844* PARAMETERS: Op - Op containing the Field definition and args845* RegionNode - Object for the containing Operation Region846* WalkState - Current method state847*848* RETURN: Status849*850* DESCRIPTION: Create a new bank field in the specified operation region851*852******************************************************************************/853854ACPI_STATUS855AcpiDsCreateBankField (856ACPI_PARSE_OBJECT *Op,857ACPI_NAMESPACE_NODE *RegionNode,858ACPI_WALK_STATE *WalkState)859{860ACPI_STATUS Status;861ACPI_PARSE_OBJECT *Arg;862ACPI_CREATE_FIELD_INFO Info;863864865ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);866867868/* First arg is the name of the parent OpRegion (must already exist) */869870Arg = Op->Common.Value.Arg;871if (!RegionNode)872{873Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,874ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,875ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);876#ifdef ACPI_ASL_COMPILER877Status = AcpiDsCreateExternalRegion (Status, Arg,878Arg->Common.Value.Name, WalkState, &RegionNode);879#endif880if (ACPI_FAILURE (Status))881{882ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,883Arg->Common.Value.Name, Status);884return_ACPI_STATUS (Status);885}886}887888/* Second arg is the Bank Register (Field) (must already exist) */889890Arg = Arg->Common.Next;891Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,892ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,893ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);894if (ACPI_FAILURE (Status))895{896ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,897Arg->Common.Value.String, Status);898return_ACPI_STATUS (Status);899}900901/*902* Third arg is the BankValue903* This arg is a TermArg, not a constant904* It will be evaluated later, by AcpiDsEvalBankFieldOperands905*/906Arg = Arg->Common.Next;907908/* Fourth arg is the field flags */909910Arg = Arg->Common.Next;911Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;912913/* Each remaining arg is a Named Field */914915Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;916Info.RegionNode = RegionNode;917918/*919* Use Info.DataRegisterNode to store BankField Op920* It's safe because DataRegisterNode will never be used when create921* bank field \we store AmlStart and AmlLength in the BankField Op for922* late evaluation. Used in AcpiExPrepFieldValue(Info)923*924* TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like925* "void *ParentOp"?926*/927Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;928929Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);930return_ACPI_STATUS (Status);931}932933934/*******************************************************************************935*936* FUNCTION: AcpiDsCreateIndexField937*938* PARAMETERS: Op - Op containing the Field definition and args939* RegionNode - Object for the containing Operation Region940* ` WalkState - Current method state941*942* RETURN: Status943*944* DESCRIPTION: Create a new index field in the specified operation region945*946******************************************************************************/947948ACPI_STATUS949AcpiDsCreateIndexField (950ACPI_PARSE_OBJECT *Op,951ACPI_NAMESPACE_NODE *RegionNode,952ACPI_WALK_STATE *WalkState)953{954ACPI_STATUS Status;955ACPI_PARSE_OBJECT *Arg;956ACPI_CREATE_FIELD_INFO Info;957958959ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);960961962/* First arg is the name of the Index register (must already exist) */963964Arg = Op->Common.Value.Arg;965Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,966ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,967ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);968if (ACPI_FAILURE (Status))969{970ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,971Arg->Common.Value.String, Status);972return_ACPI_STATUS (Status);973}974975/* Second arg is the data register (must already exist) */976977Arg = Arg->Common.Next;978Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,979ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,980ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);981if (ACPI_FAILURE (Status))982{983ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,984Arg->Common.Value.String, Status);985return_ACPI_STATUS (Status);986}987988/* Next arg is the field flags */989990Arg = Arg->Common.Next;991Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;992993/* Each remaining arg is a Named Field */994995Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;996Info.RegionNode = RegionNode;997998Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);999return_ACPI_STATUS (Status);1000}100110021003