What information does the resource file under /sys/bus/pci/device/0000:xx:xx.x/resource contain?
Asked Answered
G

2

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
Gabrila answered 15/5, 2014 at 5:27 Comment(3)
I could not get info regarding the resource file so posted the question here.Gabrila
I did some research and this seems to explain it. You should consider doing more research before submitting questions.Fury
No reason to not help the nearly 5000 visitors to this question from wasting time pursuing questionable info and broken links (like yours @Fury - which seems to be here for the moment...) So @Gabrila 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.Wrac
B
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.

Bromic answered 15/5, 2014 at 5:50 Comment(1)
And the flags for the resources are defined (and sort of documented) here.Iva
S
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);
Seclude answered 11/1, 2021 at 18:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.