From nobody Fri Nov 14 13:43:19 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1587924847; cv=none; d=zohomail.com; s=zohoarc; b=E8Z8pgBiSIty27nFWWII9BOAXjRbUoDHefHRhm6jWDdm3P+9PT99ZJArr+P0RQhy4XB1KrG2ufb6/vyTTKR4XbdxyC/YZcZUpLRU8kB2rYUUlxHP/icCiFzN5uc35vA/siV6yd9ZTxRaII5AGIQUtvmZQ+OYaYBYzbVqQ59418c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587924847; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xNaYO+sCfsehU5XWqLYjLkVF1/mahMGUoh3ox2oA17k=; b=AGbCSvQECcCGBCJUymId8AUPYLmu3X1jWh9woaRwhTSnNPbzL58zBi6kVhsSd7Z4fOCtNYTvImylJB1Wqs7h6XoGfwNKY4Bb9oqIJSXtgHRqetNBxoh5Gxwqn42Fc2KBq9Ze1iGVhCHWtAWX/JXK8iOjoBlSkzQ1Ts4yzFgATzs= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1587924847317803.8622874635471; Sun, 26 Apr 2020 11:14:07 -0700 (PDT) Received: from localhost ([::1]:41360 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSln3-00060O-RS for importer@patchew.org; Sun, 26 Apr 2020 14:14:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33676) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jSlcO-0007um-0x for qemu-devel@nongnu.org; Sun, 26 Apr 2020 14:03:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jSlcG-0007s4-GU for qemu-devel@nongnu.org; Sun, 26 Apr 2020 14:03:03 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:45425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jSlcG-0007on-31; Sun, 26 Apr 2020 14:02:56 -0400 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E51295C00A3; Sun, 26 Apr 2020 14:02:53 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Sun, 26 Apr 2020 14:02:53 -0400 Received: from ThinkpadX1Yoga3.localdomain (c-73-93-84-208.hsd1.ca.comcast.net [73.93.84.208]) by mail.messagingengine.com (Postfix) with ESMTPA id 2353D3065E2A; Sun, 26 Apr 2020 14:02:53 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alistair23.me; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=xNaYO+sCfsehU 5XWqLYjLkVF1/mahMGUoh3ox2oA17k=; b=VopH6HbXvsTeKkBIjg65cSj1VYlC1 KQLAgW1A0wa9U9qXdNiVvn0aEsWtCWUdDE5AGVK9/L5qbn7F6r8SQyMELPi05gNF neTl1Rp851wVCKZC3V1nUWpbdc9DfwM6ACMBYJYQFmGMj+IQD2Nm41CgrCOEpGh4 koeqrMDoUul6HMou2CvNc1y8YiB9i8l+U3SWTJDcBqWX16xrjUgm0Gs9cw6hDbQI C5MdgRxw/GLYVVPj+0XFpUajLpeqmpQrBfsP34LZxNW8/z3P8brMR1M4D7yh1uYU vgFvjVf4yqkf/euubu7WDMo5PPHVLuBENk5GLVYkvHLzoXIdIVCvwLqOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=xNaYO+sCfsehU5XWqLYjLkVF1/mahMGUoh3ox2oA17k=; b=YjgZUuMx yrqaJes/M9p8ipci0ptVQ0ScyoFEYOb8HYwGU7b03Fnccn2yYfv2jER1JWNUfa8v U7inKspQN+/p8SSXW2XTo+sBeUI+V8tc9VcUsW4SFdxaUwVoouoGsNc6UeUh2bcL XGUnHgj1vfu4UdDb1Vu5rlTS8g7k4uaOa0az2UjfHAEKHRVAT5xA3u8ou4FYSl/L r5cG5tFf2yf9kWFPCZUx7hgXMfgJmvJ/LZo/luiPmsCZCdlU7bFtt1lBj3wVY6k8 lNHMOHClFemRN+n34O11BX+W3B7OINmORFQN2b8Q9/9Io3/Ay48huJCWLCqkMSgs fV7fA0iO82D6HQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrheejgdduvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheptehlihhsthgrihhrucfhrhgrnhgtihhsuceorghlihhsthgr ihhrsegrlhhishhtrghirhdvfedrmhgvqeenucffohhmrghinhepghhnuhdrohhrghenuc fkphepjeefrdelfedrkeegrddvtdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprghlihhsthgrihhrsegrlhhishhtrghirhdvfedrmhgv X-ME-Proxy: From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 4/9] riscv: Initial commit of OpenTitan machine Date: Sat, 25 Apr 2020 04:29:13 -0700 Message-Id: <76e9a626877f7901cead298811dba12c7873f869.1587920572.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=66.111.4.29; envelope-from=alistair@alistair23.me; helo=out5-smtp.messagingengine.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/26 14:02:38 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.111.4.29 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Alistair Francis This adds a barebone OpenTitan machine to QEMU. Signed-off-by: Alistair Francis --- MAINTAINERS | 10 ++ default-configs/riscv32-softmmu.mak | 1 + default-configs/riscv64-softmmu.mak | 11 +- hw/riscv/Kconfig | 5 + hw/riscv/Makefile.objs | 1 + hw/riscv/opentitan.c | 169 ++++++++++++++++++++++++++++ include/hw/riscv/opentitan.h | 63 +++++++++++ 7 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 hw/riscv/opentitan.c create mode 100644 include/hw/riscv/opentitan.h diff --git a/MAINTAINERS b/MAINTAINERS index 8cbc1fac2b..3cd9fc0898 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1225,6 +1225,16 @@ F: pc-bios/canyonlands.dt[sb] F: pc-bios/u-boot-sam460ex-20100605.bin F: roms/u-boot-sam460ex =20 +RISC-V Machines +----------------- +OpenTitan +M: Alistair Francis +L: qemu-riscv@nongnu.org +S: Supported +F: hw/riscv/opentitan.c +F: include/hw/riscv/opentitan.h + + SH4 Machines ------------ R2D diff --git a/default-configs/riscv32-softmmu.mak b/default-configs/riscv32-= softmmu.mak index 1ae077ed87..94a236c9c2 100644 --- a/default-configs/riscv32-softmmu.mak +++ b/default-configs/riscv32-softmmu.mak @@ -10,3 +10,4 @@ CONFIG_SPIKE=3Dy CONFIG_SIFIVE_E=3Dy CONFIG_SIFIVE_U=3Dy CONFIG_RISCV_VIRT=3Dy +CONFIG_OPENTITAN=3Dy diff --git a/default-configs/riscv64-softmmu.mak b/default-configs/riscv64-= softmmu.mak index 235c6f473f..aaf6d735bb 100644 --- a/default-configs/riscv64-softmmu.mak +++ b/default-configs/riscv64-softmmu.mak @@ -1,3 +1,12 @@ # Default configuration for riscv64-softmmu =20 -include riscv32-softmmu.mak +# Uncomment the following lines to disable these optional devices: +# +#CONFIG_PCI_DEVICES=3Dn + +# Boards: +# +CONFIG_SPIKE=3Dy +CONFIG_SIFIVE_E=3Dy +CONFIG_SIFIVE_U=3Dy +CONFIG_RISCV_VIRT=3Dy diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index ff9fbe958a..94d19571f7 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -27,6 +27,11 @@ config SPIKE select HTIF select SIFIVE =20 +config OPENTITAN + bool + select HART + select UNIMP + config RISCV_VIRT bool imply PCI_DEVICES diff --git a/hw/riscv/Makefile.objs b/hw/riscv/Makefile.objs index fc3c6dd7c8..57cc708f5d 100644 --- a/hw/riscv/Makefile.objs +++ b/hw/riscv/Makefile.objs @@ -1,6 +1,7 @@ obj-y +=3D boot.o obj-$(CONFIG_SPIKE) +=3D riscv_htif.o obj-$(CONFIG_HART) +=3D riscv_hart.o +obj-$(CONFIG_OPENTITAN) +=3D opentitan.o obj-$(CONFIG_SIFIVE_E) +=3D sifive_e.o obj-$(CONFIG_SIFIVE_E) +=3D sifive_e_prci.o obj-$(CONFIG_SIFIVE) +=3D sifive_clint.o diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c new file mode 100644 index 0000000000..1f9f4a8dd0 --- /dev/null +++ b/hw/riscv/opentitan.c @@ -0,0 +1,169 @@ +/* + * QEMU RISC-V Board Compatible with OpenTitan FPGA platform + * + * Copyright (c) 2020 Western Digital + * + * Provides a board compatible with the OpenTitan FPGA platform: + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 f= or + * 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/riscv/opentitan.h" +#include "qapi/error.h" +#include "hw/boards.h" +#include "hw/misc/unimp.h" +#include "hw/riscv/boot.h" +#include "exec/address-spaces.h" + +static const struct MemmapEntry { + hwaddr base; + hwaddr size; +} ibex_memmap[] =3D { + [IBEX_ROM] =3D { 0x00008000, 0xc000 }, + [IBEX_RAM] =3D { 0x10000000, 0x10000 }, + [IBEX_FLASH] =3D { 0x20000000, 0x80000 }, + [IBEX_UART] =3D { 0x40000000, 0x10000 }, + [IBEX_GPIO] =3D { 0x40010000, 0x10000 }, + [IBEX_SPI] =3D { 0x40020000, 0x10000 }, + [IBEX_FLASH_CTRL] =3D { 0x40030000, 0x10000 }, + [IBEX_PINMUX] =3D { 0x40070000, 0x10000 }, + [IBEX_RV_TIMER] =3D { 0x40080000, 0x10000 }, + [IBEX_PLIC] =3D { 0x40090000, 0x10000 }, + [IBEX_AES] =3D { 0x40110000, 0x10000 }, + [IBEX_HMAC] =3D { 0x40120000, 0x10000 }, + [IBEX_ALERT_HANDLER] =3D { 0x40130000, 0x10000 }, + [IBEX_USBDEV] =3D { 0x40150000, 0x10000 } +}; + +static void riscv_opentitan_init(MachineState *machine) +{ + const struct MemmapEntry *memmap =3D ibex_memmap; + OpenTitanState *s =3D g_new0(OpenTitanState, 1); + MemoryRegion *sys_mem =3D get_system_memory(); + MemoryRegion *main_mem =3D g_new(MemoryRegion, 1); + + /* Initialize SoC */ + object_initialize_child(OBJECT(machine), "soc", &s->soc, + sizeof(s->soc), TYPE_RISCV_IBEX_SOC, + &error_abort, NULL); + object_property_set_bool(OBJECT(&s->soc), true, "realized", + &error_abort); + + memory_region_init_ram(main_mem, NULL, "riscv.lowrisc.ibex.ram", + memmap[IBEX_RAM].size, &error_fatal); + memory_region_add_subregion(sys_mem, + memmap[IBEX_RAM].base, main_mem); + + + if (machine->firmware) { + riscv_load_firmware(machine->firmware, memmap[IBEX_RAM].base); + } + + if (machine->kernel_filename) { + riscv_load_kernel(machine->kernel_filename, NULL); + } +} + +static void riscv_opentitan_machine_init(MachineClass *mc) +{ + mc->desc =3D "RISC-V Board compatible with OpenTitan"; + mc->init =3D riscv_opentitan_init; + mc->max_cpus =3D 1; + mc->default_cpu_type =3D TYPE_RISCV_CPU_IBEX; +} + +DEFINE_MACHINE("opentitan", riscv_opentitan_machine_init) + +static void riscv_lowrisc_ibex_soc_init(Object *obj) +{ + LowRISCIbexSoCState *s =3D RISCV_IBEX_SOC(obj); + + object_initialize_child(obj, "cpus", &s->cpus, + sizeof(s->cpus), TYPE_RISCV_HART_ARRAY, + &error_abort, NULL); +} + +static void riscv_lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **e= rrp) +{ + const struct MemmapEntry *memmap =3D ibex_memmap; + MachineState *ms =3D MACHINE(qdev_get_machine()); + LowRISCIbexSoCState *s =3D RISCV_IBEX_SOC(dev_soc); + MemoryRegion *sys_mem =3D get_system_memory(); + + object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type", + &error_abort); + object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts", + &error_abort); + object_property_set_bool(OBJECT(&s->cpus), true, "realized", + &error_abort); + + /* Boot ROM */ + memory_region_init_rom(&s->rom, OBJECT(dev_soc), "riscv.lowrisc.ibex.r= om", + memmap[IBEX_ROM].size, &error_fatal); + memory_region_add_subregion(sys_mem, + memmap[IBEX_ROM].base, &s->rom); + + /* Flash memory */ + memory_region_init_rom(&s->flash_mem, OBJECT(dev_soc), "riscv.lowrisc.= ibex.flash", + memmap[IBEX_FLASH].size, &error_fatal); + memory_region_add_subregion(sys_mem, memmap[IBEX_FLASH].base, + &s->flash_mem); + + create_unimplemented_device("riscv.lowrisc.ibex.uart", + memmap[IBEX_UART].base, memmap[IBEX_UART].size); + create_unimplemented_device("riscv.lowrisc.ibex.gpio", + memmap[IBEX_GPIO].base, memmap[IBEX_GPIO].size); + create_unimplemented_device("riscv.lowrisc.ibex.spi", + memmap[IBEX_SPI].base, memmap[IBEX_SPI].size); + create_unimplemented_device("riscv.lowrisc.ibex.flash_ctrl", + memmap[IBEX_FLASH_CTRL].base, memmap[IBEX_FLASH_CTRL].size); + create_unimplemented_device("riscv.lowrisc.ibex.rv_timer", + memmap[IBEX_RV_TIMER].base, memmap[IBEX_RV_TIMER].size); + create_unimplemented_device("riscv.lowrisc.ibex.aes", + memmap[IBEX_AES].base, memmap[IBEX_AES].size); + create_unimplemented_device("riscv.lowrisc.ibex.hmac", + memmap[IBEX_HMAC].base, memmap[IBEX_HMAC].size); + create_unimplemented_device("riscv.lowrisc.ibex.plic", + memmap[IBEX_PLIC].base, memmap[IBEX_PLIC].size); + create_unimplemented_device("riscv.lowrisc.ibex.pinmux", + memmap[IBEX_PINMUX].base, memmap[IBEX_PINMUX].size); + create_unimplemented_device("riscv.lowrisc.ibex.alert_handler", + memmap[IBEX_ALERT_HANDLER].base, memmap[IBEX_ALERT_HANDLER].size); + create_unimplemented_device("riscv.lowrisc.ibex.USBDEV", + memmap[IBEX_USBDEV].base, memmap[IBEX_USBDEV].size); +} + +static void riscv_lowrisc_ibex_soc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D riscv_lowrisc_ibex_soc_realize; + /* Reason: Uses serial_hds in realize function, thus can't be used twi= ce */ + dc->user_creatable =3D false; +} + +static const TypeInfo riscv_lowrisc_ibex_soc_type_info =3D { + .name =3D TYPE_RISCV_IBEX_SOC, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(LowRISCIbexSoCState), + .instance_init =3D riscv_lowrisc_ibex_soc_init, + .class_init =3D riscv_lowrisc_ibex_soc_class_init, +}; + +static void riscv_lowrisc_ibex_soc_register_types(void) +{ + type_register_static(&riscv_lowrisc_ibex_soc_type_info); +} + +type_init(riscv_lowrisc_ibex_soc_register_types) diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h new file mode 100644 index 0000000000..15a3d87ed0 --- /dev/null +++ b/include/hw/riscv/opentitan.h @@ -0,0 +1,63 @@ +/* + * QEMU RISC-V Board Compatible with OpenTitan FPGA platform + * + * Copyright (c) 2020 Western Digital + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2 or later, as published by the Free Software Foundation. + * + * This program is distributed in the hope 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 f= or + * more details. + * + * You should have received a copy of the GNU General Public License along= with + * this program. If not, see . + */ + +#ifndef HW_OPENTITAN_H +#define HW_OPENTITAN_H + +#include "hw/riscv/riscv_hart.h" + +#define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc" +#define RISCV_IBEX_SOC(obj) \ + OBJECT_CHECK(LowRISCIbexSoCState, (obj), TYPE_RISCV_IBEX_SOC) + +typedef struct LowRISCIbexSoCState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + RISCVHartArrayState cpus; + MemoryRegion flash_mem; + MemoryRegion rom; +} LowRISCIbexSoCState; + +typedef struct OpenTitanState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + LowRISCIbexSoCState soc; +} OpenTitanState; + +enum { + IBEX_ROM, + IBEX_RAM, + IBEX_FLASH, + IBEX_UART, + IBEX_GPIO, + IBEX_SPI, + IBEX_FLASH_CTRL, + IBEX_RV_TIMER, + IBEX_AES, + IBEX_HMAC, + IBEX_PLIC, + IBEX_PINMUX, + IBEX_ALERT_HANDLER, + IBEX_USBDEV, +}; + +#endif --=20 2.26.2