From patchwork Thu Oct 4 20:06: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: 10626611 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 3A80C13BB for ; Thu, 4 Oct 2018 20:11:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BBF8296C4 for ; Thu, 4 Oct 2018 20:11:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FE40296CA; Thu, 4 Oct 2018 20:11:59 +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 649ED296C4 for ; Thu, 4 Oct 2018 20:11:58 +0000 (UTC) Received: from localhost ([::1]:58836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g89yX-0003EF-GW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Oct 2018 16:11:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g89tm-0008UH-GL for qemu-devel@nongnu.org; Thu, 04 Oct 2018 16:07:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g89ti-00083O-7a for qemu-devel@nongnu.org; Thu, 04 Oct 2018 16:07:02 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:31232) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g89tg-0007zV-6t for qemu-devel@nongnu.org; Thu, 04 Oct 2018 16:06:58 -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=1538683616; x=1570219616; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=GoMgZcH2fHlR9h1e6MoxF07+0WD+6N850VNnILVqeTk=; b=pYsMnMIWBsGf69dQGyU2fVn+ZFXMsEH7JazS7ElO01HMkKAYEO27ThJs kaSZJAcKluXTkogMK0i0x6eW8Usqoeo0OQxm+VEtRz/xiu3ztAINKDNQr j12aKTGRpaqhGfjRAP3sEqCqySswJ/m/0ojlk8fjlBS5QOnmkw6Zz8KQJ CTsN+5pBCVviSnJIjTAuZR7r33TUX7iRlaJCl7PVyoLP2PFNKY1BUj0nC 5N6Vs/sTfoGqtDFm4GF//QsBgtlIGI0hJY2CY26/+S3zzCmpTfzND3UER PlPox+CkgExP117jbMlxaGz8wjW4TSfFo2uAa0ZIatnPFeRgUixCw5Xus A==; X-IronPort-AV: E=Sophos;i="5.54,341,1534780800"; d="scan'208";a="195573145" Received: from mail-bl2nam02lp0087.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.87]) by ob1.hgst.iphmx.com with ESMTP; 05 Oct 2018 04:06:51 +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=LKUAuIwkA4ZVcfpvJ2N/J0ujs6JOhMCkjgXmJXK9C0fZ4bli/HQVBy7e+q7ou9fP5pL51nCLDpEEVDL1R/i0UBA1P0DVqQ53WXWGcQSh2/K0w/VDEbnpYIpHnhLXOjGSgbhshORqffza4863nTJQNezxhZp2uXeEzYSYlvXfXr4= Received: from MWHPR04MB0401.namprd04.prod.outlook.com (10.173.48.18) by MWHPR04MB1136.namprd04.prod.outlook.com (10.173.51.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.25; Thu, 4 Oct 2018 20:06:49 +0000 Received: from MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::f94c:102e:8dce:7c02]) by MWHPR04MB0401.namprd04.prod.outlook.com ([fe80::f94c:102e:8dce:7c02%6]) with mapi id 15.20.1185.026; Thu, 4 Oct 2018 20:06:49 +0000 From: Alistair Francis To: "qemu-devel@nongnu.org" , "mjc@sifive.com" Thread-Topic: [PATCH v5 4/5] hw/riscv/sifive_u: Connect the Xilinx PCIe Thread-Index: AQHUXB3I32qWzxk9NkKscbO2Il9kmQ== Date: Thu, 4 Oct 2018 20:06:49 +0000 Message-ID: References: In-Reply-To: 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: BYAPR02CA0058.namprd02.prod.outlook.com (2603:10b6:a03:54::35) To MWHPR04MB0401.namprd04.prod.outlook.com (2603:10b6:300:70::18) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alistair.Francis@wdc.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [199.255.44.171] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; MWHPR04MB1136; 6:pSUzFZggls2T1kuuzIxF54MZRLlhC+04l410X14NA1JXvfwTk0ZyQQurBZf96TbOnH8xtDiT8xXYKco64GUOADiyJOSJF0GZ8RWF0mFcRxV4XeG/8ap6L3vaOam+u5EfTtHV3DSMXnSBDCw4FgyWJ4pEiSJI1a6hV4QQ9OcJoZJjmyjDoz737L26sakldsEKD50cC1Ltxg4R21PWVTFath3gqXbex2mksAERRk5rQV352UiMYBqgi5MAVIFo08ijhdOKIoFgqKBnZURJ1vgYLngcb1+dAsI+5QlkhLFcZeCF4/B6gkAv0NsOttUL0VlCi0lYo59GpANvSKNwYNjtHTerv80uIM9lWdecqYvfuLfVcpq61GqKAVsEJ9qBmnY4hNyZZt7QqZazPg0j1cE6Qj1AuINm+QI+QkIpTkcrwDAl3v+p/eNObcZuGJn4FkLnhqPHH/aHHMUG3b8jlqpXAg==; 5:K8Bta9Fd+684m/mEtcwaYfimJPIxMY13BxeaukQ7CY3iv3Y1vYsc2+IlfZaErFl7vuaUbbe78pGT/79M2K7G9+WUR4sT5clXXzO1vWQ35NywgYiuVmacG+Vb3XV9AT1ouxIhlT3wCJwnqfy+RWQxcCXletBXdlc+5jekv3MWxj0=; 7:VkrSI2iyDUNPIi8DO8umU285C2GD6oRxx+rHOsV1u+jc/z47svn4gtM+XGkO/bC/x7EFjsuovzIQT/LWm3u5wl6K8hA6qlOwVAVn+p5n/c3rezjVFavZ02zwAGPiNEHTZbUj7V9CRk/21usgkq/de90j867t5f6IYn3JDuI6O0thxL/r1DQ7he22eFejpTvkJ7pMscCiI7q/ilVJaZfFPzRCaVakGdhZaFYo9LeAm2M4m0ndQ5VbWJxxJF1dn9ow x-ms-office365-filtering-correlation-id: e38e02cc-138b-4db0-2eaf-08d62a34eb02 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:MWHPR04MB1136; x-ms-traffictypediagnostic: MWHPR04MB1136: 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)(3002001)(3231355)(944501410)(52105095)(10201501046)(6055026)(149066)(150057)(6041310)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(201708071742011)(7699051); SRVR:MWHPR04MB1136; BCL:0; PCL:0; RULEID:; SRVR:MWHPR04MB1136; x-forefront-prvs: 0815F8251E x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(376002)(396003)(39860400002)(136003)(366004)(189003)(199004)(99286004)(66066001)(486006)(478600001)(5660300001)(4326008)(2906002)(72206003)(71200400001)(6436002)(39060400002)(6486002)(5250100002)(76176011)(36756003)(6506007)(386003)(71190400001)(6512007)(52116002)(53936002)(118296001)(25786009)(81166006)(2501003)(256004)(110136005)(102836004)(68736007)(54906003)(316002)(6116002)(3846002)(305945005)(105586002)(14454004)(44832011)(106356001)(186003)(14444005)(476003)(446003)(7736002)(26005)(2616005)(50226002)(97736004)(11346002)(81156014)(8676002)(86362001)(8936002)(2900100001); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR04MB1136; H:MWHPR04MB0401.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; x-microsoft-antispam-message-info: Cvrv4mlmN+eDBVMm9jKf3vml/A2te3wJzui3rOuOu3JGSFILLB9X/LsuAd9tiLpD1xZvK6INKs2s57absgM4a1Jhs2uIaRGHQdiu4UauiF+a4MUrN/CKelwBCQ4rgJlIn3him8ro+NCPrV42ubZLPzYZzdsjdCLVps9RRbbOJEzmRPEBbnsZIC059ZUlPq0Rxvyrp+vyrXSzRlnKNlIAXVTuignYQFMWOMhyEDfx+QvdnMemVmKJ7/qvSoo0cS8GAAnlDe++TZO4Ojj9hfloSkzWfIaUEkndIKaUqWTiJkZ8qV/e+AIqCzbPkbO8KZlTqtVE7Eeb4WgL04dsRpemIFO2OGEKdhYP6dJlnRfLxFw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: e38e02cc-138b-4db0-2eaf-08d62a34eb02 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Oct 2018 20:06:49.5063 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR04MB1136 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 68.232.141.245 Subject: [Qemu-devel] [PATCH v5 4/5] 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: "alistair23@gmail.com" , "palmer@sifive.com" , Alistair Francis , "stephen@eideticom.com" 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 };