rslist.c revision 91116
1/*******************************************************************************
2 *
3 * Module Name: rslist - Linked list utilities
4 *              $Revision: 26 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
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
20 * property rights.
21 *
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
28 *
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;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
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.
54 *
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
65 * make.
66 *
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
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
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.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
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
89 * PARTICULAR PURPOSE.
90 *
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
98 * LIMITED REMEDY.
99 *
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.
114 *
115 *****************************************************************************/
116
117#define __RSLIST_C__
118
119#include "acpi.h"
120#include "acresrc.h"
121
122#define _COMPONENT          ACPI_RESOURCES
123        ACPI_MODULE_NAME    ("rslist")
124
125
126/*******************************************************************************
127 *
128 * FUNCTION:    AcpiRsGetResourceType
129 *
130 * PARAMETERS:  ResourceStartByte       - Byte 0 of a resource descriptor
131 *
132 * RETURN:      The Resource Type (Name) with no extraneous bits
133 *
134 * DESCRIPTION: Extract the Resource Type/Name from the first byte of
135 *              a resource descriptor.
136 *
137 ******************************************************************************/
138
139UINT8
140AcpiRsGetResourceType (
141    UINT8                   ResourceStartByte)
142{
143
144    ACPI_FUNCTION_ENTRY ();
145
146
147    /*
148     * Determine if this is a small or large resource
149     */
150    switch (ResourceStartByte & ACPI_RDESC_TYPE_MASK)
151    {
152    case ACPI_RDESC_TYPE_SMALL:
153
154        /*
155         * Small Resource Type -- Only bits 6:3 are valid
156         */
157        return ((UINT8) (ResourceStartByte & ACPI_RDESC_SMALL_MASK));
158
159
160    case ACPI_RDESC_TYPE_LARGE:
161
162        /*
163         * Large Resource Type -- All bits are valid
164         */
165        return (ResourceStartByte);
166    }
167
168    return (0xFF);
169}
170
171
172/*******************************************************************************
173 *
174 * FUNCTION:    AcpiRsByteStreamToList
175 *
176 * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource byte stream
177 *              ByteStreamBufferLength  - Length of ByteStreamBuffer
178 *              OutputBuffer            - Pointer to the buffer that will
179 *                                        contain the output structures
180 *
181 * RETURN:      Status
182 *
183 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
184 *              linked list of resources in the caller's output buffer
185 *
186 ******************************************************************************/
187
188ACPI_STATUS
189AcpiRsByteStreamToList (
190    UINT8                   *ByteStreamBuffer,
191    UINT32                  ByteStreamBufferLength,
192    UINT8                   *OutputBuffer)
193{
194    ACPI_STATUS             Status;
195    UINT32                  BytesParsed = 0;
196    UINT8                   ResourceType = 0;
197    ACPI_SIZE               BytesConsumed = 0;
198    UINT8                   *Buffer = OutputBuffer;
199    ACPI_SIZE               StructureSize = 0;
200    BOOLEAN                 EndTagProcessed = FALSE;
201    ACPI_RESOURCE           *Resource;
202
203    ACPI_FUNCTION_TRACE ("RsByteStreamToList");
204
205
206    while (BytesParsed < ByteStreamBufferLength &&
207            FALSE == EndTagProcessed)
208    {
209        /*
210         * The next byte in the stream is the resource type
211         */
212        ResourceType = AcpiRsGetResourceType (*ByteStreamBuffer);
213
214        switch (ResourceType)
215        {
216        case ACPI_RDESC_TYPE_MEMORY_24:
217            /*
218             * 24-Bit Memory Resource
219             */
220            Status = AcpiRsMemory24Resource (ByteStreamBuffer,
221                        &BytesConsumed, &Buffer, &StructureSize);
222            break;
223
224
225        case ACPI_RDESC_TYPE_LARGE_VENDOR:
226            /*
227             * Vendor Defined Resource
228             */
229            Status = AcpiRsVendorResource (ByteStreamBuffer,
230                        &BytesConsumed, &Buffer, &StructureSize);
231            break;
232
233
234        case ACPI_RDESC_TYPE_MEMORY_32:
235            /*
236             * 32-Bit Memory Range Resource
237             */
238            Status = AcpiRsMemory32RangeResource (ByteStreamBuffer,
239                        &BytesConsumed, &Buffer, &StructureSize);
240            break;
241
242
243        case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
244            /*
245             * 32-Bit Fixed Memory Resource
246             */
247            Status = AcpiRsFixedMemory32Resource (ByteStreamBuffer,
248                        &BytesConsumed, &Buffer, &StructureSize);
249            break;
250
251
252        case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
253            /*
254             * 64-Bit Address Resource
255             */
256            Status = AcpiRsAddress64Resource (ByteStreamBuffer,
257                        &BytesConsumed, &Buffer, &StructureSize);
258            break;
259
260
261        case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
262            /*
263             * 32-Bit Address Resource
264             */
265            Status = AcpiRsAddress32Resource (ByteStreamBuffer,
266                        &BytesConsumed, &Buffer, &StructureSize);
267            break;
268
269
270        case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
271            /*
272             * 16-Bit Address Resource
273             */
274            Status = AcpiRsAddress16Resource (ByteStreamBuffer,
275                        &BytesConsumed, &Buffer, &StructureSize);
276            break;
277
278
279        case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
280            /*
281             * Extended IRQ
282             */
283            Status = AcpiRsExtendedIrqResource (ByteStreamBuffer,
284                        &BytesConsumed, &Buffer, &StructureSize);
285            break;
286
287
288        case ACPI_RDESC_TYPE_IRQ_FORMAT:
289            /*
290             * IRQ Resource
291             */
292            Status = AcpiRsIrqResource (ByteStreamBuffer,
293                        &BytesConsumed, &Buffer, &StructureSize);
294            break;
295
296
297        case ACPI_RDESC_TYPE_DMA_FORMAT:
298            /*
299             * DMA Resource
300             */
301            Status = AcpiRsDmaResource (ByteStreamBuffer,
302                        &BytesConsumed, &Buffer, &StructureSize);
303            break;
304
305
306        case ACPI_RDESC_TYPE_START_DEPENDENT:
307            /*
308             * Start Dependent Functions Resource
309             */
310            Status = AcpiRsStartDependFnsResource (ByteStreamBuffer,
311                        &BytesConsumed, &Buffer, &StructureSize);
312            break;
313
314
315        case ACPI_RDESC_TYPE_END_DEPENDENT:
316            /*
317             * End Dependent Functions Resource
318             */
319            Status = AcpiRsEndDependFnsResource (ByteStreamBuffer,
320                        &BytesConsumed, &Buffer, &StructureSize);
321            break;
322
323
324        case ACPI_RDESC_TYPE_IO_PORT:
325            /*
326             * IO Port Resource
327             */
328            Status = AcpiRsIoResource (ByteStreamBuffer,
329                        &BytesConsumed, &Buffer, &StructureSize);
330            break;
331
332
333        case ACPI_RDESC_TYPE_FIXED_IO_PORT:
334            /*
335             * Fixed IO Port Resource
336             */
337            Status = AcpiRsFixedIoResource (ByteStreamBuffer,
338                        &BytesConsumed, &Buffer, &StructureSize);
339            break;
340
341
342        case ACPI_RDESC_TYPE_SMALL_VENDOR:
343            /*
344             * Vendor Specific Resource
345             */
346            Status = AcpiRsVendorResource (ByteStreamBuffer,
347                        &BytesConsumed, &Buffer, &StructureSize);
348            break;
349
350
351        case ACPI_RDESC_TYPE_END_TAG:
352            /*
353             * End Tag
354             */
355            EndTagProcessed = TRUE;
356            Status = AcpiRsEndTagResource (ByteStreamBuffer,
357                        &BytesConsumed, &Buffer, &StructureSize);
358            break;
359
360
361        default:
362            /*
363             * Invalid/Unknowns resource type
364             */
365            Status = AE_AML_ERROR;
366            break;
367        }
368
369        if (ACPI_FAILURE (Status))
370        {
371            return_ACPI_STATUS (Status);
372        }
373
374        /*
375         * Update the return value and counter
376         */
377        BytesParsed += BytesConsumed;
378
379        /*
380         * Set the byte stream to point to the next resource
381         */
382        ByteStreamBuffer += BytesConsumed;
383
384        /*
385         * Set the Buffer to the next structure
386         */
387        Resource = (ACPI_RESOURCE *)Buffer;
388        Resource->Length = ACPI_ALIGN_RESOURCE_SIZE(Resource->Length);
389        Buffer += ACPI_ALIGN_RESOURCE_SIZE(StructureSize);
390
391    } /*  end while */
392
393    /*
394     * Check the reason for exiting the while loop
395     */
396    if (TRUE != EndTagProcessed)
397    {
398        return_ACPI_STATUS (AE_AML_ERROR);
399    }
400
401    return_ACPI_STATUS (AE_OK);
402}
403
404
405/*******************************************************************************
406 *
407 * FUNCTION:    AcpiRsListToByteStream
408 *
409 * PARAMETERS:  LinkedList              - Pointer to the resource linked list
410 *              ByteSteamSizeNeeded     - Calculated size of the byte stream
411 *                                        needed from calling
412 *                                        AcpiRsCalculateByteStreamLength()
413 *                                        The size of the OutputBuffer is
414 *                                        guaranteed to be >=
415 *                                        ByteStreamSizeNeeded
416 *              OutputBuffer            - Pointer to the buffer that will
417 *                                        contain the byte stream
418 *
419 * RETURN:      Status
420 *
421 * DESCRIPTION: Takes the resource linked list and parses it, creating a
422 *              byte stream of resources in the caller's output buffer
423 *
424 ******************************************************************************/
425
426ACPI_STATUS
427AcpiRsListToByteStream (
428    ACPI_RESOURCE           *LinkedList,
429    UINT32                  ByteStreamSizeNeeded,
430    UINT8                   *OutputBuffer)
431{
432    ACPI_STATUS             Status;
433    UINT8                   *Buffer = OutputBuffer;
434    ACPI_SIZE               BytesConsumed = 0;
435    BOOLEAN                 Done = FALSE;
436
437
438    ACPI_FUNCTION_TRACE ("RsListToByteStream");
439
440
441    while (!Done)
442    {
443        switch (LinkedList->Id)
444        {
445        case ACPI_RSTYPE_IRQ:
446            /*
447             * IRQ Resource
448             */
449            Status = AcpiRsIrqStream (LinkedList, &Buffer, &BytesConsumed);
450            break;
451
452        case ACPI_RSTYPE_DMA:
453            /*
454             * DMA Resource
455             */
456            Status = AcpiRsDmaStream (LinkedList, &Buffer, &BytesConsumed);
457            break;
458
459        case ACPI_RSTYPE_START_DPF:
460            /*
461             * Start Dependent Functions Resource
462             */
463            Status = AcpiRsStartDependFnsStream (LinkedList,
464                            &Buffer, &BytesConsumed);
465            break;
466
467        case ACPI_RSTYPE_END_DPF:
468            /*
469             * End Dependent Functions Resource
470             */
471            Status = AcpiRsEndDependFnsStream (LinkedList,
472                            &Buffer, &BytesConsumed);
473            break;
474
475        case ACPI_RSTYPE_IO:
476            /*
477             * IO Port Resource
478             */
479            Status = AcpiRsIoStream (LinkedList, &Buffer, &BytesConsumed);
480            break;
481
482        case ACPI_RSTYPE_FIXED_IO:
483            /*
484             * Fixed IO Port Resource
485             */
486            Status = AcpiRsFixedIoStream (LinkedList, &Buffer, &BytesConsumed);
487            break;
488
489        case ACPI_RSTYPE_VENDOR:
490            /*
491             * Vendor Defined Resource
492             */
493            Status = AcpiRsVendorStream (LinkedList, &Buffer, &BytesConsumed);
494            break;
495
496        case ACPI_RSTYPE_END_TAG:
497            /*
498             * End Tag
499             */
500            Status = AcpiRsEndTagStream (LinkedList, &Buffer, &BytesConsumed);
501
502            /*
503             * An End Tag indicates the end of the Resource Template
504             */
505            Done = TRUE;
506            break;
507
508        case ACPI_RSTYPE_MEM24:
509            /*
510             * 24-Bit Memory Resource
511             */
512            Status = AcpiRsMemory24Stream (LinkedList, &Buffer, &BytesConsumed);
513            break;
514
515        case ACPI_RSTYPE_MEM32:
516            /*
517             * 32-Bit Memory Range Resource
518             */
519            Status = AcpiRsMemory32RangeStream (LinkedList, &Buffer,
520                        &BytesConsumed);
521            break;
522
523        case ACPI_RSTYPE_FIXED_MEM32:
524            /*
525             * 32-Bit Fixed Memory Resource
526             */
527            Status = AcpiRsFixedMemory32Stream (LinkedList, &Buffer,
528                        &BytesConsumed);
529            break;
530
531        case ACPI_RSTYPE_ADDRESS16:
532            /*
533             * 16-Bit Address Descriptor Resource
534             */
535            Status = AcpiRsAddress16Stream (LinkedList, &Buffer,
536                        &BytesConsumed);
537            break;
538
539        case ACPI_RSTYPE_ADDRESS32:
540            /*
541             * 32-Bit Address Descriptor Resource
542             */
543            Status = AcpiRsAddress32Stream (LinkedList, &Buffer,
544                        &BytesConsumed);
545            break;
546
547        case ACPI_RSTYPE_ADDRESS64:
548            /*
549             * 64-Bit Address Descriptor Resource
550             */
551            Status = AcpiRsAddress64Stream (LinkedList, &Buffer,
552                        &BytesConsumed);
553            break;
554
555        case ACPI_RSTYPE_EXT_IRQ:
556            /*
557             * Extended IRQ Resource
558             */
559            Status = AcpiRsExtendedIrqStream (LinkedList, &Buffer,
560                        &BytesConsumed);
561            break;
562
563        default:
564            /*
565             * If we get here, everything is out of sync,
566             *  so exit with an error
567             */
568            Status = AE_BAD_DATA;
569            break;
570
571        } /* switch (LinkedList->Id) */
572
573        if (ACPI_FAILURE (Status))
574        {
575            return_ACPI_STATUS (Status);
576        }
577
578        /*
579         * Set the Buffer to point to the open byte
580         */
581        Buffer += BytesConsumed;
582
583        /*
584         * Point to the next object
585         */
586        LinkedList = ACPI_PTR_ADD (ACPI_RESOURCE,
587                        LinkedList, LinkedList->Length);
588    }
589
590    return_ACPI_STATUS (AE_OK);
591}
592
593