drivers: virtualization: Add interface for ivshmem-v2

ivshmem-v2 is primarily used for IPC in the Jailhouse hypervisor

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
This commit is contained in:
Grant Ramsay 2023-04-30 14:34:35 +12:00 committed by Christopher Friedt
commit 4ed404a27f
5 changed files with 259 additions and 4 deletions

View file

@ -28,10 +28,9 @@ source "subsys/logging/Kconfig.template.log_config"
config IVSHMEM_DOORBELL
bool "Support interrupt based ivshmem (doorbell version)"
depends on PCIE_MSI_X && PCIE_MSI_MULTI_VECTOR
help
This will enable support of ivshmem-doorbell, i.e. the interrupt
based ivshmem.
based ivshmem. For ivshmem-v2 INTx interrupts are also supported.
config IVSHMEM_MSI_X_VECTORS
int "How many notification vectors should be pre-allocated?"
@ -44,11 +43,12 @@ config IVSHMEM_MSI_X_VECTORS
ivshmem.
config IVSHMEM_INT_PRIORITY
int "Interrupt priority"
int "MSI-X interrupt priority"
default 2
depends on IVSHMEM_DOORBELL
help
Interrupt priority used for the MSI-X generated interrupts.
INTx interrupt priority is configured in the device tree.
config IVSHMEM_SHELL
bool "IVshmem shell module"
@ -59,4 +59,11 @@ config IVSHMEM_SHELL
endif # IVSHMEM
config IVSHMEM_V2
bool "Inter-VM shared memory v2 (ivshmem-v2)"
select IVSHMEM
help
Enable ivshmem-v2 support.
ivshmem-v2 is primarily used for IPC in the Jailhouse hypervisor.
endif # VIRTUALIZATION

View file

@ -13,9 +13,30 @@
#include <zephyr/drivers/pcie/msi.h>
#endif
#define PCIE_CONF_CMDSTAT_INTX_DISABLE 0x0400
#define PCIE_CONF_INTR_PIN(x) (((x) >> 8) & 0xFFu)
#define IVSHMEM_CFG_ID 0x00
#define IVSHMEM_CFG_NEXT_CAP 0x01
#define IVSHMEM_CFG_LENGTH 0x02
#define IVSHMEM_CFG_PRIV_CNTL 0x03
#define IVSHMEM_PRIV_CNTL_ONESHOT_INT BIT(0)
#define IVSHMEM_CFG_STATE_TAB_SZ 0x04
#define IVSHMEM_CFG_RW_SECTION_SZ 0x08
#define IVSHMEM_CFG_OUTPUT_SECTION_SZ 0x10
#define IVSHMEM_CFG_ADDRESS 0x18
#define IVSHMEM_INT_ENABLE BIT(0)
#define IVSHMEM_PCIE_REG_BAR_IDX 0
#define IVSHMEM_PCIE_MSI_X_BAR_IDX 1
#define IVSHMEM_PCIE_SHMEM_BAR_IDX 2
#define PCIE_INTX_PIN_MIN 1
#define PCIE_INTX_PIN_MAX 4
#define INTX_IRQ_UNUSED UINT32_MAX
struct ivshmem_param {
const struct device *dev;
struct k_poll_signal *signal;
@ -32,6 +53,14 @@ struct ivshmem {
struct ivshmem_param params[CONFIG_IVSHMEM_MSI_X_VECTORS];
uint16_t n_vectors;
#endif
#ifdef CONFIG_IVSHMEM_V2
bool ivshmem_v2;
uint32_t max_peers;
size_t rw_section_size;
size_t rw_section_offset;
size_t output_section_size;
size_t output_section_offset;
#endif
};
struct ivshmem_reg {
@ -41,6 +70,26 @@ struct ivshmem_reg {
uint32_t doorbell;
};
#ifdef CONFIG_IVSHMEM_V2
struct ivshmem_v2_reg {
uint32_t id;
uint32_t max_peers;
uint32_t int_control;
uint32_t doorbell;
uint32_t state;
};
struct ivshmem_cfg {
struct intx_info {
uint32_t irq;
uint32_t priority;
uint32_t flags;
} intx_info[PCIE_INTX_PIN_MAX];
};
#endif /* CONFIG_IVSHMEM_V2 */
#define IVSHMEM_GEN_DOORBELL(i, v) ((i << 16) | (v & 0xFFFF))
#endif /* ZEPHYR_DRIVERS_VIRTUALIZATION_VIRT_IVSHMEM_H_ */