xref: /freebsd/sys/contrib/dev/acpica/components/dispatcher/dsfield.c (revision ca86bcf2531c7b149c95244a67853d44323e7855)
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 - 2017, 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 <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/amlcode.h>
155 #include <contrib/dev/acpica/include/acdispat.h>
156 #include <contrib/dev/acpica/include/acinterp.h>
157 #include <contrib/dev/acpica/include/acnamesp.h>
158 #include <contrib/dev/acpica/include/acparser.h>
159 
160 
161 #define _COMPONENT          ACPI_DISPATCHER
162         ACPI_MODULE_NAME    ("dsfield")
163 
164 /* Local prototypes */
165 
166 #ifdef ACPI_ASL_COMPILER
167 #include <contrib/dev/acpica/include/acdisasm.h>
168 
169 static ACPI_STATUS
170 AcpiDsCreateExternalRegion (
171     ACPI_STATUS             LookupStatus,
172     ACPI_PARSE_OBJECT       *Op,
173     char                    *Path,
174     ACPI_WALK_STATE         *WalkState,
175     ACPI_NAMESPACE_NODE     **Node);
176 #endif
177 
178 static ACPI_STATUS
179 AcpiDsGetFieldNames (
180     ACPI_CREATE_FIELD_INFO  *Info,
181     ACPI_WALK_STATE         *WalkState,
182     ACPI_PARSE_OBJECT       *Arg);
183 
184 
185 #ifdef ACPI_ASL_COMPILER
186 /*******************************************************************************
187  *
188  * FUNCTION:    AcpiDsCreateExternalRegion (iASL Disassembler only)
189  *
190  * PARAMETERS:  LookupStatus    - Status from NsLookup operation
191  *              Op              - Op containing the Field definition and args
192  *              Path            - Pathname of the region
193  *  `           WalkState       - Current method state
194  *              Node            - Where the new region node is returned
195  *
196  * RETURN:      Status
197  *
198  * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
199  *              region node/object.
200  *
201  ******************************************************************************/
202 
203 static ACPI_STATUS
204 AcpiDsCreateExternalRegion (
205     ACPI_STATUS             LookupStatus,
206     ACPI_PARSE_OBJECT       *Op,
207     char                    *Path,
208     ACPI_WALK_STATE         *WalkState,
209     ACPI_NAMESPACE_NODE     **Node)
210 {
211     ACPI_STATUS             Status;
212     ACPI_OPERAND_OBJECT     *ObjDesc;
213 
214 
215     if (LookupStatus != AE_NOT_FOUND)
216     {
217         return (LookupStatus);
218     }
219 
220     /*
221      * Table disassembly:
222      * OperationRegion not found. Generate an External for it, and
223      * insert the name into the namespace.
224      */
225     AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
226 
227     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
228        ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
229     if (ACPI_FAILURE (Status))
230     {
231         return (Status);
232     }
233 
234     /* Must create and install a region object for the new node */
235 
236     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
237     if (!ObjDesc)
238     {
239         return (AE_NO_MEMORY);
240     }
241 
242     ObjDesc->Region.Node = *Node;
243     Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
244     return (Status);
245 }
246 #endif
247 
248 
249 /*******************************************************************************
250  *
251  * FUNCTION:    AcpiDsCreateBufferField
252  *
253  * PARAMETERS:  Op                  - Current parse op (CreateXXField)
254  *              WalkState           - Current state
255  *
256  * RETURN:      Status
257  *
258  * DESCRIPTION: Execute the CreateField operators:
259  *              CreateBitFieldOp,
260  *              CreateByteFieldOp,
261  *              CreateWordFieldOp,
262  *              CreateDwordFieldOp,
263  *              CreateQwordFieldOp,
264  *              CreateFieldOp       (all of which define a field in a buffer)
265  *
266  ******************************************************************************/
267 
268 ACPI_STATUS
269 AcpiDsCreateBufferField (
270     ACPI_PARSE_OBJECT       *Op,
271     ACPI_WALK_STATE         *WalkState)
272 {
273     ACPI_PARSE_OBJECT       *Arg;
274     ACPI_NAMESPACE_NODE     *Node;
275     ACPI_STATUS             Status;
276     ACPI_OPERAND_OBJECT     *ObjDesc;
277     ACPI_OPERAND_OBJECT     *SecondDesc = NULL;
278     UINT32                  Flags;
279 
280 
281     ACPI_FUNCTION_TRACE (DsCreateBufferField);
282 
283 
284     /*
285      * Get the NameString argument (name of the new BufferField)
286      */
287     if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
288     {
289         /* For CreateField, name is the 4th argument */
290 
291         Arg = AcpiPsGetArg (Op, 3);
292     }
293     else
294     {
295         /* For all other CreateXXXField operators, name is the 3rd argument */
296 
297         Arg = AcpiPsGetArg (Op, 2);
298     }
299 
300     if (!Arg)
301     {
302         return_ACPI_STATUS (AE_AML_NO_OPERAND);
303     }
304 
305     if (WalkState->DeferredNode)
306     {
307         Node = WalkState->DeferredNode;
308         Status = AE_OK;
309     }
310     else
311     {
312         /* Execute flag should always be set when this function is entered */
313 
314         if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
315         {
316             return_ACPI_STATUS (AE_AML_INTERNAL);
317         }
318 
319         /* Creating new namespace node, should not already exist */
320 
321         Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
322             ACPI_NS_ERROR_IF_FOUND;
323 
324         /*
325          * Mark node temporary if we are executing a normal control
326          * method. (Don't mark if this is a module-level code method)
327          */
328         if (WalkState->MethodNode &&
329             !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
330         {
331             Flags |= ACPI_NS_TEMPORARY;
332         }
333 
334         /* Enter the NameString into the namespace */
335 
336         Status = AcpiNsLookup (WalkState->ScopeInfo,
337             Arg->Common.Value.String, ACPI_TYPE_ANY,
338             ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
339         if (ACPI_FAILURE (Status))
340         {
341             ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
342             return_ACPI_STATUS (Status);
343         }
344     }
345 
346     /*
347      * We could put the returned object (Node) on the object stack for later,
348      * but for now, we will put it in the "op" object that the parser uses,
349      * so we can get it again at the end of this scope.
350      */
351     Op->Common.Node = Node;
352 
353     /*
354      * If there is no object attached to the node, this node was just created
355      * and we need to create the field object. Otherwise, this was a lookup
356      * of an existing node and we don't want to create the field object again.
357      */
358     ObjDesc = AcpiNsGetAttachedObject (Node);
359     if (ObjDesc)
360     {
361         return_ACPI_STATUS (AE_OK);
362     }
363 
364     /*
365      * The Field definition is not fully parsed at this time.
366      * (We must save the address of the AML for the buffer and index operands)
367      */
368 
369     /* Create the buffer field object */
370 
371     ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
372     if (!ObjDesc)
373     {
374         Status = AE_NO_MEMORY;
375         goto Cleanup;
376     }
377 
378     /*
379      * Remember location in AML stream of the field unit opcode and operands
380      * -- since the buffer and index operands must be evaluated.
381      */
382     SecondDesc = ObjDesc->Common.NextObject;
383     SecondDesc->Extra.AmlStart = Op->Named.Data;
384     SecondDesc->Extra.AmlLength = Op->Named.Length;
385     ObjDesc->BufferField.Node = Node;
386 
387     /* Attach constructed field descriptors to parent node */
388 
389     Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
390     if (ACPI_FAILURE (Status))
391     {
392         goto Cleanup;
393     }
394 
395 
396 Cleanup:
397 
398     /* Remove local reference to the object */
399 
400     AcpiUtRemoveReference (ObjDesc);
401     return_ACPI_STATUS (Status);
402 }
403 
404 
405 /*******************************************************************************
406  *
407  * FUNCTION:    AcpiDsGetFieldNames
408  *
409  * PARAMETERS:  Info            - CreateField info structure
410  *  `           WalkState       - Current method state
411  *              Arg             - First parser arg for the field name list
412  *
413  * RETURN:      Status
414  *
415  * DESCRIPTION: Process all named fields in a field declaration. Names are
416  *              entered into the namespace.
417  *
418  ******************************************************************************/
419 
420 static ACPI_STATUS
421 AcpiDsGetFieldNames (
422     ACPI_CREATE_FIELD_INFO  *Info,
423     ACPI_WALK_STATE         *WalkState,
424     ACPI_PARSE_OBJECT       *Arg)
425 {
426     ACPI_STATUS             Status;
427     UINT64                  Position;
428     ACPI_PARSE_OBJECT       *Child;
429 
430 
431     ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
432 
433 
434     /* First field starts at bit zero */
435 
436     Info->FieldBitPosition = 0;
437 
438     /* Process all elements in the field list (of parse nodes) */
439 
440     while (Arg)
441     {
442         /*
443          * Four types of field elements are handled:
444          * 1) Name - Enters a new named field into the namespace
445          * 2) Offset - specifies a bit offset
446          * 3) AccessAs - changes the access mode/attributes
447          * 4) Connection - Associate a resource template with the field
448          */
449         switch (Arg->Common.AmlOpcode)
450         {
451         case AML_INT_RESERVEDFIELD_OP:
452 
453             Position = (UINT64) Info->FieldBitPosition +
454                 (UINT64) Arg->Common.Value.Size;
455 
456             if (Position > ACPI_UINT32_MAX)
457             {
458                 ACPI_ERROR ((AE_INFO,
459                     "Bit offset within field too large (> 0xFFFFFFFF)"));
460                 return_ACPI_STATUS (AE_SUPPORT);
461             }
462 
463             Info->FieldBitPosition = (UINT32) Position;
464             break;
465 
466         case AML_INT_ACCESSFIELD_OP:
467         case AML_INT_EXTACCESSFIELD_OP:
468             /*
469              * Get new AccessType, AccessAttribute, and AccessLength fields
470              * -- to be used for all field units that follow, until the
471              * end-of-field or another AccessAs keyword is encountered.
472              * NOTE. These three bytes are encoded in the integer value
473              * of the parseop for convenience.
474              *
475              * In FieldFlags, preserve the flag bits other than the
476              * ACCESS_TYPE bits.
477              */
478 
479             /* AccessType (ByteAcc, WordAcc, etc.) */
480 
481             Info->FieldFlags = (UINT8)
482                 ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
483                 ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
484 
485             /* AccessAttribute (AttribQuick, AttribByte, etc.) */
486 
487             Info->Attribute = (UINT8)
488                 ((Arg->Common.Value.Integer >> 8) & 0xFF);
489 
490             /* AccessLength (for serial/buffer protocols) */
491 
492             Info->AccessLength = (UINT8)
493                 ((Arg->Common.Value.Integer >> 16) & 0xFF);
494             break;
495 
496         case AML_INT_CONNECTION_OP:
497             /*
498              * Clear any previous connection. New connection is used for all
499              * fields that follow, similar to AccessAs
500              */
501             Info->ResourceBuffer = NULL;
502             Info->ConnectionNode = NULL;
503             Info->PinNumberIndex = 0;
504 
505             /*
506              * A Connection() is either an actual resource descriptor (buffer)
507              * or a named reference to a resource template
508              */
509             Child = Arg->Common.Value.Arg;
510             if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
511             {
512                 Info->ResourceBuffer = Child->Named.Data;
513                 Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
514             }
515             else
516             {
517                 /* Lookup the Connection() namepath, it should already exist */
518 
519                 Status = AcpiNsLookup (WalkState->ScopeInfo,
520                     Child->Common.Value.Name, ACPI_TYPE_ANY,
521                     ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
522                     WalkState, &Info->ConnectionNode);
523                 if (ACPI_FAILURE (Status))
524                 {
525                     ACPI_ERROR_NAMESPACE (Child->Common.Value.Name, Status);
526                     return_ACPI_STATUS (Status);
527                 }
528             }
529             break;
530 
531         case AML_INT_NAMEDFIELD_OP:
532 
533             /* Lookup the name, it should already exist */
534 
535             Status = AcpiNsLookup (WalkState->ScopeInfo,
536                 (char *) &Arg->Named.Name, Info->FieldType,
537                 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
538                 WalkState, &Info->FieldNode);
539             if (ACPI_FAILURE (Status))
540             {
541                 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
542                 return_ACPI_STATUS (Status);
543             }
544             else
545             {
546                 Arg->Common.Node = Info->FieldNode;
547                 Info->FieldBitLength = Arg->Common.Value.Size;
548 
549                 /*
550                  * If there is no object attached to the node, this node was
551                  * just created and we need to create the field object.
552                  * Otherwise, this was a lookup of an existing node and we
553                  * don't want to create the field object again.
554                  */
555                 if (!AcpiNsGetAttachedObject (Info->FieldNode))
556                 {
557                     Status = AcpiExPrepFieldValue (Info);
558                     if (ACPI_FAILURE (Status))
559                     {
560                         return_ACPI_STATUS (Status);
561                     }
562                 }
563             }
564 
565             /* Keep track of bit position for the next field */
566 
567             Position = (UINT64) Info->FieldBitPosition +
568                 (UINT64) Arg->Common.Value.Size;
569 
570             if (Position > ACPI_UINT32_MAX)
571             {
572                 ACPI_ERROR ((AE_INFO,
573                     "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
574                     ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
575                 return_ACPI_STATUS (AE_SUPPORT);
576             }
577 
578             Info->FieldBitPosition += Info->FieldBitLength;
579             Info->PinNumberIndex++; /* Index relative to previous Connection() */
580             break;
581 
582         default:
583 
584             ACPI_ERROR ((AE_INFO,
585                 "Invalid opcode in field list: 0x%X",
586                 Arg->Common.AmlOpcode));
587             return_ACPI_STATUS (AE_AML_BAD_OPCODE);
588         }
589 
590         Arg = Arg->Common.Next;
591     }
592 
593     return_ACPI_STATUS (AE_OK);
594 }
595 
596 
597 /*******************************************************************************
598  *
599  * FUNCTION:    AcpiDsCreateField
600  *
601  * PARAMETERS:  Op              - Op containing the Field definition and args
602  *              RegionNode      - Object for the containing Operation Region
603  *  `           WalkState       - Current method state
604  *
605  * RETURN:      Status
606  *
607  * DESCRIPTION: Create a new field in the specified operation region
608  *
609  ******************************************************************************/
610 
611 ACPI_STATUS
612 AcpiDsCreateField (
613     ACPI_PARSE_OBJECT       *Op,
614     ACPI_NAMESPACE_NODE     *RegionNode,
615     ACPI_WALK_STATE         *WalkState)
616 {
617     ACPI_STATUS             Status;
618     ACPI_PARSE_OBJECT       *Arg;
619     ACPI_CREATE_FIELD_INFO  Info;
620 
621 
622     ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
623 
624 
625     /* First arg is the name of the parent OpRegion (must already exist) */
626 
627     Arg = Op->Common.Value.Arg;
628 
629     if (!RegionNode)
630     {
631         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
632             ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
633             ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
634 #ifdef ACPI_ASL_COMPILER
635         Status = AcpiDsCreateExternalRegion (Status, Arg,
636             Arg->Common.Value.Name, WalkState, &RegionNode);
637 #endif
638         if (ACPI_FAILURE (Status))
639         {
640             ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
641             return_ACPI_STATUS (Status);
642         }
643     }
644 
645     memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
646 
647     /* Second arg is the field flags */
648 
649     Arg = Arg->Common.Next;
650     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
651     Info.Attribute = 0;
652 
653     /* Each remaining arg is a Named Field */
654 
655     Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
656     Info.RegionNode = RegionNode;
657 
658     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
659     return_ACPI_STATUS (Status);
660 }
661 
662 
663 /*******************************************************************************
664  *
665  * FUNCTION:    AcpiDsInitFieldObjects
666  *
667  * PARAMETERS:  Op              - Op containing the Field definition and args
668  *  `           WalkState       - Current method state
669  *
670  * RETURN:      Status
671  *
672  * DESCRIPTION: For each "Field Unit" name in the argument list that is
673  *              part of the field declaration, enter the name into the
674  *              namespace.
675  *
676  ******************************************************************************/
677 
678 ACPI_STATUS
679 AcpiDsInitFieldObjects (
680     ACPI_PARSE_OBJECT       *Op,
681     ACPI_WALK_STATE         *WalkState)
682 {
683     ACPI_STATUS             Status;
684     ACPI_PARSE_OBJECT       *Arg = NULL;
685     ACPI_NAMESPACE_NODE     *Node;
686     UINT8                   Type = 0;
687     UINT32                  Flags;
688 
689 
690     ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
691 
692 
693     /* Execute flag should always be set when this function is entered */
694 
695     if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
696     {
697         if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
698         {
699             /* BankField Op is deferred, just return OK */
700 
701             return_ACPI_STATUS (AE_OK);
702         }
703 
704         return_ACPI_STATUS (AE_AML_INTERNAL);
705     }
706 
707     /*
708      * Get the FieldList argument for this opcode. This is the start of the
709      * list of field elements.
710      */
711     switch (WalkState->Opcode)
712     {
713     case AML_FIELD_OP:
714 
715         Arg = AcpiPsGetArg (Op, 2);
716         Type = ACPI_TYPE_LOCAL_REGION_FIELD;
717         break;
718 
719     case AML_BANK_FIELD_OP:
720 
721         Arg = AcpiPsGetArg (Op, 4);
722         Type = ACPI_TYPE_LOCAL_BANK_FIELD;
723         break;
724 
725     case AML_INDEX_FIELD_OP:
726 
727         Arg = AcpiPsGetArg (Op, 3);
728         Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
729         break;
730 
731     default:
732 
733         return_ACPI_STATUS (AE_BAD_PARAMETER);
734     }
735 
736     /* Creating new namespace node(s), should not already exist */
737 
738     Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
739         ACPI_NS_ERROR_IF_FOUND;
740 
741     /*
742      * Mark node(s) temporary if we are executing a normal control
743      * method. (Don't mark if this is a module-level code method)
744      */
745     if (WalkState->MethodNode &&
746         !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
747     {
748         Flags |= ACPI_NS_TEMPORARY;
749     }
750 
751     /*
752      * Walk the list of entries in the FieldList
753      * Note: FieldList can be of zero length. In this case, Arg will be NULL.
754      */
755     while (Arg)
756     {
757         /*
758          * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
759          * in the field names in order to enter them into the namespace.
760          */
761         if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
762         {
763             Status = AcpiNsLookup (WalkState->ScopeInfo,
764                 (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
765                 Flags, WalkState, &Node);
766             if (ACPI_FAILURE (Status))
767             {
768                 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
769                 if (Status != AE_ALREADY_EXISTS)
770                 {
771                     return_ACPI_STATUS (Status);
772                 }
773 
774                 /* Name already exists, just ignore this error */
775 
776                 Status = AE_OK;
777             }
778 
779             Arg->Common.Node = Node;
780         }
781 
782         /* Get the next field element in the list */
783 
784         Arg = Arg->Common.Next;
785     }
786 
787     return_ACPI_STATUS (AE_OK);
788 }
789 
790 
791 /*******************************************************************************
792  *
793  * FUNCTION:    AcpiDsCreateBankField
794  *
795  * PARAMETERS:  Op              - Op containing the Field definition and args
796  *              RegionNode      - Object for the containing Operation Region
797  *              WalkState       - Current method state
798  *
799  * RETURN:      Status
800  *
801  * DESCRIPTION: Create a new bank field in the specified operation region
802  *
803  ******************************************************************************/
804 
805 ACPI_STATUS
806 AcpiDsCreateBankField (
807     ACPI_PARSE_OBJECT       *Op,
808     ACPI_NAMESPACE_NODE     *RegionNode,
809     ACPI_WALK_STATE         *WalkState)
810 {
811     ACPI_STATUS             Status;
812     ACPI_PARSE_OBJECT       *Arg;
813     ACPI_CREATE_FIELD_INFO  Info;
814 
815 
816     ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
817 
818 
819     /* First arg is the name of the parent OpRegion (must already exist) */
820 
821     Arg = Op->Common.Value.Arg;
822     if (!RegionNode)
823     {
824         Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
825             ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
826             ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
827 #ifdef ACPI_ASL_COMPILER
828         Status = AcpiDsCreateExternalRegion (Status, Arg,
829             Arg->Common.Value.Name, WalkState, &RegionNode);
830 #endif
831         if (ACPI_FAILURE (Status))
832         {
833             ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
834             return_ACPI_STATUS (Status);
835         }
836     }
837 
838     /* Second arg is the Bank Register (Field) (must already exist) */
839 
840     Arg = Arg->Common.Next;
841     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
842         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
843         ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
844     if (ACPI_FAILURE (Status))
845     {
846         ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
847         return_ACPI_STATUS (Status);
848     }
849 
850     /*
851      * Third arg is the BankValue
852      * This arg is a TermArg, not a constant
853      * It will be evaluated later, by AcpiDsEvalBankFieldOperands
854      */
855     Arg = Arg->Common.Next;
856 
857     /* Fourth arg is the field flags */
858 
859     Arg = Arg->Common.Next;
860     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
861 
862     /* Each remaining arg is a Named Field */
863 
864     Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
865     Info.RegionNode = RegionNode;
866 
867     /*
868      * Use Info.DataRegisterNode to store BankField Op
869      * It's safe because DataRegisterNode will never be used when create
870      * bank field \we store AmlStart and AmlLength in the BankField Op for
871      * late evaluation. Used in AcpiExPrepFieldValue(Info)
872      *
873      * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
874      * "void *ParentOp"?
875      */
876     Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
877 
878     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
879     return_ACPI_STATUS (Status);
880 }
881 
882 
883 /*******************************************************************************
884  *
885  * FUNCTION:    AcpiDsCreateIndexField
886  *
887  * PARAMETERS:  Op              - Op containing the Field definition and args
888  *              RegionNode      - Object for the containing Operation Region
889  *  `           WalkState       - Current method state
890  *
891  * RETURN:      Status
892  *
893  * DESCRIPTION: Create a new index field in the specified operation region
894  *
895  ******************************************************************************/
896 
897 ACPI_STATUS
898 AcpiDsCreateIndexField (
899     ACPI_PARSE_OBJECT       *Op,
900     ACPI_NAMESPACE_NODE     *RegionNode,
901     ACPI_WALK_STATE         *WalkState)
902 {
903     ACPI_STATUS             Status;
904     ACPI_PARSE_OBJECT       *Arg;
905     ACPI_CREATE_FIELD_INFO  Info;
906 
907 
908     ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
909 
910 
911     /* First arg is the name of the Index register (must already exist) */
912 
913     Arg = Op->Common.Value.Arg;
914     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
915         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
916         ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
917     if (ACPI_FAILURE (Status))
918     {
919         ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
920         return_ACPI_STATUS (Status);
921     }
922 
923     /* Second arg is the data register (must already exist) */
924 
925     Arg = Arg->Common.Next;
926     Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
927         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
928         ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
929     if (ACPI_FAILURE (Status))
930     {
931         ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
932         return_ACPI_STATUS (Status);
933     }
934 
935     /* Next arg is the field flags */
936 
937     Arg = Arg->Common.Next;
938     Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
939 
940     /* Each remaining arg is a Named Field */
941 
942     Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
943     Info.RegionNode = RegionNode;
944 
945     Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
946     return_ACPI_STATUS (Status);
947 }
948