Skip to contentSkip to conversation

hw/arm: Add support for USB, SATA, and watchdog to Allwinner R40

PATCH Superseded Guenter Roeck 4 participants 12 messages Jan 13, 2024 – Jan 17, 2024 Arm/Allwinner sunXi SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hw/arm: Add support for USB, SATA, and watchdog to Allwinner R40

Add support for

- USB 2.0 EHCI/OHCI
- SATA/AHCI
- Watchdog

to Allwinner R40. The hardware is quite similar to Allwinner A10 and H3, so the code is derived from the implementations for those SOCs.

Tested with bpim2u emulation by instantiating EHCI and OHCI keyboards, by booting from USB, by booting from ATA/SATA drive, and by manually testing watchdog operation.

----------------------------------------------------------------
Guenter Roeck (3):
hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board hw/arm: Add AHCI/SATA controller to Allwinner R40 and Bananapi board hw/arm: Add watchdog timer to Allwinner H40 and Bananapi board

 docs/system/arm/bananapi_m2u.rst |  5 ++-
 hw/arm/Kconfig                   |  4 ++
 hw/arm/allwinner-r40.c           | 90 ++++++++++++++++++++++++++++++++++++++--
 include/hw/arm/allwinner-r40.h   | 15 +++++++
 4 files changed, 109 insertions(+), 5 deletions(-)
#1 lore raw

PATCH 1/3 hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Allwinner R40 supports two USB host ports shared between a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. Add support for both of them.

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

---
 docs/system/arm/bananapi_m2u.rst |  2 +-
 hw/arm/Kconfig                   |  2 +
 hw/arm/allwinner-r40.c           | 70 +++++++++++++++++++++++++++++++-
 include/hw/arm/allwinner-r40.h   |  9 ++++
 4 files changed, 80 insertions(+), 3 deletions(-)
docs/system/arm/bananapi_m2u.rst +1 -1
index b09ba5c548..e77c425e2c 100644
@@ -23,6 +23,7 @@ The Banana Pi M2U machine supports the following devices:
  * GMAC ethernet
  * Clock Control Unit
  * TWI (I2C)
+ * USB 2.0
 
 Limitations
 """""""""""
@@ -33,7 +34,6 @@ Currently, Banana Pi M2U does *not* support the following features:
 - Audio output
 - Hardware Watchdog
 - Real Time Clock
-- USB 2.0 interfaces
 
 Also see the 'unimplemented' array in the Allwinner R40 SoC module
 for a complete list of unimplemented I/O devices: ``./hw/arm/allwinner-r40.c``
hw/arm/Kconfig +2 -0
index 39d255425b..6b508780d3 100644
@@ -415,6 +415,8 @@ config ALLWINNER_R40
     select ARM_TIMER
     select ARM_GIC
     select UNIMP
+    select USB_OHCI
+    select USB_EHCI_SYSBUS
     select SD
 
 config RASPI
hw/arm/allwinner-r40.c +68 -2

113 lines not on this page · raw message

include/hw/arm/allwinner-r40.h +9 -0
index 6e1ac9d4c1..ae82822d42 100644
@@ -30,6 +30,8 @@
 #include "hw/i2c/allwinner-i2c.h"
 #include "hw/net/allwinner_emac.h"
 #include "hw/net/allwinner-sun8i-emac.h"
+#include "hw/usb/hcd-ohci.h"
+#include "hw/usb/hcd-ehci.h"
 #include "target/arm/cpu.h"
 #include "sysemu/block-backend.h"
 
@@ -44,6 +46,10 @@ enum {
     AW_R40_DEV_MMC1,
     AW_R40_DEV_MMC2,
     AW_R40_DEV_MMC3,
+    AW_R40_DEV_EHCI1,
+    AW_R40_DEV_OHCI1,
+    AW_R40_DEV_EHCI2,
+    AW_R40_DEV_OHCI2,
     AW_R40_DEV_CCU,
     AW_R40_DEV_PIT,
     AW_R40_DEV_UART0,
@@ -88,6 +94,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(AwR40State, AW_R40)
  * which are currently emulated by the R40 SoC code.
  */
 #define AW_R40_NUM_MMCS         4
+#define AW_R40_NUM_USB          2
 #define AW_R40_NUM_UARTS        8
 
 struct AwR40State {
@@ -106,6 +113,8 @@ struct AwR40State {
     AwSRAMCState sramc;
     AwA10PITState timer;
     AwSdHostState mmc[AW_R40_NUM_MMCS];
+    EHCISysBusState ehci[AW_R40_NUM_USB];
+    OHCISysBusState ohci[AW_R40_NUM_USB];
     AwR40ClockCtlState ccu;
     AwR40DramCtlState dramc;
     AWI2CState i2c0;
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Hi,

Quoted 6 lines · Guenter Roeck

Allwinner R40 supports two USB host ports shared between a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. Add support for both of them.

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

I never really understood the reason for machine_usb() and had on my TODO to do some archeology research to figure it out since quite some time. Having to map an UnimpDevice due to CLI options seems like an anti-pattern when the device is indeed implemented in the repository.

IIUC MachineState was introduced by a big rework during 2014-2015, and ::usb became a property.

Reading git-history and mailing list threads, apparently it was not easy for the mac99 machine (read whole thread):
https://lore.kernel.org/qemu-devel/[email protected]/
A bit later commit c6e765035b ("powerpc: fix -machine usb=no for newworld and pseries machines") introduced the ::usb_disabled property to deal with CLI -nodefaults with these 2 specific machines.

(-nodefaults is yet another CLI option I never really understood but take it as legacy heritage with biggest maintenance headaches).

The R40 is a SoC photolithographied on silicon as a single piece with a set of in-silicon peripherals, we can not remove peripherals from this HW. We can not remove its USB controller.

What we can do is play at the external devices connected on buses exposed by the SoC.

I can understand it is convenient for CLI users to start a machine with a console and a keyboard, so if a machine provides a USB bus, then it is created with a USB to UART converter and a USB keyboard.

So I'd interpret '-machine usb=off' as "if this machine has a USB controller providing a USB bus which is not exposed outside of the machine", but certainly not as "any mmio-mapped USB controller is removed from chipsets".

To the extend I can understand floppy/cdrom/sdcard drives can be inserted into available controllers used as buses, but I don't really understand how to do that with serial/parallel.

Quoted 67 lines
---
  docs/system/arm/bananapi_m2u.rst |  2 +-
  hw/arm/Kconfig                   |  2 +
  hw/arm/allwinner-r40.c           | 70 +++++++++++++++++++++++++++++++-
  include/hw/arm/allwinner-r40.h   |  9 ++++
  4 files changed, 80 insertions(+), 3 deletions(-)
hw/arm/allwinner-r40.c +46 -0
@@ -407,6 +427,37 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
      sysbus_realize(SYS_BUS_DEVICE(&s->ccu), &error_fatal);
      sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_R40_DEV_CCU]);
 
+    /* USB */
+    if (machine_usb(current_machine)) {
+        int i;
+
+        for (i = 0; i < AW_R40_NUM_USB; i++) {
+            g_autofree char *bus = g_strdup_printf("usb-bus.%d", i);
+
+            object_property_set_bool(OBJECT(&s->ehci[i]), "companion-enable",
+                                     true, &error_fatal);
+            sysbus_realize(SYS_BUS_DEVICE(&s->ehci[i]), &error_fatal);
+            sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci[i]), 0,
+                            allwinner_r40_memmap[i ? AW_R40_DEV_EHCI2
+                                                   : AW_R40_DEV_EHCI1]);
+            sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci[i]), 0,
+                               qdev_get_gpio_in(DEVICE(&s->gic),
+                                                i ? AW_R40_GIC_SPI_EHCI2
+                                                  : AW_R40_GIC_SPI_EHCI1));
+
+            object_property_set_str(OBJECT(&s->ohci[i]), "masterbus", bus,
+                                    &error_fatal);
+            sysbus_realize(SYS_BUS_DEVICE(&s->ohci[i]), &error_fatal);
+            sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci[i]), 0,
+                            allwinner_r40_memmap[i ? AW_R40_DEV_OHCI2
+                                                   : AW_R40_DEV_OHCI1]);
+            sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci[i]), 0,
+                               qdev_get_gpio_in(DEVICE(&s->gic),
+                                                i ? AW_R40_GIC_SPI_OHCI2
+                                                  : AW_R40_GIC_SPI_OHCI1));
+        }
+    }
+
      /* SD/MMC */
      for (int i = 0; i < AW_R40_NUM_MMCS; i++) {
          qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->gic),
@@ -498,6 +549,21 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
                                      r40_unimplemented[i].base,
                                      r40_unimplemented[i].size);
      }
+    if (!machine_usb(current_machine)) {
+        /* unimplemented if USB is not enabled */
+        create_unimplemented_device("usb-ehci1",
+                                    allwinner_r40_memmap[AW_R40_DEV_EHCI1],
+                                    0x800);
+        create_unimplemented_device("usb-ehci2",
+                                    allwinner_r40_memmap[AW_R40_DEV_EHCI2],
+                                    0x800);
+        create_unimplemented_device("usb-ohci1",
+                                    allwinner_r40_memmap[AW_R40_DEV_OHCI1],
+                                    0x800);
+        create_unimplemented_device("usb-ohci2",
+                                    allwinner_r40_memmap[AW_R40_DEV_OHCI2],
+                                    0x800);
+    }
  }
#3 lore raw

Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

Quoted 4 lines · Guenter Roeck

Allwinner R40 supports two USB host ports shared between a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. Add support for both of them.

Quoted 8 lines
Quoted 2 lines

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

I never really understood the reason for machine_usb() and had on my TODO to do some archeology research to figure it out since quite some time. Having to map an UnimpDevice due to CLI options seems like an anti-pattern when the device is indeed implemented in the repository.

Me not either. I copied the code from aw_a10_init(), trying to use the same pattern. I am perfectly fine with making it unconditional, but then I would argue that it should be unconditional for Allwinner A10 as well (not that I really care much, just for consistency).

The "-usb" option says "enable on-board USB host controller (if not enabled by default)". Unfortunately, that doesn't tell me much, and most specifically it doesn't tell me how to enable it by default. One option I can think of would be to enable it on the machine level, i.e., from bananapi_m2u.c, but then, again, I don't see if/how that is done for other boards. Any suggestions ?

Of course, I could discuss this with the person who implemented this code for A10, but it turns out that was me, for no good reason than that I tried to follow the pattern I had seen elsewhere without really understanding what I was doing.

So should I drop the conditional from H40 and send a separate patch to drop it from the A10 code as well, following your line of argument ? Or drop it and leave A10 alone ?

Thanks,
Guenter

#4 lore raw

Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Quoted 17 lines · Guenter Roeck
Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

Quoted 4 lines · Guenter Roeck

Allwinner R40 supports two USB host ports shared between a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. Add support for both of them.

Quoted 8 lines
Quoted 2 lines

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

I never really understood the reason for machine_usb() and had on my TODO to do some archeology research to figure it out since quite some time. Having to map an UnimpDevice due to CLI options seems like an anti-pattern when the device is indeed implemented in the repository.

Quoted 4 lines

Me not either. I copied the code from aw_a10_init(), trying to use the same pattern. I am perfectly fine with making it unconditional, but then I would argue that it should be unconditional for Allwinner A10 as well (not that I really care much, just for consistency).

Certainly, but I'd rather have a global pattern cleanup, not just Allwinner based machines. Looking at the repository:

$ git grep -w machine_usb hw/
hw/arm/allwinner-a10.c:82:    if (machine_usb(current_machine)) {
hw/arm/allwinner-a10.c:168:    if (machine_usb(current_machine)) {
hw/arm/nseries.c:1356:    if (machine_usb(machine)) {
hw/arm/realview.c:288:        if (machine_usb(machine)) {
hw/arm/realview.c-289-            pci_create_simple(pci_bus, -1, "pci-ohci");
hw/arm/versatilepb.c:276:    if (machine_usb(machine)) {
hw/arm/versatilepb.c-277-        pci_create_simple(pci_bus, -1, "pci-ohci");
hw/core/machine.c:1175:bool machine_usb(MachineState *machine)
hw/i386/acpi-microvm.c:88:    if (machine_usb(MACHINE(mms))) {
hw/i386/acpi-microvm.c-89-        xhci_sysbus_build_aml(scope, MICROVM_XHCI_BASE, MICROVM_XHCI_IRQ);
hw/i386/microvm.c:218:    if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) {
hw/i386/microvm.c-225-        sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE);
hw/i386/pc_piix.c:267: machine_usb(machine), &error_abort);
hw/i386/pc_q35.c:321:    if (machine_usb(machine)) {
hw/i386/pc_q35.c-323-        ehci_create_ich9_with_companions(host_bus, 0x1d);
hw/ppc/mac_oldworld.c:300:    if (machine_usb(machine)) {
hw/ppc/mac_oldworld.c-301-        pci_create_simple(pci_bus, -1, "pci-ohci");

I'd classify that as "USB controller over MMIO / over some bus (PCI)".

The "plug a PCI-to-USB card by default" seems a valid use case (except for Q35 which is a Frankenstein case, ICH9 chipset is like ARM SoC, USB bus is always there).

IMHO all the MMIO uses should be corrected.

Quoted 7 lines

The "-usb" option says "enable on-board USB host controller (if not enabled by default)". Unfortunately, that doesn't tell me much, and most specifically it doesn't tell me how to enable it by default. One option I can think of would be to enable it on the machine level, i.e., from bananapi_m2u.c, but then, again, I don't see if/how that is done for other boards. Any suggestions ?

Quoted 8 lines

Of course, I could discuss this with the person who implemented this code for A10, but it turns out that was me, for no good reason than that I tried to follow the pattern I had seen elsewhere without really understanding what I was doing.

So should I drop the conditional from H40 and send a separate patch to drop it from the A10 code as well, following your line of argument ? Or drop it and leave A10 alone ?

Well your patch isn't invalid, so:

I'm just worried we are taking a bad path here and would rather avoid it if possible...

Regards,

Phil.

#5 lore raw

Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Quoted 65 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Guenter Roeck
Quoted 7 lines · Philippe Mathieu-Daudé

Hi,

Quoted 4 lines · Guenter Roeck

Allwinner R40 supports two USB host ports shared between a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. Add support for both of them.

Quoted 8 lines
Quoted 2 lines

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

I never really understood the reason for machine_usb() and had on my TODO to do some archeology research to figure it out since quite some time. Having to map an UnimpDevice due to CLI options seems like an anti-pattern when the device is indeed implemented in the repository.

Quoted 4 lines

Me not either. I copied the code from aw_a10_init(), trying to use the same pattern. I am perfectly fine with making it unconditional, but then I would argue that it should be unconditional for Allwinner A10 as well (not that I really care much, just for consistency).

Certainly, but I'd rather have a global pattern cleanup, not just Allwinner based machines. Looking at the repository:

$ git grep -w machine_usb hw/
hw/arm/allwinner-a10.c:82:    if (machine_usb(current_machine)) {
hw/arm/allwinner-a10.c:168:    if (machine_usb(current_machine)) {
hw/arm/nseries.c:1356:    if (machine_usb(machine)) {
hw/arm/realview.c:288:        if (machine_usb(machine)) {
hw/arm/realview.c-289-            pci_create_simple(pci_bus, -1, "pci-ohci");
hw/arm/versatilepb.c:276:    if (machine_usb(machine)) {
hw/arm/versatilepb.c-277-        pci_create_simple(pci_bus, -1, "pci-ohci");
hw/core/machine.c:1175:bool machine_usb(MachineState *machine)
hw/i386/acpi-microvm.c:88:    if (machine_usb(MACHINE(mms))) {
hw/i386/acpi-microvm.c-89-        xhci_sysbus_build_aml(scope, MICROVM_XHCI_BASE, MICROVM_XHCI_IRQ);
hw/i386/microvm.c:218:    if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) {
hw/i386/microvm.c-225-        sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE);
hw/i386/pc_piix.c:267: machine_usb(machine), &error_abort);
hw/i386/pc_q35.c:321:    if (machine_usb(machine)) {
hw/i386/pc_q35.c-323-        ehci_create_ich9_with_companions(host_bus, 0x1d);
hw/ppc/mac_oldworld.c:300:    if (machine_usb(machine)) {
hw/ppc/mac_oldworld.c-301-        pci_create_simple(pci_bus, -1, "pci-ohci");

I'd classify that as "USB controller over MMIO / over some bus (PCI)".

The "plug a PCI-to-USB card by default" seems a valid use case (except for Q35 which is a Frankenstein case, ICH9 chipset is like ARM SoC, USB bus is always there).

IMHO all the MMIO uses should be corrected.

Quoted 12 lines

The "-usb" option says "enable on-board USB host controller (if not enabled by default)". Unfortunately, that doesn't tell me much, and most specifically it doesn't tell me how to enable it by default. One option I can think of would be to enable it on the machine level, i.e., from bananapi_m2u.c, but then, again, I don't see if/how that is done for other boards. Any suggestions ?

Of course, I could discuss this with the person who implemented this code for A10, but it turns out that was me, for no good reason than that I tried to follow the pattern I had seen elsewhere without really understanding what I was doing.

Quoted 8 lines
Quoted 3 lines

So should I drop the conditional from H40 and send a separate patch to drop it from the A10 code as well, following your line of argument ? Or drop it and leave A10 alone ?

Well your patch isn't invalid, so:

I'll send v2 anyway, especially taking your other patch series into account.

Thanks,
Guenter

#6 lore raw

Re: Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

In reply to Guenter Roeck
Quoted 15 lines · Guenter Roeck
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Guenter Roeck

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

I never really understood the reason for machine_usb() and had on my TODO to do some archeology research to figure it out since quite some time. Having to map an UnimpDevice due to CLI options seems like an anti-pattern when the device is indeed implemented in the repository.

Me not either. I copied the code from aw_a10_init(), trying to use the same pattern. I am perfectly fine with making it unconditional, but then I would argue that it should be unconditional for Allwinner A10 as well (not that I really care much, just for consistency).

Quoted 6 lines

The "-usb" option says "enable on-board USB host controller (if not enabled by default)". Unfortunately, that doesn't tell me much, and most specifically it doesn't tell me how to enable it by default. One option I can think of would be to enable it on the machine level, i.e., from bananapi_m2u.c, but then, again, I don't see if/how that is done for other boards. Any suggestions ?

The -usb switch is there as long as I remember (which goes back to qemu 0.1x days). I suspect it was introduced in the early usb emulation days, where usb emulation was more fragile and turning it on by default didn't look like a good plan.

usb emulation in modern qemu should be stable enough that enabling it by default should not be much of a problem. ohci/uhci/ehci emulation is somewhat expensive due to polling being wired into the hardware design, but as long as there are no usb devices connected this should not be much of a concern either as the guest drivers usually put the usb host adapter to sleep in that case (which saves power on physical hardware and stops the polling timer in qemu).

So, turning on usb support by default makes sense to me when emulating boards, where guests expect the usb controllers being present at specific MMIO addresses, so mapping UnimpDevice is not needed.

In case guests detect hardware via generated device tree / generated ACPI tables / pci bus scan (i.e. arm virt + microvm + pc + q35) it IMHO makes sense to keep current behavior.

take care,
Gerd

#7 lore raw

Re: Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Am 16. Januar 2024 10:13:37 UTC schrieb Gerd Hoffmann <[email protected]>:

Quoted 36 lines · Guenter Roeck
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Guenter Roeck
Quoted 2 lines

If machine USB support is not enabled, create unimplemented devices for the USB memory ranges to avoid crashes when booting Linux.

I never really understood the reason for machine_usb() and had on my TODO to do some archeology research to figure it out since quite some time. Having to map an UnimpDevice due to CLI options seems like an anti-pattern when the device is indeed implemented in the repository.

Me not either. I copied the code from aw_a10_init(), trying to use the same pattern. I am perfectly fine with making it unconditional, but then I would argue that it should be unconditional for Allwinner A10 as well (not that I really care much, just for consistency).

Quoted 6 lines

The "-usb" option says "enable on-board USB host controller (if not enabled by default)". Unfortunately, that doesn't tell me much, and most specifically it doesn't tell me how to enable it by default. One option I can think of would be to enable it on the machine level, i.e., from bananapi_m2u.c, but then, again, I don't see if/how that is done for other boards. Any suggestions ?

The -usb switch is there as long as I remember (which goes back to qemu 0.1x days). I suspect it was introduced in the early usb emulation days, where usb emulation was more fragile and turning it on by default didn't look like a good plan.

usb emulation in modern qemu should be stable enough that enabling it by default should not be much of a problem. ohci/uhci/ehci emulation is somewhat expensive due to polling being wired into the hardware design, but as long as there are no usb devices connected this should not be much of a concern either as the guest drivers usually put the usb host adapter to sleep in that case (which saves power on physical hardware and stops the polling timer in qemu).

Quoted 3 lines

So, turning on usb support by default makes sense to me when emulating boards, where guests expect the usb controllers being present at specific MMIO addresses, so mapping UnimpDevice is not needed.

Good idea, this might make upstreaming my VIA-south-bridges-in-the-pc-machine work simpler.

Quoted 4 lines

In case guests detect hardware via generated device tree / generated ACPI tables / pci bus scan (i.e. arm virt + microvm + pc + q35) it IMHO makes sense to keep current behavior.

I remember similar discussions with Phil during PIIX consolidation where the motivation was to make the code simpler by removing options. That is, if a piece of silicon contains multiple functions, the QEMU model should always instantiate all (available) functions rather than providing options for cherry-picking.

Especially in highly integrated devices (such as south bridges) there might be interconnections between functions that are hard to handle when some are optional. For example, the ACPI function in the VIA south bridges detect activity from all other functions. In both PIIX and VIA, the USB function can be (de)activated by software from the ISA function (not implemented yet).

The latter would allow the current behavior of the pc machine(s) to be implemented while avoiding the cherry picking problem: The BIOS could switch the USB function on or off depending on fw_cfg (please correct me if I'm wrong). I think this would't even need compat machinery. Of course, support would need to be added in SeaBIOS and -- I guess -- Tianocore. I'd like to look into that but, as usual, no guarantees when this will arrive.

Best regards,
Bernhard

Quoted 5 lines

take care,
Gerd

#8 lore raw

Re: Re: Re: [PATCH 1/3] hw/arm: Add EHCI/OHCI controllers to Allwinner R40 and Bananapi board

Quoted 17 lines
Quoted 3 lines

In case guests detect hardware via generated device tree / generated ACPI tables / pci bus scan (i.e. arm virt + microvm + pc + q35) it IMHO makes sense to keep current behavior.

I remember similar discussions with Phil during PIIX consolidation where the motivation was to make the code simpler by removing options. That is, if a piece of silicon contains multiple functions, the QEMU model should always instantiate all (available) functions rather than providing options for cherry-picking.

Especially in highly integrated devices (such as south bridges) there might be interconnections between functions that are hard to handle when some are optional. For example, the ACPI function in the VIA south bridges detect activity from all other functions. In both PIIX and VIA, the USB function can be (de)activated by software from the ISA function (not implemented yet).

Quoted 7 lines

The latter would allow the current behavior of the pc machine(s) to be implemented while avoiding the cherry picking problem: The BIOS could switch the USB function on or off depending on fw_cfg (please correct me if I'm wrong). I think this would't even need compat machinery. Of course, support would need to be added in SeaBIOS and -- I guess -- Tianocore. I'd like to look into that but, as usual, no guarantees when this will arrive.

Well, our chipsets are quite old. piix has uhci, q35 has uhci+ehci. Modern usb is xhci, which also is more virtualization friendly hardware design. Also qemu usb configuration is much simpler in case there is only one usb bus (xhci) instead of two (xhci + chipset) because you don't have to explicitly assign usb devices to a specific usb bus if there is only one. So I don't like the idea to have the chipset usb bus present by default.

We have a similar problem in the LPC bridges. They likewise have bits in the pci config space to enable/disable ISA devices such as floppy, serial port, parallel port. These bits are implemented, but read-only. So it is possible to read them to figure whenever a given device is present, but it is not possible to set them to enable/disable devices. Before we switched the ACPI DSDT to be 100% generated we actually had some AML functions reading those bits to figure whenever these ISA devices are present or not.

I'd suggest to follow that design pattern for the config bits in the south bridge ACPI function.

take care,
Gerd

#9 lore raw

PATCH 2/3 hw/arm: Add AHCI/SATA controller to Allwinner R40 and Bananapi board

In reply to Guenter Roeck

Allwinner R40 supports an AHCI compliant SATA controller. Add support for it.

---
 docs/system/arm/bananapi_m2u.rst |  1 +
 hw/arm/Kconfig                   |  1 +
 hw/arm/allwinner-r40.c           | 12 +++++++++++-
 include/hw/arm/allwinner-r40.h   |  3 +++
 4 files changed, 16 insertions(+), 1 deletion(-)
docs/system/arm/bananapi_m2u.rst +1 -0
index e77c425e2c..542310591d 100644
@@ -22,6 +22,7 @@ The Banana Pi M2U machine supports the following devices:
  * EMAC ethernet
  * GMAC ethernet
  * Clock Control Unit
+ * SATA
  * TWI (I2C)
  * USB 2.0
 
hw/arm/Kconfig +1 -0
index 6b508780d3..98ca5ebc7d 100644
@@ -408,6 +408,7 @@ config ALLWINNER_H3
 config ALLWINNER_R40
     bool
     default y if TCG && ARM
+    select AHCI
     select ALLWINNER_SRAMC
     select ALLWINNER_A10_PIT
     select AXP2XX_PMU
hw/arm/allwinner-r40.c +11 -1
index f42b0fa0ce..f90d59fb5e 100644
@@ -46,6 +46,7 @@ const hwaddr allwinner_r40_memmap[] = {
     [AW_R40_DEV_MMC1]       = 0x01c10000,
     [AW_R40_DEV_MMC2]       = 0x01c11000,
     [AW_R40_DEV_MMC3]       = 0x01c12000,
+    [AW_R40_DEV_AHCI]       = 0x01c18000,
     [AW_R40_DEV_EHCI1]      = 0x01c19000,
     [AW_R40_DEV_OHCI1]      = 0x01c19400,
     [AW_R40_DEV_EHCI2]      = 0x01c1c000,
@@ -93,7 +94,6 @@ static struct AwR40Unimplemented r40_unimplemented[] = {
     { "usb0-host",  0x01c14000, 4 * KiB },
     { "crypto",     0x01c15000, 4 * KiB },
     { "spi2",       0x01c17000, 4 * KiB },
-    { "sata",       0x01c18000, 4 * KiB },
     { "usb1-phy",   0x01c19800, 2 * KiB },
     { "sid",        0x01c1b000, 4 * KiB },
     { "usb2-phy",   0x01c1c800, 2 * KiB },
@@ -186,6 +186,7 @@ enum {
     AW_R40_GIC_SPI_MMC2      = 34,
     AW_R40_GIC_SPI_MMC3      = 35,
     AW_R40_GIC_SPI_EMAC      = 55,
+    AW_R40_GIC_SPI_AHCI      = 56,
     AW_R40_GIC_SPI_OHCI1     = 64,
     AW_R40_GIC_SPI_OHCI2     = 65,
     AW_R40_GIC_SPI_EHCI1     = 76,
@@ -285,6 +286,8 @@ static void allwinner_r40_init(Object *obj)
                                 TYPE_AW_SDHOST_SUN50I_A64);
     }
 
+    object_initialize_child(obj, "sata", &s->sata, TYPE_ALLWINNER_AHCI);
+
     if (machine_usb(current_machine)) {
         int i;
 
@@ -427,6 +430,13 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
     sysbus_realize(SYS_BUS_DEVICE(&s->ccu), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->ccu), 0, s->memmap[AW_R40_DEV_CCU]);
 
+    /* SATA / AHCI */
+    sysbus_realize(SYS_BUS_DEVICE(&s->sata), &error_fatal);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0,
+                    allwinner_r40_memmap[AW_R40_DEV_AHCI]);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->sata), 0,
+                       qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_AHCI));
+
     /* USB */
     if (machine_usb(current_machine)) {
         int i;
include/hw/arm/allwinner-r40.h +3 -0
index ae82822d42..c589fcc1c1 100644
@@ -22,6 +22,7 @@
 
 #include "qom/object.h"
 #include "hw/timer/allwinner-a10-pit.h"
+#include "hw/ide/ahci.h"
 #include "hw/intc/arm_gic.h"
 #include "hw/sd/allwinner-sdhost.h"
 #include "hw/misc/allwinner-r40-ccu.h"
@@ -46,6 +47,7 @@ enum {
     AW_R40_DEV_MMC1,
     AW_R40_DEV_MMC2,
     AW_R40_DEV_MMC3,
+    AW_R40_DEV_AHCI,
     AW_R40_DEV_EHCI1,
     AW_R40_DEV_OHCI1,
     AW_R40_DEV_EHCI2,
@@ -112,6 +114,7 @@ struct AwR40State {
     const hwaddr *memmap;
     AwSRAMCState sramc;
     AwA10PITState timer;
+    AllwinnerAHCIState sata;
     AwSdHostState mmc[AW_R40_NUM_MMCS];
     EHCISysBusState ehci[AW_R40_NUM_USB];
     OHCISysBusState ohci[AW_R40_NUM_USB];
Signature · 1 line
2.39.2
Reviewed-by on v1 2/3
#10 lore raw

Re: [PATCH 2/3] hw/arm: Add AHCI/SATA controller to Allwinner R40 and Bananapi board

Quoted 10 lines · Guenter Roeck

Allwinner R40 supports an AHCI compliant SATA controller. Add support for it.

---
  docs/system/arm/bananapi_m2u.rst |  1 +
  hw/arm/Kconfig                   |  1 +
  hw/arm/allwinner-r40.c           | 12 +++++++++++-
  include/hw/arm/allwinner-r40.h   |  3 +++
  4 files changed, 16 insertions(+), 1 deletion(-)
#11 lore raw

PATCH 3/3 hw/arm: Add watchdog timer to Allwinner H40 and Bananapi board

In reply to Guenter Roeck

Add watchdog timer support to Allwinner-H40 and Bananapi. The watchdog timer is added as an overlay to the Timer module memory map.

---
 docs/system/arm/bananapi_m2u.rst | 2 +-
 hw/arm/Kconfig                   | 1 +
 hw/arm/allwinner-r40.c           | 8 ++++++++
 include/hw/arm/allwinner-r40.h   | 3 +++
 4 files changed, 13 insertions(+), 1 deletion(-)
docs/system/arm/bananapi_m2u.rst +1 -1
index 542310591d..587b488655 100644
@@ -25,6 +25,7 @@ The Banana Pi M2U machine supports the following devices:
  * SATA
  * TWI (I2C)
  * USB 2.0
+ * Hardware Watchdog
 
 Limitations
 """""""""""
@@ -33,7 +34,6 @@ Currently, Banana Pi M2U does *not* support the following features:
 
 - Graphical output via HDMI, GPU and/or the Display Engine
 - Audio output
-- Hardware Watchdog
 - Real Time Clock
 
 Also see the 'unimplemented' array in the Allwinner R40 SoC module
hw/arm/Kconfig +1 -0
index 98ca5ebc7d..386edbae15 100644
@@ -411,6 +411,7 @@ config ALLWINNER_R40
     select AHCI
     select ALLWINNER_SRAMC
     select ALLWINNER_A10_PIT
+    select ALLWINNER_WDT
     select AXP2XX_PMU
     select SERIAL
     select ARM_TIMER
hw/arm/allwinner-r40.c +8 -0
index f90d59fb5e..334692ef97 100644
@@ -53,6 +53,7 @@ const hwaddr allwinner_r40_memmap[] = {
     [AW_R40_DEV_OHCI2]      = 0x01c1c400,
     [AW_R40_DEV_CCU]        = 0x01c20000,
     [AW_R40_DEV_PIT]        = 0x01c20c00,
+    [AW_R40_DEV_WDT]        = 0x01c20c90,
     [AW_R40_DEV_UART0]      = 0x01c28000,
     [AW_R40_DEV_UART1]      = 0x01c28400,
     [AW_R40_DEV_UART2]      = 0x01c28800,
@@ -279,6 +280,8 @@ static void allwinner_r40_init(Object *obj)
     object_property_add_alias(obj, "clk1-freq", OBJECT(&s->timer),
                               "clk1-freq");
 
+    object_initialize_child(obj, "wdt", &s->wdt, TYPE_AW_WDT_SUN4I);
+
     object_initialize_child(obj, "ccu", &s->ccu, TYPE_AW_R40_CCU);
 
     for (int i = 0; i < AW_R40_NUM_MMCS; i++) {
@@ -553,6 +556,11 @@ static void allwinner_r40_realize(DeviceState *dev, Error **errp)
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->emac), 0,
                        qdev_get_gpio_in(DEVICE(&s->gic), AW_R40_GIC_SPI_EMAC));
 
+    /* WDT */
+    sysbus_realize(SYS_BUS_DEVICE(&s->wdt), &error_fatal);
+    sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->wdt), 0,
+                            allwinner_r40_memmap[AW_R40_DEV_WDT], 1);
+
     /* Unimplemented devices */
     for (unsigned i = 0; i < ARRAY_SIZE(r40_unimplemented); i++) {
         create_unimplemented_device(r40_unimplemented[i].device_name,
include/hw/arm/allwinner-r40.h +3 -0
index c589fcc1c1..66c38e7d90 100644
@@ -33,6 +33,7 @@
 #include "hw/net/allwinner-sun8i-emac.h"
 #include "hw/usb/hcd-ohci.h"
 #include "hw/usb/hcd-ehci.h"
+#include "hw/watchdog/allwinner-wdt.h"
 #include "target/arm/cpu.h"
 #include "sysemu/block-backend.h"
 
@@ -54,6 +55,7 @@ enum {
     AW_R40_DEV_OHCI2,
     AW_R40_DEV_CCU,
     AW_R40_DEV_PIT,
+    AW_R40_DEV_WDT,
     AW_R40_DEV_UART0,
     AW_R40_DEV_UART1,
     AW_R40_DEV_UART2,
@@ -114,6 +116,7 @@ struct AwR40State {
     const hwaddr *memmap;
     AwSRAMCState sramc;
     AwA10PITState timer;
+    AwWdtState wdt;
     AllwinnerAHCIState sata;
     AwSdHostState mmc[AW_R40_NUM_MMCS];
     EHCISysBusState ehci[AW_R40_NUM_USB];
Signature · 1 line
2.39.2