xref: /onnv-gate/usr/src/uts/intel/io/acpica/resources/rsutils.c (revision 9980:13d7f3eec672)
13446Smrj /*******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: rsutils - Utilities for the resource manager
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 __RSUTILS_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
120*9980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj #include "acnamesp.h"
1223446Smrj #include "acresrc.h"
1233446Smrj 
1243446Smrj 
1253446Smrj #define _COMPONENT          ACPI_RESOURCES
1263446Smrj         ACPI_MODULE_NAME    ("rsutils")
1273446Smrj 
1283446Smrj 
1293446Smrj /*******************************************************************************
1303446Smrj  *
1313446Smrj  * FUNCTION:    AcpiRsDecodeBitmask
1323446Smrj  *
1333446Smrj  * PARAMETERS:  Mask            - Bitmask to decode
1343446Smrj  *              List            - Where the converted list is returned
1353446Smrj  *
1363446Smrj  * RETURN:      Count of bits set (length of list)
1373446Smrj  *
1383446Smrj  * DESCRIPTION: Convert a bit mask into a list of values
1393446Smrj  *
1403446Smrj  ******************************************************************************/
1413446Smrj 
1423446Smrj UINT8
AcpiRsDecodeBitmask(UINT16 Mask,UINT8 * List)1433446Smrj AcpiRsDecodeBitmask (
1443446Smrj     UINT16                  Mask,
1453446Smrj     UINT8                   *List)
1463446Smrj {
1477851SDana.Myers@Sun.COM     UINT8                   i;
1483446Smrj     UINT8                   BitCount;
1493446Smrj 
1503446Smrj 
1513446Smrj     ACPI_FUNCTION_ENTRY ();
1523446Smrj 
1533446Smrj 
1543446Smrj     /* Decode the mask bits */
1553446Smrj 
1563446Smrj     for (i = 0, BitCount = 0; Mask; i++)
1573446Smrj     {
1583446Smrj         if (Mask & 0x0001)
1593446Smrj         {
1607851SDana.Myers@Sun.COM             List[BitCount] = i;
1613446Smrj             BitCount++;
1623446Smrj         }
1633446Smrj 
1643446Smrj         Mask >>= 1;
1653446Smrj     }
1663446Smrj 
1673446Smrj     return (BitCount);
1683446Smrj }
1693446Smrj 
1703446Smrj 
1713446Smrj /*******************************************************************************
1723446Smrj  *
1733446Smrj  * FUNCTION:    AcpiRsEncodeBitmask
1743446Smrj  *
1753446Smrj  * PARAMETERS:  List            - List of values to encode
1763446Smrj  *              Count           - Length of list
1773446Smrj  *
1783446Smrj  * RETURN:      Encoded bitmask
1793446Smrj  *
1803446Smrj  * DESCRIPTION: Convert a list of values to an encoded bitmask
1813446Smrj  *
1823446Smrj  ******************************************************************************/
1833446Smrj 
1843446Smrj UINT16
AcpiRsEncodeBitmask(UINT8 * List,UINT8 Count)1853446Smrj AcpiRsEncodeBitmask (
1863446Smrj     UINT8                   *List,
1873446Smrj     UINT8                   Count)
1883446Smrj {
1897851SDana.Myers@Sun.COM     UINT32                  i;
1903446Smrj     UINT16                  Mask;
1913446Smrj 
1923446Smrj 
1933446Smrj     ACPI_FUNCTION_ENTRY ();
1943446Smrj 
1953446Smrj 
1963446Smrj     /* Encode the list into a single bitmask */
1973446Smrj 
1983446Smrj     for (i = 0, Mask = 0; i < Count; i++)
1993446Smrj     {
2007851SDana.Myers@Sun.COM         Mask |= (0x1 << List[i]);
2013446Smrj     }
2023446Smrj 
2033446Smrj     return (Mask);
2043446Smrj }
2053446Smrj 
2063446Smrj 
2073446Smrj /*******************************************************************************
2083446Smrj  *
2093446Smrj  * FUNCTION:    AcpiRsMoveData
2103446Smrj  *
2113446Smrj  * PARAMETERS:  Destination         - Pointer to the destination descriptor
2123446Smrj  *              Source              - Pointer to the source descriptor
2133446Smrj  *              ItemCount           - How many items to move
2143446Smrj  *              MoveType            - Byte width
2153446Smrj  *
2163446Smrj  * RETURN:      None
2173446Smrj  *
2183446Smrj  * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
2193446Smrj  *              alignment issues and endian issues if necessary, as configured
2203446Smrj  *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
2213446Smrj  *
2223446Smrj  ******************************************************************************/
2233446Smrj 
2243446Smrj void
AcpiRsMoveData(void * Destination,void * Source,UINT16 ItemCount,UINT8 MoveType)2253446Smrj AcpiRsMoveData (
2263446Smrj     void                    *Destination,
2273446Smrj     void                    *Source,
2283446Smrj     UINT16                  ItemCount,
2293446Smrj     UINT8                   MoveType)
2303446Smrj {
2317851SDana.Myers@Sun.COM     UINT32                  i;
2323446Smrj 
2333446Smrj 
2343446Smrj     ACPI_FUNCTION_ENTRY ();
2353446Smrj 
2363446Smrj 
2373446Smrj     /* One move per item */
2383446Smrj 
2393446Smrj     for (i = 0; i < ItemCount; i++)
2403446Smrj     {
2413446Smrj         switch (MoveType)
2423446Smrj         {
2433446Smrj         /*
2443446Smrj          * For the 8-bit case, we can perform the move all at once
2453446Smrj          * since there are no alignment or endian issues
2463446Smrj          */
2473446Smrj         case ACPI_RSC_MOVE8:
2483446Smrj             ACPI_MEMCPY (Destination, Source, ItemCount);
2493446Smrj             return;
2503446Smrj 
2513446Smrj         /*
2523446Smrj          * 16-, 32-, and 64-bit cases must use the move macros that perform
2533446Smrj          * endian conversion and/or accomodate hardware that cannot perform
2543446Smrj          * misaligned memory transfers
2553446Smrj          */
2563446Smrj         case ACPI_RSC_MOVE16:
2573446Smrj             ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
2583446Smrj                                 &ACPI_CAST_PTR (UINT16, Source)[i]);
2593446Smrj             break;
2603446Smrj 
2613446Smrj         case ACPI_RSC_MOVE32:
2623446Smrj             ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
2633446Smrj                                 &ACPI_CAST_PTR (UINT32, Source)[i]);
2643446Smrj             break;
2653446Smrj 
2663446Smrj         case ACPI_RSC_MOVE64:
2673446Smrj             ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
2683446Smrj                                 &ACPI_CAST_PTR (UINT64, Source)[i]);
2693446Smrj             break;
2703446Smrj 
2713446Smrj         default:
2723446Smrj             return;
2733446Smrj         }
2743446Smrj     }
2753446Smrj }
2763446Smrj 
2773446Smrj 
2783446Smrj /*******************************************************************************
2793446Smrj  *
2803446Smrj  * FUNCTION:    AcpiRsSetResourceLength
2813446Smrj  *
2823446Smrj  * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
2833446Smrj  *                                    the header and length fields.
2843446Smrj  *              Aml                 - Pointer to the raw AML descriptor
2853446Smrj  *
2863446Smrj  * RETURN:      None
2873446Smrj  *
2883446Smrj  * DESCRIPTION: Set the ResourceLength field of an AML
2893446Smrj  *              resource descriptor, both Large and Small descriptors are
2903446Smrj  *              supported automatically. Note: Descriptor Type field must
2913446Smrj  *              be valid.
2923446Smrj  *
2933446Smrj  ******************************************************************************/
2943446Smrj 
2953446Smrj void
AcpiRsSetResourceLength(ACPI_RSDESC_SIZE TotalLength,AML_RESOURCE * Aml)2963446Smrj AcpiRsSetResourceLength (
2973446Smrj     ACPI_RSDESC_SIZE        TotalLength,
2983446Smrj     AML_RESOURCE            *Aml)
2993446Smrj {
3003446Smrj     ACPI_RS_LENGTH          ResourceLength;
3013446Smrj 
3023446Smrj 
3033446Smrj     ACPI_FUNCTION_ENTRY ();
3043446Smrj 
3053446Smrj 
3063446Smrj     /* Length is the total descriptor length minus the header length */
3073446Smrj 
3083446Smrj     ResourceLength = (ACPI_RS_LENGTH)
3093446Smrj         (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
3103446Smrj 
3113446Smrj     /* Length is stored differently for large and small descriptors */
3123446Smrj 
3133446Smrj     if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
3143446Smrj     {
3153446Smrj         /* Large descriptor -- bytes 1-2 contain the 16-bit length */
3163446Smrj 
3173446Smrj         ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
3183446Smrj     }
3193446Smrj     else
3203446Smrj     {
3213446Smrj         /* Small descriptor -- bits 2:0 of byte 0 contain the length */
3223446Smrj 
3233446Smrj         Aml->SmallHeader.DescriptorType = (UINT8)
3243446Smrj 
3253446Smrj             /* Clear any existing length, preserving descriptor type bits */
3263446Smrj 
3273446Smrj             ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
3283446Smrj 
3293446Smrj             | ResourceLength);
3303446Smrj     }
3313446Smrj }
3323446Smrj 
3333446Smrj 
3343446Smrj /*******************************************************************************
3353446Smrj  *
3363446Smrj  * FUNCTION:    AcpiRsSetResourceHeader
3373446Smrj  *
3383446Smrj  * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
3393446Smrj  *              TotalLength         - Length of the AML descriptor, including
3403446Smrj  *                                    the header and length fields.
3413446Smrj  *              Aml                 - Pointer to the raw AML descriptor
3423446Smrj  *
3433446Smrj  * RETURN:      None
3443446Smrj  *
3453446Smrj  * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
3463446Smrj  *              resource descriptor, both Large and Small descriptors are
3473446Smrj  *              supported automatically
3483446Smrj  *
3493446Smrj  ******************************************************************************/
3503446Smrj 
3513446Smrj void
AcpiRsSetResourceHeader(UINT8 DescriptorType,ACPI_RSDESC_SIZE TotalLength,AML_RESOURCE * Aml)3523446Smrj AcpiRsSetResourceHeader (
3533446Smrj     UINT8                   DescriptorType,
3543446Smrj     ACPI_RSDESC_SIZE        TotalLength,
3553446Smrj     AML_RESOURCE            *Aml)
3563446Smrj {
3573446Smrj     ACPI_FUNCTION_ENTRY ();
3583446Smrj 
3593446Smrj 
3603446Smrj     /* Set the Resource Type */
3613446Smrj 
3623446Smrj     Aml->SmallHeader.DescriptorType = DescriptorType;
3633446Smrj 
3643446Smrj     /* Set the Resource Length */
3653446Smrj 
3663446Smrj     AcpiRsSetResourceLength (TotalLength, Aml);
3673446Smrj }
3683446Smrj 
3693446Smrj 
3703446Smrj /*******************************************************************************
3713446Smrj  *
3723446Smrj  * FUNCTION:    AcpiRsStrcpy
3733446Smrj  *
3743446Smrj  * PARAMETERS:  Destination         - Pointer to the destination string
3753446Smrj  *              Source              - Pointer to the source string
3763446Smrj  *
3773446Smrj  * RETURN:      String length, including NULL terminator
3783446Smrj  *
3793446Smrj  * DESCRIPTION: Local string copy that returns the string length, saving a
3803446Smrj  *              strcpy followed by a strlen.
3813446Smrj  *
3823446Smrj  ******************************************************************************/
3833446Smrj 
3843446Smrj static UINT16
AcpiRsStrcpy(char * Destination,char * Source)3853446Smrj AcpiRsStrcpy (
3863446Smrj     char                    *Destination,
3873446Smrj     char                    *Source)
3883446Smrj {
3893446Smrj     UINT16                  i;
3903446Smrj 
3913446Smrj 
3923446Smrj     ACPI_FUNCTION_ENTRY ();
3933446Smrj 
3943446Smrj 
3953446Smrj     for (i = 0; Source[i]; i++)
3963446Smrj     {
3973446Smrj         Destination[i] = Source[i];
3983446Smrj     }
3993446Smrj 
4003446Smrj     Destination[i] = 0;
4013446Smrj 
4023446Smrj     /* Return string length including the NULL terminator */
4033446Smrj 
4043446Smrj     return ((UINT16) (i + 1));
4053446Smrj }
4063446Smrj 
4073446Smrj 
4083446Smrj /*******************************************************************************
4093446Smrj  *
4103446Smrj  * FUNCTION:    AcpiRsGetResourceSource
4113446Smrj  *
4123446Smrj  * PARAMETERS:  ResourceLength      - Length field of the descriptor
4133446Smrj  *              MinimumLength       - Minimum length of the descriptor (minus
4143446Smrj  *                                    any optional fields)
4153446Smrj  *              ResourceSource      - Where the ResourceSource is returned
4163446Smrj  *              Aml                 - Pointer to the raw AML descriptor
4173446Smrj  *              StringPtr           - (optional) where to store the actual
4183446Smrj  *                                    ResourceSource string
4193446Smrj  *
4203446Smrj  * RETURN:      Length of the string plus NULL terminator, rounded up to native
4213446Smrj  *              word boundary
4223446Smrj  *
4233446Smrj  * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
4243446Smrj  *              to an internal resource descriptor
4253446Smrj  *
4263446Smrj  ******************************************************************************/
4273446Smrj 
4283446Smrj ACPI_RS_LENGTH
AcpiRsGetResourceSource(ACPI_RS_LENGTH ResourceLength,ACPI_RS_LENGTH MinimumLength,ACPI_RESOURCE_SOURCE * ResourceSource,AML_RESOURCE * Aml,char * StringPtr)4293446Smrj AcpiRsGetResourceSource (
4303446Smrj     ACPI_RS_LENGTH          ResourceLength,
4313446Smrj     ACPI_RS_LENGTH          MinimumLength,
4323446Smrj     ACPI_RESOURCE_SOURCE    *ResourceSource,
4333446Smrj     AML_RESOURCE            *Aml,
4343446Smrj     char                    *StringPtr)
4353446Smrj {
4363446Smrj     ACPI_RSDESC_SIZE        TotalLength;
4373446Smrj     UINT8                   *AmlResourceSource;
4383446Smrj 
4393446Smrj 
4403446Smrj     ACPI_FUNCTION_ENTRY ();
4413446Smrj 
4423446Smrj 
4433446Smrj     TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
4443446Smrj     AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
4453446Smrj 
4463446Smrj     /*
4473446Smrj      * ResourceSource is present if the length of the descriptor is longer than
4483446Smrj      * the minimum length.
4493446Smrj      *
4503446Smrj      * Note: Some resource descriptors will have an additional null, so
4513446Smrj      * we add 1 to the minimum length.
4523446Smrj      */
4533446Smrj     if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
4543446Smrj     {
4553446Smrj         /* Get the ResourceSourceIndex */
4563446Smrj 
4573446Smrj         ResourceSource->Index = AmlResourceSource[0];
4583446Smrj 
4593446Smrj         ResourceSource->StringPtr = StringPtr;
4603446Smrj         if (!StringPtr)
4613446Smrj         {
4623446Smrj             /*
4633446Smrj              * String destination pointer is not specified; Set the String
4643446Smrj              * pointer to the end of the current ResourceSource structure.
4653446Smrj              */
4663446Smrj             ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
4673446Smrj                 sizeof (ACPI_RESOURCE_SOURCE));
4683446Smrj         }
4693446Smrj 
4703446Smrj         /*
4713446Smrj          * In order for the Resource length to be a multiple of the native
4723446Smrj          * word, calculate the length of the string (+1 for NULL terminator)
4733446Smrj          * and expand to the next word multiple.
4743446Smrj          *
4753446Smrj          * Zero the entire area of the buffer.
4763446Smrj          */
4773446Smrj         TotalLength = (UINT32) ACPI_STRLEN (
4783446Smrj             ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
4793446Smrj         TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
4803446Smrj 
4813446Smrj         ACPI_MEMSET (ResourceSource->StringPtr, 0, TotalLength);
4823446Smrj 
4833446Smrj         /* Copy the ResourceSource string to the destination */
4843446Smrj 
4853446Smrj         ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
4863446Smrj             ACPI_CAST_PTR (char, &AmlResourceSource[1]));
4873446Smrj 
4883446Smrj         return ((ACPI_RS_LENGTH) TotalLength);
4893446Smrj     }
4903446Smrj 
4913446Smrj     /* ResourceSource is not present */
4923446Smrj 
4933446Smrj     ResourceSource->Index = 0;
4943446Smrj     ResourceSource->StringLength = 0;
4953446Smrj     ResourceSource->StringPtr = NULL;
4963446Smrj     return (0);
4973446Smrj }
4983446Smrj 
4993446Smrj 
5003446Smrj /*******************************************************************************
5013446Smrj  *
5023446Smrj  * FUNCTION:    AcpiRsSetResourceSource
5033446Smrj  *
5043446Smrj  * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
5053446Smrj  *              MinimumLength       - Minimum length of the descriptor (minus
5063446Smrj  *                                    any optional fields)
5073446Smrj  *              ResourceSource      - Internal ResourceSource
5083446Smrj 
5093446Smrj  *
5103446Smrj  * RETURN:      Total length of the AML descriptor
5113446Smrj  *
5123446Smrj  * DESCRIPTION: Convert an optional ResourceSource from internal format to a
5133446Smrj  *              raw AML resource descriptor
5143446Smrj  *
5153446Smrj  ******************************************************************************/
5163446Smrj 
5173446Smrj ACPI_RSDESC_SIZE
AcpiRsSetResourceSource(AML_RESOURCE * Aml,ACPI_RS_LENGTH MinimumLength,ACPI_RESOURCE_SOURCE * ResourceSource)5183446Smrj AcpiRsSetResourceSource (
5193446Smrj     AML_RESOURCE            *Aml,
5203446Smrj     ACPI_RS_LENGTH          MinimumLength,
5213446Smrj     ACPI_RESOURCE_SOURCE    *ResourceSource)
5223446Smrj {
5233446Smrj     UINT8                   *AmlResourceSource;
5243446Smrj     ACPI_RSDESC_SIZE        DescriptorLength;
5253446Smrj 
5263446Smrj 
5273446Smrj     ACPI_FUNCTION_ENTRY ();
5283446Smrj 
5293446Smrj 
5303446Smrj     DescriptorLength = MinimumLength;
5313446Smrj 
5323446Smrj     /* Non-zero string length indicates presence of a ResourceSource */
5333446Smrj 
5343446Smrj     if (ResourceSource->StringLength)
5353446Smrj     {
5363446Smrj         /* Point to the end of the AML descriptor */
5373446Smrj 
5383446Smrj         AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
5393446Smrj 
5403446Smrj         /* Copy the ResourceSourceIndex */
5413446Smrj 
5423446Smrj         AmlResourceSource[0] = (UINT8) ResourceSource->Index;
5433446Smrj 
5443446Smrj         /* Copy the ResourceSource string */
5453446Smrj 
5463446Smrj         ACPI_STRCPY (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
5473446Smrj             ResourceSource->StringPtr);
5483446Smrj 
5493446Smrj         /*
5503446Smrj          * Add the length of the string (+ 1 for null terminator) to the
5513446Smrj          * final descriptor length
5523446Smrj          */
5533446Smrj         DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
5543446Smrj     }
5553446Smrj 
5563446Smrj     /* Return the new total length of the AML descriptor */
5573446Smrj 
5583446Smrj     return (DescriptorLength);
5593446Smrj }
5603446Smrj 
5613446Smrj 
5623446Smrj /*******************************************************************************
5633446Smrj  *
5643446Smrj  * FUNCTION:    AcpiRsGetPrtMethodData
5653446Smrj  *
5663446Smrj  * PARAMETERS:  Node            - Device node
5673446Smrj  *              RetBuffer       - Pointer to a buffer structure for the
5683446Smrj  *                                results
5693446Smrj  *
5703446Smrj  * RETURN:      Status
5713446Smrj  *
5723446Smrj  * DESCRIPTION: This function is called to get the _PRT value of an object
5733446Smrj  *              contained in an object specified by the handle passed in
5743446Smrj  *
5753446Smrj  *              If the function fails an appropriate status will be returned
5763446Smrj  *              and the contents of the callers buffer is undefined.
5773446Smrj  *
5783446Smrj  ******************************************************************************/
5793446Smrj 
5803446Smrj ACPI_STATUS
AcpiRsGetPrtMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)5813446Smrj AcpiRsGetPrtMethodData (
5823446Smrj     ACPI_NAMESPACE_NODE     *Node,
5833446Smrj     ACPI_BUFFER             *RetBuffer)
5843446Smrj {
5853446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
5863446Smrj     ACPI_STATUS             Status;
5873446Smrj 
5883446Smrj 
5893446Smrj     ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
5903446Smrj 
5913446Smrj 
5923446Smrj     /* Parameters guaranteed valid by caller */
5933446Smrj 
5943446Smrj     /* Execute the method, no parameters */
5953446Smrj 
5963446Smrj     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
5973446Smrj                 ACPI_BTYPE_PACKAGE, &ObjDesc);
5983446Smrj     if (ACPI_FAILURE (Status))
5993446Smrj     {
6003446Smrj         return_ACPI_STATUS (Status);
6013446Smrj     }
6023446Smrj 
6033446Smrj     /*
6043446Smrj      * Create a resource linked list from the byte stream buffer that comes
6053446Smrj      * back from the _CRS method execution.
6063446Smrj      */
6073446Smrj     Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
6083446Smrj 
6093446Smrj     /* On exit, we must delete the object returned by EvaluateObject */
6103446Smrj 
6113446Smrj     AcpiUtRemoveReference (ObjDesc);
6123446Smrj     return_ACPI_STATUS (Status);
6133446Smrj }
6143446Smrj 
6153446Smrj 
6163446Smrj /*******************************************************************************
6173446Smrj  *
6183446Smrj  * FUNCTION:    AcpiRsGetCrsMethodData
6193446Smrj  *
6203446Smrj  * PARAMETERS:  Node            - Device node
6213446Smrj  *              RetBuffer       - Pointer to a buffer structure for the
6223446Smrj  *                                results
6233446Smrj  *
6243446Smrj  * RETURN:      Status
6253446Smrj  *
6263446Smrj  * DESCRIPTION: This function is called to get the _CRS value of an object
6273446Smrj  *              contained in an object specified by the handle passed in
6283446Smrj  *
6293446Smrj  *              If the function fails an appropriate status will be returned
6303446Smrj  *              and the contents of the callers buffer is undefined.
6313446Smrj  *
6323446Smrj  ******************************************************************************/
6333446Smrj 
6343446Smrj ACPI_STATUS
AcpiRsGetCrsMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)6353446Smrj AcpiRsGetCrsMethodData (
6363446Smrj     ACPI_NAMESPACE_NODE     *Node,
6373446Smrj     ACPI_BUFFER             *RetBuffer)
6383446Smrj {
6393446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
6403446Smrj     ACPI_STATUS             Status;
6413446Smrj 
6423446Smrj 
6433446Smrj     ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
6443446Smrj 
6453446Smrj 
6463446Smrj     /* Parameters guaranteed valid by caller */
6473446Smrj 
6483446Smrj     /* Execute the method, no parameters */
6493446Smrj 
6503446Smrj     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
6513446Smrj                 ACPI_BTYPE_BUFFER, &ObjDesc);
6523446Smrj     if (ACPI_FAILURE (Status))
6533446Smrj     {
6543446Smrj         return_ACPI_STATUS (Status);
6553446Smrj     }
6563446Smrj 
6573446Smrj     /*
6583446Smrj      * Make the call to create a resource linked list from the
6593446Smrj      * byte stream buffer that comes back from the _CRS method
6603446Smrj      * execution.
6613446Smrj      */
6623446Smrj     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
6633446Smrj 
6643446Smrj     /* On exit, we must delete the object returned by evaluateObject */
6653446Smrj 
6663446Smrj     AcpiUtRemoveReference (ObjDesc);
6673446Smrj     return_ACPI_STATUS (Status);
6683446Smrj }
6693446Smrj 
6703446Smrj 
6713446Smrj /*******************************************************************************
6723446Smrj  *
6733446Smrj  * FUNCTION:    AcpiRsGetPrsMethodData
6743446Smrj  *
6753446Smrj  * PARAMETERS:  Node            - Device node
6763446Smrj  *              RetBuffer       - Pointer to a buffer structure for the
6773446Smrj  *                                results
6783446Smrj  *
6793446Smrj  * RETURN:      Status
6803446Smrj  *
6813446Smrj  * DESCRIPTION: This function is called to get the _PRS value of an object
6823446Smrj  *              contained in an object specified by the handle passed in
6833446Smrj  *
6843446Smrj  *              If the function fails an appropriate status will be returned
6853446Smrj  *              and the contents of the callers buffer is undefined.
6863446Smrj  *
6873446Smrj  ******************************************************************************/
6883446Smrj 
6893446Smrj ACPI_STATUS
AcpiRsGetPrsMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * RetBuffer)6903446Smrj AcpiRsGetPrsMethodData (
6913446Smrj     ACPI_NAMESPACE_NODE     *Node,
6923446Smrj     ACPI_BUFFER             *RetBuffer)
6933446Smrj {
6943446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
6953446Smrj     ACPI_STATUS             Status;
6963446Smrj 
6973446Smrj 
6983446Smrj     ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
6993446Smrj 
7003446Smrj 
7013446Smrj     /* Parameters guaranteed valid by caller */
7023446Smrj 
7033446Smrj     /* Execute the method, no parameters */
7043446Smrj 
7053446Smrj     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
7063446Smrj                 ACPI_BTYPE_BUFFER, &ObjDesc);
7073446Smrj     if (ACPI_FAILURE (Status))
7083446Smrj     {
7093446Smrj         return_ACPI_STATUS (Status);
7103446Smrj     }
7113446Smrj 
7123446Smrj     /*
7133446Smrj      * Make the call to create a resource linked list from the
7143446Smrj      * byte stream buffer that comes back from the _CRS method
7153446Smrj      * execution.
7163446Smrj      */
7173446Smrj     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
7183446Smrj 
7193446Smrj     /* On exit, we must delete the object returned by evaluateObject */
7203446Smrj 
7213446Smrj     AcpiUtRemoveReference (ObjDesc);
7223446Smrj     return_ACPI_STATUS (Status);
7233446Smrj }
7243446Smrj 
7253446Smrj 
7263446Smrj /*******************************************************************************
7273446Smrj  *
7283446Smrj  * FUNCTION:    AcpiRsGetMethodData
7293446Smrj  *
7303446Smrj  * PARAMETERS:  Handle          - Handle to the containing object
7313446Smrj  *              Path            - Path to method, relative to Handle
7323446Smrj  *              RetBuffer       - Pointer to a buffer structure for the
7333446Smrj  *                                results
7343446Smrj  *
7353446Smrj  * RETURN:      Status
7363446Smrj  *
7373446Smrj  * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
7383446Smrj  *              object contained in an object specified by the handle passed in
7393446Smrj  *
7403446Smrj  *              If the function fails an appropriate status will be returned
7413446Smrj  *              and the contents of the callers buffer is undefined.
7423446Smrj  *
7433446Smrj  ******************************************************************************/
7443446Smrj 
7453446Smrj ACPI_STATUS
AcpiRsGetMethodData(ACPI_HANDLE Handle,char * Path,ACPI_BUFFER * RetBuffer)7463446Smrj AcpiRsGetMethodData (
7473446Smrj     ACPI_HANDLE             Handle,
7483446Smrj     char                    *Path,
7493446Smrj     ACPI_BUFFER             *RetBuffer)
7503446Smrj {
7513446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
7523446Smrj     ACPI_STATUS             Status;
7533446Smrj 
7543446Smrj 
7553446Smrj     ACPI_FUNCTION_TRACE (RsGetMethodData);
7563446Smrj 
7573446Smrj 
7583446Smrj     /* Parameters guaranteed valid by caller */
7593446Smrj 
7603446Smrj     /* Execute the method, no parameters */
7613446Smrj 
7623446Smrj     Status = AcpiUtEvaluateObject (Handle, Path, ACPI_BTYPE_BUFFER, &ObjDesc);
7633446Smrj     if (ACPI_FAILURE (Status))
7643446Smrj     {
7653446Smrj         return_ACPI_STATUS (Status);
7663446Smrj     }
7673446Smrj 
7683446Smrj     /*
7693446Smrj      * Make the call to create a resource linked list from the
7703446Smrj      * byte stream buffer that comes back from the method
7713446Smrj      * execution.
7723446Smrj      */
7733446Smrj     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
7743446Smrj 
7753446Smrj     /* On exit, we must delete the object returned by EvaluateObject */
7763446Smrj 
7773446Smrj     AcpiUtRemoveReference (ObjDesc);
7783446Smrj     return_ACPI_STATUS (Status);
7793446Smrj }
7803446Smrj 
7813446Smrj 
7823446Smrj /*******************************************************************************
7833446Smrj  *
7843446Smrj  * FUNCTION:    AcpiRsSetSrsMethodData
7853446Smrj  *
7863446Smrj  * PARAMETERS:  Node            - Device node
7873446Smrj  *              InBuffer        - Pointer to a buffer structure of the
7883446Smrj  *                                parameter
7893446Smrj  *
7903446Smrj  * RETURN:      Status
7913446Smrj  *
7923446Smrj  * DESCRIPTION: This function is called to set the _SRS of an object contained
7933446Smrj  *              in an object specified by the handle passed in
7943446Smrj  *
7953446Smrj  *              If the function fails an appropriate status will be returned
7963446Smrj  *              and the contents of the callers buffer is undefined.
7973446Smrj  *
7983446Smrj  * Note: Parameters guaranteed valid by caller
7993446Smrj  *
8003446Smrj  ******************************************************************************/
8013446Smrj 
8023446Smrj ACPI_STATUS
AcpiRsSetSrsMethodData(ACPI_NAMESPACE_NODE * Node,ACPI_BUFFER * InBuffer)8033446Smrj AcpiRsSetSrsMethodData (
8043446Smrj     ACPI_NAMESPACE_NODE     *Node,
8053446Smrj     ACPI_BUFFER             *InBuffer)
8063446Smrj {
8073446Smrj     ACPI_EVALUATE_INFO      *Info;
8083446Smrj     ACPI_OPERAND_OBJECT     *Args[2];
8093446Smrj     ACPI_STATUS             Status;
8103446Smrj     ACPI_BUFFER             Buffer;
8113446Smrj 
8123446Smrj 
8133446Smrj     ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
8143446Smrj 
8153446Smrj 
8163446Smrj     /* Allocate and initialize the evaluation information block */
8173446Smrj 
8183446Smrj     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
8193446Smrj     if (!Info)
8203446Smrj     {
8213446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
8223446Smrj     }
8233446Smrj 
8243446Smrj     Info->PrefixNode = Node;
8253446Smrj     Info->Pathname = METHOD_NAME__SRS;
8263446Smrj     Info->Parameters = Args;
8273446Smrj     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
8283446Smrj 
8293446Smrj     /*
8303446Smrj      * The InBuffer parameter will point to a linked list of
8313446Smrj      * resource parameters. It needs to be formatted into a
8323446Smrj      * byte stream to be sent in as an input parameter to _SRS
8333446Smrj      *
8343446Smrj      * Convert the linked list into a byte stream
8353446Smrj      */
8363446Smrj     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
8373446Smrj     Status = AcpiRsCreateAmlResources (InBuffer->Pointer, &Buffer);
8383446Smrj     if (ACPI_FAILURE (Status))
8393446Smrj     {
8403446Smrj         goto Cleanup;
8413446Smrj     }
8423446Smrj 
8433446Smrj     /* Create and initialize the method parameter object */
8443446Smrj 
8453446Smrj     Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
8463446Smrj     if (!Args[0])
8473446Smrj     {
8483446Smrj         /*
8493446Smrj          * Must free the buffer allocated above (otherwise it is freed
8503446Smrj          * later)
8513446Smrj          */
8523446Smrj         ACPI_FREE (Buffer.Pointer);
8533446Smrj         Status = AE_NO_MEMORY;
8543446Smrj         goto Cleanup;
8553446Smrj     }
8563446Smrj 
8573446Smrj     Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
8583446Smrj     Args[0]->Buffer.Pointer = Buffer.Pointer;
8593446Smrj     Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
8603446Smrj     Args[1] = NULL;
8613446Smrj 
8623446Smrj     /* Execute the method, no return value is expected */
8633446Smrj 
8643446Smrj     Status = AcpiNsEvaluate (Info);
8653446Smrj 
8663446Smrj     /* Clean up and return the status from AcpiNsEvaluate */
8673446Smrj 
8683446Smrj     AcpiUtRemoveReference (Args[0]);
8693446Smrj 
8703446Smrj Cleanup:
8713446Smrj     ACPI_FREE (Info);
8723446Smrj     return_ACPI_STATUS (Status);
8733446Smrj }
8743446Smrj 
875