In the Getting access to I/O memory recipe in Chapter 6, Miscellaneous Kernel Internals, we saw how the MMU works and how we can get access to a memory-mapped peripheral. Within the kernel space, we must instruct the MMU in order to correctly translate a virtual address into a proper one, which must point to a well-defined physical address to which our peripheral belongs, otherwise, we can't control it!
On the other hand, in that section, we also used a userspace tool named devmem2, which can be used to get access to a physical address from the user space, using the mmap() system call. This system call is really interesting, because it allows us to do a lot of useful things, so let's start by taking a look at its man page (man 2 mmap):
NAME
mmap, munmap - map or unmap files or devices into memory
SYNOPSIS
#include <sys/mman.h>...