aboutsummaryrefslogtreecommitdiff
path: root/include/hw/misc/ivshmem-flat.h
blob: 0c2b01578121ae8686cad3ef0ba81e18e3a6a662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
82
83
84
85
86
/*
 * Inter-VM Shared Memory Flat Device
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright (c) 2023 Linaro Ltd.
 * Authors:
 *   Gustavo Romero
 *
 */

#ifndef IVSHMEM_FLAT_H
#define IVSHMEM_FLAT_H

#include "qemu/queue.h"
#include "qemu/event_notifier.h"
#include "chardev/char-fe.h"
#include "exec/memory.h"
#include "qom/object.h"
#include "hw/sysbus.h"

#define IVSHMEM_MAX_VECTOR_NUM 64

/*
 * QEMU interface:
 *  + QOM property "chardev" is the character device id of the ivshmem server
 *    socket
 *  + QOM property "shmem-size" sets the size of the RAM region shared between
 *    the device and the ivshmem server
 *  + sysbus MMIO region 0: device I/O mapped registers
 *  + sysbus MMIO region 1: shared memory with ivshmem server
 *  + sysbus IRQ 0: single output interrupt
 */

#define TYPE_IVSHMEM_FLAT "ivshmem-flat"
typedef struct IvshmemFTState IvshmemFTState;

DECLARE_INSTANCE_CHECKER(IvshmemFTState, IVSHMEM_FLAT, TYPE_IVSHMEM_FLAT)

/* Ivshmem registers. See ./docs/specs/ivshmem-spec.txt for details. */
enum ivshmem_registers {
    INTMASK = 0,
    INTSTATUS = 4,
    IVPOSITION = 8,
    DOORBELL = 12,
};

typedef struct VectorInfo {
    EventNotifier event_notifier;
    uint16_t id;
} VectorInfo;

typedef struct IvshmemPeer {
    QTAILQ_ENTRY(IvshmemPeer) next;
    VectorInfo vector[IVSHMEM_MAX_VECTOR_NUM];
    int vector_counter;
    uint16_t id;
} IvshmemPeer;

struct IvshmemFTState {
    SysBusDevice parent_obj;

    uint64_t msg_buf;
    int msg_buffered_bytes;

    QTAILQ_HEAD(, IvshmemPeer) peer;
    IvshmemPeer own;

    CharBackend server_chr;

    /* IRQ */
    qemu_irq irq;

    /* I/O registers */
    MemoryRegion iomem;
    uint32_t intmask;
    uint32_t intstatus;
    uint32_t ivposition;
    uint32_t doorbell;

    /* Shared memory */
    MemoryRegion shmem;
    int shmem_fd;
    uint32_t shmem_size;
};

#endif /* IVSHMEM_FLAT_H */