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 v2 8/9] vfio/pci: Fixup PCI option ROMs
Date: Fri, 12 Feb 2016 17:17:18 -0700 [thread overview]
Message-ID: <20160213001718.17724.39810.stgit@gimli.home> (raw)
In-Reply-To: <20160213000436.17724.35780.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 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)
next prev parent reply other threads:[~2016-02-13 0:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-13 0:16 [Qemu-devel] [RFC PATCH v2 0/9] vfio: capability chains, sparse mmap, device specific regions, IGD support Alex Williamson
2016-02-13 0:16 ` [Qemu-devel] [RFC PATCH v2 1/9] vfio: Add sysfsdev property for pci & platform Alex Williamson
2016-02-13 0:16 ` [Qemu-devel] [RFC PATCH v2 2/9] vfio: Wrap VFIO_DEVICE_GET_REGION_INFO Alex Williamson
2016-02-13 0:16 ` [Qemu-devel] [RFC PATCH v2 3/9] vfio: Generalize region support Alex Williamson
2016-02-13 0:16 ` [Qemu-devel] [RFC PATCH v2 4/9] vfio/pci: Convert all MemoryRegion to dynamic alloc and consistent functions Alex Williamson
2016-02-13 0:17 ` [Qemu-devel] [RFC PATCH v2 5/9] linux-headers/vfio: Update for proposed capabilities list Alex Williamson
2016-02-13 0:17 ` [Qemu-devel] [RFC PATCH v2 6/9] vfio: Enable sparse mmap capability Alex Williamson
2016-02-13 0:17 ` [Qemu-devel] [RFC PATCH v2 7/9] vfio/pci: Intel IGD graphics support Alex Williamson
2016-02-13 0:17 ` Alex Williamson [this message]
2016-02-13 0:17 ` [Qemu-devel] [RFC PATCH v2 9/9] vfio/pci: Intel IGD stolen memory quirk 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=20160213001718.17724.39810.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).