-
Notifications
You must be signed in to change notification settings - Fork 14
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 may be bad, or not. Some of our registers are write-only, I don't know how they would react to read. Made issue #2.
-
Apropos of atomic access: the original code does nothing special for atomicity, no any acquire-release stuff. It just works because there are no concurrent threads. If a flush after write is needed on some weird architecture, it will occur automatically when the mapping is undone. A read after write may help with this, so we'll add a switch to do read-back after write. Anyway, the I/O memory we need to access must be always mapped in non-cached mode.
-
Flush after write: same as atomic access. Not needed; kernel (or the thing responsible for /dev/mem) should flush memory on munmap (explicit or automatic).
-
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 reads/writes be used instead of mmap on /dev/mem? A: No, mmap is the way. Reads/writes are deprecated.
- bildroot.net
- 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