diff options
Diffstat (limited to 'hw/usb-hid.c')
-rw-r--r-- | hw/usb-hid.c | 106 |
1 files changed, 62 insertions, 44 deletions
diff --git a/hw/usb-hid.c b/hw/usb-hid.c index c850a91947..c8b6ee7cd1 100644 --- a/hw/usb-hid.c +++ b/hw/usb-hid.c @@ -846,65 +846,44 @@ static void usb_hid_handle_destroy(USBDevice *dev) qemu_free(s); } -USBDevice *usb_tablet_init(void) +static int usb_hid_initfn(USBDevice *dev, int kind) { - USBHIDState *s; - - s = qemu_mallocz(sizeof(USBHIDState)); + USBHIDState *s = DO_UPCAST(USBHIDState, dev, dev); s->dev.speed = USB_SPEED_FULL; - s->dev.handle_packet = usb_generic_handle_packet; - - s->dev.handle_reset = usb_mouse_handle_reset; - s->dev.handle_control = usb_hid_handle_control; - s->dev.handle_data = usb_hid_handle_data; - s->dev.handle_destroy = usb_hid_handle_destroy; - s->kind = USB_TABLET; + s->kind = kind; /* Force poll routine to be run and grab input the first time. */ s->changed = 1; - - pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet"); - - return (USBDevice *)s; + return 0; } -USBDevice *usb_mouse_init(void) +static int usb_tablet_initfn(USBDevice *dev) { - USBHIDState *s; + return usb_hid_initfn(dev, USB_TABLET); +} - s = qemu_mallocz(sizeof(USBHIDState)); - s->dev.speed = USB_SPEED_FULL; - s->dev.handle_packet = usb_generic_handle_packet; +static int usb_mouse_initfn(USBDevice *dev) +{ + return usb_hid_initfn(dev, USB_MOUSE); +} - s->dev.handle_reset = usb_mouse_handle_reset; - s->dev.handle_control = usb_hid_handle_control; - s->dev.handle_data = usb_hid_handle_data; - s->dev.handle_destroy = usb_hid_handle_destroy; - s->kind = USB_MOUSE; - /* Force poll routine to be run and grab input the first time. */ - s->changed = 1; +static int usb_keyboard_initfn(USBDevice *dev) +{ + return usb_hid_initfn(dev, USB_KEYBOARD); +} - pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse"); +USBDevice *usb_tablet_init(void) +{ + return usb_create_simple(NULL /* FIXME */, "QEMU USB Tablet"); +} - return (USBDevice *)s; +USBDevice *usb_mouse_init(void) +{ + return usb_create_simple(NULL /* FIXME */, "QEMU USB Mouse"); } USBDevice *usb_keyboard_init(void) { - USBHIDState *s; - - s = qemu_mallocz(sizeof(USBHIDState)); - s->dev.speed = USB_SPEED_FULL; - s->dev.handle_packet = usb_generic_handle_packet; - - s->dev.handle_reset = usb_keyboard_handle_reset; - s->dev.handle_control = usb_hid_handle_control; - s->dev.handle_data = usb_hid_handle_data; - s->dev.handle_destroy = usb_hid_handle_destroy; - s->kind = USB_KEYBOARD; - - pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Keyboard"); - - return (USBDevice *) s; + return usb_create_simple(NULL /* FIXME */, "QEMU USB Keyboard"); } void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *)) @@ -914,3 +893,42 @@ void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *)) s->datain_opaque = opaque; s->datain = datain; } + +static struct USBDeviceInfo hid_info[] = { + { + .qdev.name = "QEMU USB Tablet", + .qdev.size = sizeof(USBHIDState), + .init = usb_tablet_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_mouse_handle_reset, + .handle_control = usb_hid_handle_control, + .handle_data = usb_hid_handle_data, + .handle_destroy = usb_hid_handle_destroy, + },{ + .qdev.name = "QEMU USB Mouse", + .qdev.size = sizeof(USBHIDState), + .init = usb_mouse_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_mouse_handle_reset, + .handle_control = usb_hid_handle_control, + .handle_data = usb_hid_handle_data, + .handle_destroy = usb_hid_handle_destroy, + },{ + .qdev.name = "QEMU USB Keyboard", + .qdev.size = sizeof(USBHIDState), + .init = usb_keyboard_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_keyboard_handle_reset, + .handle_control = usb_hid_handle_control, + .handle_data = usb_hid_handle_data, + .handle_destroy = usb_hid_handle_destroy, + },{ + /* end of list */ + } +}; + +static void usb_hid_register_devices(void) +{ + usb_qdev_register_many(hid_info); +} +device_init(usb_hid_register_devices) |