Hi,
You got some sort of PCI device and you have to write to the address specified in one of the BARs. This address might not exist (i.e. the address is located at 0xde000000 but you have less memory then that). Is it possible then to map that address to virtual memory so you can still configure the PCI device, or isn't that accepted by the PCI device?
Greets,
Bietje
[FIXED] PCI config space
[FIXED] PCI config space
Last edited by Bietje on Thu Nov 03, 2011 9:30 am, edited 1 time in total.
Re: PCI config space
The term "memory-mapped IO" means that memory of the device is mapped into the address space. I.e., it has nothing to do with the amount of RAM you have installed.Bietje wrote:...located at 0xde000000 but you have less memory then that...
Every good solution is obvious once you've found it.
Re: PCI config space
Meaning that mapping the memory address to a virtual address to write/read from it doesn't matter?Solar wrote:The term "memory-mapped IO" means that memory of the device is mapped into the address space. I.e., it has nothing to do with the amount of RAM you have installed.Bietje wrote:...located at 0xde000000 but you have less memory then that...
-
- Member
- Posts: 223
- Joined: Thu Jul 05, 2007 8:58 am
Re: PCI config space
It means that read/writes to the physical address specified in the BAR are send to the device. Whatever paging does on top of that is of no interest to the device.
Re: PCI config space
Hmm oke
There is some read/write register at some address specified by the BAR (MSI-X address register), writing a value (say 0xff) to that address and reading it back returns 0 when the address is mapped 1:1. So how can I read back the correct value from memory mapped I/O?
Greets,
Bietje
ps:
what I did:
So bar is the address specified by the BAR and the output is 0.
There is some read/write register at some address specified by the BAR (MSI-X address register), writing a value (say 0xff) to that address and reading it back returns 0 when the address is mapped 1:1. So how can I read back the correct value from memory mapped I/O?
Greets,
Bietje
ps:
what I did:
Code: Select all
uint32_t *bar = get_bar_value(0x20);
*bar = 0xff
printf("%x\n", *bar);
Re: PCI config space
What would be the "correct" value you expected?Bietje wrote:So how can I read back the correct value from memory mapped I/O?
Edit: I get the impression that you are feeling your way in the dark, unaware of what is actually going on or what the BAR is meant to be. Please tell me if I'm wrong.
Every good solution is obvious once you've found it.
Re: PCI config space
With correct I mean that when I do a memory write towards the memory mapped address that the value is stored/saved there, and when I read back the location that the value is returned. Although, I thought that was correct since the space is read/write according to the PCI (3.0) specification.Solar wrote:What would be the "correct" value you expected?Bietje wrote:So how can I read back the correct value from memory mapped I/O?
Edit: I get the impression that you are feeling your way in the dark, unaware of what is actually going on or what the BAR is meant to be. Please tell me if I'm wrong.
Re: PCI config space
...which is true for RAM, but might be a completely different thing if what you are writing to is a device register. I'm out on a limb here since I never wrote PCI drivers myself, but as far as I understood it, the BAR contents merely tell you where the device's memory is. What it is, and what writing 0x000000ff to offset 0x20 (as you did) means to the device, is up to the device, and should be looked up in its technical documentation. Perhaps your 0x000000ff@0x20 asked a SATA controller to tell you how many SATA devices are connected to it, and the 0x00000000 you got in reply is the answer (zero). Perhaps you just told your GPU to go into suspend mode, and it told you that it could not. I don't know.Bietje wrote:With correct I mean that when I do a memory write towards the memory mapped address that the value is stored/saved there, and when I read back the location that the value is returned...Solar wrote:What would be the "correct" value you expected?
Perhaps I am pointing out the obvious to you and am making a fool of myself. I don't know that either. It's hard to tell from the information you gave so far.
Every good solution is obvious once you've found it.
Re: PCI config space
My stupidity...
Greets,
Bietje
That fixed allot... Thread wasn't completely useless it clarified some other things as well, thanks!PCI Specification wrote:When you want to retrieve the actual base address of a BAR, be sure to mask the lower bits. For 16-Bit Memory Space BARs, you calculate (BAR[x] & 0xFFF0). For 32-Bit Memory Space BARs, you calculate (BAR[x] & 0xFFFFFFF0). For 64-Bit Memory Space BARs, you calculate ((BAR[x] & 0xFFFFFFF0) + ((BAR[x+1] & 0xFFFFFFFF) << 32)) For I/O Space BARs, you calculate (BAR[x] & 0xFFFFFFFC).
Greets,
Bietje