aslcache.c revision 1.1.1.3
1/******************************************************************************
2 *
3 * Module Name: aslcache -- Local cache support for iASL
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2018, 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 "aslcompiler.h"
45
46/*
47 * Local caches. The caches are fully deleted after the compilation/disassembly
48 * of each individual input file. Thus, individual allocations from the cache
49 * memory do not need to be freed or even released back into the cache.
50 *
51 * See aslallocate.c for standard heap allocations.
52 */
53
54
55/*******************************************************************************
56 *
57 * FUNCTION:    UtLocalCacheCalloc
58 *
59 * PARAMETERS:  Length              - Size of buffer requested
60 *
61 * RETURN:      Pointer to the buffer. Aborts compiler on allocation failure
62 *
63 * DESCRIPTION: Allocate a string buffer. Bypass the local
64 *              dynamic memory manager for performance reasons (This has a
65 *              major impact on the speed of the compiler.)
66 *
67 ******************************************************************************/
68
69char *
70UtLocalCacheCalloc (
71    UINT32                  Length)
72{
73    char                    *Buffer;
74    ASL_CACHE_INFO          *Cache;
75    UINT32                  CacheSize = ASL_STRING_CACHE_SIZE;
76
77
78    if (Length > CacheSize)
79    {
80        CacheSize = Length;
81
82        if (AslGbl_StringCacheList)
83        {
84            Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
85
86            /* Link new cache buffer just following head of list */
87
88            Cache->Next = AslGbl_StringCacheList->Next;
89            AslGbl_StringCacheList->Next = Cache;
90
91            /* Leave cache management pointers alone as they pertain to head */
92
93            AslGbl_StringCount++;
94            AslGbl_StringSize += Length;
95
96            return (Cache->Buffer);
97        }
98    }
99
100    if ((AslGbl_StringCacheNext + Length) >= AslGbl_StringCacheLast)
101    {
102        /* Allocate a new buffer */
103
104        Cache = UtLocalCalloc (sizeof (Cache->Next) + CacheSize);
105
106        /* Link new cache buffer to head of list */
107
108        Cache->Next = AslGbl_StringCacheList;
109        AslGbl_StringCacheList = Cache;
110
111        /* Setup cache management pointers */
112
113        AslGbl_StringCacheNext = Cache->Buffer;
114        AslGbl_StringCacheLast = AslGbl_StringCacheNext + CacheSize;
115    }
116
117    AslGbl_StringCount++;
118    AslGbl_StringSize += Length;
119
120    Buffer = AslGbl_StringCacheNext;
121    AslGbl_StringCacheNext += Length;
122    return (Buffer);
123}
124
125
126/*******************************************************************************
127 *
128 * FUNCTION:    UtParseOpCacheCalloc
129 *
130 * PARAMETERS:  None
131 *
132 * RETURN:      New parse op. Aborts on allocation failure
133 *
134 * DESCRIPTION: Allocate a new parse op for the parse tree. Bypass the local
135 *              dynamic memory manager for performance reasons (This has a
136 *              major impact on the speed of the compiler.)
137 *
138 ******************************************************************************/
139
140ACPI_PARSE_OBJECT *
141UtParseOpCacheCalloc (
142    void)
143{
144    ASL_CACHE_INFO          *Cache;
145
146
147    if (AslGbl_ParseOpCacheNext >= AslGbl_ParseOpCacheLast)
148    {
149        /* Allocate a new buffer */
150
151        Cache = UtLocalCalloc (sizeof (Cache->Next) +
152            (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE));
153
154        /* Link new cache buffer to head of list */
155
156        Cache->Next = AslGbl_ParseOpCacheList;
157        AslGbl_ParseOpCacheList = Cache;
158
159        /* Setup cache management pointers */
160
161        AslGbl_ParseOpCacheNext = ACPI_CAST_PTR (ACPI_PARSE_OBJECT, Cache->Buffer);
162        AslGbl_ParseOpCacheLast = AslGbl_ParseOpCacheNext + ASL_PARSEOP_CACHE_SIZE;
163    }
164
165    AslGbl_ParseOpCount++;
166    return (AslGbl_ParseOpCacheNext++);
167}
168
169
170/*******************************************************************************
171 *
172 * FUNCTION:    UtSubtableCacheCalloc - Data Table compiler
173 *
174 * PARAMETERS:  None
175 *
176 * RETURN:      Pointer to the buffer. Aborts on allocation failure
177 *
178 * DESCRIPTION: Allocate a subtable object buffer. Bypass the local
179 *              dynamic memory manager for performance reasons (This has a
180 *              major impact on the speed of the compiler.)
181 *
182 ******************************************************************************/
183
184DT_SUBTABLE *
185UtSubtableCacheCalloc (
186    void)
187{
188    ASL_CACHE_INFO          *Cache;
189
190
191    if (AslGbl_SubtableCacheNext >= AslGbl_SubtableCacheLast)
192    {
193        /* Allocate a new buffer */
194
195        Cache = UtLocalCalloc (sizeof (Cache->Next) +
196            (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE));
197
198        /* Link new cache buffer to head of list */
199
200        Cache->Next = AslGbl_SubtableCacheList;
201        AslGbl_SubtableCacheList = Cache;
202
203        /* Setup cache management pointers */
204
205        AslGbl_SubtableCacheNext = ACPI_CAST_PTR (DT_SUBTABLE, Cache->Buffer);
206        AslGbl_SubtableCacheLast = AslGbl_SubtableCacheNext + ASL_SUBTABLE_CACHE_SIZE;
207    }
208
209    AslGbl_SubtableCount++;
210    return (AslGbl_SubtableCacheNext++);
211}
212
213
214/*******************************************************************************
215 *
216 * FUNCTION:    UtFieldCacheCalloc - Data Table compiler
217 *
218 * PARAMETERS:  None
219 *
220 * RETURN:      Pointer to the buffer. Aborts on allocation failure
221 *
222 * DESCRIPTION: Allocate a field object buffer. Bypass the local
223 *              dynamic memory manager for performance reasons (This has a
224 *              major impact on the speed of the compiler.)
225 *
226 ******************************************************************************/
227
228DT_FIELD *
229UtFieldCacheCalloc (
230    void)
231{
232    ASL_CACHE_INFO          *Cache;
233
234
235    if (AslGbl_FieldCacheNext >= AslGbl_FieldCacheLast)
236    {
237        /* Allocate a new buffer */
238
239        Cache = UtLocalCalloc (sizeof (Cache->Next) +
240            (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE));
241
242        /* Link new cache buffer to head of list */
243
244        Cache->Next = AslGbl_FieldCacheList;
245        AslGbl_FieldCacheList = Cache;
246
247        /* Setup cache management pointers */
248
249        AslGbl_FieldCacheNext = ACPI_CAST_PTR (DT_FIELD, Cache->Buffer);
250        AslGbl_FieldCacheLast =AslGbl_FieldCacheNext + ASL_FIELD_CACHE_SIZE;
251    }
252
253    AslGbl_FieldCount++;
254    return (AslGbl_FieldCacheNext++);
255}
256
257
258/*******************************************************************************
259 *
260 * FUNCTION:    UtDeleteLocalCaches
261 *
262 * PARAMETERS:  None
263 *
264 * RETURN:      None
265 *
266 * DESCRIPTION: Delete all local cache buffer blocks
267 *
268 ******************************************************************************/
269
270void
271UtDeleteLocalCaches (
272    void)
273{
274    UINT32                  BufferCount;
275    ASL_CACHE_INFO          *Next;
276
277
278    /*
279     * Generic cache, arbitrary size allocations
280     */
281    BufferCount = 0;
282    while (AslGbl_StringCacheList)
283    {
284        Next = AslGbl_StringCacheList->Next;
285        ACPI_FREE (AslGbl_StringCacheList);
286        AslGbl_StringCacheList = Next;
287        BufferCount++;
288    }
289
290    DbgPrint (ASL_DEBUG_OUTPUT,
291        "%u Strings (%u bytes), Buffer size: %u bytes, %u Buffers\n",
292        AslGbl_StringCount, AslGbl_StringSize, ASL_STRING_CACHE_SIZE, BufferCount);
293
294    /* Reset cache globals */
295
296    AslGbl_StringSize = 0;
297    AslGbl_StringCount = 0;
298    AslGbl_StringCacheNext = NULL;
299    AslGbl_StringCacheLast = NULL;
300
301    /*
302     * Parse Op cache
303     */
304    BufferCount = 0;
305    while (AslGbl_ParseOpCacheList)
306    {
307        Next = AslGbl_ParseOpCacheList->Next;
308        ACPI_FREE (AslGbl_ParseOpCacheList);
309        AslGbl_ParseOpCacheList = Next;
310        BufferCount++;
311    }
312
313    DbgPrint (ASL_DEBUG_OUTPUT,
314        "%u ParseOps, Buffer size: %u ops (%u bytes), %u Buffers\n",
315        AslGbl_ParseOpCount, ASL_PARSEOP_CACHE_SIZE,
316        (sizeof (ACPI_PARSE_OBJECT) * ASL_PARSEOP_CACHE_SIZE), BufferCount);
317
318    /* Reset cache globals */
319
320    AslGbl_ParseOpCount = 0;
321    AslGbl_ParseOpCacheNext = NULL;
322    AslGbl_ParseOpCacheLast = NULL;
323    AslGbl_ParseTreeRoot = NULL;
324
325    /*
326     * Table Compiler - Field cache
327     */
328    BufferCount = 0;
329    while (AslGbl_FieldCacheList)
330    {
331        Next = AslGbl_FieldCacheList->Next;
332        ACPI_FREE (AslGbl_FieldCacheList);
333        AslGbl_FieldCacheList = Next;
334        BufferCount++;
335    }
336
337    DbgPrint (ASL_DEBUG_OUTPUT,
338        "%u Fields, Buffer size: %u fields (%u bytes), %u Buffers\n",
339        AslGbl_FieldCount, ASL_FIELD_CACHE_SIZE,
340        (sizeof (DT_FIELD) * ASL_FIELD_CACHE_SIZE), BufferCount);
341
342    /* Reset cache globals */
343
344    AslGbl_FieldCount = 0;
345    AslGbl_FieldCacheNext = NULL;
346    AslGbl_FieldCacheLast = NULL;
347
348    /*
349     * Table Compiler - Subtable cache
350     */
351    BufferCount = 0;
352    while (AslGbl_SubtableCacheList)
353    {
354        Next = AslGbl_SubtableCacheList->Next;
355        ACPI_FREE (AslGbl_SubtableCacheList);
356        AslGbl_SubtableCacheList = Next;
357        BufferCount++;
358    }
359
360    DbgPrint (ASL_DEBUG_OUTPUT,
361        "%u Subtables, Buffer size: %u subtables (%u bytes), %u Buffers\n",
362        AslGbl_SubtableCount, ASL_SUBTABLE_CACHE_SIZE,
363        (sizeof (DT_SUBTABLE) * ASL_SUBTABLE_CACHE_SIZE), BufferCount);
364
365    /* Reset cache globals */
366
367    AslGbl_SubtableCount = 0;
368    AslGbl_SubtableCacheNext = NULL;
369    AslGbl_SubtableCacheLast = NULL;
370}
371