diff --git a/Application/VerifyMsrE2/VerifyMsrE2.c b/Application/VerifyMsrE2/VerifyMsrE2.c new file mode 100644 index 00000000..ec8e3922 --- /dev/null +++ b/Application/VerifyMsrE2/VerifyMsrE2.c @@ -0,0 +1,101 @@ +/** @file + Verify MSR 0xE2 status on all the processors. + +Copyright (c) 2018, vit9696. All rights reserved.
+This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC EFI_MP_SERVICES_PROTOCOL *mMpServices; +STATIC UINTN mHasLockedCores; +STATIC UINTN mHasUnlockedCores; + +VOID +EFIAPI +ReadMsrE2 ( + IN VOID *Buffer + ) +{ + UINTN ProcNum = 0; + MSR_BROADWELL_PKG_CST_CONFIG_CONTROL_REGISTER Value; + EFI_STATUS Status; + + Status = mMpServices->WhoAmI (mMpServices, &ProcNum); + + if (EFI_ERROR (Status)) { + Print (L"Failed to detect CPU Number\n"); + } + + Value.Uint64 = AsmReadMsr64 (MSR_BROADWELL_PKG_CST_CONFIG_CONTROL); + + Print (L"CPU%02d has MSR 0xE2: 0x%016LX\n", ProcNum, Value.Uint64); + + if (Value.Bits.CFGLock) { + mHasLockedCores = 1; + } else { + mHasUnlockedCores = 1; + } +} + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + Print (L"Looking up EFI_MP_SERVICES_PROTOCOL...\n"); + + Status = gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&mMpServices); + if (EFI_ERROR (Status)) { + Print (L"Failed to find EFI_MP_SERVICES_PROTOCOL - %r\n", Status); + return Status; + } + + Print (L"Checking MSR 0xE2 on all CPUs. Values must be SAME!!!\n"); + + ReadMsrE2 (NULL); + + Print (L"Starting All APs to verify 0xE2 register...\n", Status); + + Status = mMpServices->StartupAllAPs (mMpServices, ReadMsrE2, TRUE, NULL, 5000000, NULL, NULL); + if (EFI_ERROR (Status)) { + Print (L"Failed to StartupAllAPs - %r\n", Status); + return Status; + } + + Print (L"Done checking MSR 0xE2 register, compare the values printed!\n"); + + if (mHasLockedCores && mHasUnlockedCores) { + Print (L"This firmware has BORKED MSR 0xE2 register!\n"); + Print (L"Some cores are locked, some are not!!!\n"); + } else if (mHasUnlockedCores) { + Print (L"This firmware has UNLOCKED MSR 0xE2 register!\n"); + } else { + Print (L"This firmware has LOCKED MSR 0xE2 register!\n"); + } + + gBS->Stall (SECONDS_TO_MICROSECONDS (3)); + + return EFI_SUCCESS; +} diff --git a/Application/VerifyMsrE2/VerifyMsrE2.inf b/Application/VerifyMsrE2/VerifyMsrE2.inf new file mode 100644 index 00000000..1364d3bd --- /dev/null +++ b/Application/VerifyMsrE2/VerifyMsrE2.inf @@ -0,0 +1,51 @@ +## @file +# Viery MSR 0xE2 status on all the processors. +# +# Copyright (c) 2018, vit9696. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = VerifyMsrE2 + FILE_GUID = 9031CCA3-EF7A-4D36-ADCA-F75802085D32 + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiMain + +# +# This flag specifies whether HII resource section is generated into PE image. +# + UEFI_HII_RESOURCE_SECTION = TRUE + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[Sources] + VerifyMsrE2.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + OcSupportPkg/OcSupportPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[Protocols] + gEfiMpServiceProtocolGuid ## CONSUMES + +[LibraryClasses] + OcConsoleControlEntryModeLib + UefiApplicationEntryPoint + UefiLib + PcdLib + IoLib diff --git a/OcSupportPkg.dsc b/OcSupportPkg.dsc index aec988cd..c70a515e 100644 --- a/OcSupportPkg.dsc +++ b/OcSupportPkg.dsc @@ -99,6 +99,7 @@ OcXmlLib|OcSupportPkg/Library/OcXmlLib/OcXmlLib.inf [Components] + OcSupportPkg/Application/VerifyMsrE2/VerifyMsrE2.inf OcSupportPkg/Library/OcAcpiLib/OcAcpiLib.inf OcSupportPkg/Library/OcAppleBootCompatLib/OcAppleBootCompatLib.inf OcSupportPkg/Library/OcAppleBootPolicyLib/OcAppleBootPolicyLib.inf