17c478bd9Sstevel@tonic-gate /*******************************************************************************
27c478bd9Sstevel@tonic-gate  *
37c478bd9Sstevel@tonic-gate  * Module Name: rscalc - Calculate stream and list lengths
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  ******************************************************************************/
67c478bd9Sstevel@tonic-gate 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
127c478bd9Sstevel@tonic-gate  * All rights reserved.
137c478bd9Sstevel@tonic-gate  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
13326f3cdf0SGordon Ross  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate #include "acpi.h"
153aa2aa9a6SDana Myers #include "accommon.h"
1547c478bd9Sstevel@tonic-gate #include "acresrc.h"
1557c478bd9Sstevel@tonic-gate #include "acnamesp.h"
1567c478bd9Sstevel@tonic-gate 
157db2bae30SDana Myers 
1587c478bd9Sstevel@tonic-gate #define _COMPONENT          ACPI_RESOURCES
1597c478bd9Sstevel@tonic-gate         ACPI_MODULE_NAME    ("rscalc")
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 
162186507a7Smyers /* Local prototypes */
163186507a7Smyers 
164186507a7Smyers static UINT8
165186507a7Smyers AcpiRsCountSetBits (
166186507a7Smyers     UINT16                  BitField);
167186507a7Smyers 
16830082d0cSmyers static ACPI_RS_LENGTH
169186507a7Smyers AcpiRsStructOptionLength (
170186507a7Smyers     ACPI_RESOURCE_SOURCE    *ResourceSource);
171186507a7Smyers 
172186507a7Smyers static UINT32
173186507a7Smyers AcpiRsStreamOptionLength (
174186507a7Smyers     UINT32                  ResourceLength,
175186507a7Smyers     UINT32                  MinimumTotalLength);
176186507a7Smyers 
177186507a7Smyers 
1787c478bd9Sstevel@tonic-gate /*******************************************************************************
1797c478bd9Sstevel@tonic-gate  *
180186507a7Smyers  * FUNCTION:    AcpiRsCountSetBits
1817c478bd9Sstevel@tonic-gate  *
182186507a7Smyers  * PARAMETERS:  BitField        - Field in which to count bits
1837c478bd9Sstevel@tonic-gate  *
184186507a7Smyers  * RETURN:      Number of bits set within the field
1857c478bd9Sstevel@tonic-gate  *
186186507a7Smyers  * DESCRIPTION: Count the number of bits set in a resource field. Used for
187186507a7Smyers  *              (Short descriptor) interrupt and DMA lists.
1887c478bd9Sstevel@tonic-gate  *
1897c478bd9Sstevel@tonic-gate  ******************************************************************************/
1907c478bd9Sstevel@tonic-gate 
191186507a7Smyers static UINT8
AcpiRsCountSetBits(UINT16 BitField)192186507a7Smyers AcpiRsCountSetBits (
193186507a7Smyers     UINT16                  BitField)
1947c478bd9Sstevel@tonic-gate {
195186507a7Smyers     UINT8                   BitsSet;
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 
198186507a7Smyers     ACPI_FUNCTION_ENTRY ();
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 
201186507a7Smyers     for (BitsSet = 0; BitField; BitsSet++)
2027c478bd9Sstevel@tonic-gate     {
203186507a7Smyers         /* Zero the least significant bit that is set */
2047c478bd9Sstevel@tonic-gate 
205db2bae30SDana Myers         BitField &= (UINT16) (BitField - 1);
206186507a7Smyers     }
2077c478bd9Sstevel@tonic-gate 
208186507a7Smyers     return (BitsSet);
209186507a7Smyers }
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 
212186507a7Smyers /*******************************************************************************
213186507a7Smyers  *
214186507a7Smyers  * FUNCTION:    AcpiRsStructOptionLength
215186507a7Smyers  *
216186507a7Smyers  * PARAMETERS:  ResourceSource      - Pointer to optional descriptor field
217186507a7Smyers  *
218186507a7Smyers  * RETURN:      Status
219186507a7Smyers  *
220186507a7Smyers  * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
221186507a7Smyers  *              ResourceSource fields in some Large descriptors. Used during
222186507a7Smyers  *              list-to-stream conversion
223186507a7Smyers  *
224186507a7Smyers  ******************************************************************************/
2257c478bd9Sstevel@tonic-gate 
22630082d0cSmyers static ACPI_RS_LENGTH
AcpiRsStructOptionLength(ACPI_RESOURCE_SOURCE * ResourceSource)227186507a7Smyers AcpiRsStructOptionLength (
228186507a7Smyers     ACPI_RESOURCE_SOURCE    *ResourceSource)
229186507a7Smyers {
230186507a7Smyers     ACPI_FUNCTION_ENTRY ();
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 
233186507a7Smyers     /*
234186507a7Smyers      * If the ResourceSource string is valid, return the size of the string
235186507a7Smyers      * (StringLength includes the NULL terminator) plus the size of the
236186507a7Smyers      * ResourceSourceIndex (1).
237186507a7Smyers      */
238186507a7Smyers     if (ResourceSource->StringPtr)
239186507a7Smyers     {
24030082d0cSmyers         return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1));
241186507a7Smyers     }
2427c478bd9Sstevel@tonic-gate 
243186507a7Smyers     return (0);
244186507a7Smyers }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 
247186507a7Smyers /*******************************************************************************
248186507a7Smyers  *
249186507a7Smyers  * FUNCTION:    AcpiRsStreamOptionLength
250186507a7Smyers  *
251186507a7Smyers  * PARAMETERS:  ResourceLength      - Length from the resource header
252186507a7Smyers  *              MinimumTotalLength  - Minimum length of this resource, before
253186507a7Smyers  *                                    any optional fields. Includes header size
254186507a7Smyers  *
255186507a7Smyers  * RETURN:      Length of optional string (0 if no string present)
256186507a7Smyers  *
257186507a7Smyers  * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
258186507a7Smyers  *              ResourceSource fields in some Large descriptors. Used during
259186507a7Smyers  *              stream-to-list conversion
260186507a7Smyers  *
261186507a7Smyers  ******************************************************************************/
2627c478bd9Sstevel@tonic-gate 
263186507a7Smyers static UINT32
AcpiRsStreamOptionLength(UINT32 ResourceLength,UINT32 MinimumAmlResourceLength)264186507a7Smyers AcpiRsStreamOptionLength (
265186507a7Smyers     UINT32                  ResourceLength,
266186507a7Smyers     UINT32                  MinimumAmlResourceLength)
267186507a7Smyers {
268186507a7Smyers     UINT32                  StringLength = 0;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 
271186507a7Smyers     ACPI_FUNCTION_ENTRY ();
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate 
274186507a7Smyers     /*
2757b1019a6SJerry Jelinek      * The ResourceSourceIndex and ResourceSource are optional elements of
2767b1019a6SJerry Jelinek      * some Large-type resource descriptors.
277186507a7Smyers      */
2787c478bd9Sstevel@tonic-gate 
279186507a7Smyers     /*
2807b1019a6SJerry Jelinek      * If the length of the actual resource descriptor is greater than the
2817b1019a6SJerry Jelinek      * ACPI spec-defined minimum length, it means that a ResourceSourceIndex
2827b1019a6SJerry Jelinek      * exists and is followed by a (required) null terminated string. The
2837b1019a6SJerry Jelinek      * string length (including the null terminator) is the resource length
2847b1019a6SJerry Jelinek      * minus the minimum length, minus one byte for the ResourceSourceIndex
2857b1019a6SJerry Jelinek      * itself.
286186507a7Smyers      */
287186507a7Smyers     if (ResourceLength > MinimumAmlResourceLength)
288186507a7Smyers     {
289186507a7Smyers         /* Compute the length of the optional string */
2907c478bd9Sstevel@tonic-gate 
291186507a7Smyers         StringLength = ResourceLength - MinimumAmlResourceLength - 1;
2927c478bd9Sstevel@tonic-gate     }
2937c478bd9Sstevel@tonic-gate 
29430082d0cSmyers     /*
29530082d0cSmyers      * Round the length up to a multiple of the native word in order to
29630082d0cSmyers      * guarantee that the entire resource descriptor is native word aligned
29730082d0cSmyers      */
29830082d0cSmyers     return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate /*******************************************************************************
3037c478bd9Sstevel@tonic-gate  *
304186507a7Smyers  * FUNCTION:    AcpiRsGetAmlLength
3057c478bd9Sstevel@tonic-gate  *
306186507a7Smyers  * PARAMETERS:  Resource            - Pointer to the resource linked list
3077b1019a6SJerry Jelinek  *              ResourceListSize    - Size of the resource linked list
308186507a7Smyers  *              SizeNeeded          - Where the required size is returned
3097c478bd9Sstevel@tonic-gate  *
3107c478bd9Sstevel@tonic-gate  * RETURN:      Status
3117c478bd9Sstevel@tonic-gate  *
312186507a7Smyers  * DESCRIPTION: Takes a linked list of internal resource descriptors and
313186507a7Smyers  *              calculates the size buffer needed to hold the corresponding
314186507a7Smyers  *              external resource byte stream.
3157c478bd9Sstevel@tonic-gate  *
3167c478bd9Sstevel@tonic-gate  ******************************************************************************/
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsGetAmlLength(ACPI_RESOURCE * Resource,ACPI_SIZE ResourceListSize,ACPI_SIZE * SizeNeeded)319186507a7Smyers AcpiRsGetAmlLength (
320186507a7Smyers     ACPI_RESOURCE           *Resource,
3217b1019a6SJerry Jelinek     ACPI_SIZE               ResourceListSize,
3227c478bd9Sstevel@tonic-gate     ACPI_SIZE               *SizeNeeded)
3237c478bd9Sstevel@tonic-gate {
324186507a7Smyers     ACPI_SIZE               AmlSizeNeeded = 0;
3257b1019a6SJerry Jelinek     ACPI_RESOURCE           *ResourceEnd;
32630082d0cSmyers     ACPI_RS_LENGTH          TotalSize;
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 
32927f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetAmlLength);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 
332186507a7Smyers     /* Traverse entire list of internal resource descriptors */
3337c478bd9Sstevel@tonic-gate 
3347b1019a6SJerry Jelinek     ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
3357b1019a6SJerry Jelinek     while (Resource < ResourceEnd)
336186507a7Smyers     {
337186507a7Smyers         /* Validate the descriptor type */
3387c478bd9Sstevel@tonic-gate 
339186507a7Smyers         if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
3407c478bd9Sstevel@tonic-gate         {
341186507a7Smyers             return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
342186507a7Smyers         }
3437c478bd9Sstevel@tonic-gate 
3447b1019a6SJerry Jelinek         /* Sanity check the length. It must not be zero, or we loop forever */
3457b1019a6SJerry Jelinek 
3467b1019a6SJerry Jelinek         if (!Resource->Length)
3477b1019a6SJerry Jelinek         {
3487b1019a6SJerry Jelinek             return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
3497b1019a6SJerry Jelinek         }
3507b1019a6SJerry Jelinek 
351186507a7Smyers         /* Get the base size of the (external stream) resource descriptor */
3527c478bd9Sstevel@tonic-gate 
35330082d0cSmyers         TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
3547c478bd9Sstevel@tonic-gate 
355186507a7Smyers         /*
356186507a7Smyers          * Augment the base size for descriptors with optional and/or
357186507a7Smyers          * variable-length fields
358186507a7Smyers          */
359186507a7Smyers         switch (Resource->Type)
360186507a7Smyers         {
361db2bae30SDana Myers         case ACPI_RESOURCE_TYPE_IRQ:
362db2bae30SDana Myers 
363db2bae30SDana Myers             /* Length can be 3 or 2 */
364db2bae30SDana Myers 
365db2bae30SDana Myers             if (Resource->Data.Irq.DescriptorLength == 2)
366db2bae30SDana Myers             {
367db2bae30SDana Myers                 TotalSize--;
368db2bae30SDana Myers             }
369db2bae30SDana Myers             break;
370db2bae30SDana Myers 
371db2bae30SDana Myers 
372db2bae30SDana Myers         case ACPI_RESOURCE_TYPE_START_DEPENDENT:
373db2bae30SDana Myers 
374db2bae30SDana Myers             /* Length can be 1 or 0 */
375db2bae30SDana Myers 
376db2bae30SDana Myers             if (Resource->Data.Irq.DescriptorLength == 0)
377db2bae30SDana Myers             {
378db2bae30SDana Myers                 TotalSize--;
379db2bae30SDana Myers             }
380db2bae30SDana Myers             break;
381db2bae30SDana Myers 
382db2bae30SDana Myers 
383186507a7Smyers         case ACPI_RESOURCE_TYPE_VENDOR:
3847c478bd9Sstevel@tonic-gate             /*
385186507a7Smyers              * Vendor Defined Resource:
386186507a7Smyers              * For a Vendor Specific resource, if the Length is between 1 and 7
387186507a7Smyers              * it will be created as a Small Resource data type, otherwise it
388186507a7Smyers              * is a Large Resource data type.
3897c478bd9Sstevel@tonic-gate              */
390186507a7Smyers             if (Resource->Data.Vendor.ByteLength > 7)
391186507a7Smyers             {
392186507a7Smyers                 /* Base size of a Large resource descriptor */
3937c478bd9Sstevel@tonic-gate 
39430082d0cSmyers                 TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
395186507a7Smyers             }
3967c478bd9Sstevel@tonic-gate 
397186507a7Smyers             /* Add the size of the vendor-specific data */
3987c478bd9Sstevel@tonic-gate 
39930082d0cSmyers             TotalSize = (ACPI_RS_LENGTH)
40030082d0cSmyers                 (TotalSize + Resource->Data.Vendor.ByteLength);
4017c478bd9Sstevel@tonic-gate             break;
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 
404186507a7Smyers         case ACPI_RESOURCE_TYPE_END_TAG:
4057c478bd9Sstevel@tonic-gate             /*
406186507a7Smyers              * End Tag:
407186507a7Smyers              * We are done -- return the accumulated total size.
4087c478bd9Sstevel@tonic-gate              */
40930082d0cSmyers             *SizeNeeded = AmlSizeNeeded + TotalSize;
4107c478bd9Sstevel@tonic-gate 
411186507a7Smyers             /* Normal exit */
4127c478bd9Sstevel@tonic-gate 
413186507a7Smyers             return_ACPI_STATUS (AE_OK);
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 
416186507a7Smyers         case ACPI_RESOURCE_TYPE_ADDRESS16:
4177c478bd9Sstevel@tonic-gate             /*
418186507a7Smyers              * 16-Bit Address Resource:
419186507a7Smyers              * Add the size of the optional ResourceSource info
4207c478bd9Sstevel@tonic-gate              */
4217b1019a6SJerry Jelinek             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4227b1019a6SJerry Jelinek                 AcpiRsStructOptionLength (
4237b1019a6SJerry Jelinek                     &Resource->Data.Address16.ResourceSource));
4247c478bd9Sstevel@tonic-gate             break;
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 
427186507a7Smyers         case ACPI_RESOURCE_TYPE_ADDRESS32:
4287c478bd9Sstevel@tonic-gate             /*
429186507a7Smyers              * 32-Bit Address Resource:
430186507a7Smyers              * Add the size of the optional ResourceSource info
4317c478bd9Sstevel@tonic-gate              */
4327b1019a6SJerry Jelinek             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4337b1019a6SJerry Jelinek                 AcpiRsStructOptionLength (
4347b1019a6SJerry Jelinek                     &Resource->Data.Address32.ResourceSource));
4357c478bd9Sstevel@tonic-gate             break;
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 
438186507a7Smyers         case ACPI_RESOURCE_TYPE_ADDRESS64:
4397c478bd9Sstevel@tonic-gate             /*
440186507a7Smyers              * 64-Bit Address Resource:
441186507a7Smyers              * Add the size of the optional ResourceSource info
4427c478bd9Sstevel@tonic-gate              */
4437b1019a6SJerry Jelinek             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4447b1019a6SJerry Jelinek                 AcpiRsStructOptionLength (
4457b1019a6SJerry Jelinek                     &Resource->Data.Address64.ResourceSource));
4467c478bd9Sstevel@tonic-gate             break;
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate 
449186507a7Smyers         case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
4507c478bd9Sstevel@tonic-gate             /*
451186507a7Smyers              * Extended IRQ Resource:
452186507a7Smyers              * Add the size of each additional optional interrupt beyond the
453186507a7Smyers              * required 1 (4 bytes for each UINT32 interrupt number)
4547c478bd9Sstevel@tonic-gate              */
4557b1019a6SJerry Jelinek             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
45630082d0cSmyers                 ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
4577c478bd9Sstevel@tonic-gate 
45830082d0cSmyers                 /* Add the size of the optional ResourceSource info */
4597c478bd9Sstevel@tonic-gate 
46030082d0cSmyers                 AcpiRsStructOptionLength (
46130082d0cSmyers                     &Resource->Data.ExtendedIrq.ResourceSource));
462186507a7Smyers             break;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 
4657b1019a6SJerry Jelinek         case ACPI_RESOURCE_TYPE_GPIO:
4667b1019a6SJerry Jelinek 
4677b1019a6SJerry Jelinek             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4687b1019a6SJerry Jelinek                 (Resource->Data.Gpio.PinTableLength * 2) +
4697b1019a6SJerry Jelinek                 Resource->Data.Gpio.ResourceSource.StringLength +
4707b1019a6SJerry Jelinek                 Resource->Data.Gpio.VendorLength);
4717b1019a6SJerry Jelinek 
4727b1019a6SJerry Jelinek             break;
4737b1019a6SJerry Jelinek 
474*35786f68SRobert Mustacchi         case ACPI_RESOURCE_TYPE_PIN_FUNCTION:
475*35786f68SRobert Mustacchi 
476*35786f68SRobert Mustacchi             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
477*35786f68SRobert Mustacchi                 (Resource->Data.PinFunction.PinTableLength * 2) +
478*35786f68SRobert Mustacchi                 Resource->Data.PinFunction.ResourceSource.StringLength +
479*35786f68SRobert Mustacchi                 Resource->Data.PinFunction.VendorLength);
480*35786f68SRobert Mustacchi 
481*35786f68SRobert Mustacchi             break;
482*35786f68SRobert Mustacchi 
4837b1019a6SJerry Jelinek 
4847b1019a6SJerry Jelinek         case ACPI_RESOURCE_TYPE_SERIAL_BUS:
4857b1019a6SJerry Jelinek 
4867b1019a6SJerry Jelinek             TotalSize = AcpiGbl_AmlResourceSerialBusSizes [
4877b1019a6SJerry Jelinek                 Resource->Data.CommonSerialBus.Type];
4887b1019a6SJerry Jelinek 
4897b1019a6SJerry Jelinek             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
4907b1019a6SJerry Jelinek                 Resource->Data.I2cSerialBus.ResourceSource.StringLength +
4917b1019a6SJerry Jelinek                 Resource->Data.I2cSerialBus.VendorLength);
4927b1019a6SJerry Jelinek 
4937b1019a6SJerry Jelinek             break;
4947b1019a6SJerry Jelinek 
495*35786f68SRobert Mustacchi         case ACPI_RESOURCE_TYPE_PIN_CONFIG:
496*35786f68SRobert Mustacchi 
497*35786f68SRobert Mustacchi             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
498*35786f68SRobert Mustacchi                 (Resource->Data.PinConfig.PinTableLength * 2) +
499*35786f68SRobert Mustacchi                 Resource->Data.PinConfig.ResourceSource.StringLength +
500*35786f68SRobert Mustacchi                 Resource->Data.PinConfig.VendorLength);
501*35786f68SRobert Mustacchi 
502*35786f68SRobert Mustacchi             break;
503*35786f68SRobert Mustacchi 
504*35786f68SRobert Mustacchi         case ACPI_RESOURCE_TYPE_PIN_GROUP:
505*35786f68SRobert Mustacchi 
506*35786f68SRobert Mustacchi             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
507*35786f68SRobert Mustacchi                 (Resource->Data.PinGroup.PinTableLength * 2) +
508*35786f68SRobert Mustacchi                 Resource->Data.PinGroup.ResourceLabel.StringLength +
509*35786f68SRobert Mustacchi                 Resource->Data.PinGroup.VendorLength);
510*35786f68SRobert Mustacchi 
511*35786f68SRobert Mustacchi             break;
512*35786f68SRobert Mustacchi 
513*35786f68SRobert Mustacchi         case ACPI_RESOURCE_TYPE_PIN_GROUP_FUNCTION:
514*35786f68SRobert Mustacchi 
515*35786f68SRobert Mustacchi             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
516*35786f68SRobert Mustacchi                 Resource->Data.PinGroupFunction.ResourceSource.StringLength +
517*35786f68SRobert Mustacchi                 Resource->Data.PinGroupFunction.ResourceSourceLabel.StringLength +
518*35786f68SRobert Mustacchi                 Resource->Data.PinGroupFunction.VendorLength);
519*35786f68SRobert Mustacchi 
520*35786f68SRobert Mustacchi             break;
521*35786f68SRobert Mustacchi 
522*35786f68SRobert Mustacchi         case ACPI_RESOURCE_TYPE_PIN_GROUP_CONFIG:
523*35786f68SRobert Mustacchi 
524*35786f68SRobert Mustacchi             TotalSize = (ACPI_RS_LENGTH) (TotalSize +
525*35786f68SRobert Mustacchi                 Resource->Data.PinGroupConfig.ResourceSource.StringLength +
526*35786f68SRobert Mustacchi                 Resource->Data.PinGroupConfig.ResourceSourceLabel.StringLength +
527*35786f68SRobert Mustacchi                 Resource->Data.PinGroupConfig.VendorLength);
528*35786f68SRobert Mustacchi 
529*35786f68SRobert Mustacchi             break;
530*35786f68SRobert Mustacchi 
531186507a7Smyers         default:
5327b1019a6SJerry Jelinek 
5337c478bd9Sstevel@tonic-gate             break;
534186507a7Smyers         }
5357c478bd9Sstevel@tonic-gate 
536186507a7Smyers         /* Update the total */
5377c478bd9Sstevel@tonic-gate 
53830082d0cSmyers         AmlSizeNeeded += TotalSize;
5397c478bd9Sstevel@tonic-gate 
540186507a7Smyers         /* Point to the next object */
5417c478bd9Sstevel@tonic-gate 
54230082d0cSmyers         Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
543186507a7Smyers     }
5447c478bd9Sstevel@tonic-gate 
54530082d0cSmyers     /* Did not find an EndTag resource descriptor */
5467c478bd9Sstevel@tonic-gate 
54730082d0cSmyers     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
548186507a7Smyers }
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate 
551186507a7Smyers /*******************************************************************************
552186507a7Smyers  *
553186507a7Smyers  * FUNCTION:    AcpiRsGetListLength
554186507a7Smyers  *
555186507a7Smyers  * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
556186507a7Smyers  *              AmlBufferLength     - Size of AmlBuffer
557186507a7Smyers  *              SizeNeeded          - Where the size needed is returned
558186507a7Smyers  *
559186507a7Smyers  * RETURN:      Status
560186507a7Smyers  *
561186507a7Smyers  * DESCRIPTION: Takes an external resource byte stream and calculates the size
562186507a7Smyers  *              buffer needed to hold the corresponding internal resource
563186507a7Smyers  *              descriptor linked list.
564186507a7Smyers  *
565186507a7Smyers  ******************************************************************************/
5667c478bd9Sstevel@tonic-gate 
567186507a7Smyers ACPI_STATUS
AcpiRsGetListLength(UINT8 * AmlBuffer,UINT32 AmlBufferLength,ACPI_SIZE * SizeNeeded)568186507a7Smyers AcpiRsGetListLength (
569186507a7Smyers     UINT8                   *AmlBuffer,
570186507a7Smyers     UINT32                  AmlBufferLength,
571186507a7Smyers     ACPI_SIZE               *SizeNeeded)
572186507a7Smyers {
57330082d0cSmyers     ACPI_STATUS             Status;
57430082d0cSmyers     UINT8                   *EndAml;
575186507a7Smyers     UINT8                   *Buffer;
57630082d0cSmyers     UINT32                  BufferSize;
577186507a7Smyers     UINT16                  Temp16;
578186507a7Smyers     UINT16                  ResourceLength;
579186507a7Smyers     UINT32                  ExtraStructBytes;
58030082d0cSmyers     UINT8                   ResourceIndex;
58130082d0cSmyers     UINT8                   MinimumAmlResourceLength;
5827b1019a6SJerry Jelinek     AML_RESOURCE            *AmlResource;
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 
58527f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetListLength);
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate 
5887b1019a6SJerry Jelinek     *SizeNeeded = ACPI_RS_SIZE_MIN;         /* Minimum size is one EndTag */
58930082d0cSmyers     EndAml = AmlBuffer + AmlBufferLength;
5907c478bd9Sstevel@tonic-gate 
59130082d0cSmyers     /* Walk the list of AML resource descriptors */
5927c478bd9Sstevel@tonic-gate 
59330082d0cSmyers     while (AmlBuffer < EndAml)
59430082d0cSmyers     {
59530082d0cSmyers         /* Validate the Resource Type and Resource Length */
5967c478bd9Sstevel@tonic-gate 
5977b1019a6SJerry Jelinek         Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
59830082d0cSmyers         if (ACPI_FAILURE (Status))
599186507a7Smyers         {
6007b1019a6SJerry Jelinek             /*
6017b1019a6SJerry Jelinek              * Exit on failure. Cannot continue because the descriptor length
6027b1019a6SJerry Jelinek              * may be bogus also.
6037b1019a6SJerry Jelinek              */
60430082d0cSmyers             return_ACPI_STATUS (Status);
605186507a7Smyers         }
6067c478bd9Sstevel@tonic-gate 
6077b1019a6SJerry Jelinek         AmlResource = (void *) AmlBuffer;
6087b1019a6SJerry Jelinek 
60930082d0cSmyers         /* Get the resource length and base (minimum) AML size */
6107c478bd9Sstevel@tonic-gate 
61130082d0cSmyers         ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
61230082d0cSmyers         MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
6137c478bd9Sstevel@tonic-gate 
61430082d0cSmyers         /*
61530082d0cSmyers          * Augment the size for descriptors with optional
61630082d0cSmyers          * and/or variable length fields
61730082d0cSmyers          */
618186507a7Smyers         ExtraStructBytes = 0;
61930082d0cSmyers         Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
6207c478bd9Sstevel@tonic-gate 
62130082d0cSmyers         switch (AcpiUtGetResourceType (AmlBuffer))
622186507a7Smyers         {
62330082d0cSmyers         case ACPI_RESOURCE_NAME_IRQ:
6247c478bd9Sstevel@tonic-gate             /*
62530082d0cSmyers              * IRQ Resource:
62630082d0cSmyers              * Get the number of bits set in the 16-bit IRQ mask
6277c478bd9Sstevel@tonic-gate              */
62830082d0cSmyers             ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
62930082d0cSmyers             ExtraStructBytes = AcpiRsCountSetBits (Temp16);
63030082d0cSmyers             break;
631186507a7Smyers 
632186507a7Smyers 
63330082d0cSmyers         case ACPI_RESOURCE_NAME_DMA:
6347c478bd9Sstevel@tonic-gate             /*
63530082d0cSmyers              * DMA Resource:
63630082d0cSmyers              * Get the number of bits set in the 8-bit DMA mask
6377c478bd9Sstevel@tonic-gate              */
63830082d0cSmyers             ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
63930082d0cSmyers             break;
640186507a7Smyers 
641186507a7Smyers 
64230082d0cSmyers         case ACPI_RESOURCE_NAME_VENDOR_SMALL:
64330082d0cSmyers         case ACPI_RESOURCE_NAME_VENDOR_LARGE:
64430082d0cSmyers             /*
64530082d0cSmyers              * Vendor Resource:
64630082d0cSmyers              * Get the number of vendor data bytes
64730082d0cSmyers              */
64830082d0cSmyers             ExtraStructBytes = ResourceLength;
6497b1019a6SJerry Jelinek 
6507b1019a6SJerry Jelinek             /*
6517b1019a6SJerry Jelinek              * There is already one byte included in the minimum
6527b1019a6SJerry Jelinek              * descriptor size. If there are extra struct bytes,
6537b1019a6SJerry Jelinek              * subtract one from the count.
6547b1019a6SJerry Jelinek              */
6557b1019a6SJerry Jelinek             if (ExtraStructBytes)
6567b1019a6SJerry Jelinek             {
6577b1019a6SJerry Jelinek                 ExtraStructBytes--;
6587b1019a6SJerry Jelinek             }
65930082d0cSmyers             break;
660186507a7Smyers 
661186507a7Smyers 
66230082d0cSmyers         case ACPI_RESOURCE_NAME_END_TAG:
66330082d0cSmyers             /*
6647b1019a6SJerry Jelinek              * End Tag: This is the normal exit
66530082d0cSmyers              */
66630082d0cSmyers             return_ACPI_STATUS (AE_OK);
667186507a7Smyers 
668186507a7Smyers 
66930082d0cSmyers         case ACPI_RESOURCE_NAME_ADDRESS32:
67030082d0cSmyers         case ACPI_RESOURCE_NAME_ADDRESS16:
67130082d0cSmyers         case ACPI_RESOURCE_NAME_ADDRESS64:
67230082d0cSmyers             /*
67330082d0cSmyers              * Address Resource:
67430082d0cSmyers              * Add the size of the optional ResourceSource
67530082d0cSmyers              */
67630082d0cSmyers             ExtraStructBytes = AcpiRsStreamOptionLength (
67730082d0cSmyers                 ResourceLength, MinimumAmlResourceLength);
67830082d0cSmyers             break;
679186507a7Smyers 
680186507a7Smyers 
68130082d0cSmyers         case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
68230082d0cSmyers             /*
68330082d0cSmyers              * Extended IRQ Resource:
68430082d0cSmyers              * Using the InterruptTableLength, add 4 bytes for each additional
68530082d0cSmyers              * interrupt. Note: at least one interrupt is required and is
68630082d0cSmyers              * included in the minimum descriptor size (reason for the -1)
68730082d0cSmyers              */
68830082d0cSmyers             ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
68927f7c583Smyers 
69030082d0cSmyers             /* Add the size of the optional ResourceSource */
691186507a7Smyers 
69230082d0cSmyers             ExtraStructBytes += AcpiRsStreamOptionLength (
69330082d0cSmyers                 ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
69430082d0cSmyers             break;
695186507a7Smyers 
6967b1019a6SJerry Jelinek         case ACPI_RESOURCE_NAME_GPIO:
6977b1019a6SJerry Jelinek 
6987b1019a6SJerry Jelinek             /* Vendor data is optional */
6997b1019a6SJerry Jelinek 
7007b1019a6SJerry Jelinek             if (AmlResource->Gpio.VendorLength)
7017b1019a6SJerry Jelinek             {
7027b1019a6SJerry Jelinek                 ExtraStructBytes +=
7037b1019a6SJerry Jelinek                     AmlResource->Gpio.VendorOffset -
7047b1019a6SJerry Jelinek                     AmlResource->Gpio.PinTableOffset +
7057b1019a6SJerry Jelinek                     AmlResource->Gpio.VendorLength;
7067b1019a6SJerry Jelinek             }
7077b1019a6SJerry Jelinek             else
7087b1019a6SJerry Jelinek             {
7097b1019a6SJerry Jelinek                 ExtraStructBytes +=
7107b1019a6SJerry Jelinek                     AmlResource->LargeHeader.ResourceLength +
7117b1019a6SJerry Jelinek                     sizeof (AML_RESOURCE_LARGE_HEADER) -
7127b1019a6SJerry Jelinek                     AmlResource->Gpio.PinTableOffset;
7137b1019a6SJerry Jelinek             }
7147b1019a6SJerry Jelinek             break;
7157b1019a6SJerry Jelinek 
716*35786f68SRobert Mustacchi         case ACPI_RESOURCE_NAME_PIN_FUNCTION:
717*35786f68SRobert Mustacchi 
718*35786f68SRobert Mustacchi             /* Vendor data is optional */
719*35786f68SRobert Mustacchi 
720*35786f68SRobert Mustacchi             if (AmlResource->PinFunction.VendorLength)
721*35786f68SRobert Mustacchi             {
722*35786f68SRobert Mustacchi                 ExtraStructBytes +=
723*35786f68SRobert Mustacchi                     AmlResource->PinFunction.VendorOffset -
724*35786f68SRobert Mustacchi                     AmlResource->PinFunction.PinTableOffset +
725*35786f68SRobert Mustacchi                     AmlResource->PinFunction.VendorLength;
726*35786f68SRobert Mustacchi             }
727*35786f68SRobert Mustacchi             else
728*35786f68SRobert Mustacchi             {
729*35786f68SRobert Mustacchi                 ExtraStructBytes +=
730*35786f68SRobert Mustacchi                     AmlResource->LargeHeader.ResourceLength +
731*35786f68SRobert Mustacchi                     sizeof (AML_RESOURCE_LARGE_HEADER) -
732*35786f68SRobert Mustacchi                     AmlResource->PinFunction.PinTableOffset;
733*35786f68SRobert Mustacchi             }
734*35786f68SRobert Mustacchi             break;
735*35786f68SRobert Mustacchi 
7367b1019a6SJerry Jelinek         case ACPI_RESOURCE_NAME_SERIAL_BUS:
7377b1019a6SJerry Jelinek 
7387b1019a6SJerry Jelinek             MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
7397b1019a6SJerry Jelinek                 AmlResource->CommonSerialBus.Type];
7407b1019a6SJerry Jelinek             ExtraStructBytes +=
7417b1019a6SJerry Jelinek                 AmlResource->CommonSerialBus.ResourceLength -
7427b1019a6SJerry Jelinek                 MinimumAmlResourceLength;
7437b1019a6SJerry Jelinek             break;
744186507a7Smyers 
745*35786f68SRobert Mustacchi         case ACPI_RESOURCE_NAME_PIN_CONFIG:
746*35786f68SRobert Mustacchi 
747*35786f68SRobert Mustacchi             /* Vendor data is optional */
748*35786f68SRobert Mustacchi 
749*35786f68SRobert Mustacchi             if (AmlResource->PinConfig.VendorLength)
750*35786f68SRobert Mustacchi             {
751*35786f68SRobert Mustacchi                 ExtraStructBytes +=
752*35786f68SRobert Mustacchi                     AmlResource->PinConfig.VendorOffset -
753*35786f68SRobert Mustacchi                     AmlResource->PinConfig.PinTableOffset +
754*35786f68SRobert Mustacchi                     AmlResource->PinConfig.VendorLength;
755*35786f68SRobert Mustacchi             }
756*35786f68SRobert Mustacchi             else
757*35786f68SRobert Mustacchi             {
758*35786f68SRobert Mustacchi                 ExtraStructBytes +=
759*35786f68SRobert Mustacchi                     AmlResource->LargeHeader.ResourceLength +
760*35786f68SRobert Mustacchi                     sizeof (AML_RESOURCE_LARGE_HEADER) -
761*35786f68SRobert Mustacchi                     AmlResource->PinConfig.PinTableOffset;
762*35786f68SRobert Mustacchi             }
763*35786f68SRobert Mustacchi             break;
764*35786f68SRobert Mustacchi 
765*35786f68SRobert Mustacchi         case ACPI_RESOURCE_NAME_PIN_GROUP:
766*35786f68SRobert Mustacchi 
767*35786f68SRobert Mustacchi             ExtraStructBytes +=
768*35786f68SRobert Mustacchi                 AmlResource->PinGroup.VendorOffset -
769*35786f68SRobert Mustacchi                 AmlResource->PinGroup.PinTableOffset +
770*35786f68SRobert Mustacchi                 AmlResource->PinGroup.VendorLength;
771*35786f68SRobert Mustacchi 
772*35786f68SRobert Mustacchi             break;
773*35786f68SRobert Mustacchi 
774*35786f68SRobert Mustacchi         case ACPI_RESOURCE_NAME_PIN_GROUP_FUNCTION:
775*35786f68SRobert Mustacchi 
776*35786f68SRobert Mustacchi             ExtraStructBytes +=
777*35786f68SRobert Mustacchi                 AmlResource->PinGroupFunction.VendorOffset -
778*35786f68SRobert Mustacchi                 AmlResource->PinGroupFunction.ResSourceOffset +
779*35786f68SRobert Mustacchi                 AmlResource->PinGroupFunction.VendorLength;
780*35786f68SRobert Mustacchi 
781*35786f68SRobert Mustacchi             break;
782*35786f68SRobert Mustacchi 
783*35786f68SRobert Mustacchi         case ACPI_RESOURCE_NAME_PIN_GROUP_CONFIG:
784*35786f68SRobert Mustacchi 
785*35786f68SRobert Mustacchi             ExtraStructBytes +=
786*35786f68SRobert Mustacchi                 AmlResource->PinGroupConfig.VendorOffset -
787*35786f68SRobert Mustacchi                 AmlResource->PinGroupConfig.ResSourceOffset +
788*35786f68SRobert Mustacchi                 AmlResource->PinGroupConfig.VendorLength;
789*35786f68SRobert Mustacchi 
790*35786f68SRobert Mustacchi             break;
791*35786f68SRobert Mustacchi 
79230082d0cSmyers         default:
7937b1019a6SJerry Jelinek 
79430082d0cSmyers             break;
7957c478bd9Sstevel@tonic-gate         }
7967c478bd9Sstevel@tonic-gate 
79730082d0cSmyers         /*
79830082d0cSmyers          * Update the required buffer size for the internal descriptor structs
79930082d0cSmyers          *
80030082d0cSmyers          * Important: Round the size up for the appropriate alignment. This
80130082d0cSmyers          * is a requirement on IA64.
80230082d0cSmyers          */
8037b1019a6SJerry Jelinek         if (AcpiUtGetResourceType (AmlBuffer) ==
8047b1019a6SJerry Jelinek             ACPI_RESOURCE_NAME_SERIAL_BUS)
8057b1019a6SJerry Jelinek         {
8067b1019a6SJerry Jelinek             BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
8077b1019a6SJerry Jelinek                 AmlResource->CommonSerialBus.Type] + ExtraStructBytes;
8087b1019a6SJerry Jelinek         }
8097b1019a6SJerry Jelinek         else
8107b1019a6SJerry Jelinek         {
8117b1019a6SJerry Jelinek             BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
8127b1019a6SJerry Jelinek                 ExtraStructBytes;
8137b1019a6SJerry Jelinek         }
81430082d0cSmyers 
8157b1019a6SJerry Jelinek         BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
81630082d0cSmyers         *SizeNeeded += BufferSize;
8177c478bd9Sstevel@tonic-gate 
81830082d0cSmyers         ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
81927f7c583Smyers             "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
82030082d0cSmyers             AcpiUtGetResourceType (AmlBuffer),
82130082d0cSmyers             AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
8227c478bd9Sstevel@tonic-gate 
823186507a7Smyers         /*
82427f7c583Smyers          * Point to the next resource within the AML stream using the length
82530082d0cSmyers          * contained in the resource descriptor header
826186507a7Smyers          */
82730082d0cSmyers         AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
8287c478bd9Sstevel@tonic-gate     }
8297c478bd9Sstevel@tonic-gate 
83030082d0cSmyers     /* Did not find an EndTag resource descriptor */
8317c478bd9Sstevel@tonic-gate 
83230082d0cSmyers     return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
8337c478bd9Sstevel@tonic-gate }
8347c478bd9Sstevel@tonic-gate 
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate /*******************************************************************************
8377c478bd9Sstevel@tonic-gate  *
8387c478bd9Sstevel@tonic-gate  * FUNCTION:    AcpiRsGetPciRoutingTableLength
8397c478bd9Sstevel@tonic-gate  *
8407c478bd9Sstevel@tonic-gate  * PARAMETERS:  PackageObject           - Pointer to the package object
8417c478bd9Sstevel@tonic-gate  *              BufferSizeNeeded        - UINT32 pointer of the size buffer
8427c478bd9Sstevel@tonic-gate  *                                        needed to properly return the
8437c478bd9Sstevel@tonic-gate  *                                        parsed data
8447c478bd9Sstevel@tonic-gate  *
8457c478bd9Sstevel@tonic-gate  * RETURN:      Status
8467c478bd9Sstevel@tonic-gate  *
8477c478bd9Sstevel@tonic-gate  * DESCRIPTION: Given a package representing a PCI routing table, this
8487c478bd9Sstevel@tonic-gate  *              calculates the size of the corresponding linked list of
8497c478bd9Sstevel@tonic-gate  *              descriptions.
8507c478bd9Sstevel@tonic-gate  *
8517c478bd9Sstevel@tonic-gate  ******************************************************************************/
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate ACPI_STATUS
AcpiRsGetPciRoutingTableLength(ACPI_OPERAND_OBJECT * PackageObject,ACPI_SIZE * BufferSizeNeeded)8547c478bd9Sstevel@tonic-gate AcpiRsGetPciRoutingTableLength (
8557c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *PackageObject,
8567c478bd9Sstevel@tonic-gate     ACPI_SIZE               *BufferSizeNeeded)
8577c478bd9Sstevel@tonic-gate {
8587c478bd9Sstevel@tonic-gate     UINT32                  NumberOfElements;
8597c478bd9Sstevel@tonic-gate     ACPI_SIZE               TempSizeNeeded = 0;
8607c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     **TopObjectList;
8617c478bd9Sstevel@tonic-gate     UINT32                  Index;
8627c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     *PackageElement;
8637c478bd9Sstevel@tonic-gate     ACPI_OPERAND_OBJECT     **SubObjectList;
8647c478bd9Sstevel@tonic-gate     BOOLEAN                 NameFound;
8657c478bd9Sstevel@tonic-gate     UINT32                  TableIndex;
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 
86827f7c583Smyers     ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate     NumberOfElements = PackageObject->Package.Count;
8727c478bd9Sstevel@tonic-gate 
8737c478bd9Sstevel@tonic-gate     /*
8747c478bd9Sstevel@tonic-gate      * Calculate the size of the return buffer.
8757c478bd9Sstevel@tonic-gate      * The base size is the number of elements * the sizes of the
8767b1019a6SJerry Jelinek      * structures. Additional space for the strings is added below.
8777c478bd9Sstevel@tonic-gate      * The minus one is to subtract the size of the UINT8 Source[1]
8787c478bd9Sstevel@tonic-gate      * member because it is added below.
8797c478bd9Sstevel@tonic-gate      *
8807c478bd9Sstevel@tonic-gate      * But each PRT_ENTRY structure has a pointer to a string and
8817c478bd9Sstevel@tonic-gate      * the size of that string must be found.
8827c478bd9Sstevel@tonic-gate      */
8837c478bd9Sstevel@tonic-gate     TopObjectList = PackageObject->Package.Elements;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate     for (Index = 0; Index < NumberOfElements; Index++)
8867c478bd9Sstevel@tonic-gate     {
8877b1019a6SJerry Jelinek         /* Dereference the subpackage */
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate         PackageElement = *TopObjectList;
8907c478bd9Sstevel@tonic-gate 
891aa2aa9a6SDana Myers         /* We must have a valid Package object */
892aa2aa9a6SDana Myers 
893aa2aa9a6SDana Myers         if (!PackageElement ||
894aa2aa9a6SDana Myers             (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
895aa2aa9a6SDana Myers         {
896aa2aa9a6SDana Myers             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
897aa2aa9a6SDana Myers         }
898aa2aa9a6SDana Myers 
8997c478bd9Sstevel@tonic-gate         /*
9007c478bd9Sstevel@tonic-gate          * The SubObjectList will now point to an array of the
9017c478bd9Sstevel@tonic-gate          * four IRQ elements: Address, Pin, Source and SourceIndex
9027c478bd9Sstevel@tonic-gate          */
9037c478bd9Sstevel@tonic-gate         SubObjectList = PackageElement->Package.Elements;
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate         /* Scan the IrqTableElements for the Source Name String */
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate         NameFound = FALSE;
9087c478bd9Sstevel@tonic-gate 
9097b1019a6SJerry Jelinek         for (TableIndex = 0;
9107b1019a6SJerry Jelinek              TableIndex < PackageElement->Package.Count && !NameFound;
9117b1019a6SJerry Jelinek              TableIndex++)
9127c478bd9Sstevel@tonic-gate         {
91330082d0cSmyers             if (*SubObjectList && /* Null object allowed */
91430082d0cSmyers 
91530082d0cSmyers                 ((ACPI_TYPE_STRING ==
916aa2aa9a6SDana Myers                     (*SubObjectList)->Common.Type) ||
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate                 ((ACPI_TYPE_LOCAL_REFERENCE ==
919aa2aa9a6SDana Myers                     (*SubObjectList)->Common.Type) &&
9207c478bd9Sstevel@tonic-gate 
921db2bae30SDana Myers                     ((*SubObjectList)->Reference.Class ==
922db2bae30SDana Myers                         ACPI_REFCLASS_NAME))))
9237c478bd9Sstevel@tonic-gate             {
9247c478bd9Sstevel@tonic-gate                 NameFound = TRUE;
9257c478bd9Sstevel@tonic-gate             }
9267c478bd9Sstevel@tonic-gate             else
9277c478bd9Sstevel@tonic-gate             {
9287c478bd9Sstevel@tonic-gate                 /* Look at the next element */
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate                 SubObjectList++;
9317c478bd9Sstevel@tonic-gate             }
9327c478bd9Sstevel@tonic-gate         }
9337c478bd9Sstevel@tonic-gate 
9347c478bd9Sstevel@tonic-gate         TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
9357c478bd9Sstevel@tonic-gate 
9367c478bd9Sstevel@tonic-gate         /* Was a String type found? */
9377c478bd9Sstevel@tonic-gate 
9387c478bd9Sstevel@tonic-gate         if (NameFound)
9397c478bd9Sstevel@tonic-gate         {
940aa2aa9a6SDana Myers             if ((*SubObjectList)->Common.Type == ACPI_TYPE_STRING)
9417c478bd9Sstevel@tonic-gate             {
9427c478bd9Sstevel@tonic-gate                 /*
9437c478bd9Sstevel@tonic-gate                  * The length String.Length field does not include the
9447c478bd9Sstevel@tonic-gate                  * terminating NULL, add 1
9457c478bd9Sstevel@tonic-gate                  */
9467c478bd9Sstevel@tonic-gate                 TempSizeNeeded += ((ACPI_SIZE)
9477c478bd9Sstevel@tonic-gate                     (*SubObjectList)->String.Length + 1);
9487c478bd9Sstevel@tonic-gate             }
9497c478bd9Sstevel@tonic-gate             else
9507c478bd9Sstevel@tonic-gate             {
9517c478bd9Sstevel@tonic-gate                 TempSizeNeeded += AcpiNsGetPathnameLength (
9527b1019a6SJerry Jelinek                     (*SubObjectList)->Reference.Node);
9537c478bd9Sstevel@tonic-gate             }
9547c478bd9Sstevel@tonic-gate         }
9557c478bd9Sstevel@tonic-gate         else
9567c478bd9Sstevel@tonic-gate         {
9577c478bd9Sstevel@tonic-gate             /*
9587c478bd9Sstevel@tonic-gate              * If no name was found, then this is a NULL, which is
9597c478bd9Sstevel@tonic-gate              * translated as a UINT32 zero.
9607c478bd9Sstevel@tonic-gate              */
9617c478bd9Sstevel@tonic-gate             TempSizeNeeded += sizeof (UINT32);
9627c478bd9Sstevel@tonic-gate         }
9637c478bd9Sstevel@tonic-gate 
9647c478bd9Sstevel@tonic-gate         /* Round up the size since each element must be aligned */
9657c478bd9Sstevel@tonic-gate 
96630082d0cSmyers         TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded);
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate         /* Point to the next ACPI_OPERAND_OBJECT */
9697c478bd9Sstevel@tonic-gate 
9707c478bd9Sstevel@tonic-gate         TopObjectList++;
9717c478bd9Sstevel@tonic-gate     }
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate     /*
97430082d0cSmyers      * Add an extra element to the end of the list, essentially a
9757c478bd9Sstevel@tonic-gate      * NULL terminator
9767c478bd9Sstevel@tonic-gate      */
9777c478bd9Sstevel@tonic-gate     *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
9787c478bd9Sstevel@tonic-gate     return_ACPI_STATUS (AE_OK);
9797c478bd9Sstevel@tonic-gate }
980