diff options
author | jkim <jkim@FreeBSD.org> | 2005-11-01 22:11:18 +0000 |
---|---|---|
committer | jkim <jkim@FreeBSD.org> | 2005-11-01 22:11:18 +0000 |
commit | 5f6a2493ddea1cf36a4dcd58b865c4148427e0a2 (patch) | |
tree | 4450b2c84d749dd8a8425a8feb88b084809f6ef0 /sys/contrib/dev/acpica/rscalc.c | |
parent | 50133a977cb75b3f52603d4b351a8cf45bb556c8 (diff) | |
download | FreeBSD-src-5f6a2493ddea1cf36a4dcd58b865c4148427e0a2.zip FreeBSD-src-5f6a2493ddea1cf36a4dcd58b865c4148427e0a2.tar.gz |
Vendor import of Intel ACPI-CA 20051021
Diffstat (limited to 'sys/contrib/dev/acpica/rscalc.c')
-rw-r--r-- | sys/contrib/dev/acpica/rscalc.c | 909 |
1 files changed, 362 insertions, 547 deletions
diff --git a/sys/contrib/dev/acpica/rscalc.c b/sys/contrib/dev/acpica/rscalc.c index 00e633a..3c33c6a 100644 --- a/sys/contrib/dev/acpica/rscalc.c +++ b/sys/contrib/dev/acpica/rscalc.c @@ -1,7 +1,7 @@ /******************************************************************************* * * Module Name: rscalc - Calculate stream and list lengths - * $Revision: 52 $ + * $Revision: 1.66 $ * ******************************************************************************/ @@ -9,7 +9,7 @@ * * 1. Copyright Notice * - * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp. + * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp. * All rights reserved. * * 2. License @@ -125,679 +125,492 @@ ACPI_MODULE_NAME ("rscalc") +/* Local prototypes */ + +static UINT8 +AcpiRsCountSetBits ( + UINT16 BitField); + +static ACPI_RS_LENGTH +AcpiRsStructOptionLength ( + ACPI_RESOURCE_SOURCE *ResourceSource); + +static UINT32 +AcpiRsStreamOptionLength ( + UINT32 ResourceLength, + UINT32 MinimumTotalLength); + + /******************************************************************************* * - * FUNCTION: AcpiRsGetByteStreamLength + * FUNCTION: AcpiRsCountSetBits * - * PARAMETERS: LinkedList - Pointer to the resource linked list - * SizeNeeded - UINT32 pointer of the size buffer needed - * to properly return the parsed data + * PARAMETERS: BitField - Field in which to count bits * - * RETURN: Status + * RETURN: Number of bits set within the field * - * DESCRIPTION: Takes the resource byte stream and parses it once, calculating - * the size buffer needed to hold the linked list that conveys - * the resource data. + * DESCRIPTION: Count the number of bits set in a resource field. Used for + * (Short descriptor) interrupt and DMA lists. * ******************************************************************************/ -ACPI_STATUS -AcpiRsGetByteStreamLength ( - ACPI_RESOURCE *LinkedList, - ACPI_SIZE *SizeNeeded) +static UINT8 +AcpiRsCountSetBits ( + UINT16 BitField) { - ACPI_SIZE ByteStreamSizeNeeded = 0; - ACPI_SIZE SegmentSize; - BOOLEAN Done = FALSE; + UINT8 BitsSet; - ACPI_FUNCTION_TRACE ("RsGetByteStreamLength"); + ACPI_FUNCTION_ENTRY (); - while (!Done) + for (BitsSet = 0; BitField; BitsSet++) { - /* - * Init the variable that will hold the size to add to the total. - */ - SegmentSize = 0; + /* Zero the least significant bit that is set */ - switch (LinkedList->Id) - { - case ACPI_RSTYPE_IRQ: - /* - * IRQ Resource - * For an IRQ Resource, Byte 3, although optional, will always be - * created - it holds IRQ information. - */ - SegmentSize = 4; - break; - - case ACPI_RSTYPE_DMA: - /* - * DMA Resource - * For this resource the size is static - */ - SegmentSize = 3; - break; - - case ACPI_RSTYPE_START_DPF: - /* - * Start Dependent Functions Resource - * For a StartDependentFunctions Resource, Byte 1, although - * optional, will always be created. - */ - SegmentSize = 2; - break; - - case ACPI_RSTYPE_END_DPF: - /* - * End Dependent Functions Resource - * For this resource the size is static - */ - SegmentSize = 1; - break; - - case ACPI_RSTYPE_IO: - /* - * IO Port Resource - * For this resource the size is static - */ - SegmentSize = 8; - break; - - case ACPI_RSTYPE_FIXED_IO: - /* - * Fixed IO Port Resource - * For this resource the size is static - */ - SegmentSize = 4; - break; + BitField &= (BitField - 1); + } - case ACPI_RSTYPE_VENDOR: - /* - * 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. - */ - if (LinkedList->Data.VendorSpecific.Length > 7) - { - SegmentSize = 3; - } - else - { - SegmentSize = 1; - } - SegmentSize += LinkedList->Data.VendorSpecific.Length; - break; + return (BitsSet); +} - case ACPI_RSTYPE_END_TAG: - /* - * End Tag - * For this resource the size is static - */ - SegmentSize = 2; - Done = TRUE; - break; - case ACPI_RSTYPE_MEM24: - /* - * 24-Bit Memory Resource - * For this resource the size is static - */ - SegmentSize = 12; - break; +/******************************************************************************* + * + * FUNCTION: AcpiRsStructOptionLength + * + * PARAMETERS: ResourceSource - Pointer to optional descriptor field + * + * RETURN: Status + * + * DESCRIPTION: Common code to handle optional ResourceSourceIndex and + * ResourceSource fields in some Large descriptors. Used during + * list-to-stream conversion + * + ******************************************************************************/ - case ACPI_RSTYPE_MEM32: - /* - * 32-Bit Memory Range Resource - * For this resource the size is static - */ - SegmentSize = 20; - break; +static ACPI_RS_LENGTH +AcpiRsStructOptionLength ( + ACPI_RESOURCE_SOURCE *ResourceSource) +{ + ACPI_FUNCTION_ENTRY (); - case ACPI_RSTYPE_FIXED_MEM32: - /* - * 32-Bit Fixed Memory Resource - * For this resource the size is static - */ - SegmentSize = 12; - break; - case ACPI_RSTYPE_ADDRESS16: - /* - * 16-Bit Address Resource - * The base size of this byte stream is 16. If a Resource Source - * string is not NULL, add 1 for the Index + the length of the null - * terminated string Resource Source + 1 for the null. - */ - SegmentSize = 16; + /* + * If the ResourceSource string is valid, return the size of the string + * (StringLength includes the NULL terminator) plus the size of the + * ResourceSourceIndex (1). + */ + if (ResourceSource->StringPtr) + { + return ((ACPI_RS_LENGTH) (ResourceSource->StringLength + 1)); + } - if (LinkedList->Data.Address16.ResourceSource.StringPtr) - { - SegmentSize += LinkedList->Data.Address16.ResourceSource.StringLength; - SegmentSize++; - } - break; + return (0); +} - case ACPI_RSTYPE_ADDRESS32: - /* - * 32-Bit Address Resource - * The base size of this byte stream is 26. If a Resource - * Source string is not NULL, add 1 for the Index + the - * length of the null terminated string Resource Source + - * 1 for the null. - */ - SegmentSize = 26; - if (LinkedList->Data.Address32.ResourceSource.StringPtr) - { - SegmentSize += LinkedList->Data.Address32.ResourceSource.StringLength; - SegmentSize++; - } - break; - - case ACPI_RSTYPE_ADDRESS64: - /* - * 64-Bit Address Resource - * The base size of this byte stream is 46. If a ResourceSource - * string is not NULL, add 1 for the Index + the length of the null - * terminated string Resource Source + 1 for the null. - */ - SegmentSize = 46; +/******************************************************************************* + * + * FUNCTION: AcpiRsStreamOptionLength + * + * PARAMETERS: ResourceLength - Length from the resource header + * MinimumTotalLength - Minimum length of this resource, before + * any optional fields. Includes header size + * + * RETURN: Length of optional string (0 if no string present) + * + * DESCRIPTION: Common code to handle optional ResourceSourceIndex and + * ResourceSource fields in some Large descriptors. Used during + * stream-to-list conversion + * + ******************************************************************************/ - if (LinkedList->Data.Address64.ResourceSource.StringPtr) - { - SegmentSize += LinkedList->Data.Address64.ResourceSource.StringLength; - SegmentSize++; - } - break; +static UINT32 +AcpiRsStreamOptionLength ( + UINT32 ResourceLength, + UINT32 MinimumAmlResourceLength) +{ + UINT32 StringLength = 0; - case ACPI_RSTYPE_EXT_IRQ: - /* - * Extended IRQ Resource - * The base size of this byte stream is 9. This is for an Interrupt - * table length of 1. For each additional interrupt, add 4. - * If a Resource Source string is not NULL, add 1 for the - * Index + the length of the null terminated string - * Resource Source + 1 for the null. - */ - SegmentSize = 9 + - (((ACPI_SIZE) LinkedList->Data.ExtendedIrq.NumberOfInterrupts - 1) * 4); - if (LinkedList->Data.ExtendedIrq.ResourceSource.StringPtr) - { - SegmentSize += LinkedList->Data.ExtendedIrq.ResourceSource.StringLength; - SegmentSize++; - } - break; + ACPI_FUNCTION_ENTRY (); - default: - /* - * If we get here, everything is out of sync, exit with error - */ - return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); - } /* switch (LinkedList->Id) */ + /* + * The ResourceSourceIndex and ResourceSource are optional elements of some + * Large-type resource descriptors. + */ - /* - * Update the total - */ - ByteStreamSizeNeeded += SegmentSize; + /* + * If the length of the actual resource descriptor is greater than the ACPI + * spec-defined minimum length, it means that a ResourceSourceIndex exists + * and is followed by a (required) null terminated string. The string length + * (including the null terminator) is the resource length minus the minimum + * length, minus one byte for the ResourceSourceIndex itself. + */ + if (ResourceLength > MinimumAmlResourceLength) + { + /* Compute the length of the optional string */ - /* - * Point to the next object - */ - LinkedList = ACPI_PTR_ADD (ACPI_RESOURCE, - LinkedList, LinkedList->Length); + StringLength = ResourceLength - MinimumAmlResourceLength - 1; } - /* - * This is the data the caller needs - */ - *SizeNeeded = ByteStreamSizeNeeded; - return_ACPI_STATUS (AE_OK); + /* Round up length to 32 bits for internal structure alignment */ + + return (ACPI_ROUND_UP_TO_32BITS (StringLength)); } /******************************************************************************* * - * FUNCTION: AcpiRsGetListLength + * FUNCTION: AcpiRsGetAmlLength * - * PARAMETERS: ByteStreamBuffer - Pointer to the resource byte stream - * ByteStreamBufferLength - Size of ByteStreamBuffer - * SizeNeeded - UINT32 pointer of the size buffer - * needed to properly return the - * parsed data + * PARAMETERS: Resource - Pointer to the resource linked list + * SizeNeeded - Where the required size is returned * * RETURN: Status * - * DESCRIPTION: Takes the resource byte stream and parses it once, calculating - * the size buffer needed to hold the linked list that conveys - * the resource data. + * DESCRIPTION: Takes a linked list of internal resource descriptors and + * calculates the size buffer needed to hold the corresponding + * external resource byte stream. * ******************************************************************************/ ACPI_STATUS -AcpiRsGetListLength ( - UINT8 *ByteStreamBuffer, - UINT32 ByteStreamBufferLength, +AcpiRsGetAmlLength ( + ACPI_RESOURCE *Resource, ACPI_SIZE *SizeNeeded) { - UINT32 BufferSize = 0; - UINT32 BytesParsed = 0; - UINT8 NumberOfInterrupts = 0; - UINT8 NumberOfChannels = 0; - UINT8 ResourceType; - UINT32 StructureSize; - UINT32 BytesConsumed; - UINT8 *Buffer; - UINT8 Temp8; - UINT16 Temp16; - UINT8 Index; - UINT8 AdditionalBytes; + ACPI_SIZE AmlSizeNeeded = 0; + ACPI_RS_LENGTH TotalSize; - ACPI_FUNCTION_TRACE ("RsGetListLength"); + ACPI_FUNCTION_TRACE ("RsGetAmlLength"); - while (BytesParsed < ByteStreamBufferLength) + /* Traverse entire list of internal resource descriptors */ + + while (Resource) { - /* - * The next byte in the stream is the resource type - */ - ResourceType = AcpiRsGetResourceType (*ByteStreamBuffer); + /* Validate the descriptor type */ - switch (ResourceType) + if (Resource->Type > ACPI_RESOURCE_TYPE_MAX) { - case ACPI_RDESC_TYPE_MEMORY_24: - /* - * 24-Bit Memory Resource - */ - BytesConsumed = 12; + return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); + } - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_MEM24); - break; + /* Get the base size of the (external stream) resource descriptor */ + TotalSize = AcpiGbl_AmlResourceSizes [Resource->Type]; - case ACPI_RDESC_TYPE_LARGE_VENDOR: + /* + * Augment the base size for descriptors with optional and/or + * variable-length fields + */ + switch (Resource->Type) + { + case ACPI_RESOURCE_TYPE_VENDOR: /* - * Vendor Defined Resource + * 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. */ - Buffer = ByteStreamBuffer; - ++Buffer; + if (Resource->Data.Vendor.ByteLength > 7) + { + /* Base size of a Large resource descriptor */ - ACPI_MOVE_16_TO_16 (&Temp16, Buffer); - BytesConsumed = Temp16 + 3; + TotalSize = sizeof (AML_RESOURCE_LARGE_HEADER); + } - /* - * Ensure a 32-bit boundary for the structure - */ - Temp16 = (UINT16) ACPI_ROUND_UP_TO_32BITS (Temp16); + /* Add the size of the vendor-specific data */ - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_VENDOR) + - (Temp16 * sizeof (UINT8)); + TotalSize = (ACPI_RS_LENGTH) + (TotalSize + Resource->Data.Vendor.ByteLength); break; - case ACPI_RDESC_TYPE_MEMORY_32: + case ACPI_RESOURCE_TYPE_END_TAG: /* - * 32-Bit Memory Range Resource + * End Tag: + * We are done -- return the accumulated total size. */ - BytesConsumed = 20; + *SizeNeeded = AmlSizeNeeded + TotalSize; - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_MEM32); - break; + /* Normal exit */ + + return_ACPI_STATUS (AE_OK); - case ACPI_RDESC_TYPE_FIXED_MEMORY_32: + case ACPI_RESOURCE_TYPE_ADDRESS16: /* - * 32-Bit Fixed Memory Resource + * 16-Bit Address Resource: + * Add the size of the optional ResourceSource info */ - BytesConsumed = 12; - - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_FIXED_MEM32); + TotalSize = (ACPI_RS_LENGTH) + (TotalSize + AcpiRsStructOptionLength ( + &Resource->Data.Address16.ResourceSource)); break; - case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE: + case ACPI_RESOURCE_TYPE_ADDRESS32: /* - * 64-Bit Address Resource + * 32-Bit Address Resource: + * Add the size of the optional ResourceSource info */ - Buffer = ByteStreamBuffer; - - ++Buffer; - ACPI_MOVE_16_TO_16 (&Temp16, Buffer); - - BytesConsumed = Temp16 + 3; + TotalSize = (ACPI_RS_LENGTH) + (TotalSize + AcpiRsStructOptionLength ( + &Resource->Data.Address32.ResourceSource)); + break; - /* - * Resource Source Index and Resource Source are optional elements. - * Check the length of the Bytestream. If it is greater than 43, - * that means that an Index exists and is followed by a null - * terminated string. Therefore, set the temp variable to the - * length minus the minimum byte stream length plus the byte for - * the Index to determine the size of the NULL terminated string. - */ - if (43 < Temp16) - { - Temp8 = (UINT8) (Temp16 - 44); - } - else - { - Temp8 = 0; - } + case ACPI_RESOURCE_TYPE_ADDRESS64: /* - * Ensure a 64-bit boundary for the structure + * 64-Bit Address Resource: + * Add the size of the optional ResourceSource info */ - Temp8 = (UINT8) ACPI_ROUND_UP_TO_64BITS (Temp8); - - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS64) + - (Temp8 * sizeof (UINT8)); + TotalSize = (ACPI_RS_LENGTH) + (TotalSize + AcpiRsStructOptionLength ( + &Resource->Data.Address64.ResourceSource)); break; - case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE: + case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: /* - * 32-Bit Address Resource + * Extended IRQ Resource: + * Add the size of each additional optional interrupt beyond the + * required 1 (4 bytes for each UINT32 interrupt number) */ - Buffer = ByteStreamBuffer; + TotalSize = (ACPI_RS_LENGTH) + (TotalSize + + ((Resource->Data.ExtendedIrq.InterruptCount - 1) * 4) + - ++Buffer; - ACPI_MOVE_16_TO_16 (&Temp16, Buffer); + /* Add the size of the optional ResourceSource info */ - BytesConsumed = Temp16 + 3; - - /* - * Resource Source Index and Resource Source are optional elements. - * Check the length of the Bytestream. If it is greater than 23, - * that means that an Index exists and is followed by a null - * terminated string. Therefore, set the temp variable to the - * length minus the minimum byte stream length plus the byte for - * the Index to determine the size of the NULL terminated string. - */ - if (23 < Temp16) - { - Temp8 = (UINT8) (Temp16 - 24); - } - else - { - Temp8 = 0; - } + AcpiRsStructOptionLength ( + &Resource->Data.ExtendedIrq.ResourceSource)); + break; - /* - * Ensure a 32-bit boundary for the structure - */ - Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8); - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS32) + - (Temp8 * sizeof (UINT8)); + default: break; + } + /* Update the total */ - case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE: - /* - * 16-Bit Address Resource - */ - Buffer = ByteStreamBuffer; - - ++Buffer; - ACPI_MOVE_16_TO_16 (&Temp16, Buffer); + AmlSizeNeeded += TotalSize; - BytesConsumed = Temp16 + 3; + /* Point to the next object */ - /* - * Resource Source Index and Resource Source are optional elements. - * Check the length of the Bytestream. If it is greater than 13, - * that means that an Index exists and is followed by a null - * terminated string. Therefore, set the temp variable to the - * length minus the minimum byte stream length plus the byte for - * the Index to determine the size of the NULL terminated string. - */ - if (13 < Temp16) - { - Temp8 = (UINT8) (Temp16 - 14); - } - else - { - Temp8 = 0; - } + Resource = ACPI_PTR_ADD (ACPI_RESOURCE, + Resource, Resource->Length); + } - /* - * Ensure a 32-bit boundary for the structure - */ - Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8); + /* Did not find an END_TAG descriptor */ - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS16) + - (Temp8 * sizeof (UINT8)); - break; + return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); +} - case ACPI_RDESC_TYPE_EXTENDED_XRUPT: - /* - * Extended IRQ - */ - Buffer = ByteStreamBuffer; +/******************************************************************************* + * + * 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. + * + ******************************************************************************/ - ++Buffer; - ACPI_MOVE_16_TO_16 (&Temp16, Buffer); +ACPI_STATUS +AcpiRsGetListLength ( + UINT8 *AmlBuffer, + UINT32 AmlBufferLength, + ACPI_SIZE *SizeNeeded) +{ + UINT8 *Buffer; + ACPI_RESOURCE_INFO *ResourceInfo; + UINT32 BufferSize = 0; + UINT32 BytesParsed = 0; + UINT8 ResourceType; + UINT16 Temp16; + UINT16 ResourceLength; + UINT16 HeaderLength; + UINT32 ExtraStructBytes; - BytesConsumed = Temp16 + 3; - /* - * Point past the length field and the Interrupt vector flags to - * save off the Interrupt table length to the Temp8 variable. - */ - Buffer += 3; - Temp8 = *Buffer; + ACPI_FUNCTION_TRACE ("RsGetListLength"); - /* - * To compensate for multiple interrupt numbers, add 4 bytes for - * each additional interrupts greater than 1 - */ - AdditionalBytes = (UINT8) ((Temp8 - 1) * 4); - /* - * Resource Source Index and Resource Source are optional elements. - * Check the length of the Bytestream. If it is greater than 9, - * that means that an Index exists and is followed by a null - * terminated string. Therefore, set the temp variable to the - * length minus the minimum byte stream length plus the byte for - * the Index to determine the size of the NULL terminated string. - */ - if (9 + AdditionalBytes < Temp16) - { - Temp8 = (UINT8) (Temp16 - (9 + AdditionalBytes)); - } - else - { - Temp8 = 0; - } + while (BytesParsed < AmlBufferLength) + { + /* The next byte in the stream is the resource descriptor type */ - /* - * Ensure a 32-bit boundary for the structure - */ - Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8); + ResourceType = AcpiUtGetResourceType (AmlBuffer); - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_EXT_IRQ) + - (AdditionalBytes * sizeof (UINT8)) + - (Temp8 * sizeof (UINT8)); - break; + /* Get the base stream size and structure sizes for the descriptor */ + ResourceInfo = AcpiRsGetResourceInfo (ResourceType); + if (!ResourceInfo) + { + return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); + } - case ACPI_RDESC_TYPE_IRQ_FORMAT: - /* - * IRQ Resource. - * Determine if it there are two or three trailing bytes - */ - Buffer = ByteStreamBuffer; - Temp8 = *Buffer; + /* Get the Length field from the input resource descriptor */ - if(Temp8 & 0x01) - { - BytesConsumed = 4; - } - else - { - BytesConsumed = 3; - } + ResourceLength = AcpiUtGetResourceLength (AmlBuffer); - /* Point past the descriptor */ + /* Augment the size for descriptors with optional fields */ - ++Buffer; + ExtraStructBytes = 0; + if (!(ResourceType & ACPI_RESOURCE_NAME_LARGE)) + { /* - * Look at the number of bits set + * Small resource descriptors */ - ACPI_MOVE_16_TO_16 (&Temp16, Buffer); + HeaderLength = sizeof (AML_RESOURCE_SMALL_HEADER); + Buffer = AmlBuffer + HeaderLength; - for (Index = 0; Index < 16; Index++) + switch (ResourceType) { - if (Temp16 & 0x1) - { - ++NumberOfInterrupts; - } - - Temp16 >>= 1; - } + case ACPI_RESOURCE_NAME_IRQ: + /* + * IRQ Resource: + * Get the number of bits set in the IRQ word + */ + ACPI_MOVE_16_TO_16 (&Temp16, Buffer); + ExtraStructBytes = (AcpiRsCountSetBits (Temp16) * + sizeof (UINT32)); + break; - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IO) + - (NumberOfInterrupts * sizeof (UINT32)); - break; + case ACPI_RESOURCE_NAME_DMA: + /* + * DMA Resource: + * Get the number of bits set in the DMA channels byte + */ + ACPI_MOVE_16_TO_16 (&Temp16, Buffer); + ExtraStructBytes = (AcpiRsCountSetBits (Temp16) * + sizeof (UINT32)); + break; - case ACPI_RDESC_TYPE_DMA_FORMAT: - /* - * DMA Resource - */ - Buffer = ByteStreamBuffer; - BytesConsumed = 3; - /* Point past the descriptor */ + case ACPI_RESOURCE_NAME_VENDOR_SMALL: + /* + * Vendor Specific Resource: + * Ensure a 32-bit boundary for the structure + */ + ExtraStructBytes = ACPI_ROUND_UP_TO_32BITS (ResourceLength); + break; - ++Buffer; - /* - * Look at the number of bits set - */ - Temp8 = *Buffer; + case ACPI_RESOURCE_NAME_END_TAG: + /* + * End Tag: + * Terminate the loop now + */ + AmlBufferLength = BytesParsed; + break; - for(Index = 0; Index < 8; Index++) - { - if(Temp8 & 0x1) - { - ++NumberOfChannels; - } - Temp8 >>= 1; + default: + break; } - - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_DMA) + - (NumberOfChannels * sizeof (UINT32)); - break; - - - case ACPI_RDESC_TYPE_START_DEPENDENT: + } + else + { /* - * Start Dependent Functions Resource - * Determine if it there are two or three trailing bytes + * Large resource descriptors */ - Buffer = ByteStreamBuffer; - Temp8 = *Buffer; + HeaderLength = sizeof (AML_RESOURCE_LARGE_HEADER); + Buffer = AmlBuffer + HeaderLength; - if(Temp8 & 0x01) - { - BytesConsumed = 2; - } - else + switch (ResourceType) { - BytesConsumed = 1; - } - - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_START_DPF); - break; - - - case ACPI_RDESC_TYPE_END_DEPENDENT: - /* - * End Dependent Functions Resource - */ - BytesConsumed = 1; - StructureSize = ACPI_RESOURCE_LENGTH; - break; - + case ACPI_RESOURCE_NAME_VENDOR_LARGE: + /* + * Vendor Defined Resource: + * Add vendor data and ensure a 32-bit boundary for the structure + */ + ExtraStructBytes = ACPI_ROUND_UP_TO_32BITS (ResourceLength); + break; - case ACPI_RDESC_TYPE_IO_PORT: - /* - * IO Port Resource - */ - BytesConsumed = 8; - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IO); - break; + case ACPI_RESOURCE_NAME_ADDRESS32: + case ACPI_RESOURCE_NAME_ADDRESS16: + /* + * 32-Bit or 16-bit Address Resource: + * Add the size of any optional data (ResourceSource) + */ + ExtraStructBytes = AcpiRsStreamOptionLength (ResourceLength, + ResourceInfo->MinimumAmlResourceLength); + break; - case ACPI_RDESC_TYPE_FIXED_IO_PORT: - /* - * Fixed IO Port Resource - */ - BytesConsumed = 4; - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_FIXED_IO); - break; + case ACPI_RESOURCE_NAME_EXTENDED_IRQ: + /* + * Extended IRQ: + * Point past the InterruptVectorFlags to get the + * InterruptTableLength. + */ + Buffer++; - case ACPI_RDESC_TYPE_SMALL_VENDOR: - /* - * Vendor Specific Resource - */ - Buffer = ByteStreamBuffer; + /* + * Add 4 bytes for each additional interrupt. Note: at least one + * interrupt is required and is included in the minimum + * descriptor size + */ + ExtraStructBytes = ((*Buffer - 1) * sizeof (UINT32)); - Temp8 = *Buffer; - Temp8 = (UINT8) (Temp8 & 0x7); - BytesConsumed = Temp8 + 1; + /* Add the size of any optional data (ResourceSource) */ - /* - * Ensure a 32-bit boundary for the structure - */ - Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8); - StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_VENDOR) + - (Temp8 * sizeof (UINT8)); - break; + ExtraStructBytes += AcpiRsStreamOptionLength ( + ResourceLength - ExtraStructBytes, + ResourceInfo->MinimumAmlResourceLength); + break; - case ACPI_RDESC_TYPE_END_TAG: - /* - * End Tag - */ - BytesConsumed = 2; - StructureSize = ACPI_RESOURCE_LENGTH; - ByteStreamBufferLength = BytesParsed; - break; + case ACPI_RESOURCE_NAME_ADDRESS64: + /* + * 64-Bit Address Resource: + * Add the size of any optional data (ResourceSource) + * Ensure a 64-bit boundary for the structure + */ + ExtraStructBytes = ACPI_ROUND_UP_TO_64BITS ( + AcpiRsStreamOptionLength (ResourceLength, + ResourceInfo->MinimumAmlResourceLength)); + break; - default: - /* - * If we get here, everything is out of sync, - * exit with an error - */ - return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE); + default: + break; + } } - /* - * Update the return value and counter - */ - BufferSize += (UINT32) ACPI_ALIGN_RESOURCE_SIZE (StructureSize); - BytesParsed += BytesConsumed; + /* Update the required buffer size for the internal descriptor structs */ + + Temp16 = (UINT16) (ResourceInfo->MinimumInternalStructLength + ExtraStructBytes); + BufferSize += (UINT32) ACPI_ALIGN_RESOURCE_SIZE (Temp16); /* - * Set the byte stream to point to the next resource + * Update byte count and point to the next resource within the stream + * using the size of the header plus the length contained in the header */ - ByteStreamBuffer += BytesConsumed; + Temp16 = (UINT16) (HeaderLength + ResourceLength); + BytesParsed += Temp16; + AmlBuffer += Temp16; } - /* - * This is the data the caller needs - */ + /* This is the data the caller needs */ + *SizeNeeded = BufferSize; return_ACPI_STATUS (AE_OK); } @@ -854,9 +667,8 @@ AcpiRsGetPciRoutingTableLength ( for (Index = 0; Index < NumberOfElements; Index++) { - /* - * Dereference the sub-package - */ + /* Dereference the sub-package */ + PackageElement = *TopObjectList; /* @@ -865,33 +677,35 @@ AcpiRsGetPciRoutingTableLength ( */ SubObjectList = PackageElement->Package.Elements; - /* - * Scan the IrqTableElements for the Source Name String - */ + /* Scan the IrqTableElements for the Source Name String */ + NameFound = FALSE; for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++) { - if ((ACPI_TYPE_STRING == ACPI_GET_OBJECT_TYPE (*SubObjectList)) || - ((ACPI_TYPE_LOCAL_REFERENCE == ACPI_GET_OBJECT_TYPE (*SubObjectList)) && - ((*SubObjectList)->Reference.Opcode == AML_INT_NAMEPATH_OP))) + if ((ACPI_TYPE_STRING == + ACPI_GET_OBJECT_TYPE (*SubObjectList)) || + + ((ACPI_TYPE_LOCAL_REFERENCE == + ACPI_GET_OBJECT_TYPE (*SubObjectList)) && + + ((*SubObjectList)->Reference.Opcode == + AML_INT_NAMEPATH_OP))) { NameFound = TRUE; } else { - /* - * Look at the next element - */ + /* Look at the next element */ + SubObjectList++; } } TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4); - /* - * Was a String type found? - */ + /* Was a String type found? */ + if (NameFound) { if (ACPI_GET_OBJECT_TYPE (*SubObjectList) == ACPI_TYPE_STRING) @@ -900,7 +714,8 @@ AcpiRsGetPciRoutingTableLength ( * The length String.Length field does not include the * terminating NULL, add 1 */ - TempSizeNeeded += ((ACPI_SIZE) (*SubObjectList)->String.Length + 1); + TempSizeNeeded += ((ACPI_SIZE) + (*SubObjectList)->String.Length + 1); } else { @@ -921,14 +736,14 @@ AcpiRsGetPciRoutingTableLength ( TempSizeNeeded = ACPI_ROUND_UP_TO_64BITS (TempSizeNeeded); - /* - * Point to the next ACPI_OPERAND_OBJECT - */ + /* Point to the next ACPI_OPERAND_OBJECT */ + TopObjectList++; } /* - * Adding an extra element to the end of the list, essentially a NULL terminator + * Adding an extra element to the end of the list, essentially a + * NULL terminator */ *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE); return_ACPI_STATUS (AE_OK); |