Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kernel quirk 'FixAppleVTD' #440

Merged
merged 8 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Docs/Configuration.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,20 @@ \subsection{Quirks Properties}\label{kernelpropsquirks}
link-down state infinitely and a Wi-Fi adapter may fail to discover networks.
Gigabyte is one of the most common OEMs with these issues.

\item
\texttt{DisableIoMapperMapping}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Requirement}: 13.3 (not required for older)\\
\textbf{Description}: Disables mapping PCI bridge device memory in IOMMU (VT-d).

\emph{Note 1}: This option resolves compatibility issues with Wi-Fi, Ethernet and
Thunderbolt devices when AppleVTD is enabled on systems where the native DMAR table
contains one or more Reserved Memory Regions.

\emph{Note 2}: This option is not needed on AMD systems or any Intel system
where the native DMAR table does not contain any Reserved Memory Regions.

\item
\texttt{DisableLinkeditJettison}\\
\textbf{Type}: \texttt{plist\ boolean}\\
Expand Down
2 changes: 2 additions & 0 deletions Docs/Sample.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@
<false/>
<key>DisableIoMapper</key>
<false/>
<key>DisableIoMapperMapping</key>
<false/>
<key>DisableLinkeditJettison</key>
<true/>
<key>DisableRtcChecksum</key>
Expand Down
2 changes: 2 additions & 0 deletions Docs/SampleCustom.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@
<false/>
<key>DisableIoMapper</key>
<false/>
<key>DisableIoMapperMapping</key>
<false/>
<key>DisableLinkeditJettison</key>
<true/>
<key>DisableRtcChecksum</key>
Expand Down
4 changes: 4 additions & 0 deletions Include/Acidanthera/Library/OcAppleKernelLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ typedef enum {
//
KernelQuirkDisableIoMapper,
//
// Disable mapping PCI bridge device memory in IOMMU (VT-d) to resolve compatibility issues.
//
KernelQuirkDisableIoMapperMapping,
//
// Disable AppleRTC checksum writing.
//
KernelQuirkDisableRtcChecksum,
Expand Down
1 change: 1 addition & 0 deletions Include/Acidanthera/Library/OcConfigurationLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ OC_DECLARE (OC_KERNEL_PATCH_ARRAY)
_(BOOLEAN , CustomPciSerialDevice , , FALSE , ()) \
_(BOOLEAN , CustomSmbiosGuid , , FALSE , ()) \
_(BOOLEAN , DisableIoMapper , , FALSE , ()) \
_(BOOLEAN , DisableIoMapperMapping , , FALSE , ()) \
_(BOOLEAN , DisableLinkeditJettison , , FALSE , ()) \
_(BOOLEAN , DisableRtcChecksum , , FALSE , ()) \
_(BOOLEAN , ExtendBTFeatureFlags , , FALSE , ()) \
Expand Down
53 changes: 53 additions & 0 deletions Library/OcAppleKernelLib/CommonPatches.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,58 @@ PatchAppleIoMapperSupport (
return Status;
}

STATIC
CONST UINT8
mAppleIoMapperMappingPatchReplace[] = {
0xC3 ///< ret
};

STATIC
PATCHER_GENERIC_PATCH
mAppleIoMapperMappingPatch = {
.Comment = DEBUG_POINTER ("AppleIoMapperMapping"),
.Base = "__ZN8AppleVTD14addMemoryRangeEyy",
.Find = NULL,
.Mask = NULL,
.Replace = mAppleIoMapperMappingPatchReplace,
.ReplaceMask = NULL,
.Size = sizeof (mAppleIoMapperMappingPatchReplace),
.Count = 1,
.Skip = 0
};

STATIC
EFI_STATUS
PatchAppleIoMapperMapping (
IN OUT PATCHER_CONTEXT *Patcher OPTIONAL,
IN UINT32 KernelVersion
)
{
EFI_STATUS Status;

//
// This patch is not required before macOS 13.3 (kernel 22.4.0)
//
if (!OcMatchDarwinVersion (KernelVersion, KERNEL_VERSION (KERNEL_VERSION_VENTURA, 4, 0), 0)) {
DEBUG ((DEBUG_INFO, "OCAK: [OK] Skipping AppleIoMapperMapping patch on %u\n", KernelVersion));
return EFI_SUCCESS;
}

if (Patcher == NULL) {
DEBUG ((DEBUG_INFO, "OCAK: [OK] Skipping %a on NULL Patcher on %u\n", __func__, KernelVersion));
return EFI_NOT_FOUND;
}

Status = PatcherApplyGenericPatch (Patcher, &mAppleIoMapperMappingPatch);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCAK: [FAIL] Failed to apply patch com.apple.iokit.IOPCIFamily AppleIoMapperMapping - %r\n", Status));
} else {
DEBUG ((DEBUG_INFO, "OCAK: [OK] Patch success com.apple.iokit.IOPCIFamily AppleIoMapperMapping\n"));
}

return Status;
}

STATIC
CONST UINT8
mAppleDummyCpuPmPatchReplace[] = {
Expand Down Expand Up @@ -2557,6 +2609,7 @@ KERNEL_QUIRK gKernelQuirks[] = {
[KernelQuirkCustomSmbiosGuid1] = { "com.apple.driver.AppleSMBIOS", PatchCustomSmbiosGuid },
[KernelQuirkCustomSmbiosGuid2] = { "com.apple.driver.AppleACPIPlatform", PatchCustomSmbiosGuid },
[KernelQuirkDisableIoMapper] = { "com.apple.iokit.IOPCIFamily", PatchAppleIoMapperSupport },
[KernelQuirkDisableIoMapperMapping] = { "com.apple.iokit.IOPCIFamily", PatchAppleIoMapperMapping },
[KernelQuirkDisableRtcChecksum] = { "com.apple.driver.AppleRTC", PatchAppleRtcChecksum },
[KernelQuirkDummyPowerManagement] = { "com.apple.driver.AppleIntelCPUPowerManagement", PatchDummyPowerManagement },
[KernelQuirkExtendBTFeatureFlags] = { "com.apple.iokit.IOBluetoothFamily", PatchBTFeatureFlags },
Expand Down
1 change: 1 addition & 0 deletions Library/OcConfigurationLib/OcConfigurationLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ OC_SCHEMA
OC_SCHEMA_BOOLEAN_IN ("CustomPciSerialDevice", OC_GLOBAL_CONFIG, Kernel.Quirks.CustomPciSerialDevice),
OC_SCHEMA_BOOLEAN_IN ("CustomSMBIOSGuid", OC_GLOBAL_CONFIG, Kernel.Quirks.CustomSmbiosGuid),
OC_SCHEMA_BOOLEAN_IN ("DisableIoMapper", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableIoMapper),
OC_SCHEMA_BOOLEAN_IN ("DisableIoMapperMapping", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableIoMapperMapping),
OC_SCHEMA_BOOLEAN_IN ("DisableLinkeditJettison", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableLinkeditJettison),
OC_SCHEMA_BOOLEAN_IN ("DisableRtcChecksum", OC_GLOBAL_CONFIG, Kernel.Quirks.DisableRtcChecksum),
OC_SCHEMA_BOOLEAN_IN ("ExtendBTFeatureFlags", OC_GLOBAL_CONFIG, Kernel.Quirks.ExtendBTFeatureFlags),
Expand Down
4 changes: 4 additions & 0 deletions Library/OcMainLib/OpenCoreKernelPatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ OcKernelApplyPatches (
OcKernelApplyQuirk (KernelQuirkDisableIoMapper, CacheType, DarwinVersion, Context, NULL);
}

if (Config->Kernel.Quirks.DisableIoMapperMapping) {
OcKernelApplyQuirk (KernelQuirkDisableIoMapperMapping, CacheType, DarwinVersion, Context, NULL);
}

if (Config->Kernel.Quirks.DisableRtcChecksum) {
OcKernelApplyQuirk (KernelQuirkDisableRtcChecksum, CacheType, DarwinVersion, Context, NULL);
}
Expand Down
8 changes: 8 additions & 0 deletions Utilities/TestKextInject/KextInject.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ ApplyKextPatches (
DEBUG ((DEBUG_WARN, "[OK] Success KernelQuirkDisableIoMapper\n"));
}

Status = PrelinkedContextApplyQuirk (Context, KernelQuirkDisableIoMapperMapping, KernelVersion);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "[FAIL] Failed to apply KernelQuirkDisableIoMapperMapping - %r\n", Status));
FailedToProcess = TRUE;
} else {
DEBUG ((DEBUG_WARN, "[OK] Success KernelQuirkDisableIoMapperMapping\n"));
}

Status = PrelinkedContextApplyQuirk (Context, KernelQuirkDisableRtcChecksum, KernelVersion);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "[FAIL] Failed to apply KernelQuirkDisableRtcChecksum - %r\n", Status));
Expand Down