Add 3rd Party NVMe Power Management Patches

This commit is contained in:
Mykola Grymalyuk
2021-04-30 22:51:12 -06:00
parent c3d8d77b07
commit d5ff1edc44
10 changed files with 323 additions and 16 deletions

View File

@@ -7,6 +7,9 @@
- Remove USB ACPI Patching requirement for Minimal SMBIOS setups
- Probe hardware for Backlight pathing on iMac10,1, iMac11,x and iMac12,x with Metal GPUs
- Add Windows UEFI Audio support to Sandy and Ivy Bridge Macs
- Add 3rd Party NVMe Power Management Patches
- NVMeFix fafc52d (1.0.7 rolling - 04-29-2021)
- Strip unused ACPI and Kernel entries during build
## 0.1.1
- Fix iMac11,3 GFX0 pathing

View File

@@ -63,12 +63,12 @@ class BuildOpenCore:
self.constants.dgpu_device = self.hexswap(binascii.hexlify(self.constants.dgpu_devices[0]["device-id"]).decode()[:4])
if print_status is True:
print(f"- Detected dGPU: {self.constants.dgpu_vendor}:{self.constants.dgpu_device}")
self.config["#Revision"]["Hardware-dGPU"] = f"{self.constants.dgpu_vendor}:{self.constants.dgpu_device}"
self.config["#Revision"]["Hardware-GFX0"] = f"{self.constants.dgpu_vendor}:{self.constants.dgpu_device}"
except ValueError:
if print_status is True:
print("- No dGPU detected")
self.constants.dgpu_devices = ""
self.config["#Revision"]["Hardware-dGPU"] = "No dGPU detected"
self.config["#Revision"]["Hardware-GFX0"] = "No dGPU detected"
def build_efi(self):
Utilities.cls()
@@ -130,6 +130,41 @@ class BuildOpenCore:
]:
self.enable_kext(name, version, path, check)
if not self.constants.custom_model:
nvme_devices = plistlib.loads(subprocess.run("ioreg -c IOPCIDevice -r -d2 -a".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
nvme_devices = [i for i in nvme_devices if i.get("IORegistryEntryChildren", None) and i["vendor-id"] != binascii.unhexlify("6B100000") and i["IORegistryEntryChildren"][0]["IORegistryEntryName"] == "IONVMeController"]
nvme_path_gfx: str = subprocess.run([self.constants.gfxutil_path] + f"-v".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
try:
x = 1
for i in nvme_devices:
nvme_vendor = self.hexswap(binascii.hexlify(i["vendor-id"]).decode()[:4])
nvme_device = self.hexswap(binascii.hexlify(i["device-id"]).decode()[:4])
print(f'- Found 3rd Party NVMe SSD ({x}): {nvme_vendor}:{nvme_device}')
self.config["#Revision"][f"Hardware-NVMe-{x}"] = f'{nvme_vendor}:{nvme_device}'
try:
nvme_path = [line.strip().split("= ", 1)[1] for line in nvme_path_gfx.split("\n") if f'{nvme_vendor}:{nvme_device}'.lower() in line.strip()][0]
nvme_path_parent = "/".join(nvme_path.split("/")[:-1])
print(f"- Found NVMe ({x}) at {nvme_path}")
#print(f"- Found NVMe({x}) Parent at {nvme_path_parent}")
self.config["DeviceProperties"]["Add"][nvme_path] = {"pci-aspm-default": 2}
self.config["DeviceProperties"]["Add"][nvme_path_parent] = {"pci-aspm-default": 2}
except IndexError:
print(f"- Failed to find Device path for NVMe {x}")
if "-nvmefaspm" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]:
print("- Falling back to -nvmefaspm")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " -nvmefaspm"
if self.get_kext_by_bundle_path("NVMeFix.kext")["Enabled"] is False:
self.enable_kext("NVMeFix.kext", self.constants.nvmefix_version, self.constants.nvmefix_path)
x = x + 1
except ValueError:
print("- No 3rd Party NVMe drive found")
except IndexError:
print("- No 3rd Party NVMe drive found")
def wifi_fake_id(self):
default_path = True
self.enable_kext("AirportBrcmFixup.kext", self.constants.airportbcrmfixup_version, self.constants.airportbcrmfixup_path)
@@ -378,8 +413,47 @@ class BuildOpenCore:
backlight_path_detection(self)
nvidia_patch(self, self.gfx0_path)
if self.model in ModelArray.MacPro71:
print("- Adding Mac Pro, Xserve DRM patches")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 -wegtree"
if not self.constants.custom_model:
mp_dgpu_devices = plistlib.loads(subprocess.run("ioreg -c IOPCIDevice -r -d2 -a".split(), stdout=subprocess.PIPE).stdout.decode().strip().encode())
mp_dgpu_devices = [i for i in mp_dgpu_devices if i["class-code"] == binascii.unhexlify("00000300") or i["class-code"] == binascii.unhexlify("00800300")]
mp_dgpu_devices_gfx: str = subprocess.run([self.constants.gfxutil_path] + f"-v".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.decode()
try:
x = 1
for i in mp_dgpu_devices:
mp_dgpu_vendor = self.hexswap(binascii.hexlify(i["vendor-id"]).decode()[:4])
mp_dgpu_device = self.hexswap(binascii.hexlify(i["device-id"]).decode()[:4])
print(f'- Found dGPU ({x}): {mp_dgpu_vendor}:{mp_dgpu_device}')
self.config["#Revision"][f"Hardware-MacPro-dGPU-{x}"] = f'{mp_dgpu_vendor}:{mp_dgpu_device}'
try:
mp_dgpu_path = [line.strip().split("= ", 1)[1] for line in mp_dgpu_devices_gfx.split("\n") if f'{mp_dgpu_vendor}:{mp_dgpu_device}'.lower() in line.strip()][0]
print(f"- Found dGPU ({x}) at {mp_dgpu_path}")
if mp_dgpu_vendor == self.constants.pci_amd_ati:
print("- Adding Mac Pro, Xserve DRM patches")
self.config["DeviceProperties"]["Add"][mp_dgpu_path] = {"shikigva": 128, "unfairgva": 1, "wegtree": 1}
#elif mp_dgpu_vendor == self.constants.pci_nvidia:
# print("- Enabling Nvidia Output Patch")
# self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True
except IndexError:
print(f"- Failed to find Device path for NVMe {x}")
if mp_dgpu_vendor == self.constants.pci_amd_ati:
print("- Adding Mac Pro, Xserve DRM patches")
if "shikigva=128 unfairgva=1 -wegtree" not in self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"]:
print("- Falling back to boot-args")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 -wegtree"
#elif mp_dgpu_vendor == self.constants.pci_nvidia:
# print("- Enabling Nvidia Output Patch")
# self.config["UEFI"]["Quirks"]["ForgeUefiSupport"] = True
x = x + 1
except ValueError:
print("- No socketed dGPU found")
except IndexError:
print("- No socketed dGPU found")
else:
print("- Adding Mac Pro, Xserve DRM patches")
self.config["NVRAM"]["Add"]["7C436110-AB2A-4BBB-A880-FE41995C9F82"]["boot-args"] += " shikigva=128 unfairgva=1 -wegtree"
# Add OpenCanopy
print("- Adding OpenCanopy GUI")
@@ -521,7 +595,7 @@ class BuildOpenCore:
elif self.constants.serial_settings == "Advanced":
print("- Using Advanced SMBIOS patching")
advanced_serial_patch(self)
else:
elif self.constants.serial_settings == "Minimal":
print("- Using Minimal SMBIOS patching")
self.spoofed_model = self.model
minimal_serial_patch(self)
@@ -567,12 +641,6 @@ class BuildOpenCore:
plistlib.dump(agpm_config, Path(new_agpm_ls).open("wb"), sort_keys=True)
plistlib.dump(amc_config, Path(new_amc_ls).open("wb"), sort_keys=True)
#if self.model in ["MacBookPro8,2", "MacBookPro8,3"]:
# print("- Disabling unsupported TeraScale 2 dGPU")
# self.config["NVRAM"]["Add"]["FA4CE28D-B62F-4C99-9CC3-6815686E30F9"]["gpu-power-prefs"] = binascii.unhexlify("01000000")
# self.config["NVRAM"]["Delete"]["FA4CE28D-B62F-4C99-9CC3-6815686E30F9"] += ["gpu-power-prefs"]
# self.config["DeviceProperties"]["Add"]["PciRoot(0x0)/Pci(0x1,0x0)/Pci(0x0,0x0)"] = {"name": binascii.unhexlify("23646973706C6179"), "IOName": "#display", "class-code": binascii.unhexlify("FFFFFFFF")}
@staticmethod
def get_item_by_kv(iterable, key, value):
item = None
@@ -609,10 +677,20 @@ class BuildOpenCore:
def cleanup(self):
print("- Cleaning up files")
# Remove unused kexts
for kext in list(self.config["Kernel"]["Add"]):
if not kext["Enabled"]:
self.config["Kernel"]["Add"].remove(kext)
# Remove unused entries
for entry in list(self.config["ACPI"]["Add"]):
if not entry["Enabled"]:
self.config["ACPI"]["Add"].remove(entry)
for entry in list(self.config["ACPI"]["Patch"]):
if not entry["Enabled"]:
self.config["ACPI"]["Patch"].remove(entry)
for entry in list(self.config["Kernel"]["Add"]):
if not entry["Enabled"]:
self.config["Kernel"]["Add"].remove(entry)
for entry in list(self.config["Kernel"]["Patch"]):
if not entry["Enabled"]:
self.config["Kernel"]["Patch"].remove(entry)
plistlib.dump(self.config, Path(self.constants.plist_path).open("wb"), sort_keys=True)
for kext in self.constants.kexts_path.rglob("*.zip"):
with zipfile.ZipFile(kext) as zip_file:

View File

@@ -35,6 +35,7 @@ class Constants:
self.smcspoof_version = "1.0.0"
self.cputscsync = "1.0.3"
self.hibernationfixup = "1.3.9"
self.nvmefix_version = "1.0.7"
self.payload_version = "0.0.4"
# Get resource path
@@ -94,6 +95,17 @@ class Constants:
self.pci_intel = "8086"
self.pci_broadcom = "14E4"
self.pci_atheros = "168C"
self.pci_apple = "106B"
# Class Codes
# https://pci-ids.ucw.cz/read/PD
self.classcode_sata = "01060100"
self.classcode_nvme = "02080100"
self.classcode_nvme_generic = "02800100"
self.classcode_wifi = "00800200"
self.classcode_gpu = "00000300"
self.classcode_gpu_variant = "00800300"
# Nvidia GPU Architecture
self.arch_tesla = "NV50"
@@ -172,6 +184,8 @@ class Constants:
@property
def hibernationfixup_path(self): return self.payload_kexts_path / Path(f"Acidanthera/HibernationFixup-v{self.hibernationfixup}.zip")
@property
def nvmefix_path(self): return self.payload_kexts_path / Path(f"Acidanthera/NVMeFix-v{self.nvmefix_version}.zip")
@property
def plist_folder_path(self): return self.payload_kexts_path / Path(f"Plists")
@property
def platform_plugin_plist_path(self): return self.plist_folder_path / Path(f"PlatformPlugin")

View File

@@ -58,9 +58,11 @@ Next, mount the Windows 10 ISO:
The open terminal and run `rsync` on the USB drive (replace CCCOMA_X64 with the mounted ISO's name, as well as replacing W10USB with your USB drive's name):
```
rsync -r /Volumes/CCCOMA_X64/ /Volumes/W10USB
rsync -r -P /Volumes/CCCOMA_X64/ /Volumes/W10USB
```
![](../images/rsync-progess.png)
Command will take some time, so sit back and get some coffee. Once finished, the root of the USB drive should look as follows:
* Ensure that these folders and files are on the root, otherwise the USB will not boot

BIN
images/rsync-progess.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 838 KiB

View File

@@ -0,0 +1,27 @@
/* Disable the non-existant Co-processor Bridge found on Arrendale, Lynnfield and Clarkdale Macs.
* IOPCIFamily in macOS 11.0 up-to 11.2 was unable to handle ACPI probing when device was not present,
* therefore kernel panicing the machine.
*
* This SSDT reports the device as disabled avoiding the probing.
* Not required for macOS 11.2 and newer, however recommended to alliviate pottential issues
*/
DefinitionBlock ("", "SSDT", 2, "DRTNIA", "CPBGoff", 0x00001000)
{
External (_SB_.CPBG, DeviceObj)
Scope (_SB.CPBG)
{
Method (_STA, 0, NotSerialized) // _STA: Status
{
If (_OSI ("Darwin"))
{
Store ("Disabling incompatible CPBG Device", Debug)
Return (Zero) // Disable only in macOS incase Windows or Linux requires
}
Else
{
Return (0x0F)
}
}
}
}

View File

@@ -0,0 +1,165 @@
/* Removes PCI0's 32-bit Allocation Limitation to resolve PCIe device support on Sandy and
* Ivy Bridge Macs, mainly applicable for Audio and eGPU support.
* BUF0 to BUF1 patch required to override exisiting BufObj in DSDT.
*
* Source:
* https://egpu.io/forums/pc-setup/fix-dsdt-override-to-correct-error-12/
*/
DefinitionBlock ("", "SSDT", 2, "DRTNIA", "WinPCI", 0x00000000)
{
External (_SB_.PCI0, DeviceObj)
Scope (\_SB.PCI0)
{
Store ("Injecting new BUF0 BuffObj", Debug)
Name (BUF0, ResourceTemplate ()
{
WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
0x0000, // Granularity
0x0000, // Range Minimum
0x00FF, // Range Maximum
0x0000, // Translation Offset
0x0100, // Length
,, )
DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
0x00000000, // Granularity
0x00000000, // Range Minimum
0x00000CF7, // Range Maximum
0x00000000, // Translation Offset
0x00000CF8, // Length
,, , TypeStatic, DenseTranslation)
IO (Decode16,
0x0CF8, // Range Minimum
0x0CF8, // Range Maximum
0x01, // Alignment
0x08, // Length
)
DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
0x00000000, // Granularity
0x00000D00, // Range Minimum
0x0000FFFF, // Range Maximum
0x00000000, // Translation Offset
0x0000F300, // Length
,, , TypeStatic, DenseTranslation)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000A0000, // Range Minimum
0x000BFFFF, // Range Maximum
0x00000000, // Translation Offset
0x00020000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000C0000, // Range Minimum
0x000C3FFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000C4000, // Range Minimum
0x000C7FFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000C8000, // Range Minimum
0x000CBFFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000CC000, // Range Minimum
0x000CFFFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000D0000, // Range Minimum
0x000D3FFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000D4000, // Range Minimum
0x000D7FFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000D8000, // Range Minimum
0x000DBFFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000DC000, // Range Minimum
0x000DFFFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000E0000, // Range Minimum
0x000E3FFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000E4000, // Range Minimum
0x000E7FFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000E8000, // Range Minimum
0x000EBFFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000EC000, // Range Minimum
0x000EFFFF, // Range Maximum
0x00000000, // Translation Offset
0x00004000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x000F0000, // Range Minimum
0x000FFFFF, // Range Maximum
0x00000000, // Translation Offset
0x00010000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0x00000000, // Range Minimum
0xFEAFFFFF, // Range Maximum
0x00000000, // Translation Offset
0xFEB00000, // Length
,, , AddressRangeMemory, TypeStatic)
DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x00000000, // Granularity
0xFED40000, // Range Minimum
0xFED44FFF, // Range Maximum
0x00000000, // Translation Offset
0x00005000, // Length
,, , AddressRangeMemory, TypeStatic)
QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite,
0x0000000000000000, // Granularity
0x0000000C20000000, // Range Minimum, set it to 48.5GB
0x0000000E0FFFFFFF, // Range Maximum, set it to 56.25GB
0x0000000000000000, // Translation Offset
0x00000001F0000000, // Length calculated by Range Max - Range Min.
,, , AddressRangeMemory, TypeStatic)
})
}
}

View File

@@ -806,6 +806,24 @@
<key>PlistPath</key>
<string>Contents/Info.plist</string>
</dict>
<dict>
<key>Arch</key>
<string>x86_64</string>
<key>Comment</key>
<string>NVMeFix</string>
<key>Enabled</key>
<false/>
<key>MaxKernel</key>
<string></string>
<key>MinKernel</key>
<string></string>
<key>BundlePath</key>
<string>NVMeFix.kext</string>
<key>ExecutablePath</key>
<string>Contents/MacOS/NVMeFix</string>
<key>PlistPath</key>
<string>Contents/Info.plist</string>
</dict>
</array>
<key>Block</key>
<array/>

Binary file not shown.