virtual address to physical address

virtual address to physical address

Post by David L » Thu, 03 Jul 1997 04:00:00



Hi, there,

I am wondering that is there any existing system call that translates
the virtual memory address to physical memory address in user process.  
Do I need to parse the page directory, page table and etc., if i want to
do so in case I have to write a system call for that purpose.

-- David

 
 
 

virtual address to physical address

Post by Marc Lefran » Fri, 04 Jul 1997 04:00:00



> Hi, there,

> I am wondering that is there any existing system call that translates
> the virtual memory address to physical memory address in user process.  
> Do I need to parse the page directory, page table and etc., if i want to
> do so in case I have to write a system call for that purpose.

> -- David

I picked the following function in a post by Ingo Molnar some time
ago. It however works only in kernel mode, could be used to write
a new system call, but IMO its natural place would be in a driver to
control bus mastering transfers

static unsigned long generic_virt_to_phys(volatile void * address)
{
       pgd_t * pgd;
       pmd_t * pmd;
       pte_t * pte;

       pgd = pgd_offset(current->mm, (unsigned long)address);
       pmd = pmd_offset(pgd, (unsigned long)address);
       pte = pte_offset(pmd, (unsigned long)address);

       return (unsigned long) ( ( pte_page(*pte) +
               (((unsigned long)address)&(PAGE_SIZE-1))) & ~PAGE_OFFSET);

Quote:}

This is a portable version.

/* unsigned long portable(void * adress) */
/* { */
/*     return virt_to_bus(phys_to_virt(generic_virt_to_phys(addr))); */
/* } */

--
_____________________________________________________________
 Marc Lefranc, Charge de Recherche au CNRS
 Laboratoire de Spectroscopie Hertzienne (URA CNRS 249)
 Bat P5, UFR de Physique
 Universite des Sciences et Technologies de Lille
 F-59655 Villeneuve d'Ascq CEDEX (FRANCE)

_____________________________________________________________

 
 
 

virtual address to physical address

Post by David L » Sat, 05 Jul 1997 04:00:00


: I picked the following function in a post by Ingo Molnar some time
: ago. It however works only in kernel mode, could be used to write
: a new system call, but IMO its natural place would be in a driver to
: control bus mastering transfers

        That's exactly what i am trying to do.  Thanks a lot I think it
        is very helpful.

        -- David

 
 
 

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

Hiya,

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
traslation.
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.

TIA

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

2. Help! g++ can't compile

3. Mapping Kernel Virtual address to Physical address

4. One more question about curses...

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

6. How to create a CD image

7. Map physical address to virtual address

8. Java on Linux help!

9. physical address from virtual address

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

11. "Kernel logical address" vs "Physical address"

12. Direct addressing of physical address

13. determining the physical address of a given user address