On 2/27/26 02:43, Jithu Joseph wrote:
Apologies for chiming in this late ... I only got a chance to test this last
week
This really is a minor comment ... can be addressed subsequently
No problem. It is not merged yet and fixes are expected.
On 2/24/2026 6:12 PM, Jamin Lin wrote:
Adds a simple i3c device to be used for testing in lieu of a real
device.
The mock target supports the following features:
- A buffer that users can read and write to.
- CCC support for commonly used CCCs when probing devices on an I3C bus.
- IBI sending upon receiving a user-defined byte.
Signed-off-by: Joe Komlodi <[email protected]>
Reviewed-by: Titus Rwantare <[email protected]>
Reviewed-by: Patrick Venture <[email protected]>
Reviewed-by: Jamin Lin <[email protected]>
Signed-off-by: Jamin Lin <[email protected]>
---
include/hw/i3c/mock-i3c-target.h | 52 ++++++
hw/i3c/mock-i3c-target.c | 298 +++++++++++++++++++++++++++++++
hw/i3c/Kconfig | 10 ++
hw/i3c/meson.build | 1 +
hw/i3c/trace-events | 10 ++
5 files changed, 371 insertions(+)
create mode 100644 include/hw/i3c/mock-i3c-target.h
create mode 100644 hw/i3c/mock-i3c-target.c
diff --git a/include/hw/i3c/mock-i3c-target.h b/include/hw/i3c/mock-i3c-target.h
new file mode 100644
...
+static int mock_i3c_target_tx(I3CTarget *i3c, const uint8_t *data,
+ uint32_t num_to_send, uint32_t *num_sent)
+{
+ MockI3cTargetState *s = MOCK_I3C_TARGET(i3c);
+ int ret;
+ uint32_t to_write;
+
+ if (s->cfg.ibi_magic && num_to_send == 1 && s->cfg.ibi_magic == *data) {
+ mock_i3c_target_ibi_timer_start(s);
+ return 0;
+ }
+
+ /* Bounds check. */
+ if (num_to_send + s->p_buf > s->cfg.buf_size) {
+ to_write = s->cfg.buf_size - s->p_buf;
+ ret = -1;
+ } else {
+ to_write = num_to_send;
+ ret = 0;
+ }
+ for (uint32_t i = 0; i < to_write; i++) {
+ trace_mock_i3c_target_tx(data[i]);
+ s->buf[s->p_buf] = data[i];
+ s->p_buf++;
+ }
num_sent is never updated prior to return, so the traces (from caller i3c_send)
looked a bit confusing
<snip>
mock_i3c_target_tx I3C mock target write 0x12
i3c_send I3C send 0/1 bytes, ack=1 ---------------------> instead of 1/1 bytes
mock_i3c_target_tx I3C mock target write 0x34
i3c_send I3C send 0/1 bytes, ack=1
</snip>
Something like below is needed
+ *num_sent = to_write
(might also needed in the ibi magic path above)
Please send a patch.
Thanks,
C.