linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: William Lee Irwin III <wli@holomorphy.com>
To: moi toi <mikemaster_f@yahoo.fr>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Physical address
Date: Mon, 8 Dec 2003 07:23:33 -0800	[thread overview]
Message-ID: <20031208152333.GU19856@holomorphy.com> (raw)
In-Reply-To: <20031208150713.39743.qmail@web25201.mail.ukl.yahoo.com>

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

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

  reply	other threads:[~2003-12-08 15:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-08 15:07 Physical address moi toi
2003-12-08 15:23 ` William Lee Irwin III [this message]
2003-12-08 15:42 ` Richard B. Johnson
2003-12-08 16:05   ` Matthias Urlichs
2003-12-09 16:04 ` Jesper Juhl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031208152333.GU19856@holomorphy.com \
    --to=wli@holomorphy.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikemaster_f@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).