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.
45 #include <acpi/acpi.h>
46 #include <acpi/acresrc.h>
48 #define _COMPONENT ACPI_RESOURCES
49 ACPI_MODULE_NAME ("rslist")
52 /*******************************************************************************
54 * FUNCTION: acpi_rs_get_resource_type
56 * PARAMETERS: resource_start_byte - Byte 0 of a resource descriptor
58 * RETURN: The Resource Type with no extraneous bits
60 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
61 * a resource descriptor.
63 ******************************************************************************/
66 acpi_rs_get_resource_type (
67 u8 resource_start_byte)
70 ACPI_FUNCTION_ENTRY ();
73 /* Determine if this is a small or large resource */
75 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) {
76 case ACPI_RDESC_TYPE_SMALL:
78 /* Small Resource Type -- Only bits 6:3 are valid */
80 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK));
83 case ACPI_RDESC_TYPE_LARGE:
85 /* Large Resource Type -- All bits are valid */
87 return (resource_start_byte);
99 /*******************************************************************************
101 * FUNCTION: acpi_rs_byte_stream_to_list
103 * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream
104 * byte_stream_buffer_length - Length of byte_stream_buffer
105 * output_buffer - Pointer to the buffer that will
106 * contain the output structures
110 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
111 * linked list of resources in the caller's output buffer
113 ******************************************************************************/
116 acpi_rs_byte_stream_to_list (
117 u8 *byte_stream_buffer,
118 u32 byte_stream_buffer_length,
122 acpi_size bytes_parsed = 0;
123 u8 resource_type = 0;
124 acpi_size bytes_consumed = 0;
125 u8 *buffer = output_buffer;
126 acpi_size structure_size = 0;
127 u8 end_tag_processed = FALSE;
128 struct acpi_resource *resource;
130 ACPI_FUNCTION_TRACE ("rs_byte_stream_to_list");
133 while (bytes_parsed < byte_stream_buffer_length &&
134 !end_tag_processed) {
135 /* The next byte in the stream is the resource type */
137 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);
139 switch (resource_type) {
140 case ACPI_RDESC_TYPE_MEMORY_24:
142 * 24-Bit Memory Resource
144 status = acpi_rs_memory24_resource (byte_stream_buffer,
145 &bytes_consumed, &buffer, &structure_size);
149 case ACPI_RDESC_TYPE_LARGE_VENDOR:
151 * Vendor Defined Resource
153 status = acpi_rs_vendor_resource (byte_stream_buffer,
154 &bytes_consumed, &buffer, &structure_size);
158 case ACPI_RDESC_TYPE_MEMORY_32:
160 * 32-Bit Memory Range Resource
162 status = acpi_rs_memory32_range_resource (byte_stream_buffer,
163 &bytes_consumed, &buffer, &structure_size);
167 case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
169 * 32-Bit Fixed Memory Resource
171 status = acpi_rs_fixed_memory32_resource (byte_stream_buffer,
172 &bytes_consumed, &buffer, &structure_size);
176 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
177 case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE:
179 * 64-Bit Address Resource
181 status = acpi_rs_address64_resource (byte_stream_buffer,
182 &bytes_consumed, &buffer, &structure_size);
186 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
188 * 32-Bit Address Resource
190 status = acpi_rs_address32_resource (byte_stream_buffer,
191 &bytes_consumed, &buffer, &structure_size);
195 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
197 * 16-Bit Address Resource
199 status = acpi_rs_address16_resource (byte_stream_buffer,
200 &bytes_consumed, &buffer, &structure_size);
204 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
208 status = acpi_rs_extended_irq_resource (byte_stream_buffer,
209 &bytes_consumed, &buffer, &structure_size);
213 case ACPI_RDESC_TYPE_IRQ_FORMAT:
217 status = acpi_rs_irq_resource (byte_stream_buffer,
218 &bytes_consumed, &buffer, &structure_size);
222 case ACPI_RDESC_TYPE_DMA_FORMAT:
226 status = acpi_rs_dma_resource (byte_stream_buffer,
227 &bytes_consumed, &buffer, &structure_size);
231 case ACPI_RDESC_TYPE_START_DEPENDENT:
233 * Start Dependent Functions Resource
235 status = acpi_rs_start_depend_fns_resource (byte_stream_buffer,
236 &bytes_consumed, &buffer, &structure_size);
240 case ACPI_RDESC_TYPE_END_DEPENDENT:
242 * End Dependent Functions Resource
244 status = acpi_rs_end_depend_fns_resource (byte_stream_buffer,
245 &bytes_consumed, &buffer, &structure_size);
249 case ACPI_RDESC_TYPE_IO_PORT:
253 status = acpi_rs_io_resource (byte_stream_buffer,
254 &bytes_consumed, &buffer, &structure_size);
258 case ACPI_RDESC_TYPE_FIXED_IO_PORT:
260 * Fixed IO Port Resource
262 status = acpi_rs_fixed_io_resource (byte_stream_buffer,
263 &bytes_consumed, &buffer, &structure_size);
267 case ACPI_RDESC_TYPE_SMALL_VENDOR:
269 * Vendor Specific Resource
271 status = acpi_rs_vendor_resource (byte_stream_buffer,
272 &bytes_consumed, &buffer, &structure_size);
276 case ACPI_RDESC_TYPE_END_TAG:
280 end_tag_processed = TRUE;
281 status = acpi_rs_end_tag_resource (byte_stream_buffer,
282 &bytes_consumed, &buffer, &structure_size);
288 * Invalid/Unknown resource type
290 status = AE_AML_INVALID_RESOURCE_TYPE;
294 if (ACPI_FAILURE (status)) {
295 return_ACPI_STATUS (status);
298 /* Update the return value and counter */
300 bytes_parsed += bytes_consumed;
302 /* Set the byte stream to point to the next resource */
304 byte_stream_buffer += bytes_consumed;
306 /* Set the Buffer to the next structure */
308 resource = ACPI_CAST_PTR (struct acpi_resource, buffer);
309 resource->length = (u32) ACPI_ALIGN_RESOURCE_SIZE (resource->length);
310 buffer += ACPI_ALIGN_RESOURCE_SIZE (structure_size);
313 /* Check the reason for exiting the while loop */
315 if (!end_tag_processed) {
316 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
319 return_ACPI_STATUS (AE_OK);
323 /*******************************************************************************
325 * FUNCTION: acpi_rs_list_to_byte_stream
327 * PARAMETERS: linked_list - Pointer to the resource linked list
328 * byte_steam_size_needed - Calculated size of the byte stream
329 * needed from calling
330 * acpi_rs_get_byte_stream_length()
331 * The size of the output_buffer is
332 * guaranteed to be >=
333 * byte_stream_size_needed
334 * output_buffer - Pointer to the buffer that will
335 * contain the byte stream
339 * DESCRIPTION: Takes the resource linked list and parses it, creating a
340 * byte stream of resources in the caller's output buffer
342 ******************************************************************************/
345 acpi_rs_list_to_byte_stream (
346 struct acpi_resource *linked_list,
347 acpi_size byte_stream_size_needed,
351 u8 *buffer = output_buffer;
352 acpi_size bytes_consumed = 0;
356 ACPI_FUNCTION_TRACE ("rs_list_to_byte_stream");
360 switch (linked_list->id) {
361 case ACPI_RSTYPE_IRQ:
365 status = acpi_rs_irq_stream (linked_list, &buffer, &bytes_consumed);
368 case ACPI_RSTYPE_DMA:
372 status = acpi_rs_dma_stream (linked_list, &buffer, &bytes_consumed);
375 case ACPI_RSTYPE_START_DPF:
377 * Start Dependent Functions Resource
379 status = acpi_rs_start_depend_fns_stream (linked_list,
380 &buffer, &bytes_consumed);
383 case ACPI_RSTYPE_END_DPF:
385 * End Dependent Functions Resource
387 status = acpi_rs_end_depend_fns_stream (linked_list,
388 &buffer, &bytes_consumed);
395 status = acpi_rs_io_stream (linked_list, &buffer, &bytes_consumed);
398 case ACPI_RSTYPE_FIXED_IO:
400 * Fixed IO Port Resource
402 status = acpi_rs_fixed_io_stream (linked_list, &buffer, &bytes_consumed);
405 case ACPI_RSTYPE_VENDOR:
407 * Vendor Defined Resource
409 status = acpi_rs_vendor_stream (linked_list, &buffer, &bytes_consumed);
412 case ACPI_RSTYPE_END_TAG:
416 status = acpi_rs_end_tag_stream (linked_list, &buffer, &bytes_consumed);
418 /* An End Tag indicates the end of the Resource Template */
423 case ACPI_RSTYPE_MEM24:
425 * 24-Bit Memory Resource
427 status = acpi_rs_memory24_stream (linked_list, &buffer, &bytes_consumed);
430 case ACPI_RSTYPE_MEM32:
432 * 32-Bit Memory Range Resource
434 status = acpi_rs_memory32_range_stream (linked_list, &buffer,
438 case ACPI_RSTYPE_FIXED_MEM32:
440 * 32-Bit Fixed Memory Resource
442 status = acpi_rs_fixed_memory32_stream (linked_list, &buffer,
446 case ACPI_RSTYPE_ADDRESS16:
448 * 16-Bit Address Descriptor Resource
450 status = acpi_rs_address16_stream (linked_list, &buffer,
454 case ACPI_RSTYPE_ADDRESS32:
456 * 32-Bit Address Descriptor Resource
458 status = acpi_rs_address32_stream (linked_list, &buffer,
462 case ACPI_RSTYPE_ADDRESS64:
464 * 64-Bit Address Descriptor Resource
466 status = acpi_rs_address64_stream (linked_list, &buffer,
470 case ACPI_RSTYPE_EXT_IRQ:
472 * Extended IRQ Resource
474 status = acpi_rs_extended_irq_stream (linked_list, &buffer,
480 * If we get here, everything is out of sync,
481 * so exit with an error
483 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
484 "Invalid descriptor type (%X) in resource list\n",
486 status = AE_BAD_DATA;
490 if (ACPI_FAILURE (status)) {
491 return_ACPI_STATUS (status);
494 /* Set the Buffer to point to the open byte */
496 buffer += bytes_consumed;
498 /* Point to the next object */
500 linked_list = ACPI_PTR_ADD (struct acpi_resource,
501 linked_list, linked_list->length);
504 return_ACPI_STATUS (AE_OK);