Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:02

0001 /******************************************************************************
0002  *
0003  * Module Name: dsfield - Dispatcher field routines
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, 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  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "amlcode.h"
0155 #include "acdispat.h"
0156 #include "acinterp.h"
0157 #include "acnamesp.h"
0158 #include "acparser.h"
0159 
0160 #ifdef ACPI_EXEC_APP
0161 #include "aecommon.h"
0162 #endif
0163 
0164 
0165 #define _COMPONENT          ACPI_DISPATCHER
0166         ACPI_MODULE_NAME    ("dsfield")
0167 
0168 /* Local prototypes */
0169 
0170 #ifdef ACPI_ASL_COMPILER
0171 #include "acdisasm.h"
0172 
0173 static ACPI_STATUS
0174 AcpiDsCreateExternalRegion (
0175     ACPI_STATUS             LookupStatus,
0176     ACPI_PARSE_OBJECT       *Op,
0177     char                    *Path,
0178     ACPI_WALK_STATE         *WalkState,
0179     ACPI_NAMESPACE_NODE     **Node);
0180 #endif
0181 
0182 static ACPI_STATUS
0183 AcpiDsGetFieldNames (
0184     ACPI_CREATE_FIELD_INFO  *Info,
0185     ACPI_WALK_STATE         *WalkState,
0186     ACPI_PARSE_OBJECT       *Arg);
0187 
0188 
0189 #ifdef ACPI_ASL_COMPILER
0190 /*******************************************************************************
0191  *
0192  * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
0193  *
0194  * PARAMETERS:  LookupStatus    - Status from NsLookup operation
0195  *              Op              - Op containing the Field definition and args
0196  *              Path            - Pathname of the region
0197  *  `           WalkState       - Current method state
0198  *              Node            - Where the new region node is returned
0199  *
0200  * RETURN:      Status
0201  *
0202  * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
0203  *              region node/object.
0204  *
0205  ******************************************************************************/
0206 
0207 static ACPI_STATUS
0208 AcpiDsCreateExternalRegion (
0209     ACPI_STATUS             LookupStatus,
0210     ACPI_PARSE_OBJECT       *Op,
0211     char                    *Path,
0212     ACPI_WALK_STATE         *WalkState,
0213     ACPI_NAMESPACE_NODE     **Node)
0214 {
0215     ACPI_STATUS             Status;
0216     ACPI_OPERAND_OBJECT     *ObjDesc;
0217 
0218 
0219     if (LookupStatus != AE_NOT_FOUND)
0220     {
0221         return (LookupStatus);
0222     }
0223 
0224     /*
0225      * Table disassembly:
0226      * OperationRegion not found. Generate an External for it, and
0227      * insert the name into the namespace.
0228      */
0229     AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
0230 
0231     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
0232        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
0233     if (ACPI_FAILURE (Status))
0234     {
0235         return (Status);
0236     }
0237 
0238     /* Must create and install a region object for the new node */
0239 
0240     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
0241     if (!ObjDesc)
0242     {
0243         return (AE_NO_MEMORY);
0244     }
0245 
0246     ObjDesc->Region.Node = *Node;
0247     Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
0248     return (Status);
0249 }
0250 #endif
0251 
0252 
0253 /*******************************************************************************
0254  *
0255  * FUNCTION:    AcpiDsCreateBufferField
0256  *
0257  * PARAMETERS:  Op                  - Current parse op (CreateXXField)
0258  *              WalkState           - Current state
0259  *
0260  * RETURN:      Status
0261  *
0262  * DESCRIPTION: Execute the CreateField operators:
0263  *              CreateBitFieldOp,
0264  *              CreateByteFieldOp,
0265  *              CreateWordFieldOp,
0266  *              CreateDwordFieldOp,
0267  *              CreateQwordFieldOp,
0268  *              CreateFieldOp       (all of which define a field in a buffer)
0269  *
0270  ******************************************************************************/
0271 
0272 ACPI_STATUS
0273 AcpiDsCreateBufferField (
0274     ACPI_PARSE_OBJECT       *Op,
0275     ACPI_WALK_STATE         *WalkState)
0276 {
0277     ACPI_PARSE_OBJECT       *Arg;
0278     ACPI_NAMESPACE_NODE     *Node;
0279     ACPI_STATUS             Status;
0280     ACPI_OPERAND_OBJECT     *ObjDesc;
0281     ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
0282     UINT32                  Flags;
0283 
0284 
0285     ACPI_FUNCTION_TRACE (DsCreateBufferField);
0286 
0287 
0288     /*
0289      * Get the NameString argument (name of the new BufferField)
0290      */
0291     if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
0292     {
0293         /* For CreateField, name is the 4th argument */
0294 
0295         Arg = AcpiPsGetArg (Op, 3);
0296     }
0297     else
0298     {
0299         /* For all other CreateXXXField operators, name is the 3rd argument */
0300 
0301         Arg = AcpiPsGetArg (Op, 2);
0302     }
0303 
0304     if (!Arg)
0305     {
0306         return_ACPI_STATUS (AE_AML_NO_OPERAND);
0307     }
0308 
0309     if (WalkState->DeferredNode)
0310     {
0311         Node = WalkState->DeferredNode;
0312     }
0313     else
0314     {
0315         /* Execute flag should always be set when this function is entered */
0316 
0317         if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
0318         {
0319             ACPI_ERROR ((AE_INFO,
0320                 "Parse execute mode is not set"));
0321             return_ACPI_STATUS (AE_AML_INTERNAL);
0322         }
0323 
0324         /* Creating new namespace node, should not already exist */
0325 
0326         Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
0327             ACPI_NS_ERROR_IF_FOUND;
0328 
0329         /*
0330          * Mark node temporary if we are executing a normal control
0331          * method. (Don't mark if this is a module-level code method)
0332          */
0333         if (WalkState->MethodNode &&
0334             !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
0335         {
0336             Flags |= ACPI_NS_TEMPORARY;
0337         }
0338 
0339         /* Enter the NameString into the namespace */
0340 
0341         Status = AcpiNsLookup (WalkState->ScopeInfo,
0342             Arg->Common.Value.String, ACPI_TYPE_ANY,
0343             ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
0344         if ((WalkState->ParseFlags & ACPI_PARSE_DISASSEMBLE) &&
0345             Status == AE_ALREADY_EXISTS)
0346         {
0347             Status = AE_OK;
0348         }
0349         else if (ACPI_FAILURE (Status))
0350         {
0351             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0352                 Arg->Common.Value.String, Status);
0353             return_ACPI_STATUS (Status);
0354         }
0355     }
0356 
0357     /*
0358      * We could put the returned object (Node) on the object stack for later,
0359      * but for now, we will put it in the "op" object that the parser uses,
0360      * so we can get it again at the end of this scope.
0361      */
0362     Op->Common.Node = Node;
0363 
0364     /*
0365      * If there is no object attached to the node, this node was just created
0366      * and we need to create the field object. Otherwise, this was a lookup
0367      * of an existing node and we don't want to create the field object again.
0368      */
0369     ObjDesc = AcpiNsGetAttachedObject (Node);
0370     if (ObjDesc)
0371     {
0372         return_ACPI_STATUS (AE_OK);
0373     }
0374 
0375     /*
0376      * The Field definition is not fully parsed at this time.
0377      * (We must save the address of the AML for the buffer and index operands)
0378      */
0379 
0380     /* Create the buffer field object */
0381 
0382     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
0383     if (!ObjDesc)
0384     {
0385         Status = AE_NO_MEMORY;
0386         goto Cleanup;
0387     }
0388 
0389     /*
0390      * Remember location in AML stream of the field unit opcode and operands
0391      * -- since the buffer and index operands must be evaluated.
0392      */
0393     SecondDesc = ObjDesc->Common.NextObject;
0394     SecondDesc->Extra.AmlStart = Op->Named.Data;
0395     SecondDesc->Extra.AmlLength = Op->Named.Length;
0396     ObjDesc->BufferField.Node = Node;
0397 
0398     /* Attach constructed field descriptors to parent node */
0399 
0400     Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
0401     if (ACPI_FAILURE (Status))
0402     {
0403         goto Cleanup;
0404     }
0405 
0406 
0407 Cleanup:
0408 
0409     /* Remove local reference to the object */
0410 
0411     AcpiUtRemoveReference (ObjDesc);
0412     return_ACPI_STATUS (Status);
0413 }
0414 
0415 
0416 /*******************************************************************************
0417  *
0418  * FUNCTION:    AcpiDsGetFieldNames
0419  *
0420  * PARAMETERS:  Info            - CreateField info structure
0421  *              WalkState       - Current method state
0422  *              Arg             - First parser arg for the field name list
0423  *
0424  * RETURN:      Status
0425  *
0426  * DESCRIPTION: Process all named fields in a field declaration. Names are
0427  *              entered into the namespace.
0428  *
0429  ******************************************************************************/
0430 
0431 static ACPI_STATUS
0432 AcpiDsGetFieldNames (
0433     ACPI_CREATE_FIELD_INFO  *Info,
0434     ACPI_WALK_STATE         *WalkState,
0435     ACPI_PARSE_OBJECT       *Arg)
0436 {
0437     ACPI_STATUS             Status;
0438     UINT64                  Position;
0439     ACPI_PARSE_OBJECT       *Child;
0440 
0441 #ifdef ACPI_EXEC_APP
0442     ACPI_OPERAND_OBJECT     *ResultDesc;
0443     ACPI_OPERAND_OBJECT     *ObjDesc;
0444     char                    *NamePath;
0445 #endif
0446 
0447 
0448     ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
0449 
0450 
0451     /* First field starts at bit zero */
0452 
0453     Info->FieldBitPosition = 0;
0454 
0455     /* Process all elements in the field list (of parse nodes) */
0456 
0457     while (Arg)
0458     {
0459         /*
0460          * Four types of field elements are handled:
0461          * 1) Name - Enters a new named field into the namespace
0462          * 2) Offset - specifies a bit offset
0463          * 3) AccessAs - changes the access mode/attributes
0464          * 4) Connection - Associate a resource template with the field
0465          */
0466         switch (Arg->Common.AmlOpcode)
0467         {
0468         case AML_INT_RESERVEDFIELD_OP:
0469 
0470             Position = (UINT64) Info->FieldBitPosition +
0471                 (UINT64) Arg->Common.Value.Size;
0472 
0473             if (Position > ACPI_UINT32_MAX)
0474             {
0475                 ACPI_ERROR ((AE_INFO,
0476                     "Bit offset within field too large (> 0xFFFFFFFF)"));
0477                 return_ACPI_STATUS (AE_SUPPORT);
0478             }
0479 
0480             Info->FieldBitPosition = (UINT32) Position;
0481             break;
0482 
0483         case AML_INT_ACCESSFIELD_OP:
0484         case AML_INT_EXTACCESSFIELD_OP:
0485             /*
0486              * Get new AccessType, AccessAttribute, and AccessLength fields
0487              * -- to be used for all field units that follow, until the
0488              * end-of-field or another AccessAs keyword is encountered.
0489              * NOTE. These three bytes are encoded in the integer value
0490              * of the parseop for convenience.
0491              *
0492              * In FieldFlags, preserve the flag bits other than the
0493              * ACCESS_TYPE bits.
0494              */
0495 
0496             /* AccessType (ByteAcc, WordAcc, etc.) */
0497 
0498             Info->FieldFlags = (UINT8)
0499                 ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
0500                 ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
0501 
0502             /* AccessAttribute (AttribQuick, AttribByte, etc.) */
0503 
0504             Info->Attribute = (UINT8)
0505                 ((Arg->Common.Value.Integer >> 8) & 0xFF);
0506 
0507             /* AccessLength (for serial/buffer protocols) */
0508 
0509             Info->AccessLength = (UINT8)
0510                 ((Arg->Common.Value.Integer >> 16) & 0xFF);
0511             break;
0512 
0513         case AML_INT_CONNECTION_OP:
0514             /*
0515              * Clear any previous connection. New connection is used for all
0516              * fields that follow, similar to AccessAs
0517              */
0518             Info->ResourceBuffer = NULL;
0519             Info->ConnectionNode = NULL;
0520             Info->PinNumberIndex = 0;
0521 
0522             /*
0523              * A Connection() is either an actual resource descriptor (buffer)
0524              * or a named reference to a resource template
0525              */
0526             Child = Arg->Common.Value.Arg;
0527             if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
0528             {
0529                 Info->ResourceBuffer = Child->Named.Data;
0530                 Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
0531             }
0532             else
0533             {
0534                 /* Lookup the Connection() namepath, it should already exist */
0535 
0536                 Status = AcpiNsLookup (WalkState->ScopeInfo,
0537                     Child->Common.Value.Name, ACPI_TYPE_ANY,
0538                     ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
0539                     WalkState, &Info->ConnectionNode);
0540                 if (ACPI_FAILURE (Status))
0541                 {
0542                     ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0543                         Child->Common.Value.Name, Status);
0544                     return_ACPI_STATUS (Status);
0545                 }
0546             }
0547             break;
0548 
0549         case AML_INT_NAMEDFIELD_OP:
0550 
0551             /* Lookup the name, it should already exist */
0552 
0553             Status = AcpiNsLookup (WalkState->ScopeInfo,
0554                 (char *) &Arg->Named.Name, Info->FieldType,
0555                 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
0556                 WalkState, &Info->FieldNode);
0557             if (ACPI_FAILURE (Status))
0558             {
0559                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0560                     (char *) &Arg->Named.Name, Status);
0561                 return_ACPI_STATUS (Status);
0562             }
0563             else
0564             {
0565                 Arg->Common.Node = Info->FieldNode;
0566                 Info->FieldBitLength = Arg->Common.Value.Size;
0567 
0568                 /*
0569                  * If there is no object attached to the node, this node was
0570                  * just created and we need to create the field object.
0571                  * Otherwise, this was a lookup of an existing node and we
0572                  * don't want to create the field object again.
0573                  */
0574                 if (!AcpiNsGetAttachedObject (Info->FieldNode))
0575                 {
0576                     Status = AcpiExPrepFieldValue (Info);
0577                     if (ACPI_FAILURE (Status))
0578                     {
0579                         return_ACPI_STATUS (Status);
0580                     }
0581 #ifdef ACPI_EXEC_APP
0582                     NamePath = AcpiNsGetExternalPathname (Info->FieldNode);
0583                     if (ACPI_SUCCESS (AeLookupInitFileEntry (NamePath, &ObjDesc)))
0584                     {
0585                         AcpiExWriteDataToField (ObjDesc,
0586                             AcpiNsGetAttachedObject (Info->FieldNode),
0587                             &ResultDesc);
0588                         AcpiUtRemoveReference (ObjDesc);
0589                     }
0590                     ACPI_FREE (NamePath);
0591 #endif
0592                 }
0593             }
0594 
0595             /* Keep track of bit position for the next field */
0596 
0597             Position = (UINT64) Info->FieldBitPosition +
0598                 (UINT64) Arg->Common.Value.Size;
0599 
0600             if (Position > ACPI_UINT32_MAX)
0601             {
0602                 ACPI_ERROR ((AE_INFO,
0603                     "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
0604                     ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
0605                 return_ACPI_STATUS (AE_SUPPORT);
0606             }
0607 
0608             Info->FieldBitPosition += Info->FieldBitLength;
0609             Info->PinNumberIndex++; /* Index relative to previous Connection() */
0610             break;
0611 
0612         default:
0613 
0614             ACPI_ERROR ((AE_INFO,
0615                 "Invalid opcode in field list: 0x%X",
0616                 Arg->Common.AmlOpcode));
0617             return_ACPI_STATUS (AE_AML_BAD_OPCODE);
0618         }
0619 
0620         Arg = Arg->Common.Next;
0621     }
0622 
0623     return_ACPI_STATUS (AE_OK);
0624 }
0625 
0626 
0627 /*******************************************************************************
0628  *
0629  * FUNCTION:    AcpiDsCreateField
0630  *
0631  * PARAMETERS:  Op              - Op containing the Field definition and args
0632  *              RegionNode      - Object for the containing Operation Region
0633  *  `           WalkState       - Current method state
0634  *
0635  * RETURN:      Status
0636  *
0637  * DESCRIPTION: Create a new field in the specified operation region
0638  *
0639  ******************************************************************************/
0640 
0641 ACPI_STATUS
0642 AcpiDsCreateField (
0643     ACPI_PARSE_OBJECT       *Op,
0644     ACPI_NAMESPACE_NODE     *RegionNode,
0645     ACPI_WALK_STATE         *WalkState)
0646 {
0647     ACPI_STATUS             Status;
0648     ACPI_PARSE_OBJECT       *Arg;
0649     ACPI_CREATE_FIELD_INFO  Info;
0650 
0651 
0652     ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
0653 
0654 
0655     /* First arg is the name of the parent OpRegion (must already exist) */
0656 
0657     Arg = Op->Common.Value.Arg;
0658 
0659     if (!RegionNode)
0660     {
0661         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
0662             ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
0663             ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
0664 #ifdef ACPI_ASL_COMPILER
0665         Status = AcpiDsCreateExternalRegion (Status, Arg,
0666             Arg->Common.Value.Name, WalkState, &RegionNode);
0667 #endif
0668         if (ACPI_FAILURE (Status))
0669         {
0670             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0671                 Arg->Common.Value.Name, Status);
0672             return_ACPI_STATUS (Status);
0673         }
0674     }
0675 
0676     memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
0677 
0678     /* Second arg is the field flags */
0679 
0680     Arg = Arg->Common.Next;
0681     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
0682     Info.Attribute = 0;
0683 
0684     /* Each remaining arg is a Named Field */
0685 
0686     Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
0687     Info.RegionNode = RegionNode;
0688 
0689     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
0690     if (ACPI_FAILURE (Status))
0691     {
0692         return_ACPI_STATUS (Status);
0693     }
0694 
0695     if (Info.RegionNode->Object->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM)
0696     {
0697         RegionNode->Object->Field.InternalPccBuffer =
0698             ACPI_ALLOCATE_ZEROED(Info.RegionNode->Object->Region.Length);
0699         if (!RegionNode->Object->Field.InternalPccBuffer)
0700         {
0701             return_ACPI_STATUS (AE_NO_MEMORY);
0702         }
0703     }
0704 
0705     return_ACPI_STATUS (Status);
0706 }
0707 
0708 
0709 /*******************************************************************************
0710  *
0711  * FUNCTION:    AcpiDsInitFieldObjects
0712  *
0713  * PARAMETERS:  Op              - Op containing the Field definition and args
0714  *  `           WalkState       - Current method state
0715  *
0716  * RETURN:      Status
0717  *
0718  * DESCRIPTION: For each "Field Unit" name in the argument list that is
0719  *              part of the field declaration, enter the name into the
0720  *              namespace.
0721  *
0722  ******************************************************************************/
0723 
0724 ACPI_STATUS
0725 AcpiDsInitFieldObjects (
0726     ACPI_PARSE_OBJECT       *Op,
0727     ACPI_WALK_STATE         *WalkState)
0728 {
0729     ACPI_STATUS             Status;
0730     ACPI_PARSE_OBJECT       *Arg = NULL;
0731     ACPI_NAMESPACE_NODE     *Node;
0732     UINT8                   Type = 0;
0733     UINT32                  Flags;
0734 
0735 
0736     ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
0737 
0738 
0739     /* Execute flag should always be set when this function is entered */
0740 
0741     if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
0742     {
0743         if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
0744         {
0745             /* BankField Op is deferred, just return OK */
0746 
0747             return_ACPI_STATUS (AE_OK);
0748         }
0749 
0750         ACPI_ERROR ((AE_INFO,
0751             "Parse deferred mode is not set"));
0752         return_ACPI_STATUS (AE_AML_INTERNAL);
0753     }
0754 
0755     /*
0756      * Get the FieldList argument for this opcode. This is the start of the
0757      * list of field elements.
0758      */
0759     switch (WalkState->Opcode)
0760     {
0761     case AML_FIELD_OP:
0762 
0763         Arg = AcpiPsGetArg (Op, 2);
0764         Type = ACPI_TYPE_LOCAL_REGION_FIELD;
0765         break;
0766 
0767     case AML_BANK_FIELD_OP:
0768 
0769         Arg = AcpiPsGetArg (Op, 4);
0770         Type = ACPI_TYPE_LOCAL_BANK_FIELD;
0771         break;
0772 
0773     case AML_INDEX_FIELD_OP:
0774 
0775         Arg = AcpiPsGetArg (Op, 3);
0776         Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
0777         break;
0778 
0779     default:
0780 
0781         return_ACPI_STATUS (AE_BAD_PARAMETER);
0782     }
0783 
0784     /* Creating new namespace node(s), should not already exist */
0785 
0786     Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
0787         ACPI_NS_ERROR_IF_FOUND;
0788 
0789     /*
0790      * Mark node(s) temporary if we are executing a normal control
0791      * method. (Don't mark if this is a module-level code method)
0792      */
0793     if (WalkState->MethodNode &&
0794         !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
0795     {
0796         Flags |= ACPI_NS_TEMPORARY;
0797     }
0798 
0799 #ifdef ACPI_EXEC_APP
0800     Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
0801 #endif
0802     /*
0803      * Walk the list of entries in the FieldList
0804      * Note: FieldList can be of zero length. In this case, Arg will be NULL.
0805      */
0806     while (Arg)
0807     {
0808         /*
0809          * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
0810          * in the field names in order to enter them into the namespace.
0811          */
0812         if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
0813         {
0814             Status = AcpiNsLookup (WalkState->ScopeInfo,
0815                 (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
0816                 Flags, WalkState, &Node);
0817             if (ACPI_FAILURE (Status))
0818             {
0819                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0820                     (char *) &Arg->Named.Name, Status);
0821                 if (Status != AE_ALREADY_EXISTS)
0822                 {
0823                     return_ACPI_STATUS (Status);
0824                 }
0825 
0826                 /* Name already exists, just ignore this error */
0827             }
0828 
0829             Arg->Common.Node = Node;
0830         }
0831 
0832         /* Get the next field element in the list */
0833 
0834         Arg = Arg->Common.Next;
0835     }
0836 
0837     return_ACPI_STATUS (AE_OK);
0838 }
0839 
0840 
0841 /*******************************************************************************
0842  *
0843  * FUNCTION:    AcpiDsCreateBankField
0844  *
0845  * PARAMETERS:  Op              - Op containing the Field definition and args
0846  *              RegionNode      - Object for the containing Operation Region
0847  *              WalkState       - Current method state
0848  *
0849  * RETURN:      Status
0850  *
0851  * DESCRIPTION: Create a new bank field in the specified operation region
0852  *
0853  ******************************************************************************/
0854 
0855 ACPI_STATUS
0856 AcpiDsCreateBankField (
0857     ACPI_PARSE_OBJECT       *Op,
0858     ACPI_NAMESPACE_NODE     *RegionNode,
0859     ACPI_WALK_STATE         *WalkState)
0860 {
0861     ACPI_STATUS             Status;
0862     ACPI_PARSE_OBJECT       *Arg;
0863     ACPI_CREATE_FIELD_INFO  Info;
0864 
0865 
0866     ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
0867 
0868 
0869     /* First arg is the name of the parent OpRegion (must already exist) */
0870 
0871     Arg = Op->Common.Value.Arg;
0872     if (!RegionNode)
0873     {
0874         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
0875             ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
0876             ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
0877 #ifdef ACPI_ASL_COMPILER
0878         Status = AcpiDsCreateExternalRegion (Status, Arg,
0879             Arg->Common.Value.Name, WalkState, &RegionNode);
0880 #endif
0881         if (ACPI_FAILURE (Status))
0882         {
0883             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0884                 Arg->Common.Value.Name, Status);
0885             return_ACPI_STATUS (Status);
0886         }
0887     }
0888 
0889     /* Second arg is the Bank Register (Field) (must already exist) */
0890 
0891     Arg = Arg->Common.Next;
0892     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
0893         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0894         ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
0895     if (ACPI_FAILURE (Status))
0896     {
0897         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0898             Arg->Common.Value.String, Status);
0899         return_ACPI_STATUS (Status);
0900     }
0901 
0902     /*
0903      * Third arg is the BankValue
0904      * This arg is a TermArg, not a constant
0905      * It will be evaluated later, by AcpiDsEvalBankFieldOperands
0906      */
0907     Arg = Arg->Common.Next;
0908 
0909     /* Fourth arg is the field flags */
0910 
0911     Arg = Arg->Common.Next;
0912     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
0913 
0914     /* Each remaining arg is a Named Field */
0915 
0916     Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
0917     Info.RegionNode = RegionNode;
0918 
0919     /*
0920      * Use Info.DataRegisterNode to store BankField Op
0921      * It's safe because DataRegisterNode will never be used when create
0922      * bank field \we store AmlStart and AmlLength in the BankField Op for
0923      * late evaluation. Used in AcpiExPrepFieldValue(Info)
0924      *
0925      * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
0926      * "void *ParentOp"?
0927      */
0928     Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
0929 
0930     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
0931     return_ACPI_STATUS (Status);
0932 }
0933 
0934 
0935 /*******************************************************************************
0936  *
0937  * FUNCTION:    AcpiDsCreateIndexField
0938  *
0939  * PARAMETERS:  Op              - Op containing the Field definition and args
0940  *              RegionNode      - Object for the containing Operation Region
0941  *  `           WalkState       - Current method state
0942  *
0943  * RETURN:      Status
0944  *
0945  * DESCRIPTION: Create a new index field in the specified operation region
0946  *
0947  ******************************************************************************/
0948 
0949 ACPI_STATUS
0950 AcpiDsCreateIndexField (
0951     ACPI_PARSE_OBJECT       *Op,
0952     ACPI_NAMESPACE_NODE     *RegionNode,
0953     ACPI_WALK_STATE         *WalkState)
0954 {
0955     ACPI_STATUS             Status;
0956     ACPI_PARSE_OBJECT       *Arg;
0957     ACPI_CREATE_FIELD_INFO  Info;
0958 
0959 
0960     ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
0961 
0962 
0963     /* First arg is the name of the Index register (must already exist) */
0964 
0965     Arg = Op->Common.Value.Arg;
0966     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
0967         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0968         ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
0969     if (ACPI_FAILURE (Status))
0970     {
0971         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0972             Arg->Common.Value.String, Status);
0973         return_ACPI_STATUS (Status);
0974     }
0975 
0976     /* Second arg is the data register (must already exist) */
0977 
0978     Arg = Arg->Common.Next;
0979     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
0980         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0981         ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
0982     if (ACPI_FAILURE (Status))
0983     {
0984         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
0985             Arg->Common.Value.String, Status);
0986         return_ACPI_STATUS (Status);
0987     }
0988 
0989     /* Next arg is the field flags */
0990 
0991     Arg = Arg->Common.Next;
0992     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
0993 
0994     /* Each remaining arg is a Named Field */
0995 
0996     Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
0997     Info.RegionNode = RegionNode;
0998 
0999     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
1000     return_ACPI_STATUS (Status);
1001 }