2 Support routines for memory profile for PiSmmCore.
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/DebugLib.h>
14 #include <Guid/MemoryProfile.h>
16 #include "PiSmmCoreMemoryProfileServices.h"
18 EDKII_MEMORY_PROFILE_PROTOCOL
*mLibProfileProtocol
;
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 PiSmmCoreMemoryProfileLibConstructor (
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
;
68 Record memory profile of multilevel caller.
70 @param[in] CallerAddress Address of caller.
71 @param[in] Action Memory profile action.
72 @param[in] MemoryType Memory type.
73 EfiMaxMemoryType means the MemoryType is unknown.
74 @param[in] Buffer Buffer address.
75 @param[in] Size Buffer size.
76 @param[in] ActionString String for memory profile action.
77 Only needed for user defined allocate action.
79 @return EFI_SUCCESS Memory profile is updated.
80 @return EFI_UNSUPPORTED Memory profile is unsupported,
81 or memory profile for the image is not required,
82 or memory profile for the memory type is not required.
83 @return EFI_ACCESS_DENIED It is during memory profile data getting.
84 @return EFI_ABORTED Memory profile recording is not enabled.
85 @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
86 @return EFI_NOT_FOUND No matched allocate info found for free action.
91 MemoryProfileLibRecord (
92 IN PHYSICAL_ADDRESS CallerAddress
,
93 IN MEMORY_PROFILE_ACTION Action
,
94 IN EFI_MEMORY_TYPE MemoryType
,
97 IN CHAR8
*ActionString OPTIONAL
100 if (BufferInSmram (Buffer
)) {
101 return SmmCoreUpdateProfile (CallerAddress
, Action
, MemoryType
, Size
, Buffer
, ActionString
);
103 if (mLibProfileProtocol
== NULL
) {
104 return EFI_UNSUPPORTED
;
106 return mLibProfileProtocol
->Record (