diff --git a/src/config.sh b/src/config.sh index 866153a..f4bfe3f 100644 --- a/src/config.sh +++ b/src/config.sh @@ -41,9 +41,12 @@ configureMachine() { configureVirtioDevices() { - DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=pcie.0,addr=0x4" + local bus + bus=$(getPciBus) + + DEV_OPTS="-device virtio-balloon-pci,id=balloon0,bus=$bus,addr=0x4" DEV_OPTS+=" -object rng-random,id=objrng0,filename=/dev/urandom" - DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=pcie.0,addr=0x1c" + DEV_OPTS+=" -device virtio-rng-pci,rng=objrng0,id=rng0,bus=$bus,addr=0x1c" return 0 } diff --git a/src/disk.sh b/src/disk.sh index 20d5a76..16849b6 100644 --- a/src/disk.sh +++ b/src/disk.sh @@ -518,11 +518,9 @@ createDevice () { local diskCache="$7" local diskSerial="$8" local diskSectors="$9" - local bus="${PCI_BUS:-pcie.0}" - # q35 uses pcie.0, while legacy pc/i440fx machines expose their devices on - # pci.0 unless the caller supplied an explicit bus. - [[ -z "${PCI_BUS:-}" && ( "${MACHINE,,}" == pc || "${MACHINE,,}" == pc-i440fx* ) ]] && bus="pci.0" + local bus + bus=$(getPciBus) local options="" [ -n "$DISK_OPTIONS" ] && options=",${DISK_OPTIONS#,}" diff --git a/src/serial.sh b/src/serial.sh index 37e26f3..0a66e58 100644 --- a/src/serial.sh +++ b/src/serial.sh @@ -111,6 +111,9 @@ waitForSocket() { configureSerialPorts() { + local bus + bus=$(getPciBus) + # Managed interactive mode separates the console and QEMU monitor into # reconnecting sockets; other runs keep the simple combined stdio monitor. if enabled "${SHUTDOWN:-Y}" && interactive; then @@ -130,7 +133,7 @@ configureSerialPorts() { fi SERIAL_OPTS+=" \ - -device virtio-serial-pci,id=virtio-serial0,bus=pcie.0,addr=0x3 \ + -device virtio-serial-pci,id=virtio-serial0,bus=$bus,addr=0x3 \ -chardev socket,id=charchannel0,path=$HOST_AGENT_SOCKET,reconnect-ms=1000 \ -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,id=channel0,name=vchannel" diff --git a/src/utils.sh b/src/utils.sh index d0e3d90..25f0ea4 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -49,6 +49,23 @@ isAmdCpu() { [[ "$vendor" == "AuthenticAMD" ]] } +getPciBus() { + + local machine="${1:-${MACHINE:-q35}}" + + if [ -n "${PCI_BUS:-}" ]; then + echo "$PCI_BUS" + return 0 + fi + + case "${machine,,}" in + pc|pc-i440fx*) echo "pci.0" ;; + *) echo "pcie.0" ;; + esac + + return 0 +} + interactive() { # A TTY on stdin is insufficient when /dev/tty is unavailable; require both