diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-10-26 15:56:45 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-10-30 08:39:30 -0500 |
commit | 0958b4cc8f7889b61770690fa29a1201895cf581 (patch) | |
tree | 377a8fb798d1607f0c90d852b31465fd4db1f13e /hw/usb-bus.c | |
parent | 51edd4e6b5a5dfbe168f21ff7cdc5d63e16c160b (diff) |
usb core: use qdev for -usbdevice
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>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/usb-bus.c')
-rw-r--r-- | hw/usb-bus.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 98987a1973..28b517f5da 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); +} |