1 /******************************************************************************
3 * Module Name: dsobject - Dispatcher object management routines
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, 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 __DSOBJECT_C__
119 #include <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/acparser.h>
121 #include <contrib/dev/acpica/amlcode.h>
122 #include <contrib/dev/acpica/acdispat.h>
123 #include <contrib/dev/acpica/acnamesp.h>
124 #include <contrib/dev/acpica/acinterp.h>
126 #define _COMPONENT ACPI_DISPATCHER
127 ACPI_MODULE_NAME ("dsobject")
130 AcpiDsBuildInternalObject (
131 ACPI_WALK_STATE *WalkState,
132 ACPI_PARSE_OBJECT *Op,
133 ACPI_OPERAND_OBJECT **ObjDescPtr);
136 #ifndef ACPI_NO_METHOD_EXECUTION
137 /*******************************************************************************
139 * FUNCTION: AcpiDsBuildInternalObject
141 * PARAMETERS: WalkState - Current walk state
142 * Op - Parser object to be translated
143 * ObjDescPtr - Where the ACPI internal object is returned
147 * DESCRIPTION: Translate a parser Op object to the equivalent namespace object
148 * Simple objects are any objects other than a package object!
150 ******************************************************************************/
153 AcpiDsBuildInternalObject (
154 ACPI_WALK_STATE *WalkState,
155 ACPI_PARSE_OBJECT *Op,
156 ACPI_OPERAND_OBJECT **ObjDescPtr)
158 ACPI_OPERAND_OBJECT *ObjDesc;
162 ACPI_FUNCTION_TRACE ("DsBuildInternalObject");
166 if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
169 * This is an named object reference. If this name was
170 * previously looked up in the namespace, it was stored in this op.
171 * Otherwise, go ahead and look it up now
173 if (!Op->Common.Node)
175 Status = AcpiNsLookup (WalkState->ScopeInfo,
176 Op->Common.Value.String,
177 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
178 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
180 (ACPI_NAMESPACE_NODE **) &(Op->Common.Node));
182 if (ACPI_FAILURE (Status))
184 ACPI_REPORT_NSERROR (Op->Common.Value.String, Status);
185 return_ACPI_STATUS (Status);
190 /* Create and init the internal ACPI object */
192 ObjDesc = AcpiUtCreateInternalObject (
193 (AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode))->ObjectType);
196 return_ACPI_STATUS (AE_NO_MEMORY);
199 Status = AcpiDsInitObjectFromOp (WalkState, Op, Op->Common.AmlOpcode,
201 if (ACPI_FAILURE (Status))
203 AcpiUtRemoveReference (ObjDesc);
204 return_ACPI_STATUS (Status);
207 *ObjDescPtr = ObjDesc;
208 return_ACPI_STATUS (AE_OK);
212 /*******************************************************************************
214 * FUNCTION: AcpiDsBuildInternalBufferObj
216 * PARAMETERS: WalkState - Current walk state
217 * Op - Parser object to be translated
218 * BufferLength - Length of the buffer
219 * ObjDescPtr - Where the ACPI internal object is returned
223 * DESCRIPTION: Translate a parser Op package object to the equivalent
226 ******************************************************************************/
229 AcpiDsBuildInternalBufferObj (
230 ACPI_WALK_STATE *WalkState,
231 ACPI_PARSE_OBJECT *Op,
233 ACPI_OPERAND_OBJECT **ObjDescPtr)
235 ACPI_PARSE_OBJECT *Arg;
236 ACPI_OPERAND_OBJECT *ObjDesc;
237 ACPI_PARSE_OBJECT *ByteList;
238 UINT32 ByteListLength = 0;
241 ACPI_FUNCTION_TRACE ("DsBuildInternalBufferObj");
244 ObjDesc = *ObjDescPtr;
248 * We are evaluating a Named buffer object "Name (xxxx, Buffer)".
249 * The buffer object already exists (from the NS node)
254 /* Create a new buffer object */
256 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
257 *ObjDescPtr = ObjDesc;
260 return_ACPI_STATUS (AE_NO_MEMORY);
265 * Second arg is the buffer data (optional) ByteList can be either
266 * individual bytes or a string initializer. In either case, a
267 * ByteList appears in the AML.
269 Arg = Op->Common.Value.Arg; /* skip first arg */
271 ByteList = Arg->Named.Next;
274 if (ByteList->Common.AmlOpcode != AML_INT_BYTELIST_OP)
276 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
277 "Expecting bytelist, got AML opcode %X in op %p\n",
278 ByteList->Common.AmlOpcode, ByteList));
280 AcpiUtRemoveReference (ObjDesc);
284 ByteListLength = (UINT32) ByteList->Common.Value.Integer;
288 * The buffer length (number of bytes) will be the larger of:
289 * 1) The specified buffer length and
290 * 2) The length of the initializer byte list
292 ObjDesc->Buffer.Length = BufferLength;
293 if (ByteListLength > BufferLength)
295 ObjDesc->Buffer.Length = ByteListLength;
298 /* Allocate the buffer */
300 if (ObjDesc->Buffer.Length == 0)
302 ObjDesc->Buffer.Pointer = NULL;
303 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
304 "Buffer defined with zero length in AML, creating\n"));
308 ObjDesc->Buffer.Pointer = ACPI_MEM_CALLOCATE (
309 ObjDesc->Buffer.Length);
310 if (!ObjDesc->Buffer.Pointer)
312 AcpiUtDeleteObjectDesc (ObjDesc);
313 return_ACPI_STATUS (AE_NO_MEMORY);
316 /* Initialize buffer from the ByteList (if present) */
320 ACPI_MEMCPY (ObjDesc->Buffer.Pointer, ByteList->Named.Data,
325 ObjDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
326 Op->Common.Node = (ACPI_NAMESPACE_NODE *) ObjDesc;
327 return_ACPI_STATUS (AE_OK);
331 /*******************************************************************************
333 * FUNCTION: AcpiDsBuildInternalPackageObj
335 * PARAMETERS: WalkState - Current walk state
336 * Op - Parser object to be translated
337 * PackageLength - Number of elements in the package
338 * ObjDescPtr - Where the ACPI internal object is returned
342 * DESCRIPTION: Translate a parser Op package object to the equivalent
345 ******************************************************************************/
348 AcpiDsBuildInternalPackageObj (
349 ACPI_WALK_STATE *WalkState,
350 ACPI_PARSE_OBJECT *Op,
351 UINT32 PackageLength,
352 ACPI_OPERAND_OBJECT **ObjDescPtr)
354 ACPI_PARSE_OBJECT *Arg;
355 ACPI_PARSE_OBJECT *Parent;
356 ACPI_OPERAND_OBJECT *ObjDesc = NULL;
357 UINT32 PackageListLength;
358 ACPI_STATUS Status = AE_OK;
362 ACPI_FUNCTION_TRACE ("DsBuildInternalPackageObj");
365 /* Find the parent of a possibly nested package */
367 Parent = Op->Common.Parent;
368 while ((Parent->Common.AmlOpcode == AML_PACKAGE_OP) ||
369 (Parent->Common.AmlOpcode == AML_VAR_PACKAGE_OP))
371 Parent = Parent->Common.Parent;
374 ObjDesc = *ObjDescPtr;
378 * We are evaluating a Named package object "Name (xxxx, Package)".
379 * Get the existing package object from the NS node
384 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
385 *ObjDescPtr = ObjDesc;
388 return_ACPI_STATUS (AE_NO_MEMORY);
391 ObjDesc->Package.Node = Parent->Common.Node;
394 ObjDesc->Package.Count = PackageLength;
396 /* Count the number of items in the package list */
398 PackageListLength = 0;
399 Arg = Op->Common.Value.Arg;
400 Arg = Arg->Common.Next;
404 Arg = Arg->Common.Next;
408 * The package length (number of elements) will be the greater
409 * of the specified length and the length of the initializer list
411 if (PackageListLength > PackageLength)
413 ObjDesc->Package.Count = PackageListLength;
417 * Allocate the pointer array (array of pointers to the
418 * individual objects). Add an extra pointer slot so
419 * that the list is always null terminated.
421 ObjDesc->Package.Elements = ACPI_MEM_CALLOCATE (
422 ((ACPI_SIZE) ObjDesc->Package.Count + 1) * sizeof (void *));
424 if (!ObjDesc->Package.Elements)
426 AcpiUtDeleteObjectDesc (ObjDesc);
427 return_ACPI_STATUS (AE_NO_MEMORY);
431 * Now init the elements of the package
434 Arg = Op->Common.Value.Arg;
435 Arg = Arg->Common.Next;
438 if (Arg->Common.AmlOpcode == AML_INT_RETURN_VALUE_OP)
440 /* Object (package or buffer) is already built */
442 ObjDesc->Package.Elements[i] =
443 ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, Arg->Common.Node);
447 Status = AcpiDsBuildInternalObject (WalkState, Arg,
448 &ObjDesc->Package.Elements[i]);
452 Arg = Arg->Common.Next;
455 ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
456 Op->Common.Node = (ACPI_NAMESPACE_NODE *) ObjDesc;
457 return_ACPI_STATUS (Status);
461 /*******************************************************************************
463 * FUNCTION: AcpiDsCreateNode
465 * PARAMETERS: WalkState - Current walk state
466 * Node - NS Node to be initialized
467 * Op - Parser object to be translated
471 * DESCRIPTION: Create the object to be associated with a namespace node
473 ******************************************************************************/
477 ACPI_WALK_STATE *WalkState,
478 ACPI_NAMESPACE_NODE *Node,
479 ACPI_PARSE_OBJECT *Op)
482 ACPI_OPERAND_OBJECT *ObjDesc;
485 ACPI_FUNCTION_TRACE_PTR ("DsCreateNode", Op);
489 * Because of the execution pass through the non-control-method
490 * parts of the table, we can arrive here twice. Only init
491 * the named object node the first time through
493 if (AcpiNsGetAttachedObject (Node))
495 return_ACPI_STATUS (AE_OK);
498 if (!Op->Common.Value.Arg)
500 /* No arguments, there is nothing to do */
502 return_ACPI_STATUS (AE_OK);
505 /* Build an internal object for the argument(s) */
507 Status = AcpiDsBuildInternalObject (WalkState, Op->Common.Value.Arg,
509 if (ACPI_FAILURE (Status))
511 return_ACPI_STATUS (Status);
514 /* Re-type the object according to its argument */
516 Node->Type = ACPI_GET_OBJECT_TYPE (ObjDesc);
518 /* Attach obj to node */
520 Status = AcpiNsAttachObject (Node, ObjDesc, Node->Type);
522 /* Remove local reference to the object */
524 AcpiUtRemoveReference (ObjDesc);
525 return_ACPI_STATUS (Status);
528 #endif /* ACPI_NO_METHOD_EXECUTION */
531 /*******************************************************************************
533 * FUNCTION: AcpiDsInitObjectFromOp
535 * PARAMETERS: WalkState - Current walk state
536 * Op - Parser op used to init the internal object
537 * Opcode - AML opcode associated with the object
538 * RetObjDesc - Namespace object to be initialized
542 * DESCRIPTION: Initialize a namespace object from a parser Op and its
543 * associated arguments. The namespace object is a more compact
544 * representation of the Op and its arguments.
546 ******************************************************************************/
549 AcpiDsInitObjectFromOp (
550 ACPI_WALK_STATE *WalkState,
551 ACPI_PARSE_OBJECT *Op,
553 ACPI_OPERAND_OBJECT **RetObjDesc)
555 const ACPI_OPCODE_INFO *OpInfo;
556 ACPI_OPERAND_OBJECT *ObjDesc;
557 ACPI_STATUS Status = AE_OK;
560 ACPI_FUNCTION_TRACE ("DsInitObjectFromOp");
563 ObjDesc = *RetObjDesc;
564 OpInfo = AcpiPsGetOpcodeInfo (Opcode);
565 if (OpInfo->Class == AML_CLASS_UNKNOWN)
569 return_ACPI_STATUS (AE_TYPE);
572 /* Perform per-object initialization */
574 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
576 case ACPI_TYPE_BUFFER:
579 * Defer evaluation of Buffer TermArg operand
581 ObjDesc->Buffer.Node = (ACPI_NAMESPACE_NODE *)
582 WalkState->Operands[0];
583 ObjDesc->Buffer.AmlStart = Op->Named.Data;
584 ObjDesc->Buffer.AmlLength = Op->Named.Length;
588 case ACPI_TYPE_PACKAGE:
591 * Defer evaluation of Package TermArg operand
593 ObjDesc->Package.Node = (ACPI_NAMESPACE_NODE *)
594 WalkState->Operands[0];
595 ObjDesc->Package.AmlStart = Op->Named.Data;
596 ObjDesc->Package.AmlLength = Op->Named.Length;
600 case ACPI_TYPE_INTEGER:
602 switch (OpInfo->Type)
604 case AML_TYPE_CONSTANT:
606 * Resolve AML Constants here - AND ONLY HERE!
607 * All constants are integers.
608 * We mark the integer with a flag that indicates that it started
609 * life as a constant -- so that stores to constants will perform
610 * as expected (noop). ZeroOp is used as a placeholder for optional
613 ObjDesc->Common.Flags = AOPOBJ_AML_CONSTANT;
619 ObjDesc->Integer.Value = 0;
624 ObjDesc->Integer.Value = 1;
629 ObjDesc->Integer.Value = ACPI_INTEGER_MAX;
631 /* Truncate value if we are executing from a 32-bit ACPI table */
633 #ifndef ACPI_NO_METHOD_EXECUTION
634 AcpiExTruncateFor32bitTable (ObjDesc);
638 case AML_REVISION_OP:
640 ObjDesc->Integer.Value = ACPI_CA_VERSION;
645 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
646 "Unknown constant opcode %X\n", Opcode));
647 Status = AE_AML_OPERAND_TYPE;
653 case AML_TYPE_LITERAL:
655 ObjDesc->Integer.Value = Op->Common.Value.Integer;
656 #ifndef ACPI_NO_METHOD_EXECUTION
657 AcpiExTruncateFor32bitTable (ObjDesc);
663 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown Integer type %X\n",
665 Status = AE_AML_OPERAND_TYPE;
671 case ACPI_TYPE_STRING:
673 ObjDesc->String.Pointer = Op->Common.Value.String;
674 ObjDesc->String.Length = (UINT32) ACPI_STRLEN (Op->Common.Value.String);
677 * The string is contained in the ACPI table, don't ever try
680 ObjDesc->Common.Flags |= AOPOBJ_STATIC_POINTER;
684 case ACPI_TYPE_METHOD:
688 case ACPI_TYPE_LOCAL_REFERENCE:
690 switch (OpInfo->Type)
692 case AML_TYPE_LOCAL_VARIABLE:
694 /* Split the opcode into a base opcode + offset */
696 ObjDesc->Reference.Opcode = AML_LOCAL_OP;
697 ObjDesc->Reference.Offset = Opcode - AML_LOCAL_OP;
699 #ifndef ACPI_NO_METHOD_EXECUTION
700 Status = AcpiDsMethodDataGetNode (AML_LOCAL_OP,
701 ObjDesc->Reference.Offset,
703 (ACPI_NAMESPACE_NODE **) &ObjDesc->Reference.Object);
708 case AML_TYPE_METHOD_ARGUMENT:
710 /* Split the opcode into a base opcode + offset */
712 ObjDesc->Reference.Opcode = AML_ARG_OP;
713 ObjDesc->Reference.Offset = Opcode - AML_ARG_OP;
715 #ifndef ACPI_NO_METHOD_EXECUTION
716 Status = AcpiDsMethodDataGetNode (AML_ARG_OP,
717 ObjDesc->Reference.Offset,
719 (ACPI_NAMESPACE_NODE **) &ObjDesc->Reference.Object);
723 default: /* Other literals, etc.. */
725 if (Op->Common.AmlOpcode == AML_INT_NAMEPATH_OP)
727 /* Node was saved in Op */
729 ObjDesc->Reference.Node = Op->Common.Node;
732 ObjDesc->Reference.Opcode = Opcode;
740 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unimplemented data type: %X\n",
741 ACPI_GET_OBJECT_TYPE (ObjDesc)));
743 Status = AE_AML_OPERAND_TYPE;
747 return_ACPI_STATUS (Status);