diff --git a/Changelog.md b/Changelog.md index 7efcb1a6..f7dd3f99 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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 diff --git a/README.md b/README.md index e241b100..c71b365f 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Read [FAQs](https://github.com/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). diff --git a/WhateverGreen/kern_ngfx.cpp b/WhateverGreen/kern_ngfx.cpp index 1967ee9b..19324022 100644 --- a/WhateverGreen/kern_ngfx.cpp +++ b/WhateverGreen/kern_ngfx.cpp @@ -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" }; @@ -35,6 +39,7 @@ 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 } }; @@ -42,7 +47,8 @@ enum KextIndex { IndexGeForce, IndexGeForceWeb, IndexNVDAStartupWeb, - IndexIONDRVSupport + IndexNVDAResman, + IndexIONDRVSupport, }; NGFX *NGFX::callbackNGFX; @@ -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)); @@ -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(); @@ -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; @@ -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); +} diff --git a/WhateverGreen/kern_ngfx.hpp b/WhateverGreen/kern_ngfx.hpp index cd89634b..83a4f162 100644 --- a/WhateverGreen/kern_ngfx.hpp +++ b/WhateverGreen/kern_ngfx.hpp @@ -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 */ @@ -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 */