Also document BGE_FAKE_AUTONEG in LINT.
[dragonfly.git] / sys / contrib / dev / acpica / rsaddr.c
1 /*******************************************************************************
2  *
3  * Module Name: rsaddr - Address resource descriptors (16/32/64)
4  *              $Revision: 29 $
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/rsaddr.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $                                                               */
117
118 #define __RSADDR_C__
119
120 #include "acpi.h"
121 #include "acresrc.h"
122
123 #define _COMPONENT          ACPI_RESOURCES
124         ACPI_MODULE_NAME    ("rsaddr")
125
126
127 /*******************************************************************************
128  *
129  * FUNCTION:    AcpiRsAddress16Resource
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 AcpiRsAddress16Resource (
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     UINT8                   *TempPtr;
158     ACPI_SIZE               StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS16);
159     UINT32                  Index;
160     UINT16                  Temp16;
161     UINT8                   Temp8;
162
163
164     ACPI_FUNCTION_TRACE ("RsAddress16Resource");
165
166     /*
167      * Point past the Descriptor to get the number of bytes consumed
168      */
169     Buffer += 1;
170     ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
171
172     *BytesConsumed = Temp16 + 3;
173     OutputStruct->Id = ACPI_RSTYPE_ADDRESS16;
174
175     /*
176      * Get the Resource Type (Byte3)
177      */
178     Buffer += 2;
179     Temp8 = *Buffer;
180
181     /* Values 0-2 are valid */
182
183     if (Temp8 > 2)
184     {
185         return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
186     }
187
188     OutputStruct->Data.Address16.ResourceType = Temp8 & 0x03;
189
190     /*
191      * Get the General Flags (Byte4)
192      */
193     Buffer += 1;
194     Temp8 = *Buffer;
195
196     /* Producer / Consumer */
197
198     OutputStruct->Data.Address16.ProducerConsumer = Temp8 & 0x01;
199
200     /* Decode */
201
202     OutputStruct->Data.Address16.Decode = (Temp8 >> 1) & 0x01;
203
204     /* Min Address Fixed */
205
206     OutputStruct->Data.Address16.MinAddressFixed = (Temp8 >> 2) & 0x01;
207
208     /* Max Address Fixed */
209
210     OutputStruct->Data.Address16.MaxAddressFixed = (Temp8 >> 3) & 0x01;
211
212     /*
213      * Get the Type Specific Flags (Byte5)
214      */
215     Buffer += 1;
216     Temp8 = *Buffer;
217
218     if (ACPI_MEMORY_RANGE == OutputStruct->Data.Address16.ResourceType)
219     {
220         OutputStruct->Data.Address16.Attribute.Memory.ReadWriteAttribute =
221                 (UINT16) (Temp8 & 0x01);
222         OutputStruct->Data.Address16.Attribute.Memory.CacheAttribute =
223                 (UINT16) ((Temp8 >> 1) & 0x0F);
224     }
225     else
226     {
227         if (ACPI_IO_RANGE == OutputStruct->Data.Address16.ResourceType)
228         {
229             OutputStruct->Data.Address16.Attribute.Io.RangeAttribute =
230                 (UINT16) (Temp8 & 0x03);
231             OutputStruct->Data.Address16.Attribute.Io.TranslationAttribute =
232                 (UINT16) ((Temp8 >> 4) & 0x03);
233         }
234         else
235         {
236             /* BUS_NUMBER_RANGE == Address16.Data->ResourceType */
237             /* Nothing needs to be filled in */
238         }
239     }
240
241     /*
242      * Get Granularity (Bytes 6-7)
243      */
244     Buffer += 1;
245     ACPI_MOVE_UNALIGNED16_TO_16 (&OutputStruct->Data.Address16.Granularity,
246                             Buffer);
247
248     /*
249      * Get MinAddressRange (Bytes 8-9)
250      */
251     Buffer += 2;
252     ACPI_MOVE_UNALIGNED16_TO_16 (&OutputStruct->Data.Address16.MinAddressRange,
253                             Buffer);
254
255     /*
256      * Get MaxAddressRange (Bytes 10-11)
257      */
258     Buffer += 2;
259     ACPI_MOVE_UNALIGNED16_TO_16 (&OutputStruct->Data.Address16.MaxAddressRange,
260                             Buffer);
261
262     /*
263      * Get AddressTranslationOffset (Bytes 12-13)
264      */
265     Buffer += 2;
266     ACPI_MOVE_UNALIGNED16_TO_16 (&OutputStruct->Data.Address16.AddressTranslationOffset,
267                             Buffer);
268
269     /*
270      * Get AddressLength (Bytes 14-15)
271      */
272     Buffer += 2;
273     ACPI_MOVE_UNALIGNED16_TO_16 (&OutputStruct->Data.Address16.AddressLength,
274                             Buffer);
275
276     /*
277      * Resource Source Index (if present)
278      */
279     Buffer += 2;
280
281     /*
282      * This will leave us pointing to the Resource Source Index
283      * If it is present, then save it off and calculate the
284      * pointer to where the null terminated string goes:
285      * Each Interrupt takes 32-bits + the 5 bytes of the
286      * stream that are default.
287      */
288     if (*BytesConsumed > 16)
289     {
290         /* Dereference the Index */
291
292         Temp8 = *Buffer;
293         OutputStruct->Data.Address16.ResourceSource.Index = (UINT32) Temp8;
294
295         /* Point to the String */
296
297         Buffer += 1;
298
299         /* Point the String pointer to the end of this structure */
300
301         OutputStruct->Data.Address16.ResourceSource.StringPtr =
302                 (char *)((UINT8 * )OutputStruct + StructSize);
303
304         TempPtr = (UINT8 *) OutputStruct->Data.Address16.ResourceSource.StringPtr;
305
306         /* Copy the string into the buffer */
307
308         Index = 0;
309
310         while (0x00 != *Buffer)
311         {
312             *TempPtr = *Buffer;
313
314             TempPtr += 1;
315             Buffer += 1;
316             Index += 1;
317         }
318
319         /*
320          * Add the terminating null
321          */
322         *TempPtr = 0x00;
323
324         OutputStruct->Data.Address16.ResourceSource.StringLength = Index + 1;
325
326         /*
327          * In order for the StructSize to fall on a 32-bit boundary,
328          * calculate the length of the string and expand the
329          * StructSize to the next 32-bit boundary.
330          */
331         Temp8 = (UINT8) (Index + 1);
332         StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
333     }
334     else
335     {
336         OutputStruct->Data.Address16.ResourceSource.Index = 0x00;
337         OutputStruct->Data.Address16.ResourceSource.StringLength = 0;
338         OutputStruct->Data.Address16.ResourceSource.StringPtr = NULL;
339     }
340
341     /*
342      * Set the Length parameter
343      */
344     OutputStruct->Length = (UINT32) StructSize;
345
346     /*
347      * Return the final size of the structure
348      */
349     *StructureSize = StructSize;
350     return_ACPI_STATUS (AE_OK);
351 }
352
353
354 /*******************************************************************************
355  *
356  * FUNCTION:    AcpiRsAddress16Stream
357  *
358  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
359  *              OutputBuffer            - Pointer to the user's return buffer
360  *              BytesConsumed           - Pointer to where the number of bytes
361  *                                        used in the OutputBuffer is returned
362  *
363  * RETURN:      Status
364  *
365  * DESCRIPTION: Take the linked list resource structure and fills in the
366  *              the appropriate bytes in a byte stream
367  *
368  ******************************************************************************/
369
370 ACPI_STATUS
371 AcpiRsAddress16Stream (
372     ACPI_RESOURCE           *LinkedList,
373     UINT8                   **OutputBuffer,
374     ACPI_SIZE               *BytesConsumed)
375 {
376     UINT8                   *Buffer = *OutputBuffer;
377     UINT8                   *LengthField;
378     UINT8                   Temp8;
379     char                    *TempPointer = NULL;
380     ACPI_SIZE               ActualBytes;
381
382
383     ACPI_FUNCTION_TRACE ("RsAddress16Stream");
384
385
386     /*
387      * The descriptor field is static
388      */
389     *Buffer = 0x88;
390     Buffer += 1;
391
392     /*
393      * Save a pointer to the Length field - to be filled in later
394      */
395     LengthField = Buffer;
396     Buffer += 2;
397
398     /*
399      * Set the Resource Type (Memory, Io, BusNumber)
400      */
401     Temp8 = (UINT8) (LinkedList->Data.Address16.ResourceType & 0x03);
402     *Buffer = Temp8;
403     Buffer += 1;
404
405     /*
406      * Set the general flags
407      */
408     Temp8 = (UINT8) (LinkedList->Data.Address16.ProducerConsumer & 0x01);
409
410     Temp8 |= (LinkedList->Data.Address16.Decode & 0x01) << 1;
411     Temp8 |= (LinkedList->Data.Address16.MinAddressFixed & 0x01) << 2;
412     Temp8 |= (LinkedList->Data.Address16.MaxAddressFixed & 0x01) << 3;
413
414     *Buffer = Temp8;
415     Buffer += 1;
416
417     /*
418      * Set the type specific flags
419      */
420     Temp8 = 0;
421
422     if (ACPI_MEMORY_RANGE == LinkedList->Data.Address16.ResourceType)
423     {
424         Temp8 = (UINT8)
425             (LinkedList->Data.Address16.Attribute.Memory.ReadWriteAttribute &
426              0x01);
427
428         Temp8 |=
429             (LinkedList->Data.Address16.Attribute.Memory.CacheAttribute &
430              0x0F) << 1;
431     }
432     else if (ACPI_IO_RANGE == LinkedList->Data.Address16.ResourceType)
433     {
434         Temp8 = (UINT8)
435             (LinkedList->Data.Address16.Attribute.Io.RangeAttribute &
436              0x03);
437         Temp8 |=
438             (LinkedList->Data.Address16.Attribute.Io.TranslationAttribute &
439              0x03) << 4;
440     }
441
442     *Buffer = Temp8;
443     Buffer += 1;
444
445     /*
446      * Set the address space granularity
447      */
448     ACPI_MOVE_UNALIGNED16_TO_16 (Buffer,
449                         &LinkedList->Data.Address16.Granularity);
450     Buffer += 2;
451
452     /*
453      * Set the address range minimum
454      */
455     ACPI_MOVE_UNALIGNED16_TO_16 (Buffer,
456                         &LinkedList->Data.Address16.MinAddressRange);
457     Buffer += 2;
458
459     /*
460      * Set the address range maximum
461      */
462     ACPI_MOVE_UNALIGNED16_TO_16 (Buffer,
463                         &LinkedList->Data.Address16.MaxAddressRange);
464     Buffer += 2;
465
466     /*
467      * Set the address translation offset
468      */
469     ACPI_MOVE_UNALIGNED16_TO_16 (Buffer,
470                         &LinkedList->Data.Address16.AddressTranslationOffset);
471     Buffer += 2;
472
473     /*
474      * Set the address length
475      */
476     ACPI_MOVE_UNALIGNED16_TO_16 (Buffer,
477                         &LinkedList->Data.Address16.AddressLength);
478     Buffer += 2;
479
480     /*
481      * Resource Source Index and Resource Source are optional
482      */
483     if (0 != LinkedList->Data.Address16.ResourceSource.StringLength)
484     {
485         Temp8 = (UINT8) LinkedList->Data.Address16.ResourceSource.Index;
486
487         *Buffer = Temp8;
488         Buffer += 1;
489
490         TempPointer = (char *) Buffer;
491
492         /*
493          * Copy the string
494          */
495         ACPI_STRCPY (TempPointer,
496                 LinkedList->Data.Address16.ResourceSource.StringPtr);
497
498         /*
499          * Buffer needs to be set to the length of the sting + one for the
500          *  terminating null
501          */
502         Buffer += (ACPI_STRLEN (LinkedList->Data.Address16.ResourceSource.StringPtr) + 1);
503     }
504
505     /*
506      * Return the number of bytes consumed in this operation
507      */
508     ActualBytes = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
509     *BytesConsumed = ActualBytes;
510
511     /*
512      * Set the length field to the number of bytes consumed
513      * minus the header size (3 bytes)
514      */
515     ActualBytes -= 3;
516     ACPI_MOVE_UNALIGNED16_TO_16 (LengthField, &ActualBytes);
517     return_ACPI_STATUS (AE_OK);
518 }
519
520
521 /*******************************************************************************
522  *
523  * FUNCTION:    AcpiRsAddress32Resource
524  *
525  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
526  *                                        stream
527  *              BytesConsumed           - Pointer to where the number of bytes
528  *                                        consumed the ByteStreamBuffer is
529  *                                        returned
530  *              OutputBuffer            - Pointer to the return data buffer
531  *              StructureSize           - Pointer to where the number of bytes
532  *                                        in the return data struct is returned
533  *
534  * RETURN:      Status
535  *
536  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
537  *              structure pointed to by the OutputBuffer.  Return the
538  *              number of bytes consumed from the byte stream.
539  *
540  ******************************************************************************/
541
542 ACPI_STATUS
543 AcpiRsAddress32Resource (
544     UINT8                   *ByteStreamBuffer,
545     ACPI_SIZE               *BytesConsumed,
546     UINT8                   **OutputBuffer,
547     ACPI_SIZE               *StructureSize)
548 {
549     UINT8                   *Buffer;
550     ACPI_RESOURCE           *OutputStruct= (void *) *OutputBuffer;
551     UINT16                  Temp16;
552     UINT8                   Temp8;
553     UINT8                   *TempPtr;
554     ACPI_SIZE               StructSize;
555     UINT32                  Index;
556
557
558     ACPI_FUNCTION_TRACE ("RsAddress32Resource");
559
560
561     Buffer = ByteStreamBuffer;
562     StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS32);
563
564     /*
565      * Point past the Descriptor to get the number of bytes consumed
566      */
567     Buffer += 1;
568     ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
569     *BytesConsumed = Temp16 + 3;
570
571     OutputStruct->Id = ACPI_RSTYPE_ADDRESS32;
572
573     /*
574      * Get the Resource Type (Byte3)
575      */
576     Buffer += 2;
577     Temp8 = *Buffer;
578
579     /* Values 0-2 are valid */
580     if(Temp8 > 2)
581     {
582         return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
583     }
584
585     OutputStruct->Data.Address32.ResourceType = Temp8 & 0x03;
586
587     /*
588      * Get the General Flags (Byte4)
589      */
590     Buffer += 1;
591     Temp8 = *Buffer;
592
593     /*
594      * Producer / Consumer
595      */
596     OutputStruct->Data.Address32.ProducerConsumer = Temp8 & 0x01;
597
598     /*
599      * Decode
600      */
601     OutputStruct->Data.Address32.Decode = (Temp8 >> 1) & 0x01;
602
603     /*
604      * Min Address Fixed
605      */
606     OutputStruct->Data.Address32.MinAddressFixed = (Temp8 >> 2) & 0x01;
607
608     /*
609      * Max Address Fixed
610      */
611     OutputStruct->Data.Address32.MaxAddressFixed = (Temp8 >> 3) & 0x01;
612
613     /*
614      * Get the Type Specific Flags (Byte5)
615      */
616     Buffer += 1;
617     Temp8 = *Buffer;
618
619     if (ACPI_MEMORY_RANGE == OutputStruct->Data.Address32.ResourceType)
620     {
621         OutputStruct->Data.Address32.Attribute.Memory.ReadWriteAttribute =
622                 (UINT16) (Temp8 & 0x01);
623
624         OutputStruct->Data.Address32.Attribute.Memory.CacheAttribute =
625                 (UINT16) ((Temp8 >> 1) & 0x0F);
626     }
627     else
628     {
629         if (ACPI_IO_RANGE == OutputStruct->Data.Address32.ResourceType)
630         {
631             OutputStruct->Data.Address32.Attribute.Io.RangeAttribute =
632                 (UINT16) (Temp8 & 0x03);
633             OutputStruct->Data.Address32.Attribute.Io.TranslationAttribute =
634                 (UINT16) ((Temp8 >> 4) & 0x03);
635         }
636         else
637         {
638             /* BUS_NUMBER_RANGE == OutputStruct->Data.Address32.ResourceType */
639             /* Nothing needs to be filled in */
640         }
641     }
642
643     /*
644      * Get Granularity (Bytes 6-9)
645      */
646     Buffer += 1;
647     ACPI_MOVE_UNALIGNED32_TO_32 (&OutputStruct->Data.Address32.Granularity,
648                             Buffer);
649
650     /*
651      * Get MinAddressRange (Bytes 10-13)
652      */
653     Buffer += 4;
654     ACPI_MOVE_UNALIGNED32_TO_32 (&OutputStruct->Data.Address32.MinAddressRange,
655                             Buffer);
656
657     /*
658      * Get MaxAddressRange (Bytes 14-17)
659      */
660     Buffer += 4;
661     ACPI_MOVE_UNALIGNED32_TO_32 (&OutputStruct->Data.Address32.MaxAddressRange,
662                             Buffer);
663
664     /*
665      * Get AddressTranslationOffset (Bytes 18-21)
666      */
667     Buffer += 4;
668     ACPI_MOVE_UNALIGNED32_TO_32 (&OutputStruct->Data.Address32.AddressTranslationOffset,
669                             Buffer);
670
671     /*
672      * Get AddressLength (Bytes 22-25)
673      */
674     Buffer += 4;
675     ACPI_MOVE_UNALIGNED32_TO_32 (&OutputStruct->Data.Address32.AddressLength,
676                             Buffer);
677
678     /*
679      * Resource Source Index (if present)
680      */
681     Buffer += 4;
682
683     /*
684      * This will leave us pointing to the Resource Source Index
685      * If it is present, then save it off and calculate the
686      * pointer to where the null terminated string goes:
687      */
688     if (*BytesConsumed > 26)
689     {
690         /* Dereference the Index */
691
692         Temp8 = *Buffer;
693         OutputStruct->Data.Address32.ResourceSource.Index =
694                 (UINT32) Temp8;
695
696         /* Point to the String */
697
698         Buffer += 1;
699
700         /* Point the String pointer to the end of this structure */
701
702         OutputStruct->Data.Address32.ResourceSource.StringPtr =
703                 (char *)((UINT8 *)OutputStruct + StructSize);
704
705         TempPtr = (UINT8 *) OutputStruct->Data.Address32.ResourceSource.StringPtr;
706
707         /* Copy the string into the buffer */
708
709         Index = 0;
710         while (0x00 != *Buffer)
711         {
712             *TempPtr = *Buffer;
713
714             TempPtr += 1;
715             Buffer += 1;
716             Index += 1;
717         }
718
719         /*
720          * Add the terminating null
721          */
722         *TempPtr = 0x00;
723         OutputStruct->Data.Address32.ResourceSource.StringLength = Index + 1;
724
725         /*
726          * In order for the StructSize to fall on a 32-bit boundary,
727          *  calculate the length of the string and expand the
728          *  StructSize to the next 32-bit boundary.
729          */
730         Temp8 = (UINT8) (Index + 1);
731         StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
732     }
733     else
734     {
735         OutputStruct->Data.Address32.ResourceSource.Index = 0x00;
736         OutputStruct->Data.Address32.ResourceSource.StringLength = 0;
737         OutputStruct->Data.Address32.ResourceSource.StringPtr = NULL;
738     }
739
740     /*
741      * Set the Length parameter
742      */
743     OutputStruct->Length = (UINT32) StructSize;
744
745     /*
746      * Return the final size of the structure
747      */
748     *StructureSize = StructSize;
749     return_ACPI_STATUS (AE_OK);
750 }
751
752
753 /*******************************************************************************
754  *
755  * FUNCTION:    AcpiRsAddress32Stream
756  *
757  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
758  *              OutputBuffer            - Pointer to the user's return buffer
759  *              BytesConsumed           - Pointer to where the number of bytes
760  *                                        used in the OutputBuffer is returned
761  *
762  * RETURN:      Status
763  *
764  * DESCRIPTION: Take the linked list resource structure and fills in the
765  *              the appropriate bytes in a byte stream
766  *
767  ******************************************************************************/
768
769 ACPI_STATUS
770 AcpiRsAddress32Stream (
771     ACPI_RESOURCE           *LinkedList,
772     UINT8                   **OutputBuffer,
773     ACPI_SIZE               *BytesConsumed)
774 {
775     UINT8                   *Buffer;
776     UINT16                  *LengthField;
777     UINT8                   Temp8;
778     char                    *TempPointer;
779
780
781     ACPI_FUNCTION_TRACE ("RsAddress32Stream");
782
783
784     Buffer = *OutputBuffer;
785
786     /*
787      * The descriptor field is static
788      */
789     *Buffer = 0x87;
790     Buffer += 1;
791
792     /*
793      * Set a pointer to the Length field - to be filled in later
794      */
795     LengthField = ACPI_CAST_PTR (UINT16, Buffer);
796     Buffer += 2;
797
798     /*
799      * Set the Resource Type (Memory, Io, BusNumber)
800      */
801     Temp8 = (UINT8) (LinkedList->Data.Address32.ResourceType & 0x03);
802
803     *Buffer = Temp8;
804     Buffer += 1;
805
806     /*
807      * Set the general flags
808      */
809     Temp8 = (UINT8) (LinkedList->Data.Address32.ProducerConsumer & 0x01);
810     Temp8 |= (LinkedList->Data.Address32.Decode & 0x01) << 1;
811     Temp8 |= (LinkedList->Data.Address32.MinAddressFixed & 0x01) << 2;
812     Temp8 |= (LinkedList->Data.Address32.MaxAddressFixed & 0x01) << 3;
813
814     *Buffer = Temp8;
815     Buffer += 1;
816
817     /*
818      * Set the type specific flags
819      */
820     Temp8 = 0;
821
822     if (ACPI_MEMORY_RANGE == LinkedList->Data.Address32.ResourceType)
823     {
824         Temp8 = (UINT8)
825             (LinkedList->Data.Address32.Attribute.Memory.ReadWriteAttribute &
826             0x01);
827
828         Temp8 |=
829             (LinkedList->Data.Address32.Attribute.Memory.CacheAttribute &
830              0x0F) << 1;
831     }
832     else if (ACPI_IO_RANGE == LinkedList->Data.Address32.ResourceType)
833     {
834         Temp8 = (UINT8)
835             (LinkedList->Data.Address32.Attribute.Io.RangeAttribute &
836              0x03);
837         Temp8 |=
838             (LinkedList->Data.Address32.Attribute.Io.TranslationAttribute &
839              0x03) << 4;
840     }
841
842     *Buffer = Temp8;
843     Buffer += 1;
844
845     /*
846      * Set the address space granularity
847      */
848     ACPI_MOVE_UNALIGNED32_TO_32 (Buffer,
849                     &LinkedList->Data.Address32.Granularity);
850     Buffer += 4;
851
852     /*
853      * Set the address range minimum
854      */
855     ACPI_MOVE_UNALIGNED32_TO_32 (Buffer,
856                     &LinkedList->Data.Address32.MinAddressRange);
857     Buffer += 4;
858
859     /*
860      * Set the address range maximum
861      */
862     ACPI_MOVE_UNALIGNED32_TO_32 (Buffer,
863                     &LinkedList->Data.Address32.MaxAddressRange);
864     Buffer += 4;
865
866     /*
867      * Set the address translation offset
868      */
869     ACPI_MOVE_UNALIGNED32_TO_32 (Buffer,
870                     &LinkedList->Data.Address32.AddressTranslationOffset);
871     Buffer += 4;
872
873     /*
874      * Set the address length
875      */
876     ACPI_MOVE_UNALIGNED32_TO_32 (Buffer,
877                     &LinkedList->Data.Address32.AddressLength);
878     Buffer += 4;
879
880     /*
881      * Resource Source Index and Resource Source are optional
882      */
883     if (0 != LinkedList->Data.Address32.ResourceSource.StringLength)
884     {
885         Temp8 = (UINT8) LinkedList->Data.Address32.ResourceSource.Index;
886
887         *Buffer = Temp8;
888         Buffer += 1;
889
890         TempPointer = (char *) Buffer;
891
892         /*
893          * Copy the string
894          */
895         ACPI_STRCPY (TempPointer,
896             LinkedList->Data.Address32.ResourceSource.StringPtr);
897
898         /*
899          * Buffer needs to be set to the length of the sting + one for the
900          *  terminating null
901          */
902         Buffer += (ACPI_STRLEN (LinkedList->Data.Address32.ResourceSource.StringPtr) + 1);
903     }
904
905     /*
906      * Return the number of bytes consumed in this operation
907      */
908     *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
909
910     /*
911      * Set the length field to the number of bytes consumed
912      *  minus the header size (3 bytes)
913      */
914     *LengthField = (UINT16) (*BytesConsumed - 3);
915     return_ACPI_STATUS (AE_OK);
916 }
917
918
919 /*******************************************************************************
920  *
921  * FUNCTION:    AcpiRsAddress64Resource
922  *
923  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
924  *                                        stream
925  *              BytesConsumed           - Pointer to where the number of bytes
926  *                                        consumed the ByteStreamBuffer is
927  *                                        returned
928  *              OutputBuffer            - Pointer to the return data buffer
929  *              StructureSize           - Pointer to where the number of bytes
930  *                                        in the return data struct is returned
931  *
932  * RETURN:      Status
933  *
934  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
935  *              structure pointed to by the OutputBuffer.  Return the
936  *              number of bytes consumed from the byte stream.
937  *
938  ******************************************************************************/
939
940 ACPI_STATUS
941 AcpiRsAddress64Resource (
942     UINT8                   *ByteStreamBuffer,
943     ACPI_SIZE               *BytesConsumed,
944     UINT8                   **OutputBuffer,
945     ACPI_SIZE               *StructureSize)
946 {
947     UINT8                   *Buffer;
948     ACPI_RESOURCE           *OutputStruct = (void *) *OutputBuffer;
949     UINT16                  Temp16;
950     UINT8                   Temp8;
951     UINT8                   *TempPtr;
952     ACPI_SIZE               StructSize;
953     UINT32                  Index;
954
955
956     ACPI_FUNCTION_TRACE ("RsAddress64Resource");
957
958
959     Buffer = ByteStreamBuffer;
960     StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS64);
961
962     /*
963      * Point past the Descriptor to get the number of bytes consumed
964      */
965     Buffer += 1;
966     ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
967
968     *BytesConsumed = Temp16 + 3;
969     OutputStruct->Id = ACPI_RSTYPE_ADDRESS64;
970
971     /*
972      * Get the Resource Type (Byte3)
973      */
974     Buffer += 2;
975     Temp8 = *Buffer;
976
977     /* Values 0-2 are valid */
978
979     if(Temp8 > 2)
980     {
981         return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
982     }
983
984     OutputStruct->Data.Address64.ResourceType = Temp8 & 0x03;
985
986     /*
987      * Get the General Flags (Byte4)
988      */
989     Buffer += 1;
990     Temp8 = *Buffer;
991
992     /*
993      * Producer / Consumer
994      */
995     OutputStruct->Data.Address64.ProducerConsumer = Temp8 & 0x01;
996
997     /*
998      * Decode
999      */
1000     OutputStruct->Data.Address64.Decode = (Temp8 >> 1) & 0x01;
1001
1002     /*
1003      * Min Address Fixed
1004      */
1005     OutputStruct->Data.Address64.MinAddressFixed = (Temp8 >> 2) & 0x01;
1006
1007     /*
1008      * Max Address Fixed
1009      */
1010     OutputStruct->Data.Address64.MaxAddressFixed = (Temp8 >> 3) & 0x01;
1011
1012     /*
1013      * Get the Type Specific Flags (Byte5)
1014      */
1015     Buffer += 1;
1016     Temp8 = *Buffer;
1017
1018     if (ACPI_MEMORY_RANGE == OutputStruct->Data.Address64.ResourceType)
1019     {
1020         OutputStruct->Data.Address64.Attribute.Memory.ReadWriteAttribute =
1021                 (UINT16) (Temp8 & 0x01);
1022
1023         OutputStruct->Data.Address64.Attribute.Memory.CacheAttribute =
1024                 (UINT16) ((Temp8 >> 1) & 0x0F);
1025     }
1026     else
1027     {
1028         if (ACPI_IO_RANGE == OutputStruct->Data.Address64.ResourceType)
1029         {
1030             OutputStruct->Data.Address64.Attribute.Io.RangeAttribute =
1031                 (UINT16) (Temp8 & 0x03);
1032             OutputStruct->Data.Address64.Attribute.Io.TranslationAttribute =
1033                 (UINT16) ((Temp8 >> 4) & 0x03);
1034         }
1035         else
1036         {
1037             /* BUS_NUMBER_RANGE == OutputStruct->Data.Address64.ResourceType */
1038             /* Nothing needs to be filled in */
1039         }
1040     }
1041
1042     /*
1043      * Get Granularity (Bytes 6-13)
1044      */
1045     Buffer += 1;
1046     ACPI_MOVE_UNALIGNED64_TO_64 (&OutputStruct->Data.Address64.Granularity,
1047                             Buffer);
1048
1049     /*
1050      * Get MinAddressRange (Bytes 14-21)
1051      */
1052     Buffer += 8;
1053     ACPI_MOVE_UNALIGNED64_TO_64 (&OutputStruct->Data.Address64.MinAddressRange,
1054                             Buffer);
1055
1056     /*
1057      * Get MaxAddressRange (Bytes 22-29)
1058      */
1059     Buffer += 8;
1060     ACPI_MOVE_UNALIGNED64_TO_64 (&OutputStruct->Data.Address64.MaxAddressRange,
1061                             Buffer);
1062
1063     /*
1064      * Get AddressTranslationOffset (Bytes 30-37)
1065      */
1066     Buffer += 8;
1067     ACPI_MOVE_UNALIGNED64_TO_64 (&OutputStruct->Data.Address64.AddressTranslationOffset,
1068                             Buffer);
1069
1070     /*
1071      * Get AddressLength (Bytes 38-45)
1072      */
1073     Buffer += 8;
1074     ACPI_MOVE_UNALIGNED64_TO_64 (&OutputStruct->Data.Address64.AddressLength,
1075                             Buffer);
1076
1077     /*
1078      * Resource Source Index (if present)
1079      */
1080     Buffer += 8;
1081
1082     /*
1083      * This will leave us pointing to the Resource Source Index
1084      * If it is present, then save it off and calculate the
1085      * pointer to where the null terminated string goes:
1086      * Each Interrupt takes 32-bits + the 5 bytes of the
1087      * stream that are default.
1088      */
1089     if (*BytesConsumed > 46)
1090     {
1091         /* Dereference the Index */
1092
1093         Temp8 = *Buffer;
1094         OutputStruct->Data.Address64.ResourceSource.Index =
1095                 (UINT32) Temp8;
1096
1097         /* Point to the String */
1098
1099         Buffer += 1;
1100
1101         /* Point the String pointer to the end of this structure */
1102
1103         OutputStruct->Data.Address64.ResourceSource.StringPtr =
1104                 (char *)((UINT8 *)OutputStruct + StructSize);
1105
1106         TempPtr = (UINT8 *) OutputStruct->Data.Address64.ResourceSource.StringPtr;
1107
1108         /* Copy the string into the buffer */
1109
1110         Index = 0;
1111         while (0x00 != *Buffer)
1112         {
1113             *TempPtr = *Buffer;
1114
1115             TempPtr += 1;
1116             Buffer += 1;
1117             Index += 1;
1118         }
1119
1120         /*
1121          * Add the terminating null
1122          */
1123         *TempPtr = 0x00;
1124
1125         OutputStruct->Data.Address64.ResourceSource.StringLength = Index + 1;
1126
1127         /*
1128          * In order for the StructSize to fall on a 32-bit boundary,
1129          * calculate the length of the string and expand the
1130          * StructSize to the next 32-bit boundary.
1131          */
1132         Temp8 = (UINT8) (Index + 1);
1133         StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
1134     }
1135     else
1136     {
1137         OutputStruct->Data.Address64.ResourceSource.Index = 0x00;
1138         OutputStruct->Data.Address64.ResourceSource.StringLength = 0;
1139         OutputStruct->Data.Address64.ResourceSource.StringPtr = NULL;
1140     }
1141
1142     /*
1143      * Set the Length parameter
1144      */
1145     OutputStruct->Length = (UINT32) StructSize;
1146
1147     /*
1148      * Return the final size of the structure
1149      */
1150     *StructureSize = StructSize;
1151     return_ACPI_STATUS (AE_OK);
1152 }
1153
1154
1155 /*******************************************************************************
1156  *
1157  * FUNCTION:    AcpiRsAddress64Stream
1158  *
1159  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
1160  *              OutputBuffer            - Pointer to the user's return buffer
1161  *              BytesConsumed           - Pointer to where the number of bytes
1162  *                                        used in the OutputBuffer is returned
1163  *
1164  * RETURN:      Status
1165  *
1166  * DESCRIPTION: Take the linked list resource structure and fills in the
1167  *              the appropriate bytes in a byte stream
1168  *
1169  ******************************************************************************/
1170
1171 ACPI_STATUS
1172 AcpiRsAddress64Stream (
1173     ACPI_RESOURCE           *LinkedList,
1174     UINT8                   **OutputBuffer,
1175     ACPI_SIZE               *BytesConsumed)
1176 {
1177     UINT8                   *Buffer;
1178     UINT16                  *LengthField;
1179     UINT8                   Temp8;
1180     char                    *TempPointer;
1181
1182
1183     ACPI_FUNCTION_TRACE ("RsAddress64Stream");
1184
1185
1186     Buffer = *OutputBuffer;
1187
1188     /*
1189      * The descriptor field is static
1190      */
1191     *Buffer = 0x8A;
1192     Buffer += 1;
1193
1194     /*
1195      * Set a pointer to the Length field - to be filled in later
1196      */
1197
1198     LengthField = ACPI_CAST_PTR (UINT16, Buffer);
1199     Buffer += 2;
1200
1201     /*
1202      * Set the Resource Type (Memory, Io, BusNumber)
1203      */
1204     Temp8 = (UINT8) (LinkedList->Data.Address64.ResourceType & 0x03);
1205
1206     *Buffer = Temp8;
1207     Buffer += 1;
1208
1209     /*
1210      * Set the general flags
1211      */
1212     Temp8 = (UINT8) (LinkedList->Data.Address64.ProducerConsumer & 0x01);
1213     Temp8 |= (LinkedList->Data.Address64.Decode & 0x01) << 1;
1214     Temp8 |= (LinkedList->Data.Address64.MinAddressFixed & 0x01) << 2;
1215     Temp8 |= (LinkedList->Data.Address64.MaxAddressFixed & 0x01) << 3;
1216
1217     *Buffer = Temp8;
1218     Buffer += 1;
1219
1220     /*
1221      * Set the type specific flags
1222      */
1223     Temp8 = 0;
1224
1225     if (ACPI_MEMORY_RANGE == LinkedList->Data.Address64.ResourceType)
1226     {
1227         Temp8 = (UINT8)
1228             (LinkedList->Data.Address64.Attribute.Memory.ReadWriteAttribute &
1229             0x01);
1230
1231         Temp8 |=
1232             (LinkedList->Data.Address64.Attribute.Memory.CacheAttribute &
1233              0x0F) << 1;
1234     }
1235     else if (ACPI_IO_RANGE == LinkedList->Data.Address64.ResourceType)
1236     {
1237         Temp8 = (UINT8)
1238             (LinkedList->Data.Address64.Attribute.Io.RangeAttribute &
1239              0x03);
1240         Temp8 |=
1241             (LinkedList->Data.Address64.Attribute.Io.RangeAttribute &
1242              0x03) << 4;
1243     }
1244
1245     *Buffer = Temp8;
1246     Buffer += 1;
1247
1248     /*
1249      * Set the address space granularity
1250      */
1251     ACPI_MOVE_UNALIGNED64_TO_64 (Buffer,
1252                         &LinkedList->Data.Address64.Granularity);
1253     Buffer += 8;
1254
1255     /*
1256      * Set the address range minimum
1257      */
1258     ACPI_MOVE_UNALIGNED64_TO_64 (Buffer,
1259                         &LinkedList->Data.Address64.MinAddressRange);
1260     Buffer += 8;
1261
1262     /*
1263      * Set the address range maximum
1264      */
1265     ACPI_MOVE_UNALIGNED64_TO_64 (Buffer,
1266                         &LinkedList->Data.Address64.MaxAddressRange);
1267     Buffer += 8;
1268
1269     /*
1270      * Set the address translation offset
1271      */
1272     ACPI_MOVE_UNALIGNED64_TO_64 (Buffer,
1273                         &LinkedList->Data.Address64.AddressTranslationOffset);
1274     Buffer += 8;
1275
1276     /*
1277      * Set the address length
1278      */
1279     ACPI_MOVE_UNALIGNED64_TO_64 (Buffer,
1280                         &LinkedList->Data.Address64.AddressLength);
1281     Buffer += 8;
1282
1283     /*
1284      * Resource Source Index and Resource Source are optional
1285      */
1286     if (0 != LinkedList->Data.Address64.ResourceSource.StringLength)
1287     {
1288         Temp8 = (UINT8) LinkedList->Data.Address64.ResourceSource.Index;
1289
1290         *Buffer = Temp8;
1291         Buffer += 1;
1292
1293         TempPointer = (char *) Buffer;
1294
1295         /*
1296          * Copy the string
1297          */
1298         ACPI_STRCPY (TempPointer, LinkedList->Data.Address64.ResourceSource.StringPtr);
1299
1300         /*
1301          * Buffer needs to be set to the length of the sting + one for the
1302          *  terminating null
1303          */
1304         Buffer += (ACPI_STRLEN (LinkedList->Data.Address64.ResourceSource.StringPtr) + 1);
1305     }
1306
1307     /*
1308      * Return the number of bytes consumed in this operation
1309      */
1310     *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
1311
1312     /*
1313      * Set the length field to the number of bytes consumed
1314      * minus the header size (3 bytes)
1315      */
1316     *LengthField = (UINT16) (*BytesConsumed - 3);
1317     return_ACPI_STATUS (AE_OK);
1318 }
1319