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