Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

pci

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
like image 898
lokesharo Avatar asked May 15 '14 05:05

lokesharo


2 Answers

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.

like image 200
Grapsus Avatar answered Oct 29 '22 17:10

Grapsus


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);
like image 36
Delus Avatar answered Oct 29 '22 16:10

Delus