1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dsfield.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $ */
118 #define __DSFIELD_C__
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
125 #include "acparser.h"
128 #define _COMPONENT ACPI_DISPATCHER
129 ACPI_MODULE_NAME ("dsfield")
132 /*******************************************************************************
134 * FUNCTION: AcpiDsCreateBufferField
136 * PARAMETERS: Opcode - The opcode to be executed
137 * Operands - List of operands for the opcode
138 * WalkState - Current state
142 * DESCRIPTION: Execute the CreateField operators:
146 * CreateDWordFieldOp,
147 * CreateQWordFieldOp,
148 * CreateFieldOp (all of which define fields in buffers)
150 ******************************************************************************/
153 AcpiDsCreateBufferField (
154 ACPI_PARSE_OBJECT *Op,
155 ACPI_WALK_STATE *WalkState)
157 ACPI_PARSE_OBJECT *Arg;
158 ACPI_NAMESPACE_NODE *Node;
160 ACPI_OPERAND_OBJECT *ObjDesc;
161 ACPI_OPERAND_OBJECT *SecondDesc = NULL;
165 ACPI_FUNCTION_TRACE ("DsCreateBufferField");
168 /* Get the NameString argument */
170 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
172 Arg = AcpiPsGetArg (Op, 3);
176 /* Create Bit/Byte/Word/Dword field */
178 Arg = AcpiPsGetArg (Op, 2);
183 return_ACPI_STATUS (AE_AML_NO_OPERAND);
187 * During the load phase, we want to enter the name of the field into
188 * the namespace. During the execute phase (when we evaluate the size
189 * operand), we want to lookup the name
191 if (WalkState->ParseFlags & ACPI_PARSE_EXECUTE)
193 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE;
197 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND;
201 * Enter the NameString into the namespace
203 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
204 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
205 Flags, WalkState, &(Node));
206 if (ACPI_FAILURE (Status))
208 ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
209 return_ACPI_STATUS (Status);
212 /* We could put the returned object (Node) on the object stack for later, but
213 * for now, we will put it in the "op" object that the parser uses, so we
214 * can get it again at the end of this scope
216 Op->Common.Node = Node;
219 * If there is no object attached to the node, this node was just created and
220 * we need to create the field object. Otherwise, this was a lookup of an
221 * existing node and we don't want to create the field object again.
223 ObjDesc = AcpiNsGetAttachedObject (Node);
226 return_ACPI_STATUS (AE_OK);
230 * The Field definition is not fully parsed at this time.
231 * (We must save the address of the AML for the buffer and index operands)
234 /* Create the buffer field object */
236 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
239 Status = AE_NO_MEMORY;
244 * Remember location in AML stream of the field unit
245 * opcode and operands -- since the buffer and index
246 * operands must be evaluated.
248 SecondDesc = ObjDesc->Common.NextObject;
249 SecondDesc->Extra.AmlStart = Op->Named.Data;
250 SecondDesc->Extra.AmlLength = Op->Named.Length;
251 ObjDesc->BufferField.Node = Node;
253 /* Attach constructed field descriptors to parent node */
255 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
256 if (ACPI_FAILURE (Status))
264 /* Remove local reference to the object */
266 AcpiUtRemoveReference (ObjDesc);
267 return_ACPI_STATUS (Status);
271 /*******************************************************************************
273 * FUNCTION: AcpiDsGetFieldNames
275 * PARAMETERS: Info - CreateField info structure
276 * ` WalkState - Current method state
277 * Arg - First parser arg for the field name list
281 * DESCRIPTION: Process all named fields in a field declaration. Names are
282 * entered into the namespace.
284 ******************************************************************************/
287 AcpiDsGetFieldNames (
288 ACPI_CREATE_FIELD_INFO *Info,
289 ACPI_WALK_STATE *WalkState,
290 ACPI_PARSE_OBJECT *Arg)
293 ACPI_INTEGER Position;
296 ACPI_FUNCTION_TRACE_PTR ("DsGetFieldNames", Info);
299 /* First field starts at bit zero */
301 Info->FieldBitPosition = 0;
303 /* Process all elements in the field list (of parse nodes) */
308 * Three types of field elements are handled:
309 * 1) Offset - specifies a bit offset
310 * 2) AccessAs - changes the access mode
311 * 3) Name - Enters a new named field into the namespace
313 switch (Arg->Common.AmlOpcode)
315 case AML_INT_RESERVEDFIELD_OP:
317 Position = (ACPI_INTEGER) Info->FieldBitPosition
318 + (ACPI_INTEGER) Arg->Common.Value.Size;
320 if (Position > ACPI_UINT32_MAX)
322 ACPI_REPORT_ERROR (("Bit offset within field too large (> 0xFFFFFFFF)\n"));
323 return_ACPI_STATUS (AE_SUPPORT);
326 Info->FieldBitPosition = (UINT32) Position;
330 case AML_INT_ACCESSFIELD_OP:
333 * Get a new AccessType and AccessAttribute -- to be used for all
334 * field units that follow, until field end or another AccessAs keyword.
336 * In FieldFlags, preserve the flag bits other than the ACCESS_TYPE bits
338 Info->FieldFlags = (UINT8) ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
339 ((UINT8) (Arg->Common.Value.Integer32 >> 8)));
341 Info->Attribute = (UINT8) (Arg->Common.Value.Integer32);
345 case AML_INT_NAMEDFIELD_OP:
347 /* Lookup the name */
349 Status = AcpiNsLookup (WalkState->ScopeInfo,
350 (char *) &Arg->Named.Name,
351 Info->FieldType, ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
352 WalkState, &Info->FieldNode);
353 if (ACPI_FAILURE (Status))
355 ACPI_REPORT_NSERROR ((char *) &Arg->Named.Name, Status);
356 if (Status != AE_ALREADY_EXISTS)
358 return_ACPI_STATUS (Status);
361 /* Already exists, ignore error */
365 Arg->Common.Node = Info->FieldNode;
366 Info->FieldBitLength = Arg->Common.Value.Size;
368 /* Create and initialize an object for the new Field Node */
370 Status = AcpiExPrepFieldValue (Info);
371 if (ACPI_FAILURE (Status))
373 return_ACPI_STATUS (Status);
377 /* Keep track of bit position for the next field */
379 Position = (ACPI_INTEGER) Info->FieldBitPosition
380 + (ACPI_INTEGER) Arg->Common.Value.Size;
382 if (Position > ACPI_UINT32_MAX)
384 ACPI_REPORT_ERROR (("Field [%4.4s] bit offset too large (> 0xFFFFFFFF)\n",
385 (char *) &Info->FieldNode->Name));
386 return_ACPI_STATUS (AE_SUPPORT);
389 Info->FieldBitPosition += Info->FieldBitLength;
395 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid opcode in field list: %X\n",
396 Arg->Common.AmlOpcode));
397 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
400 Arg = Arg->Common.Next;
403 return_ACPI_STATUS (AE_OK);
407 /*******************************************************************************
409 * FUNCTION: AcpiDsCreateField
411 * PARAMETERS: Op - Op containing the Field definition and args
412 * RegionNode - Object for the containing Operation Region
413 * ` WalkState - Current method state
417 * DESCRIPTION: Create a new field in the specified operation region
419 ******************************************************************************/
423 ACPI_PARSE_OBJECT *Op,
424 ACPI_NAMESPACE_NODE *RegionNode,
425 ACPI_WALK_STATE *WalkState)
428 ACPI_PARSE_OBJECT *Arg;
429 ACPI_CREATE_FIELD_INFO Info;
432 ACPI_FUNCTION_TRACE_PTR ("DsCreateField", Op);
435 /* First arg is the name of the parent OpRegion (must already exist) */
437 Arg = Op->Common.Value.Arg;
440 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
441 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
442 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
443 if (ACPI_FAILURE (Status))
445 ACPI_REPORT_NSERROR (Arg->Common.Value.Name, Status);
446 return_ACPI_STATUS (Status);
450 /* Second arg is the field flags */
452 Arg = Arg->Common.Next;
453 Info.FieldFlags = Arg->Common.Value.Integer8;
456 /* Each remaining arg is a Named Field */
458 Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
459 Info.RegionNode = RegionNode;
461 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
463 return_ACPI_STATUS (Status);
467 /*******************************************************************************
469 * FUNCTION: AcpiDsInitFieldObjects
471 * PARAMETERS: Op - Op containing the Field definition and args
472 * ` WalkState - Current method state
476 * DESCRIPTION: For each "Field Unit" name in the argument list that is
477 * part of the field declaration, enter the name into the
480 ******************************************************************************/
483 AcpiDsInitFieldObjects (
484 ACPI_PARSE_OBJECT *Op,
485 ACPI_WALK_STATE *WalkState)
488 ACPI_PARSE_OBJECT *Arg = NULL;
489 ACPI_NAMESPACE_NODE *Node;
493 ACPI_FUNCTION_TRACE_PTR ("DsInitFieldObjects", Op);
496 switch (WalkState->Opcode)
499 Arg = AcpiPsGetArg (Op, 2);
500 Type = ACPI_TYPE_LOCAL_REGION_FIELD;
503 case AML_BANK_FIELD_OP:
504 Arg = AcpiPsGetArg (Op, 4);
505 Type = ACPI_TYPE_LOCAL_BANK_FIELD;
508 case AML_INDEX_FIELD_OP:
509 Arg = AcpiPsGetArg (Op, 3);
510 Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
514 return_ACPI_STATUS (AE_BAD_PARAMETER);
518 * Walk the list of entries in the FieldList
522 /* Ignore OFFSET and ACCESSAS terms here */
524 if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
526 Status = AcpiNsLookup (WalkState->ScopeInfo,
527 (char *) &Arg->Named.Name,
528 Type, ACPI_IMODE_LOAD_PASS1,
529 ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE | ACPI_NS_ERROR_IF_FOUND,
531 if (ACPI_FAILURE (Status))
533 ACPI_REPORT_NSERROR ((char *) &Arg->Named.Name, Status);
534 if (Status != AE_ALREADY_EXISTS)
536 return_ACPI_STATUS (Status);
539 /* Name already exists, just ignore this error */
544 Arg->Common.Node = Node;
547 /* Move to next field in the list */
549 Arg = Arg->Common.Next;
552 return_ACPI_STATUS (AE_OK);
556 /*******************************************************************************
558 * FUNCTION: AcpiDsCreateBankField
560 * PARAMETERS: Op - Op containing the Field definition and args
561 * RegionNode - Object for the containing Operation Region
562 * ` WalkState - Current method state
566 * DESCRIPTION: Create a new bank field in the specified operation region
568 ******************************************************************************/
571 AcpiDsCreateBankField (
572 ACPI_PARSE_OBJECT *Op,
573 ACPI_NAMESPACE_NODE *RegionNode,
574 ACPI_WALK_STATE *WalkState)
577 ACPI_PARSE_OBJECT *Arg;
578 ACPI_CREATE_FIELD_INFO Info;
581 ACPI_FUNCTION_TRACE_PTR ("DsCreateBankField", Op);
584 /* First arg is the name of the parent OpRegion (must already exist) */
586 Arg = Op->Common.Value.Arg;
589 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
590 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
591 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
592 if (ACPI_FAILURE (Status))
594 ACPI_REPORT_NSERROR (Arg->Common.Value.Name, Status);
595 return_ACPI_STATUS (Status);
599 /* Second arg is the Bank Register (Field) (must already exist) */
601 Arg = Arg->Common.Next;
602 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
603 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
604 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
605 if (ACPI_FAILURE (Status))
607 ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
608 return_ACPI_STATUS (Status);
611 /* Third arg is the BankValue */
613 Arg = Arg->Common.Next;
614 Info.BankValue = Arg->Common.Value.Integer32;
616 /* Fourth arg is the field flags */
618 Arg = Arg->Common.Next;
619 Info.FieldFlags = Arg->Common.Value.Integer8;
621 /* Each remaining arg is a Named Field */
623 Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
624 Info.RegionNode = RegionNode;
626 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
628 return_ACPI_STATUS (Status);
632 /*******************************************************************************
634 * FUNCTION: AcpiDsCreateIndexField
636 * PARAMETERS: Op - Op containing the Field definition and args
637 * RegionNode - Object for the containing Operation Region
638 * ` WalkState - Current method state
642 * DESCRIPTION: Create a new index field in the specified operation region
644 ******************************************************************************/
647 AcpiDsCreateIndexField (
648 ACPI_PARSE_OBJECT *Op,
649 ACPI_NAMESPACE_NODE *RegionNode,
650 ACPI_WALK_STATE *WalkState)
653 ACPI_PARSE_OBJECT *Arg;
654 ACPI_CREATE_FIELD_INFO Info;
657 ACPI_FUNCTION_TRACE_PTR ("DsCreateIndexField", Op);
660 /* First arg is the name of the Index register (must already exist) */
662 Arg = Op->Common.Value.Arg;
663 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
664 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
665 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
666 if (ACPI_FAILURE (Status))
668 ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
669 return_ACPI_STATUS (Status);
672 /* Second arg is the data register (must already exist) */
674 Arg = Arg->Common.Next;
675 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
676 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
677 ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
678 if (ACPI_FAILURE (Status))
680 ACPI_REPORT_NSERROR (Arg->Common.Value.String, Status);
681 return_ACPI_STATUS (Status);
684 /* Next arg is the field flags */
686 Arg = Arg->Common.Next;
687 Info.FieldFlags = Arg->Common.Value.Integer8;
689 /* Each remaining arg is a Named Field */
691 Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
692 Info.RegionNode = RegionNode;
694 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
696 return_ACPI_STATUS (Status);