1 /******************************************************************************
2  *
3  * Module Name: dsfield - Dispatcher field routines
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "amlcode.h"
155 #include "acdispat.h"
156 #include "acinterp.h"
157 #include "acnamesp.h"
158 #include "acparser.h"
159 
160 #ifdef ACPI_EXEC_APP
161 #include "aecommon.h"
162 #endif
163 
164 
165 #define _COMPONENT          ACPI_DISPATCHER
166         ACPI_MODULE_NAME    ("dsfield")
167 
168 /* Local prototypes */
169 
170 #ifdef ACPI_ASL_COMPILER
171 #include "acdisasm.h"
172 
173 static ACPI_STATUS
174 AcpiDsCreateExternalRegion (
175     ACPI_STATUS             LookupStatus,
176     ACPI_PARSE_OBJECT       *Op,
177     char                    *Path,
178     ACPI_WALK_STATE         *WalkState,
179     ACPI_NAMESPACE_NODE     **Node);
180 #endif
181 
182 static ACPI_STATUS
183 AcpiDsGetFieldNames (
184     ACPI_CREATE_FIELD_INFO  *Info,
185     ACPI_WALK_STATE         *WalkState,
186     ACPI_PARSE_OBJECT       *Arg);
187 
188 
189 #ifdef ACPI_ASL_COMPILER
190 /*******************************************************************************
191  *
192  * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
193  *
194  * PARAMETERS:  LookupStatus    - Status from NsLookup operation
195  *              Op              - Op containing the Field definition and args
196  *              Path            - Pathname of the region
197  *  `           WalkState       - Current method state
198  *              Node            - Where the new region node is returned
199  *
200  * RETURN:      Status
201  *
202  * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
203  *              region node/object.
204  *
205  ******************************************************************************/
206 
207 static ACPI_STATUS
208 AcpiDsCreateExternalRegion (
209     ACPI_STATUS             LookupStatus,
210     ACPI_PARSE_OBJECT       *Op,
211     char                    *Path,
212     ACPI_WALK_STATE         *WalkState,
213     ACPI_NAMESPACE_NODE     **Node)
214 {
215     ACPI_STATUS             Status;
216     ACPI_OPERAND_OBJECT     *ObjDesc;
217 
218 
219     if (LookupStatus != AE_NOT_FOUND)
220     {
221         return (LookupStatus);
222     }
223 
224     /*
225      * Table disassembly:
226      * OperationRegion not found. Generate an External for it, and
227      * insert the name into the namespace.
228      */
229     AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
230 
231     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
232        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
233     if (ACPI_FAILURE (Status))
234     {
235         return (Status);
236     }
237 
238     /* Must create and install a region object for the new node */
239 
240     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
241     if (!ObjDesc)
242     {
243         return (AE_NO_MEMORY);
244     }
245 
246     ObjDesc->Region.Node = *Node;
247     Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
248     return (Status);
249 }
250 #endif
251 
252 
253 /*******************************************************************************
254  *
255  * FUNCTION:    AcpiDsCreateBufferField
256  *
257  * PARAMETERS:  Op                  - Current parse op (CreateXXField)
258  *              WalkState           - Current state
259  *
260  * RETURN:      Status
261  *
262  * DESCRIPTION: Execute the CreateField operators:
263  *              CreateBitFieldOp,
264  *              CreateByteFieldOp,
265  *              CreateWordFieldOp,
266  *              CreateDwordFieldOp,
267  *              CreateQwordFieldOp,
268  *              CreateFieldOp       (all of which define a field in a buffer)
269  *
270  ******************************************************************************/
271 
272 ACPI_STATUS
273 AcpiDsCreateBufferField (
274     ACPI_PARSE_OBJECT       *Op,
275     ACPI_WALK_STATE         *WalkState)
276 {
277     ACPI_PARSE_OBJECT       *Arg;
278     ACPI_NAMESPACE_NODE     *Node;
279     ACPI_STATUS             Status;
280     ACPI_OPERAND_OBJECT     *ObjDesc;
281     ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
282     UINT32                  Flags;
283 
284 
285     ACPI_FUNCTION_TRACE (DsCreateBufferField);
286 
287 
288     /*
289      * Get the NameString argument (name of the new BufferField)
290      */
291     if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
292     {
293         /* For CreateField, name is the 4th argument */
294 
295         Arg = AcpiPsGetArg (Op, 3);
296     }
297     else
298     {
299         /* For all other CreateXXXField operators, name is the 3rd argument */
300 
301         Arg = AcpiPsGetArg (Op, 2);
302     }
303 
304     if (!Arg)
305     {
306         return_ACPI_STATUS (AE_AML_NO_OPERAND);
307     }
308 
309     if (WalkState->DeferredNode)
310     {
311         Node = WalkState->DeferredNode;
312     }
313     else
314     {
315         /* Execute flag should always be set when this function is entered */
316 
317         if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
318         {
319             ACPI_ERROR ((AE_INFO,
320                 "Parse execute mode is not set"));
321             return_ACPI_STATUS (AE_AML_INTERNAL);
322         }
323 
324         /* Creating new namespace node, should not already exist */
325 
326         Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
327             ACPI_NS_ERROR_IF_FOUND;
328 
329         /*
330          * Mark node temporary if we are executing a normal control
331          * method. (Don't mark if this is a module-level code method)
332          */
333         if (WalkState->MethodNode &&
334             !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
335         {
336             Flags |= ACPI_NS_TEMPORARY;
337         }
338 
339         /* Enter the NameString into the namespace */
340 
341         Status = AcpiNsLookup (WalkState->ScopeInfo,
342             Arg->Common.Value.String, ACPI_TYPE_ANY,
343             ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
344         if (ACPI_FAILURE (Status))
345         {
346             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
347                 Arg->Common.Value.String, Status);
348             return_ACPI_STATUS (Status);
349         }
350     }
351 
352     /*
353      * We could put the returned object (Node) on the object stack for later,
354      * but for now, we will put it in the "op" object that the parser uses,
355      * so we can get it again at the end of this scope.
356      */
357     Op->Common.Node = Node;
358 
359     /*
360      * If there is no object attached to the node, this node was just created
361      * and we need to create the field object. Otherwise, this was a lookup
362      * of an existing node and we don't want to create the field object again.
363      */
364     ObjDesc = AcpiNsGetAttachedObject (Node);
365     if (ObjDesc)
366     {
367         return_ACPI_STATUS (AE_OK);
368     }
369 
370     /*
371      * The Field definition is not fully parsed at this time.
372      * (We must save the address of the AML for the buffer and index operands)
373      */
374 
375     /* Create the buffer field object */
376 
377     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
378     if (!ObjDesc)
379     {
380         Status = AE_NO_MEMORY;
381         goto Cleanup;
382     }
383 
384     /*
385      * Remember location in AML stream of the field unit opcode and operands
386      * -- since the buffer and index operands must be evaluated.
387      */
388     SecondDesc = ObjDesc->Common.NextObject;
389     SecondDesc->Extra.AmlStart = Op->Named.Data;
390     SecondDesc->Extra.AmlLength = Op->Named.Length;
391     ObjDesc->BufferField.Node = Node;
392 
393     /* Attach constructed field descriptors to parent node */
394 
395     Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
396     if (ACPI_FAILURE (Status))
397     {
398         goto Cleanup;
399     }
400 
401 
402 Cleanup:
403 
404     /* Remove local reference to the object */
405 
406     AcpiUtRemoveReference (ObjDesc);
407     return_ACPI_STATUS (Status);
408 }
409 
410 
411 /*******************************************************************************
412  *
413  * FUNCTION:    AcpiDsGetFieldNames
414  *
415  * PARAMETERS:  Info            - CreateField info structure
416  *              WalkState       - Current method state
417  *              Arg             - First parser arg for the field name list
418  *
419  * RETURN:      Status
420  *
421  * DESCRIPTION: Process all named fields in a field declaration. Names are
422  *              entered into the namespace.
423  *
424  ******************************************************************************/
425 
426 static ACPI_STATUS
427 AcpiDsGetFieldNames (
428     ACPI_CREATE_FIELD_INFO  *Info,
429     ACPI_WALK_STATE         *WalkState,
430     ACPI_PARSE_OBJECT       *Arg)
431 {
432     ACPI_STATUS             Status;
433     UINT64                  Position;
434     ACPI_PARSE_OBJECT       *Child;
435 
436 #ifdef ACPI_EXEC_APP
437     ACPI_OPERAND_OBJECT     *ResultDesc;
438     ACPI_OPERAND_OBJECT     *ObjDesc;
439     char                    *NamePath;
440 #endif
441 
442 
443     ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
444 
445 
446     /* First field starts at bit zero */
447 
448     Info->FieldBitPosition = 0;
449 
450     /* Process all elements in the field list (of parse nodes) */
451 
452     while (Arg)
453     {
454         /*
455          * Four types of field elements are handled:
456          * 1) Name - Enters a new named field into the namespace
457          * 2) Offset - specifies a bit offset
458          * 3) AccessAs - changes the access mode/attributes
459          * 4) Connection - Associate a resource template with the field
460          */
461         switch (Arg->Common.AmlOpcode)
462         {
463         case AML_INT_RESERVEDFIELD_OP:
464 
465             Position = (UINT64) Info->FieldBitPosition +
466                 (UINT64) Arg->Common.Value.Size;
467 
468             if (Position > ACPI_UINT32_MAX)
469             {
470                 ACPI_ERROR ((AE_INFO,
471                     "Bit offset within field too large (> 0xFFFFFFFF)"));
472                 return_ACPI_STATUS (AE_SUPPORT);
473             }
474 
475             Info->FieldBitPosition = (UINT32) Position;
476             break;
477 
478         case AML_INT_ACCESSFIELD_OP:
479         case AML_INT_EXTACCESSFIELD_OP:
480             /*
481              * Get new AccessType, AccessAttribute, and AccessLength fields
482              * -- to be used for all field units that follow, until the
483              * end-of-field or another AccessAs keyword is encountered.
484              * NOTE. These three bytes are encoded in the integer value
485              * of the parseop for convenience.
486              *
487              * In FieldFlags, preserve the flag bits other than the
488              * ACCESS_TYPE bits.
489              */
490 
491             /* AccessType (ByteAcc, WordAcc, etc.) */
492 
493             Info->FieldFlags = (UINT8)
494                 ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
495                 ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
496 
497             /* AccessAttribute (AttribQuick, AttribByte, etc.) */
498 
499             Info->Attribute = (UINT8)
500                 ((Arg->Common.Value.Integer >> 8) & 0xFF);
501 
502             /* AccessLength (for serial/buffer protocols) */
503 
504             Info->AccessLength = (UINT8)
505                 ((Arg->Common.Value.Integer >> 16) & 0xFF);
506             break;
507 
508         case AML_INT_CONNECTION_OP:
509             /*
510              * Clear any previous connection. New connection is used for all
511              * fields that follow, similar to AccessAs
512              */
513             Info->ResourceBuffer = NULL;
514             Info->ConnectionNode = NULL;
515             Info->PinNumberIndex = 0;
516 
517             /*
518              * A Connection() is either an actual resource descriptor (buffer)
519              * or a named reference to a resource template
520              */
521             Child = Arg->Common.Value.Arg;
522             if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
523             {
524                 Info->ResourceBuffer = Child->Named.Data;
525                 Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
526             }
527             else
528             {
529                 /* Lookup the Connection() namepath, it should already exist */
530 
531                 Status = AcpiNsLookup (WalkState->ScopeInfo,
532                     Child->Common.Value.Name, ACPI_TYPE_ANY,
533                     ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
534                     WalkState, &Info->ConnectionNode);
535                 if (ACPI_FAILURE (Status))
536                 {
537                     ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
538                         Child->Common.Value.Name, Status);
539                     return_ACPI_STATUS (Status);
540                 }
541             }
542             break;
543 
544         case AML_INT_NAMEDFIELD_OP:
545 
546             /* Lookup the name, it should already exist */
547 
548             Status = AcpiNsLookup (WalkState->ScopeInfo,
549                 (char *) &Arg->Named.Name, Info->FieldType,
550                 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
551                 WalkState, &Info->FieldNode);
552             if (ACPI_FAILURE (Status))
553             {
554                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
555                     (char *) &Arg->Named.Name, Status);
556                 return_ACPI_STATUS (Status);
557             }
558             else
559             {
560                 Arg->Common.Node = Info->FieldNode;
561                 Info->FieldBitLength = Arg->Common.Value.Size;
562 
563                 /*
564                  * If there is no object attached to the node, this node was
565                  * just created and we need to create the field object.
566                  * Otherwise, this was a lookup of an existing node and we
567                  * don't want to create the field object again.
568                  */
569                 if (!AcpiNsGetAttachedObject (Info->FieldNode))
570                 {
571                     Status = AcpiExPrepFieldValue (Info);
572                     if (ACPI_FAILURE (Status))
573                     {
574                         return_ACPI_STATUS (Status);
575                     }
576 #ifdef ACPI_EXEC_APP
577                     NamePath = AcpiNsGetExternalPathname (Info->FieldNode);
578                     if (ACPI_SUCCESS (AeLookupInitFileEntry (NamePath, &ObjDesc)))
579                     {
580                         AcpiExWriteDataToField (ObjDesc,
581                             AcpiNsGetAttachedObject (Info->FieldNode),
582                             &ResultDesc);
583                         AcpiUtRemoveReference (ObjDesc);
584                     }
585                     ACPI_FREE (NamePath);
586 #endif
587                 }
588             }
589 
590             /* Keep track of bit position for the next field */
591 
592             Position = (UINT64) Info->FieldBitPosition +
593                 (UINT64) Arg->Common.Value.Size;
594 
595             if (Position > ACPI_UINT32_MAX)
596             {
597                 ACPI_ERROR ((AE_INFO,
598                     "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
599                     ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
600                 return_ACPI_STATUS (AE_SUPPORT);
601             }
602 
603             Info->FieldBitPosition += Info->FieldBitLength;
604             Info->PinNumberIndex++; /* Index relative to previous Connection() */
605             break;
606 
607         default:
608 
609             ACPI_ERROR ((AE_INFO,
610                 "Invalid opcode in field list: 0x%X",
611                 Arg->Common.AmlOpcode));
612             return_ACPI_STATUS (AE_AML_BAD_OPCODE);
613         }
614 
615         Arg = Arg->Common.Next;
616     }
617 
618     return_ACPI_STATUS (AE_OK);
619 }
620 
621 
622 /*******************************************************************************
623  *
624  * FUNCTION:    AcpiDsCreateField
625  *
626  * PARAMETERS:  Op              - Op containing the Field definition and args
627  *              RegionNode      - Object for the containing Operation Region
628  *  `           WalkState       - Current method state
629  *
630  * RETURN:      Status
631  *
632  * DESCRIPTION: Create a new field in the specified operation region
633  *
634  ******************************************************************************/
635 
636 ACPI_STATUS
637 AcpiDsCreateField (
638     ACPI_PARSE_OBJECT       *Op,
639     ACPI_NAMESPACE_NODE     *RegionNode,
640     ACPI_WALK_STATE         *WalkState)
641 {
642     ACPI_STATUS             Status;
643     ACPI_PARSE_OBJECT       *Arg;
644     ACPI_CREATE_FIELD_INFO  Info;
645 
646 
647     ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
648 
649 
650     /* First arg is the name of the parent OpRegion (must already exist) */
651 
652     Arg = Op->Common.Value.Arg;
653 
654     if (!RegionNode)
655     {
656         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
657             ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
658             ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
659 #ifdef ACPI_ASL_COMPILER
660         Status = AcpiDsCreateExternalRegion (Status, Arg,
661             Arg->Common.Value.Name, WalkState, &RegionNode);
662 #endif
663         if (ACPI_FAILURE (Status))
664         {
665             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
666                 Arg->Common.Value.Name, Status);
667             return_ACPI_STATUS (Status);
668         }
669     }
670 
671     memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
672 
673     /* Second arg is the field flags */
674 
675     Arg = Arg->Common.Next;
676     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
677     Info.Attribute = 0;
678 
679     /* Each remaining arg is a Named Field */
680 
681     Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
682     Info.RegionNode = RegionNode;
683 
684     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
685     if (Info.RegionNode->Object->Region.SpaceId == ACPI_ADR_SPACE_PLATFORM_COMM &&
686         !(RegionNode->Object->Field.InternalPccBuffer
687         = ACPI_ALLOCATE_ZEROED(Info.RegionNode->Object->Region.Length)))
688     {
689         return_ACPI_STATUS (AE_NO_MEMORY);
690     }
691     return_ACPI_STATUS (Status);
692 }
693 
694 
695 /*******************************************************************************
696  *
697  * FUNCTION:    AcpiDsInitFieldObjects
698  *
699  * PARAMETERS:  Op              - Op containing the Field definition and args
700  *  `           WalkState       - Current method state
701  *
702  * RETURN:      Status
703  *
704  * DESCRIPTION: For each "Field Unit" name in the argument list that is
705  *              part of the field declaration, enter the name into the
706  *              namespace.
707  *
708  ******************************************************************************/
709 
710 ACPI_STATUS
711 AcpiDsInitFieldObjects (
712     ACPI_PARSE_OBJECT       *Op,
713     ACPI_WALK_STATE         *WalkState)
714 {
715     ACPI_STATUS             Status;
716     ACPI_PARSE_OBJECT       *Arg = NULL;
717     ACPI_NAMESPACE_NODE     *Node;
718     UINT8                   Type = 0;
719     UINT32                  Flags;
720 
721 
722     ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
723 
724 
725     /* Execute flag should always be set when this function is entered */
726 
727     if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
728     {
729         if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
730         {
731             /* BankField Op is deferred, just return OK */
732 
733             return_ACPI_STATUS (AE_OK);
734         }
735 
736         ACPI_ERROR ((AE_INFO,
737             "Parse deferred mode is not set"));
738         return_ACPI_STATUS (AE_AML_INTERNAL);
739     }
740 
741     /*
742      * Get the FieldList argument for this opcode. This is the start of the
743      * list of field elements.
744      */
745     switch (WalkState->Opcode)
746     {
747     case AML_FIELD_OP:
748 
749         Arg = AcpiPsGetArg (Op, 2);
750         Type = ACPI_TYPE_LOCAL_REGION_FIELD;
751         break;
752 
753     case AML_BANK_FIELD_OP:
754 
755         Arg = AcpiPsGetArg (Op, 4);
756         Type = ACPI_TYPE_LOCAL_BANK_FIELD;
757         break;
758 
759     case AML_INDEX_FIELD_OP:
760 
761         Arg = AcpiPsGetArg (Op, 3);
762         Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
763         break;
764 
765     default:
766 
767         return_ACPI_STATUS (AE_BAD_PARAMETER);
768     }
769 
770     /* Creating new namespace node(s), should not already exist */
771 
772     Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
773         ACPI_NS_ERROR_IF_FOUND;
774 
775     /*
776      * Mark node(s) temporary if we are executing a normal control
777      * method. (Don't mark if this is a module-level code method)
778      */
779     if (WalkState->MethodNode &&
780         !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
781     {
782         Flags |= ACPI_NS_TEMPORARY;
783     }
784 
785 #ifdef ACPI_EXEC_APP
786         Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
787 #endif
788     /*
789      * Walk the list of entries in the FieldList
790      * Note: FieldList can be of zero length. In this case, Arg will be NULL.
791      */
792     while (Arg)
793     {
794         /*
795          * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
796          * in the field names in order to enter them into the namespace.
797          */
798         if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
799         {
800             Status = AcpiNsLookup (WalkState->ScopeInfo,
801                 (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
802                 Flags, WalkState, &Node);
803             if (ACPI_FAILURE (Status))
804             {
805                 ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
806                     (char *) &Arg->Named.Name, Status);
807                 if (Status != AE_ALREADY_EXISTS)
808                 {
809                     return_ACPI_STATUS (Status);
810                 }
811 
812                 /* Name already exists, just ignore this error */
813             }
814 
815             Arg->Common.Node = Node;
816         }
817 
818         /* Get the next field element in the list */
819 
820         Arg = Arg->Common.Next;
821     }
822 
823     return_ACPI_STATUS (AE_OK);
824 }
825 
826 
827 /*******************************************************************************
828  *
829  * FUNCTION:    AcpiDsCreateBankField
830  *
831  * PARAMETERS:  Op              - Op containing the Field definition and args
832  *              RegionNode      - Object for the containing Operation Region
833  *              WalkState       - Current method state
834  *
835  * RETURN:      Status
836  *
837  * DESCRIPTION: Create a new bank field in the specified operation region
838  *
839  ******************************************************************************/
840 
841 ACPI_STATUS
842 AcpiDsCreateBankField (
843     ACPI_PARSE_OBJECT       *Op,
844     ACPI_NAMESPACE_NODE     *RegionNode,
845     ACPI_WALK_STATE         *WalkState)
846 {
847     ACPI_STATUS             Status;
848     ACPI_PARSE_OBJECT       *Arg;
849     ACPI_CREATE_FIELD_INFO  Info;
850 
851 
852     ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
853 
854 
855     /* First arg is the name of the parent OpRegion (must already exist) */
856 
857     Arg = Op->Common.Value.Arg;
858     if (!RegionNode)
859     {
860         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
861             ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
862             ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
863 #ifdef ACPI_ASL_COMPILER
864         Status = AcpiDsCreateExternalRegion (Status, Arg,
865             Arg->Common.Value.Name, WalkState, &RegionNode);
866 #endif
867         if (ACPI_FAILURE (Status))
868         {
869             ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
870                 Arg->Common.Value.Name, Status);
871             return_ACPI_STATUS (Status);
872         }
873     }
874 
875     /* Second arg is the Bank Register (Field) (must already exist) */
876 
877     Arg = Arg->Common.Next;
878     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
879         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
880         ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
881     if (ACPI_FAILURE (Status))
882     {
883         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
884             Arg->Common.Value.String, Status);
885         return_ACPI_STATUS (Status);
886     }
887 
888     /*
889      * Third arg is the BankValue
890      * This arg is a TermArg, not a constant
891      * It will be evaluated later, by AcpiDsEvalBankFieldOperands
892      */
893     Arg = Arg->Common.Next;
894 
895     /* Fourth arg is the field flags */
896 
897     Arg = Arg->Common.Next;
898     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
899 
900     /* Each remaining arg is a Named Field */
901 
902     Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
903     Info.RegionNode = RegionNode;
904 
905     /*
906      * Use Info.DataRegisterNode to store BankField Op
907      * It's safe because DataRegisterNode will never be used when create
908      * bank field \we store AmlStart and AmlLength in the BankField Op for
909      * late evaluation. Used in AcpiExPrepFieldValue(Info)
910      *
911      * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
912      * "void *ParentOp"?
913      */
914     Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
915 
916     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
917     return_ACPI_STATUS (Status);
918 }
919 
920 
921 /*******************************************************************************
922  *
923  * FUNCTION:    AcpiDsCreateIndexField
924  *
925  * PARAMETERS:  Op              - Op containing the Field definition and args
926  *              RegionNode      - Object for the containing Operation Region
927  *  `           WalkState       - Current method state
928  *
929  * RETURN:      Status
930  *
931  * DESCRIPTION: Create a new index field in the specified operation region
932  *
933  ******************************************************************************/
934 
935 ACPI_STATUS
936 AcpiDsCreateIndexField (
937     ACPI_PARSE_OBJECT       *Op,
938     ACPI_NAMESPACE_NODE     *RegionNode,
939     ACPI_WALK_STATE         *WalkState)
940 {
941     ACPI_STATUS             Status;
942     ACPI_PARSE_OBJECT       *Arg;
943     ACPI_CREATE_FIELD_INFO  Info;
944 
945 
946     ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
947 
948 
949     /* First arg is the name of the Index register (must already exist) */
950 
951     Arg = Op->Common.Value.Arg;
952     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
953         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
954         ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
955     if (ACPI_FAILURE (Status))
956     {
957         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
958             Arg->Common.Value.String, Status);
959         return_ACPI_STATUS (Status);
960     }
961 
962     /* Second arg is the data register (must already exist) */
963 
964     Arg = Arg->Common.Next;
965     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
966         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
967         ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
968     if (ACPI_FAILURE (Status))
969     {
970         ACPI_ERROR_NAMESPACE (WalkState->ScopeInfo,
971             Arg->Common.Value.String, Status);
972         return_ACPI_STATUS (Status);
973     }
974 
975     /* Next arg is the field flags */
976 
977     Arg = Arg->Common.Next;
978     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
979 
980     /* Each remaining arg is a Named Field */
981 
982     Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
983     Info.RegionNode = RegionNode;
984 
985     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
986     return_ACPI_STATUS (Status);
987 }
988