1

I use mmap to access on a pci device but I have some doubts.

1) Seeing various examples about pci device access I noticed that in same cases the mmap is execute with the /dev/mem file like this

if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) PRINT_ERROR; map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target_base);

and in other cases with the pci device descriptor like this

if((fd = open("file /sys/devices/pci0001:00/0001:00:07.0/resource0", O_RDWR | O_SYNC)) == -1) PRINT_ERROR; map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target_base);

What is the difference?

2) In a mine embedded device I don't have the /dev/mem file. Why? Depends on how the kernel was compiled?

I tried to manually create one with this command

mknod -m 660 /dev/mem c 1 1 chown root:kmem /dev/mem;

but the mmap command not works. How can I solve?

FBGenesy
  • 39
  • 2
  • "not works" - what error? Taking the `/sys/devices...` path looks preferable (ref; https://stackoverflow.com/questions/40395221/pci-e-memory-space-access-with-mmap), What does `lspci -v` show for this device? – danblack Jan 31 '19 at 00:23
  • I use the pcimem program that you can find here [link](https://github.com/billfarrow/pcimem). When execute the mmap command, it return a generic error "Invalid argument". I tried to change pci_mem parameters but actually the only argument that is affected is sys_file that is correctly opened previously. The sys_file correspond to a pci ethernet adapter inside the pc that have 2 memory region. – FBGenesy Jan 31 '19 at 17:23

0 Answers0