1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
117 #define __DSFIELD_C__
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
);
174 /* Get the NameString argument */
176 if (Op
->Common
.AmlOpcode
== AML_CREATE_FIELD_OP
)
178 Arg
= AcpiPsGetArg (Op
, 3);
182 /* Create Bit/Byte/Word/Dword field */
184 Arg
= AcpiPsGetArg (Op
, 2);
189 return_ACPI_STATUS (AE_AML_NO_OPERAND
);
192 if (WalkState
->DeferredNode
)
194 Node
= WalkState
->DeferredNode
;
200 * During the load phase, we want to enter the name of the field into
201 * the namespace. During the execute phase (when we evaluate the size
202 * operand), we want to lookup the name
204 if (WalkState
->ParseFlags
& ACPI_PARSE_EXECUTE
)
206 Flags
= ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
;
210 Flags
= ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
|
211 ACPI_NS_ERROR_IF_FOUND
;
215 * Enter the NameString into the namespace
217 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.String
,
218 ACPI_TYPE_ANY
, ACPI_IMODE_LOAD_PASS1
,
219 Flags
, WalkState
, &(Node
));
220 if (ACPI_FAILURE (Status
))
222 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.String
, Status
);
223 return_ACPI_STATUS (Status
);
228 * We could put the returned object (Node) on the object stack for later,
229 * but for now, we will put it in the "op" object that the parser uses,
230 * so we can get it again at the end of this scope
232 Op
->Common
.Node
= Node
;
235 * If there is no object attached to the node, this node was just created
236 * and we need to create the field object. Otherwise, this was a lookup
237 * of an existing node and we don't want to create the field object again.
239 ObjDesc
= AcpiNsGetAttachedObject (Node
);
242 return_ACPI_STATUS (AE_OK
);
246 * The Field definition is not fully parsed at this time.
247 * (We must save the address of the AML for the buffer and index operands)
250 /* Create the buffer field object */
252 ObjDesc
= AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD
);
255 Status
= AE_NO_MEMORY
;
260 * Remember location in AML stream of the field unit
261 * opcode and operands -- since the buffer and index
262 * operands must be evaluated.
264 SecondDesc
= ObjDesc
->Common
.NextObject
;
265 SecondDesc
->Extra
.AmlStart
= Op
->Named
.Data
;
266 SecondDesc
->Extra
.AmlLength
= Op
->Named
.Length
;
267 ObjDesc
->BufferField
.Node
= Node
;
269 /* Attach constructed field descriptors to parent node */
271 Status
= AcpiNsAttachObject (Node
, ObjDesc
, ACPI_TYPE_BUFFER_FIELD
);
272 if (ACPI_FAILURE (Status
))
280 /* Remove local reference to the object */
282 AcpiUtRemoveReference (ObjDesc
);
283 return_ACPI_STATUS (Status
);
287 /*******************************************************************************
289 * FUNCTION: AcpiDsGetFieldNames
291 * PARAMETERS: Info - CreateField info structure
292 * ` WalkState - Current method state
293 * Arg - First parser arg for the field name list
297 * DESCRIPTION: Process all named fields in a field declaration. Names are
298 * entered into the namespace.
300 ******************************************************************************/
303 AcpiDsGetFieldNames (
304 ACPI_CREATE_FIELD_INFO
*Info
,
305 ACPI_WALK_STATE
*WalkState
,
306 ACPI_PARSE_OBJECT
*Arg
)
309 ACPI_INTEGER Position
;
312 ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames
, Info
);
315 /* First field starts at bit zero */
317 Info
->FieldBitPosition
= 0;
319 /* Process all elements in the field list (of parse nodes) */
324 * Three types of field elements are handled:
325 * 1) Offset - specifies a bit offset
326 * 2) AccessAs - changes the access mode
327 * 3) Name - Enters a new named field into the namespace
329 switch (Arg
->Common
.AmlOpcode
)
331 case AML_INT_RESERVEDFIELD_OP
:
333 Position
= (ACPI_INTEGER
) Info
->FieldBitPosition
334 + (ACPI_INTEGER
) Arg
->Common
.Value
.Size
;
336 if (Position
> ACPI_UINT32_MAX
)
338 ACPI_ERROR ((AE_INFO
,
339 "Bit offset within field too large (> 0xFFFFFFFF)"));
340 return_ACPI_STATUS (AE_SUPPORT
);
343 Info
->FieldBitPosition
= (UINT32
) Position
;
347 case AML_INT_ACCESSFIELD_OP
:
350 * Get a new AccessType and AccessAttribute -- to be used for all
351 * field units that follow, until field end or another AccessAs
354 * In FieldFlags, preserve the flag bits other than the
357 Info
->FieldFlags
= (UINT8
)
358 ((Info
->FieldFlags
& ~(AML_FIELD_ACCESS_TYPE_MASK
)) |
359 ((UINT8
) ((UINT32
) Arg
->Common
.Value
.Integer
>> 8)));
361 Info
->Attribute
= (UINT8
) (Arg
->Common
.Value
.Integer
);
365 case AML_INT_NAMEDFIELD_OP
:
367 /* Lookup the name */
369 Status
= AcpiNsLookup (WalkState
->ScopeInfo
,
370 (char *) &Arg
->Named
.Name
,
371 Info
->FieldType
, ACPI_IMODE_EXECUTE
,
372 ACPI_NS_DONT_OPEN_SCOPE
,
373 WalkState
, &Info
->FieldNode
);
374 if (ACPI_FAILURE (Status
))
376 ACPI_ERROR_NAMESPACE ((char *) &Arg
->Named
.Name
, Status
);
377 if (Status
!= AE_ALREADY_EXISTS
)
379 return_ACPI_STATUS (Status
);
382 /* Already exists, ignore error */
386 Arg
->Common
.Node
= Info
->FieldNode
;
387 Info
->FieldBitLength
= Arg
->Common
.Value
.Size
;
389 /* Create and initialize an object for the new Field Node */
391 Status
= AcpiExPrepFieldValue (Info
);
392 if (ACPI_FAILURE (Status
))
394 return_ACPI_STATUS (Status
);
398 /* Keep track of bit position for the next field */
400 Position
= (ACPI_INTEGER
) Info
->FieldBitPosition
401 + (ACPI_INTEGER
) Arg
->Common
.Value
.Size
;
403 if (Position
> ACPI_UINT32_MAX
)
405 ACPI_ERROR ((AE_INFO
,
406 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
407 ACPI_CAST_PTR (char, &Info
->FieldNode
->Name
)));
408 return_ACPI_STATUS (AE_SUPPORT
);
411 Info
->FieldBitPosition
+= Info
->FieldBitLength
;
417 ACPI_ERROR ((AE_INFO
,
418 "Invalid opcode in field list: %X",
419 Arg
->Common
.AmlOpcode
));
420 return_ACPI_STATUS (AE_AML_BAD_OPCODE
);
423 Arg
= Arg
->Common
.Next
;
426 return_ACPI_STATUS (AE_OK
);
430 /*******************************************************************************
432 * FUNCTION: AcpiDsCreateField
434 * PARAMETERS: Op - Op containing the Field definition and args
435 * RegionNode - Object for the containing Operation Region
436 * ` WalkState - Current method state
440 * DESCRIPTION: Create a new field in the specified operation region
442 ******************************************************************************/
446 ACPI_PARSE_OBJECT
*Op
,
447 ACPI_NAMESPACE_NODE
*RegionNode
,
448 ACPI_WALK_STATE
*WalkState
)
451 ACPI_PARSE_OBJECT
*Arg
;
452 ACPI_CREATE_FIELD_INFO Info
;
455 ACPI_FUNCTION_TRACE_PTR (DsCreateField
, Op
);
458 /* First arg is the name of the parent OpRegion (must already exist) */
460 Arg
= Op
->Common
.Value
.Arg
;
463 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.Name
,
464 ACPI_TYPE_REGION
, ACPI_IMODE_EXECUTE
,
465 ACPI_NS_SEARCH_PARENT
, WalkState
, &RegionNode
);
466 if (ACPI_FAILURE (Status
))
468 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.Name
, Status
);
469 return_ACPI_STATUS (Status
);
473 /* Second arg is the field flags */
475 Arg
= Arg
->Common
.Next
;
476 Info
.FieldFlags
= (UINT8
) Arg
->Common
.Value
.Integer
;
479 /* Each remaining arg is a Named Field */
481 Info
.FieldType
= ACPI_TYPE_LOCAL_REGION_FIELD
;
482 Info
.RegionNode
= RegionNode
;
484 Status
= AcpiDsGetFieldNames (&Info
, WalkState
, Arg
->Common
.Next
);
486 return_ACPI_STATUS (Status
);
490 /*******************************************************************************
492 * FUNCTION: AcpiDsInitFieldObjects
494 * PARAMETERS: Op - Op containing the Field definition and args
495 * ` WalkState - Current method state
499 * DESCRIPTION: For each "Field Unit" name in the argument list that is
500 * part of the field declaration, enter the name into the
503 ******************************************************************************/
506 AcpiDsInitFieldObjects (
507 ACPI_PARSE_OBJECT
*Op
,
508 ACPI_WALK_STATE
*WalkState
)
511 ACPI_PARSE_OBJECT
*Arg
= NULL
;
512 ACPI_NAMESPACE_NODE
*Node
;
516 ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects
, Op
);
519 switch (WalkState
->Opcode
)
522 Arg
= AcpiPsGetArg (Op
, 2);
523 Type
= ACPI_TYPE_LOCAL_REGION_FIELD
;
526 case AML_BANK_FIELD_OP
:
527 Arg
= AcpiPsGetArg (Op
, 4);
528 Type
= ACPI_TYPE_LOCAL_BANK_FIELD
;
531 case AML_INDEX_FIELD_OP
:
532 Arg
= AcpiPsGetArg (Op
, 3);
533 Type
= ACPI_TYPE_LOCAL_INDEX_FIELD
;
537 return_ACPI_STATUS (AE_BAD_PARAMETER
);
541 * Walk the list of entries in the FieldList
545 /* Ignore OFFSET and ACCESSAS terms here */
547 if (Arg
->Common
.AmlOpcode
== AML_INT_NAMEDFIELD_OP
)
549 Status
= AcpiNsLookup (WalkState
->ScopeInfo
,
550 (char *) &Arg
->Named
.Name
,
551 Type
, ACPI_IMODE_LOAD_PASS1
,
552 ACPI_NS_NO_UPSEARCH
| ACPI_NS_DONT_OPEN_SCOPE
|
553 ACPI_NS_ERROR_IF_FOUND
,
555 if (ACPI_FAILURE (Status
))
557 ACPI_ERROR_NAMESPACE ((char *) &Arg
->Named
.Name
, Status
);
558 if (Status
!= AE_ALREADY_EXISTS
)
560 return_ACPI_STATUS (Status
);
563 /* Name already exists, just ignore this error */
568 Arg
->Common
.Node
= Node
;
571 /* Move to next field in the list */
573 Arg
= Arg
->Common
.Next
;
576 return_ACPI_STATUS (AE_OK
);
580 /*******************************************************************************
582 * FUNCTION: AcpiDsCreateBankField
584 * PARAMETERS: Op - Op containing the Field definition and args
585 * RegionNode - Object for the containing Operation Region
586 * ` WalkState - Current method state
590 * DESCRIPTION: Create a new bank field in the specified operation region
592 ******************************************************************************/
595 AcpiDsCreateBankField (
596 ACPI_PARSE_OBJECT
*Op
,
597 ACPI_NAMESPACE_NODE
*RegionNode
,
598 ACPI_WALK_STATE
*WalkState
)
601 ACPI_PARSE_OBJECT
*Arg
;
602 ACPI_CREATE_FIELD_INFO Info
;
605 ACPI_FUNCTION_TRACE_PTR (DsCreateBankField
, Op
);
608 /* First arg is the name of the parent OpRegion (must already exist) */
610 Arg
= Op
->Common
.Value
.Arg
;
613 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.Name
,
614 ACPI_TYPE_REGION
, ACPI_IMODE_EXECUTE
,
615 ACPI_NS_SEARCH_PARENT
, WalkState
, &RegionNode
);
616 if (ACPI_FAILURE (Status
))
618 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.Name
, Status
);
619 return_ACPI_STATUS (Status
);
623 /* Second arg is the Bank Register (Field) (must already exist) */
625 Arg
= Arg
->Common
.Next
;
626 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.String
,
627 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
628 ACPI_NS_SEARCH_PARENT
, WalkState
, &Info
.RegisterNode
);
629 if (ACPI_FAILURE (Status
))
631 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.String
, Status
);
632 return_ACPI_STATUS (Status
);
635 /* Third arg is the BankValue */
637 /* TBD: This arg is a TermArg, not a constant, and must be evaluated */
639 Arg
= Arg
->Common
.Next
;
641 /* Currently, only the following constants are supported */
643 switch (Arg
->Common
.AmlOpcode
)
657 Info
.BankValue
= (UINT32
) Arg
->Common
.Value
.Integer
;
662 ACPI_ERROR ((AE_INFO
, "Non-constant BankValue for BankField is not implemented"));
665 /* Fourth arg is the field flags */
667 Arg
= Arg
->Common
.Next
;
668 Info
.FieldFlags
= (UINT8
) Arg
->Common
.Value
.Integer
;
670 /* Each remaining arg is a Named Field */
672 Info
.FieldType
= ACPI_TYPE_LOCAL_BANK_FIELD
;
673 Info
.RegionNode
= RegionNode
;
675 Status
= AcpiDsGetFieldNames (&Info
, WalkState
, Arg
->Common
.Next
);
677 return_ACPI_STATUS (Status
);
681 /*******************************************************************************
683 * FUNCTION: AcpiDsCreateIndexField
685 * PARAMETERS: Op - Op containing the Field definition and args
686 * RegionNode - Object for the containing Operation Region
687 * ` WalkState - Current method state
691 * DESCRIPTION: Create a new index field in the specified operation region
693 ******************************************************************************/
696 AcpiDsCreateIndexField (
697 ACPI_PARSE_OBJECT
*Op
,
698 ACPI_NAMESPACE_NODE
*RegionNode
,
699 ACPI_WALK_STATE
*WalkState
)
702 ACPI_PARSE_OBJECT
*Arg
;
703 ACPI_CREATE_FIELD_INFO Info
;
706 ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField
, Op
);
709 /* First arg is the name of the Index register (must already exist) */
711 Arg
= Op
->Common
.Value
.Arg
;
712 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.String
,
713 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
714 ACPI_NS_SEARCH_PARENT
, WalkState
, &Info
.RegisterNode
);
715 if (ACPI_FAILURE (Status
))
717 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.String
, Status
);
718 return_ACPI_STATUS (Status
);
721 /* Second arg is the data register (must already exist) */
723 Arg
= Arg
->Common
.Next
;
724 Status
= AcpiNsLookup (WalkState
->ScopeInfo
, Arg
->Common
.Value
.String
,
725 ACPI_TYPE_ANY
, ACPI_IMODE_EXECUTE
,
726 ACPI_NS_SEARCH_PARENT
, WalkState
, &Info
.DataRegisterNode
);
727 if (ACPI_FAILURE (Status
))
729 ACPI_ERROR_NAMESPACE (Arg
->Common
.Value
.String
, Status
);
730 return_ACPI_STATUS (Status
);
733 /* Next arg is the field flags */
735 Arg
= Arg
->Common
.Next
;
736 Info
.FieldFlags
= (UINT8
) Arg
->Common
.Value
.Integer
;
738 /* Each remaining arg is a Named Field */
740 Info
.FieldType
= ACPI_TYPE_LOCAL_INDEX_FIELD
;
741 Info
.RegionNode
= RegionNode
;
743 Status
= AcpiDsGetFieldNames (&Info
, WalkState
, Arg
->Common
.Next
);
745 return_ACPI_STATUS (Status
);