From patchwork Thu Oct 11 20:31:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 10637399 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 3A160157A for ; Thu, 11 Oct 2018 20:36:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 281EC2C0BE for ; Thu, 11 Oct 2018 20:36:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B8B32C12B; Thu, 11 Oct 2018 20:36:37 +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 7F0D32C0BE for ; Thu, 11 Oct 2018 20:36:36 +0000 (UTC) Received: from localhost ([::1]:37005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAhhD-0001cs-NX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 16:36:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39635) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAhcg-0006dw-I9 for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:31:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAhcb-0006XR-I9 for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:31:54 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:29171) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gAhcb-0006Un-9L for qemu-devel@nongnu.org; Thu, 11 Oct 2018 16:31:49 -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=1539289909; x=1570825909; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=rmyP7lC/3WWN17yldvR9N3TXffRoD+BWhqhhJHHx924=; b=ctgqEMrFUUVzv79DnNNrYAYA7vH2+m9XUPp/t+bqfDBLxVpNc5g9Me4D wdEJMSSNZdxSVPt0HjEp7Q4SNtCF4EEnZVDcryNXj7HxIIkEpmPmpQA17 ICXkTwLHyDCnO9gv5hyoPSuQktwtKYzs9dSJkaiv/FWHKe/1XoJLH/CoF vcxU2hWXiTWo05wPuk9P1eemu31gL+cQnjLr5eQw3wrlj3GU32xWXVygj 18EblnROLRLwTyUZ2Akhwbb+t+lc0JdubgIr1eGuB/wpdzOxx16j4aHeC n2VFCT/cKU6JKaDzsti8watERMXGoRpDrbuof1T6LLaDA+PsJ07KMdTFh w==; X-IronPort-AV: E=Sophos;i="5.54,369,1534780800"; d="scan'208";a="91781670" Received: from mail-bl2nam02lp0081.outbound.protection.outlook.com (HELO NAM02-BL2-obe.outbound.protection.outlook.com) ([207.46.163.81]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 04:31:47 +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=Rwxme/cgtNzRgFkqS6szo2qPGZz1Khr09O0xEjf27Tk=; b=CdxCu5bbPUH/SQ8z678YnDw0RnLSz9hiymsoISfl9ivzg9YPLil5l+IDyKNbweauydveT13GqRQMlndZpfHKm6+0TI+arz5IWaV8m1oYcy0Sf+YHboI+cj6iO5wRRK4k5Atqtz+7QL1atHo2PUiY5OyRPJAaia+H+ZUeVyNFze8= Received: from CY4PR04MB0392.namprd04.prod.outlook.com (10.173.188.145) by CY4PR04MB1224.namprd04.prod.outlook.com (10.173.193.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1207.26; Thu, 11 Oct 2018 20:31:44 +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:44 +0000 From: Alistair Francis To: "peter.maydell@linaro.org" Thread-Topic: [PULL 02/10] hw/riscv/virt: Connect the gpex PCIe Thread-Index: AQHUYaFsS0KgJgQ3gUS6GYyGmqKj7A== Date: Thu, 11 Oct 2018 20:31:43 +0000 Message-ID: <20181011203115.18666-3-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; CY4PR04MB1224; 6:I0LVz/XOoEkf0Lk6lmiGnFL/diGFJMHTWepVpaKfTEGtaCUWaFnZi6F8y8qE7ZvDcpQxL5XOuHinEdUMJSofve172Pozvt+m3DhojjUgcMeo/jGtR67UCPizaM+oO7VdI/kUg6V2O9u8cxpoqgdTdxDycVwvqqRPhGR5sjQ+UfaagyiTLbjzPSH3tCe2+QXvMzZ+LI51Js2DRGB+K2OiTWGExkVfy8RecdP6hfExEZgocSpEhI6hVVEGKGNOdUd1i5JDslg+xdmDG17j143u7rqoVWc9Fu8lboWy+B0BAwhySics6jsQn4USSUv1doXuTERcLVT5znMImN6nNWoqQ2x2kj/SZgI3oJSuyF6SqrEvO1n9q321VyVs79dhYrlJbQdhIzaGe7pliG6CdL3YNrL6RorRQN486Luo0nGAgtn44aArBMEDz9aRq3MQNYG0JuwZ2BaHB0+V7mV7H0BFCQ==; 5:/eeMwZ4z8vNjDZEG4okLhg2WwFWAR0uMb1JdRdb8OjspSkDIKcMMj2RYr1TMng51IX3jU3/8FqNX2vXhodZ+9p8VcvNGs4PGJQuNkLC5QEBAj/bPPkrEu5XAv4rigLfF2JWvknDX4RvJW7N0QKkXzKtHI/3/BC2MQ32/DmXw6tA=; 7:OdizJyVM9Nqf4LHqZF8+3MVMKRYqgOzCKr23haqgGpTMsOupBfeeaQjK7RIAKnNxMbv44P+oaCeddQVwGXCOl4jK7BgHuhcEwHU8hIlknsGvbqAMKEyTUC9t2gkGZ1o2vKbgmcpfHPtwpJAc2bv/cAGMXE1N+bfCpZ2tAendvLHW7AYuK7ZEfoTqDzaMQ9E+xkfjWGFDgpsvCPdEBwBa2u+uQlAZojGJGpG4bqYrnAs2M1HeN2iJaLBDB/3ekvuH x-ms-office365-filtering-correlation-id: ca147c75-3033-463e-2ba7-08d62fb88eb3 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:CY4PR04MB1224; x-ms-traffictypediagnostic: CY4PR04MB1224: 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)(8121501046)(5005006)(3231355)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201708071742011)(7699051); SRVR:CY4PR04MB1224; BCL:0; PCL:0; RULEID:; SRVR:CY4PR04MB1224; x-forefront-prvs: 08220FA8D6 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(396003)(346002)(376002)(39860400002)(366004)(136003)(199004)(189003)(81156014)(8936002)(68736007)(36756003)(6506007)(86362001)(7736002)(6916009)(8676002)(105586002)(76176011)(2906002)(256004)(81166006)(50226002)(54906003)(5660300001)(5640700003)(6486002)(1076002)(4326008)(52116002)(486006)(11346002)(2900100001)(102836004)(2501003)(99286004)(2616005)(6436002)(478600001)(72206003)(44832011)(476003)(186003)(97736004)(2351001)(25786009)(71190400001)(53936002)(3846002)(14454004)(386003)(106356001)(316002)(6512007)(446003)(305945005)(71200400001)(26005)(66066001)(6116002)(5250100002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR04MB1224; H:CY4PR04MB0392.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; x-microsoft-antispam-message-info: c1arToNNiYbsPT3P/UZoZQFF5kXDmA/w8u7inrXyOrFTfuUzjvOBGlqgZ3zWvJy4gd+Sm+Zg1eGbMapArMwp8ymc/uTXC0cF6CU5TOHEeRKMo5DSjRPM7sZe28iyrJaG5fIFLB9IAj5Yz3tG+vocBM8ry/mFzP3uFcNHqQwg/2Bpmrbe8/+50j4bPIM4C0JXxfAeQwQfQt+6G4BgSTMlSh9W7NWl0+ZCxuX2XxjoOj3+jNT9+jBXH80QoLYeMsW35RkVwLNfzJgYKHgQYjiVGatWf3yau3uCTRKVX4ktpK1gNQWG/yndPSDpqneG1zUXX0ZbJpkgK4/zRLC9bDjojH3Sp3Ku/O+lnagng7HvWWc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca147c75-3033-463e-2ba7-08d62fb88eb3 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Oct 2018 20:31:43.9372 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR04MB1224 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 216.71.154.42 Subject: [Qemu-devel] [PULL 02/10] hw/riscv/virt: Connect the gpex 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 gpex PCIe device based on the device tree included in the HiFive Unleashed ROM. Signed-off-by: Alistair Francis --- default-configs/riscv32-softmmu.mak | 6 ++- default-configs/riscv64-softmmu.mak | 6 ++- hw/riscv/virt.c | 58 +++++++++++++++++++++++++++++ include/hw/riscv/virt.h | 4 +- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/default-configs/riscv32-softmmu.mak b/default-configs/riscv32-softmmu.mak index 7937c69e22..3e3d195f37 100644 --- a/default-configs/riscv32-softmmu.mak +++ b/default-configs/riscv32-softmmu.mak @@ -1,7 +1,11 @@ # Default configuration for riscv-softmmu +include pci.mak + CONFIG_SERIAL=y CONFIG_VIRTIO_MMIO=y -include virtio.mak CONFIG_CADENCE=y + +CONFIG_PCI_GENERIC=y +CONFIG_PCI_XILINX=y diff --git a/default-configs/riscv64-softmmu.mak b/default-configs/riscv64-softmmu.mak index 7937c69e22..3e3d195f37 100644 --- a/default-configs/riscv64-softmmu.mak +++ b/default-configs/riscv64-softmmu.mak @@ -1,7 +1,11 @@ # Default configuration for riscv-softmmu +include pci.mak + CONFIG_SERIAL=y CONFIG_VIRTIO_MMIO=y -include virtio.mak CONFIG_CADENCE=y + +CONFIG_PCI_GENERIC=y +CONFIG_PCI_XILINX=y diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 005169eabc..9bd2c10581 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -39,6 +39,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/gpex.h" #include "elf.h" #include @@ -55,6 +57,7 @@ static const struct MemmapEntry { [VIRT_UART0] = { 0x10000000, 0x100 }, [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, [VIRT_DRAM] = { 0x80000000, 0x0 }, + [VIRT_PCIE] = { 0x2000000000, 0x4000000 }, }; static uint64_t load_kernel(const char *kernel_filename) @@ -233,6 +236,32 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, g_free(nodename); } + nodename = g_strdup_printf("/pci@%lx", + (long) memmap[VIRT_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", + "pci-host-ecam-generic"); + qemu_fdt_setprop_string(fdt, nodename, "device_type", "pci"); + qemu_fdt_setprop_cells(fdt, nodename, "reg", 0x20, 0x0, 0x0, + memmap[VIRT_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", PCIE_IRQ); + g_free(nodename); + + nodename = g_strdup_printf("/pci@%lx/interrupt-controller", + (long) memmap[VIRT_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("/test@%lx", (long)memmap[VIRT_TEST].base); qemu_fdt_add_subnode(fdt, nodename); @@ -260,6 +289,31 @@ static void *create_fdt(RISCVVirtState *s, const struct MemmapEntry *memmap, return fdt; } + +static inline DeviceState * +gpex_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_GPEX_HOST); + + 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); + + sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0, irq); + + return dev; +} + static void riscv_virt_board_init(MachineState *machine) { const struct MemmapEntry *memmap = virt_memmap; @@ -382,6 +436,10 @@ static void riscv_virt_board_init(MachineState *machine) qdev_get_gpio_in(DEVICE(s->plic), VIRTIO_IRQ + i)); } + gpex_pcie_init(system_memory, 0, memmap[VIRT_PCIE].base, + memmap[VIRT_PCIE].size, 0x40000000, 0x20000000, + qdev_get_gpio_in(DEVICE(s->plic), PCIE_IRQ), true); + serial_mm_init(system_memory, memmap[VIRT_UART0].base, 0, qdev_get_gpio_in(DEVICE(s->plic), UART0_IRQ), 399193, serial_hd(0), DEVICE_LITTLE_ENDIAN); diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h index 7cb2742070..d0129c2ca5 100644 --- a/include/hw/riscv/virt.h +++ b/include/hw/riscv/virt.h @@ -38,13 +38,15 @@ enum { VIRT_PLIC, VIRT_UART0, VIRT_VIRTIO, - VIRT_DRAM + VIRT_DRAM, + VIRT_PCIE }; enum { UART0_IRQ = 10, VIRTIO_IRQ = 1, /* 1 to 8 */ VIRTIO_COUNT = 8, + PCIE_IRQ = 0x20, VIRTIO_NDEV = 0x35 };