* [PATCH v4 04/20] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning
[not found] <20210126194710.2248-1-kun.q@outlook.com>
@ 2021-01-26 19:46 ` Kun Qin
2021-01-26 19:46 ` [PATCH v4 05/20] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
` (13 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:46 UTC (permalink / raw)
To: devel
Cc: Ard Biesheuvel, Sami Mujawar, Jiewen Yao, Supreeth Venkatesh,
Jiewen Yao
Assigning MmramRangeCount from MmCorePrivate (UINT64) to local variable
MmramRangeCount (UINT32) will cause compilation failure due to "warning
C4244: '=': conversion from 'UINT64' to 'UINT32', possible loss of data".
This changes defines local MmramRangeCount as UINTN type and adds type
cast before value assignment.
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---
Notes:
v4:
- Reviewed previously, no change
v3:
- Added reviewed-by tag [Jiewen]
v2:
- Changed variable type to UINTN and cast before assignments [Jiewen]
StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c
index 8fbd4d934784..ba5470dd7156 100644
--- a/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmCoreMemoryAllocationLib/StandaloneMmCoreMemoryAllocationLib.c
@@ -841,7 +841,7 @@ MemoryAllocationLibConstructor (
VOID *HobStart;
EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHobData;
EFI_MMRAM_DESCRIPTOR *MmramRanges;
- UINT32 MmramRangeCount;
+ UINTN MmramRangeCount;
EFI_HOB_GUID_TYPE *MmramRangesHob;
HobStart = GetHobList ();
@@ -868,7 +868,7 @@ MemoryAllocationLibConstructor (
return EFI_UNSUPPORTED;
}
- MmramRangeCount = MmramRangesHobData->NumberOfMmReservedRegions;
+ MmramRangeCount = (UINTN) MmramRangesHobData->NumberOfMmReservedRegions;
if (MmramRanges == NULL) {
return EFI_UNSUPPORTED;
}
@@ -877,7 +877,7 @@ MemoryAllocationLibConstructor (
DataInHob = GET_GUID_HOB_DATA (GuidHob);
MmCorePrivate = (MM_CORE_PRIVATE_DATA *)(UINTN)DataInHob->Address;
MmramRanges = (EFI_MMRAM_DESCRIPTOR *)(UINTN)MmCorePrivate->MmramRanges;
- MmramRangeCount = MmCorePrivate->MmramRangeCount;
+ MmramRangeCount = (UINTN) MmCorePrivate->MmramRangeCount;
}
{
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 05/20] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture
[not found] <20210126194710.2248-1-kun.q@outlook.com>
2021-01-26 19:46 ` [PATCH v4 04/20] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
@ 2021-01-26 19:46 ` Kun Qin
2021-01-26 19:46 ` [PATCH v4 06/20] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
` (12 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:46 UTC (permalink / raw)
To: devel
Cc: Ard Biesheuvel, Sami Mujawar, Jiewen Yao, Supreeth Venkatesh,
Jiewen Yao
This change extends StandaloneMmMemLib library to support X64
architecture. The implementation is ported from MdePkg/Library/SmmMemLib.
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---
Notes:
v4:
- Added reviewed-by tag [Jiewen]
v3:
- Updated destructor description of varibales to pass CI build.
v2:
- Added routine to fix bug of not initializing MmRanges [Jiewen]
- Extends support to x86 instead of x64 only [Hao]
StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c | 27 ++++
StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c | 52 +++++++
StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c | 155 ++++++++++++++++++++
StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf | 13 +-
4 files changed, 246 insertions(+), 1 deletion(-)
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c
index cb7c5e677a6b..4124959e0435 100644
--- a/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/AArch64/StandaloneMmMemLibInternal.c
@@ -40,4 +40,31 @@ MmMemLibInternalCalculateMaximumSupportAddress (
DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
}
+/**
+ Initialize cached Mmram Ranges from HOB.
+
+ @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information.
+ @retval EFI_SUCCESS MmRanges are populated successfully.
+
+**/
+EFI_STATUS
+MmMemLibInternalPopulateMmramRanges (
+ VOID
+ )
+{
+ // Not implemented for AARCH64.
+ return EFI_SUCCESS;
+}
+
+/**
+ Deinitialize cached Mmram Ranges.
+
+**/
+VOID
+MmMemLibInternalFreeMmramRanges (
+ VOID
+ )
+{
+ // Not implemented for AARCH64.
+}
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c
index b533bd8390cd..2737f95315eb 100644
--- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.c
@@ -37,6 +37,27 @@ MmMemLibInternalCalculateMaximumSupportAddress (
VOID
);
+/**
+ Initialize cached Mmram Ranges from HOB.
+
+ @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information.
+ @retval EFI_SUCCESS MmRanges are populated successfully.
+
+**/
+EFI_STATUS
+MmMemLibInternalPopulateMmramRanges (
+ VOID
+ );
+
+/**
+ Deinitialize cached Mmram Ranges.
+
+**/
+VOID
+MmMemLibInternalFreeMmramRanges (
+ VOID
+ );
+
/**
This function check if the buffer is valid per processor architecture and not overlap with MMRAM.
@@ -253,11 +274,42 @@ MemLibConstructor (
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
)
{
+ EFI_STATUS Status;
//
// Calculate and save maximum support address
//
MmMemLibInternalCalculateMaximumSupportAddress ();
+ //
+ // Initialize cached Mmram Ranges from HOB.
+ //
+ Status = MmMemLibInternalPopulateMmramRanges ();
+
+ return Status;
+}
+
+/**
+ Destructor for Mm Mem library.
+
+ @param ImageHandle The image handle of the process.
+ @param MmSystemTable The EFI System Table pointer.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+MemLibDestructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *MmSystemTable
+ )
+{
+
+ //
+ // Deinitialize cached Mmram Ranges.
+ //
+ MmMemLibInternalFreeMmramRanges ();
+
return EFI_SUCCESS;
}
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c
new file mode 100644
index 000000000000..1a978541716a
--- /dev/null
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/X86StandaloneMmMemLibInternal.c
@@ -0,0 +1,155 @@
+/** @file
+ Internal ARCH Specific file of MM memory check library.
+
+ MM memory check library implementation. This library consumes MM_ACCESS_PROTOCOL
+ to get MMRAM information. In order to use this library instance, the platform should produce
+ all MMRAM range via MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
+ and MM driver) and/or specific dedicated hardware.
+
+ Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+#include <PiMm.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+
+#include <Guid/MmCoreData.h>
+#include <Guid/MmramMemoryReserve.h>
+
+//
+// Maximum support address used to check input buffer
+//
+extern EFI_PHYSICAL_ADDRESS mMmMemLibInternalMaximumSupportAddress;
+extern EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
+extern UINTN mMmMemLibInternalMmramCount;
+
+/**
+ Calculate and save the maximum support address.
+
+**/
+VOID
+MmMemLibInternalCalculateMaximumSupportAddress (
+ VOID
+ )
+{
+ VOID *Hob;
+ UINT32 RegEax;
+ UINT8 PhysicalAddressBits;
+
+ //
+ // Get physical address bits supported.
+ //
+ Hob = GetFirstHob (EFI_HOB_TYPE_CPU);
+ if (Hob != NULL) {
+ PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace;
+ } else {
+ AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL);
+ if (RegEax >= 0x80000008) {
+ AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL);
+ PhysicalAddressBits = (UINT8) RegEax;
+ } else {
+ PhysicalAddressBits = 36;
+ }
+ }
+ //
+ // IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.
+ //
+ ASSERT (PhysicalAddressBits <= 52);
+ if (PhysicalAddressBits > 48) {
+ PhysicalAddressBits = 48;
+ }
+
+ //
+ // Save the maximum support address in one global variable
+ //
+ mMmMemLibInternalMaximumSupportAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
+ DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress = 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
+}
+
+/**
+ Initialize cached Mmram Ranges from HOB.
+
+ @retval EFI_UNSUPPORTED The routine is unable to extract MMRAM information.
+ @retval EFI_SUCCESS MmRanges are populated successfully.
+
+**/
+EFI_STATUS
+MmMemLibInternalPopulateMmramRanges (
+ VOID
+ )
+{
+ VOID *HobStart;
+ EFI_HOB_GUID_TYPE *GuidHob;
+ MM_CORE_DATA_HOB_DATA *DataInHob;
+ MM_CORE_PRIVATE_DATA *MmCorePrivateData;
+ EFI_HOB_GUID_TYPE *MmramRangesHob;
+ EFI_MMRAM_HOB_DESCRIPTOR_BLOCK *MmramRangesHobData;
+ EFI_MMRAM_DESCRIPTOR *MmramDescriptors;
+
+ HobStart = GetHobList ();
+ DEBUG ((DEBUG_INFO, "%a - 0x%x\n", __FUNCTION__, HobStart));
+
+ //
+ // Extract MM Core Private context from the Hob. If absent search for
+ // a Hob containing the MMRAM ranges
+ //
+ GuidHob = GetNextGuidHob (&gMmCoreDataHobGuid, HobStart);
+ if (GuidHob == NULL) {
+ MmramRangesHob = GetFirstGuidHob (&gEfiMmPeiMmramMemoryReserveGuid);
+ if (MmramRangesHob == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ MmramRangesHobData = GET_GUID_HOB_DATA (MmramRangesHob);
+ if (MmramRangesHobData == NULL || MmramRangesHobData->Descriptor == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ mMmMemLibInternalMmramCount = MmramRangesHobData->NumberOfMmReservedRegions;
+ MmramDescriptors = MmramRangesHobData->Descriptor;
+ } else {
+ DataInHob = GET_GUID_HOB_DATA (GuidHob);
+ if (DataInHob == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ MmCorePrivateData = (MM_CORE_PRIVATE_DATA *) (UINTN) DataInHob->Address;
+ if (MmCorePrivateData == NULL || MmCorePrivateData->MmramRanges == 0) {
+ return EFI_UNSUPPORTED;
+ }
+
+ mMmMemLibInternalMmramCount = (UINTN) MmCorePrivateData->MmramRangeCount;
+ MmramDescriptors = (EFI_MMRAM_DESCRIPTOR *) (UINTN) MmCorePrivateData->MmramRanges;
+ }
+
+ mMmMemLibInternalMmramRanges = AllocatePool (mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR));
+ if (mMmMemLibInternalMmramRanges) {
+ CopyMem (mMmMemLibInternalMmramRanges,
+ MmramDescriptors,
+ mMmMemLibInternalMmramCount * sizeof (EFI_MMRAM_DESCRIPTOR));
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Deinitialize cached Mmram Ranges.
+
+**/
+VOID
+MmMemLibInternalFreeMmramRanges (
+ VOID
+ )
+{
+ if (mMmMemLibInternalMmramRanges != NULL) {
+ FreePool (mMmMemLibInternalMmramRanges);
+ }
+}
+
diff --git a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
index 49da02e54e6d..062b0d7a1161 100644
--- a/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
+++ b/StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
@@ -8,6 +8,7 @@
#
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -22,16 +23,20 @@ [Defines]
PI_SPECIFICATION_VERSION = 0x00010032
LIBRARY_CLASS = MemLib|MM_STANDALONE MM_CORE_STANDALONE
CONSTRUCTOR = MemLibConstructor
+ DESTRUCTOR = MemLibDestructor
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = AARCH64
+# VALID_ARCHITECTURES = IA32 X64 AARCH64
#
[Sources.Common]
StandaloneMmMemLib.c
+[Sources.IA32, Sources.X64]
+ X86StandaloneMmMemLibInternal.c
+
[Sources.AARCH64]
AArch64/StandaloneMmMemLibInternal.c
@@ -42,3 +47,9 @@ [Packages]
[LibraryClasses]
BaseMemoryLib
DebugLib
+ HobLib
+ MemoryAllocationLib
+
+[Guids]
+ gMmCoreDataHobGuid ## SOMETIMES_CONSUMES ## HOB
+ gEfiMmPeiMmramMemoryReserveGuid ## SOMETIMES_CONSUMES ## HOB
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 06/20] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib
[not found] <20210126194710.2248-1-kun.q@outlook.com>
2021-01-26 19:46 ` [PATCH v4 04/20] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
2021-01-26 19:46 ` [PATCH v4 05/20] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
@ 2021-01-26 19:46 ` Kun Qin
2021-01-26 19:46 ` [PATCH v4 07/20] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
` (11 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:46 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu, Eric Dong
This change added support of StandaloneMm for SmmLockBoxLib. It replaces
gSmst with gMmst to support both traditional MM and standalone MM. The
contructor and desctructor functions are abstracted to support different
function prototype definitions.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Previously reviewed. No change.
v2:
- Removed "EFIAPI" for internal library functions [Hao]
- Added Reviewed-by tag [Hao]
MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.c => SmmLockBoxMmLib.c} | 82 +++++++++-----------
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c | 53 +++++++++++++
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c | 53 +++++++++++++
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h | 25 ++++++
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf | 15 ++--
MdeModulePkg/Library/SmmLockBoxLib/{SmmLockBoxSmmLib.inf => SmmLockBoxStandaloneMmLib.inf} | 26 ++++---
MdeModulePkg/MdeModulePkg.dsc | 2 +
7 files changed, 191 insertions(+), 65 deletions(-)
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
similarity index 89%
rename from MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
rename to MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
index 4cc0e8b78e5b..a709851806eb 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.c
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c
@@ -6,16 +6,16 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include <PiSmm.h>
-#include <Library/SmmServicesTableLib.h>
+#include <PiMm.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/LockBoxLib.h>
#include <Library/DebugLib.h>
#include <Guid/SmmLockBox.h>
#include <Guid/EndOfS3Resume.h>
-#include <Protocol/SmmReadyToLock.h>
-#include <Protocol/SmmEndOfDxe.h>
+#include <Protocol/MmReadyToLock.h>
+#include <Protocol/MmEndOfDxe.h>
#include <Protocol/SmmSxDispatch2.h>
#include "SmmLockBoxLibPrivate.h"
@@ -49,13 +49,13 @@ InternalGetSmmLockBoxContext (
//
// Check if gEfiSmmLockBoxCommunicationGuid is installed by someone
//
- for (Index = 0; Index < gSmst->NumberOfTableEntries; Index++) {
- if (CompareGuid (&gSmst->SmmConfigurationTable[Index].VendorGuid, &gEfiSmmLockBoxCommunicationGuid)) {
+ for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) {
+ if (CompareGuid (&gMmst->MmConfigurationTable[Index].VendorGuid, &gEfiSmmLockBoxCommunicationGuid)) {
//
// Found. That means some other library instance is already run.
// No need to install again, just return.
//
- return (SMM_LOCK_BOX_CONTEXT *)gSmst->SmmConfigurationTable[Index].VendorTable;
+ return (SMM_LOCK_BOX_CONTEXT *)gMmst->MmConfigurationTable[Index].VendorTable;
}
}
@@ -142,8 +142,8 @@ SmmLockBoxSmmEndOfDxeNotify (
//
// Locate SmmSxDispatch2 protocol.
//
- Status = gSmst->SmmLocateProtocol (
- &gEfiSmmSxDispatch2ProtocolGuid,
+ Status = gMmst->MmLocateProtocol (
+ &gEfiMmSxDispatchProtocolGuid,
NULL,
(VOID **)&SxDispatch
);
@@ -191,29 +191,24 @@ SmmLockBoxEndOfS3ResumeNotify (
Constructor for SmmLockBox library.
This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
- @param[in] ImageHandle Image handle of this driver.
- @param[in] SystemTable A Pointer to the EFI System Table.
-
@retval EFI_SUCEESS
@return Others Some error occurs.
**/
EFI_STATUS
-EFIAPI
-SmmLockBoxSmmConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+SmmLockBoxMmConstructor (
+ VOID
)
{
EFI_STATUS Status;
SMM_LOCK_BOX_CONTEXT *SmmLockBoxContext;
- DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Enter\n"));
+ DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Enter\n"));
//
// Register SmmReadyToLock notification.
//
- Status = gSmst->SmmRegisterProtocolNotify (
- &gEfiSmmReadyToLockProtocolGuid,
+ Status = gMmst->MmRegisterProtocolNotify (
+ &gEfiMmReadyToLockProtocolGuid,
SmmLockBoxSmmReadyToLockNotify,
&mSmmLockBoxRegistrationSmmReadyToLock
);
@@ -222,8 +217,8 @@ SmmLockBoxSmmConstructor (
//
// Register SmmEndOfDxe notification.
//
- Status = gSmst->SmmRegisterProtocolNotify (
- &gEfiSmmEndOfDxeProtocolGuid,
+ Status = gMmst->MmRegisterProtocolNotify (
+ &gEfiMmEndOfDxeProtocolGuid,
SmmLockBoxSmmEndOfDxeNotify,
&mSmmLockBoxRegistrationSmmEndOfDxe
);
@@ -232,7 +227,7 @@ SmmLockBoxSmmConstructor (
//
// Register EndOfS3Resume notification.
//
- Status = gSmst->SmmRegisterProtocolNotify (
+ Status = gMmst->MmRegisterProtocolNotify (
&gEdkiiEndOfS3ResumeGuid,
SmmLockBoxEndOfS3ResumeNotify,
&mSmmLockBoxRegistrationEndOfS3Resume
@@ -249,7 +244,7 @@ SmmLockBoxSmmConstructor (
// No need to install again, just return.
//
DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - already installed\n"));
- DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Exit\n"));
+ DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
return EFI_SUCCESS;
}
@@ -263,8 +258,8 @@ SmmLockBoxSmmConstructor (
}
mSmmLockBoxContext.LockBoxDataAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)&mLockBoxQueue;
- Status = gSmst->SmmInstallConfigurationTable (
- gSmst,
+ Status = gMmst->MmInstallConfigurationTable (
+ gMmst,
&gEfiSmmLockBoxCommunicationGuid,
&mSmmLockBoxContext,
sizeof(mSmmLockBoxContext)
@@ -274,7 +269,7 @@ SmmLockBoxSmmConstructor (
DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxContext - %x\n", (UINTN)&mSmmLockBoxContext));
DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib LockBoxDataAddress - %x\n", (UINTN)&mLockBoxQueue));
- DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmConstructor - Exit\n"));
+ DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmConstructor - Exit\n"));
return Status;
}
@@ -284,26 +279,21 @@ SmmLockBoxSmmConstructor (
This is used to uninstall SmmLockBoxCommunication configuration table
if it has been installed in Constructor.
- @param[in] ImageHandle Image handle of this driver.
- @param[in] SystemTable A Pointer to the EFI System Table.
-
@retval EFI_SUCEESS The destructor always returns EFI_SUCCESS.
**/
EFI_STATUS
-EFIAPI
-SmmLockBoxSmmDestructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+SmmLockBoxMmDestructor (
+ VOID
)
{
EFI_STATUS Status;
- DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxSmmDestructor in %a module\n", gEfiCallerBaseName));
+ DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SmmLockBoxMmDestructor in %a module\n", gEfiCallerBaseName));
if (mSmmConfigurationTableInstalled) {
- Status = gSmst->SmmInstallConfigurationTable (
- gSmst,
+ Status = gMmst->MmInstallConfigurationTable (
+ gMmst,
&gEfiSmmLockBoxCommunicationGuid,
NULL,
0
@@ -316,8 +306,8 @@ SmmLockBoxSmmDestructor (
//
// Unregister SmmReadyToLock notification.
//
- Status = gSmst->SmmRegisterProtocolNotify (
- &gEfiSmmReadyToLockProtocolGuid,
+ Status = gMmst->MmRegisterProtocolNotify (
+ &gEfiMmReadyToLockProtocolGuid,
NULL,
&mSmmLockBoxRegistrationSmmReadyToLock
);
@@ -327,8 +317,8 @@ SmmLockBoxSmmDestructor (
//
// Unregister SmmEndOfDxe notification.
//
- Status = gSmst->SmmRegisterProtocolNotify (
- &gEfiSmmEndOfDxeProtocolGuid,
+ Status = gMmst->MmRegisterProtocolNotify (
+ &gEfiMmEndOfDxeProtocolGuid,
NULL,
&mSmmLockBoxRegistrationSmmEndOfDxe
);
@@ -338,7 +328,7 @@ SmmLockBoxSmmDestructor (
//
// Unregister EndOfS3Resume notification.
//
- Status = gSmst->SmmRegisterProtocolNotify (
+ Status = gMmst->MmRegisterProtocolNotify (
&gEdkiiEndOfS3ResumeGuid,
NULL,
&mSmmLockBoxRegistrationEndOfS3Resume
@@ -453,7 +443,7 @@ SaveLockBox (
//
// Allocate SMRAM buffer
//
- Status = gSmst->SmmAllocatePages (
+ Status = gMmst->MmAllocatePages (
AllocateAnyPages,
EfiRuntimeServicesData,
EFI_SIZE_TO_PAGES (Length),
@@ -468,14 +458,14 @@ SaveLockBox (
//
// Allocate LockBox
//
- Status = gSmst->SmmAllocatePool (
+ Status = gMmst->MmAllocatePool (
EfiRuntimeServicesData,
sizeof(*LockBox),
(VOID **)&LockBox
);
ASSERT_EFI_ERROR (Status);
if (EFI_ERROR (Status)) {
- gSmst->SmmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
+ gMmst->MmFreePages (SmramBuffer, EFI_SIZE_TO_PAGES (Length));
DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib SaveLockBox - Exit (%r)\n", EFI_OUT_OF_RESOURCES));
return EFI_OUT_OF_RESOURCES;
}
@@ -662,7 +652,7 @@ UpdateLockBox (
DEBUG_INFO,
"SmmLockBoxSmmLib UpdateLockBox - Allocate new buffer to enlarge.\n"
));
- Status = gSmst->SmmAllocatePages (
+ Status = gMmst->MmAllocatePages (
AllocateAnyPages,
EfiRuntimeServicesData,
EFI_SIZE_TO_PAGES (Offset + Length),
@@ -679,7 +669,7 @@ UpdateLockBox (
//
CopyMem ((VOID *)(UINTN)SmramBuffer, (VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
ZeroMem ((VOID *)(UINTN)LockBox->SmramBuffer, (UINTN)LockBox->Length);
- gSmst->SmmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES ((UINTN)LockBox->Length));
+ gMmst->MmFreePages (LockBox->SmramBuffer, EFI_SIZE_TO_PAGES ((UINTN)LockBox->Length));
LockBox->SmramBuffer = SmramBuffer;
}
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c
new file mode 100644
index 000000000000..722121da430b
--- /dev/null
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.c
@@ -0,0 +1,53 @@
+/** @file
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "SmmLockBoxLibPrivate.h"
+
+/**
+ Constructor for SmmLockBox library.
+ This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable A Pointer to the EFI System Table.
+
+ @retval EFI_SUCEESS
+ @return Others Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxStandaloneMmConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return SmmLockBoxMmConstructor ();
+}
+
+/**
+ Destructor for SmmLockBox library.
+ This is used to uninstall SmmLockBoxCommunication configuration table
+ if it has been installed in Constructor.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable A Pointer to the EFI System Table.
+
+ @retval EFI_SUCEESS The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxStandaloneMmDestructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return SmmLockBoxMmDestructor ();
+}
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
new file mode 100644
index 000000000000..a748abb16c54
--- /dev/null
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxTraditionalMmLib.c
@@ -0,0 +1,53 @@
+/** @file
+
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiSmm.h>
+
+#include "SmmLockBoxLibPrivate.h"
+
+/**
+ Constructor for SmmLockBox library.
+ This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable A Pointer to the EFI System Table.
+
+ @retval EFI_SUCEESS
+ @return Others Some error occurs.
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxTraditionalConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return SmmLockBoxMmConstructor ();
+}
+
+/**
+ Destructor for SmmLockBox library.
+ This is used to uninstall SmmLockBoxCommunication configuration table
+ if it has been installed in Constructor.
+
+ @param[in] ImageHandle Image handle of this driver.
+ @param[in] SystemTable A Pointer to the EFI System Table.
+
+ @retval EFI_SUCEESS The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+SmmLockBoxTraditionalDestructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return SmmLockBoxMmDestructor ();
+}
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
index 35311cb85d69..449333e94bc6 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxLibPrivate.h
@@ -43,5 +43,30 @@ typedef struct {
#pragma pack()
+/**
+ Constructor for SmmLockBox library.
+ This is used to set SmmLockBox context, which will be used in PEI phase in S3 boot path later.
+
+ @retval EFI_SUCEESS
+ @return Others Some error occurs.
+**/
+EFI_STATUS
+SmmLockBoxMmConstructor (
+ VOID
+ );
+
+/**
+ Destructor for SmmLockBox library.
+ This is used to uninstall SmmLockBoxCommunication configuration table
+ if it has been installed in Constructor.
+
+ @retval EFI_SUCEESS The destructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+SmmLockBoxMmDestructor (
+ VOID
+ );
+
#endif
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
index 2b6cc983b988..44f7b63c5d20 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
@@ -15,8 +15,8 @@ [Defines]
MODULE_TYPE = DXE_SMM_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = LockBoxLib|DXE_SMM_DRIVER
- CONSTRUCTOR = SmmLockBoxSmmConstructor
- DESTRUCTOR = SmmLockBoxSmmDestructor
+ CONSTRUCTOR = SmmLockBoxTraditionalConstructor
+ DESTRUCTOR = SmmLockBoxTraditionalDestructor
#
# The following information is for reference only and not required by the build tools.
@@ -25,7 +25,8 @@ [Defines]
#
[Sources]
- SmmLockBoxSmmLib.c
+ SmmLockBoxTraditionalMmLib.c
+ SmmLockBoxMmLib.c
SmmLockBoxLibPrivate.h
[Packages]
@@ -33,14 +34,14 @@ [Packages]
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
- SmmServicesTableLib
+ MmServicesTableLib
BaseLib
DebugLib
[Protocols]
- gEfiSmmReadyToLockProtocolGuid ## NOTIFY
- gEfiSmmEndOfDxeProtocolGuid ## NOTIFY
- gEfiSmmSxDispatch2ProtocolGuid ## NOTIFY
+ gEfiMmReadyToLockProtocolGuid ## NOTIFY
+ gEfiMmEndOfDxeProtocolGuid ## NOTIFY
+ gEfiMmSxDispatchProtocolGuid ## NOTIFY
[Guids]
## SOMETIMES_CONSUMES ## UNDEFINED # SmmSystemTable
diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
similarity index 52%
copy from MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
copy to MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
index 2b6cc983b988..d46dfb3f9aa8 100644
--- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
+++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
@@ -2,6 +2,7 @@
# SMM LockBox library instance.
#
# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -9,14 +10,14 @@
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = SmmLockBoxSmmLib
- MODULE_UNI_FILE = SmmLockBoxSmmLib.uni
- FILE_GUID = E04894D6-290D-4171-A362-0ACFD939F3C8
- MODULE_TYPE = DXE_SMM_DRIVER
+ BASE_NAME = SmmLockBoxStandaloneMmLib
+ FILE_GUID = 3C05978B-30CA-4544-9C5A-AB99265EFC31
+ MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
- LIBRARY_CLASS = LockBoxLib|DXE_SMM_DRIVER
- CONSTRUCTOR = SmmLockBoxSmmConstructor
- DESTRUCTOR = SmmLockBoxSmmDestructor
+ PI_SPECIFICATION_VERSION = 0x00010032
+ LIBRARY_CLASS = LockBoxLib|MM_STANDALONE
+ CONSTRUCTOR = SmmLockBoxStandaloneMmConstructor
+ DESTRUCTOR = SmmLockBoxStandaloneMmDestructor
#
# The following information is for reference only and not required by the build tools.
@@ -25,7 +26,8 @@ [Defines]
#
[Sources]
- SmmLockBoxSmmLib.c
+ SmmLockBoxStandaloneMmLib.c
+ SmmLockBoxMmLib.c
SmmLockBoxLibPrivate.h
[Packages]
@@ -33,14 +35,14 @@ [Packages]
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
- SmmServicesTableLib
+ MmServicesTableLib
BaseLib
DebugLib
[Protocols]
- gEfiSmmReadyToLockProtocolGuid ## NOTIFY
- gEfiSmmEndOfDxeProtocolGuid ## NOTIFY
- gEfiSmmSxDispatch2ProtocolGuid ## NOTIFY
+ gEfiMmReadyToLockProtocolGuid ## NOTIFY
+ gEfiMmEndOfDxeProtocolGuid ## NOTIFY
+ gEfiMmSxDispatchProtocolGuid ## NOTIFY
[Guids]
## SOMETIMES_CONSUMES ## UNDEFINED # SmmSystemTable
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 6d4e361afd51..9afd40eeed46 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -167,6 +167,7 @@ [LibraryClasses.common.MM_STANDALONE]
MemoryAllocationLib|MdeModulePkg/Library/BaseMemoryAllocationLibNull/BaseMemoryAllocationLibNull.inf
StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
+ LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
[LibraryClasses.ARM, LibraryClasses.AARCH64]
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
@@ -484,6 +485,7 @@ [Components.IA32, Components.X64]
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxPeiLib.inf
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxDxeLib.inf
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf
+ MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf
MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 07/20] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (2 preceding siblings ...)
2021-01-26 19:46 ` [PATCH v4 06/20] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
@ 2021-01-26 19:46 ` Kun Qin
2021-01-26 19:46 ` [PATCH v4 08/20] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver " Kun Qin
` (10 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:46 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao, Jiewen Yao
This change added support of StandaloneMm for ReportStatusCodeLib. It
adds a new instance of ReportStatusCodeLib for MM_STANDALONE type, and
abstracts the references of gMmst and gSmst functionalities into separate
files in order to link in proper Service Table for SMM core/drivers.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Added reviewed-by tag [Hao]
v2:
- Removed "EFIAPI" for internal functions.
- Minor new file description update.
MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c | 16 +++++----
MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c | 38 ++++++++++++++++++++
MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c | 38 ++++++++++++++++++++
MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h | 36 +++++++++++++++++++
MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf | 4 ++-
MdeModulePkg/Library/SmmReportStatusCodeLib/{SmmReportStatusCodeLib.inf => StandaloneMmReportStatusCodeLib.inf} | 22 ++++++------
MdeModulePkg/MdeModulePkg.dsc | 1 +
7 files changed, 137 insertions(+), 18 deletions(-)
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
index 3a1772538cdf..fb1769db9223 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.c
@@ -1,5 +1,5 @@
/** @file
- Report Status Code Library for SMM Phase.
+ Report Status Code Library for MM Phase.
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -8,7 +8,7 @@
#include <Library/ReportStatusCodeLib.h>
#include <Library/DebugLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/PcdLib.h>
@@ -16,10 +16,12 @@
#include <Guid/StatusCodeDataTypeId.h>
#include <Guid/StatusCodeDataTypeDebug.h>
-#include <Protocol/SmmStatusCode.h>
+#include <Protocol/MmStatusCode.h>
-EFI_SMM_REPORT_STATUS_CODE mReportStatusCode = NULL;
-EFI_SMM_STATUS_CODE_PROTOCOL *mStatusCodeProtocol = NULL;
+#include "ReportStatusCodeLib.h"
+
+EFI_MM_REPORT_STATUS_CODE mReportStatusCode = NULL;
+EFI_MM_STATUS_CODE_PROTOCOL *mStatusCodeProtocol = NULL;
/**
@@ -29,14 +31,14 @@ EFI_SMM_STATUS_CODE_PROTOCOL *mStatusCodeProtocol = NULL;
NULL is returned if no status code service is available.
**/
-EFI_SMM_REPORT_STATUS_CODE
+EFI_MM_REPORT_STATUS_CODE
InternalGetReportStatusCode (
VOID
)
{
EFI_STATUS Status;
- Status = gSmst->SmmLocateProtocol (&gEfiSmmStatusCodeProtocolGuid, NULL, (VOID**)&mStatusCodeProtocol);
+ Status = InternalLocateProtocol (&gEfiMmStatusCodeProtocolGuid, NULL, (VOID**)&mStatusCodeProtocol);
if (!EFI_ERROR (Status) && mStatusCodeProtocol != NULL) {
return mStatusCodeProtocol->ReportStatusCode;
}
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c
new file mode 100644
index 000000000000..a4c428dc88a9
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibStandaloneMm.c
@@ -0,0 +1,38 @@
+/** @file
+ Abstraction layer for MM service table used by MM ReportStatusCodeLib.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/MmServicesTableLib.h>
+
+/**
+ Returns the first protocol instance that matches the given protocol.
+
+ @param[in] Protocol Provides the protocol to search for.
+ @param[in] Registration Optional registration key returned from
+ RegisterProtocolNotify().
+ @param[out] Interface On return, a pointer to the first interface that matches Protocol and
+ Registration.
+
+ @retval EFI_SUCCESS A protocol instance matching Protocol was found and returned in
+ Interface.
+ @retval EFI_NOT_FOUND No protocol instances were found that match Protocol and
+ Registration.
+ @retval EFI_INVALID_PARAMETER Interface is NULL.
+ Protocol is NULL.
+
+**/
+EFI_STATUS
+InternalLocateProtocol (
+ IN EFI_GUID *Protocol,
+ IN VOID *Registration, OPTIONAL
+ OUT VOID **Interface
+ )
+{
+ return gMmst->MmLocateProtocol (Protocol, Registration, Interface);
+}
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c
new file mode 100644
index 000000000000..603e222f5508
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLibTraditional.c
@@ -0,0 +1,38 @@
+/** @file
+ Abstraction layer for SMM service table used by SMM ReportStatusCodeLib.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/SmmServicesTableLib.h>
+
+/**
+ Returns the first protocol instance that matches the given protocol.
+
+ @param[in] Protocol Provides the protocol to search for.
+ @param[in] Registration Optional registration key returned from
+ RegisterProtocolNotify().
+ @param[out] Interface On return, a pointer to the first interface that matches Protocol and
+ Registration.
+
+ @retval EFI_SUCCESS A protocol instance matching Protocol was found and returned in
+ Interface.
+ @retval EFI_NOT_FOUND No protocol instances were found that match Protocol and
+ Registration.
+ @retval EFI_INVALID_PARAMETER Interface is NULL.
+ Protocol is NULL.
+
+**/
+EFI_STATUS
+InternalLocateProtocol (
+ IN EFI_GUID *Protocol,
+ IN VOID *Registration, OPTIONAL
+ OUT VOID **Interface
+ )
+{
+ return gSmst->SmmLocateProtocol (Protocol, Registration, Interface);
+}
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
new file mode 100644
index 000000000000..2820e40dde19
--- /dev/null
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/ReportStatusCodeLib.h
@@ -0,0 +1,36 @@
+/** @file
+ Report Status Code Library for MM Phase.
+
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _MM_RSC_LIB_H_
+#define _MM_RSC_LIB_H_
+
+/**
+ Returns the first protocol instance that matches the given protocol.
+
+ @param[in] Protocol Provides the protocol to search for.
+ @param[in] Registration Optional registration key returned from
+ RegisterProtocolNotify().
+ @param[out] Interface On return, a pointer to the first interface that matches Protocol and
+ Registration.
+
+ @retval EFI_SUCCESS A protocol instance matching Protocol was found and returned in
+ Interface.
+ @retval EFI_NOT_FOUND No protocol instances were found that match Protocol and
+ Registration.
+ @retval EFI_INVALID_PARAMETER Interface is NULL.
+ Protocol is NULL.
+
+**/
+EFI_STATUS
+InternalLocateProtocol (
+ IN EFI_GUID *Protocol,
+ IN VOID *Registration, OPTIONAL
+ OUT VOID **Interface
+ );
+
+#endif // _MM_RSC_LIB_H_
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
index 72496bfababd..02dce09a199d 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
@@ -28,6 +28,8 @@ [Defines]
[Sources]
ReportStatusCodeLib.c
+ ReportStatusCodeLib.h
+ ReportStatusCodeLibTraditional.c
[Packages]
MdePkg/MdePkg.dec
@@ -45,7 +47,7 @@ [Guids]
gEfiStatusCodeDataTypeDebugGuid ## SOMETIMES_CONSUMES ## UNDEFINED
[Protocols]
- gEfiSmmStatusCodeProtocolGuid ## CONSUMES
+ gEfiMmStatusCodeProtocolGuid ## CONSUMES
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask ## CONSUMES
diff --git a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
similarity index 56%
copy from MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
copy to MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
index 72496bfababd..866e09249a6a 100644
--- a/MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
@@ -1,9 +1,10 @@
## @file
-# SMM report status code library.
+# Standalone MM report status code library.
#
-# Retrieve status code and report status code in SMM phase.
+# Retrieve status code and report status code in MM phase.
#
# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -12,13 +13,12 @@
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = SmmReportStatusCodeLib
- MODULE_UNI_FILE = SmmReportStatusCodeLib.uni
- FILE_GUID = 67089D19-B3D6-4d9e-A0EB-FEDC1F83A1EE
- MODULE_TYPE = DXE_SMM_DRIVER
+ BASE_NAME = StandaloneMmReportStatusCodeLib
+ FILE_GUID = 17C7FC8C-8C5D-497E-9C0E-C21255B30E04
+ MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
- PI_SPECIFICATION_VERSION = 0x0001000A
- LIBRARY_CLASS = ReportStatusCodeLib|DXE_SMM_DRIVER SMM_CORE
+ PI_SPECIFICATION_VERSION = 0x00010032
+ LIBRARY_CLASS = ReportStatusCodeLib|MM_STANDALONE
#
# The following information is for reference only and not required by the build tools.
@@ -28,6 +28,8 @@ [Defines]
[Sources]
ReportStatusCodeLib.c
+ ReportStatusCodeLib.h
+ ReportStatusCodeLibStandaloneMm.c
[Packages]
MdePkg/MdePkg.dec
@@ -36,7 +38,7 @@ [Packages]
[LibraryClasses]
PcdLib
BaseMemoryLib
- SmmServicesTableLib
+ MmServicesTableLib
DebugLib
MemoryAllocationLib
@@ -45,7 +47,7 @@ [Guids]
gEfiStatusCodeDataTypeDebugGuid ## SOMETIMES_CONSUMES ## UNDEFINED
[Protocols]
- gEfiSmmStatusCodeProtocolGuid ## CONSUMES
+ gEfiMmStatusCodeProtocolGuid ## CONSUMES
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask ## CONSUMES
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 9afd40eeed46..200fbcc18a18 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -474,6 +474,7 @@ [Components.IA32, Components.X64]
}
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
+ MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 08/20] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver in StandaloneMm
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (3 preceding siblings ...)
2021-01-26 19:46 ` [PATCH v4 07/20] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
@ 2021-01-26 19:46 ` Kun Qin
2021-01-26 19:46 ` [PATCH v4 09/20] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
` (9 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:46 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao, Jiewen Yao
This change added support of StandaloneMm for StatusCodeHandler. It
adds a new instance of StatusCodeHandler of MM_STANDALONE type, and
abstracts the driver entrypoint into separate files, replaced gSmst with
gMmst, and switched to MM version of RscHandlerProtocol.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Added reviewed-by tag [Hao]
v2:
- New patch to support StatusCodeHandler in standalone mm [Liming]
MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c | 36 ++++++++++----------
MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c | 2 +-
MdeModulePkg/Universal/StatusCodeHandler/Smm/{StatusCodeHandlerSmm.c => StatusCodeHandlerMm.c} | 23 +++++--------
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c | 31 +++++++++++++++++
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c | 31 +++++++++++++++++
MdeModulePkg/MdeModulePkg.dsc | 1 +
MdeModulePkg/Universal/StatusCodeHandler/Smm/{StatusCodeHandlerSmm.h => StatusCodeHandlerMm.h} | 23 ++++++++++---
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf | 15 ++++----
MdeModulePkg/Universal/StatusCodeHandler/Smm/{StatusCodeHandlerSmm.inf => StatusCodeHandlerStandaloneMm.inf} | 32 ++++++++---------
9 files changed, 132 insertions(+), 62 deletions(-)
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
index c9b43fd2468f..14bac8ec3c18 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/MemoryStatusCodeWorker.c
@@ -7,15 +7,15 @@
**/
-#include "StatusCodeHandlerSmm.h"
+#include "StatusCodeHandlerMm.h"
-RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;
+RUNTIME_MEMORY_STATUSCODE_HEADER *mMmMemoryStatusCodeTable;
/**
- Initialize SMM memory status code table as initialization for memory status code worker
+ Initialize MM memory status code table as initialization for memory status code worker
- @retval EFI_SUCCESS SMM memory status code table successfully initialized.
- @retval others Errors from gSmst->SmmInstallConfigurationTable().
+ @retval EFI_SUCCESS MM memory status code table successfully initialized.
+ @retval others Errors from gMmst->MmInstallConfigurationTable().
**/
EFI_STATUS
MemoryStatusCodeInitializeWorker (
@@ -25,17 +25,17 @@ MemoryStatusCodeInitializeWorker (
EFI_STATUS Status;
//
- // Allocate SMM memory status code pool.
+ // Allocate MM memory status code pool.
//
- mSmmMemoryStatusCodeTable = (RUNTIME_MEMORY_STATUSCODE_HEADER *)AllocateZeroPool (sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024);
- ASSERT (mSmmMemoryStatusCodeTable != NULL);
+ mMmMemoryStatusCodeTable = (RUNTIME_MEMORY_STATUSCODE_HEADER *)AllocateZeroPool (sizeof (RUNTIME_MEMORY_STATUSCODE_HEADER) + PcdGet16 (PcdStatusCodeMemorySize) * 1024);
+ ASSERT (mMmMemoryStatusCodeTable != NULL);
- mSmmMemoryStatusCodeTable->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
- Status = gSmst->SmmInstallConfigurationTable (
- gSmst,
+ mMmMemoryStatusCodeTable->MaxRecordsNumber = (PcdGet16 (PcdStatusCodeMemorySize) * 1024) / sizeof (MEMORY_STATUSCODE_RECORD);
+ Status = gMmst->MmInstallConfigurationTable (
+ gMmst,
&gMemoryStatusCodeRecordGuid,
- &mSmmMemoryStatusCodeTable,
- sizeof (mSmmMemoryStatusCodeTable)
+ &mMmMemoryStatusCodeTable,
+ sizeof (mMmMemoryStatusCodeTable)
);
return Status;
}
@@ -74,8 +74,8 @@ MemoryStatusCodeReportWorker (
//
// Locate current record buffer.
//
- Record = (MEMORY_STATUSCODE_RECORD *) (mSmmMemoryStatusCodeTable + 1);
- Record = &Record[mSmmMemoryStatusCodeTable->RecordIndex++];
+ Record = (MEMORY_STATUSCODE_RECORD *) (mMmMemoryStatusCodeTable + 1);
+ Record = &Record[mMmMemoryStatusCodeTable->RecordIndex++];
//
// Save status code.
@@ -92,12 +92,12 @@ MemoryStatusCodeReportWorker (
// so the first record is pointed by record index.
// If it is less then max number, index of the first record is zero.
//
- mSmmMemoryStatusCodeTable->NumberOfRecords++;
- if (mSmmMemoryStatusCodeTable->RecordIndex == mSmmMemoryStatusCodeTable->MaxRecordsNumber) {
+ mMmMemoryStatusCodeTable->NumberOfRecords++;
+ if (mMmMemoryStatusCodeTable->RecordIndex == mMmMemoryStatusCodeTable->MaxRecordsNumber) {
//
// Wrap around record index.
//
- mSmmMemoryStatusCodeTable->RecordIndex = 0;
+ mMmMemoryStatusCodeTable->RecordIndex = 0;
}
return EFI_SUCCESS;
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c
index 3df0a6712611..bcb75bc7b170 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/SerialStatusCodeWorker.c
@@ -6,7 +6,7 @@
**/
-#include "StatusCodeHandlerSmm.h"
+#include "StatusCodeHandlerMm.h"
/**
Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.c
similarity index 69%
rename from MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c
rename to MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.c
index 20271571ded4..4948d3d99ad6 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.c
@@ -1,15 +1,15 @@
/** @file
Status Code Handler Driver which produces general handlers and hook them
- onto the SMM status code router.
+ onto the MM status code router.
Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include "StatusCodeHandlerSmm.h"
+#include "StatusCodeHandlerMm.h"
-EFI_SMM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
+EFI_MM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
/**
@@ -42,27 +42,22 @@ InitializationDispatcherWorker (
}
/**
- Entry point of SMM Status Code Driver.
+ Entry point of Common MM Status Code Driver.
- This function is the entry point of SMM Status Code Driver.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
+ This function is the entry point of MM Status Code Driver.
@retval EFI_SUCCESS The entry point is executed successfully.
**/
EFI_STATUS
-EFIAPI
-StatusCodeHandlerSmmEntry (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+StatusCodeHandlerCommonEntry (
+ VOID
)
{
EFI_STATUS Status;
- Status = gSmst->SmmLocateProtocol (
- &gEfiSmmRscHandlerProtocolGuid,
+ Status = gMmst->MmLocateProtocol (
+ &gEfiMmRscHandlerProtocolGuid,
NULL,
(VOID **) &mRscHandlerProtocol
);
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c
new file mode 100644
index 000000000000..11a61705d612
--- /dev/null
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandalone.c
@@ -0,0 +1,31 @@
+/** @file
+ Abstraction layer that contains Standalone MM specific implementation for
+ Status Code Handler Driver.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "StatusCodeHandlerMm.h"
+
+/**
+ Entry point of Standalone MM Status Code Driver.
+
+ This function is the entry point of Standalone MM Status Code Driver.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI MM System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+StatusCodeHandlerStandaloneMmEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return StatusCodeHandlerCommonEntry ();
+}
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c
new file mode 100644
index 000000000000..1105f184b08e
--- /dev/null
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerTraditional.c
@@ -0,0 +1,31 @@
+/** @file
+ Abstraction layer that contains Standalone MM specific implementation for
+ Status Code Handler Driver.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "StatusCodeHandlerMm.h"
+
+/**
+ Entry point of Traditional MM Status Code Driver.
+
+ This function is the entry point of Traditional MM Status Code Driver.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+StatusCodeHandlerTraditionalMmEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return StatusCodeHandlerCommonEntry ();
+}
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 200fbcc18a18..098909490095 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -476,6 +476,7 @@ [Components.IA32, Components.X64]
MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
MdeModulePkg/Library/SmmReportStatusCodeLib/StandaloneMmReportStatusCodeLib.inf
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
+ MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryAllocationProfileLib.inf
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.h
similarity index 87%
rename from MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h
rename to MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.h
index 6b5d53a4fee3..7871ee404046 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.h
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerMm.h
@@ -7,10 +7,10 @@
**/
-#ifndef __STATUS_CODE_HANDLER_SMM_H__
-#define __STATUS_CODE_HANDLER_SMM_H__
+#ifndef __STATUS_CODE_HANDLER_MM_H__
+#define __STATUS_CODE_HANDLER_MM_H__
-#include <Protocol/SmmReportStatusCodeHandler.h>
+#include <Protocol/MmReportStatusCodeHandler.h>
#include <Guid/MemoryStatusCodeRecord.h>
#include <Guid/StatusCodeDataTypeId.h>
@@ -22,7 +22,7 @@
#include <Library/PrintLib.h>
#include <Library/PcdLib.h>
#include <Library/UefiDriverEntryPoint.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/SerialPortLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
@@ -32,7 +32,7 @@
//
#define MAX_DEBUG_MESSAGE_LENGTH 0x100
-extern RUNTIME_MEMORY_STATUSCODE_HEADER *mSmmMemoryStatusCodeTable;
+extern RUNTIME_MEMORY_STATUSCODE_HEADER *mMmMemoryStatusCodeTable;
/**
Locates Serial I/O Protocol as initialization for serial status code worker.
@@ -114,4 +114,17 @@ MemoryStatusCodeReportWorker (
IN EFI_STATUS_CODE_DATA *Data OPTIONAL
);
+/**
+ Entry point of Common MM Status Code Driver.
+
+ This function is the entry point of MM Status Code Driver.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+StatusCodeHandlerCommonEntry (
+ VOID
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
index 4e24d87e55d1..90abe662d291 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
@@ -1,5 +1,5 @@
## @file
-# Status Code Handler Driver which produces general handlers and hook them onto the SMM status code router.
+# Status Code Handler Driver which produces general handlers and hook them onto the MM status code router.
#
# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
@@ -17,7 +17,7 @@ [Defines]
MODULE_TYPE = DXE_SMM_DRIVER
PI_SPECIFICATION_VERSION = 0x0001000A
VERSION_STRING = 1.0
- ENTRY_POINT = StatusCodeHandlerSmmEntry
+ ENTRY_POINT = StatusCodeHandlerTraditionalMmEntry
#
# The following information is for reference only and not required by the build tools.
@@ -26,8 +26,9 @@ [Defines]
#
[Sources]
- StatusCodeHandlerSmm.c
- StatusCodeHandlerSmm.h
+ StatusCodeHandlerMm.c
+ StatusCodeHandlerMm.h
+ StatusCodeHandlerTraditional.c
SerialStatusCodeWorker.c
MemoryStatusCodeWorker.c
@@ -37,7 +38,7 @@ [Packages]
[LibraryClasses]
SerialPortLib
- SmmServicesTableLib
+ MmServicesTableLib
UefiDriverEntryPoint
PcdLib
PrintLib
@@ -51,7 +52,7 @@ [Guids]
gMemoryStatusCodeRecordGuid ## SOMETIMES_PRODUCES ## UNDEFINED # SmmSystemTable
[Protocols]
- gEfiSmmRscHandlerProtocolGuid ## CONSUMES
+ gEfiMmRscHandlerProtocolGuid ## CONSUMES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial ## CONSUMES
@@ -59,7 +60,7 @@ [Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize |128| gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory ## SOMETIMES_CONSUMES
[Depex]
- gEfiSmmRscHandlerProtocolGuid
+ gEfiMmRscHandlerProtocolGuid
[UserExtensions.TianoCore."ExtraFiles"]
StatusCodeHandlerSmmExtra.uni
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
similarity index 62%
copy from MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
copy to MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
index 4e24d87e55d1..d7c863bf064c 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
+++ b/MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
@@ -1,8 +1,9 @@
## @file
-# Status Code Handler Driver which produces general handlers and hook them onto the SMM status code router.
+# Status Code Handler Driver which produces general handlers and hook them onto the MM status code router.
#
# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
+# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -11,13 +12,12 @@
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = StatusCodeHandlerSmm
- MODULE_UNI_FILE = StatusCodeHandlerSmm.uni
- FILE_GUID = 79CD78D8-6EDC-4978-BD02-3299C387AB17
- MODULE_TYPE = DXE_SMM_DRIVER
- PI_SPECIFICATION_VERSION = 0x0001000A
+ BASE_NAME = StatusCodeHandlerStandaloneMm
+ FILE_GUID = EBE7802F-5E11-4D4E-B463-22D2425D156B
+ MODULE_TYPE = MM_STANDALONE
+ PI_SPECIFICATION_VERSION = 0x00010032
VERSION_STRING = 1.0
- ENTRY_POINT = StatusCodeHandlerSmmEntry
+ ENTRY_POINT = StatusCodeHandlerStandaloneMmEntry
#
# The following information is for reference only and not required by the build tools.
@@ -26,8 +26,9 @@ [Defines]
#
[Sources]
- StatusCodeHandlerSmm.c
- StatusCodeHandlerSmm.h
+ StatusCodeHandlerMm.c
+ StatusCodeHandlerMm.h
+ StatusCodeHandlerStandalone.c
SerialStatusCodeWorker.c
MemoryStatusCodeWorker.c
@@ -37,8 +38,8 @@ [Packages]
[LibraryClasses]
SerialPortLib
- SmmServicesTableLib
- UefiDriverEntryPoint
+ MmServicesTableLib
+ StandaloneMmDriverEntryPoint
PcdLib
PrintLib
ReportStatusCodeLib
@@ -48,10 +49,10 @@ [LibraryClasses]
[Guids]
gEfiStatusCodeDataTypeStringGuid ## SOMETIMES_CONSUMES ## UNDEFINED
- gMemoryStatusCodeRecordGuid ## SOMETIMES_PRODUCES ## UNDEFINED # SmmSystemTable
+ gMemoryStatusCodeRecordGuid ## SOMETIMES_PRODUCES ## UNDEFINED # MmSystemTable
[Protocols]
- gEfiSmmRscHandlerProtocolGuid ## CONSUMES
+ gEfiMmRscHandlerProtocolGuid ## CONSUMES
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial ## CONSUMES
@@ -59,7 +60,4 @@ [Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize |128| gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory ## SOMETIMES_CONSUMES
[Depex]
- gEfiSmmRscHandlerProtocolGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
- StatusCodeHandlerSmmExtra.uni
+ gEfiMmRscHandlerProtocolGuid
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 09/20] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (4 preceding siblings ...)
2021-01-26 19:46 ` [PATCH v4 08/20] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver " Kun Qin
@ 2021-01-26 19:46 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 10/20] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
` (8 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:46 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao
This change added support of FPDT driver under StandaloneMm. It replaces
SMM version ReportStatusCode protocol with MM version. This patch also
abstracts standalone and traditional MM interfaces into separate files to
support each corresponding function prototypes and implementations.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Added reviewed-by tag [Hao]
v2:
- Removed "EFIAPI" for internally abstracted functions [Hao]
- Support driver for both IA32 and X64 in dsc file [Hao]
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerformanceSmm.c => FirmwarePerformanceCommon.c} | 76 +++++++++-----------
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c | 61 ++++++++++++++++
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c | 61 ++++++++++++++++
MdeModulePkg/MdeModulePkg.dsc | 2 +
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h | 50 +++++++++++++
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf | 11 +--
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/{FirmwarePerformanceSmm.inf => FirmwarePerformanceStandaloneMm.inf} | 31 ++++----
7 files changed, 230 insertions(+), 62 deletions(-)
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
similarity index 75%
rename from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
rename to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
index d6c6e7693e4d..ecadef8711ed 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.c
@@ -1,11 +1,11 @@
/** @file
- This module collects performance data for SMM driver boot records and S3 Suspend Performance Record.
+ This module collects performance data for MM driver boot records and S3 Suspend Performance Record.
This module registers report status code listener to collect performance data
- for SMM driver boot records and S3 Suspend Performance Record.
+ for MM driver boot records and S3 Suspend Performance Record.
Caution: This module requires additional review when modified.
- This driver will have external input - communicate buffer in SMM mode.
+ This driver will have external input - communicate buffer in MM mode.
This external input must be validated carefully to avoid security issue like
buffer overflow, integer overflow.
@@ -16,13 +16,13 @@
**/
-#include <PiSmm.h>
+#include <PiMm.h>
-#include <Protocol/SmmReportStatusCodeHandler.h>
+#include <Protocol/MmReportStatusCodeHandler.h>
#include <Guid/FirmwarePerformance.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/TimerLib.h>
@@ -30,23 +30,22 @@
#include <Library/PcdLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
#include <Library/SynchronizationLib.h>
-#include <Library/SmmMemLib.h>
+#include "FirmwarePerformanceCommon.h"
-SMM_BOOT_PERFORMANCE_TABLE *mSmmBootPerformanceTable = NULL;
+SMM_BOOT_PERFORMANCE_TABLE *mMmBootPerformanceTable = NULL;
-EFI_SMM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
+EFI_MM_RSC_HANDLER_PROTOCOL *mRscHandlerProtocol = NULL;
UINT64 mSuspendStartTime = 0;
BOOLEAN mS3SuspendLockBoxSaved = FALSE;
UINT32 mBootRecordSize = 0;
UINT8 *mBootRecordBuffer = NULL;
-SPIN_LOCK mSmmFpdtLock;
-BOOLEAN mSmramIsOutOfResource = FALSE;
+SPIN_LOCK mMmFpdtLock;
+BOOLEAN mMmramIsOutOfResource = FALSE;
/**
- Report status code listener for SMM. This is used to record the performance
+ Report status code listener for MM. This is used to record the performance
data for S3 Suspend Start and S3 Suspend End in FPDT.
@param[in] CodeType Indicates the type of status code being reported.
@@ -66,7 +65,7 @@ BOOLEAN mSmramIsOutOfResource = FALSE;
**/
EFI_STATUS
EFIAPI
-FpdtStatusCodeListenerSmm (
+FpdtStatusCodeListenerMm (
IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
@@ -89,19 +88,19 @@ FpdtStatusCodeListenerSmm (
// Collect one or more Boot records in boot time
//
if (Data != NULL && CompareGuid (&Data->Type, &gEdkiiFpdtExtendedFirmwarePerformanceGuid)) {
- AcquireSpinLock (&mSmmFpdtLock);
+ AcquireSpinLock (&mMmFpdtLock);
//
// Get the boot performance data.
//
- CopyMem (&mSmmBootPerformanceTable, Data + 1, Data->Size);
- mBootRecordBuffer = ((UINT8 *) (mSmmBootPerformanceTable)) + sizeof (SMM_BOOT_PERFORMANCE_TABLE);
+ CopyMem (&mMmBootPerformanceTable, Data + 1, Data->Size);
+ mBootRecordBuffer = ((UINT8 *) (mMmBootPerformanceTable)) + sizeof (SMM_BOOT_PERFORMANCE_TABLE);
- ReleaseSpinLock (&mSmmFpdtLock);
+ ReleaseSpinLock (&mMmFpdtLock);
return EFI_SUCCESS;
}
if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {
- DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerSmm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableSmm\n"));
+ DEBUG ((DEBUG_ERROR, "FpdtStatusCodeListenerMm: Performance data reported through gEfiFirmwarePerformanceGuid will not be collected by FirmwarePerformanceDataTableMm\n"));
return EFI_UNSUPPORTED;
}
@@ -157,7 +156,7 @@ FpdtStatusCodeListenerSmm (
/**
Communication service SMI Handler entry.
- This SMI handler provides services for report SMM boot records.
+ This SMI handler provides services for report MM boot records.
Caution: This function may receive untrusted input.
Communicate buffer and buffer size are external input, so this function will do basic validation.
@@ -166,7 +165,7 @@ FpdtStatusCodeListenerSmm (
@param[in] RegisterContext Points to an optional handler context which was specified when the
handler was registered.
@param[in, out] CommBuffer A pointer to a collection of data in memory that will
- be conveyed from a non-SMM environment into an SMM environment.
+ be conveyed from a non-MM environment into an MM environment.
@param[in, out] CommBufferSize The size of the CommBuffer.
@retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
@@ -207,8 +206,8 @@ FpdtSmiHandler (
return EFI_SUCCESS;
}
- if (!SmmIsBufferOutsideSmmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
- DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM communication data buffer in SMRAM or overflow!\n"));
+ if (!IsBufferOutsideMmValid ((UINTN)CommBuffer, TempCommBufferSize)) {
+ DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM communication data buffer in MMRAM or overflow!\n"));
return EFI_SUCCESS;
}
@@ -218,8 +217,8 @@ FpdtSmiHandler (
switch (SmmCommData->Function) {
case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :
- if (mSmmBootPerformanceTable != NULL) {
- mBootRecordSize = mSmmBootPerformanceTable->Header.Length - sizeof (SMM_BOOT_PERFORMANCE_TABLE);
+ if (mMmBootPerformanceTable != NULL) {
+ mBootRecordSize = mMmBootPerformanceTable->Header.Length - sizeof (SMM_BOOT_PERFORMANCE_TABLE);
}
SmmCommData->BootRecordSize = mBootRecordSize;
break;
@@ -244,8 +243,8 @@ FpdtSmiHandler (
BootRecordSize = mBootRecordSize - BootRecordOffset;
}
SmmCommData->BootRecordSize = BootRecordSize;
- if (!SmmIsBufferOutsideSmmValid ((UINTN)BootRecordData, BootRecordSize)) {
- DEBUG ((EFI_D_ERROR, "FpdtSmiHandler: SMM Data buffer in SMRAM or overflow!\n"));
+ if (!IsBufferOutsideMmValid ((UINTN)BootRecordData, BootRecordSize)) {
+ DEBUG ((DEBUG_ERROR, "FpdtSmiHandler: MM Data buffer in MMRAM or overflow!\n"));
Status = EFI_ACCESS_DENIED;
break;
}
@@ -267,20 +266,15 @@ FpdtSmiHandler (
}
/**
- The module Entry Point of the Firmware Performance Data Table SMM driver.
-
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
+ The module Entry Point of the Firmware Performance Data Table MM driver.
@retval EFI_SUCCESS The entry point is executed successfully.
@retval Other Some error occurs when executing this entry point.
**/
EFI_STATUS
-EFIAPI
-FirmwarePerformanceSmmEntryPoint (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+FirmwarePerformanceCommonEntryPoint (
+ VOID
)
{
EFI_STATUS Status;
@@ -289,13 +283,13 @@ FirmwarePerformanceSmmEntryPoint (
//
// Initialize spin lock
//
- InitializeSpinLock (&mSmmFpdtLock);
+ InitializeSpinLock (&mMmFpdtLock);
//
- // Get SMM Report Status Code Handler Protocol.
+ // Get MM Report Status Code Handler Protocol.
//
- Status = gSmst->SmmLocateProtocol (
- &gEfiSmmRscHandlerProtocolGuid,
+ Status = gMmst->MmLocateProtocol (
+ &gEfiMmRscHandlerProtocolGuid,
NULL,
(VOID **) &mRscHandlerProtocol
);
@@ -304,14 +298,14 @@ FirmwarePerformanceSmmEntryPoint (
//
// Register report status code listener for BootRecords and S3 Suspend Start and End.
//
- Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);
+ Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerMm);
ASSERT_EFI_ERROR (Status);
//
// Register SMI handler.
//
Handle = NULL;
- Status = gSmst->SmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &Handle);
+ Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &Handle);
ASSERT_EFI_ERROR (Status);
return Status;
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c
new file mode 100644
index 000000000000..d7da61c98c66
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.c
@@ -0,0 +1,61 @@
+/** @file
+ This module collects performance data for MM driver boot records and S3 Suspend Performance Record.
+
+ This module registers report status code listener to collect performance data
+ for MM driver boot records and S3 Suspend Performance Record.
+
+ Caution: This module requires additional review when modified.
+ This driver will have external input - communicate buffer in MM mode.
+ This external input must be validated carefully to avoid security issue like
+ buffer overflow, integer overflow.
+
+ FpdtSmiHandler() will receive untrusted input and do basic validation.
+
+ Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c), Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include <Library/StandaloneMmMemLib.h>
+#include "FirmwarePerformanceCommon.h"
+
+/**
+ This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+ @param Buffer The buffer start address to be checked.
+ @param Length The buffer length to be checked.
+
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM.
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+IsBufferOutsideMmValid (
+ IN EFI_PHYSICAL_ADDRESS Buffer,
+ IN UINT64 Length
+ )
+{
+ return MmIsBufferOutsideMmValid (Buffer, Length);
+}
+
+/**
+ The module Entry Point of the Firmware Performance Data Table MM driver.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI MM System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+FirmwarePerformanceStandaloneMmEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return FirmwarePerformanceCommonEntryPoint ();
+}
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c
new file mode 100644
index 000000000000..43c050d6b516
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceTraditional.c
@@ -0,0 +1,61 @@
+/** @file
+ This module collects performance data for MM driver boot records and S3 Suspend Performance Record.
+
+ This module registers report status code listener to collect performance data
+ for MM driver boot records and S3 Suspend Performance Record.
+
+ Caution: This module requires additional review when modified.
+ This driver will have external input - communicate buffer in MM mode.
+ This external input must be validated carefully to avoid security issue like
+ buffer overflow, integer overflow.
+
+ FpdtSmiHandler() will receive untrusted input and do basic validation.
+
+ Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c), Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiSmm.h>
+
+#include <Library/SmmMemLib.h>
+#include "FirmwarePerformanceCommon.h"
+
+/**
+ This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+ @param Buffer The buffer start address to be checked.
+ @param Length The buffer length to be checked.
+
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM.
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+IsBufferOutsideMmValid (
+ IN EFI_PHYSICAL_ADDRESS Buffer,
+ IN UINT64 Length
+ )
+{
+ return SmmIsBufferOutsideSmmValid (Buffer, Length);
+}
+
+/**
+ The module Entry Point of the Firmware Performance Data Table MM driver.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+FirmwarePerformanceSmmEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return FirmwarePerformanceCommonEntryPoint ();
+}
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 098909490095..34ca571ca662 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -168,6 +168,7 @@ [LibraryClasses.common.MM_STANDALONE]
StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
+ MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf
[LibraryClasses.ARM, LibraryClasses.AARCH64]
ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
@@ -495,6 +496,7 @@ [Components.IA32, Components.X64]
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
MdeModulePkg/Universal/Acpi/SmmS3SaveState/SmmS3SaveState.inf
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
+ MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.inf
MdeModulePkg/Universal/RegularExpressionDxe/RegularExpressionDxe.inf
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h
new file mode 100644
index 000000000000..0fbdac02de4c
--- /dev/null
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceCommon.h
@@ -0,0 +1,50 @@
+/** @file
+ This module collects performance data for SMM driver boot records and S3 Suspend Performance Record.
+
+ This module registers report status code listener to collect performance data
+ for SMM driver boot records and S3 Suspend Performance Record.
+
+ Caution: This module requires additional review when modified.
+ This driver will have external input - communicate buffer in SMM mode.
+ This external input must be validated carefully to avoid security issue like
+ buffer overflow, integer overflow.
+
+ FpdtSmiHandler() will receive untrusted input and do basic validation.
+
+ Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c), Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _FW_PERF_COMMON_H_
+#define _FW_PERF_COMMON_H_
+
+/**
+ This function is an abstraction layer for implementation specific Mm buffer validation routine.
+
+ @param Buffer The buffer start address to be checked.
+ @param Length The buffer length to be checked.
+
+ @retval TRUE This buffer is valid per processor architecture and not overlap with SMRAM.
+ @retval FALSE This buffer is not valid per processor architecture or overlap with SMRAM.
+**/
+BOOLEAN
+IsBufferOutsideMmValid (
+ IN EFI_PHYSICAL_ADDRESS Buffer,
+ IN UINT64 Length
+ );
+
+/**
+ The module Entry Point of the Firmware Performance Data Table MM driver.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+FirmwarePerformanceCommonEntryPoint (
+ VOID
+ );
+
+#endif // _FW_PERF_COMMON_H_
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
index 618cbd56ca59..b7194bd899dd 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
@@ -26,7 +26,9 @@ [Defines]
#
[Sources]
- FirmwarePerformanceSmm.c
+ FirmwarePerformanceCommon.c
+ FirmwarePerformanceCommon.h
+ FirmwarePerformanceTraditional.c
[Packages]
MdePkg/MdePkg.dec
@@ -34,7 +36,7 @@ [Packages]
[LibraryClasses]
UefiDriverEntryPoint
- SmmServicesTableLib
+ MmServicesTableLib
BaseLib
DebugLib
TimerLib
@@ -42,12 +44,11 @@ [LibraryClasses]
PcdLib
BaseMemoryLib
MemoryAllocationLib
- UefiBootServicesTableLib
SynchronizationLib
SmmMemLib
[Protocols]
- gEfiSmmRscHandlerProtocolGuid ## CONSUMES
+ gEfiMmRscHandlerProtocolGuid ## CONSUMES
[Guids]
## SOMETIMES_PRODUCES ## UNDEFINED # SaveLockBox
@@ -61,7 +62,7 @@ [Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd ## CONSUMES
[Depex]
- gEfiSmmRscHandlerProtocolGuid
+ gEfiMmRscHandlerProtocolGuid
[UserExtensions.TianoCore."ExtraFiles"]
FirmwarePerformanceSmmExtra.uni
diff --git a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
similarity index 65%
copy from MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
copy to MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
index 618cbd56ca59..e6aad88be0ef 100644
--- a/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf
+++ b/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceStandaloneMm.inf
@@ -5,19 +5,19 @@
# for SMM boot performance records and S3 Suspend Performance Record.
#
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = FirmwarePerformanceSmm
- MODULE_UNI_FILE = FirmwarePerformanceSmm.uni
- FILE_GUID = 044310AB-77FD-402a-AF1A-87D4120E7329
- MODULE_TYPE = DXE_SMM_DRIVER
+ BASE_NAME = FirmwarePerformanceStandaloneMm
+ FILE_GUID = 827AC29D-E52D-4B1A-874A-C6577E0699CF
+ MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
- PI_SPECIFICATION_VERSION = 0x0001000A
- ENTRY_POINT = FirmwarePerformanceSmmEntryPoint
+ PI_SPECIFICATION_VERSION = 0x00010032
+ ENTRY_POINT = FirmwarePerformanceStandaloneMmEntryPoint
#
# The following information is for reference only and not required by the build tools.
@@ -26,15 +26,18 @@ [Defines]
#
[Sources]
- FirmwarePerformanceSmm.c
+ FirmwarePerformanceCommon.c
+ FirmwarePerformanceCommon.h
+ FirmwarePerformanceStandaloneMm.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
+ StandaloneMmPkg/StandaloneMmPkg.dec
[LibraryClasses]
- UefiDriverEntryPoint
- SmmServicesTableLib
+ StandaloneMmDriverEntryPoint
+ MmServicesTableLib
BaseLib
DebugLib
TimerLib
@@ -42,12 +45,11 @@ [LibraryClasses]
PcdLib
BaseMemoryLib
MemoryAllocationLib
- UefiBootServicesTableLib
SynchronizationLib
- SmmMemLib
+ MemLib
[Protocols]
- gEfiSmmRscHandlerProtocolGuid ## CONSUMES
+ gEfiMmRscHandlerProtocolGuid ## CONSUMES
[Guids]
## SOMETIMES_PRODUCES ## UNDEFINED # SaveLockBox
@@ -61,7 +63,4 @@ [Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd ## CONSUMES
[Depex]
- gEfiSmmRscHandlerProtocolGuid
-
-[UserExtensions.TianoCore."ExtraFiles"]
- FirmwarePerformanceSmmExtra.uni
+ gEfiMmRscHandlerProtocolGuid
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 10/20] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (5 preceding siblings ...)
2021-01-26 19:46 ` [PATCH v4 09/20] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib: Support StandaloneMm Instance Kun Qin
` (7 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu, Dandan Bi, Liming Gao
This change added support of RSC router under StandaloneMm. It replaces
SMM version ReportStatusCode protocol definitions with MM version. This
patch also switched to use gMmst instead of gSmst. Lastly, it abstracts
standalone and traditional MM driver entrypoints into separate files to
allow maximal common implementations.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Added reviewed-by tag [Hao]
- Updated function descriptions to match function interface [Hao]
v2:
- Removed "EFIAPI" for internally abstracted functions [Hao]
- Updated function descriptions [Hao]
- Updated ReportDispatcher to make *.h and *.c consistent [Hao]
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCodeRouterSmm.c => ReportStatusCodeRouterCommon.c} | 59 +++++++++-----------
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c | 33 +++++++++++
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c | 33 +++++++++++
MdeModulePkg/MdeModulePkg.dsc | 1 +
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/{ReportStatusCodeRouterSmm.h => ReportStatusCodeRouterCommon.h} | 46 +++++++++------
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf | 13 +++--
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf | 49 ++++++++++++++++
7 files changed, 179 insertions(+), 55 deletions(-)
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
similarity index 74%
rename from MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c
rename to MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
index c3ab5cd05045..c4843a745d69 100644
--- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.c
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.c
@@ -7,7 +7,7 @@
**/
-#include "ReportStatusCodeRouterSmm.h"
+#include "ReportStatusCodeRouterCommon.h"
LIST_ENTRY mCallbackListHead = INITIALIZE_LIST_HEAD_VARIABLE (mCallbackListHead);
@@ -17,11 +17,11 @@ LIST_ENTRY mCallbackListHead = INITIALIZE_LIST_HEAD_VARIABLE (mCallba
//
UINT32 mStatusCodeNestStatus = 0;
-EFI_SMM_STATUS_CODE_PROTOCOL mSmmStatusCodeProtocol = {
+EFI_MM_STATUS_CODE_PROTOCOL mSmmStatusCodeProtocol = {
ReportDispatcher
};
-EFI_SMM_RSC_HANDLER_PROTOCOL mSmmRscHandlerProtocol = {
+EFI_MM_RSC_HANDLER_PROTOCOL mSmmRscHandlerProtocol = {
Register,
Unregister
};
@@ -45,18 +45,18 @@ EFI_SMM_RSC_HANDLER_PROTOCOL mSmmRscHandlerProtocol = {
EFI_STATUS
EFIAPI
Register (
- IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
+ IN EFI_MM_RSC_HANDLER_CALLBACK Callback
)
{
LIST_ENTRY *Link;
- SMM_RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;
+ MM_RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;
if (Callback == NULL) {
return EFI_INVALID_PARAMETER;
}
for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link); Link = GetNextNode (&mCallbackListHead, Link)) {
- CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
+ CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
if (CallbackEntry->RscHandlerCallback == Callback) {
//
// If the function was already registered. It can't be registered again.
@@ -65,10 +65,10 @@ Register (
}
}
- CallbackEntry = (SMM_RSC_HANDLER_CALLBACK_ENTRY *)AllocatePool (sizeof (SMM_RSC_HANDLER_CALLBACK_ENTRY));
+ CallbackEntry = (MM_RSC_HANDLER_CALLBACK_ENTRY *)AllocatePool (sizeof (MM_RSC_HANDLER_CALLBACK_ENTRY));
ASSERT (CallbackEntry != NULL);
- CallbackEntry->Signature = SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;
+ CallbackEntry->Signature = MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;
CallbackEntry->RscHandlerCallback = Callback;
InsertTailList (&mCallbackListHead, &CallbackEntry->Node);
@@ -92,18 +92,18 @@ Register (
EFI_STATUS
EFIAPI
Unregister (
- IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
+ IN EFI_MM_RSC_HANDLER_CALLBACK Callback
)
{
LIST_ENTRY *Link;
- SMM_RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;
+ MM_RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;
if (Callback == NULL) {
return EFI_INVALID_PARAMETER;
}
for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link); Link = GetNextNode (&mCallbackListHead, Link)) {
- CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
+ CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
if (CallbackEntry->RscHandlerCallback == Callback) {
//
// If the function is found in list, delete it and return.
@@ -121,8 +121,8 @@ Unregister (
/**
Provides an interface that a software module can call to report a status code.
- @param This EFI_SMM_STATUS_CODE_PROTOCOL instance.
- @param Type Indicates the type of status code being reported.
+ @param This EFI_MM_STATUS_CODE_PROTOCOL instance.
+ @param CodeType Indicates the type of status code being reported.
@param Value Describes the current status of a hardware or software entity.
This included information about the class and subclass that is used to
classify the entity as well as an operation.
@@ -140,16 +140,16 @@ Unregister (
EFI_STATUS
EFIAPI
ReportDispatcher (
- IN CONST EFI_SMM_STATUS_CODE_PROTOCOL *This,
- IN EFI_STATUS_CODE_TYPE Type,
+ IN CONST EFI_MM_STATUS_CODE_PROTOCOL *This,
+ IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
- IN CONST EFI_GUID *CallerId OPTIONAL,
+ IN CONST EFI_GUID *CallerId,
IN EFI_STATUS_CODE_DATA *Data OPTIONAL
)
{
LIST_ENTRY *Link;
- SMM_RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;
+ MM_RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;
//
// Use atom operation to avoid the reentant of report.
@@ -160,13 +160,13 @@ ReportDispatcher (
}
for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link);) {
- CallbackEntry = CR (Link, SMM_RSC_HANDLER_CALLBACK_ENTRY, Node, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
+ CallbackEntry = CR (Link, MM_RSC_HANDLER_CALLBACK_ENTRY, Node, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);
//
// The handler may remove itself, so get the next handler in advance.
//
Link = GetNextNode (&mCallbackListHead, Link);
CallbackEntry->RscHandlerCallback (
- Type,
+ CodeType,
Value,
Instance,
(EFI_GUID*)CallerId,
@@ -186,20 +186,15 @@ ReportDispatcher (
/**
Entry point of Generic Status Code Driver.
- This function is the entry point of SMM Status Code Router .
- It produces SMM Report Stataus Code Handler and Status Code protocol.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
+ This function is the common entry point of MM Status Code Router.
+ It produces MM Report Status Code Handler and Status Code protocol.
@retval EFI_SUCCESS The entry point is executed successfully.
**/
EFI_STATUS
-EFIAPI
-GenericStatusCodeSmmEntry (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+GenericStatusCodeCommonEntry (
+ VOID
)
{
EFI_STATUS Status;
@@ -210,9 +205,9 @@ GenericStatusCodeSmmEntry (
//
// Install SmmRscHandler Protocol
//
- Status = gSmst->SmmInstallProtocolInterface (
+ Status = gMmst->MmInstallProtocolInterface (
&Handle,
- &gEfiSmmRscHandlerProtocolGuid,
+ &gEfiMmRscHandlerProtocolGuid,
EFI_NATIVE_INTERFACE,
&mSmmRscHandlerProtocol
);
@@ -221,9 +216,9 @@ GenericStatusCodeSmmEntry (
//
// Install SmmStatusCode Protocol
//
- Status = gSmst->SmmInstallProtocolInterface (
+ Status = gMmst->MmInstallProtocolInterface (
&Handle,
- &gEfiSmmStatusCodeProtocolGuid,
+ &gEfiMmStatusCodeProtocolGuid,
EFI_NATIVE_INTERFACE,
&mSmmStatusCodeProtocol
);
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c
new file mode 100644
index 000000000000..bd1519fa1506
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.c
@@ -0,0 +1,33 @@
+/** @file
+ Report Status Code Router Driver which produces MM Report Stataus Code Handler Protocol
+ and MM Status Code Protocol.
+
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "ReportStatusCodeRouterCommon.h"
+
+/**
+ Entry point of Generic Status Code Driver.
+
+ This function is the entry point of MM Status Code Router .
+ It produces MM Report Stataus Code Handler and Status Code protocol.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericStatusCodeStandaloneMmEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return GenericStatusCodeCommonEntry ();
+}
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c
new file mode 100644
index 000000000000..360a0eef6b6d
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterTraditional.c
@@ -0,0 +1,33 @@
+/** @file
+ Report Status Code Router Driver which produces MM Report Stataus Code Handler Protocol
+ and MM Status Code Protocol.
+
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "ReportStatusCodeRouterCommon.h"
+
+/**
+ Entry point of Generic Status Code Driver.
+
+ This function is the entry point of SMM Status Code Router .
+ It produces SMM Report Stataus Code Handler and Status Code protocol.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+GenericStatusCodeTraditionalEntry (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ return GenericStatusCodeCommonEntry ();
+}
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index 34ca571ca662..f95c7cd69ee1 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -479,6 +479,7 @@ [Components.IA32, Components.X64]
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerSmm.inf
MdeModulePkg/Universal/StatusCodeHandler/Smm/StatusCodeHandlerStandaloneMm.inf
MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
+ MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
MdeModulePkg/Universal/LockBox/SmmLockBox/SmmLockBox.inf
MdeModulePkg/Library/SmmMemoryAllocationProfileLib/SmmMemoryAllocationProfileLib.inf
MdeModulePkg/Library/PiSmmCoreMemoryAllocationLib/PiSmmCoreMemoryAllocationProfileLib.inf
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
similarity index 72%
rename from MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h
rename to MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
index f8c48c62e790..4f4d055222d4 100644
--- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.h
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterCommon.h
@@ -6,28 +6,26 @@
**/
-#ifndef __REPORT_STATUS_CODE_ROUTER_SMM_H__
-#define __REPORT_STATUS_CODE_ROUTER_SMM_H__
+#ifndef __REPORT_STATUS_CODE_ROUTER_COMMON_H__
+#define __REPORT_STATUS_CODE_ROUTER_COMMON_H__
-
-#include <Protocol/SmmReportStatusCodeHandler.h>
-#include <Protocol/SmmStatusCode.h>
+#include <Protocol/MmReportStatusCodeHandler.h>
+#include <Protocol/MmStatusCode.h>
#include <Library/BaseLib.h>
#include <Library/SynchronizationLib.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
-#define SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE SIGNATURE_32 ('s', 'h', 'c', 'e')
+#define MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE SIGNATURE_32 ('s', 'h', 'c', 'e')
typedef struct {
UINTN Signature;
- EFI_SMM_RSC_HANDLER_CALLBACK RscHandlerCallback;
+ EFI_MM_RSC_HANDLER_CALLBACK RscHandlerCallback;
LIST_ENTRY Node;
-} SMM_RSC_HANDLER_CALLBACK_ENTRY;
+} MM_RSC_HANDLER_CALLBACK_ENTRY;
/**
Register the callback function for ReportStatusCode() notification.
@@ -48,7 +46,7 @@ typedef struct {
EFI_STATUS
EFIAPI
Register (
- IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
+ IN EFI_MM_RSC_HANDLER_CALLBACK Callback
);
/**
@@ -67,14 +65,14 @@ Register (
EFI_STATUS
EFIAPI
Unregister (
- IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
+ IN EFI_MM_RSC_HANDLER_CALLBACK Callback
);
/**
Provides an interface that a software module can call to report a status code.
- @param This EFI_SMM_STATUS_CODE_PROTOCOL instance.
- @param Type Indicates the type of status code being reported.
+ @param This EFI_MM_STATUS_CODE_PROTOCOL instance.
+ @param CodeType Indicates the type of status code being reported.
@param Value Describes the current status of a hardware or software entity.
This included information about the class and subclass that is used to
classify the entity as well as an operation.
@@ -92,12 +90,26 @@ Unregister (
EFI_STATUS
EFIAPI
ReportDispatcher (
- IN CONST EFI_SMM_STATUS_CODE_PROTOCOL *This,
- IN EFI_STATUS_CODE_TYPE Type,
+ IN CONST EFI_MM_STATUS_CODE_PROTOCOL *This,
+ IN EFI_STATUS_CODE_TYPE CodeType,
IN EFI_STATUS_CODE_VALUE Value,
IN UINT32 Instance,
- IN CONST EFI_GUID *CallerId OPTIONAL,
+ IN CONST EFI_GUID *CallerId,
IN EFI_STATUS_CODE_DATA *Data OPTIONAL
);
+/**
+ Entry point of Generic Status Code Driver.
+
+ This function is the common entry point of MM Status Code Router.
+ It produces MM Report Status Code Handler and Status Code protocol.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+
+**/
+EFI_STATUS
+GenericStatusCodeCommonEntry (
+ VOID
+ );
+
#endif
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
index 46fdcb7bf959..539badc4c755 100644
--- a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterSmm.inf
@@ -16,7 +16,7 @@ [Defines]
MODULE_TYPE = DXE_SMM_DRIVER
PI_SPECIFICATION_VERSION = 0x0001000A
VERSION_STRING = 1.0
- ENTRY_POINT = GenericStatusCodeSmmEntry
+ ENTRY_POINT = GenericStatusCodeTraditionalEntry
#
# The following information is for reference only and not required by the build tools.
@@ -25,15 +25,16 @@ [Defines]
#
[Sources]
- ReportStatusCodeRouterSmm.c
- ReportStatusCodeRouterSmm.h
+ ReportStatusCodeRouterCommon.c
+ ReportStatusCodeRouterCommon.h
+ ReportStatusCodeRouterTraditional.c
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
- SmmServicesTableLib
+ MmServicesTableLib
UefiDriverEntryPoint
DebugLib
BaseLib
@@ -41,8 +42,8 @@ [LibraryClasses]
MemoryAllocationLib
[Protocols]
- gEfiSmmRscHandlerProtocolGuid ## PRODUCES
- gEfiSmmStatusCodeProtocolGuid ## PRODUCES
+ gEfiMmRscHandlerProtocolGuid ## PRODUCES
+ gEfiMmStatusCodeProtocolGuid ## PRODUCES
[Depex]
TRUE
diff --git a/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
new file mode 100644
index 000000000000..7aa0127e0bec
--- /dev/null
+++ b/MdeModulePkg/Universal/ReportStatusCodeRouter/Smm/ReportStatusCodeRouterStandaloneMm.inf
@@ -0,0 +1,49 @@
+## @file
+# Report Status Code Router Driver which produces MM Report Stataus Code Handler Protocol and MM Status Code Protocol.
+#
+# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = ReportStatusCodeRouterStandaloneMm
+ FILE_GUID = EAEEDEF9-ABE7-4B95-82B0-5A534C899B46
+ MODULE_TYPE = MM_STANDALONE
+ PI_SPECIFICATION_VERSION = 0x00010032
+ VERSION_STRING = 1.0
+ ENTRY_POINT = GenericStatusCodeStandaloneMmEntry
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ ReportStatusCodeRouterCommon.c
+ ReportStatusCodeRouterCommon.h
+ ReportStatusCodeRouterStandaloneMm.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ MmServicesTableLib
+ StandaloneMmDriverEntryPoint
+ DebugLib
+ BaseLib
+ SynchronizationLib
+ MemoryAllocationLib
+
+[Protocols]
+ gEfiMmRscHandlerProtocolGuid ## PRODUCES
+ gEfiMmStatusCodeProtocolGuid ## PRODUCES
+
+[Depex]
+ TRUE
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib: Support StandaloneMm Instance
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (6 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 10/20] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-27 0:56 ` Wu, Hao A
2021-01-26 19:47 ` [PATCH v4 12/20] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
` (6 subsequent siblings)
14 siblings, 1 reply; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Hao A Wu, Eric Dong, Ray Ni
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3185
This change added support of SMI handler profile library router under
StandaloneMm. This change replaces gSmst with gMmst. It also abstracts
standalone and traditional MM driver entrypoints into separate files to
allow maximal common implementations.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
---
Notes:
v4:
- Newly created for SmmSmiHandlerProfileLib coverage.
MdeModulePkg/Library/SmmSmiHandlerProfileLib/{SmmSmiHandlerProfileLib.c => MmSmiHandlerProfileLib.c} | 20 ++---
MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c | 90 ++------------------
MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.c | 31 +++++++
MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.h | 23 +++++
MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf | 4 +-
MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.inf | 44 ++++++++++
MdeModulePkg/MdeModulePkg.dsc | 1 +
7 files changed, 117 insertions(+), 96 deletions(-)
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.c
similarity index 86%
copy from MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
copy to MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.c
index b76e8f0dc132..f800220b549c 100644
--- a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.c
@@ -1,14 +1,15 @@
/** @file
- SMM driver instance of SmiHandlerProfile Library.
+ MM driver instance of SmiHandlerProfile Library.
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include <PiSmm.h>
+#include <PiMm.h>
#include <Library/SmiHandlerProfileLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#include <Guid/SmiHandlerProfile.h>
SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile;
@@ -82,21 +83,16 @@ SmiHandlerProfileUnregisterHandler (
}
/**
- The constructor function for SMI handler profile.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
+ The common constructor function for SMI handler profile.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
-EFIAPI
-SmmSmiHandlerProfileLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+MmSmiHandlerProfileLibInitialization (
+ VOID
)
{
- gSmst->SmmLocateProtocol (
+ gMmst->MmLocateProtocol (
&gSmiHandlerProfileGuid,
NULL,
(VOID **) &mSmiHandlerProfile
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
index b76e8f0dc132..0167d81b880d 100644
--- a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.c
@@ -2,87 +2,17 @@
SMM driver instance of SmiHandlerProfile Library.
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include <PiSmm.h>
-#include <Library/SmiHandlerProfileLib.h>
-#include <Library/SmmServicesTableLib.h>
-#include <Guid/SmiHandlerProfile.h>
+#include <PiMm.h>
-SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile;
+#include "MmSmiHandlerProfileLib.h"
/**
- This function is called by SmmChildDispatcher module to report
- a new SMI handler is registered, to SmmCore.
-
- @param HandlerGuid The GUID to identify the type of the handler.
- For the SmmChildDispatch protocol, the HandlerGuid
- must be the GUID of SmmChildDispatch protocol.
- @param Handler The SMI handler.
- @param CallerAddress The address of the module who registers the SMI handler.
- @param Context The context of the SMI handler.
- For the SmmChildDispatch protocol, the Context
- must match the one defined for SmmChildDispatch protocol.
- @param ContextSize The size of the context in bytes.
- For the SmmChildDispatch protocol, the Context
- must match the one defined for SmmChildDispatch protocol.
-
- @retval EFI_SUCCESS The information is recorded.
- @retval EFI_UNSUPPORTED The feature is unsupported.
- @retval EFI_OUT_OF_RESOURCES There is no enough resource to record the information.
-**/
-EFI_STATUS
-EFIAPI
-SmiHandlerProfileRegisterHandler (
- IN EFI_GUID *HandlerGuid,
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN PHYSICAL_ADDRESS CallerAddress,
- IN VOID *Context, OPTIONAL
- IN UINTN ContextSize OPTIONAL
- )
-{
- if (mSmiHandlerProfile != NULL) {
- return mSmiHandlerProfile->RegisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, CallerAddress, Context, ContextSize);
- }
- return EFI_UNSUPPORTED;
-}
-
-/**
- This function is called by SmmChildDispatcher module to report
- an existing SMI handler is unregistered, to SmmCore.
-
- @param HandlerGuid The GUID to identify the type of the handler.
- For the SmmChildDispatch protocol, the HandlerGuid
- must be the GUID of SmmChildDispatch protocol.
- @param Handler The SMI handler.
- @param Context The context of the SMI handler.
- If it is NOT NULL, it will be used to check what is registered.
- @param ContextSize The size of the context in bytes.
- If Context is NOT NULL, it will be used to check what is registered.
-
- @retval EFI_SUCCESS The original record is removed.
- @retval EFI_UNSUPPORTED The feature is unsupported.
- @retval EFI_NOT_FOUND There is no record for the HandlerGuid and handler.
-**/
-EFI_STATUS
-EFIAPI
-SmiHandlerProfileUnregisterHandler (
- IN EFI_GUID *HandlerGuid,
- IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
- IN VOID *Context, OPTIONAL
- IN UINTN ContextSize OPTIONAL
- )
-{
- if (mSmiHandlerProfile != NULL) {
- return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile, HandlerGuid, Handler, Context, ContextSize);
- }
- return EFI_UNSUPPORTED;
-}
-
-/**
- The constructor function for SMI handler profile.
+ The constructor function for traditional MM SMI handler profile.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@@ -92,15 +22,9 @@ SmiHandlerProfileUnregisterHandler (
EFI_STATUS
EFIAPI
SmmSmiHandlerProfileLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
)
{
- gSmst->SmmLocateProtocol (
- &gSmiHandlerProfileGuid,
- NULL,
- (VOID **) &mSmiHandlerProfile
- );
- return EFI_SUCCESS;
+ return MmSmiHandlerProfileLibInitialization ();
}
-
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.c b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.c
new file mode 100644
index 000000000000..a7714390e5b1
--- /dev/null
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.c
@@ -0,0 +1,31 @@
+/** @file
+ Standalone MM driver instance of SmiHandlerProfile Library.
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "MmSmiHandlerProfileLib.h"
+
+/**
+ The constructor function for standalone MM SMI handler profile.
+
+ @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
+StandaloneMmSmiHandlerProfileLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return MmSmiHandlerProfileLibInitialization ();
+}
+
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.h b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.h
new file mode 100644
index 000000000000..8e390590ee7b
--- /dev/null
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib.h
@@ -0,0 +1,23 @@
+/** @file
+ MM driver instance of SmiHandlerProfile Library.
+
+ Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _MM_SMI_HANDLER_PROFILE_LIB_H_
+#define _MM_SMI_HANDLER_PROFILE_LIB_H_
+
+/**
+ The common constructor function for SMI handler profile.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+**/
+EFI_STATUS
+MmSmiHandlerProfileLibInitialization (
+ VOID
+ );
+
+#endif //_SMM_SMI_HANDLER_PROFILE_LIB_H_
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
index 1d738c7087c6..56007d502134 100644
--- a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
@@ -27,6 +27,8 @@ [Defines]
#
[Sources]
+ MmSmiHandlerProfileLib.c
+ MmSmiHandlerProfileLib.h
SmmSmiHandlerProfileLib.c
[Packages]
@@ -34,7 +36,7 @@ [Packages]
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
- SmmServicesTableLib
+ MmServicesTableLib
[Guids]
gSmiHandlerProfileGuid ## CONSUMES ## GUID # Locate protocol
diff --git a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.inf b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.inf
new file mode 100644
index 000000000000..a885cc2b2ae1
--- /dev/null
+++ b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.inf
@@ -0,0 +1,44 @@
+## @file
+# Standalone MM driver instance of SmiHandlerProfile Library.
+#
+# This library instance provides real functionality for SmmChildDispatcher module.
+#
+# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = StandaloneMmSmiHandlerProfileLib
+ FILE_GUID = 1F2ED27B-A01D-4867-B993-9B710E5926C5
+ MODULE_TYPE = MM_STANDALONE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x10000032
+ LIBRARY_CLASS = SmiHandlerProfileLib|MM_STANDALONE
+ CONSTRUCTOR = StandaloneMmSmiHandlerProfileLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MmSmiHandlerProfileLib.c
+ MmSmiHandlerProfileLib.h
+ StandaloneMmSmiHandlerProfileLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ MmServicesTableLib
+
+[Guids]
+ gSmiHandlerProfileGuid ## CONSUMES ## GUID # Locate protocol
+
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc
index f95c7cd69ee1..7ca4a1bb3080 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -492,6 +492,7 @@ [Components.IA32, Components.X64]
MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformHookLibNull.inf
MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLib.inf
+ MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandlerProfileLib.inf
MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDecompressLib.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 12/20] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (7 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib: Support StandaloneMm Instance Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 13/20] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
` (5 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Michael D Kinney, Liming Gao, Zhiguang Liu
This change added an instance of UefiDevicePathLib for StandaloneMm. It
abstracts DevicePathFromHandle function into different files for
Standalone MM and other instances to avoid linking gBS into MM_STANDALONE
drivers.
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
---
Notes:
v4:
- Reviewed previously. No change.
v3:
- Added reviewed-by tag [Liming]
v2:
- No review, no change.
MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c | 33 -------------
MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c | 51 ++++++++++++++++++++
MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c | 40 +++++++++++++++
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf | 1 +
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf | 1 +
MdePkg/Library/UefiDevicePathLib/{UefiDevicePathLib.inf => UefiDevicePathLibStandaloneMm.inf} | 11 +++--
MdePkg/MdePkg.dsc | 1 +
7 files changed, 100 insertions(+), 38 deletions(-)
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
index 9274ef8dda98..7d5fb18d2516 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c
@@ -806,39 +806,6 @@ UefiDevicePathLibIsDevicePathMultiInstance (
}
-/**
- Retrieves the device path protocol from a handle.
-
- This function returns the device path protocol from the handle specified by Handle.
- If Handle is NULL or Handle does not contain a device path protocol, then NULL
- is returned.
-
- @param Handle The handle from which to retrieve the device
- path protocol.
-
- @return The device path protocol from the handle specified by Handle.
-
-**/
-EFI_DEVICE_PATH_PROTOCOL *
-EFIAPI
-DevicePathFromHandle (
- IN EFI_HANDLE Handle
- )
-{
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- EFI_STATUS Status;
-
- Status = gBS->HandleProtocol (
- Handle,
- &gEfiDevicePathProtocolGuid,
- (VOID *) &DevicePath
- );
- if (EFI_ERROR (Status)) {
- DevicePath = NULL;
- }
- return DevicePath;
-}
-
/**
Allocates a device path for a file and appends it to an existing device path.
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c
new file mode 100644
index 000000000000..7f3b6076ef34
--- /dev/null
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesDxeSmm.c
@@ -0,0 +1,51 @@
+/** @file
+ Device Path services. The thing to remember is device paths are built out of
+ nodes. The device path is terminated by an end node that is length
+ sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
+ all over this file.
+
+ The only place where multi-instance device paths are supported is in
+ environment varibles. Multi-instance device paths should never be placed
+ on a Handle.
+
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "UefiDevicePathLib.h"
+
+
+/**
+ Retrieves the device path protocol from a handle.
+
+ This function returns the device path protocol from the handle specified by Handle.
+ If Handle is NULL or Handle does not contain a device path protocol, then NULL
+ is returned.
+
+ @param Handle The handle from which to retrieve the device
+ path protocol.
+
+ @return The device path protocol from the handle specified by Handle.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+DevicePathFromHandle (
+ IN EFI_HANDLE Handle
+ )
+{
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ EFI_STATUS Status;
+
+ Status = gBS->HandleProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID *) &DevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ DevicePath = NULL;
+ }
+ return DevicePath;
+}
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c
new file mode 100644
index 000000000000..930e778d373a
--- /dev/null
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilitiesStandaloneMm.c
@@ -0,0 +1,40 @@
+/** @file
+ Device Path services. The thing to remember is device paths are built out of
+ nodes. The device path is terminated by an end node that is length
+ sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
+ all over this file.
+
+ The only place where multi-instance device paths are supported is in
+ environment varibles. Multi-instance device paths should never be placed
+ on a Handle.
+
+ Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "UefiDevicePathLib.h"
+
+
+/**
+ Retrieves the device path protocol from a handle.
+
+ This function returns the device path protocol from the handle specified by Handle.
+ If Handle is NULL or Handle does not contain a device path protocol, then NULL
+ is returned.
+
+ @param Handle The handle from which to retrieve the device
+ path protocol.
+
+ @return The device path protocol from the handle specified by Handle.
+
+**/
+EFI_DEVICE_PATH_PROTOCOL *
+EFIAPI
+DevicePathFromHandle (
+ IN EFI_HANDLE Handle
+ )
+{
+ return NULL;
+}
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
index 3c41c0695a72..eb85a54a74c3 100644
--- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
@@ -26,6 +26,7 @@ [Defines]
[Sources]
DevicePathUtilities.c
+ DevicePathUtilitiesDxeSmm.c
DevicePathToText.c
DevicePathFromText.c
UefiDevicePathLib.c
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
index e812e3e1d41e..81323bc70061 100644
--- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
+++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
@@ -29,6 +29,7 @@ [Defines]
[Sources]
DevicePathUtilities.c
+ DevicePathUtilitiesDxeSmm.c
DevicePathToText.c
DevicePathFromText.c
UefiDevicePathLibOptionalDevicePathProtocol.c
diff --git a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
similarity index 79%
copy from MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
copy to MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
index 3c41c0695a72..23fedf38b7eb 100644
--- a/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+++ b/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
@@ -4,6 +4,7 @@
# Device Path Library that layers on top of the Memory Allocation Library.
#
# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -14,10 +15,11 @@ [Defines]
INF_VERSION = 0x00010005
BASE_NAME = UefiDevicePathLib
MODULE_UNI_FILE = UefiDevicePathLib.uni
- FILE_GUID = 91c1677a-e57f-4191-8b8e-eb7711a716e0
- MODULE_TYPE = UEFI_DRIVER
+ FILE_GUID = D8E58437-44D3-4154-B7A7-EB794923EF12
+ MODULE_TYPE = MM_STANDALONE
+ PI_SPECIFICATION_VERSION = 0x00010032
VERSION_STRING = 1.0
- LIBRARY_CLASS = DevicePathLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE MM_STANDALONE
+ LIBRARY_CLASS = DevicePathLib | MM_STANDALONE MM_CORE_STANDALONE
#
@@ -26,6 +28,7 @@ [Defines]
[Sources]
DevicePathUtilities.c
+ DevicePathUtilitiesStandaloneMm.c
DevicePathToText.c
DevicePathFromText.c
UefiDevicePathLib.c
@@ -34,7 +37,6 @@ [Sources]
[Packages]
MdePkg/MdePkg.dec
-
[LibraryClasses]
BaseLib
MemoryAllocationLib
@@ -71,4 +73,3 @@ [Protocols]
[Pcd]
gEfiMdePkgTokenSpaceGuid.PcdMaximumDevicePathNodeCount ## SOMETIMES_CONSUMES
-
diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc
index 8d1a5b20c9cd..ce009086815f 100644
--- a/MdePkg/MdePkg.dsc
+++ b/MdePkg/MdePkg.dsc
@@ -109,6 +109,7 @@ [Components]
MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.inf
MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibStandaloneMm.inf
MdePkg/Library/UefiDevicePathLib/UefiDevicePathLibOptionalDevicePathProtocol.inf
MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLibDevicePathProtocol.inf
MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 13/20] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (8 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 12/20] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 14/20] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
` (4 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Ray Ni
This change added a new instance of AcpiTimerLib for StandaloneMm core
and drivers. It centralizes the common routines into shared files and
abstract the library constructor into corresponding files to accommodate
each constructor function prototypes.
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
---
Notes:
v4:
- Added reviewed-by tag [Ray]
v3:
- Renamed "CommonAcpiTimerLib" to "DxeStandaloneMmAcpiTimerLib" to
avoid confusion [Ray]
- Renamed BASE NAME (and file name) to StandaloneMmAcpiTimerLib [Ray]
v2:
- Removed "EFIAPI" for internal functions.
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c | 81 +-------------------
PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.c => DxeStandaloneMmAcpiTimerLib.c} | 9 +--
PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c | 31 ++++++++
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf | 2 +
PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h | 24 ++++++
PcAtChipsetPkg/Library/AcpiTimerLib/{DxeAcpiTimerLib.inf => StandaloneMmAcpiTimerLib.inf} | 19 +++--
PcAtChipsetPkg/PcAtChipsetPkg.dsc | 1 +
7 files changed, 74 insertions(+), 93 deletions(-)
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
index 3ad831b15e8a..9ac2a446e365 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
@@ -2,72 +2,14 @@
ACPI Timer implements one instance of Timer Library.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <PiDxe.h>
-#include <Library/TimerLib.h>
-#include <Library/BaseLib.h>
-#include <Library/HobLib.h>
-extern GUID mFrequencyHobGuid;
-
-/**
- The constructor function enables ACPI IO space.
-
- If ACPI I/O space not enabled, this function will enable it.
- It will always return RETURN_SUCCESS.
-
- @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
-
-**/
-RETURN_STATUS
-EFIAPI
-AcpiTimerLibConstructor (
- VOID
- );
-
-/**
- Calculate TSC frequency.
-
- The TSC counting frequency is determined by comparing how far it counts
- during a 101.4 us period as determined by the ACPI timer.
- The ACPI timer is used because it counts at a known frequency.
- The TSC is sampled, followed by waiting 363 counts of the ACPI timer,
- or 101.4 us. The TSC is then sampled again. The difference multiplied by
- 9861 is the TSC frequency. There will be a small error because of the
- overhead of reading the ACPI timer. An attempt is made to determine and
- compensate for this error.
-
- @return The number of TSC counts per second.
-
-**/
-UINT64
-InternalCalculateTscFrequency (
- VOID
- );
-
-//
-// Cached performance counter frequency
-//
-UINT64 mPerformanceCounterFrequency = 0;
-
-/**
- Internal function to retrieves the 64-bit frequency in Hz.
-
- Internal function to retrieves the 64-bit frequency in Hz.
-
- @return The frequency in Hz.
-
-**/
-UINT64
-InternalGetPerformanceCounterFrequency (
- VOID
- )
-{
- return mPerformanceCounterFrequency;
-}
+#include "DxeStandaloneMmAcpiTimerLib.h"
/**
The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
@@ -85,22 +27,5 @@ DxeAcpiTimerLibConstructor (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_HOB_GUID_TYPE *GuidHob;
-
- //
- // Enable ACPI IO space.
- //
- AcpiTimerLibConstructor ();
-
- //
- // Initialize PerformanceCounterFrequency
- //
- GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
- if (GuidHob != NULL) {
- mPerformanceCounterFrequency = *(UINT64*)GET_GUID_HOB_DATA (GuidHob);
- } else {
- mPerformanceCounterFrequency = InternalCalculateTscFrequency ();
- }
-
- return EFI_SUCCESS;
+ return CommonAcpiTimerLibConstructor ();
}
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
similarity index 86%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
copy to PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
index 3ad831b15e8a..0e401194d01d 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c
@@ -72,17 +72,12 @@ InternalGetPerformanceCounterFrequency (
/**
The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
- @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 RETURN_SUCCESS.
**/
EFI_STATUS
-EFIAPI
-DxeAcpiTimerLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+CommonAcpiTimerLibConstructor (
+ VOID
)
{
EFI_HOB_GUID_TYPE *GuidHob;
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c
new file mode 100644
index 000000000000..97aca5606905
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.c
@@ -0,0 +1,31 @@
+/** @file
+ ACPI Timer implements one instance of Timer Library.
+
+ Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "DxeStandaloneMmAcpiTimerLib.h"
+
+/**
+ The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
+
+ @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 RETURN_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+StandaloneMmAcpiTimerLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return CommonAcpiTimerLibConstructor ();
+}
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
index d86356f4ff17..93972e53c9c5 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
@@ -25,6 +25,8 @@ [Defines]
[Sources]
AcpiTimerLib.c
DxeAcpiTimerLib.c
+ DxeStandaloneMmAcpiTimerLib.c
+ DxeStandaloneMmAcpiTimerLib.h
[Packages]
MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
new file mode 100644
index 000000000000..6015d684e5bd
--- /dev/null
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.h
@@ -0,0 +1,24 @@
+/** @file
+ Header file internal to ACPI TimerLib.
+
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#ifndef _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
+#define _DXE_STANDALONE_MM_ACPI_TIMER_LIB_H_
+
+/**
+ The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
+
+ @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
+
+**/
+EFI_STATUS
+CommonAcpiTimerLibConstructor (
+ VOID
+ );
+
+#endif
diff --git a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
similarity index 70%
copy from PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
copy to PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
index d86356f4ff17..c5efdd145d19 100644
--- a/PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
+++ b/PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
@@ -1,5 +1,5 @@
## @file
-# DXE ACPI Timer Library
+# Standalone MM ACPI Timer Library
#
# Provides basic timer support using the ACPI timer hardware. The performance
# counter features are provided by the processors time stamp counter.
@@ -8,23 +8,26 @@
# is compatible with both 24-bit and 32-bit ACPI timers.
#
# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = DxeAcpiTimerLib
- FILE_GUID = E624B98C-845A-4b94-9B50-B20475D552B9
- MODULE_TYPE = DXE_DRIVER
+ BASE_NAME = StandaloneMmAcpiTimerLib
+ FILE_GUID = C771858D-AF09-4D1A-B2F3-C7F081C3F076
+ MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
- LIBRARY_CLASS = TimerLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE
- CONSTRUCTOR = DxeAcpiTimerLibConstructor
- MODULE_UNI_FILE = DxeAcpiTimerLib.uni
+ PI_SPECIFICATION_VERSION = 0x00010032
+ LIBRARY_CLASS = TimerLib|MM_CORE_STANDALONE MM_STANDALONE
+ CONSTRUCTOR = StandaloneMmAcpiTimerLibConstructor
[Sources]
AcpiTimerLib.c
- DxeAcpiTimerLib.c
+ StandaloneMmAcpiTimerLib.c
+ DxeStandaloneMmAcpiTimerLib.c
+ DxeStandaloneMmAcpiTimerLib.h
[Packages]
MdePkg/MdePkg.dec
diff --git a/PcAtChipsetPkg/PcAtChipsetPkg.dsc b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
index b61b7d1f528e..3d1fb816f54f 100644
--- a/PcAtChipsetPkg/PcAtChipsetPkg.dsc
+++ b/PcAtChipsetPkg/PcAtChipsetPkg.dsc
@@ -53,6 +53,7 @@ [Components]
PcAtChipsetPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.inf
PcAtChipsetPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf
PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.inf
+ PcAtChipsetPkg/Library/AcpiTimerLib/StandaloneMmAcpiTimerLib.inf
PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
[BuildOptions]
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 14/20] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (9 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 13/20] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 15/20] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
` (3 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar, Jiewen Yao
This change added a new instance of Tcg2PhysicalPresenceLib to support
MM_STANDALONE type drivers. It centralizes the common routines into
shared files and abstract the library constructor into corresponding
files to implement each constructor function prototypes.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Previously reviewed. No change.
v2:
- Added Reviewed-by tag [Jiewen]
- Removed "EFIAPI" for internal functions
- Updated internal function description
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib.c => MmTcg2PhysicalPresenceLibCommon.c} | 33 +-
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c | 368 +-------------------
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c | 42 +++
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h | 34 ++
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf | 6 +-
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/{SmmTcg2PhysicalPresenceLib.inf => StandaloneMmTcg2PhysicalPresenceLib.inf} | 22 +-
SecurityPkg/SecurityPkg.dsc | 2 +
7 files changed, 113 insertions(+), 394 deletions(-)
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
similarity index 90%
copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
index 8afaa0a7857d..3788537db318 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.c
@@ -15,7 +15,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include <PiSmm.h>
+#include <PiMm.h>
#include <Guid/Tcg2PhysicalPresenceData.h>
@@ -25,7 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/Tcg2PpVendorLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#define PP_INF_VERSION_1_2 "1.2"
@@ -55,7 +55,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
UINTN DataSize;
EFI_TCG2_PHYSICAL_PRESENCE PpData;
- DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n"));
+ DEBUG ((DEBUG_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n"));
//
// Get the Physical Presence variable
@@ -71,7 +71,7 @@ Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
if (EFI_ERROR (Status)) {
*MostRecentRequest = 0;
*Response = 0;
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
+ DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE;
}
@@ -108,7 +108,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
EFI_TCG2_PHYSICAL_PRESENCE PpData;
EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags;
- DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", *OperationRequest, *RequestParameter));
+ DEBUG ((DEBUG_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", *OperationRequest, *RequestParameter));
ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
//
@@ -123,7 +123,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
&PpData
);
if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
+ DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
goto EXIT;
}
@@ -147,7 +147,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
&PpData
);
if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));
+ DEBUG ((DEBUG_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));
ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
goto EXIT;
}
@@ -173,7 +173,7 @@ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
// Sync PPRQ/PPRM from PP Variable if PP submission fails
//
if (ReturnCode != TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM with PP variable.\n", Status));
+ DEBUG ((DEBUG_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM with PP variable.\n", Status));
DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
ZeroMem(&PpData, DataSize);
Status = mTcg2PpSmmVariable->SmmGetVariable (
@@ -245,7 +245,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags;
BOOLEAN RequestConfirmed;
- DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));
+ DEBUG ((DEBUG_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));
//
// Get the Physical Presence variable
@@ -259,7 +259,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
&PpData
);
if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
+ DEBUG ((DEBUG_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
}
//
@@ -274,7 +274,7 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
&Flags
);
if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status = %r\n", Status));
+ DEBUG ((DEBUG_ERROR, "[TPM2] Get PP flags failure! Status = %r\n", Status));
return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
}
@@ -372,17 +372,12 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
-
@retval EFI_SUCCESS The constructor successfully added string package.
@retval Other value The constructor can't add string package.
**/
EFI_STATUS
-EFIAPI
-Tcg2PhysicalPresenceLibConstructor (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+Tcg2PhysicalPresenceLibCommonConstructor (
+ VOID
)
{
EFI_STATUS Status;
@@ -394,7 +389,7 @@ Tcg2PhysicalPresenceLibConstructor (
//
// Locate SmmVariableProtocol.
//
- Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpSmmVariable);
+ Status = gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpSmmVariable);
ASSERT_EFI_ERROR (Status);
mTcg2PhysicalPresenceFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags);
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
index 8afaa0a7857d..36d8b89dcdd9 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.c
@@ -17,355 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <PiSmm.h>
-#include <Guid/Tcg2PhysicalPresenceData.h>
-
-#include <Protocol/SmmVariable.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/Tcg2PpVendorLib.h>
-#include <Library/SmmServicesTableLib.h>
-
-#define PP_INF_VERSION_1_2 "1.2"
-
-EFI_SMM_VARIABLE_PROTOCOL *mTcg2PpSmmVariable;
-BOOLEAN mIsTcg2PPVerLowerThan_1_3 = FALSE;
-UINT32 mTcg2PhysicalPresenceFlags;
-
-/**
- The handler for TPM physical presence function:
- Return TPM Operation Response to OS Environment.
-
- This API should be invoked in OS runtime phase to interface with ACPI method.
-
- @param[out] MostRecentRequest Most recent operation request.
- @param[out] Response Response to the most recent operation request.
-
- @return Return Code for Return TPM Operation Response to OS Environment.
-**/
-UINT32
-EFIAPI
-Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
- OUT UINT32 *MostRecentRequest,
- OUT UINT32 *Response
- )
-{
- EFI_STATUS Status;
- UINTN DataSize;
- EFI_TCG2_PHYSICAL_PRESENCE PpData;
-
- DEBUG ((EFI_D_INFO, "[TPM2] ReturnOperationResponseToOsFunction\n"));
-
- //
- // Get the Physical Presence variable
- //
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
- Status = mTcg2PpSmmVariable->SmmGetVariable (
- TCG2_PHYSICAL_PRESENCE_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpData
- );
- if (EFI_ERROR (Status)) {
- *MostRecentRequest = 0;
- *Response = 0;
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
- return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_FAILURE;
- }
-
- *MostRecentRequest = PpData.LastPPRequest;
- *Response = PpData.PPResponse;
-
- return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS;
-}
-
-/**
- The handler for TPM physical presence function:
- Submit TPM Operation Request to Pre-OS Environment and
- Submit TPM Operation Request to Pre-OS Environment 2.
-
- This API should be invoked in OS runtime phase to interface with ACPI method.
-
- Caution: This function may receive untrusted input.
-
- @param[in, out] Pointer to OperationRequest TPM physical presence operation request.
- @param[in, out] Pointer to RequestParameter TPM physical presence operation request parameter.
-
- @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
- Submit TPM Operation Request to Pre-OS Environment 2.
- **/
-UINT32
-Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx (
- IN OUT UINT32 *OperationRequest,
- IN OUT UINT32 *RequestParameter
- )
-{
- EFI_STATUS Status;
- UINT32 ReturnCode;
- UINTN DataSize;
- EFI_TCG2_PHYSICAL_PRESENCE PpData;
- EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags;
-
- DEBUG ((EFI_D_INFO, "[TPM2] SubmitRequestToPreOSFunction, Request = %x, %x\n", *OperationRequest, *RequestParameter));
- ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
-
- //
- // Get the Physical Presence variable
- //
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
- Status = mTcg2PpSmmVariable->SmmGetVariable (
- TCG2_PHYSICAL_PRESENCE_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpData
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
- ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
- goto EXIT;
- }
-
- if ((*OperationRequest > TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) &&
- (*OperationRequest < TCG2_PHYSICAL_PRESENCE_STORAGE_MANAGEMENT_BEGIN) ) {
- ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED;
- goto EXIT;
- }
-
- if ((PpData.PPRequest != *OperationRequest) ||
- (PpData.PPRequestParameter != *RequestParameter)) {
- PpData.PPRequest = (UINT8)*OperationRequest;
- PpData.PPRequestParameter = *RequestParameter;
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
- Status = mTcg2PpSmmVariable->SmmSetVariable (
- TCG2_PHYSICAL_PRESENCE_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- DataSize,
- &PpData
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Set PP variable failure! Status = %r\n", Status));
- ReturnCode = TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
- goto EXIT;
- }
- }
-
- if (*OperationRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS);
- Status = mTcg2PpSmmVariable->SmmGetVariable (
- TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- NULL,
- &DataSize,
- &Flags
- );
- if (EFI_ERROR (Status)) {
- Flags.PPFlags = mTcg2PhysicalPresenceFlags;
- }
- ReturnCode = Tcg2PpVendorLibSubmitRequestToPreOSFunction (*OperationRequest, Flags.PPFlags, *RequestParameter);
- }
-
-EXIT:
- //
- // Sync PPRQ/PPRM from PP Variable if PP submission fails
- //
- if (ReturnCode != TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Submit PP Request failure! Sync PPRQ/PPRM with PP variable.\n", Status));
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
- ZeroMem(&PpData, DataSize);
- Status = mTcg2PpSmmVariable->SmmGetVariable (
- TCG2_PHYSICAL_PRESENCE_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpData
- );
- *OperationRequest = (UINT32)PpData.PPRequest;
- *RequestParameter = PpData.PPRequestParameter;
- }
-
- return ReturnCode;
-}
-
-/**
- The handler for TPM physical presence function:
- Submit TPM Operation Request to Pre-OS Environment and
- Submit TPM Operation Request to Pre-OS Environment 2.
-
- This API should be invoked in OS runtime phase to interface with ACPI method.
-
- Caution: This function may receive untrusted input.
-
- @param[in] OperationRequest TPM physical presence operation request.
- @param[in] RequestParameter TPM physical presence operation request parameter.
-
- @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
- Submit TPM Operation Request to Pre-OS Environment 2.
-**/
-UINT32
-EFIAPI
-Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (
- IN UINT32 OperationRequest,
- IN UINT32 RequestParameter
- )
-{
- UINT32 TempOperationRequest;
- UINT32 TempRequestParameter;
-
- TempOperationRequest = OperationRequest;
- TempRequestParameter = RequestParameter;
-
- return Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunctionEx(&TempOperationRequest, &TempRequestParameter);
-}
-
-/**
- The handler for TPM physical presence function:
- Get User Confirmation Status for Operation.
-
- This API should be invoked in OS runtime phase to interface with ACPI method.
-
- Caution: This function may receive untrusted input.
-
- @param[in] OperationRequest TPM physical presence operation request.
-
- @return Return Code for Get User Confirmation Status for Operation.
-**/
-UINT32
-EFIAPI
-Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
- IN UINT32 OperationRequest
- )
-{
- EFI_STATUS Status;
- UINTN DataSize;
- EFI_TCG2_PHYSICAL_PRESENCE PpData;
- EFI_TCG2_PHYSICAL_PRESENCE_FLAGS Flags;
- BOOLEAN RequestConfirmed;
-
- DEBUG ((EFI_D_INFO, "[TPM2] GetUserConfirmationStatusFunction, Request = %x\n", OperationRequest));
-
- //
- // Get the Physical Presence variable
- //
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE);
- Status = mTcg2PpSmmVariable->SmmGetVariable (
- TCG2_PHYSICAL_PRESENCE_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpData
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP variable failure! Status = %r\n", Status));
- return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
- }
- //
- // Get the Physical Presence flags
- //
- DataSize = sizeof (EFI_TCG2_PHYSICAL_PRESENCE_FLAGS);
- Status = mTcg2PpSmmVariable->SmmGetVariable (
- TCG2_PHYSICAL_PRESENCE_FLAGS_VARIABLE,
- &gEfiTcg2PhysicalPresenceGuid,
- NULL,
- &DataSize,
- &Flags
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((EFI_D_ERROR, "[TPM2] Get PP flags failure! Status = %r\n", Status));
- return TCG_PP_GET_USER_CONFIRMATION_BLOCKED_BY_BIOS_CONFIGURATION;
- }
-
- RequestConfirmed = FALSE;
-
- switch (OperationRequest) {
- case TCG2_PHYSICAL_PRESENCE_CLEAR:
- case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR:
- case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2:
- case TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3:
- if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CLEAR) == 0) {
- RequestConfirmed = TRUE;
- }
- break;
-
- case TCG2_PHYSICAL_PRESENCE_NO_ACTION:
- case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_TRUE:
- RequestConfirmed = TRUE;
- break;
-
- case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_CLEAR_FALSE:
- break;
-
- case TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS:
- if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_PCRS) == 0) {
- RequestConfirmed = TRUE;
- }
- break;
-
- case TCG2_PHYSICAL_PRESENCE_CHANGE_EPS:
- if ((Flags.PPFlags & TCG2_BIOS_TPM_MANAGEMENT_FLAG_PP_REQUIRED_FOR_CHANGE_EPS) == 0) {
- RequestConfirmed = TRUE;
- }
- break;
-
- case TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS:
- RequestConfirmed = TRUE;
- break;
-
- case TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID:
- if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID) == 0) {
- RequestConfirmed = TRUE;
- }
- break;
-
- case TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID:
- if ((Flags.PPFlags & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID) == 0) {
- RequestConfirmed = TRUE;
- }
- break;
-
- case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE:
- case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE:
- RequestConfirmed = TRUE;
- break;
-
- case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE:
- case TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE:
- break;
-
- default:
- if (!mIsTcg2PPVerLowerThan_1_3) {
- if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- //
- // TCG2 PP1.3 spec defined operations that are reserved or un-implemented
- //
- return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;
- }
- } else {
- //
- // TCG PP lower than 1.3. (1.0, 1.1, 1.2)
- //
- if (OperationRequest <= TCG2_PHYSICAL_PRESENCE_NO_ACTION_MAX) {
- RequestConfirmed = TRUE;
- } else if (OperationRequest < TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- return TCG_PP_GET_USER_CONFIRMATION_NOT_IMPLEMENTED;
- }
- }
- break;
- }
-
- if (OperationRequest >= TCG2_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- return Tcg2PpVendorLibGetUserConfirmationStatusFunction (OperationRequest, Flags.PPFlags);
- }
-
- if (RequestConfirmed) {
- return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_NOT_REQUIRED;
- } else {
- return TCG_PP_GET_USER_CONFIRMATION_ALLOWED_AND_PPUSER_REQUIRED;
- }
-}
+#include "MmTcg2PhysicalPresenceLibCommon.h"
/**
The constructor function locates SmmVariable protocol.
@@ -380,24 +32,10 @@ Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction (
**/
EFI_STATUS
EFIAPI
-Tcg2PhysicalPresenceLibConstructor (
+Tcg2PhysicalPresenceLibTraditionalConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
-
- if (AsciiStrnCmp(PP_INF_VERSION_1_2, (CHAR8 *)PcdGetPtr(PcdTcgPhysicalPresenceInterfaceVer), sizeof(PP_INF_VERSION_1_2) - 1) >= 0) {
- mIsTcg2PPVerLowerThan_1_3 = TRUE;
- }
-
- //
- // Locate SmmVariableProtocol.
- //
- Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpSmmVariable);
- ASSERT_EFI_ERROR (Status);
-
- mTcg2PhysicalPresenceFlags = PcdGet32(PcdTcg2PhysicalPresenceFlags);
-
- return EFI_SUCCESS;
+ return Tcg2PhysicalPresenceLibCommonConstructor ();
}
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c
new file mode 100644
index 000000000000..5c298a8d5720
--- /dev/null
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.c
@@ -0,0 +1,42 @@
+/** @file
+ Handle TPM 2.0 physical presence requests from OS.
+
+ This library will handle TPM 2.0 physical presence request from OS.
+
+ Caution: This module requires additional review when modified.
+ This driver will have external input - variable.
+ This external input must be validated carefully to avoid security issue.
+
+ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
+ will receive untrusted input and do validation.
+
+Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiMm.h>
+
+#include "MmTcg2PhysicalPresenceLibCommon.h"
+
+/**
+ The constructor function locates SmmVariable protocol.
+
+ It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor successfully added string package.
+ @retval Other value The constructor can't add string package.
+**/
+EFI_STATUS
+EFIAPI
+Tcg2PhysicalPresenceLibStandaloneMmConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ return Tcg2PhysicalPresenceLibCommonConstructor ();
+}
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h
new file mode 100644
index 000000000000..a0182739e9c8
--- /dev/null
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/MmTcg2PhysicalPresenceLibCommon.h
@@ -0,0 +1,34 @@
+/** @file
+ Handle TPM 2.0 physical presence requests from OS.
+
+ This library will handle TPM 2.0 physical presence request from OS.
+
+ Caution: This module requires additional review when modified.
+ This driver will have external input - variable.
+ This external input must be validated carefully to avoid security issue.
+
+ Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction() and Tcg2PhysicalPresenceLibGetUserConfirmationStatusFunction()
+ will receive untrusted input and do validation.
+
+Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
+#define _MM_TCG2_PHYSICAL_PRESENCE_LIB_COMMON_H_
+
+/**
+ The constructor function locates MmVariable protocol.
+
+ It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
+
+ @retval EFI_SUCCESS The constructor successfully added string package.
+ @retval Other value The constructor can't add string package.
+**/
+EFI_STATUS
+Tcg2PhysicalPresenceLibCommonConstructor (
+ VOID
+ );
+
+#endif
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
index 6a9bdf66f0a6..d911adbdb648 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
@@ -20,7 +20,7 @@ [Defines]
MODULE_TYPE = DXE_SMM_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = Tcg2PhysicalPresenceLib|DXE_SMM_DRIVER
- CONSTRUCTOR = Tcg2PhysicalPresenceLibConstructor
+ CONSTRUCTOR = Tcg2PhysicalPresenceLibTraditionalConstructor
#
# The following information is for reference only and not required by the build tools.
@@ -30,6 +30,8 @@ [Defines]
[Sources]
SmmTcg2PhysicalPresenceLib.c
+ MmTcg2PhysicalPresenceLibCommon.c
+ MmTcg2PhysicalPresenceLibCommon.h
[Packages]
MdePkg/MdePkg.dec
@@ -39,7 +41,7 @@ [Packages]
[LibraryClasses]
DebugLib
Tcg2PpVendorLib
- SmmServicesTableLib
+ MmServicesTableLib
BaseMemoryLib
[Guids]
diff --git a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
similarity index 64%
copy from SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
copy to SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
index 6a9bdf66f0a6..6d11b6b9f198 100644
--- a/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
+++ b/SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
@@ -8,19 +8,20 @@
# This external input must be validated carefully to avoid security issue.
#
# Copyright (c) 2015 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = SmmTcg2PhysicalPresenceLib
- MODULE_UNI_FILE = SmmTcg2PhysicalPresenceLib.uni
- FILE_GUID = AAE02741-858B-4964-9887-CA870489D944
- MODULE_TYPE = DXE_SMM_DRIVER
+ BASE_NAME = StandaloneMmTcg2PhysicalPresenceLib
+ FILE_GUID = 75E3D07B-689C-4F42-A8A0-46AFAE868A6F
+ MODULE_TYPE = MM_STANDALONE
+ PI_SPECIFICATION_VERSION = 0x00010032
VERSION_STRING = 1.0
- LIBRARY_CLASS = Tcg2PhysicalPresenceLib|DXE_SMM_DRIVER
- CONSTRUCTOR = Tcg2PhysicalPresenceLibConstructor
+ LIBRARY_CLASS = Tcg2PhysicalPresenceLib|MM_STANDALONE
+ CONSTRUCTOR = Tcg2PhysicalPresenceLibStandaloneMmConstructor
#
# The following information is for reference only and not required by the build tools.
@@ -29,7 +30,9 @@ [Defines]
#
[Sources]
- SmmTcg2PhysicalPresenceLib.c
+ StandaloneMmTcg2PhysicalPresenceLib.c
+ MmTcg2PhysicalPresenceLibCommon.c
+ MmTcg2PhysicalPresenceLibCommon.h
[Packages]
MdePkg/MdePkg.dec
@@ -39,7 +42,7 @@ [Packages]
[LibraryClasses]
DebugLib
Tcg2PpVendorLib
- SmmServicesTableLib
+ MmServicesTableLib
BaseMemoryLib
[Guids]
@@ -48,6 +51,9 @@ [Guids]
## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"
gEfiTcg2PhysicalPresenceGuid
+[Protocols]
+ gEfiSmmVariableProtocolGuid ## CONSUMES
+
[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTcgPhysicalPresenceInterfaceVer ## CONSUMES
gEfiSecurityPkgTokenSpaceGuid.PcdTcg2PhysicalPresenceFlags ## SOMETIMES_CONSUMES
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 36d15b79f928..7240b2573e4e 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -150,6 +150,7 @@ [LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATION]
[LibraryClasses.common.DXE_SMM_DRIVER]
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf
+ MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf
ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf
SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf
@@ -316,6 +317,7 @@ [Components.IA32, Components.X64]
SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/SmmTcg2PhysicalPresenceLib.inf
+ SecurityPkg/Library/SmmTcg2PhysicalPresenceLib/StandaloneMmTcg2PhysicalPresenceLib.inf
#
# Random Number Generator
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 15/20] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (10 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 14/20] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 16/20] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
` (2 subsequent siblings)
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar, Jiewen Yao
This change extends this null instance of Tcg2PpVendorLib to support
MM_STANDALONE drivers.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Previously reviewed. No change.
v2:
- Added Reviewed-by tag [Jiewen]
SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf b/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
index b969cbf9afff..9b18a1ab82f1 100644
--- a/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
+++ b/SecurityPkg/Library/Tcg2PpVendorLibNull/Tcg2PpVendorLibNull.inf
@@ -13,7 +13,7 @@ [Defines]
FILE_GUID = 51924AE9-BE81-4820-94BA-7C9546E702D0
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
- LIBRARY_CLASS = Tcg2PpVendorLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_DRIVER
+ LIBRARY_CLASS = Tcg2PpVendorLib|DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_DRIVER MM_STANDALONE
#
# The following information is for reference only and not required by the build tools.
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 16/20] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (11 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 15/20] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 17/20] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
2021-01-26 19:47 ` [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file Kun Qin
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Jiewen Yao, Jian J Wang, Qi Zhang, Rahul Kumar, Jiewen Yao
This change added a new instance of Tpm2DeviceLibDTpm to support drivers
of type MM_STANDALONE. It abstracts dynamic Pcd access into separate file
for different instances to avoid dynamic usage for StandaloneMm modules.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Jiewen Yao <Jiewen.yao@intel.com>
---
Notes:
v4:
- Previously reviewed. No change.
v3:
- Previously reviewed. No change.
v2:
- Added Reviewed-by tag [Jiewen]
- Removed "EFIAPI" for internal functions
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c | 42 +-----------
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c | 68 ++++++++++++++++++++
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c | 66 +++++++++++++++++++
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c | 40 +-----------
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c | 15 +++--
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h | 67 +++++++++++++++++++
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf | 3 +
SecurityPkg/Library/Tpm2DeviceLibDTpm/{Tpm2DeviceLibDTpm.inf => Tpm2DeviceLibDTpmStandaloneMm.inf} | 13 ++--
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf | 3 +
SecurityPkg/SecurityPkg.dsc | 1 +
10 files changed, 228 insertions(+), 90 deletions(-)
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
index 42e1ecbce95a..238389dbdb1b 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.c
@@ -13,29 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/Tpm2DeviceLib.h>
#include <Library/PcdLib.h>
-/**
- Return PTP interface type.
-
- @param[in] Register Pointer to PTP register.
-
- @return PTP interface type.
-**/
-TPM2_PTP_INTERFACE_TYPE
-Tpm2GetPtpInterface (
- IN VOID *Register
- );
-
-/**
- Return PTP CRB interface IdleByPass state.
-
- @param[in] Register Pointer to PTP register.
-
- @return PTP CRB interface IdleByPass state.
-**/
-UINT8
-Tpm2GetIdleByPass (
- IN VOID *Register
- );
+#include "Tpm2DeviceLibDTpm.h"
/**
This service enables the sending of commands to the TPM2.
@@ -145,21 +123,5 @@ Tpm2DeviceLibConstructor (
VOID
)
{
- TPM2_PTP_INTERFACE_TYPE PtpInterface;
- UINT8 IdleByPass;
-
- //
- // Cache current active TpmInterfaceType only when needed
- //
- if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
- PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
- PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
- }
-
- if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
- IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
- PcdSet8S(PcdCRBIdleByPass, IdleByPass);
- }
-
- return EFI_SUCCESS;
+ return InternalTpm2DeviceLibDTpmCommonConstructor ();
}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
new file mode 100644
index 000000000000..bc35e257e105
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmBase.c
@@ -0,0 +1,68 @@
+/** @file
+ This file abstract internal interfaces of which implementation differs per library instance.
+
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/Tpm2DeviceLib.h>
+#include <Library/PcdLib.h>
+
+#include "Tpm2DeviceLibDTpm.h"
+
+/**
+ Return cached PTP CRB interface IdleByPass state.
+
+ @return Cached PTP CRB interface IdleByPass state.
+**/
+UINT8
+GetCachedIdleByPass (
+ VOID
+ )
+{
+ return PcdGet8(PcdCRBIdleByPass);
+}
+
+/**
+ Return cached PTP interface type.
+
+ @return Cached PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+GetCachedPtpInterface (
+ VOID
+ )
+{
+ return PcdGet8(PcdActiveTpmInterfaceType);
+}
+
+/**
+ The common function cache current active TpmInterfaceType when needed.
+
+ @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
+**/
+EFI_STATUS
+InternalTpm2DeviceLibDTpmCommonConstructor (
+ VOID
+ )
+{
+ TPM2_PTP_INTERFACE_TYPE PtpInterface;
+ UINT8 IdleByPass;
+
+ //
+ // Cache current active TpmInterfaceType only when needed
+ //
+ if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
+ PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+ PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
+ }
+
+ if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
+ IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+ PcdSet8S(PcdCRBIdleByPass, IdleByPass);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c
new file mode 100644
index 000000000000..eac866d2a77a
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.c
@@ -0,0 +1,66 @@
+/** @file
+ This file abstract internal interfaces of which implementation differs per library instance.
+
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/Tpm2DeviceLib.h>
+
+#include "Tpm2DeviceLibDTpm.h"
+
+TPM2_PTP_INTERFACE_TYPE mActiveTpmInterfaceType;
+UINT8 mCRBIdleByPass;
+
+/**
+ Return cached PTP CRB interface IdleByPass state.
+
+ @return Cached PTP CRB interface IdleByPass state.
+**/
+UINT8
+GetCachedIdleByPass (
+ VOID
+ )
+{
+ return mCRBIdleByPass;
+}
+
+/**
+ Return cached PTP interface type.
+
+ @return Cached PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+GetCachedPtpInterface (
+ VOID
+ )
+{
+ return mActiveTpmInterfaceType;
+}
+
+/**
+ The common function cache current active TpmInterfaceType when needed.
+
+ @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
+**/
+EFI_STATUS
+InternalTpm2DeviceLibDTpmCommonConstructor (
+ VOID
+ )
+{
+ mActiveTpmInterfaceType = 0xFF;
+ mCRBIdleByPass = 0xFF;
+
+ //
+ // Always cache current active TpmInterfaceType for StandaloneMm implementation
+ //
+ mActiveTpmInterfaceType = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+
+ if (mActiveTpmInterfaceType == Tpm2PtpInterfaceCrb) {
+ mCRBIdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
index 691eaa40c045..053e597d2ee2 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.c
@@ -16,29 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Guid/TpmInstance.h>
-/**
- Return PTP interface type.
-
- @param[in] Register Pointer to PTP register.
-
- @return PTP interface type.
-**/
-TPM2_PTP_INTERFACE_TYPE
-Tpm2GetPtpInterface (
- IN VOID *Register
- );
-
-/**
- Return PTP CRB interface IdleByPass state.
-
- @param[in] Register Pointer to PTP register.
-
- @return PTP CRB interface IdleByPass state.
-**/
-UINT8
-Tpm2GetIdleByPass (
- IN VOID *Register
- );
+#include "Tpm2DeviceLibDTpm.h"
/**
Dump PTP register information.
@@ -102,8 +80,6 @@ Tpm2InstanceLibDTpmConstructor (
)
{
EFI_STATUS Status;
- TPM2_PTP_INTERFACE_TYPE PtpInterface;
- UINT8 IdleByPass;
Status = Tpm2RegisterTpm2DeviceLib (&mDTpm2InternalTpm2Device);
if ((Status == EFI_SUCCESS) || (Status == EFI_UNSUPPORTED)) {
@@ -111,19 +87,7 @@ Tpm2InstanceLibDTpmConstructor (
// Unsupported means platform policy does not need this instance enabled.
//
if (Status == EFI_SUCCESS) {
- //
- // Cache current active TpmInterfaceType only when needed
- //
- if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
- PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
- PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
- }
-
- if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
- IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
- PcdSet8S(PcdCRBIdleByPass, IdleByPass);
- }
-
+ Status = InternalTpm2DeviceLibDTpmCommonConstructor ();
DumpPtpInfo ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
}
return EFI_SUCCESS;
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
index 2c73385b6ce5..f1f80916834f 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2Ptp.c
@@ -2,6 +2,7 @@
PTP (Platform TPM Profile) CRB (Command Response Buffer) interface used by dTPM2.0 library.
Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c), Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -19,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <IndustryStandard/TpmPtp.h>
#include <IndustryStandard/TpmTis.h>
+#include "Tpm2DeviceLibDTpm.h"
+
//
// Execution of the command may take from several seconds to minutes for certain
// commands, such as key generation.
@@ -174,7 +177,7 @@ PtpCrbTpmCommand (
// STEP 0:
// if CapCRbIdelByPass == 0, enforce Idle state before sending command
//
- if (PcdGet8(PcdCRBIdleByPass) == 0 && (MmioRead32((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){
+ if (GetCachedIdleByPass () == 0 && (MmioRead32((UINTN)&CrbReg->CrbControlStatus) & PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE) == 0){
Status = PtpCrbWaitRegisterBits (
&CrbReg->CrbControlStatus,
PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
@@ -330,7 +333,7 @@ PtpCrbTpmCommand (
// Goto Ready State if command is completed successfully and TPM support IdleBypass
// If not supported. flow down to GoIdle
//
- if (PcdGet8(PcdCRBIdleByPass) == 1) {
+ if (GetCachedIdleByPass () == 1) {
MmioWrite32((UINTN)&CrbReg->CrbControlRequest, PTP_CRB_CONTROL_AREA_REQUEST_COMMAND_READY);
return Status;
}
@@ -350,7 +353,7 @@ PtpCrbTpmCommand (
// Only enforce Idle state transition if execution fails when CRBIdleBypass==1
// Leave regular Idle delay at the beginning of next command execution
//
- if (PcdGet8(PcdCRBIdleByPass) == 1){
+ if (GetCachedIdleByPass () == 1){
Status = PtpCrbWaitRegisterBits (
&CrbReg->CrbControlStatus,
PTP_CRB_CONTROL_AREA_STATUS_TPM_IDLE,
@@ -519,7 +522,7 @@ DumpPtpInfo (
Vid = 0xFFFF;
Did = 0xFFFF;
Rid = 0xFF;
- PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
+ PtpInterface = GetCachedPtpInterface ();
DEBUG ((EFI_D_INFO, "PtpInterface - %x\n", PtpInterface));
switch (PtpInterface) {
case Tpm2PtpInterfaceCrb:
@@ -564,7 +567,7 @@ DTpm2SubmitCommand (
{
TPM2_PTP_INTERFACE_TYPE PtpInterface;
- PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
+ PtpInterface = GetCachedPtpInterface ();
switch (PtpInterface) {
case Tpm2PtpInterfaceCrb:
return PtpCrbTpmCommand (
@@ -603,7 +606,7 @@ DTpm2RequestUseTpm (
{
TPM2_PTP_INTERFACE_TYPE PtpInterface;
- PtpInterface = PcdGet8(PcdActiveTpmInterfaceType);
+ PtpInterface = GetCachedPtpInterface ();
switch (PtpInterface) {
case Tpm2PtpInterfaceCrb:
return PtpCrbRequestUseTpm ((PTP_CRB_REGISTERS_PTR) (UINTN) PcdGet64 (PcdTpmBaseAddress));
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
new file mode 100644
index 000000000000..9fff98952251
--- /dev/null
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.h
@@ -0,0 +1,67 @@
+/** @file
+ This header file includes common internal fuction prototypes.
+
+Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
+Copyright (c) Microsoft Corporation.
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _TPM2_DEVICE_LIB_DTPM_H_
+#define _TPM2_DEVICE_LIB_DTPM_H_
+
+/**
+ Return PTP interface type.
+
+ @param[in] Register Pointer to PTP register.
+
+ @return PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+Tpm2GetPtpInterface (
+ IN VOID *Register
+ );
+
+/**
+ Return PTP CRB interface IdleByPass state.
+
+ @param[in] Register Pointer to PTP register.
+
+ @return PTP CRB interface IdleByPass state.
+**/
+UINT8
+Tpm2GetIdleByPass (
+ IN VOID *Register
+ );
+
+/**
+ Return cached PTP interface type.
+
+ @return Cached PTP interface type.
+**/
+TPM2_PTP_INTERFACE_TYPE
+GetCachedPtpInterface (
+ VOID
+ );
+
+/**
+ Return cached PTP CRB interface IdleByPass state.
+
+ @return Cached PTP CRB interface IdleByPass state.
+**/
+UINT8
+GetCachedIdleByPass (
+ VOID
+ );
+
+/**
+ The common function cache current active TpmInterfaceType when needed.
+
+ @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
+**/
+EFI_STATUS
+InternalTpm2DeviceLibDTpmCommonConstructor (
+ VOID
+ );
+
+#endif // _TPM2_DEVICE_LIB_DTPM_H_
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
index 2b627504634d..be3a0053ccce 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
@@ -11,6 +11,7 @@
# only uses TPM 2.0 DTPM device.
#
# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -34,6 +35,8 @@ [Sources]
Tpm2Tis.c
Tpm2Ptp.c
Tpm2DeviceLibDTpm.c
+ Tpm2DeviceLibDTpmBase.c
+ Tpm2DeviceLibDTpm.h
[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
similarity index 70%
copy from SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
copy to SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
index 2b627504634d..18c08ad8bdcc 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
@@ -11,19 +11,20 @@
# only uses TPM 2.0 DTPM device.
#
# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = Tpm2DeviceLibDTpm
- MODULE_UNI_FILE = Tpm2DeviceLibDTpm.uni
- FILE_GUID = E54A3327-A345-4068-8842-70AC0D519855
+ BASE_NAME = Tpm2DeviceLibDTpmStandaloneMm
+ FILE_GUID = 9A5DB21A-FF0B-46D0-8672-B4F83FEF1F0E
MODULE_TYPE = BASE
VERSION_STRING = 1.0
- LIBRARY_CLASS = Tpm2DeviceLib|PEIM DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ LIBRARY_CLASS = Tpm2DeviceLib|MM_STANDALONE
CONSTRUCTOR = Tpm2DeviceLibConstructor
+
#
# The following information is for reference only and not required by the build tools.
#
@@ -34,6 +35,8 @@ [Sources]
Tpm2Tis.c
Tpm2Ptp.c
Tpm2DeviceLibDTpm.c
+ Tpm2DeviceLibDTpmStandaloneMm.c
+ Tpm2DeviceLibDTpm.h
[Packages]
MdePkg/MdePkg.dec
@@ -49,5 +52,3 @@ [LibraryClasses]
[Pcd]
gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES
- gEfiSecurityPkgTokenSpaceGuid.PcdActiveTpmInterfaceType ## PRODUCES
- gEfiSecurityPkgTokenSpaceGuid.PcdCRBIdleByPass ## PRODUCES
diff --git a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
index 5f267f552ce3..31113d93ee41 100644
--- a/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
+++ b/SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
@@ -6,6 +6,7 @@
# and PTP (Platform TPM Profile) functions.
#
# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) Microsoft Corporation
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -30,6 +31,8 @@ [Sources]
Tpm2Tis.c
Tpm2Ptp.c
Tpm2InstanceLibDTpm.c
+ Tpm2DeviceLibDTpmBase.c
+ Tpm2DeviceLibDTpm.h
[Packages]
MdePkg/MdePkg.dec
diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
index 7240b2573e4e..618420a56c33 100644
--- a/SecurityPkg/SecurityPkg.dsc
+++ b/SecurityPkg/SecurityPkg.dsc
@@ -211,6 +211,7 @@ [Components]
SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpm.inf
SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2InstanceLibDTpm.inf
+ SecurityPkg/Library/Tpm2DeviceLibDTpm/Tpm2DeviceLibDTpmStandaloneMm.inf
SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterDxe.inf
SecurityPkg/Library/Tpm2DeviceLibRouter/Tpm2DeviceLibRouterPei.inf
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 17/20] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (12 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 16/20] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-26 19:47 ` [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file Kun Qin
14 siblings, 0 replies; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar
This change replaced gSmst with gMmst to support broader compatibility
under MM environment for CpuIo2Smm driver.
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
---
Notes:
v4:
- Added reviewed-by tag [Laszlo]
- Added reviewed-by tag [Ray]
v3:
- Break gMmst replacement into separate PR [Laszlo]
v2:
- Removed "EFIAPI" for internal functions.
UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c | 6 +++---
UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h | 2 +-
UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 2 +-
UefiCpuPkg/UefiCpuPkg.dsc | 1 +
4 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index b840d3e10cae..c0a2baecee03 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -390,12 +390,12 @@ SmmCpuIo2Initialize (
//
// Copy the SMM CPU I/O Protocol instance into the System Management System Table
//
- CopyMem (&gSmst->SmmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
+ CopyMem (&gMmst->MmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
//
- // Install the SMM CPU I/O Protocol into the SMM protocol database
+ // Install the SMM CPU I/O Protocol into the MM protocol database
//
- Status = gSmst->SmmInstallProtocolInterface (
+ Status = gMmst->MmInstallProtocolInterface (
&mHandle,
&gEfiSmmCpuIo2ProtocolGuid,
EFI_NATIVE_INTERFACE,
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
index 4c133b58c9f4..c80261945f71 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
@@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
-#include <Library/SmmServicesTableLib.h>
+#include <Library/MmServicesTableLib.h>
#include <Library/BaseMemoryLib.h>
#define MAX_IO_PORT_ADDRESS 0xFFFF
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
index bc78fa4e42d2..b743a5e0e316 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
@@ -34,7 +34,7 @@ [LibraryClasses]
BaseLib
DebugLib
IoLib
- SmmServicesTableLib
+ MmServicesTableLib
BaseMemoryLib
[Protocols]
diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc
index 5834eafaa200..c3c27afff88e 100644
--- a/UefiCpuPkg/UefiCpuPkg.dsc
+++ b/UefiCpuPkg/UefiCpuPkg.dsc
@@ -91,6 +91,7 @@ [LibraryClasses.common.DXE_DRIVER]
[LibraryClasses.common.DXE_SMM_DRIVER]
SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf
+ MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file
[not found] <20210126194710.2248-1-kun.q@outlook.com>
` (13 preceding siblings ...)
2021-01-26 19:47 ` [PATCH v4 17/20] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
@ 2021-01-26 19:47 ` Kun Qin
2021-01-29 7:06 ` Ni, Ray
14 siblings, 1 reply; 17+ messages in thread
From: Kun Qin @ 2021-01-26 19:47 UTC (permalink / raw)
To: devel; +Cc: Eric Dong, Ray Ni, Laszlo Ersek, Rahul Kumar
This change abstracts CpuIo2Smm driver entrypoint into separate file and
moves functions/definitions that are not substantially specific to
Traditional MM (SMM) into CpuIo2Mm.* in order to set ways for Standalone
MM support in the future.
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Kun Qin <kun.q@outlook.com>
---
Notes:
v4:
- Newly created patch to rename files for existed SMM driver [Ray]
UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.c => CpuIo2Mm.c} | 11 +-
UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c | 385 +-------------------
UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.h => CpuIo2Mm.h} | 12 +
UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 3 +-
4 files changed, 22 insertions(+), 389 deletions(-)
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.c
similarity index 95%
copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
copy to UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.c
index c0a2baecee03..7e314eaa1558 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.c
@@ -6,7 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include "CpuIo2Smm.h"
+#include "CpuIo2Mm.h"
//
// Handle for the SMM CPU I/O Protocol
@@ -371,18 +371,13 @@ CpuIoServiceWrite (
/**
The module Entry Point SmmCpuIoProtocol driver
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
-
@retval EFI_SUCCESS The entry point is executed successfully.
@retval Other Some error occurs when executing this entry point.
**/
EFI_STATUS
-EFIAPI
-SmmCpuIo2Initialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
+CommonCpuIo2Initialize (
+ VOID
)
{
EFI_STATUS Status;
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
index c0a2baecee03..1acce9f3d462 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
@@ -2,374 +2,17 @@
Produces the SMM CPU I/O Protocol.
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
-#include "CpuIo2Smm.h"
+#include <PiSmm.h>
-//
-// Handle for the SMM CPU I/O Protocol
-//
-EFI_HANDLE mHandle = NULL;
-
-//
-// SMM CPU I/O Protocol instance
-//
-EFI_SMM_CPU_IO2_PROTOCOL mSmmCpuIo2 = {
- {
- CpuMemoryServiceRead,
- CpuMemoryServiceWrite
- },
- {
- CpuIoServiceRead,
- CpuIoServiceWrite
- }
-};
-
-//
-// Lookup table for increment values based on transfer widths
-//
-UINT8 mStride[] = {
- 1, // SMM_IO_UINT8
- 2, // SMM_IO_UINT16
- 4, // SMM_IO_UINT32
- 8 // SMM_IO_UINT64
-};
-
-/**
- Check parameters to a SMM CPU I/O Protocol service request.
-
- @param[in] MmioOperation TRUE for an MMIO operation, FALSE for I/O Port operation.
- @param[in] Width Signifies the width of the I/O operations.
- @param[in] Address The base address of the I/O operations. The caller is
- responsible for aligning the Address if required.
- @param[in] Count The number of I/O operations to perform.
- @param[in] Buffer For read operations, the destination buffer to store
- the results. For write operations, the source buffer
- from which to write data.
-
- @retval EFI_SUCCESS The data was read from or written to the device.
- @retval EFI_UNSUPPORTED The Address is not valid for this system.
- @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
-
-**/
-EFI_STATUS
-CpuIoCheckParameter (
- IN BOOLEAN MmioOperation,
- IN EFI_SMM_IO_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Count,
- IN VOID *Buffer
- )
-{
- UINT64 MaxCount;
- UINT64 Limit;
-
- //
- // Check to see if Buffer is NULL
- //
- if (Buffer == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Check to see if Width is in the valid range
- //
- if ((UINT32)Width > SMM_IO_UINT64) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Check to see if Width is in the valid range for I/O Port operations
- //
- if (!MmioOperation && (Width == SMM_IO_UINT64)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Check to see if any address associated with this transfer exceeds the maximum
- // allowed address. The maximum address implied by the parameters passed in is
- // Address + Size * Count. If the following condition is met, then the transfer
- // is not supported.
- //
- // Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS) + 1
- //
- // Since MAX_ADDRESS can be the maximum integer value supported by the CPU and Count
- // can also be the maximum integer value supported by the CPU, this range
- // check must be adjusted to avoid all overflow conditions.
- //
- // The following form of the range check is equivalent but assumes that
- // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1).
- //
- Limit = (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS);
- if (Count == 0) {
- if (Address > Limit) {
- return EFI_UNSUPPORTED;
- }
- } else {
- MaxCount = RShiftU64 (Limit, Width);
- if (MaxCount < (Count - 1)) {
- return EFI_UNSUPPORTED;
- }
- if (Address > LShiftU64 (MaxCount - Count + 1, Width)) {
- return EFI_UNSUPPORTED;
- }
- }
-
- //
- // Check to see if Address is aligned
- //
- if ((Address & ((UINT64)mStride[Width] - 1)) != 0) {
- return EFI_UNSUPPORTED;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Reads memory-mapped registers.
-
- The I/O operations are carried out exactly as requested. The caller is
- responsible for any alignment and I/O width issues that the bus, device,
- platform, or type of I/O might require.
-
- @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
- @param[in] Width Signifies the width of the I/O operations.
- @param[in] Address The base address of the I/O operations. The caller is
- responsible for aligning the Address if required.
- @param[in] Count The number of I/O operations to perform.
- @param[out] Buffer For read operations, the destination buffer to store
- the results. For write operations, the source buffer
- from which to write data.
-
- @retval EFI_SUCCESS The data was read from or written to the device.
- @retval EFI_UNSUPPORTED The Address is not valid for this system.
- @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMemoryServiceRead (
- IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
- IN EFI_SMM_IO_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Count,
- OUT VOID *Buffer
- )
-{
- EFI_STATUS Status;
- UINT8 Stride;
- UINT8 *Uint8Buffer;
-
- Status = CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Select loop based on the width of the transfer
- //
- Stride = mStride[Width];
- for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
- if (Width == SMM_IO_UINT8) {
- *Uint8Buffer = MmioRead8 ((UINTN)Address);
- } else if (Width == SMM_IO_UINT16) {
- *((UINT16 *)Uint8Buffer) = MmioRead16 ((UINTN)Address);
- } else if (Width == SMM_IO_UINT32) {
- *((UINT32 *)Uint8Buffer) = MmioRead32 ((UINTN)Address);
- } else if (Width == SMM_IO_UINT64) {
- *((UINT64 *)Uint8Buffer) = MmioRead64 ((UINTN)Address);
- }
- }
- return EFI_SUCCESS;
-}
-
-/**
- Writes memory-mapped registers.
-
- The I/O operations are carried out exactly as requested. The caller is
- responsible for any alignment and I/O width issues that the bus, device,
- platform, or type of I/O might require.
-
- @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
- @param[in] Width Signifies the width of the I/O operations.
- @param[in] Address The base address of the I/O operations. The caller is
- responsible for aligning the Address if required.
- @param[in] Count The number of I/O operations to perform.
- @param[in] Buffer For read operations, the destination buffer to store
- the results. For write operations, the source buffer
- from which to write data.
-
- @retval EFI_SUCCESS The data was read from or written to the device.
- @retval EFI_UNSUPPORTED The Address is not valid for this system.
- @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuMemoryServiceWrite (
- IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
- IN EFI_SMM_IO_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Count,
- IN VOID *Buffer
- )
-{
- EFI_STATUS Status;
- UINT8 Stride;
- UINT8 *Uint8Buffer;
-
- Status = CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Select loop based on the width of the transfer
- //
- Stride = mStride[Width];
- for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
- if (Width == SMM_IO_UINT8) {
- MmioWrite8 ((UINTN)Address, *Uint8Buffer);
- } else if (Width == SMM_IO_UINT16) {
- MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));
- } else if (Width == SMM_IO_UINT32) {
- MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));
- } else if (Width == SMM_IO_UINT64) {
- MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer));
- }
- }
- return EFI_SUCCESS;
-}
-
-/**
- Reads I/O registers.
-
- The I/O operations are carried out exactly as requested. The caller is
- responsible for any alignment and I/O width issues that the bus, device,
- platform, or type of I/O might require.
-
- @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
- @param[in] Width Signifies the width of the I/O operations.
- @param[in] Address The base address of the I/O operations. The caller is
- responsible for aligning the Address if required.
- @param[in] Count The number of I/O operations to perform.
- @param[out] Buffer For read operations, the destination buffer to store
- the results. For write operations, the source buffer
- from which to write data.
-
- @retval EFI_SUCCESS The data was read from or written to the device.
- @retval EFI_UNSUPPORTED The Address is not valid for this system.
- @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuIoServiceRead (
- IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
- IN EFI_SMM_IO_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Count,
- OUT VOID *Buffer
- )
-{
- EFI_STATUS Status;
- UINT8 Stride;
- UINT8 *Uint8Buffer;
-
- Status = CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Select loop based on the width of the transfer
- //
- Stride = mStride[Width];
- for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
- if (Width == SMM_IO_UINT8) {
- *Uint8Buffer = IoRead8 ((UINTN)Address);
- } else if (Width == SMM_IO_UINT16) {
- *((UINT16 *)Uint8Buffer) = IoRead16 ((UINTN)Address);
- } else if (Width == SMM_IO_UINT32) {
- *((UINT32 *)Uint8Buffer) = IoRead32 ((UINTN)Address);
- }
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Write I/O registers.
-
- The I/O operations are carried out exactly as requested. The caller is
- responsible for any alignment and I/O width issues that the bus, device,
- platform, or type of I/O might require.
-
- @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
- @param[in] Width Signifies the width of the I/O operations.
- @param[in] Address The base address of the I/O operations. The caller is
- responsible for aligning the Address if required.
- @param[in] Count The number of I/O operations to perform.
- @param[in] Buffer For read operations, the destination buffer to store
- the results. For write operations, the source buffer
- from which to write data.
-
- @retval EFI_SUCCESS The data was read from or written to the device.
- @retval EFI_UNSUPPORTED The Address is not valid for this system.
- @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
- @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
- lack of resources
-
-**/
-EFI_STATUS
-EFIAPI
-CpuIoServiceWrite (
- IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
- IN EFI_SMM_IO_WIDTH Width,
- IN UINT64 Address,
- IN UINTN Count,
- IN VOID *Buffer
- )
-{
- EFI_STATUS Status;
- UINT8 Stride;
- UINT8 *Uint8Buffer;
-
- //
- // Make sure the parameters are valid
- //
- Status = CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer);
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- //
- // Select loop based on the width of the transfer
- //
- Stride = mStride[Width];
- for (Uint8Buffer = (UINT8 *)Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
- if (Width == SMM_IO_UINT8) {
- IoWrite8 ((UINTN)Address, *Uint8Buffer);
- } else if (Width == SMM_IO_UINT16) {
- IoWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));
- } else if (Width == SMM_IO_UINT32) {
- IoWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));
- }
- }
-
- return EFI_SUCCESS;
-}
+#include "CpuIo2Mm.h"
/**
- The module Entry Point SmmCpuIoProtocol driver
+ The module Entry Point for Traditional MM CpuIoProtocol driver
@param[in] ImageHandle The firmware allocated handle for the EFI image.
@param[in] SystemTable A pointer to the EFI System Table.
@@ -385,23 +28,5 @@ SmmCpuIo2Initialize (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
-
- //
- // Copy the SMM CPU I/O Protocol instance into the System Management System Table
- //
- CopyMem (&gMmst->MmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
-
- //
- // Install the SMM CPU I/O Protocol into the MM protocol database
- //
- Status = gMmst->MmInstallProtocolInterface (
- &mHandle,
- &gEfiSmmCpuIo2ProtocolGuid,
- EFI_NATIVE_INTERFACE,
- &mSmmCpuIo2
- );
- ASSERT_EFI_ERROR (Status);
-
- return Status;
+ return CommonCpuIo2Initialize ();
}
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.h
similarity index 93%
rename from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
rename to UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.h
index c80261945f71..eda9fbb090cd 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.h
@@ -153,4 +153,16 @@ CpuIoServiceWrite (
IN VOID *Buffer
);
+/**
+ The module Entry Point SmmCpuIoProtocol driver
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval Other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+CommonCpuIo2Initialize (
+ VOID
+ );
+
#endif
diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
index b743a5e0e316..304f0ce83c62 100644
--- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
+++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
@@ -24,7 +24,8 @@ [Defines]
[Sources]
CpuIo2Smm.c
- CpuIo2Smm.h
+ CpuIo2Mm.c
+ CpuIo2Mm.h
[Packages]
MdePkg/MdePkg.dec
--
2.30.0.windows.1
^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib: Support StandaloneMm Instance
2021-01-26 19:47 ` [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib: Support StandaloneMm Instance Kun Qin
@ 2021-01-27 0:56 ` Wu, Hao A
0 siblings, 0 replies; 17+ messages in thread
From: Wu, Hao A @ 2021-01-27 0:56 UTC (permalink / raw)
To: Kun Qin, devel@edk2.groups.io; +Cc: Wang, Jian J, Dong, Eric, Ni, Ray
> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Wednesday, January 27, 2021 3:47 AM
> To: devel@edk2.groups.io
> Cc: Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>;
> Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>
> Subject: [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib:
> Support StandaloneMm Instance
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3185
>
> This change added support of SMI handler profile library router under
> StandaloneMm. This change replaces gSmst with gMmst. It also abstracts
> standalone and traditional MM driver entrypoints into separate files to allow
> maximal common implementations.
>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>
> Notes:
> v4:
> - Newly created for SmmSmiHandlerProfileLib coverage.
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Best Regards,
Hao Wu
>
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/{SmmSmiHandlerProfileL
> ib.c => MmSmiHandlerProfileLib.c} | 20 ++---
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLi
> b.c | 90 ++------------------
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandl
> erProfileLib.c | 31 +++++++
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib
> .h | 23 +++++
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLi
> b.inf | 4 +-
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandl
> erProfileLib.inf | 44 ++++++++++
> MdeModulePkg/MdeModulePkg.dsc | 1
> +
> 7 files changed, 117 insertions(+), 96 deletions(-)
>
> diff --git
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfile
> Lib.c
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfile
> Lib.c
> similarity index 86%
> copy from
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLi
> b.c
> copy to
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileLib
> .c
> index b76e8f0dc132..f800220b549c 100644
> ---
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfile
> Lib.c
> +++
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfile
> Li
> +++ b.c
> @@ -1,14 +1,15 @@
> /** @file
> - SMM driver instance of SmiHandlerProfile Library.
> + MM driver instance of SmiHandlerProfile Library.
>
> Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> + Copyright (c) Microsoft Corporation.
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
>
> -#include <PiSmm.h>
> +#include <PiMm.h>
> #include <Library/SmiHandlerProfileLib.h> -#include
> <Library/SmmServicesTableLib.h>
> +#include <Library/MmServicesTableLib.h>
> #include <Guid/SmiHandlerProfile.h>
>
> SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile; @@ -82,21
> +83,16 @@ SmiHandlerProfileUnregisterHandler ( }
>
> /**
> - The constructor function for SMI handler profile.
> -
> - @param ImageHandle The firmware allocated handle for the EFI image.
> - @param SystemTable A pointer to the EFI System Table.
> + The common constructor function for SMI handler profile.
>
> @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
> **/
> EFI_STATUS
> -EFIAPI
> -SmmSmiHandlerProfileLibConstructor (
> - IN EFI_HANDLE ImageHandle,
> - IN EFI_SYSTEM_TABLE *SystemTable
> +MmSmiHandlerProfileLibInitialization (
> + VOID
> )
> {
> - gSmst->SmmLocateProtocol (
> + gMmst->MmLocateProtocol (
> &gSmiHandlerProfileGuid,
> NULL,
> (VOID **) &mSmiHandlerProfile diff --git
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfile
> Lib.c
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfil
> eLib.c
> index b76e8f0dc132..0167d81b880d 100644
> ---
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfile
> Lib.c
> +++
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfil
> eL
> +++ ib.c
> @@ -2,87 +2,17 @@
> SMM driver instance of SmiHandlerProfile Library.
>
> Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> + Copyright (c) Microsoft Corporation.
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
>
> -#include <PiSmm.h>
> -#include <Library/SmiHandlerProfileLib.h> -#include
> <Library/SmmServicesTableLib.h> -#include <Guid/SmiHandlerProfile.h>
> +#include <PiMm.h>
>
> -SMI_HANDLER_PROFILE_PROTOCOL *mSmiHandlerProfile;
> +#include "MmSmiHandlerProfileLib.h"
>
> /**
> - This function is called by SmmChildDispatcher module to report
> - a new SMI handler is registered, to SmmCore.
> -
> - @param HandlerGuid The GUID to identify the type of the handler.
> - For the SmmChildDispatch protocol, the HandlerGuid
> - must be the GUID of SmmChildDispatch protocol.
> - @param Handler The SMI handler.
> - @param CallerAddress The address of the module who registers the SMI
> handler.
> - @param Context The context of the SMI handler.
> - For the SmmChildDispatch protocol, the Context
> - must match the one defined for SmmChildDispatch protocol.
> - @param ContextSize The size of the context in bytes.
> - For the SmmChildDispatch protocol, the Context
> - must match the one defined for SmmChildDispatch protocol.
> -
> - @retval EFI_SUCCESS The information is recorded.
> - @retval EFI_UNSUPPORTED The feature is unsupported.
> - @retval EFI_OUT_OF_RESOURCES There is no enough resource to record
> the information.
> -**/
> -EFI_STATUS
> -EFIAPI
> -SmiHandlerProfileRegisterHandler (
> - IN EFI_GUID *HandlerGuid,
> - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
> - IN PHYSICAL_ADDRESS CallerAddress,
> - IN VOID *Context, OPTIONAL
> - IN UINTN ContextSize OPTIONAL
> - )
> -{
> - if (mSmiHandlerProfile != NULL) {
> - return mSmiHandlerProfile->RegisterHandler (mSmiHandlerProfile,
> HandlerGuid, Handler, CallerAddress, Context, ContextSize);
> - }
> - return EFI_UNSUPPORTED;
> -}
> -
> -/**
> - This function is called by SmmChildDispatcher module to report
> - an existing SMI handler is unregistered, to SmmCore.
> -
> - @param HandlerGuid The GUID to identify the type of the handler.
> - For the SmmChildDispatch protocol, the HandlerGuid
> - must be the GUID of SmmChildDispatch protocol.
> - @param Handler The SMI handler.
> - @param Context The context of the SMI handler.
> - If it is NOT NULL, it will be used to check what is registered.
> - @param ContextSize The size of the context in bytes.
> - If Context is NOT NULL, it will be used to check what is
> registered.
> -
> - @retval EFI_SUCCESS The original record is removed.
> - @retval EFI_UNSUPPORTED The feature is unsupported.
> - @retval EFI_NOT_FOUND There is no record for the HandlerGuid and
> handler.
> -**/
> -EFI_STATUS
> -EFIAPI
> -SmiHandlerProfileUnregisterHandler (
> - IN EFI_GUID *HandlerGuid,
> - IN EFI_SMM_HANDLER_ENTRY_POINT2 Handler,
> - IN VOID *Context, OPTIONAL
> - IN UINTN ContextSize OPTIONAL
> - )
> -{
> - if (mSmiHandlerProfile != NULL) {
> - return mSmiHandlerProfile->UnregisterHandler (mSmiHandlerProfile,
> HandlerGuid, Handler, Context, ContextSize);
> - }
> - return EFI_UNSUPPORTED;
> -}
> -
> -/**
> - The constructor function for SMI handler profile.
> + The constructor function for traditional MM SMI handler profile.
>
> @param ImageHandle The firmware allocated handle for the EFI image.
> @param SystemTable A pointer to the EFI System Table.
> @@ -92,15 +22,9 @@ SmiHandlerProfileUnregisterHandler ( EFI_STATUS
> EFIAPI SmmSmiHandlerProfileLibConstructor (
> - IN EFI_HANDLE ImageHandle,
> - IN EFI_SYSTEM_TABLE *SystemTable
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_SYSTEM_TABLE *SystemTable
> )
> {
> - gSmst->SmmLocateProtocol (
> - &gSmiHandlerProfileGuid,
> - NULL,
> - (VOID **) &mSmiHandlerProfile
> - );
> - return EFI_SUCCESS;
> + return MmSmiHandlerProfileLibInitialization ();
> }
> -
> diff --git
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHan
> dlerProfileLib.c
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHan
> dlerProfileLib.c
> new file mode 100644
> index 000000000000..a7714390e5b1
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHan
> dle
> +++ rProfileLib.c
> @@ -0,0 +1,31 @@
> +/** @file
> + Standalone MM driver instance of SmiHandlerProfile Library.
> +
> + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> + Copyright (c) Microsoft Corporation.
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <PiMm.h>
> +
> +#include "MmSmiHandlerProfileLib.h"
> +
> +/**
> + The constructor function for standalone MM SMI handler profile.
> +
> + @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
> +StandaloneMmSmiHandlerProfileLibConstructor (
> + IN EFI_HANDLE ImageHandle,
> + IN EFI_MM_SYSTEM_TABLE *SystemTable
> + )
> +{
> + return MmSmiHandlerProfileLibInitialization (); }
> +
> diff --git
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfileL
> ib.h
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfile
> Lib.h
> new file mode 100644
> index 000000000000..8e390590ee7b
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/MmSmiHandlerProfile
> Li
> +++ b.h
> @@ -0,0 +1,23 @@
> +/** @file
> + MM driver instance of SmiHandlerProfile Library.
> +
> + Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
> + Copyright (c) Microsoft Corporation.
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#ifndef _MM_SMI_HANDLER_PROFILE_LIB_H_
> +#define _MM_SMI_HANDLER_PROFILE_LIB_H_
> +
> +/**
> + The common constructor function for SMI handler profile.
> +
> + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
> +**/
> +EFI_STATUS
> +MmSmiHandlerProfileLibInitialization (
> + VOID
> + );
> +
> +#endif //_SMM_SMI_HANDLER_PROFILE_LIB_H_
> diff --git
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfile
> Lib.inf
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfil
> eLib.inf
> index 1d738c7087c6..56007d502134 100644
> ---
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfile
> Lib.inf
> +++
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfil
> eL
> +++ ib.inf
> @@ -27,6 +27,8 @@ [Defines]
> #
>
> [Sources]
> + MmSmiHandlerProfileLib.c
> + MmSmiHandlerProfileLib.h
> SmmSmiHandlerProfileLib.c
>
> [Packages]
> @@ -34,7 +36,7 @@ [Packages]
> MdeModulePkg/MdeModulePkg.dec
>
> [LibraryClasses]
> - SmmServicesTableLib
> + MmServicesTableLib
>
> [Guids]
> gSmiHandlerProfileGuid ## CONSUMES ## GUID # Locate protocol
> diff --git
> a/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHan
> dlerProfileLib.inf
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHan
> dlerProfileLib.inf
> new file mode 100644
> index 000000000000..a885cc2b2ae1
> --- /dev/null
> +++
> b/MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHan
> dle
> +++ rProfileLib.inf
> @@ -0,0 +1,44 @@
> +## @file
> +# Standalone MM driver instance of SmiHandlerProfile Library.
> +#
> +# This library instance provides real functionality for SmmChildDispatcher
> module.
> +#
> +# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR> #
> +Copyright (c) Microsoft Corporation.
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent # # ##
> +
> +[Defines]
> + INF_VERSION = 0x00010005
> + BASE_NAME = StandaloneMmSmiHandlerProfileLib
> + FILE_GUID = 1F2ED27B-A01D-4867-B993-9B710E5926C5
> + MODULE_TYPE = MM_STANDALONE
> + VERSION_STRING = 1.0
> + PI_SPECIFICATION_VERSION = 0x10000032
> + LIBRARY_CLASS = SmiHandlerProfileLib|MM_STANDALONE
> + CONSTRUCTOR =
> StandaloneMmSmiHandlerProfileLibConstructor
> +
> +#
> +# The following information is for reference only and not required by the
> build tools.
> +#
> +# VALID_ARCHITECTURES = IA32 X64
> +#
> +
> +[Sources]
> + MmSmiHandlerProfileLib.c
> + MmSmiHandlerProfileLib.h
> + StandaloneMmSmiHandlerProfileLib.c
> +
> +[Packages]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> +
> +[LibraryClasses]
> + MmServicesTableLib
> +
> +[Guids]
> + gSmiHandlerProfileGuid ## CONSUMES ## GUID # Locate protocol
> +
> diff --git a/MdeModulePkg/MdeModulePkg.dsc
> b/MdeModulePkg/MdeModulePkg.dsc index f95c7cd69ee1..7ca4a1bb3080
> 100644
> --- a/MdeModulePkg/MdeModulePkg.dsc
> +++ b/MdeModulePkg/MdeModulePkg.dsc
> @@ -492,6 +492,7 @@ [Components.IA32, Components.X64]
>
> MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.inf
>
> MdeModulePkg/Library/SmmCorePlatformHookLibNull/SmmCorePlatformH
> ookLibNull.inf
>
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/SmmSmiHandlerProfileLi
> b.inf
> +
> +
> MdeModulePkg/Library/SmmSmiHandlerProfileLib/StandaloneMmSmiHandl
> erPro
> + fileLib.inf
>
> MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaArchCustomDeco
> mpressLib.inf
>
> MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutor
> Dxe.inf
> MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
> --
> 2.30.0.windows.1
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file
2021-01-26 19:47 ` [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file Kun Qin
@ 2021-01-29 7:06 ` Ni, Ray
0 siblings, 0 replies; 17+ messages in thread
From: Ni, Ray @ 2021-01-29 7:06 UTC (permalink / raw)
To: Kun Qin, devel@edk2.groups.io; +Cc: Dong, Eric, Laszlo Ersek, Kumar, Rahul1
Reviewed-by: Ray Ni <ray.ni@intel.com>
> -----Original Message-----
> From: Kun Qin <kun.q@outlook.com>
> Sent: Wednesday, January 27, 2021 3:47 AM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul1
> <rahul1.kumar@intel.com>
> Subject: [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file
>
> This change abstracts CpuIo2Smm driver entrypoint into separate file and
> moves functions/definitions that are not substantially specific to
> Traditional MM (SMM) into CpuIo2Mm.* in order to set ways for Standalone
> MM support in the future.
>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
>
> Signed-off-by: Kun Qin <kun.q@outlook.com>
> ---
>
> Notes:
> v4:
> - Newly created patch to rename files for existed SMM driver [Ray]
>
> UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.c => CpuIo2Mm.c} | 11 +-
> UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c | 385 +-------------------
> UefiCpuPkg/CpuIo2Smm/{CpuIo2Smm.h => CpuIo2Mm.h} | 12 +
> UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf | 3 +-
> 4 files changed, 22 insertions(+), 389 deletions(-)
>
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.c
> similarity index 95%
> copy from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> copy to UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.c
> index c0a2baecee03..7e314eaa1558 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.c
> @@ -6,7 +6,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
>
> -#include "CpuIo2Smm.h"
> +#include "CpuIo2Mm.h"
>
> //
> // Handle for the SMM CPU I/O Protocol
> @@ -371,18 +371,13 @@ CpuIoServiceWrite (
> /**
> The module Entry Point SmmCpuIoProtocol driver
>
> - @param[in] ImageHandle The firmware allocated handle for the EFI image.
> - @param[in] SystemTable A pointer to the EFI System Table.
> -
> @retval EFI_SUCCESS The entry point is executed successfully.
> @retval Other Some error occurs when executing this entry point.
>
> **/
> EFI_STATUS
> -EFIAPI
> -SmmCpuIo2Initialize (
> - IN EFI_HANDLE ImageHandle,
> - IN EFI_SYSTEM_TABLE *SystemTable
> +CommonCpuIo2Initialize (
> + VOID
> )
> {
> EFI_STATUS Status;
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> index c0a2baecee03..1acce9f3d462 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.c
> @@ -2,374 +2,17 @@
> Produces the SMM CPU I/O Protocol.
>
> Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) Microsoft Corporation.
> SPDX-License-Identifier: BSD-2-Clause-Patent
>
> **/
>
> -#include "CpuIo2Smm.h"
> +#include <PiSmm.h>
>
> -//
> -// Handle for the SMM CPU I/O Protocol
> -//
> -EFI_HANDLE mHandle = NULL;
> -
> -//
> -// SMM CPU I/O Protocol instance
> -//
> -EFI_SMM_CPU_IO2_PROTOCOL mSmmCpuIo2 = {
> - {
> - CpuMemoryServiceRead,
> - CpuMemoryServiceWrite
> - },
> - {
> - CpuIoServiceRead,
> - CpuIoServiceWrite
> - }
> -};
> -
> -//
> -// Lookup table for increment values based on transfer widths
> -//
> -UINT8 mStride[] = {
> - 1, // SMM_IO_UINT8
> - 2, // SMM_IO_UINT16
> - 4, // SMM_IO_UINT32
> - 8 // SMM_IO_UINT64
> -};
> -
> -/**
> - Check parameters to a SMM CPU I/O Protocol service request.
> -
> - @param[in] MmioOperation TRUE for an MMIO operation, FALSE for I/O Port operation.
> - @param[in] Width Signifies the width of the I/O operations.
> - @param[in] Address The base address of the I/O operations. The caller is
> - responsible for aligning the Address if required.
> - @param[in] Count The number of I/O operations to perform.
> - @param[in] Buffer For read operations, the destination buffer to store
> - the results. For write operations, the source buffer
> - from which to write data.
> -
> - @retval EFI_SUCCESS The data was read from or written to the device.
> - @retval EFI_UNSUPPORTED The Address is not valid for this system.
> - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
> -
> -**/
> -EFI_STATUS
> -CpuIoCheckParameter (
> - IN BOOLEAN MmioOperation,
> - IN EFI_SMM_IO_WIDTH Width,
> - IN UINT64 Address,
> - IN UINTN Count,
> - IN VOID *Buffer
> - )
> -{
> - UINT64 MaxCount;
> - UINT64 Limit;
> -
> - //
> - // Check to see if Buffer is NULL
> - //
> - if (Buffer == NULL) {
> - return EFI_INVALID_PARAMETER;
> - }
> -
> - //
> - // Check to see if Width is in the valid range
> - //
> - if ((UINT32)Width > SMM_IO_UINT64) {
> - return EFI_INVALID_PARAMETER;
> - }
> -
> - //
> - // Check to see if Width is in the valid range for I/O Port operations
> - //
> - if (!MmioOperation && (Width == SMM_IO_UINT64)) {
> - return EFI_INVALID_PARAMETER;
> - }
> -
> - //
> - // Check to see if any address associated with this transfer exceeds the maximum
> - // allowed address. The maximum address implied by the parameters passed in is
> - // Address + Size * Count. If the following condition is met, then the transfer
> - // is not supported.
> - //
> - // Address + Size * Count > (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS) + 1
> - //
> - // Since MAX_ADDRESS can be the maximum integer value supported by the CPU and Count
> - // can also be the maximum integer value supported by the CPU, this range
> - // check must be adjusted to avoid all overflow conditions.
> - //
> - // The following form of the range check is equivalent but assumes that
> - // MAX_ADDRESS and MAX_IO_PORT_ADDRESS are of the form (2^n - 1).
> - //
> - Limit = (MmioOperation ? MAX_ADDRESS : MAX_IO_PORT_ADDRESS);
> - if (Count == 0) {
> - if (Address > Limit) {
> - return EFI_UNSUPPORTED;
> - }
> - } else {
> - MaxCount = RShiftU64 (Limit, Width);
> - if (MaxCount < (Count - 1)) {
> - return EFI_UNSUPPORTED;
> - }
> - if (Address > LShiftU64 (MaxCount - Count + 1, Width)) {
> - return EFI_UNSUPPORTED;
> - }
> - }
> -
> - //
> - // Check to see if Address is aligned
> - //
> - if ((Address & ((UINT64)mStride[Width] - 1)) != 0) {
> - return EFI_UNSUPPORTED;
> - }
> -
> - return EFI_SUCCESS;
> -}
> -
> -/**
> - Reads memory-mapped registers.
> -
> - The I/O operations are carried out exactly as requested. The caller is
> - responsible for any alignment and I/O width issues that the bus, device,
> - platform, or type of I/O might require.
> -
> - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
> - @param[in] Width Signifies the width of the I/O operations.
> - @param[in] Address The base address of the I/O operations. The caller is
> - responsible for aligning the Address if required.
> - @param[in] Count The number of I/O operations to perform.
> - @param[out] Buffer For read operations, the destination buffer to store
> - the results. For write operations, the source buffer
> - from which to write data.
> -
> - @retval EFI_SUCCESS The data was read from or written to the device.
> - @retval EFI_UNSUPPORTED The Address is not valid for this system.
> - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
> - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
> - lack of resources
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -CpuMemoryServiceRead (
> - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
> - IN EFI_SMM_IO_WIDTH Width,
> - IN UINT64 Address,
> - IN UINTN Count,
> - OUT VOID *Buffer
> - )
> -{
> - EFI_STATUS Status;
> - UINT8 Stride;
> - UINT8 *Uint8Buffer;
> -
> - Status = CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer);
> - if (EFI_ERROR (Status)) {
> - return Status;
> - }
> -
> - //
> - // Select loop based on the width of the transfer
> - //
> - Stride = mStride[Width];
> - for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
> - if (Width == SMM_IO_UINT8) {
> - *Uint8Buffer = MmioRead8 ((UINTN)Address);
> - } else if (Width == SMM_IO_UINT16) {
> - *((UINT16 *)Uint8Buffer) = MmioRead16 ((UINTN)Address);
> - } else if (Width == SMM_IO_UINT32) {
> - *((UINT32 *)Uint8Buffer) = MmioRead32 ((UINTN)Address);
> - } else if (Width == SMM_IO_UINT64) {
> - *((UINT64 *)Uint8Buffer) = MmioRead64 ((UINTN)Address);
> - }
> - }
> - return EFI_SUCCESS;
> -}
> -
> -/**
> - Writes memory-mapped registers.
> -
> - The I/O operations are carried out exactly as requested. The caller is
> - responsible for any alignment and I/O width issues that the bus, device,
> - platform, or type of I/O might require.
> -
> - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
> - @param[in] Width Signifies the width of the I/O operations.
> - @param[in] Address The base address of the I/O operations. The caller is
> - responsible for aligning the Address if required.
> - @param[in] Count The number of I/O operations to perform.
> - @param[in] Buffer For read operations, the destination buffer to store
> - the results. For write operations, the source buffer
> - from which to write data.
> -
> - @retval EFI_SUCCESS The data was read from or written to the device.
> - @retval EFI_UNSUPPORTED The Address is not valid for this system.
> - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
> - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
> - lack of resources
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -CpuMemoryServiceWrite (
> - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
> - IN EFI_SMM_IO_WIDTH Width,
> - IN UINT64 Address,
> - IN UINTN Count,
> - IN VOID *Buffer
> - )
> -{
> - EFI_STATUS Status;
> - UINT8 Stride;
> - UINT8 *Uint8Buffer;
> -
> - Status = CpuIoCheckParameter (TRUE, Width, Address, Count, Buffer);
> - if (EFI_ERROR (Status)) {
> - return Status;
> - }
> -
> - //
> - // Select loop based on the width of the transfer
> - //
> - Stride = mStride[Width];
> - for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
> - if (Width == SMM_IO_UINT8) {
> - MmioWrite8 ((UINTN)Address, *Uint8Buffer);
> - } else if (Width == SMM_IO_UINT16) {
> - MmioWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));
> - } else if (Width == SMM_IO_UINT32) {
> - MmioWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));
> - } else if (Width == SMM_IO_UINT64) {
> - MmioWrite64 ((UINTN)Address, *((UINT64 *)Uint8Buffer));
> - }
> - }
> - return EFI_SUCCESS;
> -}
> -
> -/**
> - Reads I/O registers.
> -
> - The I/O operations are carried out exactly as requested. The caller is
> - responsible for any alignment and I/O width issues that the bus, device,
> - platform, or type of I/O might require.
> -
> - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
> - @param[in] Width Signifies the width of the I/O operations.
> - @param[in] Address The base address of the I/O operations. The caller is
> - responsible for aligning the Address if required.
> - @param[in] Count The number of I/O operations to perform.
> - @param[out] Buffer For read operations, the destination buffer to store
> - the results. For write operations, the source buffer
> - from which to write data.
> -
> - @retval EFI_SUCCESS The data was read from or written to the device.
> - @retval EFI_UNSUPPORTED The Address is not valid for this system.
> - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
> - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
> - lack of resources
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -CpuIoServiceRead (
> - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
> - IN EFI_SMM_IO_WIDTH Width,
> - IN UINT64 Address,
> - IN UINTN Count,
> - OUT VOID *Buffer
> - )
> -{
> - EFI_STATUS Status;
> - UINT8 Stride;
> - UINT8 *Uint8Buffer;
> -
> - Status = CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer);
> - if (EFI_ERROR (Status)) {
> - return Status;
> - }
> -
> - //
> - // Select loop based on the width of the transfer
> - //
> - Stride = mStride[Width];
> - for (Uint8Buffer = Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
> - if (Width == SMM_IO_UINT8) {
> - *Uint8Buffer = IoRead8 ((UINTN)Address);
> - } else if (Width == SMM_IO_UINT16) {
> - *((UINT16 *)Uint8Buffer) = IoRead16 ((UINTN)Address);
> - } else if (Width == SMM_IO_UINT32) {
> - *((UINT32 *)Uint8Buffer) = IoRead32 ((UINTN)Address);
> - }
> - }
> -
> - return EFI_SUCCESS;
> -}
> -
> -/**
> - Write I/O registers.
> -
> - The I/O operations are carried out exactly as requested. The caller is
> - responsible for any alignment and I/O width issues that the bus, device,
> - platform, or type of I/O might require.
> -
> - @param[in] This The EFI_SMM_CPU_IO2_PROTOCOL instance.
> - @param[in] Width Signifies the width of the I/O operations.
> - @param[in] Address The base address of the I/O operations. The caller is
> - responsible for aligning the Address if required.
> - @param[in] Count The number of I/O operations to perform.
> - @param[in] Buffer For read operations, the destination buffer to store
> - the results. For write operations, the source buffer
> - from which to write data.
> -
> - @retval EFI_SUCCESS The data was read from or written to the device.
> - @retval EFI_UNSUPPORTED The Address is not valid for this system.
> - @retval EFI_INVALID_PARAMETER Width or Count, or both, were invalid.
> - @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a
> - lack of resources
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -CpuIoServiceWrite (
> - IN CONST EFI_SMM_CPU_IO2_PROTOCOL *This,
> - IN EFI_SMM_IO_WIDTH Width,
> - IN UINT64 Address,
> - IN UINTN Count,
> - IN VOID *Buffer
> - )
> -{
> - EFI_STATUS Status;
> - UINT8 Stride;
> - UINT8 *Uint8Buffer;
> -
> - //
> - // Make sure the parameters are valid
> - //
> - Status = CpuIoCheckParameter (FALSE, Width, Address, Count, Buffer);
> - if (EFI_ERROR (Status)) {
> - return Status;
> - }
> -
> - //
> - // Select loop based on the width of the transfer
> - //
> - Stride = mStride[Width];
> - for (Uint8Buffer = (UINT8 *)Buffer; Count > 0; Address += Stride, Uint8Buffer += Stride, Count--) {
> - if (Width == SMM_IO_UINT8) {
> - IoWrite8 ((UINTN)Address, *Uint8Buffer);
> - } else if (Width == SMM_IO_UINT16) {
> - IoWrite16 ((UINTN)Address, *((UINT16 *)Uint8Buffer));
> - } else if (Width == SMM_IO_UINT32) {
> - IoWrite32 ((UINTN)Address, *((UINT32 *)Uint8Buffer));
> - }
> - }
> -
> - return EFI_SUCCESS;
> -}
> +#include "CpuIo2Mm.h"
>
> /**
> - The module Entry Point SmmCpuIoProtocol driver
> + The module Entry Point for Traditional MM CpuIoProtocol driver
>
> @param[in] ImageHandle The firmware allocated handle for the EFI image.
> @param[in] SystemTable A pointer to the EFI System Table.
> @@ -385,23 +28,5 @@ SmmCpuIo2Initialize (
> IN EFI_SYSTEM_TABLE *SystemTable
> )
> {
> - EFI_STATUS Status;
> -
> - //
> - // Copy the SMM CPU I/O Protocol instance into the System Management System Table
> - //
> - CopyMem (&gMmst->MmIo, &mSmmCpuIo2, sizeof (mSmmCpuIo2));
> -
> - //
> - // Install the SMM CPU I/O Protocol into the MM protocol database
> - //
> - Status = gMmst->MmInstallProtocolInterface (
> - &mHandle,
> - &gEfiSmmCpuIo2ProtocolGuid,
> - EFI_NATIVE_INTERFACE,
> - &mSmmCpuIo2
> - );
> - ASSERT_EFI_ERROR (Status);
> -
> - return Status;
> + return CommonCpuIo2Initialize ();
> }
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.h
> similarity index 93%
> rename from UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> rename to UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.h
> index c80261945f71..eda9fbb090cd 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.h
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Mm.h
> @@ -153,4 +153,16 @@ CpuIoServiceWrite (
> IN VOID *Buffer
> );
>
> +/**
> + The module Entry Point SmmCpuIoProtocol driver
> +
> + @retval EFI_SUCCESS The entry point is executed successfully.
> + @retval Other Some error occurs when executing this entry point.
> +
> +**/
> +EFI_STATUS
> +CommonCpuIo2Initialize (
> + VOID
> + );
> +
> #endif
> diff --git a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> index b743a5e0e316..304f0ce83c62 100644
> --- a/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> +++ b/UefiCpuPkg/CpuIo2Smm/CpuIo2Smm.inf
> @@ -24,7 +24,8 @@ [Defines]
>
> [Sources]
> CpuIo2Smm.c
> - CpuIo2Smm.h
> + CpuIo2Mm.c
> + CpuIo2Mm.h
>
> [Packages]
> MdePkg/MdePkg.dec
> --
> 2.30.0.windows.1
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2021-01-29 7:07 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20210126194710.2248-1-kun.q@outlook.com>
2021-01-26 19:46 ` [PATCH v4 04/20] StandaloneMmPkg: StandaloneMmCoreMemoryAllocationLib: Fix compiler warning Kun Qin
2021-01-26 19:46 ` [PATCH v4 05/20] StandaloneMmPkg: StandaloneMmMemLib: Extends support for X64 architecture Kun Qin
2021-01-26 19:46 ` [PATCH v4 06/20] MdeModulePkg: SmmLockBoxSmmLib: Support StandaloneMm for SmmLockBoxLib Kun Qin
2021-01-26 19:46 ` [PATCH v4 07/20] MdeModulePkg: SmmReportStatusCodeLib: ReportStatusCodeLib in StandaloneMm Kun Qin
2021-01-26 19:46 ` [PATCH v4 08/20] MdeModulePkg: StatusCodeHandler: StatusCodeHandler driver " Kun Qin
2021-01-26 19:46 ` [PATCH v4 09/20] MdeModulePkg: FirmwarePerformanceDataTable: Added StandaloneMm support Kun Qin
2021-01-26 19:47 ` [PATCH v4 10/20] MdeModulePkg: ReportStatusCodeRouter: Support StandaloneMm RSC Router Kun Qin
2021-01-26 19:47 ` [PATCH v4 11/20] MdeModulePkg: SmmSmiHandlerProfileLib: Support StandaloneMm Instance Kun Qin
2021-01-27 0:56 ` Wu, Hao A
2021-01-26 19:47 ` [PATCH v4 12/20] MdePkg: UefiDevicePathLib: Support UefiDevicePathLib under StandaloneMm Kun Qin
2021-01-26 19:47 ` [PATCH v4 13/20] PcAtChipsetPkg: AcpiTimerLib: Added StandaloneMm instance of AcpiTimerLib Kun Qin
2021-01-26 19:47 ` [PATCH v4 14/20] SecurityPkg: Tcg2PhysicalPresenceLib: Introduce StandaloneMm instance Kun Qin
2021-01-26 19:47 ` [PATCH v4 15/20] SecurityPkg: Tcg2PpVendorLibNull: Added support for MM_STANDALONE type Kun Qin
2021-01-26 19:47 ` [PATCH v4 16/20] SecurityPkg: Tpm2DeviceLibDTpm: Introduce StandaloneMm instance Kun Qin
2021-01-26 19:47 ` [PATCH v4 17/20] UefiCpuPkg: CpuIo2Smm: Move CpuIo2Smm driver to consume gMmst Kun Qin
2021-01-26 19:47 ` [PATCH v4 18/20] UefiCpuPkg: CpuIo2Smm: Abstract SMM specific functions into separate file Kun Qin
2021-01-29 7:06 ` Ni, Ray
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox