From 4d882731cec0ec16844d5bf01cbdcdc611965a19 Mon Sep 17 00:00:00 2001 From: Junming Liu Date: Fri, 10 Jan 2020 22:21:20 +0000 Subject: [PATCH] dm:passthrough graphics stolen memory to uos gpu gop driver and uos IGD driver will use graphics stolen memory(gsm) when enable GVT-d. This patch pass-thru gsm to uos gpu. After set physical GPU gsm size 64MB in host BIOS: Here is the steps: (1) set gsm gpa(guest physical addrress) 0xDB000000; (2) get gsm hpa(host physical addrress); (3) build EPT mapping for gsm. v1 -> v2: * initialize the EPT mapping for passthrough GPU gsm region in passthru_init instead of reading the BDSM config space v2 -> v3: * add EPT unmap when deinit * change some micro name Tracked-On: #4360 Signed-off-by: Junming Liu Reviewed-by: Zhao Yakui Reviewed-by: Liu XinYun Reviewed-by: Shuo A Liu Reviewed-by: Wu Binbin Acked-by: Yu Wang --- devicemodel/core/sw_load_common.c | 3 +++ devicemodel/hw/pci/passthrough.c | 30 +++++++++++++++++++++++++----- devicemodel/include/pcireg.h | 4 ++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/devicemodel/core/sw_load_common.c b/devicemodel/core/sw_load_common.c index 199f98d21..b5e7c9a15 100644 --- a/devicemodel/core/sw_load_common.c +++ b/devicemodel/core/sw_load_common.c @@ -101,6 +101,9 @@ const struct e820_entry e820_default_entries[NUM_E820_ENTRIES] = { * For ACRN, we simply hard code to 64MB and static * reserved the memory region to avoid more efforts in OVMF, * and user *must* align the native BIOS setting to 64MB. + * + * GPU_GSM_GPA micro in passthrough.c should ++ * align with this address here. */ .baseaddr = 0xDB000000, .length = 0x4000000, diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index 9b09da21e..580cca58d 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -69,6 +69,10 @@ */ #define AUDIO_NHLT_HACK 1 +#define GPU_GSM_SIZE 0x4000000 +/* set gsm gpa=0xDB000000, which is reserved in e820 table */ +#define GPU_GSM_GPA 0xDB000000 + extern uint64_t audio_nhlt_len; /* reference count for libpciaccess init/deinit */ @@ -81,6 +85,8 @@ struct mmio_map { size_t size; }; +uint32_t gsm_start_hpa = 0; + struct passthru_dev { struct pci_vdev *dev; struct pcibar bar[PCI_BARMAX + 1]; @@ -861,6 +867,14 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) if (error < 0) goto done; + if (ptdev->phys_bdf == PCI_BDF_GPU) { + /* get gsm hpa */ + gsm_start_hpa = read_config(ptdev->phys_dev, PCIR_BDSM, 4); + gsm_start_hpa &= PCIM_BDSM_GSM_MASK; + /* initialize the EPT mapping for passthrough GPU gsm region */ + vm_map_ptdev_mmio(ctx, 0, 2, 0, GPU_GSM_GPA, GPU_GSM_SIZE, gsm_start_hpa); + } + /* If ptdev support MSI/MSIX, stop here to skip virtual INTx setup. * Forge Guest to use MSI/MSIX in this case to mitigate IRQ sharing * issue @@ -946,6 +960,10 @@ passthru_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts) ptdev->bar[i].addr); } + if (ptdev->phys_bdf == PCI_BDF_GPU) { + vm_unmap_ptdev_mmio(ctx, 0, 2, 0, GPU_GSM_GPA, GPU_GSM_SIZE, gsm_start_hpa); + } + pciaccess_cleanup(); free(ptdev); vm_unassign_ptdev(ctx, bus, slot, func); @@ -1037,13 +1055,15 @@ passthru_cfgread(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, /* Everything else just read from the device's config space */ *rv = read_config(ptdev->phys_dev, coff, bytes); - /* - * return zero for graphics stolen memory since acrn does not have - * support for RMRR + /* passthru_init has initialized the EPT mapping + * for GPU gsm region. + * So uos GPU can passthrough physical gsm now. + * Here, only need return gsm gpa value for uos. */ if ((PCI_BDF(dev->bus, dev->slot, dev->func) == PCI_BDF_GPU) - && (coff == PCIR_GMCH_CTL)) { - *rv &= ~PCIM_GMCH_CTL_GMS; + && (coff == PCIR_BDSM)) { + *rv &= ~PCIM_BDSM_GSM_MASK; + *rv |= GPU_GSM_GPA; } return 0; diff --git a/devicemodel/include/pcireg.h b/devicemodel/include/pcireg.h index 1c106cd9c..3857d8325 100644 --- a/devicemodel/include/pcireg.h +++ b/devicemodel/include/pcireg.h @@ -1066,6 +1066,6 @@ #define PCIM_OSC_CTL_PCIE_CAP_STRUCT 0x10 /* Various Capability Structures */ /* Graphics definitions */ -#define PCIR_GMCH_CTL 0x50 /*GMCH grpahics control register */ -#define PCIM_GMCH_CTL_GMS 0xFF00 /*GMS - stolen memory bits 15:8 */ +#define PCIR_BDSM 0x5C /* BDSM graphics base data of stolen memory register */ +#define PCIM_BDSM_GSM_MASK 0xFFF00000 /* bits 31:20 contains the base address of stolen memory */ #endif