Skip to content

Commit

Permalink
ReBarDxe: Add CMOS reset detection
Browse files Browse the repository at this point in the history
  • Loading branch information
xCuri0 committed Feb 26, 2023
1 parent 6837c52 commit 885e487
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 20 additions & 1 deletion ReBarDxe/ReBar.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 xCuri0 <zkqri0@gmail.com>
Copyright (c) 2022-2023 xCuri0 <zkqri0@gmail.com>
SPDX-License-Identifier: MIT
*/
#include <Uefi.h>
Expand All @@ -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}};

Expand Down Expand Up @@ -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"));

Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion ReBarState/ReBarState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 885e487

Please sign in to comment.