hw/arm/aspeed: Add AST1040 peripheral support
PATCH v2 6/10 hw/arm/aspeed_ast1040: Add SGPIO controller support
In reply to Jamin LinThe AST1040 SGPIO controller is compatible with the AST2700 SGPIO controller implementation.
AST1040 contains two SGPIO controllers, so reuse the existing "aspeed.sgpio-ast2700" device model instead of keeping them as unimplemented devices.
MMIO mapping:
- SGPIOM0 : 0x74C0C000
- SGPIOM1 : 0x74C0D000
IRQ mapping:
- SGPIOM0 : IRQ 85
- SGPIOM1 : IRQ 88
--- hw/arm/aspeed_ast1040.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
hw/arm/aspeed_ast1040.c +17 -12
@@ -56,6 +56,7 @@ static const int aspeed_soc_ast1040_irqmap[] = { [ASPEED_DEV_ADC] = 80, [ASPEED_DEV_GPIO] = 82, [ASPEED_DEV_SGPIOM0] = 85, + [ASPEED_DEV_SGPIOM1] = 88, [ASPEED_DEV_TIMER1] = 92, [ASPEED_DEV_I3C] = 96, /* 96 ~ 103 */ [ASPEED_DEV_WDT] = 112,
@@ -112,14 +113,14 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"adc" , &s->adc,TYPE_ASPEED_2700_ADC );object_initialize_child (obj,"peci" , &s->peci,TYPE_ASPEED_PECI );object_initialize_child (obj,"gpio" , &s->gpio,"aspeed.gpio-ast2700" ); +for (i =0 ; i < sc->sgpio_num; i++) { +object_initialize_child (obj,"sgpio[*]" , &s->sgpiom[i], +"aspeed.sgpio-ast2700" ); + }object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"udc" , &s->udc,TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"sgpiom[0]" , &s->sgpiom[0 ], -TYPE_UNIMPLEMENTED_DEVICE ); -object_initialize_child (obj,"sgpiom[1]" , &s->sgpiom[1 ], -TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"jtag[0]" , &s->jtag[0 ],TYPE_UNIMPLEMENTED_DEVICE ); object_initialize_child(obj, "jtag[1]", &s->jtag[1],
@@ -221,6 +222,17 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpio),0 ,aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_GPIO )); +/* SGPIO */ +for (i =0 ; i < sc->sgpio_num; i++) { +if (!sysbus_realize (SYS_BUS_DEVICE (&s->sgpiom[i]), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->sgpiom[i]),0 , + sc->memmap[ASPEED_DEV_SGPIOM0 + i]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->sgpiom[i]),0 , +aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_SGPIOM0 + i)); + } +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
@@ -234,14 +246,6 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)"aspeed.udc" , sc->memmap[ASPEED_DEV_UDC], 0x4000); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->sgpiom[0 ]), -"aspeed.sgpiom0" , - sc->memmap[ASPEED_DEV_SGPIOM0 ],0x1000 ); - -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->sgpiom[1 ]), -"aspeed.sgpiom1" , - sc->memmap[ASPEED_DEV_SGPIOM1 ],0x1000 ); -aspeed_mmio_map_unimplemented (s->memory,SYS_BUS_DEVICE (&s->jtag[0 ]),"aspeed.jtag0" , sc->memmap[ASPEED_DEV_JTAG0 ],0x100 );
@@ -269,6 +273,7 @@ static void aspeed_soc_ast1040_class_init(ObjectClass *klass, const void *data) sc->sram_size[0 ] =128 * KiB; sc->sram_size[1 ] =16 * MiB;/* Hyper RAM */ sc->uarts_num =13 ; + sc->sgpio_num =2 ; sc->uarts_base =ASPEED_DEV_UART0 ; sc->irqmap = aspeed_soc_ast1040_irqmap; sc->memmap = aspeed_soc_ast1040_memmap;
Signature · 1 line
2.43.0
PATCH v2 9/10 hw/arm/aspeed_ast1040_evb: Introduce onboard I2C device
In reply to Jamin LinIntroduce onboard I2C device initialization for the AST1040 EVB model.
This change adds the initial onboard I2C device setup flow and instantiates a 24C08 SMBus EEPROM device connected to I2C bus 0, matching the current AST1040 EVB hardware design.
--- hw/arm/aspeed_ast1040_evb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
hw/arm/aspeed_ast1040_evb.c +18 -0
@@ -14,6 +14,7 @@#include "hw/arm/aspeed_soc.h" #include "hw/core/qdev-clock.h" #include "system/system.h" +#include "hw/i2c/smbus_eeprom.h" #define AST1040_INTERNAL_FLASH_SIZE (4 * MiB)/* Main SYSCLK frequency in Hz (400MHz) */
@@ -38,12 +39,28 @@ static void aspeed_bic_machine_init(MachineState *machine)aspeed_connect_serial_hds_to_uarts (bmc);qdev_realize (DEVICE (bmc->soc),NULL , &error_abort); +if (amc->i2c_init) { + amc->i2c_init (bmc); + } +armv7m_load_kernel (ARM_CPU (first_cpu), machine->kernel_filename,0 ,AST1040_INTERNAL_FLASH_SIZE ); } +static void ast1040_evb_i2c_init (AspeedMachineState *bmc) +{ +AspeedSoCState *soc = bmc->soc; + +/* U10 24C08 connects to SDA/SCL Group 1 by default */ +uint8_t *eeprom_buf =g_malloc0 (32 * KiB); +smbus_eeprom_init_one (aspeed_i2c_get_bus (&soc->i2c,0 ),0x50 , eeprom_buf); + +/* U11 LM75 connects to SDA/SCL Group 2 by default */ +i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,1 ),"tmp105" ,0x4d ); +} +static void aspeed_machine_ast1040_evb_class_init (ObjectClass *oc,const void *data) {
@@ -55,6 +72,7 @@ static void aspeed_machine_ast1040_evb_class_init(ObjectClass *oc, amc->hw_strap1 =0 ; amc->hw_strap2 =0 ; mc->init = aspeed_bic_machine_init; + amc->i2c_init = ast1040_evb_i2c_init; mc->default_ram_size =0 ; amc->macs_mask =0 ; amc->uart_default =ASPEED_DEV_UART12 ;
Signature · 1 line
2.43.0
v2 cover hw/arm/aspeed: Add AST1040 peripheral support
This series extends the AST1040 SoC model by adding support for several peripherals that are compatible with existing AST2700 controller models.
The AST1040 shares a number of peripheral IP blocks with the AST2700, allowing the existing QEMU models to be reused with minimal changes. This series adds support for ADC, PECI, GPIO, SGPIO, I2C, and watchdog controllers, and updates the AST1040 EVB machine to instantiate onboard I2C devices for validation.
For I2C support, a new AST1040 I2C type is introduced. The model inherits the AST2700 I2C architecture, including DMA support and 64-bit DMA address registers, while constraining DMA accesses to the 16 MiB HyperRAM address space available on AST1040.
Depends on:
https://github.com/legoater/qemu.git (branch: aspeed-next)
v1:
1. Support ADC, GPIO, SGPIO, I2C and PECI
v2:
1. Address review feedback.
2. Fix issues reported during review.
Jamin Lin (10):
hw/i2c/aspeed_i2c: Introduce dma_addr_lo_mask to unify DMA address
handling
hw/i2c/aspeed_i2c: Increase AST2700 buffer mode size and adjust offset hw/arm/aspeed_ast1040: Reuse AST2700 ADC model hw/arm/aspeed_ast1040: Introduce PECI support hw/arm/aspeed_ast1040: Reuse AST2700 GPIO controller model hw/arm/aspeed_ast1040: Add SGPIO controller support hw/i2c/aspeed_i2c: Introduce AST1040 I2C model hw/arm/aspeed_ast1040: Introduce I2C support hw/arm/aspeed_ast1040_evb: Introduce onboard I2C device hw/arm/aspeed_ast1040: Reuse AST2700 watchdog models
include/hw/i2c/aspeed_i2c.h | 8 ++- hw/arm/aspeed_ast1040.c | 97 +++++++++++++++++++++++++++++----- hw/arm/aspeed_ast1040_evb.c | 18 +++++++ hw/i2c/aspeed_i2c.c | 101 ++++++++++++++++++++++++------------ 4 files changed, 175 insertions(+), 49 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 2/10 hw/i2c/aspeed_i2c: Increase AST2700 buffer mode size and adjust offset
Update the AST2700 I2C buffer mode configuration to match the latest firmware definition:
- Increase buffer mode pool size from 0x20 to 0x40
- Adjust buffer mode base offset to 0x1c0
Since the buffer mode region size changes, the migration state layout is also modified. Bump the VMState version numbers to prevent incompatible migration between old and new machine states.
--- include/hw/i2c/aspeed_i2c.h | 2 +- hw/i2c/aspeed_i2c.c | 46 ++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-)
include/hw/i2c/aspeed_i2c.h +1 -1
@@ -35,7 +35,7 @@ OBJECT_DECLARE_TYPE(AspeedI2CState, AspeedI2CClass, ASPEED_I2C)#define ASPEED_I2C_NR_BUSSES 16#define ASPEED_I2C_SHARE_POOL_SIZE 0x800 -#define ASPEED_I2C_BUS_POOL_SIZE 0x20 +#define ASPEED_I2C_BUS_POOL_SIZE 0x40#define ASPEED_I2C_NEW_NUM_REG (0xa0 >> 2)#define A_I2CD_M_STOP_CMD BIT(5)
hw/i2c/aspeed_i2c.c +23 -23
85 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 8/10 hw/arm/aspeed_ast1040: Introduce I2C support
In reply to Jamin LinIntroduce I2C controller support for the AST1040 SoC model.
The I2C model type is selected from the SoC type name, allowing the AST1040 SoC to use the corresponding aspeed.i2c-ast1040 model.
The I2C controller is mapped at 0x74C0F000 and uses IRQs 64 - 77, with one IRQ assigned per I2C bus.
The controller DRAM link is connected to SRAM1 (HyperRAM) for DMA support.
--- hw/arm/aspeed_ast1040.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
hw/arm/aspeed_ast1040.c +16 -0
@@ -117,6 +117,7 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"sgpio[*]" , &s->sgpiom[i],"aspeed.sgpio-ast2700" ); } +object_initialize_child (obj,"i2c" , &s->i2c,TYPE_ASPEED_1040_I2C );object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );
@@ -233,6 +234,21 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp) aspeed_soc_ast1040_get_irq(s, ASPEED_DEV_SGPIOM0 + i)); } +/* I2C */ +object_property_set_link (OBJECT (&s->i2c),"dram" ,OBJECT (&s->sram[1 ]), + &error_abort); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->i2c), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->i2c),0 , + sc->memmap[ASPEED_DEV_I2C ]); +for (i =0 ; i <ASPEED_I2C_GET_CLASS (&s->i2c)->num_busses; i++) { +qemu_irq irq =qdev_get_gpio_in (DEVICE (&a->armv7m), + sc->irqmap[ASPEED_DEV_I2C ] + i); +/* The AST1040 I2C controller has one IRQ per bus. */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c.busses[i]),0 , irq); + } +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
Signature · 1 line
2.43.0
PATCH v2 10/10 hw/arm/aspeed_ast1040: Reuse AST2700 watchdog models
In reply to Jamin LinInstantiate and realize the watchdog models for the AST1040 SoC.
The AST1040 watchdog controller is compatible with the AST2700 watchdog controller, so reuse the existing AST2700 watchdog model.
Configure the AST1040 SoC with 8 watchdog instances and map them to their corresponding MMIO regions. The first watchdog controller (WDT0) is located at 0x74c37000, with subsequent watchdogs placed according to the controller register space size.
Each watchdog is linked to the SCU device before realization to provide the required reset and system control interactions.
--- hw/arm/aspeed_ast1040.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
hw/arm/aspeed_ast1040.c +19 -0
@@ -119,6 +119,11 @@ static void aspeed_soc_ast1040_init(Object *obj) }object_initialize_child (obj,"i2c" , &s->i2c,TYPE_ASPEED_1040_I2C ); +for (i =0 ; i < sc->wdts_num; i++) { +object_initialize_child (obj,"wdt[*]" , &s->wdt[i], +"aspeed.wdt-ast2700" ); + } +object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"udc" , &s->udc,TYPE_UNIMPLEMENTED_DEVICE );
@@ -249,6 +254,19 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c.busses[i]),0 , irq); } +/* Watch dog */ +for (i =0 ; i < sc->wdts_num; i++) { +AspeedWDTClass *awc =ASPEED_WDT_GET_CLASS (&s->wdt[i]); +hwaddr wdt_offset = sc->memmap[ASPEED_DEV_WDT ] + i * awc->iosize; + +object_property_set_link (OBJECT (&s->wdt[i]),"scu" ,OBJECT (&s->scu), + &error_abort); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->wdt[i]), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->wdt[i]),0 , wdt_offset); + } +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
@@ -290,6 +308,7 @@ static void aspeed_soc_ast1040_class_init(ObjectClass *klass, const void *data) sc->sram_size[1 ] =16 * MiB;/* Hyper RAM */ sc->uarts_num =13 ; sc->sgpio_num =2 ; + sc->wdts_num =8 ; sc->uarts_base =ASPEED_DEV_UART0 ; sc->irqmap = aspeed_soc_ast1040_irqmap; sc->memmap = aspeed_soc_ast1040_memmap;
Signature · 1 line
2.43.0
PATCH v2 4/10 hw/arm/aspeed_ast1040: Introduce PECI support
In reply to Jamin LinIntroduce PECI support for the AST1040 SoC model.
This change adds the PECI MMIO region and IRQ mapping, initializes the PECI device instance, and realizes the controller during SoC initialization.
The PECI controller is mapped at 0x74C1F000 and connected to IRQ 164.
--- hw/arm/aspeed_ast1040.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
hw/arm/aspeed_ast1040.c +12 -0
@@ -31,6 +31,7 @@ static const hwaddr aspeed_soc_ast1040_memmap[] = { [ASPEED_DEV_SGPIOM0] = 0x74C0C000, [ASPEED_DEV_SGPIOM1] = 0x74C0D000, [ASPEED_DEV_I2C] = 0x74C0F000, + [ASPEED_DEV_PECI] = 0x74C1F000, [ASPEED_DEV_I3C] = 0x74C20000, [ASPEED_DEV_UART0] = 0x74C33000, [ASPEED_DEV_UART1] = 0x74C33100,
@@ -76,6 +77,7 @@ static const int aspeed_soc_ast1040_irqmap[] = { [ASPEED_DEV_UART11] = 146, [ASPEED_DEV_UART12] = 147, [ASPEED_DEV_JTAG0] = 162, + [ASPEED_DEV_PECI] = 164, };static qemu_irq aspeed_soc_ast1040_get_irq (AspeedSoCState *s,int dev)
@@ -108,6 +110,7 @@ static void aspeed_soc_ast1040_init(Object *obj) }object_initialize_child (obj,"adc" , &s->adc,TYPE_ASPEED_2700_ADC ); +object_initialize_child (obj,"peci" , &s->peci,TYPE_ASPEED_PECI );object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );
@@ -199,6 +202,15 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->adc),0 ,aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_ADC )); +/* PECI */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->peci), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->peci),0 , + sc->memmap[ASPEED_DEV_PECI ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->peci),0 , +aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_PECI )); +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
Signature · 1 line
2.43.0
PATCH v2 7/10 hw/i2c/aspeed_i2c: Introduce AST1040 I2C model
In reply to Jamin LinIntroduce the AST1040 I2C controller model.
The AST1040 I2C controller is compatible with the AST2700 I2C controller, including DMA support and the 64-bit DMA address registers. Set has_dma64 so firmware can access the high address register and program it to zero, as the CM4 CPU only supports 32-bit addressing.
Since AST1040 has 16MB HyperRAM, limit the DMA low address mask to 0x00ffffff.
--- include/hw/i2c/aspeed_i2c.h | 1 + hw/i2c/aspeed_i2c.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
include/hw/i2c/aspeed_i2c.h +1 -0
@@ -30,6 +30,7 @@#define TYPE_ASPEED_2500_I2C TYPE_ASPEED_I2C "-ast2500"#define TYPE_ASPEED_2600_I2C TYPE_ASPEED_I2C "-ast2600"#define TYPE_ASPEED_1030_I2C TYPE_ASPEED_I2C "-ast1030" +#define TYPE_ASPEED_1040_I2C TYPE_ASPEED_I2C "-ast1040"#define TYPE_ASPEED_2700_I2C TYPE_ASPEED_I2C "-ast2700"OBJECT_DECLARE_TYPE (AspeedI2CState, AspeedI2CClass,ASPEED_I2C )
hw/i2c/aspeed_i2c.c +33 -0
@@ -1654,6 +1654,34 @@ static void aspeed_1030_i2c_class_init(ObjectClass *klass, const void *data) aic->dma_addr_lo_mask =0x7fffffff ; } +static void aspeed_1040_i2c_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +AspeedI2CClass *aic =ASPEED_I2C_CLASS (klass); + + dc->desc ="ASPEED 1040 I2C Controller" ; + +/* +* AST1040 reuses the AST2700 I2C controller implementation since +* the AST1040 is compatible with AST2700. The only difference +* is that AST1040 HyperRAM is limited to 16 MiB, so the DMA low +* address mask is restricted accordingly. +*/ + aic->num_busses =16 ; + aic->reg_size =0xa0 ; + aic->reg_gap_size =0x60 ; + aic->gap =-1 ;/* no gap */ + aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq; + aic->pool_size =0x40 ; + aic->pool_gap_size =0xc0 ; + aic->pool_base =0x1c0 ; + aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; + aic->has_dma = true; + aic->mem_size =0x2000 ; + aic->has_dma64 = true; + aic->dma_addr_lo_mask =0x00ffffff ; +} +static void aspeed_2700_i2c_class_init (ObjectClass *klass,const void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -1703,6 +1731,11 @@ static const TypeInfo aspeed_i2c_types[] = { .parent = TYPE_ASPEED_I2C, .class_init = aspeed_1030_i2c_class_init, }, + { + .name = TYPE_ASPEED_1040_I2C, + .parent = TYPE_ASPEED_I2C, + .class_init = aspeed_1040_i2c_class_init, + }, { .name = TYPE_ASPEED_2400_I2C, .parent = TYPE_ASPEED_I2C,
Signature · 1 line
2.43.0
PATCH v2 1/10 hw/i2c/aspeed_i2c: Introduce dma_addr_lo_mask to unify DMA address handling
In reply to Jamin LinThe Aspeed I2C controller has two register layouts.
The AST2500 uses the old mode with a single DMA address register (I2CD_DMA_ADDR) where the address is 4-byte aligned and masked to 0x3ffffffc.
From AST2600 onwards, the new mode provides separate master TX/RX and slave RX DMA address registers (I2CM_DMA_TX_ADDR, I2CM_DMA_RX_ADDR, I2CS_DMA_RX_ADDR) with different address widths per SoC:
AST2600 (new mode): 0x7fffffff - bits[30:0] AST1030 (new mode): 0x7fffffff - bits[30:0] AST1060 (new mode): 0x7fffffff - bits[30:0] AST2700 (new mode): 0xffffffff - bits[31:0]
Introduce dma_addr_lo_mask as a per-class attribute and apply it uniformly when storing DMA address register writes and when loading the address into dma_dram_offset for both master and slave paths. This replaces the previous FIELD_EX32 extractions (which incorrectly stripped bit 31 on AST2700) and the hardcoded 0x3ffffffc literal in the old-mode path.
--- include/hw/i2c/aspeed_i2c.h | 5 +---- hw/i2c/aspeed_i2c.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-)
include/hw/i2c/aspeed_i2c.h +1 -4
@@ -209,13 +209,9 @@ REG32(I2CS_DMA_LEN, 0x2c) FIELD(I2CS_DMA_LEN, TX_BUF_LEN_W1T, 15, 1) FIELD(I2CS_DMA_LEN, TX_BUF_LEN, 0, 11) REG32(I2CM_DMA_TX_ADDR, 0x30) - FIELD(I2CM_DMA_TX_ADDR, ADDR, 0, 31) REG32(I2CM_DMA_RX_ADDR, 0x34) - FIELD(I2CM_DMA_RX_ADDR, ADDR, 0, 31) REG32(I2CS_DMA_TX_ADDR, 0x38) - FIELD(I2CS_DMA_TX_ADDR, ADDR, 0, 31) REG32(I2CS_DMA_RX_ADDR, 0x3c) - FIELD(I2CS_DMA_RX_ADDR, ADDR, 0, 31) REG32(I2CS_DEV_ADDR, 0x40) REG32(I2CM_DMA_LEN_STS, 0x48)FIELD (I2CM_DMA_LEN_STS ,RX_LEN ,16 ,13 )
@@ -303,6 +299,7 @@ struct AspeedI2CClass {bool has_share_pool;uint64_t mem_size;bool has_dma64; +uint32_t dma_addr_lo_mask; };static inline bool aspeed_i2c_is_new_mode (AspeedI2CState *s)
hw/i2c/aspeed_i2c.c +13 -9
@@ -236,7 +236,7 @@ static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus) value = bus->regs[R_I2CM_DMA_TX_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , -FIELD_EX32 (value,I2CM_DMA_TX_ADDR ,ADDR )); + value & aic->dma_addr_lo_mask);if (aic->has_dma64) { value = bus->regs[R_I2CM_DMA_TX_ADDR_HI ]; bus->dma_dram_offset =
@@ -246,7 +246,7 @@ static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus) }else { value = bus->regs[R_I2CD_DMA_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , - value &0x3ffffffc ); + value & aic->dma_addr_lo_mask); } }
@@ -261,7 +261,7 @@ static void aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus) value = bus->regs[R_I2CM_DMA_RX_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , -FIELD_EX32 (value,I2CM_DMA_RX_ADDR ,ADDR )); + value & aic->dma_addr_lo_mask);if (aic->has_dma64) { value = bus->regs[R_I2CM_DMA_RX_ADDR_HI ]; bus->dma_dram_offset =
@@ -271,7 +271,7 @@ static void aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus) }else { value = bus->regs[R_I2CD_DMA_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , - value &0x3ffffffc ); + value & aic->dma_addr_lo_mask); } }
@@ -735,12 +735,10 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,aspeed_i2c_bus_raise_interrupt (bus);break ;case A_I2CM_DMA_TX_ADDR : - bus->regs[R_I2CM_DMA_TX_ADDR ] =FIELD_EX32 (value,I2CM_DMA_TX_ADDR , -ADDR ); + bus->regs[R_I2CM_DMA_TX_ADDR ] = value & aic->dma_addr_lo_mask;break ;case A_I2CM_DMA_RX_ADDR : - bus->regs[R_I2CM_DMA_RX_ADDR ] =FIELD_EX32 (value,I2CM_DMA_RX_ADDR , -ADDR ); + bus->regs[R_I2CM_DMA_RX_ADDR ] = value & aic->dma_addr_lo_mask;break ;case A_I2CM_DMA_LEN : w1t = FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN_W1T) ||
@@ -1375,6 +1373,8 @@ static void aspeed_i2c_class_init(ObjectClass *klass, const void *data)static int aspeed_i2c_bus_new_slave_event (AspeedI2CBus *bus,enum i2c_event event) { +AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); +switch (event) {case I2C_START_SEND_ASYNC :if (!SHARED_ARRAY_FIELD_EX32 (bus->regs,R_I2CS_CMD ,RX_DMA_EN )) {
@@ -1385,7 +1385,7 @@ static int aspeed_i2c_bus_new_slave_event(AspeedI2CBus *bus,ARRAY_FIELD_DP32 (bus->regs,I2CS_DMA_LEN_STS ,RX_LEN ,0 ); bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , -ARRAY_FIELD_EX32 (bus->regs,I2CS_DMA_RX_ADDR ,ADDR )); + bus->regs[R_I2CS_DMA_RX_ADDR ] & aic->dma_addr_lo_mask); bus->regs[R_I2CC_DMA_LEN ] =ARRAY_FIELD_EX32 (bus->regs,I2CS_DMA_LEN ,RX_BUF_LEN ) +1 ;i2c_ack (bus->bus);
@@ -1608,6 +1608,7 @@ static void aspeed_2500_i2c_class_init(ObjectClass *klass, const void *data) aic->check_sram = true; aic->has_dma = true; aic->mem_size =0x1000 ; + aic->dma_addr_lo_mask =0x3ffffffc ; }static qemu_irq aspeed_2600_i2c_bus_get_irq (AspeedI2CBus *bus)
@@ -1631,6 +1632,7 @@ static void aspeed_2600_i2c_class_init(ObjectClass *klass, const void *data) aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size =0x1000 ; + aic->dma_addr_lo_mask =0x7fffffff ; }static void aspeed_1030_i2c_class_init (ObjectClass *klass,const void *data)
@@ -1649,6 +1651,7 @@ static void aspeed_1030_i2c_class_init(ObjectClass *klass, const void *data) aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size =0x10000 ; + aic->dma_addr_lo_mask =0x7fffffff ; }static void aspeed_2700_i2c_class_init (ObjectClass *klass,const void *data)
@@ -1670,6 +1673,7 @@ static void aspeed_2700_i2c_class_init(ObjectClass *klass, const void *data) aic->has_dma = true; aic->mem_size =0x2000 ; aic->has_dma64 = true; + aic->dma_addr_lo_mask =0xffffffff ; }static const TypeInfo aspeed_i2c_types[] = {
Signature · 1 line
2.43.0
PATCH v2 3/10 hw/arm/aspeed_ast1040: Reuse AST2700 ADC model
In reply to Jamin LinInstead of introducing a dedicated TYPE_ASPEED_1040_ADC model, initialize the existing AST2700 ADC device directly for AST1040. This avoids unnecessary duplication and keeps the codebase simpler and easier to maintain.
Add ADC device initialization and realization support to the AST1040 SoC model using TYPE_ASPEED_2700_ADC.
--- hw/arm/aspeed_ast1040.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
hw/arm/aspeed_ast1040.c +11 -0
@@ -107,6 +107,8 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"uart[*]" , &s->uart[i],TYPE_SERIAL_MM ); } +object_initialize_child (obj,"adc" , &s->adc,TYPE_ASPEED_2700_ADC ); +object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"udc" , &s->udc,TYPE_UNIMPLEMENTED_DEVICE );
@@ -188,6 +190,15 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp) aspeed_soc_ast1040_get_irq(s, uart)); } +/* ADC */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->adc), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->adc),0 , + sc->memmap[ASPEED_DEV_ADC ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->adc),0 , +aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_ADC )); +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
Signature · 1 line
2.43.0
PATCH v2 5/10 hw/arm/aspeed_ast1040: Reuse AST2700 GPIO controller model
In reply to Jamin LinThe AST1040 GPIO controller is compatible with the AST2700 GPIO controller implementation.
Reuse the existing "aspeed.gpio-ast2700" device model for AST1040 instead of introducing a separate implementation.
Add the GPIO device initialization, MMIO mapping, and IRQ wiring for the AST1040 SoC model.
--- hw/arm/aspeed_ast1040.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/arm/aspeed_ast1040.c +10 -0
@@ -111,6 +111,7 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"adc" , &s->adc,TYPE_ASPEED_2700_ADC );object_initialize_child (obj,"peci" , &s->peci,TYPE_ASPEED_PECI ); +object_initialize_child (obj,"gpio" , &s->gpio,"aspeed.gpio-ast2700" );object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );
@@ -211,6 +212,15 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)sysbus_connect_irq (SYS_BUS_DEVICE (&s->peci),0 ,aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_PECI )); +/* GPIO */ +if (!sysbus_realize (SYS_BUS_DEVICE (&s->gpio), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->gpio),0 , + sc->memmap[ASPEED_DEV_GPIO ]); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->gpio),0 , +aspeed_soc_ast1040_get_irq (s,ASPEED_DEV_GPIO )); +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
Signature · 1 line
2.43.0
Re: [PATCH v2 01/10] hw/i2c/aspeed_i2c: Introduce dma_addr_lo_mask to unify DMA address handling
In reply to Jamin LinQuoted 20 lines · Jamin Lin
The Aspeed I2C controller has two register layouts.
The AST2500 uses the old mode with a single DMA address register (
I2CD_DMA_ADDR) where the address is 4-byte aligned and masked to0x3ffffffc.From AST2600 onwards, the new mode provides separate master TX/RX and slave RX DMA
address registers (I2CM_DMA_TX_ADDR,I2CM_DMA_RX_ADDR,I2CS_DMA_RX_ADDR) with different address widths per SoC:AST2600 (new mode): 0x7fffffff - bits[30:0] AST1030 (new mode): 0x7fffffff - bits[30:0] AST1060 (new mode): 0x7fffffff - bits[30:0] AST2700 (new mode): 0xffffffff - bits[31:0]Introduce
dma_addr_lo_maskas a per-class attribute and apply it uniformly when storing DMA address register writes and when loading the address intodma_dram_offsetfor both master and slave paths. This replaces the previousFIELD_EX32extractions (which incorrectly stripped bit 31 on AST2700) and the hardcoded0x3ffffffcliteral in the old-mode path.
Quoted 6 lines
Fixes 1809ab6a67359e0876981cd05d2a50b2843eabad ("hw/i2c/aspeed: Add AST2700 support")Signed-off-by Jamin Lin <[email protected]>--- include/hw/i2c/aspeed_i2c.h | 5 +---- hw/i2c/aspeed_i2c.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-)
aspeed_i2c_bus_new_write() still has :
case A_I2CS_DMA_RX_ADDR:
bus->regs[R_I2CS_DMA_RX_ADDR] = value;Is that ok ?
Thanks,
C.
Quoted 132 lines
include/hw/i2c/aspeed_i2c.h +1
-4@@ -209,13 +209,9 @@ REG32(I2CS_DMA_LEN, 0x2c) FIELD(I2CS_DMA_LEN, TX_BUF_LEN_W1T, 15, 1) FIELD(I2CS_DMA_LEN, TX_BUF_LEN, 0, 11) REG32(I2CM_DMA_TX_ADDR, 0x30) - FIELD(I2CM_DMA_TX_ADDR, ADDR, 0, 31) REG32(I2CM_DMA_RX_ADDR, 0x34) - FIELD(I2CM_DMA_RX_ADDR, ADDR, 0, 31) REG32(I2CS_DMA_TX_ADDR, 0x38) - FIELD(I2CS_DMA_TX_ADDR, ADDR, 0, 31) REG32(I2CS_DMA_RX_ADDR, 0x3c) - FIELD(I2CS_DMA_RX_ADDR, ADDR, 0, 31) REG32(I2CS_DEV_ADDR, 0x40) REG32(I2CM_DMA_LEN_STS, 0x48)FIELD (I2CM_DMA_LEN_STS ,RX_LEN ,16 ,13 )@@ -303,6 +299,7 @@ struct AspeedI2CClass {bool has_share_pool;uint64_t mem_size;bool has_dma64; +uint32_t dma_addr_lo_mask; };static inline bool aspeed_i2c_is_new_mode (AspeedI2CState *s)hw/i2c/aspeed_i2c.c +13
-9@@ -236,7 +236,7 @@ static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus) value = bus->regs[R_I2CM_DMA_TX_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , -FIELD_EX32 (value,I2CM_DMA_TX_ADDR ,ADDR )); + value & aic->dma_addr_lo_mask);if (aic->has_dma64) { value = bus->regs[R_I2CM_DMA_TX_ADDR_HI ]; bus->dma_dram_offset =@@ -246,7 +246,7 @@ static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus) }else { value = bus->regs[R_I2CD_DMA_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , - value &0x3ffffffc ); + value & aic->dma_addr_lo_mask); } }@@ -261,7 +261,7 @@ static void aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus) value = bus->regs[R_I2CM_DMA_RX_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , -FIELD_EX32 (value,I2CM_DMA_RX_ADDR ,ADDR )); + value & aic->dma_addr_lo_mask);if (aic->has_dma64) { value = bus->regs[R_I2CM_DMA_RX_ADDR_HI ]; bus->dma_dram_offset =@@ -271,7 +271,7 @@ static void aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus) }else { value = bus->regs[R_I2CD_DMA_ADDR ]; bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , - value &0x3ffffffc ); + value & aic->dma_addr_lo_mask); } }@@ -735,12 +735,10 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,aspeed_i2c_bus_raise_interrupt (bus);break ;case A_I2CM_DMA_TX_ADDR : - bus->regs[R_I2CM_DMA_TX_ADDR ] =FIELD_EX32 (value,I2CM_DMA_TX_ADDR , -ADDR ); + bus->regs[R_I2CM_DMA_TX_ADDR ] = value & aic->dma_addr_lo_mask;break ;case A_I2CM_DMA_RX_ADDR : - bus->regs[R_I2CM_DMA_RX_ADDR ] =FIELD_EX32 (value,I2CM_DMA_RX_ADDR , -ADDR ); + bus->regs[R_I2CM_DMA_RX_ADDR ] = value & aic->dma_addr_lo_mask;break ;case A_I2CM_DMA_LEN : w1t = FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN_W1T) ||@@ -1375,6 +1373,8 @@ static void aspeed_i2c_class_init(ObjectClass *klass, const void *data)static int aspeed_i2c_bus_new_slave_event (AspeedI2CBus *bus,enum i2c_event event) { +AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); +switch (event) {case I2C_START_SEND_ASYNC :if (!SHARED_ARRAY_FIELD_EX32 (bus->regs,R_I2CS_CMD ,RX_DMA_EN )) {@@ -1385,7 +1385,7 @@ static int aspeed_i2c_bus_new_slave_event(AspeedI2CBus *bus,ARRAY_FIELD_DP32 (bus->regs,I2CS_DMA_LEN_STS ,RX_LEN ,0 ); bus->dma_dram_offset =deposit64 (bus->dma_dram_offset,0 ,32 , -ARRAY_FIELD_EX32 (bus->regs,I2CS_DMA_RX_ADDR ,ADDR )); + bus->regs[R_I2CS_DMA_RX_ADDR ] & aic->dma_addr_lo_mask); bus->regs[R_I2CC_DMA_LEN ] =ARRAY_FIELD_EX32 (bus->regs,I2CS_DMA_LEN ,RX_BUF_LEN ) +1 ;i2c_ack (bus->bus);@@ -1608,6 +1608,7 @@ static void aspeed_2500_i2c_class_init(ObjectClass *klass, const void *data) aic->check_sram = true; aic->has_dma = true; aic->mem_size =0x1000 ; + aic->dma_addr_lo_mask =0x3ffffffc ; }static qemu_irq aspeed_2600_i2c_bus_get_irq (AspeedI2CBus *bus)@@ -1631,6 +1632,7 @@ static void aspeed_2600_i2c_class_init(ObjectClass *klass, const void *data) aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size =0x1000 ; + aic->dma_addr_lo_mask =0x7fffffff ; }static void aspeed_1030_i2c_class_init (ObjectClass *klass,const void *data)@@ -1649,6 +1651,7 @@ static void aspeed_1030_i2c_class_init(ObjectClass *klass, const void *data) aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size =0x10000 ; + aic->dma_addr_lo_mask =0x7fffffff ; }static void aspeed_2700_i2c_class_init (ObjectClass *klass,const void *data)@@ -1670,6 +1673,7 @@ static void aspeed_2700_i2c_class_init(ObjectClass *klass, const void *data) aic->has_dma = true; aic->mem_size =0x2000 ; aic->has_dma64 = true; + aic->dma_addr_lo_mask =0xffffffff ; }static const TypeInfo aspeed_i2c_types[] = {
Re: [PATCH v2 02/10] hw/i2c/aspeed_i2c: Increase AST2700 buffer mode size and adjust offset
In reply to Jamin LinQuoted 34 lines · Jamin Lin
Update the AST2700 I2C buffer mode configuration to match the latest firmware definition:
- Increase buffer mode pool size from0x20to0x40
- Adjust buffer mode base offset to0x1c0Since the buffer mode region size changes, the migration state layout is also modified. Bump the VMState version numbers to prevent incompatible migration between old and new machine states.
Fixes 1809ab6a67359e0876981cd05d2a50b2843eabad ("hw/i2c/aspeed: Add AST2700 support")Signed-off-by Jamin Lin <[email protected]>--- include/hw/i2c/aspeed_i2c.h | 2 +- hw/i2c/aspeed_i2c.c | 46 ++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-)include/hw/i2c/aspeed_i2c.h +1
-1@@ -35,7 +35,7 @@ OBJECT_DECLARE_TYPE(AspeedI2CState, AspeedI2CClass, ASPEED_I2C)#define ASPEED_I2C_NR_BUSSES 16#define ASPEED_I2C_SHARE_POOL_SIZE 0x800 -#define ASPEED_I2C_BUS_POOL_SIZE 0x20 +#define ASPEED_I2C_BUS_POOL_SIZE 0x40#define ASPEED_I2C_NEW_NUM_REG (0xa0 >> 2)#define A_I2CD_M_STOP_CMD BIT(5)hw/i2c/aspeed_i2c.c +0
-0
hw/i2c/aspeed_i2c.c static const MemoryRegionOps aspeed_i2c_bus_pool_ops = { · line 1136
Quoted 7 lines
hw/i2c/aspeed_i2c.c +2
-2@@ -1132,8 +1132,8 @@ static const MemoryRegionOps aspeed_i2c_bus_pool_ops = {static const VMStateDescription aspeed_i2c_bus_vmstate = { .name =TYPE_ASPEED_I2C , - .version_id =7 , - .minimum_version_id =6 , + .version_id =8 , + .minimum_version_id =7 ,
I think min should be '8'. QEMU can not deserialise a v7 format of the pool array. It reads exactly ASPEED_I2C_BUS_POOL_SIZE bytes from the migration stream. But the size has changed.
Quoted 81 lines
hw/i2c/aspeed_i2c.c +21
-21.fields = (const VMStateField[]) {VMSTATE_UINT32_ARRAY (regs, AspeedI2CBus,ASPEED_I2C_NEW_NUM_REG ),VMSTATE_UINT32_V (pending_intr_sts, AspeedI2CBus,7 ),@@ -1145,8 +1145,8 @@ static const VMStateDescription aspeed_i2c_bus_vmstate = {static const VMStateDescription aspeed_i2c_vmstate = { .name =TYPE_ASPEED_I2C , - .version_id =3 , - .minimum_version_id =3 , + .version_id =4 , + .minimum_version_id =4 , .fields = (const VMStateField []) {VMSTATE_UINT32 (intr_status, AspeedI2CState), VMSTATE_STRUCT_ARRAY(busses, AspeedI2CState,@@ -1250,37 +1250,37 @@ static void aspeed_i2c_instance_init(Object *obj)* Address Definitions (AST2700) * 0x000 ... 0x0FF: Global Register * 0x100 ... 0x19F: Device 0 -* 0x1A0 ... 0x1BF: Device 0 buffer +* 0x1C0 ... 0x1FF: Device 0 buffer * 0x200 ... 0x29F: Device 1 -* 0x2A0 ... 0x2BF: Device 1 buffer +* 0x2C0 ... 0x2FF: Device 1 buffer * 0x300 ... 0x39F: Device 2 -* 0x3A0 ... 0x3BF: Device 2 buffer +* 0x3C0 ... 0x3FF: Device 2 buffer * 0x400 ... 0x49F: Device 3 -* 0x4A0 ... 0x4BF: Device 3 buffer +* 0x4C0 ... 0x4FF: Device 3 buffer * 0x500 ... 0x59F: Device 4 -* 0x5A0 ... 0x5BF: Device 4 buffer +* 0x5C0 ... 0x5FF: Device 4 buffer * 0x600 ... 0x69F: Device 5 -* 0x6A0 ... 0x6BF: Device 5 buffer +* 0x6C0 ... 0x6FF: Device 5 buffer * 0x700 ... 0x79F: Device 6 -* 0x7A0 ... 0x7BF: Device 6 buffer +* 0x7C0 ... 0x7FF: Device 6 buffer * 0x800 ... 0x89F: Device 7 -* 0x8A0 ... 0x8BF: Device 7 buffer +* 0x8C0 ... 0x8FF: Device 7 buffer * 0x900 ... 0x99F: Device 8 -* 0x9A0 ... 0x9BF: Device 8 buffer +* 0x9C0 ... 0x9FF: Device 8 buffer * 0xA00 ... 0xA9F: Device 9 -* 0xAA0 ... 0xABF: Device 9 buffer +* 0xAC0 ... 0xAFF: Device 9 buffer * 0xB00 ... 0xB9F: Device 10 -* 0xBA0 ... 0xBBF: Device 10 buffer +* 0xBC0 ... 0xBFF: Device 10 buffer * 0xC00 ... 0xC9F: Device 11 -* 0xCA0 ... 0xCBF: Device 11 buffer +* 0xCC0 ... 0xCFF: Device 11 buffer * 0xD00 ... 0xD9F: Device 12 -* 0xDA0 ... 0xDBF: Device 12 buffer +* 0xDC0 ... 0xDFF: Device 12 buffer * 0xE00 ... 0xE9F: Device 13 -* 0xEA0 ... 0xEBF: Device 13 buffer +* 0xEC0 ... 0xEFF: Device 13 buffer * 0xF00 ... 0xF9F: Device 14 -* 0xFA0 ... 0xFBF: Device 14 buffer +* 0xFC0 ... 0xFFF: Device 14 buffer * 0x1000 ... 0x109F: Device 15 -* 0x10A0 ... 0x10BF: Device 15 buffer +* 0x10C0 ... 0x10BF: Device 15 buffer */ static void aspeed_i2c_realize (DeviceState *dev,Error **errp) {@@ -1666,9 +1666,9 @@ static void aspeed_2700_i2c_class_init(ObjectClass *klass, const void *data) aic->reg_gap_size =0x60 ; aic->gap =-1 ;/* no gap */ aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq; - aic->pool_size =0x20 ; - aic->pool_gap_size =0xe0 ; - aic->pool_base =0x1a0 ; + aic->pool_size =0x40 ; + aic->pool_gap_size =0xc0 ; + aic->pool_base =0x1c0 ; aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size =0x2000 ;
Re: [PATCH v2 08/10] hw/arm/aspeed_ast1040: Introduce I2C support
In reply to Jamin LinQuoted 7 lines · Jamin Lin
Introduce I2C controller support for the AST1040 SoC model.
The I2C model type is selected from the SoC type name, allowing the AST1040 SoC to use the corresponding aspeed.i2c-ast1040 model.
The I2C controller is mapped at
0x74C0F000and uses IRQs 64 - 77, with one IRQ assigned per I2C bus.
64 - 79. The irqmap array needs a change too.
Quoted 43 lines
The controller DRAM link is connected to SRAM1 (HyperRAM) for DMA support.
Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast1040.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)hw/arm/aspeed_ast1040.c +16
-0@@ -117,6 +117,7 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"sgpio[*]" , &s->sgpiom[i],"aspeed.sgpio-ast2700" ); } +object_initialize_child (obj,"i2c" , &s->i2c,TYPE_ASPEED_1040_I2C );object_initialize_child (obj,"pwm" , &s->pwm,TYPE_UNIMPLEMENTED_DEVICE );object_initialize_child (obj,"espi" , &s->espi,TYPE_UNIMPLEMENTED_DEVICE );@@ -233,6 +234,21 @@ static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp) aspeed_soc_ast1040_get_irq(s, ASPEED_DEV_SGPIOM0 + i)); } +/* I2C */ +object_property_set_link (OBJECT (&s->i2c),"dram" ,OBJECT (&s->sram[1 ]), + &error_abort); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->i2c), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->i2c),0 , + sc->memmap[ASPEED_DEV_I2C ]); +for (i =0 ; i <ASPEED_I2C_GET_CLASS (&s->i2c)->num_busses; i++) { +qemu_irq irq =qdev_get_gpio_in (DEVICE (&a->armv7m), + sc->irqmap[ASPEED_DEV_I2C ] + i); +/* The AST1040 I2C controller has one IRQ per bus. */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c.busses[i]),0 , irq); + } +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory, SYS_BUS_DEVICE(&s->pwm), "aspeed.pwm",
Re: [PATCH v2 09/10] hw/arm/aspeed_ast1040_evb: Introduce onboard I2C device
In reply to Jamin LinQuoted 34 lines · Jamin Lin
Introduce onboard I2C device initialization for the AST1040 EVB model.
This change adds the initial onboard I2C device setup flow and instantiates a 24C08 SMBus EEPROM device connected to I2C bus 0, matching the current AST1040 EVB hardware design.
Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast1040_evb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)hw/arm/aspeed_ast1040_evb.c +5
-0@@ -14,6 +14,7 @@#include "hw/arm/aspeed_soc.h" #include "hw/core/qdev-clock.h" #include "system/system.h" +#include "hw/i2c/smbus_eeprom.h" #define AST1040_INTERNAL_FLASH_SIZE (4 * MiB)/* Main SYSCLK frequency in Hz (400MHz) */ @@ -38,12 +39,28 @@ static void aspeed_bic_machine_init(MachineState *machine)aspeed_connect_serial_hds_to_uarts (bmc);qdev_realize (DEVICE (bmc->soc),NULL , &error_abort); +if (amc->i2c_init) { + amc->i2c_init (bmc); + } + armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
hw/arm/aspeed_ast1040_evb.c static void aspeed_bic_machine_init(MachineState *machine) · line 57
Quoted 10 lines
hw/arm/aspeed_ast1040_evb.c +6
-00 , AST1040_INTERNAL_FLASH_SIZE); } +static void ast1040_evb_i2c_init (AspeedMachineState *bmc) +{ +AspeedSoCState *soc = bmc->soc; + +/* U10 24C08 connects to SDA/SCL Group 1 by default */ +uint8_t *eeprom_buf =g_malloc0 (32 * KiB);
The smbus-eeprom device's internal buffer is 256 bytes.
We have been copy/pasting this 32 * KiB size for a while it seems but SMBUS_EEPROM_SIZE would be enough.
Anyhow,
Thanks,
C.
Quoted 17 lines
hw/arm/aspeed_ast1040_evb.c +7
-0+smbus_eeprom_init_one (aspeed_i2c_get_bus (&soc->i2c,0 ),0x50 , eeprom_buf); + +/* U11 LM75 connects to SDA/SCL Group 2 by default */ +i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,1 ),"tmp105" ,0x4d ); +} +static void aspeed_machine_ast1040_evb_class_init (ObjectClass *oc,const void *data) {@@ -55,6 +72,7 @@ static void aspeed_machine_ast1040_evb_class_init(ObjectClass *oc, amc->hw_strap1 =0 ; amc->hw_strap2 =0 ; mc->init = aspeed_bic_machine_init; + amc->i2c_init = ast1040_evb_i2c_init; mc->default_ram_size =0 ; amc->macs_mask =0 ; amc->uart_default =ASPEED_DEV_UART12 ;
RE: [PATCH v2 02/10] hw/i2c/aspeed_i2c: Increase AST2700 buffer mode size and adjust offset
In reply to Cédric Le GoaterHi Cédric
Quoted 44 lines
Subject: Re: [PATCH v2 02/10] hw/i2c/aspeed_i2c: Increase AST2700 buffer mode size and adjust offset
Quoted 10 lines · Jamin Lin
Update the AST2700 I2C buffer mode configuration to match the latest firmware definition:
- Increase buffer mode pool size from0x20to0x40
- Adjust buffer mode base offset to0x1c0Since the buffer mode region size changes, the migration state layout is also modified. Bump the VMState version numbers to prevent incompatible migration between old and new machine states.
Fixes 1809ab6a67359e0876981cd05d2a50b2843eabad ("hw/i2c/aspeed:Add
include/hw/i2c/aspeed_i2c.h OBJECT_DECLARE_TYPE(AspeedI2CState,
Quoted 12 lines
AST2700 support")
Signed-off-by Jamin Lin <[email protected]>--- include/hw/i2c/aspeed_i2c.h | 2 +- hw/i2c/aspeed_i2c.c | 46 ++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 24 deletions(-)include/hw/i2c/aspeed_i2c.h +0
-0@@ -35,7 +35,7 @@ OBJECT_DECLARE_TYPE(AspeedI2CState,AspeedI2CClass,
Quoted 16 lines
include/hw/i2c/aspeed_i2c.h +0
-0ASPEED_I2C)#define ASPEED_I2C_NR_BUSSES 16#define ASPEED_I2C_SHARE_POOL_SIZE 0x800 -#define
ASPEED_I2C_BUS_POOL_SIZE0x20include/hw/i2c/aspeed_i2c.h +1
-0+#define ASPEED_I2C_BUS_POOL_SIZE 0x40#define ASPEED_I2C_NEW_NUM_REG (0xa0 >> 2)#define A_I2CD_M_STOP_CMD BIT(5)hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
a6b44174f5..595b5fcf5c100644hw/i2c/aspeed_i2c.c +0
-0@@ -1132,8 +1132,8 @@ static const MemoryRegionOps aspeed_i2c_bus_pool_ops = {
Quoted 12 lines
hw/i2c/aspeed_i2c.c static const MemoryRegionOps aspeed_i2c_bus_pool_ops = { · line 1136
Quoted 6 lines
hw/i2c/aspeed_i2c.c +2
-2static const VMStateDescription aspeed_i2c_bus_vmstate = { .name =TYPE_ASPEED_I2C , - .version_id =7 , - .minimum_version_id =6 , + .version_id =8 , + .minimum_version_id =7 ,I think min should be '8'. QEMU can not deserialise a v7 format of the pool array. It reads exactly
ASPEED_I2C_BUS_POOL_SIZEbytes from the migration stream. But the size has changed.
Thanks for the review and suggestion.
Will do.
Jamin
Quoted 86 lines
hw/i2c/aspeed_i2c.c static const MemoryRegionOps · line 1139
Quoted 3 lines
hw/i2c/aspeed_i2c.c +0
-0.fields = (const VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, AspeedI2CBus,
ASPEED_I2C_NEW_NUM_REG),hw/i2c/aspeed_i2c.c static const VMStateDescription aspeed_i2c_bus_vmstate = {
Quoted 13 lines
VMSTATE_UINT32_V(pending_intr_sts, AspeedI2CBus, 7), @@-1145,8 +1145,8 @@ static const VMStateDescription
aspeed_i2c_bus_vmstate= {static const VMStateDescription aspeed_i2c_vmstate = { .name = TYPE_ASPEED_I2C,hw/i2c/aspeed_i2c.c +2
-2- .version_id = 3, - .minimum_version_id = 3, + .version_id = 4, + .minimum_version_id = 4, .fields = (const VMStateField []) {VMSTATE_UINT32 (intr_status, AspeedI2CState), VMSTATE_STRUCT_ARRAY(busses, AspeedI2CState, @@-1250,37
hw/i2c/aspeed_i2c.c static void
Quoted 55 lines
+1250,37 @@ static void
aspeed_i2c_instance_init(Object *obj)
* Address Definitions (AST2700)
*0x000...0x0FF: Global Register
*0x100...0x19F: Device 0
- *0x1A0...0x1BF: Device 0 buffer
+ *0x1C0...0x1FF: Device 0 buffer
*0x200...0x29F: Device 1
- *0x2A0...0x2BF: Device 1 buffer
+ *0x2C0...0x2FF: Device 1 buffer
*0x300...0x39F: Device 2
- *0x3A0...0x3BF: Device 2 buffer
+ *0x3C0...0x3FF: Device 2 buffer
*0x400...0x49F: Device 3
- *0x4A0...0x4BF: Device 3 buffer
+ *0x4C0...0x4FF: Device 3 buffer
*0x500...0x59F: Device 4
- *0x5A0...0x5BF: Device 4 buffer
+ *0x5C0...0x5FF: Device 4 buffer
*0x600...0x69F: Device 5
- *0x6A0...0x6BF: Device 5 buffer
+ *0x6C0...0x6FF: Device 5 buffer
*0x700...0x79F: Device 6
- *0x7A0...0x7BF: Device 6 buffer
+ *0x7C0...0x7FF: Device 6 buffer
*0x800...0x89F: Device 7
- *0x8A0...0x8BF: Device 7 buffer
+ *0x8C0...0x8FF: Device 7 buffer
*0x900...0x99F: Device 8
- *0x9A0...0x9BF: Device 8 buffer
+ *0x9C0...0x9FF: Device 8 buffer
*0xA00...0xA9F: Device 9
- *0xAA0...0xABF: Device 9 buffer
+ *0xAC0...0xAFF: Device 9 buffer
*0xB00...0xB9F: Device 10
- *0xBA0...0xBBF: Device 10 buffer
+ *0xBC0...0xBFF: Device 10 buffer
*0xC00...0xC9F: Device 11
- *0xCA0...0xCBF: Device 11 buffer
+ *0xCC0...0xCFF: Device 11 buffer
*0xD00...0xD9F: Device 12
- *0xDA0...0xDBF: Device 12 buffer
+ *0xDC0...0xDFF: Device 12 buffer
*0xE00...0xE9F: Device 13
- *0xEA0...0xEBF: Device 13 buffer
+ *0xEC0...0xEFF: Device 13 buffer
*0xF00...0xF9F: Device 14
- *0xFA0...0xFBF: Device 14 buffer
+ *0xFC0...0xFFF: Device 14 buffer
*0x1000...0x109F: Device 15
- *0x10A0...0x10BF: Device 15 buffer
+ *0x10C0...0x10BF: Device 15 buffer
*/
static voidaspeed_i2c_realize(DeviceState *dev, Error **errp){hw/i2c/aspeed_i2c.c +0
-0@@ -1666,9 +1666,9 @@ static void
aspeed_2700_i2c_class_init(ObjectClass *klass, const void *data)Quoted 12 lines
hw/i2c/aspeed_i2c.c +3
-3aic->reg_gap_size =0x60 ; aic->gap =-1 ;/* no gap */ aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq; - aic->pool_size =0x20 ; - aic->pool_gap_size =0xe0 ; - aic->pool_base =0x1a0 ; + aic->pool_size =0x40 ; + aic->pool_gap_size =0xc0 ; + aic->pool_base =0x1c0 ; aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size =0x2000 ;
RE: [PATCH v2 08/10] hw/arm/aspeed_ast1040: Introduce I2C support
In reply to Cédric Le GoaterHi Cédric,
Quoted 5 lines
Subject: Re: [PATCH v2 08/10] hw/arm/aspeed_ast1040: Introduce I2C support
Quoted 2 lines · Jamin Lin
Introduce I2C controller support for the AST1040 SoC model.
Quoted 8 lines
Quoted 5 lines
The I2C model type is selected from the SoC type name, allowing the AST1040 SoC to use the corresponding aspeed.i2c-ast1040 model.
The I2C controller is mapped at
0x74C0F000and uses IRQs 64 - 77, with one IRQ assigned per I2C bus.64 - 79. The irqmap array needs a change too.
Sorry, that's my mistake.
After checking the AST1040 datasheet, I confirmed that the AST1040 I2C controller supports 14 buses. Therefore, the IRQ range should indeed be 64 - 77, with one IRQ assigned to each bus.
I'll update the patch accordingly and set the I2C bus count to 14 (devices 0 - 13).
https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/
Thanks for catching this.
Jamin
Quoted 50 lines
Quoted 14 lines
The controller DRAM link is connected to SRAM1 (HyperRAM) for DMA support.
Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast1040.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)hw/arm/aspeed_ast1040.c index renamed from hw/arm/aspeed_ast1040.c +0
-0
77211ce1f3..6d1cb9b102100644hw/arm/aspeed_ast1040.c static void aspeed_soc_ast1040_init(Object *obj) · line 123
Quoted 7 lines
hw/arm/aspeed_ast1040.c +2
-0@@ -117,6 +117,7 @@ static void aspeed_soc_ast1040_init(Object *obj)object_initialize_child (obj,"sgpio[*]" , &s->sgpiom[i],"aspeed.sgpio-ast2700" ); } +object_initialize_child (obj,"i2c" , &s->i2c, +TYPE_ASPEED_1040_I2C ); object_initialize_child(obj, "pwm", &s->pwm,
TYPE_UNIMPLEMENTED_DEVICE);Quoted 2 lines
object_initialize_child(obj, "espi", &s->espi,
TYPE_UNIMPLEMENTED_DEVICE); @@ -233,6 +234,21 @@ static void
aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)Quoted 1 line
aspeed_soc_ast1040_get_irq(s,
ASPEED_DEV_SGPIOM0+ i));hw/arm/aspeed_ast1040.c
Quoted 4 lines
}hw/arm/aspeed_ast1040.c +2
-0+/* I2C */ + object_property_set_link(OBJECT(&s->i2c), "dram",
OBJECT(&s->sram[1]),hw/arm/aspeed_ast1040.c static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp) · line 251
Quoted 9 lines
hw/arm/aspeed_ast1040.c +9
-0+ &error_abort); +if (!sysbus_realize (SYS_BUS_DEVICE (&s->i2c), errp)) { +return ; + } +aspeed_mmio_map (s->memory,SYS_BUS_DEVICE (&s->i2c),0 , + sc->memmap[ASPEED_DEV_I2C ]); +for (i =0 ; i <ASPEED_I2C_GET_CLASS (&s->i2c)->num_busses; i++) { + qemu_irq irq = qdev_get_gpio_in(DEVICE(&a->armv7m), +sc->irqmap[ASPEED_DEV_I2C] + i);
hw/arm/aspeed_ast1040.c static void aspeed_soc_ast1040_realize(DeviceState *dev_soc, Error **errp)
Quoted 6 lines
hw/arm/aspeed_ast1040.c +4
-0+/* The AST1040 I2C controller has one IRQ per bus. */ +sysbus_connect_irq (SYS_BUS_DEVICE (&s->i2c.busses[i]),0 , irq); + } +/* Unimplemented peripherals */ aspeed_mmio_map_unimplemented(s->memory,
SYS_BUS_DEVICE(&s->pwm),Quoted 1 line
"aspeed.pwm",
RE: [PATCH v2 09/10] hw/arm/aspeed_ast1040_evb: Introduce onboard I2C device
In reply to Cédric Le GoaterHi Cédric
Quoted 41 lines
Subject: Re: [PATCH v2 09/10] hw/arm/aspeed_ast1040_evb: Introduce onboard I2C device
Quoted 37 lines · Jamin Lin
Introduce onboard I2C device initialization for the AST1040 EVB model.
This change adds the initial onboard I2C device setup flow and instantiates a 24C08 SMBus EEPROM device connected to I2C bus 0, matching the current AST1040 EVB hardware design.
Signed-off-by Jamin Lin <[email protected]>--- hw/arm/aspeed_ast1040_evb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)hw/arm/aspeed_ast1040_evb.c +1
-0@@ -14,6 +14,7 @@#include "hw/arm/aspeed_soc.h" #include "hw/core/qdev-clock.h" #include "system/system.h" +#include "hw/i2c/smbus_eeprom.h" #define AST1040_INTERNAL_FLASH_SIZE (4 * MiB) /* Main SYSCLK frequency in Hz (400MHz) */ @@ -38,12 +39,28 @@static void
aspeed_bic_machine_init(MachineState *machine)aspeed_connect_serial_hds_to_uarts(bmc); qdev_realize(DEVICE(bmc->soc), NULL, &error_abort);hw/arm/aspeed_ast1040_evb.c +4
-0+if (amc->i2c_init) { + amc->i2c_init (bmc); + } +armv7m_load_kernel (ARM_CPU (first_cpu), machine->kernel_filename,0 ,AST1040_INTERNAL_FLASH_SIZE ); }
Quoted 6 lines
hw/arm/aspeed_ast1040_evb.c static void aspeed_bic_machine_init(MachineState *machine) · line 57
Quoted 5 lines
hw/arm/aspeed_ast1040_evb.c +5
-0+static void ast1040_evb_i2c_init (AspeedMachineState *bmc) { +AspeedSoCState *soc = bmc->soc; + +/* U10 24C08 connects to SDA/SCL Group 1 by default */ +uint8_t *eeprom_buf =g_malloc0 (32 * KiB);
I will change it to 256 in v3.
If you would prefer to use SMBUS_EEPROM_SIZE, I can handle that in a separate cleanup patch series:
Move #define SMBUS_EEPROM_SIZE 256 to include/hw/i2c/smbus_eeprom.h.
Update the ASPEED machine models to use SMBUS_EEPROM_SIZE instead of hard-coded EEPROM buffer sizes.
I also noticed that several ASPEED machine models currently use inconsistent EEPROM sizes:
hw/arm/aspeed_ast1040_evb.c: SMBUS_EEPROM_SIZE hw/arm/aspeed_ast2500_supermicro-x11spi.c: 32 * 1024 hw/arm/aspeed_ast2400_supermicrox11.c: 32 * 1024 hw/arm/aspeed_ast2500_evb.c: 8 * 1024 hw/arm/aspeed_ast10x0_evb.c: 32 * 1024 hw/arm/aspeed_ast2600_evb.c: 8 * 1024 hw/arm/aspeed_ast2400_palmetto.c: 32 * 1024
hw/arm/aspeed_ast2500_witherspoon.c: 8 * 1024
Do you mean that we should update all of these ASPEED machine models to use:
uint8_t *eeprom_buf = g_malloc0(SMBUS_EEPROM_SIZE);
instead of the current hard-coded sizes?
Thanks,
Jamin
Quoted 37 lines
The smbus-eeprom device's internal buffer is 256 bytes.
We have been copy/pasting this 32 * KiB size for a while it seems but
SMBUS_EEPROM_SIZEwould be enough.Anyhow,
Reviewed-by Cédric Le Goater <[email protected]>Thanks,
C.
hw/arm/aspeed_ast1040_evb.c
Quoted 9 lines
hw/arm/aspeed_ast1040_evb.c +7
-0+smbus_eeprom_init_one (aspeed_i2c_get_bus (&soc->i2c,0 ),0x50 , + eeprom_buf); + +/* U11 LM75 connects to SDA/SCL Group 2 by default */ +i2c_slave_create_simple (aspeed_i2c_get_bus (&soc->i2c,1 ), +"tmp105" ,0x4d ); } +static void aspeed_machine_ast1040_evb_class_init (ObjectClass *oc, const void*data)
hw/arm/aspeed_ast1040_evb.c static void
Quoted 2 lines
{hw/arm/aspeed_ast1040_evb.c +0
-0@@ -55,6 +72,7 @@ static voidaspeed_machine_ast1040_evb_class_init(ObjectClass *oc,
Quoted 7 lines
hw/arm/aspeed_ast1040_evb.c +1
-0amc->hw_strap1 =0 ; amc->hw_strap2 =0 ; mc->init = aspeed_bic_machine_init; + amc->i2c_init = ast1040_evb_i2c_init; mc->default_ram_size =0 ; amc->macs_mask =0 ; amc->uart_default =ASPEED_DEV_UART12 ;
RE: [PATCH v2 01/10] hw/i2c/aspeed_i2c: Introduce dma_addr_lo_mask to unify DMA address handling
In reply to Cédric Le GoaterHi Cédric
Quoted 36 lines
Subject: Re: [PATCH v2 01/10] hw/i2c/aspeed_i2c: Introduce
dma_addr_lo_maskto unify DMA address handlingQuoted 4 lines · Jamin Lin
The Aspeed I2C controller has two register layouts.
The AST2500 uses the old mode with a single DMA address register (
I2CD_DMA_ADDR) where the address is 4-byte aligned and masked to
0x3ffffffc.Quoted 2 lines
From AST2600 onwards, the new mode provides separate master TX/RX
and
Quoted 1 line
slave RX DMA address registers (
I2CM_DMA_TX_ADDR,
I2CM_DMA_RX_ADDR,Quoted 6 lines
I2CS_DMA_RX_ADDR) with different address widths per SoC:AST2600 (new mode): 0x7fffffff - bits[30:0] AST1030 (new mode): 0x7fffffff - bits[30:0] AST1060 (new mode): 0x7fffffff - bits[30:0] AST2700 (new mode): 0xffffffff - bits[31:0]Quoted 8 lines
Introduce
dma_addr_lo_maskas a per-class attribute and apply it uniformly when storing DMA address register writes and when loading the address intodma_dram_offsetfor both master and slave paths. This replaces the previousFIELD_EX32extractions (which incorrectly stripped bit 31 on AST2700) and the hardcoded0x3ffffffcliteral in the old-mode path.Fixes 1809ab6a67359e0876981cd05d2a50b2843eabad ("hw/i2c/aspeed:Add
Quoted 6 lines
AST2700 support")
Signed-off-by Jamin Lin <[email protected]>--- include/hw/i2c/aspeed_i2c.h | 5 +---- hw/i2c/aspeed_i2c.c | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-)
Quoted 7 lines
aspeed_i2c_bus_new_write()still has :case A_I2CS_DMA_RX_ADDR: bus->regs[R_I2CS_DMA_RX_ADDR] = value;Is that ok ?
Thanks for the review and suggestion.
Will add.
Jamin
Quoted 164 lines
Thanks,
C.
hw/i2c/aspeed_i2c.c static void
Quoted 32 lines
include/hw/i2c/aspeed_i2c.h +0
-4@@ -209,13 +209,9 @@ REG32(I2CS_DMA_LEN, 0x2c) FIELD(I2CS_DMA_LEN, TX_BUF_LEN_W1T, 15, 1) FIELD(I2CS_DMA_LEN, TX_BUF_LEN, 0, 11) REG32(I2CM_DMA_TX_ADDR, 0x30) - FIELD(I2CM_DMA_TX_ADDR, ADDR, 0, 31) REG32(I2CM_DMA_RX_ADDR, 0x34) - FIELD(I2CM_DMA_RX_ADDR, ADDR, 0, 31) REG32(I2CS_DMA_TX_ADDR, 0x38) - FIELD(I2CS_DMA_TX_ADDR, ADDR, 0, 31) REG32(I2CS_DMA_RX_ADDR, 0x3c) - FIELD(I2CS_DMA_RX_ADDR, ADDR, 0, 31) REG32(I2CS_DEV_ADDR, 0x40) REG32(I2CM_DMA_LEN_STS, 0x48) FIELD(I2CM_DMA_LEN_STS, RX_LEN, 16, 13) @@ -303,6 +299,7 @@struct AspeedI2CClass { bool has_share_pool; uint64_t mem_size; bool has_dma64;+
uint32_tdma_addr_lo_mask;
};static inline bool
aspeed_i2c_is_new_mode(AspeedI2CState *s)diff
--gita/hw/i2c/aspeed_i2c.cb/hw/i2c/aspeed_i2c.cindex4a6732a185..a6b44174f5100644hw/i2c/aspeed_i2c.c +0
-0@@ -236,7 +236,7 @@ static void
aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus)hw/i2c/aspeed_i2c.c static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus)
Quoted 4 lines
hw/i2c/aspeed_i2c.c +0
-1value = bus->regs[R_I2CM_DMA_TX_ADDR ]; bus->dma_dram_offset = deposit64(bus->dma_dram_offset, 0, 32, - FIELD_EX32(value, I2CM_DMA_TX_ADDR,ADDR));
hw/i2c/aspeed_i2c.c static void
Quoted 5 lines
hw/i2c/aspeed_i2c.c +1
-0+ value & aic->dma_addr_lo_mask);if (aic->has_dma64) { value = bus->regs[R_I2CM_DMA_TX_ADDR_HI ]; bus->dma_dram_offset =@@ -246,7 +246,7 @@ static void
aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus)hw/i2c/aspeed_i2c.c static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus)
Quoted 3 lines
hw/i2c/aspeed_i2c.c +0
-0}else { value = bus->regs[R_I2CD_DMA_ADDR ]; bus->dma_dram_offset = deposit64(bus->dma_dram_offset, 0,32,
hw/i2c/aspeed_i2c.c static void
Quoted 7 lines
hw/i2c/aspeed_i2c.c +2
-1- value & 0x3ffffffc); + value & + aic->dma_addr_lo_mask); } }@@ -261,7 +261,7 @@ static void
aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus)hw/i2c/aspeed_i2c.c static void aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus)
Quoted 4 lines
hw/i2c/aspeed_i2c.c +0
-1value = bus->regs[R_I2CM_DMA_RX_ADDR ]; bus->dma_dram_offset = deposit64(bus->dma_dram_offset, 0, 32, - FIELD_EX32(value, I2CM_DMA_RX_ADDR,ADDR));
hw/i2c/aspeed_i2c.c static void
Quoted 5 lines
hw/i2c/aspeed_i2c.c +1
-0+ value & aic->dma_addr_lo_mask);if (aic->has_dma64) { value = bus->regs[R_I2CM_DMA_RX_ADDR_HI ]; bus->dma_dram_offset =@@ -271,7 +271,7 @@ static void
aspeed_i2c_set_rx_dma_dram_offset(AspeedI2CBus *bus)hw/i2c/aspeed_i2c.c static void aspeed_i2c_set_tx_dma_dram_offset(AspeedI2CBus *bus)
Quoted 3 lines
hw/i2c/aspeed_i2c.c +0
-0}else { value = bus->regs[R_I2CD_DMA_ADDR ]; bus->dma_dram_offset = deposit64(bus->dma_dram_offset, 0,32,
hw/i2c/aspeed_i2c.c static void
Quoted 7 lines
hw/i2c/aspeed_i2c.c +2
-1- value & 0x3ffffffc); + value & + aic->dma_addr_lo_mask); } }@@ -735,12 +735,10 @@ static voidaspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
Quoted 4 lines
hw/i2c/aspeed_i2c.c +0
-1aspeed_i2c_bus_raise_interrupt (bus);break ;case A_I2CM_DMA_TX_ADDR : - bus->regs[R_I2CM_DMA_TX_ADDR] = FIELD_EX32(value,
I2CM_DMA_TX_ADDR,hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
Quoted 6 lines
hw/i2c/aspeed_i2c.c +2
-2- ADDR); + bus->regs[R_I2CM_DMA_TX_ADDR ] = value & + aic->dma_addr_lo_mask;break ;case A_I2CM_DMA_RX_ADDR : - bus->regs[R_I2CM_DMA_RX_ADDR] = FIELD_EX32(value,
I2CM_DMA_RX_ADDR,hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
Quoted 6 lines
hw/i2c/aspeed_i2c.c +2
-1- ADDR); + bus->regs[R_I2CM_DMA_RX_ADDR ] = value & + aic->dma_addr_lo_mask;break ;case A_I2CM_DMA_LEN : w1t =FIELD_EX32 (value,I2CM_DMA_LEN ,RX_BUF_LEN_W1T )|| @@
Quoted 1 line
-1375,6 +1373,8 @@ static void aspeed_i2c_class_init(ObjectClass *klass,
const void *data)
Quoted 2 lines
static int aspeed_i2c_bus_new_slave_event(AspeedI2CBus *bus,
enumi2c_eventevent)
Quoted 7 lines
{hw/i2c/aspeed_i2c.c +2
-0+AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); + switch (event) { case I2C_START_SEND_ASYNC: if (!SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CS_CMD,
RX_DMA_EN)) { @@ -1385,7 +1385,7 @@ static intaspeed_i2c_bus_new_slave_event(AspeedI2CBus *bus,
Quoted 1 line
ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN,0);
Quoted 3 lines
bus->dma_dram_offset = deposit64(bus->dma_dram_offset, 0, 32,- ARRAY_FIELD_EX32(bus->regs,
I2CS_DMA_RX_ADDR, ADDR));Quoted 4 lines
+ bus->regs[R_I2CS_DMA_RX_ADDR] &
+ aic->dma_addr_lo_mask); bus->regs[R_I2CC_DMA_LEN] = ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_LEN,
RX_BUF_LEN) + 1;hw/i2c/aspeed_i2c.c static void
Quoted 2 lines
i2c_ack(bus->bus);hw/i2c/aspeed_i2c.c +0
-0@@ -1608,6 +1608,7 @@ static void
aspeed_2500_i2c_class_init(ObjectClass *klass, const void *data)hw/i2c/aspeed_i2c.c static void aspeed_2500_i2c_class_init(ObjectClass *klass, const void *data)
Quoted 8 lines
hw/i2c/aspeed_i2c.c +1
-1aic->check_sram = true; aic->has_dma = true; aic->mem_size =0x1000 ; + aic->dma_addr_lo_mask =0x3ffffffc ; } static qemu_irq aspeed_2600_i2c_bus_get_irq(AspeedI2CBus *bus) @@ -1631,6 +1632,7 @@ static void aspeed_2600_i2c_class_init(ObjectClass*klass, const void *data)
Quoted 8 lines
aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size = 0x1000;+
aic->dma_addr_lo_mask=0x7fffffff;
}static void aspeed_1030_i2c_class_init(ObjectClass *klass, const
void *data) @@ -1649,6 +1651,7 @@ static void
aspeed_1030_i2c_class_init(ObjectClass *klass, const void *data)Quoted 8 lines
aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; aic->has_dma = true; aic->mem_size = 0x10000;+
aic->dma_addr_lo_mask=0x7fffffff;
}static void aspeed_2700_i2c_class_init(ObjectClass *klass, const
void *data) @@ -1670,6 +1673,7 @@ static void
aspeed_2700_i2c_class_init(ObjectClass *klass, const void *data)Quoted 7 lines
aic->has_dma = true; aic->mem_size = 0x2000; aic->has_dma64 = true;+
aic->dma_addr_lo_mask=0xffffffff;
}static const TypeInfo aspeed_i2c_types[] = {