Home | History | Annotate | Line # | Download | only in resources
      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.15  christos /******************************************************************************
      8  1.1.1.15  christos  *
      9  1.1.1.15  christos  * 1. Copyright Notice
     10  1.1.1.15  christos  *
     11  1.1.1.16  christos  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.1.1.15  christos  * 2. License
     15  1.1.1.15  christos  *
     16  1.1.1.15  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.15  christos  * rights. You may have additional license terms from the party that provided
     18  1.1.1.15  christos  * you this software, covering your right to use that party's intellectual
     19  1.1.1.15  christos  * property rights.
     20  1.1.1.15  christos  *
     21  1.1.1.15  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.15  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.15  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.15  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.15  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.15  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.15  christos  *
     28  1.1.1.15  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.15  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.15  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.15  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.15  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.15  christos  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.15  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.15  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.15  christos  *
     37  1.1.1.15  christos  * The above copyright and patent license is granted only if the following
     38  1.1.1.15  christos  * conditions are met:
     39  1.1.1.15  christos  *
     40  1.1.1.15  christos  * 3. Conditions
     41  1.1.1.15  christos  *
     42  1.1.1.15  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.15  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.15  christos  * Code or modification with rights to further distribute source must include
     45  1.1.1.15  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.15  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.15  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.15  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.15  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.15  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.15  christos  * must include a prominent statement that the modification is derived,
     52  1.1.1.15  christos  * directly or indirectly, from Original Intel Code.
     53  1.1.1.15  christos  *
     54  1.1.1.15  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.15  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.15  christos  * Code or modification without rights to further distribute source must
     57  1.1.1.15  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.15  christos  * documentation and/or other materials provided with distribution. In
     59  1.1.1.15  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.15  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.15  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.15  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.15  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.15  christos  * make.
     65  1.1.1.15  christos  *
     66  1.1.1.15  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.15  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.15  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.15  christos  * provision in the documentation and/or other materials provided with the
     70  1.1.1.15  christos  * distribution.
     71  1.1.1.15  christos  *
     72  1.1.1.15  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.15  christos  * Intel Code.
     74  1.1.1.15  christos  *
     75  1.1.1.15  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.15  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.15  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.15  christos  * without prior written authorization from Intel.
     79  1.1.1.15  christos  *
     80  1.1.1.15  christos  * 4. Disclaimer and Export Compliance
     81  1.1.1.15  christos  *
     82  1.1.1.15  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.15  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.15  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.15  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.15  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.15  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.15  christos  * PARTICULAR PURPOSE.
     89  1.1.1.15  christos  *
     90  1.1.1.15  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.15  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.15  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.15  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.15  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.15  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.15  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.15  christos  * LIMITED REMEDY.
     98  1.1.1.15  christos  *
     99  1.1.1.15  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.15  christos  * software or system incorporating such software without first obtaining any
    101  1.1.1.15  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.15  christos  * any other agency or department of the United States Government. In the
    103  1.1.1.15  christos  * event Licensee exports any such software from the United States or
    104  1.1.1.15  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.15  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.15  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.15  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.15  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.15  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.15  christos  * United States government or any agency thereof requires an export license,
    111  1.1.1.15  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.15  christos  * such license, approval or letter.
    113  1.1.1.15  christos  *
    114  1.1.1.15  christos  *****************************************************************************
    115  1.1.1.15  christos  *
    116  1.1.1.15  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.15  christos  * following license:
    118  1.1.1.15  christos  *
    119   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
    120   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
    121   1.1.1.2    jruoho  * are met:
    122   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
    123   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124   1.1.1.2    jruoho  *    without modification.
    125   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
    129   1.1.1.2    jruoho  *    binary redistribution.
    130   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
    132   1.1.1.2    jruoho  *    from this software without specific prior written permission.
    133   1.1.1.2    jruoho  *
    134   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.1.1.12  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.15  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.15  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.15  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.15  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.15  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.15  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.15  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.15  christos  *
    146  1.1.1.15  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.15  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.15  christos  * Software Foundation.
    149  1.1.1.15  christos  *
    150  1.1.1.15  christos  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "acpi.h"
    153       1.1    jruoho #include "accommon.h"
    154       1.1    jruoho #include "acresrc.h"
    155       1.1    jruoho #include "acnamesp.h"
    156       1.1    jruoho 
    157       1.1    jruoho 
    158       1.1    jruoho #define _COMPONENT          ACPI_RESOURCES
    159       1.1    jruoho         ACPI_MODULE_NAME    ("rscalc")
    160       1.1    jruoho 
    161       1.1    jruoho 
    162       1.1    jruoho /* Local prototypes */
    163       1.1    jruoho 
    164       1.1    jruoho static UINT8
    165       1.1    jruoho AcpiRsCountSetBits (
    166       1.1    jruoho     UINT16                  BitField);
    167       1.1    jruoho 
    168       1.1    jruoho static ACPI_RS_LENGTH
    169       1.1    jruoho AcpiRsStructOptionLength (
    170       1.1    jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource);
    171       1.1    jruoho 
    172       1.1    jruoho static UINT32
    173       1.1    jruoho AcpiRsStreamOptionLength (
    174       1.1    jruoho     UINT32                  ResourceLength,
    175       1.1    jruoho     UINT32                  MinimumTotalLength);
    176       1.1    jruoho 
    177       1.1    jruoho 
    178       1.1    jruoho /*******************************************************************************
    179       1.1    jruoho  *
    180       1.1    jruoho  * FUNCTION:    AcpiRsCountSetBits
    181       1.1    jruoho  *
    182       1.1    jruoho  * PARAMETERS:  BitField        - Field in which to count bits
    183       1.1    jruoho  *
    184       1.1    jruoho  * RETURN:      Number of bits set within the field
    185       1.1    jruoho  *
    186       1.1    jruoho  * DESCRIPTION: Count the number of bits set in a resource field. Used for
    187       1.1    jruoho  *              (Short descriptor) interrupt and DMA lists.
    188       1.1    jruoho  *
    189       1.1    jruoho  ******************************************************************************/
    190       1.1    jruoho 
    191       1.1    jruoho static UINT8
    192       1.1    jruoho AcpiRsCountSetBits (
    193       1.1    jruoho     UINT16                  BitField)
    194       1.1    jruoho {
    195       1.1    jruoho     UINT8                   BitsSet;
    196       1.1    jruoho 
    197       1.1    jruoho 
    198       1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    199       1.1    jruoho 
    200       1.1    jruoho 
    201       1.1    jruoho     for (BitsSet = 0; BitField; BitsSet++)
    202       1.1    jruoho     {
    203       1.1    jruoho         /* Zero the least significant bit that is set */
    204       1.1    jruoho 
    205       1.1    jruoho         BitField &= (UINT16) (BitField - 1);
    206       1.1    jruoho     }
    207       1.1    jruoho 
    208       1.1    jruoho     return (BitsSet);
    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:    AcpiRsStructOptionLength
    215       1.1    jruoho  *
    216       1.1    jruoho  * PARAMETERS:  ResourceSource      - Pointer to optional descriptor field
    217       1.1    jruoho  *
    218       1.1    jruoho  * RETURN:      Status
    219       1.1    jruoho  *
    220       1.1    jruoho  * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
    221       1.1    jruoho  *              ResourceSource fields in some Large descriptors. Used during
    222       1.1    jruoho  *              list-to-stream conversion
    223       1.1    jruoho  *
    224       1.1    jruoho  ******************************************************************************/
    225       1.1    jruoho 
    226       1.1    jruoho static ACPI_RS_LENGTH
    227       1.1    jruoho AcpiRsStructOptionLength (
    228       1.1    jruoho     ACPI_RESOURCE_SOURCE    *ResourceSource)
    229       1.1    jruoho {
    230       1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    231       1.1    jruoho 
    232       1.1    jruoho 
    233       1.1    jruoho     /*
    234       1.1    jruoho      * If the ResourceSource string is valid, return the size of the string
    235       1.1    jruoho      * (StringLength includes the NULL terminator) plus the size of the
    236       1.1    jruoho      * ResourceSourceIndex (1).
    237       1.1    jruoho      */
    238       1.1    jruoho     if (ResourceSource->StringPtr)
    239       1.1    jruoho     {
    240       1.1    jruoho         return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1));
    241       1.1    jruoho     }
    242       1.1    jruoho 
    243       1.1    jruoho     return (0);
    244       1.1    jruoho }
    245       1.1    jruoho 
    246       1.1    jruoho 
    247       1.1    jruoho /*******************************************************************************
    248       1.1    jruoho  *
    249       1.1    jruoho  * FUNCTION:    AcpiRsStreamOptionLength
    250       1.1    jruoho  *
    251       1.1    jruoho  * PARAMETERS:  ResourceLength      - Length from the resource header
    252       1.1    jruoho  *              MinimumTotalLength  - Minimum length of this resource, before
    253       1.1    jruoho  *                                    any optional fields. Includes header size
    254       1.1    jruoho  *
    255       1.1    jruoho  * RETURN:      Length of optional string (0 if no string present)
    256       1.1    jruoho  *
    257       1.1    jruoho  * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
    258       1.1    jruoho  *              ResourceSource fields in some Large descriptors. Used during
    259       1.1    jruoho  *              stream-to-list conversion
    260       1.1    jruoho  *
    261       1.1    jruoho  ******************************************************************************/
    262       1.1    jruoho 
    263       1.1    jruoho static UINT32
    264       1.1    jruoho AcpiRsStreamOptionLength (
    265       1.1    jruoho     UINT32                  ResourceLength,
    266       1.1    jruoho     UINT32                  MinimumAmlResourceLength)
    267       1.1    jruoho {
    268       1.1    jruoho     UINT32                  StringLength = 0;
    269       1.1    jruoho 
    270       1.1    jruoho 
    271       1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    272       1.1    jruoho 
    273       1.1    jruoho 
    274       1.1    jruoho     /*
    275   1.1.1.6  christos      * The ResourceSourceIndex and ResourceSource are optional elements of
    276   1.1.1.6  christos      * some Large-type resource descriptors.
    277       1.1    jruoho      */
    278       1.1    jruoho 
    279       1.1    jruoho     /*
    280   1.1.1.6  christos      * If the length of the actual resource descriptor is greater than the
    281   1.1.1.6  christos      * ACPI spec-defined minimum length, it means that a ResourceSourceIndex
    282   1.1.1.6  christos      * exists and is followed by a (required) null terminated string. The
    283   1.1.1.6  christos      * string length (including the null terminator) is the resource length
    284   1.1.1.6  christos      * minus the minimum length, minus one byte for the ResourceSourceIndex
    285   1.1.1.6  christos      * itself.
    286       1.1    jruoho      */
    287       1.1    jruoho     if (ResourceLength > MinimumAmlResourceLength)
    288       1.1    jruoho     {
    289       1.1    jruoho         /* Compute the length of the optional string */
    290       1.1    jruoho 
    291       1.1    jruoho         StringLength = ResourceLength - MinimumAmlResourceLength - 1;
    292       1.1    jruoho     }
    293       1.1    jruoho 
    294       1.1    jruoho     /*
    295       1.1    jruoho      * Round the length up to a multiple of the native word in order to
    296       1.1    jruoho      * guarantee that the entire resource descriptor is native word aligned
    297       1.1    jruoho      */
    298       1.1    jruoho     return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
    299       1.1    jruoho }
    300       1.1    jruoho 
    301       1.1    jruoho 
    302       1.1    jruoho /*******************************************************************************
    303       1.1    jruoho  *
    304       1.1    jruoho  * FUNCTION:    AcpiRsGetAmlLength
    305       1.1    jruoho  *
    306       1.1    jruoho  * PARAMETERS:  Resource            - Pointer to the resource linked list
    307   1.1.1.3  christos  *              ResourceListSize    - Size of the resource linked list
    308       1.1    jruoho  *              SizeNeeded          - Where the required size is returned
    309       1.1    jruoho  *
    310       1.1    jruoho  * RETURN:      Status
    311       1.1    jruoho  *
    312       1.1    jruoho  * DESCRIPTION: Takes a linked list of internal resource descriptors and
    313       1.1    jruoho  *              calculates the size buffer needed to hold the corresponding
    314       1.1    jruoho  *              external resource byte stream.
    315       1.1    jruoho  *
    316       1.1    jruoho  ******************************************************************************/
    317       1.1    jruoho 
    318       1.1    jruoho ACPI_STATUS
    319       1.1    jruoho AcpiRsGetAmlLength (
    320       1.1    jruoho     ACPI_RESOURCE           *Resource,
    321   1.1.1.3  christos     ACPI_SIZE               ResourceListSize,
    322       1.1    jruoho     ACPI_SIZE               *SizeNeeded)
    323       1.1    jruoho {
    324       1.1    jruoho     ACPI_SIZE               AmlSizeNeeded = 0;
    325   1.1.1.3  christos     ACPI_RESOURCE           *ResourceEnd;
    326       1.1    jruoho     ACPI_RS_LENGTH          TotalSize;
    327       1.1    jruoho 
    328       1.1    jruoho 
    329       1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetAmlLength);
    330       1.1    jruoho 
    331       1.1    jruoho 
    332       1.1    jruoho     /* Traverse entire list of internal resource descriptors */
    333       1.1    jruoho 
    334   1.1.1.3  christos     ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
    335   1.1.1.3  christos     while (Resource < ResourceEnd)
    336       1.1    jruoho     {
    337       1.1    jruoho         /* Validate the descriptor type */
    338       1.1    jruoho 
    339       1.1    jruoho         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
    340       1.1    jruoho         {
    341       1.1    jruoho             return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
    342       1.1    jruoho         }
    343       1.1    jruoho 
    344   1.1.1.3  christos         /* Sanity check the length. It must not be zero, or we loop forever */
    345   1.1.1.3  christos 
    346   1.1.1.3  christos         if (!Resource->Length)
    347   1.1.1.3  christos         {
    348   1.1.1.3  christos             return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
    349   1.1.1.3  christos         }
    350   1.1.1.3  christos 
    351       1.1    jruoho         /* Get the base size of the (external stream) resource descriptor */
    352       1.1    jruoho 
    353       1.1    jruoho         TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
    354       1.1    jruoho 
    355       1.1    jruoho         /*
    356       1.1    jruoho          * Augment the base size for descriptors with optional and/or
    357       1.1    jruoho          * variable-length fields
    358       1.1    jruoho          */
    359       1.1    jruoho         switch (Resource->Type)
    360       1.1    jruoho         {
    361       1.1    jruoho         case ACPI_RESOURCE_TYPE_IRQ:
    362       1.1    jruoho 
    363       1.1    jruoho             /* Length can be 3 or 2 */
    364       1.1    jruoho 
    365       1.1    jruoho             if (Resource->Data.Irq.DescriptorLength == 2)
    366       1.1    jruoho             {
    367       1.1    jruoho                 TotalSize--;
    368       1.1    jruoho             }
    369       1.1    jruoho             break;
    370       1.1    jruoho 
    371       1.1    jruoho 
    372       1.1    jruoho         case ACPI_RESOURCE_TYPE_START_DEPENDENT:
    373       1.1    jruoho 
    374       1.1    jruoho             /* Length can be 1 or 0 */
    375       1.1    jruoho 
    376       1.1    jruoho             if (Resource->Data.Irq.DescriptorLength == 0)
    377       1.1    jruoho             {
    378       1.1    jruoho                 TotalSize--;
    379       1.1    jruoho             }
    380       1.1    jruoho             break;
    381       1.1    jruoho 
    382       1.1    jruoho 
    383       1.1    jruoho         case ACPI_RESOURCE_TYPE_VENDOR:
    384       1.1    jruoho             /*
    385       1.1    jruoho              * Vendor Defined Resource:
    386       1.1    jruoho              * For a Vendor Specific resource, if the Length is between 1 and 7
    387       1.1    jruoho              * it will be created as a Small Resource data type, otherwise it
    388       1.1    jruoho              * is a Large Resource data type.
    389       1.1    jruoho              */
    390       1.1    jruoho             if (Resource->Data.Vendor.ByteLength > 7)
    391       1.1    jruoho             {
    392       1.1    jruoho                 /* Base size of a Large resource descriptor */
    393       1.1    jruoho 
    394       1.1    jruoho                 TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
    395       1.1    jruoho             }
    396       1.1    jruoho 
    397       1.1    jruoho             /* Add the size of the vendor-specific data */
    398       1.1    jruoho 
    399       1.1    jruoho             TotalSize = (ACPI_RS_LENGTH)
    400       1.1    jruoho                 (TotalSize + Resource->Data.Vendor.ByteLength);
    401       1.1    jruoho             break;
    402       1.1    jruoho 
    403       1.1    jruoho 
    404       1.1    jruoho         case ACPI_RESOURCE_TYPE_END_TAG:
    405       1.1    jruoho             /*
    406       1.1    jruoho              * End Tag:
    407       1.1    jruoho              * We are done -- return the accumulated total size.
    408       1.1    jruoho              */
    409       1.1    jruoho             *SizeNeeded = AmlSizeNeeded + TotalSize;
    410       1.1    jruoho 
    411       1.1    jruoho             /* Normal exit */
    412       1.1    jruoho 
    413       1.1    jruoho             return_ACPI_STATUS (AE_OK);
    414       1.1    jruoho 
    415       1.1    jruoho 
    416       1.1    jruoho         case ACPI_RESOURCE_TYPE_ADDRESS16:
    417       1.1    jruoho             /*
    418       1.1    jruoho              * 16-Bit Address Resource:
    419       1.1    jruoho              * Add the size of the optional ResourceSource info
    420       1.1    jruoho              */
    421   1.1.1.6  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    422   1.1.1.6  christos                 AcpiRsStructOptionLength (
    423   1.1.1.6  christos                     &Resource->Data.Address16.ResourceSource));
    424       1.1    jruoho             break;
    425       1.1    jruoho 
    426       1.1    jruoho 
    427       1.1    jruoho         case ACPI_RESOURCE_TYPE_ADDRESS32:
    428       1.1    jruoho             /*
    429       1.1    jruoho              * 32-Bit Address Resource:
    430       1.1    jruoho              * Add the size of the optional ResourceSource info
    431       1.1    jruoho              */
    432   1.1.1.6  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    433   1.1.1.6  christos                 AcpiRsStructOptionLength (
    434   1.1.1.6  christos                     &Resource->Data.Address32.ResourceSource));
    435       1.1    jruoho             break;
    436       1.1    jruoho 
    437       1.1    jruoho 
    438       1.1    jruoho         case ACPI_RESOURCE_TYPE_ADDRESS64:
    439       1.1    jruoho             /*
    440       1.1    jruoho              * 64-Bit Address Resource:
    441       1.1    jruoho              * Add the size of the optional ResourceSource info
    442       1.1    jruoho              */
    443   1.1.1.6  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    444   1.1.1.6  christos                 AcpiRsStructOptionLength (
    445   1.1.1.6  christos                     &Resource->Data.Address64.ResourceSource));
    446       1.1    jruoho             break;
    447       1.1    jruoho 
    448       1.1    jruoho 
    449       1.1    jruoho         case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
    450       1.1    jruoho             /*
    451       1.1    jruoho              * Extended IRQ Resource:
    452       1.1    jruoho              * Add the size of each additional optional interrupt beyond the
    453       1.1    jruoho              * required 1 (4 bytes for each UINT32 interrupt number)
    454       1.1    jruoho              */
    455   1.1.1.6  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    456       1.1    jruoho                 ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
    457       1.1    jruoho 
    458       1.1    jruoho                 /* Add the size of the optional ResourceSource info */
    459       1.1    jruoho 
    460       1.1    jruoho                 AcpiRsStructOptionLength (
    461       1.1    jruoho                     &Resource->Data.ExtendedIrq.ResourceSource));
    462       1.1    jruoho             break;
    463       1.1    jruoho 
    464       1.1    jruoho 
    465   1.1.1.3  christos         case ACPI_RESOURCE_TYPE_GPIO:
    466   1.1.1.3  christos 
    467   1.1.1.6  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    468   1.1.1.6  christos                 (Resource->Data.Gpio.PinTableLength * 2) +
    469   1.1.1.3  christos                 Resource->Data.Gpio.ResourceSource.StringLength +
    470   1.1.1.3  christos                 Resource->Data.Gpio.VendorLength);
    471   1.1.1.3  christos 
    472   1.1.1.3  christos             break;
    473   1.1.1.3  christos 
    474   1.1.1.8  christos         case ACPI_RESOURCE_TYPE_PIN_FUNCTION:
    475   1.1.1.8  christos 
    476   1.1.1.8  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    477   1.1.1.8  christos                 (Resource->Data.PinFunction.PinTableLength * 2) +
    478   1.1.1.8  christos                 Resource->Data.PinFunction.ResourceSource.StringLength +
    479   1.1.1.8  christos                 Resource->Data.PinFunction.VendorLength);
    480   1.1.1.8  christos 
    481   1.1.1.8  christos             break;
    482   1.1.1.8  christos 
    483  1.1.1.14  christos         case ACPI_RESOURCE_TYPE_CLOCK_INPUT:
    484  1.1.1.14  christos 
    485  1.1.1.14  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    486  1.1.1.14  christos                 Resource->Data.ClockInput.ResourceSource.StringLength);
    487  1.1.1.14  christos 
    488  1.1.1.14  christos             break;
    489  1.1.1.14  christos 
    490   1.1.1.3  christos 
    491   1.1.1.3  christos         case ACPI_RESOURCE_TYPE_SERIAL_BUS:
    492   1.1.1.3  christos 
    493   1.1.1.6  christos             TotalSize = AcpiGbl_AmlResourceSerialBusSizes [
    494   1.1.1.6  christos                 Resource->Data.CommonSerialBus.Type];
    495   1.1.1.3  christos 
    496   1.1.1.3  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    497   1.1.1.3  christos                 Resource->Data.I2cSerialBus.ResourceSource.StringLength +
    498   1.1.1.3  christos                 Resource->Data.I2cSerialBus.VendorLength);
    499   1.1.1.3  christos 
    500   1.1.1.3  christos             break;
    501   1.1.1.3  christos 
    502   1.1.1.8  christos         case ACPI_RESOURCE_TYPE_PIN_CONFIG:
    503   1.1.1.8  christos 
    504   1.1.1.8  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    505   1.1.1.8  christos                 (Resource->Data.PinConfig.PinTableLength * 2) +
    506   1.1.1.8  christos                 Resource->Data.PinConfig.ResourceSource.StringLength +
    507   1.1.1.8  christos                 Resource->Data.PinConfig.VendorLength);
    508   1.1.1.8  christos 
    509   1.1.1.8  christos             break;
    510   1.1.1.8  christos 
    511   1.1.1.8  christos         case ACPI_RESOURCE_TYPE_PIN_GROUP:
    512   1.1.1.8  christos 
    513   1.1.1.8  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    514   1.1.1.8  christos                 (Resource->Data.PinGroup.PinTableLength * 2) +
    515   1.1.1.8  christos                 Resource->Data.PinGroup.ResourceLabel.StringLength +
    516   1.1.1.8  christos                 Resource->Data.PinGroup.VendorLength);
    517   1.1.1.8  christos 
    518   1.1.1.8  christos             break;
    519   1.1.1.8  christos 
    520   1.1.1.8  christos         case ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION:
    521   1.1.1.8  christos 
    522   1.1.1.8  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    523   1.1.1.8  christos                 Resource->Data.PinGroupFunction.ResourceSource.StringLength +
    524   1.1.1.8  christos                 Resource->Data.PinGroupFunction.ResourceSourceLabel.StringLength +
    525   1.1.1.8  christos                 Resource->Data.PinGroupFunction.VendorLength);
    526   1.1.1.8  christos 
    527   1.1.1.8  christos             break;
    528   1.1.1.8  christos 
    529   1.1.1.8  christos         case ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG:
    530   1.1.1.8  christos 
    531   1.1.1.8  christos             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
    532   1.1.1.8  christos                 Resource->Data.PinGroupConfig.ResourceSource.StringLength +
    533   1.1.1.8  christos                 Resource->Data.PinGroupConfig.ResourceSourceLabel.StringLength +
    534   1.1.1.8  christos                 Resource->Data.PinGroupConfig.VendorLength);
    535   1.1.1.8  christos 
    536   1.1.1.8  christos             break;
    537   1.1.1.8  christos 
    538       1.1    jruoho         default:
    539   1.1.1.3  christos 
    540       1.1    jruoho             break;
    541       1.1    jruoho         }
    542       1.1    jruoho 
    543       1.1    jruoho         /* Update the total */
    544       1.1    jruoho 
    545       1.1    jruoho         AmlSizeNeeded += TotalSize;
    546       1.1    jruoho 
    547       1.1    jruoho         /* Point to the next object */
    548       1.1    jruoho 
    549       1.1    jruoho         Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
    550       1.1    jruoho     }
    551       1.1    jruoho 
    552       1.1    jruoho     /* Did not find an EndTag resource descriptor */
    553       1.1    jruoho 
    554       1.1    jruoho     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
    555       1.1    jruoho }
    556       1.1    jruoho 
    557       1.1    jruoho 
    558       1.1    jruoho /*******************************************************************************
    559       1.1    jruoho  *
    560       1.1    jruoho  * FUNCTION:    AcpiRsGetListLength
    561       1.1    jruoho  *
    562       1.1    jruoho  * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
    563       1.1    jruoho  *              AmlBufferLength     - Size of AmlBuffer
    564       1.1    jruoho  *              SizeNeeded          - Where the size needed is returned
    565       1.1    jruoho  *
    566       1.1    jruoho  * RETURN:      Status
    567       1.1    jruoho  *
    568       1.1    jruoho  * DESCRIPTION: Takes an external resource byte stream and calculates the size
    569       1.1    jruoho  *              buffer needed to hold the corresponding internal resource
    570       1.1    jruoho  *              descriptor linked list.
    571       1.1    jruoho  *
    572       1.1    jruoho  ******************************************************************************/
    573       1.1    jruoho 
    574       1.1    jruoho ACPI_STATUS
    575       1.1    jruoho AcpiRsGetListLength (
    576       1.1    jruoho     UINT8                   *AmlBuffer,
    577       1.1    jruoho     UINT32                  AmlBufferLength,
    578       1.1    jruoho     ACPI_SIZE               *SizeNeeded)
    579       1.1    jruoho {
    580       1.1    jruoho     ACPI_STATUS             Status;
    581       1.1    jruoho     UINT8                   *EndAml;
    582       1.1    jruoho     UINT8                   *Buffer;
    583       1.1    jruoho     UINT32                  BufferSize;
    584       1.1    jruoho     UINT16                  Temp16;
    585       1.1    jruoho     UINT16                  ResourceLength;
    586       1.1    jruoho     UINT32                  ExtraStructBytes;
    587       1.1    jruoho     UINT8                   ResourceIndex;
    588       1.1    jruoho     UINT8                   MinimumAmlResourceLength;
    589   1.1.1.3  christos     AML_RESOURCE            *AmlResource;
    590       1.1    jruoho 
    591       1.1    jruoho 
    592       1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetListLength);
    593       1.1    jruoho 
    594       1.1    jruoho 
    595   1.1.1.3  christos     *SizeNeeded = ACPI_RS_SIZE_MIN;         /* Minimum size is one EndTag */
    596       1.1    jruoho     EndAml = AmlBuffer + AmlBufferLength;
    597       1.1    jruoho 
    598       1.1    jruoho     /* Walk the list of AML resource descriptors */
    599       1.1    jruoho 
    600       1.1    jruoho     while (AmlBuffer < EndAml)
    601       1.1    jruoho     {
    602       1.1    jruoho         /* Validate the Resource Type and Resource Length */
    603       1.1    jruoho 
    604   1.1.1.3  christos         Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
    605       1.1    jruoho         if (ACPI_FAILURE (Status))
    606       1.1    jruoho         {
    607   1.1.1.3  christos             /*
    608   1.1.1.3  christos              * Exit on failure. Cannot continue because the descriptor length
    609   1.1.1.3  christos              * may be bogus also.
    610   1.1.1.3  christos              */
    611       1.1    jruoho             return_ACPI_STATUS (Status);
    612       1.1    jruoho         }
    613       1.1    jruoho 
    614   1.1.1.3  christos         AmlResource = (void *) AmlBuffer;
    615   1.1.1.3  christos 
    616       1.1    jruoho         /* Get the resource length and base (minimum) AML size */
    617       1.1    jruoho 
    618       1.1    jruoho         ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
    619       1.1    jruoho         MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
    620       1.1    jruoho 
    621       1.1    jruoho         /*
    622       1.1    jruoho          * Augment the size for descriptors with optional
    623       1.1    jruoho          * and/or variable length fields
    624       1.1    jruoho          */
    625       1.1    jruoho         ExtraStructBytes = 0;
    626       1.1    jruoho         Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
    627       1.1    jruoho 
    628       1.1    jruoho         switch (AcpiUtGetResourceType (AmlBuffer))
    629       1.1    jruoho         {
    630       1.1    jruoho         case ACPI_RESOURCE_NAME_IRQ:
    631       1.1    jruoho             /*
    632       1.1    jruoho              * IRQ Resource:
    633       1.1    jruoho              * Get the number of bits set in the 16-bit IRQ mask
    634       1.1    jruoho              */
    635       1.1    jruoho             ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
    636       1.1    jruoho             ExtraStructBytes = AcpiRsCountSetBits (Temp16);
    637       1.1    jruoho             break;
    638       1.1    jruoho 
    639       1.1    jruoho 
    640       1.1    jruoho         case ACPI_RESOURCE_NAME_DMA:
    641       1.1    jruoho             /*
    642       1.1    jruoho              * DMA Resource:
    643       1.1    jruoho              * Get the number of bits set in the 8-bit DMA mask
    644       1.1    jruoho              */
    645       1.1    jruoho             ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
    646       1.1    jruoho             break;
    647       1.1    jruoho 
    648       1.1    jruoho 
    649       1.1    jruoho         case ACPI_RESOURCE_NAME_VENDOR_SMALL:
    650       1.1    jruoho         case ACPI_RESOURCE_NAME_VENDOR_LARGE:
    651       1.1    jruoho             /*
    652       1.1    jruoho              * Vendor Resource:
    653       1.1    jruoho              * Get the number of vendor data bytes
    654       1.1    jruoho              */
    655       1.1    jruoho             ExtraStructBytes = ResourceLength;
    656   1.1.1.3  christos 
    657   1.1.1.3  christos             /*
    658   1.1.1.3  christos              * There is already one byte included in the minimum
    659   1.1.1.3  christos              * descriptor size. If there are extra struct bytes,
    660   1.1.1.3  christos              * subtract one from the count.
    661   1.1.1.3  christos              */
    662   1.1.1.3  christos             if (ExtraStructBytes)
    663   1.1.1.3  christos             {
    664   1.1.1.3  christos                 ExtraStructBytes--;
    665   1.1.1.3  christos             }
    666       1.1    jruoho             break;
    667       1.1    jruoho 
    668       1.1    jruoho 
    669       1.1    jruoho         case ACPI_RESOURCE_NAME_END_TAG:
    670       1.1    jruoho             /*
    671   1.1.1.3  christos              * End Tag: This is the normal exit
    672       1.1    jruoho              */
    673       1.1    jruoho             return_ACPI_STATUS (AE_OK);
    674       1.1    jruoho 
    675       1.1    jruoho 
    676       1.1    jruoho         case ACPI_RESOURCE_NAME_ADDRESS32:
    677       1.1    jruoho         case ACPI_RESOURCE_NAME_ADDRESS16:
    678       1.1    jruoho         case ACPI_RESOURCE_NAME_ADDRESS64:
    679       1.1    jruoho             /*
    680       1.1    jruoho              * Address Resource:
    681       1.1    jruoho              * Add the size of the optional ResourceSource
    682       1.1    jruoho              */
    683       1.1    jruoho             ExtraStructBytes = AcpiRsStreamOptionLength (
    684       1.1    jruoho                 ResourceLength, MinimumAmlResourceLength);
    685       1.1    jruoho             break;
    686       1.1    jruoho 
    687       1.1    jruoho 
    688       1.1    jruoho         case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
    689       1.1    jruoho             /*
    690       1.1    jruoho              * Extended IRQ Resource:
    691       1.1    jruoho              * Using the InterruptTableLength, add 4 bytes for each additional
    692       1.1    jruoho              * interrupt. Note: at least one interrupt is required and is
    693       1.1    jruoho              * included in the minimum descriptor size (reason for the -1)
    694       1.1    jruoho              */
    695       1.1    jruoho             ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
    696       1.1    jruoho 
    697       1.1    jruoho             /* Add the size of the optional ResourceSource */
    698       1.1    jruoho 
    699       1.1    jruoho             ExtraStructBytes += AcpiRsStreamOptionLength (
    700       1.1    jruoho                 ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
    701       1.1    jruoho             break;
    702       1.1    jruoho 
    703   1.1.1.3  christos         case ACPI_RESOURCE_NAME_GPIO:
    704   1.1.1.3  christos 
    705   1.1.1.3  christos             /* Vendor data is optional */
    706   1.1.1.3  christos 
    707   1.1.1.3  christos             if (AmlResource->Gpio.VendorLength)
    708   1.1.1.3  christos             {
    709   1.1.1.6  christos                 ExtraStructBytes +=
    710   1.1.1.6  christos                     AmlResource->Gpio.VendorOffset -
    711   1.1.1.6  christos                     AmlResource->Gpio.PinTableOffset +
    712   1.1.1.6  christos                     AmlResource->Gpio.VendorLength;
    713   1.1.1.3  christos             }
    714   1.1.1.3  christos             else
    715   1.1.1.3  christos             {
    716   1.1.1.6  christos                 ExtraStructBytes +=
    717   1.1.1.6  christos                     AmlResource->LargeHeader.ResourceLength +
    718   1.1.1.3  christos                     sizeof (AML_RESOURCE_LARGE_HEADER) -
    719   1.1.1.3  christos                     AmlResource->Gpio.PinTableOffset;
    720   1.1.1.3  christos             }
    721   1.1.1.3  christos             break;
    722   1.1.1.3  christos 
    723   1.1.1.8  christos         case ACPI_RESOURCE_NAME_PIN_FUNCTION:
    724   1.1.1.8  christos 
    725   1.1.1.8  christos             /* Vendor data is optional */
    726   1.1.1.8  christos 
    727   1.1.1.8  christos             if (AmlResource->PinFunction.VendorLength)
    728   1.1.1.8  christos             {
    729   1.1.1.8  christos                 ExtraStructBytes +=
    730   1.1.1.8  christos                     AmlResource->PinFunction.VendorOffset -
    731   1.1.1.8  christos                     AmlResource->PinFunction.PinTableOffset +
    732   1.1.1.8  christos                     AmlResource->PinFunction.VendorLength;
    733   1.1.1.8  christos             }
    734   1.1.1.8  christos             else
    735   1.1.1.8  christos             {
    736   1.1.1.8  christos                 ExtraStructBytes +=
    737   1.1.1.8  christos                     AmlResource->LargeHeader.ResourceLength +
    738   1.1.1.8  christos                     sizeof (AML_RESOURCE_LARGE_HEADER) -
    739   1.1.1.8  christos                     AmlResource->PinFunction.PinTableOffset;
    740   1.1.1.8  christos             }
    741   1.1.1.8  christos             break;
    742   1.1.1.8  christos 
    743  1.1.1.14  christos         case ACPI_RESOURCE_NAME_SERIAL_BUS: {
    744   1.1.1.3  christos 
    745   1.1.1.3  christos             MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
    746  1.1.1.16  christos                 AmlResource->CommonSerialBus.Type];
    747   1.1.1.6  christos             ExtraStructBytes +=
    748  1.1.1.16  christos                 AmlResource->CommonSerialBus.ResourceLength -
    749   1.1.1.3  christos                 MinimumAmlResourceLength;
    750   1.1.1.3  christos             break;
    751  1.1.1.14  christos         }
    752       1.1    jruoho 
    753   1.1.1.8  christos         case ACPI_RESOURCE_NAME_PIN_CONFIG:
    754   1.1.1.8  christos 
    755   1.1.1.8  christos             /* Vendor data is optional */
    756   1.1.1.8  christos 
    757   1.1.1.8  christos             if (AmlResource->PinConfig.VendorLength)
    758   1.1.1.8  christos             {
    759   1.1.1.8  christos                 ExtraStructBytes +=
    760   1.1.1.8  christos                     AmlResource->PinConfig.VendorOffset -
    761   1.1.1.8  christos                     AmlResource->PinConfig.PinTableOffset +
    762   1.1.1.8  christos                     AmlResource->PinConfig.VendorLength;
    763   1.1.1.8  christos             }
    764   1.1.1.8  christos             else
    765   1.1.1.8  christos             {
    766   1.1.1.8  christos                 ExtraStructBytes +=
    767   1.1.1.8  christos                     AmlResource->LargeHeader.ResourceLength +
    768   1.1.1.8  christos                     sizeof (AML_RESOURCE_LARGE_HEADER) -
    769   1.1.1.8  christos                     AmlResource->PinConfig.PinTableOffset;
    770   1.1.1.8  christos             }
    771   1.1.1.8  christos             break;
    772   1.1.1.8  christos 
    773   1.1.1.8  christos         case ACPI_RESOURCE_NAME_PIN_GROUP:
    774   1.1.1.8  christos 
    775   1.1.1.8  christos             ExtraStructBytes +=
    776   1.1.1.8  christos                 AmlResource->PinGroup.VendorOffset -
    777   1.1.1.8  christos                 AmlResource->PinGroup.PinTableOffset +
    778   1.1.1.8  christos                 AmlResource->PinGroup.VendorLength;
    779   1.1.1.8  christos 
    780   1.1.1.8  christos             break;
    781   1.1.1.8  christos 
    782   1.1.1.8  christos         case ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION:
    783   1.1.1.8  christos 
    784   1.1.1.8  christos             ExtraStructBytes +=
    785   1.1.1.8  christos                 AmlResource->PinGroupFunction.VendorOffset -
    786   1.1.1.8  christos                 AmlResource->PinGroupFunction.ResSourceOffset +
    787   1.1.1.8  christos                 AmlResource->PinGroupFunction.VendorLength;
    788   1.1.1.8  christos 
    789   1.1.1.8  christos             break;
    790   1.1.1.8  christos 
    791   1.1.1.8  christos         case ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG:
    792   1.1.1.8  christos 
    793   1.1.1.8  christos             ExtraStructBytes +=
    794   1.1.1.8  christos                 AmlResource->PinGroupConfig.VendorOffset -
    795   1.1.1.8  christos                 AmlResource->PinGroupConfig.ResSourceOffset +
    796   1.1.1.8  christos                 AmlResource->PinGroupConfig.VendorLength;
    797   1.1.1.8  christos 
    798   1.1.1.8  christos             break;
    799   1.1.1.8  christos 
    800  1.1.1.14  christos         case ACPI_RESOURCE_NAME_CLOCK_INPUT:
    801  1.1.1.14  christos             ExtraStructBytes = AcpiRsStreamOptionLength (
    802  1.1.1.14  christos                 ResourceLength, MinimumAmlResourceLength);
    803  1.1.1.14  christos 
    804  1.1.1.14  christos             break;
    805  1.1.1.14  christos 
    806       1.1    jruoho         default:
    807   1.1.1.3  christos 
    808       1.1    jruoho             break;
    809       1.1    jruoho         }
    810       1.1    jruoho 
    811       1.1    jruoho         /*
    812       1.1    jruoho          * Update the required buffer size for the internal descriptor structs
    813       1.1    jruoho          *
    814       1.1    jruoho          * Important: Round the size up for the appropriate alignment. This
    815       1.1    jruoho          * is a requirement on IA64.
    816       1.1    jruoho          */
    817   1.1.1.6  christos         if (AcpiUtGetResourceType (AmlBuffer) ==
    818   1.1.1.6  christos             ACPI_RESOURCE_NAME_SERIAL_BUS)
    819   1.1.1.3  christos         {
    820   1.1.1.3  christos             BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
    821  1.1.1.16  christos                 AmlResource->CommonSerialBus.Type] + ExtraStructBytes;
    822   1.1.1.3  christos         }
    823   1.1.1.3  christos         else
    824   1.1.1.3  christos         {
    825   1.1.1.3  christos             BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
    826   1.1.1.6  christos                 ExtraStructBytes;
    827   1.1.1.3  christos         }
    828       1.1    jruoho 
    829   1.1.1.6  christos         BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
    830       1.1    jruoho         *SizeNeeded += BufferSize;
    831       1.1    jruoho 
    832       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
    833  1.1.1.12  christos             "Type %.2X, AmlLength %.2X InternalLength %.2X%8X\n",
    834       1.1    jruoho             AcpiUtGetResourceType (AmlBuffer),
    835  1.1.1.12  christos             AcpiUtGetDescriptorLength (AmlBuffer), ACPI_FORMAT_UINT64(*SizeNeeded)));
    836       1.1    jruoho 
    837       1.1    jruoho         /*
    838       1.1    jruoho          * Point to the next resource within the AML stream using the length
    839       1.1    jruoho          * contained in the resource descriptor header
    840       1.1    jruoho          */
    841       1.1    jruoho         AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
    842       1.1    jruoho     }
    843       1.1    jruoho 
    844       1.1    jruoho     /* Did not find an EndTag resource descriptor */
    845       1.1    jruoho 
    846       1.1    jruoho     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
    847       1.1    jruoho }
    848       1.1    jruoho 
    849       1.1    jruoho 
    850       1.1    jruoho /*******************************************************************************
    851       1.1    jruoho  *
    852       1.1    jruoho  * FUNCTION:    AcpiRsGetPciRoutingTableLength
    853       1.1    jruoho  *
    854       1.1    jruoho  * PARAMETERS:  PackageObject           - Pointer to the package object
    855       1.1    jruoho  *              BufferSizeNeeded        - UINT32 pointer of the size buffer
    856       1.1    jruoho  *                                        needed to properly return the
    857       1.1    jruoho  *                                        parsed data
    858       1.1    jruoho  *
    859       1.1    jruoho  * RETURN:      Status
    860       1.1    jruoho  *
    861       1.1    jruoho  * DESCRIPTION: Given a package representing a PCI routing table, this
    862       1.1    jruoho  *              calculates the size of the corresponding linked list of
    863       1.1    jruoho  *              descriptions.
    864       1.1    jruoho  *
    865       1.1    jruoho  ******************************************************************************/
    866       1.1    jruoho 
    867       1.1    jruoho ACPI_STATUS
    868       1.1    jruoho AcpiRsGetPciRoutingTableLength (
    869       1.1    jruoho     ACPI_OPERAND_OBJECT     *PackageObject,
    870       1.1    jruoho     ACPI_SIZE               *BufferSizeNeeded)
    871       1.1    jruoho {
    872       1.1    jruoho     UINT32                  NumberOfElements;
    873       1.1    jruoho     ACPI_SIZE               TempSizeNeeded = 0;
    874       1.1    jruoho     ACPI_OPERAND_OBJECT     **TopObjectList;
    875       1.1    jruoho     UINT32                  Index;
    876       1.1    jruoho     ACPI_OPERAND_OBJECT     *PackageElement;
    877       1.1    jruoho     ACPI_OPERAND_OBJECT     **SubObjectList;
    878       1.1    jruoho     BOOLEAN                 NameFound;
    879       1.1    jruoho     UINT32                  TableIndex;
    880       1.1    jruoho 
    881       1.1    jruoho 
    882       1.1    jruoho     ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
    883       1.1    jruoho 
    884       1.1    jruoho 
    885       1.1    jruoho     NumberOfElements = PackageObject->Package.Count;
    886       1.1    jruoho 
    887       1.1    jruoho     /*
    888       1.1    jruoho      * Calculate the size of the return buffer.
    889       1.1    jruoho      * The base size is the number of elements * the sizes of the
    890   1.1.1.3  christos      * structures. Additional space for the strings is added below.
    891       1.1    jruoho      * The minus one is to subtract the size of the UINT8 Source[1]
    892       1.1    jruoho      * member because it is added below.
    893       1.1    jruoho      *
    894       1.1    jruoho      * But each PRT_ENTRY structure has a pointer to a string and
    895       1.1    jruoho      * the size of that string must be found.
    896       1.1    jruoho      */
    897       1.1    jruoho     TopObjectList = PackageObject->Package.Elements;
    898       1.1    jruoho 
    899       1.1    jruoho     for (Index = 0; Index < NumberOfElements; Index++)
    900       1.1    jruoho     {
    901   1.1.1.4  christos         /* Dereference the subpackage */
    902       1.1    jruoho 
    903       1.1    jruoho         PackageElement = *TopObjectList;
    904       1.1    jruoho 
    905       1.1    jruoho         /* We must have a valid Package object */
    906       1.1    jruoho 
    907       1.1    jruoho         if (!PackageElement ||
    908       1.1    jruoho             (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
    909       1.1    jruoho         {
    910       1.1    jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
    911       1.1    jruoho         }
    912       1.1    jruoho 
    913       1.1    jruoho         /*
    914       1.1    jruoho          * The SubObjectList will now point to an array of the
    915       1.1    jruoho          * four IRQ elements: Address, Pin, Source and SourceIndex
    916       1.1    jruoho          */
    917       1.1    jruoho         SubObjectList = PackageElement->Package.Elements;
    918       1.1    jruoho 
    919       1.1    jruoho         /* Scan the IrqTableElements for the Source Name String */
    920       1.1    jruoho 
    921       1.1    jruoho         NameFound = FALSE;
    922       1.1    jruoho 
    923   1.1.1.3  christos         for (TableIndex = 0;
    924   1.1.1.3  christos              TableIndex < PackageElement->Package.Count && !NameFound;
    925   1.1.1.3  christos              TableIndex++)
    926       1.1    jruoho         {
    927       1.1    jruoho             if (*SubObjectList && /* Null object allowed */
    928       1.1    jruoho 
    929       1.1    jruoho                 ((ACPI_TYPE_STRING ==
    930       1.1    jruoho                     (*SubObjectList)->Common.Type) ||
    931       1.1    jruoho 
    932       1.1    jruoho                 ((ACPI_TYPE_LOCAL_REFERENCE ==
    933       1.1    jruoho                     (*SubObjectList)->Common.Type) &&
    934       1.1    jruoho 
    935       1.1    jruoho                     ((*SubObjectList)->Reference.Class ==
    936       1.1    jruoho                         ACPI_REFCLASS_NAME))))
    937       1.1    jruoho             {
    938       1.1    jruoho                 NameFound = TRUE;
    939       1.1    jruoho             }
    940       1.1    jruoho             else
    941       1.1    jruoho             {
    942       1.1    jruoho                 /* Look at the next element */
    943       1.1    jruoho 
    944       1.1    jruoho                 SubObjectList++;
    945       1.1    jruoho             }
    946       1.1    jruoho         }
    947       1.1    jruoho 
    948       1.1    jruoho         TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
    949       1.1    jruoho 
    950       1.1    jruoho         /* Was a String type found? */
    951       1.1    jruoho 
    952       1.1    jruoho         if (NameFound)
    953       1.1    jruoho         {
    954       1.1    jruoho             if ((*SubObjectList)->Common.Type == ACPI_TYPE_STRING)
    955       1.1    jruoho             {
    956       1.1    jruoho                 /*
    957       1.1    jruoho                  * The length String.Length field does not include the
    958       1.1    jruoho                  * terminating NULL, add 1
    959       1.1    jruoho                  */
    960       1.1    jruoho                 TempSizeNeeded += ((ACPI_SIZE)
    961       1.1    jruoho                     (*SubObjectList)->String.Length + 1);
    962       1.1    jruoho             }
    963       1.1    jruoho             else
    964       1.1    jruoho             {
    965       1.1    jruoho                 TempSizeNeeded += AcpiNsGetPathnameLength (
    966   1.1.1.6  christos                     (*SubObjectList)->Reference.Node);
    967       1.1    jruoho             }
    968       1.1    jruoho         }
    969       1.1    jruoho         else
    970       1.1    jruoho         {
    971       1.1    jruoho             /*
    972       1.1    jruoho              * If no name was found, then this is a NULL, which is
    973       1.1    jruoho              * translated as a UINT32 zero.
    974       1.1    jruoho              */
    975       1.1    jruoho             TempSizeNeeded += sizeof (UINT32);
    976       1.1    jruoho         }
    977       1.1    jruoho 
    978       1.1    jruoho         /* Round up the size since each element must be aligned */
    979       1.1    jruoho 
    980       1.1    jruoho         TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded);
    981       1.1    jruoho 
    982       1.1    jruoho         /* Point to the next ACPI_OPERAND_OBJECT */
    983       1.1    jruoho 
    984       1.1    jruoho         TopObjectList++;
    985       1.1    jruoho     }
    986       1.1    jruoho 
    987       1.1    jruoho     /*
    988       1.1    jruoho      * Add an extra element to the end of the list, essentially a
    989       1.1    jruoho      * NULL terminator
    990       1.1    jruoho      */
    991       1.1    jruoho     *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
    992       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    993       1.1    jruoho }
    994