Merge from vendor branch LIBPCAP:
[dragonfly.git] / sys / contrib / dev / acpica / rscalc.c
1 /*******************************************************************************
2  *
3  * Module Name: rscalc - Calculate stream and list lengths
4  *              $Revision: 47 $
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/rscalc.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $                                                               */
117
118 #define __RSCALC_C__
119
120 #include "acpi.h"
121 #include "acresrc.h"
122 #include "amlcode.h"
123 #include "acnamesp.h"
124
125 #define _COMPONENT          ACPI_RESOURCES
126         ACPI_MODULE_NAME    ("rscalc")
127
128
129 /*******************************************************************************
130  *
131  * FUNCTION:    AcpiRsGetByteStreamLength
132  *
133  * PARAMETERS:  LinkedList          - Pointer to the resource linked list
134  *              SizeNeeded          - UINT32 pointer of the size buffer needed
135  *                                    to properly return the parsed data
136  *
137  * RETURN:      Status
138  *
139  * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
140  *              the size buffer needed to hold the linked list that conveys
141  *              the resource data.
142  *
143  ******************************************************************************/
144
145 ACPI_STATUS
146 AcpiRsGetByteStreamLength (
147     ACPI_RESOURCE           *LinkedList,
148     ACPI_SIZE               *SizeNeeded)
149 {
150     ACPI_SIZE               ByteStreamSizeNeeded = 0;
151     ACPI_SIZE               SegmentSize;
152     ACPI_RESOURCE_EXT_IRQ   *ExIrq = NULL;
153     BOOLEAN                 Done = FALSE;
154
155
156     ACPI_FUNCTION_TRACE ("RsGetByteStreamLength");
157
158
159     while (!Done)
160     {
161         /*
162          * Init the variable that will hold the size to add to the total.
163          */
164         SegmentSize = 0;
165
166         switch (LinkedList->Id)
167         {
168         case ACPI_RSTYPE_IRQ:
169             /*
170              * IRQ Resource
171              * For an IRQ Resource, Byte 3, although optional, will
172              * always be created - it holds IRQ information.
173              */
174             SegmentSize = 4;
175             break;
176
177         case ACPI_RSTYPE_DMA:
178             /*
179              * DMA Resource
180              * For this resource the size is static
181              */
182             SegmentSize = 3;
183             break;
184
185         case ACPI_RSTYPE_START_DPF:
186             /*
187              * Start Dependent Functions Resource
188              * For a StartDependentFunctions Resource, Byte 1,
189              * although optional, will always be created.
190              */
191             SegmentSize = 2;
192             break;
193
194         case ACPI_RSTYPE_END_DPF:
195             /*
196              * End Dependent Functions Resource
197              * For this resource the size is static
198              */
199             SegmentSize = 1;
200             break;
201
202         case ACPI_RSTYPE_IO:
203             /*
204              * IO Port Resource
205              * For this resource the size is static
206              */
207             SegmentSize = 8;
208             break;
209
210         case ACPI_RSTYPE_FIXED_IO:
211             /*
212              * Fixed IO Port Resource
213              * For this resource the size is static
214              */
215             SegmentSize = 4;
216             break;
217
218         case ACPI_RSTYPE_VENDOR:
219             /*
220              * Vendor Defined Resource
221              * For a Vendor Specific resource, if the Length is
222              * between 1 and 7 it will be created as a Small
223              * Resource data type, otherwise it is a Large
224              * Resource data type.
225              */
226             if (LinkedList->Data.VendorSpecific.Length > 7)
227             {
228                 SegmentSize = 3;
229             }
230             else
231             {
232                 SegmentSize = 1;
233             }
234             SegmentSize += LinkedList->Data.VendorSpecific.Length;
235             break;
236
237         case ACPI_RSTYPE_END_TAG:
238             /*
239              * End Tag
240              * For this resource the size is static
241              */
242             SegmentSize = 2;
243             Done = TRUE;
244             break;
245
246         case ACPI_RSTYPE_MEM24:
247             /*
248              * 24-Bit Memory Resource
249              * For this resource the size is static
250              */
251             SegmentSize = 12;
252             break;
253
254         case ACPI_RSTYPE_MEM32:
255             /*
256              * 32-Bit Memory Range Resource
257              * For this resource the size is static
258              */
259             SegmentSize = 20;
260             break;
261
262         case ACPI_RSTYPE_FIXED_MEM32:
263             /*
264              * 32-Bit Fixed Memory Resource
265              * For this resource the size is static
266              */
267             SegmentSize = 12;
268             break;
269
270         case ACPI_RSTYPE_ADDRESS16:
271             /*
272              * 16-Bit Address Resource
273              * The base size of this byte stream is 16. If a
274              * Resource Source string is not NULL, add 1 for
275              * the Index + the length of the null terminated
276              * string Resource Source + 1 for the null.
277              */
278             SegmentSize = 16;
279
280             if (LinkedList->Data.Address16.ResourceSource.StringPtr)
281             {
282                 SegmentSize += LinkedList->Data.Address16.ResourceSource.StringLength;
283                 SegmentSize++;
284             }
285             break;
286
287         case ACPI_RSTYPE_ADDRESS32:
288             /*
289              * 32-Bit Address Resource
290              * The base size of this byte stream is 26. If a Resource
291              * Source string is not NULL, add 1 for the Index + the
292              * length of the null terminated string Resource Source +
293              * 1 for the null.
294              */
295             SegmentSize = 26;
296
297             if (LinkedList->Data.Address32.ResourceSource.StringPtr)
298             {
299                 SegmentSize += LinkedList->Data.Address32.ResourceSource.StringLength;
300                 SegmentSize++;
301             }
302             break;
303
304         case ACPI_RSTYPE_ADDRESS64:
305             /*
306              * 64-Bit Address Resource
307              * The base size of this byte stream is 46. If a Resource
308              * Source string is not NULL, add 1 for the Index + the
309              * length of the null terminated string Resource Source +
310              * 1 for the null.
311              */
312             SegmentSize = 46;
313
314             if (LinkedList->Data.Address64.ResourceSource.StringPtr)
315             {
316                 SegmentSize += LinkedList->Data.Address64.ResourceSource.StringLength;
317                 SegmentSize++;
318             }
319             break;
320
321         case ACPI_RSTYPE_EXT_IRQ:
322             /*
323              * Extended IRQ Resource
324              * The base size of this byte stream is 9. This is for an
325              * Interrupt table length of 1.  For each additional
326              * interrupt, add 4.
327              * If a Resource Source string is not NULL, add 1 for the
328              * Index + the length of the null terminated string
329              * Resource Source + 1 for the null.
330              */
331             SegmentSize = 9 +
332                 (((ACPI_SIZE) LinkedList->Data.ExtendedIrq.NumberOfInterrupts - 1) * 4);
333
334             if (ExIrq && ExIrq->ResourceSource.StringPtr)
335             {
336                 SegmentSize += LinkedList->Data.ExtendedIrq.ResourceSource.StringLength;
337                 SegmentSize++;
338             }
339             break;
340
341         default:
342             /*
343              * If we get here, everything is out of sync,
344              * so exit with an error
345              */
346             return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
347
348         } /* switch (LinkedList->Id) */
349
350         /*
351          * Update the total
352          */
353         ByteStreamSizeNeeded += SegmentSize;
354
355         /*
356          * Point to the next object
357          */
358         LinkedList = ACPI_PTR_ADD (ACPI_RESOURCE,
359                         LinkedList, LinkedList->Length);
360     }
361
362     /*
363      * This is the data the caller needs
364      */
365     *SizeNeeded = ByteStreamSizeNeeded;
366     return_ACPI_STATUS (AE_OK);
367 }
368
369
370 /*******************************************************************************
371  *
372  * FUNCTION:    AcpiRsGetListLength
373  *
374  * PARAMETERS:  ByteStreamBuffer        - Pointer to the resource byte stream
375  *              ByteStreamBufferLength  - Size of ByteStreamBuffer
376  *              SizeNeeded              - UINT32 pointer of the size buffer
377  *                                        needed to properly return the
378  *                                        parsed data
379  *
380  * RETURN:      Status
381  *
382  * DESCRIPTION: Takes the resource byte stream and parses it once, calculating
383  *              the size buffer needed to hold the linked list that conveys
384  *              the resource data.
385  *
386  ******************************************************************************/
387
388 ACPI_STATUS
389 AcpiRsGetListLength (
390     UINT8                   *ByteStreamBuffer,
391     UINT32                  ByteStreamBufferLength,
392     ACPI_SIZE               *SizeNeeded)
393 {
394     UINT32                  BufferSize = 0;
395     UINT32                  BytesParsed = 0;
396     UINT8                   NumberOfInterrupts = 0;
397     UINT8                   NumberOfChannels = 0;
398     UINT8                   ResourceType;
399     UINT32                  StructureSize;
400     UINT32                  BytesConsumed;
401     UINT8                   *Buffer;
402     UINT8                   Temp8;
403     UINT16                  Temp16;
404     UINT8                   Index;
405     UINT8                   AdditionalBytes;
406
407
408     ACPI_FUNCTION_TRACE ("RsGetListLength");
409
410
411     while (BytesParsed < ByteStreamBufferLength)
412     {
413         /*
414          * The next byte in the stream is the resource type
415          */
416         ResourceType = AcpiRsGetResourceType (*ByteStreamBuffer);
417
418         switch (ResourceType)
419         {
420         case ACPI_RDESC_TYPE_MEMORY_24:
421             /*
422              * 24-Bit Memory Resource
423              */
424             BytesConsumed = 12;
425
426             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_MEM24);
427             break;
428
429
430         case ACPI_RDESC_TYPE_LARGE_VENDOR:
431             /*
432              * Vendor Defined Resource
433              */
434             Buffer = ByteStreamBuffer;
435             ++Buffer;
436
437             ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
438             BytesConsumed = Temp16 + 3;
439
440             /*
441              * Ensure a 32-bit boundary for the structure
442              */
443             Temp16 = (UINT16) ACPI_ROUND_UP_TO_32BITS (Temp16);
444
445             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_VENDOR) +
446                                 (Temp16 * sizeof (UINT8));
447             break;
448
449
450         case ACPI_RDESC_TYPE_MEMORY_32:
451             /*
452              * 32-Bit Memory Range Resource
453              */
454
455             BytesConsumed = 20;
456
457             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_MEM32);
458             break;
459
460
461         case ACPI_RDESC_TYPE_FIXED_MEMORY_32:
462             /*
463              * 32-Bit Fixed Memory Resource
464              */
465             BytesConsumed = 12;
466
467             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_FIXED_MEM32);
468             break;
469
470
471         case ACPI_RDESC_TYPE_QWORD_ADDRESS_SPACE:
472             /*
473              * 64-Bit Address Resource
474              */
475             Buffer = ByteStreamBuffer;
476
477             ++Buffer;
478             ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
479
480             BytesConsumed = Temp16 + 3;
481
482             /*
483              * Resource Source Index and Resource Source are
484              * optional elements.  Check the length of the
485              * Bytestream.  If it is greater than 43, that
486              * means that an Index exists and is followed by
487              * a null termininated string.  Therefore, set
488              * the temp variable to the length minus the minimum
489              * byte stream length plus the byte for the Index to
490              * determine the size of the NULL terminiated string.
491              */
492             if (43 < Temp16)
493             {
494                 Temp8 = (UINT8) (Temp16 - 44);
495             }
496             else
497             {
498                 Temp8 = 0;
499             }
500
501             /*
502              * Ensure a 64-bit boundary for the structure
503              */
504             Temp8 = (UINT8) ACPI_ROUND_UP_TO_64BITS (Temp8);
505
506             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS64) +
507                                 (Temp8 * sizeof (UINT8));
508             break;
509
510
511         case ACPI_RDESC_TYPE_DWORD_ADDRESS_SPACE:
512             /*
513              * 32-Bit Address Resource
514              */
515             Buffer = ByteStreamBuffer;
516
517             ++Buffer;
518             ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
519
520             BytesConsumed = Temp16 + 3;
521
522             /*
523              * Resource Source Index and Resource Source are
524              * optional elements.  Check the length of the
525              * Bytestream.  If it is greater than 23, that
526              * means that an Index exists and is followed by
527              * a null termininated string.  Therefore, set
528              * the temp variable to the length minus the minimum
529              * byte stream length plus the byte for the Index to
530              * determine the size of the NULL terminiated string.
531              */
532             if (23 < Temp16)
533             {
534                 Temp8 = (UINT8) (Temp16 - 24);
535             }
536             else
537             {
538                 Temp8 = 0;
539             }
540
541             /*
542              * Ensure a 32-bit boundary for the structure
543              */
544             Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8);
545
546             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS32) +
547                                 (Temp8 * sizeof (UINT8));
548             break;
549
550
551         case ACPI_RDESC_TYPE_WORD_ADDRESS_SPACE:
552             /*
553              * 16-Bit Address Resource
554              */
555             Buffer = ByteStreamBuffer;
556
557             ++Buffer;
558             ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
559
560             BytesConsumed = Temp16 + 3;
561
562             /*
563              * Resource Source Index and Resource Source are
564              * optional elements.  Check the length of the
565              * Bytestream.  If it is greater than 13, that
566              * means that an Index exists and is followed by
567              * a null termininated string.  Therefore, set
568              * the temp variable to the length minus the minimum
569              * byte stream length plus the byte for the Index to
570              * determine the size of the NULL terminiated string.
571              */
572             if (13 < Temp16)
573             {
574                 Temp8 = (UINT8) (Temp16 - 14);
575             }
576             else
577             {
578                 Temp8 = 0;
579             }
580
581             /*
582              * Ensure a 32-bit boundary for the structure
583              */
584             Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8);
585
586             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_ADDRESS16) +
587                                 (Temp8 * sizeof (UINT8));
588             break;
589
590
591         case ACPI_RDESC_TYPE_EXTENDED_XRUPT:
592             /*
593              * Extended IRQ
594              */
595             Buffer = ByteStreamBuffer;
596
597             ++Buffer;
598             ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
599
600             BytesConsumed = Temp16 + 3;
601
602             /*
603              * Point past the length field and the
604              * Interrupt vector flags to save off the
605              * Interrupt table length to the Temp8 variable.
606              */
607             Buffer += 3;
608             Temp8 = *Buffer;
609
610             /*
611              * To compensate for multiple interrupt numbers, add 4 bytes for
612              * each additional interrupts greater than 1
613              */
614             AdditionalBytes = (UINT8) ((Temp8 - 1) * 4);
615
616             /*
617              * Resource Source Index and Resource Source are
618              * optional elements.  Check the length of the
619              * Bytestream.  If it is greater than 9, that
620              * means that an Index exists and is followed by
621              * a null termininated string.  Therefore, set
622              * the temp variable to the length minus the minimum
623              * byte stream length plus the byte for the Index to
624              * determine the size of the NULL terminiated string.
625              */
626             if (9 + AdditionalBytes < Temp16)
627             {
628                 Temp8 = (UINT8) (Temp16 - (9 + AdditionalBytes));
629             }
630             else
631             {
632                 Temp8 = 0;
633             }
634
635             /*
636              * Ensure a 32-bit boundary for the structure
637              */
638             Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8);
639
640             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_EXT_IRQ) +
641                                 (AdditionalBytes * sizeof (UINT8)) +
642                                 (Temp8 * sizeof (UINT8));
643             break;
644
645
646         case ACPI_RDESC_TYPE_IRQ_FORMAT:
647             /*
648              * IRQ Resource.
649              * Determine if it there are two or three trailing bytes
650              */
651             Buffer = ByteStreamBuffer;
652             Temp8 = *Buffer;
653
654             if(Temp8 & 0x01)
655             {
656                 BytesConsumed = 4;
657             }
658             else
659             {
660                 BytesConsumed = 3;
661             }
662
663             /*
664              * Point past the descriptor
665              */
666             ++Buffer;
667
668             /*
669              * Look at the number of bits set
670              */
671             ACPI_MOVE_UNALIGNED16_TO_16 (&Temp16, Buffer);
672
673             for (Index = 0; Index < 16; Index++)
674             {
675                 if (Temp16 & 0x1)
676                 {
677                     ++NumberOfInterrupts;
678                 }
679
680                 Temp16 >>= 1;
681             }
682
683             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IO) +
684                                 (NumberOfInterrupts * sizeof (UINT32));
685             break;
686
687
688         case ACPI_RDESC_TYPE_DMA_FORMAT:
689             /*
690              * DMA Resource
691              */
692             Buffer = ByteStreamBuffer;
693             BytesConsumed = 3;
694
695             /*
696              * Point past the descriptor
697              */
698             ++Buffer;
699
700             /*
701              * Look at the number of bits set
702              */
703             Temp8 = *Buffer;
704
705             for(Index = 0; Index < 8; Index++)
706             {
707                 if(Temp8 & 0x1)
708                 {
709                     ++NumberOfChannels;
710                 }
711
712                 Temp8 >>= 1;
713             }
714
715             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_DMA) +
716                                 (NumberOfChannels * sizeof (UINT32));
717             break;
718
719
720         case ACPI_RDESC_TYPE_START_DEPENDENT:
721             /*
722              * Start Dependent Functions Resource
723              * Determine if it there are two or three trailing bytes
724              */
725             Buffer = ByteStreamBuffer;
726             Temp8 = *Buffer;
727
728             if(Temp8 & 0x01)
729             {
730                 BytesConsumed = 2;
731             }
732             else
733             {
734                 BytesConsumed = 1;
735             }
736
737             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_START_DPF);
738             break;
739
740
741         case ACPI_RDESC_TYPE_END_DEPENDENT:
742             /*
743              * End Dependent Functions Resource
744              */
745             BytesConsumed = 1;
746             StructureSize = ACPI_RESOURCE_LENGTH;
747             break;
748
749
750         case ACPI_RDESC_TYPE_IO_PORT:
751             /*
752              * IO Port Resource
753              */
754             BytesConsumed = 8;
755             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_IO);
756             break;
757
758
759         case ACPI_RDESC_TYPE_FIXED_IO_PORT:
760             /*
761              * Fixed IO Port Resource
762              */
763             BytesConsumed = 4;
764             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_FIXED_IO);
765             break;
766
767
768         case ACPI_RDESC_TYPE_SMALL_VENDOR:
769             /*
770              * Vendor Specific Resource
771              */
772             Buffer = ByteStreamBuffer;
773
774             Temp8 = *Buffer;
775             Temp8 = (UINT8) (Temp8 & 0x7);
776             BytesConsumed = Temp8 + 1;
777
778             /*
779              * Ensure a 32-bit boundary for the structure
780              */
781             Temp8 = (UINT8) ACPI_ROUND_UP_TO_32BITS (Temp8);
782             StructureSize = ACPI_SIZEOF_RESOURCE (ACPI_RESOURCE_VENDOR) +
783                                 (Temp8 * sizeof (UINT8));
784             break;
785
786
787         case ACPI_RDESC_TYPE_END_TAG:
788             /*
789              * End Tag
790              */
791             BytesConsumed = 2;
792             StructureSize = ACPI_RESOURCE_LENGTH;
793             ByteStreamBufferLength = BytesParsed;
794             break;
795
796
797         default:
798             /*
799              * If we get here, everything is out of sync,
800              *  so exit with an error
801              */
802             return_ACPI_STATUS (AE_AML_INVALID_RESOURCE_TYPE);
803         }
804
805         /*
806          * Update the return value and counter
807          */
808         BufferSize += ACPI_ALIGN_RESOURCE_SIZE(StructureSize);
809         BytesParsed += BytesConsumed;
810
811         /*
812          * Set the byte stream to point to the next resource
813          */
814         ByteStreamBuffer += BytesConsumed;
815     }
816
817     /*
818      * This is the data the caller needs
819      */
820     *SizeNeeded = BufferSize;
821     return_ACPI_STATUS (AE_OK);
822 }
823
824
825 /*******************************************************************************
826  *
827  * FUNCTION:    AcpiRsGetPciRoutingTableLength
828  *
829  * PARAMETERS:  PackageObject           - Pointer to the package object
830  *              BufferSizeNeeded        - UINT32 pointer of the size buffer
831  *                                        needed to properly return the
832  *                                        parsed data
833  *
834  * RETURN:      Status
835  *
836  * DESCRIPTION: Given a package representing a PCI routing table, this
837  *              calculates the size of the corresponding linked list of
838  *              descriptions.
839  *
840  ******************************************************************************/
841
842 ACPI_STATUS
843 AcpiRsGetPciRoutingTableLength (
844     ACPI_OPERAND_OBJECT     *PackageObject,
845     ACPI_SIZE               *BufferSizeNeeded)
846 {
847     UINT32                  NumberOfElements;
848     ACPI_SIZE               TempSizeNeeded = 0;
849     ACPI_OPERAND_OBJECT     **TopObjectList;
850     UINT32                  Index;
851     ACPI_OPERAND_OBJECT     *PackageElement;
852     ACPI_OPERAND_OBJECT     **SubObjectList;
853     BOOLEAN                 NameFound;
854     UINT32                  TableIndex;
855
856
857     ACPI_FUNCTION_TRACE ("RsGetPciRoutingTableLength");
858
859
860     NumberOfElements = PackageObject->Package.Count;
861
862     /*
863      * Calculate the size of the return buffer.
864      * The base size is the number of elements * the sizes of the
865      * structures.  Additional space for the strings is added below.
866      * The minus one is to subtract the size of the UINT8 Source[1]
867      * member because it is added below.
868      *
869      * But each PRT_ENTRY structure has a pointer to a string and
870      * the size of that string must be found.
871      */
872     TopObjectList = PackageObject->Package.Elements;
873
874     for (Index = 0; Index < NumberOfElements; Index++)
875     {
876         /*
877          * Dereference the sub-package
878          */
879         PackageElement = *TopObjectList;
880
881         /*
882          * The SubObjectList will now point to an array of the
883          * four IRQ elements: Address, Pin, Source and SourceIndex
884          */
885         SubObjectList = PackageElement->Package.Elements;
886
887         /*
888          * Scan the IrqTableElements for the Source Name String
889          */
890         NameFound = FALSE;
891
892         for (TableIndex = 0; TableIndex < 4 && !NameFound; TableIndex++)
893         {
894             if ((ACPI_TYPE_STRING == ACPI_GET_OBJECT_TYPE (*SubObjectList)) ||
895                 ((ACPI_TYPE_LOCAL_REFERENCE == ACPI_GET_OBJECT_TYPE (*SubObjectList)) &&
896                     ((*SubObjectList)->Reference.Opcode == AML_INT_NAMEPATH_OP)))
897             {
898                 NameFound = TRUE;
899             }
900             else
901             {
902                 /*
903                  * Look at the next element
904                  */
905                 SubObjectList++;
906             }
907         }
908
909         TempSizeNeeded += (sizeof (ACPI_PCI_ROUTING_TABLE) - 4);
910
911         /*
912          * Was a String type found?
913          */
914         if (NameFound)
915         {
916             if (ACPI_GET_OBJECT_TYPE (*SubObjectList) == ACPI_TYPE_STRING)
917             {
918                 /*
919                  * The length String.Length field does not include the
920                  * terminating NULL, add 1
921                  */
922                 TempSizeNeeded += ((ACPI_SIZE) (*SubObjectList)->String.Length + 1);
923             }
924             else
925             {
926                 TempSizeNeeded += AcpiNsGetPathnameLength (
927                                     (*SubObjectList)->Reference.Node);
928             }
929         }
930         else
931         {
932             /*
933              * If no name was found, then this is a NULL, which is
934              * translated as a UINT32 zero.
935              */
936             TempSizeNeeded += sizeof (UINT32);
937         }
938
939         /* Round up the size since each element must be aligned */
940
941         TempSizeNeeded = ACPI_ROUND_UP_TO_64BITS (TempSizeNeeded);
942
943         /*
944          * Point to the next ACPI_OPERAND_OBJECT
945          */
946         TopObjectList++;
947     }
948
949     /*
950      * Adding an extra element to the end of the list, essentially a NULL terminator
951      */
952     *BufferSizeNeeded = TempSizeNeeded + sizeof (ACPI_PCI_ROUTING_TABLE);
953     return_ACPI_STATUS (AE_OK);
954 }