1*1be29345SJoe Komlodi #ifndef MOCK_I3C_TARGET_H_ 2*1be29345SJoe Komlodi #define MOCK_I3C_TARGET_H_ 3*1be29345SJoe Komlodi 4*1be29345SJoe Komlodi /* 5*1be29345SJoe Komlodi * Mock I3C Device 6*1be29345SJoe Komlodi * 7*1be29345SJoe Komlodi * Copyright (c) 2025 Google LLC 8*1be29345SJoe Komlodi * 9*1be29345SJoe Komlodi * The mock I3C device can be thought of as a simple EEPROM. It has a buffer, 10*1be29345SJoe Komlodi * and the pointer in the buffer is reset to 0 on an I3C STOP. 11*1be29345SJoe Komlodi * To write to the buffer, issue a private write and send data. 12*1be29345SJoe Komlodi * To read from the buffer, issue a private read. 13*1be29345SJoe Komlodi * 14*1be29345SJoe Komlodi * The mock target also supports sending target interrupt IBIs. 15*1be29345SJoe Komlodi * To issue an IBI, set the 'ibi-magic-num' property to a non-zero number, and 16*1be29345SJoe Komlodi * send that number in a private transaction. The mock target will issue an IBI 17*1be29345SJoe Komlodi * after 1 second. 18*1be29345SJoe Komlodi * 19*1be29345SJoe Komlodi * It also supports a handful of CCCs that are typically used when probing I3C 20*1be29345SJoe Komlodi * devices. 21*1be29345SJoe Komlodi * 22*1be29345SJoe Komlodi * SPDX-License-Identifier: GPL-2.0-or-later 23*1be29345SJoe Komlodi */ 24*1be29345SJoe Komlodi 25*1be29345SJoe Komlodi #include "qemu/osdep.h" 26*1be29345SJoe Komlodi #include "qemu/timer.h" 27*1be29345SJoe Komlodi #include "hw/i3c/i3c.h" 28*1be29345SJoe Komlodi 29*1be29345SJoe Komlodi #define TYPE_MOCK_I3C_TARGET "mock-i3c-target" 30*1be29345SJoe Komlodi OBJECT_DECLARE_SIMPLE_TYPE(MockI3cTargetState, MOCK_I3C_TARGET) 31*1be29345SJoe Komlodi 32*1be29345SJoe Komlodi struct MockI3cTargetState { 33*1be29345SJoe Komlodi I3CTarget i3c; 34*1be29345SJoe Komlodi 35*1be29345SJoe Komlodi /* General device state */ 36*1be29345SJoe Komlodi bool can_ibi; 37*1be29345SJoe Komlodi QEMUTimer qtimer; 38*1be29345SJoe Komlodi size_t p_buf; 39*1be29345SJoe Komlodi uint8_t *buf; 40*1be29345SJoe Komlodi 41*1be29345SJoe Komlodi /* For Handing CCCs. */ 42*1be29345SJoe Komlodi bool in_ccc; 43*1be29345SJoe Komlodi I3CCCC curr_ccc; 44*1be29345SJoe Komlodi uint8_t ccc_byte_offset; 45*1be29345SJoe Komlodi 46*1be29345SJoe Komlodi struct { 47*1be29345SJoe Komlodi uint32_t buf_size; 48*1be29345SJoe Komlodi uint8_t ibi_magic; 49*1be29345SJoe Komlodi } cfg; 50*1be29345SJoe Komlodi }; 51*1be29345SJoe Komlodi 52*1be29345SJoe Komlodi #endif 53