From: Jamin Lin <jamin_lin@aspeedtech.com>
To: "Cédric Le Goater" <clg@kaod.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Steven Lee" <steven_lee@aspeedtech.com>,
"Troy Lee" <leetroy@gmail.com>,
"Kane Chen" <kane_chen@aspeedtech.com>,
"Andrew Jeffery" <andrew@codeconstruct.com.au>,
"Joel Stanley" <joel@jms.id.au>,
"open list:ASPEED BMCs" <qemu-arm@nongnu.org>,
"open list:All patches CC here" <qemu-devel@nongnu.org>
Cc: Jamin Lin <jamin_lin@aspeedtech.com>, Troy Lee <troy_lee@aspeedtech.com>
Subject: [PATCH v1 1/8] hw/i2c/aspeed_i2c: Support the AST2700 master buffer mode
Date: Tue, 4 Aug 2026 08:19:57 +0000 [thread overview]
Message-ID: <20260804081955.1563537-2-jamin_lin@aspeedtech.com> (raw)
In-Reply-To: <20260804081955.1563537-1-jamin_lin@aspeedtech.com>
The AST2700 I2C controller can move master DMA payloads through its
internal SRAM pool rather than DRAM. The Linux driver calls this "buffer
mode" and selects it by default. Buffer mode reuses the master DMA
command bits (TX/RX_DMA_EN) and the DMA length registers, so the only
difference from a DRAM transfer is where the data comes from and goes
to: an offset into the pool programmed in I2CM_DMA_TX/RX_ADDR. The
I2CC_VERSION_CTRL FUNC_CFG_DMA_EN bit selects between the two.
Implement I2CC_VERSION_CTRL and, when FUNC_CFG_DMA_EN is clear, move the
payload through the pool buffer instead of DRAM.
I2CC_VERSION_CTRL resets to all ones, so guests that never program it
keep targeting DRAM and behave as before. The register sits above the
register window of the earlier SoCs, which are therefore unaffected.
Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
---
include/hw/i2c/aspeed_i2c.h | 2 +
hw/i2c/aspeed_i2c.c | 79 +++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h
index 156998e7c1..05937a7a0b 100644
--- a/include/hw/i2c/aspeed_i2c.h
+++ b/include/hw/i2c/aspeed_i2c.h
@@ -231,6 +231,8 @@ REG32(I2CS_DMA_TX_ADDR_HI, 0x68)
FIELD(I2CS_DMA_TX_ADDR_HI, ADDR_HI, 0, 7)
REG32(I2CS_DMA_RX_ADDR_HI, 0x6c)
FIELD(I2CS_DMA_RX_ADDR_HI, ADDR_HI, 0, 7)
+REG32(I2CC_VERSION_CTRL, 0x94)
+ FIELD(I2CC_VERSION_CTRL, FUNC_CFG_DMA_EN, 2, 1)
struct AspeedI2CState;
diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
index 27afcaecee..68bdcd0e25 100644
--- a/hw/i2c/aspeed_i2c.c
+++ b/hw/i2c/aspeed_i2c.c
@@ -159,6 +159,7 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,
case A_I2CS_INTR_CTRL:
case A_I2CS_DMA_LEN_STS:
case A_I2CS_INTR_STS:
+ case A_I2CC_VERSION_CTRL:
value = bus->regs[offset / sizeof(*bus->regs)];
break;
case A_I2CC_DMA_ADDR:
@@ -295,6 +296,65 @@ static int aspeed_i2c_dma_read(AspeedI2CBus *bus, uint8_t *data)
return 0;
}
+/*
+ * In AST2700 buffer mode the master DMA command bits (TX/RX_DMA_EN) and the
+ * DMA length registers are reused, but data is moved through the controller
+ * internal SRAM pool at the offset programmed in I2CM_DMA_TX/RX_ADDR instead
+ * of DRAM. FUNC_CFG_DMA_EN selects between the two (set = DRAM).
+ */
+static bool aspeed_i2c_bus_dma_to_pool(AspeedI2CBus *bus)
+{
+ return aspeed_i2c_is_new_mode(bus->controller) &&
+ !ARRAY_FIELD_EX32(bus->regs, I2CC_VERSION_CTRL, FUNC_CFG_DMA_EN);
+}
+
+static int aspeed_i2c_bus_send_dma_pool(AspeedI2CBus *bus)
+{
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
+ uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
+ uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
+ uint32_t offset = bus->regs[R_I2CM_DMA_TX_ADDR];
+ uint8_t *pool_base = aic->bus_pool_base(bus);
+ int ret = -1;
+ int i;
+
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, 0);
+ for (i = 0; bus->regs[reg_dma_len] &&
+ offset + i < ASPEED_I2C_BUS_POOL_SIZE; i++) {
+ trace_aspeed_i2c_bus_send("BUFF", i + 1, bus->regs[reg_dma_len],
+ pool_base[offset + i]);
+ ret = i2c_send(bus->bus, pool_base[offset + i]);
+ bus->regs[reg_dma_len]--;
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, i + 1);
+ if (ret) {
+ break;
+ }
+ }
+ SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, TX_DMA_EN, 0);
+ return ret;
+}
+
+static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus)
+{
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
+ uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
+ uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
+ uint32_t offset = bus->regs[R_I2CM_DMA_RX_ADDR];
+ uint8_t *pool_base = aic->bus_pool_base(bus);
+ int i;
+
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
+ for (i = 0; bus->regs[reg_dma_len] &&
+ offset + i < ASPEED_I2C_BUS_POOL_SIZE; i++) {
+ pool_base[offset + i] = i2c_recv(bus->bus);
+ trace_aspeed_i2c_bus_recv("BUFF", i + 1, bus->regs[reg_dma_len],
+ pool_base[offset + i]);
+ bus->regs[reg_dma_len]--;
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, i + 1);
+ }
+ SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_DMA_EN, 0);
+}
+
static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
{
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
@@ -320,6 +380,10 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
}
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, TX_BUFF_EN, 0);
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN)) {
+ /* In buffer mode the DMA moves data through the pool, not DRAM */
+ if (aspeed_i2c_bus_dma_to_pool(bus)) {
+ return aspeed_i2c_bus_send_dma_pool(bus);
+ }
/* In new mode, clear how many bytes we TXed */
if (aspeed_i2c_is_new_mode(bus->controller)) {
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, 0);
@@ -385,6 +449,11 @@ static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_pool_ctrl, RX_COUNT, i & 0xff);
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_BUFF_EN, 0);
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN)) {
+ /* In buffer mode the DMA moves data through the pool, not DRAM */
+ if (aspeed_i2c_bus_dma_to_pool(bus)) {
+ aspeed_i2c_bus_recv_dma_pool(bus);
+ return;
+ }
/* In new mode, clear how many bytes we RXed */
if (aspeed_i2c_is_new_mode(bus->controller)) {
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
@@ -854,6 +923,9 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
I2CS_DMA_RX_ADDR_HI,
ADDR_HI);
break;
+ case A_I2CC_VERSION_CTRL:
+ bus->regs[R_I2CC_VERSION_CTRL] = value;
+ break;
default:
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
__func__, offset);
@@ -1497,6 +1569,13 @@ static void aspeed_i2c_bus_reset_hold(Object *obj, ResetType type)
memset(s->regs, 0, sizeof(s->regs));
s->pending_intr_sts = 0;
i2c_end_transfer(s->bus);
+ /*
+ * I2CC_VERSION_CTRL resets to all-ones. FUNC_CFG_DMA_EN is therefore set,
+ * so master DMA targets DRAM unless the guest clears it to select buffer
+ * mode. Guests unaware of buffer mode never touch this register and keep
+ * doing DRAM DMA.
+ */
+ s->regs[R_I2CC_VERSION_CTRL] = 0xffffffff;
}
static void aspeed_i2c_bus_realize(DeviceState *dev, Error **errp)
--
2.43.0
next prev parent reply other threads:[~2026-08-04 8:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 8:19 [PATCH v1 0/8] tests/functional/arm/test_aspeed: Update ASPEED SDK v11.03 Jamin Lin
2026-08-04 8:19 ` Jamin Lin [this message]
2026-08-04 8:19 ` [PATCH v1 2/8] tests/functional/aarch64/test_aspeed_ast2700a2: " Jamin Lin
2026-08-04 8:20 ` [PATCH v1 3/8] tests/functional/aarch64/test_aspeed_ast2700a1: " Jamin Lin
2026-08-04 8:20 ` [PATCH v1 4/8] tests/functional/aarch64/test_aspeed_ast2700fc: " Jamin Lin
2026-08-04 8:20 ` [PATCH v1 5/8] tests/functional/arm/test_aspeed_ast2600_sdk: " Jamin Lin
2026-08-04 8:20 ` [PATCH v1 6/8] tests/functional/arm/test_aspeed_ast2500_sdk: " Jamin Lin
2026-08-04 8:20 ` [PATCH v1 7/8] tests/functional/arm/test_aspeed_ast1030: Update ASPEED Zephyr SDK v03.08 Jamin Lin
2026-08-04 8:20 ` [PATCH v1 8/8] tests/functional/arm/test_aspeed_ast1060: Update ASPEED ZEPHYR PROJECT v03.07 Jamin Lin
2026-08-06 12:52 ` [PATCH v1 0/8] tests/functional/arm/test_aspeed: Update ASPEED SDK v11.03 Cédric Le Goater
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260804081955.1563537-2-jamin_lin@aspeedtech.com \
--to=jamin_lin@aspeedtech.com \
--cc=andrew@codeconstruct.com.au \
--cc=clg@kaod.org \
--cc=joel@jms.id.au \
--cc=kane_chen@aspeedtech.com \
--cc=leetroy@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=steven_lee@aspeedtech.com \
--cc=troy_lee@aspeedtech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.