0
votes

I found belows code in linux kerel code at http://lxr.free-electrons.com/source/arch/arm/include/asm/io.h?v=3.1;a=arm

#define __raw_readl(a)          (__chk_io_ptr(a), *(volatile unsigned int __force   *)(a))

I am unable to understand it. How does it work. I know it used to read some bytes from mapped device memory but can not understand how does it work?

1

1 Answers

1
votes

It seems to work the following way:

  1. Call the __chk_io_ptr(a) in order to check the memory available
  2. Read unsigned int from memory by dereferencing the pointer.

I suppose you use this macro the following way:

unsigned int data = __raw_readl(a);

By preprocessor it is replaced by:

unsigned int data =  (__chk_io_ptr(a), *(volatile unsigned int __force   *)(a));

So as result of the comma operator in data stored unsigned long value pointed by a.

EDIT: The __chk_io_ptr(a) seems to be a macro in accordance to this.

#define __chk_io_ptr(x) (void)0

That actually does nothing.