6

I am doing a project to read the registers of the device from the pci configuration space and for that I need to mmap the space, for this I have to read the resource file. But what data this file contains. By looking at it, it looks to save some sort of addresses. I searched and read somewhere these are BAR's but there are only max of 6 BAR's so what are the other fields? The file contents are :

0x000000000000fc00 0x000000000000fcff 0x0000000000020101
0x00000000dcff0000 0x00000000dcffffff 0x0000000000120204
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000dcf80000 0x00000000dcfbffff 0x0000000000120204
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000dc000000 0x00000000dc0fffff 0x0000000000027200
0x00000000dc500000 0x00000000dc5fffff 0x0000000000120204
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000dc100000 0x00000000dc4fffff 0x0000000000120204
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
Lee Duhem
  • 14,695
  • 3
  • 29
  • 47
lokesharo
  • 305
  • 2
  • 11
  • 1
    I could not get info regarding the resource file so posted the question here. – lokesharo May 15 '14 at 05:31
  • **I** did some research and [this](http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi?coll=linux&db=bks&srch=&fname=/SGI_Developer/REACTLINUX_PG/sgi_html/ch07.html) seems to explain it. You should consider doing more research before submitting questions. – Theolodis May 15 '14 at 05:38
  • 6
    No reason to not help the nearly 5000 visitors to this question from wasting time pursuing questionable info and broken links (like yours @Theolodis - which seems to be [here](https://techpubs.jurassic.nl/manuals/linux/developer/REACTLINUX_PG/sgi_html/ch07.html) for the moment...) So @lokesharo it looks as though each line of the `resource` file describes a Region with start, end, and flag fields. Why there are more than 6? It seems holes can form in bars due to conflicts. I understand moving a PCI card to another slot can affect what you may be seeing here. – duanev Feb 21 '19 at 21:08

2 Answers2

6

These special files are documented in Documentation/filesystems/sysfs-pci.txt.

The resource file contains host addresses of PCI resources. Then you have resource1, resource2 etc. files with each region's contents. Those can be mmaped.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
Grapsus
  • 2,714
  • 15
  • 14
  • And the flags for the resources are defined (and sort of documented) [here](https://elixir.bootlin.com/linux/latest/source/include/linux/ioport.h). – Eugene Ryabtsev Aug 22 '23 at 09:03
2

I know this is an old question but my googling brought me here too and I didn't realize it was answered at first, @duanev seems to be correct. The relevant code can be found in resource_show(...) in pci-sysfs.c

struct resource *res =  &pci_dev->resource[i];
pci_resource_to_user(pci_dev, i, res, &start, &end);
str += sprintf(str, "0x%016llx 0x%016llx 0x%016llx\n",
           (unsigned long long)start,
           (unsigned long long)end,
           (unsigned long long)res->flags);
Delus
  • 196
  • 2
  • 6