提交 b7734fc3 编写于 作者: V vit9696

Fix FSBFrequency and thread count detection on Penryn

上级 30fb8799
......@@ -47,7 +47,6 @@ typedef struct {
UINT8 CurBusRatio; ///< Current Multiplier
UINT8 MinBusRatio; ///< Min Bus Ratio
UINT8 MaxBusRatio; ///< Max Bus Ratio
UINT8 MaxBusRatioDiv;
UINT8 TurboBusRatio1;
UINT8 TurboBusRatio2;
......@@ -65,14 +64,25 @@ typedef struct {
} OC_CPU_INFO;
// OcCpuScanProcessor
/** Scan the processor and fill the cpu info structure with results
/**
Scan the processor and fill the cpu info structure with results.
@param[in] Cpu A pointer to the cpu info structure to fill with results
@param[in] Cpu A pointer to the cpu info structure to fill with results.
**/
VOID
OcCpuScanProcessor (
IN OUT OC_CPU_INFO *Cpu
);
/**
Disable flex ratio if it has invalid value.
Commonly fixes early reboot on APTIO IV (Ivy/Haswell).
@param[in] Cpu A pointer to the cpu info.
**/
VOID
OcCpuCorrectFlexRatio (
IN OC_CPU_INFO *Cpu
);
#endif // OC_CPU_LIB_H_
......@@ -587,12 +587,21 @@ ScanIntelProcessor (
//
if (Cpu->Model >= CPU_MODEL_NEHALEM) {
PerfStatus.Uint64 = AsmReadMsr64 (MSR_IA32_PERF_STATUS);
Cpu->CurBusRatio = (UINT8) (PerfStatus.Bits.State >> 8U);
PlatformInfo.Uint64 = AsmReadMsr64 (MSR_NEHALEM_PLATFORM_INFO);
Cpu->MinBusRatio = (UINT8) PlatformInfo.Bits.MaximumEfficiencyRatio;
Cpu->MaxBusRatio = (UINT8) PlatformInfo.Bits.MaximumNonTurboRatio;
} else if (Cpu->Model >= CPU_MODEL_PENRYN) {
PerfStatus.Uint64 = AsmReadMsr64 (MSR_IA32_PERF_STATUS);
Cpu->MaxBusRatio = (UINT8) (PerfStatus.Uint64 >> 8U) & 0x1FU;
//
// Undocumented values:
// Non-integer bus ratio for the max-multi.
// Non-integer bus ratio for the current-multi.
//
// MaxBusRatioDiv = (UINT8)(PerfStatus.Uint64 >> 46U) & 0x01U;
// CurrDiv = (UINT8)(PerfStatus.Uint64 >> 14U) & 0x01U;
//
}
if (Cpu->Model >= CPU_MODEL_NEHALEM
......@@ -659,9 +668,10 @@ ScanIntelProcessor (
));
//
// Both checked to workaround virtual cpu
// There may be some quirks with virtual CPUs (VMware is fine).
// Formerly we checked Cpu->MinBusRatio > 0, but we have no MinBusRatio on Penryn.
//
if (Cpu->MinBusRatio > 0 && Cpu->MaxBusRatio > Cpu->MinBusRatio) {
if (Cpu->TSCFrequency > 0 && Cpu->MaxBusRatio > Cpu->MinBusRatio) {
Cpu->FSBFrequency = DivU64x32 (Cpu->TSCFrequency, Cpu->MaxBusRatio);
Cpu->CPUFrequency = MultU64x32 (Cpu->FSBFrequency, Cpu->MaxBusRatio);
} else {
......@@ -699,9 +709,12 @@ ScanIntelProcessor (
CoreCount *= 2;
}
Cpu->CoreCount = CoreCount;
Cpu->ThreadCount = Cpu->CoreCount;
if (Cpu->Features & CPUID_FEATURE_HTT) {
Cpu->ThreadCount *= 2;
//
// We should not be blindly relying on Cpu->Features & CPUID_FEATURE_HTT.
// On Penryn CPUs it is set even without Hyper Threading.
//
if (Cpu->ThreadCount < Cpu->CoreCount) {
Cpu->ThreadCount = Cpu->CoreCount;
}
}
} else if (Cpu->Model == CPU_MODEL_WESTMERE) {
......@@ -847,3 +860,28 @@ OcCpuScanProcessor (
ScanIntelProcessor (Cpu);
}
}
VOID
OcCpuCorrectFlexRatio (
IN OC_CPU_INFO *Cpu
)
{
UINT64 Msr;
UINT64 FlexRatio;
if (Cpu->Vendor[0] == CPUID_VENDOR_INTEL
&& Cpu->Model != CPU_MODEL_GOLDMONT
&& Cpu->Model != CPU_MODEL_AIRMONT
&& Cpu->Model != CPU_MODEL_AVOTON) {
Msr = AsmReadMsr64 (MSR_FLEX_RATIO);
if (Msr & FLEX_RATIO_EN) {
FlexRatio = BitFieldRead64 (Msr, 8, 15);
if (FlexRatio == 0) {
//
// Disable Flex Ratio if current value is 0.
//
AsmWriteMsr64 (MSR_FLEX_RATIO, Msr & ~((UINT64) FLEX_RATIO_EN));
}
}
}
}
......@@ -18,7 +18,8 @@ listed here.
1. No dmg boot detection.
* OcAppleKernelLib
**Status**: functional
**Issues**: none
**Issues**:
1. No executable kext injection.
* OcCompressionLib
**Status**: functional
**Issues**: none
......@@ -36,7 +37,6 @@ listed here.
1. No package count detection.
1. No AMD CPU support.
1. Apple processor type detection is incomplete.
1. FSBFrequency calculation is sometimes incorrect, e.g. for Core 2 Quad Q9450.
* OcCryptoLib
**Status**: functional
**Issues**: none
......
......@@ -132,27 +132,7 @@ TestDataHub (
gBS->SetWatchdogTimer (0, 0, 0, NULL);
//TODO: put this elsewhere, fixes early reboot on APTIO IV (Ivy/Haswell).
{
UINT64 Msr;
UINT64 FlexRatio;
if (CpuInfo.Vendor[0] == CPUID_VENDOR_INTEL
&& CpuInfo.Model != CPU_MODEL_GOLDMONT
&& CpuInfo.Model != CPU_MODEL_AIRMONT
&& CpuInfo.Model != CPU_MODEL_AVOTON) {
Msr = AsmReadMsr64 (MSR_FLEX_RATIO);
if (Msr & FLEX_RATIO_EN) {
FlexRatio = BitFieldRead64 (Msr, 8, 15);
if (FlexRatio == 0) {
//
// Disable Flex Ratio if current value is 0.
//
AsmWriteMsr64 (MSR_FLEX_RATIO, Msr & ~((UINT64) FLEX_RATIO_EN));
}
}
}
}
OcCpuCorrectFlexRatio (&CpuInfo);
return EFI_SUCCESS;
}
......
......@@ -696,6 +696,15 @@ AsmReadMsr64 (
return 0;
}
STATIC
VOID
AsmWriteMsr64 (
UINT32 Index,
UINT64 Value
)
{
}
STATIC
UINT64
EFIAPI
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册