xref: /onnv-gate/usr/src/uts/intel/io/acpica/utilities/utresrc.c (revision 9980:13d7f3eec672)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: utresrc - Resource managment 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 #define __UTRESRC_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
120*9980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj #include "amlresrc.h"
1223446Smrj 
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_UTILITIES
1253446Smrj         ACPI_MODULE_NAME    ("utresrc")
1263446Smrj 
1273446Smrj 
1283446Smrj #if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER)
1293446Smrj 
1303446Smrj /*
1313446Smrj  * Strings used to decode resource descriptors.
1323446Smrj  * Used by both the disasssembler and the debugger resource dump routines
1333446Smrj  */
1343446Smrj const char                      *AcpiGbl_BmDecode[] =
1353446Smrj {
1363446Smrj     "NotBusMaster",
1373446Smrj     "BusMaster"
1383446Smrj };
1393446Smrj 
1403446Smrj const char                      *AcpiGbl_ConfigDecode[] =
1413446Smrj {
1423446Smrj     "0 - Good Configuration",
1433446Smrj     "1 - Acceptable Configuration",
1443446Smrj     "2 - Suboptimal Configuration",
1453446Smrj     "3 - ***Invalid Configuration***",
1463446Smrj };
1473446Smrj 
1483446Smrj const char                      *AcpiGbl_ConsumeDecode[] =
1493446Smrj {
1503446Smrj     "ResourceProducer",
1513446Smrj     "ResourceConsumer"
1523446Smrj };
1533446Smrj 
1543446Smrj const char                      *AcpiGbl_DecDecode[] =
1553446Smrj {
1563446Smrj     "PosDecode",
1573446Smrj     "SubDecode"
1583446Smrj };
1593446Smrj 
1603446Smrj const char                      *AcpiGbl_HeDecode[] =
1613446Smrj {
1623446Smrj     "Level",
1633446Smrj     "Edge"
1643446Smrj };
1653446Smrj 
1663446Smrj const char                      *AcpiGbl_IoDecode[] =
1673446Smrj {
1683446Smrj     "Decode10",
1693446Smrj     "Decode16"
1703446Smrj };
1713446Smrj 
1723446Smrj const char                      *AcpiGbl_LlDecode[] =
1733446Smrj {
1743446Smrj     "ActiveHigh",
1753446Smrj     "ActiveLow"
1763446Smrj };
1773446Smrj 
1783446Smrj const char                      *AcpiGbl_MaxDecode[] =
1793446Smrj {
1803446Smrj     "MaxNotFixed",
1813446Smrj     "MaxFixed"
1823446Smrj };
1833446Smrj 
1843446Smrj const char                      *AcpiGbl_MemDecode[] =
1853446Smrj {
1863446Smrj     "NonCacheable",
1873446Smrj     "Cacheable",
1883446Smrj     "WriteCombining",
1893446Smrj     "Prefetchable"
1903446Smrj };
1913446Smrj 
1923446Smrj const char                      *AcpiGbl_MinDecode[] =
1933446Smrj {
1943446Smrj     "MinNotFixed",
1953446Smrj     "MinFixed"
1963446Smrj };
1973446Smrj 
1983446Smrj const char                      *AcpiGbl_MtpDecode[] =
1993446Smrj {
2003446Smrj     "AddressRangeMemory",
2013446Smrj     "AddressRangeReserved",
2023446Smrj     "AddressRangeACPI",
2033446Smrj     "AddressRangeNVS"
2043446Smrj };
2053446Smrj 
2063446Smrj const char                      *AcpiGbl_RngDecode[] =
2073446Smrj {
2083446Smrj     "InvalidRanges",
2093446Smrj     "NonISAOnlyRanges",
2103446Smrj     "ISAOnlyRanges",
2113446Smrj     "EntireRange"
2123446Smrj };
2133446Smrj 
2143446Smrj const char                      *AcpiGbl_RwDecode[] =
2153446Smrj {
2163446Smrj     "ReadOnly",
2173446Smrj     "ReadWrite"
2183446Smrj };
2193446Smrj 
2203446Smrj const char                      *AcpiGbl_ShrDecode[] =
2213446Smrj {
2223446Smrj     "Exclusive",
2233446Smrj     "Shared"
2243446Smrj };
2253446Smrj 
2263446Smrj const char                      *AcpiGbl_SizDecode[] =
2273446Smrj {
2283446Smrj     "Transfer8",
2293446Smrj     "Transfer8_16",
2303446Smrj     "Transfer16",
2313446Smrj     "InvalidSize"
2323446Smrj };
2333446Smrj 
2343446Smrj const char                      *AcpiGbl_TrsDecode[] =
2353446Smrj {
2363446Smrj     "DenseTranslation",
2373446Smrj     "SparseTranslation"
2383446Smrj };
2393446Smrj 
2403446Smrj const char                      *AcpiGbl_TtpDecode[] =
2413446Smrj {
2423446Smrj     "TypeStatic",
2433446Smrj     "TypeTranslation"
2443446Smrj };
2453446Smrj 
2463446Smrj const char                      *AcpiGbl_TypDecode[] =
2473446Smrj {
2483446Smrj     "Compatibility",
2493446Smrj     "TypeA",
2503446Smrj     "TypeB",
2513446Smrj     "TypeF"
2523446Smrj };
2533446Smrj 
2543446Smrj #endif
2553446Smrj 
2563446Smrj 
2573446Smrj /*
2583446Smrj  * Base sizes of the raw AML resource descriptors, indexed by resource type.
2593446Smrj  * Zero indicates a reserved (and therefore invalid) resource type.
2603446Smrj  */
2613446Smrj const UINT8                 AcpiGbl_ResourceAmlSizes[] =
2623446Smrj {
2633446Smrj     /* Small descriptors */
2643446Smrj 
2653446Smrj     0,
2663446Smrj     0,
2673446Smrj     0,
2683446Smrj     0,
2693446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_IRQ),
2703446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_DMA),
2713446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_START_DEPENDENT),
2723446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_DEPENDENT),
2733446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_IO),
2743446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_FIXED_IO),
2753446Smrj     0,
2763446Smrj     0,
2773446Smrj     0,
2783446Smrj     0,
2793446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_VENDOR_SMALL),
2803446Smrj     ACPI_AML_SIZE_SMALL (AML_RESOURCE_END_TAG),
2813446Smrj 
2823446Smrj     /* Large descriptors */
2833446Smrj 
2843446Smrj     0,
2853446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY24),
2863446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_GENERIC_REGISTER),
2873446Smrj     0,
2883446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_VENDOR_LARGE),
2893446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_MEMORY32),
2903446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_FIXED_MEMORY32),
2913446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS32),
2923446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS16),
2933446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_IRQ),
2943446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_ADDRESS64),
2953446Smrj     ACPI_AML_SIZE_LARGE (AML_RESOURCE_EXTENDED_ADDRESS64)
2963446Smrj };
2973446Smrj 
2983446Smrj 
2993446Smrj /*
3003446Smrj  * Resource types, used to validate the resource length field.
3013446Smrj  * The length of fixed-length types must match exactly, variable
3023446Smrj  * lengths must meet the minimum required length, etc.
3033446Smrj  * Zero indicates a reserved (and therefore invalid) resource type.
3043446Smrj  */
3053446Smrj static const UINT8          AcpiGbl_ResourceTypes[] =
3063446Smrj {
3073446Smrj     /* Small descriptors */
3083446Smrj 
3093446Smrj     0,
3103446Smrj     0,
3113446Smrj     0,
3123446Smrj     0,
3133446Smrj     ACPI_SMALL_VARIABLE_LENGTH,
3143446Smrj     ACPI_FIXED_LENGTH,
3153446Smrj     ACPI_SMALL_VARIABLE_LENGTH,
3163446Smrj     ACPI_FIXED_LENGTH,
3173446Smrj     ACPI_FIXED_LENGTH,
3183446Smrj     ACPI_FIXED_LENGTH,
3193446Smrj     0,
3203446Smrj     0,
3213446Smrj     0,
3223446Smrj     0,
3233446Smrj     ACPI_VARIABLE_LENGTH,
3243446Smrj     ACPI_FIXED_LENGTH,
3253446Smrj 
3263446Smrj     /* Large descriptors */
3273446Smrj 
3283446Smrj     0,
3293446Smrj     ACPI_FIXED_LENGTH,
3303446Smrj     ACPI_FIXED_LENGTH,
3313446Smrj     0,
3323446Smrj     ACPI_VARIABLE_LENGTH,
3333446Smrj     ACPI_FIXED_LENGTH,
3343446Smrj     ACPI_FIXED_LENGTH,
3353446Smrj     ACPI_VARIABLE_LENGTH,
3363446Smrj     ACPI_VARIABLE_LENGTH,
3373446Smrj     ACPI_VARIABLE_LENGTH,
3383446Smrj     ACPI_VARIABLE_LENGTH,
3393446Smrj     ACPI_FIXED_LENGTH
3403446Smrj };
3413446Smrj 
3423446Smrj 
3433446Smrj /*******************************************************************************
3443446Smrj  *
3453446Smrj  * FUNCTION:    AcpiUtWalkAmlResources
3463446Smrj  *
3473446Smrj  * PARAMETERS:  Aml             - Pointer to the raw AML resource template
3483446Smrj  *              AmlLength       - Length of the entire template
3493446Smrj  *              UserFunction    - Called once for each descriptor found. If
3503446Smrj  *                                NULL, a pointer to the EndTag is returned
3513446Smrj  *              Context         - Passed to UserFunction
3523446Smrj  *
3533446Smrj  * RETURN:      Status
3543446Smrj  *
3553446Smrj  * DESCRIPTION: Walk a raw AML resource list(buffer). User function called
3563446Smrj  *              once for each resource found.
3573446Smrj  *
3583446Smrj  ******************************************************************************/
3593446Smrj 
3603446Smrj ACPI_STATUS
AcpiUtWalkAmlResources(UINT8 * Aml,ACPI_SIZE AmlLength,ACPI_WALK_AML_CALLBACK UserFunction,void * Context)3613446Smrj AcpiUtWalkAmlResources (
3623446Smrj     UINT8                   *Aml,
3633446Smrj     ACPI_SIZE               AmlLength,
3643446Smrj     ACPI_WALK_AML_CALLBACK  UserFunction,
3653446Smrj     void                    *Context)
3663446Smrj {
3673446Smrj     ACPI_STATUS             Status;
3683446Smrj     UINT8                   *EndAml;
3693446Smrj     UINT8                   ResourceIndex;
3703446Smrj     UINT32                  Length;
3713446Smrj     UINT32                  Offset = 0;
3723446Smrj 
3733446Smrj 
3743446Smrj     ACPI_FUNCTION_TRACE (UtWalkAmlResources);
3753446Smrj 
3763446Smrj 
3773446Smrj     /* The absolute minimum resource template is one EndTag descriptor */
3783446Smrj 
3793446Smrj     if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
3803446Smrj     {
3813446Smrj         return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
3823446Smrj     }
3833446Smrj 
3843446Smrj     /* Point to the end of the resource template buffer */
3853446Smrj 
3863446Smrj     EndAml = Aml + AmlLength;
3873446Smrj 
3883446Smrj     /* Walk the byte list, abort on any invalid descriptor type or length */
3893446Smrj 
3903446Smrj     while (Aml < EndAml)
3913446Smrj     {
3923446Smrj         /* Validate the Resource Type and Resource Length */
3933446Smrj 
3943446Smrj         Status = AcpiUtValidateResource (Aml, &ResourceIndex);
3953446Smrj         if (ACPI_FAILURE (Status))
3963446Smrj         {
3973446Smrj             return_ACPI_STATUS (Status);
3983446Smrj         }
3993446Smrj 
4003446Smrj         /* Get the length of this descriptor */
4013446Smrj 
4023446Smrj         Length = AcpiUtGetDescriptorLength (Aml);
4033446Smrj 
4043446Smrj         /* Invoke the user function */
4053446Smrj 
4063446Smrj         if (UserFunction)
4073446Smrj         {
4083446Smrj             Status = UserFunction (Aml, Length, Offset, ResourceIndex, Context);
4093446Smrj             if (ACPI_FAILURE (Status))
4103446Smrj             {
4113446Smrj                 return (Status);
4123446Smrj             }
4133446Smrj         }
4143446Smrj 
4153446Smrj         /* An EndTag descriptor terminates this resource template */
4163446Smrj 
4173446Smrj         if (AcpiUtGetResourceType (Aml) == ACPI_RESOURCE_NAME_END_TAG)
4183446Smrj         {
4193446Smrj             /*
4203446Smrj              * There must be at least one more byte in the buffer for
4213446Smrj              * the 2nd byte of the EndTag
4223446Smrj              */
4233446Smrj             if ((Aml + 1) >= EndAml)
4243446Smrj             {
4253446Smrj                 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
4263446Smrj             }
4273446Smrj 
4283446Smrj             /* Return the pointer to the EndTag if requested */
4293446Smrj 
4303446Smrj             if (!UserFunction)
4313446Smrj             {
4323446Smrj                 *(void **) Context = Aml;
4333446Smrj             }
4343446Smrj 
4353446Smrj             /* Normal exit */
4363446Smrj 
4373446Smrj             return_ACPI_STATUS (AE_OK);
4383446Smrj         }
4393446Smrj 
4403446Smrj         Aml += Length;
4413446Smrj         Offset += Length;
4423446Smrj     }
4433446Smrj 
4443446Smrj     /* Did not find an EndTag descriptor */
4453446Smrj 
4463446Smrj     return (AE_AML_NO_RESOURCE_END_TAG);
4473446Smrj }
4483446Smrj 
4493446Smrj 
4503446Smrj /*******************************************************************************
4513446Smrj  *
4523446Smrj  * FUNCTION:    AcpiUtValidateResource
4533446Smrj  *
4543446Smrj  * PARAMETERS:  Aml             - Pointer to the raw AML resource descriptor
4553446Smrj  *              ReturnIndex     - Where the resource index is returned. NULL
4563446Smrj  *                                if the index is not required.
4573446Smrj  *
4583446Smrj  * RETURN:      Status, and optionally the Index into the global resource tables
4593446Smrj  *
4603446Smrj  * DESCRIPTION: Validate an AML resource descriptor by checking the Resource
4613446Smrj  *              Type and Resource Length. Returns an index into the global
4623446Smrj  *              resource information/dispatch tables for later use.
4633446Smrj  *
4643446Smrj  ******************************************************************************/
4653446Smrj 
4663446Smrj ACPI_STATUS
AcpiUtValidateResource(void * Aml,UINT8 * ReturnIndex)4673446Smrj AcpiUtValidateResource (
4683446Smrj     void                    *Aml,
4693446Smrj     UINT8                   *ReturnIndex)
4703446Smrj {
4713446Smrj     UINT8                   ResourceType;
4723446Smrj     UINT8                   ResourceIndex;
4733446Smrj     ACPI_RS_LENGTH          ResourceLength;
4743446Smrj     ACPI_RS_LENGTH          MinimumResourceLength;
4753446Smrj 
4763446Smrj 
4773446Smrj     ACPI_FUNCTION_ENTRY ();
4783446Smrj 
4793446Smrj 
4803446Smrj     /*
4813446Smrj      * 1) Validate the ResourceType field (Byte 0)
4823446Smrj      */
4833446Smrj     ResourceType = ACPI_GET8 (Aml);
4843446Smrj 
4853446Smrj     /*
4863446Smrj      * Byte 0 contains the descriptor name (Resource Type)
4873446Smrj      * Examine the large/small bit in the resource header
4883446Smrj      */
4893446Smrj     if (ResourceType & ACPI_RESOURCE_NAME_LARGE)
4903446Smrj     {
4913446Smrj         /* Verify the large resource type (name) against the max */
4923446Smrj 
4933446Smrj         if (ResourceType > ACPI_RESOURCE_NAME_LARGE_MAX)
4943446Smrj         {
4953446Smrj             return (AE_AML_INVALID_RESOURCE_TYPE);
4963446Smrj         }
4973446Smrj 
4983446Smrj         /*
4993446Smrj          * Large Resource Type -- bits 6:0 contain the name
5003446Smrj          * Translate range 0x80-0x8B to index range 0x10-0x1B
5013446Smrj          */
5023446Smrj         ResourceIndex = (UINT8) (ResourceType - 0x70);
5033446Smrj     }
5043446Smrj     else
5053446Smrj     {
5063446Smrj         /*
5073446Smrj          * Small Resource Type -- bits 6:3 contain the name
5083446Smrj          * Shift range to index range 0x00-0x0F
5093446Smrj          */
5103446Smrj         ResourceIndex = (UINT8)
5113446Smrj             ((ResourceType & ACPI_RESOURCE_NAME_SMALL_MASK) >> 3);
5123446Smrj     }
5133446Smrj 
5143446Smrj     /* Check validity of the resource type, zero indicates name is invalid */
5153446Smrj 
5163446Smrj     if (!AcpiGbl_ResourceTypes[ResourceIndex])
5173446Smrj     {
5183446Smrj         return (AE_AML_INVALID_RESOURCE_TYPE);
5193446Smrj     }
5203446Smrj 
5213446Smrj 
5223446Smrj     /*
5233446Smrj      * 2) Validate the ResourceLength field. This ensures that the length
5243446Smrj      *    is at least reasonable, and guarantees that it is non-zero.
5253446Smrj      */
5263446Smrj     ResourceLength = AcpiUtGetResourceLength (Aml);
5273446Smrj     MinimumResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
5283446Smrj 
5293446Smrj     /* Validate based upon the type of resource - fixed length or variable */
5303446Smrj 
5313446Smrj     switch (AcpiGbl_ResourceTypes[ResourceIndex])
5323446Smrj     {
5333446Smrj     case ACPI_FIXED_LENGTH:
5343446Smrj 
5353446Smrj         /* Fixed length resource, length must match exactly */
5363446Smrj 
5373446Smrj         if (ResourceLength != MinimumResourceLength)
5383446Smrj         {
5393446Smrj             return (AE_AML_BAD_RESOURCE_LENGTH);
5403446Smrj         }
5413446Smrj         break;
5423446Smrj 
5433446Smrj     case ACPI_VARIABLE_LENGTH:
5443446Smrj 
5453446Smrj         /* Variable length resource, length must be at least the minimum */
5463446Smrj 
5473446Smrj         if (ResourceLength < MinimumResourceLength)
5483446Smrj         {
5493446Smrj             return (AE_AML_BAD_RESOURCE_LENGTH);
5503446Smrj         }
5513446Smrj         break;
5523446Smrj 
5533446Smrj     case ACPI_SMALL_VARIABLE_LENGTH:
5543446Smrj 
5553446Smrj         /* Small variable length resource, length can be (Min) or (Min-1) */
5563446Smrj 
5573446Smrj         if ((ResourceLength > MinimumResourceLength) ||
5583446Smrj             (ResourceLength < (MinimumResourceLength - 1)))
5593446Smrj         {
5603446Smrj             return (AE_AML_BAD_RESOURCE_LENGTH);
5613446Smrj         }
5623446Smrj         break;
5633446Smrj 
5643446Smrj     default:
5653446Smrj 
5663446Smrj         /* Shouldn't happen (because of validation earlier), but be sure */
5673446Smrj 
5683446Smrj         return (AE_AML_INVALID_RESOURCE_TYPE);
5693446Smrj     }
5703446Smrj 
5713446Smrj     /* Optionally return the resource table index */
5723446Smrj 
5733446Smrj     if (ReturnIndex)
5743446Smrj     {
5753446Smrj         *ReturnIndex = ResourceIndex;
5763446Smrj     }
5773446Smrj 
5783446Smrj     return (AE_OK);
5793446Smrj }
5803446Smrj 
5813446Smrj 
5823446Smrj /*******************************************************************************
5833446Smrj  *
5843446Smrj  * FUNCTION:    AcpiUtGetResourceType
5853446Smrj  *
5863446Smrj  * PARAMETERS:  Aml             - Pointer to the raw AML resource descriptor
5873446Smrj  *
5883446Smrj  * RETURN:      The Resource Type with no extraneous bits (except the
5893446Smrj  *              Large/Small descriptor bit -- this is left alone)
5903446Smrj  *
5913446Smrj  * DESCRIPTION: Extract the Resource Type/Name from the first byte of
5923446Smrj  *              a resource descriptor.
5933446Smrj  *
5943446Smrj  ******************************************************************************/
5953446Smrj 
5963446Smrj UINT8
AcpiUtGetResourceType(void * Aml)5973446Smrj AcpiUtGetResourceType (
5983446Smrj     void                    *Aml)
5993446Smrj {
6003446Smrj     ACPI_FUNCTION_ENTRY ();
6013446Smrj 
6023446Smrj 
6033446Smrj     /*
6043446Smrj      * Byte 0 contains the descriptor name (Resource Type)
6053446Smrj      * Examine the large/small bit in the resource header
6063446Smrj      */
6073446Smrj     if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
6083446Smrj     {
6093446Smrj         /* Large Resource Type -- bits 6:0 contain the name */
6103446Smrj 
6113446Smrj         return (ACPI_GET8 (Aml));
6123446Smrj     }
6133446Smrj     else
6143446Smrj     {
6153446Smrj         /* Small Resource Type -- bits 6:3 contain the name */
6163446Smrj 
6173446Smrj         return ((UINT8) (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_SMALL_MASK));
6183446Smrj     }
6193446Smrj }
6203446Smrj 
6213446Smrj 
6223446Smrj /*******************************************************************************
6233446Smrj  *
6243446Smrj  * FUNCTION:    AcpiUtGetResourceLength
6253446Smrj  *
6263446Smrj  * PARAMETERS:  Aml             - Pointer to the raw AML resource descriptor
6273446Smrj  *
6283446Smrj  * RETURN:      Byte Length
6293446Smrj  *
6303446Smrj  * DESCRIPTION: Get the "Resource Length" of a raw AML descriptor. By
6313446Smrj  *              definition, this does not include the size of the descriptor
6323446Smrj  *              header or the length field itself.
6333446Smrj  *
6343446Smrj  ******************************************************************************/
6353446Smrj 
6363446Smrj UINT16
AcpiUtGetResourceLength(void * Aml)6373446Smrj AcpiUtGetResourceLength (
6383446Smrj     void                    *Aml)
6393446Smrj {
6403446Smrj     ACPI_RS_LENGTH          ResourceLength;
6413446Smrj 
6423446Smrj 
6433446Smrj     ACPI_FUNCTION_ENTRY ();
6443446Smrj 
6453446Smrj 
6463446Smrj     /*
6473446Smrj      * Byte 0 contains the descriptor name (Resource Type)
6483446Smrj      * Examine the large/small bit in the resource header
6493446Smrj      */
6503446Smrj     if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
6513446Smrj     {
6523446Smrj         /* Large Resource type -- bytes 1-2 contain the 16-bit length */
6533446Smrj 
6543446Smrj         ACPI_MOVE_16_TO_16 (&ResourceLength, ACPI_ADD_PTR (UINT8, Aml, 1));
6553446Smrj 
6563446Smrj     }
6573446Smrj     else
6583446Smrj     {
6593446Smrj         /* Small Resource type -- bits 2:0 of byte 0 contain the length */
6603446Smrj 
6613446Smrj         ResourceLength = (UINT16) (ACPI_GET8 (Aml) &
6623446Smrj                                     ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK);
6633446Smrj     }
6643446Smrj 
6653446Smrj     return (ResourceLength);
6663446Smrj }
6673446Smrj 
6683446Smrj 
6693446Smrj /*******************************************************************************
6703446Smrj  *
6713446Smrj  * FUNCTION:    AcpiUtGetResourceHeaderLength
6723446Smrj  *
6733446Smrj  * PARAMETERS:  Aml             - Pointer to the raw AML resource descriptor
6743446Smrj  *
6753446Smrj  * RETURN:      Length of the AML header (depends on large/small descriptor)
6763446Smrj  *
6773446Smrj  * DESCRIPTION: Get the length of the header for this resource.
6783446Smrj  *
6793446Smrj  ******************************************************************************/
6803446Smrj 
6813446Smrj UINT8
AcpiUtGetResourceHeaderLength(void * Aml)6823446Smrj AcpiUtGetResourceHeaderLength (
6833446Smrj     void                    *Aml)
6843446Smrj {
6853446Smrj     ACPI_FUNCTION_ENTRY ();
6863446Smrj 
6873446Smrj 
6883446Smrj     /* Examine the large/small bit in the resource header */
6893446Smrj 
6903446Smrj     if (ACPI_GET8 (Aml) & ACPI_RESOURCE_NAME_LARGE)
6913446Smrj     {
6923446Smrj         return (sizeof (AML_RESOURCE_LARGE_HEADER));
6933446Smrj     }
6943446Smrj     else
6953446Smrj     {
6963446Smrj         return (sizeof (AML_RESOURCE_SMALL_HEADER));
6973446Smrj     }
6983446Smrj }
6993446Smrj 
7003446Smrj 
7013446Smrj /*******************************************************************************
7023446Smrj  *
7033446Smrj  * FUNCTION:    AcpiUtGetDescriptorLength
7043446Smrj  *
7053446Smrj  * PARAMETERS:  Aml             - Pointer to the raw AML resource descriptor
7063446Smrj  *
7073446Smrj  * RETURN:      Byte length
7083446Smrj  *
7093446Smrj  * DESCRIPTION: Get the total byte length of a raw AML descriptor, including the
7103446Smrj  *              length of the descriptor header and the length field itself.
7113446Smrj  *              Used to walk descriptor lists.
7123446Smrj  *
7133446Smrj  ******************************************************************************/
7143446Smrj 
7153446Smrj UINT32
AcpiUtGetDescriptorLength(void * Aml)7163446Smrj AcpiUtGetDescriptorLength (
7173446Smrj     void                    *Aml)
7183446Smrj {
7193446Smrj     ACPI_FUNCTION_ENTRY ();
7203446Smrj 
7213446Smrj 
7223446Smrj     /*
7233446Smrj      * Get the Resource Length (does not include header length) and add
7243446Smrj      * the header length (depends on if this is a small or large resource)
7253446Smrj      */
7263446Smrj     return (AcpiUtGetResourceLength (Aml) +
7273446Smrj             AcpiUtGetResourceHeaderLength (Aml));
7283446Smrj }
7293446Smrj 
7303446Smrj 
7313446Smrj /*******************************************************************************
7323446Smrj  *
7333446Smrj  * FUNCTION:    AcpiUtGetResourceEndTag
7343446Smrj  *
7353446Smrj  * PARAMETERS:  ObjDesc         - The resource template buffer object
7363446Smrj  *              EndTag          - Where the pointer to the EndTag is returned
7373446Smrj  *
7383446Smrj  * RETURN:      Status, pointer to the end tag
7393446Smrj  *
7403446Smrj  * DESCRIPTION: Find the EndTag resource descriptor in an AML resource template
7413446Smrj  *              Note: allows a buffer length of zero.
7423446Smrj  *
7433446Smrj  ******************************************************************************/
7443446Smrj 
7453446Smrj ACPI_STATUS
AcpiUtGetResourceEndTag(ACPI_OPERAND_OBJECT * ObjDesc,UINT8 ** EndTag)7463446Smrj AcpiUtGetResourceEndTag (
7473446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc,
7483446Smrj     UINT8                   **EndTag)
7493446Smrj {
7503446Smrj     ACPI_STATUS             Status;
7513446Smrj 
7523446Smrj 
7533446Smrj     ACPI_FUNCTION_TRACE (UtGetResourceEndTag);
7543446Smrj 
7553446Smrj 
7563446Smrj     /* Allow a buffer length of zero */
7573446Smrj 
7583446Smrj     if (!ObjDesc->Buffer.Length)
7593446Smrj     {
7603446Smrj         *EndTag = ObjDesc->Buffer.Pointer;
7613446Smrj         return_ACPI_STATUS (AE_OK);
7623446Smrj     }
7633446Smrj 
7643446Smrj     /* Validate the template and get a pointer to the EndTag */
7653446Smrj 
7663446Smrj     Status = AcpiUtWalkAmlResources (ObjDesc->Buffer.Pointer,
7673446Smrj                 ObjDesc->Buffer.Length, NULL, EndTag);
7683446Smrj 
7693446Smrj     return_ACPI_STATUS (Status);
7703446Smrj }
7713446Smrj 
7723446Smrj 
773