Getting the physical address of a user virtual address.

Getting the physical address of a user virtual address.

Post by John Broadhea » Thu, 02 Dec 1999 04:00:00



I have got a memory testing program from Usenet that, with this DIMM,
often fails. I am able to see exactly which virtual address it failed
on, but since the underlying physical address changes every time, I
don't know if it's always failing in the same place.

Is there a system call that will return the physical address if given a
virtual address in the calling process's space?

On a side note, does somewhat faulty memory often fail consistently on
the same address or range of addresses, or can a fault happen on any
address on the chip?

-John

 
 
 

Getting the physical address of a user virtual address.

Post by Friedrich Seifer » Sat, 04 Dec 1999 04:00:00



> I have got a memory testing program from Usenet that, with this DIMM,
> often fails. I am able to see exactly which virtual address it failed
> on, but since the underlying physical address changes every time, I
> don't know if it's always failing in the same place.

> Is there a system call that will return the physical address if given a
> virtual address in the calling process's space?

There is no standard syscall for that. But a simple ioctl implemented
in a character device driver module can do that. It must perform
something
like this:

...
#include <asm/pgtable.h>
...

unsigned long getphys(unsigned long virt_addr)
{
        pte_t *pte_ptr;

        pte_ptr = pte_offset(pmd_offset(pgd_offset(current->mm, virt_addr),
                             virt_addr), virt_addr);
        return = pte_page(*pte_ptr) + (virt_addr & 0x0FFF);

Quote:}

Bye, Friedrich

 
 
 

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;
        else
        {
            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,
vma->vm_page_prot))

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.

Thanks,

Chris Fought

2. PLIP and slirp- how?

3. User virtual address to physical address translation -- how?

4. XF86 3.1 - xinit error

5. virtual address to physical address

6. User authentication module

7. Map physical address to virtual address

8. NNTP Server can not talk to you

9. physical address from virtual address

10. Mapping Kernel Virtual address to Physical address

11. determining the physical address of a given user address

12. "Kernel logical address" vs "Physical address"

13. Direct addressing of physical address