shd
shd

Reputation: 1129

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?

Upvotes: 6

Views: 5819

Answers (2)

Peter
Peter

Reputation: 14937

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

Upvotes: 10

Jeyaram
Jeyaram

Reputation: 9474

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.

Upvotes: 0

Related Questions