From nobody Wed May 8 14:38:31 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+52555+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+52555+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577260700; cv=none; d=zohomail.com; s=zohoarc; b=R/Nwe3wcSJ6LTVL/nfN0jXCUg4y1Lg03TpHuXyYYKitGYojmcgxX6guciVG7clDCdUYic7PlzCl5Aaz3zS0ox3pdazaWyMlFuMfi2/1FFLc2k5zgOa6EIw3obgdRM9fiyo/m5w0mEf/eS8gIm4hYYHLqTIBVcHk9m2HmadWPaK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577260700; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=eyTVl83DmPwmeFeCVSXXoeK/iPkjV7cWZhxgGD4kkdU=; b=d76bx6ClWucHqMgIhRbj4Tg9CvkuM8V3sSGV2HqWvG9LEY/p9RbXYb1vq8UDnNBIugYyJu99EHXnbFZ5BzxqO2VTsqNQU0yZ9wzRwMkWW41Yrxj4SVkaRvgS9pYdJw+UTK0GW1EKCVRDMM/y+0B+6g1kL384hSOvJnUUbUuuWF4= 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+52555+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 1577260700522783.5917760952658; Tue, 24 Dec 2019 23:58:20 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id sQdnYY1788612xgak7ZT6zrP; Tue, 24 Dec 2019 23:58:20 -0800 X-Received: from mga05.intel.com (mga05.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10742.1577260698093845890 for ; Tue, 24 Dec 2019 23:58:19 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2019 23:58:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,353,1571727600"; d="scan'208";a="214704516" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 24 Dec 2019 23:58:17 -0800 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Eric Dong , Ray Ni , Laszlo Ersek , Star Zeng , Siyuan Fu , Michael D Kinney Subject: [edk2-devel] [PATCH v2 1/6] UefiCpuPkg/MpInitLib: Collect processors' CPUID & Platform ID info Date: Wed, 25 Dec 2019 15:58:09 +0800 Message-Id: <20191225075814.8372-2-hao.a.wu@intel.com> In-Reply-To: <20191225075814.8372-1-hao.a.wu@intel.com> References: <20191225075814.8372-1-hao.a.wu@intel.com> 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,hao.a.wu@intel.com X-Gm-Message-State: hjcO6IV7ecaSfwsAVsodfqepx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1577260700; bh=XPeOZlc11wWkxbti/5D0Gyz76VrTPOxc7JqiKABrVrQ=; h=Cc:Date:From:Reply-To:Subject:To; b=ioSg+tHYxoRGurLQpG18o3EJiFMlIi3PUx1gGD6Bbu2G8Tfh2WKpwhxuSBGQl/mPqOA gJdkQ1qj+03HInrTgpUcjyUixtAMU01dVPm43htOAvTjOfhcc1Px2ynZ+M6NZkS60qloG IV6RePiRjD8C35SYDjJk/KgJADxydA0o5H8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2429 This commit will collect the CPUID and Platform ID information for each processor within system. They will be stored in the CPU_AP_DATA structure. These information will be used in the next commit to decide whether a microcode patch will be loaded into memory. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Star Zeng Cc: Siyuan Fu Cc: Michael D Kinney Signed-off-by: Hao A Wu Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 ++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 8fa07b12c5..4440dc2701 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -122,6 +122,8 @@ typedef struct { UINT64 CurrentTime; UINT64 TotalTime; EFI_EVENT WaitEvent; + UINT32 ProcessorSignature; + UINT8 PlatformId; } CPU_AP_DATA; =20 // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index d32adf0780..d5077e080e 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -548,7 +548,8 @@ InitializeApData ( IN UINT64 ApTopOfStack ) { - CPU_INFO_IN_HOB *CpuInfoInHob; + CPU_INFO_IN_HOB *CpuInfoInHob; + MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr; =20 CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; CpuInfoInHob[ProcessorNumber].InitialApicId =3D GetInitialApicId (); @@ -559,6 +560,17 @@ InitializeApData ( CpuMpData->CpuData[ProcessorNumber].Waiting =3D FALSE; CpuMpData->CpuData[ProcessorNumber].CpuHealthy =3D (BistData =3D=3D 0) ?= TRUE : FALSE; =20 + PlatformIdMsr.Uint64 =3D AsmReadMsr64 (MSR_IA32_PLATFORM_ID); + CpuMpData->CpuData[ProcessorNumber].PlatformId =3D (UINT8) PlatformIdMsr= .Bits.PlatformId; + + AsmCpuid ( + CPUID_VERSION_INFO, + &CpuMpData->CpuData[ProcessorNumber].ProcessorSignature, + NULL, + NULL, + NULL + ); + InitializeSpinLock(&CpuMpData->CpuData[ProcessorNumber].ApLock); SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } --=20 2.12.0.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 (#52555): https://edk2.groups.io/g/devel/message/52555 Mute This Topic: https://groups.io/mt/69259683/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 May 8 14:38:31 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+52556+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+52556+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577260702; cv=none; d=zohomail.com; s=zohoarc; b=kCQLCTKHDlj3yZdWFS8430gagbMbVwM07Jr5kYrLQmag5NBMiK5570IQcDyYt0j6lDYtJ0pKePiNrQpL02/4PLDZ+bR7AloEiDSNofd7FBpMKQmZbVZnnTgqrrELpR5iUDlsdChJt4emGK0K2xgS4O1kIPFuNzykiTMH5fmkZfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577260702; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=vMWlMVLdqfA74HviNsI55AmPCrA9xatFz4oOmSGRfWs=; b=bQgiQoncy36b3eUJBCDdejMK1F4dgq49u95r44wf4FalFat8toksWsS47UTCCfkXVbkYjdubrf7Zohqrz+WkPkr8ajF6Kf1V7HkIlEhBx40AQoo1Ni+qC8jCKcBDmEU+hsKb5ljTUOUQ/4RYo8sXxcQH+hK/jMRIVAt4RoJCDbU= 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+52556+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 1577260702436498.23916490844067; Tue, 24 Dec 2019 23:58:22 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id lahPYY1788612xXLcVXEWUSV; Tue, 24 Dec 2019 23:58:21 -0800 X-Received: from mga05.intel.com (mga05.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10742.1577260698093845890 for ; Tue, 24 Dec 2019 23:58:21 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2019 23:58:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,353,1571727600"; d="scan'208";a="214704521" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 24 Dec 2019 23:58:19 -0800 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Eric Dong , Ray Ni , Laszlo Ersek , Star Zeng , Siyuan Fu , Michael D Kinney Subject: [edk2-devel] [PATCH v2 2/6] UefiCpuPkg/MpInitLib: Reduce the size when loading microcode patches Date: Wed, 25 Dec 2019 15:58:10 +0800 Message-Id: <20191225075814.8372-3-hao.a.wu@intel.com> In-Reply-To: <20191225075814.8372-1-hao.a.wu@intel.com> References: <20191225075814.8372-1-hao.a.wu@intel.com> 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,hao.a.wu@intel.com X-Gm-Message-State: ZmVbebZkPhyiUCX5c9EUrpZrx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1577260701; bh=JW31AUGGf1ZbXZlwXbODREV+H4zmPbwoVruaDiUjHV4=; h=Cc:Date:From:Reply-To:Subject:To; b=vnBibazxpM3+uCAORmTk/JHtuNQTquGIqYhzI/auwY2ni2h1FhSx5U5/9PE4hX43PYK b8JZ5MCkZvWnKSNz4Sfe3iszfCMT6sY1fR99o8C0DLUG18tcIexWr5Dqom9KzE95GhIB9 My40WRJKyyN59QLzYhAk/pYAldHOFI2mLzM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2429 This commit will attempt to reduce the copy size when loading the microcode patches data from flash into memory. Such optimization is done by a pre-process of the microcode patch headers (on flash). A microcode patch will be loaded into memory only when the below 2 criteria are met: A. With a microcode patch header (which means the data is not padding data between microcode patches); B. The 'ProcessorSignature' & 'ProcessorFlags' fields in the header match at least one processor within system. Criterion B will require all the processors to be woken up once to collect their CPUID and Platform ID information. Hence, this commit will move the copy, detect and apply of microcode patch on BSP and APs after all the processors have been woken up. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Star Zeng Cc: Siyuan Fu Cc: Michael D Kinney Signed-off-by: Hao A Wu --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 24 ++ UefiCpuPkg/Library/MpInitLib/Microcode.c | 229 ++++++++++++++++++++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 82 ++----- 3 files changed, 277 insertions(+), 58 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 4440dc2701..56b0df664a 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -44,6 +44,20 @@ #define CPU_SWITCH_STATE_LOADED 2 =20 // +// Default maximum number of entries to store the microcode patches inform= ation +// +#define DEFAULT_MAX_MICROCODE_PATCH_NUM 8 + +// +// Data structure for microcode patch information +// +typedef struct { + UINTN Address; + UINTN Size; + UINTN AlignedSize; +} MICROCODE_PATCH_INFO; + +// // CPU exchange information for switch BSP // typedef struct { @@ -576,6 +590,16 @@ MicrocodeDetect ( ); =20 /** + Load the required microcode patches data into memory. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +LoadMicrocodePatch ( + IN OUT CPU_MP_DATA *CpuMpData + ); + +/** Detect whether Mwait-monitor feature is supported. =20 @retval TRUE Mwait-monitor feature is supported. diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 199b1f23ce..2dfbcc13ab 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -331,3 +331,232 @@ Done: MicroData [0x%08x], Revision [0x%08x]\n", Eax.Uint32, ProcessorFlag= s, (UINTN) MicrocodeData, LatestRevision)); } } + +/** + Actual worker function that loads the required microcode patches into me= mory. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. + @param[in] Patches The pointer to an array of information= on + the microcode patches that will be loa= ded + into memory. + @param[in] PatchCount The number of microcode patches that w= ill + be loaded into memory. + @param[in] TotalLoadSize The total size of all the microcode pa= tches + to be loaded. +**/ +VOID +LoadMicrocodePatchWorker ( + IN OUT CPU_MP_DATA *CpuMpData, + IN MICROCODE_PATCH_INFO *Patches, + IN UINTN PatchCount, + IN UINTN TotalLoadSize + ) +{ + UINTN Index; + VOID *MicrocodePatchInRam; + UINT8 *Walker; + + ASSERT ((Patches !=3D NULL) && (PatchCount !=3D 0)); + + MicrocodePatchInRam =3D AllocatePages (EFI_SIZE_TO_PAGES (TotalLoadSize)= ); + if (MicrocodePatchInRam =3D=3D NULL) { + return; + } + + // + // Load all the required microcode patches into memory + // + for (Walker =3D MicrocodePatchInRam, Index =3D 0; Index < PatchCount; In= dex++) { + CopyMem ( + Walker, + (VOID *) Patches[Index].Address, + Patches[Index].Size + ); + + // + // Zero-fill the padding area + // Please note that AlignedSize will be no less than Size + // + ZeroMem ( + Walker + Patches[Index].Size, + Patches[Index].AlignedSize - Patches[Index].Size + ); + + Walker +=3D Patches[Index].AlignedSize; + } + + // + // Update the microcode patch related fields in CpuMpData + // + CpuMpData->MicrocodePatchAddress =3D (UINTN) MicrocodePatchInRam; + CpuMpData->MicrocodePatchRegionSize =3D TotalLoadSize; + + DEBUG (( + DEBUG_INFO, + "%a: Required microcode patches have been loaded at 0x%lx, with size 0= x%lx.\n", + __FUNCTION__, CpuMpData->MicrocodePatchAddress, CpuMpData->MicrocodePa= tchRegionSize + )); + + return; +} + +/** + Load the required microcode patches data into memory. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +LoadMicrocodePatch ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + CPU_MICROCODE_HEADER *MicrocodeEntryPoint; + UINTN MicrocodeEnd; + UINTN DataSize; + UINTN TotalSize; + MICROCODE_PATCH_INFO *PatchInfoBuffer; + UINTN MaxPatchNumber; + UINTN PatchCount; + UINTN TotalLoadSize; + UINT32 ProcessorSignature; + UINT32 ProcessorFlags; + UINTN Index; + CPU_AP_DATA *CpuData; + BOOLEAN NeedLoad; + + // + // Initialize the microcode patch related fields in CpuMpData as the val= ues + // specified by the PCD pair. If the microcode patches are loaded into m= emory, + // these fields will be updated. + // + CpuMpData->MicrocodePatchAddress =3D PcdGet64 (PcdCpuMicrocodePatchAd= dress); + CpuMpData->MicrocodePatchRegionSize =3D PcdGet64 (PcdCpuMicrocodePatchRe= gionSize); + + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (UINTN) CpuMpData->M= icrocodePatchAddress; + MicrocodeEnd =3D (UINTN) MicrocodeEntryPoint + + (UINTN) CpuMpData->MicrocodePatchRegionSize; + if ((MicrocodeEntryPoint =3D=3D NULL) || ((UINTN) MicrocodeEntryPoint = =3D=3D MicrocodeEnd)) { + // + // There is no microcode patches + // + return; + } + + PatchCount =3D 0; + MaxPatchNumber =3D DEFAULT_MAX_MICROCODE_PATCH_NUM; + TotalLoadSize =3D 0; + PatchInfoBuffer =3D AllocatePool (MaxPatchNumber * sizeof (MICROCODE_PAT= CH_INFO)); + if (PatchInfoBuffer =3D=3D NULL) { + return; + } + + // + // Process the header of each microcode patch within the region. + // The purpose is to decide which microcode patch(es) will be loaded int= o memory. + // + do { + if (MicrocodeEntryPoint->HeaderVersion !=3D 0x1) { + // + // Padding data between the microcode patches, skip 1KB to check nex= t entry. + // + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) Microcode= EntryPoint) + SIZE_1KB); + continue; + } + + DataSize =3D MicrocodeEntryPoint->DataSize; + if (DataSize =3D=3D 0) { + TotalSize =3D sizeof (CPU_MICROCODE_HEADER) + 2000; + } else { + TotalSize =3D sizeof (CPU_MICROCODE_HEADER) + DataSize; + } + + if ( (UINTN)MicrocodeEntryPoint > (MAX_ADDRESS - TotalSize) || + ((UINTN)MicrocodeEntryPoint + TotalSize) > MicrocodeEnd || + (TotalSize & 0x3) !=3D 0 + ) { + // + // Not a valid microcode header, skip 1KB to check next entry. + // + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) Microcode= EntryPoint) + SIZE_1KB); + continue; + } + + TotalSize =3D (DataSize =3D=3D 0) ? 2048 : MicrocodeEntryPoint->TotalS= ize; + + // + // Check the 'ProcessorSignature' & 'ProcessorFlags' of this microcode= patch + // with the processors' CPUID & PlatformID to decide if it will be cop= ied + // into memory + // + ProcessorSignature =3D MicrocodeEntryPoint->ProcessorSignature.Uint32; + ProcessorFlags =3D MicrocodeEntryPoint->ProcessorFlags; + NeedLoad =3D FALSE; + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + CpuData =3D &CpuMpData->CpuData[Index]; + if ((ProcessorSignature =3D=3D CpuData->ProcessorSignature) && + (ProcessorFlags & (1 << CpuData->PlatformId)) !=3D 0) { + NeedLoad =3D TRUE; + break; + } + } + + if (NeedLoad) { + PatchCount++; + if (PatchCount >=3D MaxPatchNumber) { + // + // Current 'PatchInfoBuffer' cannot hold the information, double t= he size + // and allocate a new buffer. + // + if (MaxPatchNumber > MAX_UINTN / 2 / sizeof (MICROCODE_PATCH_INFO)= ) { + // + // Overflow check for MaxPatchNumber + // + goto OnExit; + } + + PatchInfoBuffer =3D ReallocatePool ( + MaxPatchNumber * sizeof (MICROCODE_PATCH_INFO), + 2 * MaxPatchNumber * sizeof (MICROCODE_PATCH_I= NFO), + PatchInfoBuffer + ); + if (PatchInfoBuffer =3D=3D NULL) { + goto OnExit; + } + MaxPatchNumber =3D MaxPatchNumber * 2; + } + + // + // Store the information of this microcode patch + // + if (TotalSize > ALIGN_VALUE (TotalSize, SIZE_1KB) || + ALIGN_VALUE (TotalSize, SIZE_1KB) > MAX_UINTN - TotalLoadSize) { + goto OnExit; + } + PatchInfoBuffer[PatchCount - 1].Address =3D (UINTN) MicrocodeEnt= ryPoint; + PatchInfoBuffer[PatchCount - 1].Size =3D TotalSize; + PatchInfoBuffer[PatchCount - 1].AlignedSize =3D ALIGN_VALUE (TotalSi= ze, SIZE_1KB); + TotalLoadSize +=3D PatchInfoBuffer[PatchCount - 1].AlignedSize; + } + + // + // Process the next microcode patch + // + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *) (((UINTN) MicrocodeEn= tryPoint) + TotalSize); + } while (((UINTN) MicrocodeEntryPoint < MicrocodeEnd)); + + 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 + )); + + LoadMicrocodePatchWorker (CpuMpData, PatchInfoBuffer, PatchCount, Tota= lLoadSize); + } + +OnExit: + if (PatchInfoBuffer !=3D NULL) { + FreePool (PatchInfoBuffer); + } + return; +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index d5077e080e..199468156b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -628,10 +628,6 @@ ApWakeupFunction ( ApTopOfStack =3D CpuMpData->Buffer + (ProcessorNumber + 1) * CpuMpD= ata->CpuApStackSize; BistData =3D *(UINT32 *) ((UINTN) ApTopOfStack - sizeof (UINTN)); // - // Do some AP initialize sync - // - ApInitializeSync (CpuMpData); - // // CpuMpData->CpuData[0].VolatileRegisters is initialized based on B= SP environment, // to initialize AP in InitConfig path. // NOTE: IDTR.BASE stored in CpuMpData->CpuData[0].VolatileRegisters= points to a different IDT shared by all APs. @@ -1615,7 +1611,6 @@ MpInitLibInitialize ( UINTN ApResetVectorSize; UINTN BackupBufferAddr; UINTN ApIdtBase; - VOID *MicrocodePatchInRam; =20 OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); if (OldCpuMpData =3D=3D NULL) { @@ -1683,39 +1678,7 @@ MpInitLibInitialize ( CpuMpData->SwitchBspFlag =3D FALSE; CpuMpData->CpuData =3D (CPU_AP_DATA *) (CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); - if (OldCpuMpData =3D=3D NULL) { - CpuMpData->MicrocodePatchRegionSize =3D PcdGet64 (PcdCpuMicrocodePatch= RegionSize); - // - // If platform has more than one CPU, relocate microcode to memory to = reduce - // loading microcode time. - // - MicrocodePatchInRam =3D NULL; - if (MaxLogicalProcessorNumber > 1) { - MicrocodePatchInRam =3D AllocatePages ( - EFI_SIZE_TO_PAGES ( - (UINTN)CpuMpData->MicrocodePatchRegionSize - ) - ); - } - if (MicrocodePatchInRam =3D=3D NULL) { - // - // there is only one processor, or no microcode patch is available, = or - // memory allocation failed - // - CpuMpData->MicrocodePatchAddress =3D PcdGet64 (PcdCpuMicrocodePatchA= ddress); - } else { - // - // there are multiple processors, and a microcode patch is available= , and - // memory allocation succeeded - // - CopyMem ( - MicrocodePatchInRam, - (VOID *)(UINTN)PcdGet64 (PcdCpuMicrocodePatchAddress), - (UINTN)CpuMpData->MicrocodePatchRegionSize - ); - CpuMpData->MicrocodePatchAddress =3D (UINTN)MicrocodePatchInRam; - } - }else { + if (OldCpuMpData !=3D NULL) { CpuMpData->MicrocodePatchRegionSize =3D OldCpuMpData->MicrocodePatchRe= gionSize; CpuMpData->MicrocodePatchAddress =3D OldCpuMpData->MicrocodePatchAd= dress; } @@ -1762,10 +1725,6 @@ MpInitLibInitialize ( (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index); } // - // Load Microcode on BSP - // - MicrocodeDetect (CpuMpData, TRUE); - // // Store BSP's MTRR setting // MtrrGetAllMtrrs (&CpuMpData->MtrrTable); @@ -1781,6 +1740,11 @@ MpInitLibInitialize ( // CollectProcessorCount (CpuMpData); } + + // + // Load required microcode patches data into memory + // + LoadMicrocodePatch (CpuMpData); } else { // // APs have been wakeup before, just get the CPU Information @@ -1788,7 +1752,6 @@ MpInitLibInitialize ( // CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; - CpuMpData->InitFlag =3D ApInitReconfig; CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { @@ -1797,21 +1760,24 @@ MpInitLibInitialize ( CpuMpData->CpuData[Index].ApFunction =3D 0; CopyMem (&CpuMpData->CpuData[Index].VolatileRegisters, &VolatileRegi= sters, sizeof (CPU_VOLATILE_REGISTERS)); } - if (MaxLogicalProcessorNumber > 1) { - // - // Wakeup APs to do some AP initialize sync - // - WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData, TRUE); - // - // Wait for all APs finished initialization - // - while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { - CpuPause (); - } - CpuMpData->InitFlag =3D ApInitDone; - for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { - SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); - } + } + + // + // Detect and apply Microcode on BSP + // + MicrocodeDetect (CpuMpData, TRUE); + + // + // Wakeup APs to do some AP initialize sync (Microcode & MTRR) + // + if (CpuMpData->CpuCount > 1) { + WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData, TRUE); + while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { + CpuPause (); + } + + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + SetApState (&CpuMpData->CpuData[Index], CpuStateIdle); } } =20 --=20 2.12.0.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 (#52556): https://edk2.groups.io/g/devel/message/52556 Mute This Topic: https://groups.io/mt/69259684/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 May 8 14:38:31 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+52557+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+52557+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577260703; cv=none; d=zohomail.com; s=zohoarc; b=i9BR4Ni9ShAKXFj08xfXTRqKYCdbY2wtM5i6oDEESDwn1mvwUQvQKJc5J/IHfxGWa6JpJgT0OwZ8CMPq5zjOM619qFKCG//g+FxyEQ0PVjqDxUE/G4DzON5c2P2TCFSVc92BD+6Az2A8y8FY8QkjwSc8wl7qnBBzayNSnrDEms0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577260703; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=nUREX90JojtK4Jbbt6yp7vMoWA5n4yvOZVIiVz1F+ng=; b=dRATYBsHe4b8YcDgloFy2xj/D5b6CJYwP6LxfT6ClLJVNMHoCFmSM5DFK8kIIf6T+ch5l2hdD8oBe9nbrdJcEJAUcHcUmswtsrJN+86HquRl5vt71BE2dPIutTFVsgZRGyCQfO6GC+pmGag3sxFb+jSQaN7RZvGl9F0KVZjsWFw= 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+52557+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 1577260703885242.3589352270808; Tue, 24 Dec 2019 23:58:23 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id ME9pYY1788612xeN5u3G6MaD; Tue, 24 Dec 2019 23:58:23 -0800 X-Received: from mga05.intel.com (mga05.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10742.1577260698093845890 for ; Tue, 24 Dec 2019 23:58:22 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2019 23:58:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,353,1571727600"; d="scan'208";a="214704524" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 24 Dec 2019 23:58:21 -0800 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Eric Dong , Ray Ni , Laszlo Ersek , Star Zeng , Siyuan Fu , Michael D Kinney Subject: [edk2-devel] [PATCH v2 3/6] UefiCpuPkg: Add definitions for EDKII microcode patch HOB Date: Wed, 25 Dec 2019 15:58:11 +0800 Message-Id: <20191225075814.8372-4-hao.a.wu@intel.com> In-Reply-To: <20191225075814.8372-1-hao.a.wu@intel.com> References: <20191225075814.8372-1-hao.a.wu@intel.com> 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,hao.a.wu@intel.com X-Gm-Message-State: drcQSrhMoU5EMon4jJOeEJWox1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1577260703; bh=QeMvE6fOA8U5nwGnwjKvUy8h3NBxAswLf5cpB37b8js=; h=Cc:Date:From:Reply-To:Subject:To; b=B6Pd8INyM2Mx4nVJVrto3s3Px6ZTHPMOcnRbbk/Q/ZjE8d1cwAFuQ/D3uN5lAiy2+va keboVSb3kcF1+QfK4j64ZXN3Fn+S0DemaHu4pGKYlZcdWtGuFeR/4EOEl/433+eUYdYQ3 8hGFjjNmuEeFnArCq0QuJVBdVDp5U+8YXfs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2430 This commit will add the definitions for EDKII microcode patch HOB. The intention of adding this HOB is to provide a scheme to store the below information: A. The base address and size of the microcode patches that are being loaded (from flash) into memory; B. The information of detected microcode patch for each processor within the system. The producer of the HOB will be the UefiCpuPkg/MpInitLib (where the load, detect and apply of the microcode happen). The consumer of the HOB can be modules that want to detect/apply the microcode patch by themselves again later during the boot flow. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Star Zeng Cc: Siyuan Fu Cc: Michael D Kinney Signed-off-by: Hao A Wu Reviewed-by: Ray Ni --- UefiCpuPkg/UefiCpuPkg.dec | 3 ++ UefiCpuPkg/Include/Guid/MicrocodePatchHob.h | 50 ++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 797f948631..45b267ac61 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -63,6 +63,9 @@ [Guids] ## Include/Guid/CpuFeaturesInitDone.h gEdkiiCpuFeaturesInitDoneGuid =3D { 0xc77c3a41, 0x61ab, 0x4143, { 0x98,= 0x3e, 0x33, 0x39, 0x28, 0x6, 0x28, 0xe5 }} =20 + ## Include/Guid/MicrocodePatchHob.h + gEdkiiMicrocodePatchHobGuid =3D { 0xd178f11d, 0x8716, 0x418e, { 0xa1,= 0x31, 0x96, 0x7d, 0x2a, 0xc4, 0x28, 0x43 }} + [Protocols] ## Include/Protocol/SmmCpuService.h gEfiSmmCpuServiceProtocolGuid =3D { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94,= 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} diff --git a/UefiCpuPkg/Include/Guid/MicrocodePatchHob.h b/UefiCpuPkg/Inclu= de/Guid/MicrocodePatchHob.h new file mode 100644 index 0000000000..8aaa08b683 --- /dev/null +++ b/UefiCpuPkg/Include/Guid/MicrocodePatchHob.h @@ -0,0 +1,50 @@ +/** @file + The microcode patch HOB is used to store the information of: + A. Base address and size of the loaded microcode patches data; + B. Detected microcode patch for each processor within system. + + Copyright (c) 2019, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#ifndef _MICROCODE_PATCH_HOB_H_ +#define _MICROCODE_PATCH_HOB_H_ + +extern EFI_GUID gEdkiiMicrocodePatchHobGuid; + +// +// The EDKII microcode patch HOB will be produced by MpInitLib and it can = be +// consumed by modules that want to detect/apply microcode patches. +// +typedef struct { + // + // The base address of the microcode patches data after being loaded into + // memory. + // + UINT64 MicrocodePatchAddress; + // + // The total size of the loaded microcode patches. + // + UINT64 MicrocodePatchRegionSize; + // + // The number of processors within the system. + // + UINT32 ProcessorCount; + // + // An array with 'ProcessorCount' elements that stores the offset (with + // regard to 'MicrocodePatchAddress') of the detected microcode patch + // (including the CPU_MICROCODE_HEADER data structure) for each processo= r. + // If no microcode patch is detected for certain processor, the relating + // element will be set to MAX_UINT64. + // + UINT64 ProcessorSpecificPatchOffset[0]; +} EDKII_MICROCODE_PATCH_HOB; + +#endif --=20 2.12.0.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 (#52557): https://edk2.groups.io/g/devel/message/52557 Mute This Topic: https://groups.io/mt/69259685/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 May 8 14:38:31 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+52558+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+52558+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577260705; cv=none; d=zohomail.com; s=zohoarc; b=QPNrtQPslunNPwyLC1/9l3y1YWzECwslo7VrRRarzVrH7tqNVdIhh4o16DyAh896ARZ4zhcjQLayB9/4v+8hN0fPysd1y/aOh15tGXxLXRt6rznKqg5tyUADguAmH2SyU0b2j+aiMnz/Ety17EwTcLV0tUoMJGp92Ek4/jMQxaI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577260705; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=CsrdKszfzOYCkwocQz+MzQNOGcG61DE3zUCec+e1ehI=; b=BvyBuKv/C4v345kE375J6PoUcx/29hkRbMp7p5uIzAiSFs8RbtxqkyKw9sunkqGviCNNXgxCndDJVYHax4J25C610anaLQ6TMVSpchiFhoTruJKWJI+9BN5EVnfqymQHLeFuPjMt5LbS2XDL5XxHWRAlAzucFCrdZ+bZSjiiHTE= 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+52558+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 15772607054981013.7941771089356; Tue, 24 Dec 2019 23:58:25 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3ceNYY1788612xCQHuF2ik21; Tue, 24 Dec 2019 23:58:24 -0800 X-Received: from mga05.intel.com (mga05.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10742.1577260698093845890 for ; Tue, 24 Dec 2019 23:58:24 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2019 23:58:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,353,1571727600"; d="scan'208";a="214704537" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 24 Dec 2019 23:58:22 -0800 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Eric Dong , Ray Ni , Laszlo Ersek , Star Zeng , Siyuan Fu , Michael D Kinney Subject: [edk2-devel] [PATCH v2 4/6] UefiCpuPkg/MpInitLib: Produce EDKII microcode patch HOB Date: Wed, 25 Dec 2019 15:58:12 +0800 Message-Id: <20191225075814.8372-5-hao.a.wu@intel.com> In-Reply-To: <20191225075814.8372-1-hao.a.wu@intel.com> References: <20191225075814.8372-1-hao.a.wu@intel.com> 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,hao.a.wu@intel.com X-Gm-Message-State: NShQe7I0vmNcsMkjkPO7pLdWx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1577260704; bh=cVE1XpjXTfPDNP6pCdl67JH2QwLXaVeq8T7C+RA2304=; h=Cc:Date:From:Reply-To:Subject:To; b=B2LqRXLqQw6NZMC84u+Fnna3A4YSwJD98n8laoQjIFinxgrJ5TUE8hLFIfz20EHw7ZG fPk5sVgvxW821p8DHp6IEq2DXuwzkgbPBXcPFfrDGUbq3ytM20mXaLYurcFkvLbbnIX0n 11q6PVaHzg2ZN5CF2zBkkOW6MC4ns/2s3vk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2430 This commit will update the MpInitLib to: A. Collect the base address and size information after microcode patches being loaded into memory; B. Collect the detected microcode patch for each processor within system; C. Based on the collected information, produce the EDKII microcode patch HOB. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Star Zeng Cc: Siyuan Fu Cc: Michael D Kinney Signed-off-by: Hao A Wu --- UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 24 +++++++-- UefiCpuPkg/Library/MpInitLib/Microcode.c | 20 +++++-- UefiCpuPkg/Library/MpInitLib/MpLib.c | 8 ++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 55 ++++++++++++++++++++ 5 files changed, 100 insertions(+), 8 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 1538185ef9..326703cc9a 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -63,3 +63,4 @@ [Pcd] =20 [Guids] gEdkiiS3SmmInitDoneGuid + gEdkiiMicrocodePatchHobGuid diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 56b0df664a..885656900c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -138,6 +138,7 @@ typedef struct { EFI_EVENT WaitEvent; UINT32 ProcessorSignature; UINT8 PlatformId; + UINT64 MicrocodeEntryAddr; } CPU_AP_DATA; =20 // @@ -580,13 +581,15 @@ CheckAndUpdateApsStatus ( /** Detect whether specified processor can find matching microcode patch and= load it. =20 - @param[in] CpuMpData The pointer to CPU MP Data structure. - @param[in] IsBspCallIn Indicate whether the caller is BSP or not. + @param[in] CpuMpData The pointer to CPU MP Data structure. + @param[in] ProcessorNumber The handle number of the processor. The ran= ge is + from 0 to the total number of logical proce= ssors + minus 1. **/ VOID MicrocodeDetect ( IN CPU_MP_DATA *CpuMpData, - IN BOOLEAN IsBspCallIn + IN UINTN ProcessorNumber ); =20 /** @@ -619,5 +622,20 @@ EnableDebugAgent ( VOID ); =20 +/** + Find the current Processor number by APIC ID. + + @param[in] CpuMpData Pointer to PEI CPU MP Data + @param[out] ProcessorNumber Return the pocessor number found + + @retval EFI_SUCCESS ProcessorNumber is found and returned. + @retval EFI_NOT_FOUND ProcessorNumber is not found. +**/ +EFI_STATUS +GetProcessorNumber ( + IN CPU_MP_DATA *CpuMpData, + OUT UINTN *ProcessorNumber + ); + #endif =20 diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 2dfbcc13ab..554d3ccddb 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -65,13 +65,15 @@ GetCurrentMicrocodeSignature ( It does not guarantee that the data has not been modified. CPU has its own mechanism to verify Microcode Binary part. =20 - @param[in] CpuMpData The pointer to CPU MP Data structure. - @param[in] IsBspCallIn Indicate whether the caller is BSP or not. + @param[in] CpuMpData The pointer to CPU MP Data structure. + @param[in] ProcessorNumber The handle number of the processor. The ran= ge is + from 0 to the total number of logical proce= ssors + minus 1. **/ VOID MicrocodeDetect ( IN CPU_MP_DATA *CpuMpData, - IN BOOLEAN IsBspCallIn + IN UINTN ProcessorNumber ) { UINT32 ExtendedTableLength; @@ -93,6 +95,7 @@ MicrocodeDetect ( MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr; UINT32 ProcessorFlags; UINT32 ThreadId; + BOOLEAN IsBspCallIn; =20 // // set ProcessorFlags to suppress incorrect compiler/analyzer warnings @@ -107,6 +110,7 @@ MicrocodeDetect ( } =20 CurrentRevision =3D GetCurrentMicrocodeSignature (); + IsBspCallIn =3D (ProcessorNumber =3D=3D (UINTN)CpuMpData->BspNumber)= ? TRUE : FALSE; if (CurrentRevision !=3D 0 && !IsBspCallIn) { // // Skip loading microcode if it has been loaded successfully @@ -319,6 +323,16 @@ Done: } } =20 + if (LatestRevision !=3D 0) { + // + // Save the detected microcode patch entry address (including the + // microcode patch header) for each processor. + // It will be used when building the microcode patch cache HOB. + // + CpuMpData->CpuData[ProcessorNumber].MicrocodeEntryAddr =3D + (UINTN) MicrocodeData - sizeof (CPU_MICROCODE_HEADER); + } + if (IsBspCallIn && (LatestRevision !=3D 0)) { // // Save BSP processor info and microcode info for later AP use. diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 199468156b..8f4b2b1973 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -399,12 +399,16 @@ ApInitializeSync ( ) { CPU_MP_DATA *CpuMpData; + UINTN ProcessorNumber; + EFI_STATUS Status; =20 CpuMpData =3D (CPU_MP_DATA *) Buffer; + Status =3D GetProcessorNumber (CpuMpData, &ProcessorNumber); + ASSERT_EFI_ERROR (Status); // // Load microcode on AP // - MicrocodeDetect (CpuMpData, FALSE); + MicrocodeDetect (CpuMpData, ProcessorNumber); // // Sync BSP's MTRR table to AP // @@ -1765,7 +1769,7 @@ MpInitLibInitialize ( // // Detect and apply Microcode on BSP // - MicrocodeDetect (CpuMpData, TRUE); + MicrocodeDetect (CpuMpData, CpuMpData->BspNumber); =20 // // Wakeup APs to do some AP initialize sync (Microcode & MTRR) diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index 3999603c3e..06e3f5d0d3 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -9,6 +9,7 @@ #include "MpLib.h" #include #include +#include =20 /** S3 SMM Init Done notification function. @@ -291,6 +292,59 @@ CheckAndUpdateApsStatus ( } =20 /** + Build the microcode patch HOB that contains the base address and size of= the + microcode patch stored in the memory. + + @param[in] CpuMpData Pointer to the CPU_MP_DATA structure. + +**/ +VOID +BuildMicrocodeCacheHob ( + IN CPU_MP_DATA *CpuMpData + ) +{ + EDKII_MICROCODE_PATCH_HOB *MicrocodeHob; + UINTN HobDataLength; + UINT32 Index; + + HobDataLength =3D sizeof (EDKII_MICROCODE_PATCH_HOB) + + sizeof (UINT64) * CpuMpData->CpuCount; + + MicrocodeHob =3D AllocatePool (HobDataLength); + if (MicrocodeHob =3D=3D NULL) { + ASSERT (FALSE); + return; + } + + // + // Store the information of the memory region that holds the microcode p= atches. + // + MicrocodeHob->MicrocodePatchAddress =3D CpuMpData->MicrocodePatchAddr= ess; + MicrocodeHob->MicrocodePatchRegionSize =3D CpuMpData->MicrocodePatchRegi= onSize; + + // + // Store the detected microcode patch for each processor as well. + // + MicrocodeHob->ProcessorCount =3D CpuMpData->CpuCount; + for (Index =3D 0; Index < CpuMpData->CpuCount; Index++) { + if (CpuMpData->CpuData[Index].MicrocodeEntryAddr !=3D 0) { + MicrocodeHob->ProcessorSpecificPatchOffset[Index] =3D + CpuMpData->CpuData[Index].MicrocodeEntryAddr - CpuMpData->Microcod= ePatchAddress; + } else { + MicrocodeHob->ProcessorSpecificPatchOffset[Index] =3D MAX_UINT64; + } + } + + BuildGuidDataHob ( + &gEdkiiMicrocodePatchHobGuid, + MicrocodeHob, + HobDataLength + ); + + return; +} + +/** Initialize global data for MP support. =20 @param[in] CpuMpData The pointer to CPU MP Data structure. @@ -302,6 +356,7 @@ InitMpGlobalData ( { EFI_STATUS Status; =20 + BuildMicrocodeCacheHob (CpuMpData); SaveCpuMpData (CpuMpData); =20 /// --=20 2.12.0.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 (#52558): https://edk2.groups.io/g/devel/message/52558 Mute This Topic: https://groups.io/mt/69259686/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 May 8 14:38:31 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+52559+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+52559+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577260706; cv=none; d=zohomail.com; s=zohoarc; b=Z8g6I+5oABKZJcOSySFodY9jAvdQIIWWjEYDLa5FO3TUzP07LpoqkIMruwbJeeErDuh0flL34YrcEeYNb+AdAzh5hnkkKJVbccmgdVPF17XVu8d4tcj7Deg52HgsuLdq3zi45fPa2XlLGeGHw71vEeTGNqA+wLaEhXkP5VmhC94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577260706; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=6FL+gzZjlrcQK+5CuJ2zeLeuzqZBurpB99qCM9h+I6I=; b=Ap2bCNfyHH0VOLLFkaKYCnLjurJyK9AcosEnxxyZMReZRz+0hUPiZNycuNojL6hd8fjyS0rftplihIrpXtHzuOH4/ZJ6chVr5qlkvOZKGY/EMxYrsfVI8Wqn73QhpABIlLiYfP45OF0sI8SLhlDeQiPImXnUZLhQSf2OZzJ4hOc= 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+52559+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 1577260706539795.5712512343897; Tue, 24 Dec 2019 23:58:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PVaNYY1788612xlefsgfSlaK; Tue, 24 Dec 2019 23:58:26 -0800 X-Received: from mga05.intel.com (mga05.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10742.1577260698093845890 for ; Tue, 24 Dec 2019 23:58:25 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2019 23:58:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,353,1571727600"; d="scan'208";a="214704551" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 24 Dec 2019 23:58:24 -0800 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Eric Dong , Ray Ni , Laszlo Ersek , Star Zeng , Siyuan Fu , Michael D Kinney Subject: [edk2-devel] [PATCH v2 5/6] UefiCpuPkg/MpInitLib: Relocate microcode patch fields in CPU_MP_DATA Date: Wed, 25 Dec 2019 15:58:13 +0800 Message-Id: <20191225075814.8372-6-hao.a.wu@intel.com> In-Reply-To: <20191225075814.8372-1-hao.a.wu@intel.com> References: <20191225075814.8372-1-hao.a.wu@intel.com> 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,hao.a.wu@intel.com X-Gm-Message-State: 2ABmFeoDw5loojnKQl0eTstMx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1577260706; bh=PbhASN4M/RsM6e5ym25JXe8DPWop80OVeklfn+Crwi0=; h=Cc:Date:From:Reply-To:Subject:To; b=iV+Iclkyks6fya07hejceu+YPYae3tPXJe8T0ZKp/HjIr3ccO6PmLXX6BsDEsiNUvzd 9ohgmYM7Sb3B1v3FRr4urlqqgk1JTX82oCaYlvF7987q/1EA80XwAG6yL5xAp3TWKImZr Uj/DunjL3DChAl/EPwHGwOoLdTKhBKtx8PM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The below 2 microcode patch related fields in structure CPU_MP_DATA: UINT64 MicrocodePatchAddress; UINT64 MicrocodePatchRegionSize; They will be passed from PEI phase and be reused DXE phase. Previously, these 2 fields were placed after some fields with type 'UINTN', this will lead to different field offset in different architecture for them. This commit will move them before the fields with different size in different architecture to ensure they can be properly used in DXE phase. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Star Zeng Cc: Siyuan Fu Cc: Michael D Kinney Signed-off-by: Hao A Wu Reviewed-by: Ray Ni --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 885656900c..5f50e79744 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -217,6 +217,8 @@ struct _CPU_MP_DATA { UINT64 CpuInfoInHob; UINT32 CpuCount; UINT32 BspNumber; + UINT64 MicrocodePatchAddress; + UINT64 MicrocodePatchRegionSize; // // The above fields data will be passed from PEI to DXE // Please make sure the fields offset same in the different @@ -260,8 +262,6 @@ struct _CPU_MP_DATA { UINT8 Vector; BOOLEAN PeriodicMode; BOOLEAN TimerInterruptState; - UINT64 MicrocodePatchAddress; - UINT64 MicrocodePatchRegionSize; =20 UINT32 ProcessorSignature; UINT32 ProcessorFlags; --=20 2.12.0.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 (#52559): https://edk2.groups.io/g/devel/message/52559 Mute This Topic: https://groups.io/mt/69259687/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 May 8 14:38:31 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+52560+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+52560+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1577260708; cv=none; d=zohomail.com; s=zohoarc; b=R1gO8MOq11QGbS4uA7eS2kcfaOwiYkLLYqcPKo1iSopzgLC2k0oAdBl4rgAqAj7FPke8oewBZt3+rkmaeLG3P2Uy8kGf1BOcF3phUsFoyYp/eL1K9iZ3l4s51LmxSEaHxgty1AehrbUk/YirJ+CVy+pncUc0axs+LJqvjyn2LwM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1577260708; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=GmLGw5cYEPJrg0dHG5VR3dfarnd+3LdrIQz5UmEDHzI=; b=n6hbIspElAd5gosn0vnCQVDZC66GwMNKxeVzaMKNokwr+EntlDWhNLSHvIVZ+vKA2SeciEaSgSm1kMT4OPm2TWyftPHs0kaEIUEz3nexSxegYAOdhrBdsf6So7nq9dP4wGAe3ChKaz8iofxRMLJaeaz7NcE00sSloEbxqpoGYv0= 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+52560+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 1577260708091320.1343046273837; Tue, 24 Dec 2019 23:58:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uBrrYY1788612xik28NkDz8P; Tue, 24 Dec 2019 23:58:27 -0800 X-Received: from mga05.intel.com (mga05.intel.com []) by mx.groups.io with SMTP id smtpd.web12.10742.1577260698093845890 for ; Tue, 24 Dec 2019 23:58:27 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Dec 2019 23:58:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,353,1571727600"; d="scan'208";a="214704566" X-Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.8]) by fmsmga008.fm.intel.com with ESMTP; 24 Dec 2019 23:58:25 -0800 From: "Wu, Hao A" To: devel@edk2.groups.io Cc: Hao A Wu , Eric Dong , Ray Ni , Laszlo Ersek , Star Zeng , Siyuan Fu , Michael D Kinney Subject: [edk2-devel] [PATCH v2 6/6] UefiCpuPkg/MpInitLib: Remove redundant microcode fields in CPU_MP_DATA Date: Wed, 25 Dec 2019 15:58:14 +0800 Message-Id: <20191225075814.8372-7-hao.a.wu@intel.com> In-Reply-To: <20191225075814.8372-1-hao.a.wu@intel.com> References: <20191225075814.8372-1-hao.a.wu@intel.com> 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,hao.a.wu@intel.com X-Gm-Message-State: TW2VFsYsQSPwkR1ag2IdEkVDx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1577260707; bh=/bgnkW3eKhxo2HiMOHJ4SC9+70Rg/UhnPZVxR9AmMQQ=; h=Cc:Date:From:Reply-To:Subject:To; b=mEMjoTYLBg8hA8mRCRzMVmOxSImib228blI2YcJl4adBXSOt5Plg4F791aq4b6I67bR +kNxtLGKTRgdJvi2qfm5DOrp/l8tdKp+H1CWCNZJTNUHqLQgBaGTg7wWYr8ajbg8PeuuU xhpMMsEhE7O+Lmz8494Xzm1ScD89sUZoHuw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Previous commits have introduced below fields in structure CPU_AP_DATA: UINT32 ProcessorSignature; UINT8 PlatformId; UINT64 MicrocodeEntryAddr; which store the information of: A. CPUID B. Platform ID C. Detected microcode patch entry address (including the microcode patch header) for each processor within system. Therefore, the below fields in structure CPU_MP_DATA: UINT32 ProcessorSignature; UINT32 ProcessorFlags; UINT64 MicrocodeDataAddress; UINT32 MicrocodeRevision; which store the BSP's information of: A. CPUID B. Platform ID C. The address and revision of detected microcode patch are redundant and can be removed. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Cc: Star Zeng Cc: Siyuan Fu Cc: Michael D Kinney Signed-off-by: Hao A Wu --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 5 -- UefiCpuPkg/Library/MpInitLib/Microcode.c | 51 ++++++-------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 5f50e79744..6609c958ce 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -263,11 +263,6 @@ struct _CPU_MP_DATA { BOOLEAN PeriodicMode; BOOLEAN TimerInterruptState; =20 - UINT32 ProcessorSignature; - UINT32 ProcessorFlags; - UINT64 MicrocodeDataAddress; - UINT32 MicrocodeRevision; - // // Whether need to use Init-Sipi-Sipi to wake up the APs. // Two cases need to set this value to TRUE. One is in HLT diff --git a/UefiCpuPkg/Library/MpInitLib/Microcode.c b/UefiCpuPkg/Library/= MpInitLib/Microcode.c index 554d3ccddb..110cbadbad 100644 --- a/UefiCpuPkg/Library/MpInitLib/Microcode.c +++ b/UefiCpuPkg/Library/MpInitLib/Microcode.c @@ -85,6 +85,7 @@ MicrocodeDetect ( UINTN Index; UINT8 PlatformId; CPUID_VERSION_INFO_EAX Eax; + CPU_AP_DATA *CpuData; UINT32 CurrentRevision; UINT32 LatestRevision; UINTN TotalSize; @@ -92,16 +93,9 @@ MicrocodeDetect ( UINT32 InCompleteCheckSum32; BOOLEAN CorrectMicrocode; VOID *MicrocodeData; - MSR_IA32_PLATFORM_ID_REGISTER PlatformIdMsr; - UINT32 ProcessorFlags; UINT32 ThreadId; BOOLEAN IsBspCallIn; =20 - // - // set ProcessorFlags to suppress incorrect compiler/analyzer warnings - // - ProcessorFlags =3D 0; - if (CpuMpData->MicrocodePatchRegionSize =3D=3D 0) { // // There is no microcode patches @@ -127,28 +121,25 @@ MicrocodeDetect ( } =20 ExtendedTableLength =3D 0; - // - // Here data of CPUID leafs have not been collected into context buffer,= so - // GetProcessorCpuid() cannot be used here to retrieve CPUID data. - // - AsmCpuid (CPUID_VERSION_INFO, &Eax.Uint32, NULL, NULL, NULL); - - // - // The index of platform information resides in bits 50:52 of MSR IA32_P= LATFORM_ID - // - PlatformIdMsr.Uint64 =3D AsmReadMsr64 (MSR_IA32_PLATFORM_ID); - PlatformId =3D (UINT8) PlatformIdMsr.Bits.PlatformId; + Eax.Uint32 =3D CpuMpData->CpuData[ProcessorNumber].ProcessorSignature; + PlatformId =3D CpuMpData->CpuData[ProcessorNumber].PlatformId; =20 // // Check whether AP has same processor with BSP. // If yes, direct use microcode info saved by BSP. // if (!IsBspCallIn) { - if ((CpuMpData->ProcessorSignature =3D=3D Eax.Uint32) && - (CpuMpData->ProcessorFlags & (1 << PlatformId)) !=3D 0) { - MicrocodeData =3D (VOID *)(UINTN) CpuMpData->MicrocodeDataAddress; - LatestRevision =3D CpuMpData->MicrocodeRevision; - goto Done; + // + // Get the CPU data for BSP + // + CpuData =3D &(CpuMpData->CpuData[CpuMpData->BspNumber]); + if ((CpuData->ProcessorSignature =3D=3D Eax.Uint32) && + (CpuData->PlatformId =3D=3D PlatformId) && + (CpuData->MicrocodeEntryAddr !=3D 0)) { + MicrocodeEntryPoint =3D (CPU_MICROCODE_HEADER *)(UINTN) CpuData->Mic= rocodeEntryAddr; + MicrocodeData =3D (VOID *) (MicrocodeEntryPoint + 1); + LatestRevision =3D MicrocodeEntryPoint->UpdateRevision; + goto Done; } } =20 @@ -216,7 +207,6 @@ MicrocodeDetect ( CheckSum32 +=3D MicrocodeEntryPoint->Checksum; if (CheckSum32 =3D=3D 0) { CorrectMicrocode =3D TRUE; - ProcessorFlags =3D MicrocodeEntryPoint->ProcessorFlags; } } else if ((MicrocodeEntryPoint->DataSize !=3D 0) && (MicrocodeEntryPoint->UpdateRevision > LatestRevision)) { @@ -260,7 +250,6 @@ MicrocodeDetect ( // Find one // CorrectMicrocode =3D TRUE; - ProcessorFlags =3D ExtendedTable->ProcessorFlag; break; } } @@ -332,18 +321,6 @@ Done: CpuMpData->CpuData[ProcessorNumber].MicrocodeEntryAddr =3D (UINTN) MicrocodeData - sizeof (CPU_MICROCODE_HEADER); } - - if (IsBspCallIn && (LatestRevision !=3D 0)) { - // - // Save BSP processor info and microcode info for later AP use. - // - CpuMpData->ProcessorSignature =3D Eax.Uint32; - CpuMpData->ProcessorFlags =3D ProcessorFlags; - CpuMpData->MicrocodeDataAddress =3D (UINTN) MicrocodeData; - CpuMpData->MicrocodeRevision =3D LatestRevision; - DEBUG ((DEBUG_INFO, "BSP Microcode:: signature [0x%08x], ProcessorFlag= s [0x%08x], \ - MicroData [0x%08x], Revision [0x%08x]\n", Eax.Uint32, ProcessorFlag= s, (UINTN) MicrocodeData, LatestRevision)); - } } =20 /** --=20 2.12.0.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 (#52560): https://edk2.groups.io/g/devel/message/52560 Mute This Topic: https://groups.io/mt/69259688/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-