1a159c266SJung-uk Kim /******************************************************************************
2a159c266SJung-uk Kim *
3a159c266SJung-uk Kim * Module Name: uttrack - Memory allocation tracking routines (debug only)
4a159c266SJung-uk Kim *
5a159c266SJung-uk Kim *****************************************************************************/
6a159c266SJung-uk Kim
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim *
90d84335fSJung-uk Kim * 1. Copyright Notice
100d84335fSJung-uk Kim *
11*722b1667SJung-uk Kim * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12a159c266SJung-uk Kim * All rights reserved.
13a159c266SJung-uk Kim *
140d84335fSJung-uk Kim * 2. License
150d84335fSJung-uk Kim *
160d84335fSJung-uk Kim * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim * property rights.
200d84335fSJung-uk Kim *
210d84335fSJung-uk Kim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim *
280d84335fSJung-uk Kim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim *
370d84335fSJung-uk Kim * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim * conditions are met:
390d84335fSJung-uk Kim *
400d84335fSJung-uk Kim * 3. Conditions
410d84335fSJung-uk Kim *
420d84335fSJung-uk Kim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim *
540d84335fSJung-uk Kim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim * make.
650d84335fSJung-uk Kim *
660d84335fSJung-uk Kim * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim * distribution.
710d84335fSJung-uk Kim *
720d84335fSJung-uk Kim * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim * Intel Code.
740d84335fSJung-uk Kim *
750d84335fSJung-uk Kim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim * without prior written authorization from Intel.
790d84335fSJung-uk Kim *
800d84335fSJung-uk Kim * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim *
820d84335fSJung-uk Kim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim *
900d84335fSJung-uk Kim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim * LIMITED REMEDY.
980d84335fSJung-uk Kim *
990d84335fSJung-uk Kim * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim * such license, approval or letter.
1130d84335fSJung-uk Kim *
1140d84335fSJung-uk Kim *****************************************************************************
1150d84335fSJung-uk Kim *
1160d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim * following license:
1180d84335fSJung-uk Kim *
119a159c266SJung-uk Kim * Redistribution and use in source and binary forms, with or without
120a159c266SJung-uk Kim * modification, are permitted provided that the following conditions
121a159c266SJung-uk Kim * are met:
122a159c266SJung-uk Kim * 1. Redistributions of source code must retain the above copyright
123a159c266SJung-uk Kim * notice, this list of conditions, and the following disclaimer,
124a159c266SJung-uk Kim * without modification.
125a159c266SJung-uk Kim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126a159c266SJung-uk Kim * substantially similar to the "NO WARRANTY" disclaimer below
127a159c266SJung-uk Kim * ("Disclaimer") and any redistribution must be conditioned upon
128a159c266SJung-uk Kim * including a substantially similar Disclaimer requirement for further
129a159c266SJung-uk Kim * binary redistribution.
130a159c266SJung-uk Kim * 3. Neither the names of the above-listed copyright holders nor the names
131a159c266SJung-uk Kim * of any contributors may be used to endorse or promote products derived
132a159c266SJung-uk Kim * from this software without specific prior written permission.
133a159c266SJung-uk Kim *
1340d84335fSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim *
1460d84335fSJung-uk Kim * Alternatively, you may choose to be licensed under the terms of the
147a159c266SJung-uk Kim * GNU General Public License ("GPL") version 2 as published by the Free
148a159c266SJung-uk Kim * Software Foundation.
149a159c266SJung-uk Kim *
1500d84335fSJung-uk Kim *****************************************************************************/
151a159c266SJung-uk Kim
152a159c266SJung-uk Kim /*
153a159c266SJung-uk Kim * These procedures are used for tracking memory leaks in the subsystem, and
154a159c266SJung-uk Kim * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
155a159c266SJung-uk Kim *
156a159c266SJung-uk Kim * Each memory allocation is tracked via a doubly linked list. Each
157a159c266SJung-uk Kim * element contains the caller's component, module name, function name, and
158a159c266SJung-uk Kim * line number. AcpiUtAllocate and AcpiUtAllocateZeroed call
159a159c266SJung-uk Kim * AcpiUtTrackAllocation to add an element to the list; deletion
160a159c266SJung-uk Kim * occurs in the body of AcpiUtFree.
161a159c266SJung-uk Kim */
162a159c266SJung-uk Kim
163a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
164a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
165a159c266SJung-uk Kim
166a159c266SJung-uk Kim #ifdef ACPI_DBG_TRACK_ALLOCATIONS
167a159c266SJung-uk Kim
168a159c266SJung-uk Kim #define _COMPONENT ACPI_UTILITIES
169a159c266SJung-uk Kim ACPI_MODULE_NAME ("uttrack")
170a159c266SJung-uk Kim
1718ef1a331SJung-uk Kim
172a159c266SJung-uk Kim /* Local prototypes */
173a159c266SJung-uk Kim
174a159c266SJung-uk Kim static ACPI_DEBUG_MEM_BLOCK *
175a159c266SJung-uk Kim AcpiUtFindAllocation (
1768ef1a331SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Allocation);
177a159c266SJung-uk Kim
178a159c266SJung-uk Kim static ACPI_STATUS
179a159c266SJung-uk Kim AcpiUtTrackAllocation (
180a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Address,
181a159c266SJung-uk Kim ACPI_SIZE Size,
182a159c266SJung-uk Kim UINT8 AllocType,
183a159c266SJung-uk Kim UINT32 Component,
184a159c266SJung-uk Kim const char *Module,
185a159c266SJung-uk Kim UINT32 Line);
186a159c266SJung-uk Kim
187a159c266SJung-uk Kim static ACPI_STATUS
188a159c266SJung-uk Kim AcpiUtRemoveAllocation (
189a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Address,
190a159c266SJung-uk Kim UINT32 Component,
191a159c266SJung-uk Kim const char *Module,
192a159c266SJung-uk Kim UINT32 Line);
193a159c266SJung-uk Kim
194a159c266SJung-uk Kim
195a159c266SJung-uk Kim /*******************************************************************************
196a159c266SJung-uk Kim *
197a159c266SJung-uk Kim * FUNCTION: AcpiUtCreateList
198a159c266SJung-uk Kim *
199a159c266SJung-uk Kim * PARAMETERS: CacheName - Ascii name for the cache
200a159c266SJung-uk Kim * ObjectSize - Size of each cached object
201a159c266SJung-uk Kim * ReturnCache - Where the new cache object is returned
202a159c266SJung-uk Kim *
203a159c266SJung-uk Kim * RETURN: Status
204a159c266SJung-uk Kim *
205a159c266SJung-uk Kim * DESCRIPTION: Create a local memory list for tracking purposed
206a159c266SJung-uk Kim *
207a159c266SJung-uk Kim ******************************************************************************/
208a159c266SJung-uk Kim
209a159c266SJung-uk Kim ACPI_STATUS
AcpiUtCreateList(const char * ListName,UINT16 ObjectSize,ACPI_MEMORY_LIST ** ReturnCache)210a159c266SJung-uk Kim AcpiUtCreateList (
211f8146b88SJung-uk Kim const char *ListName,
212a159c266SJung-uk Kim UINT16 ObjectSize,
213a159c266SJung-uk Kim ACPI_MEMORY_LIST **ReturnCache)
214a159c266SJung-uk Kim {
215a159c266SJung-uk Kim ACPI_MEMORY_LIST *Cache;
216a159c266SJung-uk Kim
217a159c266SJung-uk Kim
218493deb39SJung-uk Kim Cache = AcpiOsAllocateZeroed (sizeof (ACPI_MEMORY_LIST));
219a159c266SJung-uk Kim if (!Cache)
220a159c266SJung-uk Kim {
221a159c266SJung-uk Kim return (AE_NO_MEMORY);
222a159c266SJung-uk Kim }
223a159c266SJung-uk Kim
224a159c266SJung-uk Kim Cache->ListName = ListName;
225a159c266SJung-uk Kim Cache->ObjectSize = ObjectSize;
226a159c266SJung-uk Kim
227a159c266SJung-uk Kim *ReturnCache = Cache;
228a159c266SJung-uk Kim return (AE_OK);
229a159c266SJung-uk Kim }
230a159c266SJung-uk Kim
231a159c266SJung-uk Kim
232a159c266SJung-uk Kim /*******************************************************************************
233a159c266SJung-uk Kim *
234a159c266SJung-uk Kim * FUNCTION: AcpiUtAllocateAndTrack
235a159c266SJung-uk Kim *
236a159c266SJung-uk Kim * PARAMETERS: Size - Size of the allocation
237a159c266SJung-uk Kim * Component - Component type of caller
238a159c266SJung-uk Kim * Module - Source file name of caller
239a159c266SJung-uk Kim * Line - Line number of caller
240a159c266SJung-uk Kim *
241a159c266SJung-uk Kim * RETURN: Address of the allocated memory on success, NULL on failure.
242a159c266SJung-uk Kim *
243a159c266SJung-uk Kim * DESCRIPTION: The subsystem's equivalent of malloc.
244a159c266SJung-uk Kim *
245a159c266SJung-uk Kim ******************************************************************************/
246a159c266SJung-uk Kim
247a159c266SJung-uk Kim void *
AcpiUtAllocateAndTrack(ACPI_SIZE Size,UINT32 Component,const char * Module,UINT32 Line)248a159c266SJung-uk Kim AcpiUtAllocateAndTrack (
249a159c266SJung-uk Kim ACPI_SIZE Size,
250a159c266SJung-uk Kim UINT32 Component,
251a159c266SJung-uk Kim const char *Module,
252a159c266SJung-uk Kim UINT32 Line)
253a159c266SJung-uk Kim {
254a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Allocation;
255a159c266SJung-uk Kim ACPI_STATUS Status;
256a159c266SJung-uk Kim
257a159c266SJung-uk Kim
258313a0c13SJung-uk Kim /* Check for an inadvertent size of zero bytes */
259313a0c13SJung-uk Kim
260313a0c13SJung-uk Kim if (!Size)
261313a0c13SJung-uk Kim {
262313a0c13SJung-uk Kim ACPI_WARNING ((Module, Line,
263313a0c13SJung-uk Kim "Attempt to allocate zero bytes, allocating 1 byte"));
264313a0c13SJung-uk Kim Size = 1;
265313a0c13SJung-uk Kim }
266313a0c13SJung-uk Kim
267313a0c13SJung-uk Kim Allocation = AcpiOsAllocate (Size + sizeof (ACPI_DEBUG_MEM_HEADER));
268a159c266SJung-uk Kim if (!Allocation)
269a159c266SJung-uk Kim {
270313a0c13SJung-uk Kim /* Report allocation error */
271313a0c13SJung-uk Kim
272313a0c13SJung-uk Kim ACPI_WARNING ((Module, Line,
273313a0c13SJung-uk Kim "Could not allocate size %u", (UINT32) Size));
274313a0c13SJung-uk Kim
275a159c266SJung-uk Kim return (NULL);
276a159c266SJung-uk Kim }
277a159c266SJung-uk Kim
278f8146b88SJung-uk Kim Status = AcpiUtTrackAllocation (
279f8146b88SJung-uk Kim Allocation, Size, ACPI_MEM_MALLOC, Component, Module, Line);
280a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
281a159c266SJung-uk Kim {
282a159c266SJung-uk Kim AcpiOsFree (Allocation);
283a159c266SJung-uk Kim return (NULL);
284a159c266SJung-uk Kim }
285a159c266SJung-uk Kim
286a159c266SJung-uk Kim AcpiGbl_GlobalList->TotalAllocated++;
287a159c266SJung-uk Kim AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
288a159c266SJung-uk Kim AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
289f8146b88SJung-uk Kim
290f8146b88SJung-uk Kim if (AcpiGbl_GlobalList->CurrentTotalSize >
291f8146b88SJung-uk Kim AcpiGbl_GlobalList->MaxOccupied)
292a159c266SJung-uk Kim {
293f8146b88SJung-uk Kim AcpiGbl_GlobalList->MaxOccupied =
294f8146b88SJung-uk Kim AcpiGbl_GlobalList->CurrentTotalSize;
295a159c266SJung-uk Kim }
296a159c266SJung-uk Kim
297a159c266SJung-uk Kim return ((void *) &Allocation->UserSpace);
298a159c266SJung-uk Kim }
299a159c266SJung-uk Kim
300a159c266SJung-uk Kim
301a159c266SJung-uk Kim /*******************************************************************************
302a159c266SJung-uk Kim *
303a159c266SJung-uk Kim * FUNCTION: AcpiUtAllocateZeroedAndTrack
304a159c266SJung-uk Kim *
305a159c266SJung-uk Kim * PARAMETERS: Size - Size of the allocation
306a159c266SJung-uk Kim * Component - Component type of caller
307a159c266SJung-uk Kim * Module - Source file name of caller
308a159c266SJung-uk Kim * Line - Line number of caller
309a159c266SJung-uk Kim *
310a159c266SJung-uk Kim * RETURN: Address of the allocated memory on success, NULL on failure.
311a159c266SJung-uk Kim *
312a159c266SJung-uk Kim * DESCRIPTION: Subsystem equivalent of calloc.
313a159c266SJung-uk Kim *
314a159c266SJung-uk Kim ******************************************************************************/
315a159c266SJung-uk Kim
316a159c266SJung-uk Kim void *
AcpiUtAllocateZeroedAndTrack(ACPI_SIZE Size,UINT32 Component,const char * Module,UINT32 Line)317a159c266SJung-uk Kim AcpiUtAllocateZeroedAndTrack (
318a159c266SJung-uk Kim ACPI_SIZE Size,
319a159c266SJung-uk Kim UINT32 Component,
320a159c266SJung-uk Kim const char *Module,
321a159c266SJung-uk Kim UINT32 Line)
322a159c266SJung-uk Kim {
323a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Allocation;
324a159c266SJung-uk Kim ACPI_STATUS Status;
325a159c266SJung-uk Kim
326a159c266SJung-uk Kim
327313a0c13SJung-uk Kim /* Check for an inadvertent size of zero bytes */
328313a0c13SJung-uk Kim
329313a0c13SJung-uk Kim if (!Size)
330313a0c13SJung-uk Kim {
331313a0c13SJung-uk Kim ACPI_WARNING ((Module, Line,
332313a0c13SJung-uk Kim "Attempt to allocate zero bytes, allocating 1 byte"));
333313a0c13SJung-uk Kim Size = 1;
334313a0c13SJung-uk Kim }
335313a0c13SJung-uk Kim
336f8146b88SJung-uk Kim Allocation = AcpiOsAllocateZeroed (
337f8146b88SJung-uk Kim Size + sizeof (ACPI_DEBUG_MEM_HEADER));
338a159c266SJung-uk Kim if (!Allocation)
339a159c266SJung-uk Kim {
340a159c266SJung-uk Kim /* Report allocation error */
341a159c266SJung-uk Kim
342a159c266SJung-uk Kim ACPI_ERROR ((Module, Line,
343a159c266SJung-uk Kim "Could not allocate size %u", (UINT32) Size));
344a159c266SJung-uk Kim return (NULL);
345a159c266SJung-uk Kim }
346a159c266SJung-uk Kim
347a159c266SJung-uk Kim Status = AcpiUtTrackAllocation (Allocation, Size,
348a159c266SJung-uk Kim ACPI_MEM_CALLOC, Component, Module, Line);
349a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
350a159c266SJung-uk Kim {
351a159c266SJung-uk Kim AcpiOsFree (Allocation);
352a159c266SJung-uk Kim return (NULL);
353a159c266SJung-uk Kim }
354a159c266SJung-uk Kim
355a159c266SJung-uk Kim AcpiGbl_GlobalList->TotalAllocated++;
356a159c266SJung-uk Kim AcpiGbl_GlobalList->TotalSize += (UINT32) Size;
357a159c266SJung-uk Kim AcpiGbl_GlobalList->CurrentTotalSize += (UINT32) Size;
358f8146b88SJung-uk Kim
359f8146b88SJung-uk Kim if (AcpiGbl_GlobalList->CurrentTotalSize >
360f8146b88SJung-uk Kim AcpiGbl_GlobalList->MaxOccupied)
361a159c266SJung-uk Kim {
362f8146b88SJung-uk Kim AcpiGbl_GlobalList->MaxOccupied =
363f8146b88SJung-uk Kim AcpiGbl_GlobalList->CurrentTotalSize;
364a159c266SJung-uk Kim }
365a159c266SJung-uk Kim
366a159c266SJung-uk Kim return ((void *) &Allocation->UserSpace);
367a159c266SJung-uk Kim }
368a159c266SJung-uk Kim
369a159c266SJung-uk Kim
370a159c266SJung-uk Kim /*******************************************************************************
371a159c266SJung-uk Kim *
372a159c266SJung-uk Kim * FUNCTION: AcpiUtFreeAndTrack
373a159c266SJung-uk Kim *
374a159c266SJung-uk Kim * PARAMETERS: Allocation - Address of the memory to deallocate
375a159c266SJung-uk Kim * Component - Component type of caller
376a159c266SJung-uk Kim * Module - Source file name of caller
377a159c266SJung-uk Kim * Line - Line number of caller
378a159c266SJung-uk Kim *
379a159c266SJung-uk Kim * RETURN: None
380a159c266SJung-uk Kim *
381a159c266SJung-uk Kim * DESCRIPTION: Frees the memory at Allocation
382a159c266SJung-uk Kim *
383a159c266SJung-uk Kim ******************************************************************************/
384a159c266SJung-uk Kim
385a159c266SJung-uk Kim void
AcpiUtFreeAndTrack(void * Allocation,UINT32 Component,const char * Module,UINT32 Line)386a159c266SJung-uk Kim AcpiUtFreeAndTrack (
387a159c266SJung-uk Kim void *Allocation,
388a159c266SJung-uk Kim UINT32 Component,
389a159c266SJung-uk Kim const char *Module,
390a159c266SJung-uk Kim UINT32 Line)
391a159c266SJung-uk Kim {
392a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *DebugBlock;
393a159c266SJung-uk Kim ACPI_STATUS Status;
394a159c266SJung-uk Kim
395a159c266SJung-uk Kim
396a159c266SJung-uk Kim ACPI_FUNCTION_TRACE_PTR (UtFree, Allocation);
397a159c266SJung-uk Kim
398a159c266SJung-uk Kim
399a159c266SJung-uk Kim if (NULL == Allocation)
400a159c266SJung-uk Kim {
401a159c266SJung-uk Kim ACPI_ERROR ((Module, Line,
402a159c266SJung-uk Kim "Attempt to delete a NULL address"));
403a159c266SJung-uk Kim
404a159c266SJung-uk Kim return_VOID;
405a159c266SJung-uk Kim }
406a159c266SJung-uk Kim
407a159c266SJung-uk Kim DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
408a159c266SJung-uk Kim (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
409a159c266SJung-uk Kim
410a159c266SJung-uk Kim AcpiGbl_GlobalList->TotalFreed++;
411a159c266SJung-uk Kim AcpiGbl_GlobalList->CurrentTotalSize -= DebugBlock->Size;
412a159c266SJung-uk Kim
413f8146b88SJung-uk Kim Status = AcpiUtRemoveAllocation (DebugBlock, Component, Module, Line);
414a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
415a159c266SJung-uk Kim {
416a159c266SJung-uk Kim ACPI_EXCEPTION ((AE_INFO, Status, "Could not free memory"));
417a159c266SJung-uk Kim }
418a159c266SJung-uk Kim
419a159c266SJung-uk Kim AcpiOsFree (DebugBlock);
420313a0c13SJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed (block %p)\n",
421313a0c13SJung-uk Kim Allocation, DebugBlock));
422a159c266SJung-uk Kim return_VOID;
423a159c266SJung-uk Kim }
424a159c266SJung-uk Kim
425a159c266SJung-uk Kim
426a159c266SJung-uk Kim /*******************************************************************************
427a159c266SJung-uk Kim *
428a159c266SJung-uk Kim * FUNCTION: AcpiUtFindAllocation
429a159c266SJung-uk Kim *
430a159c266SJung-uk Kim * PARAMETERS: Allocation - Address of allocated memory
431a159c266SJung-uk Kim *
4328ef1a331SJung-uk Kim * RETURN: Three cases:
4338ef1a331SJung-uk Kim * 1) List is empty, NULL is returned.
4348ef1a331SJung-uk Kim * 2) Element was found. Returns Allocation parameter.
4358ef1a331SJung-uk Kim * 3) Element was not found. Returns position where it should be
4368ef1a331SJung-uk Kim * inserted into the list.
437a159c266SJung-uk Kim *
438a159c266SJung-uk Kim * DESCRIPTION: Searches for an element in the global allocation tracking list.
4398ef1a331SJung-uk Kim * If the element is not found, returns the location within the
4408ef1a331SJung-uk Kim * list where the element should be inserted.
4418ef1a331SJung-uk Kim *
4428ef1a331SJung-uk Kim * Note: The list is ordered by larger-to-smaller addresses.
4438ef1a331SJung-uk Kim *
4448ef1a331SJung-uk Kim * This global list is used to detect memory leaks in ACPICA as
4458ef1a331SJung-uk Kim * well as other issues such as an attempt to release the same
4468ef1a331SJung-uk Kim * internal object more than once. Although expensive as far
4478ef1a331SJung-uk Kim * as cpu time, this list is much more helpful for finding these
4488ef1a331SJung-uk Kim * types of issues than using memory leak detectors outside of
4498ef1a331SJung-uk Kim * the ACPICA code.
450a159c266SJung-uk Kim *
451a159c266SJung-uk Kim ******************************************************************************/
452a159c266SJung-uk Kim
453a159c266SJung-uk Kim static ACPI_DEBUG_MEM_BLOCK *
AcpiUtFindAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation)454a159c266SJung-uk Kim AcpiUtFindAllocation (
4558ef1a331SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Allocation)
456a159c266SJung-uk Kim {
457a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Element;
458a159c266SJung-uk Kim
459a159c266SJung-uk Kim
460a159c266SJung-uk Kim Element = AcpiGbl_GlobalList->ListHead;
4618ef1a331SJung-uk Kim if (!Element)
462a159c266SJung-uk Kim {
4638ef1a331SJung-uk Kim return (NULL);
4648ef1a331SJung-uk Kim }
4658ef1a331SJung-uk Kim
4668ef1a331SJung-uk Kim /*
4678ef1a331SJung-uk Kim * Search for the address.
4688ef1a331SJung-uk Kim *
4698ef1a331SJung-uk Kim * Note: List is ordered by larger-to-smaller addresses, on the
4708ef1a331SJung-uk Kim * assumption that a new allocation usually has a larger address
4718ef1a331SJung-uk Kim * than previous allocations.
4728ef1a331SJung-uk Kim */
4738ef1a331SJung-uk Kim while (Element > Allocation)
4748ef1a331SJung-uk Kim {
4758ef1a331SJung-uk Kim /* Check for end-of-list */
4768ef1a331SJung-uk Kim
4778ef1a331SJung-uk Kim if (!Element->Next)
478a159c266SJung-uk Kim {
479a159c266SJung-uk Kim return (Element);
480a159c266SJung-uk Kim }
481a159c266SJung-uk Kim
482a159c266SJung-uk Kim Element = Element->Next;
483a159c266SJung-uk Kim }
484a159c266SJung-uk Kim
4858ef1a331SJung-uk Kim if (Element == Allocation)
4868ef1a331SJung-uk Kim {
4878ef1a331SJung-uk Kim return (Element);
4888ef1a331SJung-uk Kim }
4898ef1a331SJung-uk Kim
4908ef1a331SJung-uk Kim return (Element->Previous);
491a159c266SJung-uk Kim }
492a159c266SJung-uk Kim
493a159c266SJung-uk Kim
494a159c266SJung-uk Kim /*******************************************************************************
495a159c266SJung-uk Kim *
496a159c266SJung-uk Kim * FUNCTION: AcpiUtTrackAllocation
497a159c266SJung-uk Kim *
498a159c266SJung-uk Kim * PARAMETERS: Allocation - Address of allocated memory
499a159c266SJung-uk Kim * Size - Size of the allocation
500a159c266SJung-uk Kim * AllocType - MEM_MALLOC or MEM_CALLOC
501a159c266SJung-uk Kim * Component - Component type of caller
502a159c266SJung-uk Kim * Module - Source file name of caller
503a159c266SJung-uk Kim * Line - Line number of caller
504a159c266SJung-uk Kim *
5058ef1a331SJung-uk Kim * RETURN: Status
506a159c266SJung-uk Kim *
507a159c266SJung-uk Kim * DESCRIPTION: Inserts an element into the global allocation tracking list.
508a159c266SJung-uk Kim *
509a159c266SJung-uk Kim ******************************************************************************/
510a159c266SJung-uk Kim
511a159c266SJung-uk Kim static ACPI_STATUS
AcpiUtTrackAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation,ACPI_SIZE Size,UINT8 AllocType,UINT32 Component,const char * Module,UINT32 Line)512a159c266SJung-uk Kim AcpiUtTrackAllocation (
513a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Allocation,
514a159c266SJung-uk Kim ACPI_SIZE Size,
515a159c266SJung-uk Kim UINT8 AllocType,
516a159c266SJung-uk Kim UINT32 Component,
517a159c266SJung-uk Kim const char *Module,
518a159c266SJung-uk Kim UINT32 Line)
519a159c266SJung-uk Kim {
520a159c266SJung-uk Kim ACPI_MEMORY_LIST *MemList;
521a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Element;
522a159c266SJung-uk Kim ACPI_STATUS Status = AE_OK;
523a159c266SJung-uk Kim
524a159c266SJung-uk Kim
525a159c266SJung-uk Kim ACPI_FUNCTION_TRACE_PTR (UtTrackAllocation, Allocation);
526a159c266SJung-uk Kim
527a159c266SJung-uk Kim
528a159c266SJung-uk Kim if (AcpiGbl_DisableMemTracking)
529a159c266SJung-uk Kim {
530a159c266SJung-uk Kim return_ACPI_STATUS (AE_OK);
531a159c266SJung-uk Kim }
532a159c266SJung-uk Kim
533a159c266SJung-uk Kim MemList = AcpiGbl_GlobalList;
534a159c266SJung-uk Kim Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
535a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
536a159c266SJung-uk Kim {
537a159c266SJung-uk Kim return_ACPI_STATUS (Status);
538a159c266SJung-uk Kim }
539a159c266SJung-uk Kim
540a159c266SJung-uk Kim /*
5418ef1a331SJung-uk Kim * Search the global list for this address to make sure it is not
5428ef1a331SJung-uk Kim * already present. This will catch several kinds of problems.
543a159c266SJung-uk Kim */
544a159c266SJung-uk Kim Element = AcpiUtFindAllocation (Allocation);
5458ef1a331SJung-uk Kim if (Element == Allocation)
546a159c266SJung-uk Kim {
547a159c266SJung-uk Kim ACPI_ERROR ((AE_INFO,
5488ef1a331SJung-uk Kim "UtTrackAllocation: Allocation (%p) already present in global list!",
549a159c266SJung-uk Kim Allocation));
550a159c266SJung-uk Kim goto UnlockAndExit;
551a159c266SJung-uk Kim }
552a159c266SJung-uk Kim
5538ef1a331SJung-uk Kim /* Fill in the instance data */
554a159c266SJung-uk Kim
555a159c266SJung-uk Kim Allocation->Size = (UINT32) Size;
556a159c266SJung-uk Kim Allocation->AllocType = AllocType;
557a159c266SJung-uk Kim Allocation->Component = Component;
558a159c266SJung-uk Kim Allocation->Line = Line;
559a159c266SJung-uk Kim
560f1db5ef7SJung-uk Kim AcpiUtSafeStrncpy (Allocation->Module, (char *) Module, ACPI_MAX_MODULE_NAME);
561a159c266SJung-uk Kim
5628ef1a331SJung-uk Kim if (!Element)
5638ef1a331SJung-uk Kim {
564a159c266SJung-uk Kim /* Insert at list head */
565a159c266SJung-uk Kim
566a159c266SJung-uk Kim if (MemList->ListHead)
567a159c266SJung-uk Kim {
568f8146b88SJung-uk Kim ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous =
569f8146b88SJung-uk Kim Allocation;
570a159c266SJung-uk Kim }
571a159c266SJung-uk Kim
572a159c266SJung-uk Kim Allocation->Next = MemList->ListHead;
573a159c266SJung-uk Kim Allocation->Previous = NULL;
574a159c266SJung-uk Kim
575a159c266SJung-uk Kim MemList->ListHead = Allocation;
5768ef1a331SJung-uk Kim }
5778ef1a331SJung-uk Kim else
5788ef1a331SJung-uk Kim {
5798ef1a331SJung-uk Kim /* Insert after element */
5808ef1a331SJung-uk Kim
5818ef1a331SJung-uk Kim Allocation->Next = Element->Next;
5828ef1a331SJung-uk Kim Allocation->Previous = Element;
5838ef1a331SJung-uk Kim
5848ef1a331SJung-uk Kim if (Element->Next)
5858ef1a331SJung-uk Kim {
5868ef1a331SJung-uk Kim (Element->Next)->Previous = Allocation;
5878ef1a331SJung-uk Kim }
5888ef1a331SJung-uk Kim
5898ef1a331SJung-uk Kim Element->Next = Allocation;
5908ef1a331SJung-uk Kim }
591a159c266SJung-uk Kim
592a159c266SJung-uk Kim
593a159c266SJung-uk Kim UnlockAndExit:
594a159c266SJung-uk Kim Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
595a159c266SJung-uk Kim return_ACPI_STATUS (Status);
596a159c266SJung-uk Kim }
597a159c266SJung-uk Kim
598a159c266SJung-uk Kim
599a159c266SJung-uk Kim /*******************************************************************************
600a159c266SJung-uk Kim *
601a159c266SJung-uk Kim * FUNCTION: AcpiUtRemoveAllocation
602a159c266SJung-uk Kim *
603a159c266SJung-uk Kim * PARAMETERS: Allocation - Address of allocated memory
604a159c266SJung-uk Kim * Component - Component type of caller
605a159c266SJung-uk Kim * Module - Source file name of caller
606a159c266SJung-uk Kim * Line - Line number of caller
607a159c266SJung-uk Kim *
6088ef1a331SJung-uk Kim * RETURN: Status
609a159c266SJung-uk Kim *
610a159c266SJung-uk Kim * DESCRIPTION: Deletes an element from the global allocation tracking list.
611a159c266SJung-uk Kim *
612a159c266SJung-uk Kim ******************************************************************************/
613a159c266SJung-uk Kim
614a159c266SJung-uk Kim static ACPI_STATUS
AcpiUtRemoveAllocation(ACPI_DEBUG_MEM_BLOCK * Allocation,UINT32 Component,const char * Module,UINT32 Line)615a159c266SJung-uk Kim AcpiUtRemoveAllocation (
616a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Allocation,
617a159c266SJung-uk Kim UINT32 Component,
618a159c266SJung-uk Kim const char *Module,
619a159c266SJung-uk Kim UINT32 Line)
620a159c266SJung-uk Kim {
621a159c266SJung-uk Kim ACPI_MEMORY_LIST *MemList;
622a159c266SJung-uk Kim ACPI_STATUS Status;
623a159c266SJung-uk Kim
624a159c266SJung-uk Kim
625ed17e06eSJung-uk Kim ACPI_FUNCTION_NAME (UtRemoveAllocation);
626a159c266SJung-uk Kim
627a159c266SJung-uk Kim
628a159c266SJung-uk Kim if (AcpiGbl_DisableMemTracking)
629a159c266SJung-uk Kim {
630ed17e06eSJung-uk Kim return (AE_OK);
631a159c266SJung-uk Kim }
632a159c266SJung-uk Kim
633a159c266SJung-uk Kim MemList = AcpiGbl_GlobalList;
634a159c266SJung-uk Kim if (NULL == MemList->ListHead)
635a159c266SJung-uk Kim {
636a159c266SJung-uk Kim /* No allocations! */
637a159c266SJung-uk Kim
638a159c266SJung-uk Kim ACPI_ERROR ((Module, Line,
639a159c266SJung-uk Kim "Empty allocation list, nothing to free!"));
640a159c266SJung-uk Kim
641ed17e06eSJung-uk Kim return (AE_OK);
642a159c266SJung-uk Kim }
643a159c266SJung-uk Kim
644a159c266SJung-uk Kim Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
645a159c266SJung-uk Kim if (ACPI_FAILURE (Status))
646a159c266SJung-uk Kim {
647ed17e06eSJung-uk Kim return (Status);
648a159c266SJung-uk Kim }
649a159c266SJung-uk Kim
650a159c266SJung-uk Kim /* Unlink */
651a159c266SJung-uk Kim
652a159c266SJung-uk Kim if (Allocation->Previous)
653a159c266SJung-uk Kim {
654a159c266SJung-uk Kim (Allocation->Previous)->Next = Allocation->Next;
655a159c266SJung-uk Kim }
656a159c266SJung-uk Kim else
657a159c266SJung-uk Kim {
658a159c266SJung-uk Kim MemList->ListHead = Allocation->Next;
659a159c266SJung-uk Kim }
660a159c266SJung-uk Kim
661a159c266SJung-uk Kim if (Allocation->Next)
662a159c266SJung-uk Kim {
663a159c266SJung-uk Kim (Allocation->Next)->Previous = Allocation->Previous;
664a159c266SJung-uk Kim }
665a159c266SJung-uk Kim
666ed17e06eSJung-uk Kim ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing %p, size 0%X\n",
667ed17e06eSJung-uk Kim &Allocation->UserSpace, Allocation->Size));
668ed17e06eSJung-uk Kim
669a159c266SJung-uk Kim /* Mark the segment as deleted */
670a159c266SJung-uk Kim
6715ef50723SJung-uk Kim memset (&Allocation->UserSpace, 0xEA, Allocation->Size);
672a159c266SJung-uk Kim
673a159c266SJung-uk Kim Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
674ed17e06eSJung-uk Kim return (Status);
675a159c266SJung-uk Kim }
676a159c266SJung-uk Kim
677a159c266SJung-uk Kim
678a159c266SJung-uk Kim /*******************************************************************************
679a159c266SJung-uk Kim *
680a159c266SJung-uk Kim * FUNCTION: AcpiUtDumpAllocationInfo
681a159c266SJung-uk Kim *
6828ef1a331SJung-uk Kim * PARAMETERS: None
683a159c266SJung-uk Kim *
684a159c266SJung-uk Kim * RETURN: None
685a159c266SJung-uk Kim *
686a159c266SJung-uk Kim * DESCRIPTION: Print some info about the outstanding allocations.
687a159c266SJung-uk Kim *
688a159c266SJung-uk Kim ******************************************************************************/
689a159c266SJung-uk Kim
690a159c266SJung-uk Kim void
AcpiUtDumpAllocationInfo(void)691a159c266SJung-uk Kim AcpiUtDumpAllocationInfo (
692a159c266SJung-uk Kim void)
693a159c266SJung-uk Kim {
694a159c266SJung-uk Kim /*
695a159c266SJung-uk Kim ACPI_MEMORY_LIST *MemList;
696a159c266SJung-uk Kim */
697a159c266SJung-uk Kim
698a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (UtDumpAllocationInfo);
699a159c266SJung-uk Kim
700a159c266SJung-uk Kim /*
701a159c266SJung-uk Kim ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
702a159c266SJung-uk Kim ("%30s: %4d (%3d Kb)\n", "Current allocations",
703a159c266SJung-uk Kim MemList->CurrentCount,
704a159c266SJung-uk Kim ROUND_UP_TO_1K (MemList->CurrentSize)));
705a159c266SJung-uk Kim
706a159c266SJung-uk Kim ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
707a159c266SJung-uk Kim ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
708a159c266SJung-uk Kim MemList->MaxConcurrentCount,
709a159c266SJung-uk Kim ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
710a159c266SJung-uk Kim
711a159c266SJung-uk Kim
712a159c266SJung-uk Kim ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
713a159c266SJung-uk Kim ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
714a159c266SJung-uk Kim RunningObjectCount,
715a159c266SJung-uk Kim ROUND_UP_TO_1K (RunningObjectSize)));
716a159c266SJung-uk Kim
717a159c266SJung-uk Kim ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
718a159c266SJung-uk Kim ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
719a159c266SJung-uk Kim RunningAllocCount,
720a159c266SJung-uk Kim ROUND_UP_TO_1K (RunningAllocSize)));
721a159c266SJung-uk Kim
722a159c266SJung-uk Kim
723a159c266SJung-uk Kim ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
724a159c266SJung-uk Kim ("%30s: %4d (%3d Kb)\n", "Current Nodes",
725a159c266SJung-uk Kim AcpiGbl_CurrentNodeCount,
726a159c266SJung-uk Kim ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
727a159c266SJung-uk Kim
728a159c266SJung-uk Kim ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
729a159c266SJung-uk Kim ("%30s: %4d (%3d Kb)\n", "Max Nodes",
730a159c266SJung-uk Kim AcpiGbl_MaxConcurrentNodeCount,
731a159c266SJung-uk Kim ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount *
732a159c266SJung-uk Kim sizeof (ACPI_NAMESPACE_NODE)))));
733a159c266SJung-uk Kim */
734a159c266SJung-uk Kim return_VOID;
735a159c266SJung-uk Kim }
736a159c266SJung-uk Kim
737a159c266SJung-uk Kim
738a159c266SJung-uk Kim /*******************************************************************************
739a159c266SJung-uk Kim *
740a159c266SJung-uk Kim * FUNCTION: AcpiUtDumpAllocations
741a159c266SJung-uk Kim *
742a159c266SJung-uk Kim * PARAMETERS: Component - Component(s) to dump info for.
743a159c266SJung-uk Kim * Module - Module to dump info for. NULL means all.
744a159c266SJung-uk Kim *
745a159c266SJung-uk Kim * RETURN: None
746a159c266SJung-uk Kim *
747a159c266SJung-uk Kim * DESCRIPTION: Print a list of all outstanding allocations.
748a159c266SJung-uk Kim *
749a159c266SJung-uk Kim ******************************************************************************/
750a159c266SJung-uk Kim
751a159c266SJung-uk Kim void
AcpiUtDumpAllocations(UINT32 Component,const char * Module)752a159c266SJung-uk Kim AcpiUtDumpAllocations (
753a159c266SJung-uk Kim UINT32 Component,
754a159c266SJung-uk Kim const char *Module)
755a159c266SJung-uk Kim {
756a159c266SJung-uk Kim ACPI_DEBUG_MEM_BLOCK *Element;
757a159c266SJung-uk Kim ACPI_DESCRIPTOR *Descriptor;
758a159c266SJung-uk Kim UINT32 NumOutstanding = 0;
759a159c266SJung-uk Kim UINT8 DescriptorType;
760a159c266SJung-uk Kim
761a159c266SJung-uk Kim
762a159c266SJung-uk Kim ACPI_FUNCTION_TRACE (UtDumpAllocations);
763a159c266SJung-uk Kim
764a159c266SJung-uk Kim
765a159c266SJung-uk Kim if (AcpiGbl_DisableMemTracking)
766a159c266SJung-uk Kim {
7678ef1a331SJung-uk Kim return_VOID;
768a159c266SJung-uk Kim }
769a159c266SJung-uk Kim
770a159c266SJung-uk Kim /*
771a159c266SJung-uk Kim * Walk the allocation list.
772a159c266SJung-uk Kim */
773a159c266SJung-uk Kim if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
774a159c266SJung-uk Kim {
7758ef1a331SJung-uk Kim return_VOID;
776a159c266SJung-uk Kim }
777a159c266SJung-uk Kim
7785f9b24faSJung-uk Kim if (!AcpiGbl_GlobalList)
7795f9b24faSJung-uk Kim {
7805f9b24faSJung-uk Kim goto Exit;
7815f9b24faSJung-uk Kim }
7825f9b24faSJung-uk Kim
783a159c266SJung-uk Kim Element = AcpiGbl_GlobalList->ListHead;
784a159c266SJung-uk Kim while (Element)
785a159c266SJung-uk Kim {
786a159c266SJung-uk Kim if ((Element->Component & Component) &&
7875ef50723SJung-uk Kim ((Module == NULL) || (0 == strcmp (Module, Element->Module))))
788a159c266SJung-uk Kim {
789f8146b88SJung-uk Kim Descriptor = ACPI_CAST_PTR (
790f8146b88SJung-uk Kim ACPI_DESCRIPTOR, &Element->UserSpace);
791a159c266SJung-uk Kim
792a159c266SJung-uk Kim if (Element->Size < sizeof (ACPI_COMMON_DESCRIPTOR))
793a159c266SJung-uk Kim {
7945f9b24faSJung-uk Kim AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u "
795a159c266SJung-uk Kim "[Not a Descriptor - too small]\n",
796a159c266SJung-uk Kim Descriptor, Element->Size, Element->Module,
797a159c266SJung-uk Kim Element->Line);
798a159c266SJung-uk Kim }
799a159c266SJung-uk Kim else
800a159c266SJung-uk Kim {
801a159c266SJung-uk Kim /* Ignore allocated objects that are in a cache */
802a159c266SJung-uk Kim
803f8146b88SJung-uk Kim if (ACPI_GET_DESCRIPTOR_TYPE (Descriptor) !=
804f8146b88SJung-uk Kim ACPI_DESC_TYPE_CACHED)
805a159c266SJung-uk Kim {
8065f9b24faSJung-uk Kim AcpiOsPrintf ("%p Length 0x%04X %9.9s-%4.4u [%s] ",
807a159c266SJung-uk Kim Descriptor, Element->Size, Element->Module,
808a159c266SJung-uk Kim Element->Line, AcpiUtGetDescriptorName (Descriptor));
809a159c266SJung-uk Kim
810e5e1f58aSJung-uk Kim /* Optional object hex dump */
811e5e1f58aSJung-uk Kim
812e5e1f58aSJung-uk Kim if (AcpiGbl_VerboseLeakDump)
813e5e1f58aSJung-uk Kim {
814e5e1f58aSJung-uk Kim AcpiOsPrintf ("\n");
815e5e1f58aSJung-uk Kim AcpiUtDumpBuffer ((UINT8 *) Descriptor, Element->Size,
816e5e1f58aSJung-uk Kim DB_BYTE_DISPLAY, 0);
817e5e1f58aSJung-uk Kim }
818e5e1f58aSJung-uk Kim
819a159c266SJung-uk Kim /* Validate the descriptor type using Type field and length */
820a159c266SJung-uk Kim
821a159c266SJung-uk Kim DescriptorType = 0; /* Not a valid descriptor type */
822a159c266SJung-uk Kim
823a159c266SJung-uk Kim switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
824a159c266SJung-uk Kim {
825a159c266SJung-uk Kim case ACPI_DESC_TYPE_OPERAND:
826a9d8d09cSJung-uk Kim
827eef1b955SJung-uk Kim if (Element->Size == sizeof (ACPI_OPERAND_OBJECT))
828a159c266SJung-uk Kim {
829a159c266SJung-uk Kim DescriptorType = ACPI_DESC_TYPE_OPERAND;
830a159c266SJung-uk Kim }
831a159c266SJung-uk Kim break;
832a159c266SJung-uk Kim
833a159c266SJung-uk Kim case ACPI_DESC_TYPE_PARSER:
834a9d8d09cSJung-uk Kim
835eef1b955SJung-uk Kim if (Element->Size == sizeof (ACPI_PARSE_OBJECT))
836a159c266SJung-uk Kim {
837a159c266SJung-uk Kim DescriptorType = ACPI_DESC_TYPE_PARSER;
838a159c266SJung-uk Kim }
839a159c266SJung-uk Kim break;
840a159c266SJung-uk Kim
841a159c266SJung-uk Kim case ACPI_DESC_TYPE_NAMED:
842a9d8d09cSJung-uk Kim
843eef1b955SJung-uk Kim if (Element->Size == sizeof (ACPI_NAMESPACE_NODE))
844a159c266SJung-uk Kim {
845a159c266SJung-uk Kim DescriptorType = ACPI_DESC_TYPE_NAMED;
846a159c266SJung-uk Kim }
847a159c266SJung-uk Kim break;
848a159c266SJung-uk Kim
849a159c266SJung-uk Kim default:
850a9d8d09cSJung-uk Kim
851a159c266SJung-uk Kim break;
852a159c266SJung-uk Kim }
853a159c266SJung-uk Kim
854a159c266SJung-uk Kim /* Display additional info for the major descriptor types */
855a159c266SJung-uk Kim
856a159c266SJung-uk Kim switch (DescriptorType)
857a159c266SJung-uk Kim {
858a159c266SJung-uk Kim case ACPI_DESC_TYPE_OPERAND:
859a9d8d09cSJung-uk Kim
860a159c266SJung-uk Kim AcpiOsPrintf ("%12.12s RefCount 0x%04X\n",
861a159c266SJung-uk Kim AcpiUtGetTypeName (Descriptor->Object.Common.Type),
862a159c266SJung-uk Kim Descriptor->Object.Common.ReferenceCount);
863a159c266SJung-uk Kim break;
864a159c266SJung-uk Kim
865a159c266SJung-uk Kim case ACPI_DESC_TYPE_PARSER:
866a9d8d09cSJung-uk Kim
867a009b7dcSJung-uk Kim AcpiOsPrintf ("AmlOpcode 0x%04X\n",
868a159c266SJung-uk Kim Descriptor->Op.Asl.AmlOpcode);
869a159c266SJung-uk Kim break;
870a159c266SJung-uk Kim
871a159c266SJung-uk Kim case ACPI_DESC_TYPE_NAMED:
872a9d8d09cSJung-uk Kim
873a159c266SJung-uk Kim AcpiOsPrintf ("%4.4s\n",
874a159c266SJung-uk Kim AcpiUtGetNodeName (&Descriptor->Node));
875a159c266SJung-uk Kim break;
876a159c266SJung-uk Kim
877a159c266SJung-uk Kim default:
878a9d8d09cSJung-uk Kim
879a159c266SJung-uk Kim AcpiOsPrintf ( "\n");
880a159c266SJung-uk Kim break;
881a159c266SJung-uk Kim }
882a159c266SJung-uk Kim }
883a159c266SJung-uk Kim }
884a159c266SJung-uk Kim
885a159c266SJung-uk Kim NumOutstanding++;
886a159c266SJung-uk Kim }
887a159c266SJung-uk Kim
888a159c266SJung-uk Kim Element = Element->Next;
889a159c266SJung-uk Kim }
890a159c266SJung-uk Kim
8915f9b24faSJung-uk Kim Exit:
892a159c266SJung-uk Kim (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
893a159c266SJung-uk Kim
894a159c266SJung-uk Kim /* Print summary */
895a159c266SJung-uk Kim
896a159c266SJung-uk Kim if (!NumOutstanding)
897a159c266SJung-uk Kim {
898f8146b88SJung-uk Kim ACPI_INFO (("No outstanding allocations"));
899a159c266SJung-uk Kim }
900a159c266SJung-uk Kim else
901a159c266SJung-uk Kim {
902b7b7e711SJung-uk Kim ACPI_ERROR ((AE_INFO, "%u (0x%X) Outstanding cache allocations",
903a159c266SJung-uk Kim NumOutstanding, NumOutstanding));
904a159c266SJung-uk Kim }
905a159c266SJung-uk Kim
906a159c266SJung-uk Kim return_VOID;
907a159c266SJung-uk Kim }
908a159c266SJung-uk Kim
909a159c266SJung-uk Kim #endif /* ACPI_DBG_TRACK_ALLOCATIONS */
910