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>
This commit is contained in:
Gerd Hoffmann 2009-10-26 15:56:47 +01:00 committed by Anthony Liguori
parent fa7c70c35a
commit 2b0efdc3e1
5 changed files with 65 additions and 38 deletions

View File

@ -627,9 +627,3 @@ fail_handle:
free(baum); free(baum);
return NULL; return NULL;
} }
USBDevice *usb_baum_init(void)
{
/* USB Product ID of Super Vario 40 */
return usb_serial_init("productid=FE72:braille");
}

View File

@ -22,8 +22,5 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
/* usb device */
USBDevice *usb_baum_init(void);
/* char device */ /* char device */
CharDriverState *chr_baum_init(QemuOpts *opts); CharDriverState *chr_baum_init(QemuOpts *opts);

View File

@ -90,8 +90,8 @@ do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0)
typedef struct { typedef struct {
USBDevice dev; USBDevice dev;
uint16_t vendorid; uint32_t vendorid;
uint16_t productid; uint32_t productid;
uint8_t recv_buf[RECV_BUF]; uint8_t recv_buf[RECV_BUF];
uint16_t recv_ptr; uint16_t recv_ptr;
uint16_t recv_used; uint16_t recv_used;
@ -527,15 +527,18 @@ static int usb_serial_initfn(USBDevice *dev)
{ {
USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev); USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
s->dev.speed = USB_SPEED_FULL; 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; return 0;
} }
USBDevice *usb_serial_init(const char *filename) static USBDevice *usb_serial_init(const char *filename)
{ {
USBDevice *dev; USBDevice *dev;
USBSerialState *s;
CharDriverState *cdrv; CharDriverState *cdrv;
unsigned short vendorid = 0x0403, productid = 0x6001; uint32_t vendorid = 0, productid = 0;
char label[32]; char label[32];
static int index; static int index;
@ -545,26 +548,26 @@ USBDevice *usb_serial_init(const char *filename)
if (strstart(filename, "vendorid=", &p)) { if (strstart(filename, "vendorid=", &p)) {
vendorid = strtol(p, &e, 16); vendorid = strtol(p, &e, 16);
if (e == p || (*e && *e != ',' && *e != ':')) { if (e == p || (*e && *e != ',' && *e != ':')) {
printf("bogus vendor ID %s\n", p); qemu_error("bogus vendor ID %s\n", p);
return NULL; return NULL;
} }
filename = e; filename = e;
} else if (strstart(filename, "productid=", &p)) { } else if (strstart(filename, "productid=", &p)) {
productid = strtol(p, &e, 16); productid = strtol(p, &e, 16);
if (e == p || (*e && *e != ',' && *e != ':')) { if (e == p || (*e && *e != ',' && *e != ':')) {
printf("bogus product ID %s\n", p); qemu_error("bogus product ID %s\n", p);
return NULL; return NULL;
} }
filename = e; filename = e;
} else { } else {
printf("unrecognized serial USB option %s\n", filename); qemu_error("unrecognized serial USB option %s\n", filename);
return NULL; return NULL;
} }
while(*filename == ',') while(*filename == ',')
filename++; filename++;
} }
if (!*filename) { if (!*filename) {
printf("character device specification needed\n"); qemu_error("character device specification needed\n");
return NULL; return NULL;
} }
filename++; filename++;
@ -574,23 +577,36 @@ USBDevice *usb_serial_init(const char *filename)
if (!cdrv) if (!cdrv)
return NULL; return NULL;
dev = usb_create_simple(NULL /* FIXME */, "QEMU USB Serial"); dev = usb_create(NULL /* FIXME */, "QEMU USB Serial");
s = DO_UPCAST(USBSerialState, dev, dev); qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
s->cs = cdrv; if (vendorid)
s->vendorid = vendorid; qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid);
s->productid = productid; if (productid)
snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Serial(%.16s)", qdev_prop_set_uint16(&dev->qdev, "productid", productid);
filename); qdev_init(&dev->qdev);
qemu_chr_add_handlers(cdrv, usb_serial_can_read, usb_serial_read, return dev;
usb_serial_event, s); }
usb_serial_handle_reset((USBDevice *)s); static USBDevice *usb_braille_init(const char *unused)
return (USBDevice *)s; {
USBDevice *dev;
CharDriverState *cdrv;
cdrv = qemu_chr_open("braille", "braille", NULL);
if (!cdrv)
return NULL;
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 = { static struct USBDeviceInfo serial_info = {
.qdev.name = "QEMU USB Serial", .qdev.name = "QEMU USB Serial",
.qdev.alias = "usb-serial",
.qdev.size = sizeof(USBSerialState), .qdev.size = sizeof(USBSerialState),
.init = usb_serial_initfn, .init = usb_serial_initfn,
.handle_packet = usb_generic_handle_packet, .handle_packet = usb_generic_handle_packet,
@ -598,10 +614,39 @@ static struct USBDeviceInfo serial_info = {
.handle_control = usb_serial_handle_control, .handle_control = usb_serial_handle_control,
.handle_data = usb_serial_handle_data, .handle_data = usb_serial_handle_data,
.handle_destroy = usb_serial_handle_destroy, .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,
.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 = "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) static void usb_serial_register_devices(void)
{ {
usb_qdev_register(&serial_info); usb_qdev_register(&serial_info);
usb_qdev_register(&braille_info);
} }
device_init(usb_serial_register_devices) device_init(usb_serial_register_devices)

View File

@ -265,9 +265,6 @@ USBDevice *usb_net_init(NICInfo *nd);
/* usb-bt.c */ /* usb-bt.c */
USBDevice *usb_bt_init(HCIInfo *hci); USBDevice *usb_bt_init(HCIInfo *hci);
/* usb-serial.c */
USBDevice *usb_serial_init(const char *filename);
/* usb ports of the VM */ /* usb ports of the VM */
#define VM_USB_HUB_SIZE 8 #define VM_USB_HUB_SIZE 8

6
vl.c
View File

@ -2558,12 +2558,6 @@ static int usb_device_add(const char *devname, int is_hotplug)
return 0; 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)) { } else if (strstart(devname, "net:", &p)) {
QemuOpts *opts; QemuOpts *opts;
int idx; int idx;