Fix GFX0 parsing for iMac11,x/12,x

This commit is contained in:
Mykola Grymalyuk
2021-04-15 20:28:32 -06:00
parent 2a12e861ac
commit fa045e96e7
3 changed files with 149 additions and 132 deletions

View File

@@ -43,6 +43,27 @@ class BuildOpenCore:
hex_str = "".join(["".join(x) for x in hex_rev])
return hex_str.upper()
def check_pciid(self):
try:
self.igpu_devices = plistlib.loads(subprocess.run("ioreg -r -n IGPU -a".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
self.igpu_devices = [i for i in self.igpu_devices if i["class-code"] == binascii.unhexlify("00000300")]
self.igpu_vendor = self.hexswap(binascii.hexlify(self.igpu_devices[0]["vendor-id"]).decode()[:4])
self.igpu_device = self.hexswap(binascii.hexlify(self.igpu_devices[0]["device-id"]).decode()[:4])
print(f"- Detected iGPU: {self.igpu_vendor}:{self.igpu_device}")
except ValueError:
print("- No iGPU detected")
self.igpu_devices = ""
try:
self.dgpu_devices = plistlib.loads(subprocess.run("ioreg -r -n GFX0 -a".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
self.dgpu_devices = [i for i in self.dgpu_devices if i["class-code"] == binascii.unhexlify("00000300")]
self.dgpu_vendor = self.hexswap(binascii.hexlify(self.dgpu_devices[0]["vendor-id"]).decode()[:4])
self.dgpu_device = self.hexswap(binascii.hexlify(self.dgpu_devices[0]["device-id"]).decode()[:4])
print(f"- Detected dGPU: {self.dgpu_vendor}:{self.dgpu_device}")
except ValueError:
print("- No dGPU detected")
self.dgpu_devices = ""
def build_efi(self):
Utilities.cls()
if not Path(self.constants.build_path).exists():
@@ -292,13 +313,10 @@ class BuildOpenCore:
else:
print("- Failed to find vendor")
elif self.constants.custom_model == "None":
current_gpu: str = subprocess.run("system_profiler SPDisplaysDataType".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
self.constants.current_gpuv = [line.strip().split(": ", 1)[1] for line in current_gpu.split("\n") if line.strip().startswith(("Vendor"))][0]
self.constants.current_gpud = [line.strip().split(": ", 1)[1] for line in current_gpu.split("\n") if line.strip().startswith(("Device ID"))][0]
print(f"- Detected GPU: {self.constants.current_gpuv} {self.constants.current_gpud}")
if (self.constants.current_gpuv == "AMD (0x1002)") & (self.constants.current_gpud in ModelArray.AMDMXMGPUs):
self.check_pciid()
if self.dgpu_devices and self.dgpu_vendor == self.constants.pci_amd_ati and self.dgpu_device in ModelArray.AMDMXMGPUs:
amd_patch(self)
elif (self.constants.current_gpuv == "NVIDIA (0x10de)") & (self.constants.current_gpud in ModelArray.NVIDIAMXMGPUs):
elif self.dgpu_devices and self.dgpu_vendor == self.constants.pci_nvidia and self.dgpu_device in ModelArray.NVIDIAMXMGPUs:
nvidia_patch(self)
elif self.model in ModelArray.MacPro71:
print("- Adding Mac Pro, Xserve DRM patches")

View File

@@ -686,32 +686,32 @@ upgradableMXMGPUs = [
# Reference: https://forums.macrumors.com/threads/2011-imac-graphics-card-upgrade.1596614/
NVIDIAMXMGPUs = [
"0x12b9", # Quadro K610M
"0x0ff6", # Quadro K1100M
"0x11fc", # Quadro K2100M
"0x0ffc", # Quadro K1000M
"0x0ffb", # Quadro K2000M
"0x11b6", # Quadro K3100M
"0x11b7", # Quadro K4100M
"0x11bc", # Quadro K5000M
"0x11b8", # Quadro K5100M
"0x11e1", # GTX 765M
"0x11e2", # GTX 765M
"0x11e0", # GTX 770M
"0x119e", # GTX 780M Mac Edition
"0x119e", # GTX 780M
"0x119f", # GTX 880M
"0x119a", # GTX 860M
"0x1392", # GTX 860M
"0x1199", # GTX 870M
"0x11a9", # GTX 870M
"12B9", # Quadro K610M
"0FF6", # Quadro K1100M
"11FC", # Quadro K2100M
"0FFC", # Quadro K1000M
"0FFB", # Quadro K2000M
"11B6", # Quadro K3100M
"11B7", # Quadro K4100M
"11BC", # Quadro K5000M
"11B8", # Quadro K5100M
"11E1", # GTX 765M
"11E2", # GTX 765M
"11E0", # GTX 770M
"119E", # GTX 780M Mac Edition
"119E", # GTX 780M
"119F", # GTX 880M
"119A", # GTX 860M
"1392", # GTX 860M
"1199", # GTX 870M
"11A9", # GTX 870M
]
AMDMXMGPUs = [
"0x67EF", # AMD RX 460
"0x67e8", # AMD WX 4130/WX 4150
"0x67e0", # AMD WX 4170
"0x67c0", # AMD WX 7100
"67EF", # AMD RX 460
"67E8", # AMD WX 4130/WX 4150
"67E0", # AMD WX 4170
"67C0", # AMD WX 7100
]
BCM4360Wifi = [
@@ -1041,83 +1041,83 @@ AddBrightness = [
# List supported IDs
TeraScale1pciid = [
"0x9400",
"0x9401",
"0x9402",
"0x9403",
"0x9581",
"0x9583",
"0x9588",
"0x94c8",
"0x94c9",
"0x9500",
"0x9501",
"0x9505",
"0x9507",
"0x9504",
"0x9506",
"0x9598",
"0x9488",
"0x9599",
"0x9591",
"0x9593",
"0x9440",
"0x9442",
"0x944A",
"0x945A",
"0x9490",
"0x949E",
"0x9480",
"0x9540",
"0x9541",
"0x954E",
"0x954F",
"0x9552",
"0x9553",
"0x94a0",
"9400",
"9401",
"9402",
"9403",
"9581",
"9583",
"9588",
"94c8",
"94c9",
"9500",
"9501",
"9505",
"9507",
"9504",
"9506",
"9598",
"9488",
"9599",
"9591",
"9593",
"9440",
"9442",
"944A",
"945A",
"9490",
"949E",
"9480",
"9540",
"9541",
"954E",
"954F",
"9552",
"9553",
"94a0",
]
TeraScale2pciid = [
"0x6738",
"0x6739",
"0x6720",
"0x6722",
"0x6768",
"0x6770",
"0x6779",
"0x6760",
"0x6761",
"0x68E0",
"0x6898",
"0x6899",
"0x68B8",
"0x68B0",
"0x68B1",
"0x68A0",
"0x68A1",
"0x6840",
"0x6841",
"0x68D8",
"0x68C0",
"0x68C1",
"0x68D9",
"0x6750",
"0x6758",
"0x6759",
"0x6740",
"0x6741",
"0x6745",
"6738",
"6739",
"6720",
"6722",
"6768",
"6770",
"6779",
"6760",
"6761",
"68E0",
"6898",
"6899",
"68B8",
"68B0",
"68B1",
"68A0",
"68A1",
"6840",
"6841",
"68D8",
"68C0",
"68C1",
"68D9",
"6750",
"6758",
"6759",
"6740",
"6741",
"6745",
]
IronLakepciid = [
"0x0044",
"0x0046",
"0044",
"0046",
]
SandyBridgepiciid = [
"0x0106",
"0x0601",
"0x0116",
"0x0102",
"0x0126",
"0106",
"0601",
"0116",
"0102",
"0126",
]

View File

@@ -201,48 +201,47 @@ class PatchSysVolume:
# Ensures no .DS_Stores got in
print("- Preparing Files")
subprocess.run(f"sudo find {self.constants.payload_apple_root_path} -name '.DS_Store' -delete".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
# TODO: Unify GPU detection logic
current_gpu: str = subprocess.run("system_profiler SPDisplaysDataType".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
self.constants.current_gpuv = [line.strip().split(": ", 1)[1] for line in current_gpu.split("\n") if line.strip().startswith(("Vendor"))][0]
self.constants.current_gpud = [line.strip().split(": ", 1)[1] for line in current_gpu.split("\n") if line.strip().startswith(("Device ID"))][0]
if self.model in ModelArray.LegacyGPU:
if (self.constants.current_gpuv == "AMD (0x1002)") & (self.constants.current_gpud in ModelArray.AMDMXMGPUs):
self.check_pciid()
if self.dgpu_devices and self.dgpu_vendor == self.constants.pci_amd_ati and self.dgpu_device in ModelArray.AMDMXMGPUs:
print("- Detected Metal-based AMD GPU, skipping legacy patches")
elif (self.constants.current_gpuv == "NVIDIA (0x10de)") & (self.constants.current_gpud in ModelArray.NVIDIAMXMGPUs):
elif self.dgpu_devices and self.dgpu_vendor == self.constants.pci_nvidia and self.dgpu_device in ModelArray.NVIDIAMXMGPUs:
print("- Detected Metal-based Nvidia GPU, skipping legacy patches")
else:
self.check_pciid()
if Path(self.constants.hiddhack_path).exists():
print("- Detected legacy GPU, attempting legacy acceleration patches")
self.gpu_accel_patches_11()
else:
if self.dgpu_devices and self.dgpu_vendor == self.constants.pci_nvidia:
print("- Adding Nvidia Brightness Control patches")
self.add_new_binaries(ModelArray.AddNvidiaBrightness11, self.constants.legacy_nvidia_path)
elif self.dgpu_devices and self.dgpu_vendor == "1002":
if self.dgpu_device in ModelArray.TeraScale1pciid:
print("- Adding AMD/ATI TeraScale 1 Brightness Control patches")
self.add_new_binaries(ModelArray.AddAMDTeraScale1Brightness11, self.constants.legacy_amd_path)
elif self.dgpu_device in ModelArray.TeraScale2pciid:
print("- Adding AMD/ATI TeraScale 2 Brightness Control patches")
self.add_new_binaries(ModelArray.AddAMDTeraScale2Brightness11, self.constants.legacy_amd_path)
else:
print("- Could not find supported Legacy AMD/ATI GPU")
if self.igpu_devices and self.igpu_vendor == "8086" and self.igpu_device in ModelArray.IronLakepciid:
print("- Adding Intel Ironlake Brightness Control patches")
self.add_new_binaries(ModelArray.AddIntelGen1Brightness, self.constants.legacy_intel_gen1_path)
elif self.igpu_devices and self.igpu_vendor == "8086" and self.igpu_device in ModelArray.SandyBridgepiciid:
print("- Adding Intel Sandy Bridge Brightness Control patches")
self.add_new_binaries(ModelArray.AddIntelGen2Brightness, self.constants.legacy_intel_gen2_path)
if self.model in ModelArray.LegacyGPUAMDIntelGen2:
# Swap custom AppleIntelSNBGraphicsFB-AMD.kext, required to fix linking
subprocess.run(f"sudo rm -R {self.mount_extensions}/AppleIntelSNBGraphicsFB.kext".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
subprocess.run(f"sudo cp -R {self.constants.legacy_amd_path}/AMD-Link/AppleIntelSNBGraphicsFB.kext {self.mount_extensions}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
elif self.igpu_device and self.igpu_vendor == self.constants.pci_nvidia and not self.dgpu_devices:
# Avoid patching twice, as Nvidia iGPUs will only have Nvidia dGPUs
print("- Adding Nvidia Brightness Control patches")
self.add_new_binaries(ModelArray.AddNvidiaBrightness11, self.constants.legacy_nvidia_path)
if self.dgpu_devices:
if self.dgpu_vendor == self.constants.pci_nvidia:
print("- Adding Nvidia Brightness Control patches")
self.add_new_binaries(ModelArray.AddNvidiaBrightness11, self.constants.legacy_nvidia_path)
elif self.dgpu_vendor == self.constants.pci_amd_ati:
if self.dgpu_device in ModelArray.TeraScale1pciid:
print("- Adding AMD/ATI TeraScale 1 Brightness Control patches")
self.add_new_binaries(ModelArray.AddAMDTeraScale1Brightness11, self.constants.legacy_amd_path)
elif self.dgpu_device in ModelArray.TeraScale2pciid:
print("- Adding AMD/ATI TeraScale 2 Brightness Control patches")
self.add_new_binaries(ModelArray.AddAMDTeraScale2Brightness11, self.constants.legacy_amd_path)
else:
print("- Could not find supported Legacy AMD/ATI GPU")
if self.igpu_devices:
if self.igpu_vendor == self.constants.pci_intel:
if self.igpu_device in ModelArray.IronLakepciid:
print("- Adding Intel Ironlake Brightness Control patches")
self.add_new_binaries(ModelArray.AddIntelGen1Brightness, self.constants.legacy_intel_gen1_path)
elif self.igpu_device in ModelArray.SandyBridgepiciid:
print("- Adding Intel Sandy Bridge Brightness Control patches")
self.add_new_binaries(ModelArray.AddIntelGen2Brightness, self.constants.legacy_intel_gen2_path)
if self.dgpu_devices and self.dgpu_vendor == self.constants.pci_amd_ati and self.dgpu_device in ModelArray.TeraScale2pciid:
# Swap custom AppleIntelSNBGraphicsFB-AMD.kext, required to fix linking
subprocess.run(f"sudo rm -R {self.mount_extensions}/AppleIntelSNBGraphicsFB.kext".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
subprocess.run(f"sudo cp -R {self.constants.legacy_amd_path}/AMD-Link/AppleIntelSNBGraphicsFB.kext {self.mount_extensions}".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode()
elif self.igpu_vendor == self.constants.pci_nvidia and not self.dgpu_devices:
# Avoid patching twice, as Nvidia iGPUs will only have Nvidia dGPUs
print("- Adding Nvidia Brightness Control patches")
self.add_new_binaries(ModelArray.AddNvidiaBrightness11, self.constants.legacy_nvidia_path)
if self.model in ModelArray.LegacyBrightness:
self.add_brightness_patch()
rebuild_required = True