4

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?

Tanner
  • 141
  • 1
  • 7

1 Answers1

2

From what I can determine the format of 0x????0004 communicates some additional information. Bit 2 indicates that the BAR is a 1=64-bit, 0=32-bit address, bit 3 indicates that memory region is 1=prefetchable, 0=non-prefetchable.

S. Ramberg
  • 36
  • 3