I have a userspace application that I use to write to the registers of a pci device. It takes the base memory address of the device as an argument. Instead of looking this up via lspci
on each platform, I wanted to write a bash script to use the vendor/device id's to look up the base address and call the application instead.
Lets use an Intel network controller with device ID of `0891' as example. This is on a Ubuntu box, but I need it to work across different Linux distributions.
I thought of just parsing the output of lspci
with something like this:
lspci -vn | grep -A 3 0891 | grep Memory | awk '{print $3}'
which produces:
f0500000
But I'm interested in getting the base address from somewhere in the file system, rather than relying on another application, so I tried:
cat /proc/bus/pci/devices | grep 0891 | awk '{print $4}'
This produces:
f0500004
Why is the second value offset by 4 bytes?
Bonus question: Where can I get PCI device base memory addresses from that will work across distributions without relying on other applications such as lspci?