1

I want to map PCIe Memory mapped config space into the user space. I am trying to use mmap system call to map the MMCONFIG physical address into the user space. I did some search but not able to figure out what to populate in the fd parameter in-order to do the correct mapping.

mmap system call : void mmap(void addr, size_t length, int prot, int flags, int fd, off_t offset);

Physical address from /proc/iomem : e0000000-efffffff : PCI MMCONFIG 0000 [bus 00-ff]

I could access PCIe enhanced configuration space using port 0xcfc & 0xcf8 but i want to achieve the same by mapping physical address into user space.

Thanks in advance

System: RHEL / x86_64

Usr1
  • 369
  • 1
  • 6
  • 15

1 Answers1

2

mmap creates a mapping of a file in the address space of your application. You have the address you want to map to, the length you want to read, flags etc... and you need to specify which file you want to map to, and this is the fd argument.

You have the /dev/mem file that gives you access to physical memory from user space, so you can open() it and use the returned fd to read the data at the desired physical address.

However, I'm pretty sure that there is a kconfig thing called CONFIG_STRICT_DEVMEM that disables /dev/mem (let's you read only the first 1mb or so) that is the default setting on modern RHEL systems if I remember correctly, so you better make sure you can actually use it.

LITzman
  • 730
  • 1
  • 16
  • So if i understand correctly, /dev/mem also contains MMIO/MMCFG mapping ? So in that case i should pass fd as /dev/mem and offset should be 0xe0000000 ? To target PCI MMCONFIG – Usr1 Jul 16 '23 at 13:09
  • `fd` is the file descriptor of `/dev/mem`. If you can elaborate about what you are trying to do, maybe someone can suggest a more eleagant solution... – LITzman Jul 16 '23 at 13:41
  • I want to access (read) pci config space From user space which is mapped to e0000000-efffffff in systems memory map. – Usr1 Jul 16 '23 at 14:05
  • 2
    I think that this should do. however, there is the `lspci` which already implements this (-xxxx I think). you can check out the source or use it if you want – LITzman Jul 16 '23 at 15:12