Skip to content

Commit

Permalink
Revert "ReBarDxe: remove RX 5600 XT quirk"
Browse files Browse the repository at this point in the history
This reverts commit c456936.
  • Loading branch information
xCuri0 committed Feb 26, 2023
1 parent ec0fb6a commit 6837c52
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ReBarDxe/ReBar.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ SPDX-License-Identifier: MIT

#define PCI_POSSIBLE_ERROR(val) ((val) == 0xffffffff)

// for quirk
#define PCI_VENDOR_ID_ATI 0x1002

// a3c5b77a-c88f-4a93-bf1c-4a92a32c65ce
static GUID reBarStateGuid = { 0xa3c5b77a, 0xc88f, 0x4a93, {0xbf, 0x1c, 0x4a, 0x92, 0xa3, 0x2c, 0x65, 0xce}};

Expand Down Expand Up @@ -145,7 +148,7 @@ INTN pciRebarFindPos(UINTN pciAddress, INTN pos, UINT8 bar)
return -1;
}

UINT32 pciRebarGetPossibleSizes(UINTN pciAddress, UINTN epos, UINT8 bar)
UINT32 pciRebarGetPossibleSizes(UINTN pciAddress, UINTN epos, UINT16 vid, UINT16 did, UINT8 bar)
{
INTN pos;
UINT32 cap;
Expand All @@ -157,6 +160,11 @@ UINT32 pciRebarGetPossibleSizes(UINTN pciAddress, UINTN epos, UINT8 bar)
pciReadConfigDword(pciAddress, pos + PCI_REBAR_CAP, &cap);
cap &= PCI_REBAR_CAP_SIZES;

/* Sapphire RX 5600 XT Pulse has an invalid cap dword for BAR 0 */
if (vid == PCI_VENDOR_ID_ATI && did == 0x731f &&
bar == 0 && cap == 0x7000)
cap = 0x3f000;

return cap >> 4;
}

Expand All @@ -180,19 +188,28 @@ INTN pciRebarSetSize(UINTN pciAddress, UINTN epos, UINT8 bar, UINT8 size)
VOID reBarSetupDevice(EFI_HANDLE handle, EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS addrInfo)
{
UINTN epos;
UINT16 vid, did;
UINTN pciAddress;

gBS->HandleProtocol(handle, &gEfiPciRootBridgeIoProtocolGuid, (void **)&pciRootBridgeIo);

pciAddress = EFI_PCI_ADDRESS(addrInfo.Bus, addrInfo.Device, addrInfo.Function, 0);
pciReadConfigWord(pciAddress, 0, &vid);
pciReadConfigWord(pciAddress, 2, &did);

if (vid == 0xFFFF)
return;

DEBUG((DEBUG_INFO, "ReBarDXE: Device vid:%x did:%x\n", vid, did));

epos = pciFindExtCapability(pciAddress, PCI_EXT_CAP_ID_REBAR);
if (epos)
{
for (UINT8 bar = 0; bar < 6; bar++)
{
UINT32 rBarS = pciRebarGetPossibleSizes(pciAddress, epos, bar);

UINT32 rBarS = pciRebarGetPossibleSizes(pciAddress, epos, vid, did, bar);
if (!rBarS)
continue;
// start with size from fls
for (UINT8 n = MIN((UINT8)fls(rBarS), reBarState); n > 0; n--) {
// check if size is supported
Expand Down

0 comments on commit 6837c52

Please sign in to comment.