qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 4/5] usb: make attach optional.
Date: Fri, 23 Oct 2009 11:26:02 +0200	[thread overview]
Message-ID: <1256289963-26430-5-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1256289963-26430-1-git-send-email-kraxel@redhat.com>

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 <kraxel@redhat.com>
---
 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;
-- 
1.6.2.5

  parent reply	other threads:[~2009-10-23  9:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-23  9:25 [Qemu-devel] [PATCH 0/5] use qdev for -usbdevice Gerd Hoffmann
2009-10-23  9:25 ` [Qemu-devel] [PATCH 1/5] usb core: " Gerd Hoffmann
2009-10-23  9:26 ` [Qemu-devel] [PATCH 2/5] usb-hid: " Gerd Hoffmann
2009-10-23  9:26 ` [Qemu-devel] [PATCH 3/5] usb-serial and braille: " Gerd Hoffmann
2009-10-23  9:26 ` Gerd Hoffmann [this message]
2009-10-23  9:26 ` [Qemu-devel] [PATCH 5/5] usb-storage: " Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1256289963-26430-5-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).