>From 1676d449355662e5842cb0c66b0eaed4e5b2bf6a Mon Sep 17 00:00:00 2001 From: Michael S. Tsirkin Date: Mon, 4 Jul 2011 12:43:59 +0300 Subject: [PATCH] pci: add standard bridge device 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. [ kraxel: squashed in irq routing fix ] Signed-off-by: Michael S. Tsirkin --- 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 7b0739c..69c9aa9 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -188,7 +188,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) += 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..a6768b0 --- /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 + * + * 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 . + */ + +#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)) % 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 .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.1