24
return (QVTD_PT_VAL & VTD_PAGE_MASK_4K) + (iova & 0xfff);
25
}
26
27
-static void save_fn(QPCIDevice *dev, int devfn, void *data)
28
-{
29
- QPCIDevice **pdev = (QPCIDevice **) data;
30
-
31
- *pdev = dev;
32
-}
33
-
34
-static QPCIDevice *setup_qtest_pci_device(QTestState *qts, QPCIBus **pcibus,
35
- QPCIBar *bar)
36
-{
37
- QPCIDevice *dev = NULL;
38
-
39
- *pcibus = qpci_new_pc(qts, NULL);
40
- g_assert(*pcibus != NULL);
41
-
42
- qpci_device_foreach(*pcibus, IOMMU_TESTDEV_VENDOR_ID,
43
- IOMMU_TESTDEV_DEVICE_ID, save_fn, &dev);
44
-
45
- g_assert(dev);
46
- qpci_device_enable(dev);
47
- *bar = qpci_iomap(dev, 0, NULL);
48
- g_assert_false(bar->is_io);
49
-
50
- return dev;
51
-}
52
-
53
-static const char *qvtd_iommu_args(QVTDTransMode mode)
54
-{
55
- switch (mode) {
56
- case QVTD_TM_SCALABLE_FLT:
57
- return "-device intel-iommu,scalable-mode=on,fsts=on ";
58
- case QVTD_TM_SCALABLE_PT:
59
- case QVTD_TM_SCALABLE_SLT:
60
- return "-device intel-iommu,scalable-mode=on ";
61
- default:
62
- return "-device intel-iommu ";
63
- }
64
-}
65
-
66
-static bool qvtd_check_caps(QTestState *qts, QVTDTransMode mode)
67
-{
68
- uint64_t ecap = qtest_readq(qts,
69
- Q35_HOST_BRIDGE_IOMMU_ADDR + DMAR_ECAP_REG);
70
-
71
- /* All scalable modes require SMTS */
72
- if (qvtd_is_scalable(mode) && !(ecap & VTD_ECAP_SMTS)) {
73
- g_test_skip("ECAP.SMTS not supported");
74
- return false;
75
- }
76
-
77
- switch (mode) {
78
- case QVTD_TM_SCALABLE_PT:
79
- if (!(ecap & VTD_ECAP_PT)) {
80
- g_test_skip("ECAP.PT not supported");
81
- return false;
82
- }
83
- break;
84
- case QVTD_TM_SCALABLE_SLT:
85
- if (!(ecap & VTD_ECAP_SSTS)) {
86
- g_test_skip("ECAP.SSTS not supported");
87
- return false;
88
- }
89
- break;
90
- case QVTD_TM_SCALABLE_FLT:
91
- if (!(ecap & VTD_ECAP_FSTS)) {
92
- g_test_skip("ECAP.FSTS not supported");
93
- return false;
94
- }
95
- break;
96
- default:
97
- break;
98
- }
99
-
100
- return true;
101
-}
102
-
27
static void run_intel_iommu_translation(const QVTDTestConfig *cfg)
28
{
29
QTestState *qts;
48
}
49
50
/* Setup and configure IOMMU-testdev PCI device */
127
- dev = setup_qtest_pci_device(qts, &pcibus, &bar);
51
+ dev = qvtd_setup_qtest_pci_device(qts, &pcibus, &bar);
52
g_assert(dev);
53
54
g_test_message("### Intel IOMMU translation mode=%d ###", cfg->trans_mode);