Why is it impossible to use ioremap and then remap_pfn_range?

In my driver, I am trying to map the address returned from ioremap to the user space address.

  • What address is returned from ioremap ?
  • How is it different from kmalloc ?
  • How can I match the address returned from ioremap ?
  • What address should be inserted in remap_pfn_range ?
+4
source share
2 answers

You do not need ioremap() if you use remap_pfn_range() . ioremap() maps the physical address to the virtual address of the kernel. remap_pfn_range() maps physical addresses directly to user space. Just pass your physical address (down to PAGE_SHIFT to create pfn) directly to remap_pfn_range() . Your questions are in order:

  • virtual kernel address
  • kmalloc returns the kernel virtual but guarantees continuous memory See question 116343
  • you could do this if you first call virt_to_phys() to convert the virtual address of the kernel to physical. But skip the step if you really don't need access to this memory range.
  • physical address, downcast on PAGE_SHIFT to create pfn
+5
source

ioremap() returns the virtual address of the kernel space. This cannot be obtained directly from user space. There is a mechanism called mmap (), here, and mapping physical addresses to a virtual linux address for a working sample.

0
source

Source: https://habr.com/ru/post/1487873/


All Articles