* [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid @ 2024-04-29 11:17 Abdul Lateef Attar via groups.io 2024-04-30 5:47 ` Ni, Ray 0 siblings, 1 reply; 4+ messages in thread From: Abdul Lateef Attar via groups.io @ 2024-04-29 11:17 UTC (permalink / raw) To: devel; +Cc: Abdul Lateef Attar, Ray Ni, Laszlo Ersek, Rahul Kumar, Gerd Hoffmann 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/PiSmmCpuDxeSmm/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 Vector for X86 CPU. Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<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 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 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 == NULL) || (MaxNumberOfCpus == NULL)) { + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); + return NULL; + } + + ProcessorInfo = NULL; + *NumberOfCpus = 0; + *MaxNumberOfCpus = 0; + + /// Get the MP Services Protocol + Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpService); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + /// Get the number of processors + Status = MpService->GetNumberOfProcessors (MpService, &NumberOfProcessors, &NumberOfEnabledProcessors); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + ASSERT (NumberOfProcessors <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + + /// Allocate buffer for processor information + ProcessorInfo = AllocateZeroPool (sizeof (EFI_PROCESSOR_INFORMATION) * NumberOfProcessors); + if (ProcessorInfo == NULL) { + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return NULL; + } + + /// Get processor information + for (Index = 0; Index < NumberOfProcessors; Index++) { + Status = MpService->GetProcessorInfo (MpService, Index | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo[Index]); + if (EFI_ERROR (Status)) { + FreePool (ProcessorInfo); + DEBUG ((DEBUG_ERROR, "%a: Failed to get processor information for processor %d\n", __func__, Index)); + ASSERT_EFI_ERROR (Status); + return NULL; + } + } + + *NumberOfCpus = NumberOfEnabledProcessors; + + ASSERT (*NumberOfCpus <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + // + // If support CPU hot plug, we need to allocate resources for possibly hot-added processors + // + if (FeaturePcdGet (PcdCpuHotPlugSupport)) { + *MaxNumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + } else { + *MaxNumberOfCpus = *NumberOfCpus; + } + + return ProcessorInfo; +} + /** Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for all CPU from MpInformation2 HOB. @@ -784,7 +863,11 @@ GetMpInformation ( HobCount = 0; FirstMpInfo2Hob = GetFirstGuidHob (&gMpInformation2HobGuid); - ASSERT (FirstMpInfo2Hob != NULL); + if (FirstMpInfo2Hob == NULL) { + DEBUG ((DEBUG_INFO, "%a: [INFO] gMpInformation2HobGuid HOB not found.\n", __func__)); + return GetMpInformationFromMpServices (NumberOfCpus, MaxNumberOfCpus); + } + GuidHob = FirstMpInfo2Hob; while (GuidHob != NULL) { MpInformation2HobData = GET_GUID_HOB_DATA (GuidHob); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/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.<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 reserved.<BR> # # 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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118387): https://edk2.groups.io/g/devel/message/118387 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] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid 2024-04-29 11:17 [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid Abdul Lateef Attar via groups.io @ 2024-04-30 5:47 ` Ni, Ray 2024-04-30 7:45 ` Abdul Lateef Attar via groups.io 0 siblings, 1 reply; 4+ messages in thread From: Ni, Ray @ 2024-04-30 5:47 UTC (permalink / raw) To: Abdul Lateef Attar, devel@edk2.groups.io Cc: Laszlo Ersek, Kumar, Rahul R, Gerd Hoffmann [-- Attachment #1: Type: text/plain, Size: 6548 bytes --] Abdul, Does Amd PEI include the CpuMpPeim? If it includes the PEIM, the MpInformation2Hob should be in the HOB database. Thanks, Ray ________________________________ From: Abdul Lateef Attar <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 <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com> Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid 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/PiSmmCpuDxeSmm/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 Vector for X86 CPU. Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<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 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 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 == NULL) || (MaxNumberOfCpus == NULL)) { + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); + return NULL; + } + + ProcessorInfo = NULL; + *NumberOfCpus = 0; + *MaxNumberOfCpus = 0; + + /// Get the MP Services Protocol + Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpService); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + /// Get the number of processors + Status = MpService->GetNumberOfProcessors (MpService, &NumberOfProcessors, &NumberOfEnabledProcessors); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + ASSERT (NumberOfProcessors <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + + /// Allocate buffer for processor information + ProcessorInfo = AllocateZeroPool (sizeof (EFI_PROCESSOR_INFORMATION) * NumberOfProcessors); + if (ProcessorInfo == NULL) { + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return NULL; + } + + /// Get processor information + for (Index = 0; Index < NumberOfProcessors; Index++) { + Status = MpService->GetProcessorInfo (MpService, Index | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo[Index]); + if (EFI_ERROR (Status)) { + FreePool (ProcessorInfo); + DEBUG ((DEBUG_ERROR, "%a: Failed to get processor information for processor %d\n", __func__, Index)); + ASSERT_EFI_ERROR (Status); + return NULL; + } + } + + *NumberOfCpus = NumberOfEnabledProcessors; + + ASSERT (*NumberOfCpus <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + // + // If support CPU hot plug, we need to allocate resources for possibly hot-added processors + // + if (FeaturePcdGet (PcdCpuHotPlugSupport)) { + *MaxNumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + } else { + *MaxNumberOfCpus = *NumberOfCpus; + } + + return ProcessorInfo; +} + /** Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for all CPU from MpInformation2 HOB. @@ -784,7 +863,11 @@ GetMpInformation ( HobCount = 0; FirstMpInfo2Hob = GetFirstGuidHob (&gMpInformation2HobGuid); - ASSERT (FirstMpInfo2Hob != NULL); + if (FirstMpInfo2Hob == NULL) { + DEBUG ((DEBUG_INFO, "%a: [INFO] gMpInformation2HobGuid HOB not found.\n", __func__)); + return GetMpInformationFromMpServices (NumberOfCpus, MaxNumberOfCpus); + } + GuidHob = FirstMpInfo2Hob; while (GuidHob != NULL) { MpInformation2HobData = GET_GUID_HOB_DATA (GuidHob); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/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.<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 reserved.<BR> # # 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 -=-=-=-=-=-=-=-=-=-=-=- 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] -=-=-=-=-=-=-=-=-=-=-=- [-- Attachment #2: Type: text/html, Size: 11179 bytes --] ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid 2024-04-30 5:47 ` Ni, Ray @ 2024-04-30 7:45 ` Abdul Lateef Attar via groups.io 2024-05-06 3:11 ` Ni, Ray 0 siblings, 1 reply; 4+ messages in thread From: Abdul Lateef Attar via groups.io @ 2024-04-30 7:45 UTC (permalink / raw) To: Ni, Ray, devel@edk2.groups.io; +Cc: Laszlo Ersek, Kumar, Rahul R, Gerd Hoffmann [-- Attachment #1: Type: text/plain, Size: 7506 bytes --] Hi Ray, Some of AMD platform doesnt use CpuMpPeim. Also this patch helps not to enforce the platform to brinup all AP's in PEI phase. Thanks AbduL On 30-04-2024 11:17, Ni, Ray wrote: > > > Caution: This message originated from an External Source. Use proper > caution when opening attachments, clicking links, or responding. > > > Abdul, > Does Amd PEI include the CpuMpPeim? > If it includes the PEIM, the MpInformation2Hob should be in the HOB > database. > > Thanks, > Ray > ------------------------------------------------------------------------ > *From:* Abdul Lateef Attar <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 > <ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul R > <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com> > *Subject:* [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL > gMpInformation2HobGuid > 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/PiSmmCpuDxeSmm/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 > Vector for X86 CPU. > > Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<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 > 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 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 == NULL) || (MaxNumberOfCpus == NULL)) { > + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); > + return NULL; > + } > + > + ProcessorInfo = NULL; > + *NumberOfCpus = 0; > + *MaxNumberOfCpus = 0; > + > + /// Get the MP Services Protocol > + Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, > (VOID **)&MpService); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + return NULL; > + } > + > + /// Get the number of processors > + Status = MpService->GetNumberOfProcessors (MpService, > &NumberOfProcessors, &NumberOfEnabledProcessors); > + if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > + return NULL; > + } > + > + ASSERT (NumberOfProcessors <= PcdGet32 > (PcdCpuMaxLogicalProcessorNumber)); > + > + /// Allocate buffer for processor information > + ProcessorInfo = AllocateZeroPool (sizeof > (EFI_PROCESSOR_INFORMATION) * NumberOfProcessors); > + if (ProcessorInfo == NULL) { > + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); > + return NULL; > + } > + > + /// Get processor information > + for (Index = 0; Index < NumberOfProcessors; Index++) { > + Status = MpService->GetProcessorInfo (MpService, Index | > CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo[Index]); > + if (EFI_ERROR (Status)) { > + FreePool (ProcessorInfo); > + DEBUG ((DEBUG_ERROR, "%a: Failed to get processor information > for processor %d\n", __func__, Index)); > + ASSERT_EFI_ERROR (Status); > + return NULL; > + } > + } > + > + *NumberOfCpus = NumberOfEnabledProcessors; > + > + ASSERT (*NumberOfCpus <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); > + // > + // If support CPU hot plug, we need to allocate resources for > possibly hot-added processors > + // > + if (FeaturePcdGet (PcdCpuHotPlugSupport)) { > + *MaxNumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); > + } else { > + *MaxNumberOfCpus = *NumberOfCpus; > + } > + > + return ProcessorInfo; > +} > + > /** > Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION > for all CPU from MpInformation2 HOB. > > @@ -784,7 +863,11 @@ GetMpInformation ( > HobCount = 0; > > FirstMpInfo2Hob = GetFirstGuidHob (&gMpInformation2HobGuid); > - ASSERT (FirstMpInfo2Hob != NULL); > + if (FirstMpInfo2Hob == NULL) { > + DEBUG ((DEBUG_INFO, "%a: [INFO] gMpInformation2HobGuid HOB not > found.\n", __func__)); > + return GetMpInformationFromMpServices (NumberOfCpus, > MaxNumberOfCpus); > + } > + > GuidHob = FirstMpInfo2Hob; > while (GuidHob != NULL) { > MpInformation2HobData = GET_GUID_HOB_DATA (GuidHob); > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf > b/UefiCpuPkg/PiSmmCpuDxeSmm/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.<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 > reserved.<BR> > # > # 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 > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118421): https://edk2.groups.io/g/devel/message/118421 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] -=-=-=-=-=-=-=-=-=-=-=- [-- Attachment #2: Type: text/html, Size: 16657 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid 2024-04-30 7:45 ` Abdul Lateef Attar via groups.io @ 2024-05-06 3:11 ` Ni, Ray 0 siblings, 0 replies; 4+ messages in thread From: Ni, Ray @ 2024-05-06 3:11 UTC (permalink / raw) To: Attar, AbdulLateef (Abdul Lateef), devel@edk2.groups.io Cc: Laszlo Ersek, Kumar, Rahul R, Gerd Hoffmann [-- Attachment #1: Type: text/plain, Size: 7751 bytes --] Reviewed-by: Ray Ni <ray.ni@intel.com> Thanks, Ray ________________________________ From: Attar, AbdulLateef (Abdul Lateef) <AbdulLateef.Attar@amd.com> Sent: Tuesday, April 30, 2024 15:45 To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io <devel@edk2.groups.io> Cc: Laszlo Ersek <lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com> Subject: Re: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid Hi Ray, Some of AMD platform doesnt use CpuMpPeim. Also this patch helps not to enforce the platform to brinup all AP's in PEI phase. Thanks AbduL On 30-04-2024 11:17, Ni, Ray wrote: Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. Abdul, Does Amd PEI include the CpuMpPeim? If it includes the PEIM, the MpInformation2Hob should be in the HOB database. Thanks, Ray ________________________________ From: Abdul Lateef Attar <AbdulLateef.Attar@amd.com><mailto:AbdulLateef.Attar@amd.com> Sent: Monday, April 29, 2024 19:17 To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io><mailto:devel@edk2.groups.io> Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com><mailto:AbdulLateef.Attar@amd.com>; Ni, Ray <ray.ni@intel.com><mailto:ray.ni@intel.com>; Laszlo Ersek <lersek@redhat.com><mailto:lersek@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com><mailto:rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com><mailto:kraxel@redhat.com> Subject: [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid 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><mailto:ray.ni@intel.com> Cc: Laszlo Ersek <lersek@redhat.com><mailto:lersek@redhat.com> Cc: Rahul Kumar <rahul1.kumar@intel.com><mailto:rahul1.kumar@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com><mailto:kraxel@redhat.com> Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com><mailto: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/PiSmmCpuDxeSmm/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 Vector for X86 CPU. Copyright (c) 2009 - 2023, Intel Corporation. All rights reserved.<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 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 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 == NULL) || (MaxNumberOfCpus == NULL)) { + ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER); + return NULL; + } + + ProcessorInfo = NULL; + *NumberOfCpus = 0; + *MaxNumberOfCpus = 0; + + /// Get the MP Services Protocol + Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpService); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + /// Get the number of processors + Status = MpService->GetNumberOfProcessors (MpService, &NumberOfProcessors, &NumberOfEnabledProcessors); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return NULL; + } + + ASSERT (NumberOfProcessors <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + + /// Allocate buffer for processor information + ProcessorInfo = AllocateZeroPool (sizeof (EFI_PROCESSOR_INFORMATION) * NumberOfProcessors); + if (ProcessorInfo == NULL) { + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return NULL; + } + + /// Get processor information + for (Index = 0; Index < NumberOfProcessors; Index++) { + Status = MpService->GetProcessorInfo (MpService, Index | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo[Index]); + if (EFI_ERROR (Status)) { + FreePool (ProcessorInfo); + DEBUG ((DEBUG_ERROR, "%a: Failed to get processor information for processor %d\n", __func__, Index)); + ASSERT_EFI_ERROR (Status); + return NULL; + } + } + + *NumberOfCpus = NumberOfEnabledProcessors; + + ASSERT (*NumberOfCpus <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + // + // If support CPU hot plug, we need to allocate resources for possibly hot-added processors + // + if (FeaturePcdGet (PcdCpuHotPlugSupport)) { + *MaxNumberOfCpus = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + } else { + *MaxNumberOfCpus = *NumberOfCpus; + } + + return ProcessorInfo; +} + /** Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for all CPU from MpInformation2 HOB. @@ -784,7 +863,11 @@ GetMpInformation ( HobCount = 0; FirstMpInfo2Hob = GetFirstGuidHob (&gMpInformation2HobGuid); - ASSERT (FirstMpInfo2Hob != NULL); + if (FirstMpInfo2Hob == NULL) { + DEBUG ((DEBUG_INFO, "%a: [INFO] gMpInformation2HobGuid HOB not found.\n", __func__)); + return GetMpInformationFromMpServices (NumberOfCpus, MaxNumberOfCpus); + } + GuidHob = FirstMpInfo2Hob; while (GuidHob != NULL) { MpInformation2HobData = GET_GUID_HOB_DATA (GuidHob); diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/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.<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 reserved.<BR> # # 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 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118584): https://edk2.groups.io/g/devel/message/118584 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] -=-=-=-=-=-=-=-=-=-=-=- [-- Attachment #2: Type: text/html, Size: 14591 bytes --] ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-06 3:11 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-04-29 11:17 [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: Handle the NULL gMpInformation2HobGuid Abdul Lateef Attar via groups.io 2024-04-30 5:47 ` Ni, Ray 2024-04-30 7:45 ` Abdul Lateef Attar via groups.io 2024-05-06 3:11 ` Ni, Ray
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox