]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/contrib/dev/acpica/compiler/dtutils.c
MFC r272444 (by jkim):
[FreeBSD/stable/10.git] / sys / contrib / dev / acpica / compiler / dtutils.c
1 /******************************************************************************
2  *
3  * Module Name: dtutils.c - Utility routines for the data table compiler
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2015, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44 #include <contrib/dev/acpica/compiler/aslcompiler.h>
45 #include <contrib/dev/acpica/compiler/dtcompiler.h>
46 #include <contrib/dev/acpica/include/actables.h>
47
48 #define _COMPONENT          DT_COMPILER
49         ACPI_MODULE_NAME    ("dtutils")
50
51 /* Local prototypes */
52
53 static void
54 DtSum (
55     DT_SUBTABLE             *Subtable,
56     void                    *Context,
57     void                    *ReturnValue);
58
59
60 /******************************************************************************
61  *
62  * FUNCTION:    DtError
63  *
64  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
65  *              MessageId           - Index into global message buffer
66  *              Op                  - Parse node where error happened
67  *              ExtraMessage        - additional error message
68  *
69  * RETURN:      None
70  *
71  * DESCRIPTION: Common error interface for data table compiler
72  *
73  *****************************************************************************/
74
75 void
76 DtError (
77     UINT8                   Level,
78     UINT16                  MessageId,
79     DT_FIELD                *FieldObject,
80     char                    *ExtraMessage)
81 {
82
83     /* Check if user wants to ignore this exception */
84
85     if (AslIsExceptionDisabled (Level, MessageId))
86     {
87         return;
88     }
89
90     if (FieldObject)
91     {
92         AslCommonError (Level, MessageId,
93             FieldObject->Line,
94             FieldObject->Line,
95             FieldObject->ByteOffset,
96             FieldObject->Column,
97             Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage);
98     }
99     else
100     {
101         AslCommonError (Level, MessageId, 0,
102             0, 0, 0, 0, ExtraMessage);
103     }
104 }
105
106
107 /******************************************************************************
108  *
109  * FUNCTION:    DtNameError
110  *
111  * PARAMETERS:  Level               - Seriousness (Warning/error, etc.)
112  *              MessageId           - Index into global message buffer
113  *              Op                  - Parse node where error happened
114  *              ExtraMessage        - additional error message
115  *
116  * RETURN:      None
117  *
118  * DESCRIPTION: Error interface for named objects
119  *
120  *****************************************************************************/
121
122 void
123 DtNameError (
124     UINT8                   Level,
125     UINT16                  MessageId,
126     DT_FIELD                *FieldObject,
127     char                    *ExtraMessage)
128 {
129
130     switch (Level)
131     {
132     case ASL_WARNING2:
133     case ASL_WARNING3:
134
135         if (Gbl_WarningLevel < Level)
136         {
137             return;
138         }
139         break;
140
141     default:
142
143         break;
144     }
145
146     if (FieldObject)
147     {
148         AslCommonError (Level, MessageId,
149             FieldObject->Line,
150             FieldObject->Line,
151             FieldObject->ByteOffset,
152             FieldObject->NameColumn,
153             Gbl_Files[ASL_FILE_INPUT].Filename, ExtraMessage);
154     }
155     else
156     {
157         AslCommonError (Level, MessageId, 0,
158             0, 0, 0, 0, ExtraMessage);
159     }
160 }
161
162
163 /*******************************************************************************
164  *
165  * FUNCTION:    DtFatal
166  *
167  * PARAMETERS:  None
168  *
169  * RETURN:      None
170  *
171  * DESCRIPTION: Dump the error log and abort the compiler. Used for serious
172  *              compile or I/O errors
173  *
174  ******************************************************************************/
175
176 void
177 DtFatal (
178     UINT16                  MessageId,
179     DT_FIELD                *FieldObject,
180     char                    *ExtraMessage)
181 {
182
183     DtError (ASL_ERROR, MessageId, FieldObject, ExtraMessage);
184
185 /*
186  * TBD: remove this entire function, DtFatal
187  *
188  * We cannot abort the compiler on error, because we may be compiling a
189  * list of files. We must move on to the next file.
190  */
191 #ifdef __OBSOLETE
192     CmCleanupAndExit ();
193     exit (1);
194 #endif
195 }
196
197
198 /******************************************************************************
199  *
200  * FUNCTION:    DtStrtoul64
201  *
202  * PARAMETERS:  String              - Null terminated string
203  *              ReturnInteger       - Where the converted integer is returned
204  *
205  * RETURN:      Status
206  *
207  * DESCRIPTION: Simple conversion of a string hex integer constant to unsigned
208  *              value. Assumes no leading "0x" for the constant.
209  *
210  * Portability note: The reason this function exists is because a 64-bit
211  * sscanf is not available in all environments.
212  *
213  *****************************************************************************/
214
215 ACPI_STATUS
216 DtStrtoul64 (
217     char                    *String,
218     UINT64                  *ReturnInteger)
219 {
220     char                    *ThisChar = String;
221     UINT32                  ThisDigit;
222     UINT64                  ReturnValue = 0;
223     int                     DigitCount = 0;
224
225
226     /* Skip over any white space in the buffer */
227
228     while ((*ThisChar == ' ') || (*ThisChar == '\t'))
229     {
230         ThisChar++;
231     }
232
233     /* Skip leading zeros */
234
235     while ((*ThisChar) == '0')
236     {
237         ThisChar++;
238     }
239
240     /* Convert character-by-character */
241
242     while (*ThisChar)
243     {
244         if (ACPI_IS_DIGIT (*ThisChar))
245         {
246             /* Convert ASCII 0-9 to Decimal value */
247
248             ThisDigit = ((UINT8) *ThisChar) - '0';
249         }
250         else /* Letter */
251         {
252             ThisDigit = (UINT32) ACPI_TOUPPER (*ThisChar);
253             if (!ACPI_IS_XDIGIT ((char) ThisDigit))
254             {
255                 /* Not A-F */
256
257                 return (AE_BAD_CHARACTER);
258             }
259
260             /* Convert ASCII Hex char (A-F) to value */
261
262             ThisDigit = (ThisDigit - 'A') + 10;
263         }
264
265         /* Insert the 4-bit hex digit */
266
267         ReturnValue <<= 4;
268         ReturnValue += ThisDigit;
269
270         ThisChar++;
271         DigitCount++;
272         if (DigitCount > 16)
273         {
274             /* Value is too large (> 64 bits/8 bytes/16 hex digits) */
275
276             return (AE_LIMIT);
277         }
278     }
279
280     *ReturnInteger = ReturnValue;
281     return (AE_OK);
282 }
283
284
285 /******************************************************************************
286  *
287  * FUNCTION:    DtGetFieldValue
288  *
289  * PARAMETERS:  Field               - Current field list pointer
290  *
291  * RETURN:      Field value
292  *
293  * DESCRIPTION: Get field value
294  *
295  *****************************************************************************/
296
297 char *
298 DtGetFieldValue (
299     DT_FIELD                *Field)
300 {
301     if (!Field)
302     {
303         return (NULL);
304     }
305
306     return (Field->Value);
307 }
308
309
310 /******************************************************************************
311  *
312  * FUNCTION:    DtGetFieldType
313  *
314  * PARAMETERS:  Info                - Data table info
315  *
316  * RETURN:      Field type
317  *
318  * DESCRIPTION: Get field type
319  *
320  *****************************************************************************/
321
322 UINT8
323 DtGetFieldType (
324     ACPI_DMTABLE_INFO       *Info)
325 {
326     UINT8                   Type;
327
328
329     /* DT_FLAG means that this is the start of a block of flag bits */
330     /* TBD - we can make these a separate opcode later */
331
332     if (Info->Flags & DT_FLAG)
333     {
334         return (DT_FIELD_TYPE_FLAGS_INTEGER);
335     }
336
337     /* Type is based upon the opcode for this field in the info table */
338
339     switch (Info->Opcode)
340     {
341     case ACPI_DMT_FLAG0:
342     case ACPI_DMT_FLAG1:
343     case ACPI_DMT_FLAG2:
344     case ACPI_DMT_FLAG3:
345     case ACPI_DMT_FLAG4:
346     case ACPI_DMT_FLAG5:
347     case ACPI_DMT_FLAG6:
348     case ACPI_DMT_FLAG7:
349     case ACPI_DMT_FLAGS0:
350     case ACPI_DMT_FLAGS1:
351     case ACPI_DMT_FLAGS2:
352     case ACPI_DMT_FLAGS4:
353
354         Type = DT_FIELD_TYPE_FLAG;
355         break;
356
357     case ACPI_DMT_NAME4:
358     case ACPI_DMT_SIG:
359     case ACPI_DMT_NAME6:
360     case ACPI_DMT_NAME8:
361     case ACPI_DMT_STRING:
362
363         Type = DT_FIELD_TYPE_STRING;
364         break;
365
366     case ACPI_DMT_BUFFER:
367     case ACPI_DMT_BUF7:
368     case ACPI_DMT_BUF10:
369     case ACPI_DMT_BUF16:
370     case ACPI_DMT_BUF128:
371     case ACPI_DMT_PCI_PATH:
372
373         Type = DT_FIELD_TYPE_BUFFER;
374         break;
375
376     case ACPI_DMT_GAS:
377     case ACPI_DMT_HESTNTFY:
378
379         Type = DT_FIELD_TYPE_INLINE_SUBTABLE;
380         break;
381
382     case ACPI_DMT_UNICODE:
383
384         Type = DT_FIELD_TYPE_UNICODE;
385         break;
386
387     case ACPI_DMT_UUID:
388
389         Type = DT_FIELD_TYPE_UUID;
390         break;
391
392     case ACPI_DMT_DEVICE_PATH:
393
394         Type = DT_FIELD_TYPE_DEVICE_PATH;
395         break;
396
397     case ACPI_DMT_LABEL:
398
399         Type = DT_FIELD_TYPE_LABEL;
400         break;
401
402     default:
403
404         Type = DT_FIELD_TYPE_INTEGER;
405         break;
406     }
407
408     return (Type);
409 }
410
411
412 /******************************************************************************
413  *
414  * FUNCTION:    DtGetBufferLength
415  *
416  * PARAMETERS:  Buffer              - List of integers,
417  *                                    for example "10 3A 4F 2E"
418  *
419  * RETURN:      Count of integer
420  *
421  * DESCRIPTION: Get length of bytes needed to store the integers
422  *
423  *****************************************************************************/
424
425 UINT32
426 DtGetBufferLength (
427     char                    *Buffer)
428 {
429     UINT32                  ByteLength = 0;
430
431
432     while (*Buffer)
433     {
434         if (*Buffer == ' ')
435         {
436             ByteLength++;
437
438             while (*Buffer == ' ')
439             {
440                 Buffer++;
441             }
442         }
443
444         Buffer++;
445     }
446
447     return (++ByteLength);
448 }
449
450
451 /******************************************************************************
452  *
453  * FUNCTION:    DtGetFieldLength
454  *
455  * PARAMETERS:  Field               - Current field
456  *              Info                - Data table info
457  *
458  * RETURN:      Field length
459  *
460  * DESCRIPTION: Get length of bytes needed to compile the field
461  *
462  * Note: This function must remain in sync with AcpiDmDumpTable.
463  *
464  *****************************************************************************/
465
466 UINT32
467 DtGetFieldLength (
468     DT_FIELD                *Field,
469     ACPI_DMTABLE_INFO       *Info)
470 {
471     UINT32                  ByteLength = 0;
472     char                    *Value;
473
474
475     /* Length is based upon the opcode for this field in the info table */
476
477     switch (Info->Opcode)
478     {
479     case ACPI_DMT_FLAG0:
480     case ACPI_DMT_FLAG1:
481     case ACPI_DMT_FLAG2:
482     case ACPI_DMT_FLAG3:
483     case ACPI_DMT_FLAG4:
484     case ACPI_DMT_FLAG5:
485     case ACPI_DMT_FLAG6:
486     case ACPI_DMT_FLAG7:
487     case ACPI_DMT_FLAGS0:
488     case ACPI_DMT_FLAGS1:
489     case ACPI_DMT_FLAGS2:
490     case ACPI_DMT_FLAGS4:
491     case ACPI_DMT_LABEL:
492     case ACPI_DMT_EXTRA_TEXT:
493
494         ByteLength = 0;
495         break;
496
497     case ACPI_DMT_UINT8:
498     case ACPI_DMT_CHKSUM:
499     case ACPI_DMT_SPACEID:
500     case ACPI_DMT_ACCWIDTH:
501     case ACPI_DMT_IVRS:
502     case ACPI_DMT_GTDT:
503     case ACPI_DMT_MADT:
504     case ACPI_DMT_PCCT:
505     case ACPI_DMT_PMTT:
506     case ACPI_DMT_SRAT:
507     case ACPI_DMT_ASF:
508     case ACPI_DMT_HESTNTYP:
509     case ACPI_DMT_FADTPM:
510     case ACPI_DMT_EINJACT:
511     case ACPI_DMT_EINJINST:
512     case ACPI_DMT_ERSTACT:
513     case ACPI_DMT_ERSTINST:
514     case ACPI_DMT_DMAR_SCOPE:
515
516         ByteLength = 1;
517         break;
518
519     case ACPI_DMT_UINT16:
520     case ACPI_DMT_DMAR:
521     case ACPI_DMT_HEST:
522     case ACPI_DMT_PCI_PATH:
523
524         ByteLength = 2;
525         break;
526
527     case ACPI_DMT_UINT24:
528
529         ByteLength = 3;
530         break;
531
532     case ACPI_DMT_UINT32:
533     case ACPI_DMT_NAME4:
534     case ACPI_DMT_SLIC:
535     case ACPI_DMT_SIG:
536     case ACPI_DMT_LPIT:
537
538         ByteLength = 4;
539         break;
540
541     case ACPI_DMT_UINT40:
542
543         ByteLength = 5;
544         break;
545
546     case ACPI_DMT_UINT48:
547     case ACPI_DMT_NAME6:
548
549         ByteLength = 6;
550         break;
551
552     case ACPI_DMT_UINT56:
553     case ACPI_DMT_BUF7:
554
555         ByteLength = 7;
556         break;
557
558     case ACPI_DMT_UINT64:
559     case ACPI_DMT_NAME8:
560
561         ByteLength = 8;
562         break;
563
564     case ACPI_DMT_STRING:
565
566         Value = DtGetFieldValue (Field);
567         if (Value)
568         {
569             ByteLength = ACPI_STRLEN (Value) + 1;
570         }
571         else
572         {   /* At this point, this is a fatal error */
573
574             sprintf (MsgBuffer, "Expected \"%s\"", Info->Name);
575             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
576             return (0);
577         }
578         break;
579
580     case ACPI_DMT_GAS:
581
582         ByteLength = sizeof (ACPI_GENERIC_ADDRESS);
583         break;
584
585     case ACPI_DMT_HESTNTFY:
586
587         ByteLength = sizeof (ACPI_HEST_NOTIFY);
588         break;
589
590     case ACPI_DMT_BUFFER:
591
592         Value = DtGetFieldValue (Field);
593         if (Value)
594         {
595             ByteLength = DtGetBufferLength (Value);
596         }
597         else
598         {   /* At this point, this is a fatal error */
599
600             sprintf (MsgBuffer, "Expected \"%s\"", Info->Name);
601             DtFatal (ASL_MSG_COMPILER_INTERNAL, NULL, MsgBuffer);
602             return (0);
603         }
604         break;
605
606     case ACPI_DMT_BUF10:
607
608         ByteLength = 10;
609         break;
610
611     case ACPI_DMT_BUF16:
612     case ACPI_DMT_UUID:
613
614         ByteLength = 16;
615         break;
616
617     case ACPI_DMT_BUF128:
618
619         ByteLength = 128;
620         break;
621
622     case ACPI_DMT_UNICODE:
623
624         Value = DtGetFieldValue (Field);
625
626         /* TBD: error if Value is NULL? (as below?) */
627
628         ByteLength = (ACPI_STRLEN (Value) + 1) * sizeof(UINT16);
629         break;
630
631     default:
632
633         DtFatal (ASL_MSG_COMPILER_INTERNAL, Field, "Invalid table opcode");
634         return (0);
635     }
636
637     return (ByteLength);
638 }
639
640
641 /******************************************************************************
642  *
643  * FUNCTION:    DtSum
644  *
645  * PARAMETERS:  DT_WALK_CALLBACK:
646  *              Subtable            - Subtable
647  *              Context             - Unused
648  *              ReturnValue         - Store the checksum of subtable
649  *
650  * RETURN:      Status
651  *
652  * DESCRIPTION: Get the checksum of subtable
653  *
654  *****************************************************************************/
655
656 static void
657 DtSum (
658     DT_SUBTABLE             *Subtable,
659     void                    *Context,
660     void                    *ReturnValue)
661 {
662     UINT8                   Checksum;
663     UINT8                   *Sum = ReturnValue;
664
665
666     Checksum = AcpiTbChecksum (Subtable->Buffer, Subtable->Length);
667     *Sum = (UINT8) (*Sum + Checksum);
668 }
669
670
671 /******************************************************************************
672  *
673  * FUNCTION:    DtSetTableChecksum
674  *
675  * PARAMETERS:  ChecksumPointer     - Where to return the checksum
676  *
677  * RETURN:      None
678  *
679  * DESCRIPTION: Set checksum of the whole data table into the checksum field
680  *
681  *****************************************************************************/
682
683 void
684 DtSetTableChecksum (
685     UINT8                   *ChecksumPointer)
686 {
687     UINT8                   Checksum = 0;
688     UINT8                   OldSum;
689
690
691     DtWalkTableTree (Gbl_RootTable, DtSum, NULL, &Checksum);
692
693     OldSum = *ChecksumPointer;
694     Checksum = (UINT8) (Checksum - OldSum);
695
696     /* Compute the final checksum */
697
698     Checksum = (UINT8) (0 - Checksum);
699     *ChecksumPointer = Checksum;
700 }
701
702
703 /******************************************************************************
704  *
705  * FUNCTION:    DtSetTableLength
706  *
707  * PARAMETERS:  None
708  *
709  * RETURN:      None
710  *
711  * DESCRIPTION: Walk the subtables and set all the length fields
712  *
713  *****************************************************************************/
714
715 void
716 DtSetTableLength (
717     void)
718 {
719     DT_SUBTABLE             *ParentTable;
720     DT_SUBTABLE             *ChildTable;
721
722
723     ParentTable = Gbl_RootTable;
724     ChildTable = NULL;
725
726     if (!ParentTable)
727     {
728         return;
729     }
730
731     DtSetSubtableLength (ParentTable);
732
733     while (1)
734     {
735         ChildTable = DtGetNextSubtable (ParentTable, ChildTable);
736         if (ChildTable)
737         {
738             if (ChildTable->LengthField)
739             {
740                 DtSetSubtableLength (ChildTable);
741             }
742
743             if (ChildTable->Child)
744             {
745                 ParentTable = ChildTable;
746                 ChildTable = NULL;
747             }
748             else
749             {
750                 ParentTable->TotalLength += ChildTable->TotalLength;
751                 if (ParentTable->LengthField)
752                 {
753                     DtSetSubtableLength (ParentTable);
754                 }
755             }
756         }
757         else
758         {
759             ChildTable = ParentTable;
760
761             if (ChildTable == Gbl_RootTable)
762             {
763                 break;
764             }
765
766             ParentTable = DtGetParentSubtable (ParentTable);
767
768             ParentTable->TotalLength += ChildTable->TotalLength;
769             if (ParentTable->LengthField)
770             {
771                 DtSetSubtableLength (ParentTable);
772             }
773         }
774     }
775 }
776
777
778 /******************************************************************************
779  *
780  * FUNCTION:    DtWalkTableTree
781  *
782  * PARAMETERS:  StartTable          - Subtable in the tree where walking begins
783  *              UserFunction        - Called during the walk
784  *              Context             - Passed to user function
785  *              ReturnValue         - The return value of UserFunction
786  *
787  * RETURN:      None
788  *
789  * DESCRIPTION: Performs a depth-first walk of the subtable tree
790  *
791  *****************************************************************************/
792
793 void
794 DtWalkTableTree (
795     DT_SUBTABLE             *StartTable,
796     DT_WALK_CALLBACK        UserFunction,
797     void                    *Context,
798     void                    *ReturnValue)
799 {
800     DT_SUBTABLE             *ParentTable;
801     DT_SUBTABLE             *ChildTable;
802
803
804     ParentTable = StartTable;
805     ChildTable = NULL;
806
807     if (!ParentTable)
808     {
809         return;
810     }
811
812     UserFunction (ParentTable, Context, ReturnValue);
813
814     while (1)
815     {
816         ChildTable = DtGetNextSubtable (ParentTable, ChildTable);
817         if (ChildTable)
818         {
819             UserFunction (ChildTable, Context, ReturnValue);
820
821             if (ChildTable->Child)
822             {
823                 ParentTable = ChildTable;
824                 ChildTable = NULL;
825             }
826         }
827         else
828         {
829             ChildTable = ParentTable;
830             if (ChildTable == Gbl_RootTable)
831             {
832                 break;
833             }
834
835             ParentTable = DtGetParentSubtable (ParentTable);
836
837             if (ChildTable->Peer == StartTable)
838             {
839                 break;
840             }
841         }
842     }
843 }
844
845
846 /*******************************************************************************
847  *
848  * FUNCTION:    UtSubtableCacheCalloc
849  *
850  * PARAMETERS:  None
851  *
852  * RETURN:      Pointer to the buffer. Aborts on allocation failure
853  *
854  * DESCRIPTION: Allocate a subtable object buffer. Bypass the local
855  *              dynamic memory manager for performance reasons (This has a
856  *              major impact on the speed of the compiler.)
857  *
858  ******************************************************************************/
859
860 DT_SUBTABLE *
861 UtSubtableCacheCalloc (
862     void)
863 {
864     ASL_CACHE_INFO          *Cache;
865
866
867     if (Gbl_SubtableCacheNext >= Gbl_SubtableCacheLast)
868     {
869         /* Allocate a new buffer */
870
871         Cache = UtLocalCalloc (sizeof (Cache->Next) +
872             (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE));
873
874         /* Link new cache buffer to head of list */
875
876         Cache->Next = Gbl_SubtableCacheList;
877         Gbl_SubtableCacheList = Cache;
878
879         /* Setup cache management pointers */
880
881         Gbl_SubtableCacheNext = ACPI_CAST_PTR (DT_SUBTABLE, Cache->Buffer);
882         Gbl_SubtableCacheLast = Gbl_SubtableCacheNext + ASL_SUBTABLE_CACHE_SIZE;
883     }
884
885     Gbl_SubtableCount++;
886     return (Gbl_SubtableCacheNext++);
887 }
888
889
890 /*******************************************************************************
891  *
892  * FUNCTION:    UtFieldCacheCalloc
893  *
894  * PARAMETERS:  None
895  *
896  * RETURN:      Pointer to the buffer. Aborts on allocation failure
897  *
898  * DESCRIPTION: Allocate a field object buffer. Bypass the local
899  *              dynamic memory manager for performance reasons (This has a
900  *              major impact on the speed of the compiler.)
901  *
902  ******************************************************************************/
903
904 DT_FIELD *
905 UtFieldCacheCalloc (
906     void)
907 {
908     ASL_CACHE_INFO          *Cache;
909
910
911     if (Gbl_FieldCacheNext >= Gbl_FieldCacheLast)
912     {
913         /* Allocate a new buffer */
914
915         Cache = UtLocalCalloc (sizeof (Cache->Next) +
916             (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE));
917
918         /* Link new cache buffer to head of list */
919
920         Cache->Next = Gbl_FieldCacheList;
921         Gbl_FieldCacheList = Cache;
922
923         /* Setup cache management pointers */
924
925         Gbl_FieldCacheNext = ACPI_CAST_PTR (DT_FIELD, Cache->Buffer);
926         Gbl_FieldCacheLast = Gbl_FieldCacheNext + ASL_FIELD_CACHE_SIZE;
927     }
928
929     Gbl_FieldCount++;
930     return (Gbl_FieldCacheNext++);
931 }
932
933
934 /*******************************************************************************
935  *
936  * FUNCTION:    DtDeleteCaches
937  *
938  * PARAMETERS:  None
939  *
940  * RETURN:      None
941  *
942  * DESCRIPTION: Delete all local cache buffer blocks
943  *
944  ******************************************************************************/
945
946 void
947 DtDeleteCaches (
948     void)
949 {
950     UINT32                  BufferCount;
951     ASL_CACHE_INFO          *Next;
952
953
954     /* Field cache */
955
956     BufferCount = 0;
957     while (Gbl_FieldCacheList)
958     {
959         Next = Gbl_FieldCacheList->Next;
960         ACPI_FREE (Gbl_FieldCacheList);
961         Gbl_FieldCacheList = Next;
962         BufferCount++;
963     }
964
965     DbgPrint (ASL_DEBUG_OUTPUT,
966         "%u Fields, Buffer size: %u fields (%u bytes), %u Buffers\n",
967         Gbl_FieldCount, ASL_FIELD_CACHE_SIZE,
968         (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE), BufferCount);
969
970     Gbl_FieldCount = 0;
971     Gbl_FieldCacheNext = NULL;
972     Gbl_FieldCacheLast = NULL;
973
974     /* Subtable cache */
975
976     BufferCount = 0;
977     while (Gbl_SubtableCacheList)
978     {
979         Next = Gbl_SubtableCacheList->Next;
980         ACPI_FREE (Gbl_SubtableCacheList);
981         Gbl_SubtableCacheList = Next;
982         BufferCount++;
983     }
984
985     DbgPrint (ASL_DEBUG_OUTPUT,
986         "%u Subtables, Buffer size: %u subtables (%u bytes), %u Buffers\n",
987         Gbl_SubtableCount, ASL_SUBTABLE_CACHE_SIZE,
988         (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE), BufferCount);
989
990     Gbl_SubtableCount = 0;
991     Gbl_SubtableCacheNext = NULL;
992     Gbl_SubtableCacheLast = NULL;
993 }