Re: [edk2-devel] [PATCH v6 31/52] TigerlakeOpenBoardPkg: Remove SmmSpiFlashCommonLib

2021-10-28 Thread Heng Luo
Reviewed-by: Heng Luo 

> -Original Message-
> From: mikub...@linux.microsoft.com 
> Sent: Friday, October 29, 2021 4:43 AM
> To: devel@edk2.groups.io
> Cc: Chaganty, Rangasai V ; Desimone,
> Nathaniel L ; Luo, Heng 
> Subject: [PATCH v6 31/52] TigerlakeOpenBoardPkg: Remove
> SmmSpiFlashCommonLib
> 
> From: Michael Kubacki 
> 
> REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3307
> 
> The library has been consolidated with instances in other Intel silicon 
> packages
> as a single instance in IntelSiliconPkg
> 
> Cc: Sai Chaganty 
> Cc: Nate DeSimone 
> Cc: Heng Luo 
> Signed-off-by: Michael Kubacki 
> Reviewed-by: Nate DeSimone 
> Reviewed-by: Sai Chaganty 
> ---
> 
> Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFla
> shCommon.c | 210 
> 
> Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFla
> shCommonSmmLib.c   |  58 --
> 
> Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SmmS
> piFlashCommonLib.inf |  49 -
>  3 files changed, 317 deletions(-)
> 
> diff --git
> a/Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiF
> lashCommon.c
> b/Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiF
> lashCommon.c
> deleted file mode 100644
> index f86896dd1ff5..
> ---
> a/Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiF
> lashCommon.c
> +++ /dev/null
> @@ -1,210 +0,0 @@
> -/** @file
> -  Wrap EFI_SPI_PROTOCOL to provide some library level interfaces
> -  for module use.
> -
> -  Copyright (c) 2021, Intel Corporation. All rights reserved.
> -  SPDX-License-Identifier: BSD-2-Clause-Patent -**/
> -
> -#include 
> -#include 
> -#include 
> -
> -PCH_SPI_PROTOCOL   *mSpiProtocol;
> -
> -//
> -// Variables for boottime and runtime usage.
> -//
> -UINTN mBiosAreaBaseAddress = 0;
> -UINTN mBiosSize= 0;
> -UINTN mBiosOffset  = 0;
> -
> -/**
> -  Enable block protection on the Serial Flash device.
> -
> -  @retval EFI_SUCCESS   Opertion is successful.
> -  @retval EFI_DEVICE_ERROR  If there is any device errors.
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -SpiFlashLock (
> -  VOID
> -  )
> -{
> -  return EFI_SUCCESS;
> -}
> -
> -/**
> -  Read NumBytes bytes of data from the address specified by
> -  PAddress into Buffer.
> -
> -  @param[in]  Address   The starting physical address of the read.
> -  @param[in,out]  NumBytes  On input, the number of bytes to read. On
> output, the number
> -of bytes actually read.
> -  @param[out] BufferThe destination data buffer for the read.
> -
> -  @retval EFI_SUCCESS   Operation is successful.
> -  @retval EFI_DEVICE_ERROR  If there is any device errors.
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -SpiFlashRead (
> -  IN UINTNAddress,
> -  IN OUT UINT32   *NumBytes,
> - OUT UINT8*Buffer
> -  )
> -{
> -  ASSERT ((NumBytes != NULL) && (Buffer != NULL));
> -  if ((NumBytes == NULL) || (Buffer == NULL)) {
> -return EFI_INVALID_PARAMETER;
> -  }
> -
> -  //
> -  // This function is implemented specifically for those platforms
> -  // at which the SPI device is memory mapped for read. So this
> -  // function just do a memory copy for Spi Flash Read.
> -  //
> -  CopyMem (Buffer, (VOID *) Address, *NumBytes);
> -
> -  return EFI_SUCCESS;
> -}
> -
> -/**
> -  Write NumBytes bytes of data from Buffer to the address specified by
> -  PAddresss.
> -
> -  @param[in]  Address The starting physical address of the write.
> -  @param[in,out]  NumBytesOn input, the number of bytes to write. On
> output,
> -  the actual number of bytes written.
> -  @param[in]  Buffer  The source data buffer for the write.
> -
> -  @retval EFI_SUCCESSOperation is successful.
> -  @retval EFI_DEVICE_ERROR   If there is any device errors.
> -  @retval EFI_INVALID_PARAMETER  Invalid parameter.
> -
> -**/
> -EFI_STATUS
> -EFIAPI
> -SpiFlashWrite (
> -  IN UINTN  Address,
> -  IN OUT UINT32 *NumBytes,
> -  IN UINT8  *Buffer
> -  )
> -{
> -  EFI_STATUSStatus;
> -  UINTN Offset;
> -  UINT32Length;
> -  UINT32RemainingBytes;
> -
> -  ASSERT ((NumBytes != NULL) && (Buffer != NULL));
> -  if ((NumBytes == NULL) || (Buffer == NULL)) {
> -return EFI_INVALID_PARAMETER;
> -  }
> -
> -  ASSERT (Address >= mBiosAreaBaseAddress);
> -  if (Address < mBiosAreaBaseAddress) {
> -return EFI_INVALID_PARAMETER;
> -  }
> -
> -  Offset = Address - mBiosAreaBaseAddress;
> -
> -  ASSERT ((*NumBytes + Offset) <= mBiosSize);
> -  if ((*NumBytes + Offset) > mBiosSize) {
> -return EFI_INVALID_PARAMETER;
> -  }
> -
> -  Status = EFI_SUCCESS;
> -  

[edk2-devel] [PATCH v6 31/52] TigerlakeOpenBoardPkg: Remove SmmSpiFlashCommonLib

2021-10-28 Thread Michael Kubacki
From: Michael Kubacki 

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3307

The library has been consolidated with instances in other Intel
silicon packages as a single instance in IntelSiliconPkg

Cc: Sai Chaganty 
Cc: Nate DeSimone 
Cc: Heng Luo 
Signed-off-by: Michael Kubacki 
Reviewed-by: Nate DeSimone 
Reviewed-by: Sai Chaganty 
---
 
Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFlashCommon.c
 | 210 
 
Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFlashCommonSmmLib.c
   |  58 --
 
Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SmmSpiFlashCommonLib.inf
 |  49 -
 3 files changed, 317 deletions(-)

diff --git 
a/Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFlashCommon.c
 
b/Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFlashCommon.c
deleted file mode 100644
index f86896dd1ff5..
--- 
a/Platform/Intel/TigerlakeOpenBoardPkg/Library/SmmSpiFlashCommonLib/SpiFlashCommon.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/** @file
-  Wrap EFI_SPI_PROTOCOL to provide some library level interfaces
-  for module use.
-
-  Copyright (c) 2021, Intel Corporation. All rights reserved.
-  SPDX-License-Identifier: BSD-2-Clause-Patent
-**/
-
-#include 
-#include 
-#include 
-
-PCH_SPI_PROTOCOL   *mSpiProtocol;
-
-//
-// Variables for boottime and runtime usage.
-//
-UINTN mBiosAreaBaseAddress = 0;
-UINTN mBiosSize= 0;
-UINTN mBiosOffset  = 0;
-
-/**
-  Enable block protection on the Serial Flash device.
-
-  @retval EFI_SUCCESS   Opertion is successful.
-  @retval EFI_DEVICE_ERROR  If there is any device errors.
-
-**/
-EFI_STATUS
-EFIAPI
-SpiFlashLock (
-  VOID
-  )
-{
-  return EFI_SUCCESS;
-}
-
-/**
-  Read NumBytes bytes of data from the address specified by
-  PAddress into Buffer.
-
-  @param[in]  Address   The starting physical address of the read.
-  @param[in,out]  NumBytes  On input, the number of bytes to read. On 
output, the number
-of bytes actually read.
-  @param[out] BufferThe destination data buffer for the read.
-
-  @retval EFI_SUCCESS   Operation is successful.
-  @retval EFI_DEVICE_ERROR  If there is any device errors.
-
-**/
-EFI_STATUS
-EFIAPI
-SpiFlashRead (
-  IN UINTNAddress,
-  IN OUT UINT32   *NumBytes,
- OUT UINT8*Buffer
-  )
-{
-  ASSERT ((NumBytes != NULL) && (Buffer != NULL));
-  if ((NumBytes == NULL) || (Buffer == NULL)) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  //
-  // This function is implemented specifically for those platforms
-  // at which the SPI device is memory mapped for read. So this
-  // function just do a memory copy for Spi Flash Read.
-  //
-  CopyMem (Buffer, (VOID *) Address, *NumBytes);
-
-  return EFI_SUCCESS;
-}
-
-/**
-  Write NumBytes bytes of data from Buffer to the address specified by
-  PAddresss.
-
-  @param[in]  Address The starting physical address of the write.
-  @param[in,out]  NumBytesOn input, the number of bytes to write. On 
output,
-  the actual number of bytes written.
-  @param[in]  Buffer  The source data buffer for the write.
-
-  @retval EFI_SUCCESSOperation is successful.
-  @retval EFI_DEVICE_ERROR   If there is any device errors.
-  @retval EFI_INVALID_PARAMETER  Invalid parameter.
-
-**/
-EFI_STATUS
-EFIAPI
-SpiFlashWrite (
-  IN UINTN  Address,
-  IN OUT UINT32 *NumBytes,
-  IN UINT8  *Buffer
-  )
-{
-  EFI_STATUSStatus;
-  UINTN Offset;
-  UINT32Length;
-  UINT32RemainingBytes;
-
-  ASSERT ((NumBytes != NULL) && (Buffer != NULL));
-  if ((NumBytes == NULL) || (Buffer == NULL)) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  ASSERT (Address >= mBiosAreaBaseAddress);
-  if (Address < mBiosAreaBaseAddress) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  Offset = Address - mBiosAreaBaseAddress;
-
-  ASSERT ((*NumBytes + Offset) <= mBiosSize);
-  if ((*NumBytes + Offset) > mBiosSize) {
-return EFI_INVALID_PARAMETER;
-  }
-
-  Status = EFI_SUCCESS;
-  RemainingBytes = *NumBytes;
-
-
-  while (RemainingBytes > 0) {
-if (RemainingBytes > SECTOR_SIZE_4KB) {
-  Length = SECTOR_SIZE_4KB;
-} else {
-  Length = RemainingBytes;
-}
-Status = mSpiProtocol->FlashWrite (
- mSpiProtocol,
- FlashRegionBios,
- (UINT32) Offset,
- Length,
- Buffer
- );
-if (EFI_ERROR (Status)) {
-  break;
-}
-RemainingBytes -= Length;
-Offset += Length;
-Buffer += Length;
-  }
-
-