Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 71e49ec

Browse files
AdityaGarg8ardbiesheuvel
authored andcommitted
x86/efistub: Call Apple set_os protocol on dual GPU Intel Macs
0c18184 ("platform/x86: apple-gmux: support MMIO gmux on T2 Macs") brought support for T2 Macs in apple-gmux. But in order to use dual GPU, the integrated GPU has to be enabled. On such dual GPU EFI Macs, the EFI stub needs to report that it is booting macOS in order to prevent the firmware from disabling the iGPU. This patch is also applicable for some non T2 Intel Macs. Based on this patch for GRUB by Andreas Heider <andreas@heider.io>: https://lists.gnu.org/archive/html/grub-devel/2013-12/msg00442.html Credits also goto Kerem Karabay <kekrby@gmail.com> for helping porting the patch to the Linux kernel. Cc: Orlando Chamberlain <orlandoch.dev@gmail.com> Signed-off-by: Aditya Garg <gargaditya08@live.com> [ardb: limit scope using list of DMI matches provided by Lukas and Orlando] Reviewed-by: Lukas Wunner <lukas@wunner.de> Tested-by: Aditya Garg <gargaditya08@live.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent cd61938 commit 71e49ec

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

drivers/firmware/efi/libstub/x86-stub.c

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,68 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
225225
}
226226
}
227227

228+
static bool apple_match_product_name(void)
229+
{
230+
static const char type1_product_matches[][15] = {
231+
"MacBookPro11,3",
232+
"MacBookPro11,5",
233+
"MacBookPro13,3",
234+
"MacBookPro14,3",
235+
"MacBookPro15,1",
236+
"MacBookPro15,3",
237+
"MacBookPro16,1",
238+
"MacBookPro16,4",
239+
};
240+
const struct efi_smbios_type1_record *record;
241+
const u8 *product;
242+
243+
record = (struct efi_smbios_type1_record *)efi_get_smbios_record(1);
244+
if (!record)
245+
return false;
246+
247+
product = efi_get_smbios_string(record, product_name);
248+
if (!product)
249+
return false;
250+
251+
for (int i = 0; i < ARRAY_SIZE(type1_product_matches); i++) {
252+
if (!strcmp(product, type1_product_matches[i]))
253+
return true;
254+
}
255+
256+
return false;
257+
}
258+
259+
static void apple_set_os(void)
260+
{
261+
struct {
262+
unsigned long version;
263+
efi_status_t (__efiapi *set_os_version)(const char *);
264+
efi_status_t (__efiapi *set_os_vendor)(const char *);
265+
} *set_os;
266+
efi_status_t status;
267+
268+
if (!efi_is_64bit() || !apple_match_product_name())
269+
return;
270+
271+
status = efi_bs_call(locate_protocol, &APPLE_SET_OS_PROTOCOL_GUID, NULL,
272+
(void **)&set_os);
273+
if (status != EFI_SUCCESS)
274+
return;
275+
276+
if (set_os->version >= 2) {
277+
status = set_os->set_os_vendor("Apple Inc.");
278+
if (status != EFI_SUCCESS)
279+
efi_err("Failed to set OS vendor via apple_set_os\n");
280+
}
281+
282+
if (set_os->version > 0) {
283+
/* The version being set doesn't seem to matter */
284+
status = set_os->set_os_version("Mac OS X 10.9");
285+
if (status != EFI_SUCCESS)
286+
efi_err("Failed to set OS version via apple_set_os\n");
287+
}
288+
}
289+
228290
efi_status_t efi_adjust_memory_range_protection(unsigned long start,
229291
unsigned long size)
230292
{
@@ -335,9 +397,12 @@ static const efi_char16_t apple[] = L"Apple";
335397

336398
static void setup_quirks(struct boot_params *boot_params)
337399
{
338-
if (IS_ENABLED(CONFIG_APPLE_PROPERTIES) &&
339-
!memcmp(efistub_fw_vendor(), apple, sizeof(apple)))
340-
retrieve_apple_device_properties(boot_params);
400+
if (!memcmp(efistub_fw_vendor(), apple, sizeof(apple))) {
401+
if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
402+
retrieve_apple_device_properties(boot_params);
403+
404+
apple_set_os();
405+
}
341406
}
342407

343408
/*

include/linux/efi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ void efi_native_runtime_setup(void);
385385
#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
386386
#define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
387387
#define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
388+
#define APPLE_SET_OS_PROTOCOL_GUID EFI_GUID(0xc5c5da95, 0x7d5c, 0x45e6, 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77)
388389
#define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
389390
#define EFI_TCG2_FINAL_EVENTS_TABLE_GUID EFI_GUID(0x1e2ed096, 0x30e2, 0x4254, 0xbd, 0x89, 0x86, 0x3b, 0xbe, 0xf8, 0x23, 0x25)
390391
#define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)

0 commit comments

Comments
 (0)