Patchwork [PATCHv2,4/4] qemu/pci: reset device registers on bus reset

login
register
mail settings
Submitter Michael S. Tsirkin
Date Sept. 16, 2009, 10:41 a.m.
Message ID <20090916104109.GE4446@redhat.com>
Download mbox | patch
Permalink /patch/33701/
State Superseded
Headers show

Comments

Michael S. Tsirkin - Sept. 16, 2009, 10:41 a.m.
Reset BARs and a couple of other registers on bus reset, as per PCI
spec.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/pci.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

Patch

diff --git a/hw/pci.c b/hw/pci.c
index 600df2f..b489d41 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -90,7 +90,20 @@  static inline int pci_bar(int reg)
 
 static void pci_device_reset(PCIDevice *dev)
 {
+    int r;
+
     memset(dev->irq_state, 0, sizeof dev->irq_state);
+    dev->config[PCI_COMMAND] &= ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
+                                  PCI_COMMAND_MASTER);
+    dev->config[PCI_CACHE_LINE_SIZE] = 0x0;
+    dev->config[PCI_INTERRUPT_LINE] = 0x0;
+    for (r = 0; r < PCI_NUM_REGIONS; ++r) {
+        if (!dev->io_regions[r].size) {
+            continue;
+        }
+        pci_set_long(dev->config + pci_bar(r), dev->io_regions[r].type);
+    }
+    pci_update_mappings(dev);
 }
 
 static void pci_bus_reset(void *opaque)