qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [QEMU][RFC V2 06/10] xen-pci: register PCI device in Xen an


From: Julien Grall
Subject: [Qemu-devel] [QEMU][RFC V2 06/10] xen-pci: register PCI device in Xen and handle IOREQ_TYPE_PCI_CONFIG
Date: Wed, 22 Aug 2012 13:30:19 +0100

With QEMU disaggregation QEMU needs to specify which PCI device it's able to
handle. It will use the device place in the topology (domain, bus, device,
function).
When Xen will trap an access for the config space, it will forge a new
ioreq and forward it to the right QEMU.

Signed-off-by: Julien Grall <address@hidden>
---
 hw/pci.c   |    6 ++++++
 hw/xen.h   |    1 +
 xen-all.c  |   38 ++++++++++++++++++++++++++++++++++++++
 xen-stub.c |    5 +++++
 4 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 4d95984..0112edf 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -33,6 +33,7 @@
 #include "qmp-commands.h"
 #include "msi.h"
 #include "msix.h"
+#include "xen.h"
 
 //#define DEBUG_PCI
 #ifdef DEBUG_PCI
@@ -781,6 +782,11 @@ static PCIDevice *do_pci_register_device(PCIDevice 
*pci_dev, PCIBus *bus,
     pci_dev->devfn = devfn;
     pstrcpy(pci_dev->name, sizeof(pci_dev->name), name);
     pci_dev->irq_state = 0;
+
+    if (xen_enabled() && xen_register_pcidev(pci_dev)) {
+        return NULL;
+    }
+
     pci_config_alloc(pci_dev);
 
     pci_config_set_vendor_id(pci_dev->config, pc->vendor_id);
diff --git a/hw/xen.h b/hw/xen.h
index e5926b7..663731a 100644
--- a/hw/xen.h
+++ b/hw/xen.h
@@ -35,6 +35,7 @@ int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
 void xen_piix3_set_irq(void *opaque, int irq_num, int level);
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
 void xen_hvm_inject_msi(uint64_t addr, uint32_t data);
+int xen_register_pcidev(PCIDevice *pci_dev);
 void xen_cmos_set_s3_resume(void *opaque, int irq, int level);
 
 qemu_irq *xen_interrupt_controller_init(void);
diff --git a/xen-all.c b/xen-all.c
index 14e5d3d..485c312 100644
--- a/xen-all.c
+++ b/xen-all.c
@@ -174,6 +174,16 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int 
level)
                               irq_num & 3, level);
 }
 
+int xen_register_pcidev(PCIDevice *pci_dev)
+{
+    DPRINTF("register pci %x:%x.%x %s\n", 0, (pci_dev->devfn >> 3) & 0x1f,
+            pci_dev->devfn & 0x7, pci_dev->name);
+
+    return xen_xc_hvm_register_pcidev(xen_xc, xen_domid, serverid,
+                                      0, 0, pci_dev->devfn >> 3,
+                                      pci_dev->devfn & 0x7);
+}
+
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
 {
     int i;
@@ -943,6 +953,29 @@ static void cpu_ioreq_move(ioreq_t *req)
     }
 }
 
+#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00040300
+static void cpu_ioreq_config_space(ioreq_t *req)
+{
+    uint64_t cf8 = req->addr;
+    uint32_t tmp = req->size;
+    uint16_t size = req->size & 0xff;
+    uint16_t off = req->size >> 16;
+
+    if ((size + off + 0xcfc) > 0xd00) {
+        hw_error("Invalid ioreq config space size = %u off = %u\n",
+                 size, off);
+    }
+
+    req->addr = 0xcfc + off;
+    req->size = size;
+
+    do_outp(0xcf8, 4, cf8);
+    cpu_ioreq_pio(req);
+    req->addr = cf8;
+    req->size = tmp;
+}
+#endif
+
 static void handle_ioreq(ioreq_t *req)
 {
     if (!req->data_is_ptr && (req->dir == IOREQ_WRITE) &&
@@ -962,6 +995,11 @@ static void handle_ioreq(ioreq_t *req)
         case IOREQ_TYPE_INVALIDATE:
             xen_invalidate_map_cache();
             break;
+#if __XEN_LATEST_INTERFACE_VERSION__ >= 0x00040300
+        case IOREQ_TYPE_PCI_CONFIG:
+            cpu_ioreq_config_space(req);
+            break;
+#endif
         default:
             hw_error("Invalid ioreq type 0x%x\n", req->type);
     }
diff --git a/xen-stub.c b/xen-stub.c
index 8ff2b79..0128965 100644
--- a/xen-stub.c
+++ b/xen-stub.c
@@ -25,6 +25,11 @@ void xen_piix3_set_irq(void *opaque, int irq_num, int level)
 {
 }
 
+int xen_register_pcidev(PCIDevice *pci_dev)
+{
+    return 1;
+}
+
 void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len)
 {
 }
-- 
Julien Grall




reply via email to

[Prev in Thread] Current Thread [Next in Thread]