OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcCpuLib.h File Reference
#include <Uefi.h>
#include <IndustryStandard/CpuId.h>
#include <IndustryStandard/AppleIntelCpuInfo.h>
#include <Protocol/FrameworkMpService.h>
#include <Protocol/MpService.h>

Go to the source code of this file.

Data Structures

struct  OC_CPU_INFO
 
struct  OC_CPU_MSR_REPORT
 
struct  OC_CPU_MSR_REPORT_PROCEDURE_ARGUMENT
 

Macros

#define OC_FALLBACK_CPU_FREQUENCY   1000000000
 

Enumerations

enum  OC_CPU_GENERATION {
  OcCpuGenerationUnknown , OcCpuGenerationBanias , OcCpuGenerationPreYonah , OcCpuGenerationYonahMerom ,
  OcCpuGenerationPenryn , OcCpuGenerationBonnell , OcCpuGenerationNehalem , OcCpuGenerationWestmere ,
  OcCpuGenerationSilvermont , OcCpuGenerationSandyBridge , OcCpuGenerationPostSandyBridge , OcCpuGenerationIvyBridge ,
  OcCpuGenerationHaswell , OcCpuGenerationBroadwell , OcCpuGenerationSkylake , OcCpuGenerationKabyLake ,
  OcCpuGenerationCoffeeLake , OcCpuGenerationCometLake , OcCpuGenerationRocketLake , OcCpuGenerationCannonLake ,
  OcCpuGenerationIceLake , OcCpuGenerationTigerLake , OcCpuGenerationAlderLake , OcCpuGenerationRaptorLake ,
  OcCpuGenerationArrowLake , OcCpuGenerationMaxGeneration
}
 

Functions

VOID OcCpuScanProcessor (IN OUT OC_CPU_INFO *Cpu)
 
VOID OcCpuGetMsrReport (IN OC_CPU_INFO *CpuInfo, OUT OC_CPU_MSR_REPORT *Report)
 
VOID EFIAPI OcCpuGetMsrReportPerCore (IN OUT VOID *Buffer)
 
OC_CPU_MSR_REPORTOcCpuGetMsrReports (IN OC_CPU_INFO *CpuInfo, OUT UINTN *EntryCount)
 
VOID OcCpuCorrectFlexRatio (IN OC_CPU_INFO *Cpu)
 
EFI_STATUS OcCpuEnableVmx (VOID)
 
EFI_STATUS OcCpuCorrectTscSync (IN OC_CPU_INFO *Cpu, IN UINTN Timeout)
 
UINT32 OcCpuModelToAppleFamily (IN CPUID_VERSION_INFO_EAX VersionEax)
 
UINT16 OcCpuFrequencyToDisplayFrequency (IN UINT64 Frequency)
 
UINT64 OcGetTSCFrequency (VOID)
 

Detailed Description

Copyright (C) 2016 - 2017, The HermitCrabs Lab. 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.

Definition in file OcCpuLib.h.

Macro Definition Documentation

◆ OC_FALLBACK_CPU_FREQUENCY

#define OC_FALLBACK_CPU_FREQUENCY   1000000000

Assumed CPU frequency when it cannot be detected. Can be overridden by e.g. emulator.

Definition at line 29 of file OcCpuLib.h.

Enumeration Type Documentation

◆ OC_CPU_GENERATION

Sorted Intel CPU generations.

Enumerator
OcCpuGenerationUnknown 
OcCpuGenerationBanias 
OcCpuGenerationPreYonah 
OcCpuGenerationYonahMerom 
OcCpuGenerationPenryn 
OcCpuGenerationBonnell 
OcCpuGenerationNehalem 
OcCpuGenerationWestmere 
OcCpuGenerationSilvermont 
OcCpuGenerationSandyBridge 
OcCpuGenerationPostSandyBridge 
OcCpuGenerationIvyBridge 
OcCpuGenerationHaswell 
OcCpuGenerationBroadwell 
OcCpuGenerationSkylake 
OcCpuGenerationKabyLake 
OcCpuGenerationCoffeeLake 
OcCpuGenerationCometLake 
OcCpuGenerationRocketLake 
OcCpuGenerationCannonLake 
OcCpuGenerationIceLake 
OcCpuGenerationTigerLake 
OcCpuGenerationAlderLake 
OcCpuGenerationRaptorLake 
OcCpuGenerationArrowLake 
OcCpuGenerationMaxGeneration 

Definition at line 35 of file OcCpuLib.h.

Function Documentation

◆ OcCpuCorrectFlexRatio()

VOID OcCpuCorrectFlexRatio ( IN OC_CPU_INFO * Cpu)

Disable flex ratio if it has invalid value. Commonly fixes early reboot on APTIO IV (Ivy/Haswell).

Parameters
[in]CpuA pointer to the cpu info.

Definition at line 1231 of file OcCpuLib.c.

◆ OcCpuCorrectTscSync()

EFI_STATUS OcCpuCorrectTscSync ( IN OC_CPU_INFO * Cpu,
IN UINTN Timeout )

Synchronise TSC on all cores (needed on server chipsets and some laptops). This does not fully replace VoodooTscSync or TSCAdjustReset due to the need to sync on S3 as well and may also work far less reliably due to the limitation of UEFI firmware not permitting MSR update runs in parallel with BSP and AP cores. However, it lets debug kernels work most of the time till the time TSC kexts start.

Parameters
[in]CpuA pointer to the cpu info.
[in]TimeoutAmount of time to wait for CPU core rendezvous.
Return values
EFI_SUCCESSon success.

Definition at line 1324 of file OcCpuLib.c.

◆ OcCpuEnableVmx()

EFI_STATUS OcCpuEnableVmx ( VOID )

Enable VMX in FeatureControl MSR if supported and not already locked by BIOS. Required to use virtualization in Windows on some Mac hardware.

REF: https://github.com/acidanthera/bugtracker/issues/1870 REF: https://www.thomas-krenn.com/en/wiki/Activating_the_Intel_VT_Virtualization_Feature (via rEFInd) REF: 'Intel 64 and IA-32 Architectures Software Developer's Manual Volume 3', p.1296 etc.

Definition at line 1256 of file OcCpuLib.c.

◆ OcCpuFrequencyToDisplayFrequency()

UINT16 OcCpuFrequencyToDisplayFrequency ( IN UINT64 Frequency)

Converts calculated CPU frequency in Hz to rounded value in MHz.

Parameters
[in]FrequencyCPU frequency in Hz.
Returns
Rounded CPU frequency in MHz.

Definition at line 742 of file AppleCpuSupport.c.

◆ OcCpuGetMsrReport()

VOID OcCpuGetMsrReport ( IN OC_CPU_INFO * CpuInfo,
OUT OC_CPU_MSR_REPORT * Report )

Get the MSR report of one core on the CPU.

Parameters
[in]CpuInfoA pointer to the cpu info.
[out]ReportThe report generated based on CpuInfo.

Definition at line 1049 of file OcCpuLib.c.

◆ OcCpuGetMsrReportPerCore()

VOID EFIAPI OcCpuGetMsrReportPerCore ( IN OUT VOID * Buffer)

Get the MSR report of a single core on the CPU. Used as a parameter of MpServices->StartupAllAPs ().

Parameters
[in,out]BufferThe pointer to private data buffer.

Definition at line 1131 of file OcCpuLib.c.

◆ OcCpuGetMsrReports()

OC_CPU_MSR_REPORT * OcCpuGetMsrReports ( IN OC_CPU_INFO * CpuInfo,
OUT UINTN * EntryCount )

Get the MSR reports of all cores on the CPU.

Parameters
[in]CpuInfoA pointer to the cpu info.
[out]EntryCountNumber of CPU cores.
Returns
A list of reports of MSR status at each core that must be freed manually, or NULL on failure.

Definition at line 1153 of file OcCpuLib.c.

◆ OcCpuModelToAppleFamily()

UINT32 OcCpuModelToAppleFamily ( IN CPUID_VERSION_INFO_EAX VersionEax)

Converts CPUID Family and Model extracted from EAX CPUID (1) call to AppleFamily value. This implements cpuid_set_cpufamily functionality as it is in XNU.

Parameters
[in]VersionEaxCPUID (1) EAX value.
Return values
AppleFamily (e.g. CPUFAMILY_UNKNOWN)

Definition at line 686 of file AppleCpuSupport.c.

◆ OcCpuScanProcessor()

VOID OcCpuScanProcessor ( IN OUT OC_CPU_INFO * Cpu)

Scan the processor and fill the cpu info structure with results.

Parameters
[in,out]CpuA pointer to the cpu info structure to fill with results.

Definition at line 832 of file OcCpuLib.c.

◆ OcGetTSCFrequency()

UINT64 OcGetTSCFrequency ( VOID )

Obtain CPU's invariant TSC frequency.

Return values
CPU'sTSC frequency or OC_FALLBACK_CPU_FREQUENCY.

Definition at line 762 of file FrequencyDetect.c.