diff --git a/hypervisor/dm/vpci/ivshmem.c b/hypervisor/dm/vpci/ivshmem.c index cf039ba50..034bb0da7 100644 --- a/hypervisor/dm/vpci/ivshmem.c +++ b/hypervisor/dm/vpci/ivshmem.c @@ -221,7 +221,7 @@ static int32_t ivshmem_mmio_handler(struct io_request *io_req, void *data) return 0; } -static int32_t read_ivshmem_vdev_cfg(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) +static int32_t read_ivshmem_vdev_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { *val = pci_vdev_read_vcfg(vdev, offset, bytes); diff --git a/hypervisor/dm/vpci/pci_pt.c b/hypervisor/dm/vpci/pci_pt.c index 9d46eccec..4a9568bbc 100644 --- a/hypervisor/dm/vpci/pci_pt.c +++ b/hypervisor/dm/vpci/pci_pt.c @@ -47,6 +47,21 @@ static inline struct msix_table_entry *get_msix_table_entry(const struct pci_vde return ((struct msix_table_entry *)hva + index); } +/** + * @brief Reading MSI-X Capability Structure + * + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ +void read_pt_vmsix_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) +{ + if (vdev->msix.is_vmsix_on_msi) { + *val = pci_vdev_read_vcfg(vdev, offset, bytes); + } else { + read_vmsix_cap_reg(vdev, offset, bytes, val); + } +} + /** * @brief Writing MSI-X Capability Structure * diff --git a/hypervisor/dm/vpci/vhostbridge.c b/hypervisor/dm/vpci/vhostbridge.c index 1e9be1fe2..3ec221a75 100644 --- a/hypervisor/dm/vpci/vhostbridge.c +++ b/hypervisor/dm/vpci/vhostbridge.c @@ -146,7 +146,7 @@ static void deinit_vhostbridge(__unused struct pci_vdev *vdev) * @pre vdev != NULL * @pre vdev->vpci != NULL */ -static int32_t read_vhostbridge_cfg(const struct pci_vdev *vdev, uint32_t offset, +static int32_t read_vhostbridge_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { *val = pci_vdev_read_vcfg(vdev, offset, bytes); diff --git a/hypervisor/dm/vpci/vmcs9900.c b/hypervisor/dm/vpci/vmcs9900.c index 9f29da768..61e72dd44 100644 --- a/hypervisor/dm/vpci/vmcs9900.c +++ b/hypervisor/dm/vpci/vmcs9900.c @@ -12,8 +12,8 @@ #include "vpci_priv.h" #include -#define MCS9900_MMIO_BAR 0U -#define MCS9900_MSIX_BAR 1U +#define MCS9900_MMIO_BAR 0U +#define MCS9900_MSIX_BAR 1U /* * @pre vdev != NULL @@ -32,12 +32,10 @@ void trigger_vmcs9900_msix(struct pci_vdev *vdev) } } -static int32_t read_vmcs9900_cfg(const struct pci_vdev *vdev, - uint32_t offset, uint32_t bytes, - uint32_t * val) +static int32_t read_vmcs9900_cfg(struct pci_vdev *vdev, + uint32_t offset, uint32_t bytes, uint32_t * val) { *val = pci_vdev_read_vcfg(vdev, offset, bytes); - return 0; } diff --git a/hypervisor/dm/vpci/vmsix.c b/hypervisor/dm/vpci/vmsix.c index 2ae6f2062..3b262017d 100644 --- a/hypervisor/dm/vpci/vmsix.c +++ b/hypervisor/dm/vpci/vmsix.c @@ -34,6 +34,34 @@ #include #include "vpci_priv.h" +/** + * @brief Reading MSI-X Capability Structure + * + * @pre vdev != NULL + * @pre vdev->pdev != NULL + */ +void read_vmsix_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) +{ + static const uint8_t msix_pt_mask[12U] = { + 0x0U, 0x0U, 0xffU, 0xffU }; /* Only PT MSI-X Message Control Register */ + uint32_t virt, phy = 0U, ctrl, pt_mask = 0U; + + virt = pci_vdev_read_vcfg(vdev, offset, bytes); + (void)memcpy_s((void *)&pt_mask, bytes, (void *)&msix_pt_mask[offset - vdev->msix.capoff], bytes); + if (pt_mask != 0U) { + phy = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes); + ctrl = pci_pdev_read_cfg(vdev->pdev->bdf, vdev->msix.capoff + PCIR_MSIX_CTRL, 2U); + if (((ctrl & PCIM_MSIXCTRL_TABLE_SIZE) + 1U) != vdev->msix.table_count) { + vdev->msix.table_count = (ctrl & PCIM_MSIXCTRL_TABLE_SIZE) + 1U; + pr_info("%s reprogram MSI-X Table Size to %d\n", __func__, vdev->msix.table_count); + /*In this case, we don't need to unmap msix EPT mapping again. */ + ASSERT(vdev->msix.table_count <= (PAGE_SIZE/ MSIX_TABLE_ENTRY_SIZE), ""); + } + } + + *val = (virt & ~pt_mask) | (phy & pt_mask); +} + /** * @brief Writing MSI-X Capability Structure * diff --git a/hypervisor/dm/vpci/vpci.c b/hypervisor/dm/vpci/vpci.c index f07060d39..f565f1912 100644 --- a/hypervisor/dm/vpci/vpci.c +++ b/hypervisor/dm/vpci/vpci.c @@ -532,15 +532,17 @@ static int32_t write_pt_dev_cfg(struct pci_vdev *vdev, uint32_t offset, return ret; } -static int32_t read_pt_dev_cfg(const struct pci_vdev *vdev, uint32_t offset, +static int32_t read_pt_dev_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { int32_t ret = 0; if (cfg_header_access(offset)) { read_cfg_header(vdev, offset, bytes, val); - } else if (msicap_access(vdev, offset) || msixcap_access(vdev, offset)) { + } else if (msicap_access(vdev, offset)) { *val = pci_vdev_read_vcfg(vdev, offset, bytes); + } else if (msixcap_access(vdev, offset)) { + read_pt_vmsix_cap_reg(vdev, offset, bytes, val); } else if (sriovcap_access(vdev, offset)) { read_sriov_cap_reg(vdev, offset, bytes, val); } else { diff --git a/hypervisor/dm/vpci/vpci_bridge.c b/hypervisor/dm/vpci/vpci_bridge.c index 05480696a..088b906ea 100644 --- a/hypervisor/dm/vpci/vpci_bridge.c +++ b/hypervisor/dm/vpci/vpci_bridge.c @@ -80,7 +80,7 @@ static void deinit_vpci_bridge(__unused struct pci_vdev *vdev) vdev->user = NULL; } -static int32_t read_vpci_bridge_cfg(const struct pci_vdev *vdev, uint32_t offset, +static int32_t read_vpci_bridge_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { if ((offset + bytes) <= 0x100U) { diff --git a/hypervisor/dm/vpci/vpci_priv.h b/hypervisor/dm/vpci/vpci_priv.h index decf2c865..07ac3f2d5 100644 --- a/hypervisor/dm/vpci/vpci_priv.h +++ b/hypervisor/dm/vpci/vpci_priv.h @@ -153,7 +153,9 @@ void deinit_vmsi(const struct pci_vdev *vdev); void init_vmsix_pt(struct pci_vdev *vdev); int32_t add_vmsix_capability(struct pci_vdev *vdev, uint32_t entry_num, uint8_t bar_num); +void read_vmsix_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val); bool write_vmsix_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val); +void read_pt_vmsix_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val); void write_pt_vmsix_cap_reg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val); uint32_t rw_vmsix_table(struct pci_vdev *vdev, struct io_request *io_req); int32_t vmsix_handle_table_mmio_access(struct io_request *io_req, void *priv_data); diff --git a/hypervisor/dm/vpci/vroot_port.c b/hypervisor/dm/vpci/vroot_port.c index 1c738b008..8327b4866 100644 --- a/hypervisor/dm/vpci/vroot_port.c +++ b/hypervisor/dm/vpci/vroot_port.c @@ -76,7 +76,7 @@ static void deinit_vrp(__unused struct pci_vdev *vdev) vdev->user = NULL; } -static int32_t read_vrp_cfg(const struct pci_vdev *vdev, uint32_t offset, +static int32_t read_vrp_cfg(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val) { *val = pci_vdev_read_vcfg(vdev, offset, bytes); diff --git a/hypervisor/include/dm/vpci.h b/hypervisor/include/dm/vpci.h index 9c12cd1fe..12498866c 100644 --- a/hypervisor/include/dm/vpci.h +++ b/hypervisor/include/dm/vpci.h @@ -104,7 +104,7 @@ struct pci_vdev_ops { void (*init_vdev)(struct pci_vdev *vdev); void (*deinit_vdev)(struct pci_vdev *vdev); int32_t (*write_vdev_cfg)(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t val); - int32_t (*read_vdev_cfg)(const struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val); + int32_t (*read_vdev_cfg)(struct pci_vdev *vdev, uint32_t offset, uint32_t bytes, uint32_t *val); }; struct pci_vdev {