aboutsummaryrefslogtreecommitdiff
path: root/hw/usb
diff options
context:
space:
mode:
Diffstat (limited to 'hw/usb')
-rw-r--r--hw/usb/Makefile.objs3
-rw-r--r--hw/usb/bus.c54
-rw-r--r--hw/usb/dev-bluetooth.c11
-rw-r--r--hw/usb/dev-network.c4
-rw-r--r--hw/usb/dev-serial.c7
-rw-r--r--hw/usb/dev-storage.c6
-rw-r--r--hw/usb/host-legacy.c1
-rw-r--r--hw/usb/host-libusb.c2
-rw-r--r--hw/usb/host-stub.c2
9 files changed, 45 insertions, 45 deletions
diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs
index 3fe4dff3bd..0ccd477577 100644
--- a/hw/usb/Makefile.objs
+++ b/hw/usb/Makefile.objs
@@ -5,7 +5,8 @@ common-obj-y += libhw.o
# usb host adapters
common-obj-$(CONFIG_USB_UHCI) += hcd-uhci.o
common-obj-$(CONFIG_USB_OHCI) += hcd-ohci.o
-common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o hcd-ehci-sysbus.o
+common-obj-$(CONFIG_USB_EHCI) += hcd-ehci.o hcd-ehci-pci.o
+common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o
common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o
common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 986b2d8da8..91fc3e20d9 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -315,23 +315,33 @@ USBDevice *usb_create(USBBus *bus, const char *name)
return USB_DEVICE(dev);
}
-USBDevice *usb_create_simple(USBBus *bus, const char *name)
+static USBDevice *usb_try_create_simple(USBBus *bus, const char *name,
+ Error **errp)
{
- USBDevice *dev = usb_create(bus, name);
- int rc;
+ Error *err = NULL;
+ USBDevice *dev;
+ dev = USB_DEVICE(qdev_try_create(&bus->qbus, name));
if (!dev) {
- error_report("Failed to create USB device '%s'", name);
+ error_setg(errp, "Failed to create USB device '%s'", name);
return NULL;
}
- rc = qdev_init(&dev->qdev);
- if (rc < 0) {
- error_report("Failed to initialize USB device '%s'", name);
+ object_property_set_bool(OBJECT(dev), true, "realized", &err);
+ if (err) {
+ error_setg(errp, "Failed to initialize USB device '%s': %s",
+ name, error_get_pretty(err));
+ error_free(err);
+ object_unparent(OBJECT(dev));
return NULL;
}
return dev;
}
+USBDevice *usb_create_simple(USBBus *bus, const char *name)
+{
+ return usb_try_create_simple(bus, name, &error_abort);
+}
+
static void usb_fill_port(USBPort *port, void *opaque, int index,
USBPortOps *ops, int speedmask)
{
@@ -416,17 +426,17 @@ void usb_claim_port(USBDevice *dev, Error **errp)
}
}
if (port == NULL) {
- error_setg(errp, "Error: usb port %s (bus %s) not found (in use?)",
+ error_setg(errp, "usb port %s (bus %s) not found (in use?)",
dev->port_path, bus->qbus.name);
return;
}
} else {
if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {
/* Create a new hub and chain it on */
- usb_create_simple(bus, "usb-hub");
+ usb_try_create_simple(bus, "usb-hub", NULL);
}
if (bus->nfree == 0) {
- error_setg(errp, "Error: tried to attach usb device %s to a bus "
+ error_setg(errp, "tried to attach usb device %s to a bus "
"with no free ports", dev->product_desc);
return;
}
@@ -627,7 +637,7 @@ static char *usb_get_fw_dev_path(DeviceState *qdev)
return fw_path;
}
-void usb_info(Monitor *mon, const QDict *qdict)
+void hmp_info_usb(Monitor *mon, const QDict *qdict)
{
USBBus *bus;
USBDevice *dev;
@@ -655,10 +665,12 @@ USBDevice *usbdevice_create(const char *cmdline)
{
USBBus *bus = usb_bus_find(-1 /* any */);
LegacyUSBFactory *f = NULL;
+ Error *err = NULL;
GSList *i;
char driver[32];
const char *params;
int len;
+ USBDevice *dev;
params = strchr(cmdline,':');
if (params) {
@@ -693,14 +705,28 @@ USBDevice *usbdevice_create(const char *cmdline)
return NULL;
}
- if (!f->usbdevice_init) {
+ if (f->usbdevice_init) {
+ dev = f->usbdevice_init(bus, params);
+ } else {
if (*params) {
error_report("usbdevice %s accepts no params", driver);
return NULL;
}
- return usb_create_simple(bus, f->name);
+ dev = usb_create(bus, f->name);
+ }
+ if (!dev) {
+ error_report("Failed to create USB device '%s'", f->name);
+ return NULL;
}
- return f->usbdevice_init(bus, params);
+ object_property_set_bool(OBJECT(dev), true, "realized", &err);
+ if (err) {
+ error_report("Failed to initialize USB device '%s': %s",
+ f->name, error_get_pretty(err));
+ error_free(err);
+ object_unparent(OBJECT(dev));
+ return NULL;
+ }
+ return dev;
}
static void usb_device_class_init(ObjectClass *klass, void *data)
diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
index 390d475c16..9bf673057a 100644
--- a/hw/usb/dev-bluetooth.c
+++ b/hw/usb/dev-bluetooth.c
@@ -530,21 +530,12 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
} else {
hci = bt_new_hci(qemu_find_bt_vlan(0));
}
-
if (!hci)
return NULL;
+
dev = usb_create(bus, name);
- if (!dev) {
- error_report("Failed to create USB device '%s'", name);
- return NULL;
- }
s = DO_UPCAST(struct USBBtState, dev, dev);
s->hci = hci;
- if (qdev_init(&dev->qdev) < 0) {
- error_report("Failed to initialize USB device '%s'", name);
- return NULL;
- }
-
return dev;
}
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index c49fde8113..b27b1f441e 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -1404,11 +1404,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
}
dev = usb_create(bus, "usb-net");
- if (!dev) {
- return NULL;
- }
qdev_set_nic_properties(&dev->qdev, &nd_table[idx]);
- qdev_init_nofail(&dev->qdev);
return dev;
}
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index 1cee450259..67c2072ce7 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -544,16 +544,11 @@ static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
return NULL;
dev = usb_create(bus, "usb-serial");
- if (!dev) {
- return NULL;
- }
qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
if (vendorid)
qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid);
if (productid)
qdev_prop_set_uint16(&dev->qdev, "productid", productid);
- qdev_init_nofail(&dev->qdev);
-
return dev;
}
@@ -568,8 +563,6 @@ static USBDevice *usb_braille_init(USBBus *bus, const char *unused)
dev = usb_create(bus, "usb-braille");
qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
- qdev_init_nofail(&dev->qdev);
-
return dev;
}
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 4539733e42..af2e1b915d 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -706,17 +706,11 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
/* create guest device */
dev = usb_create(bus, "usb-storage");
- if (!dev) {
- return NULL;
- }
if (qdev_prop_set_drive(&dev->qdev, "drive",
blk_by_legacy_dinfo(dinfo)) < 0) {
object_unparent(OBJECT(dev));
return NULL;
}
- if (qdev_init(&dev->qdev) < 0)
- return NULL;
-
return dev;
}
diff --git a/hw/usb/host-legacy.c b/hw/usb/host-legacy.c
index 3cc9c4282c..422ed9a65f 100644
--- a/hw/usb/host-legacy.c
+++ b/hw/usb/host-legacy.c
@@ -128,7 +128,6 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
qdev_prop_set_uint32(&dev->qdev, "hostaddr", filter.addr);
qdev_prop_set_uint32(&dev->qdev, "vendorid", filter.vendor_id);
qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id);
- qdev_init_nofail(&dev->qdev);
return dev;
fail:
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 38f7c7268b..10f4735ddf 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -1636,7 +1636,7 @@ static void usb_host_auto_check(void *unused)
timer_mod(usb_auto_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 2000);
}
-void usb_host_info(Monitor *mon, const QDict *qdict)
+void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
{
libusb_device **devs = NULL;
struct libusb_device_descriptor ddesc;
diff --git a/hw/usb/host-stub.c b/hw/usb/host-stub.c
index 28d8032caf..2eaaa83419 100644
--- a/hw/usb/host-stub.c
+++ b/hw/usb/host-stub.c
@@ -35,7 +35,7 @@
#include "hw/usb.h"
#include "monitor/monitor.h"
-void usb_host_info(Monitor *mon, const QDict *qdict)
+void hmp_info_usbhost(Monitor *mon, const QDict *qdict)
{
monitor_printf(mon, "USB host devices not supported\n");
}