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