bios - PCI BAR memory addresses

07
2014-07
  • RJSmith92

    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.

  • Answers
  • harrymc

    I believe there is some confusion here, as there is a difference between I/O and non-I/O devices.
    From wikipedia Memory-mapped I/O (MMIO) :

    Memory-mapped I/O uses the same address bus to address both memory and I/O devices – the memory and registers of the I/O devices are mapped to (associated with) address values. So when an address is accessed by the CPU, it may refer to a portion of physical RAM, but it can also refer to memory of the I/O device. Thus, the CPU instructions used to access the memory can also be used for accessing devices. Each I/O device monitors the CPU's address bus and responds to any CPU access of an address assigned to that device, connecting the data bus to the desired device's hardware register. To accommodate the I/O devices, areas of the addresses used by the CPU must be reserved for I/O and must not be available for normal physical memory.

    From your article :

    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).

    image

    The Type field of the Memory Space BAR Layout specifies the size of the base register and where in memory it can be mapped. If it has a value of 0x00 then the base register is 32-bits wide and can be mapped anywhere in the 32-bit Memory Space. A value of 0x02 means the base register is 64-bits wide and can be mapped anywhere in the 64-bit Memory Space (A 64-bit base address register consumes 2 of the base address registers available).

    Thus there is no conflict between the two, as it all depends on the device. If the device intercepts the memory reference on the bus, then the address is virtual. If it doesn't, then it's real physical address that is used to communicate with the device (for example NVRAM).

    However, in all cases, real physical address is used for I/O devices, since computer instructions that refer to it can only use real addresses. This memory may be wasted if the device intercepts references to it. To avoid such waste, the operating system will usually allocate it beyond the real physical memory (this will cause no errors of bad memory access, since the device will intercept all references).

    This is the reason for the well-known problem of 32-bit Windows computers not seemingly being able to use the entire 4 GB of memory. The reason was that Windows, being 32-bit, allocated device memory using real addresses, which then became unavailable for both the cases: whether the addressed memory was really used, or unused because intercepted by the device.

    Another useful wikipedia article is : PCI configuration space.


  • Related Question

    memory - PCI cards fail when using 4 gig ram
  • user836

    I recently installed 4 gig or ram into my 32bit vista box. I realize that I wont be able to use the entire 4 gig until I go to 64bit vista, but 2 gig wasn't enough and I figured I could use as much of the 4 gig as vista will allow until I upgrade to 64 bit.

    When I installed the 4 gig of ram, all of my PCI cards, A second graphics card, a second NIC, and a firewire card, stop working. Looking in device manager, the error was "This device cannot find enough free resources that it can use".

    I read that PCI cards need some of the addressable memory space to use for memory mapping? Is the problem I use it all up with my ram? If so, Can I reserve some memory for these devices?

    My computer is a Dell Precision 390. It has the Intel 975X Express chipset and an Intel Core 2 6600 @2.40 GHz processor.

    Update: Removing my second video card allowed the other two PCI cards to start working. I'm not sure why.


  • Related Answers
  • Joshua

    It could be that your computer is set to prioritize RAM over allocation for the cards. I would go to the BIOS and change the setting of PNP OS Installed (it'll be different for every BIOS but the idea is that the OS can change the settings of your PCI cards). If it's set to disabled or off, enable it. This will let Windows change the settings of your cards and could allow them to work. If it is already enabled go ahead and disable it since it could be Windows that is reallocating things in the first place.

    Neither change will harm your computer and can easily be set back.

  • th3dude

    I don't think this should be a problem, but it does really sound like a memory addressing problem.

    You are right. PCI cards, video cards, etc all need to be mapped to that small amount of space that 32 bit provides.

    Remove the extra RAM that you installed (ie go back to 2GB). If that fixes the problem, then it is definitely a mapping issue.

    In some cases, updating your BIOS can fix the issue. However, the only sure-fire fixes are to either:

    1. Stick with 2GB RAM (assuming it works from above) until you upgrade your OS.
    2. Upgrade your OS soon. You can always check out the Windows 7 free test versions that are available until next spring to tide you over.

    Definitely try updating your BIOS first, though, as I've seen some people say that it works.

  • harrymc

    Your problem is that the first video card is using the same resources that the second video card is requesting. You're probably getting Device Manager error code 12, for which Microsoft counsels to disable the conflicting device.

    You can verify this in the device manager / Display Adapters : right-click on each video card, then Properties and check the Resources tab of both cards for conflict.

    This problem won't be solved by going to Vista 64-bits.
    Some advice I've found when searching:

    1. Update the video driver
    2. Upgrade or downgrade the BIOS (dangerous!)
    3. This might not apply, but BIOS changes to either (a) limit the AGP Aperture to 256MB, or (b) change the video Share Memory size.
    4. Move the video card to another slot, for new resources to be allocated.
    5. In this thread the solution was to edit the boot options by entering

      bcdedit /set CONFIGACCESSPOLICY DISALLOWMMCONFIG
      which can be undone by:
      bcdedit /set CONFIGACCESSPOLICY default

    6. Clean install of the O/S, since resources are allocated during the installation of Windows.

    Needless to say, make sure you have good backups before doing any of the above.

  • Ronald Pottol

    Also, a 32 bit PCI card can only see 2GB of ram, the system has to double buffer it to get the data to the other 2GB of ram. Remember that from your ISA SCSI cards and having more than 16MB?

  • Raynet

    I don't know how much memory your displaycards have, but it is possible (though newer cards should be smart about this and not allocate all their memory directly) that they eat up all the available memory.

    In 32bit Windows your memory address space is divided in two blocks. First block from 0 to 2GB is accessible for you applications. The range from 2GB to 4GB is reserved for the Windows kernel and device memory. All your devices usually require some memory to work and this is mapped into the 2GB - 4GB area. Displaycards also map their internal memory there. If you have 2 cards with 512MB memory in each, that would mean 1GB of that memory would be allocated to their needs. As the video memory on displaycards got bigger, they began to map only part of their memory to that 2GB-4GB area, atleast when running 32bit OS. So that shouldn't usually be a problem.

    I would first try installing latest drivers for all devices and then try to boot with 4GB of RAM. If this doesn't work, upgrading to the latest BIOS might be worth a try, also you could try to go with smaller AGP Aperture -setting in BIOS as Drake suggested. And it never hurts to download Memtest to check that the memory isn't faulty.

    You could also try to enable PAE, that would allow you to use all of your memory. Unfortunately there are some device drivers that won't work with this setting.