提交 6f914f98 编写于 作者: V vit9696

Utilities: Let CPU decoder be tested externally

上级 c6f4de9e
......@@ -18,6 +18,7 @@ Utilities/ocvalidate/ocvalidate
Utilities/LogoutHook/nvramdump
Utilities/RsaTool/RsaTool
Utilities/TestBmf/Bmf
Utilities/TestCpuFrequency/CpuFrequency
Utilities/TestDiskImage/DiskImage
Utilities/TestHelloWorld/HelloWorld
Utilities/TestImg4/Img4
......
......@@ -211,6 +211,19 @@ OcCpuModelToAppleFamily (
IN CPUID_VERSION_INFO_EAX VersionEax
);
/**
Converts calculated CPU frequency in Hz to rounded
value in MHz.
@param[in] Frequency CPU frequency in Hz.
@return Rounded CPU frequency in MHz.
**/
UINT16
OcCpuFrequencyToDisplayFrequency (
IN UINT64 Frequency
);
/**
Obtain CPU's invariant TSC frequency.
......
......@@ -658,3 +658,31 @@ OcCpuModelToAppleFamily (
return CPUFAMILY_UNKNOWN;
}
}
UINT16
OcCpuFrequencyToDisplayFrequency (
IN UINT64 Frequency
)
{
UINT16 MhzSpeed;
UINT16 MhzRemainder;
//
// Round to nearest in MHz
//
MhzSpeed = (UINT16) DivU64x32 (Frequency + 500000, 1000000);
MhzRemainder = MhzSpeed % 100;
//
// Round to two digits when the second digit is above zero or to one otherwise.
// REF: https://github.com/acidanthera/bugtracker/issues/1521
//
if (MhzRemainder >= 60 && MhzRemainder < 90) {
MhzSpeed = (MhzSpeed) / 10 * 10;
} else if (MhzRemainder >= 12 && MhzRemainder < 90) {
MhzSpeed = (MhzSpeed + 5) / 10 * 10;
} else {
MhzSpeed = (MhzSpeed + 50) / 100 * 100;
}
return MhzSpeed;
}
......@@ -388,7 +388,6 @@ PatchProcessorInformation (
UINT8 StringIndex;
UINT8 TmpCount;
UINT16 MhzSpeed;
UINT16 MhzRemainder;
Original = SmbiosGetOriginalStructure (SMBIOS_TYPE_PROCESSOR_INFORMATION, 1);
MinLength = sizeof (*Original.Standard.Type4);
......@@ -407,30 +406,7 @@ PatchProcessorInformation (
SMBIOS_OVERRIDE_V (Table, Standard.Type4->Voltage, Original, NULL, NULL);
Table->CurrentPtr.Standard.Type4->ExternalClock = CpuInfo->ExternalClock;
//
// Round to nearest in MHz
//
MhzSpeed = (UINT16) DivU64x32 (CpuInfo->CPUFrequency + 500000, 1000000);
MhzRemainder = MhzSpeed % 100;
//
// Round to two digits when the second digit is above zero or to one otherwise.
// REF: https://github.com/acidanthera/bugtracker/issues/1521
// 3506084610 Hz -> 3506 MHz i7 4770k (3.5)
// 3324999575 Hz -> 3325 MHz Xeon X5680 (3.33)
// 3324999977 Hz -> 3325 MHz Xeon X5680 (3.33)
// 3457999888 Hz -> 3458 MHz Xeon X5690 (3.46)
// 2666362112 Hz -> 2666 MHz C2Q Q9450 (2.66)
// 3058999712 Hz -> 3059 MHz Xeon X5675 (3.06)
// 1992617296 Hz -> 1993 MHz i7 2630QM (2.0)
// 3010680273 Hz -> 3011 MHz P4 530 (3.0)
//
if (MhzRemainder >= 60 && MhzRemainder < 90) {
MhzSpeed = (MhzSpeed) / 10 * 10;
} else if (MhzRemainder >= 12 && MhzRemainder < 90) {
MhzSpeed = (MhzSpeed + 5) / 10 * 10;
} else {
MhzSpeed = (MhzSpeed + 50) / 100 * 100;
}
MhzSpeed = OcCpuFrequencyToDisplayFrequency (CpuInfo->CPUFrequency);
DEBUG ((DEBUG_INFO, "OCSMB: CPU display frequency is %uMHz\n", MhzSpeed));
......
/** @file
Copyright (C) 2021, vit9696. All rights reserved.
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 <Library/OcCpuLib.h>
#include <Library/DebugLib.h>
#include <sys/time.h>
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct FREQUENCY_TEST_ {
UINT64 FrequencyHz;
UINT16 FrequencyMHz;
CONST CHAR8 *Model;
} FREQUENCY_TEST;
int main() {
STATIC FREQUENCY_TEST mTests[] = {
{ 3506084610 /* Hz */, 3500 /* MHz, Raw 3506 MHz */, "i7 4770K" },
{ 3324999575 /* Hz */, 3330 /* MHz, Raw 3325 MHz */, "Xeon X5680" },
{ 3324999977 /* Hz */, 3330 /* MHz, Raw 3325 MHz */, "Xeon X5680" },
{ 3457999888 /* Hz */, 3460 /* MHz, Raw 3458 MHz */, "Xeon X5690" },
{ 2666362112 /* Hz */, 2660 /* MHz, Raw 2666 MHz */, "C2Q Q9450" },
{ 3058999712 /* Hz */, 3060 /* MHz, Raw 3059 MHz */, "Xeon X5675" },
{ 1992617296 /* Hz */, 2000 /* MHz, Raw 1993 MHz */, "i7 2630QM" },
{ 3010680273 /* Hz */, 3000 /* MHz, Raw 3011 MHz */, "P4 530" },
};
int code = 0;
for (size_t i = 0; i < sizeof(mTests)/sizeof(mTests[0]); ++i) {
UINT16 Read = OcCpuFrequencyToDisplayFrequency (mTests[i].FrequencyHz);
if (Read != mTests[i].FrequencyMHz) {
DEBUG ((
DEBUG_WARN,
"Frequency %04u instead if %04u for %a\n",
Read,
mTests[i].FrequencyMHz,
mTests[i].Model
));
code = 1;
}
}
return code;
}
## @file
# Copyright (c) 2020, PMheart. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
##
PROJECT = CpuFrequency
PRODUCT = $(PROJECT)$(SUFFIX)
OBJS = $(PROJECT).o
include ../../User/Makefile
......@@ -12,6 +12,7 @@ buildutil() {
"ocpasswordgen"
"ocvalidate"
"TestBmf"
"TestCpuFrequency"
"TestDiskImage"
"TestHelloWorld"
"TestImg4"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册