From patchwork Tue Oct 5 14:40:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alon Levy X-Patchwork-Id: 66836 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 90B9BB70CB for ; Wed, 6 Oct 2010 01:50:26 +1100 (EST) Received: from localhost ([127.0.0.1]:59337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P38qU-0001KP-PC for incoming@patchwork.ozlabs.org; Tue, 05 Oct 2010 10:50:22 -0400 Received: from [140.186.70.92] (port=42652 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P38Va-0001QB-4l for qemu-devel@nongnu.org; Tue, 05 Oct 2010 10:29:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P38UK-0001HL-EQ for qemu-devel@nongnu.org; Tue, 05 Oct 2010 10:28:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32054) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P38UK-0001H2-5Y for qemu-devel@nongnu.org; Tue, 05 Oct 2010 10:27:28 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o95ERQBq013579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 5 Oct 2010 10:27:26 -0400 Received: from localhost (dhcp-1-173.tlv.redhat.com [10.35.1.173]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o95ERNc2027218 for ; Tue, 5 Oct 2010 10:27:25 -0400 Date: Tue, 5 Oct 2010 16:40:29 +0200 From: Alon Levy To: qemu-devel@nongnu.org Message-Id: <20101005164029.92f21cb3.alevy@redhat.com> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH] monitor: add usb_detach 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 Signed-off-by: Alon Levy --- qemu-monitor.hx | 17 +++++++++++++++++ sysemu.h | 1 + vl.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 0 deletions(-) diff --git a/qemu-monitor.hx b/qemu-monitor.hx index 49bcd8d..9c792a9 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -711,6 +711,23 @@ command @code{info usb} to see the devices you can remove. ETEXI { + .name = "usb_detach", + .args_type = "devname:s", + .params = "device", + .help = "detach USB device 'bus.addr'", + .mhandler.cmd = do_usb_detach, + }, + +STEXI +@item usb_detach @var{devname} +@findex usb_detach + +Detach the USB device @var{devname} from the QEMU virtual USB +hub. @var{devname} has the syntax @code{bus.addr}. Use the monitor +command @code{info usb} to see the devices you can detach. +ETEXI + + { .name = "device_add", .args_type = "device:O", .params = "driver[,prop=value][,...]", diff --git a/sysemu.h b/sysemu.h index a1f6466..ac68863 100644 --- a/sysemu.h +++ b/sysemu.h @@ -183,6 +183,7 @@ extern struct soundhw soundhw[]; void do_usb_add(Monitor *mon, const QDict *qdict); void do_usb_del(Monitor *mon, const QDict *qdict); +void do_usb_detach(Monitor *mon, const QDict *qdict); void usb_info(Monitor *mon); void rtc_change_mon_event(struct tm *tm); diff --git a/vl.c b/vl.c index d352d18..6cfa009 100644 --- a/vl.c +++ b/vl.c @@ -891,6 +891,47 @@ void do_usb_del(Monitor *mon, const QDict *qdict) } } +static USBDevice *usb_device_from_bus_dot_addr(const char *devname) +{ + int bus_num, addr; + const char *p; + USBBus *bus; + USBPort *port; + + if (!usb_enabled) { + return NULL; + } + p = strchr(devname, '.'); + if (!p) { + return NULL; + } + bus_num = strtoul(devname, NULL, 0); + addr = strtoul(p + 1, NULL, 0); + bus = usb_bus_find(bus_num); + if (!bus) { + return NULL; + } + QTAILQ_FOREACH(port, &bus->used, next) { + if (port->dev->addr == addr) { + break; + } + } + if (!port) { + return NULL; + } + return port->dev; +} + +void do_usb_detach(Monitor *mon, const QDict *qdict) +{ + const char *devname = qdict_get_str(qdict, "devname"); + USBDevice *dev = usb_device_from_bus_dot_addr(devname); + + if (dev == NULL || usb_device_detach(dev) < 0) { + error_report("could not detach USB device '%s'", devname); + } +} + /***********************************************************/ /* PCMCIA/Cardbus */