Home | History | Annotate | Line # | Download | only in resources
rsutils.c revision 1.7
      1  1.1    jruoho /*******************************************************************************
      2  1.1    jruoho  *
      3  1.1    jruoho  * Module Name: rsutils - Utilities for the resource manager
      4  1.1    jruoho  *
      5  1.1    jruoho  ******************************************************************************/
      6  1.1    jruoho 
      7  1.3    jruoho /*
      8  1.6  christos  * Copyright (C) 2000 - 2015, Intel Corp.
      9  1.1    jruoho  * All rights reserved.
     10  1.1    jruoho  *
     11  1.3    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.3    jruoho  * modification, are permitted provided that the following conditions
     13  1.3    jruoho  * are met:
     14  1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.3    jruoho  *    without modification.
     17  1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.3    jruoho  *    binary redistribution.
     22  1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.3    jruoho  *    from this software without specific prior written permission.
     25  1.3    jruoho  *
     26  1.3    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.3    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.3    jruoho  * Software Foundation.
     29  1.3    jruoho  *
     30  1.3    jruoho  * NO WARRANTY
     31  1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.3    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.3    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.3    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.3    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.3    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.3    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.3    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.3    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.3    jruoho  */
     43  1.1    jruoho 
     44  1.1    jruoho #include "acpi.h"
     45  1.1    jruoho #include "accommon.h"
     46  1.1    jruoho #include "acnamesp.h"
     47  1.1    jruoho #include "acresrc.h"
     48  1.1    jruoho 
     49  1.1    jruoho 
     50  1.1    jruoho #define _COMPONENT          ACPI_RESOURCES
     51  1.1    jruoho         ACPI_MODULE_NAME    ("rsutils")
     52  1.1    jruoho 
     53  1.1    jruoho 
     54  1.1    jruoho /*******************************************************************************
     55  1.1    jruoho  *
     56  1.1    jruoho  * FUNCTION:    AcpiRsDecodeBitmask
     57  1.1    jruoho  *
     58  1.1    jruoho  * PARAMETERS:  Mask            - Bitmask to decode
     59  1.1    jruoho  *              List            - Where the converted list is returned
     60  1.1    jruoho  *
     61  1.1    jruoho  * RETURN:      Count of bits set (length of list)
     62  1.1    jruoho  *
     63  1.1    jruoho  * DESCRIPTION: Convert a bit mask into a list of values
     64  1.1    jruoho  *
     65  1.1    jruoho  ******************************************************************************/
     66  1.1    jruoho 
     67  1.1    jruoho UINT8
     68  1.1    jruoho AcpiRsDecodeBitmask (
     69  1.1    jruoho     UINT16                  Mask,
     70  1.1    jruoho     UINT8                   *List)
     71  1.1    jruoho {
     72  1.1    jruoho     UINT8                   i;
     73  1.1    jruoho     UINT8                   BitCount;
     74  1.1    jruoho 
     75  1.1    jruoho 
     76  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
     77  1.1    jruoho 
     78  1.1    jruoho 
     79  1.1    jruoho     /* Decode the mask bits */
     80  1.1    jruoho 
     81  1.1    jruoho     for (i = 0, BitCount = 0; Mask; i++)
     82  1.1    jruoho     {
     83  1.1    jruoho         if (Mask & 0x0001)
     84  1.1    jruoho         {
     85  1.1    jruoho             List[BitCount] = i;
     86  1.1    jruoho             BitCount++;
     87  1.1    jruoho         }
     88  1.1    jruoho 
     89  1.1    jruoho         Mask >>= 1;
     90  1.1    jruoho     }
     91  1.1    jruoho 
     92  1.1    jruoho     return (BitCount);
     93  1.1    jruoho }
     94  1.1    jruoho 
     95  1.1    jruoho 
     96  1.1    jruoho /*******************************************************************************
     97  1.1    jruoho  *
     98  1.1    jruoho  * FUNCTION:    AcpiRsEncodeBitmask
     99  1.1    jruoho  *
    100  1.1    jruoho  * PARAMETERS:  List            - List of values to encode
    101  1.1    jruoho  *              Count           - Length of list
    102  1.1    jruoho  *
    103  1.1    jruoho  * RETURN:      Encoded bitmask
    104  1.1    jruoho  *
    105  1.1    jruoho  * DESCRIPTION: Convert a list of values to an encoded bitmask
    106  1.1    jruoho  *
    107  1.1    jruoho  ******************************************************************************/
    108  1.1    jruoho 
    109  1.1    jruoho UINT16
    110  1.1    jruoho AcpiRsEncodeBitmask (
    111  1.1    jruoho     UINT8                   *List,
    112  1.1    jruoho     UINT8                   Count)
    113  1.1    jruoho {
    114  1.1    jruoho     UINT32                  i;
    115  1.1    jruoho     UINT16                  Mask;
    116  1.1    jruoho 
    117  1.1    jruoho 
    118  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    119  1.1    jruoho 
    120  1.1    jruoho 
    121  1.1    jruoho     /* Encode the list into a single bitmask */
    122  1.1    jruoho 
    123  1.1    jruoho     for (i = 0, Mask = 0; i < Count; i++)
    124  1.1    jruoho     {
    125  1.1    jruoho         Mask |= (0x1 << List[i]);
    126  1.1    jruoho     }
    127  1.1    jruoho 
    128  1.1    jruoho     return (Mask);
    129  1.1    jruoho }
    130  1.1    jruoho 
    131  1.1    jruoho 
    132  1.1    jruoho /*******************************************************************************
    133  1.1    jruoho  *
    134  1.1    jruoho  * FUNCTION:    AcpiRsMoveData
    135  1.1    jruoho  *
    136  1.1    jruoho  * PARAMETERS:  Destination         - Pointer to the destination descriptor
    137  1.1    jruoho  *              Source              - Pointer to the source descriptor
    138  1.1    jruoho  *              ItemCount           - How many items to move
    139  1.1    jruoho  *              MoveType            - Byte width
    140  1.1    jruoho  *
    141  1.1    jruoho  * RETURN:      None
    142  1.1    jruoho  *
    143  1.1    jruoho  * DESCRIPTION: Move multiple data items from one descriptor to another. Handles
    144  1.1    jruoho  *              alignment issues and endian issues if necessary, as configured
    145  1.1    jruoho  *              via the ACPI_MOVE_* macros. (This is why a memcpy is not used)
    146  1.1    jruoho  *
    147  1.1    jruoho  ******************************************************************************/
    148  1.1    jruoho 
    149  1.1    jruoho void
    150  1.1    jruoho AcpiRsMoveData (
    151  1.1    jruoho     void                    *Destination,
    152  1.1    jruoho     void                    *Source,
    153  1.1    jruoho     UINT16                  ItemCount,
    154  1.1    jruoho     UINT8                   MoveType)
    155  1.1    jruoho {
    156  1.1    jruoho     UINT32                  i;
    157  1.1    jruoho 
    158  1.1    jruoho 
    159  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    160  1.1    jruoho 
    161  1.1    jruoho 
    162  1.1    jruoho     /* One move per item */
    163  1.1    jruoho 
    164  1.1    jruoho     for (i = 0; i < ItemCount; i++)
    165  1.1    jruoho     {
    166  1.1    jruoho         switch (MoveType)
    167  1.1    jruoho         {
    168  1.1    jruoho         /*
    169  1.1    jruoho          * For the 8-bit case, we can perform the move all at once
    170  1.1    jruoho          * since there are no alignment or endian issues
    171  1.1    jruoho          */
    172  1.1    jruoho         case ACPI_RSC_MOVE8:
    173  1.4  christos         case ACPI_RSC_MOVE_GPIO_RES:
    174  1.4  christos         case ACPI_RSC_MOVE_SERIAL_VEN:
    175  1.4  christos         case ACPI_RSC_MOVE_SERIAL_RES:
    176  1.4  christos 
    177  1.7  christos             memcpy (Destination, Source, ItemCount);
    178  1.1    jruoho             return;
    179  1.1    jruoho 
    180  1.1    jruoho         /*
    181  1.1    jruoho          * 16-, 32-, and 64-bit cases must use the move macros that perform
    182  1.4  christos          * endian conversion and/or accommodate hardware that cannot perform
    183  1.1    jruoho          * misaligned memory transfers
    184  1.1    jruoho          */
    185  1.1    jruoho         case ACPI_RSC_MOVE16:
    186  1.4  christos         case ACPI_RSC_MOVE_GPIO_PIN:
    187  1.4  christos 
    188  1.1    jruoho             ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
    189  1.1    jruoho                                 &ACPI_CAST_PTR (UINT16, Source)[i]);
    190  1.1    jruoho             break;
    191  1.1    jruoho 
    192  1.1    jruoho         case ACPI_RSC_MOVE32:
    193  1.4  christos 
    194  1.1    jruoho             ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
    195  1.1    jruoho                                 &ACPI_CAST_PTR (UINT32, Source)[i]);
    196  1.1    jruoho             break;
    197  1.1    jruoho 
    198  1.1    jruoho         case ACPI_RSC_MOVE64:
    199  1.4  christos 
    200  1.1    jruoho             ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
    201  1.1    jruoho                                 &ACPI_CAST_PTR (UINT64, Source)[i]);
    202  1.1    jruoho             break;
    203  1.1    jruoho 
    204  1.1    jruoho         default:
    205  1.4  christos 
    206  1.1    jruoho             return;
    207  1.1    jruoho         }
    208  1.1    jruoho     }
    209  1.1    jruoho }
    210  1.1    jruoho 
    211  1.1    jruoho 
    212  1.1    jruoho /*******************************************************************************
    213  1.1    jruoho  *
    214  1.1    jruoho  * FUNCTION:    AcpiRsSetResourceLength
    215  1.1    jruoho  *
    216  1.1    jruoho  * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
    217  1.1    jruoho  *                                    the header and length fields.
    218  1.1    jruoho  *              Aml                 - Pointer to the raw AML descriptor
    219  1.1    jruoho  *
    220  1.1    jruoho  * RETURN:      None
    221  1.1    jruoho  *
    222  1.1    jruoho  * DESCRIPTION: Set the ResourceLength field of an AML
    223  1.1    jruoho  *              resource descriptor, both Large and Small descriptors are
    224  1.1    jruoho  *              supported automatically. Note: Descriptor Type field must
    225  1.1    jruoho  *              be valid.
    226  1.1    jruoho  *
    227  1.1    jruoho  ******************************************************************************/
    228  1.1    jruoho 
    229  1.1    jruoho void
    230  1.1    jruoho AcpiRsSetResourceLength (
    231  1.1    jruoho     ACPI_RSDESC_SIZE        TotalLength,
    232  1.1    jruoho     AML_RESOURCE            *Aml)
    233  1.1    jruoho {
    234  1.1    jruoho     ACPI_RS_LENGTH          ResourceLength;
    235  1.1    jruoho 
    236  1.1    jruoho 
    237  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    238  1.1    jruoho 
    239  1.1    jruoho 
    240  1.1    jruoho     /* Length is the total descriptor length minus the header length */
    241  1.1    jruoho 
    242  1.1    jruoho     ResourceLength = (ACPI_RS_LENGTH)
    243  1.1    jruoho         (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
    244  1.1    jruoho 
    245  1.1    jruoho     /* Length is stored differently for large and small descriptors */
    246  1.1    jruoho 
    247  1.1    jruoho     if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
    248  1.1    jruoho     {
    249  1.1    jruoho         /* Large descriptor -- bytes 1-2 contain the 16-bit length */
    250  1.1    jruoho 
    251  1.1    jruoho         ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
    252  1.1    jruoho     }
    253  1.1    jruoho     else
    254  1.1    jruoho     {
    255  1.1    jruoho         /* Small descriptor -- bits 2:0 of byte 0 contain the length */
    256  1.1    jruoho 
    257  1.1    jruoho         Aml->SmallHeader.DescriptorType = (UINT8)
    258  1.1    jruoho 
    259  1.1    jruoho             /* Clear any existing length, preserving descriptor type bits */
    260  1.1    jruoho 
    261  1.1    jruoho             ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
    262  1.1    jruoho 
    263  1.1    jruoho             | ResourceLength);
    264  1.1    jruoho     }
    265  1.1    jruoho }
    266  1.1    jruoho 
    267  1.1    jruoho 
    268  1.1    jruoho /*******************************************************************************
    269  1.1    jruoho  *
    270  1.1    jruoho  * FUNCTION:    AcpiRsSetResourceHeader
    271  1.1    jruoho  *
    272  1.1    jruoho  * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
    273  1.1    jruoho  *              TotalLength         - Length of the AML descriptor, including
    274  1.1    jruoho  *                                    the header and length fields.
    275  1.1    jruoho  *              Aml                 - Pointer to the raw AML descriptor
    276  1.1    jruoho  *
    277  1.1    jruoho  * RETURN:      None
    278  1.1    jruoho  *
    279  1.1    jruoho  * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
    280  1.1    jruoho  *              resource descriptor, both Large and Small descriptors are
    281  1.1    jruoho  *              supported automatically
    282  1.1    jruoho  *
    283  1.1    jruoho  ******************************************************************************/
    284  1.1    jruoho 
    285  1.1    jruoho void
    286  1.1    jruoho AcpiRsSetResourceHeader (
    287  1.1    jruoho     UINT8                   DescriptorType,
    288  1.1    jruoho     ACPI_RSDESC_SIZE        TotalLength,
    289  1.1    jruoho     AML_RESOURCE            *Aml)
    290  1.1    jruoho {
    291  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    292  1.1    jruoho 
    293  1.1    jruoho 
    294  1.1    jruoho     /* Set the Resource Type */
    295  1.1    jruoho 
    296  1.1    jruoho     Aml->SmallHeader.DescriptorType = DescriptorType;
    297  1.1    jruoho 
    298  1.1    jruoho     /* Set the Resource Length */
    299  1.1    jruoho 
    300  1.1    jruoho     AcpiRsSetResourceLength (TotalLength, Aml);
    301  1.1    jruoho }
    302  1.1    jruoho 
    303  1.1    jruoho 
    304  1.1    jruoho /*******************************************************************************
    305  1.1    jruoho  *
    306  1.1    jruoho  * FUNCTION:    AcpiRsStrcpy
    307  1.1    jruoho  *
    308  1.1    jruoho  * PARAMETERS:  Destination         - Pointer to the destination string
    309  1.1    jruoho  *              Source              - Pointer to the source string
    310  1.1    jruoho  *
    311  1.1    jruoho  * RETURN:      String length, including NULL terminator
    312  1.1    jruoho  *
    313  1.1    jruoho  * DESCRIPTION: Local string copy that returns the string length, saving a
    314  1.1    jruoho  *              strcpy followed by a strlen.
    315  1.1    jruoho  *
    316  1.1    jruoho  ******************************************************************************/
    317  1.1    jruoho 
    318  1.1    jruoho static UINT16
    319  1.1    jruoho AcpiRsStrcpy (
    320  1.1    jruoho     char                    *Destination,
    321  1.1    jruoho     char                    *Source)
    322  1.1    jruoho {
    323  1.1    jruoho     UINT16                  i;
    324  1.1    jruoho 
    325  1.1    jruoho 
    326  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    327  1.1    jruoho 
    328  1.1    jruoho 
    329  1.1    jruoho     for (i = 0; Source[i]; i++)
    330  1.1    jruoho     {
    331  1.1    jruoho         Destination[i] = Source[i];
    332  1.1    jruoho     }
    333  1.1    jruoho 
    334  1.1    jruoho     Destination[i] = 0;
    335  1.1    jruoho 
    336  1.1    jruoho     /* Return string length including the NULL terminator */
    337  1.1    jruoho 
    338  1.1    jruoho     return ((UINT16) (i + 1));
    339  1.1    jruoho }
    340  1.1    jruoho 
    341  1.1    jruoho 
    342  1.1    jruoho /*******************************************************************************
    343  1.1    jruoho  *
    344  1.1    jruoho  * FUNCTION:    AcpiRsGetResourceSource
    345  1.1    jruoho  *
    346  1.1    jruoho  * PARAMETERS:  ResourceLength      - Length field of the descriptor
    347  1.1    jruoho  *              MinimumLength       - Minimum length of the descriptor (minus
    348  1.1    jruoho  *                                    any optional fields)
    349  1.1    jruoho  *              ResourceSource      - Where the ResourceSource is returned
    350  1.1    jruoho  *              Aml                 - Pointer to the raw AML descriptor
    351  1.1    jruoho  *              StringPtr           - (optional) where to store the actual
    352  1.1    jruoho  *                                    ResourceSource string
    353  1.1    jruoho  *
    354  1.1    jruoho  * RETURN:      Length of the string plus NULL terminator, rounded up to native
    355  1.1    jruoho  *              word boundary
    356  1.1    jruoho  *
    357  1.1    jruoho  * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
    358  1.1    jruoho  *              to an internal resource descriptor
    359  1.1    jruoho  *
    360  1.1    jruoho  ******************************************************************************/
    361  1.1    jruoho 
    362  1.1    jruoho ACPI_RS_LENGTH
    363  1.1    jruoho AcpiRsGetResourceSource (
    364  1.1    jruoho     ACPI_RS_LENGTH          ResourceLength,
    365  1.1    jruoho     ACPI_RS_LENGTH          MinimumLength,
    366  1.1    jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource,
    367  1.1    jruoho     AML_RESOURCE            *Aml,
    368  1.1    jruoho     char                    *StringPtr)
    369  1.1    jruoho {
    370  1.1    jruoho     ACPI_RSDESC_SIZE        TotalLength;
    371  1.1    jruoho     UINT8                   *AmlResourceSource;
    372  1.1    jruoho 
    373  1.1    jruoho 
    374  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    375  1.1    jruoho 
    376  1.1    jruoho 
    377  1.1    jruoho     TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
    378  1.1    jruoho     AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
    379  1.1    jruoho 
    380  1.1    jruoho     /*
    381  1.1    jruoho      * ResourceSource is present if the length of the descriptor is longer than
    382  1.1    jruoho      * the minimum length.
    383  1.1    jruoho      *
    384  1.1    jruoho      * Note: Some resource descriptors will have an additional null, so
    385  1.1    jruoho      * we add 1 to the minimum length.
    386  1.1    jruoho      */
    387  1.1    jruoho     if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
    388  1.1    jruoho     {
    389  1.1    jruoho         /* Get the ResourceSourceIndex */
    390  1.1    jruoho 
    391  1.1    jruoho         ResourceSource->Index = AmlResourceSource[0];
    392  1.1    jruoho 
    393  1.1    jruoho         ResourceSource->StringPtr = StringPtr;
    394  1.1    jruoho         if (!StringPtr)
    395  1.1    jruoho         {
    396  1.1    jruoho             /*
    397  1.1    jruoho              * String destination pointer is not specified; Set the String
    398  1.1    jruoho              * pointer to the end of the current ResourceSource structure.
    399  1.1    jruoho              */
    400  1.1    jruoho             ResourceSource->StringPtr = ACPI_ADD_PTR (char, ResourceSource,
    401  1.1    jruoho                 sizeof (ACPI_RESOURCE_SOURCE));
    402  1.1    jruoho         }
    403  1.1    jruoho 
    404  1.1    jruoho         /*
    405  1.1    jruoho          * In order for the Resource length to be a multiple of the native
    406  1.1    jruoho          * word, calculate the length of the string (+1 for NULL terminator)
    407  1.1    jruoho          * and expand to the next word multiple.
    408  1.1    jruoho          *
    409  1.1    jruoho          * Zero the entire area of the buffer.
    410  1.1    jruoho          */
    411  1.7  christos         TotalLength = (UINT32) strlen (
    412  1.1    jruoho             ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
    413  1.1    jruoho         TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
    414  1.1    jruoho 
    415  1.7  christos         memset (ResourceSource->StringPtr, 0, TotalLength);
    416  1.1    jruoho 
    417  1.1    jruoho         /* Copy the ResourceSource string to the destination */
    418  1.1    jruoho 
    419  1.1    jruoho         ResourceSource->StringLength = AcpiRsStrcpy (ResourceSource->StringPtr,
    420  1.1    jruoho             ACPI_CAST_PTR (char, &AmlResourceSource[1]));
    421  1.1    jruoho 
    422  1.1    jruoho         return ((ACPI_RS_LENGTH) TotalLength);
    423  1.1    jruoho     }
    424  1.1    jruoho 
    425  1.1    jruoho     /* ResourceSource is not present */
    426  1.1    jruoho 
    427  1.1    jruoho     ResourceSource->Index = 0;
    428  1.1    jruoho     ResourceSource->StringLength = 0;
    429  1.1    jruoho     ResourceSource->StringPtr = NULL;
    430  1.1    jruoho     return (0);
    431  1.1    jruoho }
    432  1.1    jruoho 
    433  1.1    jruoho 
    434  1.1    jruoho /*******************************************************************************
    435  1.1    jruoho  *
    436  1.1    jruoho  * FUNCTION:    AcpiRsSetResourceSource
    437  1.1    jruoho  *
    438  1.1    jruoho  * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
    439  1.1    jruoho  *              MinimumLength       - Minimum length of the descriptor (minus
    440  1.1    jruoho  *                                    any optional fields)
    441  1.1    jruoho  *              ResourceSource      - Internal ResourceSource
    442  1.1    jruoho 
    443  1.1    jruoho  *
    444  1.1    jruoho  * RETURN:      Total length of the AML descriptor
    445  1.1    jruoho  *
    446  1.1    jruoho  * DESCRIPTION: Convert an optional ResourceSource from internal format to a
    447  1.1    jruoho  *              raw AML resource descriptor
    448  1.1    jruoho  *
    449  1.1    jruoho  ******************************************************************************/
    450  1.1    jruoho 
    451  1.1    jruoho ACPI_RSDESC_SIZE
    452  1.1    jruoho AcpiRsSetResourceSource (
    453  1.1    jruoho     AML_RESOURCE            *Aml,
    454  1.1    jruoho     ACPI_RS_LENGTH          MinimumLength,
    455  1.1    jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource)
    456  1.1    jruoho {
    457  1.1    jruoho     UINT8                   *AmlResourceSource;
    458  1.1    jruoho     ACPI_RSDESC_SIZE        DescriptorLength;
    459  1.1    jruoho 
    460  1.1    jruoho 
    461  1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    462  1.1    jruoho 
    463  1.1    jruoho 
    464  1.1    jruoho     DescriptorLength = MinimumLength;
    465  1.1    jruoho 
    466  1.1    jruoho     /* Non-zero string length indicates presence of a ResourceSource */
    467  1.1    jruoho 
    468  1.1    jruoho     if (ResourceSource->StringLength)
    469  1.1    jruoho     {
    470  1.1    jruoho         /* Point to the end of the AML descriptor */
    471  1.1    jruoho 
    472  1.1    jruoho         AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
    473  1.1    jruoho 
    474  1.1    jruoho         /* Copy the ResourceSourceIndex */
    475  1.1    jruoho 
    476  1.1    jruoho         AmlResourceSource[0] = (UINT8) ResourceSource->Index;
    477  1.1    jruoho 
    478  1.1    jruoho         /* Copy the ResourceSource string */
    479  1.1    jruoho 
    480  1.7  christos         strcpy (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
    481  1.1    jruoho             ResourceSource->StringPtr);
    482  1.1    jruoho 
    483  1.1    jruoho         /*
    484  1.1    jruoho          * Add the length of the string (+ 1 for null terminator) to the
    485  1.1    jruoho          * final descriptor length
    486  1.1    jruoho          */
    487  1.1    jruoho         DescriptorLength += ((ACPI_RSDESC_SIZE) ResourceSource->StringLength + 1);
    488  1.1    jruoho     }
    489  1.1    jruoho 
    490  1.1    jruoho     /* Return the new total length of the AML descriptor */
    491  1.1    jruoho 
    492  1.1    jruoho     return (DescriptorLength);
    493  1.1    jruoho }
    494  1.1    jruoho 
    495  1.1    jruoho 
    496  1.1    jruoho /*******************************************************************************
    497  1.1    jruoho  *
    498  1.1    jruoho  * FUNCTION:    AcpiRsGetPrtMethodData
    499  1.1    jruoho  *
    500  1.1    jruoho  * PARAMETERS:  Node            - Device node
    501  1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    502  1.1    jruoho  *                                results
    503  1.1    jruoho  *
    504  1.1    jruoho  * RETURN:      Status
    505  1.1    jruoho  *
    506  1.1    jruoho  * DESCRIPTION: This function is called to get the _PRT value of an object
    507  1.1    jruoho  *              contained in an object specified by the handle passed in
    508  1.1    jruoho  *
    509  1.1    jruoho  *              If the function fails an appropriate status will be returned
    510  1.1    jruoho  *              and the contents of the callers buffer is undefined.
    511  1.1    jruoho  *
    512  1.1    jruoho  ******************************************************************************/
    513  1.1    jruoho 
    514  1.1    jruoho ACPI_STATUS
    515  1.1    jruoho AcpiRsGetPrtMethodData (
    516  1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    517  1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    518  1.1    jruoho {
    519  1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    520  1.1    jruoho     ACPI_STATUS             Status;
    521  1.1    jruoho 
    522  1.1    jruoho 
    523  1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
    524  1.1    jruoho 
    525  1.1    jruoho 
    526  1.1    jruoho     /* Parameters guaranteed valid by caller */
    527  1.1    jruoho 
    528  1.1    jruoho     /* Execute the method, no parameters */
    529  1.1    jruoho 
    530  1.1    jruoho     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRT,
    531  1.1    jruoho                 ACPI_BTYPE_PACKAGE, &ObjDesc);
    532  1.1    jruoho     if (ACPI_FAILURE (Status))
    533  1.1    jruoho     {
    534  1.1    jruoho         return_ACPI_STATUS (Status);
    535  1.1    jruoho     }
    536  1.1    jruoho 
    537  1.1    jruoho     /*
    538  1.1    jruoho      * Create a resource linked list from the byte stream buffer that comes
    539  1.1    jruoho      * back from the _CRS method execution.
    540  1.1    jruoho      */
    541  1.1    jruoho     Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
    542  1.1    jruoho 
    543  1.1    jruoho     /* On exit, we must delete the object returned by EvaluateObject */
    544  1.1    jruoho 
    545  1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    546  1.1    jruoho     return_ACPI_STATUS (Status);
    547  1.1    jruoho }
    548  1.1    jruoho 
    549  1.1    jruoho 
    550  1.1    jruoho /*******************************************************************************
    551  1.1    jruoho  *
    552  1.1    jruoho  * FUNCTION:    AcpiRsGetCrsMethodData
    553  1.1    jruoho  *
    554  1.1    jruoho  * PARAMETERS:  Node            - Device node
    555  1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    556  1.1    jruoho  *                                results
    557  1.1    jruoho  *
    558  1.1    jruoho  * RETURN:      Status
    559  1.1    jruoho  *
    560  1.1    jruoho  * DESCRIPTION: This function is called to get the _CRS value of an object
    561  1.1    jruoho  *              contained in an object specified by the handle passed in
    562  1.1    jruoho  *
    563  1.1    jruoho  *              If the function fails an appropriate status will be returned
    564  1.1    jruoho  *              and the contents of the callers buffer is undefined.
    565  1.1    jruoho  *
    566  1.1    jruoho  ******************************************************************************/
    567  1.1    jruoho 
    568  1.1    jruoho ACPI_STATUS
    569  1.1    jruoho AcpiRsGetCrsMethodData (
    570  1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    571  1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    572  1.1    jruoho {
    573  1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    574  1.1    jruoho     ACPI_STATUS             Status;
    575  1.1    jruoho 
    576  1.1    jruoho 
    577  1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
    578  1.1    jruoho 
    579  1.1    jruoho 
    580  1.1    jruoho     /* Parameters guaranteed valid by caller */
    581  1.1    jruoho 
    582  1.1    jruoho     /* Execute the method, no parameters */
    583  1.1    jruoho 
    584  1.1    jruoho     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__CRS,
    585  1.1    jruoho                 ACPI_BTYPE_BUFFER, &ObjDesc);
    586  1.1    jruoho     if (ACPI_FAILURE (Status))
    587  1.1    jruoho     {
    588  1.1    jruoho         return_ACPI_STATUS (Status);
    589  1.1    jruoho     }
    590  1.1    jruoho 
    591  1.1    jruoho     /*
    592  1.1    jruoho      * Make the call to create a resource linked list from the
    593  1.1    jruoho      * byte stream buffer that comes back from the _CRS method
    594  1.1    jruoho      * execution.
    595  1.1    jruoho      */
    596  1.1    jruoho     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    597  1.1    jruoho 
    598  1.1    jruoho     /* On exit, we must delete the object returned by evaluateObject */
    599  1.1    jruoho 
    600  1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    601  1.1    jruoho     return_ACPI_STATUS (Status);
    602  1.1    jruoho }
    603  1.1    jruoho 
    604  1.1    jruoho 
    605  1.1    jruoho /*******************************************************************************
    606  1.1    jruoho  *
    607  1.1    jruoho  * FUNCTION:    AcpiRsGetPrsMethodData
    608  1.1    jruoho  *
    609  1.1    jruoho  * PARAMETERS:  Node            - Device node
    610  1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    611  1.1    jruoho  *                                results
    612  1.1    jruoho  *
    613  1.1    jruoho  * RETURN:      Status
    614  1.1    jruoho  *
    615  1.1    jruoho  * DESCRIPTION: This function is called to get the _PRS value of an object
    616  1.1    jruoho  *              contained in an object specified by the handle passed in
    617  1.1    jruoho  *
    618  1.1    jruoho  *              If the function fails an appropriate status will be returned
    619  1.1    jruoho  *              and the contents of the callers buffer is undefined.
    620  1.1    jruoho  *
    621  1.1    jruoho  ******************************************************************************/
    622  1.1    jruoho 
    623  1.1    jruoho ACPI_STATUS
    624  1.1    jruoho AcpiRsGetPrsMethodData (
    625  1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    626  1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    627  1.1    jruoho {
    628  1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    629  1.1    jruoho     ACPI_STATUS             Status;
    630  1.1    jruoho 
    631  1.1    jruoho 
    632  1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
    633  1.1    jruoho 
    634  1.1    jruoho 
    635  1.1    jruoho     /* Parameters guaranteed valid by caller */
    636  1.1    jruoho 
    637  1.1    jruoho     /* Execute the method, no parameters */
    638  1.1    jruoho 
    639  1.1    jruoho     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__PRS,
    640  1.1    jruoho                 ACPI_BTYPE_BUFFER, &ObjDesc);
    641  1.1    jruoho     if (ACPI_FAILURE (Status))
    642  1.1    jruoho     {
    643  1.1    jruoho         return_ACPI_STATUS (Status);
    644  1.1    jruoho     }
    645  1.1    jruoho 
    646  1.1    jruoho     /*
    647  1.1    jruoho      * Make the call to create a resource linked list from the
    648  1.1    jruoho      * byte stream buffer that comes back from the _CRS method
    649  1.1    jruoho      * execution.
    650  1.1    jruoho      */
    651  1.1    jruoho     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    652  1.1    jruoho 
    653  1.1    jruoho     /* On exit, we must delete the object returned by evaluateObject */
    654  1.1    jruoho 
    655  1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    656  1.1    jruoho     return_ACPI_STATUS (Status);
    657  1.1    jruoho }
    658  1.1    jruoho 
    659  1.1    jruoho 
    660  1.1    jruoho /*******************************************************************************
    661  1.1    jruoho  *
    662  1.4  christos  * FUNCTION:    AcpiRsGetAeiMethodData
    663  1.4  christos  *
    664  1.4  christos  * PARAMETERS:  Node            - Device node
    665  1.4  christos  *              RetBuffer       - Pointer to a buffer structure for the
    666  1.4  christos  *                                results
    667  1.4  christos  *
    668  1.4  christos  * RETURN:      Status
    669  1.4  christos  *
    670  1.4  christos  * DESCRIPTION: This function is called to get the _AEI value of an object
    671  1.4  christos  *              contained in an object specified by the handle passed in
    672  1.4  christos  *
    673  1.4  christos  *              If the function fails an appropriate status will be returned
    674  1.4  christos  *              and the contents of the callers buffer is undefined.
    675  1.4  christos  *
    676  1.4  christos  ******************************************************************************/
    677  1.4  christos 
    678  1.4  christos ACPI_STATUS
    679  1.4  christos AcpiRsGetAeiMethodData (
    680  1.4  christos     ACPI_NAMESPACE_NODE     *Node,
    681  1.4  christos     ACPI_BUFFER             *RetBuffer)
    682  1.4  christos {
    683  1.4  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    684  1.4  christos     ACPI_STATUS             Status;
    685  1.4  christos 
    686  1.4  christos 
    687  1.4  christos     ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
    688  1.4  christos 
    689  1.4  christos 
    690  1.4  christos     /* Parameters guaranteed valid by caller */
    691  1.4  christos 
    692  1.4  christos     /* Execute the method, no parameters */
    693  1.4  christos 
    694  1.4  christos     Status = AcpiUtEvaluateObject (Node, METHOD_NAME__AEI,
    695  1.4  christos                 ACPI_BTYPE_BUFFER, &ObjDesc);
    696  1.4  christos     if (ACPI_FAILURE (Status))
    697  1.4  christos     {
    698  1.4  christos         return_ACPI_STATUS (Status);
    699  1.4  christos     }
    700  1.4  christos 
    701  1.4  christos     /*
    702  1.4  christos      * Make the call to create a resource linked list from the
    703  1.4  christos      * byte stream buffer that comes back from the _CRS method
    704  1.4  christos      * execution.
    705  1.4  christos      */
    706  1.4  christos     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    707  1.4  christos 
    708  1.4  christos     /* On exit, we must delete the object returned by evaluateObject */
    709  1.4  christos 
    710  1.4  christos     AcpiUtRemoveReference (ObjDesc);
    711  1.4  christos     return_ACPI_STATUS (Status);
    712  1.4  christos }
    713  1.4  christos 
    714  1.4  christos 
    715  1.4  christos /*******************************************************************************
    716  1.4  christos  *
    717  1.1    jruoho  * FUNCTION:    AcpiRsGetMethodData
    718  1.1    jruoho  *
    719  1.1    jruoho  * PARAMETERS:  Handle          - Handle to the containing object
    720  1.1    jruoho  *              Path            - Path to method, relative to Handle
    721  1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    722  1.1    jruoho  *                                results
    723  1.1    jruoho  *
    724  1.1    jruoho  * RETURN:      Status
    725  1.1    jruoho  *
    726  1.1    jruoho  * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
    727  1.1    jruoho  *              object contained in an object specified by the handle passed in
    728  1.1    jruoho  *
    729  1.1    jruoho  *              If the function fails an appropriate status will be returned
    730  1.1    jruoho  *              and the contents of the callers buffer is undefined.
    731  1.1    jruoho  *
    732  1.1    jruoho  ******************************************************************************/
    733  1.1    jruoho 
    734  1.1    jruoho ACPI_STATUS
    735  1.1    jruoho AcpiRsGetMethodData (
    736  1.1    jruoho     ACPI_HANDLE             Handle,
    737  1.1    jruoho     char                    *Path,
    738  1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    739  1.1    jruoho {
    740  1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    741  1.1    jruoho     ACPI_STATUS             Status;
    742  1.1    jruoho 
    743  1.1    jruoho 
    744  1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetMethodData);
    745  1.1    jruoho 
    746  1.1    jruoho 
    747  1.1    jruoho     /* Parameters guaranteed valid by caller */
    748  1.1    jruoho 
    749  1.1    jruoho     /* Execute the method, no parameters */
    750  1.1    jruoho 
    751  1.4  christos     Status = AcpiUtEvaluateObject (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle),
    752  1.4  christos         Path, ACPI_BTYPE_BUFFER, &ObjDesc);
    753  1.1    jruoho     if (ACPI_FAILURE (Status))
    754  1.1    jruoho     {
    755  1.1    jruoho         return_ACPI_STATUS (Status);
    756  1.1    jruoho     }
    757  1.1    jruoho 
    758  1.1    jruoho     /*
    759  1.1    jruoho      * Make the call to create a resource linked list from the
    760  1.1    jruoho      * byte stream buffer that comes back from the method
    761  1.1    jruoho      * execution.
    762  1.1    jruoho      */
    763  1.1    jruoho     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    764  1.1    jruoho 
    765  1.1    jruoho     /* On exit, we must delete the object returned by EvaluateObject */
    766  1.1    jruoho 
    767  1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    768  1.1    jruoho     return_ACPI_STATUS (Status);
    769  1.1    jruoho }
    770  1.1    jruoho 
    771  1.1    jruoho 
    772  1.1    jruoho /*******************************************************************************
    773  1.1    jruoho  *
    774  1.1    jruoho  * FUNCTION:    AcpiRsSetSrsMethodData
    775  1.1    jruoho  *
    776  1.1    jruoho  * PARAMETERS:  Node            - Device node
    777  1.1    jruoho  *              InBuffer        - Pointer to a buffer structure of the
    778  1.1    jruoho  *                                parameter
    779  1.1    jruoho  *
    780  1.1    jruoho  * RETURN:      Status
    781  1.1    jruoho  *
    782  1.1    jruoho  * DESCRIPTION: This function is called to set the _SRS of an object contained
    783  1.1    jruoho  *              in an object specified by the handle passed in
    784  1.1    jruoho  *
    785  1.1    jruoho  *              If the function fails an appropriate status will be returned
    786  1.1    jruoho  *              and the contents of the callers buffer is undefined.
    787  1.1    jruoho  *
    788  1.1    jruoho  * Note: Parameters guaranteed valid by caller
    789  1.1    jruoho  *
    790  1.1    jruoho  ******************************************************************************/
    791  1.1    jruoho 
    792  1.1    jruoho ACPI_STATUS
    793  1.1    jruoho AcpiRsSetSrsMethodData (
    794  1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    795  1.1    jruoho     ACPI_BUFFER             *InBuffer)
    796  1.1    jruoho {
    797  1.1    jruoho     ACPI_EVALUATE_INFO      *Info;
    798  1.1    jruoho     ACPI_OPERAND_OBJECT     *Args[2];
    799  1.1    jruoho     ACPI_STATUS             Status;
    800  1.1    jruoho     ACPI_BUFFER             Buffer;
    801  1.1    jruoho 
    802  1.1    jruoho 
    803  1.1    jruoho     ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
    804  1.1    jruoho 
    805  1.1    jruoho 
    806  1.1    jruoho     /* Allocate and initialize the evaluation information block */
    807  1.1    jruoho 
    808  1.1    jruoho     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    809  1.1    jruoho     if (!Info)
    810  1.1    jruoho     {
    811  1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    812  1.1    jruoho     }
    813  1.1    jruoho 
    814  1.1    jruoho     Info->PrefixNode = Node;
    815  1.4  christos     Info->RelativePathname = __UNCONST(METHOD_NAME__SRS);
    816  1.1    jruoho     Info->Parameters = Args;
    817  1.1    jruoho     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
    818  1.1    jruoho 
    819  1.1    jruoho     /*
    820  1.1    jruoho      * The InBuffer parameter will point to a linked list of
    821  1.1    jruoho      * resource parameters. It needs to be formatted into a
    822  1.1    jruoho      * byte stream to be sent in as an input parameter to _SRS
    823  1.1    jruoho      *
    824  1.1    jruoho      * Convert the linked list into a byte stream
    825  1.1    jruoho      */
    826  1.1    jruoho     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    827  1.4  christos     Status = AcpiRsCreateAmlResources (InBuffer, &Buffer);
    828  1.1    jruoho     if (ACPI_FAILURE (Status))
    829  1.1    jruoho     {
    830  1.1    jruoho         goto Cleanup;
    831  1.1    jruoho     }
    832  1.1    jruoho 
    833  1.1    jruoho     /* Create and initialize the method parameter object */
    834  1.1    jruoho 
    835  1.1    jruoho     Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
    836  1.1    jruoho     if (!Args[0])
    837  1.1    jruoho     {
    838  1.1    jruoho         /*
    839  1.1    jruoho          * Must free the buffer allocated above (otherwise it is freed
    840  1.1    jruoho          * later)
    841  1.1    jruoho          */
    842  1.1    jruoho         ACPI_FREE (Buffer.Pointer);
    843  1.1    jruoho         Status = AE_NO_MEMORY;
    844  1.1    jruoho         goto Cleanup;
    845  1.1    jruoho     }
    846  1.1    jruoho 
    847  1.1    jruoho     Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
    848  1.1    jruoho     Args[0]->Buffer.Pointer = Buffer.Pointer;
    849  1.1    jruoho     Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
    850  1.1    jruoho     Args[1] = NULL;
    851  1.1    jruoho 
    852  1.1    jruoho     /* Execute the method, no return value is expected */
    853  1.1    jruoho 
    854  1.1    jruoho     Status = AcpiNsEvaluate (Info);
    855  1.1    jruoho 
    856  1.1    jruoho     /* Clean up and return the status from AcpiNsEvaluate */
    857  1.1    jruoho 
    858  1.1    jruoho     AcpiUtRemoveReference (Args[0]);
    859  1.1    jruoho 
    860  1.1    jruoho Cleanup:
    861  1.1    jruoho     ACPI_FREE (Info);
    862  1.1    jruoho     return_ACPI_STATUS (Status);
    863  1.1    jruoho }
    864