[pve-devel] [PATCH] enable q35 machine support

Alexandre Derumier aderumier at odiso.com
Mon May 26 09:49:56 CEST 2014


q35 use pcie.0 root by default. so currently we can't start machine model q35.

we need to add 3 pci-bridge pci.0, pci.1, pci.2, to handle our devices.

pcie.0 does not support hotplug. so pci-bridge are defined at startup.

I use an pve-q35.cfg (mostly the same than q35-chipset.cfg from qemu docs).

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 Makefile          |    1 +
 PVE/QemuServer.pm |   43 +++++++++-------
 pve-q35.cfg       |  147 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+), 17 deletions(-)
 create mode 100644 pve-q35.cfg

diff --git a/Makefile b/Makefile
index 99dc897..5820732 100644
--- a/Makefile
+++ b/Makefile
@@ -75,6 +75,7 @@ install: ${PKGSOURCES}
 	install -d ${DESTDIR}/usr/share/man/man5
 	install -d ${DESTDIR}/usr/share/${PACKAGE}
 	install -m 0644 pve-usb.cfg ${DESTDIR}/usr/share/${PACKAGE}
+	install -m 0644 pve-q35.cfg ${DESTDIR}/usr/share/${PACKAGE}
 	make -C PVE install
 	install -m 0755 qm ${DESTDIR}${SBINDIR}
 	install -m 0755 qmrestore ${DESTDIR}${SBINDIR}
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e1b85c3..becfadf 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2318,6 +2318,7 @@ sub config_to_command {
 
     my $have_ovz = -f '/proc/vz/vestat';
 
+    my $q35 = 1 if($conf->{machine} && $conf->{machine} =~ m/q35/);
     push @$cmd, '/usr/bin/kvm';
 
     push @$cmd, '-id', $vmid;
@@ -2335,16 +2336,20 @@ sub config_to_command {
 
     push @$cmd, '-daemonize';
 
-    $pciaddr = print_pci_addr("piix3", $bridges);
-    push @$devices, '-device', "piix3-usb-uhci,id=uhci$pciaddr.0x2";
+    if($q35){
+        push @$devices, '-readconfig', '/usr/share/qemu-server/pve-q35.cfg';
+    }else{
+        $pciaddr = print_pci_addr("piix3", $bridges);
+        push @$devices, '-device', "piix3-usb-uhci,id=uhci$pciaddr.0x2";
 
-    my $use_usb2 = 0;
-    for (my $i = 0; $i < $MAX_USB_DEVICES; $i++)  {
-	next if !$conf->{"usb$i"};
-	$use_usb2 = 1;
+        my $use_usb2 = 0;
+            for (my $i = 0; $i < $MAX_USB_DEVICES; $i++)  {
+                next if !$conf->{"usb$i"};
+                $use_usb2 = 1;
+            }
+            # include usb device config
+            push @$devices, '-readconfig', '/usr/share/qemu-server/pve-usb.cfg' if $use_usb2;
     }
-    # include usb device config
-    push @$devices, '-readconfig', '/usr/share/qemu-server/pve-usb.cfg' if $use_usb2;
 
     my $vga = $conf->{vga};
 
@@ -2371,7 +2376,8 @@ sub config_to_command {
 	$tablet = 0 if $vga =~ m/^serial\d+$/; # disable if we use serial terminal (no vga card)
     }
 
-    push @$devices, '-device', 'usb-tablet,id=tablet,bus=uhci.0,port=1' if $tablet;
+    my $usbbus = $q35 ? "ehci" : "uhci";
+    push @$devices, '-device', "usb-tablet,id=tablet,bus=$usbbus.0,port=1" if $tablet;
 
     # host pci devices
     for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++)  {
@@ -2658,13 +2664,14 @@ sub config_to_command {
          push @$devices, '-device', $netdevicefull;
     }
 
-    #bridges
-    while (my ($k, $v) = each %$bridges) {
-	$pciaddr = print_pci_addr("pci.$k");
-	unshift @$devices, '-device', "pci-bridge,id=pci.$k,chassis_nr=$k$pciaddr" if $k > 0;
+    if(!$q35){
+	#bridges
+	while (my ($k, $v) = each %$bridges) {
+	    $pciaddr = print_pci_addr("pci.$k");
+	    unshift @$devices, '-device', "pci-bridge,id=pci.$k,chassis_nr=$k$pciaddr" if $k > 0;
+	}
     }
 
-
     # hack: virtio with fairsched is unreliable, so we do not use fairsched
     # when the VM uses virtio devices.
     if (!$use_virtio && $have_ovz) {
@@ -2743,9 +2750,10 @@ sub vm_deviceplug {
     my ($storecfg, $conf, $vmid, $deviceid, $device) = @_;
 
     return 1 if !check_running($vmid);
-
+    my $q35 = 1 if ($conf->{machine} && $conf->{machine} =~ m/q35/);
     if ($deviceid eq 'tablet') {
-	my $devicefull = "usb-tablet,id=tablet,bus=uhci.0,port=1";
+	my $usbbus = $q35 ? "ehci" : "uhci";
+	my $devicefull = "usb-tablet,id=tablet,bus=$usbbus.0,port=1";
 	qemu_deviceadd($vmid, $devicefull);
 	return 1;
     }
@@ -2796,7 +2804,8 @@ sub vm_deviceplug {
         }
     }
 
-    if ($deviceid =~ m/^(pci\.)(\d+)$/) {
+    
+    if (!$q35 && $deviceid =~ m/^(pci\.)(\d+)$/) {
 	my $bridgeid = $2;
 	my $pciaddr = print_pci_addr($deviceid);
 	my $devicefull = "pci-bridge,id=pci.$bridgeid,chassis_nr=$bridgeid$pciaddr";
diff --git a/pve-q35.cfg b/pve-q35.cfg
new file mode 100644
index 0000000..f9f72fc
--- /dev/null
+++ b/pve-q35.cfg
@@ -0,0 +1,147 @@
+[device "ehci"]
+  driver = "ich9-usb-ehci1"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1d.7"
+
+[device "uhci-1"]
+  driver = "ich9-usb-uhci1"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1d.0"
+  masterbus = "ehci.0"
+  firstport = "0"
+
+[device "uhci-2"]
+  driver = "ich9-usb-uhci2"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1d.1"
+  masterbus = "ehci.0"
+  firstport = "2"
+
+[device "uhci-3"]
+  driver = "ich9-usb-uhci3"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1d.2"
+  masterbus = "ehci.0"
+  firstport = "4"
+
+[device "ehci-2"]
+  driver = "ich9-usb-ehci2"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1a.7"
+
+[device "uhci-4"]
+  driver = "ich9-usb-uhci4"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1a.0"
+  masterbus = "ehci-2.0"
+  firstport = "0"
+
+[device "uhci-5"]
+  driver = "ich9-usb-uhci5"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1a.1"
+  masterbus = "ehci-2.0"
+  firstport = "2"
+
+[device "uhci-6"]
+  driver = "ich9-usb-uhci6"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1a.2"
+  masterbus = "ehci-2.0"
+  firstport = "4"
+
+
+[device "audio0"]
+  driver = "ich9-intel-hda"
+  bus = "pcie.0"
+  addr = "1b.0"
+
+
+[device "ich9-pcie-port-1"]
+  driver = "ioh3420"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1c.0"
+  port = "1"
+  chassis = "1"
+
+[device "ich9-pcie-port-2"]
+  driver = "ioh3420"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1c.1"
+  port = "2"
+  chassis = "2"
+
+[device "ich9-pcie-port-3"]
+  driver = "ioh3420"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1c.2"
+  port = "3"
+  chassis = "3"
+
+[device "ich9-pcie-port-4"]
+  driver = "ioh3420"
+  multifunction = "on"
+  bus = "pcie.0"
+  addr = "1c.3"
+  port = "4"
+  chassis = "4"
+
+##
+# Example PCIe switch with two downstream ports
+#
+#[device "pcie-switch-upstream-port-1"]
+#  driver = "x3130-upstream"
+#  bus = "ich9-pcie-port-4"
+#  addr = "00.0"
+#
+#[device "pcie-switch-downstream-port-1-1"]
+#  driver = "xio3130-downstream"
+#  multifunction = "on"
+#  bus = "pcie-switch-upstream-port-1"
+#  addr = "00.0"
+#  port = "1"
+#  chassis = "5"
+#
+#[device "pcie-switch-downstream-port-1-2"]
+#  driver = "xio3130-downstream"
+#  multifunction = "on"
+#  bus = "pcie-switch-upstream-port-1"
+#  addr = "00.1"
+#  port = "1"
+#  chassis = "6"
+
+
+
+[device "pcidmi"}
+  driver = "i82801b11-bridge"
+  bus = "pcie.0"
+  addr = "1e.0"
+
+[device "pci.0"]
+  driver = "pci-bridge"
+  bus = "pcidmi"
+  addr = "1.0"
+  chassis_nr = "1"
+
+[device "pci.1"]
+  driver = "pci-bridge"
+  bus = "pcidmi"
+  addr = "2.0"
+  chassis_nr = "2"
+
+[device "pci.2"]
+  driver = "pci-bridge"
+  bus = "pcidmi"
+  addr = "3.0"
+  chassis_nr = "3"
-- 
1.7.10.4




More information about the pve-devel mailing list