6

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?
Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79
shd
  • 1,201
  • 4
  • 17
  • 29

2 Answers2

10

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
Community
  • 1
  • 1
Peter
  • 14,559
  • 35
  • 55
0

ioremap() returns the kernel space virtual address. This can't be accessed directly from user space. There is mechanism called mmap(), refer here and Mapping physical addresses to virtual address linux for working sample.

Community
  • 1
  • 1
Jeyaram
  • 9,158
  • 7
  • 41
  • 63