Home | History | Annotate | Line # | Download | only in resources
rsutils.c revision 1.10.12.1
      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.10.12.1  pgoyette  * Copyright (C) 2000 - 2018, 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.8  christos             ACPI_MOVE_16_TO_16 (
    189        1.8  christos                 &ACPI_CAST_PTR (UINT16, Destination)[i],
    190        1.8  christos                 &ACPI_CAST_PTR (UINT16, Source)[i]);
    191        1.1    jruoho             break;
    192        1.1    jruoho 
    193        1.1    jruoho         case ACPI_RSC_MOVE32:
    194        1.4  christos 
    195        1.8  christos             ACPI_MOVE_32_TO_32 (
    196        1.8  christos                 &ACPI_CAST_PTR (UINT32, Destination)[i],
    197        1.8  christos                 &ACPI_CAST_PTR (UINT32, Source)[i]);
    198        1.1    jruoho             break;
    199        1.1    jruoho 
    200        1.1    jruoho         case ACPI_RSC_MOVE64:
    201        1.4  christos 
    202        1.8  christos             ACPI_MOVE_64_TO_64 (
    203        1.8  christos                 &ACPI_CAST_PTR (UINT64, Destination)[i],
    204        1.8  christos                 &ACPI_CAST_PTR (UINT64, Source)[i]);
    205        1.1    jruoho             break;
    206        1.1    jruoho 
    207        1.1    jruoho         default:
    208        1.4  christos 
    209        1.1    jruoho             return;
    210        1.1    jruoho         }
    211        1.1    jruoho     }
    212        1.1    jruoho }
    213        1.1    jruoho 
    214        1.1    jruoho 
    215        1.1    jruoho /*******************************************************************************
    216        1.1    jruoho  *
    217        1.1    jruoho  * FUNCTION:    AcpiRsSetResourceLength
    218        1.1    jruoho  *
    219        1.1    jruoho  * PARAMETERS:  TotalLength         - Length of the AML descriptor, including
    220        1.1    jruoho  *                                    the header and length fields.
    221        1.1    jruoho  *              Aml                 - Pointer to the raw AML descriptor
    222        1.1    jruoho  *
    223        1.1    jruoho  * RETURN:      None
    224        1.1    jruoho  *
    225        1.1    jruoho  * DESCRIPTION: Set the ResourceLength field of an AML
    226        1.1    jruoho  *              resource descriptor, both Large and Small descriptors are
    227        1.1    jruoho  *              supported automatically. Note: Descriptor Type field must
    228        1.1    jruoho  *              be valid.
    229        1.1    jruoho  *
    230        1.1    jruoho  ******************************************************************************/
    231        1.1    jruoho 
    232        1.1    jruoho void
    233        1.1    jruoho AcpiRsSetResourceLength (
    234        1.1    jruoho     ACPI_RSDESC_SIZE        TotalLength,
    235        1.1    jruoho     AML_RESOURCE            *Aml)
    236        1.1    jruoho {
    237        1.1    jruoho     ACPI_RS_LENGTH          ResourceLength;
    238        1.1    jruoho 
    239        1.1    jruoho 
    240        1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    241        1.1    jruoho 
    242        1.1    jruoho 
    243        1.1    jruoho     /* Length is the total descriptor length minus the header length */
    244        1.1    jruoho 
    245        1.1    jruoho     ResourceLength = (ACPI_RS_LENGTH)
    246        1.1    jruoho         (TotalLength - AcpiUtGetResourceHeaderLength (Aml));
    247        1.1    jruoho 
    248        1.1    jruoho     /* Length is stored differently for large and small descriptors */
    249        1.1    jruoho 
    250        1.1    jruoho     if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
    251        1.1    jruoho     {
    252        1.1    jruoho         /* Large descriptor -- bytes 1-2 contain the 16-bit length */
    253        1.1    jruoho 
    254        1.8  christos         ACPI_MOVE_16_TO_16 (
    255        1.8  christos             &Aml->LargeHeader.ResourceLength, &ResourceLength);
    256        1.1    jruoho     }
    257        1.1    jruoho     else
    258        1.1    jruoho     {
    259        1.8  christos         /*
    260        1.8  christos          * Small descriptor -- bits 2:0 of byte 0 contain the length
    261        1.8  christos          * Clear any existing length, preserving descriptor type bits
    262        1.8  christos          */
    263        1.1    jruoho         Aml->SmallHeader.DescriptorType = (UINT8)
    264        1.8  christos             ((Aml->SmallHeader.DescriptorType &
    265        1.8  christos                 ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)
    266        1.1    jruoho             | ResourceLength);
    267        1.1    jruoho     }
    268        1.1    jruoho }
    269        1.1    jruoho 
    270        1.1    jruoho 
    271        1.1    jruoho /*******************************************************************************
    272        1.1    jruoho  *
    273        1.1    jruoho  * FUNCTION:    AcpiRsSetResourceHeader
    274        1.1    jruoho  *
    275        1.1    jruoho  * PARAMETERS:  DescriptorType      - Byte to be inserted as the type
    276        1.1    jruoho  *              TotalLength         - Length of the AML descriptor, including
    277        1.1    jruoho  *                                    the header and length fields.
    278        1.1    jruoho  *              Aml                 - Pointer to the raw AML descriptor
    279        1.1    jruoho  *
    280        1.1    jruoho  * RETURN:      None
    281        1.1    jruoho  *
    282        1.1    jruoho  * DESCRIPTION: Set the DescriptorType and ResourceLength fields of an AML
    283        1.1    jruoho  *              resource descriptor, both Large and Small descriptors are
    284        1.1    jruoho  *              supported automatically
    285        1.1    jruoho  *
    286        1.1    jruoho  ******************************************************************************/
    287        1.1    jruoho 
    288        1.1    jruoho void
    289        1.1    jruoho AcpiRsSetResourceHeader (
    290        1.1    jruoho     UINT8                   DescriptorType,
    291        1.1    jruoho     ACPI_RSDESC_SIZE        TotalLength,
    292        1.1    jruoho     AML_RESOURCE            *Aml)
    293        1.1    jruoho {
    294        1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    295        1.1    jruoho 
    296        1.1    jruoho 
    297        1.1    jruoho     /* Set the Resource Type */
    298        1.1    jruoho 
    299        1.1    jruoho     Aml->SmallHeader.DescriptorType = DescriptorType;
    300        1.1    jruoho 
    301        1.1    jruoho     /* Set the Resource Length */
    302        1.1    jruoho 
    303        1.1    jruoho     AcpiRsSetResourceLength (TotalLength, Aml);
    304        1.1    jruoho }
    305        1.1    jruoho 
    306        1.1    jruoho 
    307        1.1    jruoho /*******************************************************************************
    308        1.1    jruoho  *
    309        1.1    jruoho  * FUNCTION:    AcpiRsStrcpy
    310        1.1    jruoho  *
    311        1.1    jruoho  * PARAMETERS:  Destination         - Pointer to the destination string
    312        1.1    jruoho  *              Source              - Pointer to the source string
    313        1.1    jruoho  *
    314        1.1    jruoho  * RETURN:      String length, including NULL terminator
    315        1.1    jruoho  *
    316        1.1    jruoho  * DESCRIPTION: Local string copy that returns the string length, saving a
    317        1.1    jruoho  *              strcpy followed by a strlen.
    318        1.1    jruoho  *
    319        1.1    jruoho  ******************************************************************************/
    320        1.1    jruoho 
    321        1.1    jruoho static UINT16
    322        1.1    jruoho AcpiRsStrcpy (
    323        1.1    jruoho     char                    *Destination,
    324        1.1    jruoho     char                    *Source)
    325        1.1    jruoho {
    326        1.1    jruoho     UINT16                  i;
    327        1.1    jruoho 
    328        1.1    jruoho 
    329        1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    330        1.1    jruoho 
    331        1.1    jruoho 
    332        1.1    jruoho     for (i = 0; Source[i]; i++)
    333        1.1    jruoho     {
    334        1.1    jruoho         Destination[i] = Source[i];
    335        1.1    jruoho     }
    336        1.1    jruoho 
    337        1.1    jruoho     Destination[i] = 0;
    338        1.1    jruoho 
    339        1.1    jruoho     /* Return string length including the NULL terminator */
    340        1.1    jruoho 
    341        1.1    jruoho     return ((UINT16) (i + 1));
    342        1.1    jruoho }
    343        1.1    jruoho 
    344        1.1    jruoho 
    345        1.1    jruoho /*******************************************************************************
    346        1.1    jruoho  *
    347        1.1    jruoho  * FUNCTION:    AcpiRsGetResourceSource
    348        1.1    jruoho  *
    349        1.1    jruoho  * PARAMETERS:  ResourceLength      - Length field of the descriptor
    350        1.1    jruoho  *              MinimumLength       - Minimum length of the descriptor (minus
    351        1.1    jruoho  *                                    any optional fields)
    352        1.1    jruoho  *              ResourceSource      - Where the ResourceSource is returned
    353        1.1    jruoho  *              Aml                 - Pointer to the raw AML descriptor
    354        1.1    jruoho  *              StringPtr           - (optional) where to store the actual
    355        1.1    jruoho  *                                    ResourceSource string
    356        1.1    jruoho  *
    357        1.1    jruoho  * RETURN:      Length of the string plus NULL terminator, rounded up to native
    358        1.1    jruoho  *              word boundary
    359        1.1    jruoho  *
    360        1.1    jruoho  * DESCRIPTION: Copy the optional ResourceSource data from a raw AML descriptor
    361        1.1    jruoho  *              to an internal resource descriptor
    362        1.1    jruoho  *
    363        1.1    jruoho  ******************************************************************************/
    364        1.1    jruoho 
    365        1.1    jruoho ACPI_RS_LENGTH
    366        1.1    jruoho AcpiRsGetResourceSource (
    367        1.1    jruoho     ACPI_RS_LENGTH          ResourceLength,
    368        1.1    jruoho     ACPI_RS_LENGTH          MinimumLength,
    369        1.1    jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource,
    370        1.1    jruoho     AML_RESOURCE            *Aml,
    371        1.1    jruoho     char                    *StringPtr)
    372        1.1    jruoho {
    373        1.1    jruoho     ACPI_RSDESC_SIZE        TotalLength;
    374        1.1    jruoho     UINT8                   *AmlResourceSource;
    375        1.1    jruoho 
    376        1.1    jruoho 
    377        1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    378        1.1    jruoho 
    379        1.1    jruoho 
    380        1.1    jruoho     TotalLength = ResourceLength + sizeof (AML_RESOURCE_LARGE_HEADER);
    381        1.1    jruoho     AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
    382        1.1    jruoho 
    383        1.1    jruoho     /*
    384        1.8  christos      * ResourceSource is present if the length of the descriptor is longer
    385        1.8  christos      * than the minimum length.
    386        1.1    jruoho      *
    387        1.1    jruoho      * Note: Some resource descriptors will have an additional null, so
    388        1.1    jruoho      * we add 1 to the minimum length.
    389        1.1    jruoho      */
    390        1.1    jruoho     if (TotalLength > (ACPI_RSDESC_SIZE) (MinimumLength + 1))
    391        1.1    jruoho     {
    392        1.1    jruoho         /* Get the ResourceSourceIndex */
    393        1.1    jruoho 
    394        1.1    jruoho         ResourceSource->Index = AmlResourceSource[0];
    395        1.1    jruoho 
    396        1.1    jruoho         ResourceSource->StringPtr = StringPtr;
    397        1.1    jruoho         if (!StringPtr)
    398        1.1    jruoho         {
    399        1.1    jruoho             /*
    400        1.1    jruoho              * String destination pointer is not specified; Set the String
    401        1.1    jruoho              * pointer to the end of the current ResourceSource structure.
    402        1.1    jruoho              */
    403        1.8  christos             ResourceSource->StringPtr = ACPI_ADD_PTR (
    404        1.8  christos                 char, ResourceSource, sizeof (ACPI_RESOURCE_SOURCE));
    405        1.1    jruoho         }
    406        1.1    jruoho 
    407        1.1    jruoho         /*
    408        1.1    jruoho          * In order for the Resource length to be a multiple of the native
    409        1.1    jruoho          * word, calculate the length of the string (+1 for NULL terminator)
    410        1.1    jruoho          * and expand to the next word multiple.
    411        1.1    jruoho          *
    412        1.1    jruoho          * Zero the entire area of the buffer.
    413        1.1    jruoho          */
    414        1.7  christos         TotalLength = (UINT32) strlen (
    415        1.1    jruoho             ACPI_CAST_PTR (char, &AmlResourceSource[1])) + 1;
    416        1.8  christos 
    417        1.1    jruoho         TotalLength = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (TotalLength);
    418        1.1    jruoho 
    419        1.7  christos         memset (ResourceSource->StringPtr, 0, TotalLength);
    420        1.1    jruoho 
    421        1.1    jruoho         /* Copy the ResourceSource string to the destination */
    422        1.1    jruoho 
    423        1.8  christos         ResourceSource->StringLength = AcpiRsStrcpy (
    424        1.8  christos             ResourceSource->StringPtr,
    425        1.1    jruoho             ACPI_CAST_PTR (char, &AmlResourceSource[1]));
    426        1.1    jruoho 
    427        1.1    jruoho         return ((ACPI_RS_LENGTH) TotalLength);
    428        1.1    jruoho     }
    429        1.1    jruoho 
    430        1.1    jruoho     /* ResourceSource is not present */
    431        1.1    jruoho 
    432        1.1    jruoho     ResourceSource->Index = 0;
    433        1.1    jruoho     ResourceSource->StringLength = 0;
    434        1.1    jruoho     ResourceSource->StringPtr = NULL;
    435        1.1    jruoho     return (0);
    436        1.1    jruoho }
    437        1.1    jruoho 
    438        1.1    jruoho 
    439        1.1    jruoho /*******************************************************************************
    440        1.1    jruoho  *
    441        1.1    jruoho  * FUNCTION:    AcpiRsSetResourceSource
    442        1.1    jruoho  *
    443        1.1    jruoho  * PARAMETERS:  Aml                 - Pointer to the raw AML descriptor
    444        1.1    jruoho  *              MinimumLength       - Minimum length of the descriptor (minus
    445        1.1    jruoho  *                                    any optional fields)
    446        1.1    jruoho  *              ResourceSource      - Internal ResourceSource
    447        1.1    jruoho 
    448        1.1    jruoho  *
    449        1.1    jruoho  * RETURN:      Total length of the AML descriptor
    450        1.1    jruoho  *
    451        1.1    jruoho  * DESCRIPTION: Convert an optional ResourceSource from internal format to a
    452        1.1    jruoho  *              raw AML resource descriptor
    453        1.1    jruoho  *
    454        1.1    jruoho  ******************************************************************************/
    455        1.1    jruoho 
    456        1.1    jruoho ACPI_RSDESC_SIZE
    457        1.1    jruoho AcpiRsSetResourceSource (
    458        1.1    jruoho     AML_RESOURCE            *Aml,
    459        1.1    jruoho     ACPI_RS_LENGTH          MinimumLength,
    460        1.1    jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource)
    461        1.1    jruoho {
    462        1.1    jruoho     UINT8                   *AmlResourceSource;
    463        1.1    jruoho     ACPI_RSDESC_SIZE        DescriptorLength;
    464        1.1    jruoho 
    465        1.1    jruoho 
    466        1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    467        1.1    jruoho 
    468        1.1    jruoho 
    469        1.1    jruoho     DescriptorLength = MinimumLength;
    470        1.1    jruoho 
    471        1.1    jruoho     /* Non-zero string length indicates presence of a ResourceSource */
    472        1.1    jruoho 
    473        1.1    jruoho     if (ResourceSource->StringLength)
    474        1.1    jruoho     {
    475        1.1    jruoho         /* Point to the end of the AML descriptor */
    476        1.1    jruoho 
    477        1.1    jruoho         AmlResourceSource = ACPI_ADD_PTR (UINT8, Aml, MinimumLength);
    478        1.1    jruoho 
    479        1.1    jruoho         /* Copy the ResourceSourceIndex */
    480        1.1    jruoho 
    481        1.1    jruoho         AmlResourceSource[0] = (UINT8) ResourceSource->Index;
    482        1.1    jruoho 
    483        1.1    jruoho         /* Copy the ResourceSource string */
    484        1.1    jruoho 
    485        1.7  christos         strcpy (ACPI_CAST_PTR (char, &AmlResourceSource[1]),
    486        1.1    jruoho             ResourceSource->StringPtr);
    487        1.1    jruoho 
    488        1.1    jruoho         /*
    489        1.1    jruoho          * Add the length of the string (+ 1 for null terminator) to the
    490        1.1    jruoho          * final descriptor length
    491        1.1    jruoho          */
    492        1.8  christos         DescriptorLength += ((ACPI_RSDESC_SIZE)
    493        1.8  christos             ResourceSource->StringLength + 1);
    494        1.1    jruoho     }
    495        1.1    jruoho 
    496        1.1    jruoho     /* Return the new total length of the AML descriptor */
    497        1.1    jruoho 
    498        1.1    jruoho     return (DescriptorLength);
    499        1.1    jruoho }
    500        1.1    jruoho 
    501        1.1    jruoho 
    502        1.1    jruoho /*******************************************************************************
    503        1.1    jruoho  *
    504        1.1    jruoho  * FUNCTION:    AcpiRsGetPrtMethodData
    505        1.1    jruoho  *
    506        1.1    jruoho  * PARAMETERS:  Node            - Device node
    507        1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    508        1.1    jruoho  *                                results
    509        1.1    jruoho  *
    510        1.1    jruoho  * RETURN:      Status
    511        1.1    jruoho  *
    512        1.1    jruoho  * DESCRIPTION: This function is called to get the _PRT value of an object
    513        1.1    jruoho  *              contained in an object specified by the handle passed in
    514        1.1    jruoho  *
    515        1.1    jruoho  *              If the function fails an appropriate status will be returned
    516        1.1    jruoho  *              and the contents of the callers buffer is undefined.
    517        1.1    jruoho  *
    518        1.1    jruoho  ******************************************************************************/
    519        1.1    jruoho 
    520        1.1    jruoho ACPI_STATUS
    521        1.1    jruoho AcpiRsGetPrtMethodData (
    522        1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    523        1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    524        1.1    jruoho {
    525        1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    526        1.1    jruoho     ACPI_STATUS             Status;
    527        1.1    jruoho 
    528        1.1    jruoho 
    529        1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetPrtMethodData);
    530        1.1    jruoho 
    531        1.1    jruoho 
    532        1.1    jruoho     /* Parameters guaranteed valid by caller */
    533        1.1    jruoho 
    534        1.1    jruoho     /* Execute the method, no parameters */
    535        1.1    jruoho 
    536        1.8  christos     Status = AcpiUtEvaluateObject (
    537        1.8  christos         Node, METHOD_NAME__PRT, ACPI_BTYPE_PACKAGE, &ObjDesc);
    538        1.1    jruoho     if (ACPI_FAILURE (Status))
    539        1.1    jruoho     {
    540        1.1    jruoho         return_ACPI_STATUS (Status);
    541        1.1    jruoho     }
    542        1.1    jruoho 
    543        1.1    jruoho     /*
    544        1.1    jruoho      * Create a resource linked list from the byte stream buffer that comes
    545        1.1    jruoho      * back from the _CRS method execution.
    546        1.1    jruoho      */
    547        1.1    jruoho     Status = AcpiRsCreatePciRoutingTable (ObjDesc, RetBuffer);
    548        1.1    jruoho 
    549        1.1    jruoho     /* On exit, we must delete the object returned by EvaluateObject */
    550        1.1    jruoho 
    551        1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    552        1.1    jruoho     return_ACPI_STATUS (Status);
    553        1.1    jruoho }
    554        1.1    jruoho 
    555        1.1    jruoho 
    556        1.1    jruoho /*******************************************************************************
    557        1.1    jruoho  *
    558        1.1    jruoho  * FUNCTION:    AcpiRsGetCrsMethodData
    559        1.1    jruoho  *
    560        1.1    jruoho  * PARAMETERS:  Node            - Device node
    561        1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    562        1.1    jruoho  *                                results
    563        1.1    jruoho  *
    564        1.1    jruoho  * RETURN:      Status
    565        1.1    jruoho  *
    566        1.1    jruoho  * DESCRIPTION: This function is called to get the _CRS value of an object
    567        1.1    jruoho  *              contained in an object specified by the handle passed in
    568        1.1    jruoho  *
    569        1.1    jruoho  *              If the function fails an appropriate status will be returned
    570        1.1    jruoho  *              and the contents of the callers buffer is undefined.
    571        1.1    jruoho  *
    572        1.1    jruoho  ******************************************************************************/
    573        1.1    jruoho 
    574        1.1    jruoho ACPI_STATUS
    575        1.1    jruoho AcpiRsGetCrsMethodData (
    576        1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    577        1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    578        1.1    jruoho {
    579        1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    580        1.1    jruoho     ACPI_STATUS             Status;
    581        1.1    jruoho 
    582        1.1    jruoho 
    583        1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetCrsMethodData);
    584        1.1    jruoho 
    585        1.1    jruoho 
    586        1.1    jruoho     /* Parameters guaranteed valid by caller */
    587        1.1    jruoho 
    588        1.1    jruoho     /* Execute the method, no parameters */
    589        1.1    jruoho 
    590        1.8  christos     Status = AcpiUtEvaluateObject (
    591        1.8  christos         Node, METHOD_NAME__CRS, ACPI_BTYPE_BUFFER, &ObjDesc);
    592        1.1    jruoho     if (ACPI_FAILURE (Status))
    593        1.1    jruoho     {
    594        1.1    jruoho         return_ACPI_STATUS (Status);
    595        1.1    jruoho     }
    596        1.1    jruoho 
    597        1.1    jruoho     /*
    598        1.1    jruoho      * Make the call to create a resource linked list from the
    599        1.1    jruoho      * byte stream buffer that comes back from the _CRS method
    600        1.1    jruoho      * execution.
    601        1.1    jruoho      */
    602        1.1    jruoho     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    603        1.1    jruoho 
    604        1.1    jruoho     /* On exit, we must delete the object returned by evaluateObject */
    605        1.1    jruoho 
    606        1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    607        1.1    jruoho     return_ACPI_STATUS (Status);
    608        1.1    jruoho }
    609        1.1    jruoho 
    610        1.1    jruoho 
    611        1.1    jruoho /*******************************************************************************
    612        1.1    jruoho  *
    613        1.1    jruoho  * FUNCTION:    AcpiRsGetPrsMethodData
    614        1.1    jruoho  *
    615        1.1    jruoho  * PARAMETERS:  Node            - Device node
    616        1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    617        1.1    jruoho  *                                results
    618        1.1    jruoho  *
    619        1.1    jruoho  * RETURN:      Status
    620        1.1    jruoho  *
    621        1.1    jruoho  * DESCRIPTION: This function is called to get the _PRS value of an object
    622        1.1    jruoho  *              contained in an object specified by the handle passed in
    623        1.1    jruoho  *
    624        1.1    jruoho  *              If the function fails an appropriate status will be returned
    625        1.1    jruoho  *              and the contents of the callers buffer is undefined.
    626        1.1    jruoho  *
    627        1.1    jruoho  ******************************************************************************/
    628        1.1    jruoho 
    629        1.1    jruoho ACPI_STATUS
    630        1.1    jruoho AcpiRsGetPrsMethodData (
    631        1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    632        1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    633        1.1    jruoho {
    634        1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    635        1.1    jruoho     ACPI_STATUS             Status;
    636        1.1    jruoho 
    637        1.1    jruoho 
    638        1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetPrsMethodData);
    639        1.1    jruoho 
    640        1.1    jruoho 
    641        1.1    jruoho     /* Parameters guaranteed valid by caller */
    642        1.1    jruoho 
    643        1.1    jruoho     /* Execute the method, no parameters */
    644        1.1    jruoho 
    645        1.8  christos     Status = AcpiUtEvaluateObject (
    646        1.8  christos         Node, METHOD_NAME__PRS, ACPI_BTYPE_BUFFER, &ObjDesc);
    647        1.1    jruoho     if (ACPI_FAILURE (Status))
    648        1.1    jruoho     {
    649        1.1    jruoho         return_ACPI_STATUS (Status);
    650        1.1    jruoho     }
    651        1.1    jruoho 
    652        1.1    jruoho     /*
    653        1.1    jruoho      * Make the call to create a resource linked list from the
    654        1.1    jruoho      * byte stream buffer that comes back from the _CRS method
    655        1.1    jruoho      * execution.
    656        1.1    jruoho      */
    657        1.1    jruoho     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    658        1.1    jruoho 
    659        1.1    jruoho     /* On exit, we must delete the object returned by evaluateObject */
    660        1.1    jruoho 
    661        1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    662        1.1    jruoho     return_ACPI_STATUS (Status);
    663        1.1    jruoho }
    664        1.1    jruoho 
    665        1.1    jruoho 
    666        1.1    jruoho /*******************************************************************************
    667        1.1    jruoho  *
    668        1.4  christos  * FUNCTION:    AcpiRsGetAeiMethodData
    669        1.4  christos  *
    670        1.4  christos  * PARAMETERS:  Node            - Device node
    671        1.4  christos  *              RetBuffer       - Pointer to a buffer structure for the
    672        1.4  christos  *                                results
    673        1.4  christos  *
    674        1.4  christos  * RETURN:      Status
    675        1.4  christos  *
    676        1.4  christos  * DESCRIPTION: This function is called to get the _AEI value of an object
    677        1.4  christos  *              contained in an object specified by the handle passed in
    678        1.4  christos  *
    679        1.4  christos  *              If the function fails an appropriate status will be returned
    680        1.4  christos  *              and the contents of the callers buffer is undefined.
    681        1.4  christos  *
    682        1.4  christos  ******************************************************************************/
    683        1.4  christos 
    684        1.4  christos ACPI_STATUS
    685        1.4  christos AcpiRsGetAeiMethodData (
    686        1.4  christos     ACPI_NAMESPACE_NODE     *Node,
    687        1.4  christos     ACPI_BUFFER             *RetBuffer)
    688        1.4  christos {
    689        1.4  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    690        1.4  christos     ACPI_STATUS             Status;
    691        1.4  christos 
    692        1.4  christos 
    693        1.4  christos     ACPI_FUNCTION_TRACE (RsGetAeiMethodData);
    694        1.4  christos 
    695        1.4  christos 
    696        1.4  christos     /* Parameters guaranteed valid by caller */
    697        1.4  christos 
    698        1.4  christos     /* Execute the method, no parameters */
    699        1.4  christos 
    700        1.8  christos     Status = AcpiUtEvaluateObject (
    701        1.8  christos         Node, METHOD_NAME__AEI, ACPI_BTYPE_BUFFER, &ObjDesc);
    702        1.4  christos     if (ACPI_FAILURE (Status))
    703        1.4  christos     {
    704        1.4  christos         return_ACPI_STATUS (Status);
    705        1.4  christos     }
    706        1.4  christos 
    707        1.4  christos     /*
    708        1.4  christos      * Make the call to create a resource linked list from the
    709        1.4  christos      * byte stream buffer that comes back from the _CRS method
    710        1.4  christos      * execution.
    711        1.4  christos      */
    712        1.4  christos     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    713        1.4  christos 
    714        1.4  christos     /* On exit, we must delete the object returned by evaluateObject */
    715        1.4  christos 
    716        1.4  christos     AcpiUtRemoveReference (ObjDesc);
    717        1.4  christos     return_ACPI_STATUS (Status);
    718        1.4  christos }
    719        1.4  christos 
    720        1.4  christos 
    721        1.4  christos /*******************************************************************************
    722        1.4  christos  *
    723        1.1    jruoho  * FUNCTION:    AcpiRsGetMethodData
    724        1.1    jruoho  *
    725        1.1    jruoho  * PARAMETERS:  Handle          - Handle to the containing object
    726        1.1    jruoho  *              Path            - Path to method, relative to Handle
    727        1.1    jruoho  *              RetBuffer       - Pointer to a buffer structure for the
    728        1.1    jruoho  *                                results
    729        1.1    jruoho  *
    730        1.1    jruoho  * RETURN:      Status
    731        1.1    jruoho  *
    732        1.1    jruoho  * DESCRIPTION: This function is called to get the _CRS or _PRS value of an
    733        1.1    jruoho  *              object contained in an object specified by the handle passed in
    734        1.1    jruoho  *
    735        1.1    jruoho  *              If the function fails an appropriate status will be returned
    736        1.1    jruoho  *              and the contents of the callers buffer is undefined.
    737        1.1    jruoho  *
    738        1.1    jruoho  ******************************************************************************/
    739        1.1    jruoho 
    740        1.1    jruoho ACPI_STATUS
    741        1.1    jruoho AcpiRsGetMethodData (
    742        1.1    jruoho     ACPI_HANDLE             Handle,
    743        1.9  christos     const char              *Path,
    744        1.1    jruoho     ACPI_BUFFER             *RetBuffer)
    745        1.1    jruoho {
    746        1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    747        1.1    jruoho     ACPI_STATUS             Status;
    748        1.1    jruoho 
    749        1.1    jruoho 
    750        1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetMethodData);
    751        1.1    jruoho 
    752        1.1    jruoho 
    753        1.1    jruoho     /* Parameters guaranteed valid by caller */
    754        1.1    jruoho 
    755        1.1    jruoho     /* Execute the method, no parameters */
    756        1.1    jruoho 
    757        1.8  christos     Status = AcpiUtEvaluateObject (
    758        1.8  christos         ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle),
    759        1.4  christos         Path, ACPI_BTYPE_BUFFER, &ObjDesc);
    760        1.1    jruoho     if (ACPI_FAILURE (Status))
    761        1.1    jruoho     {
    762        1.1    jruoho         return_ACPI_STATUS (Status);
    763        1.1    jruoho     }
    764        1.1    jruoho 
    765        1.1    jruoho     /*
    766        1.1    jruoho      * Make the call to create a resource linked list from the
    767        1.1    jruoho      * byte stream buffer that comes back from the method
    768        1.1    jruoho      * execution.
    769        1.1    jruoho      */
    770        1.1    jruoho     Status = AcpiRsCreateResourceList (ObjDesc, RetBuffer);
    771        1.1    jruoho 
    772        1.1    jruoho     /* On exit, we must delete the object returned by EvaluateObject */
    773        1.1    jruoho 
    774        1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    775        1.1    jruoho     return_ACPI_STATUS (Status);
    776        1.1    jruoho }
    777        1.1    jruoho 
    778        1.1    jruoho 
    779        1.1    jruoho /*******************************************************************************
    780        1.1    jruoho  *
    781        1.1    jruoho  * FUNCTION:    AcpiRsSetSrsMethodData
    782        1.1    jruoho  *
    783        1.1    jruoho  * PARAMETERS:  Node            - Device node
    784        1.1    jruoho  *              InBuffer        - Pointer to a buffer structure of the
    785        1.1    jruoho  *                                parameter
    786        1.1    jruoho  *
    787        1.1    jruoho  * RETURN:      Status
    788        1.1    jruoho  *
    789        1.1    jruoho  * DESCRIPTION: This function is called to set the _SRS of an object contained
    790        1.1    jruoho  *              in an object specified by the handle passed in
    791        1.1    jruoho  *
    792        1.1    jruoho  *              If the function fails an appropriate status will be returned
    793        1.1    jruoho  *              and the contents of the callers buffer is undefined.
    794        1.1    jruoho  *
    795        1.1    jruoho  * Note: Parameters guaranteed valid by caller
    796        1.1    jruoho  *
    797        1.1    jruoho  ******************************************************************************/
    798        1.1    jruoho 
    799        1.1    jruoho ACPI_STATUS
    800        1.1    jruoho AcpiRsSetSrsMethodData (
    801        1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    802        1.1    jruoho     ACPI_BUFFER             *InBuffer)
    803        1.1    jruoho {
    804        1.1    jruoho     ACPI_EVALUATE_INFO      *Info;
    805        1.1    jruoho     ACPI_OPERAND_OBJECT     *Args[2];
    806        1.1    jruoho     ACPI_STATUS             Status;
    807        1.1    jruoho     ACPI_BUFFER             Buffer;
    808        1.1    jruoho 
    809        1.1    jruoho 
    810        1.1    jruoho     ACPI_FUNCTION_TRACE (RsSetSrsMethodData);
    811        1.1    jruoho 
    812        1.1    jruoho 
    813        1.1    jruoho     /* Allocate and initialize the evaluation information block */
    814        1.1    jruoho 
    815        1.1    jruoho     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    816        1.1    jruoho     if (!Info)
    817        1.1    jruoho     {
    818        1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    819        1.1    jruoho     }
    820        1.1    jruoho 
    821        1.1    jruoho     Info->PrefixNode = Node;
    822        1.4  christos     Info->RelativePathname = __UNCONST(METHOD_NAME__SRS);
    823        1.1    jruoho     Info->Parameters = Args;
    824        1.1    jruoho     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
    825        1.1    jruoho 
    826        1.1    jruoho     /*
    827        1.1    jruoho      * The InBuffer parameter will point to a linked list of
    828        1.1    jruoho      * resource parameters. It needs to be formatted into a
    829        1.1    jruoho      * byte stream to be sent in as an input parameter to _SRS
    830        1.1    jruoho      *
    831        1.1    jruoho      * Convert the linked list into a byte stream
    832        1.1    jruoho      */
    833        1.1    jruoho     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    834        1.4  christos     Status = AcpiRsCreateAmlResources (InBuffer, &Buffer);
    835        1.1    jruoho     if (ACPI_FAILURE (Status))
    836        1.1    jruoho     {
    837        1.1    jruoho         goto Cleanup;
    838        1.1    jruoho     }
    839        1.1    jruoho 
    840        1.1    jruoho     /* Create and initialize the method parameter object */
    841        1.1    jruoho 
    842        1.1    jruoho     Args[0] = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
    843        1.1    jruoho     if (!Args[0])
    844        1.1    jruoho     {
    845        1.1    jruoho         /*
    846        1.1    jruoho          * Must free the buffer allocated above (otherwise it is freed
    847        1.1    jruoho          * later)
    848        1.1    jruoho          */
    849        1.1    jruoho         ACPI_FREE (Buffer.Pointer);
    850        1.1    jruoho         Status = AE_NO_MEMORY;
    851        1.1    jruoho         goto Cleanup;
    852        1.1    jruoho     }
    853        1.1    jruoho 
    854        1.1    jruoho     Args[0]->Buffer.Length  = (UINT32) Buffer.Length;
    855        1.1    jruoho     Args[0]->Buffer.Pointer = Buffer.Pointer;
    856        1.1    jruoho     Args[0]->Common.Flags   = AOPOBJ_DATA_VALID;
    857        1.1    jruoho     Args[1] = NULL;
    858        1.1    jruoho 
    859        1.1    jruoho     /* Execute the method, no return value is expected */
    860        1.1    jruoho 
    861        1.1    jruoho     Status = AcpiNsEvaluate (Info);
    862        1.1    jruoho 
    863        1.1    jruoho     /* Clean up and return the status from AcpiNsEvaluate */
    864        1.1    jruoho 
    865        1.1    jruoho     AcpiUtRemoveReference (Args[0]);
    866        1.1    jruoho 
    867        1.1    jruoho Cleanup:
    868        1.1    jruoho     ACPI_FREE (Info);
    869        1.1    jruoho     return_ACPI_STATUS (Status);
    870        1.1    jruoho }
    871