From e5b21a2e909fac042605d00966e9224de892e13f Mon Sep 17 00:00:00 2001 From: Zhipeng Gong Date: Thu, 18 Oct 2018 09:23:09 +0800 Subject: [PATCH] dm: passthrough opregion to uos gpu --- devicemodel/core/sw_load_bzimage.c | 4 ++++ devicemodel/hw/pci/passthrough.c | 15 +++++++++++++++ devicemodel/include/vmmapi.h | 5 +++++ 3 files changed, 24 insertions(+) diff --git a/devicemodel/core/sw_load_bzimage.c b/devicemodel/core/sw_load_bzimage.c index b6dbdda87..52ffa74d9 100644 --- a/devicemodel/core/sw_load_bzimage.c +++ b/devicemodel/core/sw_load_bzimage.c @@ -298,6 +298,10 @@ acrn_prepare_zeropage(struct vmctx *ctx, int setup_size) /* Create/add e820 table entries in zeropage */ zeropage->e820_nentries = acrn_create_e820_table(ctx, zeropage->e820); + if (opregion_start != 0) { + zeropage->e820_nentries = add_e820_entry(zeropage->e820, zeropage->e820_nentries, + opregion_start, OPREGION_SIZE, E820_TYPE_RESERVED); + } return 0; } diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index f60efb0e3..f44aba9af 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -89,6 +89,8 @@ struct mmio_map { size_t size; }; +uint32_t opregion_start = 0; + struct passthru_dev { struct pci_vdev *dev; struct pcibar bar[PCI_BARMAX + 1]; @@ -848,6 +850,12 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts) if (error < 0) goto done; + if (ptdev->phys_bdf == PCI_BDF_GPU) { + opregion_start = read_config(ptdev->phys_dev, PCIR_ASLS_CTL, 4); + printf("Opregion start=%x\n", opregion_start); + opregion_start = ALIGN_DOWN(opregion_start, 4096); + } + /* 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 @@ -1000,6 +1008,13 @@ passthru_cfgread(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, *rv &= ~PCIM_GMCH_CTL_GMS; } + if ((PCI_BDF(dev->bus, dev->slot, dev->func) == PCI_BDF_GPU) + && (coff == PCIR_ASLS_CTL)) { + printf("passthrough opregion = %x\n", ptdev->phys_bdf); + vm_unmap_ptdev_mmio(ctx, 0, 2, 0, opregion_start, OPREGION_SIZE, opregion_start); + vm_map_ptdev_mmio(ctx, 0, 2, 0, opregion_start, OPREGION_SIZE, opregion_start); + } + return 0; } diff --git a/devicemodel/include/vmmapi.h b/devicemodel/include/vmmapi.h index 77f8dc8c4..bbdfc47dc 100644 --- a/devicemodel/include/vmmapi.h +++ b/devicemodel/include/vmmapi.h @@ -143,4 +143,9 @@ void vm_reset_watchdog(struct vmctx *ctx); int vm_ioeventfd(struct vmctx *ctx, struct acrn_ioeventfd *args); int vm_irqfd(struct vmctx *ctx, struct acrn_irqfd *args); + +extern uint32_t opregion_start; +#define OPREGION_SIZE 0x3000 +#define PCIR_ASLS_CTL 0xFC + #endif /* _VMMAPI_H_ */