Skip to content

Commit

Permalink
Add NVIDIA error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Jun 5, 2021
1 parent 6130078 commit 2144863
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ WhateverGreen Changelog
=======================
#### v1.5.0
- Fixed AMD WX-4170 name for 67E0 device id
- Added NVIDIA driver error logging with `-ngfxdbg`

#### v1.4.9
- Added per-GPU disabling API: inject `disable-gpu` to disable
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Read [FAQs](https:/acidanthera/WhateverGreen/blob/master/Manual/) an
- `ngfxgl=1` boot argument (and `disable-metal` property) to disable Metal support on NVIDIA
- `ngfxcompat=1` boot argument (and `force-compat` property) to ignore compatibility check in NVDAStartupWeb
- `ngfxsubmit=0` boot argument (and `disable-gfx-submit` property) to disable interface stuttering fix on 10.13
- `-ngfxdbg` boot argument to enable NVIDIA driver error logging
- `gfxrst=1` to prefer drawing Apple logo at 2nd boot stage instead of framebuffer copying.
- `gfxrst=4` to disable framebuffer init interaction during 2nd boot stage.
- `igfxframe=frame` to inject a dedicated framebuffer identifier into IGPU (only for TESTING purposes).
Expand Down
28 changes: 27 additions & 1 deletion WhateverGreen/kern_ngfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ static const char *pathNVDAStartupWeb[] {
"/System/Library/Extensions/NVDAStartupWeb.kext/Contents/MacOS/NVDAStartupWeb"
};

static const char *pathNVDAResman[] {
"/System/Library/Extensions/NVDAResman.kext/Contents/MacOS/NVDAResman"
};

static const char *pathIONDRVSupport[] {
"/System/Library/Extensions/IONDRVSupport.kext/IONDRVSupport"
};
Expand All @@ -35,14 +39,16 @@ static KernelPatcher::KextInfo kextList[] {
{ "com.apple.GeForce", pathGeForce, arrsize(pathGeForce), {}, {}, KernelPatcher::KextInfo::Unloaded },
{ "com.nvidia.web.GeForceWeb", pathGeForceWeb, arrsize(pathGeForceWeb), {}, {}, KernelPatcher::KextInfo::Unloaded },
{ "com.nvidia.NVDAStartupWeb", pathNVDAStartupWeb, arrsize(pathNVDAStartupWeb), {}, {}, KernelPatcher::KextInfo::Unloaded },
{ "com.apple.nvidia.driver.NVDAResman", pathNVDAResman, arrsize(pathNVDAResman), {}, {}, KernelPatcher::KextInfo::Unloaded },
{ "com.apple.iokit.IONDRVSupport", pathIONDRVSupport, arrsize(pathIONDRVSupport), {}, {}, KernelPatcher::KextInfo::Unloaded }
};

enum KextIndex {
IndexGeForce,
IndexGeForceWeb,
IndexNVDAStartupWeb,
IndexIONDRVSupport
IndexNVDAResman,
IndexIONDRVSupport,
};

NGFX *NGFX::callbackNGFX;
Expand All @@ -51,6 +57,7 @@ void NGFX::init() {
callbackNGFX = this;

PE_parse_boot_argn("ngfxcompat", &forceDriverCompatibility, sizeof(forceDriverCompatibility));
enableDebugLogging = checkKernelArgument("-ngfxdbg");
disableTeamUnrestrict = checkKernelArgument("-ngfxlibvalfix");

lilu.onKextLoadForce(kextList, arrsize(kextList));
Expand Down Expand Up @@ -88,6 +95,9 @@ void NGFX::processKernel(KernelPatcher &patcher, DeviceInfo *info) {

if (getKernelVersion() <= KernelVersion::Catalina)
kextList[IndexIONDRVSupport].switchOff();

if (!enableDebugLogging)
kextList[IndexNVDAResman].switchOff();
} else {
for (size_t i = 0; i < arrsize(kextList); i++)
kextList[i].switchOff();
Expand Down Expand Up @@ -117,6 +127,13 @@ bool NGFX::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t a
if (kextList[IndexIONDRVSupport].loadIndex == index) {
KernelPatcher::RouteRequest request("__ZN17IONDRVFramebuffer10_doControlEPS_jPv", wrapNdrvDoControl, orgNdrvDoControl);
patcher.routeMultiple(index, &request, 1, address, size);
return true;
}

if (kextList[IndexNVDAResman].loadIndex == index) {
KernelPatcher::RouteRequest request("_nvErrorLog_va", resmanErrorLogVA);
patcher.routeMultiple(index, &request, 1, address, size);
return true;
}

return false;
Expand Down Expand Up @@ -368,3 +385,12 @@ IOReturn NGFX::wrapNdrvDoControl(IONDRVFramebuffer *fb, UInt32 code, void *param

return FunctionCast(wrapNdrvDoControl, callbackNGFX->orgNdrvDoControl)(fb, code, params);
}

void NGFX::resmanErrorLogVA(void *context, uint32_t id, const char *format, ...) {
char buf[1024];
va_list va;
va_start(va, format);
vsnprintf(buf, sizeof(buf), format, va);
va_end(va);
SYSLOG("ngfx", "RM%u: %s", id, buf);
}
11 changes: 10 additions & 1 deletion WhateverGreen/kern_ngfx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class NGFX {
*/
int fifoSubmit {-1};

/**
* Enable debug logging in NVIDIA drivers
*/
bool enableDebugLogging {false};

/**
* Disable team unrestriction patches fixing visual glitches on 10.12 with Web drivers
*/
Expand Down Expand Up @@ -162,8 +167,12 @@ class NGFX {
/**
* IONDRVFramebuffer::_doControl wrapper used to avoid debug spam
*/

static IOReturn wrapNdrvDoControl(IONDRVFramebuffer *fb, UInt32 code, void *params);

/**
* nvErrorLog_va replacement with logging support
*/
static void resmanErrorLogVA(void *context, uint32_t id, const char *format, ...);
};

#endif /* kern_ngfx_hpp */

0 comments on commit 2144863

Please sign in to comment.