‹ BackHN Continuity

Thread

ReBarUEFI: Resizable BAR for almost any UEFI system

243 points · 77 comments · nateb2022

  1. bigwheels · · focus · HN ↗
    What does this do? I perused the README but I'm still clueless on what the purpose and use-case is for ReBAR.

    (Posting this under the assumption others will also appreciate a bit of quick context.)

    1. zir_blazer · · focus · HN ↗
      Since about 5 or 6 years ago, PCIe Video Cards advertise a capability known as Resizeable BAR. PCI Devices like GPUs require some memory to use for PCI MMIO, which is directly visible on the CPU Address Space. As a side note, this Address Space is shared with RAM, and anyone that was around when having 4 GiB RAM with a 32 Bit OS was common (Earlier than 2010 or so) knows that you only saw about 3.25 GiB RAM or so because of sharing the Address Space with PCI MMIO, and those fortunate enough to have used SLI usually saw even less than that, like 2.87 GiB RAM.

      GPUs has been using a 256 MiB PCI MMIO window regardless of how much VRAM they actually have since... nearly forever? At least since PCIe is a thing, since I recall than AGP Aperture Size was seteable in era accurate BIOSes. PCIe 3.0 specification introduced a feature known as Resizeable BAR, where the PCI Device can tell a compatible Firmware how much MMIO it actually wants. GPUs uses that to tell a ReBAR capable UEFI Firmware that it wants more MMIO (Usually as big as the GPU VRAM), or uses legacy 256 MiB otherwise.

      1. akiselev · · focus · HN ↗
        Just to make sure I understand: Is the resizable BAR/MMIO a RAM buffer for PCie packets? Or does it have some deeper integration with DMA or something? I assume it's not like memory mapped peripherals on an AXI bus which is why you need the buffer?
        1. imtringued · · focus · HN ↗
          There is no buffer at all. BAR is "base address register" (hint, there is no "the BAR"). Each PCIe device / function can have up to 6 32-bit BARs or 3 64 bit BARs.

          When you insert a GPU into a PCIe slot, the memory mapped regions in memory can't be put in a hard wired location because any arbitrary device can be inserted and it can provide an arbitrary amount of memory (yes the GPU provides its own memory to the CPU). A BAR reserves a memory mapped region in the CPU space that is backed by the PCIe device.

          When the BAR is smaller than the memory of the inserted device, the CPU cannot communicate with all of the memory on the inserted device directly anmore. This means if you want to perform a write to a region in the GPU outside a BAR region you have to go through the BAR region anyway. It's not a RAM buffer for PCIe packets.

          >I assume it's not like memory mapped peripherals on an AXI bus which is why you need the buffer?

          The PCIe controller is an AXI peripheral...

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.