From 721c866d63f358bf27f9060dddd5a4e74037b121 Mon Sep 17 00:00:00 2001 From: Rong Liu Date: Wed, 5 May 2021 22:17:27 +0000 Subject: [PATCH] dm: PTM: Enable ptm on passthru device If user sets enable_ptm option on passthru device, passthru device calls ptm_probe() to check and enable ptm on passthru device. If error is found during sanity check, ptm will not be enabled in the guest and an error will be reported to user. However, this doesn't prevent user from launching guest and passing through the device to the guest. If no error is found, PTM is enabled in the guest and the passthru device will connect to virtual root port (which acts as PTM root) instead of virtual host bridge. Tracked-On: #5915 Signed-off-by: Rong Liu Acked-by: Yu Wang --- devicemodel/hw/pci/passthrough.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index f9c606de1..bf5d114a8 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -47,6 +47,7 @@ #include "acpi.h" #include "dm.h" #include "passthru.h" +#include "ptm.h" /* Some audio drivers get topology data from ACPI NHLT table. * For such drivers, we need to copy the host NHLT table to make it @@ -524,6 +525,8 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) bool keep_gsi = false; bool need_reset = true; bool d3hot_reset = false; + bool enable_ptm = false; + int vrp_sec_bus = 0; int vmsix_on_msi_bar_id = -1; struct acrn_assign_pcidev pcidev = {}; uint16_t vendor = 0, device = 0; @@ -564,7 +567,9 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) pr_err("faild to parse msix emulation bar id"); return -EINVAL; } - + } else if (!strncmp(opt, "enable_ptm", 10)) { + pr_notice(": opt=enable_ptm.\n"); + enable_ptm = true; } else pr_warn("Invalid passthru options:%s", opt); } @@ -670,6 +675,20 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) } } + if (enable_ptm) { + error = ptm_probe(ctx, ptdev, &vrp_sec_bus); + + if (!error && (vrp_sec_bus > 0)) { + /* if ptm is enabled, ptm capable ptdev (ptm requestor) is connected to virtual + * root port (ptm root), instead of virutal host bridge. */ + pcidev.virt_bdf = PCI_BDF(vrp_sec_bus, 0, 0); + } + else { + enable_ptm = false; + pr_err("%s: Failed to enable PTM on passthrough device %x:%x:%x.\n", __func__, bus, slot, func); + } + } + pcidev.intr_line = pci_get_cfgdata8(dev, PCIR_INTLINE); pcidev.intr_pin = pci_get_cfgdata8(dev, PCIR_INTPIN); error = vm_assign_pcidev(ctx, &pcidev);