From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org, kvm@vger.kernel.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Isaku Yamahata <yamahata@valinux.co.jp>,
Avi Kivity <avi@redhat.com>
Subject: [Qemu-devel] [PATCHv2-RFC 2/2] pci: add standard bridge device
Date: Mon, 13 Feb 2012 11:16:04 +0200 [thread overview]
Message-ID: <f9b630bb6c67f0facf29e42277ad7d991e660b3c.1329124507.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1329124507.git.mst@redhat.com>
This adds support for a standard pci to pci bridge,
enabling support for more than 32 PCI devices in the system.
Device hotplug is supported by means of SHPC controller.
For guests with an SHPC driver, this allows robust hotplug
and even hotplug of nested bridges, up to 31 devices
per bridge.
TODO:
- chassis capability support
- migration support
- remove dependency on pci_internals.h
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
Makefile.objs | 2 +-
hw/pci_bridge_dev.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 137 insertions(+), 1 deletions(-)
create mode 100644 hw/pci_bridge_dev.c
diff --git a/Makefile.objs b/Makefile.objs
index 4546477..e89112c 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -193,7 +193,7 @@ hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
hw-obj-y += usb-libhw.o
hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
hw-obj-y += fw_cfg.o
-hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
+hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
hw-obj-$(CONFIG_PCI) += msix.o msi.o
hw-obj-$(CONFIG_PCI) += shpc.o
hw-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
diff --git a/hw/pci_bridge_dev.c b/hw/pci_bridge_dev.c
new file mode 100644
index 0000000..f48cd2d
--- /dev/null
+++ b/hw/pci_bridge_dev.c
@@ -0,0 +1,136 @@
+/*
+ * Standard PCI Bridge Device
+ *
+ * Copyright (c) 2011 Red Hat Inc. Author: Michael S. Tsirkin <mst@redhat.com>
+ *
+ * http://www.pcisig.com/specifications/conventional/pci_to_pci_bridge_architecture/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "pci_bridge.h"
+#include "pci_ids.h"
+#include "shpc.h"
+#include "memory.h"
+#include "pci_internals.h"
+
+#define REDHAT_PCI_VENDOR_ID 0x1b36
+#define PCI_BRIDGE_DEV_VENDOR_ID REDHAT_PCI_VENDOR_ID
+#define PCI_BRIDGE_DEV_DEVICE_ID 0x1
+
+struct PCIBridgeDev {
+ PCIBridge bridge;
+ MemoryRegion bar;
+};
+typedef struct PCIBridgeDev PCIBridgeDev;
+
+/* Mapping mandated by PCI-to-PCI Bridge architecture specification,
+ * revision 1.2 */
+/* Table 9-1: Interrupt Binding for Devices Behind a Bridge */
+static int pci_bridge_dev_map_irq_fn(PCIDevice *dev, int irq_num)
+{
+ return (irq_num + PCI_SLOT(dev->devfn)) % PCI_NUM_PINS;
+}
+
+static int pci_bridge_dev_initfn(PCIDevice *dev)
+{
+ PCIBridge *br = DO_UPCAST(PCIBridge, dev, dev);
+ PCIBridgeDev *bridge_dev = DO_UPCAST(PCIBridgeDev, bridge, br);
+ int err;
+ br->map_irq = pci_bridge_dev_map_irq_fn;
+ /* If we don't specify the name, the bus will be addressed as <id>.0, where
+ * id is the parent id. But it seems more natural to address the bus using
+ * the parent device name. */
+ if (dev->qdev.id && *dev->qdev.id) {
+ br->bus_name = dev->qdev.id;
+ }
+ err = pci_bridge_initfn(dev);
+ if (err) {
+ goto bridge_error;
+ }
+ memory_region_init(&bridge_dev->bar, "shpc-bar", shpc_bar_size(dev));
+ err = shpc_init(dev, &br->sec_bus, &bridge_dev->bar, 0);
+ if (err) {
+ goto error;
+ }
+ /* TODO: spec recommends using 64 bit prefetcheable BAR.
+ * Check whether that works well. */
+ pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &bridge_dev->bar);
+ dev->config[PCI_INTERRUPT_PIN] = 0x1;
+ return 0;
+error:
+ memory_region_destroy(&bridge_dev->bar);
+bridge_error:
+ return err;
+}
+
+static int pci_bridge_dev_exitfn(PCIDevice *dev)
+{
+ PCIBridge *br = DO_UPCAST(PCIBridge, dev, dev);
+ PCIBridgeDev *bridge_dev = DO_UPCAST(PCIBridgeDev, bridge, br);
+ int ret;
+ shpc_cleanup(dev);
+ memory_region_destroy(&bridge_dev->bar);
+ ret = pci_bridge_exitfn(dev);
+ assert(!ret);
+ return 0;
+}
+
+static void pci_bridge_dev_write_config(PCIDevice *d,
+ uint32_t address, uint32_t val, int len)
+{
+ pci_bridge_write_config(d, address, val, len);
+ shpc_cap_write_config(d, address, val, len);
+}
+
+static void qdev_pci_bridge_dev_reset(DeviceState *qdev)
+{
+ PCIDevice *dev = DO_UPCAST(PCIDevice, qdev, qdev);
+ pci_bridge_reset(qdev);
+ shpc_reset(dev);
+}
+
+static void pci_bridge_dev_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+ k->init = pci_bridge_dev_initfn;
+ k->exit = pci_bridge_dev_exitfn;
+ k->config_write = pci_bridge_dev_write_config;
+ k->vendor_id = PCI_BRIDGE_DEV_VENDOR_ID;
+ k->device_id = PCI_BRIDGE_DEV_DEVICE_ID;
+ k->class_id = PCI_CLASS_BRIDGE_PCI;
+ k->is_bridge = 1,
+ dc->desc = "Standard PCI Bridge";
+ dc->reset = qdev_pci_bridge_dev_reset;
+ /*
+ * TODO: migration.
+ * dc->vmsd =
+ * dc->props =
+ */
+}
+
+static TypeInfo pci_bridge_dev_info = {
+ .name = "pci-bridge",
+ .parent = TYPE_PCI_DEVICE,
+ .instance_size = sizeof(PCIBridgeDev),
+ .class_init = pci_bridge_dev_class_init,
+};
+
+static void pci_bridge_dev_register(void)
+{
+ type_register_static(&pci_bridge_dev_info);
+}
+
+device_init(pci_bridge_dev_register);
--
1.7.9.111.gf3fb0
next prev parent reply other threads:[~2012-02-13 9:16 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-13 9:15 [Qemu-devel] [PATCHv2-RFC 0/2] RFC: standard pci bridge device Michael S. Tsirkin
2012-02-13 9:15 ` [Qemu-devel] [PATCHv2-RFC 1/2] shpc: standard hot plug controller Michael S. Tsirkin
2012-02-13 10:03 ` Isaku Yamahata
2012-02-13 11:49 ` Michael S. Tsirkin
2012-02-13 14:30 ` Isaku Yamahata
2012-02-13 14:49 ` Michael S. Tsirkin
2012-02-17 13:20 ` Gerd Hoffmann
2012-02-13 9:16 ` Michael S. Tsirkin [this message]
2012-02-17 13:25 ` [Qemu-devel] [PATCHv2-RFC 2/2] pci: add standard bridge device Gerd Hoffmann
2012-02-19 14:57 ` Michael S. Tsirkin
2012-02-19 23:44 ` Michael S. Tsirkin
2012-02-17 13:33 ` Gerd Hoffmann
2012-02-20 22:40 ` Michael S. Tsirkin
2012-02-21 8:02 ` Gerd Hoffmann
2012-02-13 9:33 ` [Qemu-devel] [PATCH RFC] seabios: add OSHP method stub Michael S. Tsirkin
2012-02-14 0:34 ` Kevin O'Connor
2012-02-14 0:43 ` Michael S. Tsirkin
2012-02-14 0:48 ` Kevin O'Connor
2012-02-14 1:09 ` Michael S. Tsirkin
2012-02-14 12:49 ` Paul Brook
2012-02-14 13:37 ` Michael S. Tsirkin
2012-02-14 13:47 ` Paul Brook
2012-02-14 14:11 ` Michael S. Tsirkin
2012-02-29 11:25 ` [Qemu-devel] [SeaBIOS] " Gerd Hoffmann
2012-02-13 9:38 ` [Qemu-devel] [PATCHv2-RFC 0/2] RFC: standard pci bridge device Wen Congyang
2012-02-13 9:56 ` Michael S. Tsirkin
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=f9b630bb6c67f0facf29e42277ad7d991e660b3c.1329124507.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yamahata@valinux.co.jp \
/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).