From 92f9f5a4f3674234e676c09127a087beecde6d50 Mon Sep 17 00:00:00 2001 From: Yuan Liu Date: Fri, 14 Aug 2020 12:08:22 +0800 Subject: [PATCH] hv: add ivshmem device Ivshmem device is used for shared memory based communication between pre-launched/post-launched VMs. this patch implements ivshmem device configuration space initialization and ivshmem device operation methods. v2: introduce init_one_pcibar interface to simplify BAR initialization operation of HV emulated PCI device. v3: 1) due to init_one_pcibar API is only used for pre-launched VM vdevs it can't be applied to all vdevs, so remove it. 2) move ivshmem BARs initialization to subsequent patch, this patch only introduce ivshmem configuration space initialization. Tracked-On: #4853 Signed-off-by: Yuan Liu Acked-by: Eddie Dong --- hypervisor/dm/vpci/ivshmem.c | 48 +++++++++++++++++++++++++++++++++ hypervisor/include/dm/ivshmem.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/hypervisor/dm/vpci/ivshmem.c b/hypervisor/dm/vpci/ivshmem.c index 42e34fa9e..801f336e8 100644 --- a/hypervisor/dm/vpci/ivshmem.c +++ b/hypervisor/dm/vpci/ivshmem.c @@ -12,6 +12,12 @@ #include #include "vpci_priv.h" +/* config space of ivshmem device */ +#define IVSHMEM_VENDOR_ID 0x1af4U +#define IVSHMEM_DEVICE_ID 0x1110U +#define IVSHMEM_CLASS 0x05U +#define IVSHMEM_REV 0x01U + /* IVSHMEM_SHM_SIZE is provided by offline tool */ static uint8_t ivshmem_base[IVSHMEM_SHM_SIZE] __aligned(PDE_SIZE); @@ -26,4 +32,46 @@ void init_ivshmem_shared_memory() } } +static int32_t read_ivshmem_vdev_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) +{ + /* Implementation in next patch */ + (void) vdev; + (void) offset; + (void) bytes; + (void) val; + return 0; +} + +static int32_t write_ivshmem_vdev_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val) +{ + /* Implementation in next patch */ + (void) vdev; + (void) offset; + (void) bytes; + (void) val; + return 0; +} + +static void init_ivshmem_vdev(struct pci_vdev *vdev) +{ + /* initialize ivshmem config */ + pci_vdev_write_vcfg(vdev, PCIR_VENDOR, 2U, IVSHMEM_VENDOR_ID); + pci_vdev_write_vcfg(vdev, PCIR_DEVICE, 2U, IVSHMEM_DEVICE_ID); + pci_vdev_write_vcfg(vdev, PCIR_REVID, 1U, IVSHMEM_REV); + pci_vdev_write_vcfg(vdev, PCIR_CLASS, 1U, IVSHMEM_CLASS); + + vdev->user = vdev; +} + +static void deinit_ivshmem_vdev(struct pci_vdev *vdev) +{ + vdev->user = NULL; +} + +const struct pci_vdev_ops vpci_ivshmem_ops = { + .init_vdev = init_ivshmem_vdev, + .deinit_vdev = deinit_ivshmem_vdev, + .write_vdev_cfg = write_ivshmem_vdev_cfg, + .read_vdev_cfg = read_ivshmem_vdev_cfg, +}; #endif diff --git a/hypervisor/include/dm/ivshmem.h b/hypervisor/include/dm/ivshmem.h index 7a8020b38..fd6bfe1e2 100644 --- a/hypervisor/include/dm/ivshmem.h +++ b/hypervisor/include/dm/ivshmem.h @@ -14,6 +14,8 @@ struct ivshmem_shm_region { uint64_t size; }; +extern const struct pci_vdev_ops vpci_ivshmem_ops; + /** * @brief Initialize ivshmem shared memory regions *