Add patch for APIC table on HEDT systems

This commit is contained in:
Hoang Hong Quan
2024-07-29 19:04:16 +07:00
parent 6e3e877719
commit 9cd65ac301
4 changed files with 58 additions and 18 deletions

0
OpCore-Simplify.py Executable file → Normal file
View File

View File

@@ -76,6 +76,7 @@ class ACPIGuru:
self.illegal_names = ("XHC1", "EHC1", "EHC2", "PXSX")
self.result = {
"Add": [],
"Delete": [],
"Patch": []
}
@@ -2890,6 +2891,53 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "GPUSPOOF", 0x00001000)
"Path": ssdt_name + ".aml"
})
def dropping_the_table(self, signature=None, oemtableid=None):
table_data = self.acpi.get_table_with_signature(signature) or self.acpi.get_table_with_id(oemtableid)
if not table_data:
return
print(list(table_data.items())[-4:])
self.result["Delete"].append({
"All": True,
"Comment": "Delete {}".format(signature or oemtableid),
"Enabled": True,
"OemTableId": self.utils.hex_to_bytes(self.utils.string_to_hex(table_data.get("id"))),
"TableLength": 0,
"TableSignature": self.utils.hex_to_bytes(self.utils.string_to_hex(table_data.get("signature")))
})
def fix_apic_processor_id(self, cpu_codename):
self.apic = self.acpi.get_table_with_signature("APIC")
processors = [line for line in self.dsdt.get("lines") if line.strip().startswith("Processor")]
if not self.is_intel_hedt_cpu(cpu_codename) or not self.apic or not processors:
return
processor_index = -1
for index, line in enumerate(self.apic.get("lines")):
if "Subtable Type" in line and "[Processor Local APIC]" in line:
processor_index += 1
apic_processor_id = self.apic["lines"][index + 2][-2:]
try:
dsdt_processor_id = processors[processor_index].split("0x")[1].split(",")[0]
except:
return
if processor_index == 0 and apic_processor_id == dsdt_processor_id:
break
self.apic["lines"][index + 2] = self.apic["lines"][index + 2][:-2] + dsdt_processor_id
if processor_index != -1:
if self.write_ssdt("APIC", "\n".join(self.apic.get("lines"))):
self.result["Add"].append({
"Comment": "Avoid kernel panic by pointing the first CPU entry to an active CPU on HEDT systems",
"Enabled": True,
"Path": "APIC.aml"
})
self.dropping_the_table("APIC")
self.utils.request_input()
def initialize_patches(self, motherboard_name, motherboard_chipset, platform, cpu_manufacturer, cpu_codename, integrated_gpu, discrete_gpu, ethernet_pci, touchpad_communication, smbios, intel_mei, unsupported_devices, macos_version, acpi_directory):
self.acpi_directory = self.check_acpi_directory(acpi_directory)
@@ -2910,6 +2958,7 @@ DefinitionBlock ("", "SSDT", 2, "ZPSS", "GPUSPOOF", 0x00001000)
self.enable_gpio_device(platform, cpu_manufacturer, touchpad_communication)
self.enable_nvram_support(motherboard_chipset)
self.fake_embedded_controller(platform)
self.fix_apic_processor_id(cpu_codename)
self.fix_hp_005_post_error(motherboard_name)
self.fix_irq_conflicts(platform, cpu_codename)
self.fix_system_clock_awac(motherboard_chipset)

View File

@@ -244,14 +244,7 @@ class ConfigProdigy:
del config["#WARNING - 3"]
del config["#WARNING - 4"]
config["ACPI"]["Add"] = efi_option.get("ACPI").get("Add")
if not self.is_intel_hedt_cpu(hardware.get("CPU Codename")) and not self.utils.contains_any(cpu_data.IntelCPUGenerations, hardware.get("CPU Codename"), end=2) is None:
for item in config["ACPI"]["Delete"]:
item.update({
"All": True,
"Enabled": True
})
else:
config["ACPI"]["Delete"] = []
config["ACPI"]["Delete"] = efi_option.get("ACPI").get("Delete")
config["ACPI"]["Patch"] = efi_option.get("ACPI").get("Patch")
config["Booter"]["MmioWhitelist"] = self.mmio_whitelist(hardware.get("CPU Codename"))

18
Scripts/utils.py Executable file → Normal file
View File

@@ -110,23 +110,21 @@ class Utils:
return string
def int_to_hex(self, number):
try:
return format(number, '02X')
except:
return number
return format(number, '02X')
def hex_to_int(self, hex_string):
return int(hex_string, 16)
def to_little_endian_hex(self, hex_str):
hex_str = hex_str.lower().lstrip("0x")
hex_str = hex_str.zfill(8)
def to_little_endian_hex(self, hex_string):
hex_string = hex_string.lower().lstrip("0x").zfill(8)
little_endian_hex = ''.join(reversed([hex_str[i:i+2] for i in range(0, len(hex_str), 2)]))
little_endian_hex = ''.join(reversed([hex_string[i:i+2] for i in range(0, len(hex_string), 2)]))
return little_endian_hex.upper()
def string_to_hex(self, string):
return ''.join(format(ord(char), '02X') for char in string)
def extract_zip_file(self, zip_path, extraction_directory=None):
if extraction_directory is None:
extraction_directory = os.path.splitext(zip_path)[0]