Skip to content

Commit 657af92

Browse files
yliu80wenlingz
authored andcommitted
hv: passthrough a VF device
Emulate Device ID, Vendor ID and MSE(Memory Space Enable) bit in configuration space for an assigned VF, initialize assgined VF Bars. The Device ID comes from PF's SRIOV capability The Vendor ID comes from PF's Vendor ID The PCI MSE bit always be set when VM reads from an assigned VF. Tracked-On: #4433 Signed-off-by: Yuan Liu <yuan1.liu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 640cf57 commit 657af92

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

hypervisor/dm/vpci/pci_pt.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,5 +387,18 @@ void init_vdev_pt(struct pci_vdev *vdev, bool is_pf_vdev)
387387
pci_command |= 0x400U;
388388
pci_pdev_write_cfg(vdev->pdev->bdf, PCIR_COMMAND, 2U, pci_command);
389389
}
390+
} else {
391+
/* VF is assigned to a UOS */
392+
if (vdev->vpci != vdev->phyfun->vpci) {
393+
uint32_t vid, did;
394+
395+
vdev->nr_bars = PCI_BAR_COUNT;
396+
/* SRIOV VF Vendor ID and Device ID initialization */
397+
vid = pci_pdev_read_cfg(vdev->phyfun->bdf, PCIR_VENDOR, 2U);
398+
did = pci_pdev_read_cfg(vdev->phyfun->bdf,
399+
(vdev->phyfun->sriov.capoff + PCIR_SRIOV_VF_DEV_ID), 2U);
400+
pci_vdev_write_vcfg(vdev, PCIR_VENDOR, 2U, vid);
401+
pci_vdev_write_vcfg(vdev, PCIR_DEVICE, 2U, did);
402+
}
390403
}
391404
}

hypervisor/dm/vpci/vpci.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ static void read_cfg_header(const struct pci_vdev *vdev,
425425
} else {
426426
if (bitmap32_test(((uint16_t)offset) >> 2U, &cfg_hdr_perm.pt_mask)) {
427427
*val = pci_pdev_read_cfg(vdev->pdev->bdf, offset, bytes);
428+
429+
/* MSE(Memory Space Enable) bit always be set for an assigned VF */
430+
if ((vdev->phyfun != NULL) && (offset == PCIR_COMMAND) &&
431+
(vdev->vpci != vdev->phyfun->vpci)) {
432+
*val |= PCIM_CMD_MEMEN;
433+
}
428434
} else {
429435
*val = pci_vdev_read_vcfg(vdev, offset, bytes);
430436
}
@@ -721,10 +727,18 @@ int32_t vpci_assign_pcidev(struct acrn_vm *tgt_vm, struct acrn_assign_pcidev *pc
721727
vdev_in_sos->vpci = vpci;
722728

723729
spinlock_obtain(&tgt_vm->vpci.lock);
724-
vdev = vpci_init_vdev(vpci, vdev_in_sos->pci_dev_config, NULL);
730+
vdev = vpci_init_vdev(vpci, vdev_in_sos->pci_dev_config, vdev_in_sos->phyfun);
725731
pci_vdev_write_vcfg(vdev, PCIR_INTERRUPT_LINE, 1U, pcidev->intr_line);
726732
pci_vdev_write_vcfg(vdev, PCIR_INTERRUPT_PIN, 1U, pcidev->intr_pin);
727733
for (idx = 0U; idx < vdev->nr_bars; idx++) {
734+
/* VF is assigned to a UOS */
735+
if (vdev->phyfun != NULL) {
736+
vdev->vbars[idx] = vdev_in_sos->vbars[idx];
737+
if (has_msix_cap(vdev) && (idx == vdev->msix.table_bar)) {
738+
vdev->msix.mmio_hpa = vdev->vbars[idx].base_hpa;
739+
vdev->msix.mmio_size = vdev->vbars[idx].size;
740+
}
741+
}
728742
pci_vdev_write_vbar(vdev, idx, pcidev->bar[idx]);
729743
}
730744

hypervisor/include/hw/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#define PCIR_SRIOV_NUMVFS 0x10U
123123
#define PCIR_SRIOV_FST_VF_OFF 0x14U
124124
#define PCIR_SRIOV_VF_STRIDE 0x16U
125+
#define PCIR_SRIOV_VF_DEV_ID 0x1AU
125126
#define PCIR_SRIOV_VF_BAR_OFF 0x24U
126127
#define PCIM_SRIOV_VF_ENABLE 0x1U
127128

0 commit comments

Comments
 (0)