qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/5] use qdev for -usbdevice
@ 2009-10-23  9:25 Gerd Hoffmann
  2009-10-23  9:25 ` [Qemu-devel] [PATCH 1/5] usb core: " Gerd Hoffmann
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2009-10-23  9:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

This patch series changes the way the -usbdevice switch (and the usb_add
monitor command) is handled.  Instead of hard-coding stuff in vl.c it
is integrated with qdev by adding new fields to USBDeviceInfo.  First
patch adds the infrastructure.  Follwing patches switch over the usb
drivers to the new way of handling things.  Not converted (yet) are:

  * bt: bluetooth is not qdev-ified at all, needs investigation.
  * host: big project, especially the auto-add-by-id stuff.
  * net: too many net patches in flight right now.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 1/5] usb core: use qdev for -usbdevice
  2009-10-23  9:25 [Qemu-devel] [PATCH 0/5] use qdev for -usbdevice Gerd Hoffmann
@ 2009-10-23  9:25 ` Gerd Hoffmann
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 2/5] usb-hid: " Gerd Hoffmann
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2009-10-23  9:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

This patchs adds infrastructure to handle -usbdevice via qdev callbacks.
USBDeviceInfo gets a name field (for the -usbdevice driver name) and a
callback for -usbdevice parameter parsing.

The new usbdevice_create() function walks the qdev driver list and looks
for a usb driver with a matching name.  When a parameter parsing
callback is present it is called, otherwise the device is created via
usb_create_simple().

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c    |    2 +-
 hw/qdev.h    |    1 +
 hw/usb-bus.c |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb.h     |    5 +++++
 vl.c         |    5 +++++
 5 files changed, 59 insertions(+), 1 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 20f931c..b0d92d2 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -35,7 +35,7 @@ static int qdev_hotplug = 0;
 /* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
 static BusState *main_system_bus;
 
-static DeviceInfo *device_info_list;
+DeviceInfo *device_info_list;
 
 static BusState *qbus_find_recursive(BusState *bus, const char *name,
                                      const BusInfo *info);
diff --git a/hw/qdev.h b/hw/qdev.h
index b79f3e3..738470b 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -140,6 +140,7 @@ struct DeviceInfo {
     BusInfo *bus_info;
     struct DeviceInfo *next;
 };
+extern DeviceInfo *device_info_list;
 
 void qdev_register(DeviceInfo *info);
 
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 98987a1..28b517f 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -252,3 +252,50 @@ void usb_info(Monitor *mon)
     }
 }
 
+/* handle legacy -usbdevice cmd line option */
+USBDevice *usbdevice_create(const char *cmdline)
+{
+    USBBus *bus = usb_bus_find(-1 /* any */);
+    DeviceInfo *info;
+    USBDeviceInfo *usb;
+    char driver[32], *params;
+    int len;
+
+    params = strchr(cmdline,':');
+    if (params) {
+        params++;
+        len = params - cmdline;
+        if (len > sizeof(driver))
+            len = sizeof(driver);
+        pstrcpy(driver, len, cmdline);
+    } else {
+        pstrcpy(driver, sizeof(driver), cmdline);
+    }
+
+    for (info = device_info_list; info != NULL; info = info->next) {
+        if (info->bus_info != &usb_bus_info)
+            continue;
+        usb = DO_UPCAST(USBDeviceInfo, qdev, info);
+        if (usb->usbdevice_name == NULL)
+            continue;
+        if (strcmp(usb->usbdevice_name, driver) != 0)
+            continue;
+        break;
+    }
+    if (info == NULL) {
+#if 0
+        /* no error because some drivers are not converted (yet) */
+        qemu_error("usbdevice %s not found\n", driver);
+#endif
+        return NULL;
+    }
+
+    if (!usb->usbdevice_init) {
+        if (params) {
+            qemu_error("usbdevice %s accepts no params\n", driver);
+            return NULL;
+        }
+        return usb_create_simple(bus, usb->qdev.name);
+    }
+    return usb->usbdevice_init(params);
+}
diff --git a/hw/usb.h b/hw/usb.h
index be4fcf6..62362a7 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -183,6 +183,10 @@ struct USBDeviceInfo {
      * Returns length or one of the USB_RET_ codes.
      */
     int (*handle_data)(USBDevice *dev, USBPacket *p);
+
+    /* handle legacy -usbdevice command line options */
+    const char *usbdevice_name;
+    USBDevice *(*usbdevice_init)(const char *params);
 };
 
 typedef void (*usb_attachfn)(USBPort *port, USBDevice *dev);
@@ -309,6 +313,7 @@ void usb_qdev_register(USBDeviceInfo *info);
 void usb_qdev_register_many(USBDeviceInfo *info);
 USBDevice *usb_create(USBBus *bus, const char *name);
 USBDevice *usb_create_simple(USBBus *bus, const char *name);
+USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
                        usb_attachfn attach);
 void usb_unregister_port(USBBus *bus, USBPort *port);
diff --git a/vl.c b/vl.c
index eb2744e..30b5306 100644
--- a/vl.c
+++ b/vl.c
@@ -2562,6 +2562,11 @@ static int usb_device_add(const char *devname, int is_hotplug)
     if (!usb_enabled)
         return -1;
 
+    /* drivers with .usbdevice_name entry in USBDeviceInfo */
+    dev = usbdevice_create(devname);
+    if (dev)
+        goto done;
+
     /* simple devices which don't need extra care */
     for (i = 0; i < ARRAY_SIZE(usbdevs); i++) {
         if (strcmp(devname, usbdevs[i].name) != 0)
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 2/5] usb-hid: use qdev for -usbdevice
  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 ` Gerd Hoffmann
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 3/5] usb-serial and braille: " Gerd Hoffmann
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2009-10-23  9:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-hid.c   |    3 +++
 hw/usb-wacom.c |    1 +
 vl.c           |   29 -----------------------------
 3 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index d1cc45e..f4a2a48 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -882,6 +882,7 @@ static struct USBDeviceInfo hid_info[] = {
     {
         .qdev.name      = "QEMU USB Tablet",
         .qdev.alias     = "usb-tablet",
+        .usbdevice_name = "tablet",
         .qdev.size      = sizeof(USBHIDState),
         .init           = usb_tablet_initfn,
         .handle_packet  = usb_generic_handle_packet,
@@ -892,6 +893,7 @@ static struct USBDeviceInfo hid_info[] = {
     },{
         .qdev.name      = "QEMU USB Mouse",
         .qdev.alias     = "usb-mouse",
+        .usbdevice_name = "mouse",
         .qdev.size      = sizeof(USBHIDState),
         .init           = usb_mouse_initfn,
         .handle_packet  = usb_generic_handle_packet,
@@ -902,6 +904,7 @@ static struct USBDeviceInfo hid_info[] = {
     },{
         .qdev.name      = "QEMU USB Keyboard",
         .qdev.alias     = "usb-kbd",
+        .usbdevice_name = "keyboard",
         .qdev.size      = sizeof(USBHIDState),
         .init           = usb_keyboard_initfn,
         .handle_packet  = usb_generic_handle_packet,
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index fa97db2..ef61376 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -411,6 +411,7 @@ static int usb_wacom_initfn(USBDevice *dev)
 static struct USBDeviceInfo wacom_info = {
     .qdev.name      = "QEMU PenPartner Tablet",
     .qdev.alias     = "wacom-tablet",
+    .usbdevice_name = "wacom-tablet",
     .qdev.size      = sizeof(USBWacomState),
     .init           = usb_wacom_initfn,
     .handle_packet  = usb_generic_handle_packet,
diff --git a/vl.c b/vl.c
index 30b5306..52ab14f 100644
--- a/vl.c
+++ b/vl.c
@@ -2533,31 +2533,10 @@ static void usb_msd_password_cb(void *opaque, int err)
         dev->info->handle_destroy(dev);
 }
 
-static struct {
-    const char *name;
-    const char *qdev;
-} usbdevs[] = {
-    {
-        .name = "mouse",
-        .qdev = "QEMU USB Mouse",
-    },{
-        .name = "tablet",
-        .qdev = "QEMU USB Tablet",
-    },{
-        .name = "keyboard",
-        .qdev = "QEMU USB Keyboard",
-    },{
-        .name = "wacom-tablet",
-        .qdev = "QEMU PenPartner Tablet",
-    }
-};
-
 static int usb_device_add(const char *devname, int is_hotplug)
 {
     const char *p;
-    USBBus *bus = usb_bus_find(-1 /* any */);
     USBDevice *dev = NULL;
-    int i;
 
     if (!usb_enabled)
         return -1;
@@ -2567,14 +2546,6 @@ static int usb_device_add(const char *devname, int is_hotplug)
     if (dev)
         goto done;
 
-    /* simple devices which don't need extra care */
-    for (i = 0; i < ARRAY_SIZE(usbdevs); i++) {
-        if (strcmp(devname, usbdevs[i].name) != 0)
-            continue;
-        dev = usb_create_simple(bus, usbdevs[i].qdev);
-        goto done;
-    }
-
     /* the other ones */
     if (strstart(devname, "host:", &p)) {
         dev = usb_host_device_open(p);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 3/5] usb-serial and braille: use qdev for -usbdevice
  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 ` Gerd Hoffmann
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 4/5] usb: make attach optional Gerd Hoffmann
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 5/5] usb-storage: use qdev for -usbdevice Gerd Hoffmann
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2009-10-23  9:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/baum.c       |    6 ----
 hw/baum.h       |    3 --
 hw/usb-serial.c |   85 ++++++++++++++++++++++++++++++++++++++++++-------------
 hw/usb.h        |    3 --
 vl.c            |    6 ----
 5 files changed, 65 insertions(+), 38 deletions(-)

diff --git a/hw/baum.c b/hw/baum.c
index c66e737..8a12985 100644
--- a/hw/baum.c
+++ b/hw/baum.c
@@ -627,9 +627,3 @@ fail_handle:
     free(baum);
     return NULL;
 }
-
-USBDevice *usb_baum_init(void)
-{
-    /* USB Product ID of Super Vario 40 */
-    return usb_serial_init("productid=FE72:braille");
-}
diff --git a/hw/baum.h b/hw/baum.h
index 39ca4b1..8af710f 100644
--- a/hw/baum.h
+++ b/hw/baum.h
@@ -22,8 +22,5 @@
  * THE SOFTWARE.
  */
 
-/* usb device */
-USBDevice *usb_baum_init(void);
-
 /* char device */
 CharDriverState *chr_baum_init(QemuOpts *opts);
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index d02f6b2..223d4c3 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -90,8 +90,8 @@ do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0)
 
 typedef struct {
     USBDevice dev;
-    uint16_t vendorid;
-    uint16_t productid;
+    uint32_t vendorid;
+    uint32_t productid;
     uint8_t recv_buf[RECV_BUF];
     uint16_t recv_ptr;
     uint16_t recv_used;
@@ -527,15 +527,18 @@ static int usb_serial_initfn(USBDevice *dev)
 {
     USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
     s->dev.speed = USB_SPEED_FULL;
+
+    qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
+                          usb_serial_event, s);
+    usb_serial_handle_reset(dev);
     return 0;
 }
 
-USBDevice *usb_serial_init(const char *filename)
+static USBDevice *usb_serial_init(const char *filename)
 {
     USBDevice *dev;
-    USBSerialState *s;
     CharDriverState *cdrv;
-    unsigned short vendorid = 0x0403, productid = 0x6001;
+    uint32_t vendorid = 0, productid = 0;
     char label[32];
     static int index;
 
@@ -545,26 +548,26 @@ USBDevice *usb_serial_init(const char *filename)
         if (strstart(filename, "vendorid=", &p)) {
             vendorid = strtol(p, &e, 16);
             if (e == p || (*e && *e != ',' && *e != ':')) {
-                printf("bogus vendor ID %s\n", p);
+                qemu_error("bogus vendor ID %s\n", p);
                 return NULL;
             }
             filename = e;
         } else if (strstart(filename, "productid=", &p)) {
             productid = strtol(p, &e, 16);
             if (e == p || (*e && *e != ',' && *e != ':')) {
-                printf("bogus product ID %s\n", p);
+                qemu_error("bogus product ID %s\n", p);
                 return NULL;
             }
             filename = e;
         } else {
-            printf("unrecognized serial USB option %s\n", filename);
+            qemu_error("unrecognized serial USB option %s\n", filename);
             return NULL;
         }
         while(*filename == ',')
             filename++;
     }
     if (!*filename) {
-        printf("character device specification needed\n");
+        qemu_error("character device specification needed\n");
         return NULL;
     }
     filename++;
@@ -574,23 +577,56 @@ USBDevice *usb_serial_init(const char *filename)
     if (!cdrv)
         return NULL;
 
-    dev = usb_create_simple(NULL /* FIXME */, "QEMU USB Serial");
-    s = DO_UPCAST(USBSerialState, dev, dev);
-    s->cs = cdrv;
-    s->vendorid = vendorid;
-    s->productid = productid;
-    snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Serial(%.16s)",
-             filename);
+    dev = usb_create(NULL /* FIXME */, "QEMU USB Serial");
+    qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
+    if (vendorid)
+        qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid);
+    if (productid)
+        qdev_prop_set_uint16(&dev->qdev, "productid", productid);
+    qdev_init(&dev->qdev);
 
-    qemu_chr_add_handlers(cdrv, usb_serial_can_read, usb_serial_read,
-                          usb_serial_event, s);
+    return dev;
+}
+
+static USBDevice *usb_braille_init(const char *unused)
+{
+    USBDevice *dev;
+    CharDriverState *cdrv;
+
+    cdrv = qemu_chr_open("braille", "braille", NULL);
+    if (!cdrv)
+        return NULL;
 
-    usb_serial_handle_reset((USBDevice *)s);
-    return (USBDevice *)s;
+    dev = usb_create(NULL /* FIXME */, "QEMU USB Braille");
+    qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
+    qdev_init(&dev->qdev);
+
+    return dev;
 }
 
 static struct USBDeviceInfo serial_info = {
     .qdev.name      = "QEMU USB Serial",
+    .qdev.alias     = "usb-serial",
+    .qdev.size      = sizeof(USBSerialState),
+    .init           = usb_serial_initfn,
+    .handle_packet  = usb_generic_handle_packet,
+    .handle_reset   = usb_serial_handle_reset,
+    .handle_control = usb_serial_handle_control,
+    .handle_data    = usb_serial_handle_data,
+    .handle_destroy = usb_serial_handle_destroy,
+    .usbdevice_name = "serial",
+    .usbdevice_init = usb_serial_init,
+    .qdev.props     = (Property[]) {
+        DEFINE_PROP_CHR("chardev",     USBSerialState, cs),
+        DEFINE_PROP_HEX32("vendorid",  USBSerialState, vendorid,  0x0403),
+        DEFINE_PROP_HEX32("productid", USBSerialState, productid, 0x6001),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static struct USBDeviceInfo braille_info = {
+    .qdev.name      = "QEMU USB Braille",
+    .qdev.alias     = "usb-braille",
     .qdev.size      = sizeof(USBSerialState),
     .init           = usb_serial_initfn,
     .handle_packet  = usb_generic_handle_packet,
@@ -598,10 +634,19 @@ static struct USBDeviceInfo serial_info = {
     .handle_control = usb_serial_handle_control,
     .handle_data    = usb_serial_handle_data,
     .handle_destroy = usb_serial_handle_destroy,
+    .usbdevice_name = "braille",
+    .usbdevice_init = usb_braille_init,
+    .qdev.props     = (Property[]) {
+        DEFINE_PROP_CHR("chardev",     USBSerialState, cs),
+        DEFINE_PROP_HEX32("vendorid",  USBSerialState, vendorid,  0x0403),
+        DEFINE_PROP_HEX32("productid", USBSerialState, productid, 0xfe72),
+        DEFINE_PROP_END_OF_LIST(),
+    },
 };
 
 static void usb_serial_register_devices(void)
 {
     usb_qdev_register(&serial_info);
+    usb_qdev_register(&braille_info);
 }
 device_init(usb_serial_register_devices)
diff --git a/hw/usb.h b/hw/usb.h
index 62362a7..a875d5b 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -265,9 +265,6 @@ USBDevice *usb_net_init(NICInfo *nd);
 /* usb-bt.c */
 USBDevice *usb_bt_init(HCIInfo *hci);
 
-/* usb-serial.c */
-USBDevice *usb_serial_init(const char *filename);
-
 /* usb ports of the VM */
 
 #define VM_USB_HUB_SIZE 8
diff --git a/vl.c b/vl.c
index 52ab14f..64761cf 100644
--- a/vl.c
+++ b/vl.c
@@ -2564,12 +2564,6 @@ static int usb_device_add(const char *devname, int is_hotplug)
                 return 0;
             }
         }
-    } else if (strstart(devname, "serial:", &p)) {
-        dev = usb_serial_init(p);
-#ifdef CONFIG_BRLAPI
-    } else if (!strcmp(devname, "braille")) {
-        dev = usb_baum_init();
-#endif
     } else if (strstart(devname, "net:", &p)) {
         QemuOpts *opts;
         int idx;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 4/5] usb: make attach optional.
  2009-10-23  9:25 [Qemu-devel] [PATCH 0/5] use qdev for -usbdevice Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 3/5] usb-serial and braille: " Gerd Hoffmann
@ 2009-10-23  9:26 ` Gerd Hoffmann
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 5/5] usb-storage: use qdev for -usbdevice Gerd Hoffmann
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2009-10-23  9:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH 5/5] usb-storage: use qdev for -usbdevice
  2009-10-23  9:25 [Qemu-devel] [PATCH 0/5] use qdev for -usbdevice Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2009-10-23  9:26 ` [Qemu-devel] [PATCH 4/5] usb: make attach optional Gerd Hoffmann
@ 2009-10-23  9:26 ` Gerd Hoffmann
  4 siblings, 0 replies; 6+ messages in thread
From: Gerd Hoffmann @ 2009-10-23  9:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Hook up usb_msd_init.

Also rework handling of encrypted block devices,
move the code out vl.c.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-msd.c |   33 +++++++++++++++++++++++++--------
 hw/usb.h     |    4 ----
 vl.c         |   25 -------------------------
 3 files changed, 25 insertions(+), 37 deletions(-)

diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index dd3010e..8dc494f 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -14,6 +14,7 @@
 #include "block.h"
 #include "scsi-disk.h"
 #include "console.h"
+#include "monitor.h"
 
 //#define DEBUG_MSD
 
@@ -508,6 +509,16 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
     return ret;
 }
 
+static void usb_msd_password_cb(void *opaque, int err)
+{
+    MSDState *s = opaque;
+
+    if (!err)
+        usb_device_attach(&s->dev);
+    else
+        qdev_unplug(&s->dev.qdev);
+}
+
 static int usb_msd_initfn(USBDevice *dev)
 {
     MSDState *s = DO_UPCAST(MSDState, dev, dev);
@@ -522,10 +533,21 @@ static int usb_msd_initfn(USBDevice *dev)
     s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, s->dinfo, 0);
     s->bus.qbus.allow_hotplug = 0;
     usb_msd_handle_reset(dev);
+
+    if (bdrv_key_required(s->dinfo->bdrv)) {
+        if (s->dev.qdev.hotplugged) {
+            monitor_read_bdrv_key_start(cur_mon, s->dinfo->bdrv,
+                                        usb_msd_password_cb, s);
+            s->dev.auto_attach = 0;
+        } else {
+            autostart = 0;
+        }
+    }
+
     return 0;
 }
 
-USBDevice *usb_msd_init(const char *filename)
+static USBDevice *usb_msd_init(const char *filename)
 {
     static int nr=0;
     char id[8];
@@ -577,13 +599,6 @@ USBDevice *usb_msd_init(const char *filename)
     return dev;
 }
 
-BlockDriverState *usb_msd_get_bdrv(USBDevice *dev)
-{
-    MSDState *s = (MSDState *)dev;
-
-    return s->dinfo->bdrv;
-}
-
 static struct USBDeviceInfo msd_info = {
     .qdev.name      = "QEMU USB MSD",
     .qdev.alias     = "usb-storage",
@@ -593,6 +608,8 @@ static struct USBDeviceInfo msd_info = {
     .handle_reset   = usb_msd_handle_reset,
     .handle_control = usb_msd_handle_control,
     .handle_data    = usb_msd_handle_data,
+    .usbdevice_name = "disk",
+    .usbdevice_init = usb_msd_init,
     .qdev.props     = (Property[]) {
         DEFINE_PROP_DRIVE("drive", MSDState, dinfo),
         DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/usb.h b/hw/usb.h
index a01f334..351c466 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -256,10 +256,6 @@ void usb_host_info(Monitor *mon);
 /* usb-hid.c */
 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
 
-/* usb-msd.c */
-USBDevice *usb_msd_init(const char *filename);
-BlockDriverState *usb_msd_get_bdrv(USBDevice *dev);
-
 /* usb-net.c */
 USBDevice *usb_net_init(NICInfo *nd);
 
diff --git a/vl.c b/vl.c
index 64761cf..994065c 100644
--- a/vl.c
+++ b/vl.c
@@ -2523,16 +2523,6 @@ static void smp_parse(const char *optarg)
 /***********************************************************/
 /* USB devices */
 
-static void usb_msd_password_cb(void *opaque, int err)
-{
-    USBDevice *dev = opaque;
-
-    if (!err)
-        usb_device_attach(dev);
-    else
-        dev->info->handle_destroy(dev);
-}
-
 static int usb_device_add(const char *devname, int is_hotplug)
 {
     const char *p;
@@ -2549,21 +2539,6 @@ static int usb_device_add(const char *devname, int is_hotplug)
     /* the other ones */
     if (strstart(devname, "host:", &p)) {
         dev = usb_host_device_open(p);
-    } else if (strstart(devname, "disk:", &p)) {
-        BlockDriverState *bs;
-
-        dev = usb_msd_init(p);
-        if (!dev)
-            return -1;
-        bs = usb_msd_get_bdrv(dev);
-        if (bdrv_key_required(bs)) {
-            autostart = 0;
-            if (is_hotplug) {
-                monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb,
-                                            dev);
-                return 0;
-            }
-        }
     } else if (strstart(devname, "net:", &p)) {
         QemuOpts *opts;
         int idx;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-10-23  9:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [Qemu-devel] [PATCH 4/5] usb: make attach optional Gerd Hoffmann
2009-10-23  9:26 ` [Qemu-devel] [PATCH 5/5] usb-storage: use qdev for -usbdevice Gerd Hoffmann

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).