77 IN OC_GLOBAL_CONFIG *Config,
79 IN UINT32 DarwinVersion,
91 OC_KERNEL_PATCH_ENTRY *UserPatch;
97 BOOLEAN IsKernelPatch;
99 UINT32 RegisterStride;
101 IsKernelPatch = Context == NULL;
113 if (EFI_ERROR (Status)) {
114 DEBUG ((DEBUG_ERROR,
"OC: Kernel patcher kernel init failure - %r\n", Status));
122 if (!IsKernelPatch) {
123 if (Config->Kernel.Quirks.AppleCpuPmCfgLock) {
127 if (Config->Kernel.Quirks.ExternalDiskIcons) {
131 if (Config->Kernel.Quirks.ThirdPartyDrives) {
135 if (Config->Kernel.Quirks.XhciPortLimit) {
141 if (Config->Kernel.Quirks.DisableIoMapper) {
145 if (Config->Kernel.Quirks.DisableIoMapperMapping) {
149 if (Config->Kernel.Quirks.DisableRtcChecksum) {
153 if (Config->Kernel.Quirks.IncreasePciBarSize) {
157 if (Config->Kernel.Quirks.CustomSmbiosGuid) {
162 if (Config->Kernel.Quirks.ExtendBTFeatureFlags) {
166 if (Config->Kernel.Quirks.ForceAquantiaEthernet) {
170 if (Config->Kernel.Quirks.ForceSecureBootScheme) {
174 if (Config->Kernel.Emulate.DummyPowerManagement) {
182 "OC: %a patcher skips DummyPowerManagement patch due to version %u <= %u <= %u\n",
194 if (Config->Kernel.Quirks.SetApfsTrimTimeout >= 0) {
199 if (Config->Kernel.Quirks.AppleXcpmCfgLock) {
203 if (Config->Kernel.Quirks.AppleXcpmExtraMsrs) {
207 if (Config->Kernel.Quirks.AppleXcpmForceBoost) {
214 if (Config->Misc.Serial.Override && Config->Kernel.Quirks.CustomPciSerialDevice) {
216 RegisterStride = PatchPcdGet32 (PcdSerialRegisterStride);
217 if ( (((RegisterBase != 0) && (RegisterStride != 0)))
218 && ((RegisterBase != 0x3F8U) || (RegisterStride != 1)))
223 DEBUG ((DEBUG_INFO,
"OC: Aborting patching PciSerialDevice because RegisterBase is zero/default value!\n"));
227 if (Config->Kernel.Quirks.PanicNoKextDump) {
231 if ( (Config->Kernel.Emulate.Cpuid1Data[0] != 0)
232 || (Config->Kernel.Emulate.Cpuid1Data[1] != 0)
233 || (Config->Kernel.Emulate.Cpuid1Data[2] != 0)
234 || (Config->Kernel.Emulate.Cpuid1Data[3] != 0))
242 Config->Kernel.Emulate.Cpuid1Data,
243 Config->Kernel.Emulate.Cpuid1Mask,
249 "OC: %a patcher skips kernel CPUID patch due to version %u <= %u <= %u\n",
258 if (Config->Kernel.Quirks.LapicKernelPanic) {
262 if (Config->Kernel.Quirks.PowerTimeoutKernelPanic) {
266 if (Config->Kernel.Quirks.DisableLinkeditJettison) {
270 if (Config->Kernel.Quirks.LegacyCommpage) {
274 if (Config->Kernel.Quirks.ProvideCurrentCpuInfo) {
279 for (Index = 0; Index < Config->Kernel.Patch.Count; ++Index) {
280 UserPatch = Config->Kernel.Patch.Values[Index];
283 if (!UserPatch->Enabled || ((AsciiStrCmp (Target,
"kernel") == 0) != IsKernelPatch)) {
292 if (AsciiStrCmp (Arch, Is32Bit ?
"x86_64" :
"i386") == 0) {
295 "OC: %a patcher skips %a (%a) patch at %u due to arch %a != %a\n",
301 Is32Bit ?
"i386" :
"x86_64"
309 "OC: %a patcher skips %a (%a) patch at %u due to version %u <= %u <= %u\n",
328 if ( (UserPatch->Replace.Size == 0)
329 || ((
OC_BLOB_GET (&UserPatch->Base)[0] ==
'\0') && (UserPatch->Find.Size != UserPatch->Replace.Size))
330 || ((UserPatch->Mask.Size > 0) && (UserPatch->Find.Size != UserPatch->Mask.Size))
331 || ((UserPatch->ReplaceMask.Size > 0) && (UserPatch->Find.Size != UserPatch->ReplaceMask.Size)))
333 DEBUG ((DEBUG_ERROR,
"OC: Kernel patch %u for %a (%a) is borked\n", Index, Target, Comment));
337 ZeroMem (&Patch,
sizeof (Patch));
339 if (
OC_BLOB_GET (&UserPatch->Comment)[0] !=
'\0') {
347 if (UserPatch->Find.Size > 0) {
353 if (UserPatch->Mask.Size > 0) {
357 if (UserPatch->ReplaceMask.Size > 0) {
361 Patch.
Size = UserPatch->Replace.Size;
362 Patch.
Count = UserPatch->Count;
363 Patch.
Skip = UserPatch->Skip;
364 Patch.
Limit = UserPatch->Limit;
376 Status = EFI_UNSUPPORTED;
381 EFI_ERROR (Status) ? DEBUG_WARN : DEBUG_INFO,
382 "OC: %a patcher result %u for %a (%a) - %r\n",