From nobody Thu May 2 08:53:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498410782177930.511419600806; Sun, 25 Jun 2017 10:13:02 -0700 (PDT) Received: from localhost ([::1]:43274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPB5n-0001Ba-J0 for importer@patchew.org; Sun, 25 Jun 2017 13:12:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPB4R-0008Ov-D8 for qemu-devel@nongnu.org; Sun, 25 Jun 2017 13:11:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPB4Q-0007rF-5l for qemu-devel@nongnu.org; Sun, 25 Jun 2017 13:11:35 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:36592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPB4P-0007qX-RL for qemu-devel@nongnu.org; Sun, 25 Jun 2017 13:11:34 -0400 Received: by mail-lf0-x241.google.com with SMTP id f28so10996150lfi.3 for ; Sun, 25 Jun 2017 10:11:33 -0700 (PDT) Received: from localhost.localdomain (broadband-5-228-183-39.moscow.rt.ru. [5.228.183.39]) by smtp.gmail.com with ESMTPSA id w3sm1460400ljd.35.2017.06.25.10.11.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Jun 2017 10:11:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8aGJ0yaEd7GZHXUKo/SHU7gEV79cNWIr+mZytu934/U=; b=dLwKWC+EznCffu0mMdfNA+/1pN5rQlJ7s6NDlu48sl9U465NU14x9k1QlA4hjx6ImG mfZi4Aw42gbXFV+0+lqelIAmfsWcButWHzoCQsfYUbea93Fb/mYxxV/lV8rQMhuleq8C H3EdXOJzgEwYOQ7G3fhu5EZ1EMatsqb5cP5tKqNaHZJK+a++sJPJIayeFVfvXnmKQW8U npO72wq9rCPjDF7cgJLS+NTKJlmAbm5GzEw6XccYlPeCSrzquSnsL7CFfhhqVs7DGgzz g7nS4C+2zX4t8dk2pnkyrSO+NuSdw+vfm+3BqNxwzr4zd4Wv9vM9GFBxUbDPxxHChEzs r22g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8aGJ0yaEd7GZHXUKo/SHU7gEV79cNWIr+mZytu934/U=; b=uJF8X0APYHJxVNNx0feby0gsulBMvVMtCrKKUm7IZcoB6j1GcBgVjemmFLDKW2O/zB 7WJRwSXlY/4OWYV7GDHPc5NtTwXRN9Q27FkPEiEn1q6I7coqOGFFiaJoweLH13YQr3RJ qQG0H9hZLe2J01x9hKAQ3VRCKTUe6FCdDEJWmJ92Mitx1+MEfKmddFxqB8gm3cScO6wK hkvPI647+7CUOgCzqq/2C2BZXtjGQdCjkzkD+Hk+JS+4IbY/tZCMg2QGe5fnalH7UQ1A 3CrAAhSzUi30bmNfcix6amjWguGXiHLEnNw7rI//YoWmKRWQ7yA5vvfnM8JExxrk6jz5 fAjg== X-Gm-Message-State: AKS2vOyFOU9gFPAuri3Y5y2FvE2nqwPDou69d9YA/oQGIbWy4QkUQnNb ukJ37dKkRR+JhE3V X-Received: by 10.25.225.153 with SMTP id l25mr5672088lfk.103.1498410692331; Sun, 25 Jun 2017 10:11:32 -0700 (PDT) From: Aleksandr Bezzubikov To: qemu-devel@nongnu.org Date: Sun, 25 Jun 2017 20:11:00 +0300 Message-Id: <1498410660-15762-2-git-send-email-zuban32s@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498410660-15762-1-git-send-email-zuban32s@gmail.com> References: <1498410660-15762-1-git-send-email-zuban32s@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH RFC] hw/pci-bridge: implement pcie-pci-bridge device 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: marcel@redhat.com, imammedo@redhat.com, Aleksandr Bezzubikov , mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Aleksandr Bezzubikov --- hw/pci-bridge/Makefile.objs | 2 +- hw/pci-bridge/pcie_pci_bridge.c | 152 ++++++++++++++++++++++++++++++++++++= ++++ include/hw/pci/pci.h | 1 + 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 hw/pci-bridge/pcie_pci_bridge.c diff --git a/hw/pci-bridge/Makefile.objs b/hw/pci-bridge/Makefile.objs index c4683cf..666db37 100644 --- a/hw/pci-bridge/Makefile.objs +++ b/hw/pci-bridge/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-y +=3D pci_bridge_dev.o +common-obj-y +=3D pci_bridge_dev.o pcie_pci_bridge.o common-obj-$(CONFIG_PCIE_PORT) +=3D pcie_root_port.o gen_pcie_root_port.o common-obj-$(CONFIG_PXB) +=3D pci_expander_bridge.o common-obj-$(CONFIG_XIO3130) +=3D xio3130_upstream.o xio3130_downstream.o diff --git a/hw/pci-bridge/pcie_pci_bridge.c b/hw/pci-bridge/pcie_pci_bridg= e.c new file mode 100644 index 0000000..06b19d6 --- /dev/null +++ b/hw/pci-bridge/pcie_pci_bridge.c @@ -0,0 +1,152 @@ +/* + * QEMU Generic PCIE-PCI Bridge + * + * Copyright (c) 2017 Aleksandr Bezzubikov + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/pci/pci.h" +#include "hw/pci/pci_bus.h" +#include "hw/pci/pci_bridge.h" +#include "hw/pci/msi.h" +#include "hw/pci/slotid_cap.h" + +typedef struct PCIEPCIBridge { + /*< private >*/ + PCIBridge parent_obj; + +#define PCI_BRIDGE_DEV_F_SHPC_REQ 0 + uint32_t flags; + /*< public >*/ +} PCIEPCIBridge; + +#define TYPE_PCIE_PCI_BRIDGE_DEV "pcie-pci-bridge" +#define PCIE_PCI_BRIDGE_DEV(obj) \ + OBJECT_CHECK(PCIEPCIBridge, (obj), TYPE_PCIE_PCI_BRIDGE_DEV) + +static void pciepci_bridge_realize(PCIDevice *d, Error **errp) +{ + int rc, pos; + Error *local_err =3D NULL; + + pci_bridge_initfn(d, TYPE_PCI_BUS); + + rc =3D pci_bridge_ssvid_init(d, 0, 0, 0x32); + if (rc < 0) { + error_setg(errp, "Can't add SSVID, error %d", rc); + goto error; + } + + rc =3D pcie_cap_init(d, 0, PCI_EXP_TYPE_PCI_BRIDGE, 0); + if (rc < 0) { + error_setg(errp, "Can't add PCIE-PCI bridge capability, error %d",= rc); + goto error; + } + + pos =3D pci_add_capability(d, PCI_CAP_ID_PM, 0, PCI_PM_SIZEOF); + assert(pos > 0); + d->exp.pm_cap =3D pos; + pci_set_word(d->config + pos + PCI_PM_PMC, 0x3); + + pcie_cap_arifwd_init(d); + pcie_cap_deverr_init(d); + + rc =3D pcie_aer_init(d, PCI_ERR_VER, 0x100, PCI_ERR_SIZEOF, &local_err= ); + if (rc < 0) { + error_propagate(errp, local_err); + goto error; + } + + rc =3D msi_init(d, 0, 1, 1, 1, &local_err); + if (rc < 0) { + error_propagate(errp, local_err); + } + + return; + + error: + pci_bridge_exitfn(d); +} + +static void pciepci_bridge_exit(PCIDevice *d) +{ + pcie_cap_exit(d); + pci_bridge_exitfn(d); +} + +static void pciepci_bridge_reset(DeviceState *qdev) +{ + pci_bridge_reset(qdev); +} + +static void pcie_pci_bridge_write_config(PCIDevice *d, + uint32_t address, uint32_t val, int len) +{ + pci_bridge_write_config(d, address, val, len); + msi_write_config(d, address, val, len); +} + + +static Property pcie_pci_bridge_dev_properties[] =3D { + DEFINE_PROP_END_OF_LIST(), +}; + +static const VMStateDescription pciepci_bridge_dev_vmstate =3D { + .name =3D TYPE_PCIE_PCI_BRIDGE_DEV, + .fields =3D (VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_obj, PCIBridge), + VMSTATE_END_OF_LIST() + } +}; + +static void pciepci_bridge_class_init(ObjectClass *klass, void *data) +{ + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + k->is_express =3D 1; + k->is_bridge =3D 1; + k->vendor_id =3D PCI_VENDOR_ID_REDHAT; + k->device_id =3D PCI_DEVICE_ID_REDHAT_PCIE_BRIDGE; + k->realize =3D pciepci_bridge_realize; + k->exit =3D pciepci_bridge_exit; + k->config_write =3D pcie_pci_bridge_write_config; + dc->vmsd =3D &pciepci_bridge_dev_vmstate; + dc->props =3D pcie_pci_bridge_dev_properties; + dc->vmsd =3D &pciepci_bridge_dev_vmstate; + dc->reset =3D &pciepci_bridge_reset; + set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); +} + +static const TypeInfo pciepci_bridge_info =3D { + .name =3D TYPE_PCIE_PCI_BRIDGE_DEV, + .parent =3D TYPE_PCI_BRIDGE, + .instance_size =3D sizeof(PCIEPCIBridge), + .class_init =3D pciepci_bridge_class_init +}; + +static void pciepci_register(void) +{ + type_register_static(&pciepci_bridge_info); +} + +type_init(pciepci_register); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index a37a2d5..47bf8da 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -98,6 +98,7 @@ #define PCI_DEVICE_ID_REDHAT_PXB_PCIE 0x000b #define PCI_DEVICE_ID_REDHAT_PCIE_RP 0x000c #define PCI_DEVICE_ID_REDHAT_XHCI 0x000d +#define PCI_DEVICE_ID_REDHAT_PCIE_BRIDGE 0x000e #define PCI_DEVICE_ID_REDHAT_QXL 0x0100 =20 #define FMT_PCIBUS PRIx64 --=20 2.7.4