Skip to content
Advertisement

how to return a phys_addr_t type value to user space

I need my driver to return phys_addr_t type value through an ioctl call. I need to return this value through a struct which is passed through arg. The question is what type do I use in this struct?

For example, say the following struct is passed through an arg

struct myStruct {
  int input1;
  char input2;
  <type> physAddr;
} ;


someStruct.physAddr = virt_to_phys(virtAddr);

virt_to_phys returns a phys_addr_t, however this type doesn’t seem to exist in any of the standard includes. So my question is what type do I need to use in user space for phys_addr_t?

Advertisement

Answer

Under the full kernel source, in include/linux/types.h we have:

#ifdef CONFIG_PHYS_ADDR_T_64BIT
typedef u64 phys_addr_t;
#else
typedef u32 phys_addr_t;
#endif

So, to be safe, just use u64.

Note that this definition is removed from /usr/include/linux/types.h.

However, if you are writing a custom utility that interacts with a custom device and its custom driver, it is okay to skip the /usr/include versions and build directly against the version in (e.g.) /usr/src/kernel/...).

This is not recommended for regular programs [of course]. But, if you are doing a hybrid system that has a lot of things going between the utility and the driver, you can craft it any way you’d like.

For example, a realtime hidef video encoding platform I wrote code for did this. The driver sent data to the device. The device sent data back. The data was sent to the utility/control program which modified the data and sent it back, etc. This was all done with a lot of custom ioctl calls, so we could do whatever was required.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement