3

Quick question, I was reading the OSDev Wiki page regarding PCI and it says the following -

"Base address Registers (or BARs) can be used to hold memory addresses used by the device, or offsets for port addresses. Typically, memory address BARs need to be located in physical ram while I/O space BARs can reside at any memory address (even beyond physical memory)."

I don't get where it says memory address BARs need to be located in physical ram? The whole point of MMIO is that when it gets assigned a memory address so that it will be routed to the device and not into physical RAM. What does it mean by it needs to be located in physical RAM?

Wouldn't it just be an address between the 3GB - 4GB address space, regardless of how much physical RAM is installed?

Is this an error on the OSDev site or have I misunderstood?

link - About halfway down, under the heading Base Address Registers

Thanks.

RJSmith92
  • 373
  • 1
  • 3
  • 9

1 Answers1

5

The OSDev site is ok. They describe memory/IO BARS from PCI device perspective, not from host perspective. So what OSDev is saying that memory BARs can be (but not necessarily are) mapped to physical RAM on PCI device. While IO BARs are usually something else (registers, FIFO, whatever).

Please also note, that the use of IO BARs is discouraged. It is better to use only memory BARs. Usually, you will have a small memory BAR that will group all the registers. And other BARs will exposes pieces of RAM of your PCI device.

Alexey Polonsky
  • 1,141
  • 11
  • 12
  • Thanks for the answer. Knowing it's from the PCI device perspective makes it clearer bit I'm still a bit confused. Isn't the memory BAR always going to be mapped to physical RAM on the device? So if my device mapped 0xE0000000 - 0xEFFFFFFF the memory BAR would contain this address range? – RJSmith92 Apr 30 '14 at 23:41
  • 1
    No, a memory BAR can be mapped to registers. As an example, you can look at any network card on your PC. They usually have just one small BAR (typically, 256bytes) and only some portion of it is registers, the rest is unused. Another example would display adapter, it usually has a small memory BAR for register and a large memory BAR that is mapped to video framebuffer, which is a piece of RAM on PCI device. – Alexey Polonsky May 01 '14 at 13:30
  • 1
    Also, the value that you see in BAR (e.g. 0xE0000000) is set by host when the host enumerates all PCI devices. This value is meaningful for host and meaningless for device. – Alexey Polonsky May 01 '14 at 13:33