Received: from eggs.gnu.org ([2001:4830:134:3::10]:55038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3Nqv-0001z2-3z for qemu-devel@nongnu.org; Wed, 15 Jan 2014 05:37:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3Nqp-0005XY-An for qemu-devel@nongnu.org; Wed, 15 Jan 2014 05:37:41 -0500 Received: from vserver.eikelenboom.it ([84.200.39.61]:36691 helo=smtp.eikelenboom.it) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3Nqo-0005Wz-Hl for qemu-devel@nongnu.org; Wed, 15 Jan 2014 05:37:34 -0500 Date: Wed, 15 Jan 2014 11:37:29 +0100 From: Sander Eikelenboom Message-ID: <9310049934.20140115113729@eikelenboom.it> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Secondary VGA passthrough not working, hitting linux kernel's pci_fixup_video List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , Anthony Liguori Cc: qemu-devel@nongnu.org Hi Michael / Anthony, I'm trying to do secondary VGA passthrough with on Xen for some time. The problem was that the driver would get the rom of the emulated VGA device instead of it's own rom from the rom bar. In the end I found out it is because of a "fixup" in the linux kernel, "pci_fixup_video" in arch/x86/pci/fixup.c that sets the IORESOURCE_ROM_SHADOW flag for both VGA cards and make both point to C000 (which is were the emulated rom is). The code there tries to verify if the bridge has the PCI_BRIDGE_CTL_VGA bit set, and would only apply the fix when that's true however the code doesn't get that far since it returns prematurely since !bridge (the code in question is below as is a dump of lspci -vvvknn). The author of that code replied: I understood there is no bridge for a VGA device in your virtual machine. Your emulator for the bridge control register is odd. I guess your virtual machine ignore "PCI-to-PCI Bridge Architecture Specification". Thank you, Eiichiro Oiwa So my first question is .. (i haven't got much knowledge on PCI) is he right and is the layout of pci devices in Qemu indeed out of spec ? Or is the pci_fixup_video code assuming too much ... ? And second .. any ideas of how to fix it ? When i prevent this quirk/fixup from running in the guest kernel, the passthrough works fine .. it can read it's bios .. playing HD video .. even DPM seems to work with the radeon :-) Also see this thread on the linux-kernel mailing list: https://lkml.org/lkml/2014/1/11/203 -- Sander /* * Fixup to mark boot BIOS video selected by BIOS before it changes * * From information provided by "Jon Smirl" * * The standard boot ROM sequence for an x86 machine uses the BIOS * to select an initial video card for boot display. This boot video * card will have it's BIOS copied to C0000 in system RAM. * IORESOURCE_ROM_SHADOW is used to associate the boot video * card with this copy. On laptops this copy has to be used since * the main ROM may be compressed or combined with another image. * See pci_map_rom() for use of this flag. Before we mark the device * with IORESOURCE_ROM_SHADOW we have to check if this is or should become * the primary video card, since this quirk is ran for all video devices. */ static void pci_fixup_video(struct pci_dev *pdev) { struct pci_dev *bridge; struct pci_bus *bus; u16 config; /* Is VGA routed to us? */ bus = pdev->bus; while (bus) { bridge = bus->self; /* * From information provided by * "David Miller" * The bridge control register is valid for PCI header * type BRIDGE, or CARDBUS. Host to PCI controllers use * PCI header type NORMAL. */ if (bridge && ((bridge->hdr_type == PCI_HEADER_TYPE_BRIDGE) || (bridge->hdr_type == PCI_HEADER_TYPE_CARDBUS))) { pci_read_config_word(bridge, PCI_BRIDGE_CONTROL, &config); if (!(config & PCI_BRIDGE_CTL_VGA)) return; } bus = bus->parent; } if (!vga_default_device() || pdev == vga_default_device()) { pci_read_config_word(pdev, PCI_COMMAND, &config); if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) { pdev->resource[PCI_ROM_RESOURCE].flags |= IORESOURCE_ROM_SHADOW; dev_printk(KERN_DEBUG, &pdev->dev, "Boot video device\n"); vga_set_default_device(pdev); } } } DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, 8, pci_fixup_video); # lspci -vvvknn 00:00.0 Host bridge [0600]: Intel Corporation 440FX - 82441FX PMC [Natoma] [8086:1237] (rev 02) Subsystem: Red Hat, Inc Qemu virtual machine [1af4:1100] Control: I/O- Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- SERR- TAbort- SERR- TAbort- SERR- TAbort- SERR- TAbort- SERR- TAbort- SERR- TAbort- SERR- TAbort- SERR-