FreeBSD/sys/contrib/dev/acpica/components/resources/rscalc.c
/*******************************************************************************
 *
 * FUNCTION:    AcpiRsGetListLength
 *
 * PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
 *              AmlBufferLength     - Size of AmlBuffer
 *              SizeNeeded          - Where the size needed is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Takes an external resource byte stream and calculates the size
 *              buffer needed to hold the corresponding internal resource
 *              descriptor linked list.
 *
 ******************************************************************************/
AcpiRsGetListLength
PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
AmlBufferLength     - Size of AmlBuffer
SizeNeeded          - Where the size needed is returned

Status

Takes an external resource byte stream and calculates the size
buffer needed to hold the corresponding internal resource
descriptor linked list.
AcpiRsGetListLength PARAMETERS : AmlBuffer - Pointer to the resource byte stream AmlBufferLength - Size of AmlBuffer SizeNeeded - Where the size needed is returned Status Takes an external resource byte stream and calculates the size buffer needed to hold the corresponding internal resource descriptor linked list .
ACPI_STATUS
AcpiRsGetListLength (
    UINT8                   *AmlBuffer,
    UINT32                  AmlBufferLength,
    ACPI_SIZE               *SizeNeeded)
{
    ACPI_STATUS             Status;
    UINT8                   *EndAml;
    UINT8                   *Buffer;
    UINT32                  BufferSize;
    UINT16                  Temp16;
    UINT16                  ResourceLength;
    UINT32                  ExtraStructBytes;
    UINT8                   ResourceIndex;
    UINT8                   MinimumAmlResourceLength;
    AML_RESOURCE            *AmlResource;
    ACPI_FUNCTION_TRACE (RsGetListLength);
    *SizeNeeded = ACPI_RS_SIZE_MIN;         
    EndAml = AmlBuffer + AmlBufferLength;
    while (AmlBuffer < EndAml)
    {
        Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }
        AmlResource = (void *) AmlBuffer;
        ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
        MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];
        ExtraStructBytes = 0;
        Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);
        switch (AcpiUtGetResourceType (AmlBuffer))
        {
        case ACPI_RESOURCE_NAME_IRQ:
            ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
            ExtraStructBytes = AcpiRsCountSetBits (Temp16);
            break;
        case ACPI_RESOURCE_NAME_DMA:
            ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
            break;
        case ACPI_RESOURCE_NAME_VENDOR_SMALL:
        case ACPI_RESOURCE_NAME_VENDOR_LARGE:
            ExtraStructBytes = ResourceLength;
            if (ExtraStructBytes)
            {
                ExtraStructBytes--;
            }
            break;
        case ACPI_RESOURCE_NAME_END_TAG:
            return_ACPI_STATUS (AE_OK);
        case ACPI_RESOURCE_NAME_ADDRESS32:
        case ACPI_RESOURCE_NAME_ADDRESS16:
        case ACPI_RESOURCE_NAME_ADDRESS64:
            ExtraStructBytes = AcpiRsStreamOptionLength (
                ResourceLength, MinimumAmlResourceLength);
            break;
        case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
            ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);
            ExtraStructBytes += AcpiRsStreamOptionLength (
                ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
            break;
        case ACPI_RESOURCE_NAME_GPIO:
            if (AmlResource->Gpio.VendorLength)
            {
                ExtraStructBytes +=
                    AmlResource->Gpio.VendorOffset -
                    AmlResource->Gpio.PinTableOffset +
                    AmlResource->Gpio.VendorLength;
            }
            else
            {
                ExtraStructBytes +=
                    AmlResource->LargeHeader.ResourceLength +
                    sizeof (AML_RESOURCE_LARGE_HEADER) -
                    AmlResource->Gpio.PinTableOffset;
            }
            break;
        case ACPI_RESOURCE_NAME_SERIAL_BUS:
            MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
                AmlResource->CommonSerialBus.Type];
            ExtraStructBytes +=
                AmlResource->CommonSerialBus.ResourceLength -
                MinimumAmlResourceLength;
            break;
        default:
            break;
        }
        if (AcpiUtGetResourceType (AmlBuffer) ==
            ACPI_RESOURCE_NAME_SERIAL_BUS)
        {
            BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
                AmlResource->CommonSerialBus.Type] + ExtraStructBytes;
        }
        else
        {
            BufferSize = AcpiGbl_ResourceStructSizes[ResourceIndex] +
                ExtraStructBytes;
        }
        BufferSize = (UINT32) ACPI_ROUND_UP_TO_NATIVE_WORD (BufferSize);
        *SizeNeeded += BufferSize;
        ACPI_DEBUG_PRINT ((ACPI_DB_RESOURCES,
            "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
            AcpiUtGetResourceType (AmlBuffer),
            AcpiUtGetDescriptorLength (AmlBuffer), BufferSize));
        AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
    }
    return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
}
ACPI_STATUS AcpiRsGetListLength ( UINT8 * AmlBuffer , UINT32 AmlBufferLength , ACPI_SIZE * SizeNeeded ) { ACPI_STATUS Status ; UINT8 * EndAml ; UINT8 * Buffer ; UINT32 BufferSize ; UINT16 Temp16 ; UINT16 ResourceLength ; UINT32 ExtraStructBytes ; UINT8 ResourceIndex ; UINT8 MinimumAmlResourceLength ; AML_RESOURCE * AmlResource ; ACPI_FUNCTION_TRACE ( RsGetListLength ) ; * SizeNeeded = ACPI_RS_SIZE_MIN ; EndAml = AmlBuffer + AmlBufferLength ; while ( AmlBuffer < EndAml ) { Status = AcpiUtValidateResource ( NULL , AmlBuffer , & ResourceIndex ) ; if ( ACPI_FAILURE ( Status ) ) { return_ACPI_STATUS ( Status ) ; } AmlResource = ( void * ) AmlBuffer ; ResourceLength = AcpiUtGetResourceLength ( AmlBuffer ) ; MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes [ ResourceIndex ] ; ExtraStructBytes = 0 ; Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength ( AmlBuffer ) ; switch ( AcpiUtGetResourceType ( AmlBuffer ) ) { case ACPI_RESOURCE_NAME_IRQ : ACPI_MOVE_16_TO_16 ( & Temp16 , Buffer ) ; ExtraStructBytes = AcpiRsCountSetBits ( Temp16 ) ; break ; case ACPI_RESOURCE_NAME_DMA : ExtraStructBytes = AcpiRsCountSetBits ( * Buffer ) ; break ; case ACPI_RESOURCE_NAME_VENDOR_SMALL : case ACPI_RESOURCE_NAME_VENDOR_LARGE : ExtraStructBytes = ResourceLength ; if ( ExtraStructBytes ) { ExtraStructBytes -- ; } break ; case ACPI_RESOURCE_NAME_END_TAG : return_ACPI_STATUS ( AE_OK ) ; case ACPI_RESOURCE_NAME_ADDRESS32 : case ACPI_RESOURCE_NAME_ADDRESS16 : case ACPI_RESOURCE_NAME_ADDRESS64 : ExtraStructBytes = AcpiRsStreamOptionLength ( ResourceLength , MinimumAmlResourceLength ) ; break ; case ACPI_RESOURCE_NAME_EXTENDED_IRQ : ExtraStructBytes = ( Buffer [ 1 ] - 1 ) * sizeof ( UINT32 ) ; ExtraStructBytes += AcpiRsStreamOptionLength ( ResourceLength - ExtraStructBytes , MinimumAmlResourceLength ) ; break ; case ACPI_RESOURCE_NAME_GPIO : if ( AmlResource -> Gpio . VendorLength ) { ExtraStructBytes += AmlResource -> Gpio . VendorOffset - AmlResource -> Gpio . PinTableOffset + AmlResource -> Gpio . VendorLength ; } else { ExtraStructBytes += AmlResource -> LargeHeader . ResourceLength + sizeof ( AML_RESOURCE_LARGE_HEADER ) - AmlResource -> Gpio . PinTableOffset ; } break ; case ACPI_RESOURCE_NAME_SERIAL_BUS : MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes [ AmlResource -> CommonSerialBus . Type ] ; ExtraStructBytes += AmlResource -> CommonSerialBus . ResourceLength - MinimumAmlResourceLength ; break ; default : break ; } if ( AcpiUtGetResourceType ( AmlBuffer ) == ACPI_RESOURCE_NAME_SERIAL_BUS ) { BufferSize = AcpiGbl_ResourceStructSerialBusSizes [ AmlResource -> CommonSerialBus . Type ] + ExtraStructBytes ; } else { BufferSize = AcpiGbl_ResourceStructSizes [ ResourceIndex ] + ExtraStructBytes ; } BufferSize = ( UINT32 ) ACPI_ROUND_UP_TO_NATIVE_WORD ( BufferSize ) ; * SizeNeeded += BufferSize ; ACPI_DEBUG_PRINT ( ( ACPI_DB_RESOURCES , " \n " , AcpiUtGetResourceType ( AmlBuffer ) , AcpiUtGetDescriptorLength ( AmlBuffer ) , BufferSize ) ) ; AmlBuffer += AcpiUtGetDescriptorLength ( AmlBuffer ) ; } return_ACPI_STATUS ( AE_AML_NO_RESOURCE_END_TAG ) ; }
FUNCTION:    AcpiRsGetListLength
 PARAMETERS:  AmlBuffer           - Pointer to the resource byte stream
              AmlBufferLength     - Size of AmlBuffer
              SizeNeeded          - Where the size needed is returned
FUNCTION : AcpiRsGetListLength PARAMETERS : AmlBuffer - Pointer to the resource byte stream AmlBufferLength - Size of AmlBuffer SizeNeeded - Where the size needed is returned
/* Minimum size is one EndTag */ /* Walk the list of AML resource descriptors */ /* Validate the Resource Type and Resource Length */ /*
             * Exit on failure. Cannot continue because the descriptor length
             * may be bogus also.
             */ /* Get the resource length and base (minimum) AML size */ /*
         * Augment the size for descriptors with optional
         * and/or variable length fields
         */ /*
             * IRQ Resource:
             * Get the number of bits set in the 16-bit IRQ mask
             */ /*
             * DMA Resource:
             * Get the number of bits set in the 8-bit DMA mask
             */ /*
             * Vendor Resource:
             * Get the number of vendor data bytes
             */ /*
             * There is already one byte included in the minimum
             * descriptor size. If there are extra struct bytes,
             * subtract one from the count.
             */ /*
             * End Tag: This is the normal exit
             */ /*
             * Address Resource:
             * Add the size of the optional ResourceSource
             */ /*
             * Extended IRQ Resource:
             * Using the InterruptTableLength, add 4 bytes for each additional
             * interrupt. Note: at least one interrupt is required and is
             * included in the minimum descriptor size (reason for the -1)
             */ /* Add the size of the optional ResourceSource */ /* Vendor data is optional */ /*
         * Update the required buffer size for the internal descriptor structs
         *
         * Important: Round the size up for the appropriate alignment. This
         * is a requirement on IA64.
         */ /*
         * Point to the next resource within the AML stream using the length
         * contained in the resource descriptor header
         */ /* Did not find an EndTag resource descriptor */