diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-08-31 14:23:59 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-09-09 14:55:17 -0500 |
commit | 806b60248218bd5f74a8b070f5a99a864e8e51c6 (patch) | |
tree | ef5ebf0b2f0aebb33cfbb6a3c7b58de8092a079c /hw/usb-hub.c | |
parent | 755700885432a8692c53549dd177d7d52d5cdd17 (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-hub.c')
-rw-r--r-- | hw/usb-hub.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/hw/usb-hub.c b/hw/usb-hub.c index 9f26bbe945..116b1d2107 100644 --- a/hw/usb-hub.c +++ b/hw/usb-hub.c @@ -486,7 +486,7 @@ static int usb_hub_broadcast_packet(USBHubState *s, USBPacket *p) port = &s->ports[i]; dev = port->port.dev; if (dev && (port->wPortStatus & PORT_STAT_ENABLE)) { - ret = dev->handle_packet(dev, p); + ret = dev->info->handle_packet(dev, p); if (ret != USB_RET_NODEV) { return ret; } @@ -521,32 +521,41 @@ static void usb_hub_handle_destroy(USBDevice *dev) qemu_free(s); } -USBDevice *usb_hub_init(int nb_ports) +static int usb_hub_initfn(USBDevice *dev) { - USBHubState *s; + USBHubState *s = DO_UPCAST(USBHubState, dev, dev); USBHubPort *port; int i; - if (nb_ports > MAX_PORTS) - return NULL; - s = qemu_mallocz(sizeof(USBHubState)); - s->dev.speed = USB_SPEED_FULL; - s->dev.handle_packet = usb_hub_handle_packet; - - /* generic USB device init */ - s->dev.handle_reset = usb_hub_handle_reset; - s->dev.handle_control = usb_hub_handle_control; - s->dev.handle_data = usb_hub_handle_data; - s->dev.handle_destroy = usb_hub_handle_destroy; - - pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Hub"); - - s->nb_ports = nb_ports; - for(i = 0; i < s->nb_ports; i++) { + s->dev.speed = USB_SPEED_FULL, + s->nb_ports = MAX_PORTS; /* FIXME: make configurable */ + for (i = 0; i < s->nb_ports; i++) { port = &s->ports[i]; qemu_register_usb_port(&port->port, s, i, usb_hub_attach); port->wPortStatus = PORT_STAT_POWER; port->wPortChange = 0; } - return (USBDevice *)s; + return 0; +} + +USBDevice *usb_hub_init(int nb_ports) +{ + return usb_create_simple(NULL /* FIXME */, "QEMU USB Hub"); +} + +static struct USBDeviceInfo hub_info = { + .qdev.name = "QEMU USB Hub", + .qdev.size = sizeof(USBHubState), + .init = usb_hub_initfn, + .handle_packet = usb_hub_handle_packet, + .handle_reset = usb_hub_handle_reset, + .handle_control = usb_hub_handle_control, + .handle_data = usb_hub_handle_data, + .handle_destroy = usb_hub_handle_destroy, +}; + +static void usb_hub_register_devices(void) +{ + usb_qdev_register(&hub_info); } +device_init(usb_hub_register_devices) |