usb: error handling fixes from Markus, make sysbus ehci arm-only.

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJU5GFFAAoJEEy22O7T6HE40lIP/0YUSJxuEWn8cWrMMiUd5Hpb
 9Yd/RVRbnFPX8yngZGC8TScxjxv22m8ziXN5nsICGUgpLVq6ZIq7vAzSbFo4Jh6O
 px9v4C/sy4u1EJ/c2cm3imz0PTRZd2yk/E7vkszm8qr0DTlO/5ULCBR1Jkq5aqj/
 yLmauhv72h9NGb+k1P9Mjc1mr66RWCH2tCeR5uhQ/s3hUadKwh0WEtdfiqIyoCsd
 jM/58TI5+EMoqXH7YHy8dJIwgJIDweafdWAySbVpNK9cKbhuB61sMbAzRB3bzjwY
 Wmco2qyj12u40jniKc7poWL385ddjfaATXmALAwkPUdQkVIIWhZH4FBtX/3YJGGb
 fX++4PaIJxxK/sz4H8VXsxVq+QaNp/1wgAIND+CuIV65FV1ioMe1/iGGI4L4LCEF
 PVpk8t7k5zrZSFn/OMchR1UQZlTWX7oRFg9M5HG6k0hr8PtKYPfrrc9OJ5th0F8j
 xb02/K5nWsYOIgpyliov7T7/gpt1kcCNkKw/KmPO6KNxKzO7jOLeEPxITGY+ASsh
 gWajDzfVCbajvZYu+rePn3wuk4iBrJzhx5yHB9gkvkuKzK8aOJPX5LDshAZGfaI0
 bN3yn/dRIasF9iVTgIv3CPLFp3UyOVFvGnkNCgjH69A0mPD/m/drmoAtlYTWjWUv
 q+VKZ3MqQArKwJXY4tJH
 =ASvH
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20150218-1' into staging

usb: error handling fixes from Markus, make sysbus ehci arm-only.

# gpg: Signature made Wed Feb 18 09:54:13 2015 GMT using RSA key ID D3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"

* remotes/kraxel/tags/pull-usb-20150218-1:
  Make sysbus EHCI devices ARM only by default
  PPC: Don't use legacy -usbdevice support for setting up board
  r2d: Don't use legacy -usbdevice support for setting up board
  usb: Change usb_create_simple() to abort on failure
  usb: Suppress bogus error when automatic usb-hub creation fails
  usb: Do not prefix error_setg() messages with "Error: "
  usb: Improve -usbdevice error reporting a bit
  usb: usb_create() can't fail, drop useless error handling

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-02-25 11:54:15 +00:00
commit 3d30395f7f
11 changed files with 54 additions and 47 deletions

View File

@ -33,6 +33,7 @@ CONFIG_PFLASH_CFI01=y
CONFIG_PFLASH_CFI02=y
CONFIG_MICRODRIVE=y
CONFIG_USB_MUSB=y
CONFIG_USB_EHCI_SYSBUS=y
CONFIG_ARM11MPCORE=y
CONFIG_A9MPCORE=y

View File

@ -420,11 +420,14 @@ static void ppc_core99_init(MachineState *machine)
if (machine->usb) {
pci_create_simple(pci_bus, -1, "pci-ohci");
/* U3 needs to use USB for input because Linux doesn't support via-cuda
on PPC64 */
if (machine_arch == ARCH_MAC99_U3) {
usbdevice_create("keyboard");
usbdevice_create("mouse");
USBBus *usb_bus = usb_bus_find(-1);
usb_create_simple(usb_bus, "usb-kbd");
usb_create_simple(usb_bus, "usb-mouse");
}
}

View File

@ -1533,9 +1533,12 @@ static void ppc_spapr_init(MachineState *machine)
if (machine->usb) {
pci_create_simple(phb->bus, -1, "pci-ohci");
if (spapr->has_graphics) {
usbdevice_create("keyboard");
usbdevice_create("mouse");
USBBus *usb_bus = usb_bus_find(-1);
usb_create_simple(usb_bus, "usb-kbd");
usb_create_simple(usb_bus, "usb-mouse");
}
}

View File

@ -301,7 +301,7 @@ static void r2d_init(MachineState *machine)
"rtl8139", i==0 ? "2" : NULL);
/* USB keyboard */
usbdevice_create("keyboard");
usb_create_simple(usb_bus_find(-1), "usb-kbd");
/* Todo: register on board registers */
memset(&boot_params, 0, sizeof(boot_params));

View File

@ -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

View File

@ -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;
}
@ -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);
}
return f->usbdevice_init(bus, params);
if (!dev) {
error_report("Failed to create USB device '%s'", f->name);
return NULL;
}
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)

View File

@ -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;
}

View File

@ -1405,11 +1405,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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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: