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 /* Dispatch table for convert-to-stream functions */
52 acpi_status(*ACPI_STREAM_HANDLER) (struct acpi_resource * resource,
54 acpi_size * bytes_consumed);
56 static ACPI_STREAM_HANDLER acpi_gbl_stream_dispatch[] = {
57 acpi_rs_irq_stream, /* ACPI_RSTYPE_IRQ */
58 acpi_rs_dma_stream, /* ACPI_RSTYPE_DMA */
59 acpi_rs_start_depend_fns_stream, /* ACPI_RSTYPE_START_DPF */
60 acpi_rs_end_depend_fns_stream, /* ACPI_RSTYPE_END_DPF */
61 acpi_rs_io_stream, /* ACPI_RSTYPE_IO */
62 acpi_rs_fixed_io_stream, /* ACPI_RSTYPE_FIXED_IO */
63 acpi_rs_vendor_stream, /* ACPI_RSTYPE_VENDOR */
64 acpi_rs_end_tag_stream, /* ACPI_RSTYPE_END_TAG */
65 acpi_rs_memory24_stream, /* ACPI_RSTYPE_MEM24 */
66 acpi_rs_memory32_range_stream, /* ACPI_RSTYPE_MEM32 */
67 acpi_rs_fixed_memory32_stream, /* ACPI_RSTYPE_FIXED_MEM32 */
68 acpi_rs_address16_stream, /* ACPI_RSTYPE_ADDRESS16 */
69 acpi_rs_address32_stream, /* ACPI_RSTYPE_ADDRESS32 */
70 acpi_rs_address64_stream, /* ACPI_RSTYPE_ADDRESS64 */
71 acpi_rs_extended_irq_stream, /* ACPI_RSTYPE_EXT_IRQ */
72 acpi_rs_generic_register_stream /* ACPI_RSTYPE_GENERIC_REG */
75 /* Dispatch tables for convert-to-resource functions */
78 acpi_status(*ACPI_RESOURCE_HANDLER) (u8 * byte_stream_buffer,
79 acpi_size * bytes_consumed,
81 acpi_size * structure_size);
83 static ACPI_RESOURCE_HANDLER acpi_gbl_sm_resource_dispatch[] = {
84 NULL, /* 0x00, Reserved */
85 NULL, /* 0x01, Reserved */
86 NULL, /* 0x02, Reserved */
87 NULL, /* 0x03, Reserved */
88 acpi_rs_irq_resource, /* ACPI_RDESC_TYPE_IRQ_FORMAT */
89 acpi_rs_dma_resource, /* ACPI_RDESC_TYPE_DMA_FORMAT */
90 acpi_rs_start_depend_fns_resource, /* ACPI_RDESC_TYPE_START_DEPENDENT */
91 acpi_rs_end_depend_fns_resource, /* ACPI_RDESC_TYPE_END_DEPENDENT */
92 acpi_rs_io_resource, /* ACPI_RDESC_TYPE_IO_PORT */
93 acpi_rs_fixed_io_resource, /* ACPI_RDESC_TYPE_FIXED_IO_PORT */
94 NULL, /* 0x0A, Reserved */
95 NULL, /* 0x0B, Reserved */
96 NULL, /* 0x0C, Reserved */
97 NULL, /* 0x0D, Reserved */
98 acpi_rs_vendor_resource, /* ACPI_RDESC_TYPE_SMALL_VENDOR */
99 acpi_rs_end_tag_resource /* ACPI_RDESC_TYPE_END_TAG */
102 static ACPI_RESOURCE_HANDLER acpi_gbl_lg_resource_dispatch[] = {
103 NULL, /* 0x00, Reserved */
104 acpi_rs_memory24_resource, /* ACPI_RDESC_TYPE_MEMORY_24 */
105 acpi_rs_generic_register_resource, /* ACPI_RDESC_TYPE_GENERIC_REGISTER */
106 NULL, /* 0x03, Reserved */
107 acpi_rs_vendor_resource, /* ACPI_RDESC_TYPE_LARGE_VENDOR */
108 acpi_rs_memory32_range_resource, /* ACPI_RDESC_TYPE_MEMORY_32 */
109 acpi_rs_fixed_memory32_resource, /* ACPI_RDESC_TYPE_FIXED_MEMORY_32 */
110 acpi_rs_address32_resource, /* ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE */
111 acpi_rs_address16_resource, /* ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE */
112 acpi_rs_extended_irq_resource, /* ACPI_RDESC_TYPE_EXTENDED_XRUPT */
113 acpi_rs_address64_resource, /* ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE */
114 acpi_rs_address64_resource /* ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE */
117 /* Local prototypes */
119 static ACPI_RESOURCE_HANDLER acpi_rs_get_resource_handler(u8 resource_type);
121 /*******************************************************************************
123 * FUNCTION: acpi_rs_get_resource_type
125 * PARAMETERS: resource_type - Byte 0 of a resource descriptor
127 * RETURN: The Resource Type with no extraneous bits (except the large/
128 * small bit -- left alone)
130 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
131 * a resource descriptor.
133 ******************************************************************************/
135 u8 acpi_rs_get_resource_type(u8 resource_type)
137 ACPI_FUNCTION_ENTRY();
139 /* Determine if this is a small or large resource */
141 if (resource_type & ACPI_RDESC_TYPE_LARGE) {
142 /* Large Resource Type -- bits 6:0 contain the name */
144 return (resource_type);
146 /* Small Resource Type -- bits 6:3 contain the name */
148 return ((u8) (resource_type & ACPI_RDESC_SMALL_MASK));
152 /*******************************************************************************
154 * FUNCTION: acpi_rs_get_resource_handler
156 * PARAMETERS: resource_type - Byte 0 of a resource descriptor
158 * RETURN: Pointer to the resource conversion handler
160 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
161 * a resource descriptor.
163 ******************************************************************************/
165 static ACPI_RESOURCE_HANDLER acpi_rs_get_resource_handler(u8 resource_type)
167 ACPI_FUNCTION_ENTRY();
169 /* Determine if this is a small or large resource */
171 if (resource_type & ACPI_RDESC_TYPE_LARGE) {
172 /* Large Resource Type -- bits 6:0 contain the name */
174 if (resource_type > ACPI_RDESC_LARGE_MAX) {
178 return (acpi_gbl_lg_resource_dispatch[(resource_type &
179 ACPI_RDESC_LARGE_MASK)]);
181 /* Small Resource Type -- bits 6:3 contain the name */
183 return (acpi_gbl_sm_resource_dispatch[((resource_type &
184 ACPI_RDESC_SMALL_MASK)
189 /*******************************************************************************
191 * FUNCTION: acpi_rs_byte_stream_to_list
193 * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream
194 * byte_stream_buffer_length - Length of byte_stream_buffer
195 * output_buffer - Pointer to the buffer that will
196 * contain the output structures
200 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
201 * linked list of resources in the caller's output buffer
203 ******************************************************************************/
206 acpi_rs_byte_stream_to_list(u8 * byte_stream_buffer,
207 u32 byte_stream_buffer_length, u8 * output_buffer)
209 u8 *buffer = output_buffer;
211 acpi_size bytes_parsed = 0;
212 acpi_size bytes_consumed = 0;
213 acpi_size structure_size = 0;
214 struct acpi_resource *resource;
215 ACPI_RESOURCE_HANDLER handler;
217 ACPI_FUNCTION_TRACE("rs_byte_stream_to_list");
219 /* Loop until end-of-buffer or an end_tag is found */
221 while (bytes_parsed < byte_stream_buffer_length) {
222 /* Get the handler associated with this Descriptor Type */
224 handler = acpi_rs_get_resource_handler(*byte_stream_buffer);
226 /* Convert a byte stream resource to local resource struct */
228 status = handler(byte_stream_buffer, &bytes_consumed,
229 &buffer, &structure_size);
231 /* Invalid resource type */
233 status = AE_AML_INVALID_RESOURCE_TYPE;
236 if (ACPI_FAILURE(status)) {
237 return_ACPI_STATUS(status);
240 /* Set the aligned length of the new resource descriptor */
242 resource = ACPI_CAST_PTR(struct acpi_resource, buffer);
244 (u32) ACPI_ALIGN_RESOURCE_SIZE(resource->length);
246 /* Normal exit on completion of an end_tag resource descriptor */
248 if (acpi_rs_get_resource_type(*byte_stream_buffer) ==
249 ACPI_RDESC_TYPE_END_TAG) {
250 return_ACPI_STATUS(AE_OK);
253 /* Update counter and point to the next input resource */
255 bytes_parsed += bytes_consumed;
256 byte_stream_buffer += bytes_consumed;
258 /* Point to the next structure in the output buffer */
260 buffer += ACPI_ALIGN_RESOURCE_SIZE(structure_size);
263 /* Completed buffer, but did not find an end_tag resource descriptor */
265 return_ACPI_STATUS(AE_AML_NO_RESOURCE_END_TAG);
268 /*******************************************************************************
270 * FUNCTION: acpi_rs_list_to_byte_stream
272 * PARAMETERS: Resource - Pointer to the resource linked list
273 * byte_steam_size_needed - Calculated size of the byte stream
274 * needed from calling
275 * acpi_rs_get_byte_stream_length()
276 * The size of the output_buffer is
277 * guaranteed to be >=
278 * byte_stream_size_needed
279 * output_buffer - Pointer to the buffer that will
280 * contain the byte stream
284 * DESCRIPTION: Takes the resource linked list and parses it, creating a
285 * byte stream of resources in the caller's output buffer
287 ******************************************************************************/
290 acpi_rs_list_to_byte_stream(struct acpi_resource *resource,
291 acpi_size byte_stream_size_needed,
294 u8 *buffer = output_buffer;
295 acpi_size bytes_consumed = 0;
298 ACPI_FUNCTION_TRACE("rs_list_to_byte_stream");
300 /* Convert each resource descriptor in the list */
303 /* Validate Type before dispatch */
305 if (resource->type > ACPI_RSTYPE_MAX) {
306 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
307 "Invalid descriptor type (%X) in resource list\n",
309 return_ACPI_STATUS(AE_BAD_DATA);
312 /* Perform the conversion, per resource type */
314 status = acpi_gbl_stream_dispatch[resource->type] (resource,
317 if (ACPI_FAILURE(status)) {
318 return_ACPI_STATUS(status);
321 /* Check for end-of-list */
323 if (resource->type == ACPI_RSTYPE_END_TAG) {
324 /* An End Tag indicates the end of the Resource Template */
326 return_ACPI_STATUS(AE_OK);
329 /* Set the Buffer to point to the next (output) resource descriptor */
331 buffer += bytes_consumed;
333 /* Point to the next input resource object */
335 resource = ACPI_PTR_ADD(struct acpi_resource,
336 resource, resource->length);