User virtual address to physical address translation -- how?

User virtual address to physical address translation -- how?

Post by James Irw » Sat, 05 Oct 2002 18:53:39


I'd appreciate an early curtailment of my need to turn user virtual
addresses to physical addresses (from withing a driver module).  My
assumptions and searches have mounted to the following:

1) User virtual addresses != kernel virtual addresses (no prizes)
2) __va() & __pa() are dumb macros for kernel/physical address
3) copy_to_user() and friends are written in assembler so I'm kind of
knackered with them. Unless I have a decade of free time.
4) I assume that the user pages are swapped in (using a machine with
no disk, let alone swap).

For additional bonus trivia:
o) I'm running some 2.2.1 kernel on a MIPS (playstation) for this test
but will ultimately be running on a diskless set-top-box with a
2.4.current kernel.

I saw something in a real old post about current->mm, and will have to
read a pile more on this.  I have the Rubini book and will have a look
at what this is.  Hopffully it'll provide me with a VMA struct that I
can use to knab out the page descriptor for the user VM and then do
the kernel __pa() translation for each page in teh VMA.

If you know a solution, a pointer to a website, some good structures
available from within kernel space, whatever, I'd appreciate it.


[James dot Irwin at zarlink dot com dot no dot spamming dot please]


User virtual address to physical address translation -- how?

Post by Robert Kais » Tue, 08 Oct 2002 17:59:39

Quote:> If you know a solution, a pointer to a website, some good structures
> available from within kernel space, whatever, I'd appreciate it.

Maybe this is of interest for you:

The patch you'll find there contains (among other things)
routines to translate user-space virtual addresses into
physical ones. Keep in mind that virtually contiguous user-space
memory is typically scattered physically and that you have
to lock down the pages or else the OS may swap them out or
change the mapping at any time.



Robert Kaiser                     email: rkaiser AT sysgo DOT de
SYSGO RTS GmbH          
Klein-Winternheim / Germany


1. YDL 1.2 Synergy VGM5 Virtual Address, Physical Address, Bus Address and remap_page_range (HELP!)

I am currently developing a kernel module to communicate with a PCI memory
device and I have run into a few problems.

1. How do I determine the physical address of my PCI device? I did examine
the IO-mapping.txt file in /usr/scr/linux and it states the following is
true for Power PC:

Physical Address: 0x0
Virtual Memory Address: 0xC0000000
Bus Address 0x80000000

Using lspci -v I find that the bus address of my device is as follows:
memory at 0xF0042100 non-prefectable
memory at 0xF1000000 prefetchable
memory at 0xF2000000 prefetchable

So how do I figure out the physical address for the bus address 0XF1000000
do I just subtract/add 0x80000000 to get the address?

2. I need the physical address because I am trying to obtain it to pass into
remap_page_range() (I need to map all of the memory from my PCI device into
kernel memory and then pass a pointer from the kernel to user space. I tried
using the value of 0x71000000 (which I obtained by subtracting 0x80000000
from 0xF1000000 and it doesn't work:
User mode application:

if( (fd = open( SCR_INT_DEV, O_RDWR )) == -1 )
             rvalue = DEVICE_ERROR;
            paddr = mmap( 0, 0x80000, prot, mmap_flags, fd, 0 );
            if( (int)paddr == -1 )
                rvalue = MAP_ERROR;

(mmap entry point in kernel module)

static int pci_mmap(struct file * file, struct vm_area_struct * vma)
 physical += vma->vm_offset;
  mapped_mem = vma->vm_end - vma->vm_start;

if (remap_page_range(vma->vm_start, 0x71000000, mapped_mem,

This works fine on a Linux 2.2.18 distribution running on an X86 (I
understand that on the Power PC that Phy addr and bus addr aren't the same)

I realize that this is a non-portable way of accessing memory, but our API
requires that it receive a user pointer to directly access memory from our
card. Can anyone please help me or point me to information that might help
me to solve the problem.


Chris Fought

2. Whereis "as86"? Kernel won't build without it!

3. Getting the physical address of a user virtual address.

4. SunRiver equipment

5. Virtual to Physical address translation

6. Still having problems with NIS+ (or so I think)

7. Virtual to Physical Address Translation

8. IEEE 488 / GP-IB / HP-IB ?

9. virtual address to physical address

10. Map physical address to virtual address

11. physical address from virtual address

12. Mapping Kernel Virtual address to Physical address

13. HELP: translation between user address and kernel address