qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Don Slutz <dslutz@verizon.com>
To: qemu-devel@nongnu.org, xen-devel@lists.xen.org
Cc: Paul Durrant <paul.durrant@citrix.com>,
	Don Slutz <don.slutz@gmail.com>, Don Slutz <dslutz@verizon.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/4] Extend device listener interface for PCI to PCI bridges
Date: Mon,  8 Jun 2015 17:18:50 -0400	[thread overview]
Message-ID: <1433798332-5830-3-git-send-email-dslutz@verizon.com> (raw)
In-Reply-To: <1433798332-5830-1-git-send-email-dslutz@verizon.com>

The commit 707ff80021ccd7a68f4b3d2c44eebf87efbb41c4 assumed that a
PCI device has a static address.  This is not true for PCI devices
that are on the secondary bus of a PCI to PCI bridge.

BIOS and/or guest OS can change the secondary bus number to a new
value at any time.

Extend the device listener interface to be called when ever the
secondary bus number is set to a new value.  This new interface
is called for all PCI devices that are on the secondary bridge.

Signed-off-by: Don Slutz <dslutz@verizon.com>
CC: Don Slutz <don.slutz@gmail.com>
---
 hw/core/qdev.c         |  7 +++++++
 hw/pci/pci_bridge.c    | 18 ++++++++++++++++++
 include/hw/qdev-core.h |  3 +++
 3 files changed, 28 insertions(+)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index b0f0f84..7728ee7 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -239,6 +239,13 @@ void device_listener_unregister(DeviceListener *listener)
     QTAILQ_REMOVE(&device_listeners, listener, link);
 }
 
+void device_listener_change_pci_bus_num(PCIBus *b, PCIDevice *d, void *opaque)
+{
+    uint8_t oldbus = GPOINTER_TO_INT(opaque);
+
+    DEVICE_LISTENER_CALL(change_pci_bus_num, Forward, d, oldbus);
+}
+
 static void device_realize(DeviceState *dev, Error **errp)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index 40c97b1..742c4d8 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -248,6 +248,7 @@ void pci_bridge_write_config(PCIDevice *d,
     PCIBridge *s = PCI_BRIDGE(d);
     uint16_t oldctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL);
     uint16_t newctl;
+    uint8_t oldbus = pci_get_byte(d->config + PCI_SECONDARY_BUS);
 
     pci_default_write_config(d, address, val, len);
 
@@ -265,6 +266,14 @@ void pci_bridge_write_config(PCIDevice *d,
         pci_bridge_update_mappings(s);
     }
 
+    if (oldbus != pci_get_byte(d->config + PCI_SECONDARY_BUS)) {
+        PCIBus *sec_bus = pci_bridge_get_sec_bus(s);
+
+        pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
+                            device_listener_change_pci_bus_num,
+                            GINT_TO_POINTER(oldbus));
+    }
+
     newctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL);
     if (~oldctl & newctl & PCI_BRIDGE_CTL_BUS_RESET) {
         /* Trigger hot reset on 0->1 transition. */
@@ -297,6 +306,7 @@ void pci_bridge_reset(DeviceState *qdev)
 {
     PCIDevice *dev = PCI_DEVICE(qdev);
     uint8_t *conf = dev->config;
+    uint8_t oldbus = conf[PCI_SECONDARY_BUS];
 
     conf[PCI_PRIMARY_BUS] = 0;
     conf[PCI_SECONDARY_BUS] = 0;
@@ -329,6 +339,14 @@ void pci_bridge_reset(DeviceState *qdev)
     pci_set_long(conf + PCI_PREF_LIMIT_UPPER32, 0);
 
     pci_set_word(conf + PCI_BRIDGE_CONTROL, 0);
+
+    if (oldbus) {
+        PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev));
+
+        pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
+                            device_listener_change_pci_bus_num,
+                            GINT_TO_POINTER(oldbus));
+    }
 }
 
 /* default qdev initialization function for PCI-to-PCI bridge */
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index d4be92f..154b4c1 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -168,6 +168,8 @@ struct DeviceState {
 struct DeviceListener {
     void (*realize)(DeviceListener *listener, DeviceState *dev);
     void (*unrealize)(DeviceListener *listener, DeviceState *dev);
+    void (*change_pci_bus_num)(DeviceListener *listener, PCIDevice *d,
+                               uint8_t oldbus);
     QTAILQ_ENTRY(DeviceListener) link;
 };
 
@@ -387,5 +389,6 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
 
 void device_listener_register(DeviceListener *listener);
 void device_listener_unregister(DeviceListener *listener);
+void device_listener_change_pci_bus_num(PCIBus *b, PCIDevice *d, void *opaque);
 
 #endif
-- 
1.8.4

  parent reply	other threads:[~2015-06-08 21:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-08 21:18 [Qemu-devel] [PATCH v2 0/4] Fix device listener interface for PCI to PCI bridges Don Slutz
2015-06-08 21:18 ` [Qemu-devel] [BUGFIX][PATCH v2 1/4] exec: Do not use MemoryRegion after free Don Slutz
2015-06-08 21:18 ` Don Slutz [this message]
2015-06-09  9:08   ` [Qemu-devel] [PATCH v2 2/4] Extend device listener interface for PCI to PCI bridges Paul Durrant
2015-06-09 13:53     ` Don Slutz
2015-06-09 13:55       ` Paul Durrant
2015-06-09 14:00         ` Don Slutz
2015-06-08 21:18 ` [Qemu-devel] [PATCH v2 3/4] xen: Add usage of " Don Slutz
2015-06-08 21:18 ` [Qemu-devel] [PATCH v2 4/4] xen: Fix map/unmap of pcidev to ioreq server Don Slutz
2015-06-09  9:05   ` Paul Durrant
2015-06-09 13:51     ` Don Slutz
2015-06-09 14:03       ` Paul Durrant
2015-06-09 14:28         ` Don Slutz
2015-06-09 15:11           ` Paul Durrant
2015-06-09 16:40             ` Don Slutz
2015-06-09  9:13 ` [Qemu-devel] [PATCH v2 0/4] Fix device listener interface for PCI to PCI bridges Michael S. Tsirkin
2015-06-09  9:18   ` Paul Durrant
2015-06-09 10:52     ` Michael S. Tsirkin
2015-06-09 10:58       ` Paul Durrant
2015-06-09 12:29         ` Michael S. Tsirkin
2015-06-09 14:14           ` Paul Durrant
2015-06-09 14:27             ` Michael S. Tsirkin
2015-06-09 15:10               ` Don Slutz

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=1433798332-5830-3-git-send-email-dslutz@verizon.com \
    --to=dslutz@verizon.com \
    --cc=don.slutz@gmail.com \
    --cc=mst@redhat.com \
    --cc=paul.durrant@citrix.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.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).