cosim_pcie_proto.h 10.1 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

Antoine Kaufmann's avatar
Antoine Kaufmann committed
25
26
27
28
29
#ifndef COSIM_PCIE_PROTO_H_
#define COSIM_PCIE_PROTO_H_

#include <stdint.h>

30
31
32
33
//#define COSIM_PCI_MSG_SZCHECK(s) static_assert(sizeof(s) == 64)
//#define COSIM_PCI_MSG_SZCHECK(s) _Static_assert(sizeof(s) == 64)
#define COSIM_PCI_MSG_SZCHECK(s)

Antoine Kaufmann's avatar
Antoine Kaufmann committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/******************************************************************************/
/* Initialization messages on Unix socket */

/** in dev_intro.flags to indicate that sender supports issuing syncs. */
#define COSIM_PCIE_PROTO_FLAGS_DI_SYNC (1 << 0)

/** Number of PCI bars */
#define COSIM_PCIE_PROTO_NBARS 6

/** in bars.flags: this is an I/O port bar. (otherwise memory) */
#define COSIM_PCIE_PROTO_BAR_IO (1 << 0)
/** in bars.flags: this is a 64-bit bar. (otherwise 32-bit only) */
#define COSIM_PCIE_PROTO_BAR_64 (1 << 1)
/** in bars.flags: this memory bar is prefetchable */
#define COSIM_PCIE_PROTO_BAR_PF (1 << 2)
Antoine Kaufmann's avatar
Antoine Kaufmann committed
49
50
51
/** in bars.flags: this memory bar is a dummy bar (device doesn't get MMIO
 * messages for this, but it dose get exposed to software. used for MSI-X). */
#define COSIM_PCIE_PROTO_BAR_DUMMY (1 << 3)
Antoine Kaufmann's avatar
Antoine Kaufmann committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

/**
 * welcome message sent by device to host. This message comes with the shared
 * memory file descriptor attached.
 */
struct cosim_pcie_proto_dev_intro {
    /** flags: see COSIM_PCIE_PROTO_FLAGS_DI_* */
    uint64_t flags;

    /** offset of the device-to-host queue in shared memory region */
    uint64_t d2h_offset;
    /** size of an entry in the device-to-host queue in bytes */
    uint64_t d2h_elen;
    /** total device-to-host queue length in #entries */
    uint64_t d2h_nentries;

    /** offset of the host-to-device queue in shared memory region */
    uint64_t h2d_offset;
    /** size of an entry in the host-to-device queue in bytes */
    uint64_t h2d_elen;
    /** total host-to-device queue length in #entries */
    uint64_t h2d_nentries;

    /** information for each BAR exposed by the device */
    struct {
        /** length of the bar in bytes (len = 0 indicates unused bar) */
        uint64_t len;
        /** flags (see COSIM_PCIE_PROTO_BAR_*) */
        uint64_t flags;
    } __attribute__((packed)) bars[COSIM_PCIE_PROTO_NBARS];
82
83
84
85
86
87
88
89
90
91
92

    /** PCI vendor id */
    uint16_t pci_vendor_id;
    /** PCI device id */
    uint16_t pci_device_id;
    /* PCI class */
    uint8_t pci_class;
    /* PCI subclass */
    uint8_t pci_subclass;
    /* PCI revision */
    uint8_t pci_revision;
93

94
95
    /* PCI number of MSI vectors */
    uint8_t pci_msi_nvecs;
96
97
98
99
100
101
102
103
104
105
106
107
108

    /* PCI number of MSI-X vectors */
    uint16_t pci_msix_nvecs;
    /* BAR number for MSI-X table */
    uint8_t pci_msix_table_bar;
    /* BAR number for MSI-X PBA */
    uint8_t pci_msix_pba_bar;
    /* Offset for MSI-X table */
    uint32_t pci_msix_table_offset;
    /* Offset for MSI-X PBA */
    uint32_t pci_msix_pba_offset;
    /* MSI-X capability offset */
    uint16_t psi_msix_cap_offset;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
109
110
111
} __attribute__((packed));


Jialin Li's avatar
Jialin Li committed
112
#define COSIM_PCIE_PROTO_FLAGS_HI_SYNC (1 << 0)
Antoine Kaufmann's avatar
Antoine Kaufmann committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140

/** welcome message sent by host to device */
struct cosim_pcie_proto_host_intro {
    /** flags: see COSIM_PCIE_PROTO_FLAGS_HI_* */
  uint64_t flags;
} __attribute__((packed));


/******************************************************************************/
/* Messages on in-memory device to host channel */

/** Mask for ownership bit in own_type field */
#define COSIM_PCIE_PROTO_D2H_OWN_MASK 0x80
/** Message is owned by device */
#define COSIM_PCIE_PROTO_D2H_OWN_DEV 0x00
/** Message is owned by host */
#define COSIM_PCIE_PROTO_D2H_OWN_HOST 0x80

/** Mask for type value in own_type field */
#define COSIM_PCIE_PROTO_D2H_MSG_MASK 0x7f
#define COSIM_PCIE_PROTO_D2H_MSG_SYNC 0x1
#define COSIM_PCIE_PROTO_D2H_MSG_READ 0x2
#define COSIM_PCIE_PROTO_D2H_MSG_WRITE 0x3
#define COSIM_PCIE_PROTO_D2H_MSG_INTERRUPT 0x4
#define COSIM_PCIE_PROTO_D2H_MSG_READCOMP 0x5
#define COSIM_PCIE_PROTO_D2H_MSG_WRITECOMP 0x6

struct cosim_pcie_proto_d2h_dummy {
141
142
143
    uint8_t pad[48];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
144
145
    uint8_t own_type;
} __attribute__((packed));
146
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_dummy);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
147
148

struct cosim_pcie_proto_d2h_sync {
149
    uint8_t pad[48];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
150
    uint64_t timestamp;
151
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
152
153
    uint8_t own_type;
} __attribute__((packed));
154
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_sync);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
155
156
157
158
159

struct cosim_pcie_proto_d2h_read {
    uint64_t req_id;
    uint64_t offset;
    uint16_t len;
160
161
162
    uint8_t pad[30];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
163
164
    uint8_t own_type;
} __attribute__((packed));
165
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_read);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
166
167
168
169
170

struct cosim_pcie_proto_d2h_write {
    uint64_t req_id;
    uint64_t offset;
    uint16_t len;
171
172
173
    uint8_t pad[30];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
174
175
176
    uint8_t own_type;
    uint8_t data[];
} __attribute__((packed));
177
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_write);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
178
179
180
181
182
183
184
185
186

#define COSIM_PCIE_PROTO_INT_LEGACY_HI 0
#define COSIM_PCIE_PROTO_INT_LEGACY_LO 1
#define COSIM_PCIE_PROTO_INT_MSI 2
#define COSIM_PCIE_PROTO_INT_MSIX 3

struct cosim_pcie_proto_d2h_interrupt {
    uint16_t vector;
    uint8_t inttype;
187
188
189
    uint8_t pad[45];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
190
191
    uint8_t own_type;
} __attribute__((packed));
192
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_interrupt);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
193
194
195

struct cosim_pcie_proto_d2h_readcomp {
    uint64_t req_id;
196
197
198
    uint8_t pad[40];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
199
200
    uint8_t own_type;
    uint8_t data[];
201
202
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_readcomp);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
203
204
205

struct cosim_pcie_proto_d2h_writecomp {
    uint64_t req_id;
206
207
208
    uint8_t pad[40];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
209
    uint8_t own_type;
210
211
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_d2h_writecomp);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
212
213
214
215
216
217
218
219
220

union cosim_pcie_proto_d2h {
    struct cosim_pcie_proto_d2h_dummy dummy;
    struct cosim_pcie_proto_d2h_sync sync;
    struct cosim_pcie_proto_d2h_read read;
    struct cosim_pcie_proto_d2h_write write;
    struct cosim_pcie_proto_d2h_interrupt interrupt;
    struct cosim_pcie_proto_d2h_readcomp readcomp;
    struct cosim_pcie_proto_d2h_writecomp writecomp;
221
222
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(union cosim_pcie_proto_d2h);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239


/******************************************************************************/
/* Messages on in-memory host to device channel */

#define COSIM_PCIE_PROTO_H2D_OWN_MASK 0x80
/** Message is owned by host */
#define COSIM_PCIE_PROTO_H2D_OWN_HOST 0x00
/** Message is owned by device */
#define COSIM_PCIE_PROTO_H2D_OWN_DEV 0x80

#define COSIM_PCIE_PROTO_H2D_MSG_MASK 0x7f
#define COSIM_PCIE_PROTO_H2D_MSG_SYNC 0x1
#define COSIM_PCIE_PROTO_H2D_MSG_READ 0x2
#define COSIM_PCIE_PROTO_H2D_MSG_WRITE 0x3
#define COSIM_PCIE_PROTO_H2D_MSG_READCOMP 0x4
#define COSIM_PCIE_PROTO_H2D_MSG_WRITECOMP 0x5
Antoine Kaufmann's avatar
Antoine Kaufmann committed
240
#define COSIM_PCIE_PROTO_H2D_MSG_DEVCTRL 0x7
Antoine Kaufmann's avatar
Antoine Kaufmann committed
241
242

struct cosim_pcie_proto_h2d_dummy {
243
244
245
    uint8_t pad[48];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
246
247
    uint8_t own_type;
} __attribute__((packed));
248
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_dummy);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
249
250

struct cosim_pcie_proto_h2d_sync {
251
    uint8_t pad[48];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
252
    uint64_t timestamp;
253
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
254
255
    uint8_t own_type;
} __attribute__((packed));
256
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_sync);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
257
258
259
260
261
262

struct cosim_pcie_proto_h2d_read {
    uint64_t req_id;
    uint64_t offset;
    uint16_t len;
    uint8_t bar;
263
264
265
    uint8_t pad[29];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
266
267
    uint8_t own_type;
} __attribute__((packed));
268
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_read);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
269
270
271
272
273
274

struct cosim_pcie_proto_h2d_write {
    uint64_t req_id;
    uint64_t offset;
    uint16_t len;
    uint8_t bar;
275
276
277
    uint8_t pad[29];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
278
279
280
    uint8_t own_type;
    uint8_t data[];
} __attribute__((packed));
281
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_write);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
282
283
284

struct cosim_pcie_proto_h2d_readcomp {
    uint64_t req_id;
285
286
287
    uint8_t pad[40];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
288
289
    uint8_t own_type;
    uint8_t data[];
290
291
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_readcomp);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
292
293
294

struct cosim_pcie_proto_h2d_writecomp {
    uint64_t req_id;
295
296
297
    uint8_t pad[40];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
298
    uint8_t own_type;
299
300
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_writecomp);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
301

Antoine Kaufmann's avatar
Antoine Kaufmann committed
302
303
304
305
306
307
308
309
310
311
312
313
#define COSIM_PCIE_PROTO_CTRL_INTX_EN (1 << 0)
#define COSIM_PCIE_PROTO_CTRL_MSI_EN (1 << 1)
#define COSIM_PCIE_PROTO_CTRL_MSIX_EN (1 << 2)
struct cosim_pcie_proto_h2d_devctrl {
    uint64_t flags;
    uint8_t pad[40];
    uint64_t timestamp;
    uint8_t pad_[7];
    uint8_t own_type;
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(struct cosim_pcie_proto_h2d_devctrl);

Antoine Kaufmann's avatar
Antoine Kaufmann committed
314
315
316
317
318
319
320
union cosim_pcie_proto_h2d {
    struct cosim_pcie_proto_h2d_dummy dummy;
    struct cosim_pcie_proto_h2d_sync sync;
    struct cosim_pcie_proto_h2d_read read;
    struct cosim_pcie_proto_h2d_write write;
    struct cosim_pcie_proto_h2d_readcomp readcomp;
    struct cosim_pcie_proto_h2d_writecomp writecomp;
Antoine Kaufmann's avatar
Antoine Kaufmann committed
321
    struct cosim_pcie_proto_h2d_devctrl devctrl;
322
323
} __attribute__((packed));
COSIM_PCI_MSG_SZCHECK(union cosim_pcie_proto_h2d);
Antoine Kaufmann's avatar
Antoine Kaufmann committed
324
325

#endif /* ndef COSIM_PCIE_PROTO_H_ */