1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
122 #define _COMPONENT ACPI_RESOURCES
123 ACPI_MODULE_NAME ("rslist")
126 /*******************************************************************************
128 * FUNCTION: AcpiRsGetResourceType
130 * PARAMETERS: ResourceStartByte - Byte 0 of a resource descriptor
132 * RETURN: The Resource Type (Name) with no extraneous bits
134 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
135 * a resource descriptor.
137 ******************************************************************************/
140 AcpiRsGetResourceType (
141 UINT8 ResourceStartByte)
144 ACPI_FUNCTION_ENTRY ();
148 * Determine if this is a small or large resource
150 switch (ResourceStartByte & ACPI_RDESC_TYPE_MASK)
152 case ACPI_RDESC_TYPE_SMALL:
155 * Small Resource Type -- Only bits 6:3 are valid
157 return ((UINT8) (ResourceStartByte & ACPI_RDESC_SMALL_MASK));
160 case ACPI_RDESC_TYPE_LARGE:
163 * Large Resource Type -- All bits are valid
165 return (ResourceStartByte);
169 /* No other types of resource descriptor */
177 /*******************************************************************************
179 * FUNCTION: AcpiRsByteStreamToList
181 * PARAMETERS: ByteStreamBuffer - Pointer to the resource byte stream
182 * ByteStreamBufferLength - Length of ByteStreamBuffer
183 * OutputBuffer - Pointer to the buffer that will
184 * contain the output structures
188 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
189 * linked list of resources in the caller's output buffer
191 ******************************************************************************/
194 AcpiRsByteStreamToList (
195 UINT8 *ByteStreamBuffer,
196 UINT32 ByteStreamBufferLength,
200 ACPI_SIZE BytesParsed = 0;
201 UINT8 ResourceType = 0;
202 ACPI_SIZE BytesConsumed = 0;
203 UINT8 *Buffer = OutputBuffer;
204 ACPI_SIZE StructureSize = 0;
205 BOOLEAN EndTagProcessed = FALSE;
206 ACPI_RESOURCE *Resource;
208 ACPI_FUNCTION_TRACE ("RsByteStreamToList");
211 while (BytesParsed < ByteStreamBufferLength &&
215 * The next byte in the stream is the resource type
217 ResourceType = AcpiRsGetResourceType (*ByteStreamBuffer);
219 switch (ResourceType)
221 case ACPI_RDESC_TYPE_MEMORY_24:
223 * 24-Bit Memory Resource
225 Status = AcpiRsMemory24Resource (ByteStreamBuffer,
226 &BytesConsumed, &Buffer, &StructureSize);
230 case ACPI_RDESC_TYPE_LARGE_VENDOR:
232 * Vendor Defined Resource
234 Status = AcpiRsVendorResource (ByteStreamBuffer,
235 &BytesConsumed, &Buffer, &StructureSize);
239 case ACPI_RDESC_TYPE_MEMORY_32:
241 * 32-Bit Memory Range Resource
243 Status = AcpiRsMemory32RangeResource (ByteStreamBuffer,
244 &BytesConsumed, &Buffer, &StructureSize);
248 case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
250 * 32-Bit Fixed Memory Resource
252 Status = AcpiRsFixedMemory32Resource (ByteStreamBuffer,
253 &BytesConsumed, &Buffer, &StructureSize);
257 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
259 * 64-Bit Address Resource
261 Status = AcpiRsAddress64Resource (ByteStreamBuffer,
262 &BytesConsumed, &Buffer, &StructureSize);
266 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
268 * 32-Bit Address Resource
270 Status = AcpiRsAddress32Resource (ByteStreamBuffer,
271 &BytesConsumed, &Buffer, &StructureSize);
275 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
277 * 16-Bit Address Resource
279 Status = AcpiRsAddress16Resource (ByteStreamBuffer,
280 &BytesConsumed, &Buffer, &StructureSize);
284 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
288 Status = AcpiRsExtendedIrqResource (ByteStreamBuffer,
289 &BytesConsumed, &Buffer, &StructureSize);
293 case ACPI_RDESC_TYPE_IRQ_FORMAT:
297 Status = AcpiRsIrqResource (ByteStreamBuffer,
298 &BytesConsumed, &Buffer, &StructureSize);
302 case ACPI_RDESC_TYPE_DMA_FORMAT:
306 Status = AcpiRsDmaResource (ByteStreamBuffer,
307 &BytesConsumed, &Buffer, &StructureSize);
311 case ACPI_RDESC_TYPE_START_DEPENDENT:
313 * Start Dependent Functions Resource
315 Status = AcpiRsStartDependFnsResource (ByteStreamBuffer,
316 &BytesConsumed, &Buffer, &StructureSize);
320 case ACPI_RDESC_TYPE_END_DEPENDENT:
322 * End Dependent Functions Resource
324 Status = AcpiRsEndDependFnsResource (ByteStreamBuffer,
325 &BytesConsumed, &Buffer, &StructureSize);
329 case ACPI_RDESC_TYPE_IO_PORT:
333 Status = AcpiRsIoResource (ByteStreamBuffer,
334 &BytesConsumed, &Buffer, &StructureSize);
338 case ACPI_RDESC_TYPE_FIXED_IO_PORT:
340 * Fixed IO Port Resource
342 Status = AcpiRsFixedIoResource (ByteStreamBuffer,
343 &BytesConsumed, &Buffer, &StructureSize);
347 case ACPI_RDESC_TYPE_SMALL_VENDOR:
349 * Vendor Specific Resource
351 Status = AcpiRsVendorResource (ByteStreamBuffer,
352 &BytesConsumed, &Buffer, &StructureSize);
356 case ACPI_RDESC_TYPE_END_TAG:
360 EndTagProcessed = TRUE;
361 Status = AcpiRsEndTagResource (ByteStreamBuffer,
362 &BytesConsumed, &Buffer, &StructureSize);
368 * Invalid/Unknown resource type
370 Status = AE_AML_INVALID_RESOURCE_TYPE;
374 if (ACPI_FAILURE (Status))
376 return_ACPI_STATUS (Status);
380 * Update the return value and counter
382 BytesParsed += BytesConsumed;
385 * Set the byte stream to point to the next resource
387 ByteStreamBuffer += BytesConsumed;
390 * Set the Buffer to the next structure
392 Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer);
393 Resource->Length = (UINT32) ACPI_ALIGN_RESOURCE_SIZE (Resource->Length);
394 Buffer += ACPI_ALIGN_RESOURCE_SIZE (StructureSize);
399 * Check the reason for exiting the while loop
401 if (!EndTagProcessed)
403 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
406 return_ACPI_STATUS (AE_OK);
410 /*******************************************************************************
412 * FUNCTION: AcpiRsListToByteStream
414 * PARAMETERS: LinkedList - Pointer to the resource linked list
415 * ByteSteamSizeNeeded - Calculated size of the byte stream
416 * needed from calling
417 * AcpiRsGetByteStreamLength()
418 * The size of the OutputBuffer is
419 * guaranteed to be >=
420 * ByteStreamSizeNeeded
421 * OutputBuffer - Pointer to the buffer that will
422 * contain the byte stream
426 * DESCRIPTION: Takes the resource linked list and parses it, creating a
427 * byte stream of resources in the caller's output buffer
429 ******************************************************************************/
432 AcpiRsListToByteStream (
433 ACPI_RESOURCE *LinkedList,
434 ACPI_SIZE ByteStreamSizeNeeded,
438 UINT8 *Buffer = OutputBuffer;
439 ACPI_SIZE BytesConsumed = 0;
440 BOOLEAN Done = FALSE;
443 ACPI_FUNCTION_TRACE ("RsListToByteStream");
448 switch (LinkedList->Id)
450 case ACPI_RSTYPE_IRQ:
454 Status = AcpiRsIrqStream (LinkedList, &Buffer, &BytesConsumed);
457 case ACPI_RSTYPE_DMA:
461 Status = AcpiRsDmaStream (LinkedList, &Buffer, &BytesConsumed);
464 case ACPI_RSTYPE_START_DPF:
466 * Start Dependent Functions Resource
468 Status = AcpiRsStartDependFnsStream (LinkedList,
469 &Buffer, &BytesConsumed);
472 case ACPI_RSTYPE_END_DPF:
474 * End Dependent Functions Resource
476 Status = AcpiRsEndDependFnsStream (LinkedList,
477 &Buffer, &BytesConsumed);
484 Status = AcpiRsIoStream (LinkedList, &Buffer, &BytesConsumed);
487 case ACPI_RSTYPE_FIXED_IO:
489 * Fixed IO Port Resource
491 Status = AcpiRsFixedIoStream (LinkedList, &Buffer, &BytesConsumed);
494 case ACPI_RSTYPE_VENDOR:
496 * Vendor Defined Resource
498 Status = AcpiRsVendorStream (LinkedList, &Buffer, &BytesConsumed);
501 case ACPI_RSTYPE_END_TAG:
505 Status = AcpiRsEndTagStream (LinkedList, &Buffer, &BytesConsumed);
508 * An End Tag indicates the end of the Resource Template
513 case ACPI_RSTYPE_MEM24:
515 * 24-Bit Memory Resource
517 Status = AcpiRsMemory24Stream (LinkedList, &Buffer, &BytesConsumed);
520 case ACPI_RSTYPE_MEM32:
522 * 32-Bit Memory Range Resource
524 Status = AcpiRsMemory32RangeStream (LinkedList, &Buffer,
528 case ACPI_RSTYPE_FIXED_MEM32:
530 * 32-Bit Fixed Memory Resource
532 Status = AcpiRsFixedMemory32Stream (LinkedList, &Buffer,
536 case ACPI_RSTYPE_ADDRESS16:
538 * 16-Bit Address Descriptor Resource
540 Status = AcpiRsAddress16Stream (LinkedList, &Buffer,
544 case ACPI_RSTYPE_ADDRESS32:
546 * 32-Bit Address Descriptor Resource
548 Status = AcpiRsAddress32Stream (LinkedList, &Buffer,
552 case ACPI_RSTYPE_ADDRESS64:
554 * 64-Bit Address Descriptor Resource
556 Status = AcpiRsAddress64Stream (LinkedList, &Buffer,
560 case ACPI_RSTYPE_EXT_IRQ:
562 * Extended IRQ Resource
564 Status = AcpiRsExtendedIrqStream (LinkedList, &Buffer,
570 * If we get here, everything is out of sync,
571 * so exit with an error
573 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid descriptor type (%X) in resource list\n",
575 Status = AE_BAD_DATA;
578 } /* switch (LinkedList->Id) */
580 if (ACPI_FAILURE (Status))
582 return_ACPI_STATUS (Status);
586 * Set the Buffer to point to the open byte
588 Buffer += BytesConsumed;
591 * Point to the next object
593 LinkedList = ACPI_PTR_ADD (ACPI_RESOURCE,
594 LinkedList, LinkedList->Length);
597 return_ACPI_STATUS (AE_OK);