Skip to contentSkip to conversation

ucb: Convert remaining PCI HCDs to realize

PATCH In review Markus Armbruster 2 participants 9 messages Feb 17, 2015 – Mar 10, 2015

lore
Share & tools
lore
#0 lore raw

cover ucb: Convert remaining PCI HCDs to realize

This series requires my "[PATCH 00/10] pci: Partial conversion to realize" and my "[PATCH 0/9] Clean up around error_get_pretty(), qerror_report_err()".

Markus Armbruster (4):
usb: Propagate errors through usb_register_companion()
usb: Improve companion configuration error messages
ohci: Complete conversion to realize
uhci: Convert to realize

 hw/usb/bus.c      | 27 ++++++++++++++-------------
 hw/usb/hcd-ehci.c | 28 +++++++++++-----------------
 hw/usb/hcd-ohci.c | 42 +++++++++++++++++++++++-------------------
 hw/usb/hcd-uhci.c | 26 ++++++++++++++------------
 include/hw/usb.h  | 12 +++++++-----
 5 files changed, 69 insertions(+), 66 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/4 usb: Propagate errors through usb_register_companion()

This loses the messages explaining the error printed with error_printf_unless_qmp(). The next commit will make up for the loss.

---
 hw/usb/bus.c      | 17 ++++++++++-------
 hw/usb/hcd-ehci.c | 23 +++++++++++++----------
 hw/usb/hcd-ohci.c | 10 +++++++---
 hw/usb/hcd-uhci.c | 10 +++++++---
 include/hw/usb.h  | 12 +++++++-----
 5 files changed, 44 insertions(+), 28 deletions(-)
hw/usb/bus.c +10 -7
index 986b2d8..8be942f 100644
@@ -350,9 +350,10 @@ void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
     bus->nfree++;
 }
 
-int usb_register_companion(const char *masterbus, USBPort *ports[],
-                           uint32_t portcount, uint32_t firstport,
-                           void *opaque, USBPortOps *ops, int speedmask)
+void usb_register_companion(const char *masterbus, USBPort *ports[],
+                            uint32_t portcount, uint32_t firstport,
+                            void *opaque, USBPortOps *ops, int speedmask,
+                            Error **errp)
 {
     USBBus *bus;
     int i;
@@ -364,21 +365,23 @@ int usb_register_companion(const char *masterbus, USBPort *ports[],
     }
 
     if (!bus || !bus->ops->register_companion) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus",
-                      "an USB masterbus");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
+                  "an USB masterbus");
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
         if (bus) {
             error_printf_unless_qmp(
                 "USB bus '%s' does not allow companion controllers\n",
                 masterbus);
         }
-        return -1;
+#endif
+        return;
     }
 
     for (i = 0; i < portcount; i++) {
         usb_fill_port(ports[i], opaque, i, ops, speedmask);
     }
 
-    return bus->ops->register_companion(bus, ports, portcount, firstport);
+    bus->ops->register_companion(bus, ports, portcount, firstport, errp);
 }
 
 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
hw/usb/hcd-ehci.c +13 -10
index ccf54b6..7d16ba8 100644
@@ -769,30 +769,35 @@ static void ehci_wakeup(USBPort *port)
     qemu_bh_schedule(s->async_bh);
 }
 
-static int ehci_register_companion(USBBus *bus, USBPort *ports[],
-                                   uint32_t portcount, uint32_t firstport)
+static void ehci_register_companion(USBBus *bus, USBPort *ports[],
+                                    uint32_t portcount, uint32_t firstport,
+                                    Error **errp)
 {
     EHCIState *s = container_of(bus, EHCIState, bus);
     uint32_t i;
 
     if (firstport + portcount > NB_PORTS) {
-        qerror_report(QERR_INVALID_PARAMETER_VALUE, "firstport",
-                      "firstport on masterbus");
+        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "firstport",
+                  "firstport on masterbus");
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
         error_printf_unless_qmp(
             "firstport value of %u makes companion take ports %u - %u, which "
             "is outside of the valid range of 0 - %u\n", firstport, firstport,
             firstport + portcount - 1, NB_PORTS - 1);
-        return -1;
+#endif
+        return;
     }
 
     for (i = 0; i < portcount; i++) {
         if (s->companion_ports[firstport + i]) {
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus",
-                          "an USB masterbus");
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
+                      "an USB masterbus");
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
             error_printf_unless_qmp(
                 "port %u on masterbus %s already has a companion assigned\n",
                 firstport + i, bus->qbus.name);
-            return -1;
+#endif
+            return;
         }
     }
 
@@ -806,8 +811,6 @@ static int ehci_register_companion(USBBus *bus, USBPort *ports[],
 
     s->companion_count++;
     s->caps[0x05] = (s->companion_count << 4) | portcount;
-
-    return 0;
 }
 
 static void ehci_wakeup_endpoint(USBBus *bus, USBEndpoint *ep,
hw/usb/hcd-ohci.c +7 -3
index a0d478e..21ec65f 100644
@@ -1832,6 +1832,7 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
                          char *masterbus, uint32_t firstport,
                          AddressSpace *as)
 {
+    Error *err = NULL;
     int i;
 
     ohci->as = as;
@@ -1857,9 +1858,12 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
         for(i = 0; i < num_ports; i++) {
             ports[i] = &ohci->rhport[i].port;
         }
-        if (usb_register_companion(masterbus, ports, num_ports,
-                firstport, ohci, &ohci_port_ops,
-                USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL) != 0) {
+        usb_register_companion(masterbus, ports, num_ports,
+                               firstport, ohci, &ohci_port_ops,
+                               USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
+                               &err);
+        if (err) {
+            error_report_err(err);
             return -1;
         }
     } else {
hw/usb/hcd-uhci.c +7 -3
index f903de7..2ca8de3 100644
@@ -1192,6 +1192,7 @@ static USBBusOps uhci_bus_ops = {
 
 static int usb_uhci_common_initfn(PCIDevice *dev)
 {
+    Error *err = NULL;
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
     UHCIPCIDeviceClass *u = container_of(pc, UHCIPCIDeviceClass, parent_class);
     UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
@@ -1209,9 +1210,12 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
         for(i = 0; i < NB_PORTS; i++) {
             ports[i] = &s->ports[i].port;
         }
-        if (usb_register_companion(s->masterbus, ports, NB_PORTS,
-                s->firstport, s, &uhci_port_ops,
-                USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL) != 0) {
+        usb_register_companion(s->masterbus, ports, NB_PORTS,
+                               s->firstport, s, &uhci_port_ops,
+                               USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
+                               &err);
+        if (err) {
+            error_report_err(err);
             return -1;
         }
     } else {
include/hw/usb.h +7 -5
index b20b959..453b22d 100644
@@ -526,8 +526,9 @@ struct USBBus {
 };
 
 struct USBBusOps {
-    int (*register_companion)(USBBus *bus, USBPort *ports[],
-                              uint32_t portcount, uint32_t firstport);
+    void (*register_companion)(USBBus *bus, USBPort *ports[],
+                               uint32_t portcount, uint32_t firstport,
+                               Error **errp);
     void (*wakeup_endpoint)(USBBus *bus, USBEndpoint *ep, unsigned int stream);
 };
 
@@ -543,9 +544,10 @@ USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
                        USBPortOps *ops, int speedmask);
-int usb_register_companion(const char *masterbus, USBPort *ports[],
-                           uint32_t portcount, uint32_t firstport,
-                           void *opaque, USBPortOps *ops, int speedmask);
+void usb_register_companion(const char *masterbus, USBPort *ports[],
+                            uint32_t portcount, uint32_t firstport,
+                            void *opaque, USBPortOps *ops, int speedmask,
+                            Error **errp);
 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr);
 void usb_unregister_port(USBBus *bus, USBPort *port);
 void usb_claim_port(USBDevice *dev, Error **errp);
Signature · 1 line
1.9.3
#3 lore raw

PATCH 3/4 ohci: Complete conversion to realize

In reply to Markus Armbruster

Commit 457215ec "ohci: Use QOM realize for OHCI" converted only "sysbus-ohci". Finish the job: convert "pci-ohci".

---
 hw/usb/hcd-ohci.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
hw/usb/hcd-ohci.c +17 -17
index 21ec65f..e180a17 100644
@@ -1827,10 +1827,10 @@ static USBPortOps ohci_port_ops = {
 static USBBusOps ohci_bus_ops = {
 };
 
-static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
-                         int num_ports, dma_addr_t localmem_base,
-                         char *masterbus, uint32_t firstport,
-                         AddressSpace *as)
+static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
+                          int num_ports, dma_addr_t localmem_base,
+                          char *masterbus, uint32_t firstport,
+                          AddressSpace *as, Error **errp)
 {
     Error *err = NULL;
     int i;
@@ -1863,8 +1863,8 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
                                USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
                                &err);
         if (err) {
-            error_report_err(err);
-            return -1;
+            error_propagate(errp, err);
+            return;
         }
     } else {
         usb_bus_new(&ohci->bus, sizeof(ohci->bus), &ohci_bus_ops, dev);
@@ -1884,8 +1884,6 @@ static int usb_ohci_init(OHCIState *ohci, DeviceState *dev,
 
     ohci->async_td = 0;
     qemu_register_reset(ohci_reset, ohci);
-
-    return 0;
 }
 
 #define TYPE_PCI_OHCI "pci-ohci"
@@ -1918,22 +1916,24 @@ static void ohci_die(OHCIState *ohci)
                  PCI_STATUS_DETECTED_PARITY);
 }
 
-static int usb_ohci_initfn_pci(PCIDevice *dev)
+static void usb_ohci_realize_pci(PCIDevice *dev, Error **errp)
 {
+    Error *err = NULL;
     OHCIPCIState *ohci = PCI_OHCI(dev);
 
     dev->config[PCI_CLASS_PROG] = 0x10; /* OHCI */
     dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
 
-    if (usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0,
-                      ohci->masterbus, ohci->firstport,
-                      pci_get_address_space(dev)) != 0) {
-        return -1;
+    usb_ohci_init(&ohci->state, DEVICE(dev), ohci->num_ports, 0,
+                  ohci->masterbus, ohci->firstport,
+                  pci_get_address_space(dev), &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
     }
+
     ohci->state.irq = pci_allocate_irq(dev);
-
     pci_register_bar(dev, 0, 0, &ohci->state.mem);
-    return 0;
 }
 
 static void usb_ohci_exit(PCIDevice *dev)
@@ -1975,7 +1975,7 @@ static void ohci_realize_pxa(DeviceState *dev, Error **errp)
 
     /* Cannot fail as we pass NULL for masterbus */
     usb_ohci_init(&s->ohci, dev, s->num_ports, s->dma_offset, NULL, 0,
-                  &address_space_memory);
+                  &address_space_memory, &error_abort);
     sysbus_init_irq(sbd, &s->ohci.irq);
     sysbus_init_mmio(sbd, &s->ohci.mem);
 }
@@ -2091,7 +2091,7 @@ static void ohci_pci_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-    k->init = usb_ohci_initfn_pci;
+    k->realize = usb_ohci_realize_pci;
     k->exit = usb_ohci_exit;
     k->vendor_id = PCI_VENDOR_ID_APPLE;
     k->device_id = PCI_DEVICE_ID_APPLE_IPID_USB;
Signature · 1 line
1.9.3
#4 lore raw

PATCH 4/4 uhci: Convert to realize

In reply to Markus Armbruster
---
 hw/usb/hcd-uhci.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/usb/hcd-uhci.c +8 -10
index 2ca8de3..e791377 100644
@@ -66,7 +66,7 @@ struct UHCIInfo {
     uint16_t   device_id;
     uint8_t    revision;
     uint8_t    irq_pin;
-    int        (*initfn)(PCIDevice *dev);
+    void       (*realize)(PCIDevice *dev, Error **errp);
     bool       unplug;
 };
 
@@ -1190,7 +1190,7 @@ static USBPortOps uhci_port_ops = {
 static USBBusOps uhci_bus_ops = {
 };
 
-static int usb_uhci_common_initfn(PCIDevice *dev)
+static void usb_uhci_common_realize(PCIDevice *dev, Error **errp)
 {
     Error *err = NULL;
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
@@ -1215,8 +1215,8 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
                                USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL,
                                &err);
         if (err) {
-            error_report_err(err);
-            return -1;
+            error_propagate(errp, err);
+            return;
         }
     } else {
         usb_bus_new(&s->bus, sizeof(s->bus), &uhci_bus_ops, DEVICE(dev));
@@ -1238,11 +1238,9 @@ static int usb_uhci_common_initfn(PCIDevice *dev)
     /* Use region 4 for consistency with real hardware.  BSD guests seem
        to rely on this.  */
     pci_register_bar(&s->dev, 4, PCI_BASE_ADDRESS_SPACE_IO, &s->io_bar);
-
-    return 0;
 }
 
-static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
+static void usb_uhci_vt82c686b_realize(PCIDevice *dev, Error **errp)
 {
     UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
     uint8_t *pci_conf = s->dev.config;
@@ -1254,7 +1252,7 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
     /* USB legacy support  */
     pci_set_long(pci_conf + 0xc0,0x00002000);
 
-    return usb_uhci_common_initfn(dev);
+    usb_uhci_common_realize(dev, errp);
 }
 
 static void usb_uhci_exit(PCIDevice *dev)
@@ -1300,7 +1298,7 @@ static void uhci_class_init(ObjectClass *klass, void *data)
     UHCIPCIDeviceClass *u = container_of(k, UHCIPCIDeviceClass, parent_class);
     UHCIInfo *info = data;
 
-    k->init = info->initfn ? info->initfn : usb_uhci_common_initfn;
+    k->realize = info->realize ? info->realize : usb_uhci_common_realize;
     k->exit = info->unplug ? usb_uhci_exit : NULL;
     k->vendor_id = info->vendor_id;
     k->device_id = info->device_id;
@@ -1339,7 +1337,7 @@ static UHCIInfo uhci_info[] = {
         .device_id = PCI_DEVICE_ID_VIA_UHCI,
         .revision  = 0x01,
         .irq_pin   = 3,
-        .initfn    = usb_uhci_vt82c686b_initfn,
+        .realize   = usb_uhci_vt82c686b_realize,
         .unplug    = true,
     },{
         .name      = "ich9-usb-uhci1", /* 00:1d.0 */
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/4 usb: Improve companion configuration error messages

In reply to Markus Armbruster

The previous commit broke the additional messages explaining the error messages. Improve the error messages, so they don't need explaining so much. Helps QMP users as well, unlike additional explanations.

---
 hw/usb/bus.c      | 18 ++++++++----------
 hw/usb/hcd-ehci.c | 21 ++++++---------------
 2 files changed, 14 insertions(+), 25 deletions(-)
hw/usb/bus.c +8 -10
index 8be942f..2219200 100644
@@ -364,16 +364,14 @@ void usb_register_companion(const char *masterbus, USBPort *ports[],
         }
     }
 
-    if (!bus || !bus->ops->register_companion) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
-                  "an USB masterbus");
-#if 0 /* conversion from qerror_report() to error_set() broke this: */
-        if (bus) {
-            error_printf_unless_qmp(
-                "USB bus '%s' does not allow companion controllers\n",
-                masterbus);
-        }
-#endif
+    if (!bus) {
+        error_setg(errp, "USB bus '%s' not found", masterbus);
+        return;
+    }
+    if (!bus->ops->register_companion) {
+        error_setg(errp, "Can't use USB bus '%s' as masterbus,"
+                   " it doesn't support companion controllers",
+                   masterbus);
         return;
     }
 
hw/usb/hcd-ehci.c +6 -15
index 7d16ba8..5c2a452 100644
@@ -777,26 +777,17 @@ static void ehci_register_companion(USBBus *bus, USBPort *ports[],
     uint32_t i;
 
     if (firstport + portcount > NB_PORTS) {
-        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "firstport",
-                  "firstport on masterbus");
-#if 0 /* conversion from qerror_report() to error_set() broke this: */
-        error_printf_unless_qmp(
-            "firstport value of %u makes companion take ports %u - %u, which "
-            "is outside of the valid range of 0 - %u\n", firstport, firstport,
-            firstport + portcount - 1, NB_PORTS - 1);
-#endif
+        error_setg(errp, "firstport must be between 0 and %u",
+                   NB_PORTS - portcount);
         return;
     }
 
     for (i = 0; i < portcount; i++) {
         if (s->companion_ports[firstport + i]) {
-            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "masterbus",
-                      "an USB masterbus");
-#if 0 /* conversion from qerror_report() to error_set() broke this: */
-            error_printf_unless_qmp(
-                "port %u on masterbus %s already has a companion assigned\n",
-                firstport + i, bus->qbus.name);
-#endif
+            error_setg(errp, "firstport %u asks for ports %u-%u,"
+                       " but port %u has a companion assigned already",
+                       firstport, firstport, firstport + portcount - 1,
+                       firstport + i);
             return;
         }
     }
Signature · 1 line
1.9.3
#5 lore raw
In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

This series requires my "[PATCH 00/10] pci: Partial conversion to realize" and my "[PATCH 0/9] Clean up around error_get_pretty(), qerror_report_err()".

Markus Armbruster (4):
usb: Propagate errors through usb_register_companion()
usb: Improve companion configuration error messages
ohci: Complete conversion to realize
uhci: Convert to realize

Series looks good. Can you ping me when the dependencies are merged?

thanks,
Gerd

#6 lore raw
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Markus Armbruster

This series requires my "[PATCH 00/10] pci: Partial conversion to realize" and my "[PATCH 0/9] Clean up around error_get_pretty(), qerror_report_err()".

Quoted 7 lines
Quoted 5 lines

Markus Armbruster (4):
usb: Propagate errors through usb_register_companion()
usb: Improve companion configuration error messages
ohci: Complete conversion to realize
uhci: Convert to realize

Series looks good. Can you ping me when the dependencies are merged?

Sure!

#7 lore raw
In reply to Gerd Hoffmann
Quoted 5 lines · Gerd Hoffmann
Quoted 4 lines · Markus Armbruster

This series requires my "[PATCH 00/10] pci: Partial conversion to realize" and my "[PATCH 0/9] Clean up around error_get_pretty(), qerror_report_err()".

Quoted 7 lines
Quoted 5 lines

Markus Armbruster (4):
usb: Propagate errors through usb_register_companion()
usb: Improve companion configuration error messages
ohci: Complete conversion to realize
uhci: Convert to realize

Series looks good. Can you ping me when the dependencies are merged?

Applies cleanly on current master (277263e), and passes my still out-of-tree pci-devs-test.

#8 lore raw
In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster

This series requires my "[PATCH 00/10] pci: Partial conversion to realize" and my "[PATCH 0/9] Clean up around error_get_pretty(), qerror_report_err()".

Markus Armbruster (4):
usb: Propagate errors through usb_register_companion()
usb: Improve companion configuration error messages
ohci: Complete conversion to realize
uhci: Convert to realize

Quoted 7 lines
 hw/usb/bus.c      | 27 ++++++++++++++-------------
 hw/usb/hcd-ehci.c | 28 +++++++++++-----------------
 hw/usb/hcd-ohci.c | 42 +++++++++++++++++++++++-------------------
 hw/usb/hcd-uhci.c | 26 ++++++++++++++------------
 include/hw/usb.h  | 12 +++++++-----
 5 files changed, 69 insertions(+), 66 deletions(-)

Added to usb patch queue.

thanks,
Gerd