xref: /onnv-gate/usr/src/uts/intel/io/acpica/utilities/uttrack.c (revision 9980:13d7f3eec672)
13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: uttrack - Memory allocation tracking routines (debug only)
43446Smrj  *
53446Smrj  *****************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
11*9980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj /*
1173446Smrj  * These procedures are used for tracking memory leaks in the subsystem, and
1183446Smrj  * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
1193446Smrj  *
1203446Smrj  * Each memory allocation is tracked via a doubly linked list.  Each
1213446Smrj  * element contains the caller's component, module name, function name, and
1223446Smrj  * line number.  AcpiUtAllocate and AcpiUtAllocateZeroed call
1233446Smrj  * AcpiUtTrackAllocation to add an element to the list; deletion
1243446Smrj  * occurs in the body of AcpiUtFree.
1253446Smrj  */
1263446Smrj 
1273446Smrj #define __UTTRACK_C__
1283446Smrj 
1293446Smrj #include "acpi.h"
130*9980SDana.Myers@Sun.COM #include "accommon.h"
1313446Smrj 
1323446Smrj #ifdef ACPI_DBG_TRACK_ALLOCATIONS
1333446Smrj 
1343446Smrj #define _COMPONENT          ACPI_UTILITIES
1353446Smrj         ACPI_MODULE_NAME    ("uttrack")
1363446Smrj 
1373446Smrj /* Local prototypes */
1383446Smrj 
1393446Smrj static ACPI_DEBUG_MEM_BLOCK *
1403446Smrj AcpiUtFindAllocation (
1413446Smrj     void                    *Allocation);
1423446Smrj 
1433446Smrj static ACPI_STATUS
1443446Smrj AcpiUtTrackAllocation (
1453446Smrj     ACPI_DEBUG_MEM_BLOCK    *Address,
1463446Smrj     ACPI_SIZE               Size,
1473446Smrj     UINT8                   AllocType,
1483446Smrj     UINT32                  Component,
1497851SDana.Myers@Sun.COM     const char              *Module,
1503446Smrj     UINT32                  Line);
1513446Smrj 
1523446Smrj static ACPI_STATUS
1533446Smrj AcpiUtRemoveAllocation (
1543446Smrj     ACPI_DEBUG_MEM_BLOCK    *Address,
1553446Smrj     UINT32                  Component,
1567851SDana.Myers@Sun.COM     const char              *Module,
1573446Smrj     UINT32                  Line);
1583446Smrj 
1593446Smrj 
1603446Smrj /*******************************************************************************
1613446Smrj  *
1623446Smrj  * FUNCTION:    AcpiUtCreateList
1633446Smrj  *
1643446Smrj  * PARAMETERS:  CacheName       - Ascii name for the cache
1653446Smrj  *              ObjectSize      - Size of each cached object
1663446Smrj  *              ReturnCache     - Where the new cache object is returned
1673446Smrj  *
1683446Smrj  * RETURN:      Status
1693446Smrj  *
1703446Smrj  * DESCRIPTION: Create a local memory list for tracking purposed
1713446Smrj  *
1723446Smrj  ******************************************************************************/
1733446Smrj 
1743446Smrj ACPI_STATUS
AcpiUtCreateList(char * ListName,UINT16 ObjectSize,ACPI_MEMORY_LIST ** ReturnCache)1753446Smrj AcpiUtCreateList (
1763446Smrj     char                    *ListName,
1773446Smrj     UINT16                  ObjectSize,
1783446Smrj     ACPI_MEMORY_LIST        **ReturnCache)
1793446Smrj {
1803446Smrj     ACPI_MEMORY_LIST        *Cache;
1813446Smrj 
1823446Smrj 
1833446Smrj     Cache = AcpiOsAllocate (sizeof (ACPI_MEMORY_LIST));
1843446Smrj     if (!Cache)
1853446Smrj     {
1863446Smrj         return (AE_NO_MEMORY);
1873446Smrj     }
1883446Smrj 
1893446Smrj     ACPI_MEMSET (Cache, 0, sizeof (ACPI_MEMORY_LIST));
1903446Smrj 
1913446Smrj     Cache->ListName   = ListName;
1923446Smrj     Cache->ObjectSize = ObjectSize;
1933446Smrj 
1943446Smrj     *ReturnCache = Cache;
1953446Smrj     return (AE_OK);
1963446Smrj }
1973446Smrj 
1983446Smrj 
1993446Smrj /*******************************************************************************
2003446Smrj  *
2013446Smrj  * FUNCTION:    AcpiUtAllocateAndTrack
2023446Smrj  *
2033446Smrj  * PARAMETERS:  Size                - Size of the allocation
2043446Smrj  *              Component           - Component type of caller
2053446Smrj  *              Module              - Source file name of caller
2063446Smrj  *              Line                - Line number of caller
2073446Smrj  *
2083446Smrj  * RETURN:      Address of the allocated memory on success, NULL on failure.
2093446Smrj  *
2103446Smrj  * DESCRIPTION: The subsystem's equivalent of malloc.
2113446Smrj  *
2123446Smrj  ******************************************************************************/
2133446Smrj 
2143446Smrj void *
AcpiUtAllocateAndTrack(ACPI_SIZE Size,UINT32 Component,const char * Module,UINT32 Line)2153446Smrj AcpiUtAllocateAndTrack (
2163446Smrj     ACPI_SIZE               Size,
2173446Smrj     UINT32                  Component,
2187851SDana.Myers@Sun.COM     const char              *Module,
2193446Smrj     UINT32                  Line)
2203446Smrj {
2213446Smrj     ACPI_DEBUG_MEM_BLOCK    *Allocation;
2223446Smrj     ACPI_STATUS             Status;
2233446Smrj 
2243446Smrj 
2253446Smrj     Allocation = AcpiUtAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER),
2263446Smrj                     Component, Module, Line);
2273446Smrj     if (!Allocation)
2283446Smrj     {
2293446Smrj         return (NULL);
2303446Smrj     }
2313446Smrj 
2323446Smrj     Status = AcpiUtTrackAllocation (Allocation, Size,
2333446Smrj                     ACPI_MEM_MALLOC, Component, Module, Line);
2343446Smrj     if (ACPI_FAILURE (Status))
2353446Smrj     {
2363446Smrj         AcpiOsFree (Allocation);
2373446Smrj         return (NULL);
2383446Smrj     }
2393446Smrj 
2403446Smrj     AcpiGbl_GlobalList->TotalAllocated++;
2417851SDana.Myers@Sun.COM     AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
2423446Smrj     AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
2437851SDana.Myers@Sun.COM     if (AcpiGbl_GlobalList->CurrentTotalSize > AcpiGbl_GlobalList->MaxOccupied)
2447851SDana.Myers@Sun.COM     {
2457851SDana.Myers@Sun.COM         AcpiGbl_GlobalList->MaxOccupied = AcpiGbl_GlobalList->CurrentTotalSize;
2467851SDana.Myers@Sun.COM     }
2473446Smrj 
2483446Smrj     return ((void *) &Allocation->UserSpace);
2493446Smrj }
2503446Smrj 
2513446Smrj 
2523446Smrj /*******************************************************************************
2533446Smrj  *
2543446Smrj  * FUNCTION:    AcpiUtAllocateZeroedAndTrack
2553446Smrj  *
2563446Smrj  * PARAMETERS:  Size                - Size of the allocation
2573446Smrj  *              Component           - Component type of caller
2583446Smrj  *              Module              - Source file name of caller
2593446Smrj  *              Line                - Line number of caller
2603446Smrj  *
2613446Smrj  * RETURN:      Address of the allocated memory on success, NULL on failure.
2623446Smrj  *
2633446Smrj  * DESCRIPTION: Subsystem equivalent of calloc.
2643446Smrj  *
2653446Smrj  ******************************************************************************/
2663446Smrj 
2673446Smrj void *
AcpiUtAllocateZeroedAndTrack(ACPI_SIZE Size,UINT32 Component,const char * Module,UINT32 Line)2683446Smrj AcpiUtAllocateZeroedAndTrack (
2693446Smrj     ACPI_SIZE               Size,
2703446Smrj     UINT32                  Component,
2717851SDana.Myers@Sun.COM     const char              *Module,
2723446Smrj     UINT32                  Line)
2733446Smrj {
2743446Smrj     ACPI_DEBUG_MEM_BLOCK    *Allocation;
2753446Smrj     ACPI_STATUS             Status;
2763446Smrj 
2773446Smrj 
2783446Smrj     Allocation = AcpiUtAllocateZeroed (Size + sizeof (ACPI_DEBUG_MEM_HEADER),
2793446Smrj                     Component, Module, Line);
2803446Smrj     if (!Allocation)
2813446Smrj     {
2823446Smrj         /* Report allocation error */
2833446Smrj 
2843446Smrj         ACPI_ERROR ((Module, Line,
2853446Smrj             "Could not allocate size %X", (UINT32) Size));
2863446Smrj         return (NULL);
2873446Smrj     }
2883446Smrj 
2893446Smrj     Status = AcpiUtTrackAllocation (Allocation, Size,
2903446Smrj                 ACPI_MEM_CALLOC, Component, Module, Line);
2913446Smrj     if (ACPI_FAILURE (Status))
2923446Smrj     {
2933446Smrj         AcpiOsFree (Allocation);
2943446Smrj         return (NULL);
2953446Smrj     }
2963446Smrj 
2973446Smrj     AcpiGbl_GlobalList->TotalAllocated++;
2987851SDana.Myers@Sun.COM     AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
2993446Smrj     AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
3007851SDana.Myers@Sun.COM     if (AcpiGbl_GlobalList->CurrentTotalSize > AcpiGbl_GlobalList->MaxOccupied)
3017851SDana.Myers@Sun.COM     {
3027851SDana.Myers@Sun.COM         AcpiGbl_GlobalList->MaxOccupied = AcpiGbl_GlobalList->CurrentTotalSize;
3037851SDana.Myers@Sun.COM     }
3043446Smrj 
3053446Smrj     return ((void *) &Allocation->UserSpace);
3063446Smrj }
3073446Smrj 
3083446Smrj 
3093446Smrj /*******************************************************************************
3103446Smrj  *
3113446Smrj  * FUNCTION:    AcpiUtFreeAndTrack
3123446Smrj  *
3133446Smrj  * PARAMETERS:  Allocation          - Address of the memory to deallocate
3143446Smrj  *              Component           - Component type of caller
3153446Smrj  *              Module              - Source file name of caller
3163446Smrj  *              Line                - Line number of caller
3173446Smrj  *
3183446Smrj  * RETURN:      None
3193446Smrj  *
3203446Smrj  * DESCRIPTION: Frees the memory at Allocation
3213446Smrj  *
3223446Smrj  ******************************************************************************/
3233446Smrj 
3243446Smrj void
AcpiUtFreeAndTrack(void * Allocation,UINT32 Component,const char * Module,UINT32 Line)3253446Smrj AcpiUtFreeAndTrack (
3263446Smrj     void                    *Allocation,
3273446Smrj     UINT32                  Component,
3287851SDana.Myers@Sun.COM     const char              *Module,
3293446Smrj     UINT32                  Line)
3303446Smrj {
3313446Smrj     ACPI_DEBUG_MEM_BLOCK    *DebugBlock;
3323446Smrj     ACPI_STATUS             Status;
3333446Smrj 
3343446Smrj 
3353446Smrj     ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation);
3363446Smrj 
3373446Smrj 
3383446Smrj     if (NULL == Allocation)
3393446Smrj     {
3403446Smrj         ACPI_ERROR ((Module, Line,
3413446Smrj             "Attempt to delete a NULL address"));
3423446Smrj 
3433446Smrj         return_VOID;
3443446Smrj     }
3453446Smrj 
3463446Smrj     DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
3473446Smrj                     (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
3483446Smrj 
3493446Smrj     AcpiGbl_GlobalList->TotalFreed++;
3503446Smrj     AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
3513446Smrj 
3523446Smrj     Status = AcpiUtRemoveAllocation (DebugBlock,
3533446Smrj                     Component, Module, Line);
3543446Smrj     if (ACPI_FAILURE (Status))
3553446Smrj     {
3563446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
3573446Smrj     }
3583446Smrj 
3593446Smrj     AcpiOsFree (DebugBlock);
3603446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Allocation));
3613446Smrj     return_VOID;
3623446Smrj }
3633446Smrj 
3643446Smrj 
3653446Smrj /*******************************************************************************
3663446Smrj  *
3673446Smrj  * FUNCTION:    AcpiUtFindAllocation
3683446Smrj  *
3693446Smrj  * PARAMETERS:  Allocation              - Address of allocated memory
3703446Smrj  *
3713446Smrj  * RETURN:      A list element if found; NULL otherwise.
3723446Smrj  *
3733446Smrj  * DESCRIPTION: Searches for an element in the global allocation tracking list.
3743446Smrj  *
3753446Smrj  ******************************************************************************/
3763446Smrj 
3773446Smrj static ACPI_DEBUG_MEM_BLOCK *
AcpiUtFindAllocation(void * Allocation)3783446Smrj AcpiUtFindAllocation (
3793446Smrj     void                    *Allocation)
3803446Smrj {
3813446Smrj     ACPI_DEBUG_MEM_BLOCK    *Element;
3823446Smrj 
3833446Smrj 
3843446Smrj     ACPI_FUNCTION_ENTRY ();
3853446Smrj 
3863446Smrj 
3873446Smrj     Element = AcpiGbl_GlobalList->ListHead;
3883446Smrj 
3893446Smrj     /* Search for the address. */
3903446Smrj 
3913446Smrj     while (Element)
3923446Smrj     {
3933446Smrj         if (Element == Allocation)
3943446Smrj         {
3953446Smrj             return (Element);
3963446Smrj         }
3973446Smrj 
3983446Smrj         Element = Element->Next;
3993446Smrj     }
4003446Smrj 
4013446Smrj     return (NULL);
4023446Smrj }
4033446Smrj 
4043446Smrj 
4053446Smrj /*******************************************************************************
4063446Smrj  *
4073446Smrj  * FUNCTION:    AcpiUtTrackAllocation
4083446Smrj  *
4093446Smrj  * PARAMETERS:  Allocation          - Address of allocated memory
4103446Smrj  *              Size                - Size of the allocation
4113446Smrj  *              AllocType           - MEM_MALLOC or MEM_CALLOC
4123446Smrj  *              Component           - Component type of caller
4133446Smrj  *              Module              - Source file name of caller
4143446Smrj  *              Line                - Line number of caller
4153446Smrj  *
4163446Smrj  * RETURN:      None.
4173446Smrj  *
4183446Smrj  * DESCRIPTION: Inserts an element into the global allocation tracking list.
4193446Smrj  *
4203446Smrj  ******************************************************************************/
4213446Smrj 
4223446Smrj static ACPI_STATUS
AcpiUtTrackAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation,ACPI_SIZE Size,UINT8 AllocType,UINT32 Component,const char * Module,UINT32 Line)4233446Smrj AcpiUtTrackAllocation (
4243446Smrj     ACPI_DEBUG_MEM_BLOCK    *Allocation,
4253446Smrj     ACPI_SIZE               Size,
4263446Smrj     UINT8                   AllocType,
4273446Smrj     UINT32                  Component,
4287851SDana.Myers@Sun.COM     const char              *Module,
4293446Smrj     UINT32                  Line)
4303446Smrj {
4313446Smrj     ACPI_MEMORY_LIST        *MemList;
4323446Smrj     ACPI_DEBUG_MEM_BLOCK    *Element;
4333446Smrj     ACPI_STATUS             Status = AE_OK;
4343446Smrj 
4353446Smrj 
4363446Smrj     ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
4373446Smrj 
4383446Smrj 
4393446Smrj     MemList = AcpiGbl_GlobalList;
4403446Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
4413446Smrj     if (ACPI_FAILURE (Status))
4423446Smrj     {
4433446Smrj         return_ACPI_STATUS (Status);
4443446Smrj     }
4453446Smrj 
4463446Smrj     /*
4473446Smrj      * Search list for this address to make sure it is not already on the list.
4483446Smrj      * This will catch several kinds of problems.
4493446Smrj      */
4503446Smrj     Element = AcpiUtFindAllocation (Allocation);
4513446Smrj     if (Element)
4523446Smrj     {
4533446Smrj         ACPI_ERROR ((AE_INFO,
4543446Smrj             "UtTrackAllocation: Allocation already present in list! (%p)",
4553446Smrj             Allocation));
4563446Smrj 
4573446Smrj         ACPI_ERROR ((AE_INFO, "Element %p Address %p",
4583446Smrj             Element, Allocation));
4593446Smrj 
4603446Smrj         goto UnlockAndExit;
4613446Smrj     }
4623446Smrj 
4633446Smrj     /* Fill in the instance data. */
4643446Smrj 
4653446Smrj     Allocation->Size      = (UINT32) Size;
4663446Smrj     Allocation->AllocType = AllocType;
4673446Smrj     Allocation->Component = Component;
4683446Smrj     Allocation->Line      = Line;
4693446Smrj 
4703446Smrj     ACPI_STRNCPY (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
4713446Smrj     Allocation->Module[ACPI_MAX_MODULE_NAME-1] = 0;
4723446Smrj 
4733446Smrj     /* Insert at list head */
4743446Smrj 
4753446Smrj     if (MemList->ListHead)
4763446Smrj     {
4773446Smrj         ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
4783446Smrj     }
4793446Smrj 
4803446Smrj     Allocation->Next = MemList->ListHead;
4813446Smrj     Allocation->Previous = NULL;
4823446Smrj 
4833446Smrj     MemList->ListHead = Allocation;
4843446Smrj 
4853446Smrj 
4863446Smrj UnlockAndExit:
4873446Smrj     Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
4883446Smrj     return_ACPI_STATUS (Status);
4893446Smrj }
4903446Smrj 
4913446Smrj 
4923446Smrj /*******************************************************************************
4933446Smrj  *
4943446Smrj  * FUNCTION:    AcpiUtRemoveAllocation
4953446Smrj  *
4963446Smrj  * PARAMETERS:  Allocation          - Address of allocated memory
4973446Smrj  *              Component           - Component type of caller
4983446Smrj  *              Module              - Source file name of caller
4993446Smrj  *              Line                - Line number of caller
5003446Smrj  *
5013446Smrj  * RETURN:
5023446Smrj  *
5033446Smrj  * DESCRIPTION: Deletes an element from the global allocation tracking list.
5043446Smrj  *
5053446Smrj  ******************************************************************************/
5063446Smrj 
5073446Smrj static ACPI_STATUS
AcpiUtRemoveAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation,UINT32 Component,const char * Module,UINT32 Line)5083446Smrj AcpiUtRemoveAllocation (
5093446Smrj     ACPI_DEBUG_MEM_BLOCK    *Allocation,
5103446Smrj     UINT32                  Component,
5117851SDana.Myers@Sun.COM     const char              *Module,
5123446Smrj     UINT32                  Line)
5133446Smrj {
5143446Smrj     ACPI_MEMORY_LIST        *MemList;
5153446Smrj     ACPI_STATUS             Status;
5163446Smrj 
5173446Smrj 
5183446Smrj     ACPI_FUNCTION_TRACE (UtRemoveAllocation);
5193446Smrj 
5203446Smrj 
5213446Smrj     MemList = AcpiGbl_GlobalList;
5223446Smrj     if (NULL == MemList->ListHead)
5233446Smrj     {
5243446Smrj         /* No allocations! */
5253446Smrj 
5263446Smrj         ACPI_ERROR ((Module, Line,
5273446Smrj             "Empty allocation list, nothing to free!"));
5283446Smrj 
5293446Smrj         return_ACPI_STATUS (AE_OK);
5303446Smrj     }
5313446Smrj 
5323446Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
5333446Smrj     if (ACPI_FAILURE (Status))
5343446Smrj     {
5353446Smrj         return_ACPI_STATUS (Status);
5363446Smrj     }
5373446Smrj 
5383446Smrj     /* Unlink */
5393446Smrj 
5403446Smrj     if (Allocation->Previous)
5413446Smrj     {
5423446Smrj         (Allocation->Previous)->Next = Allocation->Next;
5433446Smrj     }
5443446Smrj     else
5453446Smrj     {
5463446Smrj         MemList->ListHead = Allocation->Next;
5473446Smrj     }
5483446Smrj 
5493446Smrj     if (Allocation->Next)
5503446Smrj     {
5513446Smrj         (Allocation->Next)->Previous = Allocation->Previous;
5523446Smrj     }
5533446Smrj 
5543446Smrj     /* Mark the segment as deleted */
5553446Smrj 
5563446Smrj     ACPI_MEMSET (&Allocation->UserSpace, 0xEA, Allocation->Size);
5573446Smrj 
5583446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size 0%X\n",
5593446Smrj         Allocation->Size));
5603446Smrj 
5613446Smrj     Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
5623446Smrj     return_ACPI_STATUS (Status);
5633446Smrj }
5643446Smrj 
5653446Smrj 
5663446Smrj /*******************************************************************************
5673446Smrj  *
5683446Smrj  * FUNCTION:    AcpiUtDumpAllocationInfo
5693446Smrj  *
5703446Smrj  * PARAMETERS:
5713446Smrj  *
5723446Smrj  * RETURN:      None
5733446Smrj  *
5743446Smrj  * DESCRIPTION: Print some info about the outstanding allocations.
5753446Smrj  *
5763446Smrj  ******************************************************************************/
5773446Smrj 
5783446Smrj void
AcpiUtDumpAllocationInfo(void)5793446Smrj AcpiUtDumpAllocationInfo (
5803446Smrj     void)
5813446Smrj {
5823446Smrj /*
5833446Smrj     ACPI_MEMORY_LIST        *MemList;
5843446Smrj */
5853446Smrj 
5863446Smrj     ACPI_FUNCTION_TRACE (UtDumpAllocationInfo);
5873446Smrj 
5883446Smrj /*
5893446Smrj     ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
5903446Smrj                     ("%30s: %4d (%3d Kb)\n", "Current allocations",
5913446Smrj                     MemList->CurrentCount,
5923446Smrj                     ROUND_UP_TO_1K (MemList->CurrentSize)));
5933446Smrj 
5943446Smrj     ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
5953446Smrj                     ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
5963446Smrj                     MemList->MaxConcurrentCount,
5973446Smrj                     ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
5983446Smrj 
5993446Smrj 
6003446Smrj     ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
6013446Smrj                     ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
6023446Smrj                     RunningObjectCount,
6033446Smrj                     ROUND_UP_TO_1K (RunningObjectSize)));
6043446Smrj 
6053446Smrj     ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
6063446Smrj                     ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
6073446Smrj                     RunningAllocCount,
6083446Smrj                     ROUND_UP_TO_1K (RunningAllocSize)));
6093446Smrj 
6103446Smrj 
6113446Smrj     ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
6123446Smrj                     ("%30s: %4d (%3d Kb)\n", "Current Nodes",
6133446Smrj                     AcpiGbl_CurrentNodeCount,
6143446Smrj                     ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
6153446Smrj 
6163446Smrj     ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
6173446Smrj                     ("%30s: %4d (%3d Kb)\n", "Max Nodes",
6183446Smrj                     AcpiGbl_MaxConcurrentNodeCount,
6193446Smrj                     ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
6203446Smrj                         sizeof (ACPI_NAMESPACE_NODE)))));
6213446Smrj */
6223446Smrj     return_VOID;
6233446Smrj }
6243446Smrj 
6253446Smrj 
6263446Smrj /*******************************************************************************
6273446Smrj  *
6283446Smrj  * FUNCTION:    AcpiUtDumpAllocations
6293446Smrj  *
6303446Smrj  * PARAMETERS:  Component           - Component(s) to dump info for.
6313446Smrj  *              Module              - Module to dump info for.  NULL means all.
6323446Smrj  *
6333446Smrj  * RETURN:      None
6343446Smrj  *
6353446Smrj  * DESCRIPTION: Print a list of all outstanding allocations.
6363446Smrj  *
6373446Smrj  ******************************************************************************/
6383446Smrj 
6393446Smrj void
AcpiUtDumpAllocations(UINT32 Component,const char * Module)6403446Smrj AcpiUtDumpAllocations (
6413446Smrj     UINT32                  Component,
6427851SDana.Myers@Sun.COM     const char              *Module)
6433446Smrj {
6443446Smrj     ACPI_DEBUG_MEM_BLOCK    *Element;
6453446Smrj     ACPI_DESCRIPTOR         *Descriptor;
6463446Smrj     UINT32                  NumOutstanding = 0;
6473446Smrj 
6483446Smrj 
6493446Smrj     ACPI_FUNCTION_TRACE (UtDumpAllocations);
6503446Smrj 
6513446Smrj 
6523446Smrj     /*
6533446Smrj      * Walk the allocation list.
6543446Smrj      */
6553446Smrj     if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
6563446Smrj     {
6573446Smrj         return;
6583446Smrj     }
6593446Smrj 
6603446Smrj     Element = AcpiGbl_GlobalList->ListHead;
6613446Smrj     while (Element)
6623446Smrj     {
6633446Smrj         if ((Element->Component & Component) &&
6643446Smrj             ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module))))
6653446Smrj         {
6663446Smrj             /* Ignore allocated objects that are in a cache */
6673446Smrj 
6683446Smrj             Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace);
6693446Smrj             if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) != ACPI_DESC_TYPE_CACHED)
6703446Smrj             {
6713446Smrj                 AcpiOsPrintf ("%p Len %04X %9.9s-%d [%s] ",
6723446Smrj                     Descriptor, Element->Size, Element->Module,
6733446Smrj                     Element->Line, AcpiUtGetDescriptorName (Descriptor));
6743446Smrj 
6753446Smrj                 /* Most of the elements will be Operand objects. */
6763446Smrj 
6773446Smrj                 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
6783446Smrj                 {
6793446Smrj                 case ACPI_DESC_TYPE_OPERAND:
6803446Smrj                     AcpiOsPrintf ("%12.12s R%hd",
6813446Smrj                         AcpiUtGetTypeName (Descriptor->Object.Common.Type),
6823446Smrj                         Descriptor->Object.Common.ReferenceCount);
6833446Smrj                     break;
6843446Smrj 
6853446Smrj                 case ACPI_DESC_TYPE_PARSER:
6863446Smrj                     AcpiOsPrintf ("AmlOpcode %04hX",
6873446Smrj                         Descriptor->Op.Asl.AmlOpcode);
6883446Smrj                     break;
6893446Smrj 
6903446Smrj                 case ACPI_DESC_TYPE_NAMED:
6913446Smrj                     AcpiOsPrintf ("%4.4s",
6923446Smrj                         AcpiUtGetNodeName (&Descriptor->Node));
6933446Smrj                     break;
6943446Smrj 
6953446Smrj                 default:
6963446Smrj                     break;
6973446Smrj                 }
6983446Smrj 
6993446Smrj                 AcpiOsPrintf ( "\n");
7003446Smrj                 NumOutstanding++;
7013446Smrj             }
7023446Smrj         }
7033446Smrj         Element = Element->Next;
7043446Smrj     }
7053446Smrj 
7063446Smrj     (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
7073446Smrj 
7083446Smrj     /* Print summary */
7093446Smrj 
7103446Smrj     if (!NumOutstanding)
7113446Smrj     {
7123446Smrj         ACPI_INFO ((AE_INFO,
7133446Smrj             "No outstanding allocations"));
7143446Smrj     }
7153446Smrj     else
7163446Smrj     {
7173446Smrj         ACPI_ERROR ((AE_INFO,
7183446Smrj             "%d(%X) Outstanding allocations",
7193446Smrj             NumOutstanding, NumOutstanding));
7203446Smrj     }
7213446Smrj 
7223446Smrj     return_VOID;
7233446Smrj }
7243446Smrj 
7253446Smrj #endif  /* ACPI_DBG_TRACK_ALLOCATIONS */
7263446Smrj 
727