Skip to content

Commit 9f59339

Browse files
committed
OcAfterCompatLib: Added 11.0 support for AvoidRuntimeDefrag
1 parent bb12f5f commit 9f59339

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ OpenCore Changelog
1717
- Fixed assertions caused by unaligned file path access in DEBUG builds
1818
- Renamed `ConfigValidity` utility to `ocvalidate` for consistency
1919
- Added `GlobalConnect` for APFS loading to workaround older firmware issues
20+
- Added 11.0 support for `AvoidRuntimeDefrag` Booter quirk
2021

2122
#### v0.5.9
2223
- Added full HiDPI support in OpenCanopy

Include/Acidanthera/Library/OcBootManagementLib.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,14 +1035,15 @@ OcGetAppleBootLoadedImage (
10351035
by other libraries, so values are often pointers to original fields.
10361036
**/
10371037
typedef struct OC_BOOT_ARGUMENTS_ {
1038-
UINT32 *MemoryMap;
1039-
UINT32 *MemoryMapSize;
1040-
UINT32 *MemoryMapDescriptorSize;
1041-
UINT32 *MemoryMapDescriptorVersion;
1042-
CHAR8 *CommandLine;
1043-
UINT32 *DeviceTreeP;
1044-
UINT32 *DeviceTreeLength;
1045-
UINT32 *CsrActiveConfig;
1038+
UINT32 *MemoryMap;
1039+
UINT32 *MemoryMapSize;
1040+
UINT32 *MemoryMapDescriptorSize;
1041+
UINT32 *MemoryMapDescriptorVersion;
1042+
CHAR8 *CommandLine;
1043+
UINT32 *DeviceTreeP;
1044+
UINT32 *DeviceTreeLength;
1045+
UINT32 *CsrActiveConfig;
1046+
EFI_SYSTEM_TABLE *SystemTable;
10461047
} OC_BOOT_ARGUMENTS;
10471048

10481049
/**

Library/OcAfterBootCompatLib/BootCompatInternal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ typedef struct KERNEL_SUPPORT_STATE_ {
256256
///
257257
UINTN SysTableRtAreaSize;
258258
///
259+
/// Physical configuration table location.
260+
///
261+
EFI_CONFIGURATION_TABLE *ConfigurationTable;
262+
///
259263
/// Virtual memory mapper context.
260264
///
261265
OC_VMEM_CONTEXT VmContext;

Library/OcAfterBootCompatLib/KernelSupport.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ AppleMapPrepareForBooting (
381381
DescriptorSize,
382382
MemoryMap
383383
);
384+
385+
//
386+
// On native Macs due to EfiBoot defragmentation it is guaranteed that
387+
// VADDR % BASE_1GB == PADDR. macOS 11 started to rely on this in
388+
// acpi_count_enabled_logical_processors, which needs to access MADT (APIC)
389+
// ACPI table, and does that through ConfigurationTables.
390+
//
391+
// The simplest approach is to just copy the table, so that it is accessible
392+
// at both actual mapping and 1:1 defragmented mapping. This should be safe,
393+
// as the memory for 1:1 defragmented mapping is reserved by EfiBoot in the
394+
// first place and is otherwise stolen anyway.
395+
//
396+
if (BootCompat->KernelState.ConfigurationTable != NULL) {
397+
CopyMem (
398+
(VOID*) ((UINTN) BA.SystemTable->ConfigurationTable & (BASE_1GB - 1)),
399+
BootCompat->KernelState.ConfigurationTable,
400+
sizeof (*BootCompat->KernelState.ConfigurationTable) * BA.SystemTable->NumberOfTableEntries
401+
);
402+
}
384403
}
385404
}
386405

@@ -545,6 +564,10 @@ AppleMapPrepareBooterState (
545564
gST,
546565
gST->Hdr.HeaderSize
547566
);
567+
//
568+
// Remember physical configuration table location.
569+
//
570+
BootCompat->KernelState.ConfigurationTable = gST->ConfigurationTable;
548571
}
549572

550573
//

Library/OcBootManagementLib/BootArguments.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ OcParseBootArgs (
4545

4646
Arguments->DeviceTreeP = &BA1->deviceTreeP;
4747
Arguments->DeviceTreeLength = &BA1->deviceTreeLength;
48+
Arguments->SystemTable = (EFI_SYSTEM_TABLE*)(UINTN) BA1->efiSystemTable;
4849
} else {
4950
//
5051
// Lion and newer
@@ -58,6 +59,7 @@ OcParseBootArgs (
5859

5960
Arguments->DeviceTreeP = &BA2->deviceTreeP;
6061
Arguments->DeviceTreeLength = &BA2->deviceTreeLength;
62+
Arguments->SystemTable = (EFI_SYSTEM_TABLE*)(UINTN) BA2->efiSystemTable;
6163

6264
if (BA2->flags & kBootArgsFlagCSRActiveConfig) {
6365
Arguments->CsrActiveConfig = &BA2->csrActiveConfig;

0 commit comments

Comments
 (0)