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-net.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-net.c')
-rw-r--r-- | hw/usb-net.c | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/hw/usb-net.c b/hw/usb-net.c index 8214a68be2..f19309ee13 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1432,32 +1432,34 @@ static void usb_net_handle_destroy(USBDevice *dev) qemu_del_vlan_client(s->vc); } -USBDevice *usb_net_init(NICInfo *nd) +static int usb_net_initfn(USBDevice *dev) { - USBNetState *s; - - s = qemu_mallocz(sizeof(USBNetState)); - s->dev.speed = USB_SPEED_FULL; - s->dev.handle_packet = usb_generic_handle_packet; + USBNetState *s = DO_UPCAST(USBNetState, dev, dev); - s->dev.handle_reset = usb_net_handle_reset; - s->dev.handle_control = usb_net_handle_control; - s->dev.handle_data = usb_net_handle_data; - s->dev.handle_destroy = usb_net_handle_destroy; + s->dev.speed = USB_SPEED_FULL; s->rndis = 1; s->rndis_state = RNDIS_UNINITIALIZED; + TAILQ_INIT(&s->rndis_resp); + s->medium = 0; /* NDIS_MEDIUM_802_3 */ s->speed = 1000000; /* 100MBps, in 100Bps units */ s->media_state = 0; /* NDIS_MEDIA_STATE_CONNECTED */; s->filter = 0; s->vendorid = 0x1234; + return 0; +} + +USBDevice *usb_net_init(NICInfo *nd) +{ + USBDevice *dev; + USBNetState *s; + + dev = usb_create_simple(NULL /* FIXME */, "QEMU USB Network Interface"); + s = DO_UPCAST(USBNetState, dev, dev); memcpy(s->mac, nd->macaddr, 6); - TAILQ_INIT(&s->rndis_resp); - pstrcpy(s->dev.devname, sizeof(s->dev.devname), - "QEMU USB Network Interface"); s->vc = nd->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, usbnet_can_receive, usbnet_receive, @@ -1476,3 +1478,20 @@ USBDevice *usb_net_init(NICInfo *nd) return (USBDevice *) s; } + +static struct USBDeviceInfo net_info = { + .qdev.name = "QEMU USB Network Interface", + .qdev.size = sizeof(USBNetState), + .init = usb_net_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_net_handle_reset, + .handle_control = usb_net_handle_control, + .handle_data = usb_net_handle_data, + .handle_destroy = usb_net_handle_destroy, +}; + +static void usb_net_register_devices(void) +{ + usb_qdev_register(&net_info); +} +device_init(usb_net_register_devices) |