[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] pci: add standard bridge device
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PATCH] pci: add standard bridge device |
Date: |
Mon, 4 Jul 2011 12:43:59 +0300 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
This adds support for a standard pci to pci bridge,
enabling support for more than 32 PCI devices in the system.
To use, specify the device id as a 'bus' option.
Example:
-device pci-bridge,id=bridge1 \
-netdev user,id=u \
-device ne2k_pci,id=net2,bus=bridge1,netdev=u
TODO: device hotplug support.
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
Makefile.objs | 2 +-
hw/pci_bridge_dev.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 1 deletions(-)
create mode 100644 hw/pci_bridge_dev.c
diff --git a/Makefile.objs b/Makefile.objs
index cea15e4..9e82b12 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -174,7 +174,7 @@ hw-obj-y += vl.o loader.o
hw-obj-$(CONFIG_VIRTIO) += virtio.o virtio-console.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) += pci_host.o pcie_host.o
hw-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
diff --git a/hw/pci_bridge_dev.c b/hw/pci_bridge_dev.c
new file mode 100644
index 0000000..c7ab5ad
--- /dev/null
+++ b/hw/pci_bridge_dev.c
@@ -0,0 +1,70 @@
+/*
+ * Standard PCI Bridge Device
+ *
+ * Copyright (c) 2011 Red Hat Inc. Author: Michael S. Tsirkin <address@hidden>
+ *
+ *
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 "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
+
+/* 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) + irq_num) % PCI_NUM_PINS;
+}
+
+static int pci_bridge_dev_initfn(PCIDevice *dev)
+{
+ PCIBridge *br = DO_UPCAST(PCIBridge, dev, dev);
+ 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;
+ }
+ return pci_bridge_initfn(dev);
+}
+
+static PCIDeviceInfo pci_bridge_dev_info = {
+ .qdev.name = "pci-bridge",
+ .qdev.desc = "Standard PCI Bridge",
+ .qdev.size = sizeof(PCIBridge),
+ .qdev.reset = pci_bridge_reset,
+ .is_bridge = 1,
+ .config_write = pci_bridge_write_config,
+ .init = pci_bridge_dev_initfn,
+ .exit = pci_bridge_exitfn,
+ .vendor_id = PCI_BRIDGE_DEV_VENDOR_ID,
+ .device_id = PCI_BRIDGE_DEV_DEVICE_ID,
+ .class_id = PCI_CLASS_BRIDGE_PCI,
+};
+
+static void pci_bridge_dev_register(void)
+{
+ pci_qdev_register(&pci_bridge_dev_info);
+}
+
+device_init(pci_bridge_dev_register);
--
1.7.5.53.gc233e
- [Qemu-devel] [PATCH] pci: add standard bridge device,
Michael S. Tsirkin <=