Skip to content

Commit

Permalink
OpenCore: Add CPU Info (MSRs) to SysReport (acidanthera#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
PMheart authored Jun 11, 2021
1 parent 0bd7dbd commit fded511
Show file tree
Hide file tree
Showing 12 changed files with 709 additions and 172 deletions.
1 change: 1 addition & 0 deletions Application/ResetSystem/ResetSystem.inf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[Packages]
MdePkg/MdePkg.dec
OpenCorePkg/OpenCorePkg.dec
UefiCpuPkg/UefiCpuPkg.dec

[LibraryClasses]
BaseLib
Expand Down
97 changes: 96 additions & 1 deletion Include/Acidanthera/Library/OcCpuLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <Uefi.h>
#include <IndustryStandard/CpuId.h>
#include <IndustryStandard/AppleIntelCpuInfo.h>
#include <Protocol/FrameworkMpService.h>
#include <Protocol/MpService.h>

/**
Assumed CPU frequency when it cannot be detected.
Expand Down Expand Up @@ -160,16 +162,109 @@ typedef struct {
UINT64 FSBFrequency;
} OC_CPU_INFO;

typedef struct {
//
// MSR_PLATFORM_INFO
//
BOOLEAN CpuHasMsrPlatformInfo;
UINT64 CpuMsrPlatformInfoValue;

//
// MSR_TURBO_RATIO_LIMIT
//
BOOLEAN CpuHasMsrTurboRatioLimit;
UINT64 CpuMsrTurboRatioLimitValue;

//
// MSR_PKG_POWER_INFO (TODO: To be confirmed)
//
BOOLEAN CpuHasMsrPkgPowerInfo;
UINT64 CpuMsrPkgPowerInfoValue;

//
// IA32_MISC_ENABLE
//
BOOLEAN CpuHasMsrIa32MiscEnable;
UINT64 CpuMsrIa32MiscEnableValue;

//
// MSR_IA32_EXT_CONFIG
//
BOOLEAN CpuHasMsrIa32ExtConfig;
UINT64 CpuMsrIa32ExtConfigValue;

//
// MSR_FSB_FREQ
//
BOOLEAN CpuHasMsrFsbFreq;
UINT64 CpuMsrFsbFreqValue;

//
// MSR_IA32_PERF_STATUS
//
BOOLEAN CpuHasMsrIa32PerfStatus;
UINT64 CpuMsrIa32PerfStatusValue;

//
// MSR_BROADWELL_PKG_CST_CONFIG_CONTROL_REGISTER (0xE2)
//
BOOLEAN CpuHasMsrE2;
UINT64 CpuMsrE2Value;
} OC_CPU_MSR_REPORT;

typedef struct {
EFI_MP_SERVICES_PROTOCOL *MpServices;
OC_CPU_MSR_REPORT *Reports;
OC_CPU_INFO *CpuInfo;
} OC_CPU_MSR_REPORT_PROCEDURE_ARGUMENT;

/**
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,out] Cpu A pointer to the cpu info structure to fill with results.
**/
VOID
OcCpuScanProcessor (
IN OUT OC_CPU_INFO *Cpu
);

/**
Get the MSR report of the CPU.
@param[in] CpuInfo A pointer to the cpu info.
@param[out] Report The report generated based on CpuInfo.
**/
VOID
OcCpuGetMsrReport (
IN OC_CPU_INFO *CpuInfo,
OUT OC_CPU_MSR_REPORT *Report
);

/**
Get the MSR report of a single core on the CPU.
@param[in,out] Buffer The pointer to private data buffer.
**/
VOID
EFIAPI
OcCpuGetMsrReportPerCore (
IN OUT VOID *Buffer
);

/**
Get the MSR reports of all cores on the CPU.
@param[in] CpuInfo A pointer to the cpu info.
@param[out] EntryCount Count of cores on the CPU.
@return Array of reports of MSR status at each core.
**/
OC_CPU_MSR_REPORT *
OcCpuGetMsrReports (
IN OC_CPU_INFO *CpuInfo,
OUT UINTN *EntryCount
);

/**
Disable flex ratio if it has invalid value.
Commonly fixes early reboot on APTIO IV (Ivy/Haswell).
Expand Down
16 changes: 16 additions & 0 deletions Include/Acidanthera/Library/OcDeviceMiscLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#define OC_DEVICE_MISC_LIB_H

#include <Uefi.h>
#include <Library/OcCpuLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcStringLib.h>

/**
Expand Down Expand Up @@ -51,6 +53,20 @@ ActivateHpetSupport (
VOID
);

/**
Dump CPU MSR data to the specified directory.
@param[in] CpuInfo A pointer to the CPU info.
@param[in] Root Directory to write CPU data.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
OcMsrDump (
IN OC_CPU_INFO *CpuInfo,
IN EFI_FILE_PROTOCOL *Root
);

/**
Upgrade UEFI version to 2.x.
Expand Down
82 changes: 50 additions & 32 deletions Include/Acidanthera/Library/OcStringLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ AsciiUint64ToLowerHex (
/**
Alternative to AsciiSPrint, which checks that the buffer can contain all the characters.
@param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
ASCII string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString A Null-terminated ASCII format string.
@param ... Variable argument list whose contents are accessed based on the
format string specified by FormatString.
@param[out] StartOfBuffer A pointer to the output buffer for the produced Null-terminated
ASCII string.
@param[in] BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param[in] FormatString A Null-terminated ASCII format string.
@param[in] ... Variable argument list whose contents are accessed based on the
format string specified by FormatString.
@retval EFI_SUCCESS When data was printed to supplied buffer.
@retval EFI_OUT_OF_RESOURCES When supplied buffer cannot contain all the characters.
Expand Down Expand Up @@ -173,9 +173,9 @@ OcAsciiSafeSPrint (
than PcdMaximumAsciiStringLength ASCII characters, not including the
Null-terminator, then ASSERT().
@param FirstString A pointer to a Null-terminated ASCII string.
@param SecondString A pointer to a Null-terminated ASCII string.
@param Length The maximum number of ASCII characters to compare.
@param[in] FirstString A pointer to a Null-terminated ASCII string.
@param[in] SecondString A pointer to a Null-terminated ASCII string.
@param[in] Length The maximum number of ASCII characters to compare.
@retval ==0 FirstString is identical to SecondString using case
insensitive comparisons.
Expand Down Expand Up @@ -245,8 +245,8 @@ OcAsciiStartsWith (
than PcdMaximumUnicodeStringLength Unicode characters, not including the
Null-terminator, then ASSERT().
@param FirstString A pointer to a Null-terminated Unicode string.
@param SecondString A pointer to a Null-terminated Unicode string.
@param[in] FirstString A pointer to a Null-terminated Unicode string.
@param[in] SecondString A pointer to a Null-terminated Unicode string.
@retval ==0 FirstString is identical to SecondString using case
insensitiv comparisons.
Expand Down Expand Up @@ -289,9 +289,9 @@ OcStriCmp (
than PcdMaximumUnicodeStringLength Unicode characters, not including the
Null-terminator, then ASSERT().
@param FirstString A pointer to a Null-terminated Unicode string.
@param SecondString A pointer to a Null-terminated Unicode string.
@param Length The maximum number of Unicode characters to compare.
@param[in] FirstString A pointer to a Null-terminated Unicode string.
@param[in] SecondString A pointer to a Null-terminated Unicode string.
@param[in] Length The maximum number of Unicode characters to compare.
@retval ==0 FirstString is identical to SecondString using case
insensitive comparisons.
Expand Down Expand Up @@ -323,8 +323,8 @@ OcStrniCmp (
or String contains more than PcdMaximumAsciiStringLength ASCII
characters, not including the Null-terminator, then ASSERT().
@param String The pointer to a Null-terminated ASCII string.
@param SearchString The pointer to a Null-terminated ASCII string to search for.
@param[in] String The pointer to a Null-terminated ASCII string.
@param[in] SearchString The pointer to a Null-terminated ASCII string to search for.
@retval NULL If the SearchString does not appear in String.
@return others If there is a match.
Expand All @@ -347,8 +347,8 @@ OcAsciiStriStr (
contains more than PcdMaximumAsciiStringLength ASCII
characters, not including the Null-terminator, then ASSERT().
@param String The pointer to a Null-terminated ASCII string.
@param Char Character to be located.
@param[in] String The pointer to a Null-terminated ASCII string.
@param[in] Char Character to be located.
@return A pointer to the first occurrence of Char in String.
@retval NULL If Char cannot be found in String.
Expand All @@ -370,8 +370,8 @@ OcAsciiStrChr (
contains more than PcdMaximumAsciiStringLength ASCII
characters, not including the Null-terminator, then ASSERT().
@param String The pointer to a Null-terminated ASCII string.
@param Char Character to be located.
@param[in] String The pointer to a Null-terminated ASCII string.
@param[in] Char Character to be located.
@return A pointer to the last occurrence of Char in String.
@retval NULL If Char cannot be found in String.
Expand Down Expand Up @@ -401,8 +401,8 @@ OcAsciiStringNPrintable (
Convert a Null-terminated ASCII GUID string to a value of type
EFI_GUID with RFC 4122 (raw) encoding.
@param String Pointer to a Null-terminated ASCII string.
@param Guid Pointer to the converted GUID.
@param[in] String Pointer to a Null-terminated ASCII string.
@param[out] Guid Pointer to the converted GUID.
@retval EFI_SUCCESS Guid is translated from String.
@retval EFI_INVALID_PARAMETER If String is NULL.
Expand All @@ -416,6 +416,24 @@ OcAsciiStrToRawGuid (
OUT GUID *Guid
);

/**
Write formatted ASCII strings to buffers.
@param[in,out] AsciiBuffer A pointer to the output buffer for the produced Null-terminated
ASCII string.
@param[in,out] AsciiBufferSize The size, in bytes, of the output buffer specified by AsciiBuffer.
@param[in] FormatString A Null-terminated ASCII format string.
@param[in] ... Variable argument list whose contents are accessed based on the
format string specified by FormatString.
**/
VOID
EFIAPI
OcAsciiPrintBuffer (
IN OUT CHAR8 **AsciiBuffer,
IN OUT UINTN *AsciiBufferSize,
IN CONST CHAR8 *FormatString,
...
);

/**
Returns the first occurrence of a Null-terminated Unicode sub-string
in a Null-terminated Unicode string through a case insensitive comparison.
Expand All @@ -434,8 +452,8 @@ OcAsciiStrToRawGuid (
or String contains more than PcdMaximumUnicodeStringLength Unicode
characters, not including the Null-terminator, then ASSERT().
@param String The pointer to a Null-terminated Unicode string.
@param SearchString The pointer to a Null-terminated Unicode string to search for.
@param[in] String The pointer to a Null-terminated Unicode string.
@param[in] SearchString The pointer to a Null-terminated Unicode string to search for.
@retval NULL If the SearchString does not appear in String.
@return others If there is a match.
Expand Down Expand Up @@ -470,12 +488,12 @@ OcStrStrLength (
/**
Alternative to UnicodeSPrint, which checks that the buffer can contain all the characters.
@param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
Unicode string.
@param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param FormatString A Null-terminated Unicode format string.
@param ... Variable argument list whose contents are accessed based on the
format string specified by FormatString.
@param[out] StartOfBuffer A pointer to the output buffer for the produced Null-terminated
Unicode string.
@param[in] BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
@param[in] FormatString A Null-terminated Unicode format string.
@param[in] ... Variable argument list whose contents are accessed based on the
format string specified by FormatString.
@retval EFI_SUCCESS When data was printed to supplied buffer.
@retval EFI_OUT_OF_RESOURCES When supplied buffer cannot contain all the characters.
Expand Down Expand Up @@ -613,8 +631,8 @@ HasValidGuidStringPrefix (
mismatched character in SecondString subtracted from the first mismatched
character in FirstString.
@param FirstString A pointer to a Null-terminated Unicode string.
@param SecondString A pointer to a Null-terminated ASCII string.
@param[in] FirstString A pointer to a Null-terminated Unicode string.
@param[in] SecondString A pointer to a Null-terminated ASCII string.
@retval ==0 FirstString is identical to SecondString.
@retval !=0 FirstString is not identical to SecondString.
Expand Down
14 changes: 14 additions & 0 deletions Include/Intel/Protocol/FrameworkMpService.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ typedef struct {
UINT64 ProcessorTestMask;
} EFI_MP_PROC_CONTEXT;

/**
The function prototype for invoking a function on an Application Processor.
This definition is used by the UEFI MP Serices Protocol, and the
PI SMM System Table.
@param[in,out] Buffer The pointer to private data buffer.
**/
typedef
VOID
(EFIAPI *EFI_AP_PROCEDURE)(
IN OUT VOID *Buffer
);

/**
Functions of this type are used with the Framework MP Services Protocol and
the SMM Services Table to execute a procedure on enabled APs. The context
Expand Down
Loading

0 comments on commit fded511

Please sign in to comment.