aspeed/i2c: Add support for pool and DMA transfer modes
cover aspeed/i2c: Add support for pool and DMA transfer modes
Hello,
The Aspeed I2C controller can operate in three different transfer modes :
- Byte Buffer mode, using a dedicated register to transfer a byte. This is what the model supports today.
- Pool Buffer mode, using an internal SRAM to transfer multiple bytes in the same command sequence.
- DMA mode, supporting transfers up to 4K to and from DRAM.
This series adds support for the pool and DMA transfer modes taking into account the specificities of each SoC.
Last patch adds some traces which proved to be useful to debug the I2C state machine.
Thanks,
C.
Cédric Le Goater (5):
aspeed/i2c: Add support for pool buffer transfers aspeed/i2c: Check SRAM enablement on A2500
aspeed: Add a DRAM memory region at the SoC level aspeed/i2c: Add support for DMA transfers aspeed/i2c: Add trace events
include/hw/arm/aspeed_soc.h | 1 + include/hw/i2c/aspeed_i2c.h | 16 ++ hw/arm/aspeed_ast2600.c | 12 +- hw/arm/aspeed_soc.c | 14 +- hw/i2c/aspeed_i2c.c | 439 +++++++++++++++++++++++++++++++++--- hw/i2c/trace-events | 9 + 6 files changed, 459 insertions(+), 32 deletions(-)
Signature · 1 line
2.21.0
PATCH 1/5 aspeed/i2c: Add support for pool buffer transfers
The Aspeed I2C controller can operate in different transfer modes :
- Byte Buffer mode, using a dedicated register to transfer a byte. This is what the model supports today.
- Pool Buffer mode, using an internal SRAM to transfer multiple bytes in the same command sequence.
Each SoC has different SRAM characteristics. On the AST2400, 2048 bytes of SRAM are available at offset 0x800 of the controller AHB window. The pool buffer can be configured from 1 to 256 bytes per bus.
On the AST2500, the SRAM is at offset 0x200 and the pool buffer is of 16 bytes per bus.
On the AST2600, the SRAM is at offset 0xC00 and the pool buffer is of 32 bytes per bus. It can be splitted in two for TX and RX but the current model does not add support for it as it it unused by known drivers.
--- include/hw/i2c/aspeed_i2c.h | 8 ++ hw/i2c/aspeed_i2c.c | 197 ++++++++++++++++++++++++++++++++---- 2 files changed, 186 insertions(+), 19 deletions(-)
include/hw/i2c/aspeed_i2c.h +8 -0
@@ -32,6 +32,7 @@ OBJECT_CHECK(AspeedI2CState, (obj), TYPE_ASPEED_I2C)#define ASPEED_I2C_NR_BUSSES 16 +#define ASPEED_I2C_MAX_POOL_SIZE 0x800struct AspeedI2CState ;
@@ -50,6 +51,7 @@ typedef struct AspeedI2CBus {uint32_t intr_status;uint32_t cmd;uint32_t buf; +uint32_t pool_ctrl; } AspeedI2CBus; typedef struct AspeedI2CState {
@@ -59,6 +61,8 @@ typedef struct AspeedI2CState {qemu_irq irq;uint32_t intr_status; +MemoryRegion pool_iomem; +uint8_t pool[ASPEED_I2C_MAX_POOL_SIZE ];AspeedI2CBus busses[ASPEED_I2C_NR_BUSSES ]; } AspeedI2CState;
@@ -75,6 +79,10 @@ typedef struct AspeedI2CClass {uint8_t reg_size;uint8_t gap;qemu_irq (*bus_get_irq)(AspeedI2CBus *); + +uint64_t pool_size; +hwaddr pool_base; +uint8_t *(*bus_pool_base)(AspeedI2CBus *); } AspeedI2CClass;I2CBus *aspeed_i2c_get_bus (DeviceState *dev,int busnr);
hw/i2c/aspeed_i2c.c +178 -19
338 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 1/5] aspeed/i2c: Add support for pool buffer transfers
Quoted 16 lines · Cédric Le Goater
The Aspeed I2C controller can operate in different transfer modes :
- Byte Buffer mode, using a dedicated register to transfer a byte. This is what the model supports today.
- Pool Buffer mode, using an internal SRAM to transfer multiple bytes in the same command sequence.
Each SoC has different SRAM characteristics. On the AST2400, 2048 bytes of SRAM are available at offset
0x800of the controller AHB window. The pool buffer can be configured from 1 to 256 bytes per bus.On the AST2500, the SRAM is at offset
0x200and the pool buffer is of 16 bytes per bus.
Quoted 6 lines
On the AST2600, the SRAM is at offset
0xC00and the pool buffer is of 32 bytes per bus. It can be splitted in two for TX and RX but the current model does not add support for it as it it unused by known drivers.Signed-off-by Cédric Le Goater <[email protected]>
Re: [PATCH 1/5] aspeed/i2c: Add support for pool buffer transfers
In reply to Cédric Le GoaterQuoted 15 lines · Cédric Le Goater
The Aspeed I2C controller can operate in different transfer modes :
- Byte Buffer mode, using a dedicated register to transfer a byte. This is what the model supports today.
- Pool Buffer mode, using an internal SRAM to transfer multiple bytes in the same command sequence.
Each SoC has different SRAM characteristics. On the AST2400, 2048 bytes of SRAM are available at offset
0x800of the controller AHB window. The pool buffer can be configured from 1 to 256 bytes per bus.On the AST2500, the SRAM is at offset
0x200and the pool buffer is of 16 bytes per bus.
Quoted 6 lines
On the AST2600, the SRAM is at offset
0xC00and the pool buffer is of 32 bytes per bus. It can be splitted in two for TX and RX but the current model does not add support for it as it it unused by known drivers.Signed-off-by Cédric Le Goater <[email protected]>
PATCH 2/5 aspeed/i2c: Check SRAM enablement on A2500
In reply to Cédric Le GoaterThe SRAM must be enabled before using the Buffer Pool mode or the DMA mode. This is not required on other SoCs.
--- include/hw/i2c/aspeed_i2c.h | 3 +++ hw/i2c/aspeed_i2c.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
include/hw/i2c/aspeed_i2c.h +3 -0
@@ -61,6 +61,7 @@ typedef struct AspeedI2CState {qemu_irq irq;uint32_t intr_status; +uint32_t ctrl_global;MemoryRegion pool_iomem;uint8_t pool[ASPEED_I2C_MAX_POOL_SIZE ];
@@ -83,6 +84,8 @@ typedef struct AspeedI2CClass {uint64_t pool_size;hwaddr pool_base;uint8_t *(*bus_pool_base)(AspeedI2CBus *); +bool check_sram; + } AspeedI2CClass;I2CBus *aspeed_i2c_get_bus (DeviceState *dev,int busnr);
hw/i2c/aspeed_i2c.c +37 -0
@@ -31,6 +31,8 @@#define I2C_CTRL_STATUS 0x00/* Device Interrupt Status */ #define I2C_CTRL_ASSIGN 0x08/* Device Interrupt Target Assignment */ +#define I2C_CTRL_GLOBAL 0x0C/* Global Control Register */ +#define I2C_CTRL_SRAM_EN BIT(0)/* I2C Device (Bus) Register */
@@ -271,6 +273,29 @@ static uint8_t aspeed_i2c_get_addr(AspeedI2CBus *bus) } } +static bool aspeed_i2c_check_sram (AspeedI2CBus *bus) +{ +AspeedI2CState *s = bus->controller; +AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (s); + +if (!aic->check_sram) { +return true; + } + +/* +* AST2500: SRAM must be enabled before using the Buffer Pool or +* DMA mode. +*/ +if (!(s->ctrl_global &I2C_CTRL_SRAM_EN ) && + (bus->cmd & (I2CD_RX_DMA_ENABLE |I2CD_TX_DMA_ENABLE | +I2CD_RX_BUFF_ENABLE |I2CD_TX_BUFF_ENABLE ))) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: SRAM is not enabled\n" , __func__); +return false; + } + +return true; +} +/* * The state machine needs some refinement. It is only used to track * invalid STOP commands for the moment.
@@ -282,6 +307,10 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) bus->cmd &= ~0xFFFF ; bus->cmd |= value &0xFFFF ; +if (!aspeed_i2c_check_sram (bus)) { +return ; + } +if (bus->cmd &I2CD_M_START_CMD ) {uint8_t state =aspeed_i2c_get_state (bus) &I2CD_MACTIVE ?I2CD_MSTARTR :I2CD_MSTART ;
@@ -436,6 +465,8 @@ static uint64_t aspeed_i2c_ctrl_read(void *opaque, hwaddr offset,switch (offset) {case I2C_CTRL_STATUS :return s->intr_status; +case I2C_CTRL_GLOBAL : +return s->ctrl_global;default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, offset);
@@ -448,7 +479,12 @@ static uint64_t aspeed_i2c_ctrl_read(void *opaque, hwaddr offset,static void aspeed_i2c_ctrl_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) { +AspeedI2CState *s = opaque; +switch (offset) { +case I2C_CTRL_GLOBAL : + s->ctrl_global = value; +break ;case I2C_CTRL_STATUS :default : qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
@@ -684,6 +720,7 @@ static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data) aic->pool_size =0x100 ; aic->pool_base =0x200 ; aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base; + aic->check_sram = true; }static const TypeInfo aspeed_2500_i2c_info = {
Signature · 1 line
2.21.0
Re: [PATCH 2/5] aspeed/i2c: Check SRAM enablement on A2500
Quoted 5 lines · Cédric Le Goater
The SRAM must be enabled before using the Buffer Pool mode or the DMA mode. This is not required on other SoCs.
Signed-off-by Cédric Le Goater <[email protected]>
Re: [PATCH 2/5] aspeed/i2c: Check SRAM enablement on A2500
In reply to Cédric Le GoaterQuoted 4 lines · Cédric Le Goater
The SRAM must be enabled before using the Buffer Pool mode or the DMA mode. This is not required on other SoCs.
Signed-off-by Cédric Le Goater <[email protected]>
PATCH 3/5 aspeed: Add a DRAM memory region at the SoC level
In reply to Cédric Le GoaterCurrently, we link the DRAM memory region to the FMC model (for DMAs) through a property alias at the SoC level. The I2C model will need a similar region for DMA support, add a DRAM region property at the SoC level for both model to use.
--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast2600.c | 7 +++++-- hw/arm/aspeed_soc.c | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-)
include/hw/arm/aspeed_soc.h +1 -0
@@ -40,6 +40,7 @@ typedef struct AspeedSoCState {ARMCPU cpu[ASPEED_CPUS_NUM ];uint32_t num_cpus;A15MPPrivState a7mpcore; +MemoryRegion *dram_mr;MemoryRegion sram;AspeedVICState vic;AspeedRtcState rtc;
hw/arm/aspeed_ast2600.c +5 -2
@@ -158,8 +158,6 @@ static void aspeed_soc_ast2600_init(Object *obj) typename);object_property_add_alias (obj,"num-cs" ,OBJECT (&s->fmc),"num-cs" , &error_abort); -object_property_add_alias (obj,"dram" ,OBJECT (&s->fmc),"dram" , - &error_abort);for (i =0 ; i < sc->spis_num; i++) {snprintf (typename,sizeof (typename),"aspeed.spi%d-%s" , i +1 , socname);
@@ -362,6 +360,11 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) }/* FMC, The number of CS is set at the board level */ +object_property_set_link (OBJECT (&s->fmc),OBJECT (s->dram_mr),"dram" , &err); +if (err) { +error_propagate (errp, err); +return ; + }object_property_set_int (OBJECT (&s->fmc), sc->memmap[ASPEED_SDRAM ],"sdram-base" , &err);if (err) {
hw/arm/aspeed_soc.c +7 -2
@@ -175,8 +175,6 @@ static void aspeed_soc_init(Object *obj) typename);object_property_add_alias (obj,"num-cs" ,OBJECT (&s->fmc),"num-cs" , &error_abort); -object_property_add_alias (obj,"dram" ,OBJECT (&s->fmc),"dram" , - &error_abort);for (i =0 ; i < sc->spis_num; i++) {snprintf (typename,sizeof (typename),"aspeed.spi%d-%s" , i +1 , socname);
@@ -323,6 +321,11 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) aspeed_soc_get_irq(s, ASPEED_I2C));/* FMC, The number of CS is set at the board level */ +object_property_set_link (OBJECT (&s->fmc),OBJECT (s->dram_mr),"dram" , &err); +if (err) { +error_propagate (errp, err); +return ; + }object_property_set_int (OBJECT (&s->fmc), sc->memmap[ASPEED_SDRAM ],"sdram-base" , &err);if (err) {
@@ -429,6 +432,8 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) }static Property aspeed_soc_properties[] = {DEFINE_PROP_UINT32 ("num-cpus" , AspeedSoCState, num_cpus,0 ), +DEFINE_PROP_LINK ("dram" , AspeedSoCState, dram_mr,TYPE_MEMORY_REGION , + MemoryRegion *),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
2.21.0
Re: [PATCH 3/5] aspeed: Add a DRAM memory region at the SoC level
Quoted 7 lines · Cédric Le Goater
Currently, we link the DRAM memory region to the FMC model (for DMAs) through a property alias at the SoC level. The I2C model will need a similar region for DMA support, add a DRAM region property at the SoC level for both model to use.
Signed-off-by Cédric Le Goater <[email protected]>
Re: [PATCH 3/5] aspeed: Add a DRAM memory region at the SoC level
In reply to Cédric Le GoaterQuoted 6 lines · Cédric Le Goater
Currently, we link the DRAM memory region to the FMC model (for DMAs) through a property alias at the SoC level. The I2C model will need a similar region for DMA support, add a DRAM region property at the SoC level for both model to use.
Signed-off-by Cédric Le Goater <[email protected]>
Re: [PATCH 3/5] aspeed: Add a DRAM memory region at the SoC level
In reply to Cédric Le GoaterQuoted 76 lines · Cédric Le Goater
Currently, we link the DRAM memory region to the FMC model (for DMAs) through a property alias at the SoC level. The I2C model will need a similar region for DMA support, add a DRAM region property at the SoC level for both model to use.
Signed-off-by Cédric Le Goater <[email protected]>--- include/hw/arm/aspeed_soc.h | 1 + hw/arm/aspeed_ast2600.c | 7 +++++-- hw/arm/aspeed_soc.c | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-)include/hw/arm/aspeed_soc.h +1
-0@@ -40,6 +40,7 @@ typedef struct AspeedSoCState {ARMCPU cpu[ASPEED_CPUS_NUM ];uint32_t num_cpus;A15MPPrivState a7mpcore; +MemoryRegion *dram_mr;MemoryRegion sram;AspeedVICState vic;AspeedRtcState rtc;hw/arm/aspeed_ast2600.c +5
-2@@ -158,8 +158,6 @@ static void aspeed_soc_ast2600_init(Object *obj) typename);object_property_add_alias (obj,"num-cs" ,OBJECT (&s->fmc),"num-cs" , &error_abort); -object_property_add_alias (obj,"dram" ,OBJECT (&s->fmc),"dram" , - &error_abort);for (i =0 ; i < sc->spis_num; i++) {snprintf (typename,sizeof (typename),"aspeed.spi%d-%s" , i +1 , socname);@@ -362,6 +360,11 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) }/* FMC, The number of CS is set at the board level */ +object_property_set_link (OBJECT (&s->fmc),OBJECT (s->dram_mr),"dram" , &err); +if (err) { +error_propagate (errp, err); +return ; + }object_property_set_int (OBJECT (&s->fmc), sc->memmap[ASPEED_SDRAM ],"sdram-base" , &err);if (err) {hw/arm/aspeed_soc.c +5
-2@@ -175,8 +175,6 @@ static void aspeed_soc_init(Object *obj) typename);object_property_add_alias (obj,"num-cs" ,OBJECT (&s->fmc),"num-cs" , &error_abort); -object_property_add_alias (obj,"dram" ,OBJECT (&s->fmc),"dram" , - &error_abort);for (i =0 ; i < sc->spis_num; i++) {snprintf (typename,sizeof (typename),"aspeed.spi%d-%s" , i +1 , socname);@@ -323,6 +321,11 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) aspeed_soc_get_irq(s, ASPEED_I2C));/* FMC, The number of CS is set at the board level */ +object_property_set_link (OBJECT (&s->fmc),OBJECT (s->dram_mr),"dram" , &err); +if (err) { +error_propagate (errp, err); +return ; + }object_property_set_int (OBJECT (&s->fmc), sc->memmap[ASPEED_SDRAM ],"sdram-base" , &err);if (err) {
hw/arm/aspeed_soc.c static void aspeed_soc_realize(DeviceState *dev, Error **errp) · line 439
Quoted 8 lines
hw/arm/aspeed_soc.c +2
-0@@ -429,6 +432,8 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) }static Property aspeed_soc_properties[] = {DEFINE_PROP_UINT32 ("num-cpus" , AspeedSoCState, num_cpus,0 ), +DEFINE_PROP_LINK ("dram" , AspeedSoCState, dram_mr,TYPE_MEMORY_REGION , + MemoryRegion *),DEFINE_PROP_END_OF_LIST (), };
PATCH 4/5 aspeed/i2c: Add support for DMA transfers
In reply to Cédric Le GoaterThe I2C controller of the Aspeed AST2500 and AST2600 SoCs supports DMA transfers to and from DRAM.
A pair of registers defines the buffer address and the length of the DMA transfer. The address should be aligned on 4 bytes and the maximum length should not exceed 4K. The receive or transmit DMA transfer can then be initiated with specific bits in the Command/Status register of the controller.
--- include/hw/i2c/aspeed_i2c.h | 5 ++ hw/arm/aspeed_ast2600.c | 5 ++ hw/arm/aspeed_soc.c | 5 ++ hw/i2c/aspeed_i2c.c | 126 +++++++++++++++++++++++++++++++++++- 4 files changed, 138 insertions(+), 3 deletions(-)
include/hw/i2c/aspeed_i2c.h +5 -0
@@ -52,6 +52,8 @@ typedef struct AspeedI2CBus {uint32_t cmd;uint32_t buf;uint32_t pool_ctrl; +uint32_t dma_addr; +uint32_t dma_len; } AspeedI2CBus; typedef struct AspeedI2CState {
@@ -66,6 +68,8 @@ typedef struct AspeedI2CState {uint8_t pool[ASPEED_I2C_MAX_POOL_SIZE ];AspeedI2CBus busses[ASPEED_I2C_NR_BUSSES ]; +MemoryRegion *dram_mr; +AddressSpace dram_as; } AspeedI2CState;#define ASPEED_I2C_CLASS (klass) \
@@ -85,6 +89,7 @@ typedef struct AspeedI2CClass {hwaddr pool_base;uint8_t *(*bus_pool_base)(AspeedI2CBus *);bool check_sram; +bool has_dma; } AspeedI2CClass;
hw/arm/aspeed_ast2600.c +5 -0
@@ -343,6 +343,11 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) }/* I2C */ +object_property_set_link (OBJECT (&s->i2c),OBJECT (s->dram_mr),"dram" , &err); +if (err) { +error_propagate (errp, err); +return ; + }object_property_set_bool (OBJECT (&s->i2c), true,"realized" , &err);if (err) {error_propagate (errp, err);
hw/arm/aspeed_soc.c +5 -0
@@ -311,6 +311,11 @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) }/* I2C */ +object_property_set_link (OBJECT (&s->i2c),OBJECT (s->dram_mr),"dram" , &err); +if (err) { +error_propagate (errp, err); +return ; + }object_property_set_bool (OBJECT (&s->i2c), true,"realized" , &err);if (err) {error_propagate (errp, err);
hw/i2c/aspeed_i2c.c +123 -3
235 lines not on this page · raw message
Signature · 1 line
2.21.0
Re: [PATCH 4/5] aspeed/i2c: Add support for DMA transfers
Quoted 11 lines · Cédric Le Goater
The I2C controller of the Aspeed AST2500 and AST2600 SoCs supports DMA transfers to and from DRAM.
A pair of registers defines the buffer address and the length of the DMA transfer. The address should be aligned on 4 bytes and the maximum length should not exceed 4K. The receive or transmit DMA transfer can then be initiated with specific bits in the Command/Status register of the controller.
Signed-off-by Cédric Le Goater <[email protected]>
Re: [PATCH 4/5] aspeed/i2c: Add support for DMA transfers
In reply to Cédric Le GoaterQuoted 10 lines · Cédric Le Goater
The I2C controller of the Aspeed AST2500 and AST2600 SoCs supports DMA transfers to and from DRAM.
A pair of registers defines the buffer address and the length of the DMA transfer. The address should be aligned on 4 bytes and the maximum length should not exceed 4K. The receive or transmit DMA transfer can then be initiated with specific bits in the Command/Status register of the controller.
Signed-off-by Cédric Le Goater <[email protected]>
PATCH 5/5 aspeed/i2c: Add trace events
In reply to Cédric Le Goater--- hw/i2c/aspeed_i2c.c | 93 ++++++++++++++++++++++++++++++++++++++------- hw/i2c/trace-events | 9 +++++ 2 files changed, 89 insertions(+), 13 deletions(-)
hw/i2c/aspeed_i2c.c +80 -13
@@ -28,6 +28,7 @@#include "hw/i2c/aspeed_i2c.h" #include "hw/irq.h" #include "hw/qdev-properties.h" +#include "trace.h" /* I2C Global Register */
@@ -158,6 +159,13 @@ static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus) {AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); +trace_aspeed_i2c_bus_raise_interrupt (bus->intr_status, + bus->intr_status &I2CD_INTR_TX_NAK ?"nak|" :"" , + bus->intr_status &I2CD_INTR_TX_ACK ?"ack|" :"" , + bus->intr_status &I2CD_INTR_RX_DONE ?"done|" :"" , + bus->intr_status &I2CD_INTR_NORMAL_STOP ?"normal|" :"" , + bus->intr_status &I2CD_INTR_ABNORMAL ?"abnormal" :"" ); + bus->intr_status &= bus->intr_ctrl;if (bus->intr_status) { bus->controller->intr_status |=1 << bus->id;
@@ -170,41 +178,57 @@ static uint64_t aspeed_i2c_bus_read(void *opaque, hwaddr offset, {AspeedI2CBus *bus = opaque;AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); +uint64_t value =-1 ;switch (offset) {case I2CD_FUN_CTRL_REG : -return bus->ctrl; + value = bus->ctrl; +break ;case I2CD_AC_TIMING_REG1 : -return bus->timing[0 ]; + value = bus->timing[0 ]; +break ;case I2CD_AC_TIMING_REG2 : -return bus->timing[1 ]; + value = bus->timing[1 ]; +break ;case I2CD_INTR_CTRL_REG : -return bus->intr_ctrl; + value = bus->intr_ctrl; +break ;case I2CD_INTR_STS_REG : -return bus->intr_status; + value = bus->intr_status; +break ;case I2CD_POOL_CTRL_REG : -return bus->pool_ctrl; + value = bus->pool_ctrl; +break ;case I2CD_BYTE_BUF_REG : -return bus->buf; + value = bus->buf; +break ;case I2CD_CMD_REG : -return bus->cmd | (i2c_bus_busy (bus->bus) <<16 ); + value = bus->cmd | (i2c_bus_busy (bus->bus) <<16 ); +break ;case I2CD_DMA_ADDR :if (!aic->has_dma) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: No DMA support\n" , __func__); -return -1 ; +break ; } -return bus->dma_addr; + value = bus->dma_addr; +break ;case I2CD_DMA_LEN :if (!aic->has_dma) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: No DMA support\n" , __func__); -return -1 ; +break ; } -return bus->dma_len; + value = bus->dma_len; +break ; +default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, offset); -return -1 ; + value =-1 ; +break ; } + +trace_aspeed_i2c_bus_read (bus->id, offset, size, value); +return value; }static void aspeed_i2c_set_state (AspeedI2CBus *bus,uint8_t state)
@@ -246,6 +270,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start)for (i = pool_start; i <I2CD_POOL_TX_COUNT (bus->pool_ctrl); i++) {uint8_t *pool_base = aic->bus_pool_base (bus); +trace_aspeed_i2c_bus_send ("BUF" , i +1 , +I2CD_POOL_TX_COUNT (bus->pool_ctrl), + pool_base[i]); ret =i2c_send (bus->bus, pool_base[i]);if (ret) {break ;
@@ -256,6 +283,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start)while (bus->dma_len) {uint8_t data;aspeed_i2c_dma_read (bus, &data); +trace_aspeed_i2c_bus_send ("DMA" , bus->dma_len, bus->dma_len, data); ret =i2c_send (bus->bus, data);if (ret) {break ;
@@ -263,6 +291,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) } bus->cmd &= ~I2CD_TX_DMA_ENABLE ; }else { +trace_aspeed_i2c_bus_send ("BYTE" , pool_start,1 , bus->buf); ret =i2c_send (bus->bus, bus->buf); }
@@ -281,6 +310,9 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)for (i =0 ; i <I2CD_POOL_RX_SIZE (bus->pool_ctrl); i++) { pool_base[i] =i2c_recv (bus->bus); +trace_aspeed_i2c_bus_recv ("BUF" , i +1 , +I2CD_POOL_RX_SIZE (bus->pool_ctrl), + pool_base[i]); }/* Update RX count */
@@ -294,6 +326,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)MemTxResult result; data =i2c_recv (bus->bus); +trace_aspeed_i2c_bus_recv ("DMA" , bus->dma_len, bus->dma_len, data); result =address_space_write (&s->dram_as, bus->dma_addr,MEMTXATTRS_UNSPECIFIED , &data,1 );if (result !=MEMTX_OK ) {
@@ -307,6 +340,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus) bus->cmd &= ~I2CD_RX_DMA_ENABLE ; }else { data =i2c_recv (bus->bus); +trace_aspeed_i2c_bus_recv ("BYTE" ,1 ,1 , bus->buf); bus->buf = (data &I2CD_BYTE_BUF_RX_MASK ) <<I2CD_BYTE_BUF_RX_SHIFT ; } }
@@ -364,6 +398,33 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)return true; } +static void aspeed_i2c_bus_cmd_dump (AspeedI2CBus *bus) +{ + g_autofree char *cmd_flags; +uint32_t count; + +if (bus->cmd & (I2CD_RX_BUFF_ENABLE |I2CD_RX_BUFF_ENABLE )) { + count =I2CD_POOL_TX_COUNT (bus->pool_ctrl); + }else if (bus->cmd & (I2CD_RX_DMA_ENABLE |I2CD_RX_DMA_ENABLE )) { + count = bus->dma_len; + }else {/* BYTE mode */ + count =1 ; + } + + cmd_flags =g_strdup_printf ("%s%s%s%s%s%s%s%s%s" , + bus->cmd &I2CD_M_START_CMD ?"start|" :"" , + bus->cmd &I2CD_RX_DMA_ENABLE ?"rxdma|" :"" , + bus->cmd &I2CD_TX_DMA_ENABLE ?"txdma|" :"" , + bus->cmd &I2CD_RX_BUFF_ENABLE ?"rxbuf|" :"" , + bus->cmd &I2CD_TX_BUFF_ENABLE ?"txbuf|" :"" , + bus->cmd &I2CD_M_TX_CMD ?"tx|" :"" , + bus->cmd &I2CD_M_RX_CMD ?"rx|" :"" , + bus->cmd &I2CD_M_S_RX_CMD_LAST ?"last|" :"" , + bus->cmd &I2CD_M_STOP_CMD ?"stop" :"" ); + +trace_aspeed_i2c_bus_cmd (bus->cmd, cmd_flags, count, bus->intr_status); +} +/* * The state machine needs some refinement. It is only used to track * invalid STOP commands for the moment.
@@ -379,6 +440,10 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)return ; } +if (trace_event_get_state_backends (TRACE_ASPEED_I2C_BUS_CMD )) { +aspeed_i2c_bus_cmd_dump (bus); + } +if (bus->cmd &I2CD_M_START_CMD ) {uint8_t state =aspeed_i2c_get_state (bus) &I2CD_MACTIVE ?I2CD_MSTARTR :I2CD_MSTART ;
@@ -465,6 +530,8 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller);bool handle_rx; +trace_aspeed_i2c_bus_write (bus->id, offset, size, value); +switch (offset) {case I2CD_FUN_CTRL_REG :if (value &I2CD_SLAVE_EN ) {
hw/i2c/trace-events +9 -0
@@ -5,3 +5,12 @@ i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)" i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x" i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x" + +# aspeed_i2c.c + +aspeed_i2c_bus_cmd(uint32_t cmd, const char *cmd_flags, uint32_t count, uint32_t intr_status) "handling cmd=0x%x %s count=%d intr=0x%x" +aspeed_i2c_bus_raise_interrupt(uint32_t intr_status, const char *str1, const char *str2, const char *str3, const char *str4, const char *str5) "handled intr=0x%x %s%s%s%s%s" +aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_write(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" +aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x"
Signature · 1 line
2.21.0
Re: [PATCH 5/5] aspeed/i2c: Add trace events
Quoted 2 lines · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>
Re: [PATCH 5/5] aspeed/i2c: Add trace events
In reply to Cédric Le GoaterQuoted 1 line · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>
Thanks for the implementation!
-Jae
Re: [PATCH 5/5] aspeed/i2c: Add trace events
In reply to Cédric Le GoaterHi Cédric,
Quoted 214 lines · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>--- hw/i2c/aspeed_i2c.c | 93 ++++++++++++++++++++++++++++++++++++++------- hw/i2c/trace-events | 9 +++++ 2 files changed, 89 insertions(+), 13 deletions(-)hw/i2c/aspeed_i2c.c +80
-13@@ -28,6 +28,7 @@#include "hw/i2c/aspeed_i2c.h" #include "hw/irq.h" #include "hw/qdev-properties.h" +#include "trace.h" /* I2C Global Register */ @@ -158,6 +159,13 @@ static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus) {AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); +trace_aspeed_i2c_bus_raise_interrupt (bus->intr_status, + bus->intr_status &I2CD_INTR_TX_NAK ?"nak|" :"" , + bus->intr_status &I2CD_INTR_TX_ACK ?"ack|" :"" , + bus->intr_status &I2CD_INTR_RX_DONE ?"done|" :"" , + bus->intr_status &I2CD_INTR_NORMAL_STOP ?"normal|" :"" , + bus->intr_status &I2CD_INTR_ABNORMAL ?"abnormal" :"" ); + bus->intr_status &= bus->intr_ctrl;if (bus->intr_status) { bus->controller->intr_status |=1 << bus->id;@@ -170,41 +178,57 @@ static uint64_t aspeed_i2c_bus_read(void *opaque, hwaddr offset, {AspeedI2CBus *bus = opaque;AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller); +uint64_t value =-1 ;switch (offset) {case I2CD_FUN_CTRL_REG : -return bus->ctrl; + value = bus->ctrl; +break ;case I2CD_AC_TIMING_REG1 : -return bus->timing[0 ]; + value = bus->timing[0 ]; +break ;case I2CD_AC_TIMING_REG2 : -return bus->timing[1 ]; + value = bus->timing[1 ]; +break ;case I2CD_INTR_CTRL_REG : -return bus->intr_ctrl; + value = bus->intr_ctrl; +break ;case I2CD_INTR_STS_REG : -return bus->intr_status; + value = bus->intr_status; +break ;case I2CD_POOL_CTRL_REG : -return bus->pool_ctrl; + value = bus->pool_ctrl; +break ;case I2CD_BYTE_BUF_REG : -return bus->buf; + value = bus->buf; +break ;case I2CD_CMD_REG : -return bus->cmd | (i2c_bus_busy (bus->bus) <<16 ); + value = bus->cmd | (i2c_bus_busy (bus->bus) <<16 ); +break ;case I2CD_DMA_ADDR :if (!aic->has_dma) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: No DMA support\n" , __func__); -return -1 ; +break ; } -return bus->dma_addr; + value = bus->dma_addr; +break ;case I2CD_DMA_LEN :if (!aic->has_dma) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: No DMA support\n" , __func__); -return -1 ; +break ; } -return bus->dma_len; + value = bus->dma_len; +break ; +default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: Bad offset 0x%" HWADDR_PRIx"\n" , __func__, offset); -return -1 ; + value =-1 ; +break ; } + +trace_aspeed_i2c_bus_read (bus->id, offset, size, value); +return value; }static void aspeed_i2c_set_state (AspeedI2CBus *bus,uint8_t state)@@ -246,6 +270,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start)for (i = pool_start; i <I2CD_POOL_TX_COUNT (bus->pool_ctrl); i++) {uint8_t *pool_base = aic->bus_pool_base (bus); +trace_aspeed_i2c_bus_send ("BUF" , i +1 , +I2CD_POOL_TX_COUNT (bus->pool_ctrl), + pool_base[i]); ret =i2c_send (bus->bus, pool_base[i]);if (ret) {break ;@@ -256,6 +283,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start)while (bus->dma_len) {uint8_t data;aspeed_i2c_dma_read (bus, &data); +trace_aspeed_i2c_bus_send ("DMA" , bus->dma_len, bus->dma_len, data); ret =i2c_send (bus->bus, data);if (ret) {break ;@@ -263,6 +291,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) } bus->cmd &= ~I2CD_TX_DMA_ENABLE ; }else { +trace_aspeed_i2c_bus_send ("BYTE" , pool_start,1 , bus->buf); ret =i2c_send (bus->bus, bus->buf); }@@ -281,6 +310,9 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)for (i =0 ; i <I2CD_POOL_RX_SIZE (bus->pool_ctrl); i++) { pool_base[i] =i2c_recv (bus->bus); +trace_aspeed_i2c_bus_recv ("BUF" , i +1 , +I2CD_POOL_RX_SIZE (bus->pool_ctrl), + pool_base[i]); }/* Update RX count */ @@ -294,6 +326,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)MemTxResult result; data =i2c_recv (bus->bus); +trace_aspeed_i2c_bus_recv ("DMA" , bus->dma_len, bus->dma_len, data); result =address_space_write (&s->dram_as, bus->dma_addr,MEMTXATTRS_UNSPECIFIED , &data,1 );if (result !=MEMTX_OK ) {@@ -307,6 +340,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus) bus->cmd &= ~I2CD_RX_DMA_ENABLE ; }else { data =i2c_recv (bus->bus); +trace_aspeed_i2c_bus_recv ("BYTE" ,1 ,1 , bus->buf); bus->buf = (data &I2CD_BYTE_BUF_RX_MASK ) <<I2CD_BYTE_BUF_RX_SHIFT ; } }@@ -364,6 +398,33 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)return true; } +static void aspeed_i2c_bus_cmd_dump (AspeedI2CBus *bus) +{ + g_autofree char *cmd_flags; +uint32_t count; + +if (bus->cmd & (I2CD_RX_BUFF_ENABLE |I2CD_RX_BUFF_ENABLE )) { + count =I2CD_POOL_TX_COUNT (bus->pool_ctrl); + }else if (bus->cmd & (I2CD_RX_DMA_ENABLE |I2CD_RX_DMA_ENABLE )) { + count = bus->dma_len; + }else {/* BYTE mode */ + count =1 ; + } + + cmd_flags =g_strdup_printf ("%s%s%s%s%s%s%s%s%s" , + bus->cmd &I2CD_M_START_CMD ?"start|" :"" , + bus->cmd &I2CD_RX_DMA_ENABLE ?"rxdma|" :"" , + bus->cmd &I2CD_TX_DMA_ENABLE ?"txdma|" :"" , + bus->cmd &I2CD_RX_BUFF_ENABLE ?"rxbuf|" :"" , + bus->cmd &I2CD_TX_BUFF_ENABLE ?"txbuf|" :"" , + bus->cmd &I2CD_M_TX_CMD ?"tx|" :"" , + bus->cmd &I2CD_M_RX_CMD ?"rx|" :"" , + bus->cmd &I2CD_M_S_RX_CMD_LAST ?"last|" :"" , + bus->cmd &I2CD_M_STOP_CMD ?"stop" :"" ); + +trace_aspeed_i2c_bus_cmd (bus->cmd, cmd_flags, count, bus->intr_status); +} +/* * The state machine needs some refinement. It is only used to track * invalid STOP commands for the moment. @@ -379,6 +440,10 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)return ; } +if (trace_event_get_state_backends (TRACE_ASPEED_I2C_BUS_CMD )) { +aspeed_i2c_bus_cmd_dump (bus); + } +if (bus->cmd &I2CD_M_START_CMD ) {uint8_t state =aspeed_i2c_get_state (bus) &I2CD_MACTIVE ?I2CD_MSTARTR :I2CD_MSTART ;@@ -465,6 +530,8 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller);bool handle_rx; +trace_aspeed_i2c_bus_write (bus->id, offset, size, value); +switch (offset) {case I2CD_FUN_CTRL_REG :if (value &I2CD_SLAVE_EN ) {hw/i2c/trace-events +0
-0
hw/i2c/trace-events line 12
Quoted 8 lines
hw/i2c/trace-events +5
-0@@ -5,3 +5,12 @@ i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)" i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x" i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x" + +# aspeed_i2c.c + +aspeed_i2c_bus_cmd(uint32_t cmd, const char *cmd_flags, uint32_t count, uint32_t intr_status) "handling cmd=0x%x %s count=%d intr=0x%x" +aspeed_i2c_bus_raise_interrupt(uint32_t intr_status, const char *str1, const char *str2, const char *str3, const char *str4, const char *str5) "handled intr=0x%x %s%s%s%s%s"
There are various trace backends, your output seems designed only for the "log" backend.
Using 'unsigned is_nak, unsigned is_ack, ...' "nak:%u ack:%u ..." would make your event compatible with the other backends (and ease their parsing).
Quoted 5 lines
hw/i2c/trace-events +4
-0+aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_write(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" +aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x"
Re: [PATCH 5/5] aspeed/i2c: Add trace events
Hello Philippe,
Quoted 215 lines · Philippe Mathieu-Daudé
Hi Cédric,
Quoted 204 lines · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>---
hw/i2c/aspeed_i2c.c| 93 ++++++++++++++++++++++++++++++++++++++------- hw/i2c/trace-events | 9 +++++2 files changed, 89 insertions(+), 13 deletions(-)hw/i2c/aspeed_i2c.c +1
-0@@ -28,6 +28,7 @@ #include "hw/i2c/aspeed_i2c.h" #include "hw/irq.h" #include "hw/qdev-properties.h" +#include "trace.h" /* I2C Global Register */ @@ -158,6 +159,13 @@ static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus) {AspeedI2CClass *aic =
ASPEED_I2C_GET_CLASS(bus->controller); + trace_aspeed_i2c_bus_raise_interrupt(bus->intr_status, +bus->intr_status&I2CD_INTR_TX_NAK? "nak|" : "", +bus->intr_status&I2CD_INTR_TX_ACK? "ack|" : "", +bus->intr_status&I2CD_INTR_RX_DONE? "done|" : "", +bus->intr_status&I2CD_INTR_NORMAL_STOP? "normal|" : "", +bus->intr_status&I2CD_INTR_ABNORMAL? "abnormal" : ""); +
bus->intr_status&=bus->intr_ctrl;
if (bus->intr_status) {
bus->controller->intr_status|= 1 <<bus->id;hw/i2c/aspeed_i2c.c +1
-0@@ -170,41 +178,57 @@ static uint64_t aspeed_i2c_bus_read(void *opaque, hwaddr offset, { AspeedI2CBus *bus = opaque; AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); + uint64_t value = -1; switch (offset) {case
I2CD_FUN_CTRL_REG:
- returnbus->ctrl;
+ value =bus->ctrl;
+ break;
caseI2CD_AC_TIMING_REG1:
- return bus->timing[0];
+ value = bus->timing[0];
+ break;
caseI2CD_AC_TIMING_REG2:
- return bus->timing[1];
+ value = bus->timing[1];
+ break;
caseI2CD_INTR_CTRL_REG:
- returnbus->intr_ctrl;
+ value =bus->intr_ctrl;
+ break;
caseI2CD_INTR_STS_REG:
- returnbus->intr_status;
+ value =bus->intr_status;
+ break;
caseI2CD_POOL_CTRL_REG:
- returnbus->pool_ctrl;
+ value =bus->pool_ctrl;
+ break;
caseI2CD_BYTE_BUF_REG:
- returnbus->buf;
+ value =bus->buf;
+ break;
caseI2CD_CMD_REG:
- returnbus->cmd| (i2c_bus_busy(bus->bus)<< 16);
+ value =bus->cmd| (i2c_bus_busy(bus->bus)<< 16);
+ break;
caseI2CD_DMA_ADDR:
if (!aic->has_dma) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__); - return -1;
+ break;
}
- returnbus->dma_addr;
+ value =bus->dma_addr;
+ break;
caseI2CD_DMA_LEN:
if (!aic->has_dma) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__); - return -1;
+ break;
}
- returnbus->dma_len;
+ value =bus->dma_len;
+ break;
+
default:
qemu_log_mask(LOG_GUEST_ERROR,
"%s: Bad offset 0x%"HWADDR_PRIx"\n",__func__, offset); - return -1;
+ value = -1;
+ break;
}
+
+trace_aspeed_i2c_bus_read(bus->id, offset, size, value);
+ return value;
}
static voidaspeed_i2c_set_state(AspeedI2CBus *bus, uint8_t state)hw/i2c/aspeed_i2c.c +4
-0@@ -246,6 +270,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) for (i = pool_start; i < I2CD_POOL_TX_COUNT(bus->pool_ctrl); i++) { uint8_t *pool_base = aic->bus_pool_base(bus); + trace_aspeed_i2c_bus_send("BUF", i + 1, + I2CD_POOL_TX_COUNT(bus->pool_ctrl), + pool_base[i]); ret = i2c_send(bus->bus, pool_base[i]); if (ret) { break;@@ -256,6 +283,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) while (bus->dma_len) { uint8_t data; aspeed_i2c_dma_read(bus, &data); + trace_aspeed_i2c_bus_send("DMA", bus->dma_len, bus->dma_len, data); ret = i2c_send(bus->bus, data); if (ret) { break;@@ -263,6 +291,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) } bus->cmd &= ~I2CD_TX_DMA_ENABLE; } else { + trace_aspeed_i2c_bus_send("BYTE", pool_start, 1, bus->buf); ret = i2c_send(bus->bus, bus->buf); } @@ -281,6 +310,9 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)for (i = 0; i <
I2CD_POOL_RX_SIZE(bus->pool_ctrl); i++) { pool_base[i] =i2c_recv(bus->bus);
+ trace_aspeed_i2c_bus_recv("BUF", i + 1,
+I2CD_POOL_RX_SIZE(bus->pool_ctrl), + pool_base[i]);
}
/* Update RX count */hw/i2c/aspeed_i2c.c +31
-0@@ -294,6 +326,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus) MemTxResult result; data = i2c_recv(bus->bus); + trace_aspeed_i2c_bus_recv("DMA", bus->dma_len, bus->dma_len, data); result = address_space_write(&s->dram_as, bus->dma_addr, MEMTXATTRS_UNSPECIFIED, &data, 1); if (result != MEMTX_OK) {@@ -307,6 +340,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus) bus->cmd &= ~I2CD_RX_DMA_ENABLE; } else { data = i2c_recv(bus->bus); + trace_aspeed_i2c_bus_recv("BYTE", 1, 1, bus->buf); bus->buf = (data & I2CD_BYTE_BUF_RX_MASK) << I2CD_BYTE_BUF_RX_SHIFT; } }@@ -364,6 +398,33 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus) return true; } +static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus) +{ + g_autofree char *cmd_flags; + uint32_t count; + + if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) { + count = I2CD_POOL_TX_COUNT(bus->pool_ctrl); + } else if (bus->cmd & (I2CD_RX_DMA_ENABLE | I2CD_RX_DMA_ENABLE)) { + count = bus->dma_len; + } else { /* BYTE mode */ + count = 1; + } + + cmd_flags = g_strdup_printf("%s%s%s%s%s%s%s%s%s", + bus->cmd & I2CD_M_START_CMD ? "start|" : "", + bus->cmd & I2CD_RX_DMA_ENABLE ? "rxdma|" : "", + bus->cmd & I2CD_TX_DMA_ENABLE ? "txdma|" : "", + bus->cmd & I2CD_RX_BUFF_ENABLE ? "rxbuf|" : "", + bus->cmd & I2CD_TX_BUFF_ENABLE ? "txbuf|" : "", + bus->cmd & I2CD_M_TX_CMD ? "tx|" : "", + bus->cmd & I2CD_M_RX_CMD ? "rx|" : "", + bus->cmd & I2CD_M_S_RX_CMD_LAST ? "last|" : "", + bus->cmd & I2CD_M_STOP_CMD ? "stop" : ""); + + trace_aspeed_i2c_bus_cmd(bus->cmd, cmd_flags, count, bus->intr_status); +} + /** The state machine needs some refinement. It is only used to track * invalid STOP commands for the moment. @@ -379,6 +440,10 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) return; } + if (trace_event_get_state_backends(TRACE_ASPEED_I2C_BUS_CMD)) { + aspeed_i2c_bus_cmd_dump(bus); + } + if (bus->cmd & I2CD_M_START_CMD) {
uint8_tstate =aspeed_i2c_get_state(bus)&I2CD_MACTIVE?I2CD_MSTARTR:I2CD_MSTART;hw/i2c/aspeed_i2c.c +1
-0@@ -465,6 +530,8 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset, AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); bool handle_rx; + trace_aspeed_i2c_bus_write(bus->id, offset, size, value); + switch (offset) {case
I2CD_FUN_CTRL_REG:
if (value &I2CD_SLAVE_EN) {hw/i2c/trace-events +0
-0@@ -5,3 +5,12 @@
i2c_event(const char *event, uint8_t address)"%s(addr:0x%02x)"i2c_send(uint8_t address, uint8_t data)"send(addr:0x%02x) data:0x%02x"i2c_recv(uint8_t address, uint8_t data)"recv(addr:0x%02x) data:0x%02x"hw/i2c/trace-events line 12
Quoted 5 lines
hw/i2c/trace-events +5
-0+ +# aspeed_i2c.c + +aspeed_i2c_bus_cmd(uint32_t cmd, const char *cmd_flags, uint32_t count, uint32_t intr_status) "handling cmd=0x%x %s count=%d intr=0x%x" +aspeed_i2c_bus_raise_interrupt(uint32_t intr_status, const char *str1, const char *str2, const char *str3, const char *str4, const char *str5) "handled intr=0x%x %s%s%s%s%s"There are various trace backends, your output seems designed only for the "log" backend.
Quoted 1 line
Using 'unsigned
is_nak, unsignedis_ack, ...' "nak:%u ack:%u ..." would make your event compatible with the other backends (and ease their parsing).
I am not sure to understand where the incompatibility is. Could you explain more please ?
Thanks,
C.
Quoted 5 lines
Quoted 5 lines
hw/i2c/trace-events +4
-0+aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_write(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" +aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x"
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 5/5] aspeed/i2c: Add trace events
Hi Cédric,
Sorry for the late reply.
Quoted 171 lines · Cédric Le Goater
Hello Philippe,
Quoted 168 lines · Philippe Mathieu-Daudé
Hi Cédric,
Quoted 165 lines · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>--- hw/i2c/aspeed_i2c.c | 93 ++++++++++++++++++++++++++++++++++++++------- hw/i2c/trace-events | 9 +++++ 2 files changed, 89 insertions(+), 13 deletions(-)hw/i2c/aspeed_i2c.c +1
-0@@ -28,6 +28,7 @@ #include "hw/i2c/aspeed_i2c.h" #include "hw/irq.h" #include "hw/qdev-properties.h" +#include "trace.h" /* I2C Global Register */ @@ -158,6 +159,13 @@ static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus) {AspeedI2CClass *aic =
ASPEED_I2C_GET_CLASS(bus->controller); + trace_aspeed_i2c_bus_raise_interrupt(bus->intr_status,
+bus->intr_status&I2CD_INTR_TX_NAK? "nak|" : "", +bus->intr_status&I2CD_INTR_TX_ACK? "ack|" : "", +bus->intr_status&I2CD_INTR_RX_DONE? "done|" : "", +bus->intr_status&I2CD_INTR_NORMAL_STOP? "normal|" : "", +bus->intr_status&I2CD_INTR_ABNORMAL? "abnormal" : "");hw/i2c/aspeed_i2c.c +34
-13+ bus->intr_status &= bus->intr_ctrl; if (bus->intr_status) { bus->controller->intr_status |= 1 << bus->id;@@ -170,41 +178,57 @@ static uint64_t aspeed_i2c_bus_read(void *opaque, hwaddr offset, { AspeedI2CBus *bus = opaque; AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); + uint64_t value = -1; switch (offset) { case I2CD_FUN_CTRL_REG: - return bus->ctrl; + value = bus->ctrl; + break; case I2CD_AC_TIMING_REG1: - return bus->timing[0]; + value = bus->timing[0]; + break; case I2CD_AC_TIMING_REG2: - return bus->timing[1]; + value = bus->timing[1]; + break; case I2CD_INTR_CTRL_REG: - return bus->intr_ctrl; + value = bus->intr_ctrl; + break; case I2CD_INTR_STS_REG: - return bus->intr_status; + value = bus->intr_status; + break; case I2CD_POOL_CTRL_REG: - return bus->pool_ctrl; + value = bus->pool_ctrl; + break; case I2CD_BYTE_BUF_REG: - return bus->buf; + value = bus->buf; + break; case I2CD_CMD_REG: - return bus->cmd | (i2c_bus_busy(bus->bus) << 16); + value = bus->cmd | (i2c_bus_busy(bus->bus) << 16); + break; case I2CD_DMA_ADDR: if (!aic->has_dma) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__); - return -1; + break; } - return bus->dma_addr; + value = bus->dma_addr; + break; case I2CD_DMA_LEN: if (!aic->has_dma) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__); - return -1; + break; } - return bus->dma_len; + value = bus->dma_len; + break; + default: qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, offset); - return -1; + value = -1; + break; } + + trace_aspeed_i2c_bus_read(bus->id, offset, size, value); + return value; } static void aspeed_i2c_set_state(AspeedI2CBus *bus, uint8_t state)@@ -246,6 +270,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) for (i = pool_start; i < I2CD_POOL_TX_COUNT(bus->pool_ctrl); i++) { uint8_t *pool_base = aic->bus_pool_base(bus); + trace_aspeed_i2c_bus_send("BUF", i + 1, + I2CD_POOL_TX_COUNT(bus->pool_ctrl), + pool_base[i]); ret = i2c_send(bus->bus, pool_base[i]); if (ret) { break;@@ -256,6 +283,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) while (bus->dma_len) { uint8_t data; aspeed_i2c_dma_read(bus, &data); + trace_aspeed_i2c_bus_send("DMA", bus->dma_len, bus->dma_len, data); ret = i2c_send(bus->bus, data); if (ret) { break;@@ -263,6 +291,7 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start) } bus->cmd &= ~I2CD_TX_DMA_ENABLE; } else { + trace_aspeed_i2c_bus_send("BYTE", pool_start, 1, bus->buf); ret = i2c_send(bus->bus, bus->buf); } @@ -281,6 +310,9 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)for (i = 0; i <
I2CD_POOL_RX_SIZE(bus->pool_ctrl); i++) { pool_base[i] =i2c_recv(bus->bus);
+ trace_aspeed_i2c_bus_recv("BUF", i + 1,
+I2CD_POOL_RX_SIZE(bus->pool_ctrl), + pool_base[i]);
}
/* Update RX count */hw/i2c/aspeed_i2c.c +18
-0@@ -294,6 +326,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus) MemTxResult result; data = i2c_recv(bus->bus); + trace_aspeed_i2c_bus_recv("DMA", bus->dma_len, bus->dma_len, data); result = address_space_write(&s->dram_as, bus->dma_addr, MEMTXATTRS_UNSPECIFIED, &data, 1); if (result != MEMTX_OK) {@@ -307,6 +340,7 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus) bus->cmd &= ~I2CD_RX_DMA_ENABLE; } else { data = i2c_recv(bus->bus); + trace_aspeed_i2c_bus_recv("BYTE", 1, 1, bus->buf); bus->buf = (data & I2CD_BYTE_BUF_RX_MASK) << I2CD_BYTE_BUF_RX_SHIFT; } }@@ -364,6 +398,33 @@ static bool aspeed_i2c_check_sram(AspeedI2CBus *bus) return true; } +static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus) +{ + g_autofree char *cmd_flags; + uint32_t count; + + if (bus->cmd & (I2CD_RX_BUFF_ENABLE | I2CD_RX_BUFF_ENABLE)) { + count = I2CD_POOL_TX_COUNT(bus->pool_ctrl); + } else if (bus->cmd & (I2CD_RX_DMA_ENABLE | I2CD_RX_DMA_ENABLE)) { + count = bus->dma_len; + } else { /* BYTE mode */ + count = 1; + } + + cmd_flags = g_strdup_printf("%s%s%s%s%s%s%s%s%s", + bus->cmd & I2CD_M_START_CMD ? "start|" : "", + bus->cmd & I2CD_RX_DMA_ENABLE ? "rxdma|" : "", + bus->cmd & I2CD_TX_DMA_ENABLE ? "txdma|" : "",
Quoted 8 lines
Quoted 8 lines
hw/i2c/aspeed_i2c.c static bool aspeed_i2c_check_sram(AspeedI2CBus *bus) · line 425
Quoted 8 lines
hw/i2c/aspeed_i2c.c +8
-0+ bus->cmd & I2CD_RX_BUFF_ENABLE ? "rxbuf|" : "", + bus->cmd & I2CD_TX_BUFF_ENABLE ? "txbuf|" : "", + bus->cmd & I2CD_M_TX_CMD ? "tx|" : "", + bus->cmd & I2CD_M_RX_CMD ? "rx|" : "", + bus->cmd & I2CD_M_S_RX_CMD_LAST ? "last|" : "", + bus->cmd & I2CD_M_STOP_CMD ? "stop" : ""); + + trace_aspeed_i2c_bus_cmd(bus->cmd, cmd_flags, count, bus->intr_status);
Hard to switch habits and review code using g_autofree :/
Quoted 39 lines
Quoted 39 lines
Quoted 28 lines
hw/i2c/aspeed_i2c.c +6
-0+} + /** The state machine needs some refinement. It is only used to track * invalid STOP commands for the moment. @@ -379,6 +440,10 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) return; } + if (trace_event_get_state_backends(TRACE_ASPEED_I2C_BUS_CMD)) { + aspeed_i2c_bus_cmd_dump(bus); + } + if (bus->cmd & I2CD_M_START_CMD) { uint8_t state = aspeed_i2c_get_state(bus) & I2CD_MACTIVE ? I2CD_MSTARTR : I2CD_MSTART;@@ -465,6 +530,8 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset, AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); bool handle_rx; + trace_aspeed_i2c_bus_write(bus->id, offset, size, value); + switch (offset) { case I2CD_FUN_CTRL_REG: if (value & I2CD_SLAVE_EN) {hw/i2c/trace-events +0
-0hw/i2c/trace-events line 12
Quoted 8 lines
hw/i2c/trace-events +5
-0@@ -5,3 +5,12 @@ i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)" i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x" i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x" + +# aspeed_i2c.c + +aspeed_i2c_bus_cmd(uint32_t cmd, const char *cmd_flags, uint32_t count, uint32_t intr_status) "handling cmd=0x%x %s count=%d intr=0x%x" +aspeed_i2c_bus_raise_interrupt(uint32_t intr_status, const char *str1, const char *str2, const char *str3, const char *str4, const char *str5) "handled intr=0x%x %s%s%s%s%s"There are various trace backends, your output seems designed only for the "log" backend.
Quoted 4 lines
Quoted 1 line
Using 'unsigned
is_nak, unsignedis_ack, ...' "nak:%u ack:%u ..." would make your event compatible with the other backends (and ease their parsing).I am not sure to understand where the incompatibility is. Could you explain more please ?
Well, the format you used is not *incompatible*, but it is not optimal.
The aspeed_i2c_bus_raise_interrupt() trace event might be OK, although the arguments could be better named.
The DTrace generated script is:
probe qemu.system.arm.log.aspeed_i2c_bus_raise_interrupt = qemu.system.arm.aspeed_i2c_bus_raise_interrupt ?
{
try {
argstr1_str = str1 ? user_string_n(str1, 512) : "<null>"
} catch {}
try {
argstr2_str = str2 ? user_string_n(str2, 512) : "<null>"
} catch {}
try {
argstr3_str = str3 ? user_string_n(str3, 512) : "<null>"
} catch {}
try {
argstr4_str = str4 ? user_string_n(str4, 512) : "<null>"
} catch {}
try {
argstr5_str = str5 ? user_string_n(str5, 512) : "<null>"
} catch {}
printf("%d@%d aspeed_i2c_bus_raise_interrupt handled intr=0x%x %s%s%s%s%s\n", pid(), gettimeofday_ns(), intr_status, argstr1_str, argstr2_str, argstr3_str, argstr4_str, argstr5_str) }
Acceptable.
The aspeed_i2c_bus_cmd() event is the one that bugged me, because thinking about tracing a particular set of commands (like: "all the commands with the rxdma bit set") I thought we'd need to parse the 'const char *cmd_flags'. But now I realize you also pass the bus->cmd value, so we can filter there, and ignore the description string. Same occurs with the other event, we can parse intr_status.
Quoted 11 lines
Thanks,
C.
Quoted 5 lines
Quoted 5 lines
hw/i2c/trace-events +4
-0+aspeed_i2c_bus_read(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_write(uint32_t busid, uint64_t offset, unsigned size, uint64_t value) "bus[%d]: To 0x%" PRIx64 " of size %u: 0x%" PRIx64 +aspeed_i2c_bus_send(const char *mode, int i, int count, uint8_t byte) "%s send %d/%d 0x%02x" +aspeed_i2c_bus_recv(const char *mode, int i, int count, uint8_t byte) "%s recv %d/%d 0x%02x"