From patchwork Thu Oct 21 06:36:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 68525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7E1311007D3 for ; Thu, 21 Oct 2010 17:44:45 +1100 (EST) Received: from localhost ([127.0.0.1]:53053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8otG-0001PL-4c for incoming@patchwork.ozlabs.org; Thu, 21 Oct 2010 02:44:42 -0400 Received: from [140.186.70.92] (port=44311 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8olU-0005zY-4Q for qemu-devel@nongnu.org; Thu, 21 Oct 2010 02:36:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8olS-0001Uf-WC for qemu-devel@nongnu.org; Thu, 21 Oct 2010 02:36:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8olS-0001UV-Or for qemu-devel@nongnu.org; Thu, 21 Oct 2010 02:36:38 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9L6acEP003143 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 21 Oct 2010 02:36:38 -0400 Received: from playa.redhat.com (vpn-6-82.tlv.redhat.com [10.35.6.82]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9L6aVSY001577 for ; Thu, 21 Oct 2010 02:36:37 -0400 From: Alon Levy To: qemu-devel@nongnu.org Date: Thu, 21 Oct 2010 08:36:31 +0200 Message-Id: <1287642991-21114-4-git-send-email-alevy@redhat.com> In-Reply-To: <1287642991-21114-1-git-send-email-alevy@redhat.com> References: <1287642991-21114-1-git-send-email-alevy@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 3/3] monitor: add usb_attach and usb_detach (v2) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 */