FreeBSD/sys/contrib/dev/acpica/components/resources/rscalc.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiRsGetAmlLength
 *
 * PARAMETERS:  Resource            - Pointer to the resource linked list
 *              ResourceListSize    - Size of the resource linked list
 *              SizeNeeded          - Where the required size is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Takes a linked list of internal resource descriptors and
 *              calculates the size buffer needed to hold the corresponding
 *              external resource byte stream.
 *
 ******************************************************************************/
AcpiRsGetAmlLength
PARAMETERS:  Resource            - Pointer to the resource linked list
ResourceListSize    - Size of the resource linked list
SizeNeeded          - Where the required size is returned

Status

Takes a linked list of internal resource descriptors and
calculates the size buffer needed to hold the corresponding
external resource byte stream.
AcpiRsGetAmlLength PARAMETERS : Resource - Pointer to the resource linked list ResourceListSize - Size of the resource linked list SizeNeeded - Where the required size is returned Status Takes a linked list of internal resource descriptors and calculates the size buffer needed to hold the corresponding external resource byte stream .
ACPI_STATUS
AcpiRsGetAmlLength (
    ACPI_RESOURCE           *Resource,
    ACPI_SIZE               ResourceListSize,
    ACPI_SIZE               *SizeNeeded)
{
    ACPI_SIZE               AmlSizeNeeded = 0;
    ACPI_RESOURCE           *ResourceEnd;
    ACPI_RS_LENGTH          TotalSize;
    ACPI_FUNCTION_TRACE (RsGetAmlLength);
    ResourceEnd = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, ResourceListSize);
    while (Resource < ResourceEnd)
    {
        if (Resource->Type > ACPI_RESOURCE_TYPE_MAX)
        {
            return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
        }
        if (!Resource->Length)
        {
            return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
        }
        TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type];
        switch (Resource->Type)
        {
        case ACPI_RESOURCE_TYPE_IRQ:
            if (Resource->Data.Irq.DescriptorLength == 2)
            {
                TotalSize--;
            }
            break;
        case ACPI_RESOURCE_TYPE_START_DEPENDENT:
            if (Resource->Data.Irq.DescriptorLength == 0)
            {
                TotalSize--;
            }
            break;
        case ACPI_RESOURCE_TYPE_VENDOR:
            if (Resource->Data.Vendor.ByteLength > 7)
            {
                TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER);
            }
            TotalSize = (ACPI_RS_LENGTH)
                (TotalSize + Resource->Data.Vendor.ByteLength);
            break;
        case ACPI_RESOURCE_TYPE_END_TAG:
            *SizeNeeded = AmlSizeNeeded + TotalSize;
            return_ACPI_STATUS (AE_OK);
        case ACPI_RESOURCE_TYPE_ADDRESS16:
            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
                AcpiRsStructOptionLength (
                    &Resource->Data.Address16.ResourceSource));
            break;
        case ACPI_RESOURCE_TYPE_ADDRESS32:
            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
                AcpiRsStructOptionLength (
                    &Resource->Data.Address32.ResourceSource));
            break;
        case ACPI_RESOURCE_TYPE_ADDRESS64:
            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
                AcpiRsStructOptionLength (
                    &Resource->Data.Address64.ResourceSource));
            break;
        case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
                ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) +
                AcpiRsStructOptionLength (
                    &Resource->Data.ExtendedIrq.ResourceSource));
            break;
        case ACPI_RESOURCE_TYPE_GPIO:
            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
                (Resource->Data.Gpio.PinTableLength * 2) +
                Resource->Data.Gpio.ResourceSource.StringLength +
                Resource->Data.Gpio.VendorLength);
            break;
        case ACPI_RESOURCE_TYPE_SERIAL_BUS:
            TotalSize = AcpiGbl_AmlResourceSerialBusSizes [
                Resource->Data.CommonSerialBus.Type];
            TotalSize = (ACPI_RS_LENGTH) (TotalSize +
                Resource->Data.I2cSerialBus.ResourceSource.StringLength +
                Resource->Data.I2cSerialBus.VendorLength);
            break;
        default:
            break;
        }
        AmlSizeNeeded += TotalSize;
        Resource = ACPI_ADD_PTR (ACPI_RESOURCE, Resource, Resource->Length);
    }
    return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
}
ACPI_STATUS AcpiRsGetAmlLength ( ACPI_RESOURCE * Resource , ACPI_SIZE ResourceListSize , ACPI_SIZE * SizeNeeded ) { ACPI_SIZE AmlSizeNeeded = 0 ; ACPI_RESOURCE * ResourceEnd ; ACPI_RS_LENGTH TotalSize ; ACPI_FUNCTION_TRACE ( RsGetAmlLength ) ; ResourceEnd = ACPI_ADD_PTR ( ACPI_RESOURCE , Resource , ResourceListSize ) ; while ( Resource < ResourceEnd ) { if ( Resource -> Type > ACPI_RESOURCE_TYPE_MAX ) { return_ACPI_STATUS ( AE_AML_INVALID_RESOURCE_TYPE ) ; } if ( ! Resource -> Length ) { return_ACPI_STATUS ( AE_AML_BAD_RESOURCE_LENGTH ) ; } TotalSize = AcpiGbl_AmlResourceSizes [ Resource -> Type ] ; switch ( Resource -> Type ) { case ACPI_RESOURCE_TYPE_IRQ : if ( Resource -> Data . Irq . DescriptorLength == 2 ) { TotalSize -- ; } break ; case ACPI_RESOURCE_TYPE_START_DEPENDENT : if ( Resource -> Data . Irq . DescriptorLength == 0 ) { TotalSize -- ; } break ; case ACPI_RESOURCE_TYPE_VENDOR : if ( Resource -> Data . Vendor . ByteLength > 7 ) { TotalSize = sizeof ( AML_RESOURCE_LARGE_HEADER ) ; } TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + Resource -> Data . Vendor . ByteLength ) ; break ; case ACPI_RESOURCE_TYPE_END_TAG : * SizeNeeded = AmlSizeNeeded + TotalSize ; return_ACPI_STATUS ( AE_OK ) ; case ACPI_RESOURCE_TYPE_ADDRESS16 : TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + AcpiRsStructOptionLength ( & Resource -> Data . Address16 . ResourceSource ) ) ; break ; case ACPI_RESOURCE_TYPE_ADDRESS32 : TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + AcpiRsStructOptionLength ( & Resource -> Data . Address32 . ResourceSource ) ) ; break ; case ACPI_RESOURCE_TYPE_ADDRESS64 : TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + AcpiRsStructOptionLength ( & Resource -> Data . Address64 . ResourceSource ) ) ; break ; case ACPI_RESOURCE_TYPE_EXTENDED_IRQ : TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + ( ( Resource -> Data . ExtendedIrq . InterruptCount - 1 ) * 4 ) + AcpiRsStructOptionLength ( & Resource -> Data . ExtendedIrq . ResourceSource ) ) ; break ; case ACPI_RESOURCE_TYPE_GPIO : TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + ( Resource -> Data . Gpio . PinTableLength * 2 ) + Resource -> Data . Gpio . ResourceSource . StringLength + Resource -> Data . Gpio . VendorLength ) ; break ; case ACPI_RESOURCE_TYPE_SERIAL_BUS : TotalSize = AcpiGbl_AmlResourceSerialBusSizes [ Resource -> Data . CommonSerialBus . Type ] ; TotalSize = ( ACPI_RS_LENGTH ) ( TotalSize + Resource -> Data . I2cSerialBus . ResourceSource . StringLength + Resource -> Data . I2cSerialBus . VendorLength ) ; break ; default : break ; } AmlSizeNeeded += TotalSize ; Resource = ACPI_ADD_PTR ( ACPI_RESOURCE , Resource , Resource -> Length ) ; } return_ACPI_STATUS ( AE_AML_NO_RESOURCE_END_TAG ) ; }
FUNCTION:    AcpiRsGetAmlLength
 PARAMETERS:  Resource            - Pointer to the resource linked list
              ResourceListSize    - Size of the resource linked list
              SizeNeeded          - Where the required size is returned
FUNCTION : AcpiRsGetAmlLength PARAMETERS : Resource - Pointer to the resource linked list ResourceListSize - Size of the resource linked list SizeNeeded - Where the required size is returned
/* Traverse entire list of internal resource descriptors */ /* Validate the descriptor type */ /* Sanity check the length. It must not be zero, or we loop forever */ /* Get the base size of the (external stream) resource descriptor */ /*
         * Augment the base size for descriptors with optional and/or
         * variable-length fields
         */ /* Length can be 3 or 2 */ /* Length can be 1 or 0 */ /*
             * Vendor Defined Resource:
             * For a Vendor Specific resource, if the Length is between 1 and 7
             * it will be created as a Small Resource data type, otherwise it
             * is a Large Resource data type.
             */ /* Base size of a Large resource descriptor */ /* Add the size of the vendor-specific data */ /*
             * End Tag:
             * We are done -- return the accumulated total size.
             */ /* Normal exit */ /*
             * 16-Bit Address Resource:
             * Add the size of the optional ResourceSource info
             */ /*
             * 32-Bit Address Resource:
             * Add the size of the optional ResourceSource info
             */ /*
             * 64-Bit Address Resource:
             * Add the size of the optional ResourceSource info
             */ /*
             * Extended IRQ Resource:
             * Add the size of each additional optional interrupt beyond the
             * required 1 (4 bytes for each UINT32 interrupt number)
             */ /* Add the size of the optional ResourceSource info */ /* Update the total */ /* Point to the next object */ /* Did not find an EndTag resource descriptor */