From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:56244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qdfgy-0005T8-Cv for qemu-devel@nongnu.org; Mon, 04 Jul 2011 05:43:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qdfgv-0003S3-Eq for qemu-devel@nongnu.org; Mon, 04 Jul 2011 05:43:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qdfgu-0003Ri-GQ for qemu-devel@nongnu.org; Mon, 04 Jul 2011 05:43:44 -0400 Date: Mon, 4 Jul 2011 12:43:59 +0300 From: "Michael S. Tsirkin" Message-ID: <20110704094358.GA10960@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] pci: add standard bridge device List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Blue Swirl , Anthony Liguori , Stefan Hajnoczi 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 --- 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 + * + * 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) + 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 .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