Skip to content

Commit

Permalink
feat: Set PP props without debug wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualEhrmanntraut committed Feb 5, 2025
1 parent 098c0c0 commit 7b62a7b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 42 deletions.
67 changes: 28 additions & 39 deletions NootedRed/DebugEnabler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ static const UInt8 kDalDmLoggerShouldLogPartialPattern[] = {0x48, 0x8D, 0x0D, 0x
static const UInt8 kDalDmLoggerShouldLogPartialPatternMask[] = {0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

// HWLibs
static const UInt8 kCosReadConfigurationSettingPattern[] = {0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, 0x41, 0x54,
0x53, 0x48, 0x85, 0xF6, 0x74, 0x00, 0x40, 0x89, 0xD0};
static const UInt8 kCosReadConfigurationSettingPatternMask[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xF0};

//------ Patches ------//

// X6000FB: Enable all Display Core logs.
Expand Down Expand Up @@ -94,6 +88,23 @@ static DebugEnabler instance {};

DebugEnabler &DebugEnabler::singleton() { return instance; }

enum GpuChannelDebugPolicy {
CHANNEL_WAIT_FOR_PM4_IDLE = 0x1,
CHANNEL_WAIT_FOR_TS_AFTER_SUBMISSION = 0x2,
// 0x8, 0x10 = ??, PM4-related
CHANNEL_DISABLE_PREEMPTION = 0x20,
};

enum GpuDebugPolicy {
WAIT_FOR_PM4_IDLE = 0x1,
WAIT_FOR_TS_AFTER_SUBMISSION = 0x2,
PANIC_AFTER_DUMPING_LOG = 0x4,
PANIC_ON_POWEROFF_REGISTER_ACCESS = 0x8,
PRINT_FUNC_ENTRY_EXIT = 0x40,
DBX_SLEEP_BEFORE_GPU_RESTART = 0x200,
DISABLE_PREEMPTION = 0x80000000,
};

void DebugEnabler::init() {
PANIC_COND(this->initialised, "DebugEnabler", "Attempted to initialise module twice!");
this->initialised = true;
Expand All @@ -115,6 +126,14 @@ void DebugEnabler::init() {
}

void DebugEnabler::processX6000FB(KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size) {
NRed::singleton().setProp32("PP_LogLevel", 0xFFFFFFFF);
NRed::singleton().setProp32("PP_LogSource", 0xFFFFFFFF);
NRed::singleton().setProp32("PP_LogDestination", 0xFFFFFFFF);
NRed::singleton().setProp32("PP_LogField", 0xFFFFFFFF);
NRed::singleton().setProp32("PP_DumpRegister", TRUE);
NRed::singleton().setProp32("PP_DumpSMCTable", TRUE);
NRed::singleton().setProp32("PP_LogDumpTableBuffers", TRUE);

RouteRequestPlus requests[] = {
{"__ZN24AMDRadeonX6000_AmdLogger15initWithPciInfoEP11IOPCIDevice", wrapInitWithPciInfo,
this->orgInitWithPciInfo},
Expand Down Expand Up @@ -163,13 +182,7 @@ void DebugEnabler::processX6000FB(KernelPatcher &patcher, size_t id, mach_vm_add
"Failed to apply AmdBiosParserHelper::initWithData patch");
}

void DebugEnabler::processX5000HWLibs(KernelPatcher &patcher, size_t id, mach_vm_address_t slide, size_t size) {
RouteRequestPlus request = {"__ZN14AmdTtlServices27cosReadConfigurationSettingEPvP36cos_read_configuration_"
"setting_inputP37cos_read_configuration_setting_output",
wrapCosReadConfigurationSetting, this->orgCosReadConfigurationSetting, kCosReadConfigurationSettingPattern,
kCosReadConfigurationSettingPatternMask};
PANIC_COND(!request.route(patcher, id, slide, size), "DebugEnabler", "Failed to route cosReadConfigurationSetting");

void DebugEnabler::processX5000HWLibs(KernelPatcher &patcher, size_t, mach_vm_address_t slide, size_t size) {
const LookupPatchPlus atiPpSvcCtrPatch = {&kextX5000HWLibs, kAtiPowerPlayServicesConstructorOriginal,
kAtiPowerPlayServicesConstructorPatched, 1};
PANIC_COND(!atiPpSvcCtrPatch.apply(patcher, slide, size), "DebugEnabler", "Failed to apply MCIL debugLevel patch");
Expand Down Expand Up @@ -236,39 +249,15 @@ void DebugEnabler::wrapDmLoggerWrite(void *, const UInt32 logType, const char *f
IOFree(message, 0x1000);
}

CAILResult DebugEnabler::wrapCosReadConfigurationSetting(void *cosHandle,
CosReadConfigurationSettingInput *readCfgInput, CosReadConfigurationSettingOutput *readCfgOutput) {
if (readCfgInput != nullptr && readCfgInput->settingName != nullptr && readCfgInput->outPtr != nullptr &&
readCfgInput->outLen == 4) {
if (strncmp(readCfgInput->settingName, "PP_LogLevel", 12) == 0 ||
strncmp(readCfgInput->settingName, "PP_LogSource", 13) == 0 ||
strncmp(readCfgInput->settingName, "PP_LogDestination", 18) == 0 ||
strncmp(readCfgInput->settingName, "PP_LogField", 12) == 0) {
*static_cast<UInt32 *>(readCfgInput->outPtr) = 0xFFFFFFFF;
if (readCfgOutput != nullptr) { readCfgOutput->settingLen = 4; }
return kCAILResultSuccess;
}
if (strncmp(readCfgInput->settingName, "PP_DumpRegister", 16) == 0 ||
strncmp(readCfgInput->settingName, "PP_DumpSMCTable", 16) == 0 ||
strncmp(readCfgInput->settingName, "PP_LogDumpTableBuffers", 23) == 0) {
*static_cast<UInt32 *>(readCfgInput->outPtr) = 1;
if (readCfgOutput != nullptr) { readCfgOutput->settingLen = 4; }
return kCAILResultSuccess;
}
}
return FunctionCast(wrapCosReadConfigurationSetting, singleton().orgCosReadConfigurationSetting)(cosHandle,
readCfgInput, readCfgOutput);
}

bool DebugEnabler::wrapGetNumericProperty(void *that, const char *name, uint32_t *value) {
auto ret = FunctionCast(wrapGetNumericProperty, singleton().orgGetNumericProperty)(that, name, value);
if (name == nullptr || strncmp(name, "GpuDebugPolicy", 15) != 0) { return ret; }
if (value != nullptr) {
// Enable entry traces
if (ret) {
*value |= (1U << 6);
*value |= PRINT_FUNC_ENTRY_EXIT;
} else {
*value = (1U << 6);
*value = PRINT_FUNC_ENTRY_EXIT;
}
}
return true;
Expand Down
2 changes: 2 additions & 0 deletions NootedRed/NRed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ void NRed::processPatcher(KernelPatcher &patcher) {
PANIC_COND(!patcher.routeMultipleLong(KernelPatcher::KernelID, requests), "NRed", "Failed to route kernel symbols");
}

void NRed::setProp32(const char *key, UInt32 value) { this->iGPU->setProperty(key, value, 32); }

UInt32 NRed::readReg32(UInt32 reg) const {
if ((reg * sizeof(UInt32)) < this->rmmio->getLength()) {
return this->rmmioPtr[reg];
Expand Down
3 changes: 0 additions & 3 deletions NootedRed/PrivateHeaders/DebugEnabler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class DebugEnabler {
bool initialised {false};
mach_vm_address_t orgInitWithPciInfo {0};
mach_vm_address_t orgCosReadConfigurationSetting {0};
mach_vm_address_t orgGetNumericProperty {0};

public:
Expand All @@ -25,7 +24,5 @@ class DebugEnabler {
static bool wrapInitWithPciInfo(void *that, void *pciDevice);
static void wrapDoGPUPanic(void *that, char const *fmt, ...);
static void wrapDmLoggerWrite(void *logger, const UInt32 logType, const char *fmt, ...);
static CAILResult wrapCosReadConfigurationSetting(void *cosHandle, CosReadConfigurationSettingInput *readCfgInput,
CosReadConfigurationSettingOutput *readCfgOutput);
static bool wrapGetNumericProperty(void *that, const char *name, UInt32 *value);
};
1 change: 1 addition & 0 deletions NootedRed/PrivateHeaders/NRed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class NRed {
void hwLateInit();
void processPatcher(KernelPatcher &patcher);

void setProp32(const char *key, UInt32 value);
UInt32 readReg32(UInt32 reg) const;
void writeReg32(UInt32 reg, UInt32 val) const;
UInt32 smuWaitForResponse() const;
Expand Down

0 comments on commit 7b62a7b

Please sign in to comment.