qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>, patches@linaro.org
Subject: [Qemu-devel] [RFC 1/2] hw/pci: Add PCI capability to allow BARs at 0
Date: Thu, 22 Aug 2013 19:28:11 +0100	[thread overview]
Message-ID: <1377196092-7482-2-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1377196092-7482-1-git-send-email-peter.maydell@linaro.org>

The PCI specification says that 0 isn't a valid address
for an MMIO bar. However some devices won't object if you
program a BAR at address 0 and will then respond to bus
accesses at that address. (In particular the host
PCI controller for the Versatile/Realview boards behaves
like this, and Linux relies on it for setting up a 1:1
mapping between PCI address space and system address
space for bus-mastering DMA.)

To allow us to model devices with this out-of-spec
quirk, add a new QEMU_PCI_ADDR0_ALLOWED flag to
cap_present which bypasses the "address 0 is not valid"
test in pci_bar_address().

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/pci/pci.c         |    3 ++-
 include/hw/pci/pci.h |    3 +++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 4c004f5..f09d799 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1058,7 +1058,8 @@ static pcibus_t pci_bar_address(PCIDevice *d,
     /* XXX: as we cannot support really dynamic
        mappings, we handle specific values as invalid
        mappings. */
-    if (last_addr <= new_addr || new_addr == 0 ||
+    if (last_addr <= new_addr ||
+        (new_addr == 0 && !(d->cap_present & QEMU_PCI_ADDR0_ALLOWED)) ||
         last_addr == PCI_BAR_UNMAPPED) {
         return PCI_BAR_UNMAPPED;
     }
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index ccec2ba..3d6a940 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -157,6 +157,9 @@ enum {
     QEMU_PCI_CAP_SHPC = (1 << QEMU_PCI_SHPC_BITNR),
 #define QEMU_PCI_SLOTID_BITNR 6
     QEMU_PCI_CAP_SLOTID = (1 << QEMU_PCI_SLOTID_BITNR),
+    /* PCI device (in breach of the spec) allows MMIO BAR at address 0 */
+#define QEMU_PCI_ADDR0_ALLOWED_BITNR 7
+    QEMU_PCI_ADDR0_ALLOWED = (1 << QEMU_PCI_ADDR0_ALLOWED_BITNR)
 };
 
 #define TYPE_PCI_DEVICE "pci-device"
-- 
1.7.9.5

  reply	other threads:[~2013-08-22 18:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 18:28 [Qemu-devel] [RFC 0/2] Implement versatile PCI IMAP registers Peter Maydell
2013-08-22 18:28 ` Peter Maydell [this message]
2013-08-22 18:28 ` [Qemu-devel] [RFC 2/2] hw/pci-host/versatile: Implement " Peter Maydell

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=1377196092-7482-2-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=mst@redhat.com \
    --cc=patches@linaro.org \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).