From patchwork Thu Oct 11 20:31:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10637395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E17F112B for ; Thu, 11 Oct 2018 20:34:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B4142C068 for ; Thu, 11 Oct 2018 20:34:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FFD62C074; Thu, 11 Oct 2018 20:34:14 +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.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 A557B2C06B for ; Thu, 11 Oct 2018 20:34:13 +0000 (UTC) Received: from localhost ([::1]:36989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAhev-0008HC-0o for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 16:34:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAhd9-0006ub-RY for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:32:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAhd4-0006rM-0H for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:32:23 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:7470) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gAhcz-0006kR-6s for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:32:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539289933; x=1570825933; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=GoMgZcH2fHlR9h1e6MoxF07+0WD+6N850VNnILVqeTk=; b=ir3WcYjr4edvpMdikR5WcxdgHJONSDhSJtePpoGLtrItL8PlcE1uUt8D 6mp6/2TxDPgnGqGLGEckgHY26iejHLZ6j2fR/4V8AYSNw0Q+huVKPO0OM 5yNt7aaGUeFj+eGc/ceJ9EVkhmV7dXpaZcqxvLvfQcfN67g/1fds6LnmJ uQxvDDr72YcPBbDuKorPXRby+QP6k/ebK87ZdoE6H0O6sJ0x94cKSphu2 3MnNX67ghPrJmq9J77PrYmZDpmNHwnzG2AgPkAx8wE9k+s6RgaFAQspAN X3+P7PyW55KXjEFtR/utNSDG6ZDUEteyqwMbW4u2nftJ9jyjEvn06AmxO Q==; X-IronPort-AV: E=Sophos;i="5.54,369,1534780800"; d="scan'208";a="196107748" Received: from mail-sn1nam02lp0016.outbound.protection.outlook.com (HELO NAM02-SN1-obe.outbound.protection.outlook.com) ([216.32.180.16]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 04:31:50 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sa9N/nMvQqT/g492ukwBhR5czzHLMcaYl1fHmL5HhnQ=; b=TyAi3ZI0ND4eR6PWSPn4649i9EnAVtQwF49BGdn9jTIwb/Hg2xrezASB2rV+a+EkWFXQNs3mXnXyMSNzpGVRYjwnnE1xjU1dSi2Y8JYD9F4F39/xbvOvTxkI4VeX+EonseR/g+hBL9mKBxr/GUdB74Bx3qerYOYDhlwTAHHMBPw= Received: from CY4PR04MB0392.namprd04.prod.outlook.com (10.173.188.145) by CY4PR04MB0454.namprd04.prod.outlook.com (10.173.189.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1228.23; Thu, 11 Oct 2018 20:31:49 +0000 Received: from CY4PR04MB0392.namprd04.prod.outlook.com ([fe80::ddab:bdc2:6bc7:6d22]) by CY4PR04MB0392.namprd04.prod.outlook.com ([fe80::ddab:bdc2:6bc7:6d22%6]) with mapi id 15.20.1228.020; Thu, 11 Oct 2018 20:31:49 +0000 From: Alistair Francis To: "peter.maydell@linaro.org" Thread-Topic: [PULL 04/10] hw/riscv/sifive_u: Connect the Xilinx PCIe Thread-Index: AQHUYaFv+VjXMORuOEuO8wlcUTgcXA== Date: Thu, 11 Oct 2018 20:31:49 +0000 Message-ID: <20181011203115.18666-5-alistair.francis@wdc.com> References: <20181011203115.18666-1-alistair.francis@wdc.com> In-Reply-To: <20181011203115.18666-1-alistair.francis@wdc.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SG2PR01CA0126.apcprd01.prod.exchangelabs.com (2603:1096:4:40::30) To CY4PR04MB0392.namprd04.prod.outlook.com (2603:10b6:903:b1::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.250] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY4PR04MB0454; 6:imXGoCNyrDzKyvSvFJ9P0+0o0wkHJswZepmTHx2vITDm8Twt/QLCdCVnKfcuTqO63/HYLVS4Ug+hRIcKS2EJHGwPnhL4YNw8/1UrLvleUBy1ayG6R9h+gYGn9JR8gBaIbDB8tXh6zUvXRR2qQk2xLGuBix+zAMoTy6yeCxFeAczQ6mRSR6Tn1V7SYaih9Z6mROGIsjxL9VRd/JdHg63KPauv1/u9MVnhmINMKMiWbNWh7zcsFml8Z9RIjsxFCRWJcCgU8Qc53Am4Cg1pXftJeshViXLWpY+XWbzwD/OmMYgd91EGRXvnwscKoNkUUsw7jr8NryjGNcA9IaMW/GnTqduxwvD/A+PqDplULmxHuxfQ5uHQMJsJF/yQFe6iSdpqBZaE91nmT8WOwa26XHvRutPNHVbJ7uFqQdki7w+J9ZTi2dTfF9Ty14slk8d4eRYWaE9b465PVUJ3ObLjfLxRwg==; 5:Jp8RsGb27wD+YXxLiisi5RQ9ISoqGDpE7X3+a2ebQZtryBBbXFwqF6kdvaRwW5U43wxA8pOvR9vhgJFzGDKjy/Rb1mns4iV+tswDAtcuuQVBC9WY2l6jd7bW8ydtLy3ZtowxEOQ0sLoEh9n8oWhsJ/a/DullSkAS+Aydv9YoCzg=; 7:W1KU/TkxfjmDWlZcLgQSYe00Nn6cNI73bx0rNjtGy+icRJfD5OrKbyg6p/l2HSUnNlN/Xk2UO+znQ0T7CqwGbeGmNl/4ic6l/THTxKnUOTZtbeGFtERNt0XKEdvpplAM/wHvBoR17+mkUeshVavoD/FKTTSO1mzr99zL2DuR72vcRhThbVJNHyLLd+PUL7HvD9j25LtkZPsQl2Kb/4e2DWHaD+s5jsB0PjGv1WhQR92tiDCZMTMRIOJ1NYiFfQQK x-ms-office365-filtering-correlation-id: 9149dfc1-a43a-464b-6de0-08d62fb89202 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:CY4PR04MB0454; x-ms-traffictypediagnostic: CY4PR04MB0454: wdcipoutbound: EOP-TRUE x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(21532816269658); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231355)(944501410)(52105095)(6055026)(149066)(150057)(6041310)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:CY4PR04MB0454; BCL:0; PCL:0; RULEID:; SRVR:CY4PR04MB0454; x-forefront-prvs: 08220FA8D6 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(346002)(39860400002)(376002)(366004)(396003)(199004)(189003)(71190400001)(71200400001)(2906002)(26005)(76176011)(2900100001)(316002)(478600001)(6436002)(54906003)(14454004)(36756003)(53936002)(6512007)(5640700003)(6486002)(66066001)(81156014)(2351001)(8936002)(476003)(7736002)(72206003)(8676002)(50226002)(105586002)(446003)(86362001)(106356001)(11346002)(99286004)(14444005)(2616005)(186003)(1076002)(3846002)(6116002)(5250100002)(2501003)(52116002)(6916009)(256004)(97736004)(25786009)(4326008)(68736007)(386003)(486006)(44832011)(5660300001)(102836004)(305945005)(81166006)(6506007); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR04MB0454; H:CY4PR04MB0392.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-microsoft-antispam-message-info: t3saycSb0yDlCKHAtvDf+qV/JwBNueVT8e4oGdlv5a8dGc6QhZjl8fLOwQVopRzv0jzz1oa65nqQ56fta/W5iiCVkuDlL4Q1gtNj6XNKFKxEBPmM4x0+Hsq5ocCGcm+PGr0nKI92RkdA/FUzktAtaWaKDQZRHeZBxxeE9IdkXOs/ChkHL1IkS2GsUdluEDt48qMeobK3uqA2SeVmOCmNAQ5gpLeB0E2N+mFz01gqwYYLs6htnEfJlQ0nBmfvAtMVPy27Eo8wFyOkf8mg+8FOMq1YwRCZLC26vWlQKEVH6QkvC7lvNmpODAeZMJ/GKI/Vf9FytRx2MfU4+MKu33HpmKMXIdguA1K3pqL3a9TVIX0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9149dfc1-a43a-464b-6de0-08d62fb89202 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2018 20:31:49.4368 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB0454 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 68.232.141.245 Subject: [Qemu-devel] [PULL 04/10] hw/riscv/sifive_u: Connect the Xilinx PCIe 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: Alistair Francis , "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 Connect the Xilinx PCIe device based on the information in the device tree stored in the ROM of the HiFish Unleashed board. Signed-off-by: Alistair Francis --- hw/riscv/sifive_u.c | 64 +++++++++++++++++++++++++++++++++++++ include/hw/riscv/sifive_u.h | 4 ++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 862f8ff5f7..4e273119c3 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -45,6 +45,8 @@ #include "sysemu/arch_init.h" #include "sysemu/device_tree.h" #include "exec/address-spaces.h" +#include "hw/pci/pci.h" +#include "hw/pci-host/xilinx-pcie.h" #include "elf.h" #include @@ -61,6 +63,7 @@ static const struct MemmapEntry { [SIFIVE_U_UART1] = { 0x10023000, 0x1000 }, [SIFIVE_U_DRAM] = { 0x80000000, 0x0 }, [SIFIVE_U_GEM] = { 0x100900FC, 0x2000 }, + [SIFIVE_U_PCIE] = { 0x2000000000, 0x4000000 }, }; #define GEM_REVISION 0x10070109 @@ -218,6 +221,32 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, qemu_fdt_setprop_cells(fdt, nodename, "reg", 0x0); g_free(nodename); + nodename = g_strdup_printf("/pci@%lx", + (long) memmap[SIFIVE_U_PCIE].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cells(fdt, nodename, "#address-cells", 0x3); + qemu_fdt_setprop_cells(fdt, nodename, "#interrupt-cells", 0x1); + qemu_fdt_setprop_cells(fdt, nodename, "#size-cells", 0x2); + qemu_fdt_setprop_string(fdt, nodename, "compatible", + "xlnx,axi-pcie-host-1.00.a"); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "pci"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", 0x20, 0x0, 0x0, + memmap[SIFIVE_U_PCIE].size); + qemu_fdt_setprop_string(fdt, nodename, "reg-names", "control"); + qemu_fdt_setprop_cells(fdt, nodename, "ranges", 0x2000000, 0x0, + 0x40000000, 0x0, 0x40000000, 0x0, 0x20000000); + qemu_fdt_setprop_cells(fdt, nodename, "interrupt-parent", plic_phandle); + qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_PCIE_IRQ); + g_free(nodename); + + nodename = g_strdup_printf("/pci@%lx/interrupt-controller", + (long) memmap[SIFIVE_U_PCIE].base); + qemu_fdt_add_subnode(fdt, nodename); + qemu_fdt_setprop_cells(fdt, nodename, "#address-cells", 0x00); + qemu_fdt_setprop_cells(fdt, nodename, "#interrupt-cells", 0x1); + qemu_fdt_setprop(fdt, nodename, "interrupt-controller", NULL, 0); + g_free(nodename); + nodename = g_strdup_printf("/soc/uart@%lx", (long)memmap[SIFIVE_U_UART0].base); qemu_fdt_add_subnode(fdt, nodename); @@ -234,6 +263,37 @@ static void create_fdt(SiFiveUState *s, const struct MemmapEntry *memmap, g_free(nodename); } +static inline DeviceState * +xilinx_pcie_init(MemoryRegion *sys_mem, uint32_t bus_nr, + hwaddr cfg_base, uint64_t cfg_size, + hwaddr mmio_base, uint64_t mmio_size, + qemu_irq irq, bool link_up) +{ + DeviceState *dev; + MemoryRegion *cfg, *mmio; + + dev = qdev_create(NULL, TYPE_XILINX_PCIE_HOST); + + qdev_prop_set_uint32(dev, "bus_nr", bus_nr); + qdev_prop_set_uint64(dev, "cfg_base", cfg_base); + qdev_prop_set_uint64(dev, "cfg_size", cfg_size); + qdev_prop_set_uint64(dev, "mmio_base", mmio_base); + qdev_prop_set_uint64(dev, "mmio_size", mmio_size); + qdev_prop_set_bit(dev, "link_up", link_up); + + qdev_init_nofail(dev); + + cfg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0); + memory_region_add_subregion_overlap(sys_mem, cfg_base, cfg, 0); + + mmio = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1); + memory_region_add_subregion_overlap(sys_mem, 0, mmio, 0); + + qdev_connect_gpio_out_named(dev, "interrupt_out", 0, irq); + + return dev; +} + static void riscv_sifive_u_init(MachineState *machine) { const struct MemmapEntry *memmap = sifive_u_memmap; @@ -373,6 +433,10 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp) sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem), 0, memmap[SIFIVE_U_GEM].base); sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem), 0, plic_gpios[SIFIVE_U_GEM_IRQ]); + + xilinx_pcie_init(system_memory, 0, memmap[SIFIVE_U_PCIE].base, + memmap[SIFIVE_U_PCIE].size, 0x40000000, 0x20000000, + qdev_get_gpio_in(DEVICE(s->plic), SIFIVE_U_PCIE_IRQ), true); } static void riscv_sifive_u_machine_init(MachineClass *mc) diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h index e8b4d9ffa3..e7292ea83b 100644 --- a/include/hw/riscv/sifive_u.h +++ b/include/hw/riscv/sifive_u.h @@ -53,12 +53,14 @@ enum { SIFIVE_U_UART0, SIFIVE_U_UART1, SIFIVE_U_DRAM, - SIFIVE_U_GEM + SIFIVE_U_GEM, + SIFIVE_U_PCIE }; enum { SIFIVE_U_UART0_IRQ = 3, SIFIVE_U_UART1_IRQ = 4, + SIFIVE_U_PCIE_IRQ = 0x20, SIFIVE_U_GEM_IRQ = 0x35 };