rsio.c revision 117521
1/*******************************************************************************
2 *
3 * Module Name: rsio - IO and DMA resource descriptors
4 *              $Revision: 24 $
5 *
6 ******************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2003, 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 __RSIO_C__
118
119#include "acpi.h"
120#include "acresrc.h"
121
122#define _COMPONENT          ACPI_RESOURCES
123        ACPI_MODULE_NAME    ("rsio")
124
125
126/*******************************************************************************
127 *
128 * FUNCTION:    AcpiRsIoResource
129 *
130 * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
131 *                                        stream
132 *              BytesConsumed           - Pointer to where the number of bytes
133 *                                        consumed the ByteStreamBuffer is
134 *                                        returned
135 *              OutputBuffer            - Pointer to the return data buffer
136 *              StructureSize           - Pointer to where the number of bytes
137 *                                        in the return data struct is returned
138 *
139 * RETURN:      Status
140 *
141 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
142 *              structure pointed to by the OutputBuffer.  Return the
143 *              number of bytes consumed from the byte stream.
144 *
145 ******************************************************************************/
146
147ACPI_STATUS
148AcpiRsIoResource (
149    UINT8                   *ByteStreamBuffer,
150    ACPI_SIZE               *BytesConsumed,
151    UINT8                   **OutputBuffer,
152    ACPI_SIZE               *StructureSize)
153{
154    UINT8                   *Buffer = ByteStreamBuffer;
155    ACPI_RESOURCE           *OutputStruct = (void *) *OutputBuffer;
156    UINT16                  Temp16 = 0;
157    UINT8                   Temp8 = 0;
158    ACPI_SIZE               StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IO);
159
160
161    ACPI_FUNCTION_TRACE ("RsIoResource");
162
163
164    /*
165     * The number of bytes consumed are Constant
166     */
167    *BytesConsumed = 8;
168
169    OutputStruct->Id = ACPI_RSTYPE_IO;
170
171    /*
172     * Check Decode
173     */
174    Buffer += 1;
175    Temp8 = *Buffer;
176
177    OutputStruct->Data.Io.IoDecode = Temp8 & 0x01;
178
179    /*
180     * Check MinBase Address
181     */
182    Buffer += 1;
183    ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
184
185    OutputStruct->Data.Io.MinBaseAddress = Temp16;
186
187    /*
188     * Check MaxBase Address
189     */
190    Buffer += 2;
191    ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
192
193    OutputStruct->Data.Io.MaxBaseAddress = Temp16;
194
195    /*
196     * Check Base alignment
197     */
198    Buffer += 2;
199    Temp8 = *Buffer;
200
201    OutputStruct->Data.Io.Alignment = Temp8;
202
203    /*
204     * Check RangeLength
205     */
206    Buffer += 1;
207    Temp8 = *Buffer;
208
209    OutputStruct->Data.Io.RangeLength = Temp8;
210
211    /*
212     * Set the Length parameter
213     */
214    OutputStruct->Length = (UINT32) StructSize;
215
216    /*
217     * Return the final size of the structure
218     */
219    *StructureSize = StructSize;
220    return_ACPI_STATUS (AE_OK);
221}
222
223
224/*******************************************************************************
225 *
226 * FUNCTION:    AcpiRsFixedIoResource
227 *
228 * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
229 *                                        stream
230 *              BytesConsumed           - Pointer to where the number of bytes
231 *                                        consumed the ByteStreamBuffer is
232 *                                        returned
233 *              OutputBuffer            - Pointer to the return data buffer
234 *              StructureSize           - Pointer to where the number of bytes
235 *                                        in the return data struct is returned
236 *
237 * RETURN:      Status
238 *
239 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
240 *              structure pointed to by the OutputBuffer.  Return the
241 *              number of bytes consumed from the byte stream.
242 *
243 ******************************************************************************/
244
245ACPI_STATUS
246AcpiRsFixedIoResource (
247    UINT8                   *ByteStreamBuffer,
248    ACPI_SIZE               *BytesConsumed,
249    UINT8                   **OutputBuffer,
250    ACPI_SIZE               *StructureSize)
251{
252    UINT8                   *Buffer = ByteStreamBuffer;
253    ACPI_RESOURCE           *OutputStruct = (void *) *OutputBuffer;
254    UINT16                  Temp16 = 0;
255    UINT8                   Temp8 = 0;
256    ACPI_SIZE               StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_FIXED_IO);
257
258
259    ACPI_FUNCTION_TRACE ("RsFixedIoResource");
260
261
262    /*
263     * The number of bytes consumed are Constant
264     */
265    *BytesConsumed = 4;
266
267    OutputStruct->Id = ACPI_RSTYPE_FIXED_IO;
268
269    /*
270     * Check Range Base Address
271     */
272    Buffer += 1;
273    ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
274
275    OutputStruct->Data.FixedIo.BaseAddress = Temp16;
276
277    /*
278     * Check RangeLength
279     */
280    Buffer += 2;
281    Temp8 = *Buffer;
282
283    OutputStruct->Data.FixedIo.RangeLength = Temp8;
284
285    /*
286     * Set the Length parameter
287     */
288    OutputStruct->Length = (UINT32) StructSize;
289
290    /*
291     * Return the final size of the structure
292     */
293    *StructureSize = StructSize;
294    return_ACPI_STATUS (AE_OK);
295}
296
297
298/*******************************************************************************
299 *
300 * FUNCTION:    AcpiRsIoStream
301 *
302 * PARAMETERS:  LinkedList              - Pointer to the resource linked list
303 *              OutputBuffer            - Pointer to the user's return buffer
304 *              BytesConsumed           - Pointer to where the number of bytes
305 *                                        used in the OutputBuffer is returned
306 *
307 * RETURN:      Status
308 *
309 * DESCRIPTION: Take the linked list resource structure and fills in the
310 *              the appropriate bytes in a byte stream
311 *
312 ******************************************************************************/
313
314ACPI_STATUS
315AcpiRsIoStream (
316    ACPI_RESOURCE           *LinkedList,
317    UINT8                   **OutputBuffer,
318    ACPI_SIZE               *BytesConsumed)
319{
320    UINT8                   *Buffer = *OutputBuffer;
321    UINT16                  Temp16 = 0;
322    UINT8                   Temp8 = 0;
323
324
325    ACPI_FUNCTION_TRACE ("RsIoStream");
326
327
328    /*
329     * The descriptor field is static
330     */
331    *Buffer = 0x47;
332    Buffer += 1;
333
334    /*
335     * Io Information Byte
336     */
337    Temp8 = (UINT8) (LinkedList->Data.Io.IoDecode & 0x01);
338
339    *Buffer = Temp8;
340    Buffer += 1;
341
342    /*
343     * Set the Range minimum base address
344     */
345    Temp16 = (UINT16) LinkedList->Data.Io.MinBaseAddress;
346
347    ACPI_MOVE_16_TO_16 (Buffer, &Temp16);
348    Buffer += 2;
349
350    /*
351     * Set the Range maximum base address
352     */
353    Temp16 = (UINT16) LinkedList->Data.Io.MaxBaseAddress;
354
355    ACPI_MOVE_16_TO_16 (Buffer, &Temp16);
356    Buffer += 2;
357
358    /*
359     * Set the base alignment
360     */
361    Temp8 = (UINT8) LinkedList->Data.Io.Alignment;
362
363    *Buffer = Temp8;
364    Buffer += 1;
365
366    /*
367     * Set the range length
368     */
369    Temp8 = (UINT8) LinkedList->Data.Io.RangeLength;
370
371    *Buffer = Temp8;
372    Buffer += 1;
373
374    /*
375     * Return the number of bytes consumed in this operation
376     */
377    *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
378    return_ACPI_STATUS (AE_OK);
379}
380
381
382/*******************************************************************************
383 *
384 * FUNCTION:    AcpiRsFixedIoStream
385 *
386 * PARAMETERS:  LinkedList              - Pointer to the resource linked list
387 *              OutputBuffer            - Pointer to the user's return buffer
388 *              BytesConsumed           - Pointer to where the number of bytes
389 *                                        used in the OutputBuffer is returned
390 *
391 * RETURN:      Status
392 *
393 * DESCRIPTION: Take the linked list resource structure and fills in the
394 *              the appropriate bytes in a byte stream
395 *
396 ******************************************************************************/
397
398ACPI_STATUS
399AcpiRsFixedIoStream (
400    ACPI_RESOURCE           *LinkedList,
401    UINT8                   **OutputBuffer,
402    ACPI_SIZE               *BytesConsumed)
403{
404    UINT8                   *Buffer = *OutputBuffer;
405    UINT16                  Temp16 = 0;
406    UINT8                   Temp8 = 0;
407
408
409    ACPI_FUNCTION_TRACE ("RsFixedIoStream");
410
411
412    /*
413     * The descriptor field is static
414     */
415    *Buffer = 0x4B;
416
417    Buffer += 1;
418
419    /*
420     * Set the Range base address
421     */
422    Temp16 = (UINT16) LinkedList->Data.FixedIo.BaseAddress;
423
424    ACPI_MOVE_16_TO_16 (Buffer, &Temp16);
425    Buffer += 2;
426
427    /*
428     * Set the range length
429     */
430    Temp8 = (UINT8) LinkedList->Data.FixedIo.RangeLength;
431
432    *Buffer = Temp8;
433    Buffer += 1;
434
435    /*
436     * Return the number of bytes consumed in this operation
437     */
438    *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
439    return_ACPI_STATUS (AE_OK);
440}
441
442
443/*******************************************************************************
444 *
445 * FUNCTION:    AcpiRsDmaResource
446 *
447 * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
448 *                                        stream
449 *              BytesConsumed           - Pointer to where the number of bytes
450 *                                        consumed the ByteStreamBuffer is
451 *                                        returned
452 *              OutputBuffer            - Pointer to the return data buffer
453 *              StructureSize           - Pointer to where the number of bytes
454 *                                        in the return data struct is returned
455 *
456 * RETURN:      Status
457 *
458 * DESCRIPTION: Take the resource byte stream and fill out the appropriate
459 *              structure pointed to by the OutputBuffer.  Return the
460 *              number of bytes consumed from the byte stream.
461 *
462 ******************************************************************************/
463
464ACPI_STATUS
465AcpiRsDmaResource (
466    UINT8                   *ByteStreamBuffer,
467    ACPI_SIZE               *BytesConsumed,
468    UINT8                   **OutputBuffer,
469    ACPI_SIZE               *StructureSize)
470{
471    UINT8                   *Buffer = ByteStreamBuffer;
472    ACPI_RESOURCE           *OutputStruct = (void *) *OutputBuffer;
473    UINT8                   Temp8 = 0;
474    UINT8                   Index;
475    UINT8                   i;
476    ACPI_SIZE               StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_DMA);
477
478
479    ACPI_FUNCTION_TRACE ("RsDmaResource");
480
481
482    /*
483     * The number of bytes consumed are Constant
484     */
485    *BytesConsumed = 3;
486    OutputStruct->Id = ACPI_RSTYPE_DMA;
487
488    /*
489     * Point to the 8-bits of Byte 1
490     */
491    Buffer += 1;
492    Temp8 = *Buffer;
493
494    /* Decode the DMA channel bits */
495
496    for (i = 0, Index = 0; Index < 8; Index++)
497    {
498        if ((Temp8 >> Index) & 0x01)
499        {
500            OutputStruct->Data.Dma.Channels[i] = Index;
501            i++;
502        }
503    }
504
505    /* Zero DMA channels is valid */
506
507    OutputStruct->Data.Dma.NumberOfChannels = i;
508    if (i > 0)
509    {
510        /*
511         * Calculate the structure size based upon the number of interrupts
512         */
513        StructSize += ((ACPI_SIZE) i - 1) * 4;
514    }
515
516    /*
517     * Point to Byte 2
518     */
519    Buffer += 1;
520    Temp8 = *Buffer;
521
522    /*
523     * Check for transfer preference (Bits[1:0])
524     */
525    OutputStruct->Data.Dma.Transfer = Temp8 & 0x03;
526
527    if (0x03 == OutputStruct->Data.Dma.Transfer)
528    {
529        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid DMA.Transfer preference (3)\n"));
530        return_ACPI_STATUS (AE_BAD_DATA);
531    }
532
533    /*
534     * Get bus master preference (Bit[2])
535     */
536    OutputStruct->Data.Dma.BusMaster = (Temp8 >> 2) & 0x01;
537
538    /*
539     * Get channel speed support (Bits[6:5])
540     */
541    OutputStruct->Data.Dma.Type = (Temp8 >> 5) & 0x03;
542
543    /*
544     * Set the Length parameter
545     */
546    OutputStruct->Length = (UINT32) StructSize;
547
548    /*
549     * Return the final size of the structure
550     */
551    *StructureSize = StructSize;
552    return_ACPI_STATUS (AE_OK);
553}
554
555
556/*******************************************************************************
557 *
558 * FUNCTION:    AcpiRsDmaStream
559 *
560 * PARAMETERS:  LinkedList              - Pointer to the resource linked list
561 *              OutputBuffer            - Pointer to the user's return buffer
562 *              BytesConsumed           - Pointer to where the number of bytes
563 *                                        used in the OutputBuffer is returned
564 *
565 * RETURN:      Status
566 *
567 * DESCRIPTION: Take the linked list resource structure and fills in the
568 *              the appropriate bytes in a byte stream
569 *
570 ******************************************************************************/
571
572ACPI_STATUS
573AcpiRsDmaStream (
574    ACPI_RESOURCE           *LinkedList,
575    UINT8                   **OutputBuffer,
576    ACPI_SIZE               *BytesConsumed)
577{
578    UINT8                   *Buffer = *OutputBuffer;
579    UINT16                  Temp16 = 0;
580    UINT8                   Temp8 = 0;
581    UINT8                   Index;
582
583
584    ACPI_FUNCTION_TRACE ("RsDmaStream");
585
586
587    /*
588     * The descriptor field is static
589     */
590    *Buffer = 0x2A;
591    Buffer += 1;
592    Temp8 = 0;
593
594    /*
595     * Loop through all of the Channels and set the mask bits
596     */
597    for (Index = 0;
598         Index < LinkedList->Data.Dma.NumberOfChannels;
599         Index++)
600    {
601        Temp16 = (UINT16) LinkedList->Data.Dma.Channels[Index];
602        Temp8 |= 0x1 << Temp16;
603    }
604
605    *Buffer = Temp8;
606    Buffer += 1;
607
608    /*
609     * Set the DMA Info
610     */
611    Temp8 = (UINT8) ((LinkedList->Data.Dma.Type & 0x03) << 5);
612    Temp8 |= ((LinkedList->Data.Dma.BusMaster & 0x01) << 2);
613    Temp8 |= (LinkedList->Data.Dma.Transfer & 0x03);
614
615    *Buffer = Temp8;
616    Buffer += 1;
617
618    /*
619     * Return the number of bytes consumed in this operation
620     */
621    *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
622    return_ACPI_STATUS (AE_OK);
623}
624
625