From d01d2d17d492f02a20fdbb5b3e678c73d72557ea Mon Sep 17 00:00:00 2001 From: Henrique Date: Fri, 6 Feb 2026 12:40:08 -0300 Subject: [PATCH] feat(quirks): Integrate AutoModernCPUQuirks for automated CPU support This PR introduces the ModernCPUQuirks module and integrates it into the Clover boot flow. **Key Features:** * **Auto-Detection:** Automatically detects Intel (12th-14th Gen) and AMD (Zen3-Zen5) processors. * **Intelligent Recommendations:** Recommends appropriate OpenCore kernel quirks based on the detected CPU. * **Non-Intrusive:** Respects user-defined settings in `config.plist`. If a user manually sets a quirk, that setting takes precedence. * **New Config Option:** Adds `AutoModernCPUQuirks` to `config.plist` (default: false). **Integration Details:** * **Module:** Added `rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.{c,h}`. * **Settings:** Updated `Config_Quirks.h` and `Settings.h` to support the new boolean option. * **Boot Flow:** Modified `main.cpp` to call the detection logic before `OcLoadKernelSupport`. * **Documentation:** updated `config-sample.plist`. **Build Requirement:** Requires compiling with `-DENABLE_MODERN_CPU_QUIRKS` to enable the functionality. --- .gitignore | 7 + .../CloverV2/EFI/CLOVER/config-sample.plist | 5 + .../Platform/Experimental/ModernCPUQuirks.c | 612 ++++++++++++++++++ .../Platform/Experimental/ModernCPUQuirks.h | 260 ++++++++ .../Experimental/README_Integration.md | 187 ++++++ rEFIt_UEFI/Platform/Experimental/SUMMARY.md | 38 ++ rEFIt_UEFI/Platform/Settings.h | 4 + .../Settings/ConfigPlist/Config_Quirks.h | 9 +- rEFIt_UEFI/refit/main.cpp | 60 ++ 9 files changed, 1181 insertions(+), 1 deletion(-) create mode 100644 rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.c create mode 100644 rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.h create mode 100644 rEFIt_UEFI/Platform/Experimental/README_Integration.md create mode 100644 rEFIt_UEFI/Platform/Experimental/SUMMARY.md diff --git a/.gitignore b/.gitignore index b2184c1a50..4c45412606 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,10 @@ DEBUG_REPORT.md CloverPackage/*.log build_failure.log buildme_run.log + +# Local directories - DO NOT COMMIT +Analysis_CloverV2/ +.bin/ + +# Build logs +my_build_log*.txt diff --git a/CloverPackage/CloverV2/EFI/CLOVER/config-sample.plist b/CloverPackage/CloverV2/EFI/CLOVER/config-sample.plist index aa310c3999..179d386b5b 100644 --- a/CloverPackage/CloverV2/EFI/CLOVER/config-sample.plist +++ b/CloverPackage/CloverV2/EFI/CLOVER/config-sample.plist @@ -1069,6 +1069,11 @@ ProvideCurrentCpuInfo + + + + AutoModernCPUQuirks + ProvideCustomSlide ProvideMaxSlide diff --git a/rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.c b/rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.c new file mode 100644 index 0000000000..abf5402162 --- /dev/null +++ b/rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.c @@ -0,0 +1,612 @@ +/** + * ModernCPUQuirks.c + * + * Experimental Modern CPU Detection and Automatic Quirk Application + * Implementation + * + * Copyright (c) 2024-2026 Clover Hackintosh & Beyond Team + * Author: Clover Team + */ + +#include "ModernCPUQuirks.h" + +#include +#include +#include +#include + +/* ============================================================================ + * Intel CPU Model Definitions (from Intel SDM) + * ============================================================================ + */ + +// Intel Family 6 Models +#define INTEL_MODEL_SKYLAKE_DT 0x5E // Skylake Desktop +#define INTEL_MODEL_SKYLAKE_MB 0x4E // Skylake Mobile +#define INTEL_MODEL_SKYLAKE_X 0x55 // Skylake-X/W +#define INTEL_MODEL_KABY_LAKE_DT 0x9E // Kaby Lake Desktop +#define INTEL_MODEL_KABY_LAKE_MB 0x8E // Kaby Lake Mobile +#define INTEL_MODEL_COFFEE_LAKE_DT 0x9E // Coffee Lake Desktop (same as KL) +#define INTEL_MODEL_COFFEE_LAKE_R_DT 0x9E // Coffee Lake-R (stepping diff) +#define INTEL_MODEL_COMET_LAKE_DT 0xA5 // Comet Lake Desktop +#define INTEL_MODEL_COMET_LAKE_MB 0xA6 // Comet Lake Mobile +#define INTEL_MODEL_ICELAKE_MB 0x7E // Ice Lake Mobile +#define INTEL_MODEL_ICELAKE_DT 0x7D // Ice Lake Desktop +#define INTEL_MODEL_TIGER_LAKE_MB 0x8C // Tiger Lake Mobile +#define INTEL_MODEL_TIGER_LAKE_R 0x8D // Tiger Lake-R +#define INTEL_MODEL_ROCKET_LAKE 0xA7 // Rocket Lake +#define INTEL_MODEL_ALDER_LAKE_DT 0x97 // Alder Lake Desktop +#define INTEL_MODEL_ALDER_LAKE_MB 0x9A // Alder Lake Mobile +#define INTEL_MODEL_RAPTOR_LAKE_DT 0xB7 // Raptor Lake Desktop +#define INTEL_MODEL_RAPTOR_LAKE_MB 0xBA // Raptor Lake Mobile +#define INTEL_MODEL_RAPTOR_LAKE_R 0xBF // Raptor Lake Refresh (14th Gen) +#define INTEL_MODEL_METEOR_LAKE 0xAC // Meteor Lake +#define INTEL_MODEL_ARROW_LAKE 0xC5 // Arrow Lake (preliminary) + +/* ============================================================================ + * AMD CPU Family/Model Definitions + * ============================================================================ + */ + +#define AMD_FAMILY_ZEN 0x17 // Zen, Zen+, Zen2 +#define AMD_FAMILY_ZEN3 0x19 // Zen3, Zen4 +#define AMD_FAMILY_ZEN5 0x1A // Zen5 (expected) + +// Zen Family (0x17) Models +#define AMD_MODEL_ZEN_SUMMIT 0x01 // Summit Ridge (Ryzen 1000) +#define AMD_MODEL_ZEN_NAPLES 0x01 // Naples (EPYC 7001) +#define AMD_MODEL_ZEN_PINNACLE 0x08 // Pinnacle Ridge (Ryzen 2000) +#define AMD_MODEL_ZEN2_MATISSE 0x71 // Matisse (Ryzen 3000) +#define AMD_MODEL_ZEN2_ROME 0x31 // Rome (EPYC 7002) + +// Zen3/4 Family (0x19) Models +#define AMD_MODEL_ZEN3_VERMEER 0x21 // Vermeer (Ryzen 5000) +#define AMD_MODEL_ZEN3_MILAN 0x01 // Milan (EPYC 7003) +#define AMD_MODEL_ZEN4_RAPHAEL 0x61 // Raphael (Ryzen 7000) +#define AMD_MODEL_ZEN4_GENOA 0x11 // Genoa (EPYC 9004) +#define AMD_MODEL_ZEN4_PHX 0x74 // Phoenix (Ryzen 7040) +#define AMD_MODEL_ZEN4_HWK 0x78 // Hawk Point (Ryzen 8000) + +/* ============================================================================ + * CPU Detection Implementation + * ============================================================================ + */ + +EFI_STATUS +ModernCpuDetect(IN OC_CPU_INFO *CpuInfo, OUT MODERN_CPU_INFO *ModernInfo) { + if (CpuInfo == NULL || ModernInfo == NULL) { + return EFI_INVALID_PARAMETER; + } + + ZeroMem(ModernInfo, sizeof(MODERN_CPU_INFO)); + + // Extract CPUID information + ModernInfo->Family = CpuInfo->CpuFamily; + ModernInfo->Model = CpuInfo->CpuModel; + ModernInfo->Stepping = CpuInfo->CpuStepping; + ModernInfo->ExtFamily = CpuInfo->CpuFamily; // OcCpuLib already extends + ModernInfo->ExtModel = CpuInfo->CpuModel; + + // Core counts + ModernInfo->TotalCoreCount = CpuInfo->CoreCount; + ModernInfo->ThreadCount = CpuInfo->ThreadCount; + + // Detect vendor and architecture + if (CpuInfo->CpuVendor == OcCpuVendorIntel) { + // Detect Intel hybrid architecture (Alder Lake+) + if (ModernInfo->Model == INTEL_MODEL_ALDER_LAKE_DT || + ModernInfo->Model == INTEL_MODEL_ALDER_LAKE_MB || + ModernInfo->Model == INTEL_MODEL_RAPTOR_LAKE_DT || + ModernInfo->Model == INTEL_MODEL_RAPTOR_LAKE_MB || + ModernInfo->Model == INTEL_MODEL_RAPTOR_LAKE_R || + ModernInfo->Model == INTEL_MODEL_METEOR_LAKE || + ModernInfo->Model == INTEL_MODEL_ARROW_LAKE) { + ModernInfo->ArchType = CPU_ARCH_HYBRID_INTEL; + ModernInfo->HasHybridArch = TRUE; + + // Note: Accurate P/E core detection requires more complex logic + // For now, we use heuristics + ModernInfo->PerfCoreCount = CpuInfo->CoreCount / 2; + ModernInfo->EffCoreCount = CpuInfo->CoreCount - ModernInfo->PerfCoreCount; + } else { + ModernInfo->ArchType = CPU_ARCH_X86_64_INTEL; + ModernInfo->HasHybridArch = FALSE; + ModernInfo->PerfCoreCount = CpuInfo->CoreCount; + ModernInfo->EffCoreCount = 0; + } + + // Determine Intel Generation + switch (ModernInfo->Model) { + case INTEL_MODEL_SKYLAKE_DT: + case INTEL_MODEL_SKYLAKE_MB: + case INTEL_MODEL_SKYLAKE_X: + ModernInfo->Generation = CPU_GEN_INTEL_SKYLAKE; + break; + + case INTEL_MODEL_KABY_LAKE_DT: + case INTEL_MODEL_KABY_LAKE_MB: + // Need to distinguish Coffee Lake by stepping + if (CpuInfo->CpuStepping >= 10) { + ModernInfo->Generation = CPU_GEN_INTEL_COFFEE_LAKE; + } else { + ModernInfo->Generation = CPU_GEN_INTEL_KABY_LAKE; + } + break; + + case INTEL_MODEL_COMET_LAKE_DT: + case INTEL_MODEL_COMET_LAKE_MB: + ModernInfo->Generation = CPU_GEN_INTEL_COMET_LAKE; + break; + + case INTEL_MODEL_ROCKET_LAKE: + ModernInfo->Generation = CPU_GEN_INTEL_ROCKET_LAKE; + break; + + case INTEL_MODEL_ALDER_LAKE_DT: + case INTEL_MODEL_ALDER_LAKE_MB: + ModernInfo->Generation = CPU_GEN_INTEL_ALDER_LAKE; + break; + + case INTEL_MODEL_RAPTOR_LAKE_DT: + case INTEL_MODEL_RAPTOR_LAKE_MB: + ModernInfo->Generation = CPU_GEN_INTEL_RAPTOR_LAKE; + break; + + case INTEL_MODEL_RAPTOR_LAKE_R: + ModernInfo->Generation = CPU_GEN_INTEL_RAPTOR_LAKE_R; + break; + + case INTEL_MODEL_METEOR_LAKE: + ModernInfo->Generation = CPU_GEN_INTEL_METEOR_LAKE; + break; + + case INTEL_MODEL_ARROW_LAKE: + ModernInfo->Generation = CPU_GEN_INTEL_ARROW_LAKE; + break; + + default: + if (ModernInfo->Family == 6 && ModernInfo->Model >= 0x90) { + // Unknown but modern + ModernInfo->Generation = CPU_GEN_INTEL_RAPTOR_LAKE; + } else { + ModernInfo->Generation = CPU_GEN_INTEL_LEGACY; + } + break; + } + } else if (CpuInfo->CpuVendor == OcCpuVendorAmd) { + ModernInfo->ArchType = CPU_ARCH_X86_64_AMD; + ModernInfo->HasHybridArch = FALSE; + ModernInfo->PerfCoreCount = CpuInfo->CoreCount; + ModernInfo->EffCoreCount = 0; + + // Determine AMD Generation + if (ModernInfo->Family == AMD_FAMILY_ZEN) { + if (ModernInfo->Model >= AMD_MODEL_ZEN2_MATISSE) { + ModernInfo->Generation = CPU_GEN_AMD_ZEN2; + } else if (ModernInfo->Model >= AMD_MODEL_ZEN_PINNACLE) { + ModernInfo->Generation = CPU_GEN_AMD_ZEN_PLUS; + } else { + ModernInfo->Generation = CPU_GEN_AMD_ZEN; + } + } else if (ModernInfo->Family == AMD_FAMILY_ZEN3) { + if (ModernInfo->Model >= AMD_MODEL_ZEN4_RAPHAEL) { + ModernInfo->Generation = CPU_GEN_AMD_ZEN4; + } else { + ModernInfo->Generation = CPU_GEN_AMD_ZEN3; + } + } else if (ModernInfo->Family == AMD_FAMILY_ZEN5) { + ModernInfo->Generation = CPU_GEN_AMD_ZEN5; + } else { + ModernInfo->Generation = CPU_GEN_AMD_LEGACY; + } + } else { + ModernInfo->ArchType = CPU_ARCH_UNKNOWN; + ModernInfo->Generation = CPU_GEN_UNKNOWN; + } + + // Set compatibility flags based on detection + ModernInfo->NeedsProvideCurrentCpuInfo = + (ModernInfo->Generation >= CPU_GEN_INTEL_ALDER_LAKE || + ModernInfo->Generation >= CPU_GEN_AMD_ZEN3); + + ModernInfo->NeedsCpuid1DataSpoof = + (ModernInfo->Generation >= CPU_GEN_INTEL_ALDER_LAKE || + IS_AMD_CPU(ModernInfo)); + + ModernInfo->NeedsXcpmPatches = + (IS_INTEL_CPU(ModernInfo) && + ModernInfo->Generation >= CPU_GEN_INTEL_SKYLAKE); + + ModernInfo->NeedsIoMapperDisable = + (ModernInfo->Generation >= CPU_GEN_INTEL_COFFEE_LAKE); + + ModernInfo->NeedsSpecialPowerManagement = + (IS_HYBRID_CPU(ModernInfo) || IS_AMD_CPU(ModernInfo)); + + DEBUG((DEBUG_INFO, "ModernCPU: Detected %a CPU, Gen=%d, Arch=%d\n", + IS_INTEL_CPU(ModernInfo) + ? "Intel" + : (IS_AMD_CPU(ModernInfo) ? "AMD" : "Unknown"), + ModernInfo->Generation, ModernInfo->ArchType)); + + return EFI_SUCCESS; +} + +/* ============================================================================ + * Quirk Recommendation Implementation + * ============================================================================ + */ + +EFI_STATUS +ModernCpuGetQuirkRecommendation(IN MODERN_CPU_INFO *ModernInfo, + OUT QUIRK_RECOMMENDATION *Recommendation) { + if (ModernInfo == NULL || Recommendation == NULL) { + return EFI_INVALID_PARAMETER; + } + + ZeroMem(Recommendation, sizeof(QUIRK_RECOMMENDATION)); + Recommendation->ConfidenceLevel = 0; + + // Base quirks for all modern macOS + Recommendation->DisableLinkeditJettison = TRUE; + Recommendation->PanicNoKextDump = TRUE; + + if (IS_INTEL_CPU(ModernInfo)) { + // Intel-specific recommendations + + if (ModernInfo->Generation >= CPU_GEN_INTEL_SKYLAKE) { + // CFG Lock unlock is almost always needed + Recommendation->AppleXcpmCfgLock = TRUE; + Recommendation->AppleCpuPmCfgLock = TRUE; + Recommendation->ConfidenceLevel = 80; + } + + if (ModernInfo->Generation >= CPU_GEN_INTEL_ALDER_LAKE) { + // Modern hybrid architectures need special handling + Recommendation->ProvideCurrentCpuInfo = TRUE; + Recommendation->DisableIoMapperMapping = TRUE; + Recommendation->PowerTimeoutKernelPanic = TRUE; + Recommendation->ConfidenceLevel = 95; + + // CPUID spoofing for hybrid CPUs + Recommendation->NeedsCpuidSpoof = TRUE; + + // Spoof to Comet Lake (0x0A0655) for best compatibility + Recommendation->SpoofedCpuid1Data[0] = 0x0A0655; + Recommendation->SpoofedCpuid1Data[1] = 0; + Recommendation->SpoofedCpuid1Data[2] = 0; + Recommendation->SpoofedCpuid1Data[3] = 0; + + Recommendation->SpoofedCpuid1Mask[0] = 0xFFFFFFFF; + Recommendation->SpoofedCpuid1Mask[1] = 0; + Recommendation->SpoofedCpuid1Mask[2] = 0; + Recommendation->SpoofedCpuid1Mask[3] = 0; + + if (IS_HYBRID_CPU(ModernInfo)) { + AsciiSPrint( + Recommendation->Description, sizeof(Recommendation->Description), + "Intel %a Gen Hybrid (P+E cores) - Requires CPUID spoof and " + "ProvideCurrentCpuInfo", + ModernInfo->Generation == CPU_GEN_INTEL_ALDER_LAKE + ? "12th" + : (ModernInfo->Generation == CPU_GEN_INTEL_RAPTOR_LAKE + ? "13th" + : (ModernInfo->Generation == CPU_GEN_INTEL_RAPTOR_LAKE_R + ? "14th" + : "15th+"))); + } + } else if (ModernInfo->Generation >= CPU_GEN_INTEL_COFFEE_LAKE) { + Recommendation->DisableIoMapper = TRUE; + Recommendation->ConfidenceLevel = 85; + + AsciiSPrint( + Recommendation->Description, sizeof(Recommendation->Description), + "Intel %dth Gen - Standard quirks recommended", + ModernInfo->Generation == CPU_GEN_INTEL_COFFEE_LAKE + ? 8 + : (ModernInfo->Generation == CPU_GEN_INTEL_COMET_LAKE ? 10 : 11)); + } else { + AsciiSPrint( + Recommendation->Description, sizeof(Recommendation->Description), + "Intel %dth Gen - Minimal quirks needed", ModernInfo->Generation); + } + } else if (IS_AMD_CPU(ModernInfo)) { + // AMD-specific recommendations + Recommendation->NeedsAMDPatches = TRUE; + Recommendation->ProvideCurrentCpuInfo = TRUE; + Recommendation->PowerTimeoutKernelPanic = TRUE; + + // AMD needs CPUID spoofing to look like Intel + Recommendation->NeedsCpuidSpoof = TRUE; + + // Spoof to Haswell for AMD compatibility + Recommendation->SpoofedCpuid1Data[0] = 0x0306C3; // Haswell + Recommendation->SpoofedCpuid1Data[1] = 0; + Recommendation->SpoofedCpuid1Data[2] = 0; + Recommendation->SpoofedCpuid1Data[3] = 0; + + Recommendation->SpoofedCpuid1Mask[0] = 0xFFFFFFFF; + Recommendation->SpoofedCpuid1Mask[1] = 0; + Recommendation->SpoofedCpuid1Mask[2] = 0; + Recommendation->SpoofedCpuid1Mask[3] = 0; + + if (ModernInfo->Generation >= CPU_GEN_AMD_ZEN4) { + Recommendation->ConfidenceLevel = 90; + AsciiSPrint( + Recommendation->Description, sizeof(Recommendation->Description), + "AMD Zen4 (Ryzen 7000) - Requires AMD patches kexts and CPUID spoof"); + } else if (ModernInfo->Generation >= CPU_GEN_AMD_ZEN3) { + Recommendation->ConfidenceLevel = 92; + AsciiSPrint( + Recommendation->Description, sizeof(Recommendation->Description), + "AMD Zen3 (Ryzen 5000) - Requires AMD patches kexts and CPUID spoof"); + } else if (ModernInfo->Generation >= CPU_GEN_AMD_ZEN2) { + Recommendation->ConfidenceLevel = 95; + AsciiSPrint( + Recommendation->Description, sizeof(Recommendation->Description), + "AMD Zen2 (Ryzen 3000) - Well-tested, requires AMD patches kexts"); + } else { + Recommendation->ConfidenceLevel = 85; + AsciiSPrint(Recommendation->Description, + sizeof(Recommendation->Description), + "AMD Zen/Zen+ - Good support with AMD patches kexts"); + } + } else { + Recommendation->ConfidenceLevel = 10; + AsciiSPrint(Recommendation->Description, + sizeof(Recommendation->Description), + "Unknown CPU vendor - Cannot provide reliable recommendations"); + } + + DEBUG((DEBUG_INFO, "ModernCPU: Quirk recommendation: %a (Confidence: %d%%)\n", + Recommendation->Description, Recommendation->ConfidenceLevel)); + + return EFI_SUCCESS; +} + +/* ============================================================================ + * Apply Quirks to Configuration + * ============================================================================ + */ + +EFI_STATUS +ModernCpuApplyQuirks(IN QUIRK_RECOMMENDATION *Recommendation, + IN OUT OC_GLOBAL_CONFIG *Config, IN BOOLEAN ForceApply) { + if (Recommendation == NULL || Config == NULL) { + return EFI_INVALID_PARAMETER; + } + + DEBUG((DEBUG_INFO, "ModernCPU: Applying quirks (Force=%d)\n", ForceApply)); + +// Apply each quirk if recommended and (force or not already set) +#define APPLY_QUIRK(quirk) \ + if (Recommendation->quirk && (ForceApply || !Config->Kernel.Quirks.quirk)) { \ + Config->Kernel.Quirks.quirk = TRUE; \ + DEBUG((DEBUG_INFO, "ModernCPU: Enabled %a\n", #quirk)); \ + } + + APPLY_QUIRK(ProvideCurrentCpuInfo); + APPLY_QUIRK(AppleXcpmCfgLock); + APPLY_QUIRK(AppleCpuPmCfgLock); + APPLY_QUIRK(AppleXcpmExtraMsrs); + APPLY_QUIRK(AppleXcpmForceBoost); + APPLY_QUIRK(DisableLinkeditJettison); + APPLY_QUIRK(DisableIoMapper); + APPLY_QUIRK(DisableIoMapperMapping); + APPLY_QUIRK(LapicKernelPanic); + APPLY_QUIRK(PanicNoKextDump); + APPLY_QUIRK(PowerTimeoutKernelPanic); + APPLY_QUIRK(XhciPortLimit); + APPLY_QUIRK(ThirdPartyDrives); + APPLY_QUIRK(ExtendBTFeatureFlags); + APPLY_QUIRK(ForceAquantiaEthernet); + APPLY_QUIRK(IncreasePciBarSize); + +#undef APPLY_QUIRK + + // Apply CPUID spoofing if needed + if (Recommendation->NeedsCpuidSpoof) { + if (ForceApply || Config->Kernel.Emulate.Cpuid1Data[0] == 0) { + CopyMem(Config->Kernel.Emulate.Cpuid1Data, + Recommendation->SpoofedCpuid1Data, + sizeof(Config->Kernel.Emulate.Cpuid1Data)); + CopyMem(Config->Kernel.Emulate.Cpuid1Mask, + Recommendation->SpoofedCpuid1Mask, + sizeof(Config->Kernel.Emulate.Cpuid1Mask)); + DEBUG((DEBUG_INFO, "ModernCPU: Applied CPUID spoof: 0x%08X\n", + Recommendation->SpoofedCpuid1Data[0])); + } + } + + return EFI_SUCCESS; +} + +/* ============================================================================ + * Report Generation + * ============================================================================ + */ + +EFI_STATUS +ModernCpuGenerateReport(IN MODERN_CPU_INFO *ModernInfo, + IN QUIRK_RECOMMENDATION *Recommendation, + OUT CHAR8 *Report, IN UINTN ReportSize) { + UINTN Offset; + + if (ModernInfo == NULL || Recommendation == NULL || Report == NULL) { + return EFI_INVALID_PARAMETER; + } + + Offset = AsciiSPrint( + Report, ReportSize, + "=== Modern CPU Detection Report ===\n\n" + "CPU Information:\n" + " Vendor: %a\n" + " Generation: %a (%d)\n" + " Family: 0x%02X, Model: 0x%02X, Stepping: %d\n" + " Core Count: %d total", + IS_INTEL_CPU(ModernInfo) ? "Intel" + : (IS_AMD_CPU(ModernInfo) ? "AMD" : "Unknown"), + ModernCpuGetGenerationName(ModernInfo->Generation), + ModernInfo->Generation, ModernInfo->Family, ModernInfo->Model, + ModernInfo->Stepping, ModernInfo->TotalCoreCount); + + if (IS_HYBRID_CPU(ModernInfo)) { + Offset += AsciiSPrint(Report + Offset, ReportSize - Offset, + " (%d P-cores + %d E-cores)", + ModernInfo->PerfCoreCount, ModernInfo->EffCoreCount); + } + + Offset += AsciiSPrint( + Report + Offset, ReportSize - Offset, + "\n Threads: %d\n" + " Hybrid Architecture: %a\n\n" + "Recommended Quirks (Confidence: %d%%):\n" + " %a\n\n" + "Essential Quirks:\n", + ModernInfo->ThreadCount, ModernInfo->HasHybridArch ? "Yes" : "No", + Recommendation->ConfidenceLevel, Recommendation->Description); + +// List enabled quirks +#define REPORT_QUIRK(quirk) \ + if (Recommendation->quirk) { \ + Offset += \ + AsciiSPrint(Report + Offset, ReportSize - Offset, " - %a\n", #quirk); \ + } + + REPORT_QUIRK(ProvideCurrentCpuInfo); + REPORT_QUIRK(AppleXcpmCfgLock); + REPORT_QUIRK(AppleCpuPmCfgLock); + REPORT_QUIRK(DisableLinkeditJettison); + REPORT_QUIRK(DisableIoMapper); + REPORT_QUIRK(DisableIoMapperMapping); + REPORT_QUIRK(PanicNoKextDump); + REPORT_QUIRK(PowerTimeoutKernelPanic); + +#undef REPORT_QUIRK + + if (Recommendation->NeedsCpuidSpoof) { + Offset += AsciiSPrint(Report + Offset, ReportSize - Offset, + "\nCPUID Spoofing:\n" + " Spoof to: 0x%08X\n", + Recommendation->SpoofedCpuid1Data[0]); + } + + if (Recommendation->NeedsAMDPatches) { + Offset += AsciiSPrint( + Report + Offset, ReportSize - Offset, + "\nRequired Kexts for AMD:\n" + " - AMDRyzenCPUPowerManagement.kext\n" + " - SMCAMDProcessor.kext\n" + " - AMD kernel patches (via OpenCore or patches section)\n"); + } + + AsciiSPrint(Report + Offset, ReportSize - Offset, + "\n=== End of Report ===\n"); + + return EFI_SUCCESS; +} + +/* ============================================================================ + * Helper Functions + * ============================================================================ + */ + +CONST CHAR8 *ModernCpuGetGenerationName(IN CPU_GENERATION Generation) { + switch (Generation) { + case CPU_GEN_INTEL_SKYLAKE: + return "Intel Skylake (6th Gen)"; + case CPU_GEN_INTEL_KABY_LAKE: + return "Intel Kaby Lake (7th Gen)"; + case CPU_GEN_INTEL_COFFEE_LAKE: + return "Intel Coffee Lake (8th/9th Gen)"; + case CPU_GEN_INTEL_COMET_LAKE: + return "Intel Comet Lake (10th Gen)"; + case CPU_GEN_INTEL_ROCKET_LAKE: + return "Intel Rocket Lake (11th Gen)"; + case CPU_GEN_INTEL_ALDER_LAKE: + return "Intel Alder Lake (12th Gen)"; + case CPU_GEN_INTEL_RAPTOR_LAKE: + return "Intel Raptor Lake (13th Gen)"; + case CPU_GEN_INTEL_RAPTOR_LAKE_R: + return "Intel Raptor Lake Refresh (14th Gen)"; + case CPU_GEN_INTEL_METEOR_LAKE: + return "Intel Meteor Lake (15th Gen)"; + case CPU_GEN_INTEL_ARROW_LAKE: + return "Intel Arrow Lake (Future)"; + + case CPU_GEN_AMD_ZEN: + return "AMD Zen (Ryzen 1000)"; + case CPU_GEN_AMD_ZEN_PLUS: + return "AMD Zen+ (Ryzen 2000)"; + case CPU_GEN_AMD_ZEN2: + return "AMD Zen2 (Ryzen 3000)"; + case CPU_GEN_AMD_ZEN3: + return "AMD Zen3 (Ryzen 5000)"; + case CPU_GEN_AMD_ZEN4: + return "AMD Zen4 (Ryzen 7000)"; + case CPU_GEN_AMD_ZEN5: + return "AMD Zen5 (Ryzen 9000)"; + + case CPU_GEN_INTEL_LEGACY: + return "Intel Legacy (Pre-6th Gen)"; + case CPU_GEN_AMD_LEGACY: + return "AMD Legacy (Pre-Zen)"; + default: + return "Unknown"; + } +} + +BOOLEAN +ModernCpuHasKnownIssues(IN MODERN_CPU_INFO *ModernInfo, + OUT CHAR8 *Issues OPTIONAL, IN UINTN IssuesSize) { + BOOLEAN HasIssues = FALSE; + UINTN Offset = 0; + + if (ModernInfo == NULL) { + return FALSE; + } + + if (Issues != NULL) { + Issues[0] = '\0'; + } + + // Check for known issues + if (IS_HYBRID_CPU(ModernInfo)) { + HasIssues = TRUE; + if (Issues != NULL && IssuesSize > Offset) { + Offset += + AsciiSPrint(Issues + Offset, IssuesSize - Offset, + "- Hybrid architecture requires ProvideCurrentCpuInfo " + "and scheduler workarounds\n"); + } + } + + if (ModernInfo->Generation >= CPU_GEN_INTEL_RAPTOR_LAKE_R) { + HasIssues = TRUE; + if (Issues != NULL && IssuesSize > Offset) { + Offset += AsciiSPrint(Issues + Offset, IssuesSize - Offset, + "- 14th Gen Intel may have stability issues on " + "macOS Ventura and below\n"); + } + } + + if (ModernInfo->Generation >= CPU_GEN_AMD_ZEN4) { + HasIssues = TRUE; + if (Issues != NULL && IssuesSize > Offset) { + Offset += AsciiSPrint(Issues + Offset, IssuesSize - Offset, + "- AMD Zen4 requires latest AMD patches and may " + "have USB controller issues\n"); + } + } + + if (ModernInfo->Generation == CPU_GEN_AMD_ZEN5) { + HasIssues = TRUE; + if (Issues != NULL && IssuesSize > Offset) { + Offset += AsciiSPrint( + Issues + Offset, IssuesSize - Offset, + "- AMD Zen5 is cutting-edge and may have incomplete macOS support\n"); + } + } + + return HasIssues; +} diff --git a/rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.h b/rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.h new file mode 100644 index 0000000000..866029c296 --- /dev/null +++ b/rEFIt_UEFI/Platform/Experimental/ModernCPUQuirks.h @@ -0,0 +1,260 @@ +/** + * ModernCPUQuirks.h + * + * Experimental Modern CPU Detection and Automatic Quirk Application + * + * This module provides intelligent detection of modern CPUs (Ryzen 7000/9000, + * Intel 14th Gen, etc.) and automatically recommends/applies the appropriate + * OpenCore kernel quirks for optimal macOS compatibility. + * + * Copyright (c) 2024-2026 Clover Hackintosh & Beyond Team + * Author: Clover Team + * + * This is an EXPERIMENTAL module for testing in Clover Hackintosh & Beyond + * before potential inclusion in the official Clover repository. + */ + +#ifndef MODERN_CPU_QUIRKS_H +#define MODERN_CPU_QUIRKS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/* ============================================================================ + * CPU Generation Definitions + * ============================================================================ + */ + +// Intel CPU Generations (Desktop/Mobile) +typedef enum { + CPU_GEN_UNKNOWN = 0, + + // Intel Legacy (before 6th Gen) - Not targeted + CPU_GEN_INTEL_LEGACY = 1, + + // Intel Modern Generations + CPU_GEN_INTEL_SKYLAKE = 6, // 6th Gen + CPU_GEN_INTEL_KABY_LAKE = 7, // 7th Gen + CPU_GEN_INTEL_COFFEE_LAKE = 8, // 8th/9th Gen + CPU_GEN_INTEL_COMET_LAKE = 10, // 10th Gen + CPU_GEN_INTEL_ROCKET_LAKE = 11, // 11th Gen + CPU_GEN_INTEL_ALDER_LAKE = 12, // 12th Gen + CPU_GEN_INTEL_RAPTOR_LAKE = 13, // 13th Gen + CPU_GEN_INTEL_RAPTOR_LAKE_R = 14, // 14th Gen (Raptor Lake Refresh) + CPU_GEN_INTEL_METEOR_LAKE = 15, // Future + CPU_GEN_INTEL_ARROW_LAKE = 16, // Future + + // AMD CPU Generations + CPU_GEN_AMD_LEGACY = 100, + CPU_GEN_AMD_ZEN = 101, // Ryzen 1000 series + CPU_GEN_AMD_ZEN_PLUS = 102, // Ryzen 2000 series + CPU_GEN_AMD_ZEN2 = 103, // Ryzen 3000 series + CPU_GEN_AMD_ZEN3 = 104, // Ryzen 5000 series + CPU_GEN_AMD_ZEN4 = 105, // Ryzen 7000 series + CPU_GEN_AMD_ZEN5 = 106, // Ryzen 9000 series (Future) + +} CPU_GENERATION; + +// CPU Architecture Type +typedef enum { + CPU_ARCH_UNKNOWN = 0, + CPU_ARCH_X86_64_INTEL = 1, + CPU_ARCH_X86_64_AMD = 2, + CPU_ARCH_HYBRID_INTEL = 3, // P-cores + E-cores (Alder Lake+) +} CPU_ARCHITECTURE_TYPE; + +/* ============================================================================ + * Modern CPU Detection Result + * ============================================================================ + */ + +typedef struct { + CPU_GENERATION Generation; + CPU_ARCHITECTURE_TYPE ArchType; + + // CPU Details + UINT32 Family; + UINT32 Model; + UINT32 Stepping; + UINT32 ExtFamily; + UINT32 ExtModel; + + // Core Configuration (for hybrid CPUs) + UINT32 PerfCoreCount; // P-cores (Performance) + UINT32 EffCoreCount; // E-cores (Efficiency) + UINT32 TotalCoreCount; + UINT32 ThreadCount; + + // Features + BOOLEAN HasAVX512; + BOOLEAN HasHybridArch; + BOOLEAN HasTME; // Total Memory Encryption + + // Compatibility Flags + BOOLEAN NeedsProvideCurrentCpuInfo; + BOOLEAN NeedsCpuid1DataSpoof; + BOOLEAN NeedsXcpmPatches; + BOOLEAN NeedsIoMapperDisable; + BOOLEAN NeedsSpecialPowerManagement; + +} MODERN_CPU_INFO; + +/* ============================================================================ + * Quirk Recommendation Result + * ============================================================================ + */ + +typedef struct { + // Essential Quirks (almost always needed for modern CPUs) + BOOLEAN ProvideCurrentCpuInfo; + BOOLEAN AppleXcpmCfgLock; + BOOLEAN AppleCpuPmCfgLock; + BOOLEAN DisableLinkeditJettison; + + // Architecture-Specific Quirks + BOOLEAN AppleXcpmExtraMsrs; + BOOLEAN AppleXcpmForceBoost; + BOOLEAN PowerTimeoutKernelPanic; + + // Hardware-Specific Quirks + BOOLEAN DisableIoMapper; + BOOLEAN DisableIoMapperMapping; + BOOLEAN LapicKernelPanic; + BOOLEAN PanicNoKextDump; + + // Optional Quirks + BOOLEAN XhciPortLimit; + BOOLEAN ThirdPartyDrives; + BOOLEAN ExtendBTFeatureFlags; + BOOLEAN ForceAquantiaEthernet; + BOOLEAN IncreasePciBarSize; + + // AMD-Specific (typically just markers, actual patches come from kexts) + BOOLEAN NeedsAMDPatches; + + // CPUID Spoofing (for unsupported CPUs) + BOOLEAN NeedsCpuidSpoof; + UINT32 SpoofedCpuid1Data[4]; + UINT32 SpoofedCpuid1Mask[4]; + + // Confidence Level (0-100) + UINT8 ConfidenceLevel; + + // Description of detected configuration + CHAR8 Description[256]; + +} QUIRK_RECOMMENDATION; + +/* ============================================================================ + * Function Declarations + * ============================================================================ + */ + +/** + * Detect the current CPU and determine its generation and architecture. + * + * @param[in] CpuInfo The OC_CPU_INFO structure from OpenCore's OcCpuLib + * @param[out] ModernInfo Filled with modern CPU detection results + * + * @return EFI_SUCCESS if detection completed successfully + */ +EFI_STATUS +ModernCpuDetect(IN OC_CPU_INFO *CpuInfo, OUT MODERN_CPU_INFO *ModernInfo); + +/** + * Get recommended quirks for the detected modern CPU. + * + * @param[in] ModernInfo The detected modern CPU information + * @param[out] Recommendation Filled with recommended quirk settings + * + * @return EFI_SUCCESS if recommendations were generated + */ +EFI_STATUS +ModernCpuGetQuirkRecommendation(IN MODERN_CPU_INFO *ModernInfo, + OUT QUIRK_RECOMMENDATION *Recommendation); + +/** + * Apply recommended quirks to the OpenCore configuration. + * This function modifies the config in-place based on recommendations. + * + * @param[in] Recommendation The quirk recommendations to apply + * @param[in,out] Config The OC_GLOBAL_CONFIG to modify + * @param[in] ForceApply If TRUE, overwrite existing quirk settings + * If FALSE, only set quirks that are currently + * disabled + * + * @return EFI_SUCCESS if quirks were applied successfully + */ +EFI_STATUS +ModernCpuApplyQuirks(IN QUIRK_RECOMMENDATION *Recommendation, + IN OUT OC_GLOBAL_CONFIG *Config, IN BOOLEAN ForceApply); + +/** + * Generate a human-readable report of the CPU detection and recommendations. + * + * @param[in] ModernInfo The detected modern CPU information + * @param[in] Recommendation The quirk recommendations + * @param[out] Report Buffer to receive the report (must be at least + * 2048 bytes) + * @param[in] ReportSize Size of the Report buffer + * + * @return EFI_SUCCESS if report was generated + */ +EFI_STATUS +ModernCpuGenerateReport(IN MODERN_CPU_INFO *ModernInfo, + IN QUIRK_RECOMMENDATION *Recommendation, + OUT CHAR8 *Report, IN UINTN ReportSize); + +/** + * Get the string name for a CPU generation enum value. + * + * @param[in] Generation The CPU generation value + * + * @return Pointer to a static string describing the generation + */ +CONST CHAR8 *ModernCpuGetGenerationName(IN CPU_GENERATION Generation); + +/** + * Check if this CPU is known to have specific compatibility issues. + * + * @param[in] ModernInfo The detected modern CPU information + * @param[out] Issues Buffer to receive issue descriptions (optional) + * @param[in] IssuesSize Size of the Issues buffer + * + * @return TRUE if known issues exist, FALSE otherwise + */ +BOOLEAN +ModernCpuHasKnownIssues(IN MODERN_CPU_INFO *ModernInfo, + OUT CHAR8 *Issues OPTIONAL, IN UINTN IssuesSize); + +/* ============================================================================ + * Helper Macros + * ============================================================================ + */ + +#define IS_INTEL_CPU(ModernInfo) \ + ((ModernInfo)->ArchType == CPU_ARCH_X86_64_INTEL || \ + (ModernInfo)->ArchType == CPU_ARCH_HYBRID_INTEL) + +#define IS_AMD_CPU(ModernInfo) ((ModernInfo)->ArchType == CPU_ARCH_X86_64_AMD) + +#define IS_HYBRID_CPU(ModernInfo) \ + ((ModernInfo)->ArchType == CPU_ARCH_HYBRID_INTEL) + +#define IS_MODERN_INTEL(ModernInfo) \ + (IS_INTEL_CPU(ModernInfo) && \ + (ModernInfo)->Generation >= CPU_GEN_INTEL_ALDER_LAKE) + +#define IS_MODERN_AMD(ModernInfo) \ + (IS_AMD_CPU(ModernInfo) && (ModernInfo)->Generation >= CPU_GEN_AMD_ZEN4) + +#ifdef __cplusplus +} +#endif + +#endif /* MODERN_CPU_QUIRKS_H */ diff --git a/rEFIt_UEFI/Platform/Experimental/README_Integration.md b/rEFIt_UEFI/Platform/Experimental/README_Integration.md new file mode 100644 index 0000000000..0f6fb3d484 --- /dev/null +++ b/rEFIt_UEFI/Platform/Experimental/README_Integration.md @@ -0,0 +1,187 @@ +/** + * ModernCPUQuirks_Integration.md + * + * Guide for integrating ModernCPUQuirks into Clover Bootloader + * + * This document explains how to integrate the experimental ModernCPUQuirks + * module into the Clover boot flow to enable automatic quirk detection + * and application for modern CPUs. + */ + +# ModernCPUQuirks Integration Guide + +## Overview + +The `ModernCPUQuirks` module provides intelligent detection of modern CPUs +(Intel 12th-14th Gen, AMD Zen3-Zen5) and automatically recommends/applies +the appropriate OpenCore kernel quirks for optimal macOS compatibility. + +## How It Works + +``` +┌────────────────────────────────────────────────────────────────────────────┐ +│ CLOVER BOOT FLOW │ +├────────────────────────────────────────────────────────────────────────────┤ +│ │ +│ ┌─────────────┐ ┌──────────────────────┐ ┌──────────────────────┐ │ +│ │ OC_CPU_INFO │────▶│ ModernCpuDetect() │────▶│ MODERN_CPU_INFO │ │ +│ │ (from │ │ - Identifies CPU Gen │ │ - Generation │ │ +│ │ OcCpuLib) │ │ - Detects hybrid arch│ │ - ArchType │ │ +│ └─────────────┘ │ - Sets compat flags │ │ - Compatibility flags│ │ +│ └──────────────────────┘ └──────────┬───────────┘ │ +│ │ │ +│ ▼ │ +│ ┌──────────────────────────────────────────────────┐ │ +│ │ ModernCpuGetQuirkRecommendation() │ │ +│ │ - Analyzes CPU requirements │ │ +│ │ - Generates QUIRK_RECOMMENDATION │ │ +│ │ - Includes CPUID spoof values for unsupported CPUs│ │ +│ └──────────────────────────────┬───────────────────┘ │ +│ │ │ +│ ▼ │ +│ ┌────────────────────────────────────────────────────────────────────┐ │ +│ │ ModernCpuApplyQuirks() │ │ +│ │ - Applies recommendations to mOpenCoreConfiguration │ │ +│ │ - Respects existing user settings (unless ForceApply=TRUE) │ │ +│ └────────────────────────────────────────────────────────────────────┘ │ +│ │ │ +│ ▼ │ +│ ┌────────────────────────────────────────────────────────────────────┐ │ +│ │ OcLoadKernelSupport() │ │ +│ │ - OpenCore's kernel patching engine │ │ +│ │ - Now has correctly configured quirks for modern CPUs │ │ +│ └────────────────────────────────────────────────────────────────────┘ │ +│ │ +└────────────────────────────────────────────────────────────────────────────┘ +``` + +## Integration Points in main.cpp + +### Step 1: Add Include + +In `rEFIt_UEFI/refit/main.cpp`, add the include: + +```cpp +#include "../Platform/Experimental/ModernCPUQuirks.h" +``` + +### Step 2: Add Auto-Detection Call + +In the `LOADER_ENTRY::StartLoader()` function, after `OcMiscLateInit()` and +before `OcLoadKernelSupport()`, add: + +```cpp +// === EXPERIMENTAL: Modern CPU Auto-Quirks === +#ifdef ENABLE_MODERN_CPU_QUIRKS +{ + MODERN_CPU_INFO ModernCpuInfo; + QUIRK_RECOMMENDATION QuirkRecommendation; + EFI_STATUS QuirkStatus; + + // Detect modern CPU + QuirkStatus = ModernCpuDetect(&mOpenCoreCpuInfo, &ModernCpuInfo); + + if (!EFI_ERROR(QuirkStatus)) { + // Get quirk recommendations + QuirkStatus = ModernCpuGetQuirkRecommendation(&ModernCpuInfo, &QuirkRecommendation); + + if (!EFI_ERROR(QuirkStatus)) { + DBG("ModernCPU: %a (Confidence: %d%%)\n", + QuirkRecommendation.Description, + QuirkRecommendation.ConfidenceLevel); + + // Apply quirks if auto-mode is enabled + if (gSettings.Quirks.AutoModernCPUQuirks) { + QuirkStatus = ModernCpuApplyQuirks( + &QuirkRecommendation, + &mOpenCoreConfiguration, + FALSE // Don't override user settings + ); + + if (!EFI_ERROR(QuirkStatus)) { + DBG("ModernCPU: Applied automatic quirks\n"); + } + } + + // Generate report if debug enabled + if (gSettings.KernelAndKextPatches.KPDebug) { + CHAR8 Report[2048]; + ModernCpuGenerateReport(&ModernCpuInfo, &QuirkRecommendation, Report, sizeof(Report)); + DBG("%a\n", Report); + } + } + } +} +#endif // ENABLE_MODERN_CPU_QUIRKS +``` + +### Step 3: Add Config Option + +In `ConfigPlist.h` or equivalent, add a new setting: + +```cpp +// In Quirks section +XBool AutoModernCPUQuirks; // Enable automatic quirk detection for modern CPUs +``` + +### Step 4: Compile Flag + +Add to the build configuration (in GNUmakefile or relevant build file): + +```makefile +# Enable experimental Modern CPU Quirks +EXPERIMENTAL_FLAGS += -DENABLE_MODERN_CPU_QUIRKS +``` + +## Usage in config.plist + +```xml +Quirks + + + AutoModernCPUQuirks + + + + ProvideCurrentCpuInfo + + +``` + +## Priority Order + +1. **User-defined quirks** (in config.plist) take priority +2. **Auto-detected quirks** fill in gaps when `AutoModernCPUQuirks` is enabled +3. **Default values** are used if neither is set + +## Supported CPUs + +### Intel +- **12th Gen (Alder Lake)**: Full support, CPUID spoof to Comet Lake +- **13th Gen (Raptor Lake)**: Full support, CPUID spoof to Comet Lake +- **14th Gen (Raptor Lake Refresh)**: Full support, CPUID spoof to Comet Lake +- **15th Gen (Meteor Lake)**: Experimental support +- **Arrow Lake and beyond**: Basic support, may need additional patches + +### AMD +- **Zen3 (Ryzen 5000)**: Full support, requires AMD patches kexts +- **Zen4 (Ryzen 7000)**: Good support, requires AMD patches kexts +- **Zen5 (Ryzen 9000)**: Experimental support + +## Testing + +Before enabling in production: + +1. Build Clover with `ENABLE_MODERN_CPU_QUIRKS` defined +2. Set `AutoModernCPUQuirks` to `true` in config.plist +3. Enable debug logging (`KPDebug` = `true`) +4. Boot and check `preboot.log` for the detection report +5. Verify that the detected quirks match your expectations +6. If issues occur, disable `AutoModernCPUQuirks` and use manual quirks + +## Future Enhancements + +1. **GPU-based detection**: Auto-detect AMD/NVIDIA GPU quirks +2. **Motherboard-specific quirks**: Handle VT-d, CFG Lock per manufacturer +3. **macOS version awareness**: Adjust quirks based on target macOS version +4. **Learning mode**: Learn from successful boots and suggest optimizations diff --git a/rEFIt_UEFI/Platform/Experimental/SUMMARY.md b/rEFIt_UEFI/Platform/Experimental/SUMMARY.md new file mode 100644 index 0000000000..f3494ef086 --- /dev/null +++ b/rEFIt_UEFI/Platform/Experimental/SUMMARY.md @@ -0,0 +1,38 @@ +# ModernCPUQuirks - Experimental Module + +## Overview + +This experimental module provides automatic CPU detection and quirk +recommendation for modern Intel and AMD processors in Clover Bootloader. + +## Technical Background + +Clover already uses OpenCore's kernel patching engine (`OcLoadKernelSupport`). +This module enhances the automatic configuration of quirks for newer hardware. + +## Supported CPUs + +### Intel +- 12th Gen (Alder Lake) - Full support +- 13th Gen (Raptor Lake) - Full support +- 14th Gen (Raptor Lake Refresh) - Full support +- 15th Gen (Meteor Lake) - Experimental + +### AMD +- Zen3 (Ryzen 5000) - Full support +- Zen4 (Ryzen 7000) - Good support +- Zen5 (Ryzen 9000) - Experimental + +## Files + +- `ModernCPUQuirks.h` - API definitions +- `ModernCPUQuirks.c` - Implementation +- `README_Integration.md` - Integration guide + +## Status + +**EXPERIMENTAL** - Requires `ENABLE_MODERN_CPU_QUIRKS` build flag. + +## License + +Same as Clover Bootloader (BSD) diff --git a/rEFIt_UEFI/Platform/Settings.h b/rEFIt_UEFI/Platform/Settings.h index 6dbcf15934..481ffe7710 100644 --- a/rEFIt_UEFI/Platform/Settings.h +++ b/rEFIt_UEFI/Platform/Settings.h @@ -2397,6 +2397,7 @@ class SETTINGS_DATA { XBool ThirdPartyDrives = false; XBool XhciPortLimit = false; XBool ProvideCurrentCpuInfo = false; + XBool AutoModernCPUQuirks = false; // Auto-detect quirks for modern CPUs #if __cplusplus > 201703L XBool operator==(const OcKernelQuirksClass &) const = default; @@ -2430,6 +2431,8 @@ class SETTINGS_DATA { return false; if (!(ProvideCurrentCpuInfo == other.ProvideCurrentCpuInfo)) return false; + if (!(AutoModernCPUQuirks == other.AutoModernCPUQuirks)) + return false; return true; } @@ -2449,6 +2452,7 @@ class SETTINGS_DATA { ThirdPartyDrives = other.dgetThirdPartyDrives(); XhciPortLimit = other.dgetXhciPortLimit(); ProvideCurrentCpuInfo = other.dgetProvideCurrentCpuInfo(); + AutoModernCPUQuirks = other.dgetAutoModernCPUQuirks(); } }; diff --git a/rEFIt_UEFI/Settings/ConfigPlist/Config_Quirks.h b/rEFIt_UEFI/Settings/ConfigPlist/Config_Quirks.h index bf247e311e..28efab4803 100644 --- a/rEFIt_UEFI/Settings/ConfigPlist/Config_Quirks.h +++ b/rEFIt_UEFI/Settings/ConfigPlist/Config_Quirks.h @@ -78,6 +78,8 @@ class Quirks_Class : public XmlDict { XmlBool ThirdPartyDrives = XmlBool(); XmlBool XhciPortLimit = XmlBool(); XmlBool ProvideCurrentCpuInfo = XmlBool(); + XmlBool AutoModernCPUQuirks = + XmlBool(); // Auto-detect quirks for modern CPUs XBool dgetAppleXcpmExtraMsrs() const { return AppleXcpmExtraMsrs.isDefined() ? AppleXcpmExtraMsrs.value() @@ -144,6 +146,10 @@ class Quirks_Class : public XmlDict { ? ProvideCurrentCpuInfo.value() : ProvideCurrentCpuInfo.nullValue; }; + XBool dgetAutoModernCPUQuirks() const { + return AutoModernCPUQuirks.isDefined() ? AutoModernCPUQuirks.value() + : AutoModernCPUQuirks.nullValue; + }; OcKernelQuirks_Class(const Quirks_Class &_parent) /*: parent(_parent)*/ {} }; @@ -286,7 +292,7 @@ class Quirks_Class : public XmlDict { OcKernelQuirks_Class OcKernelQuirks; OcBooterQuirks_Class OcBooterQuirks; - XmlDictField m_fields[39] = { + XmlDictField m_fields[40] = { {"AvoidRuntimeDefrag", OcBooterQuirks.AvoidRuntimeDefrag}, {"DevirtualiseMmio", OcBooterQuirks.DevirtualiseMmio}, {"DisableSingleUser", OcBooterQuirks.DisableSingleUser}, @@ -326,6 +332,7 @@ class Quirks_Class : public XmlDict { {"ThirdPartyDrives", OcKernelQuirks.ThirdPartyDrives}, {"XhciPortLimit", OcKernelQuirks.XhciPortLimit}, {"ProvideCurrentCpuInfo", OcKernelQuirks.ProvideCurrentCpuInfo}, + {"AutoModernCPUQuirks", OcKernelQuirks.AutoModernCPUQuirks}, }; Quirks_Class() : OcKernelQuirks(*this), OcBooterQuirks(*this) {} diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index ac167cef00..adb7dbec88 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -51,6 +51,11 @@ #include "../Platform/DataHubCpu.h" #include "../Platform/Edid.h" #include "../Platform/Events.h" + +// Experimental: Modern CPU Quirks auto-detection +#ifdef ENABLE_MODERN_CPU_QUIRKS +#include "../Platform/Experimental/ModernCPUQuirks.h" +#endif #include "../Platform/Hibernate.h" #include "../Platform/Injectors.h" #include "../Platform/KextList.h" @@ -1340,6 +1345,61 @@ void LOADER_ENTRY::StartLoader() { mOpenCoreConfiguration.Kernel.Quirks.ProvideCurrentCpuInfo = gSettings.Quirks.OcKernelQuirks.ProvideCurrentCpuInfo; + // Experimental: Auto-detect and apply quirks for modern CPUs +#ifdef ENABLE_MODERN_CPU_QUIRKS + if (gSettings.Quirks.OcKernelQuirks.AutoModernCPUQuirks) { + MODERN_CPU_INFO ModernInfo; + QUIRK_RECOMMENDATION QuirkRec; + + DBG("ModernCPUQuirks: Auto-detection enabled, detecting CPU...\n"); + + EFI_STATUS Status = ModernCpuDetect(&mOpenCoreCpuInfo, &ModernInfo); + if (!EFI_ERROR(Status)) { + DBG("ModernCPUQuirks: Detected CPU Family=0x%X Model=0x%X Gen=%d\n", + ModernInfo.CpuFamily, ModernInfo.CpuModel, ModernInfo.Generation); + + Status = ModernCpuGetQuirkRecommendation(&ModernInfo, &QuirkRec); + if (!EFI_ERROR(Status) && QuirkRec.ConfidenceLevel > 50) { + DBG("ModernCPUQuirks: Applying recommended quirks " + "(confidence=%d%%)\n", + QuirkRec.ConfidenceLevel); + + // Apply quirks only if not already set by user + if (!mOpenCoreConfiguration.Kernel.Quirks.ProvideCurrentCpuInfo && + QuirkRec.ProvideCurrentCpuInfo) { + mOpenCoreConfiguration.Kernel.Quirks.ProvideCurrentCpuInfo = TRUE; + DBG("ModernCPUQuirks: Enabled ProvideCurrentCpuInfo\n"); + } + if (!mOpenCoreConfiguration.Kernel.Quirks.DisableIoMapperMapping && + QuirkRec.DisableIoMapperMapping) { + mOpenCoreConfiguration.Kernel.Quirks.DisableIoMapperMapping = TRUE; + DBG("ModernCPUQuirks: Enabled DisableIoMapperMapping\n"); + } + if (!mOpenCoreConfiguration.Kernel.Quirks.PowerTimeoutKernelPanic && + QuirkRec.PowerTimeoutKernelPanic) { + mOpenCoreConfiguration.Kernel.Quirks.PowerTimeoutKernelPanic = TRUE; + DBG("ModernCPUQuirks: Enabled PowerTimeoutKernelPanic\n"); + } + if (!mOpenCoreConfiguration.Kernel.Quirks.AppleXcpmCfgLock && + QuirkRec.AppleXcpmCfgLock) { + mOpenCoreConfiguration.Kernel.Quirks.AppleXcpmCfgLock = TRUE; + DBG("ModernCPUQuirks: Enabled AppleXcpmCfgLock\n"); + } + if (!mOpenCoreConfiguration.Kernel.Quirks.AppleCpuPmCfgLock && + QuirkRec.AppleCpuPmCfgLock) { + mOpenCoreConfiguration.Kernel.Quirks.AppleCpuPmCfgLock = TRUE; + DBG("ModernCPUQuirks: Enabled AppleCpuPmCfgLock\n"); + } + } else { + DBG("ModernCPUQuirks: Low confidence (%d%%), skipping auto-quirks\n", + QuirkRec.ConfidenceLevel); + } + } else { + DBG("ModernCPUQuirks: CPU detection failed, status=%r\n", Status); + } + } +#endif + mOpenCoreConfiguration.Kernel.Add.Count = (UINT32)kextArray.size(); mOpenCoreConfiguration.Kernel.Add.AllocCount = mOpenCoreConfiguration.Kernel.Add.Count;