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 3C9EF740035 for ; Thu, 9 May 2024 00:09:30 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=H9WbkSyO0JTZ8ZGkUD1QO1dwaeLbEFGsJ+fYw1j15J8=; 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:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1715213368; v=1; b=MmSde7Wp04HobqjJbazaXNOj9MNCsiYFetbGoC/aDtTR199ACqMsTAZlrbCH51aopIT4hmA4 i8+gNobc319uisiPtej4hfwGwTuY5Sgb29EG4cz1bzve0HEsrcBT5RFPdOf9tc31w1L8h4N7CAU LJe6mq57ZrSwdcmEovjWwc3hIxZJNNAVp42R4f/pno5pywHAIhnTOVke1VjqAHEhOt8cZ0hlMLf c8BzoIiBEIyn3k3j19jv1c5RSszQ6zQBflnt6T2bpoFCQp2DnPXItz9q3BZwzPdnRf8/bniKUQT lQhIhb4vRgWCqCLbItpH2TNTk3/ff+lkfdR3xz0343+0w== X-Received: by 127.0.0.2 with SMTP id rm3aYY7687511x6L3UvjYq4h; Wed, 08 May 2024 17:09:28 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by mx.groups.io with SMTP id smtpd.web10.2567.1715213366885136606 for ; Wed, 08 May 2024 17:09:27 -0700 X-CSE-ConnectionGUID: 5sGWSBnLTSy8vsAa5ShtpQ== X-CSE-MsgGUID: zwAXBY9GTpWbyxnLkMYaRw== X-IronPort-AV: E=McAfee;i="6600,9927,11067"; a="11044570" X-IronPort-AV: E=Sophos;i="6.08,146,1712646000"; d="scan'208";a="11044570" X-Received: from orviesa003.jf.intel.com ([10.64.159.143]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 17:09:27 -0700 X-CSE-ConnectionGUID: 5BpbfXyBSZGX8UH7DLHXQg== X-CSE-MsgGUID: +wwTuCf3TYekVfcC3FyWWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,146,1712646000"; d="scan'208";a="33745134" X-Received: from nldesimo-desk.amr.corp.intel.com ([10.241.240.67]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2024 17:09:27 -0700 From: "Nate DeSimone" To: devel@edk2.groups.io Cc: Chasel Chiu , Liming Gao , Eric Dong , Sai Chaganty , Rosen Chuang , Saloni Kasbekar Subject: [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei Date: Wed, 8 May 2024 17:09:17 -0700 Message-ID: <20240509000918.2336-2-nathaniel.l.desimone@intel.com> In-Reply-To: <20240509000918.2336-1-nathaniel.l.desimone@intel.com> References: <20240509000918.2336-1-nathaniel.l.desimone@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 Resent-Date: Wed, 08 May 2024 17:09:27 -0700 Resent-From: nathaniel.l.desimone@intel.com Reply-To: devel@edk2.groups.io,nathaniel.l.desimone@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: osPzb6NP84rC720EKi2skNY3x7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=MmSde7Wp; 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 MpInfo2HobPei provides backwards compatibility between FSP binaries built with older versions of EDK II and the latest EDK II. Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is required by newer implementations of the CPU DXE driver, however older versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei creates gMpInformation2HobGuid and if it does not it creates it. Cc: Chasel Chiu Cc: Liming Gao Cc: Eric Dong Cc: Sai Chaganty Cc: Rosen Chuang Cc: Saloni Kasbekar Signed-off-by: Nate DeSimone --- .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c | 236 ++++++++++++++++++ .../MpInfo2HobPei/MpInfo2HobPei.inf | 47 ++++ .../Intel/MinPlatformPkg/MinPlatformPkg.dsc | 3 +- 3 files changed, 285 insertions(+), 1 deletion(-) create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c new file mode 100644 index 0000000000..4cbc4cf7e6 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c @@ -0,0 +1,236 @@ +/** @file + Multi-processor Info 2 HOB PEIM. + + The purpose of this PEIM is to provide backwards compatibility between FSP + binaries built with older versions of EDK II and the latest EDK II. + + Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is + required by newer implementations of the CPU DXE driver, however older + versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei + creates gMpInformation2HobGuid and if it does not it creates it. + +Copyright (c) 2024, Intel Corporation. All rights reserved.
+ +SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +typedef struct { + EDKII_PEI_MP_SERVICES2_PPI *CpuMpPpi2; + UINT8 *CoreTypes; +} GET_PROCESSOR_CORE_TYPE_BUFFER; + +/** + Get CPU core type. + + @param[in, out] Buffer Argument of the procedure. +**/ +VOID +EFIAPI +GetProcessorCoreType ( + IN OUT VOID *Buffer + ) +{ + EFI_STATUS Status; + UINT8 *CoreTypes; + CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX NativeModelIdAndCoreTypeEax; + UINTN ProcessorIndex; + GET_PROCESSOR_CORE_TYPE_BUFFER *Params; + + Params = (GET_PROCESSOR_CORE_TYPE_BUFFER *)Buffer; + Status = Params->CpuMpPpi2->WhoAmI (Params->CpuMpPpi2, &ProcessorIndex); + ASSERT_EFI_ERROR (Status); + + CoreTypes = Params->CoreTypes; + AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL); + CoreTypes[ProcessorIndex] = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType; +} + +/** + Create gMpInformation2HobGuid. +**/ +VOID +BuildMpInformationHob ( + IN EDKII_PEI_MP_SERVICES2_PPI *CpuMpPpi2 + ) +{ + GET_PROCESSOR_CORE_TYPE_BUFFER Buffer; + EFI_STATUS Status; + UINTN ProcessorIndex; + UINTN NumberOfProcessors; + UINTN NumberOfEnabledProcessors; + UINTN NumberOfProcessorsInHob; + UINTN MaxProcessorsPerHob; + MP_INFORMATION2_HOB_DATA *MpInformation2HobData; + MP_INFORMATION2_ENTRY *MpInformation2Entry; + UINTN Index; + UINT8 *CoreTypes; + UINT32 CpuidMaxInput; + UINTN CoreTypePages; + + ProcessorIndex = 0; + MpInformation2HobData = NULL; + MpInformation2Entry = NULL; + CoreTypes = NULL; + CoreTypePages = 0; + + Status = CpuMpPpi2->GetNumberOfProcessors ( + CpuMpPpi2, + &NumberOfProcessors, + &NumberOfEnabledProcessors + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Get Processors CoreType + // + AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL); + if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) { + CoreTypePages = EFI_SIZE_TO_PAGES (sizeof (UINT8) * NumberOfProcessors); + CoreTypes = AllocatePages (CoreTypePages); + ASSERT (CoreTypes != NULL); + if (CoreTypes == NULL) { + goto Done; + } + + Buffer.CoreTypes = CoreTypes; + Buffer.CpuMpPpi2 = CpuMpPpi2; + Status = CpuMpPpi2->StartupAllCPUs ( + CpuMpPpi2, + GetProcessorCoreType, + 0, + (VOID *)&Buffer + ); + ASSERT_EFI_ERROR (Status); + } + + MaxProcessorsPerHob = ((MAX_UINT16 & ~7) - sizeof (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof (MP_INFORMATION2_ENTRY); + NumberOfProcessorsInHob = MaxProcessorsPerHob; + + // + // Create MP_INFORMATION2_HOB. when the max HobLength 0xFFF8 is not enough, there + // will be a MP_INFORMATION2_HOB series in the HOB list. + // In the HOB list, there is a gMpInformation2HobGuid with 0 value NumberOfProcessors + // fields to indicate it's the last MP_INFORMATION2_HOB. + // + while (NumberOfProcessorsInHob != 0) { + NumberOfProcessorsInHob = MIN (NumberOfProcessors - ProcessorIndex, MaxProcessorsPerHob); + MpInformation2HobData = BuildGuidHob ( + &gMpInformation2HobGuid, + sizeof (MP_INFORMATION2_HOB_DATA) + sizeof (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob + ); + ASSERT (MpInformation2HobData != NULL); + if (MpInformation2HobData == NULL) { + goto Done; + } + + MpInformation2HobData->Version = MP_INFORMATION2_HOB_REVISION; + MpInformation2HobData->ProcessorIndex = ProcessorIndex; + MpInformation2HobData->NumberOfProcessors = (UINT16)NumberOfProcessorsInHob; + MpInformation2HobData->EntrySize = sizeof (MP_INFORMATION2_ENTRY); + + DEBUG ((DEBUG_INFO, "Creating MpInformation2 HOB...\n")); + + for (Index = 0; Index < NumberOfProcessorsInHob; Index++) { + MpInformation2Entry = &MpInformation2HobData->Entry[Index]; + Status = CpuMpPpi2->GetProcessorInfo ( + CpuMpPpi2, + (Index + ProcessorIndex) | CPU_V2_EXTENDED_TOPOLOGY, + &MpInformation2Entry->ProcessorInfo + ); + ASSERT_EFI_ERROR (Status); + + MpInformation2Entry->CoreType = (CoreTypes != NULL) ? CoreTypes[Index + ProcessorIndex] : 0; + + DEBUG (( + DEBUG_INFO, + " Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x, CoreType = 0x%x\n", + Index + ProcessorIndex, + MpInformation2Entry->ProcessorInfo.ProcessorId, + MpInformation2Entry->ProcessorInfo.StatusFlag, + MpInformation2Entry->CoreType + )); + DEBUG (( + DEBUG_INFO, + " Location = Package:%d Core:%d Thread:%d\n", + MpInformation2Entry->ProcessorInfo.Location.Package, + MpInformation2Entry->ProcessorInfo.Location.Core, + MpInformation2Entry->ProcessorInfo.Location.Thread + )); + DEBUG (( + DEBUG_INFO, + " Location2 = Package:%d Die:%d Tile:%d Module:%d Core:%d Thread:%d\n", + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Package, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Die, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Tile, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Module, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Core, + MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Thread + )); + } + + ProcessorIndex += NumberOfProcessorsInHob; + } + +Done: + if (CoreTypes != NULL) { + FreePages (CoreTypes, CoreTypePages); + } +} + +/** + Check if CpuMpPei creates gMpInformation2HobGuid and if it does not it + creates it. + + @param[in] ImageHandle Handle for the image of this driver + @param[in] SystemTable Pointer to the EFI System Table + + @retval EFI_UNSUPPORTED +**/ +EFI_STATUS +EFIAPI +MpInfo2HobPeiEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status; + EFI_PEI_PPI_DESCRIPTOR *TempPpiDescriptor; + EDKII_PEI_MP_SERVICES2_PPI *CpuMpPpi2; + EFI_HOB_GUID_TYPE *GuidHob; + + Status = PeiServicesLocatePpi ( + &gEdkiiPeiMpServices2PpiGuid, + 0, + &TempPpiDescriptor, + (VOID **)&CpuMpPpi2 + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + goto Done; + } + + GuidHob = GetFirstGuidHob (&gMpInformation2HobGuid); + if (GuidHob == NULL) { + DEBUG ((DEBUG_INFO, "gMpInformation2HobGuid was not created by CpuMpPei, creating now\n")); + BuildMpInformationHob (CpuMpPpi2); + } + +Done: + return Status; +} diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf new file mode 100644 index 0000000000..eecfdbf422 --- /dev/null +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf @@ -0,0 +1,47 @@ +### @file +# Component information file for the Multi-processor Info 2 HOB PEIM. +# +# The purpose of this PEIM is to provide backwards compatibility between FSP +# binaries built with older versions of EDK II and the latest EDK II. +# +# Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is +# required by newer implementations of the CPU DXE driver, however older +# versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei +# creates gMpInformation2HobGuid and if it does not it creates it. +# +# Copyright (c) 2024, Intel Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +### + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = MpInfo2HobPei + FILE_GUID = 010B5607-D5B3-4302-BCBC-C1A68087E9BE + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + ENTRY_POINT = MpInfo2HobPeiEntryPoint + +[LibraryClasses] + PeimEntryPoint + DebugLib + MemoryAllocationLib + HobLib + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + MinPlatformPkg/MinPlatformPkg.dec + +[Sources] + MpInfo2HobPei.c + +[Guids] + gMpInformation2HobGuid ## SOMETIMES_PRODUCES ## HOB + +[Ppis] + gEdkiiPeiMpServices2PpiGuid ## CONSUMES + +[Depex] + gEdkiiPeiMpServices2PpiGuid diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc index ecb4d8f65e..30cdf1fb82 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc @@ -1,7 +1,7 @@ ## @file # Platform description. # -# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -150,6 +150,7 @@ MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf + MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf -- 2.44.0.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118707): https://edk2.groups.io/g/devel/message/118707 Mute This Topic: https://groups.io/mt/105992897/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-