1 /******************************************************************************
3 * Module Name: dmextern - Support for External() ASL statements
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, 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 #include <contrib/dev/acpica/include/acpi.h>
117 #include <contrib/dev/acpica/include/accommon.h>
118 #include <contrib/dev/acpica/include/amlcode.h>
119 #include <contrib/dev/acpica/include/acnamesp.h>
120 #include <contrib/dev/acpica/include/acdisasm.h>
124 * This module is used for application-level code (iASL disassembler) only.
126 * It contains the code to create and emit any necessary External() ASL
127 * statements for the module being disassembled.
129 #define _COMPONENT ACPI_CA_DISASSEMBLER
130 ACPI_MODULE_NAME ("dmextern")
134 * This table maps ACPI_OBJECT_TYPEs to the corresponding ASL
135 * ObjectTypeKeyword. Used to generate typed external declarations
137 static const char *AcpiGbl_DmTypeNames[] =
139 /* 00 */ "", /* Type ANY */
142 /* 03 */ ", BuffObj",
144 /* 05 */ ", FieldUnitObj",
145 /* 06 */ ", DeviceObj",
146 /* 07 */ ", EventObj",
147 /* 08 */ ", MethodObj",
148 /* 09 */ ", MutexObj",
149 /* 10 */ ", OpRegionObj",
150 /* 11 */ ", PowerResObj",
151 /* 12 */ ", ProcessorObj",
152 /* 13 */ ", ThermalZoneObj",
153 /* 14 */ ", BuffFieldObj",
154 /* 15 */ ", DDBHandleObj",
155 /* 16 */ "", /* Debug object */
156 /* 17 */ ", FieldUnitObj",
157 /* 18 */ ", FieldUnitObj",
158 /* 19 */ ", FieldUnitObj"
162 /* Local prototypes */
165 AcpiDmGetObjectTypeName (
166 ACPI_OBJECT_TYPE Type);
169 AcpiDmNormalizeParentPrefix (
170 ACPI_PARSE_OBJECT *Op,
174 /*******************************************************************************
176 * FUNCTION: AcpiDmGetObjectTypeName
178 * PARAMETERS: Type - An ACPI_OBJECT_TYPE
180 * RETURN: Pointer to a string
182 * DESCRIPTION: Map an object type to the ASL object type string.
184 ******************************************************************************/
187 AcpiDmGetObjectTypeName (
188 ACPI_OBJECT_TYPE Type)
191 if (Type == ACPI_TYPE_LOCAL_SCOPE)
193 Type = ACPI_TYPE_DEVICE;
196 else if (Type > ACPI_TYPE_LOCAL_INDEX_FIELD)
201 return (AcpiGbl_DmTypeNames[Type]);
205 /*******************************************************************************
207 * FUNCTION: AcpiDmNormalizeParentPrefix
209 * PARAMETERS: Op - Parse op
210 * Path - Path with parent prefix
212 * RETURN: The full pathname to the object (from the namespace root)
214 * DESCRIPTION: Returns the full pathname of a path with parent prefix
215 * The caller must free the fullpath returned.
217 ******************************************************************************/
220 AcpiDmNormalizeParentPrefix (
221 ACPI_PARSE_OBJECT *Op,
224 ACPI_NAMESPACE_NODE *Node;
230 /* Search upwards in the parse tree until we reach a namespace node */
239 Op = Op->Common.Parent;
248 * Find the actual parent node for the reference:
249 * Remove all carat prefixes from the input path.
250 * There may be multiple parent prefixes (For example, ^^^M000)
252 Node = Op->Common.Node;
253 while (Node && (*Path == (UINT8) AML_PARENT_PREFIX))
255 Node = AcpiNsGetParentNode (Node);
264 /* Get the full pathname for the parent node */
266 ParentPath = AcpiNsGetExternalPathname (Node);
272 Length = (ACPI_STRLEN (ParentPath) + ACPI_STRLEN (Path) + 1);
276 * If ParentPath is not just a simple '\', increment the length
277 * for the required dot separator (ParentPath.Path)
282 Fullpath = ACPI_ALLOCATE_ZEROED (Length);
289 * Concatenate parent fullpath and path. For example,
290 * parent fullpath "\_SB_", Path "^INIT", Fullpath "\_SB_.INIT"
292 * Copy the parent path
294 ACPI_STRCAT (Fullpath, ParentPath);
296 /* Add dot separator (don't need dot if parent fullpath is a single "\") */
300 ACPI_STRCAT (Fullpath, ".");
303 /* Copy child path (carat parent prefix(es) were skipped above) */
305 ACPI_STRCAT (Fullpath, Path);
308 ACPI_FREE (ParentPath);
313 /*******************************************************************************
315 * FUNCTION: AcpiDmAddToExternalList
317 * PARAMETERS: Op - Current parser Op
318 * Path - Internal (AML) path to the object
319 * Type - ACPI object type to be added
320 * Value - Arg count if adding a Method object
324 * DESCRIPTION: Insert a new name into the global list of Externals which
325 * will in turn be later emitted as an External() declaration
326 * in the disassembled output.
328 ******************************************************************************/
331 AcpiDmAddToExternalList (
332 ACPI_PARSE_OBJECT *Op,
338 char *Fullpath = NULL;
339 ACPI_EXTERNAL_LIST *NewExternal;
340 ACPI_EXTERNAL_LIST *NextExternal;
341 ACPI_EXTERNAL_LIST *PrevExternal = NULL;
350 /* Externalize the ACPI path */
352 Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Path,
353 NULL, &ExternalPath);
354 if (ACPI_FAILURE (Status))
359 /* Get the full pathname from root if "Path" has a parent prefix */
361 if (*Path == (UINT8) AML_PARENT_PREFIX)
363 Fullpath = AcpiDmNormalizeParentPrefix (Op, ExternalPath);
366 /* Set new external path */
368 ACPI_FREE (ExternalPath);
369 ExternalPath = Fullpath;
373 /* Check all existing externals to ensure no duplicates */
375 NextExternal = AcpiGbl_ExternalList;
378 if (!ACPI_STRCMP (ExternalPath, NextExternal->Path))
380 /* Duplicate method, check that the Value (ArgCount) is the same */
382 if ((NextExternal->Type == ACPI_TYPE_METHOD) &&
383 (NextExternal->Value != Value))
385 ACPI_ERROR ((AE_INFO,
386 "Argument count mismatch for method %s %u %u",
387 NextExternal->Path, NextExternal->Value, Value));
390 /* Allow upgrade of type from ANY */
392 else if (NextExternal->Type == ACPI_TYPE_ANY)
394 NextExternal->Type = Type;
395 NextExternal->Value = Value;
398 ACPI_FREE (ExternalPath);
402 NextExternal = NextExternal->Next;
405 /* Allocate and init a new External() descriptor */
407 NewExternal = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EXTERNAL_LIST));
410 ACPI_FREE (ExternalPath);
414 NewExternal->Path = ExternalPath;
415 NewExternal->Type = Type;
416 NewExternal->Value = Value;
417 NewExternal->Length = (UINT16) ACPI_STRLEN (ExternalPath);
419 /* Was the external path with parent prefix normalized to a fullpath? */
421 if (Fullpath == ExternalPath)
423 /* Get new internal path */
425 Status = AcpiNsInternalizeName (ExternalPath, &Path);
426 if (ACPI_FAILURE (Status))
428 ACPI_FREE (ExternalPath);
429 ACPI_FREE (NewExternal);
433 /* Set flag to indicate External->InternalPath need to be freed */
435 NewExternal->Flags |= ACPI_IPATH_ALLOCATED;
438 NewExternal->InternalPath = Path;
440 /* Link the new descriptor into the global list, ordered by string length */
442 NextExternal = AcpiGbl_ExternalList;
445 if (NewExternal->Length <= NextExternal->Length)
449 PrevExternal->Next = NewExternal;
453 AcpiGbl_ExternalList = NewExternal;
456 NewExternal->Next = NextExternal;
460 PrevExternal = NextExternal;
461 NextExternal = NextExternal->Next;
466 PrevExternal->Next = NewExternal;
470 AcpiGbl_ExternalList = NewExternal;
475 /*******************************************************************************
477 * FUNCTION: AcpiDmAddExternalsToNamespace
483 * DESCRIPTION: Add all externals to the namespace. Allows externals to be
486 ******************************************************************************/
489 AcpiDmAddExternalsToNamespace (
493 ACPI_NAMESPACE_NODE *Node;
494 ACPI_OPERAND_OBJECT *MethodDesc;
495 ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
500 /* Add the external name (object) into the namespace */
502 Status = AcpiNsLookup (NULL, External->InternalPath, External->Type,
503 ACPI_IMODE_LOAD_PASS1,
504 ACPI_NS_EXTERNAL | ACPI_NS_DONT_OPEN_SCOPE,
507 if (ACPI_FAILURE (Status))
509 ACPI_EXCEPTION ((AE_INFO, Status,
510 "while adding external to namespace [%s]",
513 else if (External->Type == ACPI_TYPE_METHOD)
515 /* For methods, we need to save the argument count */
517 MethodDesc = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
518 MethodDesc->Method.ParamCount = (UINT8) External->Value;
519 Node->Object = MethodDesc;
522 External = External->Next;
527 /*******************************************************************************
529 * FUNCTION: AcpiDmGetExternalMethodCount
533 * RETURN: The number of control method externals in the external list
535 * DESCRIPTION: Return the number of method externals that have been generated.
536 * If any control method externals have been found, we must
537 * re-parse the entire definition block with the new information
538 * (number of arguments for the methods.) This is limitation of
539 * AML, we don't know the number of arguments from the control
540 * method invocation itself.
542 ******************************************************************************/
545 AcpiDmGetExternalMethodCount (
548 ACPI_EXTERNAL_LIST *External = AcpiGbl_ExternalList;
554 if (External->Type == ACPI_TYPE_METHOD)
559 External = External->Next;
566 /*******************************************************************************
568 * FUNCTION: AcpiDmClearExternalList
574 * DESCRIPTION: Free the entire External info list
576 ******************************************************************************/
579 AcpiDmClearExternalList (
582 ACPI_EXTERNAL_LIST *NextExternal;
585 while (AcpiGbl_ExternalList)
587 NextExternal = AcpiGbl_ExternalList->Next;
588 ACPI_FREE (AcpiGbl_ExternalList->Path);
589 ACPI_FREE (AcpiGbl_ExternalList);
590 AcpiGbl_ExternalList = NextExternal;
595 /*******************************************************************************
597 * FUNCTION: AcpiDmEmitExternals
603 * DESCRIPTION: Emit an External() ASL statement for each of the externals in
604 * the global external info list.
606 ******************************************************************************/
609 AcpiDmEmitExternals (
612 ACPI_EXTERNAL_LIST *NextExternal;
615 if (!AcpiGbl_ExternalList)
621 * Walk the list of externals (unresolved references)
622 * found during the AML parsing
624 while (AcpiGbl_ExternalList)
626 AcpiOsPrintf (" External (%s%s",
627 AcpiGbl_ExternalList->Path,
628 AcpiDmGetObjectTypeName (AcpiGbl_ExternalList->Type));
630 if (AcpiGbl_ExternalList->Type == ACPI_TYPE_METHOD)
632 AcpiOsPrintf (") // %d Arguments\n",
633 AcpiGbl_ExternalList->Value);
637 AcpiOsPrintf (")\n");
640 /* Free this external info block and move on to next external */
642 NextExternal = AcpiGbl_ExternalList->Next;
643 if (AcpiGbl_ExternalList->Flags & ACPI_IPATH_ALLOCATED)
645 ACPI_FREE (AcpiGbl_ExternalList->InternalPath);
648 ACPI_FREE (AcpiGbl_ExternalList->Path);
649 ACPI_FREE (AcpiGbl_ExternalList);
650 AcpiGbl_ExternalList = NextExternal;