From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 728187803D1 for ; Tue, 30 Apr 2024 05:47:09 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=BfWR8vtWgJ8QR0vXnjdwAyUeTIYQsZWMX+txiNtlNjM=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20240206; t=1714456028; v=1; b=fI0ki6kWyHX/YspGKMDKhU2l3j1uyFfwo2GICJWSsPzYfuR6Zy+7eZkORXXgSaOLV+Wx5agE ZZCvkWaSxQjGw6g1NTyWOzRmoeqMHlSpWsE/cdDJkkzMtpNiJiC00Lha/DD6/vrUHFCDMwlXL95 AGcCuU9LWzpuqxFUGn2lxeRETYa0rX5Ikm7/XMQZ8xGN5dFSJU6HPJ4drM1rYu0A+RdNdNe+I90 8Xy9444O6avjWBqLR/dolALQm/OKlkudWdrD6CV7dhUkJ3xs5bV4uz2mSEMhDY30JcpjCuM9VVA 5oXhkjHhpZ5ENIvidsCsYdADyJiTxp+Sxg38qQCKlGxIw== X-Received: by 127.0.0.2 with SMTP id HxoeYY7687511x5cZyhLoEu0; Mon, 29 Apr 2024 22:47:08 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mx.groups.io with SMTP id smtpd.web11.8531.1714456027555949535 for ; Mon, 29 Apr 2024 22:47:07 -0700 X-CSE-ConnectionGUID: LGDrDQJ1Rj6Sy3XQwOEmMQ== X-CSE-MsgGUID: Kb1oXnC6SxmR+/Jhf/KOLA== X-IronPort-AV: E=McAfee;i="6600,9927,11059"; a="21292594" X-IronPort-AV: E=Sophos;i="6.07,241,1708416000"; d="scan'208,217";a="21292594" X-Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2024 22:47:07 -0700 X-CSE-ConnectionGUID: IsBi520dR0S5Dxo05fK8NA== X-CSE-MsgGUID: trYkljDtTNWguNrLFl167g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,241,1708416000"; d="scan'208,217";a="31151178" X-Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by orviesa004.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 29 Apr 2024 22:47:07 -0700 X-Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 29 Apr 2024 22:47:06 -0700 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 29 Apr 2024 22:47:06 -0700 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Mon, 29 Apr 2024 22:47:06 -0700 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.40) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 29 Apr 2024 22:47:05 -0700 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by CO1PR11MB5010.namprd11.prod.outlook.com (2603:10b6:303:93::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Tue, 30 Apr 2024 05:47:03 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::8774:81a7:c5b7:5c2c]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::8774:81a7:c5b7:5c2c%7]) with mapi id 15.20.7519.031; Tue, 30 Apr 2024 05:47:03 +0000 From: "Ni, Ray" To: Abdul Lateef Attar , "devel@edk2.groups.io" CC: Laszlo Ersek , "Kumar, Rahul R" , Gerd Hoffmann Subject: Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid Thread-Topic: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid Thread-Index: AQHamibihGNhkDX8TUCHuAqLc7tFyrGATwr0 Date: Tue, 30 Apr 2024 05:47:03 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|CO1PR11MB5010:EE_ x-ms-office365-filtering-correlation-id: 081a73c8-18ac-45bf-a67c-08dc68d8f646 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: =?us-ascii?Q?fNlh0KjV0lzxWdMBH/sH/AuFh/meukL2VbN+iE99iHw8pKyZGjpUVymjZ2TC?= =?us-ascii?Q?WV8UZpnsmbcEUSzHOsFSh9Q1Lrm3yMxDYUSdMhe2h2rnRbPr5c3jTi34+1Fe?= =?us-ascii?Q?XOP6vj+rRmtR/NI8lPz6AYzOUp1Q0GlVlESW8Lm0+JStaeQJFQqAb2lMujkk?= =?us-ascii?Q?ji/OGVyzR/FSKOHfFrEyQdxG5hHTj46tfBYlSI5DB8vdUibcdUCPZPwWVJ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+FIoXeFobjnS0hmx9efZ5KA+sZ7pN/7//Idf?= =?us-ascii?Q?InWICDbW9g2dFXY/jR884ijUoWRieOkY6Uet4nRgJ/LibwHqKoiQN0cXfNru?= =?us-ascii?Q?kf5ROTSavyB/Ub9ofeVAgBRLZ8mfaCPirYs+IBs/72GZG/rCkuX9oyxretJ+?= =?us-ascii?Q?uaeYO2YScLThIv39eIsn3V62dz0lQwnjd+XxkKZ3dAE6DnuDALYpxsdnzWjq?= =?us-ascii?Q?WdUpebBijUxfFtgBYBBChRXYuTb60ecq+zLuDEOu1/4ylA=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?3ObobBBQCbVlF9W4CwlSA142Wgq3ZaSBEasAoVzKOKd7SDuv1127wMFEF8qR?= =?us-ascii?Q?LI//cI7yVdicrHEx121uIN7EEhY6zNsgNAvtYMIfUmPEVuxW60MOGe/LRh3i?= =?us-ascii?Q?8iQWIZ2ROsFsvxeBwKj71AeojzJM2XdciRs0RMMjj/pdYUToGnWRiiV+TfZU?= =?us-ascii?Q?XUUUrL1LK67WPlHyX1SRx6QZzjqIobq5bj3YeJdHTQxdDN/ElMvCC/JHaBSN?= =?us-ascii?Q?XGcmWN3JePTf9gjjarJRJwU8OdTALuanjXdubwPz+rG0DcQzql37MFIsY2EP?= =?us-ascii?Q?UqMKx6frMl36oQGQPiJ1vVwctEjIhSNcn2MPdMYyUj2AbaI/bAMPl8e/srlT?= =?us-ascii?Q?c4Z1SPrRzDaSWhRHCzIAFm8/0L3KYVW2/WbvTb0O089OjX2SQhVsW56/fAB/?= =?us-ascii?Q?SsMu+43MoaOiWsXZjXZ3UWlOTpHR2oxRu+NUDTQsBFSydRuQGznGvrqoDeCS?= =?us-ascii?Q?lrrHzAxDMnFJlJQCxANvu2tFeymhB11aJUKNyctuWipmELsbyESTdybDieb/?= =?us-ascii?Q?0p4q53T/Pj5KdmpSryDA5Z70tR960KXWnDlXrl6o8mcV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bzJtRpGH2WXPt+EBF+XSrTkrGILFbdTPrO/JS65ARUeq23xgIl1+5Sai?= =?us-ascii?Q?gcA65foLfpQmcInfwqfNtlaUc1xUubS1P7O4BP8tdCT2zIGqA7JD59xoyy+6?= =?us-ascii?Q?Gk421mj8lBHpLfElN/U=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 081a73c8-18ac-45bf-a67c-08dc68d8f646 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Apr 2024 05:47:03.3760 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 4bE/So6h+BbXzrAdmumyIxMGtg4iZXEYFUPsFxfhE1bnHJn6CPYsJA8w5D3XfVSe2e0oup7WEXJqKvGRCbiDbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR11MB5010 X-OriginatorOrg: intel.com 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 Resent-Date: Mon, 29 Apr 2024 22:47:07 -0700 Resent-From: ray.ni@intel.com Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ilHxbVw0opJ2c1l0G0TeNlJSx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB8244E05949E0F6E0BCF8E76E8C1A2MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=fI0ki6kW; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io --_000_MN6PR11MB8244E05949E0F6E0BCF8E76E8C1A2MN6PR11MB8244namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Abdul, Does Amd PEI include the CpuMpPeim? If it includes the PEIM, the MpInformation2Hob should be in the HOB databas= e. Thanks, Ray ________________________________ From: Abdul Lateef Attar Sent: Monday, April 29, 2024 19:17 To: devel@edk2.groups.io Cc: Abdul Lateef Attar ; Ni, Ray ; Laszlo Ersek ; Kumar, Rahul R ; Gerd Hoffmann Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2= HobGuid If gMpInformation2HobGuid HOB is NULL, then fall back to an older way of collecting CPU information from the MP services library. Cc: Ray Ni Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Abdul Lateef Attar --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 87 +++++++++++++++++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 3 +- 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 499f979d34..74e494f332 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -3,7 +3,7 @@ Agent Module to load other modules to deploy SMM Entry Vect= or for X86 CPU. Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Incorporated. All rights reserved.
-Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved= .
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -750,6 +750,85 @@ MpInformation2HobCompare ( return 0; } +/** + Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for = all CPU from gEfiMpServiceProtocolGuid. + + @param[out] NumberOfCpus Pointer to NumberOfCpus. + @param[out] MaxNumberOfCpus Pointer to MaxNumberOfCpus. + + @retval ProcessorInfo Pointer to EFI_PROCESSOR_INFORMATION = buffer. +**/ +EFI_PROCESSOR_INFORMATION * +GetMpInformationFromMpServices ( + OUT UINTN *NumberOfCpus, + OUT UINTN *MaxNumberOfCpus + ) +{ + EFI_STATUS Status; + UINTN Index; + UINTN NumberOfEnabledProcessors; + UINTN NumberOfProcessors; + EFI_MP_SERVICES_PROTOCOL *MpService; + EFI_PROCESSOR_INFORMATION *ProcessorInfo; + + if ((NumberOfCpus =3D=3D NULL) || (MaxNumberOfCpus =3D=3D NULL)) { + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); + return NULL; + } + + ProcessorInfo =3D NULL; + *NumberOfCpus =3D 0; + *MaxNumberOfCpus =3D 0; + + /// Get the MP Services Protocol + Status =3D gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID = **)&MpService); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + /// Get the number of processors + Status =3D MpService->GetNumberOfProcessors (MpService, &NumberOfProcess= ors, &NumberOfEnabledProcessors); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + ASSERT (NumberOfProcessors <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r)); + + /// Allocate buffer for processor information + ProcessorInfo =3D AllocateZeroPool (sizeof (EFI_PROCESSOR_INFORMATION) *= NumberOfProcessors); + if (ProcessorInfo =3D=3D NULL) { + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return NULL; + } + + /// Get processor information + for (Index =3D 0; Index < NumberOfProcessors; Index++) { + Status =3D MpService->GetProcessorInfo (MpService, Index | CPU_V2_EXTE= NDED_TOPOLOGY, &ProcessorInfo[Index]); + if (EFI_ERROR (Status)) { + FreePool (ProcessorInfo); + DEBUG ((DEBUG_ERROR, "%a: Failed to get processor information for pr= ocessor %d\n", __func__, Index)); + ASSERT_EFI_ERROR (Status); + return NULL; + } + } + + *NumberOfCpus =3D NumberOfEnabledProcessors; + + ASSERT (*NumberOfCpus <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + // + // 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 *NumberOfCpus; + } + + return ProcessorInfo; +} + /** Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for = all CPU from MpInformation2 HOB. @@ -784,7 +863,11 @@ GetMpInformation ( HobCount =3D 0; FirstMpInfo2Hob =3D GetFirstGuidHob (&gMpInformation2HobGuid); - ASSERT (FirstMpInfo2Hob !=3D NULL); + if (FirstMpInfo2Hob =3D=3D NULL) { + DEBUG ((DEBUG_INFO, "%a: [INFO] gMpInformation2HobGuid HOB not found.\= n", __func__)); + return GetMpInformationFromMpServices (NumberOfCpus, MaxNumberOfCpus); + } + GuidHob =3D FirstMpInfo2Hob; while (GuidHob !=3D NULL) { MpInformation2HobData =3D GET_GUID_HOB_DATA (GuidHob); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index a018954ed7..db99a63c5a 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -6,7 +6,7 @@ # # Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.
# Copyright (c) 2017, AMD Incorporated. All rights reserved.
-# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -114,6 +114,7 @@ gEdkiiSmmMemoryAttributeProtocolGuid ## PRODUCES gEfiMmMpProtocolGuid ## PRODUCES gEdkiiSmmCpuRendezvousProtocolGuid ## PRODUCES + gEfiMpServiceProtocolGuid ## CONSUMES [Guids] gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # = it is used for S3 boot. -- 2.34.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 (#118412): https://edk2.groups.io/g/devel/message/118412 Mute This Topic: https://groups.io/mt/105798412/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB8244E05949E0F6E0BCF8E76E8C1A2MN6PR11MB8244namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Abdul,
Does Amd PEI include the CpuMpPeim?
If it includes the PEIM, the MpInformation2Hob should be in the HOB databas= e.

Thanks,
Ray

From: Abdul Lateef Attar &l= t;AbdulLateef.Attar@amd.com>
Sent: Monday, April 29, 2024 19:17
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>; Ni, Ray &l= t;ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahu= l R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com>= ;
Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInfor= mation2HobGuid
 
If gMpInformation2HobGuid HOB is NULL,
then fall back to an older way of collecting
CPU information from the MP services library.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c   | 87 +++++++++= ++++++++++-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf |  3 +-
 2 files changed, 87 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c
index 499f979d34..74e494f332 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -3,7 +3,7 @@ Agent Module to load other modules to deploy SMM Entry Vect= or for X86 CPU.
 
 Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<= ;BR>
 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR><= br> -Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<BR= >
+Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserved= .<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -750,6 +750,85 @@ MpInformation2HobCompare (
   return 0;
 }
 
+/**
+  Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION= for all CPU from gEfiMpServiceProtocolGuid.
+
+  @param[out] NumberOfCpus       &= nbsp;   Pointer to NumberOfCpus.
+  @param[out] MaxNumberOfCpus      &nbs= p; Pointer to MaxNumberOfCpus.
+
+  @retval ProcessorInfo       &nbs= p;      Pointer to EFI_PROCESSOR_INFORMATION buffe= r.
+**/
+EFI_PROCESSOR_INFORMATION *
+GetMpInformationFromMpServices (
+  OUT UINTN  *NumberOfCpus,
+  OUT UINTN  *MaxNumberOfCpus
+  )
+{
+  EFI_STATUS         &nb= sp;       Status;
+  UINTN          &n= bsp;           Index;
+  UINTN          &n= bsp;           NumberOfEn= abledProcessors;
+  UINTN          &n= bsp;           NumberOfPr= ocessors;
+  EFI_MP_SERVICES_PROTOCOL   *MpService;
+  EFI_PROCESSOR_INFORMATION  *ProcessorInfo;
+
+  if ((NumberOfCpus =3D=3D NULL) || (MaxNumberOfCpus =3D=3D NULL)) {<= br> +    ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);
+    return NULL;
+  }
+
+  ProcessorInfo    =3D NULL;
+  *NumberOfCpus    =3D 0;
+  *MaxNumberOfCpus =3D 0;
+
+  /// Get the MP Services Protocol
+  Status =3D gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, = NULL, (VOID **)&MpService);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return NULL;
+  }
+
+  /// Get the number of processors
+  Status =3D MpService->GetNumberOfProcessors (MpService, &Num= berOfProcessors, &NumberOfEnabledProcessors);
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return NULL;
+  }
+
+  ASSERT (NumberOfProcessors <=3D PcdGet32 (PcdCpuMaxLogicalProces= sorNumber));
+
+  /// Allocate buffer for processor information
+  ProcessorInfo =3D AllocateZeroPool (sizeof (EFI_PROCESSOR_INFORMATI= ON) * NumberOfProcessors);
+  if (ProcessorInfo =3D=3D NULL) {
+    ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES);
+    return NULL;
+  }
+
+  /// Get processor information
+  for (Index =3D 0; Index < NumberOfProcessors; Index++) {
+    Status =3D MpService->GetProcessorInfo (MpService, I= ndex | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo[Index]);
+    if (EFI_ERROR (Status)) {
+      FreePool (ProcessorInfo);
+      DEBUG ((DEBUG_ERROR, "%a: Failed to ge= t processor information for processor %d\n", __func__, Index));
+      ASSERT_EFI_ERROR (Status);
+      return NULL;
+    }
+  }
+
+  *NumberOfCpus =3D NumberOfEnabledProcessors;
+
+  ASSERT (*NumberOfCpus <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNu= mber));
+  //
+  // If support CPU hot plug, we need to allocate resources for possi= bly hot-added processors
+  //
+  if (FeaturePcdGet (PcdCpuHotPlugSupport)) {
+    *MaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcesso= rNumber);
+  } else {
+    *MaxNumberOfCpus =3D *NumberOfCpus;
+  }
+
+  return ProcessorInfo;
+}
+
 /**
   Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORM= ATION for all CPU from MpInformation2 HOB.
 
@@ -784,7 +863,11 @@ GetMpInformation (
   HobCount         =      =3D 0;
 
   FirstMpInfo2Hob =3D GetFirstGuidHob (&gMpInformation2HobGu= id);
-  ASSERT (FirstMpInfo2Hob !=3D NULL);
+  if (FirstMpInfo2Hob =3D=3D NULL) {
+    DEBUG ((DEBUG_INFO, "%a: [INFO] gMpInformation2Hob= Guid HOB not found.\n", __func__));
+    return GetMpInformationFromMpServices (NumberOfCpus, Ma= xNumberOfCpus);
+  }
+
   GuidHob =3D FirstMpInfo2Hob;
   while (GuidHob !=3D NULL) {
     MpInformation2HobData =3D GET_GUID_HOB_DATA (GuidH= ob);
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf
index a018954ed7..db99a63c5a 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf
@@ -6,7 +6,7 @@
 #
 # Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.&= lt;BR>
 # Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>= ;
-# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.<= BR>
+# Copyright (C) 2023 - 2024 Advanced Micro Devices, Inc. All rights reserv= ed.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -114,6 +114,7 @@
   gEdkiiSmmMemoryAttributeProtocolGuid     #= # PRODUCES
   gEfiMmMpProtocolGuid       =             &nb= sp; ## PRODUCES
   gEdkiiSmmCpuRendezvousProtocolGuid    &nbs= p;  ## PRODUCES
+  gEfiMpServiceProtocolGuid       =          ## CONSUMES
 
 [Guids]
   gEfiAcpiVariableGuid       =             &nb= sp; ## SOMETIMES_CONSUMES ## HOB # it is used for S3 boot.
--
2.34.1

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#118412) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB8244E05949E0F6E0BCF8E76E8C1A2MN6PR11MB8244namp_--