From patchwork Fri Oct 23 09:26:02 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 36772 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 27C77B7BBC for ; Fri, 23 Oct 2009 20:36:41 +1100 (EST) Received: from localhost ([127.0.0.1]:52838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1GZa-0002G8-2E for incoming@patchwork.ozlabs.org; Fri, 23 Oct 2009 05:36:38 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1GPY-00080P-2p for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1GPS-0007yD-OA for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:14 -0400 Received: from [199.232.76.173] (port=40162 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1GPS-0007xq-8o for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38273) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1GPR-0002Ad-Km for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:09 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9N9Q89B027935 for ; Fri, 23 Oct 2009 05:26:09 -0400 Received: from zweiblum.home.kraxel.org (vpn2-9-162.ams2.redhat.com [10.36.9.162]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9N9Q5ND005925; Fri, 23 Oct 2009 05:26:06 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 299337010B; Fri, 23 Oct 2009 11:26:04 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 23 Oct 2009 11:26:02 +0200 Message-Id: <1256289963-26430-5-git-send-email-kraxel@redhat.com> In-Reply-To: <1256289963-26430-1-git-send-email-kraxel@redhat.com> References: <1256289963-26430-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 4/5] usb: make attach optional. 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 Add a auto_attach field to USBDevice, which is enabled by default. USB drivers can clear this field in case they do *not* want the device being attached (i.e. plugged into a usb port) automatically after successfull init(). Use cases: * attaching encrypted mass storage devices (see next patch). * maybe also -usbdevice host:$vendorid:$productid Signed-off-by: Gerd Hoffmann --- hw/usb-bus.c | 7 +++++-- hw/usb.h | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 28b517f..4d0c10d 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -46,7 +46,7 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) pstrcpy(dev->devname, sizeof(dev->devname), qdev->info->name); dev->info = info; rc = dev->info->init(dev); - if (rc == 0) + if (rc == 0 && dev->auto_attach) usb_device_attach(dev); return rc; } @@ -82,6 +82,7 @@ void usb_qdev_register_many(USBDeviceInfo *info) USBDevice *usb_create(USBBus *bus, const char *name) { DeviceState *dev; + USBDevice *usb; #if 1 /* temporary stopgap until all usb is properly qdev-ified */ @@ -95,7 +96,9 @@ USBDevice *usb_create(USBBus *bus, const char *name) #endif dev = qdev_create(&bus->qbus, name); - return DO_UPCAST(USBDevice, qdev, dev); + usb = DO_UPCAST(USBDevice, qdev, dev); + usb->auto_attach = 1; + return usb; } USBDevice *usb_create_simple(USBBus *bus, const char *name) diff --git a/hw/usb.h b/hw/usb.h index a875d5b..a01f334 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -133,6 +133,7 @@ struct USBDevice { int speed; uint8_t addr; char devname[32]; + int auto_attach; int attached; int state;