usb: usb-serial QOMify
Signed-off-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
d371cbc778
commit
cdf0d7694d
@ -103,6 +103,9 @@ typedef struct {
|
|||||||
CharDriverState *cs;
|
CharDriverState *cs;
|
||||||
} USBSerialState;
|
} USBSerialState;
|
||||||
|
|
||||||
|
#define TYPE_USB_SERIAL "usb-serial-dev"
|
||||||
|
#define USB_SERIAL_DEV(obj) OBJECT_CHECK(USBSerialState, (obj), TYPE_USB_SERIAL)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
STR_MANUFACTURER = 1,
|
STR_MANUFACTURER = 1,
|
||||||
STR_PRODUCT_SERIAL,
|
STR_PRODUCT_SERIAL,
|
||||||
@ -473,7 +476,7 @@ static void usb_serial_event(void *opaque, int event)
|
|||||||
|
|
||||||
static void usb_serial_realize(USBDevice *dev, Error **errp)
|
static void usb_serial_realize(USBDevice *dev, Error **errp)
|
||||||
{
|
{
|
||||||
USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
|
USBSerialState *s = USB_SERIAL_DEV(dev);
|
||||||
Error *local_err = NULL;
|
Error *local_err = NULL;
|
||||||
|
|
||||||
usb_desc_create_serial(dev);
|
usb_desc_create_serial(dev);
|
||||||
@ -576,26 +579,40 @@ static Property serial_properties[] = {
|
|||||||
DEFINE_PROP_END_OF_LIST(),
|
DEFINE_PROP_END_OF_LIST(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void usb_serial_dev_class_init(ObjectClass *klass, void *data)
|
||||||
|
{
|
||||||
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||||
|
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
|
||||||
|
|
||||||
|
uc->realize = usb_serial_realize;
|
||||||
|
uc->handle_reset = usb_serial_handle_reset;
|
||||||
|
uc->handle_control = usb_serial_handle_control;
|
||||||
|
uc->handle_data = usb_serial_handle_data;
|
||||||
|
dc->vmsd = &vmstate_usb_serial;
|
||||||
|
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const TypeInfo usb_serial_dev_type_info = {
|
||||||
|
.name = TYPE_USB_SERIAL,
|
||||||
|
.parent = TYPE_USB_DEVICE,
|
||||||
|
.instance_size = sizeof(USBSerialState),
|
||||||
|
.abstract = true,
|
||||||
|
.class_init = usb_serial_dev_class_init,
|
||||||
|
};
|
||||||
|
|
||||||
static void usb_serial_class_initfn(ObjectClass *klass, void *data)
|
static void usb_serial_class_initfn(ObjectClass *klass, void *data)
|
||||||
{
|
{
|
||||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||||
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
|
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
|
||||||
|
|
||||||
uc->realize = usb_serial_realize;
|
|
||||||
uc->product_desc = "QEMU USB Serial";
|
uc->product_desc = "QEMU USB Serial";
|
||||||
uc->usb_desc = &desc_serial;
|
uc->usb_desc = &desc_serial;
|
||||||
uc->handle_reset = usb_serial_handle_reset;
|
|
||||||
uc->handle_control = usb_serial_handle_control;
|
|
||||||
uc->handle_data = usb_serial_handle_data;
|
|
||||||
dc->vmsd = &vmstate_usb_serial;
|
|
||||||
dc->props = serial_properties;
|
dc->props = serial_properties;
|
||||||
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo serial_info = {
|
static const TypeInfo serial_info = {
|
||||||
.name = "usb-serial",
|
.name = "usb-serial",
|
||||||
.parent = TYPE_USB_DEVICE,
|
.parent = TYPE_USB_SERIAL,
|
||||||
.instance_size = sizeof(USBSerialState),
|
|
||||||
.class_init = usb_serial_class_initfn,
|
.class_init = usb_serial_class_initfn,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -609,26 +626,20 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
|
|||||||
DeviceClass *dc = DEVICE_CLASS(klass);
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||||
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
|
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
|
||||||
|
|
||||||
uc->realize = usb_serial_realize;
|
|
||||||
uc->product_desc = "QEMU USB Braille";
|
uc->product_desc = "QEMU USB Braille";
|
||||||
uc->usb_desc = &desc_braille;
|
uc->usb_desc = &desc_braille;
|
||||||
uc->handle_reset = usb_serial_handle_reset;
|
|
||||||
uc->handle_control = usb_serial_handle_control;
|
|
||||||
uc->handle_data = usb_serial_handle_data;
|
|
||||||
dc->vmsd = &vmstate_usb_serial;
|
|
||||||
dc->props = braille_properties;
|
dc->props = braille_properties;
|
||||||
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo braille_info = {
|
static const TypeInfo braille_info = {
|
||||||
.name = "usb-braille",
|
.name = "usb-braille",
|
||||||
.parent = TYPE_USB_DEVICE,
|
.parent = TYPE_USB_SERIAL,
|
||||||
.instance_size = sizeof(USBSerialState),
|
|
||||||
.class_init = usb_braille_class_initfn,
|
.class_init = usb_braille_class_initfn,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void usb_serial_register_types(void)
|
static void usb_serial_register_types(void)
|
||||||
{
|
{
|
||||||
|
type_register_static(&usb_serial_dev_type_info);
|
||||||
type_register_static(&serial_info);
|
type_register_static(&serial_info);
|
||||||
usb_legacy_register("usb-serial", "serial", usb_serial_init);
|
usb_legacy_register("usb-serial", "serial", usb_serial_init);
|
||||||
type_register_static(&braille_info);
|
type_register_static(&braille_info);
|
||||||
|
Loading…
Reference in New Issue
Block a user