xref: /qemu/include/hw/misc/ivshmem-flat.h (revision 8f5a4cfc7ed9e06e07fdd8e8fdf50ef3ea783f63)
1 /*
2  * Inter-VM Shared Memory Flat Device
3  *
4  * SPDX-FileCopyrightText: 2023 Linaro Ltd.
5  * SPDX-FileContributor: Gustavo Romero <gustavo.romero@linaro.org>
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  *
8  */
9 
10 #ifndef IVSHMEM_FLAT_H
11 #define IVSHMEM_FLAT_H
12 
13 #include "qemu/queue.h"
14 #include "qemu/event_notifier.h"
15 #include "chardev/char-fe.h"
16 #include "exec/memory.h"
17 #include "qom/object.h"
18 #include "hw/sysbus.h"
19 
20 #define IVSHMEM_MAX_VECTOR_NUM 64
21 
22 /*
23  * QEMU interface:
24  *  + QOM property "chardev" is the character device id of the ivshmem server
25  *    socket
26  *  + QOM property "shmem-size" sets the size of the RAM region shared between
27  *    the device and the ivshmem server
28  *  + sysbus MMIO region 0: device I/O mapped registers
29  *  + sysbus MMIO region 1: shared memory with ivshmem server
30  *  + sysbus IRQ 0: single output interrupt
31  */
32 
33 #define TYPE_IVSHMEM_FLAT "ivshmem-flat"
34 typedef struct IvshmemFTState IvshmemFTState;
35 
36 DECLARE_INSTANCE_CHECKER(IvshmemFTState, IVSHMEM_FLAT, TYPE_IVSHMEM_FLAT)
37 
38 /* Ivshmem registers. See ./docs/specs/ivshmem-spec.txt for details. */
39 enum ivshmem_registers {
40     INTMASK = 0,
41     INTSTATUS = 4,
42     IVPOSITION = 8,
43     DOORBELL = 12,
44 };
45 
46 typedef struct VectorInfo {
47     EventNotifier event_notifier;
48     uint16_t id;
49 } VectorInfo;
50 
51 typedef struct IvshmemPeer {
52     QTAILQ_ENTRY(IvshmemPeer) next;
53     VectorInfo vector[IVSHMEM_MAX_VECTOR_NUM];
54     int vector_counter;
55     uint16_t id;
56 } IvshmemPeer;
57 
58 struct IvshmemFTState {
59     SysBusDevice parent_obj;
60 
61     uint64_t msg_buf;
62     int msg_buffered_bytes;
63 
64     QTAILQ_HEAD(, IvshmemPeer) peer;
65     IvshmemPeer own;
66 
67     CharBackend server_chr;
68 
69     /* IRQ */
70     qemu_irq irq;
71 
72     /* I/O registers */
73     MemoryRegion iomem;
74     uint32_t intmask;
75     uint32_t intstatus;
76     uint32_t ivposition;
77     uint32_t doorbell;
78 
79     /* Shared memory */
80     MemoryRegion shmem;
81     int shmem_fd;
82     uint32_t shmem_size;
83 };
84 
85 #endif /* IVSHMEM_FLAT_H */
86