In my driver, I am trying to map an address returned from ioremap
to a userspace address.
ioremap
?kmalloc
address ?ioremap
?remap_pfn_range
?remap_pfn_range() maps physical memory (by means of kernel logical address) to a user space process. It is particularly useful for implementing the mmap() system call.
A successful call to ioremap() returns a kernel virtual address corresponding to start of the requested physical address range. This address is not normally meant to be dereferenced directly, though, for a number of (often architecture-specific) reasons.
The vm_area_struct structure describes a single memory area over a contiguous interval in a given address space. The kernel treats each memory area as a unique memory object. Each memory area shares certain properties, such as permissions and a set of associated operations.
You don't need ioremap()
if you're using remap_pfn_range()
. ioremap()
maps a physical address into a kernel virtual address. remap_pfn_range()
maps physical addresses directly to user space. Just pass your physical address (downshifted by PAGE_SHIFT to produce a pfn) directly to remap_pfn_range()
. Your questions in order:
virt_to_phys()
first, to convert kernel virtual address to physical. But skip a step if you don't actually need kernel access to this memory rangeIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With