rslist.c revision 77424
1/*******************************************************************************
2 *
3 * Module Name: rslist - Linked list utilities
4 *              $Revision: 17 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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        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    /*
145     * Determine if this is a small or large resource
146     */
147    switch (ResourceStartByte & RESOURCE_DESC_TYPE_MASK)
148    {
149    case RESOURCE_DESC_TYPE_SMALL:
150
151        /*
152         * Small Resource Type -- Only bits 6:3 are valid
153         */
154        return ((UINT8) (ResourceStartByte & RESOURCE_DESC_SMALL_MASK));
155        break;
156
157
158    case RESOURCE_DESC_TYPE_LARGE:
159
160        /*
161         * Large Resource Type -- All bits are valid
162         */
163        return (ResourceStartByte);
164        break;
165    }
166
167    return (0xFF);
168}
169
170
171/*******************************************************************************
172 *
173 * FUNCTION:    AcpiRsByteStreamToList
174 *
175 * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource byte stream
176 *              ByteStreamBufferLength  - Length of ByteStreamBuffer
177 *              OutputBuffer            - Pointer to the buffer that will
178 *                                        contain the output structures
179 *
180 * RETURN:      Status
181 *
182 * DESCRIPTION: Takes the resource byte stream and parses it, creating a
183 *              linked list of resources in the caller's output buffer
184 *
185 ******************************************************************************/
186
187ACPI_STATUS
188AcpiRsByteStreamToList (
189    UINT8                   *ByteStreamBuffer,
190    UINT32                  ByteStreamBufferLength,
191    UINT8                   **OutputBuffer)
192{
193    ACPI_STATUS             Status;
194    UINT32                  BytesParsed = 0;
195    UINT8                   ResourceType = 0;
196    UINT32                  BytesConsumed = 0;
197    UINT8                   **Buffer = OutputBuffer;
198    UINT32                  StructureSize = 0;
199    BOOLEAN                 EndTagProcessed = FALSE;
200
201
202    FUNCTION_TRACE ("RsByteStreamToList");
203
204
205    while (BytesParsed < ByteStreamBufferLength &&
206            FALSE == EndTagProcessed)
207    {
208        /*
209         * The next byte in the stream is the resource type
210         */
211        ResourceType = AcpiRsGetResourceType (*ByteStreamBuffer);
212
213        switch (ResourceType)
214        {
215        case RESOURCE_DESC_MEMORY_24:
216            /*
217             * 24-Bit Memory Resource
218             */
219            Status = AcpiRsMemory24Resource (ByteStreamBuffer,
220                        &BytesConsumed, Buffer, &StructureSize);
221            break;
222
223
224        case RESOURCE_DESC_LARGE_VENDOR:
225            /*
226             * Vendor Defined Resource
227             */
228            Status = AcpiRsVendorResource (ByteStreamBuffer,
229                        &BytesConsumed, Buffer, &StructureSize);
230            break;
231
232
233        case RESOURCE_DESC_MEMORY_32:
234            /*
235             * 32-Bit Memory Range Resource
236             */
237            Status = AcpiRsMemory32RangeResource (ByteStreamBuffer,
238                        &BytesConsumed, Buffer, &StructureSize);
239            break;
240
241
242        case RESOURCE_DESC_FIXED_MEMORY_32:
243            /*
244             * 32-Bit Fixed Memory Resource
245             */
246            Status = AcpiRsFixedMemory32Resource (ByteStreamBuffer,
247                        &BytesConsumed, Buffer, &StructureSize);
248            break;
249
250
251        case RESOURCE_DESC_QWORD_ADDRESS_SPACE:
252            /*
253             * 64-Bit Address Resource
254             */
255            Status = AcpiRsAddress64Resource (ByteStreamBuffer,
256                        &BytesConsumed, Buffer, &StructureSize);
257            break;
258
259
260        case RESOURCE_DESC_DWORD_ADDRESS_SPACE:
261            /*
262             * 32-Bit Address Resource
263             */
264            Status = AcpiRsAddress32Resource (ByteStreamBuffer,
265                        &BytesConsumed, Buffer, &StructureSize);
266            break;
267
268
269        case RESOURCE_DESC_WORD_ADDRESS_SPACE:
270            /*
271             * 16-Bit Address Resource
272             */
273            Status = AcpiRsAddress16Resource (ByteStreamBuffer,
274                        &BytesConsumed, Buffer, &StructureSize);
275            break;
276
277
278        case RESOURCE_DESC_EXTENDED_XRUPT:
279            /*
280             * Extended IRQ
281             */
282            Status = AcpiRsExtendedIrqResource (ByteStreamBuffer,
283                        &BytesConsumed, Buffer, &StructureSize);
284            break;
285
286
287        case RESOURCE_DESC_IRQ_FORMAT:
288            /*
289             * IRQ Resource
290             */
291            Status = AcpiRsIrqResource (ByteStreamBuffer,
292                        &BytesConsumed, Buffer, &StructureSize);
293            break;
294
295
296        case RESOURCE_DESC_DMA_FORMAT:
297            /*
298             * DMA Resource
299             */
300            Status = AcpiRsDmaResource (ByteStreamBuffer,
301                        &BytesConsumed, Buffer, &StructureSize);
302            break;
303
304
305        case RESOURCE_DESC_START_DEPENDENT:
306            /*
307             * Start Dependent Functions Resource
308             */
309            Status = AcpiRsStartDependentFunctionsResource (ByteStreamBuffer,
310                        &BytesConsumed, Buffer, &StructureSize);
311            break;
312
313
314        case RESOURCE_DESC_END_DEPENDENT:
315            /*
316             * End Dependent Functions Resource
317             */
318            Status = AcpiRsEndDependentFunctionsResource (ByteStreamBuffer,
319                        &BytesConsumed, Buffer, &StructureSize);
320            break;
321
322
323        case RESOURCE_DESC_IO_PORT:
324            /*
325             * IO Port Resource
326             */
327            Status = AcpiRsIoResource (ByteStreamBuffer,
328                        &BytesConsumed, Buffer, &StructureSize);
329            break;
330
331
332        case RESOURCE_DESC_FIXED_IO_PORT:
333            /*
334             * Fixed IO Port Resource
335             */
336            Status = AcpiRsFixedIoResource (ByteStreamBuffer,
337                        &BytesConsumed, Buffer, &StructureSize);
338            break;
339
340
341        case RESOURCE_DESC_SMALL_VENDOR:
342            /*
343             * Vendor Specific Resource
344             */
345            Status = AcpiRsVendorResource (ByteStreamBuffer,
346                        &BytesConsumed, Buffer, &StructureSize);
347            break;
348
349
350        case RESOURCE_DESC_END_TAG:
351            /*
352             * End Tag
353             */
354            EndTagProcessed = TRUE;
355            Status = AcpiRsEndTagResource (ByteStreamBuffer,
356                        &BytesConsumed, Buffer, &StructureSize);
357            break;
358
359
360        default:
361            /*
362             * Invalid/Unknowns resource type
363             */
364            Status = AE_AML_ERROR;
365            break;
366        }
367
368
369        if (!ACPI_SUCCESS(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        *Buffer += StructureSize;
388
389    } /*  end while */
390
391    /*
392     * Check the reason for exiting the while loop
393     */
394    if (TRUE != EndTagProcessed)
395    {
396        return_ACPI_STATUS (AE_AML_ERROR);
397    }
398
399    return_ACPI_STATUS (AE_OK);
400}
401
402
403/*******************************************************************************
404 *
405 * FUNCTION:    AcpiRsListToByteStream
406 *
407 * PARAMETERS:  LinkedList              - Pointer to the resource linked list
408 *              ByteSteamSizeNeeded     - Calculated size of the byte stream
409 *                                        needed from calling
410 *                                        AcpiRsCalculateByteStreamLength()
411 *                                        The size of the OutputBuffer is
412 *                                        guaranteed to be >=
413 *                                        ByteStreamSizeNeeded
414 *              OutputBuffer            - Pointer to the buffer that will
415 *                                        contain the byte stream
416 *
417 * RETURN:      Status
418 *
419 * DESCRIPTION: Takes the resource linked list and parses it, creating a
420 *              byte stream of resources in the caller's output buffer
421 *
422 ******************************************************************************/
423
424ACPI_STATUS
425AcpiRsListToByteStream (
426    ACPI_RESOURCE           *LinkedList,
427    UINT32                  ByteStreamSizeNeeded,
428    UINT8                   **OutputBuffer)
429{
430    ACPI_STATUS             Status;
431    UINT8                   *Buffer = *OutputBuffer;
432    UINT32                  BytesConsumed = 0;
433    BOOLEAN                 Done = FALSE;
434
435
436    FUNCTION_TRACE ("RsListToByteStream");
437
438    while (!Done)
439    {
440        switch (LinkedList->Id)
441        {
442        case ACPI_RSTYPE_IRQ:
443            /*
444             * IRQ Resource
445             */
446            Status = AcpiRsIrqStream (LinkedList, &Buffer, &BytesConsumed);
447            break;
448
449        case ACPI_RSTYPE_DMA:
450            /*
451             * DMA Resource
452             */
453            Status = AcpiRsDmaStream (LinkedList, &Buffer, &BytesConsumed);
454            break;
455
456        case ACPI_RSTYPE_START_DPF:
457            /*
458             * Start Dependent Functions Resource
459             */
460            Status = AcpiRsStartDependentFunctionsStream (LinkedList,
461                            &Buffer, &BytesConsumed);
462            break;
463
464        case ACPI_RSTYPE_END_DPF:
465            /*
466             * End Dependent Functions Resource
467             */
468            Status = AcpiRsEndDependentFunctionsStream (LinkedList,
469                            &Buffer, &BytesConsumed);
470            break;
471
472        case ACPI_RSTYPE_IO:
473            /*
474             * IO Port Resource
475             */
476            Status = AcpiRsIoStream (LinkedList, &Buffer, &BytesConsumed);
477            break;
478
479        case ACPI_RSTYPE_FIXED_IO:
480            /*
481             * Fixed IO Port Resource
482             */
483            Status = AcpiRsFixedIoStream (LinkedList, &Buffer, &BytesConsumed);
484            break;
485
486        case ACPI_RSTYPE_VENDOR:
487            /*
488             * Vendor Defined Resource
489             */
490            Status = AcpiRsVendorStream (LinkedList, &Buffer, &BytesConsumed);
491            break;
492
493        case ACPI_RSTYPE_END_TAG:
494            /*
495             * End Tag
496             */
497            Status = AcpiRsEndTagStream (LinkedList, &Buffer, &BytesConsumed);
498
499            /*
500             * An End Tag indicates the end of the Resource Template
501             */
502            Done = TRUE;
503            break;
504
505        case ACPI_RSTYPE_MEM24:
506            /*
507             * 24-Bit Memory Resource
508             */
509            Status = AcpiRsMemory24Stream (LinkedList, &Buffer, &BytesConsumed);
510            break;
511
512        case ACPI_RSTYPE_MEM32:
513            /*
514             * 32-Bit Memory Range Resource
515             */
516            Status = AcpiRsMemory32RangeStream (LinkedList, &Buffer,
517                        &BytesConsumed);
518            break;
519
520        case ACPI_RSTYPE_FIXED_MEM32:
521            /*
522             * 32-Bit Fixed Memory Resource
523             */
524            Status = AcpiRsFixedMemory32Stream (LinkedList, &Buffer,
525                        &BytesConsumed);
526            break;
527
528        case ACPI_RSTYPE_ADDRESS16:
529            /*
530             * 16-Bit Address Descriptor Resource
531             */
532            Status = AcpiRsAddress16Stream (LinkedList, &Buffer,
533                        &BytesConsumed);
534            break;
535
536        case ACPI_RSTYPE_ADDRESS32:
537            /*
538             * 32-Bit Address Descriptor Resource
539             */
540            Status = AcpiRsAddress32Stream (LinkedList, &Buffer,
541                        &BytesConsumed);
542            break;
543
544        case ACPI_RSTYPE_ADDRESS64:
545            /*
546             * 64-Bit Address Descriptor Resource
547             */
548            Status = AcpiRsAddress64Stream (LinkedList, &Buffer,
549                        &BytesConsumed);
550            break;
551
552        case ACPI_RSTYPE_EXT_IRQ:
553            /*
554             * Extended IRQ Resource
555             */
556            Status = AcpiRsExtendedIrqStream (LinkedList, &Buffer,
557                        &BytesConsumed);
558            break;
559
560        default:
561            /*
562             * If we get here, everything is out of sync,
563             *  so exit with an error
564             */
565            Status = AE_BAD_DATA;
566            break;
567
568        } /* switch (LinkedList->Id) */
569
570
571        if (!ACPI_SUCCESS(Status))
572        {
573            return_ACPI_STATUS (Status);
574        }
575
576        /*
577         * Set the Buffer to point to the open byte
578         */
579        Buffer += BytesConsumed;
580
581        /*
582         * Point to the next object
583         */
584        LinkedList = POINTER_ADD (ACPI_RESOURCE,
585                        LinkedList, LinkedList->Length);
586    }
587
588    return_ACPI_STATUS (AE_OK);
589}
590
591