From 5f0a33fd194631b00a19b07bc4adac79a11042a0 Mon Sep 17 00:00:00 2001 From: Hoang Hong Quan Date: Tue, 12 Nov 2024 01:07:22 +0700 Subject: [PATCH] Replace spoof method by adding the disable-gpu property --- OpCore-Simplify.py | 16 +++--- README.md | 2 +- Scripts/acpi_guru.py | 109 +++++++++----------------------------- Scripts/config_prodigy.py | 17 +++--- 4 files changed, 44 insertions(+), 100 deletions(-) diff --git a/OpCore-Simplify.py b/OpCore-Simplify.py index 248c742..1b669db 100644 --- a/OpCore-Simplify.py +++ b/OpCore-Simplify.py @@ -134,17 +134,17 @@ class OCPE: source_efi_dir = os.path.join(self.k.ock_files_dir, "OpenCorePkg") shutil.copytree(source_efi_dir, self.result_dir, dirs_exist_ok=True) - print("Done") - print("2. Generate config.plist...", end=" ") + config_file = os.path.join(self.result_dir, "EFI", "OC", "config.plist") config_data = self.u.read_file(config_file) if not config_data: raise Exception("Error: The file {} does not exist.".format(config_file)) - - self.co.genarate(hardware_report, smbios_model, macos_version, needs_oclp, self.k.kexts, config_data) print("Done") - print("3. Apply ACPI patches...", end=" ") + print("2. Apply ACPI patches...", end=" ") + config_data["ACPI"]["Add"] = [] + config_data["ACPI"]["Delete"] = [] + config_data["ACPI"]["Patch"] = [] if self.ac.ensure_dsdt(): self.ac.hardware_report = hardware_report self.ac.unsupported_devices = unsupported_devices @@ -171,11 +171,13 @@ class OCPE: config_data["ACPI"]["Patch"].extend(self.ac.dsdt_patches) config_data["ACPI"]["Patch"] = self.ac.apply_acpi_patches(config_data["ACPI"]["Patch"]) print("Done") - print("4. Copy kexts and snapshot to config.plist...", end=" ") + print("3. Copy kexts and snapshot to config.plist...", end=" ") kexts_directory = os.path.join(self.result_dir, "EFI", "OC", "Kexts") self.k.install_kexts_to_efi(macos_version, kexts_directory) config_data["Kernel"]["Add"] = self.k.load_kexts(macos_version, kexts_directory) - + print("Done") + print("4. Generate config.plist...", end=" ") + self.co.genarate(hardware_report, unsupported_devices, smbios_model, macos_version, needs_oclp, self.k.kexts, config_data) self.u.write_file(config_file, config_data) print("Done") print("5. Clean up unused drivers, resources, and tools...", end=" ") diff --git a/README.md b/README.md index 5855cc0..44fc656 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ - Integrated with [SSDTTime](https://github.com/corpnewt/SSDTTime) for common patches (e.g., FakeEC, FixHPET, PLUG, RTCAWAC). - Includes custom patches: - Prevent kernel panics by directing the first CPU entry to an active CPU, disabling the UNC0 device, and creating a new RTC device for HEDT systems. - - Disable unsupported or unused PCI devices, such as the GPU (using Optimus, Bumblebee, and spoof methods), Wi-Fi card, and NVMe storage controller. + - Disable unsupported or unused PCI devices, such as the GPU (using Optimus and Bumblebee methods or adding the disable-gpu property), Wi-Fi card, and NVMe storage controller. - Fix sleep state values in _PRW methods (GPRW, UPRW, HP special) to prevent immediate wake. - Add devices including ALS0, BUS0, MCHC, PMCR, PNLF, RMNE, IMEI, USBX, XOSI, along with a Surface Patch. - Enable ALSD and GPI0 devices. diff --git a/Scripts/acpi_guru.py b/Scripts/acpi_guru.py index 1802597..e65b6e9 100644 --- a/Scripts/acpi_guru.py +++ b/Scripts/acpi_guru.py @@ -1837,90 +1837,34 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "[[ALSName]]", 0x00000000) if "GPU" in device_name: ssdt_name = "SSDT-Disable_GPU_{}".format(device_props.get("ACPI Path").split(".")[2]) target_device = device_props.get("ACPI Path") - ssdt_content = """ -// Resource: https://github.com/dortania/Getting-Started-With-ACPI/blob/master/extra-files/decompiled/SSDT-GPU-DISABLE.dsl -DefinitionBlock ("", "SSDT", 2, "ZPSS", "DGPU", 0x00000000) -{ - External ([[DevicePath]], DeviceObj) - - Method ([[DevicePath]]._DSM, 4, NotSerialized) // _DSM: Device-Specific Method - { - If ((!Arg2 || (_OSI ("Darwin") == Zero))) - { - Return (Buffer (One) - { - 0x03 // . - }) - } - - Return (Package (0x0A) - { - "name", - Buffer (0x09) - { - "#display" - }, - - "IOName", - "#display", - "class-code", - Buffer (0x04) - { - 0xFF, 0xFF, 0xFF, 0xFF // .... - }, - - "vendor-id", - Buffer (0x04) - { - 0xFF, 0xFF, 0x00, 0x00 // .... - }, - - "device-id", - Buffer (0x04) - { - 0xFF, 0xFF, 0x00, 0x00 // .... - } - }) - } -} -""" - target_off_method = target_ps3_method = None + off_method_found = ps3_method_found = False for table_name, table_data in self.acpi.acpi_tables.items(): - if not "DSDT" in table_data.get("signature", "") and not "SSDT" in table_data.get("signature", ""): - continue - off_methods = self.acpi.get_method_paths("_OFF", table_data) ps3_methods = self.acpi.get_method_paths("_PS3", table_data) - off_method_of_target_device = next((method for method in off_methods if method[0].startswith(target_device)), None) - ps3_method_of_target_device = next((method for method in ps3_methods if method[0].startswith(target_device)), None) + off_method_found = off_method_found or any(method[0].startswith(target_device) and not self.is_method_in_power_resource(method, table_data.get("lines")) for method in off_methods) + ps3_method_found = ps3_method_found or any(method[0].startswith(target_device) for method in ps3_methods) + + if not off_method_found and not ps3_method_found: + continue - if off_method_of_target_device: - if self.is_method_in_power_resource(off_method_of_target_device, table_data.get("lines")): - off_method_of_target_device = None - - if off_method_of_target_device: - target_off_method = off_method_of_target_device[0] - - if ps3_method_of_target_device: - target_ps3_method = ps3_method_of_target_device[0] - - if target_off_method or target_ps3_method: - ssdt_content = """ + device_props["Disabled"] = True + + ssdt_content = """ DefinitionBlock ("", "SSDT", 2, "ZPSS", "DGPU", 0x00000000) {""" - if target_off_method: - ssdt_content += """ + if off_method_found: + ssdt_content += """ External ([[DevicePath]]._OFF, MethodObj) External ([[DevicePath]]._ON_, MethodObj)""" - if target_ps3_method: - ssdt_content += """ + if ps3_method_found: + ssdt_content += """ External ([[DevicePath]]._PS0, MethodObj) External ([[DevicePath]]._PS3, MethodObj) External ([[DevicePath]]._DSM, MethodObj) """ - ssdt_content += """ + ssdt_content += """ Device (DGPU) { Name (_HID, "DGPU1000") @@ -1944,29 +1888,29 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "DGPU", 0x00000000) Method (_ON, 0, NotSerialized) { """ - if target_off_method: - ssdt_content += """ + if off_method_found: + ssdt_content += """ [[DevicePath]]._ON () """ - if target_ps3_method: - ssdt_content += """ + if ps3_method_found: + ssdt_content += """ [[DevicePath]]._PS0 () """ - ssdt_content += """ + ssdt_content += """ } Method (_OFF, 0, NotSerialized) { """ - if target_off_method: - ssdt_content += """ + if off_method_found: + ssdt_content += """ [[DevicePath]]._OFF () """ - if target_ps3_method: - ssdt_content += """ + if ps3_method_found: + ssdt_content += """ [[DevicePath]]._DSM (ToUUID ("a486d8f8-0bda-471b-a72b-6042a6b5bee0") /* Unknown UUID */, 0x0100, 0x1A, Buffer (0x04) { 0x01, 0x00, 0x00, 0x03 // .... @@ -1974,11 +1918,8 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "DGPU", 0x00000000) [[DevicePath]]._PS3 () """ - ssdt_content += """ - } - } -} -""" + ssdt_content += """\n }\n }\n}""" + elif "Network" in device_name and device_props.get("Bus Type") == "PCI" and \ (not device_props.get("Device ID") in pci_data.NetworkIDs or 20 < pci_data.NetworkIDs.index(device_props.get("Device ID")) < 108 ): ssdt_name = "SSDT-Disable_WiFi_{}".format(device_props.get("ACPI Path").split(".")[2]) diff --git a/Scripts/config_prodigy.py b/Scripts/config_prodigy.py index 179ebe2..c9f4d48 100644 --- a/Scripts/config_prodigy.py +++ b/Scripts/config_prodigy.py @@ -232,7 +232,7 @@ class ConfigProdigy: return dict(sorted(igpu_properties.items(), key=lambda item: item[0])) - def deviceproperties(self, hardware_report, macos_version, kexts): + def deviceproperties(self, hardware_report, unsupported_devices, macos_version, kexts): deviceproperties_add = {} for kext in kexts: @@ -295,6 +295,12 @@ class ConfigProdigy: "built-in": self.utils.hex_to_bytes("01") } + for device_name, device_props in unsupported_devices.items(): + if "GPU" in device_name and not device_props.get("Disabled", False): + deviceproperties_add[device_props.get("PCI Path")] = { + "disable-gpu": True + } + for key, value in deviceproperties_add.items(): for key_child, value_child in value.items(): if isinstance(value_child, str): @@ -486,16 +492,12 @@ class ConfigProdigy: return uefi_drivers - def genarate(self, hardware_report, smbios_model, macos_version, needs_oclp, kexts, config): + def genarate(self, hardware_report, unsupported_devices, smbios_model, macos_version, needs_oclp, kexts, config): del config["#WARNING - 1"] del config["#WARNING - 2"] del config["#WARNING - 3"] del config["#WARNING - 4"] - config["ACPI"]["Add"] = [] - config["ACPI"]["Delete"] = [] - config["ACPI"]["Patch"] = [] - config["Booter"]["MmioWhitelist"] = self.mmio_whitelist(hardware_report.get("Motherboard").get("Chipset")) config["Booter"]["Patch"] = self.add_booter_patch(smbios_model, macos_version) config["Booter"]["Quirks"]["DevirtualiseMmio"] = len(config["Booter"]["MmioWhitelist"]) != 0 or \ @@ -511,9 +513,8 @@ class ConfigProdigy: config["Booter"]["Quirks"]["SetupVirtualMap"] = not hardware_report.get("Motherboard").get("Chipset") in chipset_data.AMDChipsets[11:17] + chipset_data.IntelChipsets[79:89] config["Booter"]["Quirks"]["SyncRuntimePermissions"] = "AMD" in hardware_report.get("CPU").get("Manufacturer") or hardware_report.get("Motherboard").get("Chipset") in chipset_data.IntelChipsets[79:89] + chipset_data.IntelChipsets[93:] - config["DeviceProperties"]["Add"] = self.deviceproperties(hardware_report, macos_version, kexts) + config["DeviceProperties"]["Add"] = self.deviceproperties(hardware_report, unsupported_devices, macos_version, kexts) - config["Kernel"]["Add"] = [] config["Kernel"]["Block"] = self.block_kext_bundle(kexts) spoof_cpuid = self.spoof_cpuid( hardware_report.get("CPU").get("Processor Name"),