OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcCpuLib.c File Reference
#include <PiDxe.h>
#include <IndustryStandard/AppleSmBios.h>
#include <Protocol/FrameworkMpService.h>
#include <Protocol/MpService.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DebugLib.h>
#include <Library/OcCpuLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <IndustryStandard/ProcessorInfo.h>
#include <Register/Microcode.h>
#include <Register/Msr.h>
#include <Register/Intel/Msr/SandyBridgeMsr.h>
#include <Register/Intel/Msr/NehalemMsr.h>
#include "OcCpuInternals.h"

Go to the source code of this file.

Functions

STATIC EFI_STATUS ScanMpServices (IN EFI_MP_SERVICES_PROTOCOL *MpServices, OUT OC_CPU_INFO *Cpu, OUT UINTN *NumberOfProcessors, OUT UINTN *NumberOfEnabledProcessors)
 
STATIC EFI_STATUS ScanFrameworkMpServices (IN FRAMEWORK_EFI_MP_SERVICES_PROTOCOL *FrameworkMpServices, OUT OC_CPU_INFO *Cpu, OUT UINTN *NumberOfProcessors, OUT UINTN *NumberOfEnabledProcessors)
 
STATIC EFI_STATUS ScanThreadCount (OUT OC_CPU_INFO *Cpu)
 
STATIC VOID SetMaxBusRatioAndMaxBusRatioDiv (IN OC_CPU_INFO *CpuInfo OPTIONAL, OUT UINT8 *MaxBusRatio, OUT UINT8 *MaxBusRatioDiv)
 
STATIC VOID ScanIntelFSBFrequency (IN OC_CPU_INFO *CpuInfo)
 
UINT64 InternalConvertAppleFSBToTSCFrequency (IN UINT64 FSBFrequency)
 
STATIC VOID ScanIntelProcessorApple (IN OUT OC_CPU_INFO *Cpu)
 
STATIC VOID ScanIntelProcessor (IN OUT OC_CPU_INFO *Cpu)
 
STATIC VOID ScanAmdProcessor (IN OUT OC_CPU_INFO *Cpu)
 
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)
 
STATIC VOID EFIAPI SyncTscOnCpu (IN VOID *Buffer)
 
STATIC VOID EFIAPI ResetAdjustTsc (IN VOID *Buffer)
 
EFI_STATUS OcCpuCorrectTscSync (IN OC_CPU_INFO *Cpu, IN UINTN Timeout)
 
OC_CPU_GENERATION InternalDetectIntelProcessorGeneration (IN OC_CPU_INFO *CpuInfo)
 

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.c.

Function Documentation

◆ InternalConvertAppleFSBToTSCFrequency()

UINT64 InternalConvertAppleFSBToTSCFrequency ( IN UINT64 FSBFrequency)

Convert Apple FSB frequency to TSC frequency

Parameters
[in]FSBFrequencyFrequency in Apple FSB format.
Return values
ConvertedTSC frequency.

Definition at line 383 of file OcCpuLib.c.

◆ InternalDetectIntelProcessorGeneration()

OC_CPU_GENERATION InternalDetectIntelProcessorGeneration ( IN OC_CPU_INFO * CpuInfo)

Obtain Intel CPU generation.

Parameters
[in]ModelCPU model from CPUID.
Return values
CPU'sgeneration (e.g. OcCpuGenerationUnknown).

Definition at line 1396 of file OcCpuLib.c.

◆ 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.

◆ 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.

◆ 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.

◆ ResetAdjustTsc()

STATIC VOID EFIAPI ResetAdjustTsc ( IN VOID * Buffer)

Definition at line 1306 of file OcCpuLib.c.

◆ ScanAmdProcessor()

STATIC VOID ScanAmdProcessor ( IN OUT OC_CPU_INFO * Cpu)

Definition at line 630 of file OcCpuLib.c.

◆ ScanFrameworkMpServices()

STATIC EFI_STATUS ScanFrameworkMpServices ( IN FRAMEWORK_EFI_MP_SERVICES_PROTOCOL * FrameworkMpServices,
OUT OC_CPU_INFO * Cpu,
OUT UINTN * NumberOfProcessors,
OUT UINTN * NumberOfEnabledProcessors )

Definition at line 102 of file OcCpuLib.c.

◆ ScanIntelFSBFrequency()

STATIC VOID ScanIntelFSBFrequency ( IN OC_CPU_INFO * CpuInfo)

Definition at line 330 of file OcCpuLib.c.

◆ ScanIntelProcessor()

STATIC VOID ScanIntelProcessor ( IN OUT OC_CPU_INFO * Cpu)

Definition at line 424 of file OcCpuLib.c.

◆ ScanIntelProcessorApple()

STATIC VOID ScanIntelProcessorApple ( IN OUT OC_CPU_INFO * Cpu)

Definition at line 404 of file OcCpuLib.c.

◆ ScanMpServices()

STATIC EFI_STATUS ScanMpServices ( IN EFI_MP_SERVICES_PROTOCOL * MpServices,
OUT OC_CPU_INFO * Cpu,
OUT UINTN * NumberOfProcessors,
OUT UINTN * NumberOfEnabledProcessors )

Definition at line 37 of file OcCpuLib.c.

◆ ScanThreadCount()

STATIC EFI_STATUS ScanThreadCount ( OUT OC_CPU_INFO * Cpu)

Definition at line 195 of file OcCpuLib.c.

◆ SetMaxBusRatioAndMaxBusRatioDiv()

STATIC VOID SetMaxBusRatioAndMaxBusRatioDiv ( IN OC_CPU_INFO *CpuInfo OPTIONAL,
OUT UINT8 * MaxBusRatio,
OUT UINT8 * MaxBusRatioDiv )

Definition at line 277 of file OcCpuLib.c.

◆ SyncTscOnCpu()

STATIC VOID EFIAPI SyncTscOnCpu ( IN VOID * Buffer)

Definition at line 1286 of file OcCpuLib.c.