1 /*******************************************************************************
3 * Module Name: rslist - Linked list utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/rslist.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
123 #define _COMPONENT ACPI_RESOURCES
124 ACPI_MODULE_NAME ("rslist")
127 /*******************************************************************************
129 * FUNCTION: AcpiRsGetResourceType
131 * PARAMETERS: ResourceStartByte - Byte 0 of a resource descriptor
133 * RETURN: The Resource Type (Name) with no extraneous bits
135 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
136 * a resource descriptor.
138 ******************************************************************************/
141 AcpiRsGetResourceType (
142 UINT8 ResourceStartByte)
145 ACPI_FUNCTION_ENTRY ();
149 * Determine if this is a small or large resource
151 switch (ResourceStartByte & ACPI_RDESC_TYPE_MASK)
153 case ACPI_RDESC_TYPE_SMALL:
156 * Small Resource Type -- Only bits 6:3 are valid
158 return ((UINT8) (ResourceStartByte & ACPI_RDESC_SMALL_MASK));
161 case ACPI_RDESC_TYPE_LARGE:
164 * Large Resource Type -- All bits are valid
166 return (ResourceStartByte);
170 /* No other types of resource descriptor */
178 /*******************************************************************************
180 * FUNCTION: AcpiRsByteStreamToList
182 * PARAMETERS: ByteStreamBuffer - Pointer to the resource byte stream
183 * ByteStreamBufferLength - Length of ByteStreamBuffer
184 * OutputBuffer - Pointer to the buffer that will
185 * contain the output structures
189 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
190 * linked list of resources in the caller's output buffer
192 ******************************************************************************/
195 AcpiRsByteStreamToList (
196 UINT8 *ByteStreamBuffer,
197 UINT32 ByteStreamBufferLength,
201 ACPI_SIZE BytesParsed = 0;
202 UINT8 ResourceType = 0;
203 ACPI_SIZE BytesConsumed = 0;
204 UINT8 *Buffer = OutputBuffer;
205 ACPI_SIZE StructureSize = 0;
206 BOOLEAN EndTagProcessed = FALSE;
207 ACPI_RESOURCE *Resource;
209 ACPI_FUNCTION_TRACE ("RsByteStreamToList");
212 while (BytesParsed < ByteStreamBufferLength &&
216 * The next byte in the stream is the resource type
218 ResourceType = AcpiRsGetResourceType (*ByteStreamBuffer);
220 switch (ResourceType)
222 case ACPI_RDESC_TYPE_MEMORY_24:
224 * 24-Bit Memory Resource
226 Status = AcpiRsMemory24Resource (ByteStreamBuffer,
227 &BytesConsumed, &Buffer, &StructureSize);
231 case ACPI_RDESC_TYPE_LARGE_VENDOR:
233 * Vendor Defined Resource
235 Status = AcpiRsVendorResource (ByteStreamBuffer,
236 &BytesConsumed, &Buffer, &StructureSize);
240 case ACPI_RDESC_TYPE_MEMORY_32:
242 * 32-Bit Memory Range Resource
244 Status = AcpiRsMemory32RangeResource (ByteStreamBuffer,
245 &BytesConsumed, &Buffer, &StructureSize);
249 case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
251 * 32-Bit Fixed Memory Resource
253 Status = AcpiRsFixedMemory32Resource (ByteStreamBuffer,
254 &BytesConsumed, &Buffer, &StructureSize);
258 case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
260 * 64-Bit Address Resource
262 Status = AcpiRsAddress64Resource (ByteStreamBuffer,
263 &BytesConsumed, &Buffer, &StructureSize);
267 case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
269 * 32-Bit Address Resource
271 Status = AcpiRsAddress32Resource (ByteStreamBuffer,
272 &BytesConsumed, &Buffer, &StructureSize);
276 case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
278 * 16-Bit Address Resource
280 Status = AcpiRsAddress16Resource (ByteStreamBuffer,
281 &BytesConsumed, &Buffer, &StructureSize);
285 case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
289 Status = AcpiRsExtendedIrqResource (ByteStreamBuffer,
290 &BytesConsumed, &Buffer, &StructureSize);
294 case ACPI_RDESC_TYPE_IRQ_FORMAT:
298 Status = AcpiRsIrqResource (ByteStreamBuffer,
299 &BytesConsumed, &Buffer, &StructureSize);
303 case ACPI_RDESC_TYPE_DMA_FORMAT:
307 Status = AcpiRsDmaResource (ByteStreamBuffer,
308 &BytesConsumed, &Buffer, &StructureSize);
312 case ACPI_RDESC_TYPE_START_DEPENDENT:
314 * Start Dependent Functions Resource
316 Status = AcpiRsStartDependFnsResource (ByteStreamBuffer,
317 &BytesConsumed, &Buffer, &StructureSize);
321 case ACPI_RDESC_TYPE_END_DEPENDENT:
323 * End Dependent Functions Resource
325 Status = AcpiRsEndDependFnsResource (ByteStreamBuffer,
326 &BytesConsumed, &Buffer, &StructureSize);
330 case ACPI_RDESC_TYPE_IO_PORT:
334 Status = AcpiRsIoResource (ByteStreamBuffer,
335 &BytesConsumed, &Buffer, &StructureSize);
339 case ACPI_RDESC_TYPE_FIXED_IO_PORT:
341 * Fixed IO Port Resource
343 Status = AcpiRsFixedIoResource (ByteStreamBuffer,
344 &BytesConsumed, &Buffer, &StructureSize);
348 case ACPI_RDESC_TYPE_SMALL_VENDOR:
350 * Vendor Specific Resource
352 Status = AcpiRsVendorResource (ByteStreamBuffer,
353 &BytesConsumed, &Buffer, &StructureSize);
357 case ACPI_RDESC_TYPE_END_TAG:
361 EndTagProcessed = TRUE;
362 Status = AcpiRsEndTagResource (ByteStreamBuffer,
363 &BytesConsumed, &Buffer, &StructureSize);
369 * Invalid/Unknown resource type
371 Status = AE_AML_INVALID_RESOURCE_TYPE;
375 if (ACPI_FAILURE (Status))
377 return_ACPI_STATUS (Status);
381 * Update the return value and counter
383 BytesParsed += BytesConsumed;
386 * Set the byte stream to point to the next resource
388 ByteStreamBuffer += BytesConsumed;
391 * Set the Buffer to the next structure
393 Resource = ACPI_CAST_PTR (ACPI_RESOURCE, Buffer);
394 Resource->Length = ACPI_ALIGN_RESOURCE_SIZE(Resource->Length);
395 Buffer += ACPI_ALIGN_RESOURCE_SIZE(StructureSize);
400 * Check the reason for exiting the while loop
402 if (!EndTagProcessed)
404 return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
407 return_ACPI_STATUS (AE_OK);
411 /*******************************************************************************
413 * FUNCTION: AcpiRsListToByteStream
415 * PARAMETERS: LinkedList - Pointer to the resource linked list
416 * ByteSteamSizeNeeded - Calculated size of the byte stream
417 * needed from calling
418 * AcpiRsGetByteStreamLength()
419 * The size of the OutputBuffer is
420 * guaranteed to be >=
421 * ByteStreamSizeNeeded
422 * OutputBuffer - Pointer to the buffer that will
423 * contain the byte stream
427 * DESCRIPTION: Takes the resource linked list and parses it, creating a
428 * byte stream of resources in the caller's output buffer
430 ******************************************************************************/
433 AcpiRsListToByteStream (
434 ACPI_RESOURCE *LinkedList,
435 ACPI_SIZE ByteStreamSizeNeeded,
439 UINT8 *Buffer = OutputBuffer;
440 ACPI_SIZE BytesConsumed = 0;
441 BOOLEAN Done = FALSE;
444 ACPI_FUNCTION_TRACE ("RsListToByteStream");
449 switch (LinkedList->Id)
451 case ACPI_RSTYPE_IRQ:
455 Status = AcpiRsIrqStream (LinkedList, &Buffer, &BytesConsumed);
458 case ACPI_RSTYPE_DMA:
462 Status = AcpiRsDmaStream (LinkedList, &Buffer, &BytesConsumed);
465 case ACPI_RSTYPE_START_DPF:
467 * Start Dependent Functions Resource
469 Status = AcpiRsStartDependFnsStream (LinkedList,
470 &Buffer, &BytesConsumed);
473 case ACPI_RSTYPE_END_DPF:
475 * End Dependent Functions Resource
477 Status = AcpiRsEndDependFnsStream (LinkedList,
478 &Buffer, &BytesConsumed);
485 Status = AcpiRsIoStream (LinkedList, &Buffer, &BytesConsumed);
488 case ACPI_RSTYPE_FIXED_IO:
490 * Fixed IO Port Resource
492 Status = AcpiRsFixedIoStream (LinkedList, &Buffer, &BytesConsumed);
495 case ACPI_RSTYPE_VENDOR:
497 * Vendor Defined Resource
499 Status = AcpiRsVendorStream (LinkedList, &Buffer, &BytesConsumed);
502 case ACPI_RSTYPE_END_TAG:
506 Status = AcpiRsEndTagStream (LinkedList, &Buffer, &BytesConsumed);
509 * An End Tag indicates the end of the Resource Template
514 case ACPI_RSTYPE_MEM24:
516 * 24-Bit Memory Resource
518 Status = AcpiRsMemory24Stream (LinkedList, &Buffer, &BytesConsumed);
521 case ACPI_RSTYPE_MEM32:
523 * 32-Bit Memory Range Resource
525 Status = AcpiRsMemory32RangeStream (LinkedList, &Buffer,
529 case ACPI_RSTYPE_FIXED_MEM32:
531 * 32-Bit Fixed Memory Resource
533 Status = AcpiRsFixedMemory32Stream (LinkedList, &Buffer,
537 case ACPI_RSTYPE_ADDRESS16:
539 * 16-Bit Address Descriptor Resource
541 Status = AcpiRsAddress16Stream (LinkedList, &Buffer,
545 case ACPI_RSTYPE_ADDRESS32:
547 * 32-Bit Address Descriptor Resource
549 Status = AcpiRsAddress32Stream (LinkedList, &Buffer,
553 case ACPI_RSTYPE_ADDRESS64:
555 * 64-Bit Address Descriptor Resource
557 Status = AcpiRsAddress64Stream (LinkedList, &Buffer,
561 case ACPI_RSTYPE_EXT_IRQ:
563 * Extended IRQ Resource
565 Status = AcpiRsExtendedIrqStream (LinkedList, &Buffer,
571 * If we get here, everything is out of sync,
572 * so exit with an error
574 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid descriptor type (%X) in resource list\n",
576 Status = AE_BAD_DATA;
579 } /* switch (LinkedList->Id) */
581 if (ACPI_FAILURE (Status))
583 return_ACPI_STATUS (Status);
587 * Set the Buffer to point to the open byte
589 Buffer += BytesConsumed;
592 * Point to the next object
594 LinkedList = ACPI_PTR_ADD (ACPI_RESOURCE,
595 LinkedList, LinkedList->Length);
598 return_ACPI_STATUS (AE_OK);