qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] [RfC] monitor/hmp: command register support
@ 2021-06-22 12:49 Gerd Hoffmann
  2021-06-22 12:49 ` [PATCH 1/5] monitor: allow register hmp commands Gerd Hoffmann
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2021-06-22 12:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Greg Kurz, Markus Armbruster, qemu-ppc,
	Gerd Hoffmann, Paolo Bonzini, Dr. David Alan Gilbert,
	David Gibson

Helps making qemu more modular,
see commit messages for details.

Depends on the "modules: add meta-data database" patch series.

Gerd Hoffmann (5):
  monitor: allow register hmp commands
  usb: drop usb_host_dev_is_scsi_storage hook
  monitor/usb: register 'info usbhost' dynamically
  usb: build usb-host as module
  monitor/tcg: move tcg hmp commands to accel/tcg, register them
    dynamically

 include/hw/usb.h             |  7 +++++-
 include/monitor/monitor.h    |  3 +++
 accel/tcg/hmp.c              | 29 +++++++++++++++++++++++
 hw/ppc/spapr.c               |  2 +-
 hw/usb/dev-storage-bot.c     |  1 +
 hw/usb/dev-storage-classic.c |  1 +
 hw/usb/dev-uas.c             |  1 +
 hw/usb/host-libusb.c         | 38 ++++++++----------------------
 hw/usb/host-stub.c           | 45 ------------------------------------
 monitor/hmp.c                |  7 ++++++
 monitor/misc.c               | 33 ++++++++++++--------------
 accel/tcg/meson.build        |  1 +
 hmp-commands-info.hx         |  3 ---
 hw/usb/meson.build           | 10 ++++----
 14 files changed, 80 insertions(+), 101 deletions(-)
 create mode 100644 accel/tcg/hmp.c
 delete mode 100644 hw/usb/host-stub.c

-- 
2.31.1




^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/5] monitor: allow register hmp commands
  2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
@ 2021-06-22 12:49 ` Gerd Hoffmann
  2021-06-22 13:13   ` Greg Kurz
  2021-06-22 12:49 ` [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook Gerd Hoffmann
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Gerd Hoffmann @ 2021-06-22 12:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Greg Kurz, Markus Armbruster, qemu-ppc,
	Gerd Hoffmann, Paolo Bonzini, Dr. David Alan Gilbert,
	David Gibson

Allow commands having a NULL cmd pointer, add a function to set the
pointer later.  Use case: allow modules implement hmp commands.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/monitor/monitor.h |  3 +++
 monitor/hmp.c             |  7 +++++++
 monitor/misc.c            | 15 +++++++++++++++
 3 files changed, 25 insertions(+)

diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index 1211d6e6d69f..1a8a369b50b2 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -51,4 +51,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
 void monitor_fdset_dup_fd_remove(int dup_fd);
 int64_t monitor_fdset_dup_fd_find(int dup_fd);
 
+void monitor_register_hmp(const char *name, bool info,
+                          void (*cmd)(Monitor *mon, const QDict *qdict));
+
 #endif /* MONITOR_H */
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 6c0b33a0b19d..d50c3124e1e1 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1089,6 +1089,13 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
         return;
     }
 
+    if (!cmd->cmd) {
+        /* FIXME: is it useful to try autoload modules here ??? */
+        monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n",
+                       (int)(cmdline - cmd_start), cmd_start);
+        return;
+    }
+
     qdict = monitor_parse_arguments(&mon->common, &cmdline, cmd);
     if (!qdict) {
         while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
diff --git a/monitor/misc.c b/monitor/misc.c
index 1539e18557f0..672267008b02 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -1974,6 +1974,21 @@ static void sortcmdlist(void)
           compare_mon_cmd);
 }
 
+void monitor_register_hmp(const char *name, bool info,
+                          void (*cmd)(Monitor *mon, const QDict *qdict))
+{
+    HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;
+
+    while (table->name != NULL) {
+        if (strcmp(table->name, name) == 0) {
+            table->cmd = cmd;
+            return;
+        }
+        table++;
+    }
+    g_assert_not_reached();
+}
+
 void monitor_init_globals(void)
 {
     monitor_init_globals_core();
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook
  2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
  2021-06-22 12:49 ` [PATCH 1/5] monitor: allow register hmp commands Gerd Hoffmann
@ 2021-06-22 12:49 ` Gerd Hoffmann
  2021-06-23  1:51   ` David Gibson
  2021-06-22 12:49 ` [PATCH 3/5] monitor/usb: register 'info usbhost' dynamically Gerd Hoffmann
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Gerd Hoffmann @ 2021-06-22 12:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Greg Kurz, Markus Armbruster, qemu-ppc,
	Gerd Hoffmann, Paolo Bonzini, Dr. David Alan Gilbert,
	David Gibson

Introduce an usb device flag instead, set it when usb-host looks at the
device descriptors anyway.  Also set it for emulated storage devices,
for consistency.  Add an inline helper function to check the flag.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/hw/usb.h             |  7 ++++++-
 hw/ppc/spapr.c               |  2 +-
 hw/usb/dev-storage-bot.c     |  1 +
 hw/usb/dev-storage-classic.c |  1 +
 hw/usb/dev-uas.c             |  1 +
 hw/usb/host-libusb.c         | 36 +++++++-----------------------------
 hw/usb/host-stub.c           |  5 -----
 7 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/include/hw/usb.h b/include/hw/usb.h
index 436e07b30404..33668dd0a99a 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -219,6 +219,7 @@ enum USBDeviceFlags {
     USB_DEV_FLAG_IS_HOST,
     USB_DEV_FLAG_MSOS_DESC_ENABLE,
     USB_DEV_FLAG_MSOS_DESC_IN_USE,
+    USB_DEV_FLAG_IS_SCSI_STORAGE,
 };
 
 /* definition of a USB device */
@@ -465,7 +466,6 @@ void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);
 
 /* usb-linux.c */
 void hmp_info_usbhost(Monitor *mon, const QDict *qdict);
-bool usb_host_dev_is_scsi_storage(USBDevice *usbdev);
 
 /* usb ports of the VM */
 
@@ -561,6 +561,11 @@ const char *usb_device_get_product_desc(USBDevice *dev);
 
 const USBDesc *usb_device_get_usb_desc(USBDevice *dev);
 
+static inline bool usb_device_is_scsi_storage(USBDevice *dev)
+{
+    return dev->flags & (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
+}
+
 /* quirks.c */
 
 /* In bulk endpoints are streaming data sources (iow behave like isoc eps) */
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 4dd90b75cc52..f83a081af0f1 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3106,7 +3106,7 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
      */
     if (strcmp("usb-host", qdev_fw_name(dev)) == 0) {
         USBDevice *usbdev = CAST(USBDevice, dev, TYPE_USB_DEVICE);
-        if (usb_host_dev_is_scsi_storage(usbdev)) {
+        if (usb_device_is_scsi_storage(usbdev)) {
             return g_strdup_printf("storage@%s/disk", usbdev->port->path);
         }
     }
diff --git a/hw/usb/dev-storage-bot.c b/hw/usb/dev-storage-bot.c
index 6aad026d1133..68ebaca10c66 100644
--- a/hw/usb/dev-storage-bot.c
+++ b/hw/usb/dev-storage-bot.c
@@ -32,6 +32,7 @@ static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
+    dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
     if (d->hotplugged) {
         s->dev.auto_attach = 0;
     }
diff --git a/hw/usb/dev-storage-classic.c b/hw/usb/dev-storage-classic.c
index 00cb34b22f02..3d017a4e6791 100644
--- a/hw/usb/dev-storage-classic.c
+++ b/hw/usb/dev-storage-classic.c
@@ -64,6 +64,7 @@ static void usb_msd_storage_realize(USBDevice *dev, Error **errp)
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
+    dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
     scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
                  &usb_msd_scsi_info_storage, NULL);
     scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable,
diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index d2bd85d3f6bb..263056231c79 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -926,6 +926,7 @@ static void usb_uas_realize(USBDevice *dev, Error **errp)
     QTAILQ_INIT(&uas->requests);
     uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas);
 
+    dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
     scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
                  &usb_uas_scsi_info, NULL);
 }
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 2518306f527f..e6d21aa8e1d3 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -770,6 +770,13 @@ static void usb_host_speed_compat(USBHostDevice *s)
         for (i = 0; i < conf->bNumInterfaces; i++) {
             for (a = 0; a < conf->interface[i].num_altsetting; a++) {
                 intf = &conf->interface[i].altsetting[a];
+
+                if (intf->bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE &&
+                    intf->bInterfaceSubClass == 6) { /* SCSI */
+                    udev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
+                    break;
+                }
+
                 for (e = 0; e < intf->bNumEndpoints; e++) {
                     endp = &intf->endpoint[e];
                     type = endp->bmAttributes & 0x3;
@@ -1893,35 +1900,6 @@ static void usb_host_auto_check(void *unused)
     timer_mod(usb_auto_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 2000);
 }
 
-/**
- * Check whether USB host device has a USB mass storage SCSI interface
- */
-bool usb_host_dev_is_scsi_storage(USBDevice *ud)
-{
-    USBHostDevice *uhd = USB_HOST_DEVICE(ud);
-    struct libusb_config_descriptor *conf;
-    const struct libusb_interface_descriptor *intf;
-    bool is_scsi_storage = false;
-    int i;
-
-    if (!uhd || libusb_get_active_config_descriptor(uhd->dev, &conf) != 0) {
-        return false;
-    }
-
-    for (i = 0; i < conf->bNumInterfaces; i++) {
-        intf = &conf->interface[i].altsetting[ud->altsetting[i]];
-        if (intf->bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE &&
-            intf->bInterfaceSubClass == 6) {                 /* 6 means SCSI */
-            is_scsi_storage = true;
-            break;
-        }
-    }
-
-    libusb_free_config_descriptor(conf);
-
-    return is_scsi_storage;
-}
-
 void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
 {
     libusb_device **devs = NULL;
diff --git a/hw/usb/host-stub.c b/hw/usb/host-stub.c
index 80809ceba542..bbe69baa390f 100644
--- a/hw/usb/host-stub.c
+++ b/hw/usb/host-stub.c
@@ -38,8 +38,3 @@ void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
 {
     monitor_printf(mon, "USB host devices not supported\n");
 }
-
-bool usb_host_dev_is_scsi_storage(USBDevice *ud)
-{
-    return false;
-}
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/5] monitor/usb: register 'info usbhost' dynamically
  2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
  2021-06-22 12:49 ` [PATCH 1/5] monitor: allow register hmp commands Gerd Hoffmann
  2021-06-22 12:49 ` [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook Gerd Hoffmann
@ 2021-06-22 12:49 ` Gerd Hoffmann
  2021-06-22 12:49 ` [PATCH 4/5] usb: build usb-host as module Gerd Hoffmann
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2021-06-22 12:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Greg Kurz, Markus Armbruster, qemu-ppc,
	Gerd Hoffmann, Paolo Bonzini, Dr. David Alan Gilbert,
	David Gibson

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/host-libusb.c |  1 +
 hw/usb/host-stub.c   | 40 ----------------------------------------
 hmp-commands-info.hx |  1 -
 hw/usb/meson.build   |  4 +---
 4 files changed, 2 insertions(+), 44 deletions(-)
 delete mode 100644 hw/usb/host-stub.c

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index e6d21aa8e1d3..2b7f87872ce3 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -1781,6 +1781,7 @@ static TypeInfo usb_host_dev_info = {
 static void usb_host_register_types(void)
 {
     type_register_static(&usb_host_dev_info);
+    monitor_register_hmp("usbhost", true, hmp_info_usbhost);
 }
 
 type_init(usb_host_register_types)
diff --git a/hw/usb/host-stub.c b/hw/usb/host-stub.c
deleted file mode 100644
index bbe69baa390f..000000000000
--- a/hw/usb/host-stub.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Stub host USB redirector
- *
- * Copyright (c) 2005 Fabrice Bellard
- *
- * Copyright (c) 2008 Max Krasnyansky
- *      Support for host device auto connect & disconnect
- *      Major rewrite to support fully async operation
- *
- * Copyright 2008 TJ <linux@tjworld.net>
- *      Added flexible support for /dev/bus/usb /sys/bus/usb/devices in addition
- *      to the legacy /proc/bus/usb USB device discovery and handling
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "qemu/osdep.h"
-#include "hw/usb.h"
-#include "monitor/monitor.h"
-
-void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
-{
-    monitor_printf(mon, "USB host devices not supported\n");
-}
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index fb59c27200cb..ce42aef47acb 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -368,7 +368,6 @@ ERST
         .args_type  = "",
         .params     = "",
         .help       = "show host USB devices",
-        .cmd        = hmp_info_usbhost,
     },
 
 SRST
diff --git a/hw/usb/meson.build b/hw/usb/meson.build
index f357270d0b6b..3d8f2ae99302 100644
--- a/hw/usb/meson.build
+++ b/hw/usb/meson.build
@@ -73,9 +73,7 @@ endif
 
 # usb pass-through
 softmmu_ss.add(when: ['CONFIG_USB', 'CONFIG_USB_LIBUSB', libusb],
-               if_true: files('host-libusb.c'),
-               if_false: files('host-stub.c'))
-softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('host-stub.c'))
+               if_true: files('host-libusb.c'))
 
 softmmu_ss.add(when: ['CONFIG_USB', 'CONFIG_XEN', libusb], if_true: files('xen-usb.c'))
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/5] usb: build usb-host as module
  2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2021-06-22 12:49 ` [PATCH 3/5] monitor/usb: register 'info usbhost' dynamically Gerd Hoffmann
@ 2021-06-22 12:49 ` Gerd Hoffmann
  2021-06-22 12:49 ` [PATCH 5/5] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically Gerd Hoffmann
  2021-08-07 10:36 ` [PATCH 0/5] [RfC] monitor/hmp: command register support Markus Armbruster
  5 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2021-06-22 12:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Greg Kurz, Markus Armbruster, qemu-ppc,
	Gerd Hoffmann, Paolo Bonzini, Dr. David Alan Gilbert,
	David Gibson

Drop one more shared library dependency (libusb) from core qemu.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/host-libusb.c | 1 +
 hw/usb/meson.build   | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 2b7f87872ce3..c0f314462aaf 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -1777,6 +1777,7 @@ static TypeInfo usb_host_dev_info = {
     .class_init    = usb_host_class_initfn,
     .instance_init = usb_host_instance_init,
 };
+module_obj(TYPE_USB_HOST_DEVICE);
 
 static void usb_host_register_types(void)
 {
diff --git a/hw/usb/meson.build b/hw/usb/meson.build
index 3d8f2ae99302..0a6029ec9797 100644
--- a/hw/usb/meson.build
+++ b/hw/usb/meson.build
@@ -72,8 +72,12 @@ if config_host.has_key('CONFIG_USB_REDIR')
 endif
 
 # usb pass-through
-softmmu_ss.add(when: ['CONFIG_USB', 'CONFIG_USB_LIBUSB', libusb],
-               if_true: files('host-libusb.c'))
+if config_host.has_key('CONFIG_USB_LIBUSB')
+  usbhost_ss = ss.source_set()
+  usbhost_ss.add(when: ['CONFIG_USB', libusb],
+                 if_true: files('host-libusb.c'))
+  hw_usb_modules += {'host': usbhost_ss}
+endif
 
 softmmu_ss.add(when: ['CONFIG_USB', 'CONFIG_XEN', libusb], if_true: files('xen-usb.c'))
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/5] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically
  2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2021-06-22 12:49 ` [PATCH 4/5] usb: build usb-host as module Gerd Hoffmann
@ 2021-06-22 12:49 ` Gerd Hoffmann
  2021-08-07 10:36 ` [PATCH 0/5] [RfC] monitor/hmp: command register support Markus Armbruster
  5 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2021-06-22 12:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: Richard Henderson, Greg Kurz, Markus Armbruster, qemu-ppc,
	Gerd Hoffmann, Paolo Bonzini, Dr. David Alan Gilbert,
	David Gibson

One more little step towards modular tcg ...

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 accel/tcg/hmp.c       | 29 +++++++++++++++++++++++++++++
 monitor/misc.c        | 18 ------------------
 accel/tcg/meson.build |  1 +
 hmp-commands-info.hx  |  2 --
 4 files changed, 30 insertions(+), 20 deletions(-)
 create mode 100644 accel/tcg/hmp.c

diff --git a/accel/tcg/hmp.c b/accel/tcg/hmp.c
new file mode 100644
index 000000000000..a6e72fdb3ed6
--- /dev/null
+++ b/accel/tcg/hmp.c
@@ -0,0 +1,29 @@
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+#include "exec/exec-all.h"
+#include "monitor/monitor.h"
+#include "sysemu/tcg.h"
+
+static void hmp_info_jit(Monitor *mon, const QDict *qdict)
+{
+    if (!tcg_enabled()) {
+        error_report("JIT information is only available with accel=tcg");
+        return;
+    }
+
+    dump_exec_info();
+    dump_drift_info();
+}
+
+static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
+{
+    dump_opcount_info();
+}
+
+static void hmp_tcg_register(void)
+{
+    monitor_register_hmp("jit", true, hmp_info_jit);
+    monitor_register_hmp("opcount", true, hmp_info_opcount);
+}
+
+type_init(hmp_tcg_register);
diff --git a/monitor/misc.c b/monitor/misc.c
index 672267008b02..e28f23e1931a 100644
--- a/monitor/misc.c
+++ b/monitor/misc.c
@@ -320,24 +320,6 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict)
     }
 }
 
-#ifdef CONFIG_TCG
-static void hmp_info_jit(Monitor *mon, const QDict *qdict)
-{
-    if (!tcg_enabled()) {
-        error_report("JIT information is only available with accel=tcg");
-        return;
-    }
-
-    dump_exec_info();
-    dump_drift_info();
-}
-
-static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
-{
-    dump_opcount_info();
-}
-#endif
-
 static void hmp_info_sync_profile(Monitor *mon, const QDict *qdict)
 {
     int64_t max = qdict_get_try_int(qdict, "max", 10);
diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build
index 0ae9180282e3..137a1a44cc0a 100644
--- a/accel/tcg/meson.build
+++ b/accel/tcg/meson.build
@@ -15,6 +15,7 @@ specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
 
 specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
   'cputlb.c',
+  'hmp.c',
 ))
 
 tcg_module_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index ce42aef47acb..27206ac049df 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -274,7 +274,6 @@ ERST
         .args_type  = "",
         .params     = "",
         .help       = "show dynamic compiler info",
-        .cmd        = hmp_info_jit,
     },
 #endif
 
@@ -289,7 +288,6 @@ ERST
         .args_type  = "",
         .params     = "",
         .help       = "show dynamic compiler opcode counters",
-        .cmd        = hmp_info_opcount,
     },
 #endif
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/5] monitor: allow register hmp commands
  2021-06-22 12:49 ` [PATCH 1/5] monitor: allow register hmp commands Gerd Hoffmann
@ 2021-06-22 13:13   ` Greg Kurz
  0 siblings, 0 replies; 10+ messages in thread
From: Greg Kurz @ 2021-06-22 13:13 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Markus Armbruster, Richard Henderson, Dr. David Alan Gilbert,
	qemu-devel, qemu-ppc, Paolo Bonzini, David Gibson

On Tue, 22 Jun 2021 14:49:11 +0200
Gerd Hoffmann <kraxel@redhat.com> wrote:

> Allow commands having a NULL cmd pointer, add a function to set the
> pointer later.  Use case: allow modules implement hmp commands.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  include/monitor/monitor.h |  3 +++
>  monitor/hmp.c             |  7 +++++++
>  monitor/misc.c            | 15 +++++++++++++++
>  3 files changed, 25 insertions(+)
> 
> diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
> index 1211d6e6d69f..1a8a369b50b2 100644
> --- a/include/monitor/monitor.h
> +++ b/include/monitor/monitor.h
> @@ -51,4 +51,7 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int flags);
>  void monitor_fdset_dup_fd_remove(int dup_fd);
>  int64_t monitor_fdset_dup_fd_find(int dup_fd);
>  
> +void monitor_register_hmp(const char *name, bool info,
> +                          void (*cmd)(Monitor *mon, const QDict *qdict));
> +
>  #endif /* MONITOR_H */
> diff --git a/monitor/hmp.c b/monitor/hmp.c
> index 6c0b33a0b19d..d50c3124e1e1 100644
> --- a/monitor/hmp.c
> +++ b/monitor/hmp.c
> @@ -1089,6 +1089,13 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
>          return;
>      }
>  
> +    if (!cmd->cmd) {
> +        /* FIXME: is it useful to try autoload modules here ??? */
> +        monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n",
> +                       (int)(cmdline - cmd_start), cmd_start);
> +        return;
> +    }
> +
>      qdict = monitor_parse_arguments(&mon->common, &cmdline, cmd);
>      if (!qdict) {
>          while (cmdline > cmd_start && qemu_isspace(cmdline[-1])) {
> diff --git a/monitor/misc.c b/monitor/misc.c
> index 1539e18557f0..672267008b02 100644
> --- a/monitor/misc.c
> +++ b/monitor/misc.c
> @@ -1974,6 +1974,21 @@ static void sortcmdlist(void)
>            compare_mon_cmd);
>  }
>  
> +void monitor_register_hmp(const char *name, bool info,
> +                          void (*cmd)(Monitor *mon, const QDict *qdict))
> +{
> +    HMPCommand *table = info ? hmp_info_cmds : hmp_cmds;
> +
> +    while (table->name != NULL) {
> +        if (strcmp(table->name, name) == 0) {

Would it make sense to register the same command multiple times ?
I guess it doesn't, so you may add an assert(table->cmd == NULL)
here.

> +            table->cmd = cmd;
> +            return;
> +        }
> +        table++;
> +    }
> +    g_assert_not_reached();
> +}
> +
>  void monitor_init_globals(void)
>  {
>      monitor_init_globals_core();



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook
  2021-06-22 12:49 ` [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook Gerd Hoffmann
@ 2021-06-23  1:51   ` David Gibson
  0 siblings, 0 replies; 10+ messages in thread
From: David Gibson @ 2021-06-23  1:51 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Markus Armbruster, Richard Henderson, Dr. David Alan Gilbert,
	qemu-devel, Greg Kurz, qemu-ppc, Paolo Bonzini

[-- Attachment #1: Type: text/plain, Size: 6735 bytes --]

On Tue, Jun 22, 2021 at 02:49:12PM +0200, Gerd Hoffmann wrote:
> Introduce an usb device flag instead, set it when usb-host looks at the
> device descriptors anyway.  Also set it for emulated storage devices,
> for consistency.  Add an inline helper function to check the flag.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

ppc parts
Acked-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  include/hw/usb.h             |  7 ++++++-
>  hw/ppc/spapr.c               |  2 +-
>  hw/usb/dev-storage-bot.c     |  1 +
>  hw/usb/dev-storage-classic.c |  1 +
>  hw/usb/dev-uas.c             |  1 +
>  hw/usb/host-libusb.c         | 36 +++++++-----------------------------
>  hw/usb/host-stub.c           |  5 -----
>  7 files changed, 17 insertions(+), 36 deletions(-)
> 
> diff --git a/include/hw/usb.h b/include/hw/usb.h
> index 436e07b30404..33668dd0a99a 100644
> --- a/include/hw/usb.h
> +++ b/include/hw/usb.h
> @@ -219,6 +219,7 @@ enum USBDeviceFlags {
>      USB_DEV_FLAG_IS_HOST,
>      USB_DEV_FLAG_MSOS_DESC_ENABLE,
>      USB_DEV_FLAG_MSOS_DESC_IN_USE,
> +    USB_DEV_FLAG_IS_SCSI_STORAGE,
>  };
>  
>  /* definition of a USB device */
> @@ -465,7 +466,6 @@ void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);
>  
>  /* usb-linux.c */
>  void hmp_info_usbhost(Monitor *mon, const QDict *qdict);
> -bool usb_host_dev_is_scsi_storage(USBDevice *usbdev);
>  
>  /* usb ports of the VM */
>  
> @@ -561,6 +561,11 @@ const char *usb_device_get_product_desc(USBDevice *dev);
>  
>  const USBDesc *usb_device_get_usb_desc(USBDevice *dev);
>  
> +static inline bool usb_device_is_scsi_storage(USBDevice *dev)
> +{
> +    return dev->flags & (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
> +}
> +
>  /* quirks.c */
>  
>  /* In bulk endpoints are streaming data sources (iow behave like isoc eps) */
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 4dd90b75cc52..f83a081af0f1 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -3106,7 +3106,7 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p, BusState *bus,
>       */
>      if (strcmp("usb-host", qdev_fw_name(dev)) == 0) {
>          USBDevice *usbdev = CAST(USBDevice, dev, TYPE_USB_DEVICE);
> -        if (usb_host_dev_is_scsi_storage(usbdev)) {
> +        if (usb_device_is_scsi_storage(usbdev)) {
>              return g_strdup_printf("storage@%s/disk", usbdev->port->path);
>          }
>      }
> diff --git a/hw/usb/dev-storage-bot.c b/hw/usb/dev-storage-bot.c
> index 6aad026d1133..68ebaca10c66 100644
> --- a/hw/usb/dev-storage-bot.c
> +++ b/hw/usb/dev-storage-bot.c
> @@ -32,6 +32,7 @@ static void usb_msd_bot_realize(USBDevice *dev, Error **errp)
>  
>      usb_desc_create_serial(dev);
>      usb_desc_init(dev);
> +    dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
>      if (d->hotplugged) {
>          s->dev.auto_attach = 0;
>      }
> diff --git a/hw/usb/dev-storage-classic.c b/hw/usb/dev-storage-classic.c
> index 00cb34b22f02..3d017a4e6791 100644
> --- a/hw/usb/dev-storage-classic.c
> +++ b/hw/usb/dev-storage-classic.c
> @@ -64,6 +64,7 @@ static void usb_msd_storage_realize(USBDevice *dev, Error **errp)
>  
>      usb_desc_create_serial(dev);
>      usb_desc_init(dev);
> +    dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
>      scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
>                   &usb_msd_scsi_info_storage, NULL);
>      scsi_dev = scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable,
> diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
> index d2bd85d3f6bb..263056231c79 100644
> --- a/hw/usb/dev-uas.c
> +++ b/hw/usb/dev-uas.c
> @@ -926,6 +926,7 @@ static void usb_uas_realize(USBDevice *dev, Error **errp)
>      QTAILQ_INIT(&uas->requests);
>      uas->status_bh = qemu_bh_new(usb_uas_send_status_bh, uas);
>  
> +    dev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
>      scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
>                   &usb_uas_scsi_info, NULL);
>  }
> diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
> index 2518306f527f..e6d21aa8e1d3 100644
> --- a/hw/usb/host-libusb.c
> +++ b/hw/usb/host-libusb.c
> @@ -770,6 +770,13 @@ static void usb_host_speed_compat(USBHostDevice *s)
>          for (i = 0; i < conf->bNumInterfaces; i++) {
>              for (a = 0; a < conf->interface[i].num_altsetting; a++) {
>                  intf = &conf->interface[i].altsetting[a];
> +
> +                if (intf->bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE &&
> +                    intf->bInterfaceSubClass == 6) { /* SCSI */
> +                    udev->flags |= (1 << USB_DEV_FLAG_IS_SCSI_STORAGE);
> +                    break;
> +                }
> +
>                  for (e = 0; e < intf->bNumEndpoints; e++) {
>                      endp = &intf->endpoint[e];
>                      type = endp->bmAttributes & 0x3;
> @@ -1893,35 +1900,6 @@ static void usb_host_auto_check(void *unused)
>      timer_mod(usb_auto_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 2000);
>  }
>  
> -/**
> - * Check whether USB host device has a USB mass storage SCSI interface
> - */
> -bool usb_host_dev_is_scsi_storage(USBDevice *ud)
> -{
> -    USBHostDevice *uhd = USB_HOST_DEVICE(ud);
> -    struct libusb_config_descriptor *conf;
> -    const struct libusb_interface_descriptor *intf;
> -    bool is_scsi_storage = false;
> -    int i;
> -
> -    if (!uhd || libusb_get_active_config_descriptor(uhd->dev, &conf) != 0) {
> -        return false;
> -    }
> -
> -    for (i = 0; i < conf->bNumInterfaces; i++) {
> -        intf = &conf->interface[i].altsetting[ud->altsetting[i]];
> -        if (intf->bInterfaceClass == LIBUSB_CLASS_MASS_STORAGE &&
> -            intf->bInterfaceSubClass == 6) {                 /* 6 means SCSI */
> -            is_scsi_storage = true;
> -            break;
> -        }
> -    }
> -
> -    libusb_free_config_descriptor(conf);
> -
> -    return is_scsi_storage;
> -}
> -
>  void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
>  {
>      libusb_device **devs = NULL;
> diff --git a/hw/usb/host-stub.c b/hw/usb/host-stub.c
> index 80809ceba542..bbe69baa390f 100644
> --- a/hw/usb/host-stub.c
> +++ b/hw/usb/host-stub.c
> @@ -38,8 +38,3 @@ void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
>  {
>      monitor_printf(mon, "USB host devices not supported\n");
>  }
> -
> -bool usb_host_dev_is_scsi_storage(USBDevice *ud)
> -{
> -    return false;
> -}

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/5] [RfC] monitor/hmp: command register support
  2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2021-06-22 12:49 ` [PATCH 5/5] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically Gerd Hoffmann
@ 2021-08-07 10:36 ` Markus Armbruster
  2021-08-09  9:16   ` Gerd Hoffmann
  5 siblings, 1 reply; 10+ messages in thread
From: Markus Armbruster @ 2021-08-07 10:36 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Richard Henderson, qemu-devel, Dr. David Alan Gilbert, Greg Kurz,
	qemu-ppc, Paolo Bonzini, David Gibson

Gerd Hoffmann <kraxel@redhat.com> writes:

> Helps making qemu more modular,
> see commit messages for details.
>
> Depends on the "modules: add meta-data database" patch series.

This series is about HMP.  Do we have equivalent functionality for QMP
already?

I apologize for not looking at this sooner.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/5] [RfC] monitor/hmp: command register support
  2021-08-07 10:36 ` [PATCH 0/5] [RfC] monitor/hmp: command register support Markus Armbruster
@ 2021-08-09  9:16   ` Gerd Hoffmann
  0 siblings, 0 replies; 10+ messages in thread
From: Gerd Hoffmann @ 2021-08-09  9:16 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Richard Henderson, qemu-devel, Dr. David Alan Gilbert, Greg Kurz,
	qemu-ppc, Paolo Bonzini, David Gibson

On Sat, Aug 07, 2021 at 12:36:13PM +0200, Markus Armbruster wrote:
> Gerd Hoffmann <kraxel@redhat.com> writes:
> 
> > Helps making qemu more modular,
> > see commit messages for details.
> >
> > Depends on the "modules: add meta-data database" patch series.
> 
> This series is about HMP.  Do we have equivalent functionality for QMP
> already?

Didn't check as the commands I've needed it this for are hmp-only.
But, yes, when going forward with building more code modular we might
need this for qmp too at some point ...

take care,
  Gerd



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-08-09  9:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 12:49 [PATCH 0/5] [RfC] monitor/hmp: command register support Gerd Hoffmann
2021-06-22 12:49 ` [PATCH 1/5] monitor: allow register hmp commands Gerd Hoffmann
2021-06-22 13:13   ` Greg Kurz
2021-06-22 12:49 ` [PATCH 2/5] usb: drop usb_host_dev_is_scsi_storage hook Gerd Hoffmann
2021-06-23  1:51   ` David Gibson
2021-06-22 12:49 ` [PATCH 3/5] monitor/usb: register 'info usbhost' dynamically Gerd Hoffmann
2021-06-22 12:49 ` [PATCH 4/5] usb: build usb-host as module Gerd Hoffmann
2021-06-22 12:49 ` [PATCH 5/5] monitor/tcg: move tcg hmp commands to accel/tcg, register them dynamically Gerd Hoffmann
2021-08-07 10:36 ` [PATCH 0/5] [RfC] monitor/hmp: command register support Markus Armbruster
2021-08-09  9:16   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).