How to access device in user space via `mmap`

firstly we need to check .config
in Linux if:
1 | CONFIG_STRICT_DEVMEM=y |
or CONFIG_IO_STRICT_DEVMEM=y
, which means to disallow to access device memory. So we need to ensure # CONFIG_IO_STRICT_DEVMEM is not set
1 | int fd = open("/dev/mem", O_RDWR | O_SYNC); |
Here, REG_ADDR
means the address of mapped regitsers, which can be found from /proc/iomem
. Bascially, the effect is the same as ioremap
in kernel space