diff --git a/Application/ResetSystem/ResetSystem.inf b/Application/ResetSystem/ResetSystem.inf index 8200ad5b7c9bbbfa4263f0c724bad70e39dff795..cb8fc8263995ffdace9c160f0a3b21dd18f768be 100644 --- a/Application/ResetSystem/ResetSystem.inf +++ b/Application/ResetSystem/ResetSystem.inf @@ -37,6 +37,7 @@ [Packages] MdePkg/MdePkg.dec OpenCorePkg/OpenCorePkg.dec + UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] BaseLib diff --git a/Include/Acidanthera/Library/OcCpuLib.h b/Include/Acidanthera/Library/OcCpuLib.h index 0678f6d3c076b24cf0ec55ca946acaf27ceaad15..1d9a911ecc8ad8b4800a5dfed2c0800be09b4a2c 100755 --- a/Include/Acidanthera/Library/OcCpuLib.h +++ b/Include/Acidanthera/Library/OcCpuLib.h @@ -18,6 +18,8 @@ #include #include #include +#include +#include /** Assumed CPU frequency when it cannot be detected. @@ -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). diff --git a/Include/Acidanthera/Library/OcDeviceMiscLib.h b/Include/Acidanthera/Library/OcDeviceMiscLib.h index 9eaf3ac9102c2d1bd953b101722f1f286b8d0daa..c4fe777f29e8431447e15b5727c090734f3cf44c 100755 --- a/Include/Acidanthera/Library/OcDeviceMiscLib.h +++ b/Include/Acidanthera/Library/OcDeviceMiscLib.h @@ -16,6 +16,8 @@ #define OC_DEVICE_MISC_LIB_H #include +#include +#include #include /** @@ -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. diff --git a/Include/Acidanthera/Library/OcStringLib.h b/Include/Acidanthera/Library/OcStringLib.h index 33cecb4ac83f2a91956a05030da77bafc609b741..9e1be00a34f68bfebbbbd655d2d114265d008499 100755 --- a/Include/Acidanthera/Library/OcStringLib.h +++ b/Include/Acidanthera/Library/OcStringLib.h @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/Include/Intel/Protocol/FrameworkMpService.h b/Include/Intel/Protocol/FrameworkMpService.h index 042b2284c9563b59a9c615c67b1919f486270b5d..7254a0c88c268bc6555c9ca5bc60d5c47a3de360 100644 --- a/Include/Intel/Protocol/FrameworkMpService.h +++ b/Include/Intel/Protocol/FrameworkMpService.h @@ -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 diff --git a/Library/OcAudioLib/OcAudioDump.c b/Library/OcAudioLib/OcAudioDump.c index 7437c2108797a203b3a46ed2582738c08018045d..e969de4b218e7efb32648833ec5ef92029888b4d 100644 --- a/Library/OcAudioLib/OcAudioDump.c +++ b/Library/OcAudioLib/OcAudioDump.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -175,52 +176,6 @@ CHAR8 *mColors[HDA_CONFIG_DEFAULT_COLOR_OTHER + 1] = "Other" }; -STATIC -VOID -EFIAPI -PrintHdaBuffer ( - IN OUT CHAR8 **AsciiBuffer, - IN UINTN *AsciiBufferSize, - IN CONST CHAR8 *FormatString, - ... - ) -{ - EFI_STATUS Status; - VA_LIST Marker; - CHAR8 Tmp[256]; - CHAR8 *NewBuffer; - UINTN NewBufferSize; - - if (*AsciiBuffer == NULL) { - return; - } - - VA_START (Marker, FormatString); - AsciiVSPrint (Tmp, sizeof (Tmp), FormatString, Marker); - VA_END (Marker); - - Status = AsciiStrCatS (*AsciiBuffer, *AsciiBufferSize, Tmp); - if (Status == EFI_BUFFER_TOO_SMALL) { - if (OcOverflowMulUN (*AsciiBufferSize, 2, &NewBufferSize)) { - return; - } - NewBuffer = ReallocatePool (*AsciiBufferSize, NewBufferSize, *AsciiBuffer); - if (NewBuffer == NULL) { - FreePool (*AsciiBuffer); - - *AsciiBuffer = NULL; - *AsciiBufferSize = 0; - - return; - } - - *AsciiBuffer = NewBuffer; - *AsciiBufferSize = NewBufferSize; - - AsciiStrCatS (*AsciiBuffer, *AsciiBufferSize, Tmp); - } -} - STATIC VOID PrintRatesFormats ( @@ -233,80 +188,80 @@ PrintRatesFormats ( // // Print sample rates. // - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " rates [0x%X]:", (UINT16) Rates); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " rates [0x%X]:", (UINT16) Rates); if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 8000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 8000"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_11KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 11025"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 11025"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 16000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 16000"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_22KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 22050"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 22050"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 32000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 32000"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_44KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 44100"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 44100"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_48KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 48000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 48000"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_88KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 88200"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 88200"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_96KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 96000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 96000"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_176KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 176400"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 176400"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_192KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 192000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 192000"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_384KHZ) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 384000"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 384000"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); // // Print sample bits. // - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " bits [0x%X]:", (UINT16)(Rates >> 16)); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " bits [0x%X]:", (UINT16)(Rates >> 16)); if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_8BIT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 8"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 8"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_16BIT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 16"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 16"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_20BIT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 20"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 20"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_24BIT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 24"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 24"); } if (Rates & HDA_PARAMETER_SUPPORTED_PCM_SIZE_RATES_32BIT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 32"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 32"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); // // Print sample formats. // - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " formats [0x%X]:", Formats); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " formats [0x%X]:", Formats); if (Formats & HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_PCM) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " PCM"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " PCM"); } if (Formats & HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_FLOAT32) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " FLOAT32"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " FLOAT32"); } if (Formats & HDA_PARAMETER_SUPPORTED_STREAM_FORMATS_AC3) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " AC3"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " AC3"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); } STATIC @@ -318,7 +273,7 @@ PrintAmpCaps ( ) { if (AmpCaps != 0) { - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, "ofs=0x%2X, nsteps=0x%2X, stepsize=0x%2X, mute=%u\n", @@ -328,7 +283,7 @@ PrintAmpCaps ( (AmpCaps & HDA_PARAMETER_AMP_CAPS_MUTE) != 0 ); } else { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "N/A\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "N/A\n"); } } @@ -345,7 +300,7 @@ PrintWidget ( // // Node header and widget capabilities. // - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, "Node 0x%2X (%u) [%a] wcaps 0x%X:", @@ -356,36 +311,36 @@ PrintWidget ( ); if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Stereo"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Stereo"); } else { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Mono"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Mono"); } if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_DIGITAL) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Digital"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Digital"); } if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_IN_AMP) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In"); } if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_OUT_AMP) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out"); } if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_L_R_SWAP) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " R/L"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " R/L"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); // // Input amp capabilities and defaults. // if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_IN_AMP) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In caps: "); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In caps: "); PrintAmpCaps (AsciiBuffer, AsciiBufferSize, HdaWidget->AmpInCapabilities); - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In vals:"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-In vals:"); for (Index = 0; Index < HdaWidget->ConnectionCount; Index++) { if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) { - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, " [0x%2X 0x%2X]", @@ -393,22 +348,22 @@ PrintWidget ( HdaWidget->AmpInRightDefaultGainMute[Index] ); } else { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " [0x%2X]", HdaWidget->AmpInLeftDefaultGainMute[Index]); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " [0x%2X]", HdaWidget->AmpInLeftDefaultGainMute[Index]); } } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); } // // Output amp capabilities and defaults. // if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_OUT_AMP) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out caps: "); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out caps: "); PrintAmpCaps (AsciiBuffer, AsciiBufferSize, HdaWidget->AmpOutCapabilities); - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out vals:"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Amp-Out vals:"); if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_STEREO) { - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, " [0x%2X 0x%2X]", @@ -416,9 +371,9 @@ PrintWidget ( HdaWidget->AmpOutRightDefaultGainMute ); } else { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " [0x%2X]", HdaWidget->AmpOutLeftDefaultGainMute); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " [0x%2X]", HdaWidget->AmpOutLeftDefaultGainMute); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); } // @@ -427,7 +382,7 @@ PrintWidget ( if (HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities) == HDA_WIDGET_TYPE_INPUT || HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities) == HDA_WIDGET_TYPE_OUTPUT) { - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, " Converter: stream=%u, channel=%u\n", @@ -436,7 +391,7 @@ PrintWidget ( ); if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_FORMAT_OVERRIDE) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " PCM:\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " PCM:\n"); PrintRatesFormats (AsciiBuffer, AsciiBufferSize, HdaWidget->SupportedPcmRates, HdaWidget->SupportedFormats); } } @@ -445,51 +400,51 @@ PrintWidget ( // Pin complex capabilities and defaults. // if (HDA_PARAMETER_WIDGET_CAPS_TYPE (HdaWidget->Capabilities) == HDA_WIDGET_TYPE_PIN_COMPLEX) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Pincap 0x%8X:", HdaWidget->PinCapabilities); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Pincap 0x%8X:", HdaWidget->PinCapabilities); if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_INPUT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " IN"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " IN"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_OUTPUT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " OUT"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " OUT"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_HEADPHONE) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " HP"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HP"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_EAPD) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " EAPD"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " EAPD"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_TRIGGER) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Trigger"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Trigger"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_PRESENCE) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Detect"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Detect"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_HBR) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " HBR"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HBR"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_HDMI) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " HDMI"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HDMI"); } if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_DISPLAYPORT) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " DP"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " DP"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); if (HdaWidget->PinCapabilities & HDA_PARAMETER_PIN_CAPS_EAPD) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " EAPD 0x%X:", HdaWidget->DefaultEapd); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " EAPD 0x%X:", HdaWidget->DefaultEapd); if (HdaWidget->DefaultEapd & HDA_EAPD_BTL_ENABLE_BTL) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " BTL"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " BTL"); } if (HdaWidget->DefaultEapd & HDA_EAPD_BTL_ENABLE_EAPD) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " EAPD"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " EAPD"); } if (HdaWidget->DefaultEapd & HDA_EAPD_BTL_ENABLE_L_R_SWAP) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " R/L"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " R/L"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); } - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, " Pin Default 0x%8X: [%a] %a at %a %a\n", @@ -500,7 +455,7 @@ PrintWidget ( mLocations[HDA_VERB_GET_CONFIGURATION_DEFAULT_LOC (HdaWidget->DefaultConfiguration)] ); - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, " Conn = %a, Color = %a\n", @@ -508,7 +463,7 @@ PrintWidget ( mColors[HDA_VERB_GET_CONFIGURATION_DEFAULT_COLOR (HdaWidget->DefaultConfiguration)] ); - PrintHdaBuffer ( + OcAsciiPrintBuffer ( AsciiBuffer, AsciiBufferSize, " DefAssociation = 0x%X, Sequence = 0x%X\n", @@ -516,31 +471,31 @@ PrintWidget ( HDA_VERB_GET_CONFIGURATION_DEFAULT_SEQUENCE (HdaWidget->DefaultConfiguration) ); - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "Pin-ctls: 0x%2X:", HdaWidget->DefaultPinControl); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "Pin-ctls: 0x%2X:", HdaWidget->DefaultPinControl); if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_VREF_EN) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " VREF"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " VREF"); } if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_IN_EN) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " IN"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " IN"); } if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_OUT_EN) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " OUT"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " OUT"); } if (HdaWidget->DefaultPinControl & HDA_PIN_WIDGET_CONTROL_HP_EN) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " HP"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " HP"); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); } // // Connections to other widgets. // if (HdaWidget->Capabilities & HDA_PARAMETER_WIDGET_CAPS_CONN_LIST) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " Connection: %u\n ", HdaWidget->ConnectionCount); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " Connection: %u\n ", HdaWidget->ConnectionCount); for (Index = 0; Index < HdaWidget->ConnectionCount; Index++) { - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, " 0x%2X", HdaWidget->Connections[Index]); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, " 0x%2X", HdaWidget->Connections[Index]); } - PrintHdaBuffer (AsciiBuffer, AsciiBufferSize, "\n"); + OcAsciiPrintBuffer (AsciiBuffer, AsciiBufferSize, "\n"); } } @@ -610,17 +565,17 @@ OcAudioDump ( DevicePathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE); } - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Device path: %s\n", DevicePathStr != NULL ? DevicePathStr : L""); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Device path: %s\n", DevicePathStr != NULL ? DevicePathStr : L""); DEBUG ((DEBUG_INFO, "OCAU: Dumping controller at %s\n", DevicePathStr != NULL ? DevicePathStr : L"")); if (DevicePathStr != NULL) { FreePool (DevicePathStr); } Status = HdaControllerInfo->GetName (HdaControllerInfo, &Name); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Controller: %s\n", Status == EFI_SUCCESS ? Name : L""); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Controller: %s\n", Status == EFI_SUCCESS ? Name : L""); Status = HdaControllerInfo->GetVendorId (HdaControllerInfo, &Tmp32A); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Vendor Id: 0x%X\n", Tmp32A); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Vendor Id: 0x%X\n", Tmp32A); // // Save dumped controller data to file. @@ -684,39 +639,39 @@ OcAudioDump ( DevicePathStr = ConvertDevicePathToText (DevicePath, FALSE, FALSE); } - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Device path: %s\n", DevicePathStr != NULL ? DevicePathStr : L""); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Device path: %s\n", DevicePathStr != NULL ? DevicePathStr : L""); DEBUG ((DEBUG_INFO, "OCAU: Dumping codec at %s\n", DevicePathStr != NULL ? DevicePathStr : L"")); if (DevicePathStr != NULL) { FreePool (DevicePathStr); } Status = HdaCodecInfo->GetAddress (HdaCodecInfo, &Tmp8); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Address: 0x%X\n\n", Tmp8); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Address: 0x%X\n\n", Tmp8); Status = HdaCodecInfo->GetName (HdaCodecInfo, &Name); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Codec: %s\n", Status == EFI_SUCCESS ? Name : L""); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Codec: %s\n", Status == EFI_SUCCESS ? Name : L""); Status = HdaCodecInfo->GetAudioFuncId (HdaCodecInfo, &Tmp8, &TmpBool); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "AFG Function Id: 0x%X (unsol %u)\n", Tmp8, TmpBool); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "AFG Function Id: 0x%X (unsol %u)\n", Tmp8, TmpBool); Status = HdaCodecInfo->GetVendorId (HdaCodecInfo, &Tmp32A); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Vendor Id: 0x%X\n", Tmp32A); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Vendor Id: 0x%X\n", Tmp32A); Status = HdaCodecInfo->GetRevisionId (HdaCodecInfo, &Tmp32A); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Revision Id: 0x%X\n", Tmp32A); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Revision Id: 0x%X\n", Tmp32A); Status = HdaCodecInfo->GetDefaultRatesFormats (HdaCodecInfo, &Tmp32A, &Tmp32B); if (!EFI_ERROR (Status) && (Tmp32A != 0 || Tmp32B != 0)) { - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Default PCM:\n"); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default PCM:\n"); PrintRatesFormats (&FileBuffer, &FileBufferSize, Tmp32A, Tmp32B); } else { - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Default PCM: N/A\n"); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default PCM: N/A\n"); } Status = HdaCodecInfo->GetDefaultAmpCaps (HdaCodecInfo, &Tmp32A, &Tmp32B); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Default Amp-In caps: "); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default Amp-In caps: "); PrintAmpCaps (&FileBuffer, &FileBufferSize, Status == EFI_SUCCESS ? Tmp32A : 0); - PrintHdaBuffer (&FileBuffer, &FileBufferSize, "Default Amp-Out caps: "); + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "Default Amp-Out caps: "); PrintAmpCaps (&FileBuffer, &FileBufferSize, Status == EFI_SUCCESS ? Tmp32B : 0); // diff --git a/Library/OcCpuLib/OcCpuLib.c b/Library/OcCpuLib/OcCpuLib.c index a80243561c817e3b7466ce5b98ca71541f9b1c12..dc6ec581210f23b4d212e087762dec4533980054 100755 --- a/Library/OcCpuLib/OcCpuLib.c +++ b/Library/OcCpuLib/OcCpuLib.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -737,11 +738,10 @@ ScanAmdProcessor ( } } -/** 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 - - @retval EFI_SUCCESS The scan was completed successfully. + @param[in,out] Cpu A pointer to the cpu info structure to fill with results. **/ VOID OcCpuScanProcessor ( @@ -958,6 +958,172 @@ OcCpuScanProcessor ( )); } +VOID +OcCpuGetMsrReport ( + IN OC_CPU_INFO *CpuInfo, + OUT OC_CPU_MSR_REPORT *Report + ) +{ + ASSERT (CpuInfo != NULL); + ASSERT (Report != NULL); + + ZeroMem (Report, sizeof (*Report)); + + // + // The CPU model must be Intel. + // + if (CpuInfo->Vendor[0] != CPUID_VENDOR_INTEL) { + return; + } + + if (CpuInfo->CpuGeneration >= OcCpuGenerationNehalem) { + // + // MSR_PLATFORM_INFO + // + Report->CpuHasMsrPlatformInfo = TRUE; + Report->CpuMsrPlatformInfoValue = AsmReadMsr64 (MSR_NEHALEM_PLATFORM_INFO); + + // + // MSR_TURBO_RATIO_LIMIT + // + Report->CpuHasMsrTurboRatioLimit = TRUE; + Report->CpuMsrTurboRatioLimitValue = AsmReadMsr64 (MSR_NEHALEM_TURBO_RATIO_LIMIT); + + // + // MSR_PKG_POWER_INFO (TODO: To be confirmed) + // + Report->CpuHasMsrPkgPowerInfo = TRUE; + Report->CpuMsrPkgPowerInfoValue = AsmReadMsr64 (MSR_GOLDMONT_PKG_POWER_INFO); + } else { + // + // IA32_MISC_ENABLE + // + Report->CpuHasMsrIa32MiscEnable = TRUE; + Report->CpuMsrIa32MiscEnableValue = AsmReadMsr64 (MSR_IA32_MISC_ENABLES); + + // + // MSR_IA32_EXT_CONFIG + // + Report->CpuHasMsrIa32ExtConfig = TRUE; + Report->CpuMsrIa32ExtConfigValue = AsmReadMsr64 (MSR_IA32_EXT_CONFIG); + + // + // MSR_CORE_FSB_FREQ + // + Report->CpuHasMsrFsbFreq = TRUE; + Report->CpuMsrFsbFreqValue = AsmReadMsr64 (MSR_CORE_FSB_FREQ); + + // + // MSR_IA32_PERF_STATUS + // + Report->CpuHasMsrIa32PerfStatus = TRUE; + Report->CpuMsrIa32PerfStatusValue = AsmReadMsr64 (MSR_IA32_PERF_STATUS); + } + + if (CpuInfo->CpuGeneration >= OcCpuGenerationSandyBridge) { + // + // MSR_BROADWELL_PKG_CST_CONFIG_CONTROL_REGISTER (MSR 0xE2) + // + Report->CpuHasMsrE2 = TRUE; + Report->CpuMsrE2Value = AsmReadMsr64 (MSR_BROADWELL_PKG_CST_CONFIG_CONTROL); + } +} + +VOID +EFIAPI +OcCpuGetMsrReportPerCore ( + IN OUT VOID *Buffer + ) +{ + OC_CPU_MSR_REPORT_PROCEDURE_ARGUMENT *Argument; + EFI_STATUS Status; + UINTN CoreIndex; + + Argument = (OC_CPU_MSR_REPORT_PROCEDURE_ARGUMENT *) Buffer; + + Status = Argument->MpServices->WhoAmI ( + Argument->MpServices, + &CoreIndex + ); + if (EFI_ERROR (Status)) { + return; + } + + OcCpuGetMsrReport (Argument->CpuInfo, &Argument->Reports[CoreIndex]); +} + +OC_CPU_MSR_REPORT * +OcCpuGetMsrReports ( + IN OC_CPU_INFO *CpuInfo, + OUT UINTN *EntryCount + ) +{ + OC_CPU_MSR_REPORT *Reports; + EFI_STATUS Status; + EFI_MP_SERVICES_PROTOCOL *MpServices; + UINTN NumberOfProcessors; + UINTN NumberOfEnabledProcessors; + OC_CPU_MSR_REPORT_PROCEDURE_ARGUMENT Argument; + + ASSERT (CpuInfo != NULL); + ASSERT (EntryCount != NULL); + + MpServices = NULL; + + Status = gBS->LocateProtocol ( + &gEfiMpServiceProtocolGuid, + NULL, + (VOID **) &MpServices + ); + if (!EFI_ERROR (Status)) { + Status = MpServices->GetNumberOfProcessors ( + MpServices, + &NumberOfProcessors, + &NumberOfEnabledProcessors + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "OCCPU: Failed to get the number of processors - %r, assuming one core\n", Status)); + NumberOfProcessors = 1; + } + } else { + DEBUG ((DEBUG_INFO, "OCCPU: Failed to find mp services - %r, assuming one core\n", Status)); + MpServices = NULL; + NumberOfProcessors = 1; + } + + Reports = (OC_CPU_MSR_REPORT *) AllocateZeroPool (NumberOfProcessors * sizeof (OC_CPU_MSR_REPORT)); + if (Reports == NULL) { + return NULL; + } + + // + // Call OcCpuGetMsrReport on the 0th member firstly. + // + OcCpuGetMsrReport (CpuInfo, &Reports[0]); + // + // Then call StartupAllAPs to fill in the rest. + // + if (MpServices != NULL) { + Argument.MpServices = MpServices; + Argument.Reports = Reports; + Argument.CpuInfo = CpuInfo; + + Status = MpServices->StartupAllAPs ( + MpServices, + OcCpuGetMsrReportPerCore, + TRUE, + NULL, + 5000000, + &Argument, + NULL + ); + } + + *EntryCount = NumberOfProcessors; + + return Reports; +} + VOID OcCpuCorrectFlexRatio ( IN OC_CPU_INFO *Cpu diff --git a/Library/OcDeviceMiscLib/MsrDump.c b/Library/OcDeviceMiscLib/MsrDump.c new file mode 100644 index 0000000000000000000000000000000000000000..0438fc7336ba7a55198974253f0886f2c48745e4 --- /dev/null +++ b/Library/OcDeviceMiscLib/MsrDump.c @@ -0,0 +1,204 @@ +/** @file + Copyright (C) 2021, PMheart. 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 +#include +#include +#include +#include +#include + +EFI_STATUS +OcMsrDump ( + IN OC_CPU_INFO *CpuInfo, + IN EFI_FILE_PROTOCOL *Root + ) +{ + EFI_STATUS Status; + OC_CPU_MSR_REPORT *Reports; + UINTN EntryCount; + UINTN Index; + + CHAR8 *FileBuffer; + UINTN FileBufferSize; + CHAR16 TmpFileName[32]; + + ASSERT (CpuInfo != NULL); + ASSERT (Root != NULL); + + FileBufferSize = SIZE_1KB; + FileBuffer = (CHAR8 *) AllocateZeroPool (FileBufferSize); + if (FileBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Reports = OcCpuGetMsrReports (CpuInfo, &EntryCount); + if (Reports == NULL) { + return EFI_UNSUPPORTED; + } + + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "CPU BrandString: %a\nMicrocodeRevision: 0x%08X\nVirtualization %d\n", + CpuInfo->BrandString, + CpuInfo->MicrocodeRevision, + CpuInfo->Hypervisor + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "CPUID %08X %08X %08X %08X\nExtSigEcx %08X\nExtSigEdx %08X\n", + CpuInfo->CpuidVerEax.Uint32, + CpuInfo->CpuidVerEbx.Uint32, + CpuInfo->CpuidVerEcx.Uint32, + CpuInfo->CpuidVerEdx.Uint32, + CpuInfo->CpuidExtSigEcx.Uint32, + CpuInfo->CpuidExtSigEdx.Uint32 + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "Type 0x%02X\nFamily 0x%02X\nModel 0x%02X\nExtModel 0x%02X\nExtFamily 0x%02X\nStepping 0x%02X\n", + CpuInfo->Type, + CpuInfo->Family, + CpuInfo->Model, + CpuInfo->ExtModel, + CpuInfo->ExtFamily, + CpuInfo->Stepping + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "Features 0x%16LX\nExtFeatures 0x%16LX\nSignature 0x%08X\n", + CpuInfo->Features, + CpuInfo->ExtFeatures, + CpuInfo->Signature + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "Brand 0x%02X\nAppleProcessorType 0x%04X\nCstConfigLock %d\nCpuGeneration %d\n", + CpuInfo->Brand, + CpuInfo->AppleProcessorType, + CpuInfo->CstConfigLock, + CpuInfo->CpuGeneration + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "MaxId 0x%08X\nMaxExtId 0x%08X\n", + CpuInfo->MaxId, + CpuInfo->MaxExtId + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "PackageCount %u\nCoreCount %u\nThreadCount %u\n", + CpuInfo->PackageCount, + CpuInfo->CoreCount, + CpuInfo->ThreadCount + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "ExternalClock %u\n", + CpuInfo->ExternalClock + ); + OcAsciiPrintBuffer ( + &FileBuffer, + &FileBufferSize, + "ARTFrequency %Lu\nCPUFrequency %Lu\nCPUFrequencyFromTSC %Lu\nCPUFrequencyFromART %Lu\nTscAdjust %Lu\nCPUFrequencyFromApple %Lu\nCPUFrequencyFromVMT %Lu\nFSBFrequency %Lu\n\n", + CpuInfo->ARTFrequency, + CpuInfo->CPUFrequency, + CpuInfo->CPUFrequencyFromTSC, + CpuInfo->CPUFrequencyFromART, + CpuInfo->TscAdjust, + CpuInfo->CPUFrequencyFromApple, + CpuInfo->CPUFrequencyFromVMT, + CpuInfo->FSBFrequency + ); + + for (Index = 0; Index < EntryCount; ++Index) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "CPU%02d:\n", Index); + + // + // MSR_PLATFORM_INFO + // + if (Reports[Index].CpuHasMsrPlatformInfo) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_PLATFORM_INFO: 0x%llX\n", Reports[Index].CpuMsrPlatformInfoValue); + } + // + // MSR_TURBO_RATIO_LIMIT + // + if (Reports[Index].CpuHasMsrTurboRatioLimit) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_TURBO_RATIO_LIMIT: 0x%llX\n", Reports[Index].CpuMsrTurboRatioLimitValue); + } + // + // MSR_PKG_POWER_INFO (TODO: To be confirmed) + // + if (Reports[Index].CpuHasMsrPkgPowerInfo) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_PKG_POWER_INFO: 0x%llX\n", Reports[Index].CpuMsrPkgPowerInfoValue); + } + + // + // MSR_BROADWELL_PKG_CST_CONFIG_CONTROL_REGISTER (0xE2) + // + if (Reports[Index].CpuHasMsrE2) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_BROADWELL_PKG_CST_CONFIG_CONTROL_REGISTER (0xE2): 0x%llX\n", Reports[Index].CpuMsrPkgPowerInfoValue); + } + + // + // IA32_MISC_ENABLE + // + if (Reports[Index].CpuHasMsrIa32MiscEnable) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "IA32_MISC_ENABLE: 0x%llX\n", Reports[Index].CpuMsrIa32MiscEnableValue); + } + // + // MSR_IA32_EXT_CONFIG + // + if (Reports[Index].CpuHasMsrIa32ExtConfig) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_IA32_EXT_CONFIG: 0x%llX\n", Reports[Index].CpuMsrIa32ExtConfigValue); + } + // + // MSR_FSB_FREQ + // + if (Reports[Index].CpuHasMsrFsbFreq) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_FSB_FREQ: 0x%llX\n", Reports[Index].CpuMsrFsbFreqValue); + } + // + // MSR_IA32_PERF_STATUS + // + if (Reports[Index].CpuHasMsrIa32PerfStatus) { + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "MSR_IA32_PERF_STATUS: 0x%llX\n", Reports[Index].CpuMsrIa32PerfStatusValue); + } + + OcAsciiPrintBuffer (&FileBuffer, &FileBufferSize, "\n"); + } + + // + // Save dumped MSR data to file. + // + if (FileBuffer != NULL) { + UnicodeSPrint (TmpFileName, sizeof (TmpFileName), L"MSRStatus.txt"); + Status = SetFileData (Root, TmpFileName, FileBuffer, (UINT32) AsciiStrLen (FileBuffer)); + DEBUG ((DEBUG_INFO, "OCDM: Dumped MSR data - %r\n", Status)); + + FreePool (FileBuffer); + } + + FreePool (Reports); + + return EFI_SUCCESS; +} diff --git a/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf b/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf index 7de26e3c8106ba455f72a744ee04cd8932d22bb4..2e387015a856c14e589d6eabd0a07ddc577bc9f3 100755 --- a/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf +++ b/Library/OcDeviceMiscLib/OcDeviceMiscLib.inf @@ -30,6 +30,7 @@ OpenCorePkg/OpenCorePkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec [Guids] gEfiEventExitBootServicesGuid @@ -66,6 +67,7 @@ ActivateHpetSupport.c DirectReset.c ForgeUefi.c + MsrDump.c ReleaseUsbOwnership.c ReloadOptionRoms.c ResetAudioTrafficClass.c diff --git a/Library/OcMainLib/OpenCoreMisc.c b/Library/OcMainLib/OpenCoreMisc.c index 5ae3c89b13671aa31b45b55a80c7e1c0b050ef89..819586368b2359aeebe4991807c6df88c08e9c4f 100644 --- a/Library/OcMainLib/OpenCoreMisc.c +++ b/Library/OcMainLib/OpenCoreMisc.c @@ -28,7 +28,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include +#include #include #include #include @@ -90,6 +92,9 @@ ProduceDebugReport ( EFI_FILE_PROTOCOL *Fs; EFI_FILE_PROTOCOL *SysReport; EFI_FILE_PROTOCOL *SubReport; + OC_CPU_INFO CpuInfo; + + OcCpuScanProcessor (&CpuInfo); if (VolumeHandle != NULL) { Fs = LocateRootVolume (VolumeHandle, NULL); @@ -174,6 +179,20 @@ ProduceDebugReport ( } DEBUG ((DEBUG_INFO, "OC: Audio dumping - %r\n", Status)); + Status = SafeFileOpen ( + SysReport, + &SubReport, + L"MSRStatus", + EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, + EFI_FILE_DIRECTORY + ); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "OC: Dumping MSRStatus for report...\n")); + Status = OcMsrDump (&CpuInfo, SubReport); + SubReport->Close (SubReport); + } + DEBUG ((DEBUG_INFO, "OC: MSRStatus dumping - %r\n", Status)); + SysReport->Close (SysReport); Fs->Close (Fs); diff --git a/Library/OcResetSystemLib/OcResetSystemLib.inf b/Library/OcResetSystemLib/OcResetSystemLib.inf index ded5399112ba81eb57b766e45d1c601f962ffde2..e28c3aed65d81fd44131848b9b5521ce2391bd1a 100644 --- a/Library/OcResetSystemLib/OcResetSystemLib.inf +++ b/Library/OcResetSystemLib/OcResetSystemLib.inf @@ -22,6 +22,7 @@ MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec OpenCorePkg/OpenCorePkg.dec + UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] BaseLib diff --git a/Library/OcStringLib/OcAsciiLib.c b/Library/OcStringLib/OcAsciiLib.c index 9b21850dfcfb8f2e3f190a53978fbc45ec77e36a..2d2d67fdfaf50ef48a5670d279ed56883f019799 100755 --- a/Library/OcStringLib/OcAsciiLib.c +++ b/Library/OcStringLib/OcAsciiLib.c @@ -18,6 +18,7 @@ #include #include #include +#include #include // IsAsciiPrint @@ -480,3 +481,48 @@ AsciiFilterString ( ++String; } } + +VOID +EFIAPI +OcAsciiPrintBuffer ( + IN OUT CHAR8 **AsciiBuffer, + IN OUT UINTN *AsciiBufferSize, + IN CONST CHAR8 *FormatString, + ... + ) +{ + EFI_STATUS Status; + VA_LIST Marker; + CHAR8 Tmp[256]; + CHAR8 *NewBuffer; + UINTN NewBufferSize; + + if (*AsciiBuffer == NULL) { + return; + } + + VA_START (Marker, FormatString); + AsciiVSPrint (Tmp, sizeof (Tmp), FormatString, Marker); + VA_END (Marker); + + Status = AsciiStrCatS (*AsciiBuffer, *AsciiBufferSize, Tmp); + if (Status == EFI_BUFFER_TOO_SMALL) { + if (OcOverflowMulUN (*AsciiBufferSize, 2, &NewBufferSize)) { + return; + } + NewBuffer = ReallocatePool (*AsciiBufferSize, NewBufferSize, *AsciiBuffer); + if (NewBuffer == NULL) { + FreePool (*AsciiBuffer); + + *AsciiBuffer = NULL; + *AsciiBufferSize = 0; + + return; + } + + *AsciiBuffer = NewBuffer; + *AsciiBufferSize = NewBufferSize; + + AsciiStrCatS (*AsciiBuffer, *AsciiBufferSize, Tmp); + } +}