diff options
Diffstat (limited to 'drivers/acpi/resources/rslist.c')
-rw-r--r-- | drivers/acpi/resources/rslist.c | 528 |
1 files changed, 106 insertions, 422 deletions
diff --git a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c index 103eb31c284e..e4778a51c17e 100644 --- a/drivers/acpi/resources/rslist.c +++ b/drivers/acpi/resources/rslist.c @@ -5,7 +5,7 @@ ******************************************************************************/ /* - * Copyright (C) 2000 - 2005, R. Byron Moore + * Copyright (C) 2000 - 2006, R. Byron Moore * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,52 +49,12 @@ ACPI_MODULE_NAME("rslist") /******************************************************************************* * - * FUNCTION: acpi_rs_get_resource_type + * FUNCTION: acpi_rs_convert_aml_to_resources * - * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor - * - * RETURN: The Resource Type with no extraneous bits - * - * DESCRIPTION: Extract the Resource Type/Name from the first byte of - * a resource descriptor. - * - ******************************************************************************/ -u8 acpi_rs_get_resource_type(u8 resource_start_byte) -{ - - ACPI_FUNCTION_ENTRY(); - - /* Determine if this is a small or large resource */ - - switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) { - case ACPI_RDESC_TYPE_SMALL: - - /* Small Resource Type -- Only bits 6:3 are valid */ - - return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK)); - - case ACPI_RDESC_TYPE_LARGE: - - /* Large Resource Type -- All bits are valid */ - - return (resource_start_byte); - - default: - /* Invalid type */ - break; - } - - return (0xFF); -} - -/******************************************************************************* - * - * FUNCTION: acpi_rs_byte_stream_to_list - * - * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream - * byte_stream_buffer_length - Length of byte_stream_buffer - * output_buffer - Pointer to the buffer that will - * contain the output structures + * PARAMETERS: Aml - Pointer to the resource byte stream + * aml_length - Length of Aml + * output_buffer - Pointer to the buffer that will + * contain the output structures * * RETURN: Status * @@ -102,241 +62,76 @@ u8 acpi_rs_get_resource_type(u8 resource_start_byte) * linked list of resources in the caller's output buffer * ******************************************************************************/ - acpi_status -acpi_rs_byte_stream_to_list(u8 * byte_stream_buffer, - u32 byte_stream_buffer_length, u8 * output_buffer) +acpi_rs_convert_aml_to_resources(u8 * aml, u32 aml_length, u8 * output_buffer) { + struct acpi_resource *resource = (void *)output_buffer; acpi_status status; - acpi_size bytes_parsed = 0; - u8 resource_type = 0; - acpi_size bytes_consumed = 0; - u8 *buffer = output_buffer; - acpi_size structure_size = 0; - u8 end_tag_processed = FALSE; - struct acpi_resource *resource; - - ACPI_FUNCTION_TRACE("rs_byte_stream_to_list"); - - while (bytes_parsed < byte_stream_buffer_length && !end_tag_processed) { - /* 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 - */ - status = acpi_rs_memory24_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_LARGE_VENDOR: - /* - * Vendor Defined Resource - */ - status = acpi_rs_vendor_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_MEMORY_32: - /* - * 32-Bit Memory Range Resource - */ - status = - acpi_rs_memory32_range_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_FIXED_MEMORY_32: - /* - * 32-Bit Fixed Memory Resource - */ - status = - acpi_rs_fixed_memory32_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE: - case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE: - /* - * 64-Bit Address Resource - */ - status = acpi_rs_address64_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE: - /* - * 32-Bit Address Resource - */ - status = acpi_rs_address32_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE: - /* - * 16-Bit Address Resource - */ - status = acpi_rs_address16_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_EXTENDED_XRUPT: - /* - * Extended IRQ - */ - status = - acpi_rs_extended_irq_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_IRQ_FORMAT: - /* - * IRQ Resource - */ - status = acpi_rs_irq_resource(byte_stream_buffer, - &bytes_consumed, &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_DMA_FORMAT: - /* - * DMA Resource - */ - status = acpi_rs_dma_resource(byte_stream_buffer, - &bytes_consumed, &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_START_DEPENDENT: - /* - * Start Dependent Functions Resource - */ - status = - acpi_rs_start_depend_fns_resource - (byte_stream_buffer, &bytes_consumed, &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_END_DEPENDENT: - /* - * End Dependent Functions Resource - */ - status = - acpi_rs_end_depend_fns_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_IO_PORT: - /* - * IO Port Resource - */ - status = acpi_rs_io_resource(byte_stream_buffer, - &bytes_consumed, &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_FIXED_IO_PORT: - /* - * Fixed IO Port Resource - */ - status = acpi_rs_fixed_io_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_SMALL_VENDOR: - /* - * Vendor Specific Resource - */ - status = acpi_rs_vendor_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - case ACPI_RDESC_TYPE_END_TAG: - /* - * End Tag - */ - end_tag_processed = TRUE; - status = acpi_rs_end_tag_resource(byte_stream_buffer, - &bytes_consumed, - &buffer, - &structure_size); - break; - - default: - /* - * Invalid/Unknown resource type - */ - status = AE_AML_INVALID_RESOURCE_TYPE; - break; - } + u8 resource_index; + u8 *end_aml; + + ACPI_FUNCTION_TRACE("rs_convert_aml_to_resources"); + end_aml = aml + aml_length; + + /* Loop until end-of-buffer or an end_tag is found */ + + while (aml < end_aml) { + /* Validate the Resource Type and Resource Length */ + + status = acpi_ut_validate_resource(aml, &resource_index); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } - /* Update the return value and counter */ + /* Convert the AML byte stream resource to a local resource struct */ - bytes_parsed += bytes_consumed; + status = + acpi_rs_convert_aml_to_resource(resource, + ACPI_CAST_PTR(union + aml_resource, + aml), + acpi_gbl_get_resource_dispatch + [resource_index]); + if (ACPI_FAILURE(status)) { + ACPI_REPORT_ERROR(("Could not convert AML resource (Type %X) to resource, %s\n", *aml, acpi_format_exception(status))); + return_ACPI_STATUS(status); + } - /* Set the byte stream to point to the next resource */ + /* Normal exit on completion of an end_tag resource descriptor */ - byte_stream_buffer += bytes_consumed; + if (acpi_ut_get_resource_type(aml) == + ACPI_RESOURCE_NAME_END_TAG) { + return_ACPI_STATUS(AE_OK); + } - /* Set the Buffer to the next structure */ + /* Point to the next input AML resource */ - resource = ACPI_CAST_PTR(struct acpi_resource, buffer); - resource->length = - (u32) ACPI_ALIGN_RESOURCE_SIZE(resource->length); - buffer += ACPI_ALIGN_RESOURCE_SIZE(structure_size); - } + aml += acpi_ut_get_descriptor_length(aml); - /* Check the reason for exiting the while loop */ + /* Point to the next structure in the output buffer */ - if (!end_tag_processed) { - return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); + resource = + ACPI_ADD_PTR(struct acpi_resource, resource, + resource->length); } - return_ACPI_STATUS(AE_OK); + /* Did not find an end_tag resource descriptor */ + + return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } /******************************************************************************* * - * FUNCTION: acpi_rs_list_to_byte_stream + * FUNCTION: acpi_rs_convert_resources_to_aml * - * PARAMETERS: linked_list - Pointer to the resource linked list - * byte_steam_size_needed - Calculated size of the byte stream - * needed from calling - * acpi_rs_get_byte_stream_length() - * The size of the output_buffer is - * guaranteed to be >= - * byte_stream_size_needed - * output_buffer - Pointer to the buffer that will - * contain the byte stream + * PARAMETERS: Resource - Pointer to the resource linked list + * aml_size_needed - Calculated size of the byte stream + * needed from calling acpi_rs_get_aml_length() + * The size of the output_buffer is + * guaranteed to be >= aml_size_needed + * output_buffer - Pointer to the buffer that will + * contain the byte stream * * RETURN: Status * @@ -346,180 +141,69 @@ acpi_rs_byte_stream_to_list(u8 * byte_stream_buffer, ******************************************************************************/ acpi_status -acpi_rs_list_to_byte_stream(struct acpi_resource *linked_list, - acpi_size byte_stream_size_needed, - u8 * output_buffer) +acpi_rs_convert_resources_to_aml(struct acpi_resource *resource, + acpi_size aml_size_needed, u8 * output_buffer) { + u8 *aml = output_buffer; + u8 *end_aml = output_buffer + aml_size_needed; acpi_status status; - u8 *buffer = output_buffer; - acpi_size bytes_consumed = 0; - u8 done = FALSE; - - ACPI_FUNCTION_TRACE("rs_list_to_byte_stream"); - - while (!done) { - switch (linked_list->id) { - case ACPI_RSTYPE_IRQ: - /* - * IRQ Resource - */ - status = - acpi_rs_irq_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_DMA: - /* - * DMA Resource - */ - status = - acpi_rs_dma_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_START_DPF: - /* - * Start Dependent Functions Resource - */ - status = acpi_rs_start_depend_fns_stream(linked_list, - &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_END_DPF: - /* - * End Dependent Functions Resource - */ - status = acpi_rs_end_depend_fns_stream(linked_list, - &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_IO: - /* - * IO Port Resource - */ - status = - acpi_rs_io_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_FIXED_IO: - /* - * Fixed IO Port Resource - */ - status = - acpi_rs_fixed_io_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_VENDOR: - /* - * Vendor Defined Resource - */ - status = - acpi_rs_vendor_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_END_TAG: - /* - * End Tag - */ - status = - acpi_rs_end_tag_stream(linked_list, &buffer, - &bytes_consumed); - - /* An End Tag indicates the end of the Resource Template */ - - done = TRUE; - break; - - case ACPI_RSTYPE_MEM24: - /* - * 24-Bit Memory Resource - */ - status = - acpi_rs_memory24_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_MEM32: - /* - * 32-Bit Memory Range Resource - */ - status = - acpi_rs_memory32_range_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_FIXED_MEM32: - /* - * 32-Bit Fixed Memory Resource - */ - status = - acpi_rs_fixed_memory32_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_ADDRESS16: - /* - * 16-Bit Address Descriptor Resource - */ - status = acpi_rs_address16_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_ADDRESS32: - /* - * 32-Bit Address Descriptor Resource - */ - status = acpi_rs_address32_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_ADDRESS64: - /* - * 64-Bit Address Descriptor Resource - */ - status = acpi_rs_address64_stream(linked_list, &buffer, - &bytes_consumed); - break; - - case ACPI_RSTYPE_EXT_IRQ: - /* - * Extended IRQ Resource - */ - status = - acpi_rs_extended_irq_stream(linked_list, &buffer, - &bytes_consumed); - break; - - default: - /* - * If we get here, everything is out of sync, - * so exit with an error - */ - ACPI_DEBUG_PRINT((ACPI_DB_ERROR, - "Invalid descriptor type (%X) in resource list\n", - linked_list->id)); - status = AE_BAD_DATA; - break; + + ACPI_FUNCTION_TRACE("rs_convert_resources_to_aml"); + + /* Walk the resource descriptor list, convert each descriptor */ + + while (aml < end_aml) { + /* Validate the (internal) Resource Type */ + + if (resource->type > ACPI_RESOURCE_TYPE_MAX) { + ACPI_REPORT_ERROR(("Invalid descriptor type (%X) in resource list\n", resource->type)); + return_ACPI_STATUS(AE_BAD_DATA); } + /* Perform the conversion */ + + status = acpi_rs_convert_resource_to_aml(resource, + ACPI_CAST_PTR(union + aml_resource, + aml), + acpi_gbl_set_resource_dispatch + [resource->type]); if (ACPI_FAILURE(status)) { + ACPI_REPORT_ERROR(("Could not convert resource (type %X) to AML, %s\n", resource->type, acpi_format_exception(status))); return_ACPI_STATUS(status); } - /* Set the Buffer to point to the open byte */ + /* Perform final sanity check on the new AML resource descriptor */ + + status = + acpi_ut_validate_resource(ACPI_CAST_PTR + (union aml_resource, aml), NULL); + if (ACPI_FAILURE(status)) { + return_ACPI_STATUS(status); + } - buffer += bytes_consumed; + /* Check for end-of-list, normal exit */ - /* Point to the next object */ + if (resource->type == ACPI_RESOURCE_TYPE_END_TAG) { + /* An End Tag indicates the end of the input Resource Template */ - linked_list = ACPI_PTR_ADD(struct acpi_resource, - linked_list, linked_list->length); + return_ACPI_STATUS(AE_OK); + } + + /* + * Extract the total length of the new descriptor and set the + * Aml to point to the next (output) resource descriptor + */ + aml += acpi_ut_get_descriptor_length(aml); + + /* Point to the next input resource descriptor */ + + resource = + ACPI_ADD_PTR(struct acpi_resource, resource, + resource->length); } - return_ACPI_STATUS(AE_OK); + /* Completed buffer, but did not find an end_tag resource descriptor */ + + return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG); } |