Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why it is not possible to use ioremap then remap_pfn_range?

In my driver, I am trying to map an address returned from ioremap to a userspace address.

  1. What kind of an address is returned from ioremap?
  2. How is it different from a kmalloc address ?
  3. How can I map an address returned from ioremap?
  4. Which address should be inserted to remap_pfn_range?
like image 606
shd Avatar asked Jun 24 '13 11:06

shd


People also ask

What is 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.

What does Ioremap return?

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.

What is a Vm_area_struct?

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.


1 Answers

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:

  1. kernel virtual address
  2. kmalloc returns kernel virtual, but guarantees contiguous memory See question 116343
  3. you could do this if you call 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 range
  4. physical address, downshifted by PAGE_SHIFT to produce a pfn
like image 129
Peter Avatar answered Oct 03 '22 22:10

Peter