utalloc.c revision 84491
1/******************************************************************************
2 *
3 * Module Name: utalloc - local cache and memory allocation routines
4 *              $Revision: 103 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 __UTALLOC_C__
118
119#include "acpi.h"
120#include "acparser.h"
121#include "acinterp.h"
122#include "acnamesp.h"
123#include "acglobal.h"
124
125#define _COMPONENT          ACPI_UTILITIES
126        MODULE_NAME         ("utalloc")
127
128
129/******************************************************************************
130 *
131 * FUNCTION:    AcpiUtReleaseToCache
132 *
133 * PARAMETERS:  ListId              - Memory list/cache ID
134 *              Object              - The object to be released
135 *
136 * RETURN:      None
137 *
138 * DESCRIPTION: Release an object to the specified cache.  If cache is full,
139 *              the object is deleted.
140 *
141 ******************************************************************************/
142
143void
144AcpiUtReleaseToCache (
145    UINT32                  ListId,
146    void                    *Object)
147{
148    ACPI_MEMORY_LIST        *CacheInfo;
149
150
151    FUNCTION_ENTRY ();
152
153
154    /* If walk cache is full, just free this wallkstate object */
155
156    CacheInfo = &AcpiGbl_MemoryLists[ListId];
157    if (CacheInfo->CacheDepth >= CacheInfo->MaxCacheDepth)
158    {
159        ACPI_MEM_FREE (Object);
160        ACPI_MEM_TRACKING (CacheInfo->TotalFreed++);
161    }
162
163    /* Otherwise put this object back into the cache */
164
165    else
166    {
167        AcpiUtAcquireMutex (ACPI_MTX_CACHES);
168
169        /* Mark the object as cached */
170
171        MEMSET (Object, 0xCA, CacheInfo->ObjectSize);
172        ((ACPI_OPERAND_OBJECT *) Object)->Common.DataType = ACPI_CACHED_OBJECT;
173
174        /* Put the object at the head of the cache list */
175
176        * (char **) (((char *) Object) + CacheInfo->LinkOffset) = CacheInfo->ListHead;
177        CacheInfo->ListHead = Object;
178        CacheInfo->CacheDepth++;
179
180        AcpiUtReleaseMutex (ACPI_MTX_CACHES);
181    }
182}
183
184
185/******************************************************************************
186 *
187 * FUNCTION:    AcpiUtAcquireFromCache
188 *
189 * PARAMETERS:  ListId              - Memory list ID
190 *
191 * RETURN:      A requested object.  NULL if the object could not be
192 *              allocated.
193 *
194 * DESCRIPTION: Get an object from the specified cache.  If cache is empty,
195 *              the object is allocated.
196 *
197 ******************************************************************************/
198
199void *
200AcpiUtAcquireFromCache (
201    UINT32                  ListId)
202{
203    ACPI_MEMORY_LIST        *CacheInfo;
204    void                    *Object;
205
206
207    PROC_NAME ("UtAcquireFromCache");
208
209
210    CacheInfo = &AcpiGbl_MemoryLists[ListId];
211    AcpiUtAcquireMutex (ACPI_MTX_CACHES);
212    ACPI_MEM_TRACKING (CacheInfo->CacheRequests++);
213
214    /* Check the cache first */
215
216    if (CacheInfo->ListHead)
217    {
218        /* There is an object available, use it */
219
220        Object = CacheInfo->ListHead;
221        CacheInfo->ListHead = * (char **) (((char *) Object) + CacheInfo->LinkOffset);
222
223        ACPI_MEM_TRACKING (CacheInfo->CacheHits++);
224        CacheInfo->CacheDepth--;
225
226#ifdef ACPI_DBG_TRACK_ALLOCATIONS
227        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n",
228            Object, AcpiGbl_MemoryLists[ListId].ListName));
229#endif
230
231        AcpiUtReleaseMutex (ACPI_MTX_CACHES);
232
233        /* Clear (zero) the previously used Object */
234
235        MEMSET (Object, 0, CacheInfo->ObjectSize);
236    }
237
238    else
239    {
240        /* The cache is empty, create a new object */
241
242        /* Avoid deadlock with ACPI_MEM_CALLOCATE */
243
244        AcpiUtReleaseMutex (ACPI_MTX_CACHES);
245
246        Object = ACPI_MEM_CALLOCATE (CacheInfo->ObjectSize);
247        ACPI_MEM_TRACKING (CacheInfo->TotalAllocated++);
248    }
249
250    return (Object);
251}
252
253
254/******************************************************************************
255 *
256 * FUNCTION:    AcpiUtDeleteGenericCache
257 *
258 * PARAMETERS:  ListId          - Memory list ID
259 *
260 * RETURN:      None
261 *
262 * DESCRIPTION: Free all objects within the requested cache.
263 *
264 ******************************************************************************/
265
266void
267AcpiUtDeleteGenericCache (
268    UINT32                  ListId)
269{
270    ACPI_MEMORY_LIST        *CacheInfo;
271    char                    *Next;
272
273
274    FUNCTION_ENTRY ();
275
276
277    CacheInfo = &AcpiGbl_MemoryLists[ListId];
278    while (CacheInfo->ListHead)
279    {
280        /* Delete one cached state object */
281
282        Next = * (char **) (((char *) CacheInfo->ListHead) + CacheInfo->LinkOffset);
283        ACPI_MEM_FREE (CacheInfo->ListHead);
284
285        CacheInfo->ListHead = Next;
286        CacheInfo->CacheDepth--;
287    }
288}
289
290
291#ifdef ACPI_DBG_TRACK_ALLOCATIONS
292
293
294/*
295 * These procedures are used for tracking memory leaks in the subsystem, and
296 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
297 *
298 * Each memory allocation is tracked via a doubly linked list.  Each
299 * element contains the caller's component, module name, function name, and
300 * line number.  AcpiUtAllocate and AcpiUtCallocate call
301 * AcpiUtTrackAllocation to add an element to the list; deletion
302 * occurs in the body of AcpiUtFree.
303 */
304
305
306/*******************************************************************************
307 *
308 * FUNCTION:    AcpiUtFindAllocation
309 *
310 * PARAMETERS:  Address             - Address of allocated memory
311 *
312 * RETURN:      A list element if found; NULL otherwise.
313 *
314 * DESCRIPTION: Searches for an element in the global allocation tracking list.
315 *
316 ******************************************************************************/
317
318ACPI_DEBUG_MEM_BLOCK *
319AcpiUtFindAllocation (
320    UINT32                  ListId,
321    void                    *Address)
322{
323    ACPI_DEBUG_MEM_BLOCK    *Element;
324
325
326    FUNCTION_ENTRY ();
327
328
329    if (ListId > ACPI_MEM_LIST_MAX)
330    {
331        return (NULL);
332    }
333
334    Element = AcpiGbl_MemoryLists[ListId].ListHead;
335
336    /* Search for the address. */
337
338    while (Element)
339    {
340        if (Element == Address)
341        {
342            return (Element);
343        }
344
345        Element = Element->Next;
346    }
347
348    return (NULL);
349}
350
351
352/*******************************************************************************
353 *
354 * FUNCTION:    AcpiUtTrackAllocation
355 *
356 * PARAMETERS:  Address             - Address of allocated memory
357 *              Size                - Size of the allocation
358 *              AllocType           - MEM_MALLOC or MEM_CALLOC
359 *              Component           - Component type of caller
360 *              Module              - Source file name of caller
361 *              Line                - Line number of caller
362 *
363 * RETURN:      None.
364 *
365 * DESCRIPTION: Inserts an element into the global allocation tracking list.
366 *
367 ******************************************************************************/
368
369ACPI_STATUS
370AcpiUtTrackAllocation (
371    UINT32                  ListId,
372    ACPI_DEBUG_MEM_BLOCK    *Address,
373    UINT32                  Size,
374    UINT8                   AllocType,
375    UINT32                  Component,
376    NATIVE_CHAR             *Module,
377    UINT32                  Line)
378{
379    ACPI_MEMORY_LIST        *MemList;
380    ACPI_DEBUG_MEM_BLOCK    *Element;
381    ACPI_STATUS             Status = AE_OK;
382
383
384    FUNCTION_TRACE_PTR ("UtTrackAllocation", Address);
385
386
387    if (ListId > ACPI_MEM_LIST_MAX)
388    {
389        return_ACPI_STATUS (AE_BAD_PARAMETER);
390    }
391
392    MemList = &AcpiGbl_MemoryLists[ListId];
393    AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
394
395    /*
396     * Search list for this address to make sure it is not already on the list.
397     * This will catch several kinds of problems.
398     */
399
400    Element = AcpiUtFindAllocation (ListId, Address);
401    if (Element)
402    {
403        REPORT_ERROR (("UtTrackAllocation: Address already present in list! (%p)\n",
404            Address));
405
406        ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", Element, Address));
407
408        goto UnlockAndExit;
409    }
410
411    /* Fill in the instance data. */
412
413    Address->Size      = Size;
414    Address->AllocType = AllocType;
415    Address->Component = Component;
416    Address->Line      = Line;
417
418    STRNCPY (Address->Module, Module, MAX_MODULE_NAME);
419
420    /* Insert at list head */
421
422    if (MemList->ListHead)
423    {
424        ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Address;
425    }
426
427    Address->Next = MemList->ListHead;
428    Address->Previous = NULL;
429
430    MemList->ListHead = Address;
431
432
433UnlockAndExit:
434    AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
435    return_ACPI_STATUS (Status);
436}
437
438
439/*******************************************************************************
440 *
441 * FUNCTION:    AcpiUtRemoveAllocation
442 *
443 * PARAMETERS:  Address             - Address of allocated memory
444 *              Component           - Component type of caller
445 *              Module              - Source file name of caller
446 *              Line                - Line number of caller
447 *
448 * RETURN:
449 *
450 * DESCRIPTION: Deletes an element from the global allocation tracking list.
451 *
452 ******************************************************************************/
453
454ACPI_STATUS
455AcpiUtRemoveAllocation (
456    UINT32                  ListId,
457    ACPI_DEBUG_MEM_BLOCK    *Address,
458    UINT32                  Component,
459    NATIVE_CHAR             *Module,
460    UINT32                  Line)
461{
462    ACPI_MEMORY_LIST        *MemList;
463
464
465    FUNCTION_TRACE ("UtRemoveAllocation");
466
467
468    if (ListId > ACPI_MEM_LIST_MAX)
469    {
470        return_ACPI_STATUS (AE_BAD_PARAMETER);
471    }
472
473    MemList = &AcpiGbl_MemoryLists[ListId];
474    if (NULL == MemList->ListHead)
475    {
476        /* No allocations! */
477
478        _REPORT_ERROR (Module, Line, Component,
479                ("UtRemoveAllocation: Empty allocation list, nothing to free!\n"));
480
481        return_ACPI_STATUS (AE_OK);
482    }
483
484
485    AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
486
487    /* Unlink */
488
489    if (Address->Previous)
490    {
491        (Address->Previous)->Next = Address->Next;
492    }
493    else
494    {
495        MemList->ListHead = Address->Next;
496    }
497
498    if (Address->Next)
499    {
500        (Address->Next)->Previous = Address->Previous;
501    }
502
503
504    /* Mark the segment as deleted */
505
506    MEMSET (&Address->UserSpace, 0xEA, Address->Size);
507
508    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size %X\n", Address->Size));
509
510    AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
511    return_ACPI_STATUS (AE_OK);
512}
513
514
515/*******************************************************************************
516 *
517 * FUNCTION:    AcpiUtDumpAllocationInfo
518 *
519 * PARAMETERS:
520 *
521 * RETURN:      None
522 *
523 * DESCRIPTION: Print some info about the outstanding allocations.
524 *
525 ******************************************************************************/
526
527void
528AcpiUtDumpAllocationInfo (
529    void)
530{
531/*
532    ACPI_MEMORY_LIST        *MemList;
533*/
534
535    FUNCTION_TRACE ("UtDumpAllocationInfo");
536
537/*
538    ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
539                    ("%30s: %4d (%3d Kb)\n", "Current allocations",
540                    MemList->CurrentCount,
541                    ROUND_UP_TO_1K (MemList->CurrentSize)));
542
543    ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
544                    ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
545                    MemList->MaxConcurrentCount,
546                    ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
547
548
549    ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
550                    ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
551                    RunningObjectCount,
552                    ROUND_UP_TO_1K (RunningObjectSize)));
553
554    ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
555                    ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
556                    RunningAllocCount,
557                    ROUND_UP_TO_1K (RunningAllocSize)));
558
559
560    ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
561                    ("%30s: %4d (%3d Kb)\n", "Current Nodes",
562                    AcpiGbl_CurrentNodeCount,
563                    ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
564
565    ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
566                    ("%30s: %4d (%3d Kb)\n", "Max Nodes",
567                    AcpiGbl_MaxConcurrentNodeCount,
568                    ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount * sizeof (ACPI_NAMESPACE_NODE)))));
569*/
570    return_VOID;
571}
572
573
574/*******************************************************************************
575 *
576 * FUNCTION:    AcpiUtDumpAllocations
577 *
578 * PARAMETERS:  Component           - Component(s) to dump info for.
579 *              Module              - Module to dump info for.  NULL means all.
580 *
581 * RETURN:      None
582 *
583 * DESCRIPTION: Print a list of all outstanding allocations.
584 *
585 ******************************************************************************/
586
587void
588AcpiUtDumpAllocations (
589    UINT32                  Component,
590    NATIVE_CHAR             *Module)
591{
592    ACPI_DEBUG_MEM_BLOCK    *Element;
593    UINT32                  i;
594
595
596    FUNCTION_TRACE ("UtDumpAllocations");
597
598
599    Element = AcpiGbl_MemoryLists[0].ListHead;
600    if (Element == NULL)
601    {
602        ACPI_DEBUG_PRINT ((ACPI_DB_OK,
603                "No outstanding allocations.\n"));
604        return_VOID;
605    }
606
607
608    /*
609     * Walk the allocation list.
610     */
611    AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
612
613    ACPI_DEBUG_PRINT ((ACPI_DB_OK,
614        "Outstanding allocations:\n"));
615
616    for (i = 1; ; i++)  /* Just a counter */
617    {
618        if ((Element->Component & Component) &&
619            ((Module == NULL) || (0 == STRCMP (Module, Element->Module))))
620        {
621            if (((ACPI_OPERAND_OBJECT  *)(&Element->UserSpace))->Common.Type != ACPI_CACHED_OBJECT)
622            {
623                ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
624                            "%p Len %04lX %9.9s-%ld",
625                            &Element->UserSpace, Element->Size, Element->Module,
626                            Element->Line));
627
628                /* Most of the elements will be internal objects. */
629
630                switch (((ACPI_OPERAND_OBJECT  *)
631                    (&Element->UserSpace))->Common.DataType)
632                {
633                case ACPI_DESC_TYPE_INTERNAL:
634                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
635                            " ObjType %s",
636                            AcpiUtGetTypeName (((ACPI_OPERAND_OBJECT  *)(&Element->UserSpace))->Common.Type)));
637                    break;
638
639                case ACPI_DESC_TYPE_PARSER:
640                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
641                            " ParseObj Opcode %04X",
642                            ((ACPI_PARSE_OBJECT *)(&Element->UserSpace))->Opcode));
643                    break;
644
645                case ACPI_DESC_TYPE_NAMED:
646                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
647                            " Node %4.4s",
648                            &((ACPI_NAMESPACE_NODE *)(&Element->UserSpace))->Name));
649                    break;
650
651                case ACPI_DESC_TYPE_STATE:
652                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
653                            " Untyped StateObj"));
654                    break;
655
656                case ACPI_DESC_TYPE_STATE_UPDATE:
657                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
658                            " UPDATE StateObj"));
659                    break;
660
661                case ACPI_DESC_TYPE_STATE_PACKAGE:
662                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
663                            " PACKAGE StateObj"));
664                    break;
665
666                case ACPI_DESC_TYPE_STATE_CONTROL:
667                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
668                            " CONTROL StateObj"));
669                    break;
670
671                case ACPI_DESC_TYPE_STATE_RPSCOPE:
672                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
673                            " ROOT-PARSE-SCOPE StateObj"));
674                    break;
675
676                case ACPI_DESC_TYPE_STATE_PSCOPE:
677                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
678                            " PARSE-SCOPE StateObj"));
679                    break;
680
681                case ACPI_DESC_TYPE_STATE_WSCOPE:
682                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
683                            " WALK-SCOPE StateObj"));
684                    break;
685
686                case ACPI_DESC_TYPE_STATE_RESULT:
687                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
688                            " RESULT StateObj"));
689                    break;
690
691                case ACPI_DESC_TYPE_STATE_NOTIFY:
692                    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK,
693                            " NOTIFY StateObj"));
694                    break;
695                }
696
697                ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OK, "\n"));
698            }
699        }
700
701        if (Element->Next == NULL)
702        {
703            break;
704        }
705
706        Element = Element->Next;
707    }
708
709    AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
710
711    ACPI_DEBUG_PRINT ((ACPI_DB_OK,
712        "Total number of unfreed allocations = %d(%X)\n", i,i));
713
714
715    return_VOID;
716
717}
718
719
720/*******************************************************************************
721 *
722 * FUNCTION:    AcpiUtAllocate
723 *
724 * PARAMETERS:  Size                - Size of the allocation
725 *              Component           - Component type of caller
726 *              Module              - Source file name of caller
727 *              Line                - Line number of caller
728 *
729 * RETURN:      Address of the allocated memory on success, NULL on failure.
730 *
731 * DESCRIPTION: The subsystem's equivalent of malloc.
732 *
733 ******************************************************************************/
734
735void *
736AcpiUtAllocate (
737    UINT32                  Size,
738    UINT32                  Component,
739    NATIVE_CHAR             *Module,
740    UINT32                  Line)
741{
742    ACPI_DEBUG_MEM_BLOCK    *Address;
743    ACPI_STATUS             Status;
744
745
746    FUNCTION_TRACE_U32 ("UtAllocate", Size);
747
748
749    /* Check for an inadvertent size of zero bytes */
750
751    if (!Size)
752    {
753        _REPORT_ERROR (Module, Line, Component,
754                ("UtAllocate: Attempt to allocate zero bytes\n"));
755        Size = 1;
756    }
757
758    Address = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK));
759    if (!Address)
760    {
761        /* Report allocation error */
762
763        _REPORT_ERROR (Module, Line, Component,
764                ("UtAllocate: Could not allocate size %X\n", Size));
765
766        return_PTR (NULL);
767    }
768
769    Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Address, Size,
770                    MEM_MALLOC, Component, Module, Line);
771    if (ACPI_FAILURE (Status))
772    {
773        AcpiOsFree (Address);
774        return_PTR (NULL);
775    }
776
777    AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalAllocated++;
778    AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize += Size;
779
780    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", Address, Size));
781
782    return_PTR ((void *) &Address->UserSpace);
783}
784
785
786/*******************************************************************************
787 *
788 * FUNCTION:    AcpiUtCallocate
789 *
790 * PARAMETERS:  Size                - Size of the allocation
791 *              Component           - Component type of caller
792 *              Module              - Source file name of caller
793 *              Line                - Line number of caller
794 *
795 * RETURN:      Address of the allocated memory on success, NULL on failure.
796 *
797 * DESCRIPTION: Subsystem equivalent of calloc.
798 *
799 ******************************************************************************/
800
801void *
802AcpiUtCallocate (
803    UINT32                  Size,
804    UINT32                  Component,
805    NATIVE_CHAR             *Module,
806    UINT32                  Line)
807{
808    ACPI_DEBUG_MEM_BLOCK    *Address;
809    ACPI_STATUS             Status;
810
811
812    FUNCTION_TRACE_U32 ("UtCallocate", Size);
813
814
815    /* Check for an inadvertent size of zero bytes */
816
817    if (!Size)
818    {
819        _REPORT_ERROR (Module, Line, Component,
820                ("UtCallocate: Attempt to allocate zero bytes\n"));
821        return_PTR (NULL);
822    }
823
824
825    Address = AcpiOsCallocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK));
826    if (!Address)
827    {
828        /* Report allocation error */
829
830        _REPORT_ERROR (Module, Line, Component,
831                ("UtCallocate: Could not allocate size %X\n", Size));
832        return_PTR (NULL);
833    }
834
835    Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Address, Size,
836                        MEM_CALLOC, Component, Module, Line);
837    if (ACPI_FAILURE (Status))
838    {
839        AcpiOsFree (Address);
840        return_PTR (NULL);
841    }
842
843    AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalAllocated++;
844    AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize += Size;
845
846    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n", Address, Size));
847    return_PTR ((void *) &Address->UserSpace);
848}
849
850
851/*******************************************************************************
852 *
853 * FUNCTION:    AcpiUtFree
854 *
855 * PARAMETERS:  Address             - Address of the memory to deallocate
856 *              Component           - Component type of caller
857 *              Module              - Source file name of caller
858 *              Line                - Line number of caller
859 *
860 * RETURN:      None
861 *
862 * DESCRIPTION: Frees the memory at Address
863 *
864 ******************************************************************************/
865
866void
867AcpiUtFree (
868    void                    *Address,
869    UINT32                  Component,
870    NATIVE_CHAR             *Module,
871    UINT32                  Line)
872{
873    ACPI_DEBUG_MEM_BLOCK    *DebugBlock;
874
875
876    FUNCTION_TRACE_PTR ("UtFree", Address);
877
878
879    if (NULL == Address)
880    {
881        _REPORT_ERROR (Module, Line, Component,
882            ("AcpiUtFree: Trying to delete a NULL address\n"));
883
884        return_VOID;
885    }
886
887    DebugBlock = (ACPI_DEBUG_MEM_BLOCK *)
888                    (((char *) Address) - sizeof (ACPI_DEBUG_MEM_HEADER));
889
890    AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalFreed++;
891    AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize -= DebugBlock->Size;
892
893    AcpiUtRemoveAllocation (ACPI_MEM_LIST_GLOBAL, DebugBlock,
894            Component, Module, Line);
895    AcpiOsFree (DebugBlock);
896
897    ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Address));
898
899    return_VOID;
900}
901
902#endif  /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */
903
904