Skip to content

Conversation

ziuziakowska
Copy link

@ziuziakowska ziuziakowska commented Oct 7, 2025

This implements the I2C transport for QEMU in opentitanlib, and creates a test of Opentitan's I2C target mode that uses the functionality in a test harness.

In this test, a simple "memory" device is emulated by software, and can be interacted with over the I2C bus. The test harness performs transfers with the device, through the new OT I2C host proxy device in QEMU to interact with devices on the internal I2C bus, namely OT I2C. The software also listens to another I2C address, and exits the test successfully when written to with a magic value.

This depends on the I2C transport protocol and host proxy device implementation in QEMU - see lowRISC/qemu#190.

For now the test is QEMU-specific, but in theory this could also run on any other execution environments which already have an I2C transport implementation in opentitanlib, with little adaptation.

@ziuziakowska ziuziakowska changed the title [WIP] [sw,test] Create QEMU I2C Target Mode Test [WIP] [sw,opentitanlib] QEMU I2C transport and target mode test Oct 9, 2025
@ziuziakowska ziuziakowska changed the title [WIP] [sw,opentitanlib] QEMU I2C transport and target mode test [sw,opentitanlib] QEMU I2C transport and target mode test Oct 9, 2025
@ziuziakowska ziuziakowska force-pushed the qemu_i2c_target_mode branch 2 times, most recently from 50b78e5 to 8ca242c Compare October 10, 2025 08:59
@ziuziakowska ziuziakowska marked this pull request as ready for review October 10, 2025 09:00
@ziuziakowska ziuziakowska requested review from a team as code owners October 10, 2025 09:00
@ziuziakowska ziuziakowska requested review from timothytrippel and removed request for a team October 10, 2025 09:00
@ziuziakowska ziuziakowska requested a review from cfrantz as a code owner October 13, 2025 09:37
@ziuziakowska ziuziakowska requested a review from jwnrt October 13, 2025 10:43
Copy link
Contributor

@engdoreis engdoreis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ziuziakowska for this great work.
I left some suggestions to be considered.
I believe that this a valid new test, and I don't see a reason for not running it on the FPGA and Silicon as well.

This implements a I2C transport for QEMU.

The transport uses a PTY to communicate with a `ot-i2c_host_proxy`
device to issue transfers to devices on the internal QEMU I2C buses.

See `docs/opentitan/i2c_host_proxy.md` in QEMU for more imformation
on the protocol.

Signed-off-by: Alice Ziuziakowska <[email protected]>
@ziuziakowska
Copy link
Author

CI failure qemu-system-riscv32: -device ot-i2c_host_proxy,bus=ot-i2c0,chardev=i2c0: 'ot-i2c_host_proxy' is not a valid device model name is expected for the moment - this device was just merged, waiting on a new release.

@ziuziakowska ziuziakowska added the CI:Rerun Rerun failed CI jobs label Oct 17, 2025
@github-actions github-actions bot removed the CI:Rerun Rerun failed CI jobs label Oct 17, 2025
Copy link
Contributor

@AlexJones0 AlexJones0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a last couple comments I noticed but this looks great, thanks!

@ziuziakowska
Copy link
Author

CI failure looks unrelated.

Copy link
Contributor

@jwnrt jwnrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, thanks

If possible I'd appreciate a comment on the host side explaining that the 0x30 pointer is just some arbitrary location in the buffer and also that you're doing the try transactions out-of-order so that moving the pointer has some significance and it's not just following on from the previous write.

I think it might be clearer to me if you were to do two separate writes to different parts of the buffer instead of splitting one write, but I don't mind either way.

This creates a test for Opentitan's I2C target mode for QEMU, using a
test harness that utilises the I2C QEMU transport implemented in the
previous commit.

The tested device emulates a simple "memory" device on each I2C bus.

The device consists of a 256-byte "memory". On a write transfer to the
device, the first byte sets the "pointer" to within the memory where
subsequent bytes are written to or read from. This value is incremented
after each written or read byte. During a read transfer, bytes from
memory to be read are buffered in the TX FIFO, which is refilled if its
fill level drops below a threshold.

The test harness uses the I2C host proxy device in QEMU to issue
transfers to write to and read from the emulated memory device.

Signed-off-by: Alice Ziuziakowska <[email protected]>
Pulls in recently merged `ot-i2c_host_proxy` device.

Signed-off-by: Alice Ziuziakowska <[email protected]>
@jwnrt
Copy link
Contributor

jwnrt commented Oct 17, 2025

CI FPGA failures are unrelated

@jwnrt jwnrt merged commit 74490a7 into lowRISC:earlgrey_1.0.0 Oct 17, 2025
32 of 34 checks passed
@ziuziakowska ziuziakowska deleted the qemu_i2c_target_mode branch October 17, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants