qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: aliguori@us.ibm.com, qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH 7/9] vfio-pci: Move devices to D0 on reset
Date: Mon, 01 Apr 2013 13:58:13 -0600	[thread overview]
Message-ID: <20130401195813.17115.37153.stgit@bling.home> (raw)
In-Reply-To: <20130401195242.17115.51929.stgit@bling.home>

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>
---
 hw/vfio_pci.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/hw/vfio_pci.c b/hw/vfio_pci.c
index b913ec0..d310730 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.

  parent reply	other threads:[~2013-04-01 19:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-01 19:57 [Qemu-devel] [GIT PULL 0/9] vfio-pci updates & VGA support Alex Williamson
2013-04-01 19:57 ` [Qemu-devel] [PATCH 1/9] linux-headers: Update to v3.9-rc2 Alex Williamson
2013-04-01 19:57 ` [Qemu-devel] [PATCH 2/9] vfio-pci: Generalize PCI config mangling Alex Williamson
2013-04-01 19:57 ` [Qemu-devel] [PATCH 3/9] vfio-pci: Add PCIe capability mangling based on bus type Alex Williamson
2013-04-01 19:57 ` [Qemu-devel] [PATCH 4/9] qemu vfio-pci: Add support for VGA MMIO and I/O port access Alex Williamson
2013-04-01 19:58 ` [Qemu-devel] [PATCH 5/9] qemu vfio-pci: Graphics device quirks Alex Williamson
2013-04-01 19:58 ` [Qemu-devel] [PATCH 6/9] vfio-pci: Add extra debugging Alex Williamson
2013-04-01 19:58 ` Alex Williamson [this message]
2013-04-01 19:58 ` [Qemu-devel] [PATCH 8/9] vfio: Add bootindex support Alex Williamson
2013-04-01 19:58 ` [Qemu-devel] [PATCH 9/9] vfio: cleanup includes 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=20130401195813.17115.37153.stgit@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=aliguori@us.ibm.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).