Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Catalina support #130

Merged
merged 19 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
31b7cd6
Initial catalina efforts
VisualEhrmanntraut Jun 7, 2023
4141ee0
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jun 9, 2023
692bf2d
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jun 9, 2023
798d922
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jun 13, 2023
6c87b34
Force meta class cast for IAMDHWChannel
VisualEhrmanntraut Jun 13, 2023
4aa821f
Apply addrlib patch to catalina
VisualEhrmanntraut Jun 13, 2023
1fc75ec
Fix more VTable mismatches
VisualEhrmanntraut Jun 13, 2023
3cd9367
There's some versions of macOS which default to having a paging queue
VisualEhrmanntraut Jun 13, 2023
e5eb821
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jun 15, 2023
73c673a
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jun 18, 2023
e7ea9aa
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jun 29, 2023
b8401bf
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jul 14, 2023
6faccee
Catalina: Wrap AmdTtlServices::getIpFw for VCN firmware
VisualEhrmanntraut Jul 14, 2023
815eca6
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jul 14, 2023
8bb392b
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jul 14, 2023
c67b9d7
Merge branch 'master' into add-catalina-support
VisualEhrmanntraut Jul 16, 2023
2db476f
Merge branch 'master' into catalina
VisualEhrmanntraut Jul 29, 2023
b329f70
Merge branch 'master' into catalina
VisualEhrmanntraut Aug 7, 2023
dd3bf7b
Deactivate {set,get}AttributeForConnection wraps on Catalina
VisualEhrmanntraut Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions NootedRed/kern_hwlibs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ bool X5000HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address
CAILDeviceTypeEntry *orgDeviceTypeTable = nullptr;
DeviceCapabilityEntry *orgDevCapTable = nullptr;

auto catalina = getKernelVersion() == KernelVersion::Catalina;
SolveRequestPlus solveRequests[] = {
{"__ZL15deviceTypeTable", orgDeviceTypeTable, kDeviceTypeTablePattern},
{"__ZN11AMDFirmware14createFirmwareEPhjjPKc", this->orgCreateFirmware, kCreateFirmwarePattern},
{"__ZL15deviceTypeTable", orgDeviceTypeTable, kDeviceTypeTablePattern, !catalina},
{"__ZN11AMDFirmware14createFirmwareEPhjjPKc", this->orgCreateFirmware, kCreateFirmwarePattern, !catalina},
{"__ZN20AMDFirmwareDirectory11putFirmwareE16_AMD_DEVICE_TYPEP11AMDFirmware", this->orgPutFirmware,
kPutFirmwarePattern},
kPutFirmwarePattern, !catalina},
{"__ZL20CAIL_ASIC_CAPS_TABLE", orgCapsTable, kCailAsicCapsTableHWLibsPattern},
{"_CAILAsicCapsInitTable", orgCapsInitTable, kCAILAsicCapsInitTablePattern},
{"_DeviceCapabilityTbl", orgDevCapTable, kDeviceCapabilityTblPattern},
Expand All @@ -45,21 +46,23 @@ bool X5000HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address
bool renoir = NRed::callback->chipType >= ChipType::Renoir;
RouteRequestPlus requests[] = {
{"__ZN35AMDRadeonX5000_AMDRadeonHWLibsX500025populateFirmwareDirectoryEv", wrapPopulateFirmwareDirectory,
this->orgPopulateFirmwareDirectory},
{"_smu_get_fw_constants", hwLibsNoop, kSmuGetFwConstantsPattern, kSmuGetFwConstantsMask},
this->orgPopulateFirmwareDirectory, !catalina},
{catalina ? "_smu_get_external_fw" : "_smu_get_fw_constants", hwLibsNoop, kSmuGetFwConstantsPattern,
kSmuGetFwConstantsMask},
{"_smu_9_0_1_check_fw_status", hwLibsNoop, kSmu901CheckFwStatusPattern, kSmu901CheckFwStatusMask},
{"_smu_9_0_1_unload_smu", hwLibsNoop, kSmu901UnloadSmuPattern, kSmu901UnloadSmuMask},
{"_psp_cmd_km_submit", wrapPspCmdKmSubmit, this->orgPspCmdKmSubmit, kPspCmdKmSubmitPattern,
kPspCmdKmSubmitMask, renoir},
{"_update_sdma_power_gating", wrapUpdateSdmaPowerGating, this->orgUpdateSdmaPowerGating,
kUpdateSdmaPowerGatingPattern, kUpdateSdmaPowerGatingMask},
{"__ZN16AmdTtlFwServices7getIpFwEjPKcP10_TtlFwInfo", wrapGetIpFw, this->orgGetIpFw, catalina},
};
PANIC_COND(!RouteRequestPlus::routeAll(patcher, id, requests, slide, size), "hwlibs",
"Failed to route symbols");

PANIC_COND(MachInfo::setKernelWriting(true, KernelPatcher::kernelWriteLock) != KERN_SUCCESS, "hwlibs",
"Failed to enable kernel writing");
*orgDeviceTypeTable = {.deviceId = NRed::callback->deviceId, .deviceType = 6};
if (!catalina) { *orgDeviceTypeTable = {.deviceId = NRed::callback->deviceId, .deviceType = 6}; }
auto found = false;
auto targetDeviceId = renoir && NRed::callback->deviceId != 0x1636 ? 0x1636 : NRed::callback->deviceId;
while (orgCapsInitTable->deviceId != 0xFFFFFFFF) {
Expand All @@ -82,7 +85,7 @@ bool X5000HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address
}
orgCapsInitTable++;
}
PANIC_COND(!found, "hwlibs", "Failed to find caps init table entry");
PANIC_COND(!found, "hwlibs", "Failed to find init caps table entry");
found = false;
while (orgDevCapTable->familyId) {
if (orgDevCapTable->familyId == AMDGPU_FAMILY_RAVEN && orgDevCapTable->deviceId == targetDeviceId) {
Expand All @@ -103,16 +106,16 @@ bool X5000HWLibs::processKext(KernelPatcher &patcher, size_t id, mach_vm_address
auto ventura = getKernelVersion() >= KernelVersion::Ventura;
auto monterey = getKernelVersion() >= KernelVersion::Monterey;
const LookupPatchPlus patches[] = {
{&kextRadeonX5000HWLibs, kPspSwInitOriginal1, kPspSwInitPatched1, 1},
{&kextRadeonX5000HWLibs, kPspSwInitOriginal1, kPspSwInitPatched1, 1, !catalina},
{&kextRadeonX5000HWLibs, kPspSwInitOriginal2, kPspSwInitOriginalMask2, kPspSwInitPatched2,
kPspSwInitPatchedMask2, 1},
kPspSwInitPatchedMask2, 1, !catalina},
{&kextRadeonX5000HWLibs, kSmuInitFunctionPointerListOriginal, kSmuInitFunctionPointerListOriginalMask,
kSmuInitFunctionPointerListPatched, kSmuInitFunctionPointerListPatchedMask, 1},
{&kextRadeonX5000HWLibs, kFullAsicResetOriginal, kFullAsicResetPatched, 1},
{&kextRadeonX5000HWLibs, kGcSwInitOriginal, kGcSwInitOriginalMask, kGcSwInitPatched, kGcSwInitPatchedMask,
1},
1, !catalina},
{&kextRadeonX5000HWLibs, kGcSetFwEntryInfoOriginal, kGcSetFwEntryInfoOriginalMask, kGcSetFwEntryInfoPatched,
kGcSetFwEntryInfoPatchedMask, 1},
kGcSetFwEntryInfoPatchedMask, 1, !catalina},
{&kextRadeonX5000HWLibs, kCreatePowerTuneServicesOriginal1, kCreatePowerTuneServicesPatched1, 1, !monterey},
{&kextRadeonX5000HWLibs, kCreatePowerTuneServicesMontereyOriginal1,
kCreatePowerTuneServicesMontereyPatched1, 1, monterey},
Expand All @@ -136,8 +139,8 @@ void X5000HWLibs::wrapPopulateFirmwareDirectory(void *that) {

bool isRenoirDerivative = NRed::callback->chipType >= ChipType::Renoir;

char filename[128] = {0};
snprintf(filename, 128, "%s_vcn.bin", NRed::callback->getChipName());
char filename[64] = {0};
snprintf(filename, 64, "%s_vcn.bin", NRed::callback->getChipName());
auto *targetFn = isRenoirDerivative ? "ativvaxy_nv.dat" : "ativvaxy_rv.dat";
DBGLOG("wred", "%s => %s", filename, targetFn);

Expand Down Expand Up @@ -181,3 +184,18 @@ CAILResult X5000HWLibs::wrapPspCmdKmSubmit(void *psp, void *ctx, void *param3, v

return FunctionCast(wrapPspCmdKmSubmit, callback->orgPspCmdKmSubmit)(psp, ctx, param3, param4);
}

bool X5000HWLibs::wrapGetIpFw(void *that, uint32_t ipVersion, char *name, void *out) {
if (!strncmp(name, "ativvaxy_rv.dat", 16) || !strncmp(name, "ativvaxy_nv.dat", 16)) {
char filename[64] = {0};
snprintf(filename, 64, "%s_vcn.bin", NRed::callback->getChipName());
DBGLOG("wred", "getIpFw: %s => %s", filename, name);

auto &fwDesc = getFWDescByName(filename);
auto *fwHeader = reinterpret_cast<const CommonFirmwareHeader *>(fwDesc.data);
getMember<const uint8_t *>(out, 0x0) = fwDesc.data + fwHeader->ucodeOff;
getMember<uint32_t>(out, 0x8) = fwHeader->ucodeSize;
return true;
}
return FunctionCast(wrapGetIpFw, callback->orgGetIpFw)(that, ipVersion, name, out);
}
2 changes: 2 additions & 0 deletions NootedRed/kern_hwlibs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class X5000HWLibs {
t_putFirmware orgPutFirmware {nullptr};
mach_vm_address_t orgUpdateSdmaPowerGating {0};
mach_vm_address_t orgPspCmdKmSubmit {0};
mach_vm_address_t orgGetIpFw {0};

static void wrapPopulateFirmwareDirectory(void *that);
static void wrapUpdateSdmaPowerGating(void *cail, uint32_t mode);
static CAILResult wrapPspCmdKmSubmit(void *psp, void *ctx, void *param3, void *param4);
static bool wrapGetIpFw(void *that, uint32_t param1, char *name, void *out);
static CAILResult hwLibsNoop();
};
2 changes: 1 addition & 1 deletion NootedRed/kern_nred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class NRed {
uint16_t revision {0};
uint32_t pciRevision {0};
IOPCIDevice *iGPU {nullptr};
OSMetaClass *metaClassMap[4][2] = {{nullptr}};
OSMetaClass *metaClassMap[5][2] = {{nullptr}};
mach_vm_address_t orgSafeMetaCast {0};
mach_vm_address_t orgApplePanelSetDisplay {0};

Expand Down
Loading