* [PATCH 0/3] Update edk2-platform repo to consume MicrocodeLib @ 2021-04-02 6:00 Ni, Ray 2021-04-02 6:00 ` [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib Ni, Ray ` (2 more replies) 0 siblings, 3 replies; 8+ messages in thread From: Ni, Ray @ 2021-04-02 6:00 UTC (permalink / raw) To: devel Ray Ni (3): MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: Consume MicrocodeLib IntelSiliconPkg/ShadowMicrocodePei: Consume MicrocodeLib .../Include/Dsc/CoreCommonLib.dsc | 3 +- .../Vlv2TbltDevicePkg/PlatformPkgIA32.dsc | 1 + .../Vlv2TbltDevicePkg/PlatformPkgX64.dsc | 1 + .../ShadowMicrocode/ShadowMicrocodePei.c | 155 ++---------------- .../ShadowMicrocode/ShadowMicrocodePei.inf | 3 +- 5 files changed, 17 insertions(+), 146 deletions(-) -- 2.27.0.windows.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib 2021-04-02 6:00 [PATCH 0/3] Update edk2-platform repo to consume MicrocodeLib Ni, Ray @ 2021-04-02 6:00 ` Ni, Ray 2021-04-08 13:59 ` [edk2-devel] " Chiu, Chasel 2021-04-02 6:00 ` [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: " Ni, Ray 2021-04-02 6:00 ` [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: " Ni, Ray 2 siblings, 1 reply; 8+ messages in thread From: Ni, Ray @ 2021-04-02 6:00 UTC (permalink / raw) To: devel; +Cc: Chasel Chiu, Nate DeSimone, Liming Gao, Eric Dong Signed-off-by: Ray Ni <ray.ni@intel.com> Cc: Chasel Chiu <chasel.chiu@intel.com> Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> Cc: Liming Gao <gaoliming@byosoft.com.cn> Cc: Eric Dong <eric.dong@intel.com> --- Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc index cf2940cf02..61d47109a6 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc @@ -106,6 +106,7 @@ MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf # # Platform @@ -165,4 +166,4 @@ SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.inf - VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf \ No newline at end of file + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf -- 2.27.0.windows.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib 2021-04-02 6:00 ` [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib Ni, Ray @ 2021-04-08 13:59 ` Chiu, Chasel 0 siblings, 0 replies; 8+ messages in thread From: Chiu, Chasel @ 2021-04-08 13:59 UTC (permalink / raw) To: devel@edk2.groups.io, Ni, Ray Cc: Desimone, Nathaniel L, Liming Gao, Dong, Eric Reviewed-by: Chasel Chiu <chasel.chiu@intel.com> > -----Original Message----- > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray > Sent: Friday, April 2, 2021 2:00 PM > To: devel@edk2.groups.io > Cc: Chiu, Chasel <chasel.chiu@intel.com>; Desimone, Nathaniel L > <nathaniel.l.desimone@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; > Dong, Eric <eric.dong@intel.com> > Subject: [edk2-devel] [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: > Consume MicrocodeLib > > Signed-off-by: Ray Ni <ray.ni@intel.com> > Cc: Chasel Chiu <chasel.chiu@intel.com> > Cc: Nate DeSimone <nathaniel.l.desimone@intel.com> > Cc: Liming Gao <gaoliming@byosoft.com.cn> > Cc: Eric Dong <eric.dong@intel.com> > --- > Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc > b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc > index cf2940cf02..61d47109a6 100644 > --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc > +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc > @@ -106,6 +106,7 @@ > MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf > LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf > SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeatures > Lib.inf+ MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf # > # Platform@@ -165,4 +166,4 @@ > SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf > VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyLib.in > f- > VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Variab > lePolicyHelperLib.inf\ No newline at end of file > + > + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V > + ariablePolicyHelperLib.inf-- > 2.27.0.windows.1 > > > > -=-=-=-=-=-= > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#73643): https://edk2.groups.io/g/devel/message/73643 > Mute This Topic: https://groups.io/mt/81796844/1777047 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [chasel.chiu@intel.com] -=- > =-=-=-=-= > ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: Consume MicrocodeLib 2021-04-02 6:00 [PATCH 0/3] Update edk2-platform repo to consume MicrocodeLib Ni, Ray 2021-04-02 6:00 ` [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib Ni, Ray @ 2021-04-02 6:00 ` Ni, Ray 2021-04-09 0:39 ` [edk2-devel] " Sun, Zailiang 2021-04-02 6:00 ` [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: " Ni, Ray 2 siblings, 1 reply; 8+ messages in thread From: Ni, Ray @ 2021-04-02 6:00 UTC (permalink / raw) To: devel; +Cc: Zailiang Sun, Yi Qian Signed-off-by: Ray Ni <ray.ni@intel.com> Cc: Zailiang Sun <zailiang.sun@intel.com> Cc: Yi Qian <yi.qian@intel.com> --- Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc | 1 + Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc | 1 + 2 files changed, 2 insertions(+) diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc index bdf69b7e9a..8516da582b 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc @@ -164,6 +164,7 @@ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf # # ICH diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc index 5f26bc02dd..a608233166 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc @@ -166,6 +166,7 @@ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf # # ICH -- 2.27.0.windows.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [edk2-devel] [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: Consume MicrocodeLib 2021-04-02 6:00 ` [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: " Ni, Ray @ 2021-04-09 0:39 ` Sun, Zailiang 0 siblings, 0 replies; 8+ messages in thread From: Sun, Zailiang @ 2021-04-09 0:39 UTC (permalink / raw) To: devel@edk2.groups.io, Ni, Ray; +Cc: Qian, Yi Reviewed-by: Zailiang Sun <zailiang.sun@intel.com> -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Ni, Ray Sent: April 2, 2021 2:00 PM To: devel@edk2.groups.io Cc: Sun, Zailiang <zailiang.sun@intel.com>; Qian, Yi <yi.qian@intel.com> Subject: [edk2-devel] [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: Consume MicrocodeLib Signed-off-by: Ray Ni <ray.ni@intel.com> Cc: Zailiang Sun <zailiang.sun@intel.com> Cc: Yi Qian <yi.qian@intel.com> --- Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc | 1 + Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc | 1 + 2 files changed, 2 insertions(+) diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc index bdf69b7e9a..8516da582b 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc @@ -164,6 +164,7 @@ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf+ MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf # # ICHdiff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc index 5f26bc02dd..a608233166 100644 --- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc +++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc @@ -166,6 +166,7 @@ CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf+ MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf # # ICH-- 2.27.0.windows.1 -=-=-=-=-=-= Groups.io Links: You receive all messages sent to this group. View/Reply Online (#73644): https://edk2.groups.io/g/devel/message/73644 Mute This Topic: https://groups.io/mt/81796845/1777111 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [zailiang.sun@intel.com] -=-=-=-=-=-= ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: Consume MicrocodeLib 2021-04-02 6:00 [PATCH 0/3] Update edk2-platform repo to consume MicrocodeLib Ni, Ray 2021-04-02 6:00 ` [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib Ni, Ray 2021-04-02 6:00 ` [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: " Ni, Ray @ 2021-04-02 6:00 ` Ni, Ray 2021-04-08 6:43 ` Siyuan, Fu 2021-04-08 16:08 ` Chaganty, Rangasai V 2 siblings, 2 replies; 8+ messages in thread From: Ni, Ray @ 2021-04-02 6:00 UTC (permalink / raw) To: devel; +Cc: Rangasai V Chaganty, Siyuan Fu Signed-off-by: Ray Ni <ray.ni@intel.com> Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com> --- .../ShadowMicrocode/ShadowMicrocodePei.c | 155 ++---------------- .../ShadowMicrocode/ShadowMicrocodePei.inf | 3 +- 2 files changed, 13 insertions(+), 145 deletions(-) diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c index 98a7aed697..4e4b69a0ca 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c @@ -1,7 +1,7 @@ /** @file FIT based microcode shadow PEIM. -Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> #include <Library/MemoryAllocationLib.h> +#include <Library/MicrocodeLib.h> #include <IndustryStandard/FirmwareInterfaceTable.h> #include <Register/Intel/Microcode.h> #include <Register/Intel/Cpuid.h> @@ -70,118 +71,6 @@ EFI_PEI_PPI_DESCRIPTOR mPeiShadowMicrocodePpiList[] = { } }; -/** - Determine if a microcode patch matchs the specific processor signature and flag. - - @param[in] CpuIdCount Number of elements in MicrocodeCpuId array. - @param[in] MicrocodeCpuId A pointer to an array of EDKII_PEI_MICROCODE_CPU_ID - structures. - @param[in] ProcessorSignature The processor signature field value - supported by a microcode patch. - @param[in] ProcessorFlags The prcessor flags field value supported by - a microcode patch. - - @retval TRUE The specified microcode patch will be loaded. - @retval FALSE The specified microcode patch will not be loaded. -**/ -BOOLEAN -IsProcessorMatchedMicrocodePatch ( - IN UINTN CpuIdCount, - IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId, - IN UINT32 ProcessorSignature, - IN UINT32 ProcessorFlags - ) -{ - UINTN Index; - - for (Index = 0; Index < CpuIdCount; Index++) { - if ((ProcessorSignature == MicrocodeCpuId[Index].ProcessorSignature) && - (ProcessorFlags & (1 << MicrocodeCpuId[Index].PlatformId)) != 0) { - return TRUE; - } - } - - return FALSE; -} - -/** - Check the 'ProcessorSignature' and 'ProcessorFlags' of the microcode - patch header with the CPUID and PlatformID of the processors within - system to decide if it will be copied into memory. - - @param[in] CpuIdCount Number of elements in MicrocodeCpuId array. - @param[in] MicrocodeCpuId A pointer to an array of EDKII_PEI_MICROCODE_CPU_ID - structures. - @param[in] MicrocodeEntryPoint The pointer to the microcode patch header. - - @retval TRUE The specified microcode patch need to be loaded. - @retval FALSE The specified microcode patch dosen't need to be loaded. -**/ -BOOLEAN -IsMicrocodePatchNeedLoad ( - IN UINTN CpuIdCount, - IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId, - CPU_MICROCODE_HEADER *MicrocodeEntryPoint - ) -{ - BOOLEAN NeedLoad; - UINTN DataSize; - UINTN TotalSize; - CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader; - UINT32 ExtendedTableCount; - CPU_MICROCODE_EXTENDED_TABLE *ExtendedTable; - UINTN Index; - - if (FeaturePcdGet (PcdShadowAllMicrocode)) { - return TRUE; - } - - // - // Check the 'ProcessorSignature' and 'ProcessorFlags' in microcode patch header. - // - NeedLoad = IsProcessorMatchedMicrocodePatch ( - CpuIdCount, - MicrocodeCpuId, - MicrocodeEntryPoint->ProcessorSignature.Uint32, - MicrocodeEntryPoint->ProcessorFlags - ); - - // - // If the Extended Signature Table exists, check if the processor is in the - // support list - // - DataSize = MicrocodeEntryPoint->DataSize; - TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize; - if ((!NeedLoad) && (DataSize != 0) && - (TotalSize - DataSize > sizeof (CPU_MICROCODE_HEADER) + - sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER))) { - ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *) ((UINT8 *) (MicrocodeEntryPoint) - + DataSize + sizeof (CPU_MICROCODE_HEADER)); - ExtendedTableCount = ExtendedTableHeader->ExtendedSignatureCount; - ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *) (ExtendedTableHeader + 1); - - for (Index = 0; Index < ExtendedTableCount; Index ++) { - // - // Check the 'ProcessorSignature' and 'ProcessorFlag' of the Extended - // Signature Table entry with the CPUID and PlatformID of the processors - // within system to decide if it will be copied into memory - // - NeedLoad = IsProcessorMatchedMicrocodePatch ( - CpuIdCount, - MicrocodeCpuId, - ExtendedTable->ProcessorSignature.Uint32, - ExtendedTable->ProcessorFlag - ); - if (NeedLoad) { - break; - } - ExtendedTable ++; - } - } - - return NeedLoad; -} - /** Actual worker function that shadows the required microcode patches into memory. @@ -439,6 +328,11 @@ ShadowMicrocode ( return EFI_OUT_OF_RESOURCES; } + if (FeaturePcdGet (PcdShadowAllMicrocode)) { + MicrocodeCpuId = NULL; + CpuIdCount = 0; + } + // // Fill up microcode patch info buffer according to FIT table. // @@ -447,37 +341,10 @@ ShadowMicrocode ( for (Index = 0; Index < EntryNum; Index++) { if (FitEntry[Index].Type == FIT_TYPE_01_MICROCODE) { MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) FitEntry[Index].Address; - - if (*(UINT32 *) MicrocodeEntryPoint == 0xFFFFFFFF) { - // - // An empty slot for reserved microcode update, skip to check next entry. - // - continue; - } - - if (MicrocodeEntryPoint->HeaderVersion != 0x1) { - // - // Not a valid microcode header, skip to check next entry. - // - continue; - } - - DataSize = MicrocodeEntryPoint->DataSize; - TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize; - if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) || - (DataSize & 0x3) != 0 || - (TotalSize & (SIZE_1KB - 1)) != 0 || - TotalSize < DataSize - ) { - // - // Not a valid microcode header, skip to check next entry. - // - continue; - } - - if (IsMicrocodePatchNeedLoad (CpuIdCount, MicrocodeCpuId, MicrocodeEntryPoint)) { - PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint; - PatchInfoBuffer[PatchCount].Size = TotalSize; + TotalSize = GetMicrocodeLength (MicrocodeEntryPoint); + if (IsValidMicrocode (MicrocodeEntryPoint, TotalSize, MicrocodeCpuId, CpuIdCount, FALSE)) { + PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint; + PatchInfoBuffer[PatchCount].Size = TotalSize; TotalLoadSize += TotalSize; PatchCount++; } diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf index 581780add8..5ee225297d 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf +++ b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf @@ -1,7 +1,7 @@ ### @file # FIT based microcode shadow PEIM. # -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -25,6 +25,7 @@ BaseMemoryLib HobLib PeiServicesLib + MicrocodeLib [Packages] MdePkg/MdePkg.dec -- 2.27.0.windows.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: Consume MicrocodeLib 2021-04-02 6:00 ` [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: " Ni, Ray @ 2021-04-08 6:43 ` Siyuan, Fu 2021-04-08 16:08 ` Chaganty, Rangasai V 1 sibling, 0 replies; 8+ messages in thread From: Siyuan, Fu @ 2021-04-08 6:43 UTC (permalink / raw) To: Ni, Ray, devel@edk2.groups.io; +Cc: Chaganty, Rangasai V Reviewed-by: Siyuan Fu <siyuan.fu@intel.com> > -----Original Message----- > From: Ni, Ray <ray.ni@intel.com> > Sent: 2021年4月2日 14:00 > To: devel@edk2.groups.io > Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Fu, Siyuan > <siyuan.fu@intel.com> > Subject: [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: Consume > MicrocodeLib > > Signed-off-by: Ray Ni <ray.ni@intel.com> > Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com> > Cc: Siyuan Fu <siyuan.fu@intel.com> > --- > .../ShadowMicrocode/ShadowMicrocodePei.c | 155 ++---------------- > .../ShadowMicrocode/ShadowMicrocodePei.inf | 3 +- > 2 files changed, 13 insertions(+), 145 deletions(-) > > diff --git > a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.c > b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.c > index 98a7aed697..4e4b69a0ca 100644 > --- > a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.c > +++ > b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.c > @@ -1,7 +1,7 @@ > /** @file > > FIT based microcode shadow PEIM. > > > > -Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> > > +Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > **/ > > @@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > #include <Library/DebugLib.h> > > #include <Library/BaseMemoryLib.h> > > #include <Library/MemoryAllocationLib.h> > > +#include <Library/MicrocodeLib.h> > > #include <IndustryStandard/FirmwareInterfaceTable.h> > > #include <Register/Intel/Microcode.h> > > #include <Register/Intel/Cpuid.h> > > @@ -70,118 +71,6 @@ EFI_PEI_PPI_DESCRIPTOR > mPeiShadowMicrocodePpiList[] = { > } > > }; > > > > -/** > > - Determine if a microcode patch matchs the specific processor signature and > flag. > > - > > - @param[in] CpuIdCount Number of elements in MicrocodeCpuId array. > > - @param[in] MicrocodeCpuId A pointer to an array of > EDKII_PEI_MICROCODE_CPU_ID > > - structures. > > - @param[in] ProcessorSignature The processor signature field value > > - supported by a microcode patch. > > - @param[in] ProcessorFlags The prcessor flags field value supported by > > - a microcode patch. > > - > > - @retval TRUE The specified microcode patch will be loaded. > > - @retval FALSE The specified microcode patch will not be loaded. > > -**/ > > -BOOLEAN > > -IsProcessorMatchedMicrocodePatch ( > > - IN UINTN CpuIdCount, > > - IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId, > > - IN UINT32 ProcessorSignature, > > - IN UINT32 ProcessorFlags > > - ) > > -{ > > - UINTN Index; > > - > > - for (Index = 0; Index < CpuIdCount; Index++) { > > - if ((ProcessorSignature == MicrocodeCpuId[Index].ProcessorSignature) && > > - (ProcessorFlags & (1 << MicrocodeCpuId[Index].PlatformId)) != 0) { > > - return TRUE; > > - } > > - } > > - > > - return FALSE; > > -} > > - > > -/** > > - Check the 'ProcessorSignature' and 'ProcessorFlags' of the microcode > > - patch header with the CPUID and PlatformID of the processors within > > - system to decide if it will be copied into memory. > > - > > - @param[in] CpuIdCount Number of elements in MicrocodeCpuId array. > > - @param[in] MicrocodeCpuId A pointer to an array of > EDKII_PEI_MICROCODE_CPU_ID > > - structures. > > - @param[in] MicrocodeEntryPoint The pointer to the microcode patch > header. > > - > > - @retval TRUE The specified microcode patch need to be loaded. > > - @retval FALSE The specified microcode patch dosen't need to be loaded. > > -**/ > > -BOOLEAN > > -IsMicrocodePatchNeedLoad ( > > - IN UINTN CpuIdCount, > > - IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId, > > - CPU_MICROCODE_HEADER *MicrocodeEntryPoint > > - ) > > -{ > > - BOOLEAN NeedLoad; > > - UINTN DataSize; > > - UINTN TotalSize; > > - CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader; > > - UINT32 ExtendedTableCount; > > - CPU_MICROCODE_EXTENDED_TABLE *ExtendedTable; > > - UINTN Index; > > - > > - if (FeaturePcdGet (PcdShadowAllMicrocode)) { > > - return TRUE; > > - } > > - > > - // > > - // Check the 'ProcessorSignature' and 'ProcessorFlags' in microcode patch > header. > > - // > > - NeedLoad = IsProcessorMatchedMicrocodePatch ( > > - CpuIdCount, > > - MicrocodeCpuId, > > - MicrocodeEntryPoint->ProcessorSignature.Uint32, > > - MicrocodeEntryPoint->ProcessorFlags > > - ); > > - > > - // > > - // If the Extended Signature Table exists, check if the processor is in the > > - // support list > > - // > > - DataSize = MicrocodeEntryPoint->DataSize; > > - TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize; > > - if ((!NeedLoad) && (DataSize != 0) && > > - (TotalSize - DataSize > sizeof (CPU_MICROCODE_HEADER) + > > - sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER))) { > > - ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *) > ((UINT8 *) (MicrocodeEntryPoint) > > - + DataSize + sizeof (CPU_MICROCODE_HEADER)); > > - ExtendedTableCount = ExtendedTableHeader->ExtendedSignatureCount; > > - ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *) > (ExtendedTableHeader + 1); > > - > > - for (Index = 0; Index < ExtendedTableCount; Index ++) { > > - // > > - // Check the 'ProcessorSignature' and 'ProcessorFlag' of the Extended > > - // Signature Table entry with the CPUID and PlatformID of the processors > > - // within system to decide if it will be copied into memory > > - // > > - NeedLoad = IsProcessorMatchedMicrocodePatch ( > > - CpuIdCount, > > - MicrocodeCpuId, > > - ExtendedTable->ProcessorSignature.Uint32, > > - ExtendedTable->ProcessorFlag > > - ); > > - if (NeedLoad) { > > - break; > > - } > > - ExtendedTable ++; > > - } > > - } > > - > > - return NeedLoad; > > -} > > - > > /** > > Actual worker function that shadows the required microcode patches into > memory. > > > > @@ -439,6 +328,11 @@ ShadowMicrocode ( > return EFI_OUT_OF_RESOURCES; > > } > > > > + if (FeaturePcdGet (PcdShadowAllMicrocode)) { > > + MicrocodeCpuId = NULL; > > + CpuIdCount = 0; > > + } > > + > > // > > // Fill up microcode patch info buffer according to FIT table. > > // > > @@ -447,37 +341,10 @@ ShadowMicrocode ( > for (Index = 0; Index < EntryNum; Index++) { > > if (FitEntry[Index].Type == FIT_TYPE_01_MICROCODE) { > > MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) > FitEntry[Index].Address; > > - > > - if (*(UINT32 *) MicrocodeEntryPoint == 0xFFFFFFFF) { > > - // > > - // An empty slot for reserved microcode update, skip to check next entry. > > - // > > - continue; > > - } > > - > > - if (MicrocodeEntryPoint->HeaderVersion != 0x1) { > > - // > > - // Not a valid microcode header, skip to check next entry. > > - // > > - continue; > > - } > > - > > - DataSize = MicrocodeEntryPoint->DataSize; > > - TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize; > > - if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) || > > - (DataSize & 0x3) != 0 || > > - (TotalSize & (SIZE_1KB - 1)) != 0 || > > - TotalSize < DataSize > > - ) { > > - // > > - // Not a valid microcode header, skip to check next entry. > > - // > > - continue; > > - } > > - > > - if (IsMicrocodePatchNeedLoad (CpuIdCount, MicrocodeCpuId, > MicrocodeEntryPoint)) { > > - PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint; > > - PatchInfoBuffer[PatchCount].Size = TotalSize; > > + TotalSize = GetMicrocodeLength (MicrocodeEntryPoint); > > + if (IsValidMicrocode (MicrocodeEntryPoint, TotalSize, MicrocodeCpuId, > CpuIdCount, FALSE)) { > > + PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint; > > + PatchInfoBuffer[PatchCount].Size = TotalSize; > > TotalLoadSize += TotalSize; > > PatchCount++; > > } > > diff --git > a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.inf > b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.inf > index 581780add8..5ee225297d 100644 > --- > a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.inf > +++ > b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePe > i.inf > @@ -1,7 +1,7 @@ > ### @file > > # FIT based microcode shadow PEIM. > > # > > -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> > > +# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> > > # > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > # > > @@ -25,6 +25,7 @@ > BaseMemoryLib > > HobLib > > PeiServicesLib > > + MicrocodeLib > > > > [Packages] > > MdePkg/MdePkg.dec > > -- > 2.27.0.windows.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: Consume MicrocodeLib 2021-04-02 6:00 ` [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: " Ni, Ray 2021-04-08 6:43 ` Siyuan, Fu @ 2021-04-08 16:08 ` Chaganty, Rangasai V 1 sibling, 0 replies; 8+ messages in thread From: Chaganty, Rangasai V @ 2021-04-08 16:08 UTC (permalink / raw) To: Ni, Ray, devel@edk2.groups.io; +Cc: Fu, Siyuan Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com> -----Original Message----- From: Ni, Ray <ray.ni@intel.com> Sent: Thursday, April 01, 2021 11:00 PM To: devel@edk2.groups.io Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Fu, Siyuan <siyuan.fu@intel.com> Subject: [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: Consume MicrocodeLib Signed-off-by: Ray Ni <ray.ni@intel.com> Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com> --- .../ShadowMicrocode/ShadowMicrocodePei.c | 155 ++---------------- .../ShadowMicrocode/ShadowMicrocodePei.inf | 3 +- 2 files changed, 13 insertions(+), 145 deletions(-) diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c index 98a7aed697..4e4b69a0ca 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c +++ b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.c @@ -1,7 +1,7 @@ /** @file FIT based microcode shadow PEIM. -Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -13,6 +13,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> #include <Library/MemoryAllocationLib.h> +#include <Library/MicrocodeLib.h> #include <IndustryStandard/FirmwareInterfaceTable.h> #include <Register/Intel/Microcode.h> #include <Register/Intel/Cpuid.h> @@ -70,118 +71,6 @@ EFI_PEI_PPI_DESCRIPTOR mPeiShadowMicrocodePpiList[] = { } }; -/** - Determine if a microcode patch matchs the specific processor signature and flag. - - @param[in] CpuIdCount Number of elements in MicrocodeCpuId array. - @param[in] MicrocodeCpuId A pointer to an array of EDKII_PEI_MICROCODE_CPU_ID - structures. - @param[in] ProcessorSignature The processor signature field value - supported by a microcode patch. - @param[in] ProcessorFlags The prcessor flags field value supported by - a microcode patch. - - @retval TRUE The specified microcode patch will be loaded. - @retval FALSE The specified microcode patch will not be loaded. -**/ -BOOLEAN -IsProcessorMatchedMicrocodePatch ( - IN UINTN CpuIdCount, - IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId, - IN UINT32 ProcessorSignature, - IN UINT32 ProcessorFlags - ) -{ - UINTN Index; - - for (Index = 0; Index < CpuIdCount; Index++) { - if ((ProcessorSignature == MicrocodeCpuId[Index].ProcessorSignature) && - (ProcessorFlags & (1 << MicrocodeCpuId[Index].PlatformId)) != 0) { - return TRUE; - } - } - - return FALSE; -} - -/** - Check the 'ProcessorSignature' and 'ProcessorFlags' of the microcode - patch header with the CPUID and PlatformID of the processors within - system to decide if it will be copied into memory. - - @param[in] CpuIdCount Number of elements in MicrocodeCpuId array. - @param[in] MicrocodeCpuId A pointer to an array of EDKII_PEI_MICROCODE_CPU_ID - structures. - @param[in] MicrocodeEntryPoint The pointer to the microcode patch header. - - @retval TRUE The specified microcode patch need to be loaded. - @retval FALSE The specified microcode patch dosen't need to be loaded. -**/ -BOOLEAN -IsMicrocodePatchNeedLoad ( - IN UINTN CpuIdCount, - IN EDKII_PEI_MICROCODE_CPU_ID *MicrocodeCpuId, - CPU_MICROCODE_HEADER *MicrocodeEntryPoint - ) -{ - BOOLEAN NeedLoad; - UINTN DataSize; - UINTN TotalSize; - CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader; - UINT32 ExtendedTableCount; - CPU_MICROCODE_EXTENDED_TABLE *ExtendedTable; - UINTN Index; - - if (FeaturePcdGet (PcdShadowAllMicrocode)) { - return TRUE; - } - - // - // Check the 'ProcessorSignature' and 'ProcessorFlags' in microcode patch header. - // - NeedLoad = IsProcessorMatchedMicrocodePatch ( - CpuIdCount, - MicrocodeCpuId, - MicrocodeEntryPoint->ProcessorSignature.Uint32, - MicrocodeEntryPoint->ProcessorFlags - ); - - // - // If the Extended Signature Table exists, check if the processor is in the - // support list - // - DataSize = MicrocodeEntryPoint->DataSize; - TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize; - if ((!NeedLoad) && (DataSize != 0) && - (TotalSize - DataSize > sizeof (CPU_MICROCODE_HEADER) + - sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER))) { - ExtendedTableHeader = (CPU_MICROCODE_EXTENDED_TABLE_HEADER *) ((UINT8 *) (MicrocodeEntryPoint) - + DataSize + sizeof (CPU_MICROCODE_HEADER)); - ExtendedTableCount = ExtendedTableHeader->ExtendedSignatureCount; - ExtendedTable = (CPU_MICROCODE_EXTENDED_TABLE *) (ExtendedTableHeader + 1); - - for (Index = 0; Index < ExtendedTableCount; Index ++) { - // - // Check the 'ProcessorSignature' and 'ProcessorFlag' of the Extended - // Signature Table entry with the CPUID and PlatformID of the processors - // within system to decide if it will be copied into memory - // - NeedLoad = IsProcessorMatchedMicrocodePatch ( - CpuIdCount, - MicrocodeCpuId, - ExtendedTable->ProcessorSignature.Uint32, - ExtendedTable->ProcessorFlag - ); - if (NeedLoad) { - break; - } - ExtendedTable ++; - } - } - - return NeedLoad; -} - /** Actual worker function that shadows the required microcode patches into memory. @@ -439,6 +328,11 @@ ShadowMicrocode ( return EFI_OUT_OF_RESOURCES; } + if (FeaturePcdGet (PcdShadowAllMicrocode)) { + MicrocodeCpuId = NULL; + CpuIdCount = 0; + } + // // Fill up microcode patch info buffer according to FIT table. // @@ -447,37 +341,10 @@ ShadowMicrocode ( for (Index = 0; Index < EntryNum; Index++) { if (FitEntry[Index].Type == FIT_TYPE_01_MICROCODE) { MicrocodeEntryPoint = (CPU_MICROCODE_HEADER *) (UINTN) FitEntry[Index].Address; - - if (*(UINT32 *) MicrocodeEntryPoint == 0xFFFFFFFF) { - // - // An empty slot for reserved microcode update, skip to check next entry. - // - continue; - } - - if (MicrocodeEntryPoint->HeaderVersion != 0x1) { - // - // Not a valid microcode header, skip to check next entry. - // - continue; - } - - DataSize = MicrocodeEntryPoint->DataSize; - TotalSize = (DataSize == 0) ? 2048 : MicrocodeEntryPoint->TotalSize; - if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) || - (DataSize & 0x3) != 0 || - (TotalSize & (SIZE_1KB - 1)) != 0 || - TotalSize < DataSize - ) { - // - // Not a valid microcode header, skip to check next entry. - // - continue; - } - - if (IsMicrocodePatchNeedLoad (CpuIdCount, MicrocodeCpuId, MicrocodeEntryPoint)) { - PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint; - PatchInfoBuffer[PatchCount].Size = TotalSize; + TotalSize = GetMicrocodeLength (MicrocodeEntryPoint); + if (IsValidMicrocode (MicrocodeEntryPoint, TotalSize, MicrocodeCpuId, CpuIdCount, FALSE)) { + PatchInfoBuffer[PatchCount].Address = (UINTN) MicrocodeEntryPoint; + PatchInfoBuffer[PatchCount].Size = TotalSize; TotalLoadSize += TotalSize; PatchCount++; } diff --git a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf index 581780add8..5ee225297d 100644 --- a/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf +++ b/Silicon/Intel/IntelSiliconPkg/Feature/ShadowMicrocode/ShadowMicrocodePei.inf @@ -1,7 +1,7 @@ ### @file # FIT based microcode shadow PEIM. # -# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2020 - 2021, Intel Corporation. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -25,6 +25,7 @@ BaseMemoryLib HobLib PeiServicesLib + MicrocodeLib [Packages] MdePkg/MdePkg.dec -- 2.27.0.windows.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-04-09 0:39 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-04-02 6:00 [PATCH 0/3] Update edk2-platform repo to consume MicrocodeLib Ni, Ray 2021-04-02 6:00 ` [PATCH 1/3] MinPlatformPkg/CoreCommonLib.dsc: Consume MicrocodeLib Ni, Ray 2021-04-08 13:59 ` [edk2-devel] " Chiu, Chasel 2021-04-02 6:00 ` [PATCH 2/3] Vlv2TbltDevicePkg/PlatformPkg[IA32|X64].dsc: " Ni, Ray 2021-04-09 0:39 ` [edk2-devel] " Sun, Zailiang 2021-04-02 6:00 ` [PATCH 3/3] IntelSiliconPkg/ShadowMicrocodePei: " Ni, Ray 2021-04-08 6:43 ` Siyuan, Fu 2021-04-08 16:08 ` Chaganty, Rangasai V
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox