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 <rong.l.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Rong Liu 2021-05-05 22:17:27 +00:00 committed by wenlingz
parent 7e93f31e2c
commit 721c866d63
1 changed files with 20 additions and 1 deletions

View File

@ -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("<PTM>: 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);