xref: /openbmc/qemu/include/hw/i3c/mock-target.h (revision c6fd2f5f0e58d243b3423aff23d081adc61350c8)
1*c6fd2f5fSJoe Komlodi #ifndef MOCK_TARGET_H_
2*c6fd2f5fSJoe Komlodi #define MOCK_TARGET_H_
3*c6fd2f5fSJoe Komlodi 
4*c6fd2f5fSJoe Komlodi /*
5*c6fd2f5fSJoe Komlodi  * Mock I3C Device
6*c6fd2f5fSJoe Komlodi  *
7*c6fd2f5fSJoe Komlodi  * Copyright (c) 2023 Google LLC
8*c6fd2f5fSJoe Komlodi  *
9*c6fd2f5fSJoe Komlodi  * The mock I3C device can be thought of as a simple EEPROM. It has a buffer,
10*c6fd2f5fSJoe Komlodi  * and the pointer in the buffer is reset to 0 on an I3C STOP.
11*c6fd2f5fSJoe Komlodi  * To write to the buffer, issue a private write and send data.
12*c6fd2f5fSJoe Komlodi  * To read from the buffer, issue a private read.
13*c6fd2f5fSJoe Komlodi  *
14*c6fd2f5fSJoe Komlodi  * The mock target also supports sending target interrupt IBIs.
15*c6fd2f5fSJoe Komlodi  * To issue an IBI, set the 'ibi-magic-num' property to a non-zero number, and
16*c6fd2f5fSJoe Komlodi  * send that number in a private transaction. The mock target will issue an IBI
17*c6fd2f5fSJoe Komlodi  * after 1 second.
18*c6fd2f5fSJoe Komlodi  *
19*c6fd2f5fSJoe Komlodi  * It also supports a handful of CCCs that are typically used when probing I3C
20*c6fd2f5fSJoe Komlodi  * devices.
21*c6fd2f5fSJoe Komlodi  *
22*c6fd2f5fSJoe Komlodi  * This program is free software; you can redistribute it and/or modify it
23*c6fd2f5fSJoe Komlodi  * under the terms of the GNU General Public License as published by the
24*c6fd2f5fSJoe Komlodi  * Free Software Foundation; either version 2 of the License, or
25*c6fd2f5fSJoe Komlodi  * (at your option) any later version.
26*c6fd2f5fSJoe Komlodi  *
27*c6fd2f5fSJoe Komlodi  * This program is distributed in the hope that it will be useful, but WITHOUT
28*c6fd2f5fSJoe Komlodi  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29*c6fd2f5fSJoe Komlodi  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
30*c6fd2f5fSJoe Komlodi  * for more details.
31*c6fd2f5fSJoe Komlodi  */
32*c6fd2f5fSJoe Komlodi 
33*c6fd2f5fSJoe Komlodi #include "qemu/osdep.h"
34*c6fd2f5fSJoe Komlodi #include "qemu/timer.h"
35*c6fd2f5fSJoe Komlodi #include "hw/i3c/i3c.h"
36*c6fd2f5fSJoe Komlodi 
37*c6fd2f5fSJoe Komlodi #define TYPE_MOCK_TARGET "mock-target"
38*c6fd2f5fSJoe Komlodi OBJECT_DECLARE_SIMPLE_TYPE(MockTargetState, MOCK_TARGET)
39*c6fd2f5fSJoe Komlodi 
40*c6fd2f5fSJoe Komlodi struct MockTargetState {
41*c6fd2f5fSJoe Komlodi     I3CTarget i3c;
42*c6fd2f5fSJoe Komlodi 
43*c6fd2f5fSJoe Komlodi     /* General device state */
44*c6fd2f5fSJoe Komlodi     bool can_ibi;
45*c6fd2f5fSJoe Komlodi     QEMUTimer qtimer;
46*c6fd2f5fSJoe Komlodi     size_t p_buf;
47*c6fd2f5fSJoe Komlodi     uint8_t *buf;
48*c6fd2f5fSJoe Komlodi 
49*c6fd2f5fSJoe Komlodi     /* For Handing CCCs. */
50*c6fd2f5fSJoe Komlodi     bool in_ccc;
51*c6fd2f5fSJoe Komlodi     I3CCCC curr_ccc;
52*c6fd2f5fSJoe Komlodi     uint8_t ccc_byte_offset;
53*c6fd2f5fSJoe Komlodi 
54*c6fd2f5fSJoe Komlodi     struct {
55*c6fd2f5fSJoe Komlodi         uint32_t buf_size;
56*c6fd2f5fSJoe Komlodi         uint8_t ibi_magic;
57*c6fd2f5fSJoe Komlodi     } cfg;
58*c6fd2f5fSJoe Komlodi };
59*c6fd2f5fSJoe Komlodi 
60*c6fd2f5fSJoe Komlodi #endif
61