提交 0958b4cc 编写于 作者: G Gerd Hoffmann 提交者: Anthony Liguori

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: NGerd Hoffmann <kraxel@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 51edd4e6
...@@ -35,7 +35,7 @@ static int qdev_hotplug = 0; ...@@ -35,7 +35,7 @@ static int qdev_hotplug = 0;
/* This is a nasty hack to allow passing a NULL bus to qdev_create. */ /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
static BusState *main_system_bus; static BusState *main_system_bus;
static DeviceInfo *device_info_list; DeviceInfo *device_info_list;
static BusState *qbus_find_recursive(BusState *bus, const char *name, static BusState *qbus_find_recursive(BusState *bus, const char *name,
const BusInfo *info); const BusInfo *info);
......
...@@ -141,6 +141,7 @@ struct DeviceInfo { ...@@ -141,6 +141,7 @@ struct DeviceInfo {
BusInfo *bus_info; BusInfo *bus_info;
struct DeviceInfo *next; struct DeviceInfo *next;
}; };
extern DeviceInfo *device_info_list;
void qdev_register(DeviceInfo *info); void qdev_register(DeviceInfo *info);
......
...@@ -252,3 +252,50 @@ void usb_info(Monitor *mon) ...@@ -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);
}
...@@ -183,6 +183,10 @@ struct USBDeviceInfo { ...@@ -183,6 +183,10 @@ struct USBDeviceInfo {
* Returns length or one of the USB_RET_ codes. * Returns length or one of the USB_RET_ codes.
*/ */
int (*handle_data)(USBDevice *dev, USBPacket *p); 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); typedef void (*usb_attachfn)(USBPort *port, USBDevice *dev);
...@@ -309,6 +313,7 @@ void usb_qdev_register(USBDeviceInfo *info); ...@@ -309,6 +313,7 @@ void usb_qdev_register(USBDeviceInfo *info);
void usb_qdev_register_many(USBDeviceInfo *info); void usb_qdev_register_many(USBDeviceInfo *info);
USBDevice *usb_create(USBBus *bus, const char *name); USBDevice *usb_create(USBBus *bus, const char *name);
USBDevice *usb_create_simple(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, void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
usb_attachfn attach); usb_attachfn attach);
void usb_unregister_port(USBBus *bus, USBPort *port); void usb_unregister_port(USBBus *bus, USBPort *port);
......
...@@ -2556,6 +2556,11 @@ static int usb_device_add(const char *devname, int is_hotplug) ...@@ -2556,6 +2556,11 @@ static int usb_device_add(const char *devname, int is_hotplug)
if (!usb_enabled) if (!usb_enabled)
return -1; 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 */ /* simple devices which don't need extra care */
for (i = 0; i < ARRAY_SIZE(usbdevs); i++) { for (i = 0; i < ARRAY_SIZE(usbdevs); i++) {
if (strcmp(devname, usbdevs[i].name) != 0) if (strcmp(devname, usbdevs[i].name) != 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册