[libvirt] [PATCHv2 14/17] qemu: support new pci controller model "pcie-switch-upstream-port"

Laine Stump laine at laine.org
Fri Jul 17 18:43:41 UTC 2015


this is backed by the qemu device x3130-upstream. It can only plug
into a pcie-root-port or pcie-switch-downstream-port.
---

V2: change test case to reflect additional pcie-root-port between
pcie-root and pcie-switch-upstream-port

src/qemu/qemu_command.c                            | 37 ++++++++++++++++++++++
 .../qemuxml2argv-pcie-switch-upstream-port.args    | 12 +++++++
 tests/qemuxml2argvtest.c                           |  9 ++++++
 3 files changed, 58 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pcie-switch-upstream-port.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 725360c..30f54ce 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1604,6 +1604,12 @@ qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
                  */
                 flags = VIR_PCI_CONNECT_TYPE_PCIE_ROOT;
                 break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+                /* pcie-switch can only connect to a true
+                 * pcie bus, and can't be hot-plugged.
+                 */
+                flags = VIR_PCI_CONNECT_TYPE_PCIE_PORT;
+                break;
             default:
                 break;
             }
@@ -2282,6 +2288,9 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
                        options->port = (addr->slot << 3) + addr->function;
                     break;
                 case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+                    if (!options->type)
+                        deviceName = "x3130-upstream";
+                    break;
                 case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
                 case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT:
                 case VIR_DOMAIN_CONTROLLER_MODEL_PCI_LAST:
@@ -2400,6 +2409,12 @@ qemuAssignDevicePCISlots(virDomainDefPtr def,
                 /* pcie-root-port can only plug into pcie-root */
                 flags = VIR_PCI_CONNECT_TYPE_PCIE_ROOT;
                 break;
+            case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+                /* pcie-switch really does need a real PCIe
+                 * port, but it doesn't need to be pcie-root
+                 */
+                flags = VIR_PCI_CONNECT_TYPE_PCIE_PORT;
+                break;
             default:
                 flags = VIR_PCI_CONNECT_HOTPLUGGABLE | VIR_PCI_CONNECT_TYPE_PCI;
                 break;
@@ -4728,6 +4743,28 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef,
                               def->opts.pciopts.type, def->opts.pciopts.port,
                               def->opts.pciopts.chassis, def->info.alias);
             break;
+        case VIR_DOMAIN_CONTROLLER_MODEL_PCIE_SWITCH_UPSTREAM_PORT:
+            if (!def->opts.pciopts.type) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("autogenerated dmi-to-pci-bridge options not set"));
+                goto error;
+            }
+            if (STREQ(def->opts.pciopts.type, "x3130-upstream")) {
+                if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_X3130_UPSTREAM)) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                                   _("the pcie-switch-upstream-port (x3130-upstream) "
+                                     "controller is not supported in this QEMU binary"));
+                goto error;
+                }
+            } else {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("unknown pcie-switch-upstream-port device '%s'"),
+                               def->opts.pciopts.type);
+                goto error;
+            }
+            virBufferAsprintf(&buf, "%s,id=%s",
+                              def->opts.pciopts.type, def->info.alias);
+            break;
         }
         break;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-pcie-switch-upstream-port.args b/tests/qemuxml2argvdata/qemuxml2argv-pcie-switch-upstream-port.args
new file mode 100644
index 0000000..c08cd4a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-pcie-switch-upstream-port.args
@@ -0,0 +1,12 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/libexec/qemu-kvm -S -M q35 -m 2048 -smp 2 -nographic -nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
+-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \
+-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x1 \
+-device ioh3420,port=0x10,chassis=3,id=pci.3,bus=pcie.0,addr=0x2 \
+-device ioh3420,port=0x18,chassis=4,id=pci.4,bus=pcie.0,addr=0x3 \
+-device x3130-upstream,id=pci.5,bus=pci.3,addr=0x0 \
+-device x3130-upstream,id=pci.6,bus=pci.4,addr=0x0 \
+-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-sata0-0-0 \
+-device ide-drive,bus=ide.0,drive=drive-sata0-0-0,id=sata0-0-0 \
+-vga qxl -global qxl-vga.ram_size=67108864 -global qxl-vga.vram_size=33554432
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 0129717..b42d483 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1504,6 +1504,15 @@ mymain(void)
             QEMU_CAPS_VGA, QEMU_CAPS_DEVICE_VIDEO_PRIMARY,
             QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, QEMU_CAPS_DEVICE_QXL);
 
+    DO_TEST("pcie-switch-upstream-port",
+            QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE,
+            QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
+            QEMU_CAPS_DEVICE_IOH3420,
+            QEMU_CAPS_DEVICE_X3130_UPSTREAM,
+            QEMU_CAPS_DRIVE, QEMU_CAPS_ICH9_AHCI,
+            QEMU_CAPS_VGA, QEMU_CAPS_DEVICE_VIDEO_PRIMARY,
+            QEMU_CAPS_VGA, QEMU_CAPS_VGA_QXL, QEMU_CAPS_DEVICE_QXL);
+
     DO_TEST("hostdev-scsi-lsi", QEMU_CAPS_DRIVE,
             QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE,
             QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_LSI,
-- 
2.1.0




More information about the libvir-list mailing list