diff --git a/Changelog.md b/Changelog.md index 0ec75c32..3b66817d 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,7 @@ OpenCore Changelog - Added TimeMachine detection to picker - Added early preview version of BootLiquor - Fixed FS discovery on NVMe with legacy drivers +- Added DirectGopCacheMode option for FB cache policy #### v0.5.6 - Various improvements to builtin text renderer diff --git a/Docs/Sample.plist b/Docs/Sample.plist index 97ffe74e..dde95b54 100644 --- a/Docs/Sample.plist +++ b/Docs/Sample.plist @@ -847,6 +847,8 @@ DirectGopRendering + DirectGopCacheMode + -1 ReconnectOnResChange ReplaceTabWithSpace diff --git a/Docs/SampleFull.plist b/Docs/SampleFull.plist index dc0762f5..931b401a 100644 --- a/Docs/SampleFull.plist +++ b/Docs/SampleFull.plist @@ -950,6 +950,8 @@ DirectGopRendering + DirectGopCacheMode + -1 ReconnectOnResChange ReplaceTabWithSpace diff --git a/Include/Library/OcConfigurationLib.h b/Include/Library/OcConfigurationLib.h index da9f8825..3c10d578 100644 --- a/Include/Library/OcConfigurationLib.h +++ b/Include/Library/OcConfigurationLib.h @@ -498,6 +498,7 @@ typedef enum { _(OC_STRING , ConsoleMode , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) \ _(OC_STRING , Resolution , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) \ _(OC_STRING , TextRenderer , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING)) \ + _(INT32 , DirectGopCacheMode , , -1 , ()) \ _(BOOLEAN , IgnoreTextInGraphics , , FALSE , ()) \ _(BOOLEAN , ClearScreenOnModeSwitch , , FALSE , ()) \ _(BOOLEAN , ProvideConsoleGop , , FALSE , ()) \ diff --git a/Include/Library/OcConsoleLib.h b/Include/Library/OcConsoleLib.h index 20717f18..7d06a184 100644 --- a/Include/Library/OcConsoleLib.h +++ b/Include/Library/OcConsoleLib.h @@ -144,10 +144,14 @@ OcReconnectConsole ( /** Use direct GOP renderer for console. + + @param[in] CacheType Caching type, e.g. CacheWriteCombining or -1 to disable. + + @retval EFI_SUCCESS on success. **/ EFI_STATUS OcUseDirectGop ( - VOID + IN INT32 CacheType ); /** diff --git a/Library/OcConfigurationLib/OcConfigurationLib.c b/Library/OcConfigurationLib/OcConfigurationLib.c index c5ed4976..d67f5730 100644 --- a/Library/OcConfigurationLib/OcConfigurationLib.c +++ b/Library/OcConfigurationLib/OcConfigurationLib.c @@ -578,6 +578,7 @@ OC_SCHEMA mUefiOutputSchema[] = { OC_SCHEMA_BOOLEAN_IN ("ClearScreenOnModeSwitch",OC_GLOBAL_CONFIG, Uefi.Output.ClearScreenOnModeSwitch), OC_SCHEMA_STRING_IN ("ConsoleMode", OC_GLOBAL_CONFIG, Uefi.Output.ConsoleMode), + OC_SCHEMA_INTEGER_IN ("DirectGopCacheMode", OC_GLOBAL_CONFIG, Uefi.Output.DirectGopCacheMode), OC_SCHEMA_BOOLEAN_IN ("DirectGopRendering", OC_GLOBAL_CONFIG, Uefi.Output.DirectGopRendering), OC_SCHEMA_BOOLEAN_IN ("IgnoreTextInGraphics", OC_GLOBAL_CONFIG, Uefi.Output.IgnoreTextInGraphics), OC_SCHEMA_BOOLEAN_IN ("ProvideConsoleGop", OC_GLOBAL_CONFIG, Uefi.Output.ProvideConsoleGop), diff --git a/Library/OcConsoleLib/ConsoleGop.c b/Library/OcConsoleLib/ConsoleGop.c index c5e119b0..591c02c1 100644 --- a/Library/OcConsoleLib/ConsoleGop.c +++ b/Library/OcConsoleLib/ConsoleGop.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,10 @@ STATIC EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE mOriginalGopSetMode; +STATIC +INT32 +mCachePolicy; + STATIC EFI_STATUS EFIAPI @@ -260,6 +265,14 @@ DirectGopSetMode ( return EFI_DEVICE_ERROR; } + if (mCachePolicy >= 0) { + MtrrSetMemoryAttribute ( + This->Mode->FrameBufferBase, + This->Mode->FrameBufferSize, + mCachePolicy + ); + } + gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; } @@ -354,7 +367,7 @@ OcReconnectConsole ( EFI_STATUS OcUseDirectGop ( - VOID + IN INT32 CacheType ) { EFI_STATUS Status; @@ -384,5 +397,26 @@ OcUseDirectGop ( mOriginalGopSetMode = Gop->SetMode; Gop->SetMode = DirectGopSetMode; Gop->Blt = DirectGopBlt; + mCachePolicy = -1; + + if (CacheType >= 0) { + Status = MtrrSetMemoryAttribute ( + Gop->Mode->FrameBufferBase, + Gop->Mode->FrameBufferSize, + CacheType + ); + DEBUG (( + DEBUG_INFO, + "OCC: FB (%Lx, %Lx) MTRR (%x) - %r\n", + (UINT64) Gop->Mode->FrameBufferBase, + (UINT64) Gop->Mode->FrameBufferSize, + CacheType, + Status + )); + if (!EFI_ERROR (Status)) { + mCachePolicy = CacheType; + } + } + return EFI_SUCCESS; } diff --git a/Library/OcConsoleLib/OcConsoleLib.inf b/Library/OcConsoleLib/OcConsoleLib.inf index a21f1c93..fcb68391 100644 --- a/Library/OcConsoleLib/OcConsoleLib.inf +++ b/Library/OcConsoleLib/OcConsoleLib.inf @@ -52,11 +52,13 @@ MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OpenCorePkg/OpenCorePkg.dec + UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] BaseLib BaseMemoryLib DebugLib FrameBufferBltLib + MtrrLib UefiBootServicesTableLib UefiRuntimeServicesTableLib diff --git a/Platform/OpenCore/OpenCoreUefiInOut.c b/Platform/OpenCore/OpenCoreUefiInOut.c index fc464ee0..73c4f432 100644 --- a/Platform/OpenCore/OpenCoreUefiInOut.c +++ b/Platform/OpenCore/OpenCoreUefiInOut.c @@ -237,7 +237,7 @@ OcLoadUefiOutputSupport ( } if (Config->Uefi.Output.DirectGopRendering) { - OcUseDirectGop (); + OcUseDirectGop (Config->Uefi.Output.DirectGopCacheMode); } if (Config->Uefi.Output.ReconnectOnResChange) {