From nobody Wed Apr 24 03:47:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+52999+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+52999+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1578457554; cv=none; d=zohomail.com; s=zohoarc; b=KoCowGBhcIU/tMcL58Mrtf7outM18GCdaOUd99tlwVGjzbE+95YvAlvFlrq8lOY5b07aa4MjZ+5InBWcw0qqUJw6l/PFonM7sbmPEE1P4Kb6k0r44vEjueHP+Q2vBM+dWv/rimgzA2xnUpFYzE6CbcYFt89XaqAx00UDHUoJheY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578457554; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Wg+LicuRu9a0DtpqymE71VBKUI8GbWBqsx3YT+G9rrw=; b=mRtcyohFqfhvMr0bn8tcMLVVLY6u0ZDjyE17pvV/Hq8cVgk3EzlaD7/CN0RefaoLWARpzVDLEB9uuCQqpUnmwy50F9VX5BgkbGe60XSi/KvaGpHEEh5eaQuATfBbfqeq392bmJiqrkhbLkct+g8BCkmrxBqfjmonbu7uk7WgvpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+52999+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1578457554494376.4338366409212; Tue, 7 Jan 2020 20:25:54 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id atNaYY1788612xDGHKJCLECz; Tue, 07 Jan 2020 20:25:54 -0800 X-Received: from mga03.intel.com (mga03.intel.com []) by mx.groups.io with SMTP id smtpd.web10.3800.1578457550722719234 for ; Tue, 07 Jan 2020 20:25:53 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jan 2020 20:25:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,408,1571727600"; d="scan'208";a="217402874" X-Received: from shwdeopenpsi787.ccr.corp.intel.com ([10.239.158.56]) by fmsmga007.fm.intel.com with ESMTP; 07 Jan 2020 20:25:51 -0800 From: "Siyuan, Fu" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, liming.gao@intel.com, eric.dong@intel.com, ray.ni@intel.com, lersek@redhat.com Subject: [edk2-devel] [Patch 1/2] MdePkg: Add header file for Firmware Interface Table specification. Date: Wed, 8 Jan 2020 12:25:24 +0800 Message-Id: <20200108042525.408-2-siyuan.fu@intel.com> In-Reply-To: <20200108042525.408-1-siyuan.fu@intel.com> References: <20200108042525.408-1-siyuan.fu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,siyuan.fu@intel.com X-Gm-Message-State: y7BYFPNAZIOBBo8BJpSWyonbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1578457554; bh=Z5MiUPQuO414Adp+AEHKcUNpkn+gNm0Ggm/YfZoxwwo=; h=Cc:Date:From:Reply-To:Subject:To; b=eSZYCM5P7igPVj7W7MKW6MKtbnDHZxQNjMu1uOZ9vYO5DHnIddrhtu62nFg2T3CJz2H XCSE3VMYegM+bvip4T2rhEzAhbgLp54O6TwNf3NSI0S6SV8r7ah/Re4EJBOrZLJeg9ZCB CvF4PuuoX6cSH/pCpq5u+tF3eFQomDLwtu0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This patch add FirmwareInterfaceTable.h for the Firmware Interface Table BIOS specification. This is to remove future edk2 dependency on edk2-platforms repo. The file content comes from edk2-platforms\Silicon\Intel\IntelSiliconPkg\Include\IndustryStandard BZ link: https://tianocore.acgmultimedia.com/show_bug.cgi?id=3D2449 Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Siyuan Fu --- .../IndustryStandard/FirmwareInterfaceTable.h | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 MdePkg/Include/IndustryStandard/FirmwareInterfaceTable.h diff --git a/MdePkg/Include/IndustryStandard/FirmwareInterfaceTable.h b/Mde= Pkg/Include/IndustryStandard/FirmwareInterfaceTable.h new file mode 100644 index 0000000000..be3e34ae1b --- /dev/null +++ b/MdePkg/Include/IndustryStandard/FirmwareInterfaceTable.h @@ -0,0 +1,76 @@ +/** @file + Industry Standard Definitions of Firmware Interface Table BIOS Specifica= tion 1.0. + + Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __FIRMWARE_INTERFACE_TABLE_H__ +#define __FIRMWARE_INTERFACE_TABLE_H__ + +// +// FIT Entry type definitions +// +#define FIT_TYPE_00_HEADER 0x00 +#define FIT_TYPE_01_MICROCODE 0x01 +#define FIT_TYPE_02_STARTUP_ACM 0x02 +#define FIT_TYPE_07_BIOS_STARTUP_MODULE 0x07 +#define FIT_TYPE_08_TPM_POLICY 0x08 +#define FIT_TYPE_09_BIOS_POLICY 0x09 +#define FIT_TYPE_0A_TXT_POLICY 0x0A +#define FIT_TYPE_0B_KEY_MANIFEST 0x0B +#define FIT_TYPE_0C_BOOT_POLICY_MANIFEST 0x0C +#define FIT_TYPE_10_CSE_SECURE_BOOT 0x10 +#define FIT_TYPE_2D_TXTSX_POLICY 0x2D +#define FIT_TYPE_2F_JMP_DEBUG_POLICY 0x2F +#define FIT_TYPE_7F_SKIP 0x7F + +#define FIT_POINTER_ADDRESS 0xFFFFFFC0 ///< Fixed address = at 4G - 40h + +#define FIT_TYPE_VERSION 0x0100 + +#define FIT_TYPE_00_SIGNATURE SIGNATURE_64 ('_', 'F', 'I', 'T', '_', ' ',= ' ', ' ') + +#pragma pack(1) + +typedef struct { + // + // Address is the base address of the firmware component + // must be aligned on 16 byte boundary + // + UINT64 Address; + // + // Size is the span of the component in multiple of 16 bytes + // + UINT8 Size[3]; + // + // Reserved must be set to 0 + // + UINT8 Reserved; + // + // Component's version number in binary coded decimal (BCD) format. + // For the FIT header entry, the value in this field will indicate the r= evision + // number of the FIT data structure. The upper byte of the revision field + // indicates the major revision and the lower byte indicates the minor r= evision. + // + UINT16 Version; + // + // FIT types 0x00 to 0x7F + // + UINT8 Type : 7; + // + // Checksum Valid indicates whether component has valid checksum. + // + UINT8 C_V : 1; + // + // Component's checksum. The modulo sum of all the bytes in the componen= t and + // the value in this field (Chksum) must add up to zero. This field is o= nly + // valid if the C_V flag is non-zero. + // + UINT8 Chksum; +} FIRMWARE_INTERFACE_TABLE_ENTRY; + +#pragma pack() + +#endif --=20 2.19.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#52999): https://edk2.groups.io/g/devel/message/52999 Mute This Topic: https://groups.io/mt/69521539/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed Apr 24 03:47:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+53000+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53000+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1578457556; cv=none; d=zohomail.com; s=zohoarc; b=f0U32BfyXcaq7vXWuyCymW7dMU65XRbTN+lDaVjbrDdisuVSL/yQYy6obhJ4z+3V8grJYYolytxbMTNOW9lLYjaWWIa9lLlggax7X/iNHRBn5XkuPeSw8dDUvYjEIW4BLS6xXaq9pBfk3CTf/vznwmNApKbx6i2plVCbq7lVhi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578457556; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=qLvcrnJfeyhG17hD/n1QfYi/kORT46Ad9jGURSUa7gs=; b=JW12TfDfW7A4WuZgRx8rNrmNgeIUnALaxHc6hvQcZjeffF06ZRRJudnP5qwK8MYvwUE2m98xK6K/MsLTxrTnNpIm0gs7VgSYh9tY5M92hIaStOIJRnOoxLSBwfvr8QTdWpjx6ERPdBb8DMxA5j/geJlXqG76cVQBtNTtxpJhrZw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+53000+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1578457556472533.6532320833373; Tue, 7 Jan 2020 20:25:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id UiCRYY1788612xchpASW4TtM; Tue, 07 Jan 2020 20:25:56 -0800 X-Received: from mga03.intel.com (mga03.intel.com []) by mx.groups.io with SMTP id smtpd.web10.3800.1578457550722719234 for ; Tue, 07 Jan 2020 20:25:55 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jan 2020 20:25:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,408,1571727600"; d="scan'208";a="217402879" X-Received: from shwdeopenpsi787.ccr.corp.intel.com ([10.239.158.56]) by fmsmga007.fm.intel.com with ESMTP; 07 Jan 2020 20:25:53 -0800 From: "Siyuan, Fu" To: devel@edk2.groups.io Cc: michael.d.kinney@intel.com, liming.gao@intel.com, eric.dong@intel.com, ray.ni@intel.com, lersek@redhat.com Subject: [edk2-devel] [Patch 2/2] UefiCpuPkg: Shadow microcode patch according to FIT microcode entry. Date: Wed, 8 Jan 2020 12:25:25 +0800 Message-Id: <20200108042525.408-3-siyuan.fu@intel.com> In-Reply-To: <20200108042525.408-1-siyuan.fu@intel.com> References: <20200108042525.408-1-siyuan.fu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,siyuan.fu@intel.com X-Gm-Message-State: a5jC3mRiIzSsYZLFlOW8JZuMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1578457556; bh=+oJzWmFXsQlGRy4kpXT0u3r6dHAUymUavfoYPBtFrfc=; h=Cc:Date:From:Reply-To:Subject:To; b=CUq6NY/T/c3/I2w8Gx9UtT/rL0LiBw+KT7i/4OchJ7yS3dfy/HAOfY7dImWuI6qbwyM VDJc9R7V5XFdhODxyYZHCW9nBQ81UPldCWgBy3+2VcnQowD3NGxEp5/1syb7kr7KXMhGQ vy60Hof4w2LcVYdxB74wT58/hjz2C2el5VI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The existing MpInitLib will shadow the microcode update patches from flash to memory and this is done by searching microcode region specified by PCD PcdCpuMicrocodePatchAddress and PcdCpuMicrocodePatchRegionSize. This brings a limition to platform FW that all the microcode patches must be placed in one continuous flash space. This patch shadows microcode update according to FIT microcode entries if it's present, otherwise it will fallback to original logic (by PCD). TEST: Tested on FIT enabled platform. BZ: https://tianocore.acgmultimedia.com/show_bug.cgi?id=3D2449 Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Siyuan Fu --- UefiCpuPkg/Library/MpInitLib/Microcode.c | 255 +++++++++++++++++------ UefiCpuPkg/Library/MpInitLib/MpLib.c | 4 +- UefiCpuPkg/Library/MpInitLib/MpLib.h | 7 +- 3 files changed, 200 insertions(+), 66 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 8f4d4da40c..6da6ebbfd3 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -318,7 +318,7 @@ Done: } =20 /** - Determine if a microcode patch will be loaded into memory. + Determine if a microcode patch matchs the specific processor signature a= nd flag. =20 @param[in] CpuMpData The pointer to CPU MP Data structure. @param[in] ProcessorSignature The processor signature field value @@ -330,7 +330,7 @@ Done: @retval FALSE The specified microcode patch will not be loaded. **/ BOOLEAN -IsMicrocodePatchNeedLoad ( +IsProcessorMatchedMicrocodePatch ( IN CPU_MP_DATA *CpuMpData, IN UINT32 ProcessorSignature, IN UINT32 ProcessorFlags @@ -351,7 +351,77 @@ IsMicrocodePatchNeedLoad ( } =20 /** - Actual worker function that loads the required microcode patches into me= mory. + 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] CpuMpData The pointer to CPU MP Data structure. + @param[in] MicrocodeEntryPoint The pointer to the microcode patch hea= der. + + @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 CPU_MP_DATA *CpuMpData, + 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; + + // + // Check the 'ProcessorSignature' and 'ProcessorFlags' in microcode patc= h header. + // + NeedLoad =3D IsProcessorMatchedMicrocodePatch ( + CpuMpData, + MicrocodeEntryPoint->ProcessorSignature.Uint32, + MicrocodeEntryPoint->ProcessorFlags + ); + + // + // If the Extended Signature Table exists, check if the processor is in = the + // support list + // + DataSize =3D MicrocodeEntryPoint->DataSize; + TotalSize =3D (DataSize =3D=3D 0) ? 2048 : MicrocodeEntryPoint->TotalSiz= e; + if ((!NeedLoad) && (DataSize !=3D 0) && + (TotalSize - DataSize > sizeof (CPU_MICROCODE_HEADER) + + sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADER)= )) { + ExtendedTableHeader =3D (CPU_MICROCODE_EXTENDED_TABLE_HEADER *) ((UINT= 8 *) (MicrocodeEntryPoint) + + DataSize + sizeof (CPU_MICROCODE_HEADER)); + ExtendedTableCount =3D ExtendedTableHeader->ExtendedSignatureCount; + ExtendedTable =3D (CPU_MICROCODE_EXTENDED_TABLE *) (ExtendedTabl= eHeader + 1); + + for (Index =3D 0; Index < ExtendedTableCount; Index ++) { + // + // Check the 'ProcessorSignature' and 'ProcessorFlag' of the Extended + // Signature Table entry with the CPUID and PlatformID of the proces= sors + // within system to decide if it will be copied into memory + // + NeedLoad =3D IsProcessorMatchedMicrocodePatch ( + CpuMpData, + ExtendedTable->ProcessorSignature.Uint32, + ExtendedTable->ProcessorFlag + ); + if (NeedLoad) { + break; + } + ExtendedTable ++; + } + } + + return NeedLoad; +} + + +/** + Actual worker function that shadows the required microcode patches into = memory. =20 @param[in, out] CpuMpData The pointer to CPU MP Data structure. @param[in] Patches The pointer to an array of information= on @@ -363,7 +433,7 @@ IsMicrocodePatchNeedLoad ( to be loaded. **/ VOID -LoadMicrocodePatchWorker ( +ShadowMicrocodePatchWorker ( IN OUT CPU_MP_DATA *CpuMpData, IN MICROCODE_PATCH_INFO *Patches, IN UINTN PatchCount, @@ -390,7 +460,6 @@ LoadMicrocodePatchWorker ( (VOID *) Patches[Index].Address, Patches[Index].Size ); - Walker +=3D Patches[Index].Size; } =20 @@ -410,12 +479,13 @@ LoadMicrocodePatchWorker ( } =20 /** - Load the required microcode patches data into memory. + Shadow the required microcode patches data into memory according to PCD + PcdCpuMicrocodePatchAddress and PcdCpuMicrocodePatchRegionSize. =20 @param[in, out] CpuMpData The pointer to CPU MP Data structure. **/ VOID -LoadMicrocodePatch ( +ShadowMicrocodePatchByPcd ( IN OUT CPU_MP_DATA *CpuMpData ) { @@ -423,15 +493,10 @@ LoadMicrocodePatch ( UINTN MicrocodeEnd; UINTN DataSize; UINTN TotalSize; - CPU_MICROCODE_EXTENDED_TABLE_HEADER *ExtendedTableHeader; - UINT32 ExtendedTableCount; - CPU_MICROCODE_EXTENDED_TABLE *ExtendedTable; MICROCODE_PATCH_INFO *PatchInfoBuffer; UINTN MaxPatchNumber; UINTN PatchCount; UINTN TotalLoadSize; - UINTN Index; - BOOLEAN NeedLoad; =20 // // Initialize the microcode patch related fields in CpuMpData as the val= ues @@ -487,55 +552,7 @@ LoadMicrocodePatch ( continue; } =20 - // - // 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 - // - NeedLoad =3D IsMicrocodePatchNeedLoad ( - CpuMpData, - MicrocodeEntryPoint->ProcessorSignature.Uint32, - MicrocodeEntryPoint->ProcessorFlags - ); - - // - // If the Extended Signature Table exists, check if the processor is i= n the - // support list - // - if ((!NeedLoad) && (DataSize !=3D 0) && - (TotalSize - DataSize > sizeof (CPU_MICROCODE_HEADER) + - sizeof (CPU_MICROCODE_EXTENDED_TABLE_HEADE= R))) { - ExtendedTableHeader =3D (CPU_MICROCODE_EXTENDED_TABLE_HEADER *) ((UI= NT8 *) (MicrocodeEntryPoint) - + DataSize + sizeof (CPU_MICROCODE_HEADER)); - ExtendedTableCount =3D ExtendedTableHeader->ExtendedSignatureCount; - ExtendedTable =3D (CPU_MICROCODE_EXTENDED_TABLE *) (ExtendedTa= bleHeader + 1); - - for (Index =3D 0; Index < ExtendedTableCount; Index ++) { - // - // Avoid access content beyond MicrocodeEnd - // - if ((UINTN) ExtendedTable > MicrocodeEnd - sizeof (CPU_MICROCODE_E= XTENDED_TABLE)) { - break; - } - - // - // Check the 'ProcessorSignature' and 'ProcessorFlag' of the Exten= ded - // Signature Table entry with the CPUID and PlatformID of the proc= essors - // within system to decide if it will be copied into memory - // - NeedLoad =3D IsMicrocodePatchNeedLoad ( - CpuMpData, - ExtendedTable->ProcessorSignature.Uint32, - ExtendedTable->ProcessorFlag - ); - if (NeedLoad) { - break; - } - ExtendedTable ++; - } - } - - if (NeedLoad) { + if (IsMicrocodePatchNeedLoad (CpuMpData, MicrocodeEntryPoint)) { PatchCount++; if (PatchCount > MaxPatchNumber) { // @@ -581,7 +598,7 @@ LoadMicrocodePatch ( __FUNCTION__, PatchCount, TotalLoadSize )); =20 - LoadMicrocodePatchWorker (CpuMpData, PatchInfoBuffer, PatchCount, Tota= lLoadSize); + ShadowMicrocodePatchWorker (CpuMpData, PatchInfoBuffer, PatchCount, To= talLoadSize); } =20 OnExit: @@ -590,3 +607,117 @@ OnExit: } return; } + +/** + Shadow the required microcode patches data into memory according to FIT = microcode entry. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. + + @return EFI_SUCCESS Microcode patch is shadowed into memory. + @return EFI_OUT_OF_RESOURCES No enough memory resource. + @return EFI_NOT_FOUND There is something wrong in FIT microcode = entry. + +**/ +EFI_STATUS +ShadowMicrocodePatchByFit ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + UINT64 FitPointer; + FIRMWARE_INTERFACE_TABLE_ENTRY *FitEntry; + UINT32 EntryNum; + UINT32 Index; + MICROCODE_PATCH_INFO *PatchInfoBuffer; + UINTN MaxPatchNumber; + CPU_MICROCODE_HEADER *MicrocodeEntryPoint; + UINTN PatchCount; + UINTN TotalSize; + UINTN TotalLoadSize; + + FitPointer =3D *(UINT64 *) (UINTN) FIT_POINTER_ADDRESS; + if ((FitPointer =3D=3D 0) || + (FitPointer =3D=3D 0xFFFFFFFFFFFFFFFF) || + (FitPointer =3D=3D 0xEEEEEEEEEEEEEEEE)) { + // + // No FIT table. + // + return EFI_NOT_FOUND; + } + FitEntry =3D (FIRMWARE_INTERFACE_TABLE_ENTRY *) (UINTN) FitPointer; + if ((FitEntry[0].Type !=3D FIT_TYPE_00_HEADER) || + (FitEntry[0].Address !=3D FIT_TYPE_00_SIGNATURE)) { + // + // Invalid FIT table, treat it as no FIT table. + // + return EFI_NOT_FOUND; + } + + EntryNum =3D *(UINT32 *)(&FitEntry[0].Size[0]) & 0xFFFFFF; + + // + // Calculate microcode entry number + // + MaxPatchNumber =3D 0; + for (Index =3D 0; Index < EntryNum; Index++) { + if (FitEntry[Index].Type =3D=3D FIT_TYPE_01_MICROCODE) { + MaxPatchNumber++; + } + } + if (MaxPatchNumber =3D=3D 0) { + return EFI_NOT_FOUND; + } + + PatchInfoBuffer =3D AllocatePool (MaxPatchNumber * sizeof (MICROCODE_PAT= CH_INFO)); + if (PatchInfoBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Fill up microcode patch info buffer according to FIT table. + // + PatchCount =3D 0; + TotalLoadSize =3D 0; + for (Index =3D 0; Index < EntryNum; Index++) { + if (FitEntry[Index].Type =3D=3D FIT_TYPE_01_MICROCODE) { + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (UINTN) FitEntry[In= dex].Address; + TotalSize =3D (MicrocodeEntryPoint->DataSize =3D=3D 0) ? 2048 : Micr= ocodeEntryPoint->TotalSize; + if (IsMicrocodePatchNeedLoad (CpuMpData, MicrocodeEntryPoint)) { + PatchInfoBuffer[PatchCount].Address =3D (UINTN) MicrocodeEntry= Point; + PatchInfoBuffer[PatchCount].Size =3D TotalSize; + TotalLoadSize +=3D TotalSize; + PatchCount++; + } + } + } + + if (PatchCount !=3D 0) { + DEBUG (( + DEBUG_INFO, + "%a: 0x%x microcode patches will be loaded into memory, with size 0x= %x.\n", + __FUNCTION__, PatchCount, TotalLoadSize + )); + + ShadowMicrocodePatchWorker (CpuMpData, PatchInfoBuffer, PatchCount, To= talLoadSize); + } + + FreePool (PatchInfoBuffer); + return EFI_SUCCESS; +} + +/** + Shadow the required microcode patches data into memory. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +ShadowMicrocodeUpdatePatch ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + EFI_STATUS Status; + + Status =3D ShadowMicrocodePatchByFit (CpuMpData); + if (EFI_ERROR (Status)) { + ShadowMicrocodePatchByPcd (CpuMpData); + } +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index e611a8ca40..6ec9b172b8 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1,7 +1,7 @@ /** @file CPU MP Initialize Library common functions. =20 - Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -1744,7 +1744,7 @@ MpInitLibInitialize ( // // Load required microcode patches data into memory // - LoadMicrocodePatch (CpuMpData); + ShadowMicrocodeUpdatePatch (CpuMpData); } else { // // APs have been wakeup before, just get the CPU Information diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b6e5a1afab..7c62d75acc 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -29,6 +29,9 @@ #include #include =20 +#include + + #define WAKEUP_AP_SIGNAL SIGNATURE_32 ('S', 'T', 'A', 'P') =20 #define CPU_INIT_MP_LIB_HOB_GUID \ @@ -587,12 +590,12 @@ MicrocodeDetect ( ); =20 /** - Load the required microcode patches data into memory. + Shadow the required microcode patches data into memory. =20 @param[in, out] CpuMpData The pointer to CPU MP Data structure. **/ VOID -LoadMicrocodePatch ( +ShadowMicrocodeUpdatePatch ( IN OUT CPU_MP_DATA *CpuMpData ); =20 --=20 2.19.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#53000): https://edk2.groups.io/g/devel/message/53000 Mute This Topic: https://groups.io/mt/69521541/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-