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 *