From nobody Fri May 17 07:47:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112063+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112063+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755359; cv=none; d=zohomail.com; s=zohoarc; b=UMJvuHYKzxnS6Hs0PkQFnQFYNhb/2lULwISlwUoFGRP4zYCjw+SxMLOhpz8GWkgyisF5z9pf66vo30Zifw4Lf0lvJFgXnQ6cS2PCfRjkQgNtDbtlky4LOrmO4EqMH1WfkF3eJLFmXjjdCTeNZeYWh4dbDXw1mc/UIs1QHvDbEqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755359; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=dSx3VHy9EiqXEmv42sNKdrODvMGJWqsurHolYz5xvAc=; b=kVwjhWk8lxMA0WQ3/qzzJTsE+u55w1K6wZ7FjmKwaB+yq9v/zsl6BIhl/cU2aVYGORHk2mReA952MZRBUL2pKtDPxQmM33ZKfY1LM1b5CgLKibYK0+P+qdE8bA7IIhqLY3ChPM7zIxh7d8lxpDDbQZ8SoXDL4Z2uxscU9Ig7pN0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112063+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701755359140971.6953723640403; Mon, 4 Dec 2023 21:49:19 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=km1QegrdSCMiQF/AES6yBn7CdVvkHjNfUK5Exc+qW10=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701755358; v=1; b=Andee6eu7d8RX2y2bx+jwVvv3ujV/zEdpyxDm9BUDmIfgwJ5RtfwWB92osslpbNWtSfjgvYm v45EDhPY25QaN48eZ9gQ2Op0rq6yic0pGQ1KBlDG9ZHT9bAva3XylW7/5zOfuJfPJ1I4MrawDoy ffcap9TCsix6RTSOGP9rIElU= X-Received: by 127.0.0.2 with SMTP id r5MsYY1788612xmuQjSjBWf4; Mon, 04 Dec 2023 21:49:18 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:18 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875426" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875426" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580527" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580527" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:16 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 1/6] UefiCpuPkg: Create gMpInformationHobGuid2 in UefiCpuPkg Date: Tue, 5 Dec 2023 13:48:55 +0800 Message-Id: <20231205054900.926-2-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: LzEqrxArGgvkavnXC40821dXx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755360252100005 Content-Type: text/plain; charset="utf-8" Create gMpInformationHobGuid2 in UefiCpuPkg. Currently, there is a gMpInformationHobGuid defined, created and consumed only in StandaloneMmPkg. The HOB contains the EFI_PROCESSOR_INFORMATION structure for each CPU and the number of processors. This is the same as the information that PiSmmCpuDxeSmm uses MpService Protocol to get. This new gMpInformationHobGuid2 also contains the NumberOfProcessors and the EFI_PROCESSOR_INFORMATION for each CPU. Also the HOB is extended to support the case that the maximum HOB length is not enough for all CPU. So there might be more than one HOB instance in the HOB list. Each HOB describes the corresponding CPU index range. The plan is to create gMpInformationHob2Guid in CpuMpPei module(implemented in next commit). Then PiSmmCpuDxeSmm and other MM_STANDALONE modules can consume the hob. This can avoid calling MpService Protocol in PiSmmCpuDxeSmm. Also the issue that one gMpInformationHobGuid might be not enough when CPU number is 1~2000 or bigger can be solved. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Include/Guid/MpInformation2.h | 56 ++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++ UefiCpuPkg/UefiCpuPkg.dec | 3 +++ 2 files changed, 59 insertions(+) diff --git a/UefiCpuPkg/Include/Guid/MpInformation2.h b/UefiCpuPkg/Include/= Guid/MpInformation2.h new file mode 100644 index 0000000000..4164ce1c30 --- /dev/null +++ b/UefiCpuPkg/Include/Guid/MpInformation2.h @@ -0,0 +1,56 @@ +/** @file + EFI MP information protocol provides a lightweight MP_SERVICES_PROTOCOL. + + MP information protocol only provides static information of MP processor. + + If SwitchBSP or Enable/DisableAP in MP service is called between the HOB + production and HOB consumption, EFI_PROCESSOR_INFORMATION.StatusFlag and + NumberOfEnabledProcessors fields in this HOB may be invalidated. + + Copyright (c) 2023, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MP_INFORMATION2_H_ +#define MP_INFORMATION2_H_ + +#include +#include +#include + +#define MP_INFORMATION2_HOB_REVISION 1 + +#define MP_INFORMATION2_GUID \ + { \ + 0x417a7f64, 0xf4e9, 0x4b32, {0x84, 0x6a, 0x5c, 0xc4, 0xd8, 0x62, 0x18,= 0x79} \ + } + +typedef struct { + EFI_PROCESSOR_INFORMATION ProcessorInfo; + // + // Add more fields in future + // +} MP_INFORMATION2_ENTRY; + +typedef struct { + UINT16 NumberOfProcessors; + UINT16 EntrySize; + UINT8 Version; + UINT8 Reserved[3]; + UINT64 ProcessorIndex; + MP_INFORMATION2_ENTRY MpInformation[0]; +} MP_INFORMATION2_HOB_DATA; + +// +// Producer of MP_INFORMATION2_HOB_DATA should assign sizeof (MP_INFORMATI= ON2_ENTRY) to MP_INFORMATION2_HOB_DATA.EntrySize +// Consumer of MP_INFORMATION2_HOB_DATA should use below macro or similar = logic to get the individual entry +// as the entry structure might be updated to include more information. +// +#define GET_MP_INFORMATION_ENTRY(MpInfoHobData, Index) \ + (MP_INFORMATION2_ENTRY *)((UINTN)&((MP_INFORMATION2_HOB_DATA *)(MpInfo= HobData))->MpInformation + (MpInfoHobData)->EntrySize * Index) + +extern EFI_GUID gMpInformationHobGuid2; + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 0b5431dbf7..61bd34ef17 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -85,6 +85,9 @@ ## Include/Guid/SmmBaseHob.h gSmmBaseHobGuid =3D { 0xc2217ba7, 0x03bb, 0x4f63, {0xa6, 0x47, 0x7c= , 0x25, 0xc5, 0xfc, 0x9d, 0x73 }} =20 + ## Include/Guid/MpInformation2.h + gMpInformationHobGuid2 =3D { 0x417a7f64, 0xf4e9, 0x4b32, {0x84, = 0x6a, 0x5c, 0xc4, 0xd8, 0x62, 0x18, 0x79 }} + [Protocols] ## Include/Protocol/SmmCpuService.h gEfiSmmCpuServiceProtocolGuid =3D { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94= , 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} --=20 2.31.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 (#112063): https://edk2.groups.io/g/devel/message/112063 Mute This Topic: https://groups.io/mt/102987137/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 Fri May 17 07:47:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112064+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112064+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755361; cv=none; d=zohomail.com; s=zohoarc; b=V4BZKyrPtPZQp36BigettJBU46PV44L8jASTqI6qA0WzTExfN2iXA7Okm5N9RCoGWVycbfJiN+IOCqfzq2dyOdAxaRsqiMvcPe7a4WGhMJxaYMbQZeVq6RXXNkoSgSUZwWblWqhLUCGHsYirhZCrzjwPwPUR0AJtdPCi/AQF3sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755361; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=B4L4zV403E0Hm6/S52nfac+720FwtDjOCZRj+GBwFHQ=; b=iPfFEBUizVBA96ppKm8gzbJMU48kCm78PpPCHFWPtTcll0sirOjj+hv1jX/9lhcfHR6whahoHKU3zg/Euco9M6Y2Q4E/l1yFzPjTpQw7iFGEWCJM3GdK/L7lYrE1qcm2BMG2Mk4E0e5ywFle+wIZq/ntDMqCq7wbp+npqshNdzw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112064+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701755361707465.1144026921248; Mon, 4 Dec 2023 21:49:21 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=KxVKRfb1gtn/G3ydUvoMkkhM00nMAfmvPdM45agFBEA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701755361; v=1; b=HUlwKQyV206Ba0wtnsMENw7nzu5hjNdFKfy9Zft4nBzHUQ+L0x+74n5shsMXSy7AHrxi0x3u T7NMZTN788ZQN4KGmCEXR7SPrMRnJ6xNUeiQpa6UtorXzOzGssmd5BmfGJ/USyzQaPenYfeLfrR A9nCgULDn4NJ7LmO3o1JOZZE= X-Received: by 127.0.0.2 with SMTP id e7K2YY1788612xuOB528Z09X; Mon, 04 Dec 2023 21:49:21 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:20 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875428" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875428" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580530" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580530" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:19 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 2/6] UefiCpuPkg: Build MpInfo2HOB in CpuMpPei Date: Tue, 5 Dec 2023 13:48:56 +0800 Message-Id: <20231205054900.926-3-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: jmumHl3qse8B0fr3u01JAP2Ex1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755362285100007 Content-Type: text/plain; charset="utf-8" Build MpInfo2HOB in CpuMpPei module so that later PiSmmCpuDxe or other StandaloneMm module can consume the HOB. Since there might be more one gMpInformationHobGuid2 in HOB list, CpuMpPei create a gMpInformationHobGuid2 with 0 value NumberOfProcessors field in the end of the process to indicate it's the last MP_INFORMATION2_HOB. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/CpuMpPei/CpuMpPei.c | 91 ++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++ UefiCpuPkg/CpuMpPei/CpuMpPei.h | 4 +++- UefiCpuPkg/CpuMpPei/CpuMpPei.inf | 3 ++- 3 files changed, 96 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c index b504bea3cf..4d80d52799 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c @@ -541,6 +541,92 @@ InitializeMpExceptionStackSwitchHandlers ( FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors * size= of (EXCEPTION_STACK_SWITCH_CONTEXT))); } =20 +/** + Create gMpInformationHobGuid2. +**/ +VOID +BuildMpInformationHob ( + VOID + ) +{ + EFI_STATUS Status; + UINTN ProcessorIndex; + UINTN NumberOfProcessors; + UINTN NumberOfEnabledProcessors; + UINTN NumberOfProcessorsInHob; + UINTN MaxProcessorsPerHob; + MP_INFORMATION2_HOB_DATA *MpInformation2HobData; + MP_INFORMATION2_ENTRY *MpInformation2Entry; + UINTN Index; + + ProcessorIndex =3D 0; + MpInformation2HobData =3D NULL; + MpInformation2Entry =3D NULL; + + Status =3D MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberO= fEnabledProcessors); + ASSERT_EFI_ERROR (Status); + MaxProcessorsPerHob =3D ((MAX_UINT16 & 7) - sizeof (EFI_HOB_GUID_TYP= E) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof (MP_INFORMATION2_ENTRY); + NumberOfProcessorsInHob =3D MaxProcessorsPerHob; + + // + // Create MP_INFORMATION2_HOB. when the max HobLength 0xFFF8 is not enou= gh, there + // will be a MP_INFORMATION2_HOB series in the HOB list. + // In the HOB list, there is a gMpInformationHobGuid2 with 0 value Numbe= rOfProcessors + // fields to indicate it's the last MP_INFORMATION2_HOB. + // + while (NumberOfProcessorsInHob !=3D 0) { + NumberOfProcessorsInHob =3D MIN (NumberOfProcessors - ProcessorIndex, = MaxProcessorsPerHob); + MpInformation2HobData =3D BuildGuidHob ( + &gMpInformationHobGuid2, + sizeof (MP_INFORMATION2_HOB_DATA) + sizeof= (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob + ); + ASSERT (MpInformation2HobData !=3D NULL); + + MpInformation2HobData->Version =3D MP_INFORMATION2_HOB_REVI= SION; + MpInformation2HobData->ProcessorIndex =3D ProcessorIndex; + MpInformation2HobData->NumberOfProcessors =3D (UINT16)NumberOfProcesso= rsInHob; + MpInformation2HobData->EntrySize =3D sizeof (MP_INFORMATION2_= ENTRY); + + DEBUG ((DEBUG_INFO, "BuildMpInformationHob\n")); + + for (Index =3D 0; Index < NumberOfProcessorsInHob; Index++) { + MpInformation2Entry =3D GET_MP_INFORMATION_ENTRY (MpInformation2HobD= ata, Index); + Status =3D MpInitLibGetProcessorInfo ( + (Index + ProcessorIndex) | CPU_V2_EXTENDED_T= OPOLOGY, + &MpInformation2Entry->ProcessorInfo, + NULL + ); + ASSERT_EFI_ERROR (Status); + DEBUG (( + DEBUG_INFO, + "ProcessorIndex =3D %x, ProcessorId =3D %lx, StatusFlag =3D %x\n", + Index + ProcessorIndex, + MpInformation2Entry->ProcessorInfo.ProcessorId, + MpInformation2Entry->ProcessorInfo.StatusFlag + )); + DEBUG (( + DEBUG_INFO, + "Location (Package/Core/Thread) =3D %d/%d/%d\n", + MpInformation2Entry->ProcessorInfo.Location.Package, + MpInformation2Entry->ProcessorInfo.Location.Core, + MpInformation2Entry->ProcessorInfo.Location.Thread + )); + DEBUG (( + DEBUG_INFO, + "Location2 (Package/Die/Tile/Module/Core/Thread) =3D %d/%d/%d/%d/%= d/%d\n", + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.P= ackage, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.D= ie, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.T= ile, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.M= odule, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.C= ore, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.T= hread + )); + } + + ProcessorIndex +=3D NumberOfProcessorsInHob; + } +} + /** Initializes MP and exceptions handlers. =20 @@ -602,6 +688,11 @@ InitializeCpuMpWorker ( Status =3D PeiServicesInstallPpi (mPeiCpuMpPpiList); ASSERT_EFI_ERROR (Status); =20 + // + // Create gMpInformationHobGuid2 + // + BuildMpInformationHob (); + return Status; } =20 diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h index 1b9a94e18f..a40fd2c077 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h @@ -1,7 +1,7 @@ /** @file Definitions to install Multiple Processor PPI. =20 - Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
+ Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -30,6 +30,8 @@ #include #include =20 +#include + extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc; =20 /** diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPe= i.inf index 865be5627e..812fa179bd 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf @@ -1,7 +1,7 @@ ## @file # CPU driver installs CPU PI Multi-processor PPI. # -# Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -50,6 +50,7 @@ =20 [Guids] gEdkiiMigratedFvInfoGuid ## = SOMETIMES_CONSUMES ## HOB + gMpInformationHobGuid2 ## PRODUCES =20 [Ppis] gEfiPeiMpServicesPpiGuid ## PRODUCES --=20 2.31.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 (#112064): https://edk2.groups.io/g/devel/message/112064 Mute This Topic: https://groups.io/mt/102987138/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 Fri May 17 07:47:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112065+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112065+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755364; cv=none; d=zohomail.com; s=zohoarc; b=LAxKJNTK02Sc+vio9m9bf5HTro4UQyQNKTfkXcmweGpu0fVUvWQEOyOHKJmxFKfG2xTDLZom/koa2/xUQA4Zrsae81w4JQuBs7/T06eoRXIFJ+GL5os4EYJoj7I5Kw46BJ2xhw+mcQHDQzbR3YeBNVpk6aVAt4rLqN0Euhl8t3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755364; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=plGElTqyVDnVKwep5fdR1zbGowG8ysu5ZTD9h8VE/PI=; b=hp4keypfnw4iDg/KSabhMcoUeFTPywYISR5SEJJgpYf5SfqlB++HxOLr/aQBu85j0G8dGN3h7X7gJVPYms81dvNpwonF9ukG8JGSAOdrhhjMlfv9t+5/6MBfqdrEHxnGKxTF/x9OMyUjrICkPVTRhjwEosvq1AfqpU8vYoFFpIc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112065+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701755364616295.7924576790916; Mon, 4 Dec 2023 21:49:24 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Cs3JDZMLIoChGNDVdmAU7rHNV1+rMwwLqr1lKPPm9Xs=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701755364; v=1; b=Kl7kCNnHel/6BfAGgWmTJCzQePwB/8dQeRMlnRfp9W+zDOAnRcXI48mr9xfIH3XRU8zKUJhp gB6VW65H6yNVrv5oPTjx92ggWi/CywOfgvljLEH4zyuMKG1AR2Ex3l2jOkgdjGVcIlGFMLk8Lfv J82U6hsU6YT2uuhiOZ5H39uU= X-Received: by 127.0.0.2 with SMTP id 7FebYY1788612xosMP4mpLVB; Mon, 04 Dec 2023 21:49:24 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:23 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875432" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875432" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580533" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580533" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:21 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 3/6] UefiCpuPkg: Consume MpInfo2Hob in PiSmmCpuDxe Date: Tue, 5 Dec 2023 13:48:57 +0800 Message-Id: <20231205054900.926-4-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: NtcVdSz337y9P2jSKbBBlB3xx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755366371100001 Content-Type: text/plain; charset="utf-8" Consume MpInfo2Hob in PiSmmCpuDxe driver to get NumberOfProcessors, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for all CPU from the MpInformation2 HOB. This can avoid calling MP service. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 209 +++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------= ------------------------------------ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 8 ++++---- 3 files changed, 171 insertions(+), 48 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 1d022a7051..d8d488b253 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -586,6 +586,152 @@ SmmReadyToLockEventNotify ( return EFI_SUCCESS; } =20 +/** + Function to compare 2 MP_INFORMATION2_HOB_DATA pointer based on Processo= rIndex. + + @param[in] Buffer1 pointer to MP_INFORMATION2_HOB_DATA poiner= to compare + @param[in] Buffer2 pointer to second MP_INFORMATION2_HOB_DATA= pointer to compare + + @retval 0 Buffer1 equal to Buffer2 + @retval <0 Buffer1 is less than Buffer2 + @retval >0 Buffer1 is greater than Buffer2 +**/ +INTN +EFIAPI +MpInformation2HobCompare ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + if ((*(MP_INFORMATION2_HOB_DATA **)Buffer1)->ProcessorIndex > (*(MP_INFO= RMATION2_HOB_DATA **)Buffer2)->ProcessorIndex) { + return 1; + } else if ((*(MP_INFORMATION2_HOB_DATA **)Buffer1)->ProcessorIndex < (*(= MP_INFORMATION2_HOB_DATA **)Buffer2)->ProcessorIndex) { + return -1; + } + + return 0; +} + +/** + Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for = all CPU from MpInformation2 HOB. + + @param[out] NumberOfCpus Pointer to NumberOfCpus. + @param[out] MaxNumberOfCpus Pointer to MaxNumberOfCpus. + @param[out] ProcessorInfoPointer Pointer to EFI_PROCESSOR_INFORMATION = buffer pointer. + + @retval EFI_SUCCESS Successfully extract information from= MpInformation2 HOB. + @retval RETURN_BUFFER_TOO_SMALL Fail to allocate memory. +**/ +EFI_STATUS +GetMpInfoFromMpInfo2Hob ( + OUT UINTN *NumberOfCpus, + OUT UINTN *MaxNumberOfCpus, + OUT EFI_PROCESSOR_INFORMATION **ProcessorInfoPointer + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + EFI_HOB_GUID_TYPE *FirstMpInfor2Hob; + MP_INFORMATION2_HOB_DATA *MpInformation2HobData; + UINTN CpuCount; + UINTN HobCount; + UINTN Index; + MP_INFORMATION2_HOB_DATA **MpInfomation2Buffer; + UINTN SortBuffer; + UINTN ProcessorIndex; + UINT64 PrevProcessorIndex; + MP_INFORMATION2_ENTRY *MpInformation2Entry; + EFI_PROCESSOR_INFORMATION *ProcessorInfo; + + GuidHob =3D NULL; + MpInformation2HobData =3D NULL; + FirstMpInfor2Hob =3D NULL; + MpInfomation2Buffer =3D NULL; + CpuCount =3D 0; + Index =3D 0; + HobCount =3D 0; + PrevProcessorIndex =3D 0; + + FirstMpInfor2Hob =3D GetFirstGuidHob (&gMpInformationHobGuid2); + ASSERT (FirstMpInfor2Hob !=3D NULL); + GuidHob =3D FirstMpInfor2Hob; + while (GuidHob !=3D NULL) { + MpInformation2HobData =3D GET_GUID_HOB_DATA (GuidHob); + + // + // This is the last MpInformationHob in the HOB list. + // + if (MpInformation2HobData->NumberOfProcessors =3D=3D 0) { + ASSERT (HobCount !=3D 0); + break; + } + + HobCount++; + CpuCount +=3D MpInformation2HobData->NumberOfProcessors; + GuidHob =3D GetNextGuidHob (&gMpInformationHobGuid2, GET_NEXT_HOB (G= uidHob)); + } + + ASSERT (CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + *NumberOfCpus =3D CpuCount; + + // + // If support CPU hot plug, we need to allocate resources for possibly h= ot-added processors + // + if (FeaturePcdGet (PcdCpuHotPlugSupport)) { + *MaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + } else { + *MaxNumberOfCpus =3D CpuCount; + } + + MpInfomation2Buffer =3D AllocatePool (sizeof (MP_INFORMATION2_HOB_DATA *= ) * HobCount); + ASSERT (MpInfomation2Buffer !=3D NULL); + if (MpInfomation2Buffer =3D=3D NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Record each MpInformation2Hob pointer in the MpInfomation2Buffer. + // + GuidHob =3D FirstMpInfor2Hob; + ASSERT (GuidHob !=3D NULL); + while (Index < HobCount) { + MpInfomation2Buffer[Index++] =3D GET_GUID_HOB_DATA (GuidHob); + GuidHob =3D GetNextGuidHob (&gMpInformationHobGui= d2, GET_NEXT_HOB (GuidHob)); + } + + ProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof (EFI= _PROCESSOR_INFORMATION) * (*MaxNumberOfCpus)); + ASSERT (ProcessorInfo !=3D NULL); + if (ProcessorInfo =3D=3D NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + QuickSort (MpInfomation2Buffer, HobCount, sizeof (MP_INFORMATION2_HOB_DA= TA *), (BASE_SORT_COMPARE)MpInformation2HobCompare, &SortBuffer); + for (Index =3D 0; Index < HobCount; Index++) { + // + // Make sure no overlap and no gap in the CPU range covered by each HOB + // + ASSERT (MpInfomation2Buffer[Index]->ProcessorIndex =3D=3D PrevProcesso= rIndex); + + // + // Cache each EFI_PROCESSOR_INFORMATION in order. + // + for (ProcessorIndex =3D 0; ProcessorIndex < MpInfomation2Buffer[Index]= ->NumberOfProcessors; ProcessorIndex++) { + MpInformation2Entry =3D GET_MP_INFORMATION_ENTRY (MpInfomation2Buffe= r[Index], ProcessorIndex); + CopyMem ( + ProcessorInfo + PrevProcessorIndex + ProcessorIndex, + &MpInformation2Entry->ProcessorInfo, + sizeof (EFI_PROCESSOR_INFORMATION) + ); + } + + PrevProcessorIndex +=3D MpInfomation2Buffer[Index]->NumberOfProcessors; + } + + *ProcessorInfoPointer =3D ProcessorInfo; + + FreePool (MpInfomation2Buffer); + return EFI_SUCCESS; +} + /** The module Entry Point of the CPU SMM driver. =20 @@ -603,26 +749,24 @@ PiCpuSmmEntry ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - EFI_MP_SERVICES_PROTOCOL *MpServices; - UINTN NumberOfEnabledProcessors; - UINTN Index; - VOID *Buffer; - UINTN BufferPages; - UINTN TileCodeSize; - UINTN TileDataSize; - UINTN TileSize; - UINT8 *Stacks; - VOID *Registration; - UINT32 RegEax; - UINT32 RegEbx; - UINT32 RegEcx; - UINT32 RegEdx; - UINTN FamilyId; - UINTN ModelId; - UINT32 Cr3; - EFI_HOB_GUID_TYPE *GuidHob; - SMM_BASE_HOB_DATA *SmmBaseHobData; + EFI_STATUS Status; + UINTN Index; + VOID *Buffer; + UINTN BufferPages; + UINTN TileCodeSize; + UINTN TileDataSize; + UINTN TileSize; + UINT8 *Stacks; + VOID *Registration; + UINT32 RegEax; + UINT32 RegEbx; + UINT32 RegEcx; + UINT32 RegEdx; + UINTN FamilyId; + UINTN ModelId; + UINT32 Cr3; + EFI_HOB_GUID_TYPE *GuidHob; + SMM_BASE_HOB_DATA *SmmBaseHobData; =20 GuidHob =3D NULL; SmmBaseHobData =3D NULL; @@ -654,17 +798,10 @@ PiCpuSmmEntry ( FindSmramInfo (&mCpuHotPlugData.SmrrBase, &mCpuHotPlugData.SmrrSize); =20 // - // Get MP Services Protocol - // - Status =3D SystemTable->BootServices->LocateProtocol (&gEfiMpServiceProt= ocolGuid, NULL, (VOID **)&MpServices); - ASSERT_EFI_ERROR (Status); - - // - // Use MP Services Protocol to retrieve the number of processors and num= ber of enabled processors + // Retrive NumberOfProcessors, MaxNumberOfCpus and EFI_PROCESSOR_INFORMA= TION for all CPU from MpInformation2 HOB. // - Status =3D MpServices->GetNumberOfProcessors (MpServices, &mNumberOfCpus= , &NumberOfEnabledProcessors); + Status =3D GetMpInfoFromMpInfo2Hob (&mNumberOfCpus, &mMaxNumberOfCpus, &= gSmmCpuPrivate->ProcessorInfo); ASSERT_EFI_ERROR (Status); - ASSERT (mNumberOfCpus <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); =20 // // If support CPU hot plug, PcdCpuSmmEnableBspElection should be set to = TRUE. @@ -690,15 +827,6 @@ PiCpuSmmEntry ( mAddressEncMask =3D PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAG= ING_1G_ADDRESS_MASK_64; DEBUG ((DEBUG_INFO, "mAddressEncMask =3D 0x%lx\n", mAddressEncMask)); =20 - // - // If support CPU hot plug, we need to allocate resources for possibly h= ot-added processors - // - if (FeaturePcdGet (PcdCpuHotPlugSupport)) { - mMaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); - } else { - mMaxNumberOfCpus =3D mNumberOfCpus; - } - gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus =3D mMaxNumberOfCpus; =20 PERF_CODE ( @@ -908,9 +1036,6 @@ PiCpuSmmEntry ( // // Allocate buffer for pointers to array in SMM_CPU_PRIVATE_DATA. // - gSmmCpuPrivate->ProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocateP= ool (sizeof (EFI_PROCESSOR_INFORMATION) * mMaxNumberOfCpus); - ASSERT (gSmmCpuPrivate->ProcessorInfo !=3D NULL); - gSmmCpuPrivate->Operation =3D (SMM_CPU_OPERATION *)AllocatePool (sizeof = (SMM_CPU_OPERATION) * mMaxNumberOfCpus); ASSERT (gSmmCpuPrivate->Operation !=3D NULL); =20 @@ -945,8 +1070,6 @@ PiCpuSmmEntry ( gSmmCpuPrivate->Operation[Index] =3D SmmCpuNone; =20 if (Index < mNumberOfCpus) { - Status =3D MpServices->GetProcessorInfo (MpServices, Index | CPU_V2_= EXTENDED_TOPOLOGY, &gSmmCpuPrivate->ProcessorInfo[Index]); - ASSERT_EFI_ERROR (Status); mCpuHotPlugData.ApicId[Index] =3D gSmmCpuPrivate->ProcessorInfo[Inde= x].ProcessorId; =20 DEBUG (( diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 20ada465c2..f18345881b 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -14,7 +14,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 -#include #include #include #include @@ -27,6 +26,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index 5d52ed7d13..b8aa2442cd 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -106,7 +106,6 @@ =20 [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES - gEfiMpServiceProtocolGuid ## CONSUMES gEfiSmmConfigurationProtocolGuid ## PRODUCES gEfiSmmCpuProtocolGuid ## PRODUCES gEfiSmmReadyToLockProtocolGuid ## NOTIFY @@ -120,6 +119,7 @@ gEdkiiPiSmmMemoryAttributesTableGuid ## CONSUMES ## SystemTable gEfiMemoryAttributesTableGuid ## CONSUMES ## SystemTable gSmmBaseHobGuid ## CONSUMES + gMpInformationHobGuid2 ## CONSUMES =20 [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmDebug ## CONS= UMES @@ -153,11 +153,11 @@ [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk ##= CONSUMES =20 +[Depex] + TRUE + [Pcd.X64] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmRestrictedMemoryAccess ## CONS= UMES =20 -[Depex] - gEfiMpServiceProtocolGuid - [UserExtensions.TianoCore."ExtraFiles"] PiSmmCpuDxeSmmExtra.uni --=20 2.31.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 (#112065): https://edk2.groups.io/g/devel/message/112065 Mute This Topic: https://groups.io/mt/102987139/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 Fri May 17 07:47:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112066+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112066+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755367; cv=none; d=zohomail.com; s=zohoarc; b=I6ntw19gpoqpANU5FG/RNtJsu/HMlnAGqAcFqdF7uAWhE35mNMUyCCezfwPqLitLYO0U/hZuvMExbetU9hyXGt7EAMDL1DrpgYHqJNq2ccQpM+fN8d9aDqzCj59qygvbiWyjz0hLyuey5JK/dPGqe9mQcrHZiCw3yTScpPutY8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755367; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=kNoPm0dVx8fukcSxXc9GTidupf/l4wj6iiJYDySLGAI=; b=MOQFS8ng0hDhxXnB6wK9AYwtx2dgXzPqqaLJdLAnHbgbkzMSxYM/5959MCE3e1nPlfmHjlbSnuWx9dW4AKRb2Pn4HlDeU/gBszXuhlGl71OYtuITGbEb4vLcKn89/S1sG8CYPNmxhJ05iHs88HjInhFv4DjaZtoAnWz3ytvhRgo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112066+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701755367209433.99858517071823; Mon, 4 Dec 2023 21:49:27 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Mj6E4/PHp8t1u3RLvVmJdZ4862HxvlXez/e7dB7/4/E=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701755366; v=1; b=ZcMQrX9VI8Dc3Ui92dP7QM5hv+2bxVlUFdSixlrS5+nfQXNOoJLUJwyg0Y1Zv+I3QE/hcuVW dyydgY3A74Q5A963lxqkn5LuY/c0LE9TMPHTxomWfmbn64whOxC+O9skMpxW6lqvFm+ObmD2kET YBhB8zArSsLH4AFotEwI4ZF0= X-Received: by 127.0.0.2 with SMTP id HzBmYY1788612x4k24GFNA9A; Mon, 04 Dec 2023 21:49:26 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:26 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875434" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875434" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580537" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580537" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:24 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 4/6] UefiCpuPkg: Add a new field in MpInfo2 HOB Date: Tue, 5 Dec 2023 13:48:58 +0800 Message-Id: <20231205054900.926-5-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: m4PYSkP1zXNpLSOb2hBQ1ymnx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755368398100007 Content-Type: text/plain; charset="utf-8" Add new field CoreType in gMpInformationHobGuid2 Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Reviewed-by: Ray Ni --- UefiCpuPkg/Include/Guid/MpInformation2.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UefiCpuPkg/Include/Guid/MpInformation2.h b/UefiCpuPkg/Include/= Guid/MpInformation2.h index 4164ce1c30..cb654d6f05 100644 --- a/UefiCpuPkg/Include/Guid/MpInformation2.h +++ b/UefiCpuPkg/Include/Guid/MpInformation2.h @@ -29,6 +29,8 @@ =20 typedef struct { EFI_PROCESSOR_INFORMATION ProcessorInfo; + UINT8 CoreType; + UINT8 Reserved[7]; // // Add more fields in future // --=20 2.31.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 (#112066): https://edk2.groups.io/g/devel/message/112066 Mute This Topic: https://groups.io/mt/102987140/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 Fri May 17 07:47:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112067+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112067+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755369; cv=none; d=zohomail.com; s=zohoarc; b=L49+JGr35mpXoIKFzfmImhE5ax95tAwdZwwQDFop4gyGBNDDKldMVORWXQv8Rqac/YuVAMLHuHHrwFxPSh7DsypQgMM7o/mgBJNhb+6+2nOA5mfVgSjnVOgC1ne1EmNWEPwF6041QMXx/aJNsR0LkPgH8L4kbvzc7erXHQWnlmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755369; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=tKH1bZ1+1ZdxTV0lU5Ol3VnROh+RhG619CrHixSsg9s=; b=IaldQaTlonIrWc3/qSmeNlzu3gh0XzFTYKs3eecOgQIlX+y33yWsgv4cvbyDhVHNY0W5rz8AfLNj3hNzaE2BOkfJDTvGNOYovFiI8l06R8jVfFkfX74Fq3lOL3u+hO/0H35L15m5QVGf46GVus5DvI4uXQxGpnVYOg1rpcuV9Ak= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112067+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 170175536952835.6075682818589; Mon, 4 Dec 2023 21:49:29 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=MQqpnbMRNKp2hLIn+NAe+xGDSmf0p+jT9YSWpBkrQDM=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701755369; v=1; b=FBFl0iA5Jbpxx8P5MytPko/bUiaPoU8AEKuXuG91Qs531RcbOprjy7OWXMdpL1UhR8NNBDGx KrBjvl+RqeOSb0AFt+p1KBtuXa4kz4FhKnHEXyt9PrzJNc42nYtbeTwdv0BV9H6aWlBB4AF0UCl zzQjScO5tdkVJZohpErdW8LE= X-Received: by 127.0.0.2 with SMTP id 6hmfYY1788612x1zDKZQm5cX; Mon, 04 Dec 2023 21:49:29 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:28 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875436" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875436" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:28 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580542" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580542" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:26 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 5/6] UefiCpuPkg: Cache core type in MpInfo2 HOB Date: Tue, 5 Dec 2023 13:48:59 +0800 Message-Id: <20231205054900.926-6-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 6XlHrN4xyS5W1d5LC6XEGaPBx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755370438100011 Content-Type: text/plain; charset="utf-8" Cache core type in MpInfo2 HOB by CpuMpPei module. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/CpuMpPei/CpuMpPei.c | 59 ++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++-- UefiCpuPkg/CpuMpPei/CpuMpPei.h | 2 ++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c index 4d80d52799..8f6863f4d9 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c @@ -541,6 +541,30 @@ InitializeMpExceptionStackSwitchHandlers ( FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors * size= of (EXCEPTION_STACK_SWITCH_CONTEXT))); } =20 +/** + Get CPU core type. + + @param[in, out] Buffer Argument of the procedure. +**/ +VOID +EFIAPI +GetProcessorCoreType ( + IN OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + UINT8 *CoreType; + CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX NativeModelIdAndCoreTypeEax; + UINTN ProcessorIndex; + + Status =3D MpInitLibWhoAmI (&ProcessorIndex); + ASSERT_EFI_ERROR (Status); + + CoreType =3D (UINT8 *)Buffer; + AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF= , &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL); + CoreType[ProcessorIndex] =3D (UINT8)NativeModelIdAndCoreTypeEax.Bits.Cor= eType; +} + /** Create gMpInformationHobGuid2. **/ @@ -558,13 +582,36 @@ BuildMpInformationHob ( MP_INFORMATION2_HOB_DATA *MpInformation2HobData; MP_INFORMATION2_ENTRY *MpInformation2Entry; UINTN Index; + UINT8 *CoreType; + UINT32 CpuidMaxInput; + UINTN Pages; =20 ProcessorIndex =3D 0; MpInformation2HobData =3D NULL; MpInformation2Entry =3D NULL; + CoreType =3D NULL; + Pages =3D 0; =20 Status =3D MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberO= fEnabledProcessors); ASSERT_EFI_ERROR (Status); + + // + // Get Processors CoreType + // + AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL); + if (CpuidMaxInput >=3D CPUID_HYBRID_INFORMATION) { + Pages =3D EFI_SIZE_TO_PAGES (sizeof (UINT8) * NumberOfProcessors); + CoreType =3D AllocatePages (Pages); + ASSERT (CoreType !=3D NULL); + + Status =3D MpInitLibStartupAllCPUs ( + GetProcessorCoreType, + 0, + (VOID *)CoreType + ); + ASSERT_EFI_ERROR (Status); + } + MaxProcessorsPerHob =3D ((MAX_UINT16 & 7) - sizeof (EFI_HOB_GUID_TYP= E) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof (MP_INFORMATION2_ENTRY); NumberOfProcessorsInHob =3D MaxProcessorsPerHob; =20 @@ -597,12 +644,16 @@ BuildMpInformationHob ( NULL ); ASSERT_EFI_ERROR (Status); + + MpInformation2Entry->CoreType =3D (CoreType !=3D NULL) ? CoreType[In= dex + ProcessorIndex] : 0; + DEBUG (( DEBUG_INFO, - "ProcessorIndex =3D %x, ProcessorId =3D %lx, StatusFlag =3D %x\n", + "ProcessorIndex =3D %x, ProcessorId =3D %lx, StatusFlag =3D %x, Co= reType =3D %x\n", Index + ProcessorIndex, MpInformation2Entry->ProcessorInfo.ProcessorId, - MpInformation2Entry->ProcessorInfo.StatusFlag + MpInformation2Entry->ProcessorInfo.StatusFlag, + MpInformation2Entry->CoreType )); DEBUG (( DEBUG_INFO, @@ -625,6 +676,10 @@ BuildMpInformationHob ( =20 ProcessorIndex +=3D NumberOfProcessorsInHob; } + + if (CoreType !=3D NULL) { + FreePages (CoreType, Pages); + } } =20 /** diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h index a40fd2c077..e7d07ffd64 100644 --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h @@ -32,6 +32,8 @@ =20 #include =20 +#include + extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc; =20 /** --=20 2.31.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 (#112067): https://edk2.groups.io/g/devel/message/112067 Mute This Topic: https://groups.io/mt/102987141/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 Fri May 17 07:47:21 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+112068+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112068+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755372; cv=none; d=zohomail.com; s=zohoarc; b=bVrMC0Ny9BtNyDPPI78ybHm592CReeYJtEDvbl4pEkS+NiqZ5bx3cA8GpqR5llcAmkAagRHxKKJ9BdPAJzMPreNUH2V1U8VoKMaTQPnOkzjg6dzPwolYINdCCy3e2dR18tJTZ+jKZMv48RALcvFNIzR4onB0KVGgGZElF6wff8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755372; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=AZKemq91ZgOtUs4Ta4w43J4swyrJP0zwuw6ffURHnEc=; b=Y1RTnHwrqWfXiAdm4vdNCvAAIhGwnKKS3cMRFoQgiQmxM8e5dWe68fqTJ8HCH7j9M9w+qV7FoxZHU1BOese8R+2opj10hRJlArDwHCemIjhxn2FxrBhdJn2hmy9wWCaWHxqZ54PDpk+FJwCE2tNL9xto56VZVsJC+dGkv8gLUkA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+112068+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701755372061550.6086886552458; Mon, 4 Dec 2023 21:49:32 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wE02bhhMNYjK8q4T32rY2OxK81uZIjXOSxB0qZxbANk=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701755371; v=1; b=gavLabr3jQcVdvx09yD1WmcWjz5ecFdpwIuvKsQs73jemEctSjDj2yezdEEsygS8CLCo5Bng lxjrqBXjvVnBwj4f4bCxqh6sGYApFnxt3N9kMvI5VhI2NGWDllHDiJWhxicFz2nUdUB1zPxfepd m30OmeaZq34zvABXYxt+f/7M= X-Received: by 127.0.0.2 with SMTP id ZklvYY1788612xkCI0uWQ3Dm; Mon, 04 Dec 2023 21:49:31 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:31 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875439" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875439" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580549" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580549" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:29 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 6/6] UefiCpuPkg: Avoid assuming only one smmbasehob Date: Tue, 5 Dec 2023 13:49:00 +0800 Message-Id: <20231205054900.926-7-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-1-dun.tan@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: rdSYUNdLvn1tgyzLFm72iZZgx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755372546100015 Content-Type: text/plain; charset="utf-8" Modify the gSmmBaseHobGuid consumption code to remove the asuumption that there is only one gSmmBaseHobGuid. If the CPU number is big enough, there will be more than one SmmBaseHob in the HOB list. Signed-off-by: Dun Tan Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 142 +++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++------------ 1 file changed, 130 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index d8d488b253..36fa5e779a 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -586,6 +586,130 @@ SmmReadyToLockEventNotify ( return EFI_SUCCESS; } =20 +/** + Function to compare 2 SMM_BASE_HOB_DATA pointer based on ProcessorIndex. + + @param[in] Buffer1 pointer to SMM_BASE_HOB_DATA poiner to com= pare + @param[in] Buffer2 pointer to second SMM_BASE_HOB_DATA pointe= r to compare + + @retval 0 Buffer1 equal to Buffer2 + @retval <0 Buffer1 is less than Buffer2 + @retval >0 Buffer1 is greater than Buffer2 +**/ +INTN +EFIAPI +SmBaseHobCompare ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + if ((*(SMM_BASE_HOB_DATA **)Buffer1)->ProcessorIndex > (*(SMM_BASE_HOB_D= ATA **)Buffer2)->ProcessorIndex) { + return 1; + } else if ((*(SMM_BASE_HOB_DATA **)Buffer1)->ProcessorIndex < (*(SMM_BAS= E_HOB_DATA **)Buffer2)->ProcessorIndex) { + return -1; + } + + return 0; +} + +/** + Extract SmBase for all CPU from SmmBase HOB. + + @param[in] FirstSmmBaseGuidHob Pointer to First SmmBaseGuidHob. + @param[in] MaxNumberOfCpus Max NumberOfCpus. + @param[out] SmBaseBufferPointer Pointer to SmBase buffer pointer. + + @retval EFI_SUCCESS Successfully extract SmBase for all C= PU from SmmBase HOB. + @retval RETURN_BUFFER_TOO_SMALL Fail to allocate memory. +**/ +EFI_STATUS +GetSmBaseFromSmmBaseHob ( + IN EFI_HOB_GUID_TYPE *FirstSmmBaseGuidHob, + IN UINTN MaxNumberOfCpus, + OUT UINTN **SmBaseBufferPointer + ) +{ + UINTN HobCount; + EFI_HOB_GUID_TYPE *GuidHob; + SMM_BASE_HOB_DATA *SmmBaseHobData; + UINTN NumberOfProcessors; + SMM_BASE_HOB_DATA **SmBaseHobPointerBuffer; + UINTN *SmBaseBuffer; + UINTN Index; + UINTN SortBuffer; + UINTN ProcessorIndex; + UINT64 PrevProcessorIndex; + + SmmBaseHobData =3D NULL; + Index =3D 0; + ProcessorIndex =3D 0; + PrevProcessorIndex =3D 0; + HobCount =3D 0; + NumberOfProcessors =3D 0; + GuidHob =3D FirstSmmBaseGuidHob; + + while (GuidHob !=3D NULL) { + HobCount++; + SmmBaseHobData =3D GET_GUID_HOB_DATA (GuidHob); + NumberOfProcessors +=3D SmmBaseHobData->NumberOfProcessors; + GuidHob =3D GetNextGuidHob (&gSmmBaseHobGuid, GET_NEXT_HOB= (GuidHob)); + } + + ASSERT (NumberOfProcessors =3D=3D MaxNumberOfCpus); + + SmBaseHobPointerBuffer =3D AllocatePool (sizeof (SMM_BASE_HOB_DATA *) * = HobCount); + ASSERT (SmBaseHobPointerBuffer !=3D NULL); + if (SmBaseHobPointerBuffer =3D=3D NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Record each SmmBaseHob pointer in the SmBaseHobPointerBuffer. + // + GuidHob =3D FirstSmmBaseGuidHob; + ASSERT (GuidHob !=3D NULL); + while (Index < HobCount) { + SmBaseHobPointerBuffer[Index++] =3D GET_GUID_HOB_DATA (GuidHob); + GuidHob =3D GetNextGuidHob (&gSmmBaseHobGuid, = GET_NEXT_HOB (GuidHob)); + } + + SmBaseBuffer =3D (UINTN *)AllocatePool (sizeof (UINTN) * (MaxNumberOfCpu= s)); + ASSERT (SmBaseBuffer !=3D NULL); + if (SmBaseBuffer =3D=3D NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + QuickSort (SmBaseHobPointerBuffer, HobCount, sizeof (SMM_BASE_HOB_DATA *= ), (BASE_SORT_COMPARE)SmBaseHobCompare, &SortBuffer); + for (Index =3D 0; Index < HobCount; Index++) { + // + // Make sure no overlap and no gap in the CPU range covered by each HOB + // + ASSERT (SmBaseHobPointerBuffer[Index]->ProcessorIndex =3D=3D PrevProce= ssorIndex); + + // + // Cache each SmBase in order. + // + if (sizeof (UINTN) =3D=3D sizeof (UINT64)) { + CopyMem ( + SmBaseBuffer + PrevProcessorIndex, + &SmBaseHobPointerBuffer[Index]->SmBase, + sizeof (UINT64) * SmBaseHobPointerBuffer[Index]->NumberOfProcessors + ); + } else { + for (ProcessorIndex =3D 0; ProcessorIndex < SmBaseHobPointerBuffer[I= ndex]->NumberOfProcessors; ProcessorIndex++) { + SmBaseBuffer[PrevProcessorIndex + ProcessorIndex] =3D (UINTN)SmBas= eHobPointerBuffer[Index]->SmBase[ProcessorIndex]; + } + } + + PrevProcessorIndex +=3D SmBaseHobPointerBuffer[Index]->NumberOfProcess= ors; + } + + FreePool (SmBaseHobPointerBuffer); + + *SmBaseBufferPointer =3D SmBaseBuffer; + return EFI_SUCCESS; +} + /** Function to compare 2 MP_INFORMATION2_HOB_DATA pointer based on Processo= rIndex. =20 @@ -766,10 +890,8 @@ PiCpuSmmEntry ( UINTN ModelId; UINT32 Cr3; EFI_HOB_GUID_TYPE *GuidHob; - SMM_BASE_HOB_DATA *SmmBaseHobData; =20 - GuidHob =3D NULL; - SmmBaseHobData =3D NULL; + GuidHob =3D NULL; =20 PERF_FUNCTION_BEGIN (); =20 @@ -1002,12 +1124,8 @@ PiCpuSmmEntry ( return RETURN_BUFFER_TOO_SMALL; } =20 - SmmBaseHobData =3D GET_GUID_HOB_DATA (GuidHob); - - // - // Assume single instance of HOB produced, expect the HOB.NumberOfProc= essors equals to the mMaxNumberOfCpus. - // - ASSERT (SmmBaseHobData->NumberOfProcessors =3D=3D (UINT32)mMaxNumberOf= Cpus && SmmBaseHobData->ProcessorIndex =3D=3D 0); + Status =3D GetSmBaseFromSmmBaseHob (GuidHob, mMaxNumberOfCpus, &mCpuHo= tPlugData.SmBase); + ASSERT_EFI_ERROR (Status); mSmmRelocated =3D TRUE; } else { // @@ -1053,8 +1171,6 @@ PiCpuSmmEntry ( // mCpuHotPlugData.ApicId =3D (UINT64 *)AllocatePool (sizeof (UINT64) * mMa= xNumberOfCpus); ASSERT (mCpuHotPlugData.ApicId !=3D NULL); - mCpuHotPlugData.SmBase =3D (UINTN *)AllocatePool (sizeof (UINTN) * mMaxN= umberOfCpus); - ASSERT (mCpuHotPlugData.SmBase !=3D NULL); mCpuHotPlugData.ArrayLength =3D (UINT32)mMaxNumberOfCpus; =20 // @@ -1063,7 +1179,9 @@ PiCpuSmmEntry ( // size for each CPU in the platform // for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { - mCpuHotPlugData.SmBase[Index] =3D mSmmRelocated ? (UINTN)SmmBaseHobDat= a->SmBase[Index] : (UINTN)Buffer + Index * TileSize - SMM_HANDLER_OFFSET; + if (!mSmmRelocated) { + mCpuHotPlugData.SmBase[Index] =3D (UINTN)Buffer + Index * TileSize -= SMM_HANDLER_OFFSET; + } =20 gSmmCpuPrivate->CpuSaveStateSize[Index] =3D sizeof (SMRAM_SAVE_STATE_M= AP); gSmmCpuPrivate->CpuSaveState[Index] =3D (VOID *)(mCpuHotPlugData.S= mBase[Index] + SMRAM_SAVE_STATE_MAP_OFFSET); --=20 2.31.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 (#112068): https://edk2.groups.io/g/devel/message/112068 Mute This Topic: https://groups.io/mt/102987142/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-