It's possible to compile QEMU without the USB devices (e.g. when using
"--without-default-devices" as option for the "configure" script).
To be still able to run the loongson3-virt machine in default mode with
such a QEMU binary, we have to check here for the availability of the
devices first before instantiating them.

Signed-off-by: Thomas Huth <th...@redhat.com>
---
 The alternative would be to use a "#ifdef CONFIG_USB_OHCI_PCI" etc.
 ... not sure what is nicer ... what do you think?

 hw/mips/loongson3_virt.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 216812f660..a0afb17030 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -447,10 +447,14 @@ static inline void 
loongson3_virt_devices_init(MachineState *machine,
 
     pci_vga_init(pci_bus);
 
-    if (defaults_enabled()) {
+    if (defaults_enabled() && module_object_class_by_name("pci-ohci")) {
         pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-tablet");
+        if (module_object_class_by_name("usb-kbd")) {
+            usb_create_simple(usb_bus_find(-1), "usb-kbd");
+        }
+        if (module_object_class_by_name("usb-tablet")) {
+            usb_create_simple(usb_bus_find(-1), "usb-tablet");
+        }
     }
 
     for (i = 0; i < nb_nics; i++) {
-- 
2.31.1


Reply via email to