示例#1
0
void
AcpiRsSetResourceLength (
    ACPI_RSDESC_SIZE        TotalLength,
    AML_RESOURCE            *Aml)
{
    ACPI_RS_LENGTH          ResourceLength;


    ACPI_FUNCTION_ENTRY ();


    /* Length is the total descriptor length minus the header length */

    ResourceLength = (ACPI_RS_LENGTH)
        (TotalLength - AcpiUtGetResourceHeaderLength (Aml));

    /* Length is stored differently for large and small descriptors */

    if (Aml->SmallHeader.DescriptorType & ACPI_RESOURCE_NAME_LARGE)
    {
        /* Large descriptor -- bytes 1-2 contain the 16-bit length */

        ACPI_MOVE_16_TO_16 (&Aml->LargeHeader.ResourceLength, &ResourceLength);
    }
    else
    {
        /* Small descriptor -- bits 2:0 of byte 0 contain the length */

        Aml->SmallHeader.DescriptorType = (UINT8)

            /* Clear any existing length, preserving descriptor type bits */

            ((Aml->SmallHeader.DescriptorType & ~ACPI_RESOURCE_NAME_SMALL_LENGTH_MASK)

            | ResourceLength);
    }
}
示例#2
0
文件: rsutils.c 项目: rodero95/sys
void
AcpiRsMoveData (
    void                    *Destination,
    void                    *Source,
    UINT16                  ItemCount,
    UINT8                   MoveType)
{
    UINT32                  i;


    ACPI_FUNCTION_ENTRY ();


    /* One move per item */

    for (i = 0; i < ItemCount; i++)
    {
        switch (MoveType)
        {
        /*
         * For the 8-bit case, we can perform the move all at once
         * since there are no alignment or endian issues
         */
        case ACPI_RSC_MOVE8:
        case ACPI_RSC_MOVE_GPIO_RES:
        case ACPI_RSC_MOVE_SERIAL_VEN:
        case ACPI_RSC_MOVE_SERIAL_RES:

            ACPI_MEMCPY (Destination, Source, ItemCount);
            return;

        /*
         * 16-, 32-, and 64-bit cases must use the move macros that perform
         * endian conversion and/or accommodate hardware that cannot perform
         * misaligned memory transfers
         */
        case ACPI_RSC_MOVE16:
        case ACPI_RSC_MOVE_GPIO_PIN:

            ACPI_MOVE_16_TO_16 (&ACPI_CAST_PTR (UINT16, Destination)[i],
                                &ACPI_CAST_PTR (UINT16, Source)[i]);
            break;

        case ACPI_RSC_MOVE32:
            
            ACPI_MOVE_32_TO_32 (&ACPI_CAST_PTR (UINT32, Destination)[i],
                                &ACPI_CAST_PTR (UINT32, Source)[i]);
            break;

        case ACPI_RSC_MOVE64:

            ACPI_MOVE_64_TO_64 (&ACPI_CAST_PTR (UINT64, Destination)[i],
                                &ACPI_CAST_PTR (UINT64, Source)[i]);
            break;

        default:

            return;
        }
    }
}
示例#3
0
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;


    ACPI_FUNCTION_TRACE (RsGetListLength);


    *SizeNeeded = 0;
    EndAml = AmlBuffer + AmlBufferLength;

    /* Walk the list of AML resource descriptors */

    while (AmlBuffer < EndAml)
    {
        /* Validate the Resource Type and Resource Length */

        Status = AcpiUtValidateResource (AmlBuffer, &ResourceIndex);
        if (ACPI_FAILURE (Status))
        {
            return_ACPI_STATUS (Status);
        }

        /* Get the resource length and base (minimum) AML size */

        ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
        MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];

        /*
         * Augment the size for descriptors with optional
         * and/or variable length fields
         */
        ExtraStructBytes = 0;
        Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);

        switch (AcpiUtGetResourceType (AmlBuffer))
        {
        case ACPI_RESOURCE_NAME_IRQ:
            /*
             * IRQ Resource:
             * Get the number of bits set in the 16-bit IRQ mask
             */
            ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
            ExtraStructBytes = AcpiRsCountSetBits (Temp16);
            break;


        case ACPI_RESOURCE_NAME_DMA:
            /*
             * DMA Resource:
             * Get the number of bits set in the 8-bit DMA mask
             */
            ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
            break;


        case ACPI_RESOURCE_NAME_VENDOR_SMALL:
        case ACPI_RESOURCE_NAME_VENDOR_LARGE:
            /*
             * Vendor Resource:
             * Get the number of vendor data bytes
             */
            ExtraStructBytes = ResourceLength;
            break;


        case ACPI_RESOURCE_NAME_END_TAG:
            /*
             * End Tag:
             * This is the normal exit, add size of EndTag
             */
            *SizeNeeded += ACPI_RS_SIZE_MIN;
            return_ACPI_STATUS (AE_OK);


        case ACPI_RESOURCE_NAME_ADDRESS32:
        case ACPI_RESOURCE_NAME_ADDRESS16:
        case ACPI_RESOURCE_NAME_ADDRESS64:
            /*
             * Address Resource:
             * Add the size of the optional ResourceSource
             */
            ExtraStructBytes = AcpiRsStreamOptionLength (
                ResourceLength, MinimumAmlResourceLength);
            break;


        case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
            /*
             * 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)
             */
            ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);

            /* Add the size of the optional ResourceSource */

            ExtraStructBytes += AcpiRsStreamOptionLength (
                ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
            break;


        default:
            break;
        }

        /*
         * 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.
         */
        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));

        /*
         * Point to the next resource within the AML stream using the length
         * contained in the resource descriptor header
         */
        AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
    }

    /* Did not find an EndTag resource descriptor */

    return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
}
示例#4
0
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;         /* Minimum size is one EndTag */
    EndAml = AmlBuffer + AmlBufferLength;

    /* Walk the list of AML resource descriptors */

    while (AmlBuffer < EndAml)
    {
        /* Validate the Resource Type and Resource Length */

        Status = AcpiUtValidateResource (NULL, AmlBuffer, &ResourceIndex);
        if (ACPI_FAILURE (Status))
        {
            /*
             * Exit on failure. Cannot continue because the descriptor length
             * may be bogus also.
             */
            return_ACPI_STATUS (Status);
        }

        AmlResource = (void *) AmlBuffer;

        /* Get the resource length and base (minimum) AML size */

        ResourceLength = AcpiUtGetResourceLength (AmlBuffer);
        MinimumAmlResourceLength = AcpiGbl_ResourceAmlSizes[ResourceIndex];

        /*
         * Augment the size for descriptors with optional
         * and/or variable length fields
         */
        ExtraStructBytes = 0;
        Buffer = AmlBuffer + AcpiUtGetResourceHeaderLength (AmlBuffer);

        switch (AcpiUtGetResourceType (AmlBuffer))
        {
        case ACPI_RESOURCE_NAME_IRQ:
            /*
             * IRQ Resource:
             * Get the number of bits set in the 16-bit IRQ mask
             */
            ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
            ExtraStructBytes = AcpiRsCountSetBits (Temp16);
            break;


        case ACPI_RESOURCE_NAME_DMA:
            /*
             * DMA Resource:
             * Get the number of bits set in the 8-bit DMA mask
             */
            ExtraStructBytes = AcpiRsCountSetBits (*Buffer);
            break;


        case ACPI_RESOURCE_NAME_VENDOR_SMALL:
        case ACPI_RESOURCE_NAME_VENDOR_LARGE:
            /*
             * Vendor Resource:
             * Get the number of vendor data bytes
             */
            ExtraStructBytes = ResourceLength;

            /*
             * There is already one byte included in the minimum
             * descriptor size. If there are extra struct bytes,
             * subtract one from the count.
             */
            if (ExtraStructBytes)
            {
                ExtraStructBytes--;
            }
            break;


        case ACPI_RESOURCE_NAME_END_TAG:
            /*
             * End Tag: This is the normal exit
             */
            return_ACPI_STATUS (AE_OK);


        case ACPI_RESOURCE_NAME_ADDRESS32:
        case ACPI_RESOURCE_NAME_ADDRESS16:
        case ACPI_RESOURCE_NAME_ADDRESS64:
            /*
             * Address Resource:
             * Add the size of the optional ResourceSource
             */
            ExtraStructBytes = AcpiRsStreamOptionLength (
                ResourceLength, MinimumAmlResourceLength);
            break;


        case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
            /*
             * 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)
             */
            ExtraStructBytes = (Buffer[1] - 1) * sizeof (UINT32);

            /* Add the size of the optional ResourceSource */

            ExtraStructBytes += AcpiRsStreamOptionLength (
                ResourceLength - ExtraStructBytes, MinimumAmlResourceLength);
            break;

        case ACPI_RESOURCE_NAME_GPIO:

            /* Vendor data is optional */

            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;
        }

        /*
         * 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.
         */
        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));

        /*
         * Point to the next resource within the AML stream using the length
         * contained in the resource descriptor header
         */
        AmlBuffer += AcpiUtGetDescriptorLength (AmlBuffer);
    }

    /* Did not find an EndTag resource descriptor */

    return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
}
示例#5
0
文件: rscalc.c 项目: kzlin129/tt-gpl
acpi_status
acpi_rs_get_list_length (
	u8                              *byte_stream_buffer,
	u32                             byte_stream_buffer_length,
	acpi_size                       *size_needed)
{
	u32                             buffer_size = 0;
	u32                             bytes_parsed = 0;
	u8                              number_of_interrupts = 0;
	u8                              number_of_channels = 0;
	u8                              resource_type;
	u32                             structure_size;
	u32                             bytes_consumed;
	u8                              *buffer;
	u8                              temp8;
	u16                             temp16;
	u8                              index;
	u8                              additional_bytes;


	ACPI_FUNCTION_TRACE ("rs_get_list_length");


	while (bytes_parsed < byte_stream_buffer_length) {
		/* The next byte in the stream is the resource type */

		resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);

		switch (resource_type) {
		case ACPI_RDESC_TYPE_MEMORY_24:
			/*
			 * 24-Bit Memory Resource
			 */
			bytes_consumed = 12;

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem24);
			break;


		case ACPI_RDESC_TYPE_LARGE_VENDOR:
			/*
			 * Vendor Defined Resource
			 */
			buffer = byte_stream_buffer;
			++buffer;

			ACPI_MOVE_16_TO_16 (&temp16, buffer);
			bytes_consumed = temp16 + 3;

			/* Ensure a 32-bit boundary for the structure */

			temp16 = (u16) ACPI_ROUND_UP_to_32_bITS (temp16);

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) +
					   (temp16 * sizeof (u8));
			break;


		case ACPI_RDESC_TYPE_MEMORY_32:
			/*
			 * 32-Bit Memory Range Resource
			 */
			bytes_consumed = 20;

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem32);
			break;


		case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
			/*
			 * 32-Bit Fixed Memory Resource
			 */
			bytes_consumed = 12;

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_mem32);
			break;


		case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE:
			/*
			 * 64-Bit Address Resource
			 */
			buffer = byte_stream_buffer;

			++buffer;
			ACPI_MOVE_16_TO_16 (&temp16, buffer);

			bytes_consumed = temp16 + 3;
			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64);
			break;


		case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
			/*
			 * 64-Bit Address Resource
			 */
			buffer = byte_stream_buffer;

			++buffer;
			ACPI_MOVE_16_TO_16 (&temp16, buffer);

			bytes_consumed = temp16 + 3;

			/*
			 * 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 = (u8) (temp16 - 44);
			}
			else {
				temp8 = 0;
			}

			/* Ensure a 64-bit boundary for the structure */

			temp8 = (u8) ACPI_ROUND_UP_to_64_bITS (temp8);

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address64) +
					   (temp8 * sizeof (u8));
			break;


		case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
			/*
			 * 32-Bit Address Resource
			 */
			buffer = byte_stream_buffer;

			++buffer;
			ACPI_MOVE_16_TO_16 (&temp16, buffer);

			bytes_consumed = 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 = (u8) (temp16 - 24);
			}
			else {
				temp8 = 0;
			}

			/* Ensure a 32-bit boundary for the structure */

			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address32) +
					   (temp8 * sizeof (u8));
			break;


		case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
			/*
			 * 16-Bit Address Resource
			 */
			buffer = byte_stream_buffer;

			++buffer;
			ACPI_MOVE_16_TO_16 (&temp16, buffer);

			bytes_consumed = temp16 + 3;

			/*
			 * 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 = (u8) (temp16 - 14);
			}
			else {
				temp8 = 0;
			}

			/* Ensure a 32-bit boundary for the structure */

			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_address16) +
					   (temp8 * sizeof (u8));
			break;


		case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
			/*
			 * Extended IRQ
			 */
			buffer = byte_stream_buffer;

			++buffer;
			ACPI_MOVE_16_TO_16 (&temp16, buffer);

			bytes_consumed = 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;

			/*
			 * To compensate for multiple interrupt numbers, add 4 bytes for
			 * each additional interrupts greater than 1
			 */
			additional_bytes = (u8) ((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 + additional_bytes < temp16) {
				temp8 = (u8) (temp16 - (9 + additional_bytes));
			}
			else {
				temp8 = 0;
			}

			/* Ensure a 32-bit boundary for the structure */

			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_ext_irq) +
					   (additional_bytes * sizeof (u8)) +
					   (temp8 * sizeof (u8));
			break;


		case ACPI_RDESC_TYPE_IRQ_FORMAT:
			/*
			 * IRQ Resource.
			 * Determine if it there are two or three trailing bytes
			 */
			buffer = byte_stream_buffer;
			temp8 = *buffer;

			if(temp8 & 0x01) {
				bytes_consumed = 4;
			}
			else {
				bytes_consumed = 3;
			}

			/* Point past the descriptor */

			++buffer;

			/* Look at the number of bits set */

			ACPI_MOVE_16_TO_16 (&temp16, buffer);

			for (index = 0; index < 16; index++) {
				if (temp16 & 0x1) {
					++number_of_interrupts;
				}

				temp16 >>= 1;
			}

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_io) +
					   (number_of_interrupts * sizeof (u32));
			break;


		case ACPI_RDESC_TYPE_DMA_FORMAT:
			/*
			 * DMA Resource
			 */
			buffer = byte_stream_buffer;
			bytes_consumed = 3;

			/* Point past the descriptor */

			++buffer;

			/* Look at the number of bits set */

			temp8 = *buffer;

			for(index = 0; index < 8; index++) {
				if(temp8 & 0x1) {
					++number_of_channels;
				}

				temp8 >>= 1;
			}

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_dma) +
					   (number_of_channels * sizeof (u32));
			break;


		case ACPI_RDESC_TYPE_START_DEPENDENT:
			/*
			 * Start Dependent Functions Resource
			 * Determine if it there are two or three trailing bytes
			 */
			buffer = byte_stream_buffer;
			temp8 = *buffer;

			if(temp8 & 0x01) {
				bytes_consumed = 2;
			}
			else {
				bytes_consumed = 1;
			}

			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_start_dpf);
			break;


		case ACPI_RDESC_TYPE_END_DEPENDENT:
			/*
			 * End Dependent Functions Resource
			 */
			bytes_consumed = 1;
			structure_size = ACPI_RESOURCE_LENGTH;
			break;


		case ACPI_RDESC_TYPE_IO_PORT:
			/*
			 * IO Port Resource
			 */
			bytes_consumed = 8;
			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_io);
			break;


		case ACPI_RDESC_TYPE_FIXED_IO_PORT:
			/*
			 * Fixed IO Port Resource
			 */
			bytes_consumed = 4;
			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_fixed_io);
			break;


		case ACPI_RDESC_TYPE_SMALL_VENDOR:
			/*
			 * Vendor Specific Resource
			 */
			buffer = byte_stream_buffer;

			temp8 = *buffer;
			temp8 = (u8) (temp8 & 0x7);
			bytes_consumed = temp8 + 1;

			/* Ensure a 32-bit boundary for the structure */

			temp8 = (u8) ACPI_ROUND_UP_to_32_bITS (temp8);
			structure_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_vendor) +
					   (temp8 * sizeof (u8));
			break;


		case ACPI_RDESC_TYPE_END_TAG:
			/*
			 * End Tag
			 */
			bytes_consumed = 2;
			structure_size = ACPI_RESOURCE_LENGTH;
			byte_stream_buffer_length = bytes_parsed;
			break;


		default:
			/*
			 * If we get here, everything is out of sync,
			 * exit with an error
			 */
			return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
		}

		/* Update the return value and counter */

		buffer_size += (u32) ACPI_ALIGN_RESOURCE_SIZE (structure_size);
		bytes_parsed += bytes_consumed;

		/* Set the byte stream to point to the next resource */

		byte_stream_buffer += bytes_consumed;
	}

	/* This is the data the caller needs */

	*size_needed = buffer_size;
	return_ACPI_STATUS (AE_OK);
}
示例#6
0
文件: rscalc.c 项目: PyroOS/Pyro
acpi_status
acpi_rs_get_list_length(u8 * aml_buffer,
			u32 aml_buffer_length, acpi_size * size_needed)
{
	acpi_status status;
	u8 *end_aml;
	u8 *buffer;
	u32 buffer_size;
	u16 temp16;
	u16 resource_length;
	u32 extra_struct_bytes;
	u8 resource_index;
	u8 minimum_aml_resource_length;

	ACPI_FUNCTION_TRACE(rs_get_list_length);

	*size_needed = 0;
	end_aml = aml_buffer + aml_buffer_length;

	/* Walk the list of AML resource descriptors */

	while (aml_buffer < end_aml) {

		/* Validate the Resource Type and Resource Length */

		status = acpi_ut_validate_resource(aml_buffer, &resource_index);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
		}

		/* Get the resource length and base (minimum) AML size */

		resource_length = acpi_ut_get_resource_length(aml_buffer);
		minimum_aml_resource_length =
		    acpi_gbl_resource_aml_sizes[resource_index];

		/*
		 * Augment the size for descriptors with optional
		 * and/or variable length fields
		 */
		extra_struct_bytes = 0;
		buffer =
		    aml_buffer + acpi_ut_get_resource_header_length(aml_buffer);

		switch (acpi_ut_get_resource_type(aml_buffer)) {
		case ACPI_RESOURCE_NAME_IRQ:
			/*
			 * IRQ Resource:
			 * Get the number of bits set in the 16-bit IRQ mask
			 */
			ACPI_MOVE_16_TO_16(&temp16, buffer);
			extra_struct_bytes = acpi_rs_count_set_bits(temp16);
			break;

		case ACPI_RESOURCE_NAME_DMA:
			/*
			 * DMA Resource:
			 * Get the number of bits set in the 8-bit DMA mask
			 */
			extra_struct_bytes = acpi_rs_count_set_bits(*buffer);
			break;

		case ACPI_RESOURCE_NAME_VENDOR_SMALL:
		case ACPI_RESOURCE_NAME_VENDOR_LARGE:
			/*
			 * Vendor Resource:
			 * Get the number of vendor data bytes
			 */
			extra_struct_bytes = resource_length;
			break;

		case ACPI_RESOURCE_NAME_END_TAG:
			/*
			 * End Tag:
			 * This is the normal exit, add size of end_tag
			 */
			*size_needed += ACPI_RS_SIZE_MIN;
			return_ACPI_STATUS(AE_OK);

		case ACPI_RESOURCE_NAME_ADDRESS32:
		case ACPI_RESOURCE_NAME_ADDRESS16:
		case ACPI_RESOURCE_NAME_ADDRESS64:
			/*
			 * Address Resource:
			 * Add the size of the optional resource_source
			 */
			extra_struct_bytes =
			    acpi_rs_stream_option_length(resource_length,
							 minimum_aml_resource_length);
			break;

		case ACPI_RESOURCE_NAME_EXTENDED_IRQ:
			/*
			 * Extended IRQ Resource:
			 * Using the interrupt_table_length, 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)
			 */
			extra_struct_bytes = (buffer[1] - 1) * sizeof(u32);

			/* Add the size of the optional resource_source */

			extra_struct_bytes +=
			    acpi_rs_stream_option_length(resource_length -
							 extra_struct_bytes,
							 minimum_aml_resource_length);
			break;

		default:
			break;
		}

		/*
		 * 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.
		 */
		buffer_size = acpi_gbl_resource_struct_sizes[resource_index] +
		    extra_struct_bytes;
		buffer_size = (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(buffer_size);

		*size_needed += buffer_size;

		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
				  "Type %.2X, AmlLength %.2X InternalLength %.2X\n",
				  acpi_ut_get_resource_type(aml_buffer),
				  acpi_ut_get_descriptor_length(aml_buffer),
				  buffer_size));

		/*
		 * Point to the next resource within the AML stream using the length
		 * contained in the resource descriptor header
		 */
		aml_buffer += acpi_ut_get_descriptor_length(aml_buffer);
	}

	/* Did not find an end_tag resource descriptor */

	return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
}
示例#7
0
acpi_status
acpi_rs_memory24_resource (
	u8                              *byte_stream_buffer,
	acpi_size                       *bytes_consumed,
	u8                              **output_buffer,
	acpi_size                       *structure_size)
{
	u8                              *buffer = byte_stream_buffer;
	struct acpi_resource            *output_struct = (void *) *output_buffer;
	u16                             temp16 = 0;
	u8                              temp8 = 0;
	acpi_size                       struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem24);


	ACPI_FUNCTION_TRACE ("rs_memory24_resource");


	/*
	 * Point past the Descriptor to get the number of bytes consumed
	 */
	buffer += 1;

	ACPI_MOVE_16_TO_16 (&temp16, buffer);
	buffer += 2;
	*bytes_consumed = (acpi_size) temp16 + 3;
	output_struct->id = ACPI_RSTYPE_MEM24;

	/*
	 * Check Byte 3 the Read/Write bit
	 */
	temp8 = *buffer;
	buffer += 1;
	output_struct->data.memory24.read_write_attribute = temp8 & 0x01;

	/*
	 * Get min_base_address (Bytes 4-5)
	 */
	ACPI_MOVE_16_TO_16 (&temp16, buffer);
	buffer += 2;
	output_struct->data.memory24.min_base_address = temp16;

	/*
	 * Get max_base_address (Bytes 6-7)
	 */
	ACPI_MOVE_16_TO_16 (&temp16, buffer);
	buffer += 2;
	output_struct->data.memory24.max_base_address = temp16;

	/*
	 * Get Alignment (Bytes 8-9)
	 */
	ACPI_MOVE_16_TO_16 (&temp16, buffer);
	buffer += 2;
	output_struct->data.memory24.alignment = temp16;

	/*
	 * Get range_length (Bytes 10-11)
	 */
	ACPI_MOVE_16_TO_16 (&temp16, buffer);
	output_struct->data.memory24.range_length = temp16;

	/*
	 * Set the Length parameter
	 */
	output_struct->length = (u32) struct_size;

	/*
	 * Return the final size of the structure
	 */
	*structure_size = struct_size;
	return_ACPI_STATUS (AE_OK);
}
示例#8
0
acpi_status
acpi_rs_memory32_range_stream (
	struct acpi_resource            *linked_list,
	u8                              **output_buffer,
	acpi_size                       *bytes_consumed)
{
	u8                              *buffer = *output_buffer;
	u16                             temp16 = 0;
	u8                              temp8 = 0;


	ACPI_FUNCTION_TRACE ("rs_memory32_range_stream");


	/*
	 * The descriptor field is static
	 */
	*buffer = 0x85;
	buffer += 1;

	/*
	 * The length field is static
	 */
	temp16 = 0x11;

	ACPI_MOVE_16_TO_16 (buffer, &temp16);
	buffer += 2;

	/*
	 * Set the Information Byte
	 */
	temp8 = (u8) (linked_list->data.memory32.read_write_attribute & 0x01);
	*buffer = temp8;
	buffer += 1;

	/*
	 * Set the Range minimum base address
	 */
	ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.min_base_address);
	buffer += 4;

	/*
	 * Set the Range maximum base address
	 */
	ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.max_base_address);
	buffer += 4;

	/*
	 * Set the base alignment
	 */
	ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.alignment);
	buffer += 4;

	/*
	 * Set the range length
	 */
	ACPI_MOVE_32_TO_32 (buffer, &linked_list->data.memory32.range_length);
	buffer += 4;

	/*
	 * Return the number of bytes consumed in this operation
	 */
	*bytes_consumed = ACPI_PTR_DIFF (buffer, *output_buffer);
	return_ACPI_STATUS (AE_OK);
}
示例#9
0
acpi_status
acpi_rs_memory32_range_resource (
	u8                              *byte_stream_buffer,
	acpi_size                       *bytes_consumed,
	u8                              **output_buffer,
	acpi_size                       *structure_size)
{
	u8                              *buffer = byte_stream_buffer;
	struct acpi_resource            *output_struct = (void *) *output_buffer;
	u16                             temp16 = 0;
	u8                              temp8 = 0;
	acpi_size                       struct_size = ACPI_SIZEOF_RESOURCE (struct acpi_resource_mem32);


	ACPI_FUNCTION_TRACE ("rs_memory32_range_resource");


	/*
	 * Point past the Descriptor to get the number of bytes consumed
	 */
	buffer += 1;

	ACPI_MOVE_16_TO_16 (&temp16, buffer);
	buffer += 2;
	*bytes_consumed = (acpi_size) temp16 + 3;

	output_struct->id = ACPI_RSTYPE_MEM32;

	/*
	 *  Point to the place in the output buffer where the data portion will
	 *  begin.
	 *  1. Set the RESOURCE_DATA * Data to point to its own address, then
	 *  2. Set the pointer to the next address.
	 *
	 *  NOTE: output_struct->Data is cast to u8, otherwise, this addition adds
	 *  4 * sizeof(RESOURCE_DATA) instead of 4 * sizeof(u8)
	 */

	/*
	 * Check Byte 3 the Read/Write bit
	 */
	temp8 = *buffer;
	buffer += 1;

	output_struct->data.memory32.read_write_attribute = temp8 & 0x01;

	/*
	 * Get min_base_address (Bytes 4-7)
	 */
	ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.min_base_address, buffer);
	buffer += 4;

	/*
	 * Get max_base_address (Bytes 8-11)
	 */
	ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.max_base_address, buffer);
	buffer += 4;

	/*
	 * Get Alignment (Bytes 12-15)
	 */
	ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.alignment, buffer);
	buffer += 4;

	/*
	 * Get range_length (Bytes 16-19)
	 */
	ACPI_MOVE_32_TO_32 (&output_struct->data.memory32.range_length, buffer);

	/*
	 * Set the Length parameter
	 */
	output_struct->length = (u32) struct_size;

	/*
	 * Return the final size of the structure
	 */
	*structure_size = struct_size;
	return_ACPI_STATUS (AE_OK);
}