[lkml]   [2003]   [Dec]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: Physical address
On Mon, Dec 08, 2003 at 04:07:13PM +0100, moi toi wrote:
> Does that mean that the functions virt_to_phys and
> virt_to_bus don't work on virtual addresses? Does anyone know, how to
> get the real physical address of the buffer.

Linux assumes 1:1 mapping of kernel virtual addresses, with various

virt_to_bus() and virt_to_phys() only work on that statically mapped
area's virtual addreses.

ioremap() dynamically establishes translations for the areas, and
the virtual addresses returned by it are not valid to resolve to
physical addresses with virt_to_bus() and virt_to_phys().

Probably the best way to find the physical address is by a direct
pagetable lookup. Something like the following (untested) may be of use:

static dma_addr_t ioremap_to_phys(unsigned long vaddr)
pgd_t *pgd;
pmd_t *pmd;
pte_t *pte;

pgd = pgd_offset_k(vaddr);
if (!pgd_present(*pgd))
return 0;
pmd = pmd_offset(pgd, vaddr);
if (!pmd_present(*pmd))
return 0;
pte = pte_offset_kernel(pmd, vaddr);
if (!pte_present(*pte))
return 0;
return ((dma_addr_t)pte_pfn(*pte) << PAGE_SHIFT) | (addr & ~PAGE_MASK);

-- wli
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:59    [W:0.044 / U:0.108 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site