aboutsummaryrefslogtreecommitdiff
path: root/hw/usb-serial.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-08-31 14:23:59 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-09-09 14:55:17 -0500
commit806b60248218bd5f74a8b070f5a99a864e8e51c6 (patch)
treeef5ebf0b2f0aebb33cfbb6a3c7b58de8092a079c /hw/usb-serial.c
parent755700885432a8692c53549dd177d7d52d5cdd17 (diff)
qdev/usb: add usb bus support to qdev, convert drivers.
* Add USBBus. * Add USBDeviceInfo, move device callbacks here. * Add usb-qdev helper functions. * Switch drivers to qdev. TODO: * make the rest of qemu aware of usb busses and kill the FIXMEs added by this patch. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/usb-serial.c')
-rw-r--r--hw/usb-serial.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 19870a53cc..091ab2cbc1 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -524,8 +524,16 @@ static void usb_serial_event(void *opaque, int event)
}
}
+static int usb_serial_initfn(USBDevice *dev)
+{
+ USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
+ s->dev.speed = USB_SPEED_FULL;
+ return 0;
+}
+
USBDevice *usb_serial_init(const char *filename)
{
+ USBDevice *dev;
USBSerialState *s;
CharDriverState *cdrv;
unsigned short vendorid = 0x0403, productid = 0x6001;
@@ -561,32 +569,40 @@ USBDevice *usb_serial_init(const char *filename)
return NULL;
}
filename++;
- s = qemu_mallocz(sizeof(USBSerialState));
snprintf(label, sizeof(label), "usbserial%d", index++);
cdrv = qemu_chr_open(label, filename, NULL);
if (!cdrv)
- goto fail;
- s->cs = cdrv;
- qemu_chr_add_handlers(cdrv, usb_serial_can_read, usb_serial_read, usb_serial_event, s);
-
- s->dev.speed = USB_SPEED_FULL;
- s->dev.handle_packet = usb_generic_handle_packet;
-
- s->dev.handle_reset = usb_serial_handle_reset;
- s->dev.handle_control = usb_serial_handle_control;
- s->dev.handle_data = usb_serial_handle_data;
- s->dev.handle_destroy = usb_serial_handle_destroy;
+ 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);
+ qemu_chr_add_handlers(cdrv, usb_serial_can_read, usb_serial_read,
+ usb_serial_event, s);
+
usb_serial_handle_reset((USBDevice *)s);
return (USBDevice *)s;
- fail:
- qemu_free(s);
- return NULL;
}
+
+static struct USBDeviceInfo serial_info = {
+ .qdev.name = "QEMU 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,
+};
+
+static void usb_serial_register_devices(void)
+{
+ usb_qdev_register(&serial_info);
+}
+device_init(usb_serial_register_devices)