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