v1->v2 changes: * fixed help text (consistent name for parameter) * added configure flag, also enabled with --enable-debug --- configure | 9 +++++++++ hmp-commands.hx | 38 ++++++++++++++++++++++++++++++++++++++ sysemu.h | 4 ++++ vl.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/configure b/configure index a869777..229a71a 100755 --- a/configure +++ b/configure @@ -292,6 +292,7 @@ gprof="no" debug_tcg="no" debug_mon="no" debug="no" +usb_monitor_attach_detach="no" strip_opt="yes" bigendian="no" mingw32="no" @@ -590,8 +591,11 @@ for opt do debug_tcg="yes" debug_mon="yes" debug="yes" + usb_monitor_attach_detach="yes" strip_opt="no" ;; + --enable-usb-mon-detach) usb_monitor_attach_detach="yes" + ;; --enable-sparse) sparse="yes" ;; --disable-sparse) sparse="no" @@ -854,6 +858,7 @@ echo " --sysconfdir=PATH install config in PATH/qemu" echo " --enable-debug-tcg enable TCG debugging" echo " --disable-debug-tcg disable TCG debugging (default)" echo " --enable-debug enable common debug build options" +echo " --enable-usb-mon-detach enable usb monitor attach & detach commands" echo " --enable-sparse enable sparse checker" echo " --disable-sparse disable sparse checker (default)" echo " --disable-strip disable stripping binaries" @@ -2311,6 +2316,7 @@ echo "host big endian $bigendian" echo "target list $target_list" echo "tcg debug enabled $debug_tcg" echo "Mon debug enabled $debug_mon" +echo "usb mon detach $usb_monitor_attach_detach" echo "gprof enabled $gprof" echo "sparse enabled $sparse" echo "strip binaries $strip_opt" @@ -2402,6 +2408,9 @@ fi if test "$debug" = "yes" ; then echo "CONFIG_DEBUG_EXEC=y" >> $config_host_mak fi +if test "$usb_monitor_attach_detach" = yes ; then + echo "CONFIG_USB_MONITOR_ATTACH_DETACH=y" >> $config_host_mak +fi if test "$strip_opt" = "yes" ; then echo "STRIP=${strip}" >> $config_host_mak fi diff --git a/hmp-commands.hx b/hmp-commands.hx index 81999aa..3014b17 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -516,6 +516,44 @@ hub. @var{devname} has the syntax @code{bus.addr}. Use the monitor command @code{info usb} to see the devices you can remove. ETEXI +#ifdef CONFIG_USB_MONITOR_ATTACH_DETACH + { + .name = "usb_attach", + .args_type = "id:s", + .params = "device", + .help = "attach USB device by id", + .mhandler.cmd = do_usb_attach, + }, + +STEXI +...@item usb_attach @var{id} +...@findex usb_attach + +Attach the USB device with id @var{id} to the QEMU virtual USB +hub. @var{id} should be a previously detached usb device. Use +...@code{info qtree} to see devices that can be attached. This +command is for debugging usage only. +ETEXI + + { + .name = "usb_detach", + .args_type = "id:s", + .params = "device", + .help = "remove USB device by id", + .mhandler.cmd = do_usb_detach, + }, + +STEXI +...@item usb_detach @var{id} +...@findex usb_detach + +Detach the USB device @var{id} from the QEMU virtual USB +hub. Use the monitor command @code{info usb} to see the +devices you can detach. This command is for debugging usage +only. +ETEXI +#endif // CONFIG_USB_MONITOR_ATTACH_DETACH + { .name = "device_add", .args_type = "device:O", diff --git a/sysemu.h b/sysemu.h index b81a70e..2e1df04 100644 --- a/sysemu.h +++ b/sysemu.h @@ -182,6 +182,10 @@ extern struct soundhw soundhw[]; void do_usb_add(Monitor *mon, const QDict *qdict); void do_usb_del(Monitor *mon, const QDict *qdict); +#ifdef CONFIG_USB_MONITOR_ATTACH_DETACH +void do_usb_attach(Monitor *mon, const QDict *qdict); +void do_usb_detach(Monitor *mon, const QDict *qdict); +#endif void usb_info(Monitor *mon); void rtc_change_mon_event(struct tm *tm); diff --git a/vl.c b/vl.c index df414ef..f233c84 100644 --- a/vl.c +++ b/vl.c @@ -894,6 +894,39 @@ void do_usb_del(Monitor *mon, const QDict *qdict) } } +#ifdef CONFIG_USB_MONITOR_ATTACH_DETACH +void do_usb_attach(Monitor *mon, const QDict *qdict) +{ + const char *id = qdict_get_str(qdict, "id"); + USBDevice *dev; + + dev = usb_device_by_id(id); + + if (dev == NULL) { + error_report("no such USB device '%s'", id); + return; + } + if (usb_device_attach(dev) < 0) { + error_report("could not attach USB device '%s'", id); + } +} + +void do_usb_detach(Monitor *mon, const QDict *qdict) +{ + const char *id = qdict_get_str(qdict, "id"); + USBDevice *dev; + + dev = usb_device_by_id(id); + if (dev == NULL) { + error_report("no such USB device '%s'", id); + return; + } + if (usb_device_detach(dev) < 0) { + error_report("could not detach USB device '%s'", id); + } +} +#endif // CONFIG_USB_MONITOR_ATTACH_DETACH + /***********************************************************/ /* PCMCIA/Cardbus */ -- 1.7.3.1