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