[PATCH] aic7xxx_osm build fix
[cris-mirror.git] / drivers / acpi / resources / rslist.c
blobe49c1e030f99f73af87ca7aef38df8d285fbc578
1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
5 ******************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 (Name) 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 ();
74 * Determine if this is a small or large resource
76 switch (resource_start_byte & ACPI_RDESC_TYPE_MASK) {
77 case ACPI_RDESC_TYPE_SMALL:
80 * Small Resource Type -- Only bits 6:3 are valid
82 return ((u8) (resource_start_byte & ACPI_RDESC_SMALL_MASK));
85 case ACPI_RDESC_TYPE_LARGE:
88 * Large Resource Type -- All bits are valid
90 return (resource_start_byte);
93 default:
94 /* No other types of resource descriptor */
95 break;
98 return (0xFF);
102 /*******************************************************************************
104 * FUNCTION: acpi_rs_byte_stream_to_list
106 * PARAMETERS: byte_stream_buffer - Pointer to the resource byte stream
107 * byte_stream_buffer_length - Length of byte_stream_buffer
108 * output_buffer - Pointer to the buffer that will
109 * contain the output structures
111 * RETURN: Status
113 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
114 * linked list of resources in the caller's output buffer
116 ******************************************************************************/
118 acpi_status
119 acpi_rs_byte_stream_to_list (
120 u8 *byte_stream_buffer,
121 u32 byte_stream_buffer_length,
122 u8 *output_buffer)
124 acpi_status status;
125 acpi_size bytes_parsed = 0;
126 u8 resource_type = 0;
127 acpi_size bytes_consumed = 0;
128 u8 *buffer = output_buffer;
129 acpi_size structure_size = 0;
130 u8 end_tag_processed = FALSE;
131 struct acpi_resource *resource;
133 ACPI_FUNCTION_TRACE ("rs_byte_stream_to_list");
136 while (bytes_parsed < byte_stream_buffer_length &&
137 !end_tag_processed) {
139 * The next byte in the stream is the resource type
141 resource_type = acpi_rs_get_resource_type (*byte_stream_buffer);
143 switch (resource_type) {
144 case ACPI_RDESC_TYPE_MEMORY_24:
146 * 24-Bit Memory Resource
148 status = acpi_rs_memory24_resource (byte_stream_buffer,
149 &bytes_consumed, &buffer, &structure_size);
150 break;
153 case ACPI_RDESC_TYPE_LARGE_VENDOR:
155 * Vendor Defined Resource
157 status = acpi_rs_vendor_resource (byte_stream_buffer,
158 &bytes_consumed, &buffer, &structure_size);
159 break;
162 case ACPI_RDESC_TYPE_MEMORY_32:
164 * 32-Bit Memory Range Resource
166 status = acpi_rs_memory32_range_resource (byte_stream_buffer,
167 &bytes_consumed, &buffer, &structure_size);
168 break;
171 case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
173 * 32-Bit Fixed Memory Resource
175 status = acpi_rs_fixed_memory32_resource (byte_stream_buffer,
176 &bytes_consumed, &buffer, &structure_size);
177 break;
180 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
181 case ACPI_RDESC_TYPE_EXTENDED_ADDRESS_SPACE:
183 * 64-Bit Address Resource
185 status = acpi_rs_address64_resource (byte_stream_buffer,
186 &bytes_consumed, &buffer, &structure_size);
187 break;
190 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
192 * 32-Bit Address Resource
194 status = acpi_rs_address32_resource (byte_stream_buffer,
195 &bytes_consumed, &buffer, &structure_size);
196 break;
199 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
201 * 16-Bit Address Resource
203 status = acpi_rs_address16_resource (byte_stream_buffer,
204 &bytes_consumed, &buffer, &structure_size);
205 break;
208 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
210 * Extended IRQ
212 status = acpi_rs_extended_irq_resource (byte_stream_buffer,
213 &bytes_consumed, &buffer, &structure_size);
214 break;
217 case ACPI_RDESC_TYPE_IRQ_FORMAT:
219 * IRQ Resource
221 status = acpi_rs_irq_resource (byte_stream_buffer,
222 &bytes_consumed, &buffer, &structure_size);
223 break;
226 case ACPI_RDESC_TYPE_DMA_FORMAT:
228 * DMA Resource
230 status = acpi_rs_dma_resource (byte_stream_buffer,
231 &bytes_consumed, &buffer, &structure_size);
232 break;
235 case ACPI_RDESC_TYPE_START_DEPENDENT:
237 * Start Dependent Functions Resource
239 status = acpi_rs_start_depend_fns_resource (byte_stream_buffer,
240 &bytes_consumed, &buffer, &structure_size);
241 break;
244 case ACPI_RDESC_TYPE_END_DEPENDENT:
246 * End Dependent Functions Resource
248 status = acpi_rs_end_depend_fns_resource (byte_stream_buffer,
249 &bytes_consumed, &buffer, &structure_size);
250 break;
253 case ACPI_RDESC_TYPE_IO_PORT:
255 * IO Port Resource
257 status = acpi_rs_io_resource (byte_stream_buffer,
258 &bytes_consumed, &buffer, &structure_size);
259 break;
262 case ACPI_RDESC_TYPE_FIXED_IO_PORT:
264 * Fixed IO Port Resource
266 status = acpi_rs_fixed_io_resource (byte_stream_buffer,
267 &bytes_consumed, &buffer, &structure_size);
268 break;
271 case ACPI_RDESC_TYPE_SMALL_VENDOR:
273 * Vendor Specific Resource
275 status = acpi_rs_vendor_resource (byte_stream_buffer,
276 &bytes_consumed, &buffer, &structure_size);
277 break;
280 case ACPI_RDESC_TYPE_END_TAG:
282 * End Tag
284 end_tag_processed = TRUE;
285 status = acpi_rs_end_tag_resource (byte_stream_buffer,
286 &bytes_consumed, &buffer, &structure_size);
287 break;
290 default:
292 * Invalid/Unknown resource type
294 status = AE_AML_INVALID_RESOURCE_TYPE;
295 break;
298 if (ACPI_FAILURE (status)) {
299 return_ACPI_STATUS (status);
303 * Update the return value and counter
305 bytes_parsed += bytes_consumed;
308 * Set the byte stream to point to the next resource
310 byte_stream_buffer += bytes_consumed;
313 * Set the Buffer to the next structure
315 resource = ACPI_CAST_PTR (struct acpi_resource, buffer);
316 resource->length = (u32) ACPI_ALIGN_RESOURCE_SIZE (resource->length);
317 buffer += ACPI_ALIGN_RESOURCE_SIZE (structure_size);
319 } /* end while */
322 * Check the reason for exiting the while loop
324 if (!end_tag_processed) {
325 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
328 return_ACPI_STATUS (AE_OK);
332 /*******************************************************************************
334 * FUNCTION: acpi_rs_list_to_byte_stream
336 * PARAMETERS: linked_list - Pointer to the resource linked list
337 * byte_steam_size_needed - Calculated size of the byte stream
338 * needed from calling
339 * acpi_rs_get_byte_stream_length()
340 * The size of the output_buffer is
341 * guaranteed to be >=
342 * byte_stream_size_needed
343 * output_buffer - Pointer to the buffer that will
344 * contain the byte stream
346 * RETURN: Status
348 * DESCRIPTION: Takes the resource linked list and parses it, creating a
349 * byte stream of resources in the caller's output buffer
351 ******************************************************************************/
353 acpi_status
354 acpi_rs_list_to_byte_stream (
355 struct acpi_resource *linked_list,
356 acpi_size byte_stream_size_needed,
357 u8 *output_buffer)
359 acpi_status status;
360 u8 *buffer = output_buffer;
361 acpi_size bytes_consumed = 0;
362 u8 done = FALSE;
365 ACPI_FUNCTION_TRACE ("rs_list_to_byte_stream");
368 while (!done) {
369 switch (linked_list->id) {
370 case ACPI_RSTYPE_IRQ:
372 * IRQ Resource
374 status = acpi_rs_irq_stream (linked_list, &buffer, &bytes_consumed);
375 break;
377 case ACPI_RSTYPE_DMA:
379 * DMA Resource
381 status = acpi_rs_dma_stream (linked_list, &buffer, &bytes_consumed);
382 break;
384 case ACPI_RSTYPE_START_DPF:
386 * Start Dependent Functions Resource
388 status = acpi_rs_start_depend_fns_stream (linked_list,
389 &buffer, &bytes_consumed);
390 break;
392 case ACPI_RSTYPE_END_DPF:
394 * End Dependent Functions Resource
396 status = acpi_rs_end_depend_fns_stream (linked_list,
397 &buffer, &bytes_consumed);
398 break;
400 case ACPI_RSTYPE_IO:
402 * IO Port Resource
404 status = acpi_rs_io_stream (linked_list, &buffer, &bytes_consumed);
405 break;
407 case ACPI_RSTYPE_FIXED_IO:
409 * Fixed IO Port Resource
411 status = acpi_rs_fixed_io_stream (linked_list, &buffer, &bytes_consumed);
412 break;
414 case ACPI_RSTYPE_VENDOR:
416 * Vendor Defined Resource
418 status = acpi_rs_vendor_stream (linked_list, &buffer, &bytes_consumed);
419 break;
421 case ACPI_RSTYPE_END_TAG:
423 * End Tag
425 status = acpi_rs_end_tag_stream (linked_list, &buffer, &bytes_consumed);
428 * An End Tag indicates the end of the Resource Template
430 done = TRUE;
431 break;
433 case ACPI_RSTYPE_MEM24:
435 * 24-Bit Memory Resource
437 status = acpi_rs_memory24_stream (linked_list, &buffer, &bytes_consumed);
438 break;
440 case ACPI_RSTYPE_MEM32:
442 * 32-Bit Memory Range Resource
444 status = acpi_rs_memory32_range_stream (linked_list, &buffer,
445 &bytes_consumed);
446 break;
448 case ACPI_RSTYPE_FIXED_MEM32:
450 * 32-Bit Fixed Memory Resource
452 status = acpi_rs_fixed_memory32_stream (linked_list, &buffer,
453 &bytes_consumed);
454 break;
456 case ACPI_RSTYPE_ADDRESS16:
458 * 16-Bit Address Descriptor Resource
460 status = acpi_rs_address16_stream (linked_list, &buffer,
461 &bytes_consumed);
462 break;
464 case ACPI_RSTYPE_ADDRESS32:
466 * 32-Bit Address Descriptor Resource
468 status = acpi_rs_address32_stream (linked_list, &buffer,
469 &bytes_consumed);
470 break;
472 case ACPI_RSTYPE_ADDRESS64:
474 * 64-Bit Address Descriptor Resource
476 status = acpi_rs_address64_stream (linked_list, &buffer,
477 &bytes_consumed);
478 break;
480 case ACPI_RSTYPE_EXT_IRQ:
482 * Extended IRQ Resource
484 status = acpi_rs_extended_irq_stream (linked_list, &buffer,
485 &bytes_consumed);
486 break;
488 default:
490 * If we get here, everything is out of sync,
491 * so exit with an error
493 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid descriptor type (%X) in resource list\n",
494 linked_list->id));
495 status = AE_BAD_DATA;
496 break;
498 } /* switch (linked_list->Id) */
500 if (ACPI_FAILURE (status)) {
501 return_ACPI_STATUS (status);
505 * Set the Buffer to point to the open byte
507 buffer += bytes_consumed;
510 * Point to the next object
512 linked_list = ACPI_PTR_ADD (struct acpi_resource,
513 linked_list, linked_list->length);
516 return_ACPI_STATUS (AE_OK);