1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
45 #include <acpi/acresrc.h>
47 #define _COMPONENT ACPI_RESOURCES
48 ACPI_MODULE_NAME("rslist")
50 /*******************************************************************************
52 * FUNCTION: acpi_rs_get_resource_type
54 * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor
56 * RETURN: The Resource Type with no extraneous bits
58 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
59 * a resource descriptor.
61 ******************************************************************************/
62 u8 acpi_rs_get_resource_type(u8 resource_start_byte)
65 ACPI_FUNCTION_ENTRY();
67 /* Determine if this is a small or large resource */
69 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) {
70 case ACPI_RDESC_TYPE_SMALL:
72 /* Small Resource Type -- Only bits 6:3 are valid */
74 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK));
76 case ACPI_RDESC_TYPE_LARGE:
78 /* Large Resource Type -- All bits are valid */
80 return (resource_start_byte);
90 /*******************************************************************************
92 * FUNCTION: acpi_rs_byte_stream_to_list
94 * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream
95 * byte_stream_buffer_length - Length of byte_stream_buffer
96 * output_buffer - Pointer to the buffer that will
97 * contain the output structures
101 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
102 * linked list of resources in the caller's output buffer
104 ******************************************************************************/
107 acpi_rs_byte_stream_to_list(u8 * byte_stream_buffer,
108 u32 byte_stream_buffer_length, u8 * output_buffer)
111 acpi_size bytes_parsed = 0;
112 u8 resource_type = 0;
113 acpi_size bytes_consumed = 0;
114 u8 *buffer = output_buffer;
115 acpi_size structure_size = 0;
116 u8 end_tag_processed = FALSE;
117 struct acpi_resource *resource;
119 ACPI_FUNCTION_TRACE("rs_byte_stream_to_list");
121 while (bytes_parsed < byte_stream_buffer_length && !end_tag_processed) {
122 /* The next byte in the stream is the resource type */
124 resource_type = acpi_rs_get_resource_type(*byte_stream_buffer);
126 switch (resource_type) {
127 case ACPI_RDESC_TYPE_MEMORY_24:
129 * 24-Bit Memory Resource
131 status = acpi_rs_memory24_resource(byte_stream_buffer,
137 case ACPI_RDESC_TYPE_LARGE_VENDOR:
139 * Vendor Defined Resource
141 status = acpi_rs_vendor_resource(byte_stream_buffer,
147 case ACPI_RDESC_TYPE_MEMORY_32:
149 * 32-Bit Memory Range Resource
152 acpi_rs_memory32_range_resource(byte_stream_buffer,
158 case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
160 * 32-Bit Fixed Memory Resource
163 acpi_rs_fixed_memory32_resource(byte_stream_buffer,
169 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
170 case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE:
172 * 64-Bit Address Resource
174 status = acpi_rs_address64_resource(byte_stream_buffer,
180 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
182 * 32-Bit Address Resource
184 status = acpi_rs_address32_resource(byte_stream_buffer,
190 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
192 * 16-Bit Address Resource
194 status = acpi_rs_address16_resource(byte_stream_buffer,
200 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
205 acpi_rs_extended_irq_resource(byte_stream_buffer,
211 case ACPI_RDESC_TYPE_IRQ_FORMAT:
215 status = acpi_rs_irq_resource(byte_stream_buffer,
216 &bytes_consumed, &buffer,
220 case ACPI_RDESC_TYPE_DMA_FORMAT:
224 status = acpi_rs_dma_resource(byte_stream_buffer,
225 &bytes_consumed, &buffer,
229 case ACPI_RDESC_TYPE_START_DEPENDENT:
231 * Start Dependent Functions Resource
234 acpi_rs_start_depend_fns_resource
235 (byte_stream_buffer, &bytes_consumed, &buffer,
239 case ACPI_RDESC_TYPE_END_DEPENDENT:
241 * End Dependent Functions Resource
244 acpi_rs_end_depend_fns_resource(byte_stream_buffer,
250 case ACPI_RDESC_TYPE_IO_PORT:
254 status = acpi_rs_io_resource(byte_stream_buffer,
255 &bytes_consumed, &buffer,
259 case ACPI_RDESC_TYPE_FIXED_IO_PORT:
261 * Fixed IO Port Resource
263 status = acpi_rs_fixed_io_resource(byte_stream_buffer,
269 case ACPI_RDESC_TYPE_SMALL_VENDOR:
271 * Vendor Specific Resource
273 status = acpi_rs_vendor_resource(byte_stream_buffer,
279 case ACPI_RDESC_TYPE_END_TAG:
283 end_tag_processed = TRUE;
284 status = acpi_rs_end_tag_resource(byte_stream_buffer,
292 * Invalid/Unknown resource type
294 status = AE_AML_INVALID_RESOURCE_TYPE;
298 if (ACPI_FAILURE(status)) {
299 return_ACPI_STATUS(status);
302 /* Update the return value and counter */
304 bytes_parsed += bytes_consumed;
306 /* Set the byte stream to point to the next resource */
308 byte_stream_buffer += bytes_consumed;
310 /* Set the Buffer to the next structure */
312 resource = ACPI_CAST_PTR(struct acpi_resource, buffer);
314 (u32) ACPI_ALIGN_RESOURCE_SIZE(resource->length);
315 buffer += ACPI_ALIGN_RESOURCE_SIZE(structure_size);
318 /* Check the reason for exiting the while loop */
320 if (!end_tag_processed) {
321 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
324 return_ACPI_STATUS(AE_OK);
327 /*******************************************************************************
329 * FUNCTION: acpi_rs_list_to_byte_stream
331 * PARAMETERS: linked_list - Pointer to the resource linked list
332 * byte_steam_size_needed - Calculated size of the byte stream
333 * needed from calling
334 * acpi_rs_get_byte_stream_length()
335 * The size of the output_buffer is
336 * guaranteed to be >=
337 * byte_stream_size_needed
338 * output_buffer - Pointer to the buffer that will
339 * contain the byte stream
343 * DESCRIPTION: Takes the resource linked list and parses it, creating a
344 * byte stream of resources in the caller's output buffer
346 ******************************************************************************/
349 acpi_rs_list_to_byte_stream(struct acpi_resource *linked_list,
350 acpi_size byte_stream_size_needed,
354 u8 *buffer = output_buffer;
355 acpi_size bytes_consumed = 0;
358 ACPI_FUNCTION_TRACE("rs_list_to_byte_stream");
361 switch (linked_list->id) {
362 case ACPI_RSTYPE_IRQ:
367 acpi_rs_irq_stream(linked_list, &buffer,
371 case ACPI_RSTYPE_DMA:
376 acpi_rs_dma_stream(linked_list, &buffer,
380 case ACPI_RSTYPE_START_DPF:
382 * Start Dependent Functions Resource
384 status = acpi_rs_start_depend_fns_stream(linked_list,
389 case ACPI_RSTYPE_END_DPF:
391 * End Dependent Functions Resource
393 status = acpi_rs_end_depend_fns_stream(linked_list,
403 acpi_rs_io_stream(linked_list, &buffer,
407 case ACPI_RSTYPE_FIXED_IO:
409 * Fixed IO Port Resource
412 acpi_rs_fixed_io_stream(linked_list, &buffer,
416 case ACPI_RSTYPE_VENDOR:
418 * Vendor Defined Resource
421 acpi_rs_vendor_stream(linked_list, &buffer,
425 case ACPI_RSTYPE_END_TAG:
430 acpi_rs_end_tag_stream(linked_list, &buffer,
433 /* An End Tag indicates the end of the Resource Template */
438 case ACPI_RSTYPE_MEM24:
440 * 24-Bit Memory Resource
443 acpi_rs_memory24_stream(linked_list, &buffer,
447 case ACPI_RSTYPE_MEM32:
449 * 32-Bit Memory Range Resource
452 acpi_rs_memory32_range_stream(linked_list, &buffer,
456 case ACPI_RSTYPE_FIXED_MEM32:
458 * 32-Bit Fixed Memory Resource
461 acpi_rs_fixed_memory32_stream(linked_list, &buffer,
465 case ACPI_RSTYPE_ADDRESS16:
467 * 16-Bit Address Descriptor Resource
469 status = acpi_rs_address16_stream(linked_list, &buffer,
473 case ACPI_RSTYPE_ADDRESS32:
475 * 32-Bit Address Descriptor Resource
477 status = acpi_rs_address32_stream(linked_list, &buffer,
481 case ACPI_RSTYPE_ADDRESS64:
483 * 64-Bit Address Descriptor Resource
485 status = acpi_rs_address64_stream(linked_list, &buffer,
489 case ACPI_RSTYPE_EXT_IRQ:
491 * Extended IRQ Resource
494 acpi_rs_extended_irq_stream(linked_list, &buffer,
500 * If we get here, everything is out of sync,
501 * so exit with an error
503 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
504 "Invalid descriptor type (%X) in resource list\n",
506 status = AE_BAD_DATA;
510 if (ACPI_FAILURE(status)) {
511 return_ACPI_STATUS(status);
514 /* Set the Buffer to point to the open byte */
516 buffer += bytes_consumed;
518 /* Point to the next object */
520 linked_list = ACPI_PTR_ADD(struct acpi_resource,
521 linked_list, linked_list->length);
524 return_ACPI_STATUS(AE_OK);