aboutsummaryrefslogtreecommitdiff
path: root/hw/usb-bus.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-08-31 14:23:59 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-09-09 14:55:17 -0500
commit806b60248218bd5f74a8b070f5a99a864e8e51c6 (patch)
treeef5ebf0b2f0aebb33cfbb6a3c7b58de8092a079c /hw/usb-bus.c
parent755700885432a8692c53549dd177d7d52d5cdd17 (diff)
downloadqemu-806b60248218bd5f74a8b070f5a99a864e8e51c6.zip
qemu-806b60248218bd5f74a8b070f5a99a864e8e51c6.tar.gz
qemu-806b60248218bd5f74a8b070f5a99a864e8e51c6.tar.bz2
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-bus.c')
-rw-r--r--hw/usb-bus.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
new file mode 100644
index 0000000..c695a37
--- /dev/null
+++ b/hw/usb-bus.c
@@ -0,0 +1,82 @@
+#include "hw.h"
+#include "usb.h"
+#include "qdev.h"
+
+static struct BusInfo usb_bus_info = {
+ .name = "USB",
+ .size = sizeof(USBBus),
+};
+static int next_usb_bus = 0;
+static TAILQ_HEAD(, USBBus) busses = TAILQ_HEAD_INITIALIZER(busses);
+
+USBBus *usb_bus_new(DeviceState *host)
+{
+ USBBus *bus;
+
+ bus = FROM_QBUS(USBBus, qbus_create(&usb_bus_info, host, NULL));
+ bus->busnr = next_usb_bus++;
+ TAILQ_INIT(&bus->free);
+ TAILQ_INIT(&bus->used);
+ TAILQ_INSERT_TAIL(&busses, bus, next);
+ return bus;
+}
+
+USBBus *usb_bus_find(int busnr)
+{
+ USBBus *bus;
+
+ if (-1 == busnr)
+ return TAILQ_FIRST(&busses);
+ TAILQ_FOREACH(bus, &busses, next) {
+ if (bus->busnr == busnr)
+ return bus;
+ }
+ return NULL;
+}
+
+static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
+{
+ USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+ USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base);
+ int rc;
+
+ pstrcpy(dev->devname, sizeof(dev->devname), qdev->info->name);
+ dev->info = info;
+ rc = dev->info->init(dev);
+ return rc;
+}
+
+void usb_qdev_register(USBDeviceInfo *info)
+{
+ info->qdev.bus_info = &usb_bus_info;
+ info->qdev.init = usb_qdev_init;
+ qdev_register(&info->qdev);
+}
+
+void usb_qdev_register_many(USBDeviceInfo *info)
+{
+ while (info->qdev.name) {
+ usb_qdev_register(info);
+ info++;
+ }
+}
+
+USBDevice *usb_create_simple(USBBus *bus, const char *name)
+{
+ DeviceState *dev;
+
+#if 1
+ /* temporary stopgap until all usb is properly qdev-ified */
+ if (!bus) {
+ bus = usb_bus_find(-1);
+ if (!bus)
+ return NULL;
+ fprintf(stderr, "%s: no bus specified, using \"%s\" for \"%s\"\n",
+ __FUNCTION__, bus->qbus.name, name);
+ }
+#endif
+
+ dev = qdev_create(&bus->qbus, name);
+ qdev_init(dev);
+ return DO_UPCAST(USBDevice, qdev, dev);
+}