xref: /onnv-gate/usr/src/uts/intel/io/acpica/disassembler/dmresrc.c (revision 9980:13d7f3eec672)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: dmresrc.c - Resource Descriptor disassembly
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_DISASSEMBLER
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_CA_DEBUGGER
1253446Smrj         ACPI_MODULE_NAME    ("dbresrc")
1263446Smrj 
1273446Smrj 
1283446Smrj /* Dispatch tables for Resource disassembly functions */
1293446Smrj 
1303446Smrj typedef
1313446Smrj void (*ACPI_RESOURCE_HANDLER) (
1323446Smrj     AML_RESOURCE            *Resource,
1333446Smrj     UINT32                  Length,
1343446Smrj     UINT32                  Level);
1353446Smrj 
1367851SDana.Myers@Sun.COM static ACPI_RESOURCE_HANDLER    AcpiGbl_DmResourceDispatch [] =
1373446Smrj {
1383446Smrj     /* Small descriptors */
1393446Smrj 
1403446Smrj     NULL,                           /* 0x00, Reserved */
1413446Smrj     NULL,                           /* 0x01, Reserved */
1423446Smrj     NULL,                           /* 0x02, Reserved */
1433446Smrj     NULL,                           /* 0x03, Reserved */
1443446Smrj     AcpiDmIrqDescriptor,            /* 0x04, ACPI_RESOURCE_NAME_IRQ_FORMAT */
1453446Smrj     AcpiDmDmaDescriptor,            /* 0x05, ACPI_RESOURCE_NAME_DMA_FORMAT */
1463446Smrj     AcpiDmStartDependentDescriptor, /* 0x06, ACPI_RESOURCE_NAME_START_DEPENDENT */
1473446Smrj     AcpiDmEndDependentDescriptor,   /* 0x07, ACPI_RESOURCE_NAME_END_DEPENDENT */
1483446Smrj     AcpiDmIoDescriptor,             /* 0x08, ACPI_RESOURCE_NAME_IO_PORT */
1493446Smrj     AcpiDmFixedIoDescriptor,        /* 0x09, ACPI_RESOURCE_NAME_FIXED_IO_PORT */
1503446Smrj     NULL,                           /* 0x0A, Reserved */
1513446Smrj     NULL,                           /* 0x0B, Reserved */
1523446Smrj     NULL,                           /* 0x0C, Reserved */
1533446Smrj     NULL,                           /* 0x0D, Reserved */
1543446Smrj     AcpiDmVendorSmallDescriptor,    /* 0x0E, ACPI_RESOURCE_NAME_SMALL_VENDOR */
1553446Smrj     NULL,                           /* 0x0F, ACPI_RESOURCE_NAME_END_TAG (not used) */
1563446Smrj 
1573446Smrj     /* Large descriptors */
1583446Smrj 
1593446Smrj     NULL,                           /* 0x00, Reserved */
1603446Smrj     AcpiDmMemory24Descriptor,       /* 0x01, ACPI_RESOURCE_NAME_MEMORY_24 */
1613446Smrj     AcpiDmGenericRegisterDescriptor,/* 0x02, ACPI_RESOURCE_NAME_GENERIC_REGISTER */
1623446Smrj     NULL,                           /* 0x03, Reserved */
1633446Smrj     AcpiDmVendorLargeDescriptor,    /* 0x04, ACPI_RESOURCE_NAME_LARGE_VENDOR */
1643446Smrj     AcpiDmMemory32Descriptor,       /* 0x05, ACPI_RESOURCE_NAME_MEMORY_32 */
1653446Smrj     AcpiDmFixedMemory32Descriptor,  /* 0x06, ACPI_RESOURCE_NAME_FIXED_MEMORY_32 */
1663446Smrj     AcpiDmDwordDescriptor,          /* 0x07, ACPI_RESOURCE_NAME_DWORD_ADDRESS_SPACE */
1673446Smrj     AcpiDmWordDescriptor,           /* 0x08, ACPI_RESOURCE_NAME_WORD_ADDRESS_SPACE */
1683446Smrj     AcpiDmInterruptDescriptor,      /* 0x09, ACPI_RESOURCE_NAME_EXTENDED_XRUPT */
1693446Smrj     AcpiDmQwordDescriptor,          /* 0x0A, ACPI_RESOURCE_NAME_QWORD_ADDRESS_SPACE */
1703446Smrj     AcpiDmExtendedDescriptor        /* 0x0B, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS_SPACE */
1713446Smrj };
1723446Smrj 
1733446Smrj 
1743446Smrj /* Only used for single-threaded applications */
1753446Smrj /* TBD: remove when name is passed as parameter to the dump functions */
1763446Smrj 
1773446Smrj static UINT32               ResourceName;
1783446Smrj 
1793446Smrj 
1803446Smrj /*******************************************************************************
1813446Smrj  *
1823446Smrj  * FUNCTION:    AcpiDmDescriptorName
1833446Smrj  *
1843446Smrj  * PARAMETERS:  None
1853446Smrj  *
1863446Smrj  * RETURN:      None
1873446Smrj  *
1883446Smrj  * DESCRIPTION: Emit a name for the descriptor if one is present (indicated
1893446Smrj  *              by the name being changed from the default name.) A name is only
1903446Smrj  *              emitted if a reference to the descriptor has been made somewhere
1913446Smrj  *              in the original ASL code.
1923446Smrj  *
1933446Smrj  ******************************************************************************/
1943446Smrj 
1953446Smrj void
AcpiDmDescriptorName(void)1963446Smrj AcpiDmDescriptorName (
1973446Smrj     void)
1983446Smrj {
1993446Smrj 
2003446Smrj     if (ResourceName == ACPI_DEFAULT_RESNAME)
2013446Smrj     {
2023446Smrj         return;
2033446Smrj     }
2043446Smrj 
2053446Smrj     AcpiOsPrintf ("%4.4s", (char *) &ResourceName);
2063446Smrj }
2073446Smrj 
2083446Smrj 
2093446Smrj /*******************************************************************************
2103446Smrj  *
2113446Smrj  * FUNCTION:    AcpiDmDumpInteger*
2123446Smrj  *
2133446Smrj  * PARAMETERS:  Value               - Value to emit
2143446Smrj  *              Name                - Associated name (emitted as a comment)
2153446Smrj  *
2163446Smrj  * RETURN:      None
2173446Smrj  *
2183446Smrj  * DESCRIPTION: Integer output helper functions
2193446Smrj  *
2203446Smrj  ******************************************************************************/
2213446Smrj 
2223446Smrj void
AcpiDmDumpInteger8(UINT8 Value,char * Name)2233446Smrj AcpiDmDumpInteger8 (
2243446Smrj     UINT8                   Value,
2253446Smrj     char                    *Name)
2263446Smrj {
2273446Smrj     AcpiOsPrintf ("0x%2.2X,               // %s\n", Value, Name);
2283446Smrj }
2293446Smrj 
2303446Smrj void
AcpiDmDumpInteger16(UINT16 Value,char * Name)2313446Smrj AcpiDmDumpInteger16 (
2323446Smrj     UINT16                  Value,
2333446Smrj     char                    *Name)
2343446Smrj {
2353446Smrj     AcpiOsPrintf ("0x%4.4X,             // %s\n", Value, Name);
2363446Smrj }
2373446Smrj 
2383446Smrj void
AcpiDmDumpInteger32(UINT32 Value,char * Name)2393446Smrj AcpiDmDumpInteger32 (
2403446Smrj     UINT32                  Value,
2413446Smrj     char                    *Name)
2423446Smrj {
2433446Smrj     AcpiOsPrintf ("0x%8.8X,         // %s\n", Value, Name);
2443446Smrj }
2453446Smrj 
2463446Smrj void
AcpiDmDumpInteger64(UINT64 Value,char * Name)2473446Smrj AcpiDmDumpInteger64 (
2483446Smrj     UINT64                  Value,
2493446Smrj     char                    *Name)
2503446Smrj {
2517851SDana.Myers@Sun.COM     AcpiOsPrintf ("0x%8.8X%8.8X, // %s\n", ACPI_FORMAT_UINT64 (Value), Name);
2523446Smrj }
2533446Smrj 
2543446Smrj 
2553446Smrj /*******************************************************************************
2563446Smrj  *
2573446Smrj  * FUNCTION:    AcpiDmBitList
2583446Smrj  *
2593446Smrj  * PARAMETERS:  Mask            - 16-bit value corresponding to 16 interrupt
2603446Smrj  *                                or DMA values
2613446Smrj  *
2623446Smrj  * RETURN:      None
2633446Smrj  *
2643446Smrj  * DESCRIPTION: Dump a bit mask as a list of individual interrupt/DMA levels.
2653446Smrj  *
2663446Smrj  ******************************************************************************/
2673446Smrj 
2683446Smrj void
AcpiDmBitList(UINT16 Mask)2693446Smrj AcpiDmBitList (
2703446Smrj     UINT16                  Mask)
2713446Smrj {
2723446Smrj     UINT32                  i;
2733446Smrj     BOOLEAN                 Previous = FALSE;
2743446Smrj 
2753446Smrj 
2763446Smrj     /* Open the initializer list */
2773446Smrj 
2783446Smrj     AcpiOsPrintf ("{");
2793446Smrj 
2803446Smrj     /* Examine each bit */
2813446Smrj 
2823446Smrj     for (i = 0; i < 16; i++)
2833446Smrj     {
2843446Smrj         /* Only interested in bits that are set to 1 */
2853446Smrj 
2863446Smrj         if (Mask & 1)
2873446Smrj         {
2883446Smrj             if (Previous)
2893446Smrj             {
2903446Smrj                 AcpiOsPrintf (",");
2913446Smrj             }
2923446Smrj             Previous = TRUE;
2933446Smrj             AcpiOsPrintf ("%d", i);
2943446Smrj         }
2953446Smrj 
2963446Smrj         Mask >>= 1;
2973446Smrj     }
2983446Smrj 
2993446Smrj     /* Close list */
3003446Smrj 
3013446Smrj     AcpiOsPrintf ("}\n");
3023446Smrj }
3033446Smrj 
3043446Smrj 
3053446Smrj /*******************************************************************************
3063446Smrj  *
3073446Smrj  * FUNCTION:    AcpiDmResourceTemplate
3083446Smrj  *
3093446Smrj  * PARAMETERS:  Info            - Curent parse tree walk info
3103446Smrj  *              ByteData        - Pointer to the byte list data
3113446Smrj  *              ByteCount       - Length of the byte list
3123446Smrj  *
3133446Smrj  * RETURN:      None
3143446Smrj  *
3153446Smrj  * DESCRIPTION: Dump the contents of a Resource Template containing a set of
3163446Smrj  *              Resource Descriptors.
3173446Smrj  *
3183446Smrj  ******************************************************************************/
3193446Smrj 
3203446Smrj void
AcpiDmResourceTemplate(ACPI_OP_WALK_INFO * Info,ACPI_PARSE_OBJECT * Op,UINT8 * ByteData,UINT32 ByteCount)3213446Smrj AcpiDmResourceTemplate (
3223446Smrj     ACPI_OP_WALK_INFO       *Info,
3233446Smrj     ACPI_PARSE_OBJECT       *Op,
3243446Smrj     UINT8                   *ByteData,
3253446Smrj     UINT32                  ByteCount)
3263446Smrj {
3273446Smrj     ACPI_STATUS             Status;
3287851SDana.Myers@Sun.COM     UINT32                  CurrentByteOffset;
3293446Smrj     UINT8                   ResourceType;
3303446Smrj     UINT32                  ResourceLength;
3313446Smrj     void                    *Aml;
3323446Smrj     UINT32                  Level;
3333446Smrj     BOOLEAN                 DependentFns = FALSE;
3343446Smrj     UINT8                   ResourceIndex;
3353446Smrj     ACPI_NAMESPACE_NODE     *Node;
3363446Smrj 
3373446Smrj 
3383446Smrj     Level = Info->Level;
3393446Smrj     ResourceName = ACPI_DEFAULT_RESNAME;
3403446Smrj     Node = Op->Common.Node;
3413446Smrj     if (Node)
3423446Smrj     {
3433446Smrj         Node = Node->Child;
3443446Smrj     }
3453446Smrj 
3467851SDana.Myers@Sun.COM     for (CurrentByteOffset = 0; CurrentByteOffset < ByteCount;)
3473446Smrj     {
3483446Smrj         Aml = &ByteData[CurrentByteOffset];
3493446Smrj 
3503446Smrj         /* Get the descriptor type and length */
3513446Smrj 
3523446Smrj         ResourceType = AcpiUtGetResourceType (Aml);
3533446Smrj         ResourceLength = AcpiUtGetResourceLength (Aml);
3543446Smrj 
3553446Smrj         /* Validate the Resource Type and Resource Length */
3563446Smrj 
3573446Smrj         Status = AcpiUtValidateResource (Aml, &ResourceIndex);
3583446Smrj         if (ACPI_FAILURE (Status))
3593446Smrj         {
3603446Smrj             AcpiOsPrintf ("/*** Could not validate Resource, type (%X) %s***/\n",
3613446Smrj                 ResourceType, AcpiFormatException (Status));
3623446Smrj             return;
3633446Smrj         }
3643446Smrj 
3653446Smrj         /* Point to next descriptor */
3663446Smrj 
3673446Smrj         CurrentByteOffset += AcpiUtGetDescriptorLength (Aml);
3683446Smrj 
3693446Smrj         /* Descriptor pre-processing */
3703446Smrj 
3713446Smrj         switch (ResourceType)
3723446Smrj         {
3733446Smrj         case ACPI_RESOURCE_NAME_START_DEPENDENT:
3743446Smrj 
3753446Smrj             /* Finish a previous StartDependentFns */
3763446Smrj 
3773446Smrj             if (DependentFns)
3783446Smrj             {
3793446Smrj                 Level--;
3803446Smrj                 AcpiDmIndent (Level);
3813446Smrj                 AcpiOsPrintf ("}\n");
3823446Smrj             }
3833446Smrj             break;
3843446Smrj 
3853446Smrj         case ACPI_RESOURCE_NAME_END_DEPENDENT:
3863446Smrj 
3873446Smrj             Level--;
3883446Smrj             DependentFns = FALSE;
3893446Smrj             break;
3903446Smrj 
3913446Smrj         case ACPI_RESOURCE_NAME_END_TAG:
3923446Smrj 
3933446Smrj             /* Normal exit, the resource list is finished */
3943446Smrj 
3953446Smrj             if (DependentFns)
3963446Smrj             {
3973446Smrj                 /*
3983446Smrj                  * Close an open StartDependentDescriptor. This indicates a
3993446Smrj                  * missing EndDependentDescriptor.
4003446Smrj                  */
4013446Smrj                 Level--;
4023446Smrj                 DependentFns = FALSE;
4033446Smrj 
4043446Smrj                 /* Go ahead and insert EndDependentFn() */
4053446Smrj 
4063446Smrj                 AcpiDmEndDependentDescriptor (Aml, ResourceLength, Level);
4073446Smrj 
4083446Smrj                 AcpiDmIndent (Level);
4093446Smrj                 AcpiOsPrintf (
4103446Smrj                     "/*** Disassembler: inserted missing EndDependentFn () ***/\n");
4113446Smrj             }
4123446Smrj             return;
4133446Smrj 
4143446Smrj         default:
4153446Smrj             break;
4163446Smrj         }
4173446Smrj 
4183446Smrj         /* Disassemble the resource structure */
4193446Smrj 
4203446Smrj         if (Node)
4213446Smrj         {
4223446Smrj             ResourceName = Node->Name.Integer;
4233446Smrj             Node = Node->Peer;
4243446Smrj         }
4253446Smrj 
4267851SDana.Myers@Sun.COM         AcpiGbl_DmResourceDispatch [ResourceIndex] (
4273446Smrj             Aml, ResourceLength, Level);
4283446Smrj 
4293446Smrj         /* Descriptor post-processing */
4303446Smrj 
4313446Smrj         if (ResourceType == ACPI_RESOURCE_NAME_START_DEPENDENT)
4323446Smrj         {
4333446Smrj             DependentFns = TRUE;
4343446Smrj             Level++;
4353446Smrj         }
4363446Smrj     }
4373446Smrj }
4383446Smrj 
4393446Smrj 
4403446Smrj /*******************************************************************************
4413446Smrj  *
4423446Smrj  * FUNCTION:    AcpiDmIsResourceTemplate
4433446Smrj  *
4443446Smrj  * PARAMETERS:  Op          - Buffer Op to be examined
4453446Smrj  *
4467851SDana.Myers@Sun.COM  * RETURN:      Status. AE_OK if valid template
4473446Smrj  *
4483446Smrj  * DESCRIPTION: Walk a byte list to determine if it consists of a valid set
4493446Smrj  *              of resource descriptors.  Nothing is output.
4503446Smrj  *
4513446Smrj  ******************************************************************************/
4523446Smrj 
4537851SDana.Myers@Sun.COM ACPI_STATUS
AcpiDmIsResourceTemplate(ACPI_PARSE_OBJECT * Op)4543446Smrj AcpiDmIsResourceTemplate (
4553446Smrj     ACPI_PARSE_OBJECT       *Op)
4563446Smrj {
4573446Smrj     ACPI_STATUS             Status;
4583446Smrj     ACPI_PARSE_OBJECT       *NextOp;
4593446Smrj     UINT8                   *Aml;
4603446Smrj     UINT8                   *EndAml;
4613446Smrj     ACPI_SIZE               Length;
4623446Smrj 
4633446Smrj 
4643446Smrj     /* This op must be a buffer */
4653446Smrj 
4663446Smrj     if (Op->Common.AmlOpcode != AML_BUFFER_OP)
4673446Smrj     {
4687851SDana.Myers@Sun.COM         return (AE_TYPE);
4693446Smrj     }
4703446Smrj 
4713446Smrj     /* Get the ByteData list and length */
4723446Smrj 
4733446Smrj     NextOp = Op->Common.Value.Arg;
4743446Smrj     NextOp = NextOp->Common.Next;
4753446Smrj     if (!NextOp)
4763446Smrj     {
4777851SDana.Myers@Sun.COM         return (AE_TYPE);
4783446Smrj     }
4793446Smrj 
4803446Smrj     Aml = NextOp->Named.Data;
4813446Smrj     Length = (ACPI_SIZE) NextOp->Common.Value.Integer;
4823446Smrj 
4833446Smrj     /* Walk the byte list, abort on any invalid descriptor type or length */
4843446Smrj 
4853446Smrj     Status = AcpiUtWalkAmlResources (Aml, Length, NULL, &EndAml);
4863446Smrj     if (ACPI_FAILURE (Status))
4873446Smrj     {
4887851SDana.Myers@Sun.COM         return (AE_TYPE);
4893446Smrj     }
4903446Smrj 
4913446Smrj     /*
4923446Smrj      * For the resource template to be valid, one EndTag must appear
4933446Smrj      * at the very end of the ByteList, not before. (For proper disassembly
4943446Smrj      * of a ResourceTemplate, the buffer must not have any extra data after
4953446Smrj      * the EndTag.)
4963446Smrj      */
4973446Smrj     if ((Aml + Length - sizeof (AML_RESOURCE_END_TAG)) != EndAml)
4983446Smrj     {
4997851SDana.Myers@Sun.COM         return (AE_AML_NO_RESOURCE_END_TAG);
5003446Smrj     }
5013446Smrj 
5023446Smrj     /*
5033446Smrj      * All resource descriptors are valid, therefore this list appears
5043446Smrj      * to be a valid resource template
5053446Smrj      */
5067851SDana.Myers@Sun.COM     return (AE_OK);
5073446Smrj }
5083446Smrj 
5093446Smrj #endif
510