diff options
author | Alex Williamson <alex.williamson@redhat.com> | 2013-04-01 13:35:08 -0600 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2013-04-01 13:35:08 -0600 |
commit | ba66181828a5e5b0bbc117c4e999ca559a87456e (patch) | |
tree | 6f31d3d561d053c2fb2841a861701723b27dff35 /hw | |
parent | 82ca891283a08cddd659b534592fe00f2159bc74 (diff) | |
download | qemu-ba66181828a5e5b0bbc117c4e999ca559a87456e.tar.gz qemu-ba66181828a5e5b0bbc117c4e999ca559a87456e.tar.bz2 qemu-ba66181828a5e5b0bbc117c4e999ca559a87456e.zip |
vfio-pci: Move devices to D0 on reset
Guests may leave devices in a low power state at reboot, but we expect
devices to be woken up for the next boot. Make this happen.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/vfio_pci.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/hw/vfio_pci.c b/hw/vfio_pci.c index b913ec0f57..d310730c6f 100644 --- a/hw/vfio_pci.c +++ b/hw/vfio_pci.c @@ -160,6 +160,7 @@ typedef struct VFIODevice { uint32_t features; #define VFIO_FEATURE_ENABLE_VGA_BIT 0 #define VFIO_FEATURE_ENABLE_VGA (1 << VFIO_FEATURE_ENABLE_VGA_BIT) + uint8_t pm_cap; bool reset_works; bool has_vga; } VFIODevice; @@ -2534,6 +2535,8 @@ static int vfio_add_std_cap(VFIODevice *vdev, uint8_t pos) case PCI_CAP_ID_MSIX: ret = vfio_setup_msix(vdev, pos); break; + case PCI_CAP_ID_PM: + vdev->pm_cap = pos; default: ret = pci_add_capability(pdev, cap_id, pos, size); break; @@ -3108,6 +3111,26 @@ static void vfio_pci_reset(DeviceState *dev) vfio_disable_interrupts(vdev); + /* Make sure the device is in D0 */ + if (vdev->pm_cap) { + uint16_t pmcsr; + uint8_t state; + + pmcsr = vfio_pci_read_config(pdev, vdev->pm_cap + PCI_PM_CTRL, 2); + state = pmcsr & PCI_PM_CTRL_STATE_MASK; + if (state) { + pmcsr &= ~PCI_PM_CTRL_STATE_MASK; + vfio_pci_write_config(pdev, vdev->pm_cap + PCI_PM_CTRL, pmcsr, 2); + /* vfio handles the necessary delay here */ + pmcsr = vfio_pci_read_config(pdev, vdev->pm_cap + PCI_PM_CTRL, 2); + state = pmcsr & PCI_PM_CTRL_STATE_MASK; + if (state) { + error_report("vfio: Unable to power on device, stuck in D%d\n", + state); + } + } + } + /* * Stop any ongoing DMA by disconecting I/O, MMIO, and bus master. * Also put INTx Disable in known state. |