]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/Subsystem/Resources/rsio.c
Vendor import of Intel ACPI-CA 20041119 with system includes fixups.
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / Subsystem / Resources / rsio.c
1 /*******************************************************************************
2  *
3  * Module Name: rsio - AcpiRsIoResource
4  *                     AcpiRsFixedIoResource
5  *                     AcpiRsIoStream
6  *                     AcpiRsFixedIoStream
7  *                     AcpiRsDmaResource
8  *                     AcpiRsDmaStream
9  *              $Revision: 12 $
10  *
11  ******************************************************************************/
12
13 /******************************************************************************
14  *
15  * 1. Copyright Notice
16  *
17  * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
18  * All rights reserved.
19  *
20  * 2. License
21  *
22  * 2.1. This is your license from Intel Corp. under its intellectual property
23  * rights.  You may have additional license terms from the party that provided
24  * you this software, covering your right to use that party's intellectual
25  * property rights.
26  *
27  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
28  * copy of the source code appearing in this file ("Covered Code") an
29  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
30  * base code distributed originally by Intel ("Original Intel Code") to copy,
31  * make derivatives, distribute, use and display any portion of the Covered
32  * Code in any form, with the right to sublicense such rights; and
33  *
34  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
35  * license (with the right to sublicense), under only those claims of Intel
36  * patents that are infringed by the Original Intel Code, to make, use, sell,
37  * offer to sell, and import the Covered Code and derivative works thereof
38  * solely to the minimum extent necessary to exercise the above copyright
39  * license, and in no event shall the patent license extend to any additions
40  * to or modifications of the Original Intel Code.  No other license or right
41  * is granted directly or by implication, estoppel or otherwise;
42  *
43  * The above copyright and patent license is granted only if the following
44  * conditions are met:
45  *
46  * 3. Conditions
47  *
48  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
49  * Redistribution of source code of any substantial portion of the Covered
50  * Code or modification with rights to further distribute source must include
51  * the above Copyright Notice, the above License, this list of Conditions,
52  * and the following Disclaimer and Export Compliance provision.  In addition,
53  * Licensee must cause all Covered Code to which Licensee contributes to
54  * contain a file documenting the changes Licensee made to create that Covered
55  * Code and the date of any change.  Licensee must include in that file the
56  * documentation of any changes made by any predecessor Licensee.  Licensee
57  * must include a prominent statement that the modification is derived,
58  * directly or indirectly, from Original Intel Code.
59  *
60  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
61  * Redistribution of source code of any substantial portion of the Covered
62  * Code or modification without rights to further distribute source must
63  * include the following Disclaimer and Export Compliance provision in the
64  * documentation and/or other materials provided with distribution.  In
65  * addition, Licensee may not authorize further sublicense of source of any
66  * portion of the Covered Code, and must include terms to the effect that the
67  * license from Licensee to its licensee is limited to the intellectual
68  * property embodied in the software Licensee provides to its licensee, and
69  * not to intellectual property embodied in modifications its licensee may
70  * make.
71  *
72  * 3.3. Redistribution of Executable. Redistribution in executable form of any
73  * substantial portion of the Covered Code or modification must reproduce the
74  * above Copyright Notice, and the following Disclaimer and Export Compliance
75  * provision in the documentation and/or other materials provided with the
76  * distribution.
77  *
78  * 3.4. Intel retains all right, title, and interest in and to the Original
79  * Intel Code.
80  *
81  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
82  * Intel shall be used in advertising or otherwise to promote the sale, use or
83  * other dealings in products derived from or relating to the Covered Code
84  * without prior written authorization from Intel.
85  *
86  * 4. Disclaimer and Export Compliance
87  *
88  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
89  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
90  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
91  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
92  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
93  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
94  * PARTICULAR PURPOSE.
95  *
96  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
97  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
98  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
99  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
100  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
101  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
102  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
103  * LIMITED REMEDY.
104  *
105  * 4.3. Licensee shall not export, either directly or indirectly, any of this
106  * software or system incorporating such software without first obtaining any
107  * required license or other approval from the U. S. Department of Commerce or
108  * any other agency or department of the United States Government.  In the
109  * event Licensee exports any such software from the United States or
110  * re-exports any such software from a foreign destination, Licensee shall
111  * ensure that the distribution and export/re-export of the software is in
112  * compliance with all laws, regulations, orders, or other restrictions of the
113  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
114  * any of its subsidiaries will export/re-export any technical data, process,
115  * software, or service, directly or indirectly, to any country for which the
116  * United States government or any agency thereof requires an export license,
117  * other governmental approval, or letter of assurance, without first obtaining
118  * such license, approval or letter.
119  *
120  *****************************************************************************/
121
122 #define __RSIO_C__
123
124 #include "acpi.h"
125 #include "acresrc.h"
126
127 #define _COMPONENT          RESOURCE_MANAGER
128         MODULE_NAME         ("rsio")
129
130
131 /*******************************************************************************
132  *
133  * FUNCTION:    AcpiRsIoResource
134  *
135  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
136  *                                          stream
137  *              BytesConsumed           - UINT32 pointer that is filled with
138  *                                          the number of bytes consumed from
139  *                                          the ByteStreamBuffer
140  *              OutputBuffer            - Pointer to the user's return buffer
141  *              StructureSize           - UINT32 pointer that is filled with
142  *                                          the number of bytes in the filled
143  *                                          in structure
144  *
145  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code
146  *
147  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
148  *                  structure pointed to by the OutputBuffer.  Return the
149  *                  number of bytes consumed from the byte stream.
150  *
151  ******************************************************************************/
152
153 ACPI_STATUS
154 AcpiRsIoResource (
155     UINT8                   *ByteStreamBuffer,
156     UINT32                  *BytesConsumed,
157     UINT8                   **OutputBuffer,
158     UINT32                  *StructureSize)
159 {
160     UINT8                   *Buffer = ByteStreamBuffer;
161     RESOURCE                *OutputStruct = (RESOURCE *) * OutputBuffer;
162     UINT16                  Temp16 = 0;
163     UINT8                   Temp8 = 0;
164     UINT32                  StructSize = sizeof (IO_RESOURCE) +
165                                          RESOURCE_LENGTH_NO_DATA;
166
167
168     FUNCTION_TRACE ("RsIoResource");
169
170     /*
171      * The number of bytes consumed are Constant
172      */
173     *BytesConsumed = 8;
174
175     OutputStruct->Id = Io;
176
177     /*
178      * Check Decode
179      */
180     Buffer += 1;
181     Temp8 = *Buffer;
182
183     OutputStruct->Data.Io.IoDecode = Temp8 & 0x01;
184
185     /*
186      * Check MinBase Address
187      */
188     Buffer += 1;
189     MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
190
191     OutputStruct->Data.Io.MinBaseAddress = Temp16;
192
193     /*
194      * Check MaxBase Address
195      */
196     Buffer += 2;
197     MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
198
199     OutputStruct->Data.Io.MaxBaseAddress = Temp16;
200
201     /*
202      * Check Base alignment
203      */
204     Buffer += 2;
205     Temp8 = *Buffer;
206
207     OutputStruct->Data.Io.Alignment = Temp8;
208
209     /*
210      * Check RangeLength
211      */
212     Buffer += 1;
213     Temp8 = *Buffer;
214
215     OutputStruct->Data.Io.RangeLength = Temp8;
216
217     /*
218      * Set the Length parameter
219      */
220     OutputStruct->Length = StructSize;
221
222     /*
223      * Return the final size of the structure
224      */
225     *StructureSize = StructSize;
226
227     return_ACPI_STATUS (AE_OK);
228 }
229
230
231 /*******************************************************************************
232  *
233  * FUNCTION:    AcpiRsFixedIoResource
234  *
235  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
236  *                                          stream
237  *              BytesConsumed           - UINT32 pointer that is filled with
238  *                                          the number of bytes consumed from
239  *                                          the ByteStreamBuffer
240  *              OutputBuffer            - Pointer to the user's return buffer
241  *              StructureSize           - UINT32 pointer that is filled with
242  *                                          the number of bytes in the filled
243  *                                          in structure
244  *
245  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code
246  *
247  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
248  *                  structure pointed to by the OutputBuffer.  Return the
249  *                  number of bytes consumed from the byte stream.
250  *
251  ******************************************************************************/
252
253 ACPI_STATUS
254 AcpiRsFixedIoResource (
255     UINT8                   *ByteStreamBuffer,
256     UINT32                  *BytesConsumed,
257     UINT8                   **OutputBuffer,
258     UINT32                  *StructureSize)
259 {
260     UINT8                   *Buffer = ByteStreamBuffer;
261     RESOURCE                *OutputStruct = (RESOURCE *) * OutputBuffer;
262     UINT16                  Temp16 = 0;
263     UINT8                   Temp8 = 0;
264     UINT32                  StructSize = sizeof (FIXED_IO_RESOURCE) +
265                                          RESOURCE_LENGTH_NO_DATA;
266
267
268     FUNCTION_TRACE ("RsFixedIoResource");
269
270     /*
271      * The number of bytes consumed are Constant
272      */
273     *BytesConsumed = 4;
274
275     OutputStruct->Id = FixedIo;
276
277     /*
278      * Check Range Base Address
279      */
280     Buffer += 1;
281     MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
282
283     OutputStruct->Data.FixedIo.BaseAddress = Temp16;
284
285     /*
286      * Check RangeLength
287      */
288     Buffer += 2;
289     Temp8 = *Buffer;
290
291     OutputStruct->Data.FixedIo.RangeLength = Temp8;
292
293     /*
294      * Set the Length parameter
295      */
296     OutputStruct->Length = StructSize;
297
298     /*
299      * Return the final size of the structure
300      */
301     *StructureSize = StructSize;
302
303     return_ACPI_STATUS (AE_OK);
304 }
305
306
307 /*******************************************************************************
308  *
309  * FUNCTION:    AcpiRsIoStream
310  *
311  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
312  *              OutputBuffer            - Pointer to the user's return buffer
313  *              BytesConsumed           - UINT32 pointer that is filled with
314  *                                          the number of bytes of the
315  *                                          OutputBuffer used
316  *
317  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code
318  *
319  * DESCRIPTION: Take the linked list resource structure and fills in the
320  *                  the appropriate bytes in a byte stream
321  *
322  ******************************************************************************/
323
324 ACPI_STATUS
325 AcpiRsIoStream (
326     RESOURCE                *LinkedList,
327     UINT8                   **OutputBuffer,
328     UINT32                  *BytesConsumed)
329 {
330     UINT8                   *Buffer = *OutputBuffer;
331     UINT16                  Temp16 = 0;
332     UINT8                   Temp8 = 0;
333
334
335     FUNCTION_TRACE ("RsIoStream");
336
337     /*
338      * The descriptor field is static
339      */
340     *Buffer = 0x47;
341     Buffer += 1;
342
343     /*
344      * Io Information Byte
345      */
346     Temp8 = (UINT8) (LinkedList->Data.Io.IoDecode & 0x01);
347
348     *Buffer = Temp8;
349     Buffer += 1;
350
351     /*
352      * Set the Range minimum base address
353      */
354     Temp16 = (UINT16) LinkedList->Data.Io.MinBaseAddress;
355
356     MOVE_UNALIGNED16_TO_16 (Buffer, &Temp16);
357     Buffer += 2;
358
359     /*
360      * Set the Range maximum base address
361      */
362     Temp16 = (UINT16) LinkedList->Data.Io.MaxBaseAddress;
363
364     MOVE_UNALIGNED16_TO_16 (Buffer, &Temp16);
365     Buffer += 2;
366
367     /*
368      * Set the base alignment
369      */
370     Temp8 = (UINT8) LinkedList->Data.Io.Alignment;
371
372     *Buffer = Temp8;
373     Buffer += 1;
374
375     /*
376      * Set the range length
377      */
378     Temp8 = (UINT8) LinkedList->Data.Io.RangeLength;
379
380     *Buffer = Temp8;
381     Buffer += 1;
382
383     /*
384      * Return the number of bytes consumed in this operation
385      */
386     *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer -
387                      (NATIVE_UINT) *OutputBuffer);
388
389     return_ACPI_STATUS (AE_OK);
390 }
391
392
393 /*******************************************************************************
394  *
395  * FUNCTION:    AcpiRsFixedIoStream
396  *
397  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
398  *              OutputBuffer            - Pointer to the user's return buffer
399  *              BytesConsumed           - UINT32 pointer that is filled with
400  *                                          the number of bytes of the
401  *                                          OutputBuffer used
402  *
403  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code
404  *
405  * DESCRIPTION: Take the linked list resource structure and fills in the
406  *                  the appropriate bytes in a byte stream
407  *
408  ******************************************************************************/
409
410 ACPI_STATUS
411 AcpiRsFixedIoStream (
412     RESOURCE                *LinkedList,
413     UINT8                   **OutputBuffer,
414     UINT32                  *BytesConsumed)
415 {
416     UINT8                   *Buffer = *OutputBuffer;
417     UINT16                  Temp16 = 0;
418     UINT8                   Temp8 = 0;
419
420
421     FUNCTION_TRACE ("RsFixedIoStream");
422
423     /*
424      * The descriptor field is static
425      */
426     *Buffer = 0x4B;
427
428     Buffer += 1;
429
430     /*
431      * Set the Range base address
432      */
433     Temp16 = (UINT16) LinkedList->Data.FixedIo.BaseAddress;
434
435     MOVE_UNALIGNED16_TO_16 (Buffer, &Temp16);
436     Buffer += 2;
437
438     /*
439      * Set the range length
440      */
441     Temp8 = (UINT8) LinkedList->Data.FixedIo.RangeLength;
442
443     *Buffer = Temp8;
444     Buffer += 1;
445
446     /*
447      * Return the number of bytes consumed in this operation
448      */
449     *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer -
450                      (NATIVE_UINT) *OutputBuffer);
451
452     return_ACPI_STATUS (AE_OK);
453 }
454
455
456 /*******************************************************************************
457  *
458  * FUNCTION:    AcpiRsDmaResource
459  *
460  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
461  *                                          stream
462  *              BytesConsumed           - UINT32 pointer that is filled with
463  *                                          the number of bytes consumed from
464  *                                          the ByteStreamBuffer
465  *              OutputBuffer            - Pointer to the user's return buffer
466  *              StructureSize           - UINT32 pointer that is filled with
467  *                                          the number of bytes in the filled
468  *                                          in structure
469  *
470  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code
471  *
472  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
473  *                  structure pointed to by the OutputBuffer.  Return the
474  *                  number of bytes consumed from the byte stream.
475  *
476  ******************************************************************************/
477
478 ACPI_STATUS
479 AcpiRsDmaResource (
480     UINT8                   *ByteStreamBuffer,
481     UINT32                  *BytesConsumed,
482     UINT8                   **OutputBuffer,
483     UINT32                  *StructureSize)
484 {
485     UINT8                   *Buffer = ByteStreamBuffer;
486     RESOURCE                *OutputStruct = (RESOURCE *) * OutputBuffer;
487     UINT8                   Temp8 = 0;
488     UINT8                   Index;
489     UINT8                   i;
490     UINT32                  StructSize = sizeof(DMA_RESOURCE) +
491                                          RESOURCE_LENGTH_NO_DATA;
492
493
494     FUNCTION_TRACE ("RsDmaResource");
495
496     /*
497      * The number of bytes consumed are Constant
498      */
499     *BytesConsumed = 3;
500     OutputStruct->Id = Dma;
501
502     /*
503      * Point to the 8-bits of Byte 1
504      */
505     Buffer += 1;
506     Temp8 = *Buffer;
507
508     /* Decode the IRQ bits */
509
510     for (i = 0, Index = 0; Index < 8; Index++)
511     {
512         if ((Temp8 >> Index) & 0x01)
513         {
514             OutputStruct->Data.Dma.Channels[i] = Index;
515             i++;
516         }
517     }
518     OutputStruct->Data.Dma.NumberOfChannels = i;
519
520
521     /*
522      * Calculate the structure size based upon the number of interrupts
523      */
524     StructSize += (OutputStruct->Data.Dma.NumberOfChannels - 1) * 4;
525
526     /*
527      * Point to Byte 2
528      */
529     Buffer += 1;
530     Temp8 = *Buffer;
531
532     /*
533      * Check for transfer preference (Bits[1:0])
534      */
535     OutputStruct->Data.Dma.Transfer = Temp8 & 0x03;
536
537     if (0x03 == OutputStruct->Data.Dma.Transfer)
538     {
539         return_ACPI_STATUS (AE_BAD_DATA);
540     }
541
542     /*
543      * Get bus master preference (Bit[2])
544      */
545     OutputStruct->Data.Dma.BusMaster = (Temp8 >> 2) & 0x01;
546
547     /*
548      * Get channel speed support (Bits[6:5])
549      */
550     OutputStruct->Data.Dma.Type = (Temp8 >> 5) & 0x03;
551
552     /*
553      * Set the Length parameter
554      */
555     OutputStruct->Length = StructSize;
556
557     /*
558      * Return the final size of the structure
559      */
560     *StructureSize = StructSize;
561
562     return_ACPI_STATUS (AE_OK);
563 }
564
565
566 /*******************************************************************************
567  *
568  * FUNCTION:    AcpiRsDmaStream
569  *
570  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
571  *              OutputBuffer            - Pointer to the user's return buffer
572  *              BytesConsumed           - UINT32 pointer that is filled with
573  *                                          the number of bytes of the
574  *                                          OutputBuffer used
575  *
576  * RETURN:      Status  AE_OK if okay, else a valid ACPI_STATUS code
577  *
578  * DESCRIPTION: Take the linked list resource structure and fills in the
579  *                  the appropriate bytes in a byte stream
580  *
581  ******************************************************************************/
582
583 ACPI_STATUS
584 AcpiRsDmaStream (
585     RESOURCE                *LinkedList,
586     UINT8                   **OutputBuffer,
587     UINT32                  *BytesConsumed)
588 {
589     UINT8                   *Buffer = *OutputBuffer;
590     UINT16                  Temp16 = 0;
591     UINT8                   Temp8 = 0;
592     UINT8                   Index;
593
594
595     FUNCTION_TRACE ("RsDmaStream");
596
597
598     /*
599      * The descriptor field is static
600      */
601     *Buffer = 0x2A;
602     Buffer += 1;
603     Temp8 = 0;
604
605     /*
606      * Loop through all of the Channels and set the mask bits
607      */
608     for (Index = 0;
609          Index < LinkedList->Data.Dma.NumberOfChannels;
610          Index++)
611     {
612         Temp16 = (UINT16) LinkedList->Data.Dma.Channels[Index];
613         Temp8 |= 0x1 << Temp16;
614     }
615
616     *Buffer = Temp8;
617     Buffer += 1;
618
619     /*
620      * Set the DMA Info
621      */
622     Temp8 = (UINT8) ((LinkedList->Data.Dma.Type & 0x03) << 5);
623     Temp8 |= ((LinkedList->Data.Dma.BusMaster & 0x01) << 2);
624     Temp8 |= (LinkedList->Data.Dma.Transfer & 0x03);
625
626     *Buffer = Temp8;
627     Buffer += 1;
628
629     /*
630      * Return the number of bytes consumed in this operation
631      */
632     *BytesConsumed = (UINT32) ((NATIVE_UINT) Buffer -
633                      (NATIVE_UINT) *OutputBuffer);
634
635     return_ACPI_STATUS (AE_OK);
636 }
637