From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUNto-0005VX-Pm for qemu-devel@nongnu.org; Fri, 12 Feb 2016 19:17:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aUNtn-0005aQ-SC for qemu-devel@nongnu.org; Fri, 12 Feb 2016 19:17:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aUNtn-0005a2-Lx for qemu-devel@nongnu.org; Fri, 12 Feb 2016 19:17:19 -0500 From: Alex Williamson Date: Fri, 12 Feb 2016 17:17:18 -0700 Message-ID: <20160213001718.17724.39810.stgit@gimli.home> In-Reply-To: <20160213000436.17724.35780.stgit@gimli.home> References: <20160213000436.17724.35780.stgit@gimli.home> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [RFC PATCH v2 8/9] vfio/pci: Fixup PCI option ROMs List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, allen.m.kay@intel.com, kvm@vger.kernel.org Devices like Intel graphics are known to not only have bad checksums, but also the wrong device ID. This is not so surprising given that the video BIOS is typically part of the system firmware image rather that embedded into the device and needs to support any IGD device installed into the system. Signed-off-by: Alex Williamson --- hw/vfio/pci.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4c376a8..07af5ca 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -832,6 +832,36 @@ static void vfio_pci_load_rom(VFIOPCIDevice *vdev) break; } } + + /* + * Test the ROM signature against our device, if the vendor is correct + * but the device ID doesn't match, store the correct device ID and + * recompute the checksum. Intel IGD devices need this and are known + * to have bogus checksums so we can't simply adjust the checksum. + */ + if (pci_get_word(vdev->rom) == 0xaa55 && + pci_get_word(vdev->rom + 0x18) + 8 < vdev->rom_size && + !memcmp(vdev->rom + pci_get_word(vdev->rom + 0x18), "PCIR", 4)) { + uint16_t vid, did; + + vid = pci_get_word(vdev->rom + pci_get_word(vdev->rom + 0x18) + 4); + did = pci_get_word(vdev->rom + pci_get_word(vdev->rom + 0x18) + 6); + + if (vid == vdev->vendor_id && did != vdev->device_id) { + int i; + uint8_t csum, *data = vdev->rom; + + pci_set_word(vdev->rom + pci_get_word(vdev->rom + 0x18) + 6, + vdev->device_id); + data[6] = 0; + + for (csum = 0, i = 0; i < vdev->rom_size; i++) { + csum += data[i]; + } + + data[6] = -csum; + } + } } static uint64_t vfio_rom_read(void *opaque, hwaddr addr, unsigned size)