@@ -43,17 +43,25 @@ static constexpr size_t kBigSurAmdBronzeMtlAddrLibGetBaseArrayModeReturnSize = s
4343
4444static_assert (kBigSurAmdBronzeMtlAddrLibGetBaseArrayModeReturnSize == sizeof (kBigSurAmdBronzeMtlAddrLibGetBaseArrayModeReturnPatched ), " patch size invalid" );
4545
46- static const uint8_t kPECI_IsEarlySAMUInitEnabledOriginal [] = {
47- 0xbe , 0x60 , 0x01 , 0x00 , 0x00 , 0xff , 0x90 , 0xb8 , 0x00 , 0x00 , 0x00 , 0x31 , 0xc9 , 0x83 , 0xf8 , 0x01 , 0x0f , 0x94 , 0xc1 , 0x89 , 0xc8 , 0x5d , 0xc3 ,
46+ // patch the 160th bit of CAIL_DDI_CAPS_POLARIS22_A0 to zero
47+ static const uint8_t kCAIL_DDI_CAPS_POLARIS22_A0Original [] = {
48+ 0x05 , 0x00 , 0x80 , 0x00 , 0xFE , 0x11 , 0x00 , 0x00 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 , 0x11 , 0x00 , 0x02 , 0x00 , 0x00 ,
49+ 0x01 , 0x00 , 0x00 , 0x68 , 0x00 , 0x00 , 0x40 , 0x29 , 0x02 , 0x40 , 0x00 , 0x00 , 0x01 , 0x01 , 0x8A , 0x62 , 0x10 , 0x86 , 0xA2 , 0x41 ,
50+ 0x00 , 0x00 , 0x00 , 0x22 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
51+ 0x00 , 0x00 , 0x00 , 0x00 ,
4852};
4953
50- static const uint8_t kPECI_IsEarlySAMUInitEnabledPatched [] = {
51- 0xbe , 0x60 , 0x01 , 0x00 , 0x00 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x31 , 0xc9 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x90 , 0x89 , 0xc8 , 0x5d , 0xc3 ,
54+ static const uint8_t kCAIL_DDI_CAPS_POLARIS22_A0Patched [] = {
55+ 0x05 , 0x00 , 0x80 , 0x00 , 0xFE , 0x11 , 0x00 , 0x00 , 0x80 , 0x00 , 0x00 , 0x00 , 0x00 , 0x10 , 0x00 , 0x11 , 0x00 , 0x02 , 0x00 , 0x00 ,
56+ 0x01 , 0x00 , 0x00 , 0x68 , 0x00 , 0x00 , 0x40 , 0x29 , 0x02 , 0x40 , 0x00 , 0x00 , 0x01 , 0x01 , 0x8A , 0x62 , 0x10 , 0x86 , 0xA2 , 0x41 ,
57+ 0x00 , 0x00 , 0x00 , 0x22 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
58+ 0x00 , 0x00 , 0x00 , 0x00 ,
59+
5260};
5361
54- static constexpr size_t kPECI_IsEarlySAMUInitEnabledOriginalSize = sizeof (kPECI_IsEarlySAMUInitEnabledOriginal );
62+ static constexpr size_t kPECI_IsEarlySAMUInitEnabledOriginalSize = sizeof (kCAIL_DDI_CAPS_POLARIS22_A0Original );
5563
56- static_assert (kPECI_IsEarlySAMUInitEnabledOriginalSize == sizeof (kPECI_IsEarlySAMUInitEnabledPatched ), " patch size invalid" );
64+ static_assert (kPECI_IsEarlySAMUInitEnabledOriginalSize == sizeof (kCAIL_DDI_CAPS_POLARIS22_A0Patched ), " patch size invalid" );
5765
5866
5967static const char kAmdBronzeMtlDriverPath [kPathMaxLen ] = " /System/Library/Extensions/AMDMTLBronzeDriver.bundle/Contents/MacOS/AMDMTLBronzeDriver" ;
@@ -77,7 +85,6 @@ static KernelPatcher::KextInfo kAMDHWLibsInfo[] = {
7785};
7886
7987static mach_vm_address_t orig_cs_validate {};
80- static mach_vm_address_t orig_IsEarlySAMUInitEnabled {};
8188static mach_vm_address_t orig_getHardwareInfo {};
8289
8390#pragma mark - Kernel patching code
@@ -167,11 +174,6 @@ static void patched_cs_validate_page(vnode_t vp,
167174 }
168175}
169176
170- static int patched_IsEarlySAMUInitEnabled (void *ctx) {
171- DBGLOG (MODULE_SHORT, " PECI_IsEarlySAMUInitEnabled: return 0" );
172- return 0 ;
173- }
174-
175177static int patched_getHardwareInfo (void *obj, uint16_t *hwInfo) {
176178 int ret = FunctionCast (patched_getHardwareInfo, orig_getHardwareInfo)(obj, hwInfo);
177179 DBGLOG (MODULE_SHORT, " AMDRadeonX4000_AMDAccelDevice::getHardwareInfo: return 0x%08X" );
@@ -239,28 +241,14 @@ static void pluginStart() {
239241 SYSLOG (MODULE_SHORT, " failed to patch getHardwareInfo: %d" , patcher.getError ());
240242 }
241243 } else if (i == kAmdRadeonX4000HwLibs && kAMDHWLibsInfo [i].loadIndex == index) {
242- // pre Monterey
243- if (getKernelVersion () <= KernelVersion::BigSur) {
244- KernelPatcher::RouteRequest amd_requests[] {
245- KernelPatcher::RouteRequest (" _PECI_IsEarlySAMUInitEnabled" , patched_IsEarlySAMUInitEnabled, orig_IsEarlySAMUInitEnabled),
246- };
247- if (patcher.routeMultiple (index, amd_requests, address, size, true , true )) {
248- DBGLOG (MODULE_SHORT, " patched PECI_IsEarlySAMUInitEnabled" );
249- } else {
250- SYSLOG (MODULE_SHORT, " failed to patch PECI_IsEarlySAMUInitEnabled: %d" , patcher.getError ());
251- }
252- }
253- // Monterey
254- else {
255- KernelPatcher::LookupPatch patch = {&kAMDHWLibsInfo [kAmdRadeonX4000HwLibs ], kPECI_IsEarlySAMUInitEnabledOriginal , kPECI_IsEarlySAMUInitEnabledPatched , sizeof (kPECI_IsEarlySAMUInitEnabledOriginal ), 1 };
256- patcher.applyLookupPatch (&patch);
257- if (patcher.getError () != KernelPatcher::Error::NoError) {
258- SYSLOG (MODULE_SHORT, " failed to binary patch PECI_IsEarlySAMUInitEnabled: %d" , patcher.getError ());
259- patcher.clearError ();
260- }
261- else {
262- DBGLOG (MODULE_SHORT, " binary patched PECI_IsEarlySAMUInitEnabled" );
244+ KernelPatcher::LookupPatch patch = {&kAMDHWLibsInfo [kAmdRadeonX4000HwLibs ], kCAIL_DDI_CAPS_POLARIS22_A0Original , kCAIL_DDI_CAPS_POLARIS22_A0Patched , sizeof (kCAIL_DDI_CAPS_POLARIS22_A0Original ), 1 };
245+ patcher.applyLookupPatch (&patch);
246+ if (patcher.getError () != KernelPatcher::Error::NoError) {
247+ SYSLOG (MODULE_SHORT, " failed to binary patch CAIL_DDI_CAPS_POLARIS22_A0: %d" , patcher.getError ());
248+ patcher.clearError ();
263249 }
250+ else {
251+ DBGLOG (MODULE_SHORT, " binary patched CAIL_DDI_CAPS_POLARIS22_A0" );
264252 }
265253 }
266254 }
0 commit comments