From: Jean Guyader Subject: [PATCH] hvmloader: Intel GPU passthrough, reverse OpRegion Date: Wed, 23 Nov 2011 16:07:40 +0000 Message-ID: <1322064460-22248-1-git-send-email-jean.guyader@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------true" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: allen.m.kay@intel.com, Jean Guyader List-Id: xen-devel@lists.xenproject.org --------------true Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: 8bit The Intel GPU uses a two pages NVS region called OpRegion. In order to get full support for the driver in the guest we need to map this region. This patch reserves 2 pages on the top of the RAM and mark this region as NVS in the e820. Then we write the address to the config space (offset 0xfc) so the device model can map the OpRegion at this address in the guest. Signed-off-by: Jean Guyader --- tools/firmware/hvmloader/config.h | 1 + tools/firmware/hvmloader/e820.c | 8 ++++++++ tools/firmware/hvmloader/pci.c | 28 ++++++++++++++++++++++++++++ tools/firmware/hvmloader/pci_regs.h | 2 ++ 4 files changed, 39 insertions(+), 0 deletions(-) --------------true Content-Type: text/x-patch; name="0001-hvmloader-Intel-GPU-passthrough-reverse-OpRegion.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-hvmloader-Intel-GPU-passthrough-reverse-OpRegion.patch" diff --git a/tools/firmware/hvmloader/config.h b/tools/firmware/hvmloader/config.h index d911352..9cac9c1 100644 --- a/tools/firmware/hvmloader/config.h +++ b/tools/firmware/hvmloader/config.h @@ -5,6 +5,7 @@ enum virtual_vga { VGA_none, VGA_std, VGA_cirrus, VGA_pt }; extern enum virtual_vga virtual_vga; +extern unsigned long igd_opregion_pgbase; struct bios_config { const char *name; diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c index 3b50dd0..fd993fe 100644 --- a/tools/firmware/hvmloader/e820.c +++ b/tools/firmware/hvmloader/e820.c @@ -124,6 +124,14 @@ int build_e820_table(struct e820entry *e820, e820[nr].type = E820_RAM; nr++; + if ( igd_opregion_pgbase ) + { + e820[nr].addr = igd_opregion_pgbase << PAGE_SHIFT; + e820[nr].size = 2 * PAGE_SIZE; + e820[nr].type = E820_NVS; + nr++; + } + /* * Explicitly reserve space for special pages. * This space starts at RESERVED_MEMBASE an extends to cover various diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c index 00490f1..13d3822 100644 --- a/tools/firmware/hvmloader/pci.c +++ b/tools/firmware/hvmloader/pci.c @@ -32,6 +32,7 @@ unsigned long pci_mem_start = PCI_MEM_START; unsigned long pci_mem_end = PCI_MEM_END; enum virtual_vga virtual_vga = VGA_none; +unsigned long igd_opregion_pgbase = 0; void pci_setup(void) { @@ -271,6 +272,33 @@ void pci_setup(void) cmd |= PCI_COMMAND_IO; pci_writew(vga_devfn, PCI_COMMAND, cmd); } + + if ( virtual_vga == VGA_pt ) + { + class = pci_readw(vga_devfn, PCI_CLASS_DEVICE); + vendor_id = pci_readw(vga_devfn, PCI_VENDOR_ID); + device_id = pci_readw(vga_devfn, PCI_DEVICE_ID); + + switch ( vendor_id ) + { + case 0x8086: /* PCI_VENDOR_INTEL */ + for ( i = 0; i < 2; i++ ) + { + struct xen_add_to_physmap xatp; + xatp.domid = DOMID_SELF; + xatp.space = XENMAPSPACE_gmfn; + xatp.idx = --hvm_info->low_mem_pgend; + xatp.gpfn = hvm_info->high_mem_pgend++; + if ( hypercall_memory_op(XENMEM_add_to_physmap, &xatp) != 0 ) + BUG(); + } + igd_opregion_pgbase = hvm_info->low_mem_pgend; + pci_writel(vga_devfn, PCI_INTEL_OPREGION, + igd_opregion_pgbase << PAGE_SHIFT); + break; + } + } + } /* diff --git a/tools/firmware/hvmloader/pci_regs.h b/tools/firmware/hvmloader/pci_regs.h index f37affe..873255c 100644 --- a/tools/firmware/hvmloader/pci_regs.h +++ b/tools/firmware/hvmloader/pci_regs.h @@ -105,6 +105,8 @@ #define PCI_MIN_GNT 0x3e /* 8 bits */ #define PCI_MAX_LAT 0x3f /* 8 bits */ +#define PCI_INTEL_OPREGION 0xfc /* 32 bits */ + #endif /* __HVMLOADER_PCI_REGS_H__ */ /* --------------true Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------true--