I am currently going through Linux Device Drivers book and found the functions for reading from I/O memory:
To read from I/O memory, use one of the following:
unsigned int ioread8(void *addr);
unsigned int ioread16(void *addr);
unsigned int ioread32(void *addr);
If you must read or write a series of values to a given I/O memory address, you can use the repeating versions of the functions:
void ioread8_rep(void *addr, void *buf, unsigned long count);
void ioread16_rep(void *addr, void *buf, unsigned long count);
void ioread32_rep(void *addr, void *buf, unsigned long count);
These functions read or writecount
values from the givenbuf
to the givenaddr
. Note thatcount
is expressed in the size of the data being written;ioread32_rep
readscount
32-bit values starting atbuf
.
I used ioread64()
and iowrite64()
in a driver code for reading and writing to a memory-mapped IO register (8 bytes). iowrite64()
works but iowrite64()
function never returns and my virtual machine (QEMU) froze - all I could do was to restart. I used GDB to debug remotely but no error messages shown. By checking dmesg on host machine, no error message shown either. For more detailed information, please refer to this question.
Since I cannot find a way to figure out why ioread64()
failed, I thought I may use ioread32_rep()
instead.
By searching through the kernel driver code, I noticed that most of the use cases of ioread32_rep()
are some buffers within the device (e.g. those network devices which handle streaming data). If I could use ioread32_rep()
to replace ioread64()
for merely reading an 8-byte memory mapped register, would that be appropriate?
Any ideas would be appreciated.