Re: [edk2] [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
Hi Ard, Some minor feedback added inline. On 2019/1/4 2:28, Ard Biesheuvel wrote: In preparation of providing a standalone MM based FTW driver, move the existing SMM driver to the new MM services table, and factor out some pieces that are specific to the traditional driver, mainly related to the use of UEFI boot services, which are not accessible to standalone MM drivers. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/MdeModulePkg.dsc | 1 + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h | 22 - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c | 31 +++ MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c | 54 +-- MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf | 5 +- MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h | 31 +++ MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c | 1 + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c | 94 MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c | 10 +-- 9 files changed, 205 insertions(+), 44 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 5d042be3a862..ef3c144ed524 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -153,6 +153,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf + MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h index 844cf3bee04d..8d146264b129 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h @@ -31,7 +31,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #include // @@ -766,4 +765,25 @@ WriteWorkSpaceData ( IN UINT8 *Buffer ); +/** + Internal implementation of CRC32. Depending on the execution context + (traditional SMM or DXE vs standalone MM), this function is implemented + via a call to the CalculateCrc32 () boot service, or via a library + call. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc32The 32-bit CRC was computed for the data buffer. + +**/ +UINT32 +FtwCalculateCrc32 ( + IN VOID *Buffer, + IN UINTNLength + ); + #endif diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c index 094e40f9d86c..24e507104bbe 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c @@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ +#include #include "FaultTolerantWrite.h" EFI_EVENT mFvbRegistration = NULL; @@ -250,3 +251,33 @@ FaultTolerantWriteInitialize ( return EFI_SUCCESS; } + +/** + Internal implementation of CRC32. Depending on the execution context + (traditional SMM or DXE vs standalone MM), this function is implemented + via a call to the CalculateCrc32 () boot service, or via a library + call. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc32The 32-bit CRC was computed for the data buffer. + +**/ +UINT32 +FtwCalculateCrc32 ( + IN VOID *Buffer, + IN UINTNLength + ) +{ + EFI_STATUSStatus; + UINT32ReturnValue; + + Status = gBS->CalculateCrc32 (Buffer, Length, ); + ASSERT_EFI_ERROR (Status); + + return ReturnValue; +} diff --git
Re: [edk2] [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
Reviewed-by: Jian J Wang > -Original Message- > From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org] > Sent: Friday, January 04, 2019 2:28 AM > To: edk2-devel@lists.01.org > Cc: Ard Biesheuvel ; Laszlo Ersek > ; Leif Lindholm ; Kinney, > Michael D ; Gao, Liming ; > Wang, Jian J ; Wu, Hao A ; > Jagadeesh Ujja ; Achin Gupta > ; Thomas Panakamattam Abraham > ; Sami Mujawar > Subject: [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot > service accesses > > In preparation of providing a standalone MM based FTW driver, move > the existing SMM driver to the new MM services table, and factor out > some pieces that are specific to the traditional driver, mainly > related to the use of UEFI boot services, which are not accessible > to standalone MM drivers. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > --- > MdeModulePkg/MdeModulePkg.dsc > | 1 + > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > | 22 - > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > | 31 +++ > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c > | 54 +-- > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf > | 5 +- > > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCom > mon.h | 31 +++ > > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c > | 1 + > > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditiona > lMm.c | 94 > MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c > | 10 +-- > 9 files changed, 205 insertions(+), 44 deletions(-) > > diff --git a/MdeModulePkg/MdeModulePkg.dsc > b/MdeModulePkg/MdeModulePkg.dsc > index 5d042be3a862..ef3c144ed524 100644 > --- a/MdeModulePkg/MdeModulePkg.dsc > +++ b/MdeModulePkg/MdeModulePkg.dsc > @@ -153,6 +153,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] >DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf > > MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemory > AllocationLib.inf > > SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTable > Lib.inf > + > MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib > .inf >LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf >SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf > > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > index 844cf3bee04d..8d146264b129 100644 > --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h > @@ -31,7 +31,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > #include > #include > #include > -#include > #include > > // > @@ -766,4 +765,25 @@ WriteWorkSpaceData ( >IN UINT8 *Buffer >); > > +/** > + Internal implementation of CRC32. Depending on the execution context > + (traditional SMM or DXE vs standalone MM), this function is implemented > + via a call to the CalculateCrc32 () boot service, or via a library > + call. > + > + If Buffer is NULL, then ASSERT(). > + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). > + > + @param[in] Buffer A pointer to the buffer on which the 32-bit CRC > is to be > computed. > + @param[in] Length The number of bytes in the buffer Data. > + > + @retval Crc32The 32-bit CRC was computed for the data buffer. > + > +**/ > +UINT32 > +FtwCalculateCrc32 ( > + IN VOID *Buffer, > + IN UINTNLength > + ); > + > #endif > diff --git > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > index 094e40f9d86c..24e507104bbe 100644 > --- > a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > +++ > b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c > @@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > > **/ > > +#include > #include "FaultTolerantWrite.h" > EFI_EVENT mFvbRegistration = NULL; > > @@ -250,3 +251,33 @@ FaultTolerantWriteInitialize ( > >return EFI_SUCCESS; > } > + > +/** > + Internal implementation of CRC32. Depending on the execution context > + (traditional SMM or DXE vs standalone MM), this function is implemented > + via a call to the CalculateCrc32 () boot service, or via a library > + call. > + > + If Buffer is NULL, then ASSERT(). > + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). > + > + @param[in] Buffer A pointer to the buffer on which the
[edk2] [PATCH 3/6] MdeModulePkg/FaultTolerantWriteDxe: factor out boot service accesses
In preparation of providing a standalone MM based FTW driver, move the existing SMM driver to the new MM services table, and factor out some pieces that are specific to the traditional driver, mainly related to the use of UEFI boot services, which are not accessible to standalone MM drivers. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/MdeModulePkg.dsc | 1 + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h | 22 - MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c | 31 +++ MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c | 54 +-- MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf | 5 +- MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmCommon.h | 31 +++ MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmmDxe.c | 1 + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteTraditionalMm.c | 94 MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c | 10 +-- 9 files changed, 205 insertions(+), 44 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 5d042be3a862..ef3c144ed524 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -153,6 +153,7 @@ [LibraryClasses.common.DXE_SMM_DRIVER] DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf + MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h index 844cf3bee04d..8d146264b129 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h @@ -31,7 +31,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include -#include #include // @@ -766,4 +765,25 @@ WriteWorkSpaceData ( IN UINT8 *Buffer ); +/** + Internal implementation of CRC32. Depending on the execution context + (traditional SMM or DXE vs standalone MM), this function is implemented + via a call to the CalculateCrc32 () boot service, or via a library + call. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc32The 32-bit CRC was computed for the data buffer. + +**/ +UINT32 +FtwCalculateCrc32 ( + IN VOID *Buffer, + IN UINTNLength + ); + #endif diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c index 094e40f9d86c..24e507104bbe 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.c @@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ +#include #include "FaultTolerantWrite.h" EFI_EVENT mFvbRegistration = NULL; @@ -250,3 +251,33 @@ FaultTolerantWriteInitialize ( return EFI_SUCCESS; } + +/** + Internal implementation of CRC32. Depending on the execution context + (traditional SMM or DXE vs standalone MM), this function is implemented + via a call to the CalculateCrc32 () boot service, or via a library + call. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc32The 32-bit CRC was computed for the data buffer. + +**/ +UINT32 +FtwCalculateCrc32 ( + IN VOID *Buffer, + IN UINTNLength + ) +{ + EFI_STATUSStatus; + UINT32ReturnValue; + + Status = gBS->CalculateCrc32 (Buffer, Length, ); + ASSERT_EFI_ERROR (Status); + + return ReturnValue; +} diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.c index