vfio-pci: Lazy PCI option ROM loading
commit6f864e6ec8812d5a5525a7861ca599c6bcabdebe
authorAlex Williamson <alex.williamson@redhat.com>
Wed, 2 Oct 2013 18:52:38 +0000 (2 12:52 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Wed, 2 Oct 2013 18:52:38 +0000 (2 12:52 -0600)
tree84b2f585eb9bed905ff74b292e7a7033c0016038
parentbefe5176ef7a0004ba23517c97c804e292273635
vfio-pci: Lazy PCI option ROM loading

During vfio-pci initfn, the device is not always in a state where the
option ROM can be read.  In the case of graphics cards, there's often
no per function reset, which means we have host driver state affecting
whether the option ROM is usable.  Ideally we want to move reading the
option ROM past any co-assigned device resets to the point where the
guest first tries to read the ROM itself.

To accomplish this, we switch the memory region for the option rom to
an I/O region rather than a memory mapped region.  This has the side
benefit that we don't waste KVM memory slots for a BAR where we don't
care about performance.  This also allows us to delay loading the ROM
from the device until the first read by the guest.  We then use the
PCI config space size of the ROM BAR when setting up the BAR through
QEMU PCI.

Another benefit of this approach is that previously when a user set
the ROM to a file using the romfile= option, we still probed VFIO for
the parameters of the ROM, which can result in dmesg errors about an
invalid ROM.  We now only probe VFIO to get the ROM contents if the
guest actually tries to read the ROM.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
hw/misc/vfio.c