From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Marcel Apfelbaum <marcel@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Laszlo Ersek <lersek@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Marcel Apfelbaum <marcel.a@redhat.com>
Subject: [Qemu-devel] [PULL 08/28] hw/pci: made pci_bus_is_root a PCIBusClass method
Date: Thu, 4 Jun 2015 13:10:35 +0200 [thread overview]
Message-ID: <1433416111-19022-9-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1433416111-19022-1-git-send-email-mst@redhat.com>
From: Marcel Apfelbaum <marcel.a@redhat.com>
Refactoring it as a method of PCIBusClass will allow
different implementations for subclasses.
Removed the assumption that the root bus does not
have a parent device because is specific only
to the default class implementation.
Signed-off-by: Marcel Apfelbaum <marcel@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
---
include/hw/pci/pci.h | 2 ++
include/hw/pci/pci_bus.h | 8 ++++++++
hw/pci/pci.c | 17 ++++++++++++++---
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 5d050c8..df05c96 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -340,6 +340,8 @@ typedef PCIINTxRoute (*pci_route_irq_fn)(void *opaque, int pin);
#define TYPE_PCI_BUS "PCI"
#define PCI_BUS(obj) OBJECT_CHECK(PCIBus, (obj), TYPE_PCI_BUS)
+#define PCI_BUS_CLASS(klass) OBJECT_CLASS_CHECK(PCIBusClass, (klass), TYPE_PCI_BUS)
+#define PCI_BUS_GET_CLASS(obj) OBJECT_GET_CLASS(PCIBusClass, (obj), TYPE_PCI_BUS)
#define TYPE_PCIE_BUS "PCIE"
bool pci_bus_is_express(PCIBus *bus);
diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h
index fabaeee..b5ba9c4 100644
--- a/include/hw/pci/pci_bus.h
+++ b/include/hw/pci/pci_bus.h
@@ -8,6 +8,14 @@
* use accessor functions in pci.h, pci_bridge.h
*/
+typedef struct PCIBusClass {
+ /*< private >*/
+ BusClass parent_class;
+ /*< public >*/
+
+ bool (*is_root)(PCIBus *bus);
+} PCIBusClass;
+
struct PCIBus {
BusState qbus;
PCIIOMMUFunc iommu_fn;
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 48f19a3..132d19e 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -88,9 +88,15 @@ static void pci_bus_unrealize(BusState *qbus, Error **errp)
vmstate_unregister(NULL, &vmstate_pcibus, bus);
}
+static bool pcibus_is_root(PCIBus *bus)
+{
+ return !bus->parent_dev;
+}
+
static void pci_bus_class_init(ObjectClass *klass, void *data)
{
BusClass *k = BUS_CLASS(klass);
+ PCIBusClass *pbc = PCI_BUS_CLASS(klass);
k->print_dev = pcibus_dev_print;
k->get_dev_path = pcibus_get_dev_path;
@@ -98,12 +104,15 @@ static void pci_bus_class_init(ObjectClass *klass, void *data)
k->realize = pci_bus_realize;
k->unrealize = pci_bus_unrealize;
k->reset = pcibus_reset;
+
+ pbc->is_root = pcibus_is_root;
}
static const TypeInfo pci_bus_info = {
.name = TYPE_PCI_BUS,
.parent = TYPE_BUS,
.instance_size = sizeof(PCIBus),
+ .class_size = sizeof(PCIBusClass),
.class_init = pci_bus_class_init,
};
@@ -278,7 +287,10 @@ PCIBus *pci_device_root_bus(const PCIDevice *d)
{
PCIBus *bus = d->bus;
- while ((d = bus->parent_dev) != NULL) {
+ while (!pci_bus_is_root(bus)) {
+ d = bus->parent_dev;
+ assert(d != NULL);
+
bus = d->bus;
}
@@ -291,7 +303,6 @@ const char *pci_root_bus_path(PCIDevice *dev)
PCIHostState *host_bridge = PCI_HOST_BRIDGE(rootbus->qbus.parent);
PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_GET_CLASS(host_bridge);
- assert(!rootbus->parent_dev);
assert(host_bridge->bus == rootbus);
if (hc->root_bus_path) {
@@ -325,7 +336,7 @@ bool pci_bus_is_express(PCIBus *bus)
bool pci_bus_is_root(PCIBus *bus)
{
- return !bus->parent_dev;
+ return PCI_BUS_GET_CLASS(bus)->is_root(bus);
}
void pci_bus_new_inplace(PCIBus *bus, size_t bus_size, DeviceState *parent,
--
MST
next prev parent reply other threads:[~2015-06-04 11:10 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-04 11:10 [Qemu-devel] [PULL 00/28] pc, acpi, virtio, tpm Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 01/28] acpi: add missing ssdt Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 02/28] hw/q35: fix floppy controller definition in ich9 Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 03/28] virtio-pci: don't try to mask or unmask vqs without notifiers Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 04/28] TPM: fix build with tpm disabled Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 05/28] virtio: 64bit features fixups Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 06/28] acpi: add acpi_send_gpe_event() to rise sci for hotplug Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 07/28] acpi: add implementation of aml_while() term Michael S. Tsirkin
2015-06-04 11:10 ` Michael S. Tsirkin [this message]
2015-06-04 11:10 ` [Qemu-devel] [PULL 09/28] hw/pci: made pci_bus_num a PCIBusClass method Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 10/28] hw/i386: query only for q35/pc when looking for pci host bridge Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 11/28] hw/pci: extend PCI config access to support devices behind PXB Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 12/28] hw/acpi: add support for i440fx 'snooping' root busses Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 13/28] hw/apci: add _PRT method for extra PCI " Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 14/28] hw/acpi: add _CRS method for extra " Michael S. Tsirkin
2015-06-04 11:10 ` [Qemu-devel] [PULL 15/28] hw/acpi: remove from root bus 0 the crs resources used by other buses Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 16/28] hw/pci: removed 'rootbus nr is 0' assumption from qmp_pci_query Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 17/28] hw/pci: introduce PCI Expander Bridge (PXB) Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 18/28] hw/pci: inform bios if the system has extra pci root buses Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 19/28] hw/pxb: add map_irq func Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 20/28] hw/pci: add support for NUMA nodes Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 21/28] hw/pxb: add numa_node parameter Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 22/28] apci: fix PXB behaviour if used with unsupported BIOS Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 23/28] docs: Add PXB documentation Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 24/28] pc-dimm: don't assert if pc-dimm alignment != hotpluggable mem range size Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 25/28] hw/acpi: acpi_pm1_cnt_init(): take "disable_s3" and "disable_s4" Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 26/28] hw/acpi: move "etc/system-states" fw_cfg file from PIIX4 to core Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 27/28] hw/acpi: piix4_pm_init(): take fw_cfg object no more Michael S. Tsirkin
2015-06-04 11:11 ` [Qemu-devel] [PULL 28/28] vhost: logs sharing Michael S. Tsirkin
2015-06-05 11:03 ` [Qemu-devel] [PULL 00/28] pc, acpi, virtio, tpm Peter Maydell
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=1433416111-19022-9-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=ehabkost@redhat.com \
--cc=lersek@redhat.com \
--cc=marcel.a@redhat.com \
--cc=marcel@redhat.com \
--cc=peter.maydell@linaro.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).