Merge from vendor branch TCPDUMP:
[dragonfly.git] / sys / contrib / dev / acpica-unix-20031203 / resources / rsaddr.c
1 /*******************************************************************************
2  *
3  * Module Name: rsaddr - Address resource descriptors (16/32/64)
4  *              $Revision: 33 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117 #define __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      * Point past the Descriptor to get the number of bytes consumed
167      */
168     Buffer += 1;
169     ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
170
171     /* Validate minimum descriptor length */
172
173     if (Temp16 < 13)
174     {
175         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
176     }
177
178     *BytesConsumed = Temp16 + 3;
179     OutputStruct->Id = ACPI_RSTYPE_ADDRESS16;
180
181     /*
182      * Get the Resource Type (Byte3)
183      */
184     Buffer += 2;
185     Temp8 = *Buffer;
186
187     /* Values 0-2 are valid */
188
189     if (Temp8 > 2)
190     {
191         return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
192     }
193
194     OutputStruct->Data.Address16.ResourceType = Temp8 & 0x03;
195
196     /*
197      * Get the General Flags (Byte4)
198      */
199     Buffer += 1;
200     Temp8 = *Buffer;
201
202     /* Producer / Consumer */
203
204     OutputStruct->Data.Address16.ProducerConsumer = Temp8 & 0x01;
205
206     /* Decode */
207
208     OutputStruct->Data.Address16.Decode = (Temp8 >> 1) & 0x01;
209
210     /* Min Address Fixed */
211
212     OutputStruct->Data.Address16.MinAddressFixed = (Temp8 >> 2) & 0x01;
213
214     /* Max Address Fixed */
215
216     OutputStruct->Data.Address16.MaxAddressFixed = (Temp8 >> 3) & 0x01;
217
218     /*
219      * Get the Type Specific Flags (Byte5)
220      */
221     Buffer += 1;
222     Temp8 = *Buffer;
223
224     if (ACPI_MEMORY_RANGE == OutputStruct->Data.Address16.ResourceType)
225     {
226         OutputStruct->Data.Address16.Attribute.Memory.ReadWriteAttribute =
227                 (UINT16) (Temp8 & 0x01);
228         OutputStruct->Data.Address16.Attribute.Memory.CacheAttribute =
229                 (UINT16) ((Temp8 >> 1) & 0x0F);
230     }
231     else
232     {
233         if (ACPI_IO_RANGE == OutputStruct->Data.Address16.ResourceType)
234         {
235             OutputStruct->Data.Address16.Attribute.Io.RangeAttribute =
236                 (UINT16) (Temp8 & 0x03);
237             OutputStruct->Data.Address16.Attribute.Io.TranslationAttribute =
238                 (UINT16) ((Temp8 >> 4) & 0x03);
239         }
240         else
241         {
242             /* BUS_NUMBER_RANGE == Address16.Data->ResourceType */
243             /* Nothing needs to be filled in */
244         }
245     }
246
247     /*
248      * Get Granularity (Bytes 6-7)
249      */
250     Buffer += 1;
251     ACPI_MOVE_16_TO_32 (&OutputStruct->Data.Address16.Granularity, Buffer);
252
253     /*
254      * Get MinAddressRange (Bytes 8-9)
255      */
256     Buffer += 2;
257     ACPI_MOVE_16_TO_32 (&OutputStruct->Data.Address16.MinAddressRange, Buffer);
258
259     /*
260      * Get MaxAddressRange (Bytes 10-11)
261      */
262     Buffer += 2;
263     ACPI_MOVE_16_TO_32 (&OutputStruct->Data.Address16.MaxAddressRange, Buffer);
264
265     /*
266      * Get AddressTranslationOffset (Bytes 12-13)
267      */
268     Buffer += 2;
269     ACPI_MOVE_16_TO_32 (&OutputStruct->Data.Address16.AddressTranslationOffset, Buffer);
270
271     /*
272      * Get AddressLength (Bytes 14-15)
273      */
274     Buffer += 2;
275     ACPI_MOVE_16_TO_32 (&OutputStruct->Data.Address16.AddressLength, Buffer);
276
277     /*
278      * Resource Source Index (if present)
279      */
280     Buffer += 2;
281
282     /*
283      * This will leave us pointing to the Resource Source Index
284      * If it is present, then save it off and calculate the
285      * pointer to where the null terminated string goes:
286      * Each Interrupt takes 32-bits + the 5 bytes of the
287      * stream that are default.
288      *
289      * Note: Some resource descriptors will have an additional null, so
290      * we add 1 to the length.
291      */
292     if (*BytesConsumed > (16 + 1))
293     {
294         /* Dereference the Index */
295
296         Temp8 = *Buffer;
297         OutputStruct->Data.Address16.ResourceSource.Index = (UINT32) Temp8;
298
299         /* Point to the String */
300
301         Buffer += 1;
302
303         /* Point the String pointer to the end of this structure */
304
305         OutputStruct->Data.Address16.ResourceSource.StringPtr =
306                 (char *)((UINT8 * )OutputStruct + StructSize);
307
308         TempPtr = (UINT8 *) OutputStruct->Data.Address16.ResourceSource.StringPtr;
309
310         /* Copy the string into the buffer */
311
312         Index = 0;
313
314         while (0x00 != *Buffer)
315         {
316             *TempPtr = *Buffer;
317
318             TempPtr += 1;
319             Buffer += 1;
320             Index += 1;
321         }
322
323         /*
324          * Add the terminating null
325          */
326         *TempPtr = 0x00;
327
328         OutputStruct->Data.Address16.ResourceSource.StringLength = Index + 1;
329
330         /*
331          * In order for the StructSize to fall on a 32-bit boundary,
332          * calculate the length of the string and expand the
333          * StructSize to the next 32-bit boundary.
334          */
335         Temp8 = (UINT8) (Index + 1);
336         StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
337     }
338     else
339     {
340         OutputStruct->Data.Address16.ResourceSource.Index = 0x00;
341         OutputStruct->Data.Address16.ResourceSource.StringLength = 0;
342         OutputStruct->Data.Address16.ResourceSource.StringPtr = NULL;
343     }
344
345     /*
346      * Set the Length parameter
347      */
348     OutputStruct->Length = (UINT32) StructSize;
349
350     /*
351      * Return the final size of the structure
352      */
353     *StructureSize = StructSize;
354     return_ACPI_STATUS (AE_OK);
355 }
356
357
358 /*******************************************************************************
359  *
360  * FUNCTION:    AcpiRsAddress16Stream
361  *
362  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
363  *              OutputBuffer            - Pointer to the user's return buffer
364  *              BytesConsumed           - Pointer to where the number of bytes
365  *                                        used in the OutputBuffer is returned
366  *
367  * RETURN:      Status
368  *
369  * DESCRIPTION: Take the linked list resource structure and fills in the
370  *              the appropriate bytes in a byte stream
371  *
372  ******************************************************************************/
373
374 ACPI_STATUS
375 AcpiRsAddress16Stream (
376     ACPI_RESOURCE           *LinkedList,
377     UINT8                   **OutputBuffer,
378     ACPI_SIZE               *BytesConsumed)
379 {
380     UINT8                   *Buffer = *OutputBuffer;
381     UINT8                   *LengthField;
382     UINT8                   Temp8;
383     char                    *TempPointer = NULL;
384     ACPI_SIZE               ActualBytes;
385
386
387     ACPI_FUNCTION_TRACE ("RsAddress16Stream");
388
389
390     /*
391      * The descriptor field is static
392      */
393     *Buffer = 0x88;
394     Buffer += 1;
395
396     /*
397      * Save a pointer to the Length field - to be filled in later
398      */
399     LengthField = Buffer;
400     Buffer += 2;
401
402     /*
403      * Set the Resource Type (Memory, Io, BusNumber)
404      */
405     Temp8 = (UINT8) (LinkedList->Data.Address16.ResourceType & 0x03);
406     *Buffer = Temp8;
407     Buffer += 1;
408
409     /*
410      * Set the general flags
411      */
412     Temp8 = (UINT8) (LinkedList->Data.Address16.ProducerConsumer & 0x01);
413
414     Temp8 |= (LinkedList->Data.Address16.Decode & 0x01) << 1;
415     Temp8 |= (LinkedList->Data.Address16.MinAddressFixed & 0x01) << 2;
416     Temp8 |= (LinkedList->Data.Address16.MaxAddressFixed & 0x01) << 3;
417
418     *Buffer = Temp8;
419     Buffer += 1;
420
421     /*
422      * Set the type specific flags
423      */
424     Temp8 = 0;
425
426     if (ACPI_MEMORY_RANGE == LinkedList->Data.Address16.ResourceType)
427     {
428         Temp8 = (UINT8)
429             (LinkedList->Data.Address16.Attribute.Memory.ReadWriteAttribute &
430              0x01);
431
432         Temp8 |=
433             (LinkedList->Data.Address16.Attribute.Memory.CacheAttribute &
434              0x0F) << 1;
435     }
436     else if (ACPI_IO_RANGE == LinkedList->Data.Address16.ResourceType)
437     {
438         Temp8 = (UINT8)
439             (LinkedList->Data.Address16.Attribute.Io.RangeAttribute &
440              0x03);
441         Temp8 |=
442             (LinkedList->Data.Address16.Attribute.Io.TranslationAttribute &
443              0x03) << 4;
444     }
445
446     *Buffer = Temp8;
447     Buffer += 1;
448
449     /*
450      * Set the address space granularity
451      */
452     ACPI_MOVE_32_TO_16 (Buffer, &LinkedList->Data.Address16.Granularity);
453     Buffer += 2;
454
455     /*
456      * Set the address range minimum
457      */
458     ACPI_MOVE_32_TO_16 (Buffer, &LinkedList->Data.Address16.MinAddressRange);
459     Buffer += 2;
460
461     /*
462      * Set the address range maximum
463      */
464     ACPI_MOVE_32_TO_16 (Buffer, &LinkedList->Data.Address16.MaxAddressRange);
465     Buffer += 2;
466
467     /*
468      * Set the address translation offset
469      */
470     ACPI_MOVE_32_TO_16 (Buffer, &LinkedList->Data.Address16.AddressTranslationOffset);
471     Buffer += 2;
472
473     /*
474      * Set the address length
475      */
476     ACPI_MOVE_32_TO_16 (Buffer, &LinkedList->Data.Address16.AddressLength);
477     Buffer += 2;
478
479     /*
480      * Resource Source Index and Resource Source are optional
481      */
482     if (0 != LinkedList->Data.Address16.ResourceSource.StringLength)
483     {
484         Temp8 = (UINT8) LinkedList->Data.Address16.ResourceSource.Index;
485
486         *Buffer = Temp8;
487         Buffer += 1;
488
489         TempPointer = (char *) Buffer;
490
491         /*
492          * Copy the string
493          */
494         ACPI_STRCPY (TempPointer,
495                 LinkedList->Data.Address16.ResourceSource.StringPtr);
496
497         /*
498          * Buffer needs to be set to the length of the sting + one for the
499          * terminating null
500          */
501         Buffer += (ACPI_SIZE)(ACPI_STRLEN (LinkedList->Data.Address16.ResourceSource.StringPtr) + 1);
502     }
503
504     /*
505      * Return the number of bytes consumed in this operation
506      */
507     ActualBytes = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
508     *BytesConsumed = ActualBytes;
509
510     /*
511      * Set the length field to the number of bytes consumed
512      * minus the header size (3 bytes)
513      */
514     ActualBytes -= 3;
515     ACPI_MOVE_SIZE_TO_16 (LengthField, &ActualBytes);
516     return_ACPI_STATUS (AE_OK);
517 }
518
519
520 /*******************************************************************************
521  *
522  * FUNCTION:    AcpiRsAddress32Resource
523  *
524  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
525  *                                        stream
526  *              BytesConsumed           - Pointer to where the number of bytes
527  *                                        consumed the ByteStreamBuffer is
528  *                                        returned
529  *              OutputBuffer            - Pointer to the return data buffer
530  *              StructureSize           - Pointer to where the number of bytes
531  *                                        in the return data struct is returned
532  *
533  * RETURN:      Status
534  *
535  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
536  *              structure pointed to by the OutputBuffer.  Return the
537  *              number of bytes consumed from the byte stream.
538  *
539  ******************************************************************************/
540
541 ACPI_STATUS
542 AcpiRsAddress32Resource (
543     UINT8                   *ByteStreamBuffer,
544     ACPI_SIZE               *BytesConsumed,
545     UINT8                   **OutputBuffer,
546     ACPI_SIZE               *StructureSize)
547 {
548     UINT8                   *Buffer;
549     ACPI_RESOURCE           *OutputStruct= (void *) *OutputBuffer;
550     UINT16                  Temp16;
551     UINT8                   Temp8;
552     UINT8                   *TempPtr;
553     ACPI_SIZE               StructSize;
554     UINT32                  Index;
555
556
557     ACPI_FUNCTION_TRACE ("RsAddress32Resource");
558
559
560     Buffer = ByteStreamBuffer;
561     StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS32);
562
563     /*
564      * Point past the Descriptor to get the number of bytes consumed
565      */
566     Buffer += 1;
567     ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
568
569     /* Validate minimum descriptor length */
570
571     if (Temp16 < 23)
572     {
573         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
574     }
575
576     *BytesConsumed = Temp16 + 3;
577     OutputStruct->Id = ACPI_RSTYPE_ADDRESS32;
578
579     /*
580      * Get the Resource Type (Byte3)
581      */
582     Buffer += 2;
583     Temp8 = *Buffer;
584
585     /* Values 0-2 are valid */
586     if(Temp8 > 2)
587     {
588         return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
589     }
590
591     OutputStruct->Data.Address32.ResourceType = Temp8 & 0x03;
592
593     /*
594      * Get the General Flags (Byte4)
595      */
596     Buffer += 1;
597     Temp8 = *Buffer;
598
599     /*
600      * Producer / Consumer
601      */
602     OutputStruct->Data.Address32.ProducerConsumer = Temp8 & 0x01;
603
604     /*
605      * Decode
606      */
607     OutputStruct->Data.Address32.Decode = (Temp8 >> 1) & 0x01;
608
609     /*
610      * Min Address Fixed
611      */
612     OutputStruct->Data.Address32.MinAddressFixed = (Temp8 >> 2) & 0x01;
613
614     /*
615      * Max Address Fixed
616      */
617     OutputStruct->Data.Address32.MaxAddressFixed = (Temp8 >> 3) & 0x01;
618
619     /*
620      * Get the Type Specific Flags (Byte5)
621      */
622     Buffer += 1;
623     Temp8 = *Buffer;
624
625     if (ACPI_MEMORY_RANGE == OutputStruct->Data.Address32.ResourceType)
626     {
627         OutputStruct->Data.Address32.Attribute.Memory.ReadWriteAttribute =
628                 (UINT16) (Temp8 & 0x01);
629
630         OutputStruct->Data.Address32.Attribute.Memory.CacheAttribute =
631                 (UINT16) ((Temp8 >> 1) & 0x0F);
632     }
633     else
634     {
635         if (ACPI_IO_RANGE == OutputStruct->Data.Address32.ResourceType)
636         {
637             OutputStruct->Data.Address32.Attribute.Io.RangeAttribute =
638                 (UINT16) (Temp8 & 0x03);
639             OutputStruct->Data.Address32.Attribute.Io.TranslationAttribute =
640                 (UINT16) ((Temp8 >> 4) & 0x03);
641         }
642         else
643         {
644             /* BUS_NUMBER_RANGE == OutputStruct->Data.Address32.ResourceType */
645             /* Nothing needs to be filled in */
646         }
647     }
648
649     /*
650      * Get Granularity (Bytes 6-9)
651      */
652     Buffer += 1;
653     ACPI_MOVE_32_TO_32 (&OutputStruct->Data.Address32.Granularity, Buffer);
654
655     /*
656      * Get MinAddressRange (Bytes 10-13)
657      */
658     Buffer += 4;
659     ACPI_MOVE_32_TO_32 (&OutputStruct->Data.Address32.MinAddressRange, Buffer);
660
661     /*
662      * Get MaxAddressRange (Bytes 14-17)
663      */
664     Buffer += 4;
665     ACPI_MOVE_32_TO_32 (&OutputStruct->Data.Address32.MaxAddressRange, Buffer);
666
667     /*
668      * Get AddressTranslationOffset (Bytes 18-21)
669      */
670     Buffer += 4;
671     ACPI_MOVE_32_TO_32 (&OutputStruct->Data.Address32.AddressTranslationOffset, Buffer);
672
673     /*
674      * Get AddressLength (Bytes 22-25)
675      */
676     Buffer += 4;
677     ACPI_MOVE_32_TO_32 (&OutputStruct->Data.Address32.AddressLength, Buffer);
678
679     /*
680      * Resource Source Index (if present)
681      */
682     Buffer += 4;
683
684     /*
685      * This will leave us pointing to the Resource Source Index
686      * If it is present, then save it off and calculate the
687      * pointer to where the null terminated string goes:
688      *
689      * Note: Some resource descriptors will have an additional null, so
690      * we add 1 to the length.
691      */
692     if (*BytesConsumed > (26 + 1))
693     {
694         /* Dereference the Index */
695
696         Temp8 = *Buffer;
697         OutputStruct->Data.Address32.ResourceSource.Index =
698                 (UINT32) Temp8;
699
700         /* Point to the String */
701
702         Buffer += 1;
703
704         /* Point the String pointer to the end of this structure */
705
706         OutputStruct->Data.Address32.ResourceSource.StringPtr =
707                 (char *)((UINT8 *)OutputStruct + StructSize);
708
709         TempPtr = (UINT8 *) OutputStruct->Data.Address32.ResourceSource.StringPtr;
710
711         /* Copy the string into the buffer */
712
713         Index = 0;
714         while (0x00 != *Buffer)
715         {
716             *TempPtr = *Buffer;
717
718             TempPtr += 1;
719             Buffer += 1;
720             Index += 1;
721         }
722
723         /*
724          * Add the terminating null
725          */
726         *TempPtr = 0x00;
727         OutputStruct->Data.Address32.ResourceSource.StringLength = Index + 1;
728
729         /*
730          * In order for the StructSize to fall on a 32-bit boundary,
731          * calculate the length of the string and expand the
732          * StructSize to the next 32-bit boundary.
733          */
734         Temp8 = (UINT8) (Index + 1);
735         StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
736     }
737     else
738     {
739         OutputStruct->Data.Address32.ResourceSource.Index = 0x00;
740         OutputStruct->Data.Address32.ResourceSource.StringLength = 0;
741         OutputStruct->Data.Address32.ResourceSource.StringPtr = NULL;
742     }
743
744     /*
745      * Set the Length parameter
746      */
747     OutputStruct->Length = (UINT32) StructSize;
748
749     /*
750      * Return the final size of the structure
751      */
752     *StructureSize = StructSize;
753     return_ACPI_STATUS (AE_OK);
754 }
755
756
757 /*******************************************************************************
758  *
759  * FUNCTION:    AcpiRsAddress32Stream
760  *
761  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
762  *              OutputBuffer            - Pointer to the user's return buffer
763  *              BytesConsumed           - Pointer to where the number of bytes
764  *                                        used in the OutputBuffer is returned
765  *
766  * RETURN:      Status
767  *
768  * DESCRIPTION: Take the linked list resource structure and fills in the
769  *              the appropriate bytes in a byte stream
770  *
771  ******************************************************************************/
772
773 ACPI_STATUS
774 AcpiRsAddress32Stream (
775     ACPI_RESOURCE           *LinkedList,
776     UINT8                   **OutputBuffer,
777     ACPI_SIZE               *BytesConsumed)
778 {
779     UINT8                   *Buffer;
780     UINT16                  *LengthField;
781     UINT8                   Temp8;
782     char                    *TempPointer;
783
784
785     ACPI_FUNCTION_TRACE ("RsAddress32Stream");
786
787
788     Buffer = *OutputBuffer;
789
790     /*
791      * The descriptor field is static
792      */
793     *Buffer = 0x87;
794     Buffer += 1;
795
796     /*
797      * Set a pointer to the Length field - to be filled in later
798      */
799     LengthField = ACPI_CAST_PTR (UINT16, Buffer);
800     Buffer += 2;
801
802     /*
803      * Set the Resource Type (Memory, Io, BusNumber)
804      */
805     Temp8 = (UINT8) (LinkedList->Data.Address32.ResourceType & 0x03);
806
807     *Buffer = Temp8;
808     Buffer += 1;
809
810     /*
811      * Set the general flags
812      */
813     Temp8 = (UINT8) (LinkedList->Data.Address32.ProducerConsumer & 0x01);
814     Temp8 |= (LinkedList->Data.Address32.Decode & 0x01) << 1;
815     Temp8 |= (LinkedList->Data.Address32.MinAddressFixed & 0x01) << 2;
816     Temp8 |= (LinkedList->Data.Address32.MaxAddressFixed & 0x01) << 3;
817
818     *Buffer = Temp8;
819     Buffer += 1;
820
821     /*
822      * Set the type specific flags
823      */
824     Temp8 = 0;
825
826     if (ACPI_MEMORY_RANGE == LinkedList->Data.Address32.ResourceType)
827     {
828         Temp8 = (UINT8)
829             (LinkedList->Data.Address32.Attribute.Memory.ReadWriteAttribute &
830             0x01);
831
832         Temp8 |=
833             (LinkedList->Data.Address32.Attribute.Memory.CacheAttribute &
834              0x0F) << 1;
835     }
836     else if (ACPI_IO_RANGE == LinkedList->Data.Address32.ResourceType)
837     {
838         Temp8 = (UINT8)
839             (LinkedList->Data.Address32.Attribute.Io.RangeAttribute &
840              0x03);
841         Temp8 |=
842             (LinkedList->Data.Address32.Attribute.Io.TranslationAttribute &
843              0x03) << 4;
844     }
845
846     *Buffer = Temp8;
847     Buffer += 1;
848
849     /*
850      * Set the address space granularity
851      */
852     ACPI_MOVE_32_TO_32 (Buffer, &LinkedList->Data.Address32.Granularity);
853     Buffer += 4;
854
855     /*
856      * Set the address range minimum
857      */
858     ACPI_MOVE_32_TO_32 (Buffer, &LinkedList->Data.Address32.MinAddressRange);
859     Buffer += 4;
860
861     /*
862      * Set the address range maximum
863      */
864     ACPI_MOVE_32_TO_32 (Buffer, &LinkedList->Data.Address32.MaxAddressRange);
865     Buffer += 4;
866
867     /*
868      * Set the address translation offset
869      */
870     ACPI_MOVE_32_TO_32 (Buffer, &LinkedList->Data.Address32.AddressTranslationOffset);
871     Buffer += 4;
872
873     /*
874      * Set the address length
875      */
876     ACPI_MOVE_32_TO_32 (Buffer, &LinkedList->Data.Address32.AddressLength);
877     Buffer += 4;
878
879     /*
880      * Resource Source Index and Resource Source are optional
881      */
882     if (0 != LinkedList->Data.Address32.ResourceSource.StringLength)
883     {
884         Temp8 = (UINT8) LinkedList->Data.Address32.ResourceSource.Index;
885
886         *Buffer = Temp8;
887         Buffer += 1;
888
889         TempPointer = (char *) Buffer;
890
891         /*
892          * Copy the string
893          */
894         ACPI_STRCPY (TempPointer,
895             LinkedList->Data.Address32.ResourceSource.StringPtr);
896
897         /*
898          * Buffer needs to be set to the length of the sting + one for the
899          *  terminating null
900          */
901         Buffer += (ACPI_SIZE)(ACPI_STRLEN (LinkedList->Data.Address32.ResourceSource.StringPtr) + 1);
902     }
903
904     /*
905      * Return the number of bytes consumed in this operation
906      */
907     *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
908
909     /*
910      * Set the length field to the number of bytes consumed
911      *  minus the header size (3 bytes)
912      */
913     *LengthField = (UINT16) (*BytesConsumed - 3);
914     return_ACPI_STATUS (AE_OK);
915 }
916
917
918 /*******************************************************************************
919  *
920  * FUNCTION:    AcpiRsAddress64Resource
921  *
922  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource input byte
923  *                                        stream
924  *              BytesConsumed           - Pointer to where the number of bytes
925  *                                        consumed the ByteStreamBuffer is
926  *                                        returned
927  *              OutputBuffer            - Pointer to the return data buffer
928  *              StructureSize           - Pointer to where the number of bytes
929  *                                        in the return data struct is returned
930  *
931  * RETURN:      Status
932  *
933  * DESCRIPTION: Take the resource byte stream and fill out the appropriate
934  *              structure pointed to by the OutputBuffer.  Return the
935  *              number of bytes consumed from the byte stream.
936  *
937  ******************************************************************************/
938
939 ACPI_STATUS
940 AcpiRsAddress64Resource (
941     UINT8                   *ByteStreamBuffer,
942     ACPI_SIZE               *BytesConsumed,
943     UINT8                   **OutputBuffer,
944     ACPI_SIZE               *StructureSize)
945 {
946     UINT8                   *Buffer;
947     ACPI_RESOURCE           *OutputStruct = (void *) *OutputBuffer;
948     UINT16                  Temp16;
949     UINT8                   Temp8;
950     UINT8                   *TempPtr;
951     ACPI_SIZE               StructSize;
952     UINT32                  Index;
953
954
955     ACPI_FUNCTION_TRACE ("RsAddress64Resource");
956
957
958     Buffer = ByteStreamBuffer;
959     StructSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS64);
960
961     /*
962      * Point past the Descriptor to get the number of bytes consumed
963      */
964     Buffer += 1;
965     ACPI_MOVE_16_TO_16 (&Temp16, Buffer);
966
967     /* Validate minimum descriptor length */
968
969     if (Temp16 < 43)
970     {
971         return_ACPI_STATUS (AE_AML_BAD_RESOURCE_LENGTH);
972     }
973
974     *BytesConsumed = Temp16 + 3;
975     OutputStruct->Id = ACPI_RSTYPE_ADDRESS64;
976
977     /*
978      * Get the Resource Type (Byte3)
979      */
980     Buffer += 2;
981     Temp8 = *Buffer;
982
983     /* Values 0-2 are valid */
984
985     if(Temp8 > 2)
986     {
987         return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
988     }
989
990     OutputStruct->Data.Address64.ResourceType = Temp8 & 0x03;
991
992     /*
993      * Get the General Flags (Byte4)
994      */
995     Buffer += 1;
996     Temp8 = *Buffer;
997
998     /*
999      * Producer / Consumer
1000      */
1001     OutputStruct->Data.Address64.ProducerConsumer = Temp8 & 0x01;
1002
1003     /*
1004      * Decode
1005      */
1006     OutputStruct->Data.Address64.Decode = (Temp8 >> 1) & 0x01;
1007
1008     /*
1009      * Min Address Fixed
1010      */
1011     OutputStruct->Data.Address64.MinAddressFixed = (Temp8 >> 2) & 0x01;
1012
1013     /*
1014      * Max Address Fixed
1015      */
1016     OutputStruct->Data.Address64.MaxAddressFixed = (Temp8 >> 3) & 0x01;
1017
1018     /*
1019      * Get the Type Specific Flags (Byte5)
1020      */
1021     Buffer += 1;
1022     Temp8 = *Buffer;
1023
1024     if (ACPI_MEMORY_RANGE == OutputStruct->Data.Address64.ResourceType)
1025     {
1026         OutputStruct->Data.Address64.Attribute.Memory.ReadWriteAttribute =
1027                 (UINT16) (Temp8 & 0x01);
1028
1029         OutputStruct->Data.Address64.Attribute.Memory.CacheAttribute =
1030                 (UINT16) ((Temp8 >> 1) & 0x0F);
1031     }
1032     else
1033     {
1034         if (ACPI_IO_RANGE == OutputStruct->Data.Address64.ResourceType)
1035         {
1036             OutputStruct->Data.Address64.Attribute.Io.RangeAttribute =
1037                 (UINT16) (Temp8 & 0x03);
1038             OutputStruct->Data.Address64.Attribute.Io.TranslationAttribute =
1039                 (UINT16) ((Temp8 >> 4) & 0x03);
1040         }
1041         else
1042         {
1043             /* BUS_NUMBER_RANGE == OutputStruct->Data.Address64.ResourceType */
1044             /* Nothing needs to be filled in */
1045         }
1046     }
1047
1048     /*
1049      * Get Granularity (Bytes 6-13)
1050      */
1051     Buffer += 1;
1052     ACPI_MOVE_64_TO_64 (&OutputStruct->Data.Address64.Granularity, Buffer);
1053
1054     /*
1055      * Get MinAddressRange (Bytes 14-21)
1056      */
1057     Buffer += 8;
1058     ACPI_MOVE_64_TO_64 (&OutputStruct->Data.Address64.MinAddressRange, Buffer);
1059
1060     /*
1061      * Get MaxAddressRange (Bytes 22-29)
1062      */
1063     Buffer += 8;
1064     ACPI_MOVE_64_TO_64 (&OutputStruct->Data.Address64.MaxAddressRange, Buffer);
1065
1066     /*
1067      * Get AddressTranslationOffset (Bytes 30-37)
1068      */
1069     Buffer += 8;
1070     ACPI_MOVE_64_TO_64 (&OutputStruct->Data.Address64.AddressTranslationOffset, Buffer);
1071
1072     /*
1073      * Get AddressLength (Bytes 38-45)
1074      */
1075     Buffer += 8;
1076     ACPI_MOVE_64_TO_64 (&OutputStruct->Data.Address64.AddressLength, Buffer);
1077
1078     /*
1079      * Resource Source Index (if present)
1080      */
1081     Buffer += 8;
1082
1083     /*
1084      * This will leave us pointing to the Resource Source Index
1085      * If it is present, then save it off and calculate the
1086      * pointer to where the null terminated string goes:
1087      * Each Interrupt takes 32-bits + the 5 bytes of the
1088      * stream that are default.
1089      *
1090      * Note: Some resource descriptors will have an additional null, so
1091      * we add 1 to the length.
1092      */
1093     if (*BytesConsumed > (46 + 1))
1094     {
1095         /* Dereference the Index */
1096
1097         Temp8 = *Buffer;
1098         OutputStruct->Data.Address64.ResourceSource.Index =
1099                 (UINT32) Temp8;
1100
1101         /* Point to the String */
1102
1103         Buffer += 1;
1104
1105         /* Point the String pointer to the end of this structure */
1106
1107         OutputStruct->Data.Address64.ResourceSource.StringPtr =
1108                 (char *)((UINT8 *)OutputStruct + StructSize);
1109
1110         TempPtr = (UINT8 *) OutputStruct->Data.Address64.ResourceSource.StringPtr;
1111
1112         /* Copy the string into the buffer */
1113
1114         Index = 0;
1115         while (0x00 != *Buffer)
1116         {
1117             *TempPtr = *Buffer;
1118
1119             TempPtr += 1;
1120             Buffer += 1;
1121             Index += 1;
1122         }
1123
1124         /*
1125          * Add the terminating null
1126          */
1127         *TempPtr = 0x00;
1128         OutputStruct->Data.Address64.ResourceSource.StringLength = Index + 1;
1129
1130         /*
1131          * In order for the StructSize to fall on a 32-bit boundary,
1132          * calculate the length of the string and expand the
1133          * StructSize to the next 32-bit boundary.
1134          */
1135         Temp8 = (UINT8) (Index + 1);
1136         StructSize += ACPI_ROUND_UP_TO_32BITS (Temp8);
1137     }
1138     else
1139     {
1140         OutputStruct->Data.Address64.ResourceSource.Index = 0x00;
1141         OutputStruct->Data.Address64.ResourceSource.StringLength = 0;
1142         OutputStruct->Data.Address64.ResourceSource.StringPtr = NULL;
1143     }
1144
1145     /*
1146      * Set the Length parameter
1147      */
1148     OutputStruct->Length = (UINT32) StructSize;
1149
1150     /*
1151      * Return the final size of the structure
1152      */
1153     *StructureSize = StructSize;
1154     return_ACPI_STATUS (AE_OK);
1155 }
1156
1157
1158 /*******************************************************************************
1159  *
1160  * FUNCTION:    AcpiRsAddress64Stream
1161  *
1162  * PARAMETERS:  LinkedList              - Pointer to the resource linked list
1163  *              OutputBuffer            - Pointer to the user's return buffer
1164  *              BytesConsumed           - Pointer to where the number of bytes
1165  *                                        used in the OutputBuffer is returned
1166  *
1167  * RETURN:      Status
1168  *
1169  * DESCRIPTION: Take the linked list resource structure and fills in the
1170  *              the appropriate bytes in a byte stream
1171  *
1172  ******************************************************************************/
1173
1174 ACPI_STATUS
1175 AcpiRsAddress64Stream (
1176     ACPI_RESOURCE           *LinkedList,
1177     UINT8                   **OutputBuffer,
1178     ACPI_SIZE               *BytesConsumed)
1179 {
1180     UINT8                   *Buffer;
1181     UINT16                  *LengthField;
1182     UINT8                   Temp8;
1183     char                    *TempPointer;
1184
1185
1186     ACPI_FUNCTION_TRACE ("RsAddress64Stream");
1187
1188
1189     Buffer = *OutputBuffer;
1190
1191     /*
1192      * The descriptor field is static
1193      */
1194     *Buffer = 0x8A;
1195     Buffer += 1;
1196
1197     /*
1198      * Set a pointer to the Length field - to be filled in later
1199      */
1200     LengthField = ACPI_CAST_PTR (UINT16, Buffer);
1201     Buffer += 2;
1202
1203     /*
1204      * Set the Resource Type (Memory, Io, BusNumber)
1205      */
1206     Temp8 = (UINT8) (LinkedList->Data.Address64.ResourceType & 0x03);
1207
1208     *Buffer = Temp8;
1209     Buffer += 1;
1210
1211     /*
1212      * Set the general flags
1213      */
1214     Temp8 = (UINT8) (LinkedList->Data.Address64.ProducerConsumer & 0x01);
1215     Temp8 |= (LinkedList->Data.Address64.Decode & 0x01) << 1;
1216     Temp8 |= (LinkedList->Data.Address64.MinAddressFixed & 0x01) << 2;
1217     Temp8 |= (LinkedList->Data.Address64.MaxAddressFixed & 0x01) << 3;
1218
1219     *Buffer = Temp8;
1220     Buffer += 1;
1221
1222     /*
1223      * Set the type specific flags
1224      */
1225     Temp8 = 0;
1226
1227     if (ACPI_MEMORY_RANGE == LinkedList->Data.Address64.ResourceType)
1228     {
1229         Temp8 = (UINT8)
1230             (LinkedList->Data.Address64.Attribute.Memory.ReadWriteAttribute &
1231             0x01);
1232
1233         Temp8 |=
1234             (LinkedList->Data.Address64.Attribute.Memory.CacheAttribute &
1235              0x0F) << 1;
1236     }
1237     else if (ACPI_IO_RANGE == LinkedList->Data.Address64.ResourceType)
1238     {
1239         Temp8 = (UINT8)
1240             (LinkedList->Data.Address64.Attribute.Io.RangeAttribute &
1241              0x03);
1242         Temp8 |=
1243             (LinkedList->Data.Address64.Attribute.Io.RangeAttribute &
1244              0x03) << 4;
1245     }
1246
1247     *Buffer = Temp8;
1248     Buffer += 1;
1249
1250     /*
1251      * Set the address space granularity
1252      */
1253     ACPI_MOVE_64_TO_64 (Buffer, &LinkedList->Data.Address64.Granularity);
1254     Buffer += 8;
1255
1256     /*
1257      * Set the address range minimum
1258      */
1259     ACPI_MOVE_64_TO_64 (Buffer, &LinkedList->Data.Address64.MinAddressRange);
1260     Buffer += 8;
1261
1262     /*
1263      * Set the address range maximum
1264      */
1265     ACPI_MOVE_64_TO_64 (Buffer, &LinkedList->Data.Address64.MaxAddressRange);
1266     Buffer += 8;
1267
1268     /*
1269      * Set the address translation offset
1270      */
1271     ACPI_MOVE_64_TO_64 (Buffer, &LinkedList->Data.Address64.AddressTranslationOffset);
1272     Buffer += 8;
1273
1274     /*
1275      * Set the address length
1276      */
1277     ACPI_MOVE_64_TO_64 (Buffer, &LinkedList->Data.Address64.AddressLength);
1278     Buffer += 8;
1279
1280     /*
1281      * Resource Source Index and Resource Source are optional
1282      */
1283     if (0 != LinkedList->Data.Address64.ResourceSource.StringLength)
1284     {
1285         Temp8 = (UINT8) LinkedList->Data.Address64.ResourceSource.Index;
1286
1287         *Buffer = Temp8;
1288         Buffer += 1;
1289
1290         TempPointer = (char *) Buffer;
1291
1292         /*
1293          * Copy the string
1294          */
1295         ACPI_STRCPY (TempPointer, LinkedList->Data.Address64.ResourceSource.StringPtr);
1296
1297         /*
1298          * Buffer needs to be set to the length of the sting + one for the
1299          * terminating null
1300          */
1301         Buffer += (ACPI_SIZE)(ACPI_STRLEN (LinkedList->Data.Address64.ResourceSource.StringPtr) + 1);
1302     }
1303
1304     /*
1305      * Return the number of bytes consumed in this operation
1306      */
1307     *BytesConsumed = ACPI_PTR_DIFF (Buffer, *OutputBuffer);
1308
1309     /*
1310      * Set the length field to the number of bytes consumed
1311      * minus the header size (3 bytes)
1312      */
1313     *LengthField = (UINT16) (*BytesConsumed - 3);
1314     return_ACPI_STATUS (AE_OK);
1315 }
1316