From 03f5c639a0bc586ba9ea54a50226e3f6ddf8b8fb Mon Sep 17 00:00:00 2001 From: Junming Liu Date: Thu, 9 Jan 2020 18:36:19 +0000 Subject: [PATCH] dm:derive the prefetch property of PCI bar for pass-through device Now the PCI bar uses the hardcoded prefetch property for the pass-through device. This doesn't work when trying to load windows GPU driver for the pass-through GPU device. For pass-through devices, set the bar prefetchable property the same as physical bar. Tracked-On: #4282 Signed-off-by: Junming Liu Reviewed-by: Zhao Yakui Reviewed-by: Shuo A Liu Acked-by: Yu Wang --- devicemodel/hw/pci/passthrough.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/devicemodel/hw/pci/passthrough.c b/devicemodel/hw/pci/passthrough.c index 2926a2d4e..9b09da21e 100644 --- a/devicemodel/hw/pci/passthrough.c +++ b/devicemodel/hw/pci/passthrough.c @@ -527,6 +527,7 @@ cfginitbar(struct vmctx *ctx, struct passthru_dev *ptdev) struct pci_bar_io bar; enum pcibar_type bartype; uint64_t base, size; + uint32_t vbar_lo32; dev = ptdev->dev; @@ -590,6 +591,24 @@ cfginitbar(struct vmctx *ctx, struct passthru_dev *ptdev) if (error) return -1; + /* + * For pass-thru devices, + * set the bar prefetchable property the same as physical bar. + * + * the pci bar prefetchable property has set by pci_emul_alloc_pbar, + * here, override the prefetchable property according to the physical bar. + */ + if (bartype == PCIBAR_MEM32 || bartype == PCIBAR_MEM64) { + vbar_lo32 = pci_get_cfgdata32(dev, PCIR_BAR(i)); + + if (bar.base & PCIM_BAR_MEM_PREFETCH) + vbar_lo32 |= PCIM_BAR_MEM_PREFETCH; + else + vbar_lo32 &= ~PCIM_BAR_MEM_PREFETCH; + + pci_set_cfgdata32(dev, PCIR_BAR(i), vbar_lo32); + } + /* The MSI-X table needs special handling */ if (i == ptdev_msix_table_bar(ptdev)) { error = init_msix_table(ctx, ptdev, base);