Skip to content

Commit c871e24

Browse files
committed
uefi: Call Apple set_os protocol to keep iGPU alive on dual-GPU Macs
1 parent d56aec6 commit c871e24

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

common/entry.s3.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,48 @@ void stage3_common(void);
3131
extern symbol __slide, __image_base, __image_end;
3232
extern symbol _start;
3333

34+
#if defined (__x86_64__)
35+
static void apple_set_os(void) {
36+
if (gST->FirmwareVendor == NULL) {
37+
return;
38+
}
39+
40+
static const CHAR16 apple[] = L"Apple";
41+
for (size_t i = 0; i < SIZEOF_ARRAY(apple) - 1; i++) {
42+
if (gST->FirmwareVendor[i] != apple[i]) {
43+
return;
44+
}
45+
}
46+
47+
EFI_GUID apple_set_os_guid = {
48+
0xc5c5da95, 0x7d5c, 0x45e6,
49+
{ 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77 }
50+
};
51+
52+
struct apple_set_os_iface {
53+
uint64_t version;
54+
EFI_STATUS (EFIAPI *set_os_version)(const char *version);
55+
EFI_STATUS (EFIAPI *set_os_vendor)(const char *vendor);
56+
} *set_os = NULL;
57+
58+
EFI_STATUS status = gBS->LocateProtocol(
59+
&apple_set_os_guid, NULL, (void **)&set_os);
60+
if (status || set_os == NULL) {
61+
return;
62+
}
63+
64+
if (set_os->version >= 2) {
65+
set_os->set_os_vendor("Apple Inc.");
66+
}
67+
if (set_os->version > 0) {
68+
set_os->set_os_version("Mac OS X 10.9");
69+
}
70+
71+
printv("apple: Set OS version via Apple set_os protocol (version %u)\n",
72+
(uint32_t)set_os->version);
73+
}
74+
#endif
75+
3476
noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
3577
gST = SystemTable;
3678
gBS = SystemTable->BootServices;
@@ -76,6 +118,10 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
76118

77119
term_fallback();
78120

121+
#if defined (__x86_64__)
122+
apple_set_os();
123+
#endif
124+
79125
status = gBS->SetWatchdogTimer(0, 0x10000, 0, NULL);
80126
if (status) {
81127
print("WARNING: Failed to disable watchdog timer!\n");

0 commit comments

Comments
 (0)