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