1 /******************************************************************************
3 * Module Name: utalloc - local cache and memory allocation routines
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/utalloc.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
118 #define __UTALLOC_C__
122 #define _COMPONENT ACPI_UTILITIES
123 ACPI_MODULE_NAME ("utalloc")
126 /******************************************************************************
128 * FUNCTION: AcpiUtReleaseToCache
130 * PARAMETERS: ListId - Memory list/cache ID
131 * Object - The object to be released
135 * DESCRIPTION: Release an object to the specified cache. If cache is full,
136 * the object is deleted.
138 ******************************************************************************/
141 AcpiUtReleaseToCache (
145 ACPI_MEMORY_LIST *CacheInfo;
148 ACPI_FUNCTION_ENTRY ();
151 /* If walk cache is full, just free this wallkstate object */
153 CacheInfo = &AcpiGbl_MemoryLists[ListId];
154 if (CacheInfo->CacheDepth >= CacheInfo->MaxCacheDepth)
156 ACPI_MEM_FREE (Object);
157 ACPI_MEM_TRACKING (CacheInfo->TotalFreed++);
160 /* Otherwise put this object back into the cache */
164 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_CACHES)))
169 /* Mark the object as cached */
171 ACPI_MEMSET (Object, 0xCA, CacheInfo->ObjectSize);
172 ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_CACHED);
174 /* Put the object at the head of the cache list */
176 * (ACPI_CAST_INDIRECT_PTR (char, &(((char *) Object)[CacheInfo->LinkOffset]))) = CacheInfo->ListHead;
177 CacheInfo->ListHead = Object;
178 CacheInfo->CacheDepth++;
180 (void) AcpiUtReleaseMutex (ACPI_MTX_CACHES);
185 /******************************************************************************
187 * FUNCTION: AcpiUtAcquireFromCache
189 * PARAMETERS: ListId - Memory list ID
191 * RETURN: A requested object. NULL if the object could not be
194 * DESCRIPTION: Get an object from the specified cache. If cache is empty,
195 * the object is allocated.
197 ******************************************************************************/
200 AcpiUtAcquireFromCache (
203 ACPI_MEMORY_LIST *CacheInfo;
207 ACPI_FUNCTION_NAME ("UtAcquireFromCache");
210 CacheInfo = &AcpiGbl_MemoryLists[ListId];
211 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_CACHES)))
216 ACPI_MEM_TRACKING (CacheInfo->CacheRequests++);
218 /* Check the cache first */
220 if (CacheInfo->ListHead)
222 /* There is an object available, use it */
224 Object = CacheInfo->ListHead;
225 CacheInfo->ListHead = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) Object)[CacheInfo->LinkOffset])));
227 ACPI_MEM_TRACKING (CacheInfo->CacheHits++);
228 CacheInfo->CacheDepth--;
230 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
231 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object %p from %s\n",
232 Object, AcpiGbl_MemoryLists[ListId].ListName));
235 if (ACPI_FAILURE (AcpiUtReleaseMutex (ACPI_MTX_CACHES)))
240 /* Clear (zero) the previously used Object */
242 ACPI_MEMSET (Object, 0, CacheInfo->ObjectSize);
247 /* The cache is empty, create a new object */
249 /* Avoid deadlock with ACPI_MEM_CALLOCATE */
251 if (ACPI_FAILURE (AcpiUtReleaseMutex (ACPI_MTX_CACHES)))
256 Object = ACPI_MEM_CALLOCATE (CacheInfo->ObjectSize);
257 ACPI_MEM_TRACKING (CacheInfo->TotalAllocated++);
264 /******************************************************************************
266 * FUNCTION: AcpiUtDeleteGenericCache
268 * PARAMETERS: ListId - Memory list ID
272 * DESCRIPTION: Free all objects within the requested cache.
274 ******************************************************************************/
277 AcpiUtDeleteGenericCache (
280 ACPI_MEMORY_LIST *CacheInfo;
284 ACPI_FUNCTION_ENTRY ();
287 CacheInfo = &AcpiGbl_MemoryLists[ListId];
288 while (CacheInfo->ListHead)
290 /* Delete one cached state object */
292 Next = *(ACPI_CAST_INDIRECT_PTR (char, &(((char *) CacheInfo->ListHead)[CacheInfo->LinkOffset])));
293 ACPI_MEM_FREE (CacheInfo->ListHead);
295 CacheInfo->ListHead = Next;
296 CacheInfo->CacheDepth--;
301 /*******************************************************************************
303 * FUNCTION: AcpiUtValidateBuffer
305 * PARAMETERS: Buffer - Buffer descriptor to be validated
309 * DESCRIPTION: Perform parameter validation checks on an ACPI_BUFFER
311 ******************************************************************************/
314 AcpiUtValidateBuffer (
318 /* Obviously, the structure pointer must be valid */
322 return (AE_BAD_PARAMETER);
325 /* Special semantics for the length */
327 if ((Buffer->Length == ACPI_NO_BUFFER) ||
328 (Buffer->Length == ACPI_ALLOCATE_BUFFER) ||
329 (Buffer->Length == ACPI_ALLOCATE_LOCAL_BUFFER))
334 /* Length is valid, the buffer pointer must be also */
336 if (!Buffer->Pointer)
338 return (AE_BAD_PARAMETER);
345 /*******************************************************************************
347 * FUNCTION: AcpiUtInitializeBuffer
349 * PARAMETERS: RequiredLength - Length needed
350 * Buffer - Buffer to be validated
354 * DESCRIPTION: Validate that the buffer is of the required length or
355 * allocate a new buffer.
357 ******************************************************************************/
360 AcpiUtInitializeBuffer (
362 ACPI_SIZE RequiredLength)
364 ACPI_STATUS Status = AE_OK;
367 switch (Buffer->Length)
371 /* Set the exception and returned the required length */
373 Status = AE_BUFFER_OVERFLOW;
377 case ACPI_ALLOCATE_BUFFER:
379 /* Allocate a new buffer */
381 Buffer->Pointer = AcpiOsAllocate (RequiredLength);
382 if (!Buffer->Pointer)
384 return (AE_NO_MEMORY);
387 /* Clear the buffer */
389 ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
393 case ACPI_ALLOCATE_LOCAL_BUFFER:
395 /* Allocate a new buffer with local interface to allow tracking */
397 Buffer->Pointer = ACPI_MEM_ALLOCATE (RequiredLength);
398 if (!Buffer->Pointer)
400 return (AE_NO_MEMORY);
403 /* Clear the buffer */
405 ACPI_MEMSET (Buffer->Pointer, 0, RequiredLength);
411 /* Validate the size of the buffer */
413 if (Buffer->Length < RequiredLength)
415 Status = AE_BUFFER_OVERFLOW;
420 Buffer->Length = RequiredLength;
425 /*******************************************************************************
427 * FUNCTION: AcpiUtAllocate
429 * PARAMETERS: Size - Size of the allocation
430 * Component - Component type of caller
431 * Module - Source file name of caller
432 * Line - Line number of caller
434 * RETURN: Address of the allocated memory on success, NULL on failure.
436 * DESCRIPTION: The subsystem's equivalent of malloc.
438 ******************************************************************************/
450 ACPI_FUNCTION_TRACE_U32 ("UtAllocate", Size);
453 /* Check for an inadvertent size of zero bytes */
457 _ACPI_REPORT_ERROR (Module, Line, Component,
458 ("UtAllocate: Attempt to allocate zero bytes\n"));
462 Allocation = AcpiOsAllocate (Size);
465 /* Report allocation error */
467 _ACPI_REPORT_ERROR (Module, Line, Component,
468 ("UtAllocate: Could not allocate size %X\n", (UINT32) Size));
473 return_PTR (Allocation);
477 /*******************************************************************************
479 * FUNCTION: AcpiUtCallocate
481 * PARAMETERS: Size - Size of the allocation
482 * Component - Component type of caller
483 * Module - Source file name of caller
484 * Line - Line number of caller
486 * RETURN: Address of the allocated memory on success, NULL on failure.
488 * DESCRIPTION: Subsystem equivalent of calloc.
490 ******************************************************************************/
502 ACPI_FUNCTION_TRACE_U32 ("UtCallocate", Size);
505 /* Check for an inadvertent size of zero bytes */
509 _ACPI_REPORT_ERROR (Module, Line, Component,
510 ("UtCallocate: Attempt to allocate zero bytes\n"));
514 Allocation = AcpiOsAllocate (Size);
517 /* Report allocation error */
519 _ACPI_REPORT_ERROR (Module, Line, Component,
520 ("UtCallocate: Could not allocate size %X\n", (UINT32) Size));
524 /* Clear the memory block */
526 ACPI_MEMSET (Allocation, 0, Size);
527 return_PTR (Allocation);
531 #ifdef ACPI_DBG_TRACK_ALLOCATIONS
533 * These procedures are used for tracking memory leaks in the subsystem, and
534 * they get compiled out when the ACPI_DBG_TRACK_ALLOCATIONS is not set.
536 * Each memory allocation is tracked via a doubly linked list. Each
537 * element contains the caller's component, module name, function name, and
538 * line number. AcpiUtAllocate and AcpiUtCallocate call
539 * AcpiUtTrackAllocation to add an element to the list; deletion
540 * occurs in the body of AcpiUtFree.
544 /*******************************************************************************
546 * FUNCTION: AcpiUtAllocateAndTrack
548 * PARAMETERS: Size - Size of the allocation
549 * Component - Component type of caller
550 * Module - Source file name of caller
551 * Line - Line number of caller
553 * RETURN: Address of the allocated memory on success, NULL on failure.
555 * DESCRIPTION: The subsystem's equivalent of malloc.
557 ******************************************************************************/
560 AcpiUtAllocateAndTrack (
566 ACPI_DEBUG_MEM_BLOCK *Allocation;
570 Allocation = AcpiUtAllocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK), Component,
577 Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Allocation, Size,
578 ACPI_MEM_MALLOC, Component, Module, Line);
579 if (ACPI_FAILURE (Status))
581 AcpiOsFree (Allocation);
585 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalAllocated++;
586 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize += (UINT32) Size;
588 return ((void *) &Allocation->UserSpace);
592 /*******************************************************************************
594 * FUNCTION: AcpiUtCallocateAndTrack
596 * PARAMETERS: Size - Size of the allocation
597 * Component - Component type of caller
598 * Module - Source file name of caller
599 * Line - Line number of caller
601 * RETURN: Address of the allocated memory on success, NULL on failure.
603 * DESCRIPTION: Subsystem equivalent of calloc.
605 ******************************************************************************/
608 AcpiUtCallocateAndTrack (
614 ACPI_DEBUG_MEM_BLOCK *Allocation;
618 Allocation = AcpiUtCallocate (Size + sizeof (ACPI_DEBUG_MEM_BLOCK), Component,
622 /* Report allocation error */
624 _ACPI_REPORT_ERROR (Module, Line, Component,
625 ("UtCallocate: Could not allocate size %X\n", (UINT32) Size));
629 Status = AcpiUtTrackAllocation (ACPI_MEM_LIST_GLOBAL, Allocation, Size,
630 ACPI_MEM_CALLOC, Component, Module, Line);
631 if (ACPI_FAILURE (Status))
633 AcpiOsFree (Allocation);
637 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalAllocated++;
638 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize += (UINT32) Size;
640 return ((void *) &Allocation->UserSpace);
644 /*******************************************************************************
646 * FUNCTION: AcpiUtFreeAndTrack
648 * PARAMETERS: Allocation - Address of the memory to deallocate
649 * Component - Component type of caller
650 * Module - Source file name of caller
651 * Line - Line number of caller
655 * DESCRIPTION: Frees the memory at Allocation
657 ******************************************************************************/
666 ACPI_DEBUG_MEM_BLOCK *DebugBlock;
670 ACPI_FUNCTION_TRACE_PTR ("UtFree", Allocation);
673 if (NULL == Allocation)
675 _ACPI_REPORT_ERROR (Module, Line, Component,
676 ("AcpiUtFree: Attempt to delete a NULL address\n"));
681 DebugBlock = ACPI_CAST_PTR (ACPI_DEBUG_MEM_BLOCK,
682 (((char *) Allocation) - sizeof (ACPI_DEBUG_MEM_HEADER)));
684 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].TotalFreed++;
685 AcpiGbl_MemoryLists[ACPI_MEM_LIST_GLOBAL].CurrentTotalSize -= DebugBlock->Size;
687 Status = AcpiUtRemoveAllocation (ACPI_MEM_LIST_GLOBAL, DebugBlock,
688 Component, Module, Line);
689 if (ACPI_FAILURE (Status))
691 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not free memory, %s\n",
692 AcpiFormatException (Status)));
695 AcpiOsFree (DebugBlock);
697 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p freed\n", Allocation));
703 /*******************************************************************************
705 * FUNCTION: AcpiUtFindAllocation
707 * PARAMETERS: Allocation - Address of allocated memory
709 * RETURN: A list element if found; NULL otherwise.
711 * DESCRIPTION: Searches for an element in the global allocation tracking list.
713 ******************************************************************************/
715 ACPI_DEBUG_MEM_BLOCK *
716 AcpiUtFindAllocation (
720 ACPI_DEBUG_MEM_BLOCK *Element;
723 ACPI_FUNCTION_ENTRY ();
726 if (ListId > ACPI_MEM_LIST_MAX)
731 Element = AcpiGbl_MemoryLists[ListId].ListHead;
733 /* Search for the address. */
737 if (Element == Allocation)
742 Element = Element->Next;
749 /*******************************************************************************
751 * FUNCTION: AcpiUtTrackAllocation
753 * PARAMETERS: Allocation - Address of allocated memory
754 * Size - Size of the allocation
755 * AllocType - MEM_MALLOC or MEM_CALLOC
756 * Component - Component type of caller
757 * Module - Source file name of caller
758 * Line - Line number of caller
762 * DESCRIPTION: Inserts an element into the global allocation tracking list.
764 ******************************************************************************/
767 AcpiUtTrackAllocation (
769 ACPI_DEBUG_MEM_BLOCK *Allocation,
776 ACPI_MEMORY_LIST *MemList;
777 ACPI_DEBUG_MEM_BLOCK *Element;
778 ACPI_STATUS Status = AE_OK;
781 ACPI_FUNCTION_TRACE_PTR ("UtTrackAllocation", Allocation);
784 if (ListId > ACPI_MEM_LIST_MAX)
786 return_ACPI_STATUS (AE_BAD_PARAMETER);
789 MemList = &AcpiGbl_MemoryLists[ListId];
790 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
791 if (ACPI_FAILURE (Status))
793 return_ACPI_STATUS (Status);
797 * Search list for this address to make sure it is not already on the list.
798 * This will catch several kinds of problems.
801 Element = AcpiUtFindAllocation (ListId, Allocation);
804 ACPI_REPORT_ERROR (("UtTrackAllocation: Allocation already present in list! (%p)\n",
807 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Element %p Address %p\n", Element, Allocation));
812 /* Fill in the instance data. */
814 Allocation->Size = (UINT32) Size;
815 Allocation->AllocType = AllocType;
816 Allocation->Component = Component;
817 Allocation->Line = Line;
819 ACPI_STRNCPY (Allocation->Module, Module, ACPI_MAX_MODULE_NAME);
821 /* Insert at list head */
823 if (MemList->ListHead)
825 ((ACPI_DEBUG_MEM_BLOCK *)(MemList->ListHead))->Previous = Allocation;
828 Allocation->Next = MemList->ListHead;
829 Allocation->Previous = NULL;
831 MemList->ListHead = Allocation;
835 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
836 return_ACPI_STATUS (Status);
840 /*******************************************************************************
842 * FUNCTION: AcpiUtRemoveAllocation
844 * PARAMETERS: Allocation - Address of allocated memory
845 * Component - Component type of caller
846 * Module - Source file name of caller
847 * Line - Line number of caller
851 * DESCRIPTION: Deletes an element from the global allocation tracking list.
853 ******************************************************************************/
856 AcpiUtRemoveAllocation (
858 ACPI_DEBUG_MEM_BLOCK *Allocation,
863 ACPI_MEMORY_LIST *MemList;
867 ACPI_FUNCTION_TRACE ("UtRemoveAllocation");
870 if (ListId > ACPI_MEM_LIST_MAX)
872 return_ACPI_STATUS (AE_BAD_PARAMETER);
875 MemList = &AcpiGbl_MemoryLists[ListId];
876 if (NULL == MemList->ListHead)
878 /* No allocations! */
880 _ACPI_REPORT_ERROR (Module, Line, Component,
881 ("UtRemoveAllocation: Empty allocation list, nothing to free!\n"));
883 return_ACPI_STATUS (AE_OK);
886 Status = AcpiUtAcquireMutex (ACPI_MTX_MEMORY);
887 if (ACPI_FAILURE (Status))
889 return_ACPI_STATUS (Status);
894 if (Allocation->Previous)
896 (Allocation->Previous)->Next = Allocation->Next;
900 MemList->ListHead = Allocation->Next;
903 if (Allocation->Next)
905 (Allocation->Next)->Previous = Allocation->Previous;
908 /* Mark the segment as deleted */
910 ACPI_MEMSET (&Allocation->UserSpace, 0xEA, Allocation->Size);
912 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Freeing size %X\n", Allocation->Size));
914 Status = AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
915 return_ACPI_STATUS (Status);
919 /*******************************************************************************
921 * FUNCTION: AcpiUtDumpAllocationInfo
927 * DESCRIPTION: Print some info about the outstanding allocations.
929 ******************************************************************************/
932 AcpiUtDumpAllocationInfo (
936 ACPI_MEMORY_LIST *MemList;
939 ACPI_FUNCTION_TRACE ("UtDumpAllocationInfo");
942 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
943 ("%30s: %4d (%3d Kb)\n", "Current allocations",
944 MemList->CurrentCount,
945 ROUND_UP_TO_1K (MemList->CurrentSize)));
947 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
948 ("%30s: %4d (%3d Kb)\n", "Max concurrent allocations",
949 MemList->MaxConcurrentCount,
950 ROUND_UP_TO_1K (MemList->MaxConcurrentSize)));
953 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
954 ("%30s: %4d (%3d Kb)\n", "Total (all) internal objects",
956 ROUND_UP_TO_1K (RunningObjectSize)));
958 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
959 ("%30s: %4d (%3d Kb)\n", "Total (all) allocations",
961 ROUND_UP_TO_1K (RunningAllocSize)));
964 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
965 ("%30s: %4d (%3d Kb)\n", "Current Nodes",
966 AcpiGbl_CurrentNodeCount,
967 ROUND_UP_TO_1K (AcpiGbl_CurrentNodeSize)));
969 ACPI_DEBUG_PRINT (TRACE_ALLOCATIONS | TRACE_TABLES,
970 ("%30s: %4d (%3d Kb)\n", "Max Nodes",
971 AcpiGbl_MaxConcurrentNodeCount,
972 ROUND_UP_TO_1K ((AcpiGbl_MaxConcurrentNodeCount * sizeof (ACPI_NAMESPACE_NODE)))));
978 /*******************************************************************************
980 * FUNCTION: AcpiUtDumpAllocations
982 * PARAMETERS: Component - Component(s) to dump info for.
983 * Module - Module to dump info for. NULL means all.
987 * DESCRIPTION: Print a list of all outstanding allocations.
989 ******************************************************************************/
992 AcpiUtDumpAllocations (
996 ACPI_DEBUG_MEM_BLOCK *Element;
997 ACPI_DESCRIPTOR *Descriptor;
998 UINT32 NumOutstanding = 0;
1001 ACPI_FUNCTION_TRACE ("UtDumpAllocations");
1005 * Walk the allocation list.
1007 if (ACPI_FAILURE (AcpiUtAcquireMutex (ACPI_MTX_MEMORY)))
1012 Element = AcpiGbl_MemoryLists[0].ListHead;
1015 if ((Element->Component & Component) &&
1016 ((Module == NULL) || (0 == ACPI_STRCMP (Module, Element->Module))))
1018 /* Ignore allocated objects that are in a cache */
1020 Descriptor = ACPI_CAST_PTR (ACPI_DESCRIPTOR, &Element->UserSpace);
1021 if (Descriptor->DescriptorId != ACPI_DESC_TYPE_CACHED)
1023 AcpiOsPrintf ("%p Len %04X %9.9s-%d ",
1024 Descriptor, Element->Size, Element->Module,
1027 /* Most of the elements will be internal objects. */
1029 switch (ACPI_GET_DESCRIPTOR_TYPE (Descriptor))
1031 case ACPI_DESC_TYPE_OPERAND:
1032 AcpiOsPrintf ("ObjType %12.12s R%hd",
1033 AcpiUtGetTypeName (Descriptor->Object.Common.Type),
1034 Descriptor->Object.Common.ReferenceCount);
1037 case ACPI_DESC_TYPE_PARSER:
1038 AcpiOsPrintf ("ParseObj AmlOpcode %04hX",
1039 Descriptor->Op.Asl.AmlOpcode);
1042 case ACPI_DESC_TYPE_NAMED:
1043 AcpiOsPrintf ("Node %4.4s",
1044 Descriptor->Node.Name.Ascii);
1047 case ACPI_DESC_TYPE_STATE:
1048 AcpiOsPrintf ("Untyped StateObj");
1051 case ACPI_DESC_TYPE_STATE_UPDATE:
1052 AcpiOsPrintf ("UPDATE StateObj");
1055 case ACPI_DESC_TYPE_STATE_PACKAGE:
1056 AcpiOsPrintf ("PACKAGE StateObj");
1059 case ACPI_DESC_TYPE_STATE_CONTROL:
1060 AcpiOsPrintf ("CONTROL StateObj");
1063 case ACPI_DESC_TYPE_STATE_RPSCOPE:
1064 AcpiOsPrintf ("ROOT-PARSE-SCOPE StateObj");
1067 case ACPI_DESC_TYPE_STATE_PSCOPE:
1068 AcpiOsPrintf ("PARSE-SCOPE StateObj");
1071 case ACPI_DESC_TYPE_STATE_WSCOPE:
1072 AcpiOsPrintf ("WALK-SCOPE StateObj");
1075 case ACPI_DESC_TYPE_STATE_RESULT:
1076 AcpiOsPrintf ("RESULT StateObj");
1079 case ACPI_DESC_TYPE_STATE_NOTIFY:
1080 AcpiOsPrintf ("NOTIFY StateObj");
1083 case ACPI_DESC_TYPE_STATE_THREAD:
1084 AcpiOsPrintf ("THREAD StateObj");
1088 /* All types should appear above */
1092 AcpiOsPrintf ( "\n");
1096 Element = Element->Next;
1099 (void) AcpiUtReleaseMutex (ACPI_MTX_MEMORY);
1103 if (!NumOutstanding)
1105 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1106 "No outstanding allocations.\n"));
1110 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1111 "%d(%X) Outstanding allocations\n",
1112 NumOutstanding, NumOutstanding));
1119 #endif /* #ifdef ACPI_DBG_TRACK_ALLOCATIONS */