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?