How to get the physical address with Bus, Device, Function, and Offset

Viewed 1269

I want to make a kernel module that read the DRAM counters to get the number of data read from DRAM (https://software.intel.com/en-us/articles/monitoring-integrated-memory-controller-requests-in-the-2nd-3rd-and-4th-generation-intel).

In that page, they say

"The BAR is available (in PCI configuration space) at Bus 0; Device 0; Function 0; Offset 048H", and UNC_IMC_DRAM_DATA_READS, which I want to read, is on "BAR + 0x5050".

Does it mean that I can get the physical address of DRAM Counter by typing

    sudo setpci 00:00:0 48.L 

and then + 0x5050 to get the address where the UNC_IMC_DRAM_DATA_READS?

Actually,

    sudo setpci 00:00:0 48.L

outputs

    fed10001

, and I accessed 0xfed15051 with busybox.

    sudo busybox devmem 0xfed15051

However, the two leftmost bit, I mean "00" in 0x00123456, are always zero.

What was wrong, and how can I get the physical address correctly with Bus, Device, Function, and Offset.

Thank you :)

1 Answers

The low bit is an enable bit and should be excluded from the address you use. See for example https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/xeon-e3-1200v6-vol-2-datasheet.pdf (section 3.12 page # 57) -- where it's documented as the MCHBAREN flag.

This document also provides detailed register descriptions of the same registers mentioned in that tech note -- starting at section 7.43 page # 202.

In general, accesses to PCI registers are pretty much always done on 32-bit (DWORD) boundaries. You'll almost never find a counter that overlaps 32-bit words.

Related