- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / resources / rslist.c
blob8e39ddded00a66eafac2f89459aa3bfaf613d2d4
1 /*******************************************************************************
3 * Module Name: rslist - Acpi_rs_byte_stream_to_list
4 * Acpi_list_to_byte_stream
5 * $Revision: 8 $
7 ******************************************************************************/
9 /*
10 * Copyright (C) 2000 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "acpi.h"
29 #include "acresrc.h"
31 #define _COMPONENT RESOURCE_MANAGER
32 MODULE_NAME ("rslist")
35 /*******************************************************************************
37 * FUNCTION: Acpi_rs_byte_stream_to_list
39 * PARAMETERS: Byte_stream_buffer - Pointer to the resource byte stream
40 * Byte_stream_buffer_length - Length of Byte_stream_buffer
41 * Output_buffer - Pointer to the buffer that will
42 * contain the output structures
44 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
46 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
47 * linked list of resources in the caller's output buffer
49 ******************************************************************************/
51 ACPI_STATUS
52 acpi_rs_byte_stream_to_list (
53 u8 *byte_stream_buffer,
54 u32 byte_stream_buffer_length,
55 u8 **output_buffer)
57 ACPI_STATUS status;
58 u32 bytes_parsed = 0;
59 u8 resource_type = 0;
60 u32 bytes_consumed = 0;
61 u8 **buffer = output_buffer;
62 u32 structure_size = 0;
63 u8 end_tag_processed = FALSE;
66 while (bytes_parsed < byte_stream_buffer_length &&
67 FALSE == end_tag_processed)
70 * Look at the next byte in the stream
72 resource_type = *byte_stream_buffer;
75 * See if this is a small or large resource
77 if(resource_type & 0x80) {
79 * Large Resource Type
81 switch (resource_type)
83 case MEMORY_RANGE_24:
85 * 24-Bit Memory Resource
87 status = acpi_rs_memory24_resource(byte_stream_buffer,
88 &bytes_consumed,
89 buffer,
90 &structure_size);
92 break;
94 case LARGE_VENDOR_DEFINED:
96 * Vendor Defined Resource
98 status = acpi_rs_vendor_resource(byte_stream_buffer,
99 &bytes_consumed,
100 buffer,
101 &structure_size);
103 break;
105 case MEMORY_RANGE_32:
107 * 32-Bit Memory Range Resource
109 status = acpi_rs_memory32_range_resource(byte_stream_buffer,
110 &bytes_consumed,
111 buffer,
112 &structure_size);
114 break;
116 case FIXED_MEMORY_RANGE_32:
118 * 32-Bit Fixed Memory Resource
120 status = acpi_rs_fixed_memory32_resource(byte_stream_buffer,
121 &bytes_consumed,
122 buffer,
123 &structure_size);
125 break;
127 case DWORD_ADDRESS_SPACE:
129 * 32-Bit Address Resource
131 status = acpi_rs_address32_resource(byte_stream_buffer,
132 &bytes_consumed,
133 buffer,
134 &structure_size);
136 break;
138 case WORD_ADDRESS_SPACE:
140 * 16-Bit Address Resource
142 status = acpi_rs_address16_resource(byte_stream_buffer,
143 &bytes_consumed,
144 buffer,
145 &structure_size);
147 break;
149 case EXTENDED_IRQ:
151 * Extended IRQ
153 status = acpi_rs_extended_irq_resource(byte_stream_buffer,
154 &bytes_consumed,
155 buffer,
156 &structure_size);
158 break;
160 /* TBD: [Future] 64-bit not currently supported */
162 case 0x8A:
163 break;
166 default:
168 * If we get here, everything is out of sync,
169 * so exit with an error
171 return (AE_AML_ERROR);
172 break;
176 else {
178 * Small Resource Type
179 * Only bits 7:3 are valid
181 resource_type >>= 3;
183 switch(resource_type)
185 case IRQ_FORMAT:
187 * IRQ Resource
189 status = acpi_rs_irq_resource(byte_stream_buffer,
190 &bytes_consumed,
191 buffer,
192 &structure_size);
194 break;
196 case DMA_FORMAT:
198 * DMA Resource
200 status = acpi_rs_dma_resource(byte_stream_buffer,
201 &bytes_consumed,
202 buffer,
203 &structure_size);
205 break;
207 case START_DEPENDENT_TAG:
209 * Start Dependent Functions Resource
211 status = acpi_rs_start_dependent_functions_resource(byte_stream_buffer,
212 &bytes_consumed,
213 buffer,
214 &structure_size);
216 break;
218 case END_DEPENDENT_TAG:
220 * End Dependent Functions Resource
222 status = acpi_rs_end_dependent_functions_resource(byte_stream_buffer,
223 &bytes_consumed,
224 buffer,
225 &structure_size);
227 break;
229 case IO_PORT_DESCRIPTOR:
231 * IO Port Resource
233 status = acpi_rs_io_resource(byte_stream_buffer,
234 &bytes_consumed,
235 buffer,
236 &structure_size);
238 break;
240 case FIXED_LOCATION_IO_DESCRIPTOR:
242 * Fixed IO Port Resource
244 status = acpi_rs_fixed_io_resource(byte_stream_buffer,
245 &bytes_consumed,
246 buffer,
247 &structure_size);
249 break;
251 case SMALL_VENDOR_DEFINED:
253 * Vendor Specific Resource
255 status = acpi_rs_vendor_resource(byte_stream_buffer,
256 &bytes_consumed,
257 buffer,
258 &structure_size);
260 break;
262 case END_TAG:
264 * End Tag
266 status = acpi_rs_end_tag_resource(byte_stream_buffer,
267 &bytes_consumed,
268 buffer,
269 &structure_size);
270 end_tag_processed = TRUE;
272 break;
274 default:
276 * If we get here, everything is out of sync,
277 * so exit with an error
279 return (AE_AML_ERROR);
280 break;
282 } /* switch */
283 } /* end else */
286 * Update the return value and counter
288 bytes_parsed += bytes_consumed;
291 * Set the byte stream to point to the next resource
293 byte_stream_buffer += bytes_consumed;
296 * Set the Buffer to the next structure
298 *buffer += structure_size;
300 } /* end while */
303 * Check the reason for exiting the while loop
305 if (!(byte_stream_buffer_length == bytes_parsed) ||
306 (TRUE != end_tag_processed))
308 return (AE_AML_ERROR);
311 return (AE_OK);
315 /*******************************************************************************
317 * FUNCTION: Acpi_rs_list_to_byte_stream
319 * PARAMETERS: Linked_list - Pointer to the resource linked list
320 * Byte_steam_size_needed - Calculated size of the byte stream
321 * needed from calling
322 * Acpi_rs_calculate_byte_stream_length()
323 * The size of the Output_buffer is
324 * guaranteed to be >=
325 * Byte_stream_size_needed
326 * Output_buffer - Pointer to the buffer that will
327 * contain the byte stream
329 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
331 * DESCRIPTION: Takes the resource linked list and parses it, creating a
332 * byte stream of resources in the caller's output buffer
334 ******************************************************************************/
336 ACPI_STATUS
337 acpi_rs_list_to_byte_stream (
338 RESOURCE *linked_list,
339 u32 byte_stream_size_needed,
340 u8 **output_buffer)
342 ACPI_STATUS status;
343 u8 *buffer = *output_buffer;
344 u32 bytes_consumed = 0;
345 u8 done = FALSE;
348 while (!done) {
349 switch (linked_list->id)
351 case irq:
353 * IRQ Resource
355 status = acpi_rs_irq_stream (linked_list,
356 &buffer,
357 &bytes_consumed);
358 break;
360 case dma:
362 * DMA Resource
364 status = acpi_rs_dma_stream (linked_list,
365 &buffer,
366 &bytes_consumed);
367 break;
369 case start_dependent_functions:
371 * Start Dependent Functions Resource
373 status = acpi_rs_start_dependent_functions_stream (linked_list,
374 &buffer,
375 &bytes_consumed);
376 break;
378 case end_dependent_functions:
380 * End Dependent Functions Resource
382 status = acpi_rs_end_dependent_functions_stream (linked_list,
383 &buffer,
384 &bytes_consumed);
385 break;
387 case io:
389 * IO Port Resource
391 status = acpi_rs_io_stream (linked_list,
392 &buffer,
393 &bytes_consumed);
394 break;
396 case fixed_io:
398 * Fixed IO Port Resource
400 status = acpi_rs_fixed_io_stream (linked_list,
401 &buffer,
402 &bytes_consumed);
403 break;
405 case vendor_specific:
407 * Vendor Defined Resource
409 status = acpi_rs_vendor_stream (linked_list,
410 &buffer,
411 &bytes_consumed);
412 break;
414 case end_tag:
416 * End Tag
418 status = acpi_rs_end_tag_stream (linked_list,
419 &buffer,
420 &bytes_consumed);
423 * An End Tag indicates the end of the Resource Template
425 done = TRUE;
426 break;
428 case memory24:
430 * 24-Bit Memory Resource
432 status = acpi_rs_memory24_stream (linked_list,
433 &buffer,
434 &bytes_consumed);
435 break;
437 case memory32:
439 * 32-Bit Memory Range Resource
441 status = acpi_rs_memory32_range_stream (linked_list,
442 &buffer,
443 &bytes_consumed);
444 break;
446 case fixed_memory32:
448 * 32-Bit Fixed Memory Resource
450 status = acpi_rs_fixed_memory32_stream (linked_list,
451 &buffer,
452 &bytes_consumed);
453 break;
455 case address16:
457 * 16-Bit Address Descriptor Resource
459 status = acpi_rs_address16_stream (linked_list,
460 &buffer,
461 &bytes_consumed);
462 break;
464 case address32:
466 * 32-Bit Address Descriptor Resource
468 status = acpi_rs_address32_stream (linked_list,
469 &buffer,
470 &bytes_consumed);
471 break;
473 case extended_irq:
475 * Extended IRQ Resource
477 status = acpi_rs_extended_irq_stream (linked_list,
478 &buffer,
479 &bytes_consumed);
480 break;
482 default:
484 * If we get here, everything is out of sync,
485 * so exit with an error
487 return (AE_BAD_DATA);
488 break;
490 } /* switch (Linked_list->Id) */
493 * Set the Buffer to point to the open byte
495 buffer += bytes_consumed;
498 * Point to the next object
500 linked_list = (RESOURCE *) ((NATIVE_UINT) linked_list +
501 (NATIVE_UINT) linked_list->length);
504 return (AE_OK);