Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Ajay Garg <ajaygargnsit@gmail.com>
Cc: Keith Busch <kbusch@kernel.org>, linux-pci@vger.kernel.org
Subject: Re: None of the virtual/physical/bus address matches the (base) BAR-0 register
Date: Sun, 3 Oct 2021 12:05:10 -0500	[thread overview]
Message-ID: <20211003170510.GA982214@bhelgaas> (raw)
In-Reply-To: <CAHP4M8XzZCwKk3TGmHKVMdf5mkWKfafE75DEKBs6-t4ZPw-kaw@mail.gmail.com>

On Sun, Oct 03, 2021 at 07:35:41AM +0530, Ajay Garg wrote:
> > Yes.  You should not need to use virt_to_phys() for PCI MMIO
> > addresses.
> 
> Hmm, the thing that started it all :P
> 
> > This path is IN the picture.  This is exactly the path used by drivers
> > doing MMIO accesses.
> >
> > The CPU does a load from a virtual address (0xffffa0c6c02eb000).  The
> > MMU translates that virtual address to a physical address
> > (0xe2c20000).
> 
> Hmm, so I guess the core takeaway is that the virtual-address <=>
> physical-address mapping is indeed happening as envisioned. It's just
> that there is no programmatic way to prove/display the mapped physical
> address, in the case of PCI-MMIO transfers (as virt_to_phys() is not
> usable in this case).

  bar0_ptr = pci_iomap(ptr, 0, pci_resource_len(ptr, 0));

  printk("Base physical-address (form-1) = [%lx]\n", dev->resource[0].start);
  printk("Base physical-address (form-2) = [%lx]\n", virt_to_phys(bar0_ptr));

  Base physical-address (form-1) = [e2c20000]
  Base physical-address (form-2) = [12e6002eb000]

Despite the fact that you shouldn't *need* to use virt_to_phys()
because drivers use virtual addresses to do MMIO, it *does* seem like
form-1 and form-2 should be the same since form-2 is basically the
result of:

  virt_to_phys(ioremap(form-1))

I can't explain the difference.

  reply	other threads:[~2021-10-03 17:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-01 14:51 None of the virtual/physical/bus address matches the (base) BAR-0 register Ajay Garg
2021-10-01 15:13 ` Keith Busch
2021-10-02  4:06   ` Ajay Garg
2021-10-02  7:49     ` Ajay Garg
2021-10-02 15:55     ` Bjorn Helgaas
2021-10-02 17:12       ` Ajay Garg
2021-10-02 19:33         ` Bjorn Helgaas
2021-10-03  2:05           ` Ajay Garg
2021-10-03 17:05             ` Bjorn Helgaas [this message]
2021-10-05  7:32               ` Ajay Garg

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=20211003170510.GA982214@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=ajaygargnsit@gmail.com \
    --cc=kbusch@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /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