1 /*******************************************************************************
3 * Module Name: rslist - Acpi_rs_byte_stream_to_list
4 * Acpi_list_to_byte_stream
7 ******************************************************************************/
10 * Copyright (C) 2000, 2001 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
31 #define _COMPONENT ACPI_RESOURCES
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 ******************************************************************************/
52 acpi_rs_byte_stream_to_list (
53 u8
*byte_stream_buffer
,
54 u32 byte_stream_buffer_length
,
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
) {
69 * Look at the next byte in the stream
71 resource_type
= *byte_stream_buffer
;
74 * See if this is a small or large resource
76 if(resource_type
& 0x80) {
80 switch (resource_type
) {
83 * 24-Bit Memory Resource
85 status
= acpi_rs_memory24_resource(byte_stream_buffer
,
92 case LARGE_VENDOR_DEFINED
:
94 * Vendor Defined Resource
96 status
= acpi_rs_vendor_resource(byte_stream_buffer
,
103 case MEMORY_RANGE_32
:
105 * 32-Bit Memory Range Resource
107 status
= acpi_rs_memory32_range_resource(byte_stream_buffer
,
114 case FIXED_MEMORY_RANGE_32
:
116 * 32-Bit Fixed Memory Resource
118 status
= acpi_rs_fixed_memory32_resource(byte_stream_buffer
,
125 case DWORD_ADDRESS_SPACE
:
127 * 32-Bit Address Resource
129 status
= acpi_rs_address32_resource(byte_stream_buffer
,
136 case WORD_ADDRESS_SPACE
:
138 * 16-Bit Address Resource
140 status
= acpi_rs_address16_resource(byte_stream_buffer
,
151 status
= acpi_rs_extended_irq_resource(byte_stream_buffer
,
158 /* TBD: [Future] 64-bit not currently supported */
166 * If we get here, everything is out of sync,
167 * so exit with an error
169 return (AE_AML_ERROR
);
176 * Small Resource Type
177 * Only bits 7:3 are valid
181 switch(resource_type
) {
186 status
= acpi_rs_irq_resource(byte_stream_buffer
,
197 status
= acpi_rs_dma_resource(byte_stream_buffer
,
204 case START_DEPENDENT_TAG
:
206 * Start Dependent Functions Resource
208 status
= acpi_rs_start_dependent_functions_resource(byte_stream_buffer
,
215 case END_DEPENDENT_TAG
:
217 * End Dependent Functions Resource
219 status
= acpi_rs_end_dependent_functions_resource(byte_stream_buffer
,
226 case IO_PORT_DESCRIPTOR
:
230 status
= acpi_rs_io_resource(byte_stream_buffer
,
237 case FIXED_LOCATION_IO_DESCRIPTOR
:
239 * Fixed IO Port Resource
241 status
= acpi_rs_fixed_io_resource(byte_stream_buffer
,
248 case SMALL_VENDOR_DEFINED
:
250 * Vendor Specific Resource
252 status
= acpi_rs_vendor_resource(byte_stream_buffer
,
263 status
= acpi_rs_end_tag_resource(byte_stream_buffer
,
267 end_tag_processed
= TRUE
;
273 * If we get here, everything is out of sync,
274 * so exit with an error
276 return (AE_AML_ERROR
);
283 * Update the return value and counter
285 bytes_parsed
+= bytes_consumed
;
288 * Set the byte stream to point to the next resource
290 byte_stream_buffer
+= bytes_consumed
;
293 * Set the Buffer to the next structure
295 *buffer
+= structure_size
;
300 * Check the reason for exiting the while loop
302 if (TRUE
!= end_tag_processed
) {
303 return (AE_AML_ERROR
);
310 /*******************************************************************************
312 * FUNCTION: Acpi_rs_list_to_byte_stream
314 * PARAMETERS: Linked_list - Pointer to the resource linked list
315 * Byte_steam_size_needed - Calculated size of the byte stream
316 * needed from calling
317 * Acpi_rs_calculate_byte_stream_length()
318 * The size of the Output_buffer is
319 * guaranteed to be >=
320 * Byte_stream_size_needed
321 * Output_buffer - Pointer to the buffer that will
322 * contain the byte stream
324 * RETURN: Status AE_OK if okay, else a valid ACPI_STATUS code
326 * DESCRIPTION: Takes the resource linked list and parses it, creating a
327 * byte stream of resources in the caller's output buffer
329 ******************************************************************************/
332 acpi_rs_list_to_byte_stream (
333 RESOURCE
*linked_list
,
334 u32 byte_stream_size_needed
,
338 u8
*buffer
= *output_buffer
;
339 u32 bytes_consumed
= 0;
344 switch (linked_list
->id
) {
349 status
= acpi_rs_irq_stream (linked_list
,
358 status
= acpi_rs_dma_stream (linked_list
,
363 case start_dependent_functions
:
365 * Start Dependent Functions Resource
367 status
= acpi_rs_start_dependent_functions_stream (linked_list
,
372 case end_dependent_functions
:
374 * End Dependent Functions Resource
376 status
= acpi_rs_end_dependent_functions_stream (linked_list
,
385 status
= acpi_rs_io_stream (linked_list
,
392 * Fixed IO Port Resource
394 status
= acpi_rs_fixed_io_stream (linked_list
,
399 case vendor_specific
:
401 * Vendor Defined Resource
403 status
= acpi_rs_vendor_stream (linked_list
,
412 status
= acpi_rs_end_tag_stream (linked_list
,
417 * An End Tag indicates the end of the Resource Template
424 * 24-Bit Memory Resource
426 status
= acpi_rs_memory24_stream (linked_list
,
433 * 32-Bit Memory Range Resource
435 status
= acpi_rs_memory32_range_stream (linked_list
,
442 * 32-Bit Fixed Memory Resource
444 status
= acpi_rs_fixed_memory32_stream (linked_list
,
451 * 16-Bit Address Descriptor Resource
453 status
= acpi_rs_address16_stream (linked_list
,
460 * 32-Bit Address Descriptor Resource
462 status
= acpi_rs_address32_stream (linked_list
,
469 * Extended IRQ Resource
471 status
= acpi_rs_extended_irq_stream (linked_list
,
478 * If we get here, everything is out of sync,
479 * so exit with an error
481 return (AE_BAD_DATA
);
484 } /* switch (Linked_list->Id) */
487 * Set the Buffer to point to the open byte
489 buffer
+= bytes_consumed
;
492 * Point to the next object
494 linked_list
= (RESOURCE
*) ((NATIVE_UINT
) linked_list
+
495 (NATIVE_UINT
) linked_list
->length
);