From patchwork Wed Jun 27 03:49:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venu Busireddy X-Patchwork-Id: 10490469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D49B060375 for ; Wed, 27 Jun 2018 03:54:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C44641FFB2 for ; Wed, 27 Jun 2018 03:54:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B852E26242; Wed, 27 Jun 2018 03:54:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E4D9A1FFB2 for ; Wed, 27 Jun 2018 03:54:10 +0000 (UTC) Received: from localhost ([::1]:56334 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fY1X0-0001Bz-8P for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Jun 2018 23:54:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fY1T1-0006ig-4Z for qemu-devel@nongnu.org; Tue, 26 Jun 2018 23:50:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fY1Sx-0006Ek-Ue for qemu-devel@nongnu.org; Tue, 26 Jun 2018 23:50:03 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:35166) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fY1Sx-0006D2-K8 for qemu-devel@nongnu.org; Tue, 26 Jun 2018 23:49:59 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w5R3nvTn050293; Wed, 27 Jun 2018 03:49:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2017-10-26; bh=A425z6qu9SK4RIN8l2d3WWy8nFFEteRyR2g5aHAhAlE=; b=RR0BtBLxmEihQXjhcKwt8BdIVmEezKZVIHYaoLIMmGXsoVL/2gmvxPYNw2osp6bGmb1J oEWTWYQHtcXJfJ8puqRbFuT5foZgckmBT1OUGNBDwayHG3iAMf5+lgKGy9K0u7ewJyeW V+U6F8Fy7LNt7CbZqxFQqcbOoJsmYd7DvKBtH17yTIETl5/a3lk1hTMwwlD6yLxqqUds 50Dxk+mBFKLTWZA0Qj8ylcc+Vu5M7mM8iZJgRA8t15pSfNajEdt82eefpwt5bPeQg4ea MPFcjAbIvhz77NUtuXJB4aTTh0OGP1Ig0mJr1n9tle4EYw1+FZZbO90iKSsBw9EhMhuo Jw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2jum0a31p6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Jun 2018 03:49:57 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w5R3nucW011993 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 Jun 2018 03:49:56 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w5R3nurg023609; Wed, 27 Jun 2018 03:49:56 GMT Received: from troi.attlocal.net (/10.154.103.180) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 26 Jun 2018 20:49:56 -0700 From: Venu Busireddy To: venu.busireddy@oracle.com, "Michael S . Tsirkin" , Marcel Apfelbaum Date: Tue, 26 Jun 2018 22:49:34 -0500 Message-Id: <20180627034935.20276-5-venu.busireddy@oracle.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180627034935.20276-1-venu.busireddy@oracle.com> References: <20180627034935.20276-1-venu.busireddy@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8936 signatures=668703 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1806270042 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 4/4] Add "Group Identifier" support to Red Hat PCI Express bridge. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add a new bridge device "pcie-downstream" with a Vendor ID of PCI_VENDOR_ID_REDHAT and Device ID of PCI_DEVICE_ID_REDHAT_DOWNSTREAM. Also add the "Vendor-Specific" capability to the bridge to contain the "Group Identifier" (UUID) that will be used to pair a virtio device with the passthrough device attached to that bridge. This capability is added to the bridge iff the "uuid" option is specified for the bridge. Signed-off-by: Venu Busireddy --- default-configs/arm-softmmu.mak | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/pci-bridge/Makefile.objs | 1 + hw/pci-bridge/pcie_downstream.c | 215 +++++++++++++++++++++++++++++ hw/pci-bridge/pcie_downstream.h | 10 ++ include/hw/pci/pci.h | 1 + 7 files changed, 230 insertions(+) create mode 100644 hw/pci-bridge/pcie_downstream.c create mode 100644 hw/pci-bridge/pcie_downstream.h diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak index 834d45cfaf..b86c6fb122 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -139,6 +139,7 @@ CONFIG_IMX_I2C=y CONFIG_PCIE_PORT=y CONFIG_XIO3130=y CONFIG_IOH3420=y +CONFIG_PCIE_DOWNSTREAM=y CONFIG_I82801B11=y CONFIG_ACPI=y CONFIG_SMBIOS=y diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 8c7d4a0fa0..a900c8f052 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -56,6 +56,7 @@ CONFIG_ACPI_NVDIMM=y CONFIG_PCIE_PORT=y CONFIG_XIO3130=y CONFIG_IOH3420=y +CONFIG_PCIE_DOWNSTREAM=y CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) diff --git a/default-configs/x86_64-softmmu.mak b/default-configs/x86_64-softmmu.mak index 0390b4303c..481e4764be 100644 --- a/default-configs/x86_64-softmmu.mak +++ b/default-configs/x86_64-softmmu.mak @@ -56,6 +56,7 @@ CONFIG_ACPI_NVDIMM=y CONFIG_PCIE_PORT=y CONFIG_XIO3130=y CONFIG_IOH3420=y +CONFIG_PCIE_DOWNSTREAM=y CONFIG_I82801B11=y CONFIG_SMBIOS=y CONFIG_HYPERV_TESTDEV=$(CONFIG_KVM) diff --git a/hw/pci-bridge/Makefile.objs b/hw/pci-bridge/Makefile.objs index 47065f87d9..5b42212edc 100644 --- a/hw/pci-bridge/Makefile.objs +++ b/hw/pci-bridge/Makefile.objs @@ -3,6 +3,7 @@ common-obj-$(CONFIG_PCIE_PORT) += pcie_root_port.o gen_pcie_root_port.o pcie_pci common-obj-$(CONFIG_PXB) += pci_expander_bridge.o common-obj-$(CONFIG_XIO3130) += xio3130_upstream.o xio3130_downstream.o common-obj-$(CONFIG_IOH3420) += ioh3420.o +common-obj-$(CONFIG_PCIE_DOWNSTREAM) += pcie_downstream.o common-obj-$(CONFIG_I82801B11) += i82801b11.o # NewWorld PowerMac common-obj-$(CONFIG_DEC_PCI) += dec.o diff --git a/hw/pci-bridge/pcie_downstream.c b/hw/pci-bridge/pcie_downstream.c new file mode 100644 index 0000000000..78604504ea --- /dev/null +++ b/hw/pci-bridge/pcie_downstream.c @@ -0,0 +1,215 @@ +/* + * Red Hat PCI Express downstream port. + * + * pcie_downstream.c + * Most of this code is copied from xio3130_downstream.c + * + * Copyright (c) 2018 Oracle and/or its affiliates. + * Author: Venu Busireddy + * + * 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 "qemu/osdep.h" +#include "hw/pci/pci_ids.h" +#include "hw/pci/msi.h" +#include "hw/pci/pcie.h" +#include "pcie_downstream.h" +#include "qapi/error.h" + +#define REDHAT_PCIE_DS_REVISION 0x1 +#define REDHAT_PCIE_DS_MSI_OFFSET 0x70 +#define REDHAT_PCIE_DS_MSI_SUPPORTED_FLAGS PCI_MSI_FLAGS_64BIT +#define REDHAT_PCIE_DS_MSI_NR_VECTOR 1 +#define REDHAT_PCIE_DS_SSVID_OFFSET 0x80 +#define REDHAT_PCIE_DS_SSVID_SVID 0 +#define REDHAT_PCIE_DS_SSVID_SSID 0 +#define REDHAT_PCIE_DS_EXP_OFFSET 0x90 +#define REDHAT_PCIE_DS_VENDOR_OFFSET 0xCC +#define REDHAT_PCIE_DS_AER_OFFSET 0x100 + +static void pcie_ds_write_config(PCIDevice *d, uint32_t address, + uint32_t val, int len) +{ + pci_bridge_write_config(d, address, val, len); + pcie_cap_flr_write_config(d, address, val, len); + pcie_cap_slot_write_config(d, address, val, len); + pcie_aer_write_config(d, address, val, len); +} + +static void pcie_ds_reset(DeviceState *qdev) +{ + PCIDevice *d = PCI_DEVICE(qdev); + + pcie_cap_deverr_reset(d); + pcie_cap_slot_reset(d); + pcie_cap_arifwd_reset(d); + pci_bridge_reset(qdev); +} + +static void pcie_ds_realize(PCIDevice *d, Error **errp) +{ + PCIEPort *p = PCIE_PORT(d); + PCIESlot *s = PCIE_SLOT(d); + int rc; + + pci_bridge_initfn(d, TYPE_PCIE_BUS); + pcie_port_init_reg(d); + + rc = pci_bridge_vendor_init(d, REDHAT_PCIE_DS_VENDOR_OFFSET, errp); + if (rc < 0) { + error_append_hint(errp, "Can't init group ID, error %d\n", rc); + goto err_bridge; + } + + rc = msi_init(d, REDHAT_PCIE_DS_MSI_OFFSET, REDHAT_PCIE_DS_MSI_NR_VECTOR, + REDHAT_PCIE_DS_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_64BIT, + REDHAT_PCIE_DS_MSI_SUPPORTED_FLAGS & PCI_MSI_FLAGS_MASKBIT, errp); + if (rc < 0) { + assert(rc == -ENOTSUP); + goto err_bridge; + } + + rc = pci_bridge_ssvid_init(d, REDHAT_PCIE_DS_SSVID_OFFSET, + REDHAT_PCIE_DS_SSVID_SVID, REDHAT_PCIE_DS_SSVID_SSID, errp); + if (rc < 0) { + goto err_bridge; + } + + rc = pcie_cap_init(d, REDHAT_PCIE_DS_EXP_OFFSET, PCI_EXP_TYPE_DOWNSTREAM, + p->port, errp); + if (rc < 0) { + goto err_msi; + } + pcie_cap_flr_init(d); + pcie_cap_deverr_init(d); + pcie_cap_slot_init(d, s->slot); + pcie_cap_arifwd_init(d); + + pcie_chassis_create(s->chassis); + rc = pcie_chassis_add_slot(s); + if (rc < 0) { + error_setg(errp, "Can't add chassis slot, error %d", rc); + goto err_pcie_cap; + } + + rc = pcie_aer_init(d, PCI_ERR_VER, REDHAT_PCIE_DS_AER_OFFSET, + PCI_ERR_SIZEOF, errp); + if (rc < 0) { + goto err; + } + + return; + +err: + pcie_chassis_del_slot(s); +err_pcie_cap: + pcie_cap_exit(d); +err_msi: + msi_uninit(d); +err_bridge: + pci_bridge_exitfn(d); +} + +static void pcie_ds_exitfn(PCIDevice *d) +{ + PCIESlot *s = PCIE_SLOT(d); + + pcie_aer_exit(d); + pcie_chassis_del_slot(s); + pcie_cap_exit(d); + msi_uninit(d); + pci_bridge_exitfn(d); +} + +PCIESlot *pcie_ds_init(PCIBus *bus, int devfn, bool multifunction, + const char *bus_name, pci_map_irq_fn map_irq, + uint8_t port, uint8_t chassis, uint16_t slot) +{ + PCIDevice *d; + PCIBridge *br; + DeviceState *qdev; + + d = pci_create_multifunction(bus, devfn, multifunction, "pcie-downstream"); + if (!d) { + return NULL; + } + br = PCI_BRIDGE(d); + + qdev = DEVICE(d); + pci_bridge_map_irq(br, bus_name, map_irq); + qdev_prop_set_uint8(qdev, "port", port); + qdev_prop_set_uint8(qdev, "chassis", chassis); + qdev_prop_set_uint16(qdev, "slot", slot); + qdev_init_nofail(qdev); + + return PCIE_SLOT(d); +} + +static Property pcie_ds_props[] = { + DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present, + QEMU_PCIE_SLTCAP_PCP_BITNR, true), + DEFINE_PROP_UUID(COMPAT_PROP_UUID, PCIDevice, uuid, false), + DEFINE_PROP_END_OF_LIST() +}; + +static const VMStateDescription vmstate_pcie_ds = { + .name = "pci-express-downstream-port", + .priority = MIG_PRI_PCI_BUS, + .version_id = 1, + .minimum_version_id = 1, + .post_load = pcie_cap_slot_post_load, + .fields = (VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_obj.parent_obj.parent_obj, PCIESlot), + VMSTATE_STRUCT(parent_obj.parent_obj.parent_obj.exp.aer_log, + PCIESlot, 0, vmstate_pcie_aer_log, PCIEAERLog), + VMSTATE_END_OF_LIST() + } +}; + +static void pcie_ds_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + + k->is_bridge = 1; + k->config_write = pcie_ds_write_config; + k->realize = pcie_ds_realize; + k->exit = pcie_ds_exitfn; + k->vendor_id = PCI_VENDOR_ID_REDHAT; + k->device_id = PCI_DEVICE_ID_REDHAT_DOWNSTREAM; + k->revision = REDHAT_PCIE_DS_REVISION; + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); + dc->desc = "Red Hat PCIe Downstream Port"; + dc->reset = pcie_ds_reset; + dc->vmsd = &vmstate_pcie_ds; + dc->props = pcie_ds_props; +} + +static const TypeInfo pcie_ds_info = { + .name = "pcie-downstream", + .parent = TYPE_PCIE_SLOT, + .class_init = pcie_ds_class_init, + .interfaces = (InterfaceInfo[]) { + { INTERFACE_PCIE_DEVICE }, + { } + }, +}; + +static void pcie_ds_register_types(void) +{ + type_register_static(&pcie_ds_info); +} + +type_init(pcie_ds_register_types) diff --git a/hw/pci-bridge/pcie_downstream.h b/hw/pci-bridge/pcie_downstream.h new file mode 100644 index 0000000000..54f18be285 --- /dev/null +++ b/hw/pci-bridge/pcie_downstream.h @@ -0,0 +1,10 @@ +#ifndef QEMU_PCIE_DOWNSTREAM_H +#define QEMU_PCIE_DOWNSTREAM_H + +#include "hw/pci/pcie_port.h" + +PCIESlot *pcie_downstream_init(PCIBus *bus, int devfn, bool multifunction, + const char *bus_name, pci_map_irq_fn map_irq, + uint8_t port, uint8_t chassis, uint16_t slot); + +#endif /* QEMU_PCIE_DOWNSTREAM_H */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index ee234c5a6f..5c61a5b496 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -103,6 +103,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_REDHAT_XHCI 0x000d #define PCI_DEVICE_ID_REDHAT_PCIE_BRIDGE 0x000e #define PCI_DEVICE_ID_REDHAT_MDPY 0x000f +#define PCI_DEVICE_ID_REDHAT_DOWNSTREAM 0x0010 #define PCI_DEVICE_ID_REDHAT_QXL 0x0100 #define FMT_PCIBUS PRIx64