]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiMemoryAllocationProfileLib/DxeMemoryProfileLib.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Library / UefiMemoryAllocationProfileLib / DxeMemoryProfileLib.c
CommitLineData
1439c255
SZ
1/** @file\r
2 Support routines for memory profile for Dxe phase drivers.\r
3\r
d1102dba 4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
1439c255
SZ
6\r
7**/\r
8\r
1439c255
SZ
9#include <Uefi.h>\r
10\r
1439c255
SZ
11#include <Library/UefiBootServicesTableLib.h>\r
12#include <Library/DebugLib.h>\r
13\r
14#include <Guid/MemoryProfile.h>\r
15\r
1436aea4 16EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;\r
1439c255
SZ
17\r
18/**\r
19 The constructor function initializes memory profile for DXE phase.\r
20\r
21 @param ImageHandle The firmware allocated handle for the EFI image.\r
22 @param SystemTable A pointer to the EFI System Table.\r
23\r
24 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
25\r
26**/\r
27EFI_STATUS\r
28EFIAPI\r
29MemoryProfileLibConstructor (\r
30 IN EFI_HANDLE ImageHandle,\r
31 IN EFI_SYSTEM_TABLE *SystemTable\r
32 )\r
33{\r
1436aea4 34 EFI_STATUS Status;\r
1439c255
SZ
35\r
36 Status = gBS->LocateProtocol (\r
37 &gEdkiiMemoryProfileGuid,\r
38 NULL,\r
1436aea4 39 (VOID **)&mLibProfileProtocol\r
1439c255
SZ
40 );\r
41 if (EFI_ERROR (Status)) {\r
42 mLibProfileProtocol = NULL;\r
43 }\r
44\r
45 return EFI_SUCCESS;\r
46}\r
47\r
48/**\r
49 Record memory profile of multilevel caller.\r
50\r
51 @param[in] CallerAddress Address of caller.\r
52 @param[in] Action Memory profile action.\r
53 @param[in] MemoryType Memory type.\r
54 EfiMaxMemoryType means the MemoryType is unknown.\r
55 @param[in] Buffer Buffer address.\r
56 @param[in] Size Buffer size.\r
57 @param[in] ActionString String for memory profile action.\r
58 Only needed for user defined allocate action.\r
59\r
60 @return EFI_SUCCESS Memory profile is updated.\r
61 @return EFI_UNSUPPORTED Memory profile is unsupported,\r
62 or memory profile for the image is not required,\r
63 or memory profile for the memory type is not required.\r
64 @return EFI_ACCESS_DENIED It is during memory profile data getting.\r
65 @return EFI_ABORTED Memory profile recording is not enabled.\r
66 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r
67 @return EFI_NOT_FOUND No matched allocate info found for free action.\r
68\r
69**/\r
70EFI_STATUS\r
71EFIAPI\r
72MemoryProfileLibRecord (\r
1436aea4
MK
73 IN PHYSICAL_ADDRESS CallerAddress,\r
74 IN MEMORY_PROFILE_ACTION Action,\r
75 IN EFI_MEMORY_TYPE MemoryType,\r
76 IN VOID *Buffer,\r
77 IN UINTN Size,\r
78 IN CHAR8 *ActionString OPTIONAL\r
1439c255
SZ
79 )\r
80{\r
81 if (mLibProfileProtocol == NULL) {\r
82 return EFI_UNSUPPORTED;\r
83 }\r
1436aea4 84\r
1439c255
SZ
85 return mLibProfileProtocol->Record (\r
86 mLibProfileProtocol,\r
87 CallerAddress,\r
88 Action,\r
89 MemoryType,\r
90 Buffer,\r
91 Size,\r
92 ActionString\r
93 );\r
94}\r