From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: alex.williamson@redhat.com, allen.m.kay@intel.com, kvm@vger.kernel.org
Subject: [Qemu-devel] [RFC PATCH v3 7/9] vfio/pci: Fixup PCI option ROMs
Date: Tue, 16 Feb 2016 14:32:31 -0700 [thread overview]
Message-ID: <20160216213231.13529.84067.stgit@gimli.home> (raw)
In-Reply-To: <20160216211249.13529.7276.stgit@gimli.home>
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 <alex.williamson@redhat.com>
---
hw/vfio/pci.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 8e20781..d0d0864 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)
next prev parent reply other threads:[~2016-02-16 21:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 21:31 [Qemu-devel] [RFC PATCH v3 0/9] vfio: capability chains, sparse mmap, device specific regions, IGD support Alex Williamson
2016-02-16 21:31 ` [Qemu-devel] [RFC PATCH v3 1/9] vfio: Add sysfsdev property for pci & platform Alex Williamson
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 2/9] vfio: Wrap VFIO_DEVICE_GET_REGION_INFO Alex Williamson
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 3/9] vfio: Generalize region support Alex Williamson
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 4/9] vfio/pci: Convert all MemoryRegion to dynamic alloc and consistent functions Alex Williamson
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 5/9] linux-headers/vfio: Update for proposed capabilities list Alex Williamson
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 6/9] vfio: Enable sparse mmap capability Alex Williamson
2016-02-16 21:32 ` Alex Williamson [this message]
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 8/9] vfio/pci: Split out VGA setup Alex Williamson
2016-02-16 21:32 ` [Qemu-devel] [RFC PATCH v3 9/9] Intel IGD support for vfio Alex Williamson
2016-02-17 11:16 ` [Qemu-devel] [RFC PATCH v3 0/9] vfio: capability chains, sparse mmap, device specific regions, IGD support Tian, Kevin
2016-02-17 14:02 ` Alex Williamson
2016-03-01 14:49 ` Gerd Hoffmann
2016-03-01 15:29 ` Eric Auger
2016-03-01 20:21 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160216213231.13529.84067.stgit@gimli.home \
--to=alex.williamson@redhat.com \
--cc=allen.m.kay@intel.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).