rscalc.c revision 1.1 1 1.1 jruoho /*******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: rscalc - Calculate stream and list lengths
4 1.1 jruoho *
5 1.1 jruoho ******************************************************************************/
6 1.1 jruoho
7 1.1 jruoho /******************************************************************************
8 1.1 jruoho *
9 1.1 jruoho * 1. Copyright Notice
10 1.1 jruoho *
11 1.1 jruoho * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 1.1 jruoho * All rights reserved.
13 1.1 jruoho *
14 1.1 jruoho * 2. License
15 1.1 jruoho *
16 1.1 jruoho * 2.1. This is your license from Intel Corp. under its intellectual property
17 1.1 jruoho * rights. You may have additional license terms from the party that provided
18 1.1 jruoho * you this software, covering your right to use that party's intellectual
19 1.1 jruoho * property rights.
20 1.1 jruoho *
21 1.1 jruoho * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 1.1 jruoho * copy of the source code appearing in this file ("Covered Code") an
23 1.1 jruoho * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 1.1 jruoho * base code distributed originally by Intel ("Original Intel Code") to copy,
25 1.1 jruoho * make derivatives, distribute, use and display any portion of the Covered
26 1.1 jruoho * Code in any form, with the right to sublicense such rights; and
27 1.1 jruoho *
28 1.1 jruoho * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 1.1 jruoho * license (with the right to sublicense), under only those claims of Intel
30 1.1 jruoho * patents that are infringed by the Original Intel Code, to make, use, sell,
31 1.1 jruoho * offer to sell, and import the Covered Code and derivative works thereof
32 1.1 jruoho * solely to the minimum extent necessary to exercise the above copyright
33 1.1 jruoho * license, and in no event shall the patent license extend to any additions
34 1.1 jruoho * to or modifications of the Original Intel Code. No other license or right
35 1.1 jruoho * is granted directly or by implication, estoppel or otherwise;
36 1.1 jruoho *
37 1.1 jruoho * The above copyright and patent license is granted only if the following
38 1.1 jruoho * conditions are met:
39 1.1 jruoho *
40 1.1 jruoho * 3. Conditions
41 1.1 jruoho *
42 1.1 jruoho * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
44 1.1 jruoho * Code or modification with rights to further distribute source must include
45 1.1 jruoho * the above Copyright Notice, the above License, this list of Conditions,
46 1.1 jruoho * and the following Disclaimer and Export Compliance provision. In addition,
47 1.1 jruoho * Licensee must cause all Covered Code to which Licensee contributes to
48 1.1 jruoho * contain a file documenting the changes Licensee made to create that Covered
49 1.1 jruoho * Code and the date of any change. Licensee must include in that file the
50 1.1 jruoho * documentation of any changes made by any predecessor Licensee. Licensee
51 1.1 jruoho * must include a prominent statement that the modification is derived,
52 1.1 jruoho * directly or indirectly, from Original Intel Code.
53 1.1 jruoho *
54 1.1 jruoho * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 1.1 jruoho * Redistribution of source code of any substantial portion of the Covered
56 1.1 jruoho * Code or modification without rights to further distribute source must
57 1.1 jruoho * include the following Disclaimer and Export Compliance provision in the
58 1.1 jruoho * documentation and/or other materials provided with distribution. In
59 1.1 jruoho * addition, Licensee may not authorize further sublicense of source of any
60 1.1 jruoho * portion of the Covered Code, and must include terms to the effect that the
61 1.1 jruoho * license from Licensee to its licensee is limited to the intellectual
62 1.1 jruoho * property embodied in the software Licensee provides to its licensee, and
63 1.1 jruoho * not to intellectual property embodied in modifications its licensee may
64 1.1 jruoho * make.
65 1.1 jruoho *
66 1.1 jruoho * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 1.1 jruoho * substantial portion of the Covered Code or modification must reproduce the
68 1.1 jruoho * above Copyright Notice, and the following Disclaimer and Export Compliance
69 1.1 jruoho * provision in the documentation and/or other materials provided with the
70 1.1 jruoho * distribution.
71 1.1 jruoho *
72 1.1 jruoho * 3.4. Intel retains all right, title, and interest in and to the Original
73 1.1 jruoho * Intel Code.
74 1.1 jruoho *
75 1.1 jruoho * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 1.1 jruoho * Intel shall be used in advertising or otherwise to promote the sale, use or
77 1.1 jruoho * other dealings in products derived from or relating to the Covered Code
78 1.1 jruoho * without prior written authorization from Intel.
79 1.1 jruoho *
80 1.1 jruoho * 4. Disclaimer and Export Compliance
81 1.1 jruoho *
82 1.1 jruoho * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 1.1 jruoho * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 1.1 jruoho * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 1.1 jruoho * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 1.1 jruoho * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 1.1 jruoho * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 1.1 jruoho * PARTICULAR PURPOSE.
89 1.1 jruoho *
90 1.1 jruoho * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 1.1 jruoho * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 1.1 jruoho * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 1.1 jruoho * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 1.1 jruoho * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 1.1 jruoho * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 1.1 jruoho * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 1.1 jruoho * LIMITED REMEDY.
98 1.1 jruoho *
99 1.1 jruoho * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 1.1 jruoho * software or system incorporating such software without first obtaining any
101 1.1 jruoho * required license or other approval from the U. S. Department of Commerce or
102 1.1 jruoho * any other agency or department of the United States Government. In the
103 1.1 jruoho * event Licensee exports any such software from the United States or
104 1.1 jruoho * re-exports any such software from a foreign destination, Licensee shall
105 1.1 jruoho * ensure that the distribution and export/re-export of the software is in
106 1.1 jruoho * compliance with all laws, regulations, orders, or other restrictions of the
107 1.1 jruoho * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 1.1 jruoho * any of its subsidiaries will export/re-export any technical data, process,
109 1.1 jruoho * software, or service, directly or indirectly, to any country for which the
110 1.1 jruoho * United States government or any agency thereof requires an export license,
111 1.1 jruoho * other governmental approval, or letter of assurance, without first obtaining
112 1.1 jruoho * such license, approval or letter.
113 1.1 jruoho *
114 1.1 jruoho *****************************************************************************/
115 1.1 jruoho
116 1.1 jruoho #define __RSCALC_C__
117 1.1 jruoho
118 1.1 jruoho #include "acpi.h"
119 1.1 jruoho #include "accommon.h"
120 1.1 jruoho #include "acresrc.h"
121 1.1 jruoho #include "acnamesp.h"
122 1.1 jruoho
123 1.1 jruoho
124 1.1 jruoho #define _COMPONENT ACPI_RESOURCES
125 1.1 jruoho ACPI_MODULE_NAME ("rscalc")
126 1.1 jruoho
127 1.1 jruoho
128 1.1 jruoho /* Local prototypes */
129 1.1 jruoho
130 1.1 jruoho static UINT8
131 1.1 jruoho AcpiRsCountSetBits (
132 1.1 jruoho UINT16 BitField);
133 1.1 jruoho
134 1.1 jruoho static ACPI_RS_LENGTH
135 1.1 jruoho AcpiRsStructOptionLength (
136 1.1 jruoho ACPI_RESOURCE_SOURCE *ResourceSource);
137 1.1 jruoho
138 1.1 jruoho static UINT32
139 1.1 jruoho AcpiRsStreamOptionLength (
140 1.1 jruoho UINT32 ResourceLength,
141 1.1 jruoho UINT32 MinimumTotalLength);
142 1.1 jruoho
143 1.1 jruoho
144 1.1 jruoho /*******************************************************************************
145 1.1 jruoho *
146 1.1 jruoho * FUNCTION: AcpiRsCountSetBits
147 1.1 jruoho *
148 1.1 jruoho * PARAMETERS: BitField - Field in which to count bits
149 1.1 jruoho *
150 1.1 jruoho * RETURN: Number of bits set within the field
151 1.1 jruoho *
152 1.1 jruoho * DESCRIPTION: Count the number of bits set in a resource field. Used for
153 1.1 jruoho * (Short descriptor) interrupt and DMA lists.
154 1.1 jruoho *
155 1.1 jruoho ******************************************************************************/
156 1.1 jruoho
157 1.1 jruoho static UINT8
158 1.1 jruoho AcpiRsCountSetBits (
159 1.1 jruoho UINT16 BitField)
160 1.1 jruoho {
161 1.1 jruoho UINT8 BitsSet;
162 1.1 jruoho
163 1.1 jruoho
164 1.1 jruoho ACPI_FUNCTION_ENTRY ();
165 1.1 jruoho
166 1.1 jruoho
167 1.1 jruoho for (BitsSet = 0; BitField; BitsSet++)
168 1.1 jruoho {
169 1.1 jruoho /* Zero the least significant bit that is set */
170 1.1 jruoho
171 1.1 jruoho BitField &= (UINT16) (BitField - 1);
172 1.1 jruoho }
173 1.1 jruoho
174 1.1 jruoho return (BitsSet);
175 1.1 jruoho }
176 1.1 jruoho
177 1.1 jruoho
178 1.1 jruoho /*******************************************************************************
179 1.1 jruoho *
180 1.1 jruoho * FUNCTION: AcpiRsStructOptionLength
181 1.1 jruoho *
182 1.1 jruoho * PARAMETERS: ResourceSource - Pointer to optional descriptor field
183 1.1 jruoho *
184 1.1 jruoho * RETURN: Status
185 1.1 jruoho *
186 1.1 jruoho * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
187 1.1 jruoho * ResourceSource fields in some Large descriptors. Used during
188 1.1 jruoho * list-to-stream conversion
189 1.1 jruoho *
190 1.1 jruoho ******************************************************************************/
191 1.1 jruoho
192 1.1 jruoho static ACPI_RS_LENGTH
193 1.1 jruoho AcpiRsStructOptionLength (
194 1.1 jruoho ACPI_RESOURCE_SOURCE *ResourceSource)
195 1.1 jruoho {
196 1.1 jruoho ACPI_FUNCTION_ENTRY ();
197 1.1 jruoho
198 1.1 jruoho
199 1.1 jruoho /*
200 1.1 jruoho * If the ResourceSource string is valid, return the size of the string
201 1.1 jruoho * (StringLength includes the NULL terminator) plus the size of the
202 1.1 jruoho * ResourceSourceIndex (1).
203 1.1 jruoho */
204 1.1 jruoho if (ResourceSource->StringPtr)
205 1.1 jruoho {
206 1.1 jruoho return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1));
207 1.1 jruoho }
208 1.1 jruoho
209 1.1 jruoho return (0);
210 1.1 jruoho }
211 1.1 jruoho
212 1.1 jruoho
213 1.1 jruoho /*******************************************************************************
214 1.1 jruoho *
215 1.1 jruoho * FUNCTION: AcpiRsStreamOptionLength
216 1.1 jruoho *
217 1.1 jruoho * PARAMETERS: ResourceLength - Length from the resource header
218 1.1 jruoho * MinimumTotalLength - Minimum length of this resource, before
219 1.1 jruoho * any optional fields. Includes header size
220 1.1 jruoho *
221 1.1 jruoho * RETURN: Length of optional string (0 if no string present)
222 1.1 jruoho *
223 1.1 jruoho * DESCRIPTION: Common code to handle optional ResourceSourceIndex and
224 1.1 jruoho * ResourceSource fields in some Large descriptors. Used during
225 1.1 jruoho * stream-to-list conversion
226 1.1 jruoho *
227 1.1 jruoho ******************************************************************************/
228 1.1 jruoho
229 1.1 jruoho static UINT32
230 1.1 jruoho AcpiRsStreamOptionLength (
231 1.1 jruoho UINT32 ResourceLength,
232 1.1 jruoho UINT32 MinimumAmlResourceLength)
233 1.1 jruoho {
234 1.1 jruoho UINT32 StringLength = 0;
235 1.1 jruoho
236 1.1 jruoho
237 1.1 jruoho ACPI_FUNCTION_ENTRY ();
238 1.1 jruoho
239 1.1 jruoho
240 1.1 jruoho /*
241 1.1 jruoho * The ResourceSourceIndex and ResourceSource are optional elements of some
242 1.1 jruoho * Large-type resource descriptors.
243 1.1 jruoho */
244 1.1 jruoho
245 1.1 jruoho /*
246 1.1 jruoho * If the length of the actual resource descriptor is greater than the ACPI
247 1.1 jruoho * spec-defined minimum length, it means that a ResourceSourceIndex exists
248 1.1 jruoho * and is followed by a (required) null terminated string. The string length
249 1.1 jruoho * (including the null terminator) is the resource length minus the minimum
250 1.1 jruoho * length, minus one byte for the ResourceSourceIndex itself.
251 1.1 jruoho */
252 1.1 jruoho if (ResourceLength > MinimumAmlResourceLength)
253 1.1 jruoho {
254 1.1 jruoho /* Compute the length of the optional string */
255 1.1 jruoho
256 1.1 jruoho StringLength = ResourceLength - MinimumAmlResourceLength - 1;
257 1.1 jruoho }
258 1.1 jruoho
259 1.1 jruoho /*
260 1.1 jruoho * Round the length up to a multiple of the native word in order to
261 1.1 jruoho * guarantee that the entire resource descriptor is native word aligned
262 1.1 jruoho */
263 1.1 jruoho return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
264 1.1 jruoho }
265 1.1 jruoho
266 1.1 jruoho
267 1.1 jruoho /*******************************************************************************
268 1.1 jruoho *
269 1.1 jruoho * FUNCTION: AcpiRsGetAmlLength
270 1.1 jruoho *
271 1.1 jruoho * PARAMETERS: Resource - Pointer to the resource linked list
272 1.1 jruoho * SizeNeeded - Where the required size is returned
273 1.1 jruoho *
274 1.1 jruoho * RETURN: Status
275 1.1 jruoho *
276 1.1 jruoho * DESCRIPTION: Takes a linked list of internal resource descriptors and
277 1.1 jruoho * calculates the size buffer needed to hold the corresponding
278 1.1 jruoho * external resource byte stream.
279 1.1 jruoho *
280 1.1 jruoho ******************************************************************************/
281 1.1 jruoho
282 1.1 jruoho ACPI_STATUS
283 1.1 jruoho AcpiRsGetAmlLength (
284 1.1 jruoho ACPI_RESOURCE *Resource,
285 1.1 jruoho ACPI_SIZE *SizeNeeded)
286 1.1 jruoho {
287 1.1 jruoho ACPI_SIZE AmlSizeNeeded = 0;
288 1.1 jruoho ACPI_RS_LENGTH TotalSize;
289 1.1 jruoho
290 1.1 jruoho
291 1.1 jruoho ACPI_FUNCTION_TRACE (RsGetAmlLength);
292 1.1 jruoho
293 1.1 jruoho
294 1.1 jruoho /* Traverse entire list of internal resource descriptors */
295 1.1 jruoho
296 1.1 jruoho while (Resource)
297 1.1 jruoho {
298 1.1 jruoho /* Validate the descriptor type */
299 1.1 jruoho
300 1.1 jruoho if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
301 1.1 jruoho {
302 1.1 jruoho return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
303 1.1 jruoho }
304 1.1 jruoho
305 1.1 jruoho /* Get the base size of the (external stream) resource descriptor */
306 1.1 jruoho
307 1.1 jruoho TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
308 1.1 jruoho
309 1.1 jruoho /*
310 1.1 jruoho * Augment the base size for descriptors with optional and/or
311 1.1 jruoho * variable-length fields
312 1.1 jruoho */
313 1.1 jruoho switch (Resource->Type)
314 1.1 jruoho {
315 1.1 jruoho case ACPI_RESOURCE_TYPE_IRQ:
316 1.1 jruoho
317 1.1 jruoho /* Length can be 3 or 2 */
318 1.1 jruoho
319 1.1 jruoho if (Resource->Data.Irq.DescriptorLength == 2)
320 1.1 jruoho {
321 1.1 jruoho TotalSize--;
322 1.1 jruoho }
323 1.1 jruoho break;
324 1.1 jruoho
325 1.1 jruoho
326 1.1 jruoho case ACPI_RESOURCE_TYPE_START_DEPENDENT:
327 1.1 jruoho
328 1.1 jruoho /* Length can be 1 or 0 */
329 1.1 jruoho
330 1.1 jruoho if (Resource->Data.Irq.DescriptorLength == 0)
331 1.1 jruoho {
332 1.1 jruoho TotalSize--;
333 1.1 jruoho }
334 1.1 jruoho break;
335 1.1 jruoho
336 1.1 jruoho
337 1.1 jruoho case ACPI_RESOURCE_TYPE_VENDOR:
338 1.1 jruoho /*
339 1.1 jruoho * Vendor Defined Resource:
340 1.1 jruoho * For a Vendor Specific resource, if the Length is between 1 and 7
341 1.1 jruoho * it will be created as a Small Resource data type, otherwise it
342 1.1 jruoho * is a Large Resource data type.
343 1.1 jruoho */
344 1.1 jruoho if (Resource->Data.Vendor.ByteLength > 7)
345 1.1 jruoho {
346 1.1 jruoho /* Base size of a Large resource descriptor */
347 1.1 jruoho
348 1.1 jruoho TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
349 1.1 jruoho }
350 1.1 jruoho
351 1.1 jruoho /* Add the size of the vendor-specific data */
352 1.1 jruoho
353 1.1 jruoho TotalSize = (ACPI_RS_LENGTH)
354 1.1 jruoho (TotalSize + Resource->Data.Vendor.ByteLength);
355 1.1 jruoho break;
356 1.1 jruoho
357 1.1 jruoho
358 1.1 jruoho case ACPI_RESOURCE_TYPE_END_TAG:
359 1.1 jruoho /*
360 1.1 jruoho * End Tag:
361 1.1 jruoho * We are done -- return the accumulated total size.
362 1.1 jruoho */
363 1.1 jruoho *SizeNeeded = AmlSizeNeeded + TotalSize;
364 1.1 jruoho
365 1.1 jruoho /* Normal exit */
366 1.1 jruoho
367 1.1 jruoho return_ACPI_STATUS (AE_OK);
368 1.1 jruoho
369 1.1 jruoho
370 1.1 jruoho case ACPI_RESOURCE_TYPE_ADDRESS16:
371 1.1 jruoho /*
372 1.1 jruoho * 16-Bit Address Resource:
373 1.1 jruoho * Add the size of the optional ResourceSource info
374 1.1 jruoho */
375 1.1 jruoho TotalSize = (ACPI_RS_LENGTH)
376 1.1 jruoho (TotalSize + AcpiRsStructOptionLength (
377 1.1 jruoho &Resource->Data.Address16.ResourceSource));
378 1.1 jruoho break;
379 1.1 jruoho
380 1.1 jruoho
381 1.1 jruoho case ACPI_RESOURCE_TYPE_ADDRESS32:
382 1.1 jruoho /*
383 1.1 jruoho * 32-Bit Address Resource:
384 1.1 jruoho * Add the size of the optional ResourceSource info
385 1.1 jruoho */
386 1.1 jruoho TotalSize = (ACPI_RS_LENGTH)
387 1.1 jruoho (TotalSize + AcpiRsStructOptionLength (
388 1.1 jruoho &Resource->Data.Address32.ResourceSource));
389 1.1 jruoho break;
390 1.1 jruoho
391 1.1 jruoho
392 1.1 jruoho case ACPI_RESOURCE_TYPE_ADDRESS64:
393 1.1 jruoho /*
394 1.1 jruoho * 64-Bit Address Resource:
395 1.1 jruoho * Add the size of the optional ResourceSource info
396 1.1 jruoho */
397 1.1 jruoho TotalSize = (ACPI_RS_LENGTH)
398 1.1 jruoho (TotalSize + AcpiRsStructOptionLength (
399 1.1 jruoho &Resource->Data.Address64.ResourceSource));
400 1.1 jruoho break;
401 1.1 jruoho
402 1.1 jruoho
403 1.1 jruoho case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
404 1.1 jruoho /*
405 1.1 jruoho * Extended IRQ Resource:
406 1.1 jruoho * Add the size of each additional optional interrupt beyond the
407 1.1 jruoho * required 1 (4 bytes for each UINT32 interrupt number)
408 1.1 jruoho */
409 1.1 jruoho TotalSize = (ACPI_RS_LENGTH)
410 1.1 jruoho (TotalSize +
411 1.1 jruoho ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
412 1.1 jruoho
413 1.1 jruoho /* Add the size of the optional ResourceSource info */
414 1.1 jruoho
415 1.1 jruoho AcpiRsStructOptionLength (
416 1.1 jruoho &Resource->Data.ExtendedIrq.ResourceSource));
417 1.1 jruoho break;
418 1.1 jruoho
419 1.1 jruoho
420 1.1 jruoho default:
421 1.1 jruoho break;
422 1.1 jruoho }
423 1.1 jruoho
424 1.1 jruoho /* Update the total */
425 1.1 jruoho
426 1.1 jruoho AmlSizeNeeded += TotalSize;
427 1.1 jruoho
428 1.1 jruoho /* Point to the next object */
429 1.1 jruoho
430 1.1 jruoho Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
431 1.1 jruoho }
432 1.1 jruoho
433 1.1 jruoho /* Did not find an EndTag resource descriptor */
434 1.1 jruoho
435 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
436 1.1 jruoho }
437 1.1 jruoho
438 1.1 jruoho
439 1.1 jruoho /*******************************************************************************
440 1.1 jruoho *
441 1.1 jruoho * FUNCTION: AcpiRsGetListLength
442 1.1 jruoho *
443 1.1 jruoho * PARAMETERS: AmlBuffer - Pointer to the resource byte stream
444 1.1 jruoho * AmlBufferLength - Size of AmlBuffer
445 1.1 jruoho * SizeNeeded - Where the size needed is returned
446 1.1 jruoho *
447 1.1 jruoho * RETURN: Status
448 1.1 jruoho *
449 1.1 jruoho * DESCRIPTION: Takes an external resource byte stream and calculates the size
450 1.1 jruoho * buffer needed to hold the corresponding internal resource
451 1.1 jruoho * descriptor linked list.
452 1.1 jruoho *
453 1.1 jruoho ******************************************************************************/
454 1.1 jruoho
455 1.1 jruoho ACPI_STATUS
456 1.1 jruoho AcpiRsGetListLength (
457 1.1 jruoho UINT8 *AmlBuffer,
458 1.1 jruoho UINT32 AmlBufferLength,
459 1.1 jruoho ACPI_SIZE *SizeNeeded)
460 1.1 jruoho {
461 1.1 jruoho ACPI_STATUS Status;
462 1.1 jruoho UINT8 *EndAml;
463 1.1 jruoho UINT8 *Buffer;
464 1.1 jruoho UINT32 BufferSize;
465 1.1 jruoho UINT16 Temp16;
466 1.1 jruoho UINT16 ResourceLength;
467 1.1 jruoho UINT32 ExtraStructBytes;
468 1.1 jruoho UINT8 ResourceIndex;
469 1.1 jruoho UINT8 MinimumAmlResourceLength;
470 1.1 jruoho
471 1.1 jruoho
472 1.1 jruoho ACPI_FUNCTION_TRACE (RsGetListLength);
473 1.1 jruoho
474 1.1 jruoho
475 1.1 jruoho *SizeNeeded = 0;
476 1.1 jruoho EndAml = AmlBuffer + AmlBufferLength;
477 1.1 jruoho
478 1.1 jruoho /* Walk the list of AML resource descriptors */
479 1.1 jruoho
480 1.1 jruoho while (AmlBuffer < EndAml)
481 1.1 jruoho {
482 1.1 jruoho /* Validate the Resource Type and Resource Length */
483 1.1 jruoho
484 1.1 jruoho Status = AcpiUtValidateResource (AmlBuffer, &ResourceIndex);
485 1.1 jruoho if (ACPI_FAILURE (Status))
486 1.1 jruoho {
487 1.1 jruoho return_ACPI_STATUS (Status);
488 1.1 jruoho }
489 1.1 jruoho
490 1.1 jruoho /* Get the resource length and base (minimum) AML size */
491 1.1 jruoho
492 1.1 jruoho ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
493 1.1 jruoho MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
494 1.1 jruoho
495 1.1 jruoho /*
496 1.1 jruoho * Augment the size for descriptors with optional
497 1.1 jruoho * and/or variable length fields
498 1.1 jruoho */
499 1.1 jruoho ExtraStructBytes = 0;
500 1.1 jruoho Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
501 1.1 jruoho
502 1.1 jruoho switch (AcpiUtGetResourceType (AmlBuffer))
503 1.1 jruoho {
504 1.1 jruoho case ACPI_RESOURCE_NAME_IRQ:
505 1.1 jruoho /*
506 1.1 jruoho * IRQ Resource:
507 1.1 jruoho * Get the number of bits set in the 16-bit IRQ mask
508 1.1 jruoho */
509 1.1 jruoho ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
510 1.1 jruoho ExtraStructBytes = AcpiRsCountSetBits (Temp16);
511 1.1 jruoho break;
512 1.1 jruoho
513 1.1 jruoho
514 1.1 jruoho case ACPI_RESOURCE_NAME_DMA:
515 1.1 jruoho /*
516 1.1 jruoho * DMA Resource:
517 1.1 jruoho * Get the number of bits set in the 8-bit DMA mask
518 1.1 jruoho */
519 1.1 jruoho ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
520 1.1 jruoho break;
521 1.1 jruoho
522 1.1 jruoho
523 1.1 jruoho case ACPI_RESOURCE_NAME_VENDOR_SMALL:
524 1.1 jruoho case ACPI_RESOURCE_NAME_VENDOR_LARGE:
525 1.1 jruoho /*
526 1.1 jruoho * Vendor Resource:
527 1.1 jruoho * Get the number of vendor data bytes
528 1.1 jruoho */
529 1.1 jruoho ExtraStructBytes = ResourceLength;
530 1.1 jruoho break;
531 1.1 jruoho
532 1.1 jruoho
533 1.1 jruoho case ACPI_RESOURCE_NAME_END_TAG:
534 1.1 jruoho /*
535 1.1 jruoho * End Tag:
536 1.1 jruoho * This is the normal exit, add size of EndTag
537 1.1 jruoho */
538 1.1 jruoho *SizeNeeded += ACPI_RS_SIZE_MIN;
539 1.1 jruoho return_ACPI_STATUS (AE_OK);
540 1.1 jruoho
541 1.1 jruoho
542 1.1 jruoho case ACPI_RESOURCE_NAME_ADDRESS32:
543 1.1 jruoho case ACPI_RESOURCE_NAME_ADDRESS16:
544 1.1 jruoho case ACPI_RESOURCE_NAME_ADDRESS64:
545 1.1 jruoho /*
546 1.1 jruoho * Address Resource:
547 1.1 jruoho * Add the size of the optional ResourceSource
548 1.1 jruoho */
549 1.1 jruoho ExtraStructBytes = AcpiRsStreamOptionLength (
550 1.1 jruoho ResourceLength, MinimumAmlResourceLength);
551 1.1 jruoho break;
552 1.1 jruoho
553 1.1 jruoho
554 1.1 jruoho case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
555 1.1 jruoho /*
556 1.1 jruoho * Extended IRQ Resource:
557 1.1 jruoho * Using the InterruptTableLength, add 4 bytes for each additional
558 1.1 jruoho * interrupt. Note: at least one interrupt is required and is
559 1.1 jruoho * included in the minimum descriptor size (reason for the -1)
560 1.1 jruoho */
561 1.1 jruoho ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
562 1.1 jruoho
563 1.1 jruoho /* Add the size of the optional ResourceSource */
564 1.1 jruoho
565 1.1 jruoho ExtraStructBytes += AcpiRsStreamOptionLength (
566 1.1 jruoho ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
567 1.1 jruoho break;
568 1.1 jruoho
569 1.1 jruoho
570 1.1 jruoho default:
571 1.1 jruoho break;
572 1.1 jruoho }
573 1.1 jruoho
574 1.1 jruoho /*
575 1.1 jruoho * Update the required buffer size for the internal descriptor structs
576 1.1 jruoho *
577 1.1 jruoho * Important: Round the size up for the appropriate alignment. This
578 1.1 jruoho * is a requirement on IA64.
579 1.1 jruoho */
580 1.1 jruoho BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
581 1.1 jruoho ExtraStructBytes;
582 1.1 jruoho BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
583 1.1 jruoho
584 1.1 jruoho *SizeNeeded += BufferSize;
585 1.1 jruoho
586 1.1 jruoho ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
587 1.1 jruoho "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
588 1.1 jruoho AcpiUtGetResourceType (AmlBuffer),
589 1.1 jruoho AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
590 1.1 jruoho
591 1.1 jruoho /*
592 1.1 jruoho * Point to the next resource within the AML stream using the length
593 1.1 jruoho * contained in the resource descriptor header
594 1.1 jruoho */
595 1.1 jruoho AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
596 1.1 jruoho }
597 1.1 jruoho
598 1.1 jruoho /* Did not find an EndTag resource descriptor */
599 1.1 jruoho
600 1.1 jruoho return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
601 1.1 jruoho }
602 1.1 jruoho
603 1.1 jruoho
604 1.1 jruoho /*******************************************************************************
605 1.1 jruoho *
606 1.1 jruoho * FUNCTION: AcpiRsGetPciRoutingTableLength
607 1.1 jruoho *
608 1.1 jruoho * PARAMETERS: PackageObject - Pointer to the package object
609 1.1 jruoho * BufferSizeNeeded - UINT32 pointer of the size buffer
610 1.1 jruoho * needed to properly return the
611 1.1 jruoho * parsed data
612 1.1 jruoho *
613 1.1 jruoho * RETURN: Status
614 1.1 jruoho *
615 1.1 jruoho * DESCRIPTION: Given a package representing a PCI routing table, this
616 1.1 jruoho * calculates the size of the corresponding linked list of
617 1.1 jruoho * descriptions.
618 1.1 jruoho *
619 1.1 jruoho ******************************************************************************/
620 1.1 jruoho
621 1.1 jruoho ACPI_STATUS
622 1.1 jruoho AcpiRsGetPciRoutingTableLength (
623 1.1 jruoho ACPI_OPERAND_OBJECT *PackageObject,
624 1.1 jruoho ACPI_SIZE *BufferSizeNeeded)
625 1.1 jruoho {
626 1.1 jruoho UINT32 NumberOfElements;
627 1.1 jruoho ACPI_SIZE TempSizeNeeded = 0;
628 1.1 jruoho ACPI_OPERAND_OBJECT **TopObjectList;
629 1.1 jruoho UINT32 Index;
630 1.1 jruoho ACPI_OPERAND_OBJECT *PackageElement;
631 1.1 jruoho ACPI_OPERAND_OBJECT **SubObjectList;
632 1.1 jruoho BOOLEAN NameFound;
633 1.1 jruoho UINT32 TableIndex;
634 1.1 jruoho
635 1.1 jruoho
636 1.1 jruoho ACPI_FUNCTION_TRACE (RsGetPciRoutingTableLength);
637 1.1 jruoho
638 1.1 jruoho
639 1.1 jruoho NumberOfElements = PackageObject->Package.Count;
640 1.1 jruoho
641 1.1 jruoho /*
642 1.1 jruoho * Calculate the size of the return buffer.
643 1.1 jruoho * The base size is the number of elements * the sizes of the
644 1.1 jruoho * structures. Additional space for the strings is added below.
645 1.1 jruoho * The minus one is to subtract the size of the UINT8 Source[1]
646 1.1 jruoho * member because it is added below.
647 1.1 jruoho *
648 1.1 jruoho * But each PRT_ENTRY structure has a pointer to a string and
649 1.1 jruoho * the size of that string must be found.
650 1.1 jruoho */
651 1.1 jruoho TopObjectList = PackageObject->Package.Elements;
652 1.1 jruoho
653 1.1 jruoho for (Index = 0; Index < NumberOfElements; Index++)
654 1.1 jruoho {
655 1.1 jruoho /* Dereference the sub-package */
656 1.1 jruoho
657 1.1 jruoho PackageElement = *TopObjectList;
658 1.1 jruoho
659 1.1 jruoho /* We must have a valid Package object */
660 1.1 jruoho
661 1.1 jruoho if (!PackageElement ||
662 1.1 jruoho (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
663 1.1 jruoho {
664 1.1 jruoho return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
665 1.1 jruoho }
666 1.1 jruoho
667 1.1 jruoho /*
668 1.1 jruoho * The SubObjectList will now point to an array of the
669 1.1 jruoho * four IRQ elements: Address, Pin, Source and SourceIndex
670 1.1 jruoho */
671 1.1 jruoho SubObjectList = PackageElement->Package.Elements;
672 1.1 jruoho
673 1.1 jruoho /* Scan the IrqTableElements for the Source Name String */
674 1.1 jruoho
675 1.1 jruoho NameFound = FALSE;
676 1.1 jruoho
677 1.1 jruoho for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++)
678 1.1 jruoho {
679 1.1 jruoho if (*SubObjectList && /* Null object allowed */
680 1.1 jruoho
681 1.1 jruoho ((ACPI_TYPE_STRING ==
682 1.1 jruoho (*SubObjectList)->Common.Type) ||
683 1.1 jruoho
684 1.1 jruoho ((ACPI_TYPE_LOCAL_REFERENCE ==
685 1.1 jruoho (*SubObjectList)->Common.Type) &&
686 1.1 jruoho
687 1.1 jruoho ((*SubObjectList)->Reference.Class ==
688 1.1 jruoho ACPI_REFCLASS_NAME))))
689 1.1 jruoho {
690 1.1 jruoho NameFound = TRUE;
691 1.1 jruoho }
692 1.1 jruoho else
693 1.1 jruoho {
694 1.1 jruoho /* Look at the next element */
695 1.1 jruoho
696 1.1 jruoho SubObjectList++;
697 1.1 jruoho }
698 1.1 jruoho }
699 1.1 jruoho
700 1.1 jruoho TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
701 1.1 jruoho
702 1.1 jruoho /* Was a String type found? */
703 1.1 jruoho
704 1.1 jruoho if (NameFound)
705 1.1 jruoho {
706 1.1 jruoho if ((*SubObjectList)->Common.Type == ACPI_TYPE_STRING)
707 1.1 jruoho {
708 1.1 jruoho /*
709 1.1 jruoho * The length String.Length field does not include the
710 1.1 jruoho * terminating NULL, add 1
711 1.1 jruoho */
712 1.1 jruoho TempSizeNeeded += ((ACPI_SIZE)
713 1.1 jruoho (*SubObjectList)->String.Length + 1);
714 1.1 jruoho }
715 1.1 jruoho else
716 1.1 jruoho {
717 1.1 jruoho TempSizeNeeded += AcpiNsGetPathnameLength (
718 1.1 jruoho (*SubObjectList)->Reference.Node);
719 1.1 jruoho }
720 1.1 jruoho }
721 1.1 jruoho else
722 1.1 jruoho {
723 1.1 jruoho /*
724 1.1 jruoho * If no name was found, then this is a NULL, which is
725 1.1 jruoho * translated as a UINT32 zero.
726 1.1 jruoho */
727 1.1 jruoho TempSizeNeeded += sizeof (UINT32);
728 1.1 jruoho }
729 1.1 jruoho
730 1.1 jruoho /* Round up the size since each element must be aligned */
731 1.1 jruoho
732 1.1 jruoho TempSizeNeeded = ACPI_ROUND_UP_TO_64BIT (TempSizeNeeded);
733 1.1 jruoho
734 1.1 jruoho /* Point to the next ACPI_OPERAND_OBJECT */
735 1.1 jruoho
736 1.1 jruoho TopObjectList++;
737 1.1 jruoho }
738 1.1 jruoho
739 1.1 jruoho /*
740 1.1 jruoho * Add an extra element to the end of the list, essentially a
741 1.1 jruoho * NULL terminator
742 1.1 jruoho */
743 1.1 jruoho *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
744 1.1 jruoho return_ACPI_STATUS (AE_OK);
745 1.1 jruoho }
746