Hi,
the original topic of this discussion was how to map vmallocated
memory into user space.
The clue is, that vmalloc creates an own memory area, such addresses
cannot be used for translation to physical addresses with virt_to_phys.
The following code translates a general, kernel virtual address
into a kernel segement virtual address (an address with a 1:1
virtual to physical mapping, that can be feed into virt_to_phys).
A complete example of a device driver using that can be found
at:
http://www.scs.ch/~frey/linux/
/* Converts a kernel virtual address into a kernel virtual
address that is part of the direct mapping between
virtual and physical address. If you e.g. allocated
memory with vmalloc(), you get virtual addresses part
of an own area. By converting such an address,
you receive a kernel virtual address that you can
e.g. feed into virt_to_phys() or MAP_NR().
Note: the function below works for one page. If you
have a set of pages, in a vmalloc allocated area,
each page may have a different virtual address in
the direct mapping.
*/
volatile void *virt_to_kseg(volatile void *address)
{
pte_t *pte;
/* if we are below the max direct mappings, we use the
direct conversion function
*/
if (MAP_NR(address) < max_mapnr)
return(address);
/* else we really have to parse the page table to get the map nr */
pte = pte_offset(pmd_offset(pgd_offset_k((unsigned long)address), (unsigned long)address), (unsigned long)address);
return((volatile void *)pte_page(*pte));
}
Thanks for all the help of you to nail that mapping down.
Martin Frey
-- Supercomputing Systems AG email: frey@scs.ch Martin Frey www: http://www.scs.ch/~frey Technoparkstrasse 1 phone: +41 (0)1 445 16 00 CH-8005 Zurich fax: +41 (0)1 445 16 10- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Fri Jun 23 2000 - 21:00:17 EST