diff options
author | Star Zeng <star.zeng@intel.com> | 2016-06-23 22:45:14 +0800 |
---|---|---|
committer | Star Zeng <star.zeng@intel.com> | 2016-07-01 09:39:59 +0800 |
commit | cdad7675e6e12418abb1231fc14c38a1373173bc (patch) | |
tree | 38e5485fdade71484af0b46e1dc0956fa4cc8dbe /MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib | |
parent | e273569285b264ce103ac5279c6892d141bec253 (diff) | |
download | edk2-cdad7675e6e12418abb1231fc14c38a1373173bc.tar.gz edk2-cdad7675e6e12418abb1231fc14c38a1373173bc.tar.bz2 edk2-cdad7675e6e12418abb1231fc14c38a1373173bc.zip |
MdeModulePkg PiSmmCoreMemoryAllocLib: Extend to support MemoryProfileLib
Cc: Jiewen Yao <jiewen.yao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Diffstat (limited to 'MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib')
8 files changed, 488 insertions, 23 deletions
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c index 5e13a3eda2..08dd17ba69 100644 --- a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/MemoryAllocationLib.c @@ -1,5 +1,6 @@ /** @file
- Support routines for memory allocation routines based on SMM Core internal functions.
+ Support routines for memory allocation routines based on SMM Core internal functions,
+ with memory profile support.
The PI System Management Mode Core Interface Specification only allows the use
of EfiRuntimeServicesCode and EfiRuntimeServicesData memory types for memory
@@ -10,7 +11,7 @@ In addition, allocation for the Reserved memory types are not supported and will
always return NULL.
- Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -23,13 +24,14 @@ #include <PiSmm.h>
-#include <Protocol/SmmAccess2.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include "PiSmmCoreMemoryAllocationServices.h"
+#include <Library/MemoryProfileLib.h>
+
EFI_SMRAM_DESCRIPTOR *mSmmCoreMemoryAllocLibSmramRanges = NULL;
UINTN mSmmCoreMemoryAllocLibSmramRangeCount = 0;
@@ -111,7 +113,20 @@ AllocatePages ( IN UINTN Pages
)
{
- return InternalAllocatePages (EfiRuntimeServicesData, Pages);
+ VOID *Buffer;
+
+ Buffer = InternalAllocatePages (EfiRuntimeServicesData, Pages);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_PAGES,
+ EfiRuntimeServicesData,
+ Buffer,
+ EFI_PAGES_TO_SIZE(Pages),
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -133,7 +148,20 @@ AllocateRuntimePages ( IN UINTN Pages
)
{
- return InternalAllocatePages (EfiRuntimeServicesData, Pages);
+ VOID *Buffer;
+
+ Buffer = InternalAllocatePages (EfiRuntimeServicesData, Pages);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_PAGES,
+ EfiRuntimeServicesData,
+ Buffer,
+ EFI_PAGES_TO_SIZE(Pages),
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -312,7 +340,20 @@ AllocateAlignedPages ( IN UINTN Alignment
)
{
- return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);
+ VOID *Buffer;
+
+ Buffer = InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_PAGES,
+ EfiRuntimeServicesData,
+ Buffer,
+ EFI_PAGES_TO_SIZE(Pages),
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -340,7 +381,20 @@ AllocateAlignedRuntimePages ( IN UINTN Alignment
)
{
- return InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);
+ VOID *Buffer;
+
+ Buffer = InternalAllocateAlignedPages (EfiRuntimeServicesData, Pages, Alignment);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ALIGNED_RUNTIME_PAGES,
+ EfiRuntimeServicesData,
+ Buffer,
+ EFI_PAGES_TO_SIZE(Pages),
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -463,7 +517,20 @@ AllocatePool ( IN UINTN AllocationSize
)
{
- return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
+ VOID *Buffer;
+
+ Buffer = InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_POOL,
+ EfiRuntimeServicesData,
+ Buffer,
+ AllocationSize,
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -484,7 +551,20 @@ AllocateRuntimePool ( IN UINTN AllocationSize
)
{
- return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
+ VOID *Buffer;
+
+ Buffer = InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_POOL,
+ EfiRuntimeServicesData,
+ Buffer,
+ AllocationSize,
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -556,7 +636,20 @@ AllocateZeroPool ( IN UINTN AllocationSize
)
{
- return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
+ VOID *Buffer;
+
+ Buffer = InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_ZERO_POOL,
+ EfiRuntimeServicesData,
+ Buffer,
+ AllocationSize,
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -578,7 +671,20 @@ AllocateRuntimeZeroPool ( IN UINTN AllocationSize
)
{
- return InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
+ VOID *Buffer;
+
+ Buffer = InternalAllocateZeroPool (EfiRuntimeServicesData, AllocationSize);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_ZERO_POOL,
+ EfiRuntimeServicesData,
+ Buffer,
+ AllocationSize,
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -663,7 +769,20 @@ AllocateCopyPool ( IN CONST VOID *Buffer
)
{
- return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);
+ VOID *NewBuffer;
+
+ NewBuffer = InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);
+ if (NewBuffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_COPY_POOL,
+ EfiRuntimeServicesData,
+ NewBuffer,
+ AllocationSize,
+ NULL
+ );
+ }
+ return NewBuffer;
}
/**
@@ -690,7 +809,20 @@ AllocateRuntimeCopyPool ( IN CONST VOID *Buffer
)
{
- return InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);
+ VOID *NewBuffer;
+
+ NewBuffer = InternalAllocateCopyPool (EfiRuntimeServicesData, AllocationSize, Buffer);
+ if (NewBuffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_ALLOCATE_RUNTIME_COPY_POOL,
+ EfiRuntimeServicesData,
+ NewBuffer,
+ AllocationSize,
+ NULL
+ );
+ }
+ return NewBuffer;
}
/**
@@ -789,7 +921,20 @@ ReallocatePool ( IN VOID *OldBuffer OPTIONAL
)
{
- return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
+ VOID *Buffer;
+
+ Buffer = InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_REALLOCATE_POOL,
+ EfiRuntimeServicesData,
+ Buffer,
+ NewSize,
+ NULL
+ );
+ }
+ return Buffer;
}
/**
@@ -821,7 +966,20 @@ ReallocateRuntimePool ( IN VOID *OldBuffer OPTIONAL
)
{
- return InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
+ VOID *Buffer;
+
+ Buffer = InternalReallocatePool (EfiRuntimeServicesData, OldSize, NewSize, OldBuffer);
+ if (Buffer != NULL) {
+ MemoryProfileLibRecord (
+ (PHYSICAL_ADDRESS) (UINTN) RETURN_ADDRESS(0),
+ MEMORY_PROFILE_ACTION_LIB_REALLOCATE_RUNTIME_POOL,
+ EfiRuntimeServicesData,
+ Buffer,
+ NewSize,
+ NULL
+ );
+ }
+ return Buffer;
}
/**
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf index e8f7081149..f2a0bf8853 100644 --- a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.inf @@ -1,10 +1,10 @@ ## @file
# Memory Allocation Library instance dedicated to SMM Core.
# The implementation borrows the SMM Core Memory Allocation services as the primitive
-# for memory allocation instead of using SMM System Table servces in an indirect way.
-# It is assumed that this library instance must be linked with SMM Cre in this package.
+# for memory allocation instead of using SMM System Table services in an indirect way.
+# It is assumed that this library instance must be linked with SMM Cre in this package.
#
-# Copyright (c) 2010 - 2015, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -35,14 +35,13 @@ [Sources]
MemoryAllocationLib.c
PiSmmCoreMemoryAllocationServices.h
+ PiSmmCoreMemoryProfileLibNull.c
[Packages]
MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
DebugLib
BaseMemoryLib
UefiBootServicesTableLib
-
-[Protocols]
- gEfiSmmAccess2ProtocolGuid ## CONSUMES
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.uni b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.uni index 56bd6ee315..28e812b4df 100644 --- a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.uni +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationLib.uni @@ -2,10 +2,10 @@ // Memory Allocation Library instance dedicated to SMM Core.
//
// The implementation borrows the SMM Core Memory Allocation services as the primitive
-// for memory allocation instead of using SMM System Table servces in an indirect way.
+// for memory allocation instead of using SMM System Table services in an indirect way.
// It is assumed that this library instance must be linked with SMM Cre in this package.
//
-// Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>
+// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
//
// This program and the accompanying materials
// are licensed and made available under the terms and conditions of the BSD License
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.inf b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.inf new file mode 100644 index 0000000000..f9800b395f --- /dev/null +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.inf @@ -0,0 +1,54 @@ +## @file
+# Memory Allocation/Profile Library instance dedicated to SMM Core.
+# The implementation borrows the SMM Core Memory Allocation/Profile services as the primitive
+# for memory allocation/profile instead of using SMM System Table servces or SMM memory profile protocol in an indirect way.
+# It is assumed that this library instance must be linked with SMM Cre in this package.
+#
+# Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PiSmmCoreMemoryAllocationProfileLib
+ MODULE_UNI_FILE = PiSmmCoreMemoryAllocationProfileLib.uni
+ FILE_GUID = D55E42AD-3E63-4536-8281-82C0F1098C5E
+ MODULE_TYPE = SMM_CORE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x0001000A
+ LIBRARY_CLASS = MemoryAllocationLib|SMM_CORE
+ CONSTRUCTOR = PiSmmCoreMemoryAllocationLibConstructor
+ LIBRARY_CLASS = MemoryProfileLib|SMM_CORE
+ CONSTRUCTOR = PiSmmCoreMemoryProfileLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MemoryAllocationLib.c
+ PiSmmCoreMemoryAllocationServices.h
+ PiSmmCoreMemoryProfileLib.c
+ PiSmmCoreMemoryProfileServices.h
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ DebugLib
+ BaseMemoryLib
+ UefiBootServicesTableLib
+
+[Guids]
+ gEdkiiMemoryProfileGuid ## SOMETIMES_CONSUMES ## GUID # Locate protocol
+
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.uni b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.uni new file mode 100644 index 0000000000..a56b117061 --- /dev/null +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.uni @@ -0,0 +1,23 @@ +// /** @file
+// Memory Allocation/Profile Library instance dedicated to SMM Core.
+//
+// The implementation borrows the SMM Core Memory Allocation/Profile services as the primitive
+// for memory allocation/profile instead of using SMM System Table servces or SMM memory profile protocol in an indirect way.
+// It is assumed that this library instance must be linked with SMM Cre in this package.
+//
+// Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>
+//
+// This program and the accompanying materials
+// are licensed and made available under the terms and conditions of the BSD License
+// which accompanies this distribution. The full text of the license may be found at
+// http://opensource.org/licenses/bsd-license.php
+// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Memory Allocation/Profile Library instance dedicated to SMM Core"
+
+#string STR_MODULE_DESCRIPTION #language en-US "The implementation borrows the SMM Core Memory Allocation/Profile services as the primitive for memory allocation/profile instead of using SMM System Table services or SMM memory profile protocol in an indirect way. This library is only intended to be linked with the SMM Core that resides in this same package."
+
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLib.c b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLib.c new file mode 100644 index 0000000000..f6a064aa82 --- /dev/null +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLib.c @@ -0,0 +1,123 @@ +/** @file
+ Support routines for memory profile for PiSmmCore.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiSmm.h>
+
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DebugLib.h>
+
+#include <Guid/MemoryProfile.h>
+
+#include "PiSmmCoreMemoryProfileServices.h"
+
+EDKII_MEMORY_PROFILE_PROTOCOL *mLibProfileProtocol;
+
+/**
+ Check whether the start address of buffer is within any of the SMRAM ranges.
+
+ @param[in] Buffer The pointer to the buffer to be checked.
+
+ @retval TURE The buffer is in SMRAM ranges.
+ @retval FALSE The buffer is out of SMRAM ranges.
+**/
+BOOLEAN
+EFIAPI
+BufferInSmram (
+ IN VOID *Buffer
+ );
+
+/**
+ The constructor function initializes memory profile for SMM phase.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+PiSmmCoreMemoryProfileLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Locate Profile Protocol
+ //
+ Status = gBS->LocateProtocol (
+ &gEdkiiMemoryProfileGuid,
+ NULL,
+ (VOID **)&mLibProfileProtocol
+ );
+ if (EFI_ERROR (Status)) {
+ mLibProfileProtocol = NULL;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Record memory profile of multilevel caller.
+
+ @param[in] CallerAddress Address of caller.
+ @param[in] Action Memory profile action.
+ @param[in] MemoryType Memory type.
+ EfiMaxMemoryType means the MemoryType is unknown.
+ @param[in] Buffer Buffer address.
+ @param[in] Size Buffer size.
+ @param[in] ActionString String for memory profile action.
+ Only needed for user defined allocate action.
+
+ @return EFI_SUCCESS Memory profile is updated.
+ @return EFI_UNSUPPORTED Memory profile is unsupported,
+ or memory profile for the image is not required,
+ or memory profile for the memory type is not required.
+ @return EFI_ACCESS_DENIED It is during memory profile data getting.
+ @return EFI_ABORTED Memory profile recording is not enabled.
+ @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
+ @return EFI_NOT_FOUND No matched allocate info found for free action.
+
+**/
+EFI_STATUS
+EFIAPI
+MemoryProfileLibRecord (
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
+ )
+{
+ if (BufferInSmram (Buffer)) {
+ return SmmCoreUpdateProfile (CallerAddress, Action, MemoryType, Size, Buffer, ActionString);
+ } else {
+ if (mLibProfileProtocol == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+ return mLibProfileProtocol->Record (
+ mLibProfileProtocol,
+ CallerAddress,
+ Action,
+ MemoryType,
+ Buffer,
+ Size,
+ ActionString
+ );
+ }
+}
+
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLibNull.c b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLibNull.c new file mode 100644 index 0000000000..6f6c2ebc91 --- /dev/null +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileLibNull.c @@ -0,0 +1,54 @@ +/** @file
+ Null routines for memory profile for PiSmmCore.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <PiSmm.h>
+
+#include <Guid/MemoryProfile.h>
+
+/**
+ Record memory profile of multilevel caller.
+
+ @param[in] CallerAddress Address of caller.
+ @param[in] Action Memory profile action.
+ @param[in] MemoryType Memory type.
+ EfiMaxMemoryType means the MemoryType is unknown.
+ @param[in] Buffer Buffer address.
+ @param[in] Size Buffer size.
+ @param[in] ActionString String for memory profile action.
+ Only needed for user defined allocate action.
+
+ @return EFI_SUCCESS Memory profile is updated.
+ @return EFI_UNSUPPORTED Memory profile is unsupported,
+ or memory profile for the image is not required,
+ or memory profile for the memory type is not required.
+ @return EFI_ACCESS_DENIED It is during memory profile data getting.
+ @return EFI_ABORTED Memory profile recording is not enabled.
+ @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
+ @return EFI_NOT_FOUND No matched allocate info found for free action.
+
+**/
+EFI_STATUS
+EFIAPI
+MemoryProfileLibRecord (
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN CHAR8 *ActionString OPTIONAL
+ )
+{
+ return EFI_UNSUPPORTED;
+}
+
diff --git a/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileServices.h b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileServices.h new file mode 100644 index 0000000000..29923ea0a2 --- /dev/null +++ b/MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryProfileServices.h @@ -0,0 +1,54 @@ +/** @file
+ Contains function prototypes for Memory Profile Services in the SMM Core.
+
+ This header file borrows the PiSmmCore Memory Profile services as the primitive
+ for memory profile.
+
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _PI_SMM_CORE_MEMORY_PROFILE_SERVICES_H_
+#define _PI_SMM_CORE_MEMORY_PROFILE_SERVICES_H_
+
+/**
+ Update SMRAM profile information.
+
+ @param CallerAddress Address of caller who call Allocate or Free.
+ @param Action This Allocate or Free action.
+ @param MemoryType Memory type.
+ EfiMaxMemoryType means the MemoryType is unknown.
+ @param Size Buffer size.
+ @param Buffer Buffer address.
+ @param ActionString String for memory profile action.
+ Only needed for user defined allocate action.
+
+ @return EFI_SUCCESS Memory profile is updated.
+ @return EFI_UNSUPPORTED Memory profile is unsupported,
+ or memory profile for the image is not required,
+ or memory profile for the memory type is not required.
+ @return EFI_ACCESS_DENIED It is during memory profile data getting.
+ @return EFI_ABORTED Memory profile recording is not enabled.
+ @return EFI_OUT_OF_RESOURCES No enough resource to update memory profile for allocate action.
+ @return EFI_NOT_FOUND No matched allocate info found for free action.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmCoreUpdateProfile (
+ IN PHYSICAL_ADDRESS CallerAddress,
+ IN MEMORY_PROFILE_ACTION Action,
+ IN EFI_MEMORY_TYPE MemoryType, // Valid for AllocatePages/AllocatePool
+ IN UINTN Size, // Valid for AllocatePages/FreePages/AllocatePool
+ IN VOID *Buffer,
+ IN CHAR8 *ActionString OPTIONAL
+ );
+
+#endif
|