1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
12 * All rights reserved.
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
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
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;
37 * The above copyright and patent license is granted only if the following
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.
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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.
80 * 4. Disclaimer and Export Compliance
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
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
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.
114 *****************************************************************************/
116 #define __DSFIELD_C__
119 #include "accommon.h"
121 #include "acdispat.h"
122 #include "acinterp.h"
123 #include "acnamesp.h"
124 #include "acparser.h"
127 #define _COMPONENT ACPI_DISPATCHER
128 ACPI_MODULE_NAME ("dsfield")
130 /* Local prototypes */
133 AcpiDsGetFieldNames (
134 ACPI_CREATE_FIELD_INFO *Info,
135 ACPI_WALK_STATE *WalkState,
136 ACPI_PARSE_OBJECT *Arg);
139 /*******************************************************************************
141 * FUNCTION: AcpiDsCreateBufferField
143 * PARAMETERS: Op - Current parse op (CreateXXField)
144 * WalkState - Current state
148 * DESCRIPTION: Execute the CreateField operators:
152 * CreateDWordFieldOp,
153 * CreateQWordFieldOp,
154 * CreateFieldOp (all of which define a field in a buffer)
156 ******************************************************************************/
159 AcpiDsCreateBufferField (
160 ACPI_PARSE_OBJECT *Op,
161 ACPI_WALK_STATE *WalkState)
163 ACPI_PARSE_OBJECT *Arg;
164 ACPI_NAMESPACE_NODE *Node;
166 ACPI_OPERAND_OBJECT *ObjDesc;
167 ACPI_OPERAND_OBJECT *SecondDesc = NULL;
171 ACPI_FUNCTION_TRACE (DsCreateBufferField);
175 * Get the NameString argument (name of the new BufferField)
177 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
179 /* For CreateField, name is the 4th argument */
181 Arg = AcpiPsGetArg (Op, 3);
185 /* For all other CreateXXXField operators, name is the 3rd argument */
187 Arg = AcpiPsGetArg (Op, 2);
192 return_ACPI_STATUS (AE_AML_NO_OPERAND);
195 if (WalkState->DeferredNode)
197 Node = WalkState->DeferredNode;
202 /* Execute flag should always be set when this function is entered */
204 if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
206 return_ACPI_STATUS (AE_AML_INTERNAL);
209 /* Creating new namespace node, should not already exist */
211 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
212 ACPI_NS_ERROR_IF_FOUND;
214 /* Mark node temporary if we are executing a method */
216 if (WalkState->MethodNode)
218 Flags |= ACPI_NS_TEMPORARY;
221 /* Enter the NameString into the namespace */
223 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
224 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
225 Flags, WalkState, &Node);
226 if (ACPI_FAILURE (Status))
228 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
229 return_ACPI_STATUS (Status);
234 * We could put the returned object (Node) on the object stack for later,
235 * but for now, we will put it in the "op" object that the parser uses,
236 * so we can get it again at the end of this scope.
238 Op->Common.Node = Node;
241 * If there is no object attached to the node, this node was just created
242 * and we need to create the field object. Otherwise, this was a lookup
243 * of an existing node and we don't want to create the field object again.
245 ObjDesc = AcpiNsGetAttachedObject (Node);
248 return_ACPI_STATUS (AE_OK);
252 * The Field definition is not fully parsed at this time.
253 * (We must save the address of the AML for the buffer and index operands)
256 /* Create the buffer field object */
258 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
261 Status = AE_NO_MEMORY;
266 * Remember location in AML stream of the field unit opcode and operands --
267 * since the buffer and index operands must be evaluated.
269 SecondDesc = ObjDesc->Common.NextObject;
270 SecondDesc->Extra.AmlStart = Op->Named.Data;
271 SecondDesc->Extra.AmlLength = Op->Named.Length;
272 ObjDesc->BufferField.Node = Node;
274 /* Attach constructed field descriptors to parent node */
276 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
277 if (ACPI_FAILURE (Status))
285 /* Remove local reference to the object */
287 AcpiUtRemoveReference (ObjDesc);
288 return_ACPI_STATUS (Status);
292 /*******************************************************************************
294 * FUNCTION: AcpiDsGetFieldNames
296 * PARAMETERS: Info - CreateField info structure
297 * ` WalkState - Current method state
298 * Arg - First parser arg for the field name list
302 * DESCRIPTION: Process all named fields in a field declaration. Names are
303 * entered into the namespace.
305 ******************************************************************************/
308 AcpiDsGetFieldNames (
309 ACPI_CREATE_FIELD_INFO *Info,
310 ACPI_WALK_STATE *WalkState,
311 ACPI_PARSE_OBJECT *Arg)
314 ACPI_INTEGER Position;
317 ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
320 /* First field starts at bit zero */
322 Info->FieldBitPosition = 0;
324 /* Process all elements in the field list (of parse nodes) */
329 * Three types of field elements are handled:
330 * 1) Offset - specifies a bit offset
331 * 2) AccessAs - changes the access mode
332 * 3) Name - Enters a new named field into the namespace
334 switch (Arg->Common.AmlOpcode)
336 case AML_INT_RESERVEDFIELD_OP:
338 Position = (ACPI_INTEGER) Info->FieldBitPosition
339 + (ACPI_INTEGER) Arg->Common.Value.Size;
341 if (Position > ACPI_UINT32_MAX)
343 ACPI_ERROR ((AE_INFO,
344 "Bit offset within field too large (> 0xFFFFFFFF)"));
345 return_ACPI_STATUS (AE_SUPPORT);
348 Info->FieldBitPosition = (UINT32) Position;
352 case AML_INT_ACCESSFIELD_OP:
355 * Get a new AccessType and AccessAttribute -- to be used for all
356 * field units that follow, until field end or another AccessAs
359 * In FieldFlags, preserve the flag bits other than the
362 Info->FieldFlags = (UINT8)
363 ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
364 ((UINT8) ((UINT32) Arg->Common.Value.Integer >> 8)));
366 Info->Attribute = (UINT8) (Arg->Common.Value.Integer);
370 case AML_INT_NAMEDFIELD_OP:
372 /* Lookup the name, it should already exist */
374 Status = AcpiNsLookup (WalkState->ScopeInfo,
375 (char *) &Arg->Named.Name, Info->FieldType,
376 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
377 WalkState, &Info->FieldNode);
378 if (ACPI_FAILURE (Status))
380 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
381 return_ACPI_STATUS (Status);
385 Arg->Common.Node = Info->FieldNode;
386 Info->FieldBitLength = Arg->Common.Value.Size;
389 * If there is no object attached to the node, this node was
390 * just created and we need to create the field object.
391 * Otherwise, this was a lookup of an existing node and we
392 * don't want to create the field object again.
394 if (!AcpiNsGetAttachedObject (Info->FieldNode))
396 Status = AcpiExPrepFieldValue (Info);
397 if (ACPI_FAILURE (Status))
399 return_ACPI_STATUS (Status);
404 /* Keep track of bit position for the next field */
406 Position = (ACPI_INTEGER) Info->FieldBitPosition
407 + (ACPI_INTEGER) Arg->Common.Value.Size;
409 if (Position > ACPI_UINT32_MAX)
411 ACPI_ERROR ((AE_INFO,
412 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
413 ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
414 return_ACPI_STATUS (AE_SUPPORT);
417 Info->FieldBitPosition += Info->FieldBitLength;
423 ACPI_ERROR ((AE_INFO,
424 "Invalid opcode in field list: %X", Arg->Common.AmlOpcode));
425 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
428 Arg = Arg->Common.Next;
431 return_ACPI_STATUS (AE_OK);
435 /*******************************************************************************
437 * FUNCTION: AcpiDsCreateField
439 * PARAMETERS: Op - Op containing the Field definition and args
440 * RegionNode - Object for the containing Operation Region
441 * ` WalkState - Current method state
445 * DESCRIPTION: Create a new field in the specified operation region
447 ******************************************************************************/
451 ACPI_PARSE_OBJECT *Op,
452 ACPI_NAMESPACE_NODE *RegionNode,
453 ACPI_WALK_STATE *WalkState)
456 ACPI_PARSE_OBJECT *Arg;
457 ACPI_CREATE_FIELD_INFO Info;
460 ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
463 /* First arg is the name of the parent OpRegion (must already exist) */
465 Arg = Op->Common.Value.Arg;
468 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
469 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
470 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
471 if (ACPI_FAILURE (Status))
473 ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
474 return_ACPI_STATUS (Status);
478 /* Second arg is the field flags */
480 Arg = Arg->Common.Next;
481 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
484 /* Each remaining arg is a Named Field */
486 Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
487 Info.RegionNode = RegionNode;
489 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
491 return_ACPI_STATUS (Status);
495 /*******************************************************************************
497 * FUNCTION: AcpiDsInitFieldObjects
499 * PARAMETERS: Op - Op containing the Field definition and args
500 * ` WalkState - Current method state
504 * DESCRIPTION: For each "Field Unit" name in the argument list that is
505 * part of the field declaration, enter the name into the
508 ******************************************************************************/
511 AcpiDsInitFieldObjects (
512 ACPI_PARSE_OBJECT *Op,
513 ACPI_WALK_STATE *WalkState)
516 ACPI_PARSE_OBJECT *Arg = NULL;
517 ACPI_NAMESPACE_NODE *Node;
522 ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
525 /* Execute flag should always be set when this function is entered */
527 if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
529 if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
531 /* BankField Op is deferred, just return OK */
533 return_ACPI_STATUS (AE_OK);
536 return_ACPI_STATUS (AE_AML_INTERNAL);
540 * Get the FieldList argument for this opcode. This is the start of the
541 * list of field elements.
543 switch (WalkState->Opcode)
546 Arg = AcpiPsGetArg (Op, 2);
547 Type = ACPI_TYPE_LOCAL_REGION_FIELD;
550 case AML_BANK_FIELD_OP:
551 Arg = AcpiPsGetArg (Op, 4);
552 Type = ACPI_TYPE_LOCAL_BANK_FIELD;
555 case AML_INDEX_FIELD_OP:
556 Arg = AcpiPsGetArg (Op, 3);
557 Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
561 return_ACPI_STATUS (AE_BAD_PARAMETER);
564 /* Creating new namespace node(s), should not already exist */
566 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
567 ACPI_NS_ERROR_IF_FOUND;
569 /* Mark node(s) temporary if we are executing a method */
571 if (WalkState->MethodNode)
573 Flags |= ACPI_NS_TEMPORARY;
577 * Walk the list of entries in the FieldList
578 * Note: FieldList can be of zero length. In this case, Arg will be NULL.
583 * Ignore OFFSET and ACCESSAS terms here; we are only interested in the
584 * field names in order to enter them into the namespace.
586 if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
588 Status = AcpiNsLookup (WalkState->ScopeInfo,
589 (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
590 Flags, WalkState, &Node);
591 if (ACPI_FAILURE (Status))
593 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
594 if (Status != AE_ALREADY_EXISTS)
596 return_ACPI_STATUS (Status);
599 /* Name already exists, just ignore this error */
604 Arg->Common.Node = Node;
607 /* Get the next field element in the list */
609 Arg = Arg->Common.Next;
612 return_ACPI_STATUS (AE_OK);
616 /*******************************************************************************
618 * FUNCTION: AcpiDsCreateBankField
620 * PARAMETERS: Op - Op containing the Field definition and args
621 * RegionNode - Object for the containing Operation Region
622 * WalkState - Current method state
626 * DESCRIPTION: Create a new bank field in the specified operation region
628 ******************************************************************************/
631 AcpiDsCreateBankField (
632 ACPI_PARSE_OBJECT *Op,
633 ACPI_NAMESPACE_NODE *RegionNode,
634 ACPI_WALK_STATE *WalkState)
637 ACPI_PARSE_OBJECT *Arg;
638 ACPI_CREATE_FIELD_INFO Info;
641 ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
644 /* First arg is the name of the parent OpRegion (must already exist) */
646 Arg = Op->Common.Value.Arg;
649 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
650 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
651 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
652 if (ACPI_FAILURE (Status))
654 ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
655 return_ACPI_STATUS (Status);
659 /* Second arg is the Bank Register (Field) (must already exist) */
661 Arg = Arg->Common.Next;
662 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
663 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
664 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
665 if (ACPI_FAILURE (Status))
667 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
668 return_ACPI_STATUS (Status);
672 * Third arg is the BankValue
673 * This arg is a TermArg, not a constant
674 * It will be evaluated later, by AcpiDsEvalBankFieldOperands
676 Arg = Arg->Common.Next;
678 /* Fourth arg is the field flags */
680 Arg = Arg->Common.Next;
681 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
683 /* Each remaining arg is a Named Field */
685 Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
686 Info.RegionNode = RegionNode;
689 * Use Info.DataRegisterNode to store BankField Op
690 * It's safe because DataRegisterNode will never be used when create bank field
691 * We store AmlStart and AmlLength in the BankField Op for late evaluation
692 * Used in AcpiExPrepFieldValue(Info)
694 * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like "void *ParentOp"?
696 Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
698 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
699 return_ACPI_STATUS (Status);
703 /*******************************************************************************
705 * FUNCTION: AcpiDsCreateIndexField
707 * PARAMETERS: Op - Op containing the Field definition and args
708 * RegionNode - Object for the containing Operation Region
709 * ` WalkState - Current method state
713 * DESCRIPTION: Create a new index field in the specified operation region
715 ******************************************************************************/
718 AcpiDsCreateIndexField (
719 ACPI_PARSE_OBJECT *Op,
720 ACPI_NAMESPACE_NODE *RegionNode,
721 ACPI_WALK_STATE *WalkState)
724 ACPI_PARSE_OBJECT *Arg;
725 ACPI_CREATE_FIELD_INFO Info;
728 ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
731 /* First arg is the name of the Index register (must already exist) */
733 Arg = Op->Common.Value.Arg;
734 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
735 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
736 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
737 if (ACPI_FAILURE (Status))
739 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
740 return_ACPI_STATUS (Status);
743 /* Second arg is the data register (must already exist) */
745 Arg = Arg->Common.Next;
746 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
747 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
748 ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
749 if (ACPI_FAILURE (Status))
751 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
752 return_ACPI_STATUS (Status);
755 /* Next arg is the field flags */
757 Arg = Arg->Common.Next;
758 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
760 /* Each remaining arg is a Named Field */
762 Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
763 Info.RegionNode = RegionNode;
765 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
767 return_ACPI_STATUS (Status);