Skip to contentSkip to conversation

Adds designware i2c module and adds it to virt arm

PATCH In review Patrick Venture 5 participants 11 messages Jan 10, 2022 – Feb 22, 2022 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#2 lore raw

PATCH 2/2 hw/arm: Enable smbus on arm virt machine.

In reply to Patrick Venture

From: Chris Rauer <[email protected]>

---
 docs/system/arm/virt.rst |  4 +++
 hw/arm/Kconfig           |  1 +
 hw/arm/virt-acpi-build.c | 24 ++++++++++++++++++
 hw/arm/virt.c            | 55 ++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/virt.h    |  3 +++
 5 files changed, 87 insertions(+)
docs/system/arm/virt.rst +4 -0
index 850787495b..e357143f6b 100644
@@ -30,6 +30,7 @@ The virt board supports:
 - An RTC
 - The fw_cfg device that allows a guest to obtain data from QEMU
 - A PL061 GPIO controller
+- A DesignWare I2C controller
 - An optional SMMUv3 IOMMU
 - hotpluggable DIMMs
 - hotpluggable NVDIMMs
@@ -121,6 +122,9 @@ ras
   Set ``on``/``off`` to enable/disable reporting host memory errors to a guest
   using ACPI and guest external abort exceptions. The default is off.
 
+smbus
+  Set ``on``/``off`` to enable/disable smbus controller. The default is ``off``.
+
 Linux guest kernel configuration
 """"""""""""""""""""""""""""""""
 
hw/arm/Kconfig +1 -0
index e652590943..692af8c265 100644
@@ -28,6 +28,7 @@ config ARM_VIRT
     select ACPI_HW_REDUCED
     select ACPI_APEI
     select ACPI_VIOT
+    select DESIGNWARE_I2C
 
 config CHEETAH
     bool
hw/arm/virt-acpi-build.c +24 -0
index d0f4867fdf..310cd6fb5b 100644
@@ -92,6 +92,26 @@ static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,
     aml_append(scope, dev);
 }
 
+static void acpi_dsdt_add_smbus(Aml *scope, const MemMapEntry *smbus_memmap,
+                                           uint32_t i2c_irq, I2CBus *smbus)
+{
+    Aml *dev = aml_device("SMB0");
+    aml_append(dev, aml_name_decl("_HID", aml_string("APMC0D0F")));
+    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+    aml_append(dev, aml_name_decl("_STA", aml_int(0x0F)));
+    aml_append(dev, aml_name_decl("_CCA", aml_int(1)));
+
+    Aml *crs = aml_resource_template();
+    aml_append(crs, aml_memory32_fixed(smbus_memmap->base,
+                                       smbus_memmap->size, AML_READ_WRITE));
+    aml_append(crs,
+               aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH,
+                             AML_EXCLUSIVE, &i2c_irq, 1));
+    aml_append(dev, aml_name_decl("_CRS", crs));
+
+    aml_append(scope, dev);
+}
+
 static void acpi_dsdt_add_fw_cfg(Aml *scope, const MemMapEntry *fw_cfg_memmap)
 {
     Aml *dev = aml_device("FWCF");
@@ -862,6 +882,10 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     acpi_dsdt_add_cpus(scope, vms);
     acpi_dsdt_add_uart(scope, &memmap[VIRT_UART],
                        (irqmap[VIRT_UART] + ARM_SPI_BASE));
+    if (vms->smbus_enabled) {
+        acpi_dsdt_add_smbus(scope, &memmap[VIRT_SMBUS],
+                            (irqmap[VIRT_SMBUS] + ARM_SPI_BASE), vms->smbus);
+    }
     if (vmc->acpi_expose_flash) {
         acpi_dsdt_add_flash(scope, &memmap[VIRT_FLASH]);
     }
hw/arm/virt.c +55 -0

103 lines not on this page · raw message

include/hw/arm/virt.h +3 -0
index dc6b66ffc8..d28de89695 100644
@@ -86,6 +86,7 @@ enum {
     VIRT_ACPI_GED,
     VIRT_NVDIMM_ACPI,
     VIRT_PVTIME,
+    VIRT_SMBUS,
     VIRT_LOWMEMMAP_LAST,
 };
 
@@ -148,6 +149,7 @@ struct VirtMachineState {
     bool virt;
     bool ras;
     bool mte;
+    bool smbus_enabled;
     OnOffAuto acpi;
     VirtGICType gic_version;
     VirtIOMMUType iommu;
@@ -169,6 +171,7 @@ struct VirtMachineState {
     DeviceState *acpi_dev;
     Notifier powerdown_notifier;
     PCIBus *bus;
+    I2CBus *smbus;
     char *oem_id;
     char *oem_table_id;
 };
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#0 lore raw

cover Adds designware i2c module and adds it to virt arm

This patch series introduces a new i2c module, namely the designware one and further enables this (optionally) for the virt-arm machine.

Chris Rauer (2):
hw/i2c: Add designware i2c controller.
hw/arm: Enable smbus on arm virt machine.

 MAINTAINERS                     |   6 +
 docs/system/arm/virt.rst        |   4 +
 hw/arm/Kconfig                  |   1 +
 hw/arm/virt-acpi-build.c        |  24 +
 hw/arm/virt.c                   |  55 +++
 hw/i2c/Kconfig                  |   4 +
 hw/i2c/designware_i2c.c         | 821 ++++++++++++++++++++++++++++++++
 hw/i2c/meson.build              |   1 +
 include/hw/arm/virt.h           |   3 +
 include/hw/i2c/designware_i2c.h | 110 +++++
 10 files changed, 1029 insertions(+)
 create mode 100644 hw/i2c/designware_i2c.c
 create mode 100644 include/hw/i2c/designware_i2c.h
Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#1 lore raw

PATCH 1/2 hw/i2c: Add designware i2c controller.

From: Chris Rauer <[email protected]>

---
 MAINTAINERS                     |   6 +
 hw/i2c/Kconfig                  |   4 +
 hw/i2c/designware_i2c.c         | 821 ++++++++++++++++++++++++++++++++
 hw/i2c/meson.build              |   1 +
 include/hw/i2c/designware_i2c.h | 110 +++++
 5 files changed, 942 insertions(+)
 create mode 100644 hw/i2c/designware_i2c.c
 create mode 100644 include/hw/i2c/designware_i2c.h
MAINTAINERS +6 -0
index f871d759fd..9aa34ea181 100644
@@ -2110,6 +2110,12 @@ S: Maintained
 F: hw/i2c/i2c_mux_pca954x.c
 F: include/hw/i2c/i2c_mux_pca954x.h
 
+DesignWare I2C
+M: Chris Rauer <[email protected]>
+S: Maintained
+F: hw/i2c/designware_i2c.c
+F: include/hw/i2c/designware_i2c.h
+
 Generic Loader
 M: Alistair Francis <[email protected]>
 S: Maintained
hw/i2c/Kconfig +4 -0
index 8217cb5041..0f3d86b869 100644
@@ -13,6 +13,10 @@ config VERSATILE_I2C
     bool
     select BITBANG_I2C
 
+config DESIGNWARE_I2C
+    bool
+    select I2C
+
 config ACPI_SMBUS
     bool
     select SMBUS
hw/i2c/designware_i2c.c new file +821 -0

821 lines not on this page · raw message

hw/i2c/meson.build +1 -0
index d3df273251..80e03c830f 100644
@@ -10,6 +10,7 @@ i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c'))
 i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c'))
 i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c'))
 i2c_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_smbus.c'))
+i2c_ss.add(when: 'CONFIG_DESIGNWARE_I2C', if_true: files('designware_i2c.c'))
 i2c_ss.add(when: 'CONFIG_SMBUS_EEPROM', if_true: files('smbus_eeprom.c'))
 i2c_ss.add(when: 'CONFIG_VERSATILE_I2C', if_true: files('versatile_i2c.c'))
 i2c_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_i2c.c'))
include/hw/i2c/designware_i2c.h new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.34.1.575.g55b058a8bb-goog
#4 lore raw
In reply to Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 6 lines · Patrick Venture

This patch series introduces a new i2c module, namely the designware one and further enables this (optionally) for the virt-arm machine.

Chris Rauer (2):
hw/i2c: Add designware i2c controller.
hw/arm: Enable smbus on arm virt machine.

Quoted 5 lines

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine, given that it increases complexity and potential attack surface for using it with KVM; this cover letter doesn't seem to provide any...

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it. (We seem to have an ICH9-SMB PCI device already; I have no idea if it's suitable.)

thanks
-- PMM

#3 lore raw
In reply to Patrick Venture
Quoted 6 lines · Patrick Venture

This patch series introduces a new i2c module, namely the designware one and further enables this (optionally) for the virt-arm machine.

Chris Rauer (2):
hw/i2c: Add designware i2c controller.
hw/arm: Enable smbus on arm virt machine.

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine, given that it increases complexity and potential attack surface for using it with KVM; this cover letter doesn't seem to provide any...

thanks
-- PMM

#5 lore raw
In reply to Peter Maydell
Quoted 1 line

I need to see a pretty strong justification for why we should be adding

new kinds of devices to the virt machine,
The designware i2c controller is a very common controller on many ARM SoCs. It has device tree bindings and ACPI bindings which makes it ideal for this platform.

Quoted 5 lines

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it.

The device is enabled by a machine parameter, “-machine virt,smbus=true”, and is disabled by default.

Quoted 1 line

(We seem to have an ICH9-SMB PCI device already; I have no idea if it's

suitable.)
I didn't find that device suitable because it is part of the Intel Southbridge, which may have some Intel platform quirks, and we don't need all the things in that IO hub.

-Chris

#6 lore raw
Quoted 7 lines · Chris Rauer
Quoted 3 lines

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine,

The designware i2c controller is a very common controller on many
ARM SoCs. It has device tree bindings and ACPI bindings which
makes it ideal for this platform.

No, I mean, why do we need an i2c controller on the virt board at all ?

Quoted 10 lines
Quoted 7 lines

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it.

(We seem to have an ICH9-SMB PCI device already; I have no idea if it's suitable.)

I didn't find that device suitable because it is part of the Intel Southbridge, which may have some Intel platform quirks, and we don't need all the things in that IO hub.

That's a pity. Is there a different PCI I2C controller we could model ?

thanks
-- PMM

#7 lore raw
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

I need to see a pretty strong justification for why we should be

adding new kinds of devices to the virt machine,

The designware i2c controller is a very common controller on many

ARM SoCs. It has device tree bindings and ACPI bindings which

Quoted 7 lines
Quoted 1 line

makes it ideal for this platform.

No, I mean, why do we need an i2c controller on the virt

board at all ?

The use case we are interested in is to enable IPMI SSIF on the arm virt machine which is why I was interested in something with ACPI support. That particular IPMI SSIF enablement patch is not in this series but I think it could be pulled into the series if necessary.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

Forgot to mention, but my prefered approach for providing

an i2c controller on the virt board would be to have a

PCI i2c controller: that way users who do need it can plug it

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

in with a -device command line option, and users who don't

need it never have to worry about it.

(We seem to have an ICH9-SMB PCI device already; I have no idea if

it's suitable.)

Quoted 9 lines
Quoted 5 lines

I didn't find that device suitable because it is part of the Intel

Southbridge, which may have some Intel platform quirks, and

we don't need all the things in that IO hub.

That's a pity. Is there a different PCI I2C controller we could model ?

I’m not aware of any standalone PCI I2C controllers. I’ve seen I2C controllers on PCI devices with other things but I don’t think those could
be used for IPMI SSIF or other general I2C use cases. Do you know of a
particular device I should take a look at?

-Chris

Quoted 29 lines · Peter Maydell
Quoted 7 lines · Chris Rauer
Quoted 3 lines

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine,

The designware i2c controller is a very common controller on many
ARM SoCs. It has device tree bindings and ACPI bindings which
makes it ideal for this platform.

No, I mean, why do we need an i2c controller on the virt board at all ?

Quoted 7 lines
Quoted 7 lines

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it.

(We seem to have an ICH9-SMB PCI device already; I have no idea if

it's suitable.)

Quoted 3 lines

I didn't find that device suitable because it is part of the Intel Southbridge, which may have some Intel platform quirks, and we don't need all the things in that IO hub.

That's a pity. Is there a different PCI I2C controller we could model ?

thanks
-- PMM

#8 lore raw
In reply to Peter Maydell

+Enrico Weigelt

Quoted 18 lines · Peter Maydell
Quoted 7 lines · Chris Rauer
Quoted 3 lines

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine,

The designware i2c controller is a very common controller on many
ARM SoCs. It has device tree bindings and ACPI bindings which
makes it ideal for this platform.

No, I mean, why do we need an i2c controller on the virt board at all ?

Quoted 5 lines
Quoted 5 lines

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

(We seem to have an ICH9-SMB PCI device already; I have no idea if it's suitable.)

I didn't find that device suitable because it is part of the Intel Southbridge, which may have some Intel platform quirks, and we don't need all the things in that IO hub.

That's a pity. Is there a different PCI I2C controller we could model ?

What about using virtio-gpio & bitbang I2C?

- virtio-gpio
https://lore.kernel.org/qemu-devel/[email protected]/

- bitbang I2C already in: hw/i2c/bitbang_i2c.c

Regards,

Phil.

#9 lore raw

Hi Phil,

Quoted 6 lines

What about using virtio-gpio & bitbang I2C?

- virtio-gpio
https://lore.kernel.org/qemu-devel/[email protected]/

- bitbang I2C already in: hw/i2c/bitbang_i2c.c

Sorry for the delay.

That looks like it might be doable with a bit more work creating the ACPI entries for the bitbang I2C. This definitely seems more appropriate on the ARM_VIRT platform instead of putting a specific controller in.

For my uses, I will have to stick with the designware controller since it matches the system I'm emulating a little more closely. We can hold back the designware stuff until another SoC platform is interested in using this controller (since it seems like it is a common one). Hopefully someone will find another use for the controller patches someday.

Thanks again for looking at our patches.

-Chris

Quoted 40 lines · Philippe Mathieu-Daudé

+Enrico Weigelt

Quoted 5 lines · Peter Maydell
Quoted 4 lines · Chris Rauer
Quoted 3 lines

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine,

Quoted 14 lines
Quoted 3 lines

The designware i2c controller is a very common controller on many
ARM SoCs. It has device tree bindings and ACPI bindings which
makes it ideal for this platform.

No, I mean, why do we need an i2c controller on the virt board at all ?

Quoted 7 lines
Quoted 7 lines

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it.

(We seem to have an ICH9-SMB PCI device already; I have no idea if

it's suitable.)

Quoted 5 lines
Quoted 3 lines

I didn't find that device suitable because it is part of the Intel Southbridge, which may have some Intel platform quirks, and we don't need all the things in that IO hub.

That's a pity. Is there a different PCI I2C controller we could model ?

What about using virtio-gpio & bitbang I2C?

- virtio-gpio
https://lore.kernel.org/qemu-devel/[email protected]/

- bitbang I2C already in: hw/i2c/bitbang_i2c.c

Regards,

Phil.

#10 lore raw
Quoted 7 lines · Chris Rauer

Hi Phil,

Quoted 5 lines

What about using virtio-gpio & bitbang I2C?

- virtio-gpio
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 6 lines
Quoted 1 line

- bitbang I2C already in: hw/i2c/bitbang_i2c.c

Sorry for the delay.

That looks like it might be doable with a bit more work creating the ACPI entries for the bitbang I2C. This definitely seems more appropriate on the ARM_VIRT platform instead of putting a specific controller in.

I would think the efficiency of this would be horrible.

Quoted 6 lines

For my uses, I will have to stick with the designware controller since it matches the system I'm emulating a little more closely. We can hold back the designware stuff until another SoC platform is interested in using this controller (since it seems like it is a common one). Hopefully someone will find another use for the controller patches someday.

I should have chimed in sooner.

The i.MX i2c device has ACPI and OF support, I believe, and it's already available in qemu. I don't think the Intel smbus device would work.

The designware one is a pretty common and general one, it's a little suprising that it hasn't already been done on qemu. I would be ok with this but Peter has the big picture here.

-corey

Quoted 49 lines

Thanks again for looking at our patches.

-Chris

Quoted 40 lines · Philippe Mathieu-Daudé

+Enrico Weigelt

Quoted 5 lines · Peter Maydell
Quoted 4 lines · Chris Rauer
Quoted 3 lines

I need to see a pretty strong justification for why we should be adding new kinds of devices to the virt machine,

Quoted 14 lines
Quoted 3 lines

The designware i2c controller is a very common controller on many
ARM SoCs. It has device tree bindings and ACPI bindings which
makes it ideal for this platform.

No, I mean, why do we need an i2c controller on the virt board at all ?

Quoted 7 lines
Quoted 7 lines

Forgot to mention, but my prefered approach for providing an i2c controller on the virt board would be to have a PCI i2c controller: that way users who do need it can plug it in with a -device command line option, and users who don't need it never have to worry about it.

(We seem to have an ICH9-SMB PCI device already; I have no idea if

it's suitable.)

Quoted 5 lines
Quoted 3 lines

I didn't find that device suitable because it is part of the Intel Southbridge, which may have some Intel platform quirks, and we don't need all the things in that IO hub.

That's a pity. Is there a different PCI I2C controller we could model ?

What about using virtio-gpio & bitbang I2C?

- virtio-gpio
https://lore.kernel.org/qemu-devel/[email protected]/

- bitbang I2C already in: hw/i2c/bitbang_i2c.c

Regards,

Phil.