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