xref: /onnv-gate/usr/src/uts/intel/io/acpica/disassembler/dmutils.c (revision 9980:13d7f3eec672)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: dmutils - AML disassembler utilities
43446Smrj  *
53446Smrj  ******************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
11*9980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj 
1173446Smrj #include "acpi.h"
118*9980SDana.Myers@Sun.COM #include "accommon.h"
1193446Smrj #include "amlcode.h"
1203446Smrj #include "acdisasm.h"
1213446Smrj 
1223446Smrj #ifdef ACPI_ASL_COMPILER
1233446Smrj #include <acnamesp.h>
1243446Smrj #endif
1253446Smrj 
1263446Smrj #ifdef ACPI_DISASSEMBLER
1273446Smrj 
1283446Smrj #define _COMPONENT          ACPI_CA_DEBUGGER
1293446Smrj         ACPI_MODULE_NAME    ("dmutils")
1303446Smrj 
1313446Smrj 
1323446Smrj ACPI_EXTERNAL_LIST              *AcpiGbl_ExternalList = NULL;
1333446Smrj 
1343446Smrj 
1353446Smrj /* Data used in keeping track of fields */
1363446Smrj #if 0
1373446Smrj const char                      *AcpiGbl_FENames[] =
1383446Smrj {
1393446Smrj     "skip",
1403446Smrj     "?access?"
1413446Smrj };              /* FE = Field Element */
1423446Smrj #endif
1433446Smrj 
1443446Smrj /* Operators for Match() */
1453446Smrj 
1463446Smrj const char                      *AcpiGbl_MatchOps[] =
1473446Smrj {
1483446Smrj     "MTR",
1493446Smrj     "MEQ",
1503446Smrj     "MLE",
1513446Smrj     "MLT",
1523446Smrj     "MGE",
1533446Smrj     "MGT"
1543446Smrj };
1553446Smrj 
1563446Smrj /* Access type decoding */
1573446Smrj 
1583446Smrj const char                      *AcpiGbl_AccessTypes[] =
1593446Smrj {
1603446Smrj     "AnyAcc",
1613446Smrj     "ByteAcc",
1623446Smrj     "WordAcc",
1633446Smrj     "DWordAcc",
1643446Smrj     "QWordAcc",
1653446Smrj     "BufferAcc",
1663446Smrj     "InvalidAccType",
1673446Smrj     "InvalidAccType"
1683446Smrj };
1693446Smrj 
1703446Smrj /* Lock rule decoding */
1713446Smrj 
1723446Smrj const char                      *AcpiGbl_LockRule[] =
1733446Smrj {
1743446Smrj     "NoLock",
1753446Smrj     "Lock"
1763446Smrj };
1773446Smrj 
1783446Smrj /* Update rule decoding */
1793446Smrj 
1803446Smrj const char                      *AcpiGbl_UpdateRules[] =
1813446Smrj {
1823446Smrj     "Preserve",
1833446Smrj     "WriteAsOnes",
1843446Smrj     "WriteAsZeros",
1853446Smrj     "InvalidUpdateRule"
1863446Smrj };
1873446Smrj 
1883446Smrj /* Strings used to decode resource descriptors */
1893446Smrj 
1903446Smrj const char                      *AcpiGbl_WordDecode[] =
1913446Smrj {
1923446Smrj     "Memory",
1933446Smrj     "IO",
1943446Smrj     "BusNumber",
1953446Smrj     "UnknownResourceType"
1963446Smrj };
1973446Smrj 
1983446Smrj const char                      *AcpiGbl_IrqDecode[] =
1993446Smrj {
2003446Smrj     "IRQNoFlags",
2013446Smrj     "IRQ"
2023446Smrj };
2033446Smrj 
2043446Smrj 
2053446Smrj #ifdef ACPI_ASL_COMPILER
2063446Smrj /*******************************************************************************
2073446Smrj  *
2083446Smrj  * FUNCTION:    AcpiDmAddToExternalList
2093446Smrj  *
2103446Smrj  * PARAMETERS:  Path            - Internal (AML) path to the object
2113446Smrj  *
2123446Smrj  * RETURN:      None
2133446Smrj  *
2143446Smrj  * DESCRIPTION: Insert a new path into the list of Externals which will in
2153446Smrj  *              turn be emitted as an External() declaration in the disassembled
2163446Smrj  *              output.
2173446Smrj  *
2183446Smrj  ******************************************************************************/
2193446Smrj 
2203446Smrj void
2213446Smrj AcpiDmAddToExternalList (
2223446Smrj     char                    *Path,
2233446Smrj     UINT8                   Type,
2243446Smrj     UINT32                  Value)
2253446Smrj {
2263446Smrj     char                    *ExternalPath;
2273446Smrj     ACPI_EXTERNAL_LIST      *NewExternal;
2283446Smrj     ACPI_EXTERNAL_LIST      *NextExternal;
2293446Smrj     ACPI_EXTERNAL_LIST      *PrevExternal = NULL;
2303446Smrj     ACPI_STATUS             Status;
2313446Smrj 
2323446Smrj 
2333446Smrj     if (!Path)
2343446Smrj     {
2353446Smrj         return;
2363446Smrj     }
2373446Smrj 
2383446Smrj     /* Externalize the ACPI path */
2393446Smrj 
2403446Smrj     Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Path,
2413446Smrj                     NULL, &ExternalPath);
2423446Smrj     if (ACPI_FAILURE (Status))
2433446Smrj     {
2443446Smrj         return;
2453446Smrj     }
2463446Smrj 
2473446Smrj     /* Ensure that we don't have duplicate externals */
2483446Smrj 
2493446Smrj     NextExternal = AcpiGbl_ExternalList;
2503446Smrj     while (NextExternal)
2513446Smrj     {
2523446Smrj         /* Allow upgrade of type from ANY */
2533446Smrj 
2543446Smrj         if (!ACPI_STRCMP (ExternalPath, NextExternal->Path))
2553446Smrj         {
2563446Smrj             /* Duplicate method, check that the Value (ArgCount) is the same */
2573446Smrj 
2583446Smrj             if ((NextExternal->Type == ACPI_TYPE_METHOD) &&
2593446Smrj                 (NextExternal->Value != Value))
2603446Smrj             {
2613446Smrj                 ACPI_ERROR ((AE_INFO, "Argument count mismatch for method %s %d %d",
2623446Smrj                     NextExternal->Path, NextExternal->Value, Value));
2633446Smrj             }
2643446Smrj             if (NextExternal->Type == ACPI_TYPE_ANY)
2653446Smrj             {
2663446Smrj                 NextExternal->Type = Type;
2673446Smrj                 NextExternal->Value = Value;
2683446Smrj             }
2693446Smrj             ACPI_FREE (ExternalPath);
2703446Smrj             return;
2713446Smrj         }
2723446Smrj         NextExternal = NextExternal->Next;
2733446Smrj     }
2743446Smrj 
2753446Smrj     /* Allocate and init a new External() descriptor */
2763446Smrj 
2773446Smrj     NewExternal = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EXTERNAL_LIST));
2783446Smrj     NewExternal->InternalPath = Path;
2793446Smrj     NewExternal->Path = ExternalPath;
2803446Smrj     NewExternal->Type = Type;
2813446Smrj     NewExternal->Value = Value;
2823446Smrj     NewExternal->Length = (UINT16) ACPI_STRLEN (ExternalPath);
2833446Smrj 
2843446Smrj     /* Link the new descriptor into the global list, ordered by string length */
2853446Smrj 
2863446Smrj     NextExternal = AcpiGbl_ExternalList;
2873446Smrj     while (NextExternal)
2883446Smrj     {
2893446Smrj         if (NewExternal->Length <= NextExternal->Length)
2903446Smrj         {
2913446Smrj             if (PrevExternal)
2923446Smrj             {
2933446Smrj                 PrevExternal->Next = NewExternal;
2943446Smrj             }
2953446Smrj             else
2963446Smrj             {
2973446Smrj                 AcpiGbl_ExternalList = NewExternal;
2983446Smrj             }
2993446Smrj 
3003446Smrj             NewExternal->Next = NextExternal;
3013446Smrj             return;
3023446Smrj         }
3033446Smrj 
3043446Smrj         PrevExternal = NextExternal;
3053446Smrj         NextExternal = NextExternal->Next;
3063446Smrj     }
3073446Smrj 
3083446Smrj     if (PrevExternal)
3093446Smrj     {
3103446Smrj         PrevExternal->Next = NewExternal;
3113446Smrj     }
3123446Smrj     else
3133446Smrj     {
3143446Smrj         AcpiGbl_ExternalList = NewExternal;
3153446Smrj     }
3163446Smrj }
3173446Smrj #endif
3183446Smrj 
3193446Smrj 
3203446Smrj /*******************************************************************************
3213446Smrj  *
3223446Smrj  * FUNCTION:    AcpiDmDecodeAttribute
3233446Smrj  *
3243446Smrj  * PARAMETERS:  Attribute       - Attribute field of AccessAs keyword
3253446Smrj  *
3263446Smrj  * RETURN:      None
3273446Smrj  *
3283446Smrj  * DESCRIPTION: Decode the AccessAs attribute byte.  (Mostly SMBus stuff)
3293446Smrj  *
3303446Smrj  ******************************************************************************/
3313446Smrj 
3323446Smrj void
3333446Smrj AcpiDmDecodeAttribute (
3343446Smrj     UINT8                   Attribute)
3353446Smrj {
3363446Smrj 
3373446Smrj     switch (Attribute)
3383446Smrj     {
3393446Smrj     case AML_FIELD_ATTRIB_SMB_QUICK:
3403446Smrj 
3413446Smrj         AcpiOsPrintf ("SMBQuick");
3423446Smrj         break;
3433446Smrj 
3443446Smrj     case AML_FIELD_ATTRIB_SMB_SEND_RCV:
3453446Smrj 
3463446Smrj         AcpiOsPrintf ("SMBSendReceive");
3473446Smrj         break;
3483446Smrj 
3493446Smrj     case AML_FIELD_ATTRIB_SMB_BYTE:
3503446Smrj 
3513446Smrj         AcpiOsPrintf ("SMBByte");
3523446Smrj         break;
3533446Smrj 
3543446Smrj     case AML_FIELD_ATTRIB_SMB_WORD:
3553446Smrj 
3563446Smrj         AcpiOsPrintf ("SMBWord");
3573446Smrj         break;
3583446Smrj 
3593446Smrj     case AML_FIELD_ATTRIB_SMB_WORD_CALL:
3603446Smrj 
3613446Smrj         AcpiOsPrintf ("SMBProcessCall");
3623446Smrj         break;
3633446Smrj 
3643446Smrj     case AML_FIELD_ATTRIB_SMB_BLOCK:
3653446Smrj 
3663446Smrj         AcpiOsPrintf ("SMBBlock");
3673446Smrj         break;
3683446Smrj 
3693446Smrj     case AML_FIELD_ATTRIB_SMB_BLOCK_CALL:
3703446Smrj 
3713446Smrj         AcpiOsPrintf ("SMBBlockProcessCall");
3723446Smrj         break;
3733446Smrj 
3743446Smrj     default:
3753446Smrj 
3763446Smrj         AcpiOsPrintf ("0x%.2X", Attribute);
3773446Smrj         break;
3783446Smrj     }
3793446Smrj }
3803446Smrj 
3813446Smrj 
3823446Smrj /*******************************************************************************
3833446Smrj  *
3843446Smrj  * FUNCTION:    AcpiDmIndent
3853446Smrj  *
3863446Smrj  * PARAMETERS:  Level               - Current source code indentation level
3873446Smrj  *
3883446Smrj  * RETURN:      None
3893446Smrj  *
3903446Smrj  * DESCRIPTION: Indent 4 spaces per indentation level.
3913446Smrj  *
3923446Smrj  ******************************************************************************/
3933446Smrj 
3943446Smrj void
3953446Smrj AcpiDmIndent (
3963446Smrj     UINT32                  Level)
3973446Smrj {
3983446Smrj 
3993446Smrj     if (!Level)
4003446Smrj     {
4013446Smrj         return;
4023446Smrj     }
4033446Smrj 
4043446Smrj     AcpiOsPrintf ("%*.s", ACPI_MUL_4 (Level), " ");
4053446Smrj }
4063446Smrj 
4073446Smrj 
4083446Smrj /*******************************************************************************
4093446Smrj  *
4103446Smrj  * FUNCTION:    AcpiDmCommaIfListMember
4113446Smrj  *
4123446Smrj  * PARAMETERS:  Op              - Current operator/operand
4133446Smrj  *
4143446Smrj  * RETURN:      TRUE if a comma was inserted
4153446Smrj  *
4163446Smrj  * DESCRIPTION: Insert a comma if this Op is a member of an argument list.
4173446Smrj  *
4183446Smrj  ******************************************************************************/
4193446Smrj 
4203446Smrj BOOLEAN
4213446Smrj AcpiDmCommaIfListMember (
4223446Smrj     ACPI_PARSE_OBJECT       *Op)
4233446Smrj {
4243446Smrj 
4253446Smrj     if (!Op->Common.Next)
4263446Smrj     {
4273446Smrj         return FALSE;
4283446Smrj     }
4293446Smrj 
4303446Smrj     if (AcpiDmListType (Op->Common.Parent) & BLOCK_COMMA_LIST)
4313446Smrj     {
4323446Smrj         /* Check for a NULL target operand */
4333446Smrj 
4343446Smrj         if ((Op->Common.Next->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&
4353446Smrj             (!Op->Common.Next->Common.Value.String))
4363446Smrj         {
4373446Smrj             /*
4383446Smrj              * To handle the Divide() case where there are two optional
4393446Smrj              * targets, look ahead one more op.  If null, this null target
4403446Smrj              * is the one and only target -- no comma needed.  Otherwise,
4413446Smrj              * we need a comma to prepare for the next target.
4423446Smrj              */
4433446Smrj             if (!Op->Common.Next->Common.Next)
4443446Smrj             {
4453446Smrj                 return FALSE;
4463446Smrj             }
4473446Smrj         }
4483446Smrj 
4493446Smrj         if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST) &&
4503446Smrj             (!(Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST)))
4513446Smrj         {
4523446Smrj             return FALSE;
4533446Smrj         }
4543446Smrj 
4553446Smrj         AcpiOsPrintf (", ");
4563446Smrj         return (TRUE);
4573446Smrj     }
4583446Smrj 
4593446Smrj     else if ((Op->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST) &&
4603446Smrj              (Op->Common.Next->Common.DisasmFlags & ACPI_PARSEOP_PARAMLIST))
4613446Smrj     {
4623446Smrj         AcpiOsPrintf (", ");
4633446Smrj         return (TRUE);
4643446Smrj     }
4653446Smrj 
4663446Smrj     return (FALSE);
4673446Smrj }
4683446Smrj 
4693446Smrj 
4703446Smrj /*******************************************************************************
4713446Smrj  *
4723446Smrj  * FUNCTION:    AcpiDmCommaIfFieldMember
4733446Smrj  *
4743446Smrj  * PARAMETERS:  Op              - Current operator/operand
4753446Smrj  *
4763446Smrj  * RETURN:      None
4773446Smrj  *
4783446Smrj  * DESCRIPTION: Insert a comma if this Op is a member of a Field argument list.
4793446Smrj  *
4803446Smrj  ******************************************************************************/
4813446Smrj 
4823446Smrj void
4833446Smrj AcpiDmCommaIfFieldMember (
4843446Smrj     ACPI_PARSE_OBJECT       *Op)
4853446Smrj {
4863446Smrj 
4873446Smrj     if (Op->Common.Next)
4883446Smrj     {
4893446Smrj         AcpiOsPrintf (", ");
4903446Smrj     }
4913446Smrj }
4923446Smrj 
4933446Smrj #endif
494