Skip to contentSkip to conversation

Add support for eGPUs on Apple Products

PATCH Superseded Atharva Tiwari 5 participants 16 messages Jan 28 – Feb 2

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for eGPUs on Apple Products

This series adds support for eGPUs on Apple products, by enabling apple-set-os on all apple devices.

A side effect of this patch is that the iGPU becomes enabled on iMacs. However, iMacs can’t use the iGPU to drive the display (They can't link-train the internal display),
so displays must be disabled on iMacs.

Changes in v2:
- Reworded cover-letter
- Transferred logic to has_no_display in the 2nd patch

Link to v1:
https://lore.kernel.org/all/[email protected]/

Atharva Tiwari (2):
efi/libstub: enable apple-set-os for all apple devices drm/i915/display: Disable display for iMac's

 drivers/firmware/efi/libstub/x86-stub.c       | 22 +++++--------------
 .../drm/i915/display/intel_display_device.c   | 13 ++++++++++-
 2 files changed, 17 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 efi/libstub: enable apple-set-os for all apple devices

Make apple-set-os run on all macs, as
apple-set-os is needed to use eGPUs and iGPU.

(tested on iMac20,1)

---
 drivers/firmware/efi/libstub/x86-stub.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/firmware/efi/libstub/x86-stub.c +5 -17
index cef32e2c82d8..60e1a41bfe5f 100644
@@ -303,32 +303,20 @@ static const struct efi_smbios_record *get_table_record(u8 type)
 
 static bool apple_match_product_name(void)
 {
-	static const char type1_product_matches[][15] = {
-		"MacBookPro11,3",
-		"MacBookPro11,5",
-		"MacBookPro13,3",
-		"MacBookPro14,3",
-		"MacBookPro15,1",
-		"MacBookPro15,3",
-		"MacBookPro16,1",
-		"MacBookPro16,4",
-	};
 	const struct efi_smbios_type1_record *record;
-	const u8 *product;
+	const u8 *vendor;
 
 	record = (struct efi_smbios_type1_record *)
 			(efi_get_smbios_record(1) ?: get_table_record(1));
 	if (!record)
 		return false;
 
-	product = efi_get_smbios_string(record, product_name);
-	if (!product)
+	vendor = efi_get_smbios_string(record, manufacturer);
+	if (!vendor)
 		return false;
 
-	for (int i = 0; i < ARRAY_SIZE(type1_product_matches); i++) {
-		if (!strcmp(product, type1_product_matches[i]))
-			return true;
-	}
+	if (!strcmp(vendor, "Apple Inc."))
+		return true;
 
 	return false;
 }
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/2] efi/libstub: enable apple-set-os for all apple devices

Quoted 2 lines · Atharva Tiwari

Make apple-set-os run on all macs, as
apple-set-os is needed to use eGPUs and iGPU.

As discussed previously, your patch will regress older MacBook Airs which use SPI to access keyboard + trackpad if the set_os protocol is invoked:

https://lore.kernel.org/all/[email protected]/

The last time this topic came up, I suggested counting the number of GPUs instead of using the DMI quirk. I even provided a patch but nobody with an eGPU bothered to test it, so the thread fizzled out:

https://lore.kernel.org/all/[email protected]/

Maybe you could give it a spin and verify if it fixes the issue for you?

Thanks,

Lukas

#3 lore raw

Re: [PATCH v2 1/2] efi/libstub: enable apple-set-os for all apple devices

Quoted 6 lines

As discussed previously, your patch will regress older MacBook Airs which use SPI to access keyboard + trackpad if the set_os protocol is invoked:

https://lore.kernel.org/all/[email protected]/

Quoted 7 lines

The last time this topic came up, I suggested counting the number of GPUs instead of using the DMI quirk. I even provided a patch but nobody with an eGPU bothered to test it, so the thread fizzled out:

https://lore.kernel.org/all/[email protected]/

Maybe you could give it a spin and verify if it fixes the issue for you?

I tested your patch, and well it works (you still need the 2nd patch to avoid a blank screen), but i can see how this will fail
like for example, with the iMacPro (only has dGPU) you would need 2 eGPUs to turn on apple-set-os.

My opinion is, we disable apple-set-os using a dmi check on the 2013/2014 MacbookAir models.

#4 lore raw

Re: [PATCH v2 1/2] efi/libstub: enable apple-set-os for all apple devices

Quoted 10 lines · Atharva Tiwari
Quoted 10 lines

As discussed previously, your patch will regress older MacBook Airs which use SPI to access keyboard + trackpad if the set_os protocol is invoked:

https://lore.kernel.org/all/[email protected]/

The last time this topic came up, I suggested counting the number of GPUs instead of using the DMI quirk. I even provided a patch but nobody with an eGPU bothered to test it, so the thread fizzled out:

Quoted 8 lines
Quoted 3 lines

https://lore.kernel.org/all/[email protected]/

Maybe you could give it a spin and verify if it fixes the issue for you?

I tested your patch, and well it works (you still need the 2nd patch to avoid a blank screen), but i can see how this will fail
like for example, with the iMacPro (only has dGPU) you would need 2 eGPUs to turn on apple-set-os.

I don't quite follow. The patch counts the number of GPUs and uses the set_os protocol if there are at least 2 of them. One dGPU + one eGPU = 2, so the protocol is used.

Am I missing something?

Thanks,

Lukas

#5 lore raw

Re: [PATCH v2 1/2] efi/libstub: enable apple-set-os for all apple devices

Quoted 5 lines

I don't quite follow. The patch counts the number of GPUs and uses the set_os protocol if there are at least 2 of them. One dGPU + one eGPU = 2, so the protocol is used.

Am I missing something?

Well your not, and it was a mistake of me, which i apologize for.

but i still think a MacBookAir dmi check would be better, as theoretically you can connect a eGPU to a 2013/2014 MacBookAir, which would enable set-os, and will cause problems in applespi.c

#6 lore raw

Re: [PATCH v2 1/2] efi/libstub: enable apple-set-os for all apple devices

In reply to Lukas Wunner
Quoted 1 line

Maybe you could give it a spin and verify if it fixes the issue for you?

I tested it, and only tested to see if it booted.
now again i tested, and it seems my iGPU and eGPU wasnt detected? and after futher debuging i found that setup_efi_pci only detected dGPU, so using update_nr_gpus was useless.

and about the macbookair situation, i say we just exclude macbook from enabling apple-set-os via a smbios quirk.

#7 lore raw

PATCH v2 2/2 drm/i915/display: Disable display for iMac's

In reply to Atharva Tiwari

Disable display on iMacs, as they can't do link training on the internal display.

(tested on iMac20,1)

---
 .../gpu/drm/i915/display/intel_display_device.c    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_display_device.c +13 -1
index 1170afaa8680..b1fec1018d7e 100644
@@ -3,6 +3,7 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include <linux/dmi.h>
 #include <linux/pci.h>
 
 #include <drm/drm_color_mgmt.h>
@@ -1435,7 +1436,18 @@ static bool has_no_display(struct pci_dev *pdev)
 		{}
 	};
 
-	return pci_match_id(ids, pdev);
+	static const struct dmi_system_id dmi_ids[] = {
+		{
+			.ident = "Apple Inc. iMac",
+			.matches = {
+				DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
+				DMI_MATCH(DMI_PRODUCT_NAME, "iMac"),
+			}
+		},
+		{}
+	};
+
+	return pci_match_id(ids, pdev) || dmi_check_system(dmi_ids);
 }
 
 #define INTEL_DISPLAY_DEVICE(_id, _desc) { .devid = (_id), .desc = (_desc) }
Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCH v2 2/2] drm/i915/display: Disable display for iMac's

Quoted 2 lines · Atharva Tiwari

Disable display on iMacs, as they can't do link training on the internal display.

I'd expand on that a bit, based on the previous discussion.

Quoted 4 lines

(tested on iMac20,1)

I can't test this, but if nobody chimes in to oppose, I'll take it.

Quoted 36 lines
---
 .../gpu/drm/i915/display/intel_display_device.c    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_display_device.c +13 -1
index 1170afaa8680..b1fec1018d7e 100644
@@ -3,6 +3,7 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include <linux/dmi.h>
 #include <linux/pci.h>
 
 #include <drm/drm_color_mgmt.h>
@@ -1435,7 +1436,18 @@ static bool has_no_display(struct pci_dev *pdev)
 		{}
 	};
 
-	return pci_match_id(ids, pdev);
+	static const struct dmi_system_id dmi_ids[] = {
+		{
+			.ident = "Apple Inc. iMac",
+			.matches = {
+				DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
+				DMI_MATCH(DMI_PRODUCT_NAME, "iMac"),
+			}
+		},
+		{}
+	};
+
+	return pci_match_id(ids, pdev) || dmi_check_system(dmi_ids);
 }
 
 #define INTEL_DISPLAY_DEVICE(_id, _desc) { .devid = (_id), .desc = (_desc) }
Signature · 1 line
Jani Nikula, Intel
#9 lore raw

Re: [PATCH v2 2/2] drm/i915/display: Disable display for iMac's

Quoted 4 lines · Jani Nikula
Quoted 2 lines · Atharva Tiwari

Disable display on iMacs, as they can't do link training on the internal display.

Quoted 8 lines

I'd expand on that a bit, based on the previous discussion.

Quoted 4 lines

(tested on iMac20,1)

I can't test this, but if nobody chimes in to oppose, I'll take it.

I guess the main problem with a hack like this is that you won't be able to get deep pkgC states due to the display hardware not going into DC5/6.

But I can't immediately think of other issues due this being an iGPU, so eg. runtime PCI D3 doesn't really do anything meaningful and thus the display hardware remaining powered on shouldn't matter that much (apart from the increased power usage).

Quoted 43 lines
Quoted 36 lines
---
 .../gpu/drm/i915/display/intel_display_device.c    | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/display/intel_display_device.c +13 -1
index 1170afaa8680..b1fec1018d7e 100644
@@ -3,6 +3,7 @@
  * Copyright © 2023 Intel Corporation
  */
 
+#include <linux/dmi.h>
 #include <linux/pci.h>
 
 #include <drm/drm_color_mgmt.h>
@@ -1435,7 +1436,18 @@ static bool has_no_display(struct pci_dev *pdev)
 		{}
 	};
 
-	return pci_match_id(ids, pdev);
+	static const struct dmi_system_id dmi_ids[] = {
+		{
+			.ident = "Apple Inc. iMac",
+			.matches = {
+				DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
+				DMI_MATCH(DMI_PRODUCT_NAME, "iMac"),
+			}
+		},
+		{}
+	};
+
+	return pci_match_id(ids, pdev) || dmi_check_system(dmi_ids);
 }
 
 #define INTEL_DISPLAY_DEVICE(_id, _desc) { .devid = (_id), .desc = (_desc) }
Signature · 1 line
Jani Nikula, Intel
Signature · 2 lines
Ville Syrjälä
Intel
#10 lore raw

Re: [PATCH v2 2/2] drm/i915/display: Disable display for iMac's

Quoted 10 lines · Ville Syrjälä
Quoted 5 lines · Jani Nikula
Quoted 4 lines · Atharva Tiwari

Disable display on iMacs, as they can't do link training on the internal display.

(tested on iMac20,1)

I guess the main problem with a hack like this is that you won't be able to get deep pkgC states due to the display hardware not going into DC5/6.

If patch [1/2] in this series results in a power regression, I'd say it needs to be reworked. Either exclude iMacs from the set_os protocol or find a way to power down the iGPU again once the kernel has assumed control.

I wonder what macOS does. If the iGPU is exposed by set_os, surely macOS must be able to power down the iGPU again, so we should be doing the same.

Thanks,

Lukas

#11 lore raw

Re: [PATCH v2 2/2] drm/i915/display: Disable display for iMac's

In reply to Atharva Tiwari
Quoted 4 lines · Atharva Tiwari

Disable display on iMacs, as they can't do link training on the internal display.

(tested on iMac20,1)

So with your patch the screen is black on those iMacs? I don't quite understand why that would be desirable.

What happens without this patch? Something worse than a black screen? This needs to be explained in the commit message so that reviewers understand why the patch is needed.

I also don't understand why this patch follows the EFI set_os one. What's the connection between those two patches? If there is none, they shouldn't be submitted as a series but as two individual patches.

Thanks,

Lukas

#12 lore raw
In reply to Atharva Tiwari
Quoted 7 lines · Atharva Tiwari

This series adds support for eGPUs on Apple products, by enabling apple-set-os on all apple devices.

A side effect of this patch is that the iGPU becomes enabled on iMacs. However, iMacs can’t use the iGPU to drive the display (They can't link-train the internal display),
so displays must be disabled on iMacs.

Oh there's the explanation that should have been in the commit message of patch [2/2].

It's possible that the iMac has a multiplexer built-in which can switch between the iGPU and dGPU at runtime. Please ensure that you have set CONFIG_APPLE_GMUX=y in your .config, the gmux driver should bind to the multiplexer if there is one.

If there is a multiplexer built-in, then disabling the iGPU is the wrong approach.

Thanks,

Lukas

#13 lore raw
Quoted 7 lines

It's possible that the iMac has a multiplexer built-in which can switch between the iGPU and dGPU at runtime. Please ensure that you have set CONFIG_APPLE_GMUX=y in your .config, the gmux driver should bind to the multiplexer if there is one.

If there is a multiplexer built-in, then disabling the iGPU is the wrong approach.

I was using apple-gmux even before this patch, and runtime GPU switching does not work on either macOS or Linux.
On macOS, the iGPU does not even appear in System Information. However, the iGPU is present in IORegistry, and Apple appears to use it only for acceleration, not for display output. This can be seen from the following IORegistry entry:

    | |   | +-o AppleIntelFramebufferController  <class AppleIntelFramebufferController, id 0x100000556, registered, matched, active, busy 0 (230 ms), retain 8>
    | |   | | |   "IOClass" = "AppleIntelFramebufferController"
    | |   | | |   "IOPersonalityPublisher" = "com.apple.driver.AppleIntelCFLGraphicsFramebuffer"
    | |   | | |   "CFBundleIdentifierKernel" = "com.apple.driver.AppleIntelCFLGraphicsFramebuffer"
    | |   | | |   "CFBundleIdentifier" = "com.apple.driver.AppleIntelCFLGraphicsFramebuffer"
    | |   | | |   "IOMatchCategory" = "IOFramebuffer"
    | |   | | |   "NumFrameBuffer" = <00>

NumFrameBuffer=0 says that iGPU isint handling any dispaly atm.

#14 lore raw

✗ LGCI.VerificationFailed: failure for Add support for eGPUs on Apple Products (rev2)

In reply to Atharva Tiwari
== Series Details ==

== Series Details ==

Series: Add support for eGPUs on Apple Products (rev2)
URL : https://patchwork.freedesktop.org/series/160655/
State : failure

== Summary ==

Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!

#15 lore raw

✗ LGCI.VerificationFailed: failure for Add support for eGPUs on Apple Products (rev2)

In reply to Atharva Tiwari
== Series Details ==

== Series Details ==

Series: Add support for eGPUs on Apple Products (rev2)
URL : https://patchwork.freedesktop.org/series/160653/
State : failure

== Summary ==

Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!