From 885e48708aa28b43456ee6864d9a47b1cc380cda Mon Sep 17 00:00:00 2001 From: Curi0 Date: Sun, 26 Feb 2023 11:07:56 +0530 Subject: [PATCH] ReBarDxe: Add CMOS reset detection --- LICENSE | 2 +- README.md | 2 +- ReBarDxe/ReBar.c | 21 ++++++++++++++++++++- ReBarState/ReBarState.cpp | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index c52c1fb..acf99e5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 xCuri0 +Copyright (c) 2022-2023 xCuri0 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 52e7e3d..f762b67 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Run ReBarState (found in Releases) and set the Resizable BAR size. **If Resizabl If you have any issues after enabling Resizable BAR see [Common Issues (and fixes)](https://github.com/xCuri0/ReBarUEFI/wiki/Common-issues-(and-fixes)) -**Some firmware don't clear NVRAM variables (ReBarState) when the CMOS is cleared. This can be a problem as CMOS clear will reset BIOS settings (4G/CSM) while keeping ReBarState enabled requiring you to boot with iGPU/non-rebar GPU to disable ReBarState. To mitigate this issue see wiki page [Enabling 4G Decode and CSM Off by default](https://github.com/xCuri0/ReBarUEFI/wiki/Enabling-4G-Decode-and-CSM-Off-by-default). If it can be figured out how to detect boot failures then this won't be required** +You won't have any issues with clearing CMOS like on earlier builds, there is now CMOS reset detection by checking system date. ### AliExpress X99 Tutorial by Miyconst [![Resizable BAR on LGA 2011-3 X99](http://img.youtube.com/vi/vcJDWMpxpjE/0.jpg)](http://www.youtube.com/watch?v=vcJDWMpxpjEE "Resizable BAR on LGA 2011-3 X99") diff --git a/ReBarDxe/ReBar.c b/ReBarDxe/ReBar.c index 4122db6..27e4d8e 100644 --- a/ReBarDxe/ReBar.c +++ b/ReBarDxe/ReBar.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2022 xCuri0 +Copyright (c) 2022-2023 xCuri0 SPDX-License-Identifier: MIT */ #include @@ -24,6 +24,9 @@ SPDX-License-Identifier: MIT // for quirk #define PCI_VENDOR_ID_ATI 0x1002 +// if system time is before this year then CMOS reset will be detected and rebar will be disabled. +#define BUILD_YEAR 2023 + // a3c5b77a-c88f-4a93-bf1c-4a92a32c65ce static GUID reBarStateGuid = { 0xa3c5b77a, 0xc88f, 0x4a93, {0xbf, 0x1c, 0x4a, 0x92, 0xa3, 0x2c, 0x65, 0xce}}; @@ -286,6 +289,7 @@ EFI_STATUS EFIAPI rebarInit( UINTN bufferSize = 1; EFI_STATUS status; UINT32 attributes; + EFI_TIME time; DEBUG((DEBUG_INFO, "ReBarDXE: Loaded\n")); @@ -301,6 +305,21 @@ EFI_STATUS EFIAPI rebarInit( if (reBarState) { DEBUG((DEBUG_INFO, "ReBarDXE: Enabled, maximum BAR size 2^%u MB\n", reBarState)); + + // Detect CMOS reset by checking if year before BUILD_YEAR + status = gRT->GetTime (&time, NULL); + if (time.Year < BUILD_YEAR) { + reBarState = 0; + bufferSize = 1; + attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; + + status = gRT->SetVariable(L"ReBarState", &reBarStateGuid, + attributes, + bufferSize, &reBarState); + + return EFI_SUCCESS; + } + // For overriding PciHostBridgeResourceAllocationProtocol pciHostBridgeResourceAllocationProtocolHook(); } diff --git a/ReBarState/ReBarState.cpp b/ReBarState/ReBarState.cpp index c5d6d8c..27f4528 100644 --- a/ReBarState/ReBarState.cpp +++ b/ReBarState/ReBarState.cpp @@ -163,7 +163,7 @@ int main() std::cout << "ReBarState variable doesn't exist / Disabled. Enter a value to create it\n"; } - std::cout << "\nVerify that 4G Decoding is enabled otherwise system will not POST with GPU. There is also a possibility of BIOS not supporting large BARs even with 4G decoding enabled.\n"; + std::cout << "\nVerify that 4G Decoding is enabled otherwise system will not POST with GPU. If your ReBarState value keeps getting reset then check your system time.\n"; std::cout << "\nIt is recommended to first try smaller sizes above 256MB in case BIOS doesn't support large BARs.\n"; std::cout << "\nEnter ReBarState Value\n 0: Disabled \nAbove 0: Maximum BAR size set to 2^x MB \n 32: Unlimited BAR size\n\n";