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