]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryProfileLib.c
MdePkg/ProcessorBind: add defines for page allocation granularity
[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
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials \r
6 are licensed and made available under the terms and conditions of the BSD License \r
7 which accompanies this distribution. The full text of the license may be found at \r
8 http://opensource.org/licenses/bsd-license.php. \r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13**/\r
14\r
15#include <PiSmm.h>\r
16\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/SmmServicesTableLib.h>\r
19#include <Library/DebugLib.h>\r
20\r
21#include <Guid/MemoryProfile.h>\r
22\r
23EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;\r
24EDKII_SMM_MEMORY_PROFILE_PROTOCOL *mLibSmmProfileProtocol;\r
25\r
26/**\r
27 Check whether the start address of buffer is within any of the SMRAM ranges.\r
28\r
29 @param[in] Buffer The pointer to the buffer to be checked.\r
30\r
3b28e744 31 @retval TRUE The buffer is in SMRAM ranges.\r
022a9bf7
SZ
32 @retval FALSE The buffer is out of SMRAM ranges.\r
33**/\r
34BOOLEAN\r
35EFIAPI\r
36BufferInSmram (\r
37 IN VOID *Buffer\r
38 );\r
39\r
40/**\r
41 The constructor function initializes memory profile for SMM phase.\r
42\r
43 @param ImageHandle The firmware allocated handle for the EFI image.\r
44 @param SystemTable A pointer to the EFI System Table.\r
45\r
46 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
47\r
48**/\r
49EFI_STATUS\r
50EFIAPI\r
51SmmMemoryProfileLibConstructor (\r
52 IN EFI_HANDLE ImageHandle,\r
53 IN EFI_SYSTEM_TABLE *SystemTable\r
54 )\r
55{\r
56 EFI_STATUS Status;\r
57\r
58 //\r
59 // Locate Profile Protocol\r
60 //\r
61 Status = gBS->LocateProtocol (\r
62 &gEdkiiMemoryProfileGuid,\r
63 NULL,\r
64 (VOID **)&mLibProfileProtocol\r
65 );\r
66 if (EFI_ERROR (Status)) {\r
67 mLibProfileProtocol = NULL;\r
68 }\r
69\r
70 Status = gSmst->SmmLocateProtocol (\r
71 &gEdkiiSmmMemoryProfileGuid,\r
72 NULL,\r
73 (VOID **)&mLibSmmProfileProtocol\r
74 );\r
75 if (EFI_ERROR (Status)) {\r
76 mLibSmmProfileProtocol = NULL;\r
77 }\r
78\r
79 return EFI_SUCCESS;\r
80}\r
81\r
82/**\r
83 Record memory profile of multilevel caller.\r
84\r
85 @param[in] CallerAddress Address of caller.\r
86 @param[in] Action Memory profile action.\r
87 @param[in] MemoryType Memory type.\r
88 EfiMaxMemoryType means the MemoryType is unknown.\r
89 @param[in] Buffer Buffer address.\r
90 @param[in] Size Buffer size.\r
91 @param[in] ActionString String for memory profile action.\r
92 Only needed for user defined allocate action.\r
93\r
94 @return EFI_SUCCESS Memory profile is updated.\r
95 @return EFI_UNSUPPORTED Memory profile is unsupported,\r
96 or memory profile for the image is not required,\r
97 or memory profile for the memory type is not required.\r
98 @return EFI_ACCESS_DENIED It is during memory profile data getting.\r
99 @return EFI_ABORTED Memory profile recording is not enabled.\r
100 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.\r
101 @return EFI_NOT_FOUND No matched allocate info found for free action.\r
102\r
103**/\r
104EFI_STATUS\r
105EFIAPI\r
106MemoryProfileLibRecord (\r
107 IN PHYSICAL_ADDRESS CallerAddress,\r
108 IN MEMORY_PROFILE_ACTION Action,\r
109 IN EFI_MEMORY_TYPE MemoryType,\r
110 IN VOID *Buffer,\r
111 IN UINTN Size,\r
112 IN CHAR8 *ActionString OPTIONAL\r
113 )\r
114{\r
115 if (BufferInSmram (Buffer)) {\r
116 if (mLibSmmProfileProtocol == NULL) {\r
117 return EFI_UNSUPPORTED;\r
118 }\r
119 return mLibSmmProfileProtocol->Record (\r
120 mLibSmmProfileProtocol,\r
121 CallerAddress,\r
122 Action,\r
123 MemoryType,\r
124 Buffer,\r
125 Size,\r
126 ActionString\r
127 );\r
128 } else {\r
129 if (mLibProfileProtocol == NULL) {\r
130 return EFI_UNSUPPORTED;\r
131 }\r
132 return mLibProfileProtocol->Record (\r
133 mLibProfileProtocol,\r
134 CallerAddress,\r
135 Action,\r
136 MemoryType,\r
137 Buffer,\r
138 Size,\r
139 ActionString\r
140 );\r
141 }\r
142}\r
143\r