2 Support routines for memory profile for Smm phase drivers.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/UefiBootServicesTableLib.h>
12 #include <Library/SmmServicesTableLib.h>
13 #include <Library/DebugLib.h>
15 #include <Guid/MemoryProfile.h>
17 EDKII_MEMORY_PROFILE_PROTOCOL
*mLibProfileProtocol
;
18 EDKII_SMM_MEMORY_PROFILE_PROTOCOL
*mLibSmmProfileProtocol
;
21 Check whether the start address of buffer is within any of the SMRAM ranges.
23 @param[in] Buffer The pointer to the buffer to be checked.
25 @retval TRUE The buffer is in SMRAM ranges.
26 @retval FALSE The buffer is out of SMRAM ranges.
35 The constructor function initializes memory profile for SMM phase.
37 @param ImageHandle The firmware allocated handle for the EFI image.
38 @param SystemTable A pointer to the EFI System Table.
40 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
45 SmmMemoryProfileLibConstructor (
46 IN EFI_HANDLE ImageHandle
,
47 IN EFI_SYSTEM_TABLE
*SystemTable
53 // Locate Profile Protocol
55 Status
= gBS
->LocateProtocol (
56 &gEdkiiMemoryProfileGuid
,
58 (VOID
**)&mLibProfileProtocol
60 if (EFI_ERROR (Status
)) {
61 mLibProfileProtocol
= NULL
;
64 Status
= gSmst
->SmmLocateProtocol (
65 &gEdkiiSmmMemoryProfileGuid
,
67 (VOID
**)&mLibSmmProfileProtocol
69 if (EFI_ERROR (Status
)) {
70 mLibSmmProfileProtocol
= NULL
;
77 Record memory profile of multilevel caller.
79 @param[in] CallerAddress Address of caller.
80 @param[in] Action Memory profile action.
81 @param[in] MemoryType Memory type.
82 EfiMaxMemoryType means the MemoryType is unknown.
83 @param[in] Buffer Buffer address.
84 @param[in] Size Buffer size.
85 @param[in] ActionString String for memory profile action.
86 Only needed for user defined allocate action.
88 @return EFI_SUCCESS Memory profile is updated.
89 @return EFI_UNSUPPORTED Memory profile is unsupported,
90 or memory profile for the image is not required,
91 or memory profile for the memory type is not required.
92 @return EFI_ACCESS_DENIED It is during memory profile data getting.
93 @return EFI_ABORTED Memory profile recording is not enabled.
94 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
95 @return EFI_NOT_FOUND No matched allocate info found for free action.
100 MemoryProfileLibRecord (
101 IN PHYSICAL_ADDRESS CallerAddress
,
102 IN MEMORY_PROFILE_ACTION Action
,
103 IN EFI_MEMORY_TYPE MemoryType
,
106 IN CHAR8
*ActionString OPTIONAL
109 if (BufferInSmram (Buffer
)) {
110 if (mLibSmmProfileProtocol
== NULL
) {
111 return EFI_UNSUPPORTED
;
114 return mLibSmmProfileProtocol
->Record (
115 mLibSmmProfileProtocol
,
124 if (mLibProfileProtocol
== NULL
) {
125 return EFI_UNSUPPORTED
;
128 return mLibProfileProtocol
->Record (