aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-10-26 15:56:47 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-30 08:39:31 -0500
commit2b0efdc3e116753e349bc3d1888a8520f57e8315 (patch)
treea17fdd90789af0fb69283a80737608f2cd68e5a1
parentfa7c70c35a24f2c5b115004c51f3b726cc630e6d (diff)
downloadqemu-2b0efdc3e116753e349bc3d1888a8520f57e8315.zip
qemu-2b0efdc3e116753e349bc3d1888a8520f57e8315.tar.gz
qemu-2b0efdc3e116753e349bc3d1888a8520f57e8315.tar.bz2
usb-serial and braille: use qdev for -usbdevice
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--hw/baum.c6
-rw-r--r--hw/baum.h3
-rw-r--r--hw/usb-serial.c85
-rw-r--r--hw/usb.h3
-rw-r--r--vl.c6
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 e103e51..2da856d 100644
--- a/vl.c
+++ b/vl.c
@@ -2558,12 +2558,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;