qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2] usb: Remove legacy -usbdevice option


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH v2] usb: Remove legacy -usbdevice option
Date: Thu, 4 Jan 2018 16:19:02 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0

On 04/01/2018 15:21, Samuel Thibault wrote:
> Samuel Thibault, on jeu. 04 janv. 2018 15:15:24 +0100, wrote:
>> I'm however still unable to make usb-serial and usb-braille work, as
>> mentioned in my other mail :)
> 
> Ah, now with the documentation I understand, one has to also pass
> -chardev braille,chardev=foobar, and then
> -device usb-braille,chardev=foobar works.
> 
> Would it be possible to make this automatic?  Before I could tell people
> "use -usbdevice braille to test braille", and now it would be
> "use -chardev braille,chardev=foobar -device usb-braille,chardev=foobar"

Maybe we can add "-braille" instead.  Something like this:

diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index 94b5c34afe..a5239b7fe7 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -13,6 +13,7 @@
 #include "qemu-common.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
+#include "sysemu/sysemu.h"
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
 #include "chardev/char-serial.h"
@@ -552,6 +553,24 @@ static USBDevice *usb_braille_init(USBBus *bus, const char 
*unused)
     return dev;
 }
 
+void usb_braille_create(Error **errp)
+{
+    USBBus *bus = usb_bus_find(-1 /* any */);
+    USBDevice *dev = usb_braille_init(bus, "braille");
+    Error *local_err = NULL;
+
+    if (!dev) {
+        error_setg(errp, "Failed to create USB device");
+        return;
+    }
+    object_property_set_bool(OBJECT(dev), true, "realized", &local_err);
+    if (local_err) {
+        error_prepend(&local_err, "Failed to initialize USB device: ");
+        error_propagate(errp, local_err);
+        object_unparent(OBJECT(dev));
+    }
+}
+
 static const VMStateDescription vmstate_usb_serial = {
     .name = "usb-serial",
     .unmigratable = 1,
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index b4c10e62ba..eae3618735 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -167,6 +167,7 @@ extern Chardev *serial_hds[MAX_SERIAL_PORTS];
 extern Chardev *parallel_hds[MAX_PARALLEL_PORTS];
 
 void hmp_info_usb(Monitor *mon, const QDict *qdict);
+void usb_braille_create(Error **errp);
 
 void add_boot_device_path(int32_t bootindex, DeviceState *dev,
                           const char *suffix);
diff --git a/qemu-options.hx b/qemu-options.hx
index 94647e21e3..92886cb777 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1214,6 +1214,16 @@ STEXI
 Enable the USB driver (if it is not used by default yet).
 ETEXI
 
+DEF("braille", QEMU_OPTION_braille,
+    "-braille        add a USB braille reader\n",
+    QEMU_ARCH_ALL)
+STEXI
address@hidden -braille
address@hidden -braille
+Add a USB Braille device.  The device will use BrlAPI to display the braille
+output on a real or fake device.
+ETEXI
+
 DEF("usbdevice", HAS_ARG, QEMU_OPTION_usbdevice,
     "-usbdevice name add the host or guest USB device 'name'\n",
     QEMU_ARCH_ALL)
diff --git a/roms/seabios b/roms/seabios
index 63451fca13..cd47172a67 160000
--- a/roms/seabios
+++ b/roms/seabios
@@ -1 +1 @@
-Subproject commit 63451fca13c75870e1703eb3e20584d91179aebc
+Subproject commit cd47172a673762a05a0c7bd27df6e3cc8febe8d6
diff --git a/vl.c b/vl.c
index 5a8482a3a0..92d8775234 100644
--- a/vl.c
+++ b/vl.c
@@ -1488,6 +1488,17 @@ static int usb_parse(const char *cmdline)
     return r;
 }
 
+static int do_braille(const char *unused)
+{
+    Error *err = NULL;
+    usb_braille_create(&err);
+    if (err) {
+        error_report_err(err);
+        return -1;
+    }
+    return 0;
+}
+
 /***********************************************************/
 /* machine registration */
 
@@ -2495,6 +2506,7 @@ struct device_config {
         DEV_DEBUGCON,  /* -debugcon */
         DEV_GDB,       /* -gdb, -s */
         DEV_SCLP,      /* s390 sclp */
+        DEV_BRAILLE,   /* -braille */
     } type;
     const char *cmdline;
     Location loc;
@@ -3411,6 +3423,9 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_no_fd_bootchk:
                 fd_bootchk = 0;
                 break;
+            case QEMU_OPTION_braille:
+                add_device_config(DEV_BRAILLE, "braille");
+                break;
             case QEMU_OPTION_netdev:
                 default_net = 0;
                 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
@@ -4728,6 +4743,9 @@ int main(int argc, char **argv, char **envp)
         if (foreach_device_config(DEV_USB, usb_parse) < 0)
             exit(1);
     }
+    if (foreach_device_config(DEV_BRAILLE, do_braille) < 0) {
+        exit(1);
+    }
 
     /* Check if IGD GFX passthrough. */
     igd_gfx_passthru();


Untested, but it compiles (and it keeps syntactic sugar out of device code).
It still would let Thomas remove over 400 lines of code, and would cater
for the specific use case.  

Paolo



reply via email to

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