1bc36eafdSMike Gerdts /*******************************************************************************
2bc36eafdSMike Gerdts *
3bc36eafdSMike Gerdts * Module Name: rscalc - Calculate stream and list lengths
4bc36eafdSMike Gerdts *
5bc36eafdSMike Gerdts ******************************************************************************/
6bc36eafdSMike Gerdts
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.
12bc36eafdSMike Gerdts * All rights reserved.
13bc36eafdSMike Gerdts *
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 *
119bc36eafdSMike Gerdts * Redistribution and use in source and binary forms, with or without
120bc36eafdSMike Gerdts * modification, are permitted provided that the following conditions
121bc36eafdSMike Gerdts * are met:
122bc36eafdSMike Gerdts * 1. Redistributions of source code must retain the above copyright
123bc36eafdSMike Gerdts * notice, this list of conditions, and the following disclaimer,
124bc36eafdSMike Gerdts * without modification.
125bc36eafdSMike Gerdts * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126bc36eafdSMike Gerdts * substantially similar to the "NO WARRANTY" disclaimer below
127bc36eafdSMike Gerdts * ("Disclaimer") and any redistribution must be conditioned upon
128bc36eafdSMike Gerdts * including a substantially similar Disclaimer requirement for further
129bc36eafdSMike Gerdts * binary redistribution.
130bc36eafdSMike Gerdts * 3. Neither the names of the above-listed copyright holders nor the names
131bc36eafdSMike Gerdts * of any contributors may be used to endorse or promote products derived
132bc36eafdSMike Gerdts * from this software without specific prior written permission.
133bc36eafdSMike Gerdts *
134*35786f68SRobert Mustacchi * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135*35786f68SRobert Mustacchi * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137*35786f68SRobert Mustacchi * 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
147bc36eafdSMike Gerdts * GNU General Public License ("GPL") version 2 as published by the Free
148bc36eafdSMike Gerdts * Software Foundation.
149bc36eafdSMike Gerdts *
150*35786f68SRobert Mustacchi *****************************************************************************/
151bc36eafdSMike Gerdts
152bc36eafdSMike Gerdts #include "acpi.h"
153bc36eafdSMike Gerdts #include "accommon.h"
154bc36eafdSMike Gerdts #include "acresrc.h"
155bc36eafdSMike Gerdts #include "acnamesp.h"
156bc36eafdSMike Gerdts
157bc36eafdSMike Gerdts
158bc36eafdSMike Gerdts #define _COMPONENT ACPI_RESOURCES
159bc36eafdSMike Gerdts ACPI_MODULE_NAME ("rscalc")
160bc36eafdSMike Gerdts
161bc36eafdSMike Gerdts
162bc36eafdSMike Gerdts /* Local prototypes */
163bc36eafdSMike Gerdts
164bc36eafdSMike Gerdts static UINT8
165bc36eafdSMike Gerdts AcpiRsCountSetBits (
166bc36eafdSMike Gerdts UINT16 BitField);
167bc36eafdSMike Gerdts
168bc36eafdSMike Gerdts static ACPI_RS_LENGTH
169bc36eafdSMike Gerdts AcpiRsStructOptionLength (
170bc36eafdSMike Gerdts ACPI_RESOURCE_SOURCE *ResourceSource);
171bc36eafdSMike Gerdts
172bc36eafdSMike Gerdts static UINT32
173bc36eafdSMike Gerdts AcpiRsStreamOptionLength (
174bc36eafdSMike Gerdts UINT32 ResourceLength,
175bc36eafdSMike Gerdts UINT32 MinimumTotalLength);
176bc36eafdSMike Gerdts
177bc36eafdSMike Gerdts
178bc36eafdSMike Gerdts /*******************************************************************************
179bc36eafdSMike Gerdts *
180bc36eafdSMike Gerdts * FUNCTION: AcpiRsCountSetBits
181bc36eafdSMike Gerdts *
182bc36eafdSMike Gerdts * PARAMETERS: BitField - Field in which to count bits
183bc36eafdSMike Gerdts *
184bc36eafdSMike Gerdts * RETURN: Number of bits set within the field
185bc36eafdSMike Gerdts *
186bc36eafdSMike Gerdts * DESCRIPTION: Count the number of bits set in a resource field. Used for
187bc36eafdSMike Gerdts * (Short descriptor) interrupt and DMA lists.
188bc36eafdSMike Gerdts *
189bc36eafdSMike Gerdts ******************************************************************************/
190bc36eafdSMike Gerdts
191bc36eafdSMike Gerdts static UINT8
AcpiRsCountSetBits(UINT16 BitField)192bc36eafdSMike Gerdts AcpiRsCountSetBits (
193bc36eafdSMike Gerdts UINT16 BitField)
194bc36eafdSMike Gerdts {
195bc36eafdSMike Gerdts UINT8 BitsSet;
196bc36eafdSMike Gerdts
197bc36eafdSMike Gerdts
198bc36eafdSMike Gerdts ACPI_FUNCTION_ENTRY ();
199bc36eafdSMike Gerdts
200bc36eafdSMike Gerdts
201bc36eafdSMike Gerdts for (BitsSet = 0; BitField; BitsSet++)
202bc36eafdSMike Gerdts {
203bc36eafdSMike Gerdts /* Zero the least significant bit that is set */
204bc36eafdSMike Gerdts
205bc36eafdSMike Gerdts BitField &= (UINT16) (BitField - 1);
206bc36eafdSMike Gerdts }
207bc36eafdSMike Gerdts
208bc36eafdSMike Gerdts return (BitsSet);
209bc36eafdSMike Gerdts }
210bc36eafdSMike Gerdts
211bc36eafdSMike Gerdts
212bc36eafdSMike Gerdts /*******************************************************************************
213bc36eafdSMike Gerdts *
214bc36eafdSMike Gerdts * FUNCTION: AcpiRsStructOptionLength
215bc36eafdSMike Gerdts *
216bc36eafdSMike Gerdts * PARAMETERS: ResourceSource - Pointer to optional descriptor field
217bc36eafdSMike Gerdts *
218bc36eafdSMike Gerdts * RETURN: Status
219bc36eafdSMike Gerdts *
220bc36eafdSMike Gerdts * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
221bc36eafdSMike Gerdts * ResourceSource fields in some Large descriptors. Used during
222bc36eafdSMike Gerdts * list-to-stream conversion
223bc36eafdSMike Gerdts *
224bc36eafdSMike Gerdts ******************************************************************************/
225bc36eafdSMike Gerdts
226bc36eafdSMike Gerdts static ACPI_RS_LENGTH
AcpiRsStructOptionLength(ACPI_RESOURCE_SOURCE * ResourceSource)227bc36eafdSMike Gerdts AcpiRsStructOptionLength (
228bc36eafdSMike Gerdts ACPI_RESOURCE_SOURCE *ResourceSource)
229bc36eafdSMike Gerdts {
230bc36eafdSMike Gerdts ACPI_FUNCTION_ENTRY ();
231bc36eafdSMike Gerdts
232bc36eafdSMike Gerdts
233bc36eafdSMike Gerdts /*
234bc36eafdSMike Gerdts * If the ResourceSource string is valid, return the size of the string
235bc36eafdSMike Gerdts * (StringLength includes the NULL terminator) plus the size of the
236bc36eafdSMike Gerdts * ResourceSourceIndex (1).
237bc36eafdSMike Gerdts */
238bc36eafdSMike Gerdts if (ResourceSource->StringPtr)
239bc36eafdSMike Gerdts {
240bc36eafdSMike Gerdts return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1));
241bc36eafdSMike Gerdts }
242bc36eafdSMike Gerdts
243bc36eafdSMike Gerdts return (0);
244bc36eafdSMike Gerdts }
245bc36eafdSMike Gerdts
246bc36eafdSMike Gerdts
247bc36eafdSMike Gerdts /*******************************************************************************
248bc36eafdSMike Gerdts *
249bc36eafdSMike Gerdts * FUNCTION: AcpiRsStreamOptionLength
250bc36eafdSMike Gerdts *
251bc36eafdSMike Gerdts * PARAMETERS: ResourceLength - Length from the resource header
252bc36eafdSMike Gerdts * MinimumTotalLength - Minimum length of this resource, before
253bc36eafdSMike Gerdts * any optional fields. Includes header size
254bc36eafdSMike Gerdts *
255bc36eafdSMike Gerdts * RETURN: Length of optional string (0 if no string present)
256bc36eafdSMike Gerdts *
257bc36eafdSMike Gerdts * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
258bc36eafdSMike Gerdts * ResourceSource fields in some Large descriptors. Used during
259bc36eafdSMike Gerdts * stream-to-list conversion
260bc36eafdSMike Gerdts *
261bc36eafdSMike Gerdts ******************************************************************************/
262bc36eafdSMike Gerdts
263bc36eafdSMike Gerdts static UINT32
AcpiRsStreamOptionLength(UINT32 ResourceLength,UINT32 MinimumAmlResourceLength)264bc36eafdSMike Gerdts AcpiRsStreamOptionLength (
265bc36eafdSMike Gerdts UINT32 ResourceLength,
266bc36eafdSMike Gerdts UINT32 MinimumAmlResourceLength)
267bc36eafdSMike Gerdts {
268bc36eafdSMike Gerdts UINT32 StringLength = 0;
269bc36eafdSMike Gerdts
270bc36eafdSMike Gerdts
271bc36eafdSMike Gerdts ACPI_FUNCTION_ENTRY ();
272bc36eafdSMike Gerdts
273bc36eafdSMike Gerdts
274bc36eafdSMike Gerdts /*
275bc36eafdSMike Gerdts * The ResourceSourceIndex and ResourceSource are optional elements of
276bc36eafdSMike Gerdts * some Large-type resource descriptors.
277bc36eafdSMike Gerdts */
278bc36eafdSMike Gerdts
279bc36eafdSMike Gerdts /*
280bc36eafdSMike Gerdts * If the length of the actual resource descriptor is greater than the
281bc36eafdSMike Gerdts * ACPI spec-defined minimum length, it means that a ResourceSourceIndex
282bc36eafdSMike Gerdts * exists and is followed by a (required) null terminated string. The
283bc36eafdSMike Gerdts * string length (including the null terminator) is the resource length
284bc36eafdSMike Gerdts * minus the minimum length, minus one byte for the ResourceSourceIndex
285bc36eafdSMike Gerdts * itself.
286bc36eafdSMike Gerdts */
287bc36eafdSMike Gerdts if (ResourceLength > MinimumAmlResourceLength)
288bc36eafdSMike Gerdts {
289bc36eafdSMike Gerdts /* Compute the length of the optional string */
290bc36eafdSMike Gerdts
291bc36eafdSMike Gerdts StringLength = ResourceLength - MinimumAmlResourceLength - 1;
292bc36eafdSMike Gerdts }
293bc36eafdSMike Gerdts
294bc36eafdSMike Gerdts /*
295bc36eafdSMike Gerdts * Round the length up to a multiple of the native word in order to
296bc36eafdSMike Gerdts * guarantee that the entire resource descriptor is native word aligned
297bc36eafdSMike Gerdts */
298bc36eafdSMike Gerdts return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
299bc36eafdSMike Gerdts }
300bc36eafdSMike Gerdts
301bc36eafdSMike Gerdts
302bc36eafdSMike Gerdts /*******************************************************************************
303bc36eafdSMike Gerdts *
304bc36eafdSMike Gerdts * FUNCTION: AcpiRsGetAmlLength
305bc36eafdSMike Gerdts *
306bc36eafdSMike Gerdts * PARAMETERS: Resource - Pointer to the resource linked list
307bc36eafdSMike Gerdts * ResourceListSize - Size of the resource linked list
308bc36eafdSMike Gerdts * SizeNeeded - Where the required size is returned
309bc36eafdSMike Gerdts *
310bc36eafdSMike Gerdts * RETURN: Status
311bc36eafdSMike Gerdts *
312bc36eafdSMike Gerdts * DESCRIPTION: Takes a linked list of internal resource descriptors and
313bc36eafdSMike Gerdts * calculates the size buffer needed to hold the corresponding
314bc36eafdSMike Gerdts * external resource byte stream.
315bc36eafdSMike Gerdts *
316bc36eafdSMike Gerdts ******************************************************************************/
317bc36eafdSMike Gerdts
318bc36eafdSMike Gerdts ACPI_STATUS
AcpiRsGetAmlLength(ACPI_RESOURCE * Resource,ACPI_SIZE ResourceListSize,ACPI_SIZE * SizeNeeded)319bc36eafdSMike Gerdts AcpiRsGetAmlLength (
320bc36eafdSMike Gerdts ACPI_RESOURCE *Resource,
321bc36eafdSMike Gerdts ACPI_SIZE ResourceListSize,
322bc36eafdSMike Gerdts ACPI_SIZE *SizeNeeded)
323bc36eafdSMike Gerdts {
324bc36eafdSMike Gerdts ACPI_SIZE AmlSizeNeeded = 0;
325bc36eafdSMike Gerdts ACPI_RESOURCE *ResourceEnd;
326bc36eafdSMike Gerdts ACPI_RS_LENGTH TotalSize;
327bc36eafdSMike Gerdts
328bc36eafdSMike Gerdts
329bc36eafdSMike Gerdts ACPI_FUNCTION_TRACE (RsGetAmlLength);
330bc36eafdSMike Gerdts
331bc36eafdSMike Gerdts
332bc36eafdSMike Gerdts /* Traverse entire list of internal resource descriptors */
333bc36eafdSMike Gerdts
334bc36eafdSMike Gerdts ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
335bc36eafdSMike Gerdts while (Resource < ResourceEnd)
336bc36eafdSMike Gerdts {
337bc36eafdSMike Gerdts /* Validate the descriptor type */
338bc36eafdSMike Gerdts
339bc36eafdSMike Gerdts if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
340bc36eafdSMike Gerdts {
341bc36eafdSMike Gerdts return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
342bc36eafdSMike Gerdts }
343bc36eafdSMike Gerdts
344bc36eafdSMike Gerdts /* Sanity check the length. It must not be zero, or we loop forever */
345bc36eafdSMike Gerdts
346bc36eafdSMike Gerdts if (!Resource->Length)
347bc36eafdSMike Gerdts {
348bc36eafdSMike Gerdts return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
349bc36eafdSMike Gerdts }
350bc36eafdSMike Gerdts
351bc36eafdSMike Gerdts /* Get the base size of the (external stream) resource descriptor */
352bc36eafdSMike Gerdts
353bc36eafdSMike Gerdts TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
354bc36eafdSMike Gerdts
355bc36eafdSMike Gerdts /*
356bc36eafdSMike Gerdts * Augment the base size for descriptors with optional and/or
357bc36eafdSMike Gerdts * variable-length fields
358bc36eafdSMike Gerdts */
359bc36eafdSMike Gerdts switch (Resource->Type)
360bc36eafdSMike Gerdts {
361bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_IRQ:
362bc36eafdSMike Gerdts
363bc36eafdSMike Gerdts /* Length can be 3 or 2 */
364bc36eafdSMike Gerdts
365bc36eafdSMike Gerdts if (Resource->Data.Irq.DescriptorLength == 2)
366bc36eafdSMike Gerdts {
367bc36eafdSMike Gerdts TotalSize--;
368bc36eafdSMike Gerdts }
369bc36eafdSMike Gerdts break;
370bc36eafdSMike Gerdts
371bc36eafdSMike Gerdts
372bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_START_DEPENDENT:
373bc36eafdSMike Gerdts
374bc36eafdSMike Gerdts /* Length can be 1 or 0 */
375bc36eafdSMike Gerdts
376bc36eafdSMike Gerdts if (Resource->Data.Irq.DescriptorLength == 0)
377bc36eafdSMike Gerdts {
378bc36eafdSMike Gerdts TotalSize--;
379bc36eafdSMike Gerdts }
380bc36eafdSMike Gerdts break;
381bc36eafdSMike Gerdts
382bc36eafdSMike Gerdts
383bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_VENDOR:
384bc36eafdSMike Gerdts /*
385bc36eafdSMike Gerdts * Vendor Defined Resource:
386bc36eafdSMike Gerdts * For a Vendor Specific resource, if the Length is between 1 and 7
387bc36eafdSMike Gerdts * it will be created as a Small Resource data type, otherwise it
388bc36eafdSMike Gerdts * is a Large Resource data type.
389bc36eafdSMike Gerdts */
390bc36eafdSMike Gerdts if (Resource->Data.Vendor.ByteLength > 7)
391bc36eafdSMike Gerdts {
392bc36eafdSMike Gerdts /* Base size of a Large resource descriptor */
393bc36eafdSMike Gerdts
394bc36eafdSMike Gerdts TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
395bc36eafdSMike Gerdts }
396bc36eafdSMike Gerdts
397bc36eafdSMike Gerdts /* Add the size of the vendor-specific data */
398bc36eafdSMike Gerdts
399bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH)
400bc36eafdSMike Gerdts (TotalSize + Resource->Data.Vendor.ByteLength);
401bc36eafdSMike Gerdts break;
402bc36eafdSMike Gerdts
403bc36eafdSMike Gerdts
404bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_END_TAG:
405bc36eafdSMike Gerdts /*
406bc36eafdSMike Gerdts * End Tag:
407bc36eafdSMike Gerdts * We are done -- return the accumulated total size.
408bc36eafdSMike Gerdts */
409bc36eafdSMike Gerdts *SizeNeeded = AmlSizeNeeded + TotalSize;
410bc36eafdSMike Gerdts
411bc36eafdSMike Gerdts /* Normal exit */
412bc36eafdSMike Gerdts
413bc36eafdSMike Gerdts return_ACPI_STATUS (AE_OK);
414bc36eafdSMike Gerdts
415bc36eafdSMike Gerdts
416bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_ADDRESS16:
417bc36eafdSMike Gerdts /*
418bc36eafdSMike Gerdts * 16-Bit Address Resource:
419bc36eafdSMike Gerdts * Add the size of the optional ResourceSource info
420bc36eafdSMike Gerdts */
421bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH) (TotalSize +
422bc36eafdSMike Gerdts AcpiRsStructOptionLength (
423bc36eafdSMike Gerdts &Resource->Data.Address16.ResourceSource));
424bc36eafdSMike Gerdts break;
425bc36eafdSMike Gerdts
426bc36eafdSMike Gerdts
427bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_ADDRESS32:
428bc36eafdSMike Gerdts /*
429bc36eafdSMike Gerdts * 32-Bit Address Resource:
430bc36eafdSMike Gerdts * Add the size of the optional ResourceSource info
431bc36eafdSMike Gerdts */
432bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH) (TotalSize +
433bc36eafdSMike Gerdts AcpiRsStructOptionLength (
434bc36eafdSMike Gerdts &Resource->Data.Address32.ResourceSource));
435bc36eafdSMike Gerdts break;
436bc36eafdSMike Gerdts
437bc36eafdSMike Gerdts
438bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_ADDRESS64:
439bc36eafdSMike Gerdts /*
440bc36eafdSMike Gerdts * 64-Bit Address Resource:
441bc36eafdSMike Gerdts * Add the size of the optional ResourceSource info
442bc36eafdSMike Gerdts */
443bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH) (TotalSize +
444bc36eafdSMike Gerdts AcpiRsStructOptionLength (
445bc36eafdSMike Gerdts &Resource->Data.Address64.ResourceSource));
446bc36eafdSMike Gerdts break;
447bc36eafdSMike Gerdts
448bc36eafdSMike Gerdts
449bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
450bc36eafdSMike Gerdts /*
451bc36eafdSMike Gerdts * Extended IRQ Resource:
452bc36eafdSMike Gerdts * Add the size of each additional optional interrupt beyond the
453bc36eafdSMike Gerdts * required 1 (4 bytes for each UINT32 interrupt number)
454bc36eafdSMike Gerdts */
455bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH) (TotalSize +
456bc36eafdSMike Gerdts ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
457bc36eafdSMike Gerdts
458bc36eafdSMike Gerdts /* Add the size of the optional ResourceSource info */
459bc36eafdSMike Gerdts
460bc36eafdSMike Gerdts AcpiRsStructOptionLength (
461bc36eafdSMike Gerdts &Resource->Data.ExtendedIrq.ResourceSource));
462bc36eafdSMike Gerdts break;
463bc36eafdSMike Gerdts
464bc36eafdSMike Gerdts
465bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_GPIO:
466bc36eafdSMike Gerdts
467bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH) (TotalSize +
468bc36eafdSMike Gerdts (Resource->Data.Gpio.PinTableLength * 2) +
469bc36eafdSMike Gerdts Resource->Data.Gpio.ResourceSource.StringLength +
470bc36eafdSMike Gerdts Resource->Data.Gpio.VendorLength);
471bc36eafdSMike Gerdts
472bc36eafdSMike Gerdts break;
473bc36eafdSMike Gerdts
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
483bc36eafdSMike Gerdts
484bc36eafdSMike Gerdts case ACPI_RESOURCE_TYPE_SERIAL_BUS:
485bc36eafdSMike Gerdts
486bc36eafdSMike Gerdts TotalSize = AcpiGbl_AmlResourceSerialBusSizes [
487bc36eafdSMike Gerdts Resource->Data.CommonSerialBus.Type];
488bc36eafdSMike Gerdts
489bc36eafdSMike Gerdts TotalSize = (ACPI_RS_LENGTH) (TotalSize +
490bc36eafdSMike Gerdts Resource->Data.I2cSerialBus.ResourceSource.StringLength +
491bc36eafdSMike Gerdts Resource->Data.I2cSerialBus.VendorLength);
492bc36eafdSMike Gerdts
493bc36eafdSMike Gerdts break;
494bc36eafdSMike Gerdts
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
531bc36eafdSMike Gerdts default:
532bc36eafdSMike Gerdts
533bc36eafdSMike Gerdts break;
534bc36eafdSMike Gerdts }
535bc36eafdSMike Gerdts
536bc36eafdSMike Gerdts /* Update the total */
537bc36eafdSMike Gerdts
538bc36eafdSMike Gerdts AmlSizeNeeded += TotalSize;
539bc36eafdSMike Gerdts
540bc36eafdSMike Gerdts /* Point to the next object */
541bc36eafdSMike Gerdts
542bc36eafdSMike Gerdts Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
543bc36eafdSMike Gerdts }
544bc36eafdSMike Gerdts
545bc36eafdSMike Gerdts /* Did not find an EndTag resource descriptor */
546bc36eafdSMike Gerdts
547bc36eafdSMike Gerdts return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
548bc36eafdSMike Gerdts }
549bc36eafdSMike Gerdts
550bc36eafdSMike Gerdts
551bc36eafdSMike Gerdts /*******************************************************************************
552bc36eafdSMike Gerdts *
553bc36eafdSMike Gerdts * FUNCTION: AcpiRsGetListLength
554bc36eafdSMike Gerdts *
555bc36eafdSMike Gerdts * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
556bc36eafdSMike Gerdts * AmlBufferLength - Size of AmlBuffer
557bc36eafdSMike Gerdts * SizeNeeded - Where the size needed is returned
558bc36eafdSMike Gerdts *
559bc36eafdSMike Gerdts * RETURN: Status
560bc36eafdSMike Gerdts *
561bc36eafdSMike Gerdts * DESCRIPTION: Takes an external resource byte stream and calculates the size
562bc36eafdSMike Gerdts * buffer needed to hold the corresponding internal resource
563bc36eafdSMike Gerdts * descriptor linked list.
564bc36eafdSMike Gerdts *
565bc36eafdSMike Gerdts ******************************************************************************/
566bc36eafdSMike Gerdts
567bc36eafdSMike Gerdts ACPI_STATUS
AcpiRsGetListLength(UINT8 * AmlBuffer,UINT32 AmlBufferLength,ACPI_SIZE * SizeNeeded)568bc36eafdSMike Gerdts AcpiRsGetListLength (
569bc36eafdSMike Gerdts UINT8 *AmlBuffer,
570bc36eafdSMike Gerdts UINT32 AmlBufferLength,
571bc36eafdSMike Gerdts ACPI_SIZE *SizeNeeded)
572bc36eafdSMike Gerdts {
573bc36eafdSMike Gerdts ACPI_STATUS Status;
574bc36eafdSMike Gerdts UINT8 *EndAml;
575bc36eafdSMike Gerdts UINT8 *Buffer;
576bc36eafdSMike Gerdts UINT32 BufferSize;
577bc36eafdSMike Gerdts UINT16 Temp16;
578bc36eafdSMike Gerdts UINT16 ResourceLength;
579bc36eafdSMike Gerdts UINT32 ExtraStructBytes;
580bc36eafdSMike Gerdts UINT8 ResourceIndex;
581bc36eafdSMike Gerdts UINT8 MinimumAmlResourceLength;
582bc36eafdSMike Gerdts AML_RESOURCE *AmlResource;
583bc36eafdSMike Gerdts
584bc36eafdSMike Gerdts
585bc36eafdSMike Gerdts ACPI_FUNCTION_TRACE (RsGetListLength);
586bc36eafdSMike Gerdts
587bc36eafdSMike Gerdts
588bc36eafdSMike Gerdts *SizeNeeded = ACPI_RS_SIZE_MIN; /* Minimum size is one EndTag */
589bc36eafdSMike Gerdts EndAml = AmlBuffer + AmlBufferLength;
590bc36eafdSMike Gerdts
591bc36eafdSMike Gerdts /* Walk the list of AML resource descriptors */
592bc36eafdSMike Gerdts
593bc36eafdSMike Gerdts while (AmlBuffer < EndAml)
594bc36eafdSMike Gerdts {
595bc36eafdSMike Gerdts /* Validate the Resource Type and Resource Length */
596bc36eafdSMike Gerdts
597bc36eafdSMike Gerdts Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
598bc36eafdSMike Gerdts if (ACPI_FAILURE (Status))
599bc36eafdSMike Gerdts {
600bc36eafdSMike Gerdts /*
601bc36eafdSMike Gerdts * Exit on failure. Cannot continue because the descriptor length
602bc36eafdSMike Gerdts * may be bogus also.
603bc36eafdSMike Gerdts */
604bc36eafdSMike Gerdts return_ACPI_STATUS (Status);
605bc36eafdSMike Gerdts }
606bc36eafdSMike Gerdts
607bc36eafdSMike Gerdts AmlResource = (void *) AmlBuffer;
608bc36eafdSMike Gerdts
609bc36eafdSMike Gerdts /* Get the resource length and base (minimum) AML size */
610bc36eafdSMike Gerdts
611bc36eafdSMike Gerdts ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
612bc36eafdSMike Gerdts MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
613bc36eafdSMike Gerdts
614bc36eafdSMike Gerdts /*
615bc36eafdSMike Gerdts * Augment the size for descriptors with optional
616bc36eafdSMike Gerdts * and/or variable length fields
617bc36eafdSMike Gerdts */
618bc36eafdSMike Gerdts ExtraStructBytes = 0;
619bc36eafdSMike Gerdts Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
620bc36eafdSMike Gerdts
621bc36eafdSMike Gerdts switch (AcpiUtGetResourceType (AmlBuffer))
622bc36eafdSMike Gerdts {
623bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_IRQ:
624bc36eafdSMike Gerdts /*
625bc36eafdSMike Gerdts * IRQ Resource:
626bc36eafdSMike Gerdts * Get the number of bits set in the 16-bit IRQ mask
627bc36eafdSMike Gerdts */
628bc36eafdSMike Gerdts ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
629bc36eafdSMike Gerdts ExtraStructBytes = AcpiRsCountSetBits (Temp16);
630bc36eafdSMike Gerdts break;
631bc36eafdSMike Gerdts
632bc36eafdSMike Gerdts
633bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_DMA:
634bc36eafdSMike Gerdts /*
635bc36eafdSMike Gerdts * DMA Resource:
636bc36eafdSMike Gerdts * Get the number of bits set in the 8-bit DMA mask
637bc36eafdSMike Gerdts */
638bc36eafdSMike Gerdts ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
639bc36eafdSMike Gerdts break;
640bc36eafdSMike Gerdts
641bc36eafdSMike Gerdts
642bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_VENDOR_SMALL:
643bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_VENDOR_LARGE:
644bc36eafdSMike Gerdts /*
645bc36eafdSMike Gerdts * Vendor Resource:
646bc36eafdSMike Gerdts * Get the number of vendor data bytes
647bc36eafdSMike Gerdts */
648bc36eafdSMike Gerdts ExtraStructBytes = ResourceLength;
649bc36eafdSMike Gerdts
650bc36eafdSMike Gerdts /*
651bc36eafdSMike Gerdts * There is already one byte included in the minimum
652bc36eafdSMike Gerdts * descriptor size. If there are extra struct bytes,
653bc36eafdSMike Gerdts * subtract one from the count.
654bc36eafdSMike Gerdts */
655bc36eafdSMike Gerdts if (ExtraStructBytes)
656bc36eafdSMike Gerdts {
657bc36eafdSMike Gerdts ExtraStructBytes--;
658bc36eafdSMike Gerdts }
659bc36eafdSMike Gerdts break;
660bc36eafdSMike Gerdts
661bc36eafdSMike Gerdts
662bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_END_TAG:
663bc36eafdSMike Gerdts /*
664bc36eafdSMike Gerdts * End Tag: This is the normal exit
665bc36eafdSMike Gerdts */
666bc36eafdSMike Gerdts return_ACPI_STATUS (AE_OK);
667bc36eafdSMike Gerdts
668bc36eafdSMike Gerdts
669bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_ADDRESS32:
670bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_ADDRESS16:
671bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_ADDRESS64:
672bc36eafdSMike Gerdts /*
673bc36eafdSMike Gerdts * Address Resource:
674bc36eafdSMike Gerdts * Add the size of the optional ResourceSource
675bc36eafdSMike Gerdts */
676bc36eafdSMike Gerdts ExtraStructBytes = AcpiRsStreamOptionLength (
677bc36eafdSMike Gerdts ResourceLength, MinimumAmlResourceLength);
678bc36eafdSMike Gerdts break;
679bc36eafdSMike Gerdts
680bc36eafdSMike Gerdts
681bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
682bc36eafdSMike Gerdts /*
683bc36eafdSMike Gerdts * Extended IRQ Resource:
684bc36eafdSMike Gerdts * Using the InterruptTableLength, add 4 bytes for each additional
685bc36eafdSMike Gerdts * interrupt. Note: at least one interrupt is required and is
686bc36eafdSMike Gerdts * included in the minimum descriptor size (reason for the -1)
687bc36eafdSMike Gerdts */
688bc36eafdSMike Gerdts ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
689bc36eafdSMike Gerdts
690bc36eafdSMike Gerdts /* Add the size of the optional ResourceSource */
691bc36eafdSMike Gerdts
692bc36eafdSMike Gerdts ExtraStructBytes += AcpiRsStreamOptionLength (
693bc36eafdSMike Gerdts ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
694bc36eafdSMike Gerdts break;
695bc36eafdSMike Gerdts
696bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_GPIO:
697bc36eafdSMike Gerdts
698bc36eafdSMike Gerdts /* Vendor data is optional */
699bc36eafdSMike Gerdts
700bc36eafdSMike Gerdts if (AmlResource->Gpio.VendorLength)
701bc36eafdSMike Gerdts {
702bc36eafdSMike Gerdts ExtraStructBytes +=
703bc36eafdSMike Gerdts AmlResource->Gpio.VendorOffset -
704bc36eafdSMike Gerdts AmlResource->Gpio.PinTableOffset +
705bc36eafdSMike Gerdts AmlResource->Gpio.VendorLength;
706bc36eafdSMike Gerdts }
707bc36eafdSMike Gerdts else
708bc36eafdSMike Gerdts {
709bc36eafdSMike Gerdts ExtraStructBytes +=
710bc36eafdSMike Gerdts AmlResource->LargeHeader.ResourceLength +
711bc36eafdSMike Gerdts sizeof (AML_RESOURCE_LARGE_HEADER) -
712bc36eafdSMike Gerdts AmlResource->Gpio.PinTableOffset;
713bc36eafdSMike Gerdts }
714bc36eafdSMike Gerdts break;
715bc36eafdSMike Gerdts
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
736bc36eafdSMike Gerdts case ACPI_RESOURCE_NAME_SERIAL_BUS:
737bc36eafdSMike Gerdts
738bc36eafdSMike Gerdts MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
739bc36eafdSMike Gerdts AmlResource->CommonSerialBus.Type];
740bc36eafdSMike Gerdts ExtraStructBytes +=
741bc36eafdSMike Gerdts AmlResource->CommonSerialBus.ResourceLength -
742bc36eafdSMike Gerdts MinimumAmlResourceLength;
743bc36eafdSMike Gerdts break;
744bc36eafdSMike Gerdts
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
792bc36eafdSMike Gerdts default:
793bc36eafdSMike Gerdts
794bc36eafdSMike Gerdts break;
795bc36eafdSMike Gerdts }
796bc36eafdSMike Gerdts
797bc36eafdSMike Gerdts /*
798bc36eafdSMike Gerdts * Update the required buffer size for the internal descriptor structs
799bc36eafdSMike Gerdts *
800bc36eafdSMike Gerdts * Important: Round the size up for the appropriate alignment. This
801bc36eafdSMike Gerdts * is a requirement on IA64.
802bc36eafdSMike Gerdts */
803bc36eafdSMike Gerdts if (AcpiUtGetResourceType (AmlBuffer) ==
804bc36eafdSMike Gerdts ACPI_RESOURCE_NAME_SERIAL_BUS)
805bc36eafdSMike Gerdts {
806bc36eafdSMike Gerdts BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
807bc36eafdSMike Gerdts AmlResource->CommonSerialBus.Type] + ExtraStructBytes;
808bc36eafdSMike Gerdts }
809bc36eafdSMike Gerdts else
810bc36eafdSMike Gerdts {
811bc36eafdSMike Gerdts BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
812bc36eafdSMike Gerdts ExtraStructBytes;
813bc36eafdSMike Gerdts }
814bc36eafdSMike Gerdts
815bc36eafdSMike Gerdts BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
816bc36eafdSMike Gerdts *SizeNeeded += BufferSize;
817bc36eafdSMike Gerdts
818bc36eafdSMike Gerdts ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
819bc36eafdSMike Gerdts "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
820bc36eafdSMike Gerdts AcpiUtGetResourceType (AmlBuffer),
821bc36eafdSMike Gerdts AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
822bc36eafdSMike Gerdts
823bc36eafdSMike Gerdts /*
824bc36eafdSMike Gerdts * Point to the next resource within the AML stream using the length
825bc36eafdSMike Gerdts * contained in the resource descriptor header
826bc36eafdSMike Gerdts */
827bc36eafdSMike Gerdts AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
828bc36eafdSMike Gerdts }
829bc36eafdSMike Gerdts
830bc36eafdSMike Gerdts /* Did not find an EndTag resource descriptor */
831bc36eafdSMike Gerdts
832bc36eafdSMike Gerdts return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
833bc36eafdSMike Gerdts }
834bc36eafdSMike Gerdts
835bc36eafdSMike Gerdts
836bc36eafdSMike Gerdts /*******************************************************************************
837bc36eafdSMike Gerdts *
838bc36eafdSMike Gerdts * FUNCTION: AcpiRsGetPciRoutingTableLength
839bc36eafdSMike Gerdts *
840bc36eafdSMike Gerdts * PARAMETERS: PackageObject - Pointer to the package object
841bc36eafdSMike Gerdts * BufferSizeNeeded - UINT32 pointer of the size buffer
842bc36eafdSMike Gerdts * needed to properly return the
843bc36eafdSMike Gerdts * parsed data
844bc36eafdSMike Gerdts *
845bc36eafdSMike Gerdts * RETURN: Status
846bc36eafdSMike Gerdts *
847bc36eafdSMike Gerdts * DESCRIPTION: Given a package representing a PCI routing table, this
848bc36eafdSMike Gerdts * calculates the size of the corresponding linked list of
849bc36eafdSMike Gerdts * descriptions.
850bc36eafdSMike Gerdts *
851bc36eafdSMike Gerdts ******************************************************************************/
852bc36eafdSMike Gerdts
853bc36eafdSMike Gerdts ACPI_STATUS
AcpiRsGetPciRoutingTableLength(ACPI_OPERAND_OBJECT * PackageObject,ACPI_SIZE * BufferSizeNeeded)854bc36eafdSMike Gerdts AcpiRsGetPciRoutingTableLength (
855bc36eafdSMike Gerdts ACPI_OPERAND_OBJECT *PackageObject,
856bc36eafdSMike Gerdts ACPI_SIZE *BufferSizeNeeded)
857bc36eafdSMike Gerdts {
858bc36eafdSMike Gerdts UINT32 NumberOfElements;
859bc36eafdSMike Gerdts ACPI_SIZE TempSizeNeeded = 0;
860bc36eafdSMike Gerdts ACPI_OPERAND_OBJECT **TopObjectList;
861bc36eafdSMike Gerdts UINT32 Index;
862bc36eafdSMike Gerdts ACPI_OPERAND_OBJECT *PackageElement;
863bc36eafdSMike Gerdts ACPI_OPERAND_OBJECT **SubObjectList;
864bc36eafdSMike Gerdts BOOLEAN NameFound;
865bc36eafdSMike Gerdts UINT32 TableIndex;
866bc36eafdSMike Gerdts
867bc36eafdSMike Gerdts
868bc36eafdSMike Gerdts ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
869bc36eafdSMike Gerdts
870bc36eafdSMike Gerdts
871bc36eafdSMike Gerdts NumberOfElements = PackageObject->Package.Count;
872bc36eafdSMike Gerdts
873bc36eafdSMike Gerdts /*
874bc36eafdSMike Gerdts * Calculate the size of the return buffer.
875bc36eafdSMike Gerdts * The base size is the number of elements * the sizes of the
876bc36eafdSMike Gerdts * structures. Additional space for the strings is added below.
877bc36eafdSMike Gerdts * The minus one is to subtract the size of the UINT8 Source[1]
878bc36eafdSMike Gerdts * member because it is added below.
879bc36eafdSMike Gerdts *
880bc36eafdSMike Gerdts * But each PRT_ENTRY structure has a pointer to a string and
881bc36eafdSMike Gerdts * the size of that string must be found.
882bc36eafdSMike Gerdts */
883bc36eafdSMike Gerdts TopObjectList = PackageObject->Package.Elements;
884bc36eafdSMike Gerdts
885bc36eafdSMike Gerdts for (Index = 0; Index < NumberOfElements; Index++)
886bc36eafdSMike Gerdts {
887bc36eafdSMike Gerdts /* Dereference the subpackage */
888bc36eafdSMike Gerdts
889bc36eafdSMike Gerdts PackageElement = *TopObjectList;
890bc36eafdSMike Gerdts
891bc36eafdSMike Gerdts /* We must have a valid Package object */
892bc36eafdSMike Gerdts
893bc36eafdSMike Gerdts if (!PackageElement ||
894bc36eafdSMike Gerdts (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
895bc36eafdSMike Gerdts {
896bc36eafdSMike Gerdts return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
897bc36eafdSMike Gerdts }
898bc36eafdSMike Gerdts
899bc36eafdSMike Gerdts /*
900bc36eafdSMike Gerdts * The SubObjectList will now point to an array of the
901bc36eafdSMike Gerdts * four IRQ elements: Address, Pin, Source and SourceIndex
902bc36eafdSMike Gerdts */
903bc36eafdSMike Gerdts SubObjectList = PackageElement->Package.Elements;
904bc36eafdSMike Gerdts
905bc36eafdSMike Gerdts /* Scan the IrqTableElements for the Source Name String */
906bc36eafdSMike Gerdts
907bc36eafdSMike Gerdts NameFound = FALSE;
908bc36eafdSMike Gerdts
909bc36eafdSMike Gerdts for (TableIndex = 0;
910bc36eafdSMike Gerdts TableIndex < PackageElement->Package.Count && !NameFound;
911bc36eafdSMike Gerdts TableIndex++)
912bc36eafdSMike Gerdts {
913bc36eafdSMike Gerdts if (*SubObjectList && /* Null object allowed */
914bc36eafdSMike Gerdts
915bc36eafdSMike Gerdts ((ACPI_TYPE_STRING ==
916bc36eafdSMike Gerdts (*SubObjectList)->Common.Type) ||
917bc36eafdSMike Gerdts
918bc36eafdSMike Gerdts ((ACPI_TYPE_LOCAL_REFERENCE ==
919bc36eafdSMike Gerdts (*SubObjectList)->Common.Type) &&
920bc36eafdSMike Gerdts
921bc36eafdSMike Gerdts ((*SubObjectList)->Reference.Class ==
922bc36eafdSMike Gerdts ACPI_REFCLASS_NAME))))
923bc36eafdSMike Gerdts {
924bc36eafdSMike Gerdts NameFound = TRUE;
925bc36eafdSMike Gerdts }
926bc36eafdSMike Gerdts else
927bc36eafdSMike Gerdts {
928bc36eafdSMike Gerdts /* Look at the next element */
929bc36eafdSMike Gerdts
930bc36eafdSMike Gerdts SubObjectList++;
931bc36eafdSMike Gerdts }
932bc36eafdSMike Gerdts }
933bc36eafdSMike Gerdts
934bc36eafdSMike Gerdts TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
935bc36eafdSMike Gerdts
936bc36eafdSMike Gerdts /* Was a String type found? */
937bc36eafdSMike Gerdts
938bc36eafdSMike Gerdts if (NameFound)
939bc36eafdSMike Gerdts {
940bc36eafdSMike Gerdts if ((*SubObjectList)->Common.Type == ACPI_TYPE_STRING)
941bc36eafdSMike Gerdts {
942bc36eafdSMike Gerdts /*
943bc36eafdSMike Gerdts * The length String.Length field does not include the
944bc36eafdSMike Gerdts * terminating NULL, add 1
945bc36eafdSMike Gerdts */
946bc36eafdSMike Gerdts TempSizeNeeded += ((ACPI_SIZE)
947bc36eafdSMike Gerdts (*SubObjectList)->String.Length + 1);
948bc36eafdSMike Gerdts }
949bc36eafdSMike Gerdts else
950bc36eafdSMike Gerdts {
951bc36eafdSMike Gerdts TempSizeNeeded += AcpiNsGetPathnameLength (
952bc36eafdSMike Gerdts (*SubObjectList)->Reference.Node);
953bc36eafdSMike Gerdts }
954bc36eafdSMike Gerdts }
955bc36eafdSMike Gerdts else
956bc36eafdSMike Gerdts {
957bc36eafdSMike Gerdts /*
958bc36eafdSMike Gerdts * If no name was found, then this is a NULL, which is
959bc36eafdSMike Gerdts * translated as a UINT32 zero.
960bc36eafdSMike Gerdts */
961bc36eafdSMike Gerdts TempSizeNeeded += sizeof (UINT32);
962bc36eafdSMike Gerdts }
963bc36eafdSMike Gerdts
964bc36eafdSMike Gerdts /* Round up the size since each element must be aligned */
965bc36eafdSMike Gerdts
966bc36eafdSMike Gerdts TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded);
967bc36eafdSMike Gerdts
968bc36eafdSMike Gerdts /* Point to the next ACPI_OPERAND_OBJECT */
969bc36eafdSMike Gerdts
970bc36eafdSMike Gerdts TopObjectList++;
971bc36eafdSMike Gerdts }
972bc36eafdSMike Gerdts
973bc36eafdSMike Gerdts /*
974bc36eafdSMike Gerdts * Add an extra element to the end of the list, essentially a
975bc36eafdSMike Gerdts * NULL terminator
976bc36eafdSMike Gerdts */
977bc36eafdSMike Gerdts *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
978bc36eafdSMike Gerdts return_ACPI_STATUS (AE_OK);
979bc36eafdSMike Gerdts }
980