2

In linux kernel. I get a reg [phy_addr], and do ioremap(), get [vir_addr], when i want to get val of this reg, What's the difference between readl() and *?

u32 value;

phys_addr_t phy_addr = 0x12345678; // it is reg addr

void *vir_addr = ioremap(phy_addr, sizeof(u32));

val = readl(vir_addr);
val = *(u32 *)vir_addr;
4
  • 4
    Goal of readl() (and friends) is to ensure that access to a memory-mapped register is properly treated as an I/O operation rather than just a basic RAM access. Study makelinux.net/ldd3/chp-9-sect-1.shtml Commented Jan 19, 2024 at 4:52
  • 2
    One difference is that readw()/readl()/writew()/writel() and friends assume the hardware registers being accessed use little-endian byte order, and the functions convert the values to/from the CPU's native byte order. Commented Jan 19, 2024 at 16:52
  • 1
    @IanAbbott, not only, the readl() might take care about alignment, while * is violating that on some architectures. Commented Jan 19, 2024 at 17:00
  • Does this answer your question? What is the benefit of calling ioread functions when using memory mapped IO Commented Feb 9, 2024 at 0:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.