Skip to contentSkip to conversation

usb cleanups: remove usb_bus_find(), extract sysbus-ohci to a separate file

PATCH In review Paolo Bonzini 5 participants 34 messages Feb 23, 2024 – Feb 26, 2024 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

cover usb cleanups: remove usb_bus_find(), extract sysbus-ohci to a separate file

Patches 1 to 3 start the removal of usb_bus_find() by replacing it with object_resolve_type_unambiguous(), a function that is included in the ACPI builder but should arguably be part of the core QOM API. Because the only USB host controller must be the one created by the machine init function itself, there is no need for a special functions that looks for the "first" bus.

Patches 4 to 7 allow machines that have builtin USB devices to make the USB system merely the default, and not require it. At this point usb_bus_find() is not used anymore outside usb.c, and the only remaining caller can inline it in patch 8.

Patches 9 and 10 do other build system cleanups to the USB subsystem, extracting sysbus-ohci to a separate file (as is already the case for EHCI and XHCI sysbus variants) and removing a duplicate file in the Meson sourcesets.

The diffstat looks unfavorable, but it's mostly due to improved documentation and to the duplicated header comment in hw/usb/hcd-ohci-sysbus.c.

Paolo

Paolo Bonzini (10):
acpi, qom: move object_resolve_type_unambiguous to core QOM
ppc: sam460ex: do not use usb_bus_find()
sh4: r2d: do not use usb_bus_find() mips/loongson3_virt: do not require CONFIG_USB
hppa: do not require CONFIG_USB
mac_newworld: do not require CONFIG_USB
pseries: do not require CONFIG_USB
usb: remove usb_bus_find
usb: extract sysbus-ohci to a separate file
usb: remove duplicate file in system_ss

 include/hw/usb.h         |  1 -
 include/qom/object.h     | 13 ++++++
 hw/hppa/machine.c        |  7 +--
 hw/i386/acpi-build.c     | 19 ++------
 hw/mips/loongson3_virt.c |  5 +-
 hw/ppc/mac_newworld.c    |  7 ++-
 hw/ppc/sam460ex.c        |  6 ++-
 hw/ppc/spapr.c           |  7 ++-
 hw/sh4/r2d.c             |  4 +-
 hw/usb/bus.c             | 15 +-----
 hw/usb/hcd-ohci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-ohci.c        | 58 ------------------------
 qom/object.c             | 16 +++++++
 hw/arm/Kconfig           | 12 +++--
 hw/display/Kconfig       |  1 +
 hw/hppa/Kconfig          |  2 +-
 hw/ppc/Kconfig           |  5 +-
 hw/sh4/Kconfig           |  1 -
 hw/usb/Kconfig           |  4 ++
 hw/usb/meson.build       |  3 +-
 20 files changed, 163 insertions(+), 114 deletions(-)
 create mode 100644 hw/usb/hcd-ohci-sysbus.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/10 acpi, qom: move object_resolve_type_unambiguous to core QOM

object_resolve_type_unambiguous provides a useful functionality, that is currently emulated for example by usb_bus_find(). Move it to core code and add error reporting for increased generality.

---
 include/qom/object.h | 13 +++++++++++++
 hw/i386/acpi-build.c | 19 ++++---------------
 qom/object.c         | 16 ++++++++++++++++
 3 files changed, 33 insertions(+), 15 deletions(-)
include/qom/object.h +13 -0
index afccd24ca7a..e9ed9550f05 100644
@@ -1550,6 +1550,19 @@ Object *object_resolve_path(const char *path, bool *ambiguous);
 Object *object_resolve_path_type(const char *path, const char *typename,
                                  bool *ambiguous);
 
+/**
+ * object_resolve_type_unambiguous:
+ * @typename: the type to look for
+ * @errp: pointer to error object
+ *
+ * Return the only object in the QOM tree of type @typename.
+ * If no match or more than one match is found, an error is
+ * returned.
+ *
+ * Returns: The matched object or NULL on path lookup failure.
+ */
+Object *object_resolve_type_unambiguous(const char *typename, Error **errp);
+
 /**
  * object_resolve_path_at:
  * @parent: the object in which to resolve the path
hw/i386/acpi-build.c +4 -15
index d3ce96dd9f9..4b47dbfd71c 100644
@@ -192,21 +192,10 @@ static void init_common_fadt_data(MachineState *ms, Object *o,
     *data = fadt;
 }
 
-static Object *object_resolve_type_unambiguous(const char *typename)
-{
-    bool ambig;
-    Object *o = object_resolve_path_type("", typename, &ambig);
-
-    if (ambig || !o) {
-        return NULL;
-    }
-    return o;
-}
-
 static void acpi_get_pm_info(MachineState *machine, AcpiPmInfo *pm)
 {
-    Object *piix = object_resolve_type_unambiguous(TYPE_PIIX4_PM);
-    Object *lpc = object_resolve_type_unambiguous(TYPE_ICH9_LPC_DEVICE);
+    Object *piix = object_resolve_type_unambiguous(TYPE_PIIX4_PM, NULL);
+    Object *lpc = object_resolve_type_unambiguous(TYPE_ICH9_LPC_DEVICE, NULL);
     Object *obj = piix ? piix : lpc;
     QObject *o;
     pm->cpu_hp_io_base = 0;
@@ -1428,8 +1417,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
            AcpiPmInfo *pm, AcpiMiscInfo *misc,
            Range *pci_hole, Range *pci_hole64, MachineState *machine)
 {
-    Object *i440fx = object_resolve_type_unambiguous(TYPE_I440FX_PCI_HOST_BRIDGE);
-    Object *q35 = object_resolve_type_unambiguous(TYPE_Q35_HOST_DEVICE);
+    Object *i440fx = object_resolve_type_unambiguous(TYPE_I440FX_PCI_HOST_BRIDGE, NULL);
+    Object *q35 = object_resolve_type_unambiguous(TYPE_Q35_HOST_DEVICE, NULL);
     CrsRangeEntry *entry;
     Aml *dsdt, *sb_scope, *scope, *dev, *method, *field, *pkg, *crs;
     CrsRangeSet crs_range_set;
qom/object.c +16 -0
index 2c4c64d2b63..d4a001cf411 100644
@@ -2229,6 +2229,22 @@ Object *object_resolve_path_at(Object *parent, const char *path)
     return object_resolve_abs_path(parent, parts, TYPE_OBJECT);
 }
 
+Object *object_resolve_type_unambiguous(const char *typename, Error **errp)
+{
+    bool ambig;
+    Object *o = object_resolve_path_type("", typename, &ambig);
+
+    if (ambig) {
+        error_setg(errp, "More than one object of type %s", typename);
+        return NULL;
+    }
+    if (!o) {
+        error_setg(errp, "No object found of type %s", typename);
+        return NULL;
+    }
+    return o;
+}
+
 typedef struct StringProperty
 {
     char *(*get)(Object *, Error **);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/10
#2 lore raw

Re: [PATCH 01/10] acpi, qom: move object_resolve_type_unambiguous to core QOM

Quoted 10 lines · Paolo Bonzini

object_resolve_type_unambiguous provides a useful functionality, that is currently emulated for example by usb_bus_find(). Move it to core code and add error reporting for increased generality.

---
  include/qom/object.h | 13 +++++++++++++
  hw/i386/acpi-build.c | 19 ++++---------------
  qom/object.c         | 16 ++++++++++++++++
  3 files changed, 33 insertions(+), 15 deletions(-)
Reviewed-by on v1 1/10
#3 lore raw

Re: [PATCH 01/10] acpi, qom: move object_resolve_type_unambiguous to core QOM

In reply to Paolo Bonzini
Quoted 10 lines · Paolo Bonzini

object_resolve_type_unambiguous provides a useful functionality, that is currently emulated for example by usb_bus_find(). Move it to core code and add error reporting for increased generality.

---
  include/qom/object.h | 13 +++++++++++++
  hw/i386/acpi-build.c | 19 ++++---------------
  qom/object.c         | 16 ++++++++++++++++
  3 files changed, 33 insertions(+), 15 deletions(-)
#4 lore raw

PATCH 2/10 ppc: sam460ex: do not use usb_bus_find()

In reply to Paolo Bonzini

usb_bus_find() is always used with argument -1; it can be replaced with a search of the single USB bus on the machine.

---
 hw/ppc/sam460ex.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ppc/sam460ex.c +4 -2
index 1e615b8d355..4d5655ab6b4 100644
@@ -273,6 +273,7 @@ static void sam460ex_init(MachineState *machine)
     DeviceState *uic[4];
     int i;
     PCIBus *pci_bus;
+    USBBus *usb_bus;
     PowerPCCPU *cpu;
     CPUPPCState *env;
     I2CBus *i2c;
@@ -420,8 +421,9 @@ static void sam460ex_init(MachineState *machine)
     sysbus_realize_and_unref(sbdev, &error_fatal);
     sysbus_mmio_map(sbdev, 0, 0x4bffd0000);
     sysbus_connect_irq(sbdev, 0, qdev_get_gpio_in(uic[2], 30));
-    usb_create_simple(usb_bus_find(-1), "usb-kbd");
-    usb_create_simple(usb_bus_find(-1), "usb-mouse");
+    usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));
+    usb_create_simple(usb_bus, "usb-kbd");
+    usb_create_simple(usb_bus, "usb-mouse");
 
     /* PCIe buses */
     dev = qdev_new(TYPE_PPC460EX_PCIE_HOST);
Signature · 1 line
2.43.0
Reviewed-by on v1 2/10
#5 lore raw

Re: [PATCH 02/10] ppc: sam460ex: do not use usb_bus_find()

Quoted 23 lines · Paolo Bonzini

usb_bus_find() is always used with argument -1; it can be replaced with a search of the single USB bus on the machine.

---
  hw/ppc/sam460ex.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
hw/ppc/sam460ex.c +1 -0
index 1e615b8d355..4d5655ab6b4 100644
@@ -273,6 +273,7 @@ static void sam460ex_init(MachineState *machine)
      DeviceState *uic[4];
      int i;
      PCIBus *pci_bus;
+    USBBus *usb_bus;
      PowerPCCPU *cpu;
      CPUPPCState *env;
      I2CBus *i2c;
@@ -420,8 +421,9 @@ static void sam460ex_init(MachineState *machine)
      sysbus_realize_and_unref(sbdev, &error_fatal);

hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 429

Quoted 10 lines
hw/ppc/sam460ex.c +3 -2
      sysbus_mmio_map(sbdev, 0, 0x4bffd0000);
      sysbus_connect_irq(sbdev, 0, qdev_get_gpio_in(uic[2], 30));
-    usb_create_simple(usb_bus_find(-1), "usb-kbd");
-    usb_create_simple(usb_bus_find(-1), "usb-mouse");
+    usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));
+    usb_create_simple(usb_bus, "usb-kbd");
+    usb_create_simple(usb_bus, "usb-mouse");
 
      /* PCIe buses */
      dev = qdev_new(TYPE_PPC460EX_PCIE_HOST);
#6 lore raw

Re: [PATCH 02/10] ppc: sam460ex: do not use usb_bus_find()

In reply to Paolo Bonzini
Quoted 17 lines · Paolo Bonzini

Once the Kconfig for hw/mips is cleaned up, it will be possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus created by loongson3_virt_devices_init().

---
 hw/mips/loongson3_virt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/mips/loongson3_virt.c +0 -0
index caedde2df00..b2a8b22b4ea 100644

hw/mips/loongson3_virt.c static inline void loongson3_virt_devices_init(MachineState *machine, · line 452

Quoted 8 lines
hw/mips/loongson3_virt.c +3 -2
@@ -447,8 +447,9 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
 
     if (defaults_enabled() && object_class_by_name("pci-ohci")) {
         pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-tablet");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-tablet");

In the previous patches, you cast just once, like this:

           USBBus *usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));
           usb_create_simple(usb_bus, "usb-kbd");
           usb_create_simple(usb_bus, "usb-tablet");

Could you do that here, too?

Same for the next few patches.

Quoted 3 lines
hw/mips/loongson3_virt.c +0 -0
     }
 
     pci_init_nic_devices(pci_bus, mc->default_nic);
#7 lore raw

Re: [PATCH 02/10] ppc: sam460ex: do not use usb_bus_find()

Please ignore this one; I replied to the wrong patch by accident.

#8 lore raw

Re: [PATCH 02/10] ppc: sam460ex: do not use usb_bus_find()

Quoted 1 line · Markus Armbruster

Please ignore this one; I replied to the wrong patch by accident.

Your comment is still valid for that patch so no need to ignore it.

Regards,
BALATON Zoltan

#9 lore raw

Re: [PATCH 02/10] ppc: sam460ex: do not use usb_bus_find()

In reply to Paolo Bonzini
Quoted 22 lines · Paolo Bonzini

usb_bus_find() is always used with argument -1; it can be replaced with a search of the single USB bus on the machine.

---
 hw/ppc/sam460ex.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/ppc/sam460ex.c +1 -0
index 1e615b8d355..4d5655ab6b4 100644
@@ -273,6 +273,7 @@ static void sam460ex_init(MachineState *machine)
     DeviceState *uic[4];
     int i;
     PCIBus *pci_bus;
+    USBBus *usb_bus;
     PowerPCCPU *cpu;
     CPUPPCState *env;
     I2CBus *i2c;

hw/ppc/sam460ex.c static void sam460ex_init(MachineState *machine) · line 424

Quoted 6 lines
hw/ppc/sam460ex.c +1 -2
@@ -420,8 +421,9 @@ static void sam460ex_init(MachineState *machine)
     sysbus_realize_and_unref(sbdev, &error_fatal);
     sysbus_mmio_map(sbdev, 0, 0x4bffd0000);
     sysbus_connect_irq(sbdev, 0, qdev_get_gpio_in(uic[2], 30));
-    usb_create_simple(usb_bus_find(-1), "usb-kbd");
-    usb_create_simple(usb_bus_find(-1), "usb-mouse");
+    usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));

This long line is really easy to break.

Quoted 5 lines
hw/ppc/sam460ex.c +2 -0
+    usb_create_simple(usb_bus, "usb-kbd");
+    usb_create_simple(usb_bus, "usb-mouse");
 
     /* PCIe buses */
     dev = qdev_new(TYPE_PPC460EX_PCIE_HOST);
#10 lore raw

PATCH 3/10 sh4: r2d: do not use usb_bus_find()

In reply to Paolo Bonzini

usb_bus_find() is always used with argument -1; it can be replaced with a search of the single USB bus on the machine.

---
 hw/sh4/r2d.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/sh4/r2d.c +3 -1
index c73e8f49b8a..4d34ad00d93 100644
@@ -244,6 +244,7 @@ static void r2d_init(MachineState *machine)
     SysBusDevice *busdev;
     MemoryRegion *address_space_mem = get_system_memory();
     PCIBus *pci_bus;
+    USBBus *usb_bus;
 
     cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
     env = &cpu->env;
@@ -312,7 +313,8 @@ static void r2d_init(MachineState *machine)
     pci_init_nic_devices(pci_bus, mc->default_nic);
 
     /* USB keyboard */
-    usb_create_simple(usb_bus_find(-1), "usb-kbd");
+    usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));
+    usb_create_simple(usb_bus, "usb-kbd");
 
     /* Todo: register on board registers */
     memset(&boot_params, 0, sizeof(boot_params));
Signature · 1 line
2.43.0
Reviewed-by on v1 3/10
#11 lore raw

Re: [PATCH 03/10] sh4: r2d: do not use usb_bus_find()

Quoted 22 lines · Paolo Bonzini

usb_bus_find() is always used with argument -1; it can be replaced with a search of the single USB bus on the machine.

---
  hw/sh4/r2d.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
hw/sh4/r2d.c +1 -0
index c73e8f49b8a..4d34ad00d93 100644
@@ -244,6 +244,7 @@ static void r2d_init(MachineState *machine)
      SysBusDevice *busdev;
      MemoryRegion *address_space_mem = get_system_memory();
      PCIBus *pci_bus;
+    USBBus *usb_bus;
 
      cpu = SUPERH_CPU(cpu_create(machine->cpu_type));
      env = &cpu->env;

hw/sh4/r2d.c static void r2d_init(MachineState *machine) · line 320

Quoted 9 lines
hw/sh4/r2d.c +2 -1
@@ -312,7 +313,8 @@ static void r2d_init(MachineState *machine)
      pci_init_nic_devices(pci_bus, mc->default_nic);
 
      /* USB keyboard */
-    usb_create_simple(usb_bus_find(-1), "usb-kbd");
+    usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));
+    usb_create_simple(usb_bus, "usb-kbd");
 
      /* Todo: register on board registers */
      memset(&boot_params, 0, sizeof(boot_params));
#12 lore raw

PATCH 4/10 mips/loongson3_virt: do not require CONFIG_USB

In reply to Paolo Bonzini

Once the Kconfig for hw/mips is cleaned up, it will be possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus created by loongson3_virt_devices_init().

---
 hw/mips/loongson3_virt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/mips/loongson3_virt.c +3 -2
index caedde2df00..b2a8b22b4ea 100644
@@ -447,8 +447,9 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
 
     if (defaults_enabled() && object_class_by_name("pci-ohci")) {
         pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-tablet");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-tablet");
     }
 
     pci_init_nic_devices(pci_bus, mc->default_nic);
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH 04/10] mips/loongson3_virt: do not require CONFIG_USB

Quoted 17 lines · Paolo Bonzini

Once the Kconfig for hw/mips is cleaned up, it will be possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus created by loongson3_virt_devices_init().

---
  hw/mips/loongson3_virt.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/mips/loongson3_virt.c +0 -0
index caedde2df00..b2a8b22b4ea 100644

hw/mips/loongson3_virt.c static inline void loongson3_virt_devices_init(MachineState *machine, · line 450

Quoted 6 lines
hw/mips/loongson3_virt.c +1 -2
@@ -447,8 +447,9 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
 
      if (defaults_enabled() && object_class_by_name("pci-ohci")) {
          pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-tablet");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);

Please swap the "Object *usb_bus" and the "pci_create_simple" lines, so that the declaration is at the beginning of the block.

Thomas

#14 lore raw

Re: [PATCH 04/10] mips/loongson3_virt: do not require CONFIG_USB

In reply to Paolo Bonzini
Quoted 17 lines · Paolo Bonzini

Once the Kconfig for hw/mips is cleaned up, it will be possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus created by loongson3_virt_devices_init().

---
 hw/mips/loongson3_virt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/mips/loongson3_virt.c +0 -0
index caedde2df00..b2a8b22b4ea 100644

hw/mips/loongson3_virt.c static inline void loongson3_virt_devices_init(MachineState *machine, · line 452

Quoted 8 lines
hw/mips/loongson3_virt.c +3 -2
@@ -447,8 +447,9 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
 
     if (defaults_enabled() && object_class_by_name("pci-ohci")) {
         pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-tablet");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-tablet");

In the previous patches, you cast just once, like this:

           USBBus *usb_bus = USB_BUS(object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort));
           usb_create_simple(usb_bus, "usb-kbd");
           usb_create_simple(usb_bus, "usb-tablet");

Could you do that here, too?

Same for the next few patches.

Quoted 3 lines
hw/mips/loongson3_virt.c +0 -0
     }
 
     pci_init_nic_devices(pci_bus, mc->default_nic);
#15 lore raw

PATCH 5/10 hppa: do not require CONFIG_USB

In reply to Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
 hw/hppa/machine.c | 7 ++++---
 hw/hppa/Kconfig   | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
hw/hppa/machine.c +4 -3
index 5fcaf5884be..11982d5776c 100644
@@ -396,10 +396,11 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
     }
 
     /* create USB OHCI controller for USB keyboard & mouse on Astro machines */
-    if (!lasi_dev && machine->enable_graphics) {
+    if (!lasi_dev && machine->enable_graphics && defaults_enabled()) {
         pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-mouse");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
     }
 
     /* register power switch emulation */
hw/hppa/Kconfig +1 -1
index dff5df7f725..ee7ffd2bfb5 100644
@@ -2,6 +2,7 @@ config HPPA_B160L
     bool
     imply PCI_DEVICES
     imply E1000_PCI
+    imply USB_OHCI_PCI
     imply VIRTIO_VGA
     select ASTRO
     select DINO
@@ -17,4 +18,3 @@ config HPPA_B160L
     select LASIPS2
     select PARALLEL
     select ARTIST
-    select USB_OHCI_PCI
Signature · 1 line
2.43.0
Reviewed-by on v1 5/10
#16 lore raw

Re: [PATCH 05/10] hppa: do not require CONFIG_USB

Quoted 19 lines · Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
  hw/hppa/machine.c | 7 ++++---
  hw/hppa/Kconfig   | 2 +-
  2 files changed, 5 insertions(+), 4 deletions(-)
hw/hppa/machine.c +0 -0
index 5fcaf5884be..11982d5776c 100644

hw/hppa/machine.c static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, · line 401

Quoted 9 lines
hw/hppa/machine.c +2 -3
@@ -396,10 +396,11 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
      }
 
      /* create USB OHCI controller for USB keyboard & mouse on Astro machines */
-    if (!lasi_dev && machine->enable_graphics) {
+    if (!lasi_dev && machine->enable_graphics && defaults_enabled()) {
          pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-mouse");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);

Declare variable at begin of function; can be casted to USB_BUS once. Otherwise:

Quoted 3 lines
hw/hppa/machine.c +2 -0
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
      }
#17 lore raw

Re: [PATCH 05/10] hppa: do not require CONFIG_USB

In reply to Paolo Bonzini
Quoted 19 lines · Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
  hw/hppa/machine.c | 7 ++++---
  hw/hppa/Kconfig   | 2 +-
  2 files changed, 5 insertions(+), 4 deletions(-)
hw/hppa/machine.c +0 -0
index 5fcaf5884be..11982d5776c 100644

hw/hppa/machine.c static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, · line 399

Quoted 5 lines
hw/hppa/machine.c +1 -1
@@ -396,10 +396,11 @@ static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus,
      }
 
      /* create USB OHCI controller for USB keyboard & mouse on Astro machines */
-    if (!lasi_dev && machine->enable_graphics) {
+    if (!lasi_dev && machine->enable_graphics && defaults_enabled()) {

Do we need the defaults_enabled() here? Isn't enable_graphics already disabled if defaults_enabled() is not set?

Thomas

Quoted 7 lines
hw/hppa/machine.c +3 -2
          pci_create_simple(pci_bus, -1, "pci-ohci");
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-mouse");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
      }
#18 lore raw

Re: [PATCH 05/10] hppa: do not require CONFIG_USB

Quoted 15 lines · Thomas Huth
Quoted 14 lines · Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
  hw/hppa/machine.c | 7 ++++---
  hw/hppa/Kconfig   | 2 +-
  2 files changed, 5 insertions(+), 4 deletions(-)
Quoted 13 lines

hw/hppa/machine.c static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, · line 399

Quoted 11 lines
hw/hppa/machine.c +0 -0
index 5fcaf5884be..11982d5776c 100644
@@ -396,10 +396,11 @@ static void machine_HP_common_init_tail(MachineState 
 *machine, PCIBus *pci_bus,
      }
        /* create USB OHCI controller for USB keyboard & mouse on Astro 

machines */

hw/hppa/machine.c +1 -1
-    if (!lasi_dev && machine->enable_graphics) {
+    if (!lasi_dev && machine->enable_graphics && defaults_enabled()) {

Do we need the defaults_enabled() here? Isn't enable_graphics already disabled if defaults_enabled() is not set?

Isn't enable_graphics controlled by -nographic and defaults_enabled controlled by -nodefaults? I think they are independent but maybe that does not answer the question if it's needed or not.

Regards,
BALATON Zoltan

Quoted 14 lines

Thomas

Quoted 8 lines
          pci_create_simple(pci_bus, -1, "pci-ohci");
hw/hppa/machine.c +1 -2
-        usb_create_simple(usb_bus_find(-1), "usb-kbd");
-        usb_create_simple(usb_bus_find(-1), "usb-mouse");
+        Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, 

&error_abort);

hw/hppa/machine.c +2 -0
+        usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+        usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
      }
#19 lore raw

Re: [PATCH 05/10] hppa: do not require CONFIG_USB

Quoted 9 lines · BALATON Zoltan
Quoted 5 lines

hw/hppa/machine.c static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, · line 399

Quoted 2 lines
hw/hppa/machine.c +1 -1
-    if (!lasi_dev && machine->enable_graphics) {
+    if (!lasi_dev && machine->enable_graphics && defaults_enabled()) {

Do we need the defaults_enabled() here? Isn't enable_graphics already disabled if defaults_enabled() is not set?

Isn't enable_graphics controlled by -nographic and defaults_enabled controlled by -nodefaults? I think they are independent but maybe that does not answer the question if it's needed or not.

Indeed they are different. The idea is that if graphics are disabled you interact with a serial console so you don't need keyboard or mouse; and if default devices are disabled of course you create as little as possible and leave everything to the user.

Paolo

#20 lore raw

Re: [PATCH 05/10] hppa: do not require CONFIG_USB

Quoted 7 lines · Paolo Bonzini
Quoted 6 lines · BALATON Zoltan
Quoted 5 lines

hw/hppa/machine.c static void machine_HP_common_init_tail(MachineState *machine, PCIBus *pci_bus, · line 399

Quoted 2 lines
hw/hppa/machine.c +1 -1
-    if (!lasi_dev && machine->enable_graphics) {
+    if (!lasi_dev && machine->enable_graphics && defaults_enabled()) {

Do we need the defaults_enabled() here? Isn't enable_graphics already disabled if defaults_enabled() is not set?

Quoted 8 lines
Quoted 3 lines

Isn't enable_graphics controlled by -nographic and defaults_enabled controlled by -nodefaults? I think they are independent but maybe that does not answer the question if it's needed or not.

Indeed they are different. The idea is that if graphics are disabled you interact with a serial console so you don't need keyboard or mouse; and if default devices are disabled of course you create as little as possible and leave everything to the user.

Indeed, I just double-checked and they are independent, sorry for mis-remembering that.

Thomas

#21 lore raw

PATCH 6/10 mac_newworld: do not require CONFIG_USB

In reply to Paolo Bonzini

With --without-default-devices it should not be required to have devices in the binary that are removed by -nodefaults. It should be therefore possible to build a binary that does not include any USB host controller or any of the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

With this change, it is possible to change "select USB_OHCI_PCI" into an "imply" directive.

---
 hw/ppc/mac_newworld.c | 7 +++----
 hw/ppc/Kconfig        | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)
hw/ppc/mac_newworld.c +3 -4
index b36dbaf2b68..4efebab66b4 100644
@@ -431,10 +431,9 @@ static void ppc_core99_init(MachineState *machine)
         /* U3 needs to use USB for input because Linux doesn't support via-cuda
         on PPC64 */
         if (!has_adb || machine_arch == ARCH_MAC99_U3) {
-            USBBus *usb_bus = usb_bus_find(-1);
-
-            usb_create_simple(usb_bus, "usb-kbd");
-            usb_create_simple(usb_bus, "usb-mouse");
+            Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+            usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+            usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
         }
     }
 
hw/ppc/Kconfig +1 -1
index 44263a58c4d..9841c2c9690 100644
@@ -116,13 +116,13 @@ config MAC_NEWWORLD
     imply PCI_DEVICES
     imply SUNGEM
     imply TEST_DEVICES
+    imply USB_OHCI_PCI
     select ADB
     select MACIO
     select MACIO_GPIO
     select MAC_PMU
     select UNIN_PCI
     select FW_CFG_PPC
-    select USB_OHCI_PCI
 
 config E500
     bool
Signature · 1 line
2.43.0
Reviewed-by on v1 6/10
#22 lore raw

Re: [PATCH 06/10] mac_newworld: do not require CONFIG_USB

Quoted 11 lines · Paolo Bonzini

With --without-default-devices it should not be required to have devices in the binary that are removed by -nodefaults. It should be therefore possible to build a binary that does not include any USB host controller or any of the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

With this change, it is possible to change "select USB_OHCI_PCI" into an "imply" directive.

Quoted 6 lines
---
  hw/ppc/mac_newworld.c | 7 +++----
  hw/ppc/Kconfig        | 2 +-
  2 files changed, 4 insertions(+), 5 deletions(-)
#23 lore raw

PATCH 7/10 pseries: do not require CONFIG_USB

In reply to Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
 hw/ppc/spapr.c | 7 +++----
 hw/ppc/Kconfig | 1 +
 2 files changed, 4 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +3 -4
index 0d72d286d80..44d339982da 100644
@@ -3024,10 +3024,9 @@ static void spapr_machine_init(MachineState *machine)
         }
 
         if (has_vga) {
-            USBBus *usb_bus = usb_bus_find(-1);
-
-            usb_create_simple(usb_bus, "usb-kbd");
-            usb_create_simple(usb_bus, "usb-mouse");
+            Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+            usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+            usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
         }
     }
 
hw/ppc/Kconfig +1 -0
index 9841c2c9690..d497fa2b825 100644
@@ -1,5 +1,6 @@
 config PSERIES
     bool
+    imply USB_OHCI_PCI
     imply PCI_DEVICES
     imply TEST_DEVICES
     imply VIRTIO_VGA
Signature · 1 line
2.43.0
Reviewed-by on v1 7/10
#24 lore raw

Re: [PATCH 07/10] pseries: do not require CONFIG_USB

Quoted 19 lines · Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
  hw/ppc/spapr.c | 7 +++----
  hw/ppc/Kconfig | 1 +
  2 files changed, 4 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +0 -0
index 0d72d286d80..44d339982da 100644

hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 3026

Quoted 3 lines
hw/ppc/spapr.c +0 -0
@@ -3024,10 +3024,9 @@ static void spapr_machine_init(MachineState *machine)
          }
 
          if (has_vga) {

Pre-existing, don't we want defaults_enabled() instead of has_vga here?

Quoted 15 lines
hw/ppc/spapr.c +3 -4
-            USBBus *usb_bus = usb_bus_find(-1);
-
-            usb_create_simple(usb_bus, "usb-kbd");
-            usb_create_simple(usb_bus, "usb-mouse");
+            Object *usb_bus = object_resolve_type_unambiguous(TYPE_USB_BUS, &error_abort);
+            usb_create_simple(USB_BUS(usb_bus), "usb-kbd");
+            usb_create_simple(USB_BUS(usb_bus), "usb-mouse");
          }
      }
 
hw/ppc/Kconfig +0 -0
index 9841c2c9690..d497fa2b825 100644

hw/ppc/Kconfig line 6

Quoted 6 lines
hw/ppc/Kconfig +1 -0
@@ -1,5 +1,6 @@
  config PSERIES
      bool
+    imply USB_OHCI_PCI
      imply PCI_DEVICES
      imply TEST_DEVICES
      imply VIRTIO_VGA
#25 lore raw

Re: [PATCH 07/10] pseries: do not require CONFIG_USB

Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 21 lines · Paolo Bonzini

With --without-default-devices it is possible to build a binary that does not include any USB host controller and therefore that does not include the code guarded by CONFIG_USB. While the simpler creation functions such as usb_create_simple can be inlined, this is not true of usb_bus_find(). Remove it, replacing it with a search of the single USB bus on the machine.

---
  hw/ppc/spapr.c | 7 +++----
  hw/ppc/Kconfig | 1 +
  2 files changed, 4 insertions(+), 4 deletions(-)
hw/ppc/spapr.c +0 -0
index 0d72d286d80..44d339982da 100644
@@ -3024,10 +3024,9 @@ static void spapr_machine_init(MachineState *machine)
          }
 
Quoted 3 lines

hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 3026

Quoted 1 line
hw/ppc/spapr.c +0 -0
          if (has_vga) {

Pre-existing, don't we want defaults_enabled() instead of has_vga here?

Yeah, but I am not sure it can be changed since pseries machine types are versioned.

Paolo

#26 lore raw

PATCH 8/10 usb: remove usb_bus_find

In reply to Paolo Bonzini

Inline the sole remaining use, which is for the -usbdevice command line.

---
 include/hw/usb.h |  1 -
 hw/usb/bus.c     | 15 +--------------
 2 files changed, 1 insertion(+), 15 deletions(-)
include/hw/usb.h +0 -1
index cfeead28403..d46d96779ad 100644
@@ -498,7 +498,6 @@ struct USBBusOps {
 void usb_bus_new(USBBus *bus, size_t bus_size,
                  USBBusOps *ops, DeviceState *host);
 void usb_bus_release(USBBus *bus);
-USBBus *usb_bus_find(int busnr);
 void usb_legacy_register(const char *typename, const char *usbdevice_name,
                          USBDevice *(*usbdevice_init)(void));
 USBDevice *usbdevice_create(const char *cmdline);
hw/usb/bus.c +1 -14
index 76fda41b7ec..796769fadb4 100644
@@ -100,19 +100,6 @@ void usb_bus_release(USBBus *bus)
     QTAILQ_REMOVE(&busses, bus, next);
 }
 
-USBBus *usb_bus_find(int busnr)
-{
-    USBBus *bus;
-
-    if (-1 == busnr)
-        return QTAILQ_FIRST(&busses);
-    QTAILQ_FOREACH(bus, &busses, next) {
-        if (bus->busnr == busnr)
-            return bus;
-    }
-    return NULL;
-}
-
 static void usb_device_realize(USBDevice *dev, Error **errp)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
@@ -643,7 +630,7 @@ HumanReadableText *qmp_x_query_usb(Error **errp)
 /* handle legacy -usbdevice cmd line option */
 USBDevice *usbdevice_create(const char *driver)
 {
-    USBBus *bus = usb_bus_find(-1 /* any */);
+    USBBus *bus = QTAILQ_FIRST(&busses);
     LegacyUSBFactory *f = NULL;
     Error *err = NULL;
     GSList *i;
Signature · 1 line
2.43.0
#28 lore raw

PATCH 9/10 usb: extract sysbus-ohci to a separate file

In reply to Paolo Bonzini

Split the sysbus version to a separate file so that it is not included in PCI-only machines, and adjust Kconfig for machines that do need sysbus-ohci. The copyrights are based on the time and employer of balrog and Paul Brook's contributions.

While adjusting the SM501 dependency, move it to the right place instead of keeping it in the R4D machine.

---
 hw/usb/hcd-ohci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++
 hw/usb/hcd-ohci.c        | 58 ------------------------
 hw/arm/Kconfig           | 12 +++--
 hw/display/Kconfig       |  1 +
 hw/ppc/Kconfig           |  2 +-
 hw/sh4/Kconfig           |  1 -
 hw/usb/Kconfig           |  4 ++
 hw/usb/meson.build       |  1 +
 8 files changed, 105 insertions(+), 65 deletions(-)
 create mode 100644 hw/usb/hcd-ohci-sysbus.c
hw/usb/hcd-ohci-sysbus.c new file +91 -0
new file mode 100644
index 00000000000..4e4481232b6
@@ -0,0 +1,91 @@
+/*
+ * QEMU USB OHCI Emulation
+ * Copyright (c) 2006 Openedhand Ltd.
+ * Copyright (c) 2010 CodeSourcery
+ * Copyright (c) 2024 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/irq.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "qemu/timer.h"
+#include "hw/usb.h"
+#include "migration/vmstate.h"
+#include "hw/sysbus.h"
+#include "hw/qdev-dma.h"
+#include "hw/qdev-properties.h"
+#include "trace.h"
+#include "hcd-ohci.h"
+
+
+static void ohci_realize_pxa(DeviceState *dev, Error **errp)
+{
+    OHCISysBusState *s = SYSBUS_OHCI(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    Error *err = NULL;
+
+    usb_ohci_init(&s->ohci, dev, s->num_ports, s->dma_offset,
+                  s->masterbus, s->firstport,
+                  &address_space_memory, ohci_sysbus_die, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_init_irq(sbd, &s->ohci.irq);
+    sysbus_init_mmio(sbd, &s->ohci.mem);
+}
+
+static void usb_ohci_reset_sysbus(DeviceState *dev)
+{
+    OHCISysBusState *s = SYSBUS_OHCI(dev);
+    OHCIState *ohci = &s->ohci;
+
+    ohci_hard_reset(ohci);
+}
+
+static Property ohci_sysbus_properties[] = {
+    DEFINE_PROP_STRING("masterbus", OHCISysBusState, masterbus),
+    DEFINE_PROP_UINT32("num-ports", OHCISysBusState, num_ports, 3),
+    DEFINE_PROP_UINT32("firstport", OHCISysBusState, firstport, 0),
+    DEFINE_PROP_DMAADDR("dma-offset", OHCISysBusState, dma_offset, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ohci_sysbus_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = ohci_realize_pxa;
+    set_bit(DEVICE_CATEGORY_USB, dc->categories);
+    dc->desc = "OHCI USB Controller";
+    device_class_set_props(dc, ohci_sysbus_properties);
+    dc->reset = usb_ohci_reset_sysbus;
+}
+
+static const TypeInfo ohci_sysbus_info = {
+    .name          = TYPE_SYSBUS_OHCI,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(OHCISysBusState),
+    .class_init    = ohci_sysbus_class_init,
+};
+
+static void ohci_register_types(void)
+{
+    type_register_static(&ohci_sysbus_info);
+}
+
+type_init(ohci_register_types)
hw/usb/hcd-ohci.c +0 -58

67 lines not on this page · raw message

hw/arm/Kconfig +7 -5
index 29abe1da29c..ffb9041b07f 100644
@@ -185,7 +185,7 @@ config PXA2XX
     select SERIAL
     select SD
     select SSI
-    select USB_OHCI
+    select USB_OHCI_SYSBUS
     select PCMCIA
 
 config GUMSTIX
@@ -256,7 +256,7 @@ config REALVIEW
     select PL310  # cache controller
     select ARM_SBCON_I2C
     select DS1338 # I2C RTC+NVRAM
-    select USB_OHCI
+    select USB_OHCI_SYSBUS
 
 config SBSA_REF
     bool
@@ -337,7 +337,7 @@ config VERSATILE
     select PL080  # DMA controller
     select PL190  # Vector PIC
     select REALVIEW
-    select USB_OHCI
+    select USB_OHCI_SYSBUS
 
 config VEXPRESS
     bool
@@ -393,6 +393,7 @@ config ALLWINNER_A10
     select AXP2XX_PMU
     select SERIAL
     select UNIMP
+    select USB_OHCI_SYSBUS
 
 config ALLWINNER_H3
     bool
@@ -406,7 +407,7 @@ config ALLWINNER_H3
     select ARM_TIMER
     select ARM_GIC
     select UNIMP
-    select USB_OHCI
+    select USB_OHCI_SYSBUS
     select USB_EHCI_SYSBUS
     select SD
 
@@ -422,7 +423,7 @@ config ALLWINNER_R40
     select ARM_TIMER
     select ARM_GIC
     select UNIMP
-    select USB_OHCI
+    select USB_OHCI_SYSBUS
     select USB_EHCI_SYSBUS
     select SD
 
@@ -528,6 +529,7 @@ config NPCM7XX
     select SSI
     select UNIMP
     select PCA954X
+    select USB_OHCI_SYSBUS
 
 config FSL_IMX25
     bool
hw/display/Kconfig +1 -0
index 1aafe1923d2..07acb37dc66 100644
@@ -77,6 +77,7 @@ config SM501
     select I2C
     select DDC
     select SERIAL
+    select USB_OHCI_SYSBUS
 
 config TCX
     bool
hw/ppc/Kconfig +1 -1
index d497fa2b825..d49e7847909 100644
@@ -67,7 +67,7 @@ config SAM460EX
     select SM501
     select SMBUS_EEPROM
     select USB_EHCI_SYSBUS
-    select USB_OHCI
+    select USB_OHCI_SYSBUS
     select FDT_PPC
 
 config AMIGAONE
hw/sh4/Kconfig +0 -1
index ab733a3f760..e0c4ecd1a53 100644
@@ -6,7 +6,6 @@ config R2D
     select I82378 if TEST_DEVICES
     select IDE_MMIO
     select PFLASH_CFI02
-    select USB_OHCI_PCI
     select PCI
     select SM501
     select SH7750
hw/usb/Kconfig +4 -0
index 0f486764ed6..f569ed7eeaa 100644
@@ -11,6 +11,10 @@ config USB_OHCI
     bool
     select USB
 
+config USB_OHCI_SYSBUS
+    bool
+    select USB_OHCI
+
 config USB_OHCI_PCI
     bool
     default y if PCI_DEVICES
hw/usb/meson.build +1 -0
index 2c13c528785..94f0e3b034d 100644
@@ -15,6 +15,7 @@ system_ss.add(when: 'CONFIG_USB', if_true: files(
 system_ss.add(when: 'CONFIG_USB_UHCI', if_true: files('hcd-uhci.c'))
 system_ss.add(when: 'CONFIG_USB_OHCI', if_true: files('hcd-ohci.c'))
 system_ss.add(when: 'CONFIG_USB_OHCI_PCI', if_true: files('hcd-ohci-pci.c'))
+system_ss.add(when: 'CONFIG_USB_OHCI_SYSBUS', if_true: files('hcd-ohci-sysbus.c'))
 system_ss.add(when: 'CONFIG_USB_EHCI', if_true: files('hcd-ehci.c'))
 system_ss.add(when: 'CONFIG_USB_EHCI_PCI', if_true: files('hcd-ehci-pci.c'))
 system_ss.add(when: 'CONFIG_USB_EHCI_SYSBUS', if_true: files('hcd-ehci.c', 'hcd-ehci-sysbus.c'))
Signature · 1 line
2.43.0
Reviewed-by on v1 9/10
#29 lore raw

Re: [PATCH 09/10] usb: extract sysbus-ohci to a separate file

Quoted 19 lines · Paolo Bonzini

Split the sysbus version to a separate file so that it is not included in PCI-only machines, and adjust Kconfig for machines that do need sysbus-ohci. The copyrights are based on the time and employer of balrog and Paul Brook's contributions.

While adjusting the SM501 dependency, move it to the right place instead of keeping it in the R4D machine.

---
  hw/usb/hcd-ohci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++
  hw/usb/hcd-ohci.c        | 58 ------------------------
  hw/arm/Kconfig           | 12 +++--
  hw/display/Kconfig       |  1 +
  hw/ppc/Kconfig           |  2 +-
  hw/sh4/Kconfig           |  1 -
  hw/usb/Kconfig           |  4 ++
  hw/usb/meson.build       |  1 +
  8 files changed, 105 insertions(+), 65 deletions(-)
Quoted 4 lines

create mode 100644 hw/usb/hcd-ohci-sysbus.c

+static void ohci_realize_pxa(DeviceState *dev, Error **errp)

s/ohci_realize_pxa/ohci_sysbus_realize/

Quoted 7 lines
hw/usb/hcd-ohci-sysbus.c new file +7 -0
+{
+    OHCISysBusState *s = SYSBUS_OHCI(dev);
+    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    Error *err = NULL;
+
+    usb_ohci_init(&s->ohci, dev, s->num_ports, s->dma_offset,
+                  s->masterbus, s->firstport,

hw/usb/hcd-ohci-sysbus.c line 52

Quoted 10 lines
hw/usb/hcd-ohci-sysbus.c new file +10 -0
+                  &address_space_memory, ohci_sysbus_die, &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_init_irq(sbd, &s->ohci.irq);
+    sysbus_init_mmio(sbd, &s->ohci.mem);
+}
+
+static void usb_ohci_reset_sysbus(DeviceState *dev)

s/usb_ohci_reset_sysbus/ohci_sysbus/reset/.

To be converted to Resettable API.

Quoted 4 lines
hw/usb/hcd-ohci-sysbus.c new file +4 -0
+{
+    OHCISysBusState *s = SYSBUS_OHCI(dev);
+    OHCIState *ohci = &s->ohci;
+

hw/usb/hcd-ohci-sysbus.c line 91

Quoted 10 lines
hw/usb/hcd-ohci-sysbus.c new file +8 -0
+    ohci_hard_reset(ohci);
+}
 
 
+static void ohci_register_types(void)
+{
+    type_register_static(&ohci_sysbus_info);
+}
+
+type_init(ohci_register_types)

Better directly use DEFINE_TYPES() in new uses, even for a single type.

hw/usb/Kconfig config USB_OHCI · line 16

Quoted 11 lines
hw/usb/Kconfig +3 -0
index 0f486764ed6..f569ed7eeaa 100644
@@ -11,6 +11,10 @@ config USB_OHCI
      bool
      select USB
 
+config USB_OHCI_SYSBUS
+    bool
+    select USB_OHCI

I start to think USB_OHCI_MMIO would be clearer. I can clean that up later, so:

Quoted 3 lines
hw/usb/Kconfig +0 -0
  config USB_OHCI_PCI
      bool
      default y if PCI_DEVICES
Reviewed-by on v1 9/10
#30 lore raw

Re: [PATCH 09/10] usb: extract sysbus-ohci to a separate file

In reply to Paolo Bonzini
Quoted 52 lines · Paolo Bonzini

Split the sysbus version to a separate file so that it is not included in PCI-only machines, and adjust Kconfig for machines that do need sysbus-ohci. The copyrights are based on the time and employer of balrog and Paul Brook's contributions.

While adjusting the SM501 dependency, move it to the right place instead of keeping it in the R4D machine.

---
  hw/usb/hcd-ohci-sysbus.c | 91 ++++++++++++++++++++++++++++++++++++++++
  hw/usb/hcd-ohci.c        | 58 ------------------------
  hw/arm/Kconfig           | 12 +++--
  hw/display/Kconfig       |  1 +
  hw/ppc/Kconfig           |  2 +-
  hw/sh4/Kconfig           |  1 -
  hw/usb/Kconfig           |  4 ++
  hw/usb/meson.build       |  1 +
  8 files changed, 105 insertions(+), 65 deletions(-)

create mode 100644 hw/usb/hcd-ohci-sysbus.c

hw/usb/hcd-ohci-sysbus.c new file +25 -0
new file mode 100644
index 00000000000..4e4481232b6
@@ -0,0 +1,91 @@
+/*
+ * QEMU USB OHCI Emulation
+ * Copyright (c) 2006 Openedhand Ltd.
+ * Copyright (c) 2010 CodeSourcery
+ * Copyright (c) 2024 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu/osdep.h"
+#include "hw/irq.h"
+#include "qapi/error.h"
+#include "qemu/module.h"
+#include "qemu/timer.h"

hw/usb/hcd-ohci-sysbus.c line 35

Quoted 10 lines
hw/usb/hcd-ohci-sysbus.c new file +10 -0
+#include "hw/usb.h"
+#include "migration/vmstate.h"
+#include "hw/sysbus.h"
+#include "hw/qdev-dma.h"
+#include "hw/qdev-properties.h"
+#include "trace.h"
+#include "hcd-ohci.h"
+
+
+static void ohci_realize_pxa(DeviceState *dev, Error **errp)

Maybe this could be renamed to ohci_sysbs_realize() now since the code is used in non-pxa devices nowadays, too?

Anyway:

#31 lore raw

PATCH 10/10 usb: remove duplicate file in system_ss

In reply to Paolo Bonzini

Because USB_EHCI_SYSBUS selects USB_EHCI, there is no need to include hcd-ehci.c explicitly.

---
 hw/usb/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/meson.build +1 -1
index 94f0e3b034d..aac3bb35f27 100644
@@ -18,7 +18,7 @@ system_ss.add(when: 'CONFIG_USB_OHCI_PCI', if_true: files('hcd-ohci-pci.c'))
 system_ss.add(when: 'CONFIG_USB_OHCI_SYSBUS', if_true: files('hcd-ohci-sysbus.c'))
 system_ss.add(when: 'CONFIG_USB_EHCI', if_true: files('hcd-ehci.c'))
 system_ss.add(when: 'CONFIG_USB_EHCI_PCI', if_true: files('hcd-ehci-pci.c'))
-system_ss.add(when: 'CONFIG_USB_EHCI_SYSBUS', if_true: files('hcd-ehci.c', 'hcd-ehci-sysbus.c'))
+system_ss.add(when: 'CONFIG_USB_EHCI_SYSBUS', if_true: files('hcd-ehci-sysbus.c'))
 system_ss.add(when: 'CONFIG_USB_XHCI', if_true: files('hcd-xhci.c'))
 system_ss.add(when: 'CONFIG_USB_XHCI_PCI', if_true: files('hcd-xhci-pci.c'))
 system_ss.add(when: 'CONFIG_USB_XHCI_SYSBUS', if_true: files('hcd-xhci-sysbus.c'))
Signature · 1 line
2.43.0
#33 lore raw
In reply to Paolo Bonzini
Quoted 11 lines · Paolo Bonzini

Paolo Bonzini (10):
acpi, qom: move object_resolve_type_unambiguous to core QOM
ppc: sam460ex: do not use usb_bus_find()
sh4: r2d: do not use usb_bus_find() mips/loongson3_virt: do not require CONFIG_USB
hppa: do not require CONFIG_USB
mac_newworld: do not require CONFIG_USB
pseries: do not require CONFIG_USB
usb: remove usb_bus_find
usb: extract sysbus-ohci to a separate file
usb: remove duplicate file in system_ss

Thanks, queued addressing Thomas & Markus comments.