Skip to content

Commit

Permalink
Add patch for apple_set_os support in the EFI stub
Browse files Browse the repository at this point in the history
  • Loading branch information
kekrby committed Aug 16, 2023
1 parent c908e50 commit 46dd873
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions 2010-efi-libstub-add-support-for-the-apple_set_os-protoco.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
From 33029b7ba2235a4bb67e61063984869206ceb1e3 Mon Sep 17 00:00:00 2001
From: Kerem Karabay <[email protected]>
Date: Thu, 5 Jan 2023 21:07:54 +0300
Subject: [PATCH] efi: libstub: add support for the apple_set_os protocol

On 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.

See also this patch for GRUB by Andreas Heider <[email protected]>:
https://lists.gnu.org/archive/html/grub-devel/2013-12/msg00442.html

Signed-off-by: Kerem Karabay <[email protected]>
---
drivers/firmware/efi/libstub/efistub.h | 13 +++++++++++++
drivers/firmware/efi/libstub/x86-stub.c | 26 +++++++++++++++++++++++++
include/linux/efi.h | 1 +
3 files changed, 40 insertions(+)

diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 54a2822cae77..78601b65f9c8 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -824,6 +824,19 @@ union apple_properties_protocol {
} mixed_mode;
};

+typedef struct apple_set_os_protocol apple_set_os_protocol_t;
+
+struct apple_set_os_protocol {
+ u64 version;
+ efi_status_t (__efiapi *set_os_version) (const char *);
+ efi_status_t (__efiapi *set_os_vendor) (const char *);
+ struct {
+ u32 version;
+ u32 set_os_version;
+ u32 set_os_vendor;
+ } mixed_mode;
+};
+
typedef u32 efi_tcg2_event_log_format;

#define INITRD_EVENT_TAG_ID 0x8F3B22ECU
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index a0bfd31358ba..ec0100683d9f 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -212,6 +212,30 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
}
}

+static void apple_set_os(void)
+{
+ efi_guid_t guid = APPLE_SET_OS_PROTOCOL_GUID;
+ apple_set_os_protocol_t *set_os;
+ efi_status_t status;
+
+ status = efi_bs_call(locate_protocol, &guid, NULL, (void **)&set_os);
+ if (status != EFI_SUCCESS)
+ return;
+
+ if (efi_table_attr(set_os, version) >= 2) {
+ status = efi_fn_call(set_os, set_os_vendor, "Apple Inc.");
+ if (status != EFI_SUCCESS)
+ efi_err("Failed to set OS vendor via apple_set_os\n");
+ }
+
+ /* The version being set doesn't seem to matter */
+ if (efi_table_attr(set_os, version) > 0) {
+ status = efi_fn_call(set_os, set_os_version, "Mac OS X 10.9");
+ if (status != EFI_SUCCESS)
+ efi_err("Failed to set OS version via apple_set_os\n");
+ }
+}
+
static void
adjust_memory_range_protection(unsigned long start, unsigned long size)
{
@@ -322,6 +346,8 @@ static void setup_quirks(struct boot_params *boot_params,
if (!memcmp(fw_vendor, apple, sizeof(apple))) {
if (IS_ENABLED(CONFIG_APPLE_PROPERTIES))
retrieve_apple_device_properties(boot_params);
+
+ apple_set_os();
}

if (IS_ENABLED(CONFIG_EFI_DXE_MEM_ATTRIBUTES))
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 571d1a6e1b74..21c066ce29d0 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -385,6 +385,7 @@ void efi_native_runtime_setup(void);
#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
#define EFI_CONSOLE_OUT_DEVICE_GUID EFI_GUID(0xd3b36f2c, 0xd551, 0x11d4, 0x9a, 0x46, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)
#define APPLE_PROPERTIES_PROTOCOL_GUID EFI_GUID(0x91bd12fe, 0xf6c3, 0x44fb, 0xa5, 0xb7, 0x51, 0x22, 0xab, 0x30, 0x3a, 0xe0)
+#define APPLE_SET_OS_PROTOCOL_GUID EFI_GUID(0xc5c5da95, 0x7d5c, 0x45e6, 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77)
#define EFI_TCG2_PROTOCOL_GUID EFI_GUID(0x607f766c, 0x7455, 0x42be, 0x93, 0x0b, 0xe4, 0xd7, 0x6d, 0xb2, 0x72, 0x0f)
#define EFI_LOAD_FILE_PROTOCOL_GUID EFI_GUID(0x56ec3091, 0x954c, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)
#define EFI_LOAD_FILE2_PROTOCOL_GUID EFI_GUID(0x4006c0c1, 0xfcb3, 0x403e, 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d)
--
2.41.0

0 comments on commit 46dd873

Please sign in to comment.