From 94941c8853448c1d2f72f90f7fedebd71035fe00 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Mon, 19 Oct 2015 19:08:47 +0000 Subject: [PATCH] UefiCpuPkg: CpuDxe: broadcast MTRR changes to APs The Quark_EDKII_v1.1.0/IA32FamilyCpuBasePkg/CpuArchDxe driver applies any MTRR changes to APs, if the EFI_MP_SERVICES_PROTOCOL is available. We should do the same. Additionally, the broadcast should occur at MP startup as well, not only when MTRR settings are changed. The inspiration is taken from Quark_EDKII_v1.1.0/IA32FamilyCpuBasePkg/CpuMpDxe/ (see the EarlyMpInit() function and its call sites in "ProcessorConfig.c"). Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Jeff Fan Reviewed-by: Michael Kinney git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18632 6f19259b-4bc3-4df7-8a09-765794883524 --- UefiCpuPkg/CpuDxe/CpuDxe.c | 26 ++++++++++++++++++++++++++ UefiCpuPkg/CpuDxe/CpuMp.c | 32 ++++++++++++++++++++++++++++++++ UefiCpuPkg/CpuDxe/CpuMp.h | 13 +++++++++++++ 3 files changed, 71 insertions(+) diff --git a/UefiCpuPkg/CpuDxe/CpuDxe.c b/UefiCpuPkg/CpuDxe/CpuDxe.c index c9df4e146a..daf97bd4a6 100644 --- a/UefiCpuPkg/CpuDxe/CpuDxe.c +++ b/UefiCpuPkg/CpuDxe/CpuDxe.c @@ -350,6 +350,9 @@ CpuSetMemoryAttributes ( { RETURN_STATUS Status; MTRR_MEMORY_CACHE_TYPE CacheType; + EFI_STATUS MpStatus; + EFI_MP_SERVICES_PROTOCOL *MpService; + MTRR_SETTINGS MtrrSettings; if (!IsMtrrSupported ()) { return EFI_UNSUPPORTED; @@ -405,6 +408,29 @@ CpuSetMemoryAttributes ( CacheType ); + if (!RETURN_ERROR (Status)) { + MpStatus = gBS->LocateProtocol ( + &gEfiMpServiceProtocolGuid, + NULL, + (VOID **)&MpService + ); + // + // Synchronize the update with all APs + // + if (!EFI_ERROR (MpStatus)) { + MtrrGetAllMtrrs (&MtrrSettings); + MpStatus = MpService->StartupAllAPs ( + MpService, // This + SetMtrrsFromBuffer, // Procedure + TRUE, // SingleThread + NULL, // WaitEvent + 0, // TimeoutInMicrosecsond + &MtrrSettings, // ProcedureArgument + NULL // FailedCpuList + ); + ASSERT (MpStatus == EFI_SUCCESS || MpStatus == EFI_NOT_STARTED); + } + } return (EFI_STATUS) Status; } diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c index f3a5a24b0f..04c2f1f0ac 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.c +++ b/UefiCpuPkg/CpuDxe/CpuMp.c @@ -1666,6 +1666,22 @@ ExitBootServicesCallback ( SendInitIpiAllExcludingSelf (); } +/** + A minimal wrapper function that allows MtrrSetAllMtrrs() to be passed to + EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() as Procedure. + + @param[in] Buffer Pointer to an MTRR_SETTINGS object, to be passed to + MtrrSetAllMtrrs(). +**/ +VOID +EFIAPI +SetMtrrsFromBuffer ( + IN VOID *Buffer + ) +{ + MtrrSetAllMtrrs (Buffer); +} + /** Initialize Multi-processor support. @@ -1676,6 +1692,7 @@ InitializeMpSupport ( ) { EFI_STATUS Status; + MTRR_SETTINGS MtrrSettings; UINTN Timeout; gMaxLogicalProcessorNumber = (UINTN) PcdGet32 (PcdCpuMaxLogicalProcessorNumber); @@ -1748,6 +1765,21 @@ InitializeMpSupport ( // CollectBistDataFromHob (); + // + // Synchronize MTRR settings to APs. + // + MtrrGetAllMtrrs (&MtrrSettings); + Status = mMpServicesTemplate.StartupAllAPs ( + &mMpServicesTemplate, // This + SetMtrrsFromBuffer, // Procedure + TRUE, // SingleThread + NULL, // WaitEvent + 0, // TimeoutInMicrosecsond + &MtrrSettings, // ProcedureArgument + NULL // FailedCpuList + ); + ASSERT (Status == EFI_SUCCESS || Status == EFI_NOT_STARTED); + Status = gBS->InstallMultipleProtocolInterfaces ( &mMpServiceHandle, &gEfiMpServiceProtocolGuid, &mMpServicesTemplate, diff --git a/UefiCpuPkg/CpuDxe/CpuMp.h b/UefiCpuPkg/CpuDxe/CpuMp.h index d2866e463b..503f3ae944 100644 --- a/UefiCpuPkg/CpuDxe/CpuMp.h +++ b/UefiCpuPkg/CpuDxe/CpuMp.h @@ -643,5 +643,18 @@ ResetApStackless ( IN UINT32 ProcessorId ); +/** + A minimal wrapper function that allows MtrrSetAllMtrrs() to be passed to + EFI_MP_SERVICES_PROTOCOL.StartupAllAPs() as Procedure. + + @param[in] Buffer Pointer to an MTRR_SETTINGS object, to be passed to + MtrrSetAllMtrrs(). +**/ +VOID +EFIAPI +SetMtrrsFromBuffer ( + IN VOID *Buffer + ); + #endif // _CPU_MP_H_ -- 2.39.2