2 Support routines for memory profile for Smm phase drivers.
4 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php.
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/SmmServicesTableLib.h>
19 #include <Library/DebugLib.h>
21 #include <Guid/MemoryProfile.h>
23 EDKII_MEMORY_PROFILE_PROTOCOL
*mLibProfileProtocol
;
24 EDKII_SMM_MEMORY_PROFILE_PROTOCOL
*mLibSmmProfileProtocol
;
27 Check whether the start address of buffer is within any of the SMRAM ranges.
29 @param[in] Buffer The pointer to the buffer to be checked.
31 @retval TRUE The buffer is in SMRAM ranges.
32 @retval FALSE The buffer is out of SMRAM ranges.
41 The constructor function initializes memory profile for SMM phase.
43 @param ImageHandle The firmware allocated handle for the EFI image.
44 @param SystemTable A pointer to the EFI System Table.
46 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
51 SmmMemoryProfileLibConstructor (
52 IN EFI_HANDLE ImageHandle
,
53 IN EFI_SYSTEM_TABLE
*SystemTable
59 // Locate Profile Protocol
61 Status
= gBS
->LocateProtocol (
62 &gEdkiiMemoryProfileGuid
,
64 (VOID
**)&mLibProfileProtocol
66 if (EFI_ERROR (Status
)) {
67 mLibProfileProtocol
= NULL
;
70 Status
= gSmst
->SmmLocateProtocol (
71 &gEdkiiSmmMemoryProfileGuid
,
73 (VOID
**)&mLibSmmProfileProtocol
75 if (EFI_ERROR (Status
)) {
76 mLibSmmProfileProtocol
= NULL
;
83 Record memory profile of multilevel caller.
85 @param[in] CallerAddress Address of caller.
86 @param[in] Action Memory profile action.
87 @param[in] MemoryType Memory type.
88 EfiMaxMemoryType means the MemoryType is unknown.
89 @param[in] Buffer Buffer address.
90 @param[in] Size Buffer size.
91 @param[in] ActionString String for memory profile action.
92 Only needed for user defined allocate action.
94 @return EFI_SUCCESS Memory profile is updated.
95 @return EFI_UNSUPPORTED Memory profile is unsupported,
96 or memory profile for the image is not required,
97 or memory profile for the memory type is not required.
98 @return EFI_ACCESS_DENIED It is during memory profile data getting.
99 @return EFI_ABORTED Memory profile recording is not enabled.
100 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
101 @return EFI_NOT_FOUND No matched allocate info found for free action.
106 MemoryProfileLibRecord (
107 IN PHYSICAL_ADDRESS CallerAddress
,
108 IN MEMORY_PROFILE_ACTION Action
,
109 IN EFI_MEMORY_TYPE MemoryType
,
112 IN CHAR8
*ActionString OPTIONAL
115 if (BufferInSmram (Buffer
)) {
116 if (mLibSmmProfileProtocol
== NULL
) {
117 return EFI_UNSUPPORTED
;
119 return mLibSmmProfileProtocol
->Record (
120 mLibSmmProfileProtocol
,
129 if (mLibProfileProtocol
== NULL
) {
130 return EFI_UNSUPPORTED
;
132 return mLibProfileProtocol
->Record (