qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 1/2] pci: add bar sizing
Date: Thu, 27 Aug 2015 11:52:51 +0300	[thread overview]
Message-ID: <1440665434-2893-1-git-send-email-mst@redhat.com> (raw)

Will be used for pci-testdev.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 lib/x86/pci.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/x86/pci.c b/lib/x86/pci.c
index 231668a..5116dac 100644
--- a/lib/x86/pci.c
+++ b/lib/x86/pci.c
@@ -19,6 +19,13 @@ static uint32_t pci_config_read(pcidevaddr_t dev, uint8_t reg)
     return inl(0xCFC);
 }
 
+static uint32_t pci_config_write(pcidevaddr_t dev, uint8_t reg, uint32_t val)
+{
+    uint32_t index = reg | (dev << 8) | (0x1 << 31);
+    outl(0xCF8, index);
+    outl(0xCFC, val);
+}
+
 /* Scan bus look for a specific device. Only bus 0 scanned for now. */
 pcidevaddr_t pci_find_dev(uint16_t vendor_id, uint16_t device_id)
 {
@@ -42,6 +49,22 @@ unsigned long pci_bar_addr(pcidevaddr_t dev, int bar_num)
     }
 }
 
+unsigned long pci_bar_size(pcidevaddr_t dev, int bar_num)
+{
+    uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4);
+    uint32_t mask;
+
+    pci_config_write(dev, PCI_BASE_ADDRESS_0 + bar_num * 4, 0xffffffff);
+    mask = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4);
+    pci_config_write(dev, PCI_BASE_ADDRESS_0 + bar_num * 4, bar);
+
+    if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
+        return ~(mask & PCI_BASE_ADDRESS_IO_MASK) + 1;
+    } else {
+        return ~(mask & PCI_BASE_ADDRESS_MEM_MASK) + 1;
+    }
+}
+
 bool pci_bar_is_memory(pcidevaddr_t dev, int bar_num)
 {
     uint32_t bar = pci_config_read(dev, PCI_BASE_ADDRESS_0 + bar_num * 4);
-- 
MST

             reply	other threads:[~2015-08-27  8:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-27  8:52 Michael S. Tsirkin [this message]
2015-08-27  8:52 ` [Qemu-devel] [PATCH 2/2] pci-test: allow bar > 4k Michael S. Tsirkin

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=1440665434-2893-1-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --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).