hw/i2c/dw: Add DesignWare I2C controller emulator
cover hw/i2c/dw: Add DesignWare I2C controller emulator
Hi all,
This series try to add DesignWare I2C controller according to DesignWare I2C databook v2.01a.
Cause DesignWare I2C controller is commonly used on arm soc chip, I add it onto arm virt board, and also an at24c eeprom for r/w operation.
I also add the I2C controller and at24c eeprom into the acpi table of arm virt board.
The code above has been confirmed with i2c-tools under linux v6.18 kernel driver.
Thanks for your review!
Alano Song.
Alano Song (2):
hw/i2c/dw: Add DesignWare I2C controller emulator hw/arm/virt: Add DesignWare I2C controller
hw/arm/Kconfig | 1 + hw/arm/virt-acpi-build.c | 32 +++ hw/arm/virt.c | 38 ++- hw/i2c/Kconfig | 4 + hw/i2c/dw_i2c.c | 517 +++++++++++++++++++++++++++++++++++++++ hw/i2c/meson.build | 1 + hw/i2c/trace-events | 4 + include/hw/arm/virt.h | 1 + include/hw/i2c/dw_i2c.h | 151 ++++++++++++ 9 files changed, 748 insertions(+), 1 deletion(-) create mode 100644 hw/i2c/dw_i2c.c create mode 100644 include/hw/i2c/dw_i2c.h
Signature · 1 line
2.43.0
PATCH 1/2 hw/i2c/dw: Add DesignWare I2C controller emulator
Add DesignWare I2C controller according to DesignWare I2C databook v2.01a.
Confirmed the model with i2c-tools under v6.18 linux driver.
The slave mode is not implemented, cause this feature is usually not used.
The 10 bit slave address is not implemented, cause this feature is usually not used, and not supported by qemu I2C core bus currently.
--- hw/i2c/Kconfig | 4 + hw/i2c/dw_i2c.c | 517 ++++++++++++++++++++++++++++++++++++++++ hw/i2c/meson.build | 1 + hw/i2c/trace-events | 4 + include/hw/i2c/dw_i2c.h | 151 ++++++++++++ 5 files changed, 677 insertions(+) create mode 100644 hw/i2c/dw_i2c.c create mode 100644 include/hw/i2c/dw_i2c.h
hw/i2c/Kconfig +4 -0
@@ -30,6 +30,10 @@ config IMX_I2C bool select I2C +config DW_I2C + bool + select I2C + config MPC_I2C bool select I2C
hw/i2c/dw_i2c.c new file +517 -0
517 lines not on this page · raw message
hw/i2c/meson.build +1 -0
@@ -7,6 +7,7 @@ i2c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i2c.c')) i2c_ss.add(when: 'CONFIG_BITBANG_I2C', if_true: files('bitbang_i2c.c')) i2c_ss.add(when: 'CONFIG_EXYNOS4', if_true: files('exynos4210_i2c.c')) i2c_ss.add(when: 'CONFIG_IMX_I2C', if_true: files('imx_i2c.c')) +i2c_ss.add(when: 'CONFIG_DW_I2C', if_true: files('dw_i2c.c')) i2c_ss.add(when: 'CONFIG_MPC_I2C', if_true: files('mpc_i2c.c')) i2c_ss.add(when: 'CONFIG_ALLWINNER_I2C', if_true: files('allwinner-i2c.c')) i2c_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('microbit_i2c.c'))
hw/i2c/trace-events +4 -0
@@ -61,3 +61,7 @@ pca954x_read_data(uint8_t value) "PCA954X read data: 0x%02x" imx_i2c_read(const char *id, const char *reg, uint64_t ofs, uint64_t value) "%s:[%s (0x%" PRIx64 ")] -> 0x%02" PRIx64 imx_i2c_write(const char *id, const char *reg, uint64_t ofs, uint64_t value) "%s:[%s (0x%" PRIx64 ")] <- 0x%02" PRIx64 + +# dw_i2c.c +dw_i2c_read(const char *id, const char *reg, uint64_t ofs, uint64_t value) "%s:[%s (0x%" PRIx64 ")] -> 0x%02" PRIx64 +dw_i2c_write(const char *id, const char *reg, uint64_t ofs, uint64_t value) "%s:[%s (0x%" PRIx64 ")] <- 0x%02" PRIx64
include/hw/i2c/dw_i2c.h new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
2.43.0
Quoted 5 lines · On Tue, 6 Jan 2026 21:12:52 +0800 [email protected] wrote:
Add DesignWare I2C controller according to DesignWare I2C databook v2.01a.
Confirmed the model with i2c-tools under v6.18 linux driver.
Quoted 8 lines
The slave mode is not implemented, cause this feature is usually not used.
The 10 bit slave address is not implemented, cause this feature is usually not used, and not supported by qemu I2C core bus currently.
Signed-off-by Alano Song <[email protected]>
Hi Alano,
A very superficial review. Sadly I don't have time to dig much deeper at the moment.
Good to see this support.
Jonathan
Quoted 15 lines
hw/i2c/dw_i2c.c new file +9
-0@@ -0,0 +1,517 @@ +/* +* DesignWare I2C Bus Serial Interface Emulation +* +* Copyright (C) 2026 Alano Song <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version.
hw/i2c/dw_i2c.c line 19
Quoted 10 lines
hw/i2c/dw_i2c.c new file +10
-0+* +* This program 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 General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/
As below. Can probably replace the boilerplate with an SPDX license line and just have the copyright + intro text here.
Quoted 13 lines
include/hw/i2c/dw_i2c.h new file +7
-0@@ -0,0 +1,151 @@ +/* +* DesignWare I2C Bus Serial Interface Emulation +* +* Copyright (C) 2026 Alano Song <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the
include/hw/i2c/dw_i2c.h line 17
Quoted 10 lines
include/hw/i2c/dw_i2c.h new file +10
-0+* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program 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 General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>.
For new code in QEMU I think we are fine with just SPDX. See many examples in tree. It saves on repeating this boilerplate.
Quoted 11 lines
include/hw/i2c/dw_i2c.h new file +11
-0+* +*/ + +#ifndef DW_I2C_H +#define DW_I2C_H + +#include "hw/core/sysbus.h" +#include "qom/object.h" +#include "qemu/fifo8.h" + +#define TYPE_DW_I2C "dw.i2c"
include/hw/i2c/dw_i2c.h line 72
Quoted 10 lines
include/hw/i2c/dw_i2c.h new file +9
-0+OBJECT_DECLARE_SIMPLE_TYPE(DWI2CState, DW_I2C) + +#define DW_I2C_TX_FIFO_DEPTH 16 +#define DW_I2C_RX_FIFO_DEPTH 16 + +#define DW_IC_CON_MASTER BIT(0) +#define DW_IC_CON_SPEED_STANDARD (0x1 << 1) +#define DW_IC_CON_SPEED_FAST (0x2 << 1) +#define DW_IC_CON_SPEED_HIGH (0x3 << 1)
Smells of value being written to a field rather than a series of values with meaning on their own. Qemu has a rich set of register field macros. I'd look at using those to make your life easier.
Quoted 1 line
+#define
DW_IC_CON_RESTART_ENBIT(5)
Quoted 16 lines · Jonathan Cameron
Quoted 5 lines · On Tue, 6 Jan 2026 21:12:52 +0800 [email protected] wrote:
Add DesignWare I2C controller according to DesignWare I2C databook v2.01a.
Confirmed the model with i2c-tools under v6.18 linux driver.Quoted 8 lines
The slave mode is not implemented, cause this feature is usually not used.
The 10 bit slave address is not implemented, cause this feature is usually not used, and not supported by qemu I2C core bus currently.
Signed-off-by Alano Song <[email protected]>
Quoted 10 lines
Hi Alano,
A very superficial review. Sadly I don't have time to dig much deeper at the moment.
Good to see this support.
Jonathan
Still appreciate for your patient review and reply!
Quoted 19 lines
Quoted 19 lines
hw/i2c/dw_i2c.c new file +13
-0@@ -0,0 +1,517 @@ +/* +* DesignWare I2C Bus Serial Interface Emulation +* +* Copyright (C) 2026 Alano Song <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program 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 General Public License
Quoted 10 lines
hw/i2c/dw_i2c.c line 19
Quoted 6 lines
hw/i2c/dw_i2c.c new file +6
-0+* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. +* +*/ As below. Can probably replace the boilerplate with an SPDX license line and just have the copyright + intro text here.
Okay, I will submit version 2 patch to refine it.
Quoted 19 lines
Quoted 19 lines
include/hw/i2c/dw_i2c.h new file +12
-0@@ -0,0 +1,151 @@ +/* +* DesignWare I2C Bus Serial Interface Emulation +* +* Copyright (C) 2026 Alano Song <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Quoted 10 lines
include/hw/i2c/dw_i2c.h line 17
Quoted 5 lines
include/hw/i2c/dw_i2c.h new file +5
-0+* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +* for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, see <http://www.gnu.org/licenses/>. For new code in QEMU I think we are fine with just SPDX. See many examples in tree. It saves on repeating this boilerplate.
Okay, I will submit version 2 patch to refine it.
Quoted 16 lines
Quoted 15 lines
include/hw/i2c/dw_i2c.h new file +15
-0+* +*/ + +#ifndef DW_I2C_H +#define DW_I2C_H + +#include "hw/core/sysbus.h" +#include "qom/object.h" +#include "qemu/fifo8.h" + +#define TYPE_DW_I2C "dw.i2c" +OBJECT_DECLARE_SIMPLE_TYPE(DWI2CState, DW_I2C) + +#define DW_I2C_TX_FIFO_DEPTH 16 +#define DW_I2C_RX_FIFO_DEPTH 16
Quoted 12 lines
include/hw/i2c/dw_i2c.h line 72
Quoted 5 lines
include/hw/i2c/dw_i2c.h new file +5
-0+ +#define DW_IC_CON_MASTER BIT(0) +#define DW_IC_CON_SPEED_STANDARD (0x1 << 1) +#define DW_IC_CON_SPEED_FAST (0x2 << 1) +#define DW_IC_CON_SPEED_HIGH (0x3 << 1)Smells of value being written to a field rather than a series of values with meaning on their own. Qemu has a rich set of register field macros. I'd look at using those to make your life easier.
Your suggestion is good, I will refine this part
in version 2 patch.
Quoted 1 line
Quoted 1 line
include/hw/i2c/dw_i2c.h new file +1
-0+#define DW_IC_CON_RESTART_EN BIT(5)
PATCH 2/2 hw/arm/virt: Add DesignWare I2C controller
In reply to [email protected]From: Alano Song <[email protected]>
Add DesignWare I2C controller onto virt board,
and also an at24c eeprom for r/w operation.
Add these two devices into arm virt acpi table.
Confirmed with i2c-tools under v6.18 linux driver.
--- hw/arm/Kconfig | 1 + hw/arm/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ hw/arm/virt.c | 38 +++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 4 files changed, 71 insertions(+), 1 deletion(-)
hw/arm/Kconfig +1 -0
@@ -36,6 +36,7 @@ config ARM_VIRT select VIRTIO_MEM_SUPPORTED select ACPI_CXL select ACPI_HMAT + select DW_I2C config CUBIEBOARD bool
hw/arm/virt-acpi-build.c +32 -0
@@ -100,6 +100,34 @@ static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,aml_append (scope, dev); } +static void acpi_dsdt_add_i2c (Aml *scope,const MemMapEntry *i2c_memmap, +uint32_t i2c_irq) +{ +Aml *i2c_dev, *eprm_dev, *crs; + + i2c_dev =aml_device ("I2C0" ); +aml_append (i2c_dev,aml_name_decl ("_HID" ,aml_string ("INT3433" ))); +aml_append (i2c_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_memory32_fixed (i2c_memmap->base, + i2c_memmap->size,AML_READ_WRITE )); +aml_append (crs,aml_interrupt (AML_CONSUMER ,AML_LEVEL ,AML_ACTIVE_HIGH , +AML_EXCLUSIVE , &i2c_irq,1 )); +aml_append (i2c_dev,aml_name_decl ("_CRS" , crs)); + + eprm_dev =aml_device ("EPRM" ); +aml_append (eprm_dev,aml_name_decl ("_HID" ,aml_string ("INT3499" ))); +aml_append (eprm_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_i2c_serial_bus_device (0x50 ,"^" )); +aml_append (eprm_dev,aml_name_decl ("_CRS" , crs)); + +aml_append (i2c_dev, eprm_dev); +aml_append (scope, i2c_dev); +} +static void acpi_dsdt_add_flash (Aml *scope,const MemMapEntry *flash_memmap) {Aml *dev, *crs;
@@ -1037,6 +1065,10 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)acpi_dsdt_add_uart (scope, &memmap[VIRT_UART1 ], (irqmap[VIRT_UART1 ] +ARM_SPI_BASE ),1 ); } + +acpi_dsdt_add_i2c (scope, &memmap[VIRT_I2C ], + irqmap[VIRT_I2C ] +ARM_SPI_BASE ); +if (vmc->acpi_expose_flash) {acpi_dsdt_add_flash (scope, &memmap[VIRT_FLASH ]); }
hw/arm/virt.c +37 -1
@@ -38,6 +38,8 @@#include "hw/arm/boot.h" #include "hw/arm/primecell.h" #include "hw/arm/virt.h" +#include "hw/i2c/dw_i2c.h" +#include "hw/nvram/eeprom_at24c.h" #include "hw/arm/machines-qom.h" #include "hw/block/flash.h" #include "hw/display/ramfb.h"
@@ -193,7 +195,8 @@ static const MemMapEntry base_memmap[] = { [VIRT_NVDIMM_ACPI] = { 0x09090000, NVDIMM_ACPI_IO_LEN}, [VIRT_PVTIME] = { 0x090a0000, 0x00010000 }, [VIRT_SECURE_GPIO] = { 0x090b0000, 0x00001000 }, - [VIRT_ACPI_PCIHP] = { 0x090c0000, ACPI_PCIHP_SIZE }, + [VIRT_I2C] = { 0x090c0000, 0x00001000 }, + [VIRT_ACPI_PCIHP] = { 0x090d0000, ACPI_PCIHP_SIZE }, [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },
@@ -245,6 +248,7 @@ static const int a15irqmap[] = { [VIRT_GPIO] = 7, [VIRT_UART1] = 8, [VIRT_ACPI_GED] = 9, + [VIRT_I2C] = 10, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] = 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */
@@ -1016,6 +1020,36 @@ static void create_uart(const VirtMachineState *vms, int uart,g_free (nodename); } +static void create_i2c (const VirtMachineState *vms,int i2c) +{ +char *nodename =NULL ; +hwaddr base = vms->memmap[i2c].base; +hwaddr size = vms->memmap[i2c].size; +int irq = vms->irqmap[i2c]; +MachineState *ms =MACHINE (vms); +DeviceState *dev =sysbus_create_simple (TYPE_DW_I2C , base, +qdev_get_gpio_in (vms->gic, irq)); +DWI2CState *s =DW_I2C (dev); + + nodename =g_strdup_printf ("/dw-i2c@%" PRIx64, base); +qemu_fdt_add_subnode (ms->fdt, nodename); +qemu_fdt_setprop_string (ms->fdt, nodename,"compatible" , +"snps,designware-i2c" ); +qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" , +2 , base,2 , size); +qemu_fdt_setprop_cells (ms->fdt, nodename,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq, +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); + +if (s && s->bus) { +at24c_eeprom_init (s->bus,0x50 ,256 ); + }else { +fprintf (stderr,"Warning: DW I2C created but bus not available\n" ); + } + +g_free (nodename); +} +static void create_rtc (const VirtMachineState *vms) {char *nodename;
@@ -2493,6 +2527,8 @@ static void machvirt_init(MachineState *machine)create_uart (vms,VIRT_UART1 , secure_sysmem,serial_hd (1 ), true); } +create_i2c (vms,VIRT_I2C ); +if (vms->secure) {create_secure_ram (vms, secure_sysmem, secure_tag_sysmem); }
include/hw/arm/virt.h +1 -0
@@ -75,6 +75,7 @@ enum {VIRT_PLATFORM_BUS ,VIRT_GPIO ,VIRT_UART1 , +VIRT_I2C ,VIRT_SECURE_MEM ,VIRT_SECURE_GPIO , VIRT_PCDIMM_ACPI,
Signature · 1 line
2.43.0
Re: [PATCH 2/2] hw/arm/virt: Add DesignWare I2C controller
Quoted 9 lines · On Tue, 6 Jan 2026 21:12:53 +0800 [email protected] wrote:
From: Alano Song <[email protected]>
Add DesignWare I2C controller onto virt board,
and also an at24c eeprom for r/w operation.Add these two devices into arm virt acpi table.
Confirmed with i2c-tools under v6.18 linux driver.
Hi Alano,
Quoted 1 line
Signed-off-by Alano Song <[email protected]>
Perhaps a silly question but why do you want this on arm/virt?
I've been carrying a backed up version of the aspeed i2c but for that we are using it with MCTP (I'm guessing this one isn't capable enough) and devices on that are inherently discoverable unlike normal I2C devices. Even so I don't plan to upstream that as for the CXL fabric stuff I can use MCTP over USB instead and don't need to change arm/virt at all.
I'm not sure how useful an eeprom is beyond verifying your control emulation, but perhaps that's all that is intended?
Quoted 12 lines
--- hw/arm/Kconfig | 1 + hw/arm/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ hw/arm/virt.c | 38 +++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 4 files changed, 71 insertions(+), 1 deletion(-)hw/arm/virt-acpi-build.c +0
-0
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 102
Quoted 3 lines
hw/arm/virt-acpi-build.c +0
-0@@ -100,6 +100,34 @@ static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,aml_append (scope, dev); }
An example of the AML blob would be useful in the patch description (or the one updating the ACPI test tables).
I'd also expect a lot of bios test failures given you didn't change the data files. Run make check-qtest and see what blow up.
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 109
Quoted 7 lines
hw/arm/virt-acpi-build.c +7
-0+static void acpi_dsdt_add_i2c (Aml *scope,const MemMapEntry *i2c_memmap, +uint32_t i2c_irq) +{ +Aml *i2c_dev, *eprm_dev, *crs; + + i2c_dev =aml_device ("I2C0" ); +aml_append (i2c_dev,aml_name_decl ("_HID" ,aml_string ("INT3433" )));
That seems to be a valid intel PNP ID, but please add a reference to where it came from (I'll guess the kernel driver rather than some document?)
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 120
Quoted 11 lines
hw/arm/virt-acpi-build.c +11
-0+aml_append (i2c_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_memory32_fixed (i2c_memmap->base, + i2c_memmap->size,AML_READ_WRITE )); +aml_append (crs,aml_interrupt (AML_CONSUMER ,AML_LEVEL ,AML_ACTIVE_HIGH , +AML_EXCLUSIVE , &i2c_irq,1 )); +aml_append (i2c_dev,aml_name_decl ("_CRS" , crs)); + + eprm_dev =aml_device ("EPRM" ); +aml_append (eprm_dev,aml_name_decl ("_HID" ,aml_string ("INT3499" )));
Likewise, a reference for this PNP format ACPI ID would be good.
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 124
Quoted 4 lines
hw/arm/virt-acpi-build.c +4
-0+aml_append (eprm_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_i2c_serial_bus_device (0x50 ,"^" ));
This is the bit that made me ask for a blob in the patch description. I have very little idea what that actually does in AML :( (the "^" in particular)
Quoted 20 lines
hw/arm/virt-acpi-build.c +5
-0+aml_append (eprm_dev,aml_name_decl ("_CRS" , crs)); + +aml_append (i2c_dev, eprm_dev); +aml_append (scope, i2c_dev); +}hw/arm/virt.c +2
-0@@ -38,6 +38,8 @@#include "hw/arm/boot.h" #include "hw/arm/primecell.h" #include "hw/arm/virt.h" +#include "hw/i2c/dw_i2c.h" +#include "hw/nvram/eeprom_at24c.h" #include "hw/arm/machines-qom.h" #include "hw/block/flash.h" #include "hw/display/ramfb.h"
hw/arm/virt.c static const MemMapEntry base_memmap[] = { · line 199
Quoted 6 lines
hw/arm/virt.c +2
-1@@ -193,7 +195,8 @@ static const MemMapEntry base_memmap[] = { [VIRT_NVDIMM_ACPI] = { 0x09090000, NVDIMM_ACPI_IO_LEN}, [VIRT_PVTIME] = { 0x090a0000, 0x00010000 }, [VIRT_SECURE_GPIO] = { 0x090b0000, 0x00001000 }, - [VIRT_ACPI_PCIHP] = { 0x090c0000, ACPI_PCIHP_SIZE }, + [VIRT_I2C] = { 0x090c0000, 0x00001000 }, + [VIRT_ACPI_PCIHP] = { 0x090d0000, ACPI_PCIHP_SIZE },
This breaks VM migration. You need to put your new memory in a hole in the memory map, not move things.
Quoted 12 lines
hw/arm/virt.c +1
-0[VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },@@ -245,6 +248,7 @@ static const int a15irqmap[] = { [VIRT_GPIO] = 7, [VIRT_UART1] = 8, [VIRT_ACPI_GED] = 9, + [VIRT_I2C] = 10, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] = 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */
hw/arm/virt.c static void create_uart(const VirtMachineState *vms, int uart, · line 1025
Quoted 6 lines
hw/arm/virt.c +3
-0@@ -1016,6 +1020,36 @@ static void create_uart(const VirtMachineState *vms, int uart,g_free (nodename); } +static void create_i2c (const VirtMachineState *vms,int i2c) +{ +char *nodename =NULL ;
Always overridden so don't set initial value. Maybe use a g_autofree to avoid having to tidy it up on exit from the function.
Quoted 26 lines
hw/arm/virt.c +26
-0+hwaddr base = vms->memmap[i2c].base; +hwaddr size = vms->memmap[i2c].size; +int irq = vms->irqmap[i2c]; +MachineState *ms =MACHINE (vms); +DeviceState *dev =sysbus_create_simple (TYPE_DW_I2C , base, +qdev_get_gpio_in (vms->gic, irq)); +DWI2CState *s =DW_I2C (dev); + + nodename =g_strdup_printf ("/dw-i2c@%" PRIx64, base); +qemu_fdt_add_subnode (ms->fdt, nodename); +qemu_fdt_setprop_string (ms->fdt, nodename,"compatible" , +"snps,designware-i2c" ); +qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" , +2 , base,2 , size); +qemu_fdt_setprop_cells (ms->fdt, nodename,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq, +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); + +if (s && s->bus) { +at24c_eeprom_init (s->bus,0x50 ,256 ); + }else { +fprintf (stderr,"Warning: DW I2C created but bus not available\n" ); + } + +g_free (nodename); +}
Re:Re: [PATCH 2/2] hw/arm/virt: Add DesignWare I2C controller
Quoted 16 lines · Jonathan Cameron via
Quoted 9 lines · On Tue, 6 Jan 2026 21:12:53 +0800 [email protected] wrote:
From: Alano Song <[email protected]>
Add DesignWare I2C controller onto virt board,
and also an at24c eeprom for r/w operation.Add these two devices into arm virt acpi table.
Confirmed with i2c-tools under v6.18 linux driver.
Hi Alano,
Quoted 1 line
Signed-off-by Alano Song <[email protected]>
Quoted 9 lines
Perhaps a silly question but why do you want this on arm/virt?
I've been carrying a backed up version of the aspeed i2c but for that we are using it with MCTP (I'm guessing this one isn't capable enough) and devices on that are inherently discoverable unlike normal I2C devices. Even so I don't plan to upstream that as for the CXL fabric stuff I can use MCTP over USB instead and don't need to change arm/virt at all.
Cause we are emulating our soc chip on qemu, and our first choice of machine board is arm/virt.
But we unfortunately found there is no DesignWare I2C model and no I2C device in arm/virt.
Someone else may encounter this problem as well, so I decide to solve it.
Quoted 5 lines
I'm not sure how useful an eeprom is beyond verifying your control emulation, but perhaps that's all that is intended?
Yes you are right, single I2C controller cannot be verified, so I add an eeprom to work with it.
Quoted 7 lines
Quoted 6 lines
--- hw/arm/Kconfig | 1 + hw/arm/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ hw/arm/virt.c | 38 +++++++++++++++++++++++++++++++++++++- include/hw/arm/virt.h | 1 + 4 files changed, 71 insertions(+), 1 deletion(-)
Quoted 15 lines
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 102
Quoted 8 lines
hw/arm/virt-acpi-build.c +0
-0@@ -100,6 +100,34 @@ static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap,aml_append (scope, dev); }An example of the AML blob would be useful in the patch description (or the one updating the ACPI test tables).
I'd also expect a lot of bios test failures given you didn't change the data files. Run make check-qtest and see what blow up.
Your suggestion is quiet right, I will add comment of ACPI table in patch v2 description.
And I make check-qtest, you are right, I will fix the test failure leaded by this patch in patch v2.
Quoted 12 lines
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 109
Quoted 7 lines
hw/arm/virt-acpi-build.c +7
-0+static void acpi_dsdt_add_i2c (Aml *scope,const MemMapEntry *i2c_memmap, +uint32_t i2c_irq) +{ +Aml *i2c_dev, *eprm_dev, *crs; + + i2c_dev =aml_device ("I2C0" ); +aml_append (i2c_dev,aml_name_decl ("_HID" ,aml_string ("INT3433" )));That seems to be a valid intel PNP ID, but please add a reference to where it came from (I'll guess the kernel driver rather than some document?)
Yes, you are right, this PNP ID comes from kernel driver(i2c-designware-platdrv.c/dw_i2c_acpi_match) it's just for testing convenience under linux kernel.
I will add comment for it.
Quoted 5 lines
Quoted 5 lines
hw/arm/virt-acpi-build.c +5
-0+aml_append (i2c_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_memory32_fixed (i2c_memmap->base, + i2c_memmap->size,AML_READ_WRITE ));
Quoted 10 lines
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 120
Quoted 6 lines
hw/arm/virt-acpi-build.c +6
-0+aml_append (crs,aml_interrupt (AML_CONSUMER ,AML_LEVEL ,AML_ACTIVE_HIGH , +AML_EXCLUSIVE , &i2c_irq,1 )); +aml_append (i2c_dev,aml_name_decl ("_CRS" , crs)); + + eprm_dev =aml_device ("EPRM" ); +aml_append (eprm_dev,aml_name_decl ("_HID" ,aml_string ("INT3499" )));Likewise, a reference for this PNP format ACPI ID would be good.
Okay, I will add comment for it :)
Quoted 10 lines
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 124
Quoted 4 lines
hw/arm/virt-acpi-build.c +4
-0+aml_append (eprm_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_i2c_serial_bus_device (0x50 ,"^" ));This is the bit that made me ask for a blob in the patch description. I have very little idea what that actually does in AML :( (the "^" in particular)
Here, "^" represents the father device of eeprom ("EPRM"), just the I2C controller device ("I2C0").
I will add description for it in patch v2.
Quoted 21 lines
Quoted 21 lines
hw/arm/virt-acpi-build.c +5
-0+aml_append (eprm_dev,aml_name_decl ("_CRS" , crs)); + +aml_append (i2c_dev, eprm_dev); +aml_append (scope, i2c_dev); +}hw/arm/virt.c +2
-0@@ -38,6 +38,8 @@#include "hw/arm/boot.h" #include "hw/arm/primecell.h" #include "hw/arm/virt.h" +#include "hw/i2c/dw_i2c.h" +#include "hw/nvram/eeprom_at24c.h" #include "hw/arm/machines-qom.h" #include "hw/block/flash.h" #include "hw/display/ramfb.h" @@ -193,7 +195,8 @@ static const MemMapEntry base_memmap[] = { [VIRT_NVDIMM_ACPI] = { 0x09090000, NVDIMM_ACPI_IO_LEN},
Quoted 10 lines
hw/arm/virt.c static const MemMapEntry base_memmap[] = { · line 199
Quoted 5 lines
hw/arm/virt.c +2
-1[VIRT_PVTIME] = { 0x090a0000, 0x00010000 }, [VIRT_SECURE_GPIO] = { 0x090b0000, 0x00001000 }, - [VIRT_ACPI_PCIHP] = { 0x090c0000, ACPI_PCIHP_SIZE }, + [VIRT_I2C] = { 0x090c0000, 0x00001000 }, + [VIRT_ACPI_PCIHP] = { 0x090d0000, ACPI_PCIHP_SIZE },This breaks VM migration. You need to put your new memory in a hole in the memory map, not move things.
Okay, I will refine this part code :)
Quoted 15 lines
Quoted 15 lines
hw/arm/virt.c +1
-0[VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },@@ -245,6 +248,7 @@ static const int a15irqmap[] = { [VIRT_GPIO] = 7, [VIRT_UART1] = 8, [VIRT_ACPI_GED] = 9, + [VIRT_I2C] = 10, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] = 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */@@ -1016,6 +1020,36 @@ static void create_uart(const VirtMachineState *vms, int uart,g_free (nodename); }
Quoted 8 lines
hw/arm/virt.c static void create_uart(const VirtMachineState *vms, int uart, · line 1025
Quoted 3 lines
hw/arm/virt.c +3
-0+static void create_i2c (const VirtMachineState *vms,int i2c) +{ +char *nodename =NULL ;Always overridden so don't set initial value. Maybe use a
g_autofreeto avoid having to tidy it up on exit from the function.
Thanks for your advice, I will refine this part code :)
Quoted 27 lines
Quoted 26 lines
hw/arm/virt.c +26
-0+hwaddr base = vms->memmap[i2c].base; +hwaddr size = vms->memmap[i2c].size; +int irq = vms->irqmap[i2c]; +MachineState *ms =MACHINE (vms); +DeviceState *dev =sysbus_create_simple (TYPE_DW_I2C , base, +qdev_get_gpio_in (vms->gic, irq)); +DWI2CState *s =DW_I2C (dev); + + nodename =g_strdup_printf ("/dw-i2c@%" PRIx64, base); +qemu_fdt_add_subnode (ms->fdt, nodename); +qemu_fdt_setprop_string (ms->fdt, nodename,"compatible" , +"snps,designware-i2c" ); +qemu_fdt_setprop_sized_cells (ms->fdt, nodename,"reg" , +2 , base,2 , size); +qemu_fdt_setprop_cells (ms->fdt, nodename,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq, +GIC_FDT_IRQ_FLAGS_LEVEL_HI ); + +if (s && s->bus) { +at24c_eeprom_init (s->bus,0x50 ,256 ); + }else { +fprintf (stderr,"Warning: DW I2C created but bus not available\n" ); + } + +g_free (nodename); +}
Re: [PATCH 2/2] hw/arm/virt: Add DesignWare I2C controller
Quoted 28 lines · On Wed, 7 Jan 2026 15:07:10 +0800 (CST) "Alano Song" <[email protected]> wrote:
Quoted 16 lines · Jonathan Cameron via
Quoted 9 lines · On Tue, 6 Jan 2026 21:12:53 +0800 [email protected] wrote:
From: Alano Song <[email protected]>
Add DesignWare I2C controller onto virt board,
and also an at24c eeprom for r/w operation.Add these two devices into arm virt acpi table.
Confirmed with i2c-tools under v6.18 linux driver.
Hi Alano,
Quoted 1 line
Signed-off-by Alano Song <[email protected]>Quoted 9 lines
Perhaps a silly question but why do you want this on arm/virt?
I've been carrying a backed up version of the aspeed i2c but for that we are using it with MCTP (I'm guessing this one isn't capable enough) and devices on that are inherently discoverable unlike normal I2C devices. Even so I don't plan to upstream that as for the CXL fabric stuff I can use MCTP over USB instead and don't need to change arm/virt at all.
Quoted 2 lines
Cause we are emulating our soc chip on qemu, and our first choice of machine board is arm/virt.
Are you planning to ultimately upstream support for emulating your SoC? If you do, is a new emulated board perhaps appropriate?
Quoted 4 lines
But we unfortunately found there is no DesignWare I2C model and no I2C device in arm/virt.
Someone else may encounter this problem as well, so I decide to solve it.
It's definitely good to have emulation of this fairly common IP.
Quoted 11 lines
Quoted 7 lines
I'm not sure how useful an eeprom is beyond verifying your control emulation, but perhaps that's all that is intended?
Yes you are right, single I2C controller cannot be verified, so I add an eeprom to work with it.
Within arm virt one concern is that this unconditionally enabled so attacks on emulation code are a real possibility (in VM usecases)
Quoted 18 lines
Quoted 4 lines
Quoted 3 lines
---
Quoted 12 lines
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 109
Quoted 7 lines
hw/arm/virt-acpi-build.c +7
-0+static void acpi_dsdt_add_i2c (Aml *scope,const MemMapEntry *i2c_memmap, +uint32_t i2c_irq) +{ +Aml *i2c_dev, *eprm_dev, *crs; + + i2c_dev =aml_device ("I2C0" ); +aml_append (i2c_dev,aml_name_decl ("_HID" ,aml_string ("INT3433" )));That seems to be a valid intel PNP ID, but please add a reference to where it came from (I'll guess the kernel driver rather than some document?)
Quoted 3 lines
Yes, you are right, this PNP ID comes from kernel
driver(i2c-designware-platdrv.c/dw_i2c_acpi_match)it's just for testing convenience under linux kernel.
If you are ultimately emulating a real SoC I'd suggest using an ID issued by they vendor of the board or the SoC. They will need to have a suitable ACPI or PNP ID though (and so be a member of UEFI.org) That will allow for any quirks in the kernel driver (and you'd need to emulate them as well). Who knows what slight differences there might be with the Intel version of the IP.
Quoted 14 lines
Quoted 12 lines
hw/arm/virt-acpi-build.c static void acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, · line 124
Quoted 6 lines
hw/arm/virt-acpi-build.c +4
-0+aml_append (eprm_dev,aml_name_decl ("_UID" ,aml_int (0 ))); + + crs =aml_resource_template (); +aml_append (crs,aml_i2c_serial_bus_device (0x50 ,"^" ));This is the bit that made me ask for a blob in the patch description. I have very little idea what that actually does in AML :( (the "^" in particular)
Quoted 3 lines
Here, "^" represents the father device of eeprom ("EPRM"), just the I2C controller device ("I2C0").
I will add description for it in patch v2.
Ah. Ok. I didn't know about that and couldn't find it in the ACPI spec :( A more specific reference like you suggest is fine.
Jonathan