Home | History | Annotate | Line # | Download | only in resources
rscalc.c revision 1.1.1.2
      1      1.1  jruoho /*******************************************************************************
      2      1.1  jruoho  *
      3      1.1  jruoho  * Module Name: rscalc - Calculate stream and list lengths
      4      1.1  jruoho  *
      5      1.1  jruoho  ******************************************************************************/
      6      1.1  jruoho 
      7  1.1.1.2  jruoho /*
      8  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
      9      1.1  jruoho  * All rights reserved.
     10      1.1  jruoho  *
     11  1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2  jruoho  * are met:
     14  1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2  jruoho  *    without modification.
     17  1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2  jruoho  *    binary redistribution.
     22  1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2  jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2  jruoho  *
     26  1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2  jruoho  * Software Foundation.
     29  1.1.1.2  jruoho  *
     30  1.1.1.2  jruoho  * NO WARRANTY
     31  1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2  jruoho  */
     43      1.1  jruoho 
     44      1.1  jruoho #define __RSCALC_C__
     45      1.1  jruoho 
     46      1.1  jruoho #include "acpi.h"
     47      1.1  jruoho #include "accommon.h"
     48      1.1  jruoho #include "acresrc.h"
     49      1.1  jruoho #include "acnamesp.h"
     50      1.1  jruoho 
     51      1.1  jruoho 
     52      1.1  jruoho #define _COMPONENT          ACPI_RESOURCES
     53      1.1  jruoho         ACPI_MODULE_NAME    ("rscalc")
     54      1.1  jruoho 
     55      1.1  jruoho 
     56      1.1  jruoho /* Local prototypes */
     57      1.1  jruoho 
     58      1.1  jruoho static UINT8
     59      1.1  jruoho AcpiRsCountSetBits (
     60      1.1  jruoho     UINT16                  BitField);
     61      1.1  jruoho 
     62      1.1  jruoho static ACPI_RS_LENGTH
     63      1.1  jruoho AcpiRsStructOptionLength (
     64      1.1  jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource);
     65      1.1  jruoho 
     66      1.1  jruoho static UINT32
     67      1.1  jruoho AcpiRsStreamOptionLength (
     68      1.1  jruoho     UINT32                  ResourceLength,
     69      1.1  jruoho     UINT32                  MinimumTotalLength);
     70      1.1  jruoho 
     71      1.1  jruoho 
     72      1.1  jruoho /*******************************************************************************
     73      1.1  jruoho  *
     74      1.1  jruoho  * FUNCTION:    AcpiRsCountSetBits
     75      1.1  jruoho  *
     76      1.1  jruoho  * PARAMETERS:  BitField        - Field in which to count bits
     77      1.1  jruoho  *
     78      1.1  jruoho  * RETURN:      Number of bits set within the field
     79      1.1  jruoho  *
     80      1.1  jruoho  * DESCRIPTION: Count the number of bits set in a resource field. Used for
     81      1.1  jruoho  *              (Short descriptor) interrupt and DMA lists.
     82      1.1  jruoho  *
     83      1.1  jruoho  ******************************************************************************/
     84      1.1  jruoho 
     85      1.1  jruoho static UINT8
     86      1.1  jruoho AcpiRsCountSetBits (
     87      1.1  jruoho     UINT16                  BitField)
     88      1.1  jruoho {
     89      1.1  jruoho     UINT8                   BitsSet;
     90      1.1  jruoho 
     91      1.1  jruoho 
     92      1.1  jruoho     ACPI_FUNCTION_ENTRY ();
     93      1.1  jruoho 
     94      1.1  jruoho 
     95      1.1  jruoho     for (BitsSet = 0; BitField; BitsSet++)
     96      1.1  jruoho     {
     97      1.1  jruoho         /* Zero the least significant bit that is set */
     98      1.1  jruoho 
     99      1.1  jruoho         BitField &= (UINT16) (BitField - 1);
    100      1.1  jruoho     }
    101      1.1  jruoho 
    102      1.1  jruoho     return (BitsSet);
    103      1.1  jruoho }
    104      1.1  jruoho 
    105      1.1  jruoho 
    106      1.1  jruoho /*******************************************************************************
    107      1.1  jruoho  *
    108      1.1  jruoho  * FUNCTION:    AcpiRsStructOptionLength
    109      1.1  jruoho  *
    110      1.1  jruoho  * PARAMETERS:  ResourceSource      - Pointer to optional descriptor field
    111      1.1  jruoho  *
    112      1.1  jruoho  * RETURN:      Status
    113      1.1  jruoho  *
    114      1.1  jruoho  * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
    115      1.1  jruoho  *              ResourceSource fields in some Large descriptors. Used during
    116      1.1  jruoho  *              list-to-stream conversion
    117      1.1  jruoho  *
    118      1.1  jruoho  ******************************************************************************/
    119      1.1  jruoho 
    120      1.1  jruoho static ACPI_RS_LENGTH
    121      1.1  jruoho AcpiRsStructOptionLength (
    122      1.1  jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource)
    123      1.1  jruoho {
    124      1.1  jruoho     ACPI_FUNCTION_ENTRY ();
    125      1.1  jruoho 
    126      1.1  jruoho 
    127      1.1  jruoho     /*
    128      1.1  jruoho      * If the ResourceSource string is valid, return the size of the string
    129      1.1  jruoho      * (StringLength includes the NULL terminator) plus the size of the
    130      1.1  jruoho      * ResourceSourceIndex (1).
    131      1.1  jruoho      */
    132      1.1  jruoho     if (ResourceSource->StringPtr)
    133      1.1  jruoho     {
    134      1.1  jruoho         return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1));
    135      1.1  jruoho     }
    136      1.1  jruoho 
    137      1.1  jruoho     return (0);
    138      1.1  jruoho }
    139      1.1  jruoho 
    140      1.1  jruoho 
    141      1.1  jruoho /*******************************************************************************
    142      1.1  jruoho  *
    143      1.1  jruoho  * FUNCTION:    AcpiRsStreamOptionLength
    144      1.1  jruoho  *
    145      1.1  jruoho  * PARAMETERS:  ResourceLength      - Length from the resource header
    146      1.1  jruoho  *              MinimumTotalLength  - Minimum length of this resource, before
    147      1.1  jruoho  *                                    any optional fields. Includes header size
    148      1.1  jruoho  *
    149      1.1  jruoho  * RETURN:      Length of optional string (0 if no string present)
    150      1.1  jruoho  *
    151      1.1  jruoho  * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
    152      1.1  jruoho  *              ResourceSource fields in some Large descriptors. Used during
    153      1.1  jruoho  *              stream-to-list conversion
    154      1.1  jruoho  *
    155      1.1  jruoho  ******************************************************************************/
    156      1.1  jruoho 
    157      1.1  jruoho static UINT32
    158      1.1  jruoho AcpiRsStreamOptionLength (
    159      1.1  jruoho     UINT32                  ResourceLength,
    160      1.1  jruoho     UINT32                  MinimumAmlResourceLength)
    161      1.1  jruoho {
    162      1.1  jruoho     UINT32                  StringLength = 0;
    163      1.1  jruoho 
    164      1.1  jruoho 
    165      1.1  jruoho     ACPI_FUNCTION_ENTRY ();
    166      1.1  jruoho 
    167      1.1  jruoho 
    168      1.1  jruoho     /*
    169      1.1  jruoho      * The ResourceSourceIndex and ResourceSource are optional elements of some
    170      1.1  jruoho      * Large-type resource descriptors.
    171      1.1  jruoho      */
    172      1.1  jruoho 
    173      1.1  jruoho     /*
    174      1.1  jruoho      * If the length of the actual resource descriptor is greater than the ACPI
    175      1.1  jruoho      * spec-defined minimum length, it means that a ResourceSourceIndex exists
    176      1.1  jruoho      * and is followed by a (required) null terminated string. The string length
    177      1.1  jruoho      * (including the null terminator) is the resource length minus the minimum
    178      1.1  jruoho      * length, minus one byte for the ResourceSourceIndex itself.
    179      1.1  jruoho      */
    180      1.1  jruoho     if (ResourceLength > MinimumAmlResourceLength)
    181      1.1  jruoho     {
    182      1.1  jruoho         /* Compute the length of the optional string */
    183      1.1  jruoho 
    184      1.1  jruoho         StringLength = ResourceLength - MinimumAmlResourceLength - 1;
    185      1.1  jruoho     }
    186      1.1  jruoho 
    187      1.1  jruoho     /*
    188      1.1  jruoho      * Round the length up to a multiple of the native word in order to
    189      1.1  jruoho      * guarantee that the entire resource descriptor is native word aligned
    190      1.1  jruoho      */
    191      1.1  jruoho     return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
    192      1.1  jruoho }
    193      1.1  jruoho 
    194      1.1  jruoho 
    195      1.1  jruoho /*******************************************************************************
    196      1.1  jruoho  *
    197      1.1  jruoho  * FUNCTION:    AcpiRsGetAmlLength
    198      1.1  jruoho  *
    199      1.1  jruoho  * PARAMETERS:  Resource            - Pointer to the resource linked list
    200      1.1  jruoho  *              SizeNeeded          - Where the required size is returned
    201      1.1  jruoho  *
    202      1.1  jruoho  * RETURN:      Status
    203      1.1  jruoho  *
    204      1.1  jruoho  * DESCRIPTION: Takes a linked list of internal resource descriptors and
    205      1.1  jruoho  *              calculates the size buffer needed to hold the corresponding
    206      1.1  jruoho  *              external resource byte stream.
    207      1.1  jruoho  *
    208      1.1  jruoho  ******************************************************************************/
    209      1.1  jruoho 
    210      1.1  jruoho ACPI_STATUS
    211      1.1  jruoho AcpiRsGetAmlLength (
    212      1.1  jruoho     ACPI_RESOURCE           *Resource,
    213      1.1  jruoho     ACPI_SIZE               *SizeNeeded)
    214      1.1  jruoho {
    215      1.1  jruoho     ACPI_SIZE               AmlSizeNeeded = 0;
    216      1.1  jruoho     ACPI_RS_LENGTH          TotalSize;
    217      1.1  jruoho 
    218      1.1  jruoho 
    219      1.1  jruoho     ACPI_FUNCTION_TRACE (RsGetAmlLength);
    220      1.1  jruoho 
    221      1.1  jruoho 
    222      1.1  jruoho     /* Traverse entire list of internal resource descriptors */
    223      1.1  jruoho 
    224      1.1  jruoho     while (Resource)
    225      1.1  jruoho     {
    226      1.1  jruoho         /* Validate the descriptor type */
    227      1.1  jruoho 
    228      1.1  jruoho         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
    229      1.1  jruoho         {
    230      1.1  jruoho             return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
    231      1.1  jruoho         }
    232      1.1  jruoho 
    233      1.1  jruoho         /* Get the base size of the (external stream) resource descriptor */
    234      1.1  jruoho 
    235      1.1  jruoho         TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
    236      1.1  jruoho 
    237      1.1  jruoho         /*
    238      1.1  jruoho          * Augment the base size for descriptors with optional and/or
    239      1.1  jruoho          * variable-length fields
    240      1.1  jruoho          */
    241      1.1  jruoho         switch (Resource->Type)
    242      1.1  jruoho         {
    243      1.1  jruoho         case ACPI_RESOURCE_TYPE_IRQ:
    244      1.1  jruoho 
    245      1.1  jruoho             /* Length can be 3 or 2 */
    246      1.1  jruoho 
    247      1.1  jruoho             if (Resource->Data.Irq.DescriptorLength == 2)
    248      1.1  jruoho             {
    249      1.1  jruoho                 TotalSize--;
    250      1.1  jruoho             }
    251      1.1  jruoho             break;
    252      1.1  jruoho 
    253      1.1  jruoho 
    254      1.1  jruoho         case ACPI_RESOURCE_TYPE_START_DEPENDENT:
    255      1.1  jruoho 
    256      1.1  jruoho             /* Length can be 1 or 0 */
    257      1.1  jruoho 
    258      1.1  jruoho             if (Resource->Data.Irq.DescriptorLength == 0)
    259      1.1  jruoho             {
    260      1.1  jruoho                 TotalSize--;
    261      1.1  jruoho             }
    262      1.1  jruoho             break;
    263      1.1  jruoho 
    264      1.1  jruoho 
    265      1.1  jruoho         case ACPI_RESOURCE_TYPE_VENDOR:
    266      1.1  jruoho             /*
    267      1.1  jruoho              * Vendor Defined Resource:
    268      1.1  jruoho              * For a Vendor Specific resource, if the Length is between 1 and 7
    269      1.1  jruoho              * it will be created as a Small Resource data type, otherwise it
    270      1.1  jruoho              * is a Large Resource data type.
    271      1.1  jruoho              */
    272      1.1  jruoho             if (Resource->Data.Vendor.ByteLength > 7)
    273      1.1  jruoho             {
    274      1.1  jruoho                 /* Base size of a Large resource descriptor */
    275      1.1  jruoho 
    276      1.1  jruoho                 TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
    277      1.1  jruoho             }
    278      1.1  jruoho 
    279      1.1  jruoho             /* Add the size of the vendor-specific data */
    280      1.1  jruoho 
    281      1.1  jruoho             TotalSize = (ACPI_RS_LENGTH)
    282      1.1  jruoho                 (TotalSize + Resource->Data.Vendor.ByteLength);
    283      1.1  jruoho             break;
    284      1.1  jruoho 
    285      1.1  jruoho 
    286      1.1  jruoho         case ACPI_RESOURCE_TYPE_END_TAG:
    287      1.1  jruoho             /*
    288      1.1  jruoho              * End Tag:
    289      1.1  jruoho              * We are done -- return the accumulated total size.
    290      1.1  jruoho              */
    291      1.1  jruoho             *SizeNeeded = AmlSizeNeeded + TotalSize;
    292      1.1  jruoho 
    293      1.1  jruoho             /* Normal exit */
    294      1.1  jruoho 
    295      1.1  jruoho             return_ACPI_STATUS (AE_OK);
    296      1.1  jruoho 
    297      1.1  jruoho 
    298      1.1  jruoho         case ACPI_RESOURCE_TYPE_ADDRESS16:
    299      1.1  jruoho             /*
    300      1.1  jruoho              * 16-Bit Address Resource:
    301      1.1  jruoho              * Add the size of the optional ResourceSource info
    302      1.1  jruoho              */
    303      1.1  jruoho             TotalSize = (ACPI_RS_LENGTH)
    304      1.1  jruoho                 (TotalSize + AcpiRsStructOptionLength (
    305      1.1  jruoho                                 &Resource->Data.Address16.ResourceSource));
    306      1.1  jruoho             break;
    307      1.1  jruoho 
    308      1.1  jruoho 
    309      1.1  jruoho         case ACPI_RESOURCE_TYPE_ADDRESS32:
    310      1.1  jruoho             /*
    311      1.1  jruoho              * 32-Bit Address Resource:
    312      1.1  jruoho              * Add the size of the optional ResourceSource info
    313      1.1  jruoho              */
    314      1.1  jruoho             TotalSize = (ACPI_RS_LENGTH)
    315      1.1  jruoho                 (TotalSize + AcpiRsStructOptionLength (
    316      1.1  jruoho                                 &Resource->Data.Address32.ResourceSource));
    317      1.1  jruoho             break;
    318      1.1  jruoho 
    319      1.1  jruoho 
    320      1.1  jruoho         case ACPI_RESOURCE_TYPE_ADDRESS64:
    321      1.1  jruoho             /*
    322      1.1  jruoho              * 64-Bit Address Resource:
    323      1.1  jruoho              * Add the size of the optional ResourceSource info
    324      1.1  jruoho              */
    325      1.1  jruoho             TotalSize = (ACPI_RS_LENGTH)
    326      1.1  jruoho                 (TotalSize + AcpiRsStructOptionLength (
    327      1.1  jruoho                                 &Resource->Data.Address64.ResourceSource));
    328      1.1  jruoho             break;
    329      1.1  jruoho 
    330      1.1  jruoho 
    331      1.1  jruoho         case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
    332      1.1  jruoho             /*
    333      1.1  jruoho              * Extended IRQ Resource:
    334      1.1  jruoho              * Add the size of each additional optional interrupt beyond the
    335      1.1  jruoho              * required 1 (4 bytes for each UINT32 interrupt number)
    336      1.1  jruoho              */
    337      1.1  jruoho             TotalSize = (ACPI_RS_LENGTH)
    338      1.1  jruoho                 (TotalSize +
    339      1.1  jruoho                 ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
    340      1.1  jruoho 
    341      1.1  jruoho                 /* Add the size of the optional ResourceSource info */
    342      1.1  jruoho 
    343      1.1  jruoho                 AcpiRsStructOptionLength (
    344      1.1  jruoho                     &Resource->Data.ExtendedIrq.ResourceSource));
    345      1.1  jruoho             break;
    346      1.1  jruoho 
    347      1.1  jruoho 
    348      1.1  jruoho         default:
    349      1.1  jruoho             break;
    350      1.1  jruoho         }
    351      1.1  jruoho 
    352      1.1  jruoho         /* Update the total */
    353      1.1  jruoho 
    354      1.1  jruoho         AmlSizeNeeded += TotalSize;
    355      1.1  jruoho 
    356      1.1  jruoho         /* Point to the next object */
    357      1.1  jruoho 
    358      1.1  jruoho         Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
    359      1.1  jruoho     }
    360      1.1  jruoho 
    361      1.1  jruoho     /* Did not find an EndTag resource descriptor */
    362      1.1  jruoho 
    363      1.1  jruoho     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
    364      1.1  jruoho }
    365      1.1  jruoho 
    366      1.1  jruoho 
    367      1.1  jruoho /*******************************************************************************
    368      1.1  jruoho  *
    369      1.1  jruoho  * FUNCTION:    AcpiRsGetListLength
    370      1.1  jruoho  *
    371      1.1  jruoho  * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
    372      1.1  jruoho  *              AmlBufferLength     - Size of AmlBuffer
    373      1.1  jruoho  *              SizeNeeded          - Where the size needed is returned
    374      1.1  jruoho  *
    375      1.1  jruoho  * RETURN:      Status
    376      1.1  jruoho  *
    377      1.1  jruoho  * DESCRIPTION: Takes an external resource byte stream and calculates the size
    378      1.1  jruoho  *              buffer needed to hold the corresponding internal resource
    379      1.1  jruoho  *              descriptor linked list.
    380      1.1  jruoho  *
    381      1.1  jruoho  ******************************************************************************/
    382      1.1  jruoho 
    383      1.1  jruoho ACPI_STATUS
    384      1.1  jruoho AcpiRsGetListLength (
    385      1.1  jruoho     UINT8                   *AmlBuffer,
    386      1.1  jruoho     UINT32                  AmlBufferLength,
    387      1.1  jruoho     ACPI_SIZE               *SizeNeeded)
    388      1.1  jruoho {
    389      1.1  jruoho     ACPI_STATUS             Status;
    390      1.1  jruoho     UINT8                   *EndAml;
    391      1.1  jruoho     UINT8                   *Buffer;
    392      1.1  jruoho     UINT32                  BufferSize;
    393      1.1  jruoho     UINT16                  Temp16;
    394      1.1  jruoho     UINT16                  ResourceLength;
    395      1.1  jruoho     UINT32                  ExtraStructBytes;
    396      1.1  jruoho     UINT8                   ResourceIndex;
    397      1.1  jruoho     UINT8                   MinimumAmlResourceLength;
    398      1.1  jruoho 
    399      1.1  jruoho 
    400      1.1  jruoho     ACPI_FUNCTION_TRACE (RsGetListLength);
    401      1.1  jruoho 
    402      1.1  jruoho 
    403      1.1  jruoho     *SizeNeeded = 0;
    404      1.1  jruoho     EndAml = AmlBuffer + AmlBufferLength;
    405      1.1  jruoho 
    406      1.1  jruoho     /* Walk the list of AML resource descriptors */
    407      1.1  jruoho 
    408      1.1  jruoho     while (AmlBuffer < EndAml)
    409      1.1  jruoho     {
    410      1.1  jruoho         /* Validate the Resource Type and Resource Length */
    411      1.1  jruoho 
    412      1.1  jruoho         Status = AcpiUtValidateResource (AmlBuffer, &ResourceIndex);
    413      1.1  jruoho         if (ACPI_FAILURE (Status))
    414      1.1  jruoho         {
    415      1.1  jruoho             return_ACPI_STATUS (Status);
    416      1.1  jruoho         }
    417      1.1  jruoho 
    418      1.1  jruoho         /* Get the resource length and base (minimum) AML size */
    419      1.1  jruoho 
    420      1.1  jruoho         ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
    421      1.1  jruoho         MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
    422      1.1  jruoho 
    423      1.1  jruoho         /*
    424      1.1  jruoho          * Augment the size for descriptors with optional
    425      1.1  jruoho          * and/or variable length fields
    426      1.1  jruoho          */
    427      1.1  jruoho         ExtraStructBytes = 0;
    428      1.1  jruoho         Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
    429      1.1  jruoho 
    430      1.1  jruoho         switch (AcpiUtGetResourceType (AmlBuffer))
    431      1.1  jruoho         {
    432      1.1  jruoho         case ACPI_RESOURCE_NAME_IRQ:
    433      1.1  jruoho             /*
    434      1.1  jruoho              * IRQ Resource:
    435      1.1  jruoho              * Get the number of bits set in the 16-bit IRQ mask
    436      1.1  jruoho              */
    437      1.1  jruoho             ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
    438      1.1  jruoho             ExtraStructBytes = AcpiRsCountSetBits (Temp16);
    439      1.1  jruoho             break;
    440      1.1  jruoho 
    441      1.1  jruoho 
    442      1.1  jruoho         case ACPI_RESOURCE_NAME_DMA:
    443      1.1  jruoho             /*
    444      1.1  jruoho              * DMA Resource:
    445      1.1  jruoho              * Get the number of bits set in the 8-bit DMA mask
    446      1.1  jruoho              */
    447      1.1  jruoho             ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
    448      1.1  jruoho             break;
    449      1.1  jruoho 
    450      1.1  jruoho 
    451      1.1  jruoho         case ACPI_RESOURCE_NAME_VENDOR_SMALL:
    452      1.1  jruoho         case ACPI_RESOURCE_NAME_VENDOR_LARGE:
    453      1.1  jruoho             /*
    454      1.1  jruoho              * Vendor Resource:
    455      1.1  jruoho              * Get the number of vendor data bytes
    456      1.1  jruoho              */
    457      1.1  jruoho             ExtraStructBytes = ResourceLength;
    458      1.1  jruoho             break;
    459      1.1  jruoho 
    460      1.1  jruoho 
    461      1.1  jruoho         case ACPI_RESOURCE_NAME_END_TAG:
    462      1.1  jruoho             /*
    463      1.1  jruoho              * End Tag:
    464      1.1  jruoho              * This is the normal exit, add size of EndTag
    465      1.1  jruoho              */
    466      1.1  jruoho             *SizeNeeded += ACPI_RS_SIZE_MIN;
    467      1.1  jruoho             return_ACPI_STATUS (AE_OK);
    468      1.1  jruoho 
    469      1.1  jruoho 
    470      1.1  jruoho         case ACPI_RESOURCE_NAME_ADDRESS32:
    471      1.1  jruoho         case ACPI_RESOURCE_NAME_ADDRESS16:
    472      1.1  jruoho         case ACPI_RESOURCE_NAME_ADDRESS64:
    473      1.1  jruoho             /*
    474      1.1  jruoho              * Address Resource:
    475      1.1  jruoho              * Add the size of the optional ResourceSource
    476      1.1  jruoho              */
    477      1.1  jruoho             ExtraStructBytes = AcpiRsStreamOptionLength (
    478      1.1  jruoho                 ResourceLength, MinimumAmlResourceLength);
    479      1.1  jruoho             break;
    480      1.1  jruoho 
    481      1.1  jruoho 
    482      1.1  jruoho         case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
    483      1.1  jruoho             /*
    484      1.1  jruoho              * Extended IRQ Resource:
    485      1.1  jruoho              * Using the InterruptTableLength, add 4 bytes for each additional
    486      1.1  jruoho              * interrupt. Note: at least one interrupt is required and is
    487      1.1  jruoho              * included in the minimum descriptor size (reason for the -1)
    488      1.1  jruoho              */
    489      1.1  jruoho             ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
    490      1.1  jruoho 
    491      1.1  jruoho             /* Add the size of the optional ResourceSource */
    492      1.1  jruoho 
    493      1.1  jruoho             ExtraStructBytes += AcpiRsStreamOptionLength (
    494      1.1  jruoho                 ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
    495      1.1  jruoho             break;
    496      1.1  jruoho 
    497      1.1  jruoho 
    498      1.1  jruoho         default:
    499      1.1  jruoho             break;
    500      1.1  jruoho         }
    501      1.1  jruoho 
    502      1.1  jruoho         /*
    503      1.1  jruoho          * Update the required buffer size for the internal descriptor structs
    504      1.1  jruoho          *
    505      1.1  jruoho          * Important: Round the size up for the appropriate alignment. This
    506      1.1  jruoho          * is a requirement on IA64.
    507      1.1  jruoho          */
    508      1.1  jruoho         BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
    509      1.1  jruoho                         ExtraStructBytes;
    510      1.1  jruoho         BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
    511      1.1  jruoho 
    512      1.1  jruoho         *SizeNeeded += BufferSize;
    513      1.1  jruoho 
    514      1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
    515      1.1  jruoho             "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
    516      1.1  jruoho             AcpiUtGetResourceType (AmlBuffer),
    517      1.1  jruoho             AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
    518      1.1  jruoho 
    519      1.1  jruoho         /*
    520      1.1  jruoho          * Point to the next resource within the AML stream using the length
    521      1.1  jruoho          * contained in the resource descriptor header
    522      1.1  jruoho          */
    523      1.1  jruoho         AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
    524      1.1  jruoho     }
    525      1.1  jruoho 
    526      1.1  jruoho     /* Did not find an EndTag resource descriptor */
    527      1.1  jruoho 
    528      1.1  jruoho     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
    529      1.1  jruoho }
    530      1.1  jruoho 
    531      1.1  jruoho 
    532      1.1  jruoho /*******************************************************************************
    533      1.1  jruoho  *
    534      1.1  jruoho  * FUNCTION:    AcpiRsGetPciRoutingTableLength
    535      1.1  jruoho  *
    536      1.1  jruoho  * PARAMETERS:  PackageObject           - Pointer to the package object
    537      1.1  jruoho  *              BufferSizeNeeded        - UINT32 pointer of the size buffer
    538      1.1  jruoho  *                                        needed to properly return the
    539      1.1  jruoho  *                                        parsed data
    540      1.1  jruoho  *
    541      1.1  jruoho  * RETURN:      Status
    542      1.1  jruoho  *
    543      1.1  jruoho  * DESCRIPTION: Given a package representing a PCI routing table, this
    544      1.1  jruoho  *              calculates the size of the corresponding linked list of
    545      1.1  jruoho  *              descriptions.
    546      1.1  jruoho  *
    547      1.1  jruoho  ******************************************************************************/
    548      1.1  jruoho 
    549      1.1  jruoho ACPI_STATUS
    550      1.1  jruoho AcpiRsGetPciRoutingTableLength (
    551      1.1  jruoho     ACPI_OPERAND_OBJECT     *PackageObject,
    552      1.1  jruoho     ACPI_SIZE               *BufferSizeNeeded)
    553      1.1  jruoho {
    554      1.1  jruoho     UINT32                  NumberOfElements;
    555      1.1  jruoho     ACPI_SIZE               TempSizeNeeded = 0;
    556      1.1  jruoho     ACPI_OPERAND_OBJECT     **TopObjectList;
    557      1.1  jruoho     UINT32                  Index;
    558      1.1  jruoho     ACPI_OPERAND_OBJECT     *PackageElement;
    559      1.1  jruoho     ACPI_OPERAND_OBJECT     **SubObjectList;
    560      1.1  jruoho     BOOLEAN                 NameFound;
    561      1.1  jruoho     UINT32                  TableIndex;
    562      1.1  jruoho 
    563      1.1  jruoho 
    564      1.1  jruoho     ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
    565      1.1  jruoho 
    566      1.1  jruoho 
    567      1.1  jruoho     NumberOfElements = PackageObject->Package.Count;
    568      1.1  jruoho 
    569      1.1  jruoho     /*
    570      1.1  jruoho      * Calculate the size of the return buffer.
    571      1.1  jruoho      * The base size is the number of elements * the sizes of the
    572      1.1  jruoho      * structures.  Additional space for the strings is added below.
    573      1.1  jruoho      * The minus one is to subtract the size of the UINT8 Source[1]
    574      1.1  jruoho      * member because it is added below.
    575      1.1  jruoho      *
    576      1.1  jruoho      * But each PRT_ENTRY structure has a pointer to a string and
    577      1.1  jruoho      * the size of that string must be found.
    578      1.1  jruoho      */
    579      1.1  jruoho     TopObjectList = PackageObject->Package.Elements;
    580      1.1  jruoho 
    581      1.1  jruoho     for (Index = 0; Index < NumberOfElements; Index++)
    582      1.1  jruoho     {
    583      1.1  jruoho         /* Dereference the sub-package */
    584      1.1  jruoho 
    585      1.1  jruoho         PackageElement = *TopObjectList;
    586      1.1  jruoho 
    587      1.1  jruoho         /* We must have a valid Package object */
    588      1.1  jruoho 
    589      1.1  jruoho         if (!PackageElement ||
    590      1.1  jruoho             (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
    591      1.1  jruoho         {
    592      1.1  jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    593      1.1  jruoho         }
    594      1.1  jruoho 
    595      1.1  jruoho         /*
    596      1.1  jruoho          * The SubObjectList will now point to an array of the
    597      1.1  jruoho          * four IRQ elements: Address, Pin, Source and SourceIndex
    598      1.1  jruoho          */
    599      1.1  jruoho         SubObjectList = PackageElement->Package.Elements;
    600      1.1  jruoho 
    601      1.1  jruoho         /* Scan the IrqTableElements for the Source Name String */
    602      1.1  jruoho 
    603      1.1  jruoho         NameFound = FALSE;
    604      1.1  jruoho 
    605      1.1  jruoho         for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++)
    606      1.1  jruoho         {
    607      1.1  jruoho             if (*SubObjectList && /* Null object allowed */
    608      1.1  jruoho 
    609      1.1  jruoho                 ((ACPI_TYPE_STRING ==
    610      1.1  jruoho                     (*SubObjectList)->Common.Type) ||
    611      1.1  jruoho 
    612      1.1  jruoho                 ((ACPI_TYPE_LOCAL_REFERENCE ==
    613      1.1  jruoho                     (*SubObjectList)->Common.Type) &&
    614      1.1  jruoho 
    615      1.1  jruoho                     ((*SubObjectList)->Reference.Class ==
    616      1.1  jruoho                         ACPI_REFCLASS_NAME))))
    617      1.1  jruoho             {
    618      1.1  jruoho                 NameFound = TRUE;
    619      1.1  jruoho             }
    620      1.1  jruoho             else
    621      1.1  jruoho             {
    622      1.1  jruoho                 /* Look at the next element */
    623      1.1  jruoho 
    624      1.1  jruoho                 SubObjectList++;
    625      1.1  jruoho             }
    626      1.1  jruoho         }
    627      1.1  jruoho 
    628      1.1  jruoho         TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
    629      1.1  jruoho 
    630      1.1  jruoho         /* Was a String type found? */
    631      1.1  jruoho 
    632      1.1  jruoho         if (NameFound)
    633      1.1  jruoho         {
    634      1.1  jruoho             if ((*SubObjectList)->Common.Type == ACPI_TYPE_STRING)
    635      1.1  jruoho             {
    636      1.1  jruoho                 /*
    637      1.1  jruoho                  * The length String.Length field does not include the
    638      1.1  jruoho                  * terminating NULL, add 1
    639      1.1  jruoho                  */
    640      1.1  jruoho                 TempSizeNeeded += ((ACPI_SIZE)
    641      1.1  jruoho                     (*SubObjectList)->String.Length + 1);
    642      1.1  jruoho             }
    643      1.1  jruoho             else
    644      1.1  jruoho             {
    645      1.1  jruoho                 TempSizeNeeded += AcpiNsGetPathnameLength (
    646      1.1  jruoho                                     (*SubObjectList)->Reference.Node);
    647      1.1  jruoho             }
    648      1.1  jruoho         }
    649      1.1  jruoho         else
    650      1.1  jruoho         {
    651      1.1  jruoho             /*
    652      1.1  jruoho              * If no name was found, then this is a NULL, which is
    653      1.1  jruoho              * translated as a UINT32 zero.
    654      1.1  jruoho              */
    655      1.1  jruoho             TempSizeNeeded += sizeof (UINT32);
    656      1.1  jruoho         }
    657      1.1  jruoho 
    658      1.1  jruoho         /* Round up the size since each element must be aligned */
    659      1.1  jruoho 
    660      1.1  jruoho         TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded);
    661      1.1  jruoho 
    662      1.1  jruoho         /* Point to the next ACPI_OPERAND_OBJECT */
    663      1.1  jruoho 
    664      1.1  jruoho         TopObjectList++;
    665      1.1  jruoho     }
    666      1.1  jruoho 
    667      1.1  jruoho     /*
    668      1.1  jruoho      * Add an extra element to the end of the list, essentially a
    669      1.1  jruoho      * NULL terminator
    670      1.1  jruoho      */
    671      1.1  jruoho     *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
    672      1.1  jruoho     return_ACPI_STATUS (AE_OK);
    673      1.1  jruoho }
    674