From patchwork Mon Jul 4 09:43:59 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 103058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 157BAB6F6C for ; Mon, 4 Jul 2011 19:50:30 +1000 (EST) Received: from localhost ([::1]:56284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QdfnN-0006VP-Bd for incoming@patchwork.ozlabs.org; Mon, 04 Jul 2011 05:50:25 -0400 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 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p649hdUa026077 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 4 Jul 2011 05:43:39 -0400 Received: from redhat.com (vpn-202-209.tlv.redhat.com [10.35.202.209]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id p649hajB028027; Mon, 4 Jul 2011 05:43:37 -0400 Date: Mon, 4 Jul 2011 12:43:59 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20110704094358.GA10960@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Blue Swirl , Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] pci: add standard bridge device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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);