1 /*******************************************************************************
2 *
3 * Module Name: rscalc - Calculate stream and list lengths
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
180 if (ResourceLength > MinimumAmlResourceLength)
181 {
182 /* Compute the length of the optional string */
183
184 StringLength = ResourceLength - MinimumAmlResourceLength - 1;
185 }
186
187 /*
188 * Round the length up to a multiple of the native word in order to
189 * guarantee that the entire resource descriptor is native word aligned
190 */
191 return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
192 }
193
194
195 /*******************************************************************************
196 *
197 * FUNCTION: AcpiRsGetAmlLength
198 *
199 * PARAMETERS: Resource - Pointer to the resource linked list
200 * SizeNeeded - Where the required size is returned
201 *
202 * RETURN: Status
203 *
204 * DESCRIPTION: Takes a linked list of internal resource descriptors and
205 * calculates the size buffer needed to hold the corresponding
206 * external resource byte stream.
207 *
208 ******************************************************************************/
209
210 ACPI_STATUS
211 AcpiRsGetAmlLength (
212 ACPI_RESOURCE *Resource,
213 ACPI_SIZE *SizeNeeded)
214 {
215 ACPI_SIZE AmlSizeNeeded = 0;
216 ACPI_RS_LENGTH TotalSize;
217
218
219 ACPI_FUNCTION_TRACE (RsGetAmlLength);
220
221
222 /* Traverse entire list of internal resource descriptors */
223
224 while (Resource)
225 {
226 /* Validate the descriptor type */
227
228 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
229 {
230 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
231 }
232
233 /* Get the base size of the (external stream) resource descriptor */
234
235 TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
236
237 /*
238 * Augment the base size for descriptors with optional and/or
239 * variable-length fields
240 */
241 switch (Resource->Type)
242 {
243 case ACPI_RESOURCE_TYPE_IRQ:
244
245 /* Length can be 3 or 2 */
246
247 if (Resource->Data.Irq.DescriptorLength == 2)
248 {
249 TotalSize--;
250 }
251 break;
252
328 break;
329
330
331 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
332 /*
333 * Extended IRQ Resource:
334 * Add the size of each additional optional interrupt beyond the
335 * required 1 (4 bytes for each UINT32 interrupt number)
336 */
337 TotalSize = (ACPI_RS_LENGTH)
338 (TotalSize +
339 ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
340
341 /* Add the size of the optional ResourceSource info */
342
343 AcpiRsStructOptionLength (
344 &Resource->Data.ExtendedIrq.ResourceSource));
345 break;
346
347
348 default:
349 break;
350 }
351
352 /* Update the total */
353
354 AmlSizeNeeded += TotalSize;
355
356 /* Point to the next object */
357
358 Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
359 }
360
361 /* Did not find an EndTag resource descriptor */
362
363 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
364 }
365
366
367 /*******************************************************************************
368 *
378 * buffer needed to hold the corresponding internal resource
379 * descriptor linked list.
380 *
381 ******************************************************************************/
382
383 ACPI_STATUS
384 AcpiRsGetListLength (
385 UINT8 *AmlBuffer,
386 UINT32 AmlBufferLength,
387 ACPI_SIZE *SizeNeeded)
388 {
389 ACPI_STATUS Status;
390 UINT8 *EndAml;
391 UINT8 *Buffer;
392 UINT32 BufferSize;
393 UINT16 Temp16;
394 UINT16 ResourceLength;
395 UINT32 ExtraStructBytes;
396 UINT8 ResourceIndex;
397 UINT8 MinimumAmlResourceLength;
398
399
400 ACPI_FUNCTION_TRACE (RsGetListLength);
401
402
403 *SizeNeeded = 0;
404 EndAml = AmlBuffer + AmlBufferLength;
405
406 /* Walk the list of AML resource descriptors */
407
408 while (AmlBuffer < EndAml)
409 {
410 /* Validate the Resource Type and Resource Length */
411
412 Status = AcpiUtValidateResource (AmlBuffer, &ResourceIndex);
413 if (ACPI_FAILURE (Status))
414 {
415 return_ACPI_STATUS (Status);
416 }
417
418 /* Get the resource length and base (minimum) AML size */
419
420 ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
421 MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
422
423 /*
424 * Augment the size for descriptors with optional
425 * and/or variable length fields
426 */
427 ExtraStructBytes = 0;
428 Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
429
430 switch (AcpiUtGetResourceType (AmlBuffer))
431 {
432 case ACPI_RESOURCE_NAME_IRQ:
433 /*
434 * IRQ Resource:
435 * Get the number of bits set in the 16-bit IRQ mask
436 */
437 ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
438 ExtraStructBytes = AcpiRsCountSetBits (Temp16);
439 break;
440
441
442 case ACPI_RESOURCE_NAME_DMA:
443 /*
444 * DMA Resource:
445 * Get the number of bits set in the 8-bit DMA mask
446 */
447 ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
448 break;
449
450
451 case ACPI_RESOURCE_NAME_VENDOR_SMALL:
452 case ACPI_RESOURCE_NAME_VENDOR_LARGE:
453 /*
454 * Vendor Resource:
455 * Get the number of vendor data bytes
456 */
457 ExtraStructBytes = ResourceLength;
458 break;
459
460
461 case ACPI_RESOURCE_NAME_END_TAG:
462 /*
463 * End Tag:
464 * This is the normal exit, add size of EndTag
465 */
466 *SizeNeeded += ACPI_RS_SIZE_MIN;
467 return_ACPI_STATUS (AE_OK);
468
469
470 case ACPI_RESOURCE_NAME_ADDRESS32:
471 case ACPI_RESOURCE_NAME_ADDRESS16:
472 case ACPI_RESOURCE_NAME_ADDRESS64:
473 /*
474 * Address Resource:
475 * Add the size of the optional ResourceSource
476 */
477 ExtraStructBytes = AcpiRsStreamOptionLength (
478 ResourceLength, MinimumAmlResourceLength);
479 break;
480
481
482 case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
483 /*
484 * Extended IRQ Resource:
485 * Using the InterruptTableLength, add 4 bytes for each additional
486 * interrupt. Note: at least one interrupt is required and is
487 * included in the minimum descriptor size (reason for the -1)
488 */
489 ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
490
491 /* Add the size of the optional ResourceSource */
492
493 ExtraStructBytes += AcpiRsStreamOptionLength (
494 ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
495 break;
496
497
498 default:
499 break;
500 }
501
502 /*
503 * Update the required buffer size for the internal descriptor structs
504 *
505 * Important: Round the size up for the appropriate alignment. This
506 * is a requirement on IA64.
507 */
508 BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
509 ExtraStructBytes;
510 BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
511
512 *SizeNeeded += BufferSize;
513
514 ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
515 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
516 AcpiUtGetResourceType (AmlBuffer),
517 AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
518
519 /*
520 * Point to the next resource within the AML stream using the length
521 * contained in the resource descriptor header
522 */
523 AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
524 }
525
526 /* Did not find an EndTag resource descriptor */
527
528 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
529 }
585 PackageElement = *TopObjectList;
586
587 /* We must have a valid Package object */
588
589 if (!PackageElement ||
590 (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
591 {
592 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
593 }
594
595 /*
596 * The SubObjectList will now point to an array of the
597 * four IRQ elements: Address, Pin, Source and SourceIndex
598 */
599 SubObjectList = PackageElement->Package.Elements;
600
601 /* Scan the IrqTableElements for the Source Name String */
602
603 NameFound = FALSE;
604
605 for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++)
606 {
607 if (*SubObjectList && /* Null object allowed */
608
609 ((ACPI_TYPE_STRING ==
610 (*SubObjectList)->Common.Type) ||
611
612 ((ACPI_TYPE_LOCAL_REFERENCE ==
613 (*SubObjectList)->Common.Type) &&
614
615 ((*SubObjectList)->Reference.Class ==
616 ACPI_REFCLASS_NAME))))
617 {
618 NameFound = TRUE;
619 }
620 else
621 {
622 /* Look at the next element */
623
624 SubObjectList++;
625 }
|
1 /*******************************************************************************
2 *
3 * Module Name: rscalc - Calculate stream and list lengths
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
180 if (ResourceLength > MinimumAmlResourceLength)
181 {
182 /* Compute the length of the optional string */
183
184 StringLength = ResourceLength - MinimumAmlResourceLength - 1;
185 }
186
187 /*
188 * Round the length up to a multiple of the native word in order to
189 * guarantee that the entire resource descriptor is native word aligned
190 */
191 return ((UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (StringLength));
192 }
193
194
195 /*******************************************************************************
196 *
197 * FUNCTION: AcpiRsGetAmlLength
198 *
199 * PARAMETERS: Resource - Pointer to the resource linked list
200 * ResourceListSize - Size of the resource linked list
201 * SizeNeeded - Where the required size is returned
202 *
203 * RETURN: Status
204 *
205 * DESCRIPTION: Takes a linked list of internal resource descriptors and
206 * calculates the size buffer needed to hold the corresponding
207 * external resource byte stream.
208 *
209 ******************************************************************************/
210
211 ACPI_STATUS
212 AcpiRsGetAmlLength (
213 ACPI_RESOURCE *Resource,
214 ACPI_SIZE ResourceListSize,
215 ACPI_SIZE *SizeNeeded)
216 {
217 ACPI_SIZE AmlSizeNeeded = 0;
218 ACPI_RESOURCE *ResourceEnd;
219 ACPI_RS_LENGTH TotalSize;
220
221
222 ACPI_FUNCTION_TRACE (RsGetAmlLength);
223
224
225 /* Traverse entire list of internal resource descriptors */
226
227 ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
228 while (Resource < ResourceEnd)
229 {
230 /* Validate the descriptor type */
231
232 if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
233 {
234 return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
235 }
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
244 /* Get the base size of the (external stream) resource descriptor */
245
246 TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
247
248 /*
249 * Augment the base size for descriptors with optional and/or
250 * variable-length fields
251 */
252 switch (Resource->Type)
253 {
254 case ACPI_RESOURCE_TYPE_IRQ:
255
256 /* Length can be 3 or 2 */
257
258 if (Resource->Data.Irq.DescriptorLength == 2)
259 {
260 TotalSize--;
261 }
262 break;
263
339 break;
340
341
342 case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
343 /*
344 * Extended IRQ Resource:
345 * Add the size of each additional optional interrupt beyond the
346 * required 1 (4 bytes for each UINT32 interrupt number)
347 */
348 TotalSize = (ACPI_RS_LENGTH)
349 (TotalSize +
350 ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
351
352 /* Add the size of the optional ResourceSource info */
353
354 AcpiRsStructOptionLength (
355 &Resource->Data.ExtendedIrq.ResourceSource));
356 break;
357
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
378 default:
379
380 break;
381 }
382
383 /* Update the total */
384
385 AmlSizeNeeded += TotalSize;
386
387 /* Point to the next object */
388
389 Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
390 }
391
392 /* Did not find an EndTag resource descriptor */
393
394 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
395 }
396
397
398 /*******************************************************************************
399 *
409 * buffer needed to hold the corresponding internal resource
410 * descriptor linked list.
411 *
412 ******************************************************************************/
413
414 ACPI_STATUS
415 AcpiRsGetListLength (
416 UINT8 *AmlBuffer,
417 UINT32 AmlBufferLength,
418 ACPI_SIZE *SizeNeeded)
419 {
420 ACPI_STATUS Status;
421 UINT8 *EndAml;
422 UINT8 *Buffer;
423 UINT32 BufferSize;
424 UINT16 Temp16;
425 UINT16 ResourceLength;
426 UINT32 ExtraStructBytes;
427 UINT8 ResourceIndex;
428 UINT8 MinimumAmlResourceLength;
429 AML_RESOURCE *AmlResource;
430
431
432 ACPI_FUNCTION_TRACE (RsGetListLength);
433
434
435 *SizeNeeded = ACPI_RS_SIZE_MIN; /* Minimum size is one EndTag */
436 EndAml = AmlBuffer + AmlBufferLength;
437
438 /* Walk the list of AML resource descriptors */
439
440 while (AmlBuffer < EndAml)
441 {
442 /* Validate the Resource Type and Resource Length */
443
444 Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
445 if (ACPI_FAILURE (Status))
446 {
447 /*
448 * Exit on failure. Cannot continue because the descriptor length
449 * may be bogus also.
450 */
451 return_ACPI_STATUS (Status);
452 }
453
454 AmlResource = (void *) AmlBuffer;
455
456 /* Get the resource length and base (minimum) AML size */
457
458 ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
459 MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
460
461 /*
462 * Augment the size for descriptors with optional
463 * and/or variable length fields
464 */
465 ExtraStructBytes = 0;
466 Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
467
468 switch (AcpiUtGetResourceType (AmlBuffer))
469 {
470 case ACPI_RESOURCE_NAME_IRQ:
471 /*
472 * IRQ Resource:
473 * Get the number of bits set in the 16-bit IRQ mask
474 */
475 ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
476 ExtraStructBytes = AcpiRsCountSetBits (Temp16);
477 break;
478
479
480 case ACPI_RESOURCE_NAME_DMA:
481 /*
482 * DMA Resource:
483 * Get the number of bits set in the 8-bit DMA mask
484 */
485 ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
486 break;
487
488
489 case ACPI_RESOURCE_NAME_VENDOR_SMALL:
490 case ACPI_RESOURCE_NAME_VENDOR_LARGE:
491 /*
492 * Vendor Resource:
493 * Get the number of vendor data bytes
494 */
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 }
506 break;
507
508
509 case ACPI_RESOURCE_NAME_END_TAG:
510 /*
511 * End Tag: This is the normal exit
512 */
513 return_ACPI_STATUS (AE_OK);
514
515
516 case ACPI_RESOURCE_NAME_ADDRESS32:
517 case ACPI_RESOURCE_NAME_ADDRESS16:
518 case ACPI_RESOURCE_NAME_ADDRESS64:
519 /*
520 * Address Resource:
521 * Add the size of the optional ResourceSource
522 */
523 ExtraStructBytes = AcpiRsStreamOptionLength (
524 ResourceLength, MinimumAmlResourceLength);
525 break;
526
527
528 case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
529 /*
530 * Extended IRQ Resource:
531 * Using the InterruptTableLength, add 4 bytes for each additional
532 * interrupt. Note: at least one interrupt is required and is
533 * included in the minimum descriptor size (reason for the -1)
534 */
535 ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
536
537 /* Add the size of the optional ResourceSource */
538
539 ExtraStructBytes += AcpiRsStreamOptionLength (
540 ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
541 break;
542
543 case ACPI_RESOURCE_NAME_GPIO:
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
568 default:
569
570 break;
571 }
572
573 /*
574 * Update the required buffer size for the internal descriptor structs
575 *
576 * Important: Round the size up for the appropriate alignment. This
577 * is a requirement on IA64.
578 */
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] +
587 ExtraStructBytes;
588 }
589 BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
590
591 *SizeNeeded += BufferSize;
592
593 ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
594 "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
595 AcpiUtGetResourceType (AmlBuffer),
596 AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
597
598 /*
599 * Point to the next resource within the AML stream using the length
600 * contained in the resource descriptor header
601 */
602 AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
603 }
604
605 /* Did not find an EndTag resource descriptor */
606
607 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
608 }
664 PackageElement = *TopObjectList;
665
666 /* We must have a valid Package object */
667
668 if (!PackageElement ||
669 (PackageElement->Common.Type != ACPI_TYPE_PACKAGE))
670 {
671 return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
672 }
673
674 /*
675 * The SubObjectList will now point to an array of the
676 * four IRQ elements: Address, Pin, Source and SourceIndex
677 */
678 SubObjectList = PackageElement->Package.Elements;
679
680 /* Scan the IrqTableElements for the Source Name String */
681
682 NameFound = FALSE;
683
684 for (TableIndex = 0;
685 TableIndex < PackageElement->Package.Count && !NameFound;
686 TableIndex++)
687 {
688 if (*SubObjectList && /* Null object allowed */
689
690 ((ACPI_TYPE_STRING ==
691 (*SubObjectList)->Common.Type) ||
692
693 ((ACPI_TYPE_LOCAL_REFERENCE ==
694 (*SubObjectList)->Common.Type) &&
695
696 ((*SubObjectList)->Reference.Class ==
697 ACPI_REFCLASS_NAME))))
698 {
699 NameFound = TRUE;
700 }
701 else
702 {
703 /* Look at the next element */
704
705 SubObjectList++;
706 }
|