Skip to content

Commit 1b3754a

Browse files
Junming Liuwenlingz
authored andcommitted
dm:passthrough opregion to uos gpu
uos IGD driver need opregion when enable GVT-d. This patch pass-thru opregion to uos gpu. Here is the steps: (1) set opregion gpa(guest physical addrress) 0xDFFFD000; (2) get opregion hpa(host physical addrress); (3) build EPT mapping for opregion. v1 -> v2: * initialize the EPT mapping for passthrough GPU opregion region in passthru_init instead of reading the ASLS config space v2 -> v3: * add EPT unmap when deinit * change some micro name Tracked-On: #4360 Signed-off-by: Junming Liu <junming.liu@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Reviewed-by: Liu XinYun <xinyun.liu@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com> Reviewed-by: Wu Binbin <binbin.wu@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 4d88273 commit 1b3754a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

devicemodel/hw/pci/passthrough.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373
/* set gsm gpa=0xDB000000, which is reserved in e820 table */
7474
#define GPU_GSM_GPA 0xDB000000
7575

76+
#define GPU_OPREGION_SIZE 0x3000
77+
/* set opregion gpa=0xDFFFD000, which is reserved in e820 table.
78+
* [0xDFFFD000, 0XE0000000] 12K opregion has reserved for GVT-g,
79+
* because GVT-d is not compatible with GVT-g,
80+
* so here can use [0xDFFFD000, 0XE0000000] region.
81+
*/
82+
#define GPU_OPREGION_GPA 0xDFFFD000
83+
7684
extern uint64_t audio_nhlt_len;
7785

7886
/* reference count for libpciaccess init/deinit */
@@ -86,6 +94,7 @@ struct mmio_map {
8694
};
8795

8896
uint32_t gsm_start_hpa = 0;
97+
uint32_t opregion_start_hpa = 0;
8998

9099
struct passthru_dev {
91100
struct pci_vdev *dev;
@@ -873,6 +882,12 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
873882
gsm_start_hpa &= PCIM_BDSM_GSM_MASK;
874883
/* initialize the EPT mapping for passthrough GPU gsm region */
875884
vm_map_ptdev_mmio(ctx, 0, 2, 0, GPU_GSM_GPA, GPU_GSM_SIZE, gsm_start_hpa);
885+
886+
/* get opregion hpa */
887+
opregion_start_hpa = read_config(ptdev->phys_dev, PCIR_ASLS_CTL, 4);
888+
opregion_start_hpa &= PCIM_ASLS_OPREGION_MASK;
889+
/* initialize the EPT mapping for passthrough GPU opregion */
890+
vm_map_ptdev_mmio(ctx, 0, 2, 0, GPU_OPREGION_GPA, GPU_OPREGION_SIZE, opregion_start_hpa);
876891
}
877892

878893
/* If ptdev support MSI/MSIX, stop here to skip virtual INTx setup.
@@ -962,6 +977,7 @@ passthru_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
962977

963978
if (ptdev->phys_bdf == PCI_BDF_GPU) {
964979
vm_unmap_ptdev_mmio(ctx, 0, 2, 0, GPU_GSM_GPA, GPU_GSM_SIZE, gsm_start_hpa);
980+
vm_unmap_ptdev_mmio(ctx, 0, 2, 0, GPU_OPREGION_GPA, GPU_OPREGION_SIZE, opregion_start_hpa);
965981
}
966982

967983
pciaccess_cleanup();
@@ -1066,6 +1082,18 @@ passthru_cfgread(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
10661082
*rv |= GPU_GSM_GPA;
10671083
}
10681084

1085+
/* passthru_init has initialized the EPT mapping
1086+
* for GPU opregion.
1087+
* So uos GPU can passthrough physical opregion now.
1088+
* Here, only need return opregion gpa value for uos.
1089+
*/
1090+
if ((PCI_BDF(dev->bus, dev->slot, dev->func) == PCI_BDF_GPU)
1091+
&& (coff == PCIR_ASLS_CTL)) {
1092+
/* reserve opregion start addr offset to 4KB page */
1093+
*rv &= ~PCIM_ASLS_OPREGION_MASK;
1094+
*rv |= GPU_OPREGION_GPA;
1095+
}
1096+
10691097
return 0;
10701098
}
10711099

devicemodel/include/pcireg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,4 +1068,6 @@
10681068
/* Graphics definitions */
10691069
#define PCIR_BDSM 0x5C /* BDSM graphics base data of stolen memory register */
10701070
#define PCIM_BDSM_GSM_MASK 0xFFF00000 /* bits 31:20 contains the base address of stolen memory */
1071+
#define PCIR_ASLS_CTL 0xFC /* Opregion start addr register */
1072+
#define PCIM_ASLS_OPREGION_MASK 0xFFFFF000 /* opregion need 4KB aligned */
10711073
#endif

0 commit comments

Comments
 (0)