10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist *
30174267aSFredrik Holmqvist * Module Name: uttrack - Memory allocation tracking routines (debug only)
40174267aSFredrik Holmqvist *
50174267aSFredrik Holmqvist *****************************************************************************/
60174267aSFredrik Holmqvist
70174267aSFredrik Holmqvist /******************************************************************************
80174267aSFredrik Holmqvist *
90174267aSFredrik Holmqvist * 1. Copyright Notice
100174267aSFredrik Holmqvist *
11*6dde014fSPulkoMandy * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
120174267aSFredrik Holmqvist * All rights reserved.
130174267aSFredrik Holmqvist *
140174267aSFredrik Holmqvist * 2. License
150174267aSFredrik Holmqvist *
160174267aSFredrik Holmqvist * 2.1. This is your license from Intel Corp. under its intellectual property
170174267aSFredrik Holmqvist * rights. You may have additional license terms from the party that provided
180174267aSFredrik Holmqvist * you this software, covering your right to use that party's intellectual
190174267aSFredrik Holmqvist * property rights.
200174267aSFredrik Holmqvist *
210174267aSFredrik Holmqvist * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220174267aSFredrik Holmqvist * copy of the source code appearing in this file ("Covered Code") an
230174267aSFredrik Holmqvist * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240174267aSFredrik Holmqvist * base code distributed originally by Intel ("Original Intel Code") to copy,
250174267aSFredrik Holmqvist * make derivatives, distribute, use and display any portion of the Covered
260174267aSFredrik Holmqvist * Code in any form, with the right to sublicense such rights; and
270174267aSFredrik Holmqvist *
280174267aSFredrik Holmqvist * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290174267aSFredrik Holmqvist * license (with the right to sublicense), under only those claims of Intel
300174267aSFredrik Holmqvist * patents that are infringed by the Original Intel Code, to make, use, sell,
310174267aSFredrik Holmqvist * offer to sell, and import the Covered Code and derivative works thereof
320174267aSFredrik Holmqvist * solely to the minimum extent necessary to exercise the above copyright
330174267aSFredrik Holmqvist * license, and in no event shall the patent license extend to any additions
340174267aSFredrik Holmqvist * to or modifications of the Original Intel Code. No other license or right
350174267aSFredrik Holmqvist * is granted directly or by implication, estoppel or otherwise;
360174267aSFredrik Holmqvist *
370174267aSFredrik Holmqvist * The above copyright and patent license is granted only if the following
380174267aSFredrik Holmqvist * conditions are met:
390174267aSFredrik Holmqvist *
400174267aSFredrik Holmqvist * 3. Conditions
410174267aSFredrik Holmqvist *
420174267aSFredrik Holmqvist * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430174267aSFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered
440174267aSFredrik Holmqvist * Code or modification with rights to further distribute source must include
450174267aSFredrik Holmqvist * the above Copyright Notice, the above License, this list of Conditions,
460174267aSFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition,
470174267aSFredrik Holmqvist * Licensee must cause all Covered Code to which Licensee contributes to
480174267aSFredrik Holmqvist * contain a file documenting the changes Licensee made to create that Covered
490174267aSFredrik Holmqvist * Code and the date of any change. Licensee must include in that file the
500174267aSFredrik Holmqvist * documentation of any changes made by any predecessor Licensee. Licensee
510174267aSFredrik Holmqvist * must include a prominent statement that the modification is derived,
520174267aSFredrik Holmqvist * directly or indirectly, from Original Intel Code.
530174267aSFredrik Holmqvist *
540174267aSFredrik Holmqvist * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550174267aSFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered
560174267aSFredrik Holmqvist * Code or modification without rights to further distribute source must
570174267aSFredrik Holmqvist * include the following Disclaimer and Export Compliance provision in the
580174267aSFredrik Holmqvist * documentation and/or other materials provided with distribution. In
590174267aSFredrik Holmqvist * addition, Licensee may not authorize further sublicense of source of any
600174267aSFredrik Holmqvist * portion of the Covered Code, and must include terms to the effect that the
610174267aSFredrik Holmqvist * license from Licensee to its licensee is limited to the intellectual
620174267aSFredrik Holmqvist * property embodied in the software Licensee provides to its licensee, and
630174267aSFredrik Holmqvist * not to intellectual property embodied in modifications its licensee may
640174267aSFredrik Holmqvist * make.
650174267aSFredrik Holmqvist *
660174267aSFredrik Holmqvist * 3.3. Redistribution of Executable. Redistribution in executable form of any
670174267aSFredrik Holmqvist * substantial portion of the Covered Code or modification must reproduce the
680174267aSFredrik Holmqvist * above Copyright Notice, and the following Disclaimer and Export Compliance
690174267aSFredrik Holmqvist * provision in the documentation and/or other materials provided with the
700174267aSFredrik Holmqvist * distribution.
710174267aSFredrik Holmqvist *
720174267aSFredrik Holmqvist * 3.4. Intel retains all right, title, and interest in and to the Original
730174267aSFredrik Holmqvist * Intel Code.
740174267aSFredrik Holmqvist *
750174267aSFredrik Holmqvist * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760174267aSFredrik Holmqvist * Intel shall be used in advertising or otherwise to promote the sale, use or
770174267aSFredrik Holmqvist * other dealings in products derived from or relating to the Covered Code
780174267aSFredrik Holmqvist * without prior written authorization from Intel.
790174267aSFredrik Holmqvist *
800174267aSFredrik Holmqvist * 4. Disclaimer and Export Compliance
810174267aSFredrik Holmqvist *
820174267aSFredrik Holmqvist * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830174267aSFredrik Holmqvist * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840174267aSFredrik Holmqvist * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850174267aSFredrik Holmqvist * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860174267aSFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870174267aSFredrik Holmqvist * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880174267aSFredrik Holmqvist * PARTICULAR PURPOSE.
890174267aSFredrik Holmqvist *
900174267aSFredrik Holmqvist * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910174267aSFredrik Holmqvist * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920174267aSFredrik Holmqvist * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930174267aSFredrik Holmqvist * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940174267aSFredrik Holmqvist * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950174267aSFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960174267aSFredrik Holmqvist * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970174267aSFredrik Holmqvist * LIMITED REMEDY.
980174267aSFredrik Holmqvist *
990174267aSFredrik Holmqvist * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000174267aSFredrik Holmqvist * software or system incorporating such software without first obtaining any
1010174267aSFredrik Holmqvist * required license or other approval from the U. S. Department of Commerce or
1020174267aSFredrik Holmqvist * any other agency or department of the United States Government. In the
1030174267aSFredrik Holmqvist * event Licensee exports any such software from the United States or
1040174267aSFredrik Holmqvist * re-exports any such software from a foreign destination, Licensee shall
1050174267aSFredrik Holmqvist * ensure that the distribution and export/re-export of the software is in
1060174267aSFredrik Holmqvist * compliance with all laws, regulations, orders, or other restrictions of the
1070174267aSFredrik Holmqvist * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080174267aSFredrik Holmqvist * any of its subsidiaries will export/re-export any technical data, process,
1090174267aSFredrik Holmqvist * software, or service, directly or indirectly, to any country for which the
1100174267aSFredrik Holmqvist * United States government or any agency thereof requires an export license,
1110174267aSFredrik Holmqvist * other governmental approval, or letter of assurance, without first obtaining
1120174267aSFredrik Holmqvist * such license, approval or letter.
1130174267aSFredrik Holmqvist *
114ff2e2f81SFredrik Holmqvist *****************************************************************************
115ff2e2f81SFredrik Holmqvist *
116ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist * following license:
118ff2e2f81SFredrik Holmqvist *
119ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist * are met:
122ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist * notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist * without modification.
125ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist * substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist * ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist * including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist * binary redistribution.
130ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist * of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist * from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist *
134ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist *
146ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist * Software Foundation.
149ff2e2f81SFredrik Holmqvist *
1500174267aSFredrik Holmqvist *****************************************************************************/
1510174267aSFredrik Holmqvist
1520174267aSFredrik Holmqvist /*
1530174267aSFredrik Holmqvist * These procedures are used for tracking memory leaks in the subsystem, and
1540174267aSFredrik Holmqvist * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
1550174267aSFredrik Holmqvist *
1560174267aSFredrik Holmqvist * Each memory allocation is tracked via a doubly linked list. Each
1570174267aSFredrik Holmqvist * element contains the caller's component, module name, function name, and
1580174267aSFredrik Holmqvist * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call
1590174267aSFredrik Holmqvist * AcpiUtTrackAllocation to add an element to the list; deletion
1600174267aSFredrik Holmqvist * occurs in the body of AcpiUtFree.
1610174267aSFredrik Holmqvist */
1620174267aSFredrik Holmqvist
1630174267aSFredrik Holmqvist #include "acpi.h"
1640174267aSFredrik Holmqvist #include "accommon.h"
1650174267aSFredrik Holmqvist
1660174267aSFredrik Holmqvist #ifdef ACPI_DBG_TRACK_ALLOCATIONS
1670174267aSFredrik Holmqvist
1680174267aSFredrik Holmqvist #define _COMPONENT ACPI_UTILITIES
1690174267aSFredrik Holmqvist ACPI_MODULE_NAME ("uttrack")
1700174267aSFredrik Holmqvist
1719b0d045cSFredrik Holmqvist
1720174267aSFredrik Holmqvist /* Local prototypes */
1730174267aSFredrik Holmqvist
1740174267aSFredrik Holmqvist static ACPI_DEBUG_MEM_BLOCK *
1750174267aSFredrik Holmqvist AcpiUtFindAllocation (
1769b0d045cSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Allocation);
1770174267aSFredrik Holmqvist
1780174267aSFredrik Holmqvist static ACPI_STATUS
1790174267aSFredrik Holmqvist AcpiUtTrackAllocation (
1800174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Address,
1810174267aSFredrik Holmqvist ACPI_SIZE Size,
1820174267aSFredrik Holmqvist UINT8 AllocType,
1830174267aSFredrik Holmqvist UINT32 Component,
1840174267aSFredrik Holmqvist const char *Module,
1850174267aSFredrik Holmqvist UINT32 Line);
1860174267aSFredrik Holmqvist
1870174267aSFredrik Holmqvist static ACPI_STATUS
1880174267aSFredrik Holmqvist AcpiUtRemoveAllocation (
1890174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Address,
1900174267aSFredrik Holmqvist UINT32 Component,
1910174267aSFredrik Holmqvist const char *Module,
1920174267aSFredrik Holmqvist UINT32 Line);
1930174267aSFredrik Holmqvist
1940174267aSFredrik Holmqvist
1950174267aSFredrik Holmqvist /*******************************************************************************
1960174267aSFredrik Holmqvist *
1970174267aSFredrik Holmqvist * FUNCTION: AcpiUtCreateList
1980174267aSFredrik Holmqvist *
1990174267aSFredrik Holmqvist * PARAMETERS: CacheName - Ascii name for the cache
2000174267aSFredrik Holmqvist * ObjectSize - Size of each cached object
2010174267aSFredrik Holmqvist * ReturnCache - Where the new cache object is returned
2020174267aSFredrik Holmqvist *
2030174267aSFredrik Holmqvist * RETURN: Status
2040174267aSFredrik Holmqvist *
2050174267aSFredrik Holmqvist * DESCRIPTION: Create a local memory list for tracking purposed
2060174267aSFredrik Holmqvist *
2070174267aSFredrik Holmqvist ******************************************************************************/
2080174267aSFredrik Holmqvist
2090174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtCreateList(const char * ListName,UINT16 ObjectSize,ACPI_MEMORY_LIST ** ReturnCache)2100174267aSFredrik Holmqvist AcpiUtCreateList (
21174ffd18dSFredrik Holmqvist const char *ListName,
2120174267aSFredrik Holmqvist UINT16 ObjectSize,
2130174267aSFredrik Holmqvist ACPI_MEMORY_LIST **ReturnCache)
2140174267aSFredrik Holmqvist {
2150174267aSFredrik Holmqvist ACPI_MEMORY_LIST *Cache;
2160174267aSFredrik Holmqvist
2170174267aSFredrik Holmqvist
21874ffd18dSFredrik Holmqvist Cache = AcpiOsAllocateZeroed (sizeof (ACPI_MEMORY_LIST));
2190174267aSFredrik Holmqvist if (!Cache)
2200174267aSFredrik Holmqvist {
2210174267aSFredrik Holmqvist return (AE_NO_MEMORY);
2220174267aSFredrik Holmqvist }
2230174267aSFredrik Holmqvist
2240174267aSFredrik Holmqvist Cache->ListName = ListName;
2250174267aSFredrik Holmqvist Cache->ObjectSize = ObjectSize;
2260174267aSFredrik Holmqvist
2270174267aSFredrik Holmqvist *ReturnCache = Cache;
2280174267aSFredrik Holmqvist return (AE_OK);
2290174267aSFredrik Holmqvist }
2300174267aSFredrik Holmqvist
2310174267aSFredrik Holmqvist
2320174267aSFredrik Holmqvist /*******************************************************************************
2330174267aSFredrik Holmqvist *
2340174267aSFredrik Holmqvist * FUNCTION: AcpiUtAllocateAndTrack
2350174267aSFredrik Holmqvist *
2360174267aSFredrik Holmqvist * PARAMETERS: Size - Size of the allocation
2370174267aSFredrik Holmqvist * Component - Component type of caller
2380174267aSFredrik Holmqvist * Module - Source file name of caller
2390174267aSFredrik Holmqvist * Line - Line number of caller
2400174267aSFredrik Holmqvist *
2410174267aSFredrik Holmqvist * RETURN: Address of the allocated memory on success, NULL on failure.
2420174267aSFredrik Holmqvist *
2430174267aSFredrik Holmqvist * DESCRIPTION: The subsystem's equivalent of malloc.
2440174267aSFredrik Holmqvist *
2450174267aSFredrik Holmqvist ******************************************************************************/
2460174267aSFredrik Holmqvist
2470174267aSFredrik Holmqvist void *
AcpiUtAllocateAndTrack(ACPI_SIZE Size,UINT32 Component,const char * Module,UINT32 Line)2480174267aSFredrik Holmqvist AcpiUtAllocateAndTrack (
2490174267aSFredrik Holmqvist ACPI_SIZE Size,
2500174267aSFredrik Holmqvist UINT32 Component,
2510174267aSFredrik Holmqvist const char *Module,
2520174267aSFredrik Holmqvist UINT32 Line)
2530174267aSFredrik Holmqvist {
2540174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Allocation;
2550174267aSFredrik Holmqvist ACPI_STATUS Status;
2560174267aSFredrik Holmqvist
2570174267aSFredrik Holmqvist
258ad5bbfb8SFredrik Holmqvist /* Check for an inadvertent size of zero bytes */
259ad5bbfb8SFredrik Holmqvist
260ad5bbfb8SFredrik Holmqvist if (!Size)
261ad5bbfb8SFredrik Holmqvist {
262ad5bbfb8SFredrik Holmqvist ACPI_WARNING ((Module, Line,
263ad5bbfb8SFredrik Holmqvist "Attempt to allocate zero bytes, allocating 1 byte"));
264ad5bbfb8SFredrik Holmqvist Size = 1;
265ad5bbfb8SFredrik Holmqvist }
266ad5bbfb8SFredrik Holmqvist
267ad5bbfb8SFredrik Holmqvist Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
2680174267aSFredrik Holmqvist if (!Allocation)
2690174267aSFredrik Holmqvist {
270ad5bbfb8SFredrik Holmqvist /* Report allocation error */
271ad5bbfb8SFredrik Holmqvist
272ad5bbfb8SFredrik Holmqvist ACPI_WARNING ((Module, Line,
273ad5bbfb8SFredrik Holmqvist "Could not allocate size %u", (UINT32) Size));
274ad5bbfb8SFredrik Holmqvist
2750174267aSFredrik Holmqvist return (NULL);
2760174267aSFredrik Holmqvist }
2770174267aSFredrik Holmqvist
278b64e8511SFredrik Holmqvist Status = AcpiUtTrackAllocation (
279b64e8511SFredrik Holmqvist Allocation, Size, ACPI_MEM_MALLOC, Component, Module, Line);
2800174267aSFredrik Holmqvist if (ACPI_FAILURE (Status))
2810174267aSFredrik Holmqvist {
2820174267aSFredrik Holmqvist AcpiOsFree (Allocation);
2830174267aSFredrik Holmqvist return (NULL);
2840174267aSFredrik Holmqvist }
2850174267aSFredrik Holmqvist
2860174267aSFredrik Holmqvist AcpiGbl_GlobalList->TotalAllocated++;
2870174267aSFredrik Holmqvist AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
2880174267aSFredrik Holmqvist AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
289b64e8511SFredrik Holmqvist
290b64e8511SFredrik Holmqvist if (AcpiGbl_GlobalList->CurrentTotalSize >
291b64e8511SFredrik Holmqvist AcpiGbl_GlobalList->MaxOccupied)
2920174267aSFredrik Holmqvist {
293b64e8511SFredrik Holmqvist AcpiGbl_GlobalList->MaxOccupied =
294b64e8511SFredrik Holmqvist AcpiGbl_GlobalList->CurrentTotalSize;
2950174267aSFredrik Holmqvist }
2960174267aSFredrik Holmqvist
2970174267aSFredrik Holmqvist return ((void *) &Allocation->UserSpace);
2980174267aSFredrik Holmqvist }
2990174267aSFredrik Holmqvist
3000174267aSFredrik Holmqvist
3010174267aSFredrik Holmqvist /*******************************************************************************
3020174267aSFredrik Holmqvist *
3030174267aSFredrik Holmqvist * FUNCTION: AcpiUtAllocateZeroedAndTrack
3040174267aSFredrik Holmqvist *
3050174267aSFredrik Holmqvist * PARAMETERS: Size - Size of the allocation
3060174267aSFredrik Holmqvist * Component - Component type of caller
3070174267aSFredrik Holmqvist * Module - Source file name of caller
3080174267aSFredrik Holmqvist * Line - Line number of caller
3090174267aSFredrik Holmqvist *
3100174267aSFredrik Holmqvist * RETURN: Address of the allocated memory on success, NULL on failure.
3110174267aSFredrik Holmqvist *
3120174267aSFredrik Holmqvist * DESCRIPTION: Subsystem equivalent of calloc.
3130174267aSFredrik Holmqvist *
3140174267aSFredrik Holmqvist ******************************************************************************/
3150174267aSFredrik Holmqvist
3160174267aSFredrik Holmqvist void *
AcpiUtAllocateZeroedAndTrack(ACPI_SIZE Size,UINT32 Component,const char * Module,UINT32 Line)3170174267aSFredrik Holmqvist AcpiUtAllocateZeroedAndTrack (
3180174267aSFredrik Holmqvist ACPI_SIZE Size,
3190174267aSFredrik Holmqvist UINT32 Component,
3200174267aSFredrik Holmqvist const char *Module,
3210174267aSFredrik Holmqvist UINT32 Line)
3220174267aSFredrik Holmqvist {
3230174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Allocation;
3240174267aSFredrik Holmqvist ACPI_STATUS Status;
3250174267aSFredrik Holmqvist
3260174267aSFredrik Holmqvist
327ad5bbfb8SFredrik Holmqvist /* Check for an inadvertent size of zero bytes */
328ad5bbfb8SFredrik Holmqvist
329ad5bbfb8SFredrik Holmqvist if (!Size)
330ad5bbfb8SFredrik Holmqvist {
331ad5bbfb8SFredrik Holmqvist ACPI_WARNING ((Module, Line,
332ad5bbfb8SFredrik Holmqvist "Attempt to allocate zero bytes, allocating 1 byte"));
333ad5bbfb8SFredrik Holmqvist Size = 1;
334ad5bbfb8SFredrik Holmqvist }
335ad5bbfb8SFredrik Holmqvist
336b64e8511SFredrik Holmqvist Allocation = AcpiOsAllocateZeroed (
337b64e8511SFredrik Holmqvist Size + sizeof (ACPI_DEBUG_MEM_HEADER));
3380174267aSFredrik Holmqvist if (!Allocation)
3390174267aSFredrik Holmqvist {
3400174267aSFredrik Holmqvist /* Report allocation error */
3410174267aSFredrik Holmqvist
3420174267aSFredrik Holmqvist ACPI_ERROR ((Module, Line,
3430174267aSFredrik Holmqvist "Could not allocate size %u", (UINT32) Size));
3440174267aSFredrik Holmqvist return (NULL);
3450174267aSFredrik Holmqvist }
3460174267aSFredrik Holmqvist
3470174267aSFredrik Holmqvist Status = AcpiUtTrackAllocation (Allocation, Size,
3480174267aSFredrik Holmqvist ACPI_MEM_CALLOC, Component, Module, Line);
3490174267aSFredrik Holmqvist if (ACPI_FAILURE (Status))
3500174267aSFredrik Holmqvist {
3510174267aSFredrik Holmqvist AcpiOsFree (Allocation);
3520174267aSFredrik Holmqvist return (NULL);
3530174267aSFredrik Holmqvist }
3540174267aSFredrik Holmqvist
3550174267aSFredrik Holmqvist AcpiGbl_GlobalList->TotalAllocated++;
3560174267aSFredrik Holmqvist AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
3570174267aSFredrik Holmqvist AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
358b64e8511SFredrik Holmqvist
359b64e8511SFredrik Holmqvist if (AcpiGbl_GlobalList->CurrentTotalSize >
360b64e8511SFredrik Holmqvist AcpiGbl_GlobalList->MaxOccupied)
3610174267aSFredrik Holmqvist {
362b64e8511SFredrik Holmqvist AcpiGbl_GlobalList->MaxOccupied =
363b64e8511SFredrik Holmqvist AcpiGbl_GlobalList->CurrentTotalSize;
3640174267aSFredrik Holmqvist }
3650174267aSFredrik Holmqvist
3660174267aSFredrik Holmqvist return ((void *) &Allocation->UserSpace);
3670174267aSFredrik Holmqvist }
3680174267aSFredrik Holmqvist
3690174267aSFredrik Holmqvist
3700174267aSFredrik Holmqvist /*******************************************************************************
3710174267aSFredrik Holmqvist *
3720174267aSFredrik Holmqvist * FUNCTION: AcpiUtFreeAndTrack
3730174267aSFredrik Holmqvist *
3740174267aSFredrik Holmqvist * PARAMETERS: Allocation - Address of the memory to deallocate
3750174267aSFredrik Holmqvist * Component - Component type of caller
3760174267aSFredrik Holmqvist * Module - Source file name of caller
3770174267aSFredrik Holmqvist * Line - Line number of caller
3780174267aSFredrik Holmqvist *
3790174267aSFredrik Holmqvist * RETURN: None
3800174267aSFredrik Holmqvist *
3810174267aSFredrik Holmqvist * DESCRIPTION: Frees the memory at Allocation
3820174267aSFredrik Holmqvist *
3830174267aSFredrik Holmqvist ******************************************************************************/
3840174267aSFredrik Holmqvist
3850174267aSFredrik Holmqvist void
AcpiUtFreeAndTrack(void * Allocation,UINT32 Component,const char * Module,UINT32 Line)3860174267aSFredrik Holmqvist AcpiUtFreeAndTrack (
3870174267aSFredrik Holmqvist void *Allocation,
3880174267aSFredrik Holmqvist UINT32 Component,
3890174267aSFredrik Holmqvist const char *Module,
3900174267aSFredrik Holmqvist UINT32 Line)
3910174267aSFredrik Holmqvist {
3920174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *DebugBlock;
3930174267aSFredrik Holmqvist ACPI_STATUS Status;
3940174267aSFredrik Holmqvist
3950174267aSFredrik Holmqvist
3960174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation);
3970174267aSFredrik Holmqvist
3980174267aSFredrik Holmqvist
3990174267aSFredrik Holmqvist if (NULL == Allocation)
4000174267aSFredrik Holmqvist {
4010174267aSFredrik Holmqvist ACPI_ERROR ((Module, Line,
4020174267aSFredrik Holmqvist "Attempt to delete a NULL address"));
4030174267aSFredrik Holmqvist
4040174267aSFredrik Holmqvist return_VOID;
4050174267aSFredrik Holmqvist }
4060174267aSFredrik Holmqvist
4070174267aSFredrik Holmqvist DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
4080174267aSFredrik Holmqvist (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
4090174267aSFredrik Holmqvist
4100174267aSFredrik Holmqvist AcpiGbl_GlobalList->TotalFreed++;
4110174267aSFredrik Holmqvist AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
4120174267aSFredrik Holmqvist
413b64e8511SFredrik Holmqvist Status = AcpiUtRemoveAllocation (DebugBlock, Component, Module, Line);
4140174267aSFredrik Holmqvist if (ACPI_FAILURE (Status))
4150174267aSFredrik Holmqvist {
4160174267aSFredrik Holmqvist ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
4170174267aSFredrik Holmqvist }
4180174267aSFredrik Holmqvist
4190174267aSFredrik Holmqvist AcpiOsFree (DebugBlock);
420ad5bbfb8SFredrik Holmqvist ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n",
421ad5bbfb8SFredrik Holmqvist Allocation, DebugBlock));
4220174267aSFredrik Holmqvist return_VOID;
4230174267aSFredrik Holmqvist }
4240174267aSFredrik Holmqvist
4250174267aSFredrik Holmqvist
4260174267aSFredrik Holmqvist /*******************************************************************************
4270174267aSFredrik Holmqvist *
4280174267aSFredrik Holmqvist * FUNCTION: AcpiUtFindAllocation
4290174267aSFredrik Holmqvist *
4300174267aSFredrik Holmqvist * PARAMETERS: Allocation - Address of allocated memory
4310174267aSFredrik Holmqvist *
4329b0d045cSFredrik Holmqvist * RETURN: Three cases:
4339b0d045cSFredrik Holmqvist * 1) List is empty, NULL is returned.
4349b0d045cSFredrik Holmqvist * 2) Element was found. Returns Allocation parameter.
4359b0d045cSFredrik Holmqvist * 3) Element was not found. Returns position where it should be
4369b0d045cSFredrik Holmqvist * inserted into the list.
4370174267aSFredrik Holmqvist *
4380174267aSFredrik Holmqvist * DESCRIPTION: Searches for an element in the global allocation tracking list.
4399b0d045cSFredrik Holmqvist * If the element is not found, returns the location within the
4409b0d045cSFredrik Holmqvist * list where the element should be inserted.
4419b0d045cSFredrik Holmqvist *
4429b0d045cSFredrik Holmqvist * Note: The list is ordered by larger-to-smaller addresses.
4439b0d045cSFredrik Holmqvist *
4449b0d045cSFredrik Holmqvist * This global list is used to detect memory leaks in ACPICA as
4459b0d045cSFredrik Holmqvist * well as other issues such as an attempt to release the same
4469b0d045cSFredrik Holmqvist * internal object more than once. Although expensive as far
4479b0d045cSFredrik Holmqvist * as cpu time, this list is much more helpful for finding these
4489b0d045cSFredrik Holmqvist * types of issues than using memory leak detectors outside of
4499b0d045cSFredrik Holmqvist * the ACPICA code.
4500174267aSFredrik Holmqvist *
4510174267aSFredrik Holmqvist ******************************************************************************/
4520174267aSFredrik Holmqvist
4530174267aSFredrik Holmqvist static ACPI_DEBUG_MEM_BLOCK *
AcpiUtFindAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation)4540174267aSFredrik Holmqvist AcpiUtFindAllocation (
4559b0d045cSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Allocation)
4560174267aSFredrik Holmqvist {
4570174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Element;
4580174267aSFredrik Holmqvist
4590174267aSFredrik Holmqvist
4600174267aSFredrik Holmqvist Element = AcpiGbl_GlobalList->ListHead;
4619b0d045cSFredrik Holmqvist if (!Element)
4620174267aSFredrik Holmqvist {
4639b0d045cSFredrik Holmqvist return (NULL);
4649b0d045cSFredrik Holmqvist }
4659b0d045cSFredrik Holmqvist
4669b0d045cSFredrik Holmqvist /*
4679b0d045cSFredrik Holmqvist * Search for the address.
4689b0d045cSFredrik Holmqvist *
4699b0d045cSFredrik Holmqvist * Note: List is ordered by larger-to-smaller addresses, on the
4709b0d045cSFredrik Holmqvist * assumption that a new allocation usually has a larger address
4719b0d045cSFredrik Holmqvist * than previous allocations.
4729b0d045cSFredrik Holmqvist */
4739b0d045cSFredrik Holmqvist while (Element > Allocation)
4749b0d045cSFredrik Holmqvist {
4759b0d045cSFredrik Holmqvist /* Check for end-of-list */
4769b0d045cSFredrik Holmqvist
4779b0d045cSFredrik Holmqvist if (!Element->Next)
4780174267aSFredrik Holmqvist {
4790174267aSFredrik Holmqvist return (Element);
4800174267aSFredrik Holmqvist }
4810174267aSFredrik Holmqvist
4820174267aSFredrik Holmqvist Element = Element->Next;
4830174267aSFredrik Holmqvist }
4840174267aSFredrik Holmqvist
4859b0d045cSFredrik Holmqvist if (Element == Allocation)
4869b0d045cSFredrik Holmqvist {
4879b0d045cSFredrik Holmqvist return (Element);
4889b0d045cSFredrik Holmqvist }
4899b0d045cSFredrik Holmqvist
4909b0d045cSFredrik Holmqvist return (Element->Previous);
4910174267aSFredrik Holmqvist }
4920174267aSFredrik Holmqvist
4930174267aSFredrik Holmqvist
4940174267aSFredrik Holmqvist /*******************************************************************************
4950174267aSFredrik Holmqvist *
4960174267aSFredrik Holmqvist * FUNCTION: AcpiUtTrackAllocation
4970174267aSFredrik Holmqvist *
4980174267aSFredrik Holmqvist * PARAMETERS: Allocation - Address of allocated memory
4990174267aSFredrik Holmqvist * Size - Size of the allocation
5000174267aSFredrik Holmqvist * AllocType - MEM_MALLOC or MEM_CALLOC
5010174267aSFredrik Holmqvist * Component - Component type of caller
5020174267aSFredrik Holmqvist * Module - Source file name of caller
5030174267aSFredrik Holmqvist * Line - Line number of caller
5040174267aSFredrik Holmqvist *
5059b0d045cSFredrik Holmqvist * RETURN: Status
5060174267aSFredrik Holmqvist *
5070174267aSFredrik Holmqvist * DESCRIPTION: Inserts an element into the global allocation tracking list.
5080174267aSFredrik Holmqvist *
5090174267aSFredrik Holmqvist ******************************************************************************/
5100174267aSFredrik Holmqvist
5110174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtTrackAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation,ACPI_SIZE Size,UINT8 AllocType,UINT32 Component,const char * Module,UINT32 Line)5120174267aSFredrik Holmqvist AcpiUtTrackAllocation (
5130174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Allocation,
5140174267aSFredrik Holmqvist ACPI_SIZE Size,
5150174267aSFredrik Holmqvist UINT8 AllocType,
5160174267aSFredrik Holmqvist UINT32 Component,
5170174267aSFredrik Holmqvist const char *Module,
5180174267aSFredrik Holmqvist UINT32 Line)
5190174267aSFredrik Holmqvist {
5200174267aSFredrik Holmqvist ACPI_MEMORY_LIST *MemList;
5210174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Element;
5220174267aSFredrik Holmqvist ACPI_STATUS Status = AE_OK;
5230174267aSFredrik Holmqvist
5240174267aSFredrik Holmqvist
5250174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
5260174267aSFredrik Holmqvist
5270174267aSFredrik Holmqvist
5280174267aSFredrik Holmqvist if (AcpiGbl_DisableMemTracking)
5290174267aSFredrik Holmqvist {
5300174267aSFredrik Holmqvist return_ACPI_STATUS (AE_OK);
5310174267aSFredrik Holmqvist }
5320174267aSFredrik Holmqvist
5330174267aSFredrik Holmqvist MemList = AcpiGbl_GlobalList;
5340174267aSFredrik Holmqvist Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
5350174267aSFredrik Holmqvist if (ACPI_FAILURE (Status))
5360174267aSFredrik Holmqvist {
5370174267aSFredrik Holmqvist return_ACPI_STATUS (Status);
5380174267aSFredrik Holmqvist }
5390174267aSFredrik Holmqvist
5400174267aSFredrik Holmqvist /*
5419b0d045cSFredrik Holmqvist * Search the global list for this address to make sure it is not
5429b0d045cSFredrik Holmqvist * already present. This will catch several kinds of problems.
5430174267aSFredrik Holmqvist */
5440174267aSFredrik Holmqvist Element = AcpiUtFindAllocation (Allocation);
5459b0d045cSFredrik Holmqvist if (Element == Allocation)
5460174267aSFredrik Holmqvist {
5470174267aSFredrik Holmqvist ACPI_ERROR ((AE_INFO,
5489b0d045cSFredrik Holmqvist "UtTrackAllocation: Allocation (%p) already present in global list!",
5490174267aSFredrik Holmqvist Allocation));
5500174267aSFredrik Holmqvist goto UnlockAndExit;
5510174267aSFredrik Holmqvist }
5520174267aSFredrik Holmqvist
5539b0d045cSFredrik Holmqvist /* Fill in the instance data */
5540174267aSFredrik Holmqvist
5550174267aSFredrik Holmqvist Allocation->Size = (UINT32) Size;
5560174267aSFredrik Holmqvist Allocation->AllocType = AllocType;
5570174267aSFredrik Holmqvist Allocation->Component = Component;
5580174267aSFredrik Holmqvist Allocation->Line = Line;
5590174267aSFredrik Holmqvist
560ff2e2f81SFredrik Holmqvist AcpiUtSafeStrncpy (Allocation->Module, (char *) Module, ACPI_MAX_MODULE_NAME);
5610174267aSFredrik Holmqvist
5629b0d045cSFredrik Holmqvist if (!Element)
5639b0d045cSFredrik Holmqvist {
5640174267aSFredrik Holmqvist /* Insert at list head */
5650174267aSFredrik Holmqvist
5660174267aSFredrik Holmqvist if (MemList->ListHead)
5670174267aSFredrik Holmqvist {
568b64e8511SFredrik Holmqvist ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous =
569b64e8511SFredrik Holmqvist Allocation;
5700174267aSFredrik Holmqvist }
5710174267aSFredrik Holmqvist
5720174267aSFredrik Holmqvist Allocation->Next = MemList->ListHead;
5730174267aSFredrik Holmqvist Allocation->Previous = NULL;
5740174267aSFredrik Holmqvist
5750174267aSFredrik Holmqvist MemList->ListHead = Allocation;
5769b0d045cSFredrik Holmqvist }
5779b0d045cSFredrik Holmqvist else
5789b0d045cSFredrik Holmqvist {
5799b0d045cSFredrik Holmqvist /* Insert after element */
5809b0d045cSFredrik Holmqvist
5819b0d045cSFredrik Holmqvist Allocation->Next = Element->Next;
5829b0d045cSFredrik Holmqvist Allocation->Previous = Element;
5839b0d045cSFredrik Holmqvist
5849b0d045cSFredrik Holmqvist if (Element->Next)
5859b0d045cSFredrik Holmqvist {
5869b0d045cSFredrik Holmqvist (Element->Next)->Previous = Allocation;
5879b0d045cSFredrik Holmqvist }
5889b0d045cSFredrik Holmqvist
5899b0d045cSFredrik Holmqvist Element->Next = Allocation;
5909b0d045cSFredrik Holmqvist }
5910174267aSFredrik Holmqvist
5920174267aSFredrik Holmqvist
5930174267aSFredrik Holmqvist UnlockAndExit:
5940174267aSFredrik Holmqvist Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
5950174267aSFredrik Holmqvist return_ACPI_STATUS (Status);
5960174267aSFredrik Holmqvist }
5970174267aSFredrik Holmqvist
5980174267aSFredrik Holmqvist
5990174267aSFredrik Holmqvist /*******************************************************************************
6000174267aSFredrik Holmqvist *
6010174267aSFredrik Holmqvist * FUNCTION: AcpiUtRemoveAllocation
6020174267aSFredrik Holmqvist *
6030174267aSFredrik Holmqvist * PARAMETERS: Allocation - Address of allocated memory
6040174267aSFredrik Holmqvist * Component - Component type of caller
6050174267aSFredrik Holmqvist * Module - Source file name of caller
6060174267aSFredrik Holmqvist * Line - Line number of caller
6070174267aSFredrik Holmqvist *
6089b0d045cSFredrik Holmqvist * RETURN: Status
6090174267aSFredrik Holmqvist *
6100174267aSFredrik Holmqvist * DESCRIPTION: Deletes an element from the global allocation tracking list.
6110174267aSFredrik Holmqvist *
6120174267aSFredrik Holmqvist ******************************************************************************/
6130174267aSFredrik Holmqvist
6140174267aSFredrik Holmqvist static ACPI_STATUS
AcpiUtRemoveAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation,UINT32 Component,const char * Module,UINT32 Line)6150174267aSFredrik Holmqvist AcpiUtRemoveAllocation (
6160174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Allocation,
6170174267aSFredrik Holmqvist UINT32 Component,
6180174267aSFredrik Holmqvist const char *Module,
6190174267aSFredrik Holmqvist UINT32 Line)
6200174267aSFredrik Holmqvist {
6210174267aSFredrik Holmqvist ACPI_MEMORY_LIST *MemList;
6220174267aSFredrik Holmqvist ACPI_STATUS Status;
6230174267aSFredrik Holmqvist
6240174267aSFredrik Holmqvist
625c70258b7SJérôme Duval ACPI_FUNCTION_NAME (UtRemoveAllocation);
6260174267aSFredrik Holmqvist
6270174267aSFredrik Holmqvist
6280174267aSFredrik Holmqvist if (AcpiGbl_DisableMemTracking)
6290174267aSFredrik Holmqvist {
630c70258b7SJérôme Duval return (AE_OK);
6310174267aSFredrik Holmqvist }
6320174267aSFredrik Holmqvist
6330174267aSFredrik Holmqvist MemList = AcpiGbl_GlobalList;
6340174267aSFredrik Holmqvist if (NULL == MemList->ListHead)
6350174267aSFredrik Holmqvist {
6360174267aSFredrik Holmqvist /* No allocations! */
6370174267aSFredrik Holmqvist
6380174267aSFredrik Holmqvist ACPI_ERROR ((Module, Line,
6390174267aSFredrik Holmqvist "Empty allocation list, nothing to free!"));
6400174267aSFredrik Holmqvist
641c70258b7SJérôme Duval return (AE_OK);
6420174267aSFredrik Holmqvist }
6430174267aSFredrik Holmqvist
6440174267aSFredrik Holmqvist Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
6450174267aSFredrik Holmqvist if (ACPI_FAILURE (Status))
6460174267aSFredrik Holmqvist {
647c70258b7SJérôme Duval return (Status);
6480174267aSFredrik Holmqvist }
6490174267aSFredrik Holmqvist
6500174267aSFredrik Holmqvist /* Unlink */
6510174267aSFredrik Holmqvist
6520174267aSFredrik Holmqvist if (Allocation->Previous)
6530174267aSFredrik Holmqvist {
6540174267aSFredrik Holmqvist (Allocation->Previous)->Next = Allocation->Next;
6550174267aSFredrik Holmqvist }
6560174267aSFredrik Holmqvist else
6570174267aSFredrik Holmqvist {
6580174267aSFredrik Holmqvist MemList->ListHead = Allocation->Next;
6590174267aSFredrik Holmqvist }
6600174267aSFredrik Holmqvist
6610174267aSFredrik Holmqvist if (Allocation->Next)
6620174267aSFredrik Holmqvist {
6630174267aSFredrik Holmqvist (Allocation->Next)->Previous = Allocation->Previous;
6640174267aSFredrik Holmqvist }
6650174267aSFredrik Holmqvist
666c70258b7SJérôme Duval ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
667c70258b7SJérôme Duval &Allocation->UserSpace, Allocation->Size));
668c70258b7SJérôme Duval
6690174267aSFredrik Holmqvist /* Mark the segment as deleted */
6700174267aSFredrik Holmqvist
671e226d1d0SFredrik Holmqvist memset (&Allocation->UserSpace, 0xEA, Allocation->Size);
6720174267aSFredrik Holmqvist
6730174267aSFredrik Holmqvist Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
674c70258b7SJérôme Duval return (Status);
6750174267aSFredrik Holmqvist }
6760174267aSFredrik Holmqvist
6770174267aSFredrik Holmqvist
6780174267aSFredrik Holmqvist /*******************************************************************************
6790174267aSFredrik Holmqvist *
6800174267aSFredrik Holmqvist * FUNCTION: AcpiUtDumpAllocationInfo
6810174267aSFredrik Holmqvist *
6829b0d045cSFredrik Holmqvist * PARAMETERS: None
6830174267aSFredrik Holmqvist *
6840174267aSFredrik Holmqvist * RETURN: None
6850174267aSFredrik Holmqvist *
6860174267aSFredrik Holmqvist * DESCRIPTION: Print some info about the outstanding allocations.
6870174267aSFredrik Holmqvist *
6880174267aSFredrik Holmqvist ******************************************************************************/
6890174267aSFredrik Holmqvist
6900174267aSFredrik Holmqvist void
AcpiUtDumpAllocationInfo(void)6910174267aSFredrik Holmqvist AcpiUtDumpAllocationInfo (
6920174267aSFredrik Holmqvist void)
6930174267aSFredrik Holmqvist {
6940174267aSFredrik Holmqvist /*
6950174267aSFredrik Holmqvist ACPI_MEMORY_LIST *MemList;
6960174267aSFredrik Holmqvist */
6970174267aSFredrik Holmqvist
6980174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE (UtDumpAllocationInfo);
6990174267aSFredrik Holmqvist
7000174267aSFredrik Holmqvist /*
7010174267aSFredrik Holmqvist ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
7020174267aSFredrik Holmqvist ("%30s: %4d (%3d Kb)\n", "Current allocations",
7030174267aSFredrik Holmqvist MemList->CurrentCount,
7040174267aSFredrik Holmqvist ROUND_UP_TO_1K (MemList->CurrentSize)));
7050174267aSFredrik Holmqvist
7060174267aSFredrik Holmqvist ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
7070174267aSFredrik Holmqvist ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
7080174267aSFredrik Holmqvist MemList->MaxConcurrentCount,
7090174267aSFredrik Holmqvist ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
7100174267aSFredrik Holmqvist
7110174267aSFredrik Holmqvist
7120174267aSFredrik Holmqvist ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
7130174267aSFredrik Holmqvist ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
7140174267aSFredrik Holmqvist RunningObjectCount,
7150174267aSFredrik Holmqvist ROUND_UP_TO_1K (RunningObjectSize)));
7160174267aSFredrik Holmqvist
7170174267aSFredrik Holmqvist ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
7180174267aSFredrik Holmqvist ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
7190174267aSFredrik Holmqvist RunningAllocCount,
7200174267aSFredrik Holmqvist ROUND_UP_TO_1K (RunningAllocSize)));
7210174267aSFredrik Holmqvist
7220174267aSFredrik Holmqvist
7230174267aSFredrik Holmqvist ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
7240174267aSFredrik Holmqvist ("%30s: %4d (%3d Kb)\n", "Current Nodes",
7250174267aSFredrik Holmqvist AcpiGbl_CurrentNodeCount,
7260174267aSFredrik Holmqvist ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
7270174267aSFredrik Holmqvist
7280174267aSFredrik Holmqvist ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
7290174267aSFredrik Holmqvist ("%30s: %4d (%3d Kb)\n", "Max Nodes",
7300174267aSFredrik Holmqvist AcpiGbl_MaxConcurrentNodeCount,
7310174267aSFredrik Holmqvist ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
7320174267aSFredrik Holmqvist sizeof (ACPI_NAMESPACE_NODE)))));
7330174267aSFredrik Holmqvist */
7340174267aSFredrik Holmqvist return_VOID;
7350174267aSFredrik Holmqvist }
7360174267aSFredrik Holmqvist
7370174267aSFredrik Holmqvist
7380174267aSFredrik Holmqvist /*******************************************************************************
7390174267aSFredrik Holmqvist *
7400174267aSFredrik Holmqvist * FUNCTION: AcpiUtDumpAllocations
7410174267aSFredrik Holmqvist *
7420174267aSFredrik Holmqvist * PARAMETERS: Component - Component(s) to dump info for.
7430174267aSFredrik Holmqvist * Module - Module to dump info for. NULL means all.
7440174267aSFredrik Holmqvist *
7450174267aSFredrik Holmqvist * RETURN: None
7460174267aSFredrik Holmqvist *
7470174267aSFredrik Holmqvist * DESCRIPTION: Print a list of all outstanding allocations.
7480174267aSFredrik Holmqvist *
7490174267aSFredrik Holmqvist ******************************************************************************/
7500174267aSFredrik Holmqvist
7510174267aSFredrik Holmqvist void
AcpiUtDumpAllocations(UINT32 Component,const char * Module)7520174267aSFredrik Holmqvist AcpiUtDumpAllocations (
7530174267aSFredrik Holmqvist UINT32 Component,
7540174267aSFredrik Holmqvist const char *Module)
7550174267aSFredrik Holmqvist {
7560174267aSFredrik Holmqvist ACPI_DEBUG_MEM_BLOCK *Element;
7570174267aSFredrik Holmqvist ACPI_DESCRIPTOR *Descriptor;
7580174267aSFredrik Holmqvist UINT32 NumOutstanding = 0;
7590174267aSFredrik Holmqvist UINT8 DescriptorType;
7600174267aSFredrik Holmqvist
7610174267aSFredrik Holmqvist
7620174267aSFredrik Holmqvist ACPI_FUNCTION_TRACE (UtDumpAllocations);
7630174267aSFredrik Holmqvist
7640174267aSFredrik Holmqvist
7650174267aSFredrik Holmqvist if (AcpiGbl_DisableMemTracking)
7660174267aSFredrik Holmqvist {
7679b0d045cSFredrik Holmqvist return_VOID;
7680174267aSFredrik Holmqvist }
7690174267aSFredrik Holmqvist
7700174267aSFredrik Holmqvist /*
7710174267aSFredrik Holmqvist * Walk the allocation list.
7720174267aSFredrik Holmqvist */
7730174267aSFredrik Holmqvist if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
7740174267aSFredrik Holmqvist {
7759b0d045cSFredrik Holmqvist return_VOID;
7760174267aSFredrik Holmqvist }
7770174267aSFredrik Holmqvist
778ff2e2f81SFredrik Holmqvist if (!AcpiGbl_GlobalList)
779ff2e2f81SFredrik Holmqvist {
780ff2e2f81SFredrik Holmqvist goto Exit;
781ff2e2f81SFredrik Holmqvist }
782ff2e2f81SFredrik Holmqvist
7830174267aSFredrik Holmqvist Element = AcpiGbl_GlobalList->ListHead;
7840174267aSFredrik Holmqvist while (Element)
7850174267aSFredrik Holmqvist {
7860174267aSFredrik Holmqvist if ((Element->Component & Component) &&
787e226d1d0SFredrik Holmqvist ((Module == NULL) || (0 == strcmp (Module, Element->Module))))
7880174267aSFredrik Holmqvist {
789b64e8511SFredrik Holmqvist Descriptor = ACPI_CAST_PTR (
790b64e8511SFredrik Holmqvist ACPI_DESCRIPTOR, &Element->UserSpace);
7910174267aSFredrik Holmqvist
7920174267aSFredrik Holmqvist if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR))
7930174267aSFredrik Holmqvist {
794ff2e2f81SFredrik Holmqvist AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u "
7950174267aSFredrik Holmqvist "[Not a Descriptor - too small]\n",
7960174267aSFredrik Holmqvist Descriptor, Element->Size, Element->Module,
7970174267aSFredrik Holmqvist Element->Line);
7980174267aSFredrik Holmqvist }
7990174267aSFredrik Holmqvist else
8000174267aSFredrik Holmqvist {
8010174267aSFredrik Holmqvist /* Ignore allocated objects that are in a cache */
8020174267aSFredrik Holmqvist
803b64e8511SFredrik Holmqvist if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) !=
804b64e8511SFredrik Holmqvist ACPI_DESC_TYPE_CACHED)
8050174267aSFredrik Holmqvist {
806ff2e2f81SFredrik Holmqvist AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u [%s] ",
8070174267aSFredrik Holmqvist Descriptor, Element->Size, Element->Module,
8080174267aSFredrik Holmqvist Element->Line, AcpiUtGetDescriptorName (Descriptor));
8090174267aSFredrik Holmqvist
8100ffed378SFredrik Holmqvist /* Optional object hex dump */
8110ffed378SFredrik Holmqvist
8120ffed378SFredrik Holmqvist if (AcpiGbl_VerboseLeakDump)
8130ffed378SFredrik Holmqvist {
8140ffed378SFredrik Holmqvist AcpiOsPrintf ("\n");
8150ffed378SFredrik Holmqvist AcpiUtDumpBuffer ((UINT8 *) Descriptor, Element->Size,
8160ffed378SFredrik Holmqvist DB_BYTE_DISPLAY, 0);
8170ffed378SFredrik Holmqvist }
8180ffed378SFredrik Holmqvist
8190174267aSFredrik Holmqvist /* Validate the descriptor type using Type field and length */
8200174267aSFredrik Holmqvist
8210174267aSFredrik Holmqvist DescriptorType = 0; /* Not a valid descriptor type */
8220174267aSFredrik Holmqvist
8230174267aSFredrik Holmqvist switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
8240174267aSFredrik Holmqvist {
8250174267aSFredrik Holmqvist case ACPI_DESC_TYPE_OPERAND:
826c70258b7SJérôme Duval
8276822cda0SFredrik Holmqvist if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
8280174267aSFredrik Holmqvist {
8290174267aSFredrik Holmqvist DescriptorType = ACPI_DESC_TYPE_OPERAND;
8300174267aSFredrik Holmqvist }
8310174267aSFredrik Holmqvist break;
8320174267aSFredrik Holmqvist
8330174267aSFredrik Holmqvist case ACPI_DESC_TYPE_PARSER:
834c70258b7SJérôme Duval
8356822cda0SFredrik Holmqvist if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
8360174267aSFredrik Holmqvist {
8370174267aSFredrik Holmqvist DescriptorType = ACPI_DESC_TYPE_PARSER;
8380174267aSFredrik Holmqvist }
8390174267aSFredrik Holmqvist break;
8400174267aSFredrik Holmqvist
8410174267aSFredrik Holmqvist case ACPI_DESC_TYPE_NAMED:
842c70258b7SJérôme Duval
8436822cda0SFredrik Holmqvist if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
8440174267aSFredrik Holmqvist {
8450174267aSFredrik Holmqvist DescriptorType = ACPI_DESC_TYPE_NAMED;
8460174267aSFredrik Holmqvist }
8470174267aSFredrik Holmqvist break;
8480174267aSFredrik Holmqvist
8490174267aSFredrik Holmqvist default:
850c70258b7SJérôme Duval
8510174267aSFredrik Holmqvist break;
8520174267aSFredrik Holmqvist }
8530174267aSFredrik Holmqvist
8540174267aSFredrik Holmqvist /* Display additional info for the major descriptor types */
8550174267aSFredrik Holmqvist
8560174267aSFredrik Holmqvist switch (DescriptorType)
8570174267aSFredrik Holmqvist {
8580174267aSFredrik Holmqvist case ACPI_DESC_TYPE_OPERAND:
859c70258b7SJérôme Duval
8600174267aSFredrik Holmqvist AcpiOsPrintf ("%12.12s RefCount 0x%04X\n",
8610174267aSFredrik Holmqvist AcpiUtGetTypeName (Descriptor->Object.Common.Type),
8620174267aSFredrik Holmqvist Descriptor->Object.Common.ReferenceCount);
8630174267aSFredrik Holmqvist break;
8640174267aSFredrik Holmqvist
8650174267aSFredrik Holmqvist case ACPI_DESC_TYPE_PARSER:
866c70258b7SJérôme Duval
8670ffed378SFredrik Holmqvist AcpiOsPrintf ("AmlOpcode 0x%04X\n",
8680174267aSFredrik Holmqvist Descriptor->Op.Asl.AmlOpcode);
8690174267aSFredrik Holmqvist break;
8700174267aSFredrik Holmqvist
8710174267aSFredrik Holmqvist case ACPI_DESC_TYPE_NAMED:
872c70258b7SJérôme Duval
8730174267aSFredrik Holmqvist AcpiOsPrintf ("%4.4s\n",
8740174267aSFredrik Holmqvist AcpiUtGetNodeName (&Descriptor->Node));
8750174267aSFredrik Holmqvist break;
8760174267aSFredrik Holmqvist
8770174267aSFredrik Holmqvist default:
878c70258b7SJérôme Duval
8790174267aSFredrik Holmqvist AcpiOsPrintf ( "\n");
8800174267aSFredrik Holmqvist break;
8810174267aSFredrik Holmqvist }
8820174267aSFredrik Holmqvist }
8830174267aSFredrik Holmqvist }
8840174267aSFredrik Holmqvist
8850174267aSFredrik Holmqvist NumOutstanding++;
8860174267aSFredrik Holmqvist }
8870174267aSFredrik Holmqvist
8880174267aSFredrik Holmqvist Element = Element->Next;
8890174267aSFredrik Holmqvist }
8900174267aSFredrik Holmqvist
891ff2e2f81SFredrik Holmqvist Exit:
8920174267aSFredrik Holmqvist (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
8930174267aSFredrik Holmqvist
8940174267aSFredrik Holmqvist /* Print summary */
8950174267aSFredrik Holmqvist
8960174267aSFredrik Holmqvist if (!NumOutstanding)
8970174267aSFredrik Holmqvist {
89874ffd18dSFredrik Holmqvist ACPI_INFO (("No outstanding allocations"));
8990174267aSFredrik Holmqvist }
9000174267aSFredrik Holmqvist else
9010174267aSFredrik Holmqvist {
902ff2e2f81SFredrik Holmqvist ACPI_ERROR ((AE_INFO, "%u (0x%X) Outstanding cache allocations",
9030174267aSFredrik Holmqvist NumOutstanding, NumOutstanding));
9040174267aSFredrik Holmqvist }
9050174267aSFredrik Holmqvist
9060174267aSFredrik Holmqvist return_VOID;
9070174267aSFredrik Holmqvist }
9080174267aSFredrik Holmqvist
9090174267aSFredrik Holmqvist #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
910