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