-
Notifications
You must be signed in to change notification settings - Fork 13
Notes
-
The original devmem does atomic reads and writes, if the address is properly aligned. This is what we want to access hardware registers.
-
However, they always do a read, even if the command specifies write. This is bad. Device registers are tricky, reads may be destructive. So we've removed the read issue #2.
-
Apropos of atomic access: the original code does nothing special for that, no any acquire-release stuff. It just works because there are no concurrent threads.
-
Also there's no special support for advanced PCI/PCIe operations like locked ops, atomic ops, RMW transactions etc.
-
Cached or non-cached memory (and other fancy attributes): the "owner" of the memory region is responsible for mmap'ping in correct mode.
-
Flush after write: we don't care. The kernel (or whatever is responsible for /dev/mem) should flush memory on munmap (explicit or automatic).
- A read after write may help with this, so we've added a switch to do read-back after write. Anyway, the I/O memory we need to access should be always mapped in non-cached mode.
-
Protection against errors and misuse: The /dev/mem device is available only if allowed in the kernel config. Even if available, it does not let access any location - only I/O memory, only if its owner (some kernel driver) has not prohibited it. In kernel config, CONFIG_DEVMEM enables /dev/mem file; CONFIG_STRICT_DEVMEM enables restrictions (only I/O memory, etc). See linux/drivers/char/mem.c
-
Q: Should normal reads/writes be used instead of mmap on /dev/mem? A: No, mmap is the way. Reads/writes are deprecated (see kernel src.)
- buildroot.net - one of sources of the orig. devmem.
- https://github.com/VCTLabs/devmem2 - Original with some fixes (a makefile, prinf formats ... ). This is what we cloned.
- https://github.com/mansr/devmem3 - several devmem-like utilities, has good things that we need - but not backwards compatible.
- https://github.com/BenGardiner/uiomem3 - uses /dev/uioN instead of /dev/mem. Interesting, we could do this with /sys/bus/pci...
- https://github.com/radii/devmem2 - clone (nonactive, at the moment of writing this)
- https://github.com/tomxuetoy/Linux_devmem2 - clone
- https://github.com/xin3liang/devmem2 - clone