]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryProfileLib.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Library / SmmMemoryAllocationProfileLib / SmmMemoryProfileLib.c
CommitLineData
022a9bf7
SZ
1/** @file\r
2 Support routines for memory profile for Smm 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
022a9bf7
SZ
6\r
7**/\r
8\r
9#include <PiSmm.h>\r
10\r
11#include <Library/UefiBootServicesTableLib.h>\r
12#include <Library/SmmServicesTableLib.h>\r
13#include <Library/DebugLib.h>\r
14\r
15#include <Guid/MemoryProfile.h>\r
16\r
17EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;\r
18EDKII_SMM_MEMORY_PROFILE_PROTOCOL *mLibSmmProfileProtocol;\r
19\r
20/**\r
21 Check whether the start address of buffer is within any of the SMRAM ranges.\r
22\r
23 @param[in] Buffer The pointer to the buffer to be checked.\r
24\r
3b28e744 25 @retval TRUE The buffer is in SMRAM ranges.\r
022a9bf7
SZ
26 @retval FALSE The buffer is out of SMRAM ranges.\r
27**/\r
28BOOLEAN\r
29EFIAPI\r
30BufferInSmram (\r
31 IN VOID *Buffer\r
32 );\r
33\r
34/**\r
35 The constructor function initializes memory profile for SMM phase.\r
36\r
37 @param ImageHandle The firmware allocated handle for the EFI image.\r
38 @param SystemTable A pointer to the EFI System Table.\r
39\r
40 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
41\r
42**/\r
43EFI_STATUS\r
44EFIAPI\r
45SmmMemoryProfileLibConstructor (\r
46 IN EFI_HANDLE ImageHandle,\r
47 IN EFI_SYSTEM_TABLE *SystemTable\r
48 )\r
49{\r
50 EFI_STATUS Status;\r
51\r
52 //\r
53 // Locate Profile Protocol\r
54 //\r
55 Status = gBS->LocateProtocol (\r
56 &gEdkiiMemoryProfileGuid,\r
57 NULL,\r
58 (VOID **)&mLibProfileProtocol\r
59 );\r
60 if (EFI_ERROR (Status)) {\r
61 mLibProfileProtocol = NULL;\r
62 }\r
63\r
64 Status = gSmst->SmmLocateProtocol (\r
65 &gEdkiiSmmMemoryProfileGuid,\r
66 NULL,\r
67 (VOID **)&mLibSmmProfileProtocol\r
68 );\r
69 if (EFI_ERROR (Status)) {\r
70 mLibSmmProfileProtocol = NULL;\r
71 }\r
72\r
73 return EFI_SUCCESS;\r
74}\r
75\r
76/**\r
77 Record memory profile of multilevel caller.\r
78\r
79 @param[in] CallerAddress Address of caller.\r
80 @param[in] Action Memory profile action.\r
81 @param[in] MemoryType Memory type.\r
82 EfiMaxMemoryType means the MemoryType is unknown.\r
83 @param[in] Buffer Buffer address.\r
84 @param[in] Size Buffer size.\r
85 @param[in] ActionString String for memory profile action.\r
86 Only needed for user defined allocate action.\r
87\r
88 @return EFI_SUCCESS Memory profile is updated.\r
89 @return EFI_UNSUPPORTED Memory profile is unsupported,\r
90 or memory profile for the image is not required,\r
91 or memory profile for the memory type is not required.\r
92 @return EFI_ACCESS_DENIED It is during memory profile data getting.\r
93 @return EFI_ABORTED Memory profile recording is not enabled.\r
94 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r
95 @return EFI_NOT_FOUND No matched allocate info found for free action.\r
96\r
97**/\r
98EFI_STATUS\r
99EFIAPI\r
100MemoryProfileLibRecord (\r
101 IN PHYSICAL_ADDRESS CallerAddress,\r
102 IN MEMORY_PROFILE_ACTION Action,\r
103 IN EFI_MEMORY_TYPE MemoryType,\r
104 IN VOID *Buffer,\r
105 IN UINTN Size,\r
106 IN CHAR8 *ActionString OPTIONAL\r
107 )\r
108{\r
109 if (BufferInSmram (Buffer)) {\r
110 if (mLibSmmProfileProtocol == NULL) {\r
111 return EFI_UNSUPPORTED;\r
112 }\r
113 return mLibSmmProfileProtocol->Record (\r
114 mLibSmmProfileProtocol,\r
115 CallerAddress,\r
116 Action,\r
117 MemoryType,\r
118 Buffer,\r
119 Size,\r
120 ActionString\r
121 );\r
122 } else {\r
123 if (mLibProfileProtocol == NULL) {\r
124 return EFI_UNSUPPORTED;\r
125 }\r
126 return mLibProfileProtocol->Record (\r
127 mLibProfileProtocol,\r
128 CallerAddress,\r
129 Action,\r
130 MemoryType,\r
131 Buffer,\r
132 Size,\r
133 ActionString\r
134 );\r
135 }\r
136}\r
137\r