1
2
3
4
5
6
7
8
9#ifndef REMOTE_PORT_H__
10#define REMOTE_PORT_H__
11
12#include <stdbool.h>
13#include "hw/remote-port-proto.h"
14#include "hw/remote-port-device.h"
15#include "chardev/char.h"
16#include "chardev/char-fe.h"
17#include "hw/ptimer.h"
18
19#define TYPE_REMOTE_PORT "remote-port"
20#define REMOTE_PORT(obj) OBJECT_CHECK(RemotePort, (obj), TYPE_REMOTE_PORT)
21
22typedef struct RemotePortRespSlot {
23 RemotePortDynPkt rsp;
24 uint32_t id;
25 bool used;
26 bool valid;
27} RemotePortRespSlot;
28
29struct RemotePort {
30 DeviceState parent;
31
32 QemuThread thread;
33 union {
34 int pipes[2];
35 struct {
36 int read;
37 int write;
38 } pipe;
39 } event;
40 Chardev *chrdev;
41 CharBackend chr;
42 bool do_sync;
43 bool doing_sync;
44 bool finalizing;
45
46 QemuMutex write_mutex;
47
48 char *chardesc;
49 char *chrdev_id;
50 struct rp_peer_state peer;
51
52 struct {
53 ptimer_state *ptimer;
54 ptimer_state *ptimer_resp;
55 bool resp_timer_enabled;
56 bool need_sync;
57 struct rp_pkt rsp;
58 uint64_t quantum;
59 } sync;
60
61 QemuMutex rsp_mutex;
62 QemuCond progress_cond;
63
64#define RX_QUEUE_SIZE 1024
65 struct {
66
67 RemotePortDynPkt pkt[RX_QUEUE_SIZE];
68 bool inuse[RX_QUEUE_SIZE];
69 QemuSemaphore sem;
70 unsigned int wpos;
71 unsigned int rpos;
72 } rx_queue;
73
74
75
76
77
78 RemotePortDynPkt rsp;
79
80
81
82
83
84
85 RemotePortDynPkt rspqueue;
86
87 bool resets[32];
88
89 const char *prefix;
90 const char *remote_prefix;
91
92 uint32_t current_id;
93
94#define REMOTE_PORT_MAX_DEVS 1024
95#define RP_MAX_OUTSTANDING_TRANSACTIONS 32
96 struct {
97 RemotePortRespSlot rsp_queue[RP_MAX_OUTSTANDING_TRANSACTIONS];
98 } dev_state[REMOTE_PORT_MAX_DEVS];
99
100 RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS];
101};
102
103
104
105
106
107
108
109
110
111
112
113
114void rp_device_attach(Object *adaptor, Object *dev,
115 int rp_nr, int dev_nr,
116 Error **errp);
117void rp_device_detach(Object *adaptor, Object *dev,
118 int rp_nr, int dev_nr,
119 Error **errp);
120bool rp_time_warp_enable(bool en);
121
122
123
124
125
126
127
128
129
130
131bool rp_device_add(QemuOpts *opts, DeviceState *dev, Error **errp);
132
133static inline void rp_resp_slot_done(RemotePort *s,
134 RemotePortRespSlot *rsp_slot)
135{
136 rp_dpkt_invalidate(&rsp_slot->rsp);
137 rsp_slot->id = ~0;
138 rsp_slot->used = false;
139 rsp_slot->valid = false;
140}
141
142RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t id);
143void rp_process(RemotePort *s);
144
145#endif
146