[edk2-platforms][PATCH v5 46/46] TigerlakeSiliconPkg/BasePchSpiCommonLib: Identify flash regions by GUID
Michael Kubacki
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3307 Updates the library to identify flash regions by GUID and internally map the GUID entries to values specific to TigerlakeSiliconPkg. Cc: Rangasai V Chaganty <rangasai.v.chaganty@...> Cc: Nate DeSimone <nathaniel.l.desimone@...> Cc: Heng Luo <heng.luo@...> Signed-off-by: Michael Kubacki <michael.kubacki@...> Reviewed-by: Nate DeSimone <nathaniel.l.desimone@...> --- Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate/BaseSpiComm= onLib/SpiCommon.c | 176 +++++++++++++++++--- Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/IncludePrivate/Library/Spi= CommonLib.h | 16 +- Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate/BaseSpiComm= onLib/BaseSpiCommonLib.inf | 18 +- 3 files changed, 177 insertions(+), 33 deletions(-) diff --git a/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate= /BaseSpiCommonLib/SpiCommon.c b/Silicon/Intel/TigerlakeSiliconPkg/IpBlock= /Spi/LibraryPrivate/BaseSpiCommonLib/SpiCommon.c index 954b349e7c8a..5f372a5b58cb 100644 --- a/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate/BaseSp= iCommonLib/SpiCommon.c +++ b/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate/BaseSp= iCommonLib/SpiCommon.c @@ -2,9 +2,12 @@ PCH SPI Common Driver implements the SPI Host Controller Compatibility= Interface. =20 Copyright (c) 2021, Intel Corporation. All rights reserved.<BR> + Copyright (c) Microsoft Corporation.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include <Uefi/UefiBaseType.h> +#include <Guid/FlashRegion.h> #include <Library/BaseLib.h> #include <Library/IoLib.h> #include <Library/DebugLib.h> @@ -21,6 +24,125 @@ #include <Library/PchPciBdfLib.h> #include <Library/SpiAccessLib.h> =20 +typedef enum { + FlashRegionDescriptor, + FlashRegionBios, + FlashRegionMe, + FlashRegionGbe, + FlashRegionPlatformData, + FlashRegionDer, + FlashRegionSecondaryBios, + FlashRegionMicrocodePatch, + FlashRegionEc, + FlashRegionDeviceExpansion, + FlashRegionIe, + FlashRegion10GbeA, + FlashRegion10GbeB, + FlashRegionAll =3D 16, + FlashRegionMax +} FLASH_REGION_TYPE; + +typedef struct { + EFI_GUID *Guid; + FLASH_REGION_TYPE Type; +} FLASH_REGION_MAPPING; + +FLASH_REGION_MAPPING mFlashRegionTypes[] =3D { + { + &gFlashRegionDescriptorGuid, + FlashRegionDescriptor + }, + { + &gFlashRegionBiosGuid, + FlashRegionBios + }, + { + &gFlashRegionMeGuid, + FlashRegionMe + }, + { + &gFlashRegionGbeGuid, + FlashRegionGbe + }, + { + &gFlashRegionPlatformDataGuid, + FlashRegionPlatformData + }, + { + &gFlashRegionDerGuid, + FlashRegionDer + }, + { + &gFlashRegionSecondaryBiosGuid, + FlashRegionSecondaryBios + }, + { + &gFlashRegionMicrocodePatchGuid, + FlashRegionMicrocodePatch + }, + { + &gFlashRegionEcGuid, + FlashRegionEc + }, + { + &gFlashRegionDeviceExpansionGuid, + FlashRegionDeviceExpansion + }, + { + &gFlashRegionIeGuid, + FlashRegionIe + }, + { + &gFlashRegion10GbeAGuid, + FlashRegion10GbeA + }, + { + &gFlashRegion10GbeBGuid, + FlashRegion10GbeB + }, + { + &gFlashRegionAllGuid, + FlashRegionAll + }, + { + &gFlashRegionMaxGuid, + FlashRegionMax + } +}; + +/** + Returns the type of a flash region given its GUID. + + @param[in] FlashRegionGuid Pointer to the flash region GUID. + @param[out] FlashRegionType Pointer to a buffer that will be set t= o the flash region type value. + + @retval EFI_SUCCESS The flash region type was found = for the given flash region GUID. + @retval EFI_INVALID_PARAMETER A pointer argument passed to the= function is NULL. + @retval EFI_NOT_FOUND The flash region type was not fo= und for the given flash region GUID. + +**/ +EFI_STATUS +GetFlashRegionType ( + IN EFI_GUID *FlashRegionGuid, + OUT FLASH_REGION_TYPE *FlashRegionType + ) +{ + UINTN Index; + + if (FlashRegionGuid =3D=3D NULL || FlashRegionType =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < ARRAY_SIZE (mFlashRegionTypes); Index++) { + if (CompareGuid (mFlashRegionTypes[Index].Guid, FlashRegionGuid)) { + *FlashRegionType =3D mFlashRegionTypes[Index].Type; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + /** Initialize an SPI protocol instance. =20 @@ -179,7 +301,7 @@ SpiProtocolConstructor ( ASSERT (SpiInstance->CpuStrapBaseAddr !=3D 0); =20 if (SpiInstance->CpuStrapBaseAddr !=3D 0x300) { - Status =3D SpiProtocolFlashRead (&(SpiInstance->SpiProtocol), FlashR= egionAll, R_FLASH_UMAP1, sizeof (Data32), (UINT8 *) (&Data32)); + Status =3D SpiProtocolFlashRead (&(SpiInstance->SpiProtocol), &gFlas= hRegionAllGuid, R_FLASH_UMAP1, sizeof (Data32), (UINT8 *) (&Data32)); ASSERT_EFI_ERROR (Status); Mdtba =3D (UINT16)(((Data32 & B_FLASH_UMAP1_MDTBA) >> N_FLASH_UMAP1_= MDTBA) << N_FLASH_UMAP1_MDTBA_REPR); DEBUG ((DEBUG_INFO, "Mdtba : %0x\n", Mdtba)); @@ -312,7 +434,7 @@ WaitForSpiCycleComplete ( This function sends the programmed SPI command to the slave device. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] SpiRegionType The SPI Region type for flash cycle wh= ich is listed in the Descriptor + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] FlashCycleType The Flash SPI cycle type list in HSFC = (Hardware Sequencing Flash Control Register) register @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. @@ -327,7 +449,7 @@ STATIC EFI_STATUS SendSpiCmd ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN FLASH_CYCLE_TYPE FlashCycleType, IN UINT32 Address, IN UINT32 ByteCount, @@ -413,7 +535,7 @@ SendSpiCmd ( } } =20 - Status =3D SpiProtocolGetRegionAddress (This, FlashRegionType, &Hardwa= reSpiAddr, &FlashRegionSize); + Status =3D SpiProtocolGetRegionAddress (This, FlashRegionGuid, &Hardwa= reSpiAddr, &FlashRegionSize); if (EFI_ERROR (Status)) { goto SendSpiCmdEnd; } @@ -626,7 +748,7 @@ SendSpiCmd ( Read data from the flash part. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for flash cycle = which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. @param[out] Buffer The Pointer to caller-allocated buffer= containing the dada received. @@ -640,7 +762,7 @@ EFI_STATUS EFIAPI SpiProtocolFlashRead ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN UINT32 Address, IN UINT32 ByteCount, OUT UINT8 *Buffer @@ -653,7 +775,7 @@ SpiProtocolFlashRead ( // Status =3D SendSpiCmd ( This, - FlashRegionType, + FlashRegionGuid, FlashCycleRead, Address, ByteCount, @@ -666,7 +788,7 @@ SpiProtocolFlashRead ( Write data to the flash part. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for flash cycle = which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. @param[in] Buffer Pointer to caller-allocated buffer con= taining the data sent during the SPI cycle. @@ -679,7 +801,7 @@ EFI_STATUS EFIAPI SpiProtocolFlashWrite ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN UINT32 Address, IN UINT32 ByteCount, IN UINT8 *Buffer @@ -692,7 +814,7 @@ SpiProtocolFlashWrite ( // Status =3D SendSpiCmd ( This, - FlashRegionType, + FlashRegionGuid, FlashCycleWrite, Address, ByteCount, @@ -705,7 +827,7 @@ SpiProtocolFlashWrite ( Erase some area on the flash part. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for flash cycle = which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. =20 @@ -717,7 +839,7 @@ EFI_STATUS EFIAPI SpiProtocolFlashErase ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN UINT32 Address, IN UINT32 ByteCount ) @@ -729,7 +851,7 @@ SpiProtocolFlashErase ( // Status =3D SendSpiCmd ( This, - FlashRegionType, + FlashRegionGuid, FlashCycleErase, Address, ByteCount, @@ -790,7 +912,7 @@ SpiProtocolFlashReadSfdp ( // Status =3D SendSpiCmd ( This, - FlashRegionAll, + &gFlashRegionAllGuid, FlashCycleReadSfdp, FlashAddress, ByteCount, @@ -849,7 +971,7 @@ SpiProtocolFlashReadJedecId ( // Status =3D SendSpiCmd ( This, - FlashRegionAll, + &gFlashRegionAllGuid, FlashCycleReadJedecId, Address, ByteCount, @@ -890,7 +1012,7 @@ SpiProtocolFlashWriteStatus ( // Status =3D SendSpiCmd ( This, - FlashRegionAll, + &gFlashRegionAllGuid, FlashCycleWriteStatus, 0, ByteCount, @@ -931,7 +1053,7 @@ SpiProtocolFlashReadStatus ( // Status =3D SendSpiCmd ( This, - FlashRegionAll, + &gFlashRegionAllGuid, FlashCycleReadStatus, 0, ByteCount, @@ -944,7 +1066,7 @@ SpiProtocolFlashReadStatus ( Get the SPI region base and size, based on the enum type =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for for the base= address which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for the base add= ress which corresponds to the type in the descriptor. @param[out] BaseAddress The Flash Linear Address for the Regio= n 'n' Base @param[out] RegionSize The size for the Region 'n' =20 @@ -956,17 +1078,23 @@ EFI_STATUS EFIAPI SpiProtocolGetRegionAddress ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, OUT UINT32 *BaseAddress, OUT UINT32 *RegionSize ) { - SPI_INSTANCE *SpiInstance; - UINTN PchSpiBar0; - UINT32 ReadValue; + EFI_STATUS Status; + FLASH_REGION_TYPE FlashRegionType; + SPI_INSTANCE *SpiInstance; + UINTN PchSpiBar0; + UINT32 ReadValue; =20 SpiInstance =3D SPI_INSTANCE_FROM_SPIPROTOCOL (This); =20 + Status =3D GetFlashRegionType (FlashRegionGuid, &FlashRegionType); + if (EFI_ERROR (Status)) { + return EFI_INVALID_PARAMETER; + } if (FlashRegionType >=3D FlashRegionMax) { return EFI_INVALID_PARAMETER; } @@ -1047,7 +1175,7 @@ SpiProtocolReadPchSoftStrap ( // Status =3D SendSpiCmd ( This, - FlashRegionDescriptor, + &gFlashRegionDescriptorGuid, FlashCycleRead, StrapFlashAddr, ByteCount, @@ -1105,7 +1233,7 @@ SpiProtocolReadCpuSoftStrap ( // Status =3D SendSpiCmd ( This, - FlashRegionDescriptor, + &gFlashRegionDescriptorGuid, FlashCycleRead, StrapFlashAddr, ByteCount, diff --git a/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/IncludePrivate= /Library/SpiCommonLib.h b/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/I= ncludePrivate/Library/SpiCommonLib.h index 3290f7712280..3038ae749ef2 100644 --- a/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/IncludePrivate/Librar= y/SpiCommonLib.h +++ b/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/IncludePrivate/Librar= y/SpiCommonLib.h @@ -146,7 +146,7 @@ IsSpiFlashWriteGranted ( Read data from the flash part. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for flash cycle = which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. @param[out] Buffer The Pointer to caller-allocated buffer= containing the dada received. @@ -160,7 +160,7 @@ EFI_STATUS EFIAPI SpiProtocolFlashRead ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN UINT32 Address, IN UINT32 ByteCount, OUT UINT8 *Buffer @@ -170,7 +170,7 @@ SpiProtocolFlashRead ( Write data to the flash part. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for flash cycle = which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. @param[in] Buffer Pointer to caller-allocated buffer con= taining the data sent during the SPI cycle. @@ -183,7 +183,7 @@ EFI_STATUS EFIAPI SpiProtocolFlashWrite ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN UINT32 Address, IN UINT32 ByteCount, IN UINT8 *Buffer @@ -193,7 +193,7 @@ SpiProtocolFlashWrite ( Erase some area on the flash part. =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for flash cycle = which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for flash cycle = which corresponds to the type in the descriptor. @param[in] Address The Flash Linear Address must fall wit= hin a region for which BIOS has access permissions. @param[in] ByteCount Number of bytes in the data portion of= the SPI cycle. =20 @@ -205,7 +205,7 @@ EFI_STATUS EFIAPI SpiProtocolFlashErase ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, IN UINT32 Address, IN UINT32 ByteCount ); @@ -298,7 +298,7 @@ SpiProtocolFlashReadStatus ( Get the SPI region base and size, based on the enum type =20 @param[in] This Pointer to the PCH_SPI_PROTOCOL instan= ce. - @param[in] FlashRegionType The Flash Region type for for the base= address which is listed in the Descriptor. + @param[in] FlashRegionGuid The Flash Region GUID for the base add= ress which corresponds to the type in the descriptor. @param[out] BaseAddress The Flash Linear Address for the Regio= n 'n' Base @param[out] RegionSize The size for the Region 'n' =20 @@ -310,7 +310,7 @@ EFI_STATUS EFIAPI SpiProtocolGetRegionAddress ( IN PCH_SPI_PROTOCOL *This, - IN FLASH_REGION_TYPE FlashRegionType, + IN EFI_GUID *FlashRegionGuid, OUT UINT32 *BaseAddress, OUT UINT32 *RegionSize ); diff --git a/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate= /BaseSpiCommonLib/BaseSpiCommonLib.inf b/Silicon/Intel/TigerlakeSiliconPk= g/IpBlock/Spi/LibraryPrivate/BaseSpiCommonLib/BaseSpiCommonLib.inf index 2686dff41e25..4981276e13e8 100644 --- a/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate/BaseSp= iCommonLib/BaseSpiCommonLib.inf +++ b/Silicon/Intel/TigerlakeSiliconPkg/IpBlock/Spi/LibraryPrivate/BaseSp= iCommonLib/BaseSpiCommonLib.inf @@ -2,6 +2,7 @@ # Component description file for the PchSpiCommonLib # # Copyright (c) 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) Microsoft Corporation.<BR> # SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -29,4 +30,19 @@ [LibraryClasses] PchPciBdfLib SpiAccessLib =20 -[Pcd] +[Guids] + gFlashRegionDescriptorGuid + gFlashRegionBiosGuid + gFlashRegionMeGuid + gFlashRegionGbeGuid + gFlashRegionPlatformDataGuid + gFlashRegionDerGuid + gFlashRegionSecondaryBiosGuid + gFlashRegionMicrocodePatchGuid + gFlashRegionEcGuid + gFlashRegionDeviceExpansionGuid + gFlashRegionIeGuid + gFlashRegion10GbeAGuid + gFlashRegion10GbeBGuid + gFlashRegionAllGuid + gFlashRegionMaxGuid --=20 2.28.0.windows.1 |
|