From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590704883; cv=none; d=zohomail.com; s=zohoarc; b=E9ebENayXNQjSG1L8e4t+jtyA6+oXu7T2Cl9gZaCISk797MrmMSGq2e19MBIRhdTmW4sdpXawemSHVky8/iBqhuAbbHn/ksk1IErBa9H/bMMtAGDSRCiA2uL8/pag0F4UXrjCXz0nXbT6u9QR/bgHAPAXys4AK6CAevUf+ARnmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590704883; h=Content-Type: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=r32PuC3K2vyPNZXj6CbX5cPYcD18htqB9C1K7d0Y3ZI=; b=N71AwFGR+wvUirJtoD+0WbQbRj6XZLKhlmJQRvgD36C1AbwmmRJnzDsPEq4bpu2zFydW6GKFLtRyNn2UA9xwPcD7ImHy+HNYaS8JBiTKgxrC5JaGz7zEOPR7RYXV6GQDcKlm1J3LXG9FeqUNc/FmMmoXoIvnKsIj+/JBpVOCW5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590704883884515.015657784342; Thu, 28 May 2020 15:28:03 -0700 (PDT) Received: from localhost ([::1]:49326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR0M-0000WK-Ih for importer@patchew.org; Thu, 28 May 2020 18:28:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvN-00027q-Jj; Thu, 28 May 2020 18:22:55 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:48457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvK-0005fa-1O; Thu, 28 May 2020 18:22:53 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:22:47 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:01 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:22:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704571; x=1622240571; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6RkZQFByFl8XM3HFMV8b3oaAVUpsBTmA2wZJl/MG+Jc=; b=oORw18Q8A1EihJyannqzPQ17wYQ/8g1Kbq5yp1IcRJ2zTRbgWZOuuXlk yOeJp3x4SEROTGARXUd+7zokDy3oo2vT9xIf4Jgtfe6hy26/Y6yM9yKaM vyHWpOC8Xcu+jDAVtUvu0w4j3XU6A6galUEkKoCzozrrQXlyDNj0PRngH q5qvDMuNHjdoXf12VEWfulAEjHvyju4BbMHqHlJJEg+k/yQTiGgphy0CD tQ4XRLpOvpC5C2uaLxdyBJwyB1CeDssVwO9UFAvnPhrhatbwDdkheqyJU 4bKLseSeu7McZ3AOHB2SKUfrGCBdp95sPBEgnuYnfkg5JQaV3q2JuA3+2 A==; IronPort-SDR: TroVOFqSTQc23EcrO4USPUmT5dEwV2uZEf/zfBarzgprkrZAFIOTVdi5l4aC5/sSJsF9DDyyKc KwXIt2rQ4JPwPzwPViX6NrJ2z5hVnujtG1rpCJgF3sBC07cvChTBHyBQKuSqTa3UHMqarnAASj WLVzOnXMpWnMQPo/9iuxEaheFEDjlOI3eHk0YRC6VAyOE3dAGXrqVRENshne8cVjcErI+49t0y CIAbTaT02QwMraQJYg3zds07Gfz43yskYuCrgiUsEaeGz3rwvBJYEGy+OI0K1Ww1gUVboetTEy iAo= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="139073326" IronPort-SDR: fbWDAwdOfVQWb1a0YtGLpY6oHCgHvC1H7bkYmuNM31pQvzCEJDhOFwjB1eMN11PLt6QwgsaURa zrKDc2NX9CQqFK1/xsp+ISXC8CxiM2pVA= IronPort-SDR: Dwnn15WbeYVaQuiFaqO1AJOIjAgX/bAYUBrRn56ezUbBdL59/NnZOUTCbxItgbejN2yYVJRfZV Lq6cnnti3D6g== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 01/11] riscv/boot: Add a missing header include Date: Thu, 28 May 2020 15:14:09 -0700 Message-Id: <7a0a552fd69403a64bf7aaf25a6ef02c10635ed1.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=216.71.153.144; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa5.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:22:43 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) As the functions declared in this header use the symbol_fn_t typedef itself declared in "hw/loader.h", we need to include it here to make the header file self-contained. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Bin Meng --- include/hw/riscv/boot.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/hw/riscv/boot.h b/include/hw/riscv/boot.h index 474a940ad5..9daa98da08 100644 --- a/include/hw/riscv/boot.h +++ b/include/hw/riscv/boot.h @@ -21,6 +21,7 @@ #define RISCV_BOOT_H =20 #include "exec/cpu-defs.h" +#include "hw/loader.h" =20 void riscv_find_and_load_firmware(MachineState *machine, const char *default_machine_firmware, --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590704677; cv=none; d=zohomail.com; s=zohoarc; b=W8QsEjPIFoVR2Uc8sZ8vnO0HuD4Pz3o4Dv9VWrhLgKO/1SQ0F/RiaOei1dO5i3rDfDSIFDT4R0p7CLy8A2ivDgpKl3EuLE4JM+aIBLjPranTZhwRz6cV0ojTzg5OwRt1d3cGVcwfHFNpFt65adub+CJ96nP9uuTtdLXaW8SWWEw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590704677; 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=NwblGPJ70ORvrCtNShy/GvzedfLvOQ9ZKrGGwZVTl6I=; b=TWweZDgFKhfsd+Lit+C0wS/3o1IM4nkNKskH8n0mhs6Rz9izblJCtfS21+1uZfue9ucD2LGLMq6vxF3VmQkVuj0FSC3/d+emn+8WzMJt89Q9jZdAYtDlXrozQ0d5QNu+gsMTLdVAMrzcDic84kUkJ5U/E9BerdCZ4BOpn/uoils= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159070467782072.84981549002396; Thu, 28 May 2020 15:24:37 -0700 (PDT) Received: from localhost ([::1]:40694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeQx2-0004Rw-Fv for importer@patchew.org; Thu, 28 May 2020 18:24:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvN-00027r-K4; Thu, 28 May 2020 18:22:55 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:48464) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvK-0005hu-SS; Thu, 28 May 2020 18:22:52 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:22:49 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:03 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:22:48 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704572; x=1622240572; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vDZd4fWZoZGped8sJN4wTNf8wH4Xep9G/tkQsk69CK0=; b=KVu9jZnn9/C41Vw5nsrLVZCtpIaDfCRtJPoFx1Zc9oXPigZt9OALyFjk aCalVVD3U6INQ6HXjIEUqMD1yE6IjY/YTk6Uq1joe7020vwx73G61klfi S7E5fU6dymCUjHLjR074i25o+oOmZUTU8NfVBkxBYD0vImH/Yp6kEHhK6 TZh0YvamG+tdUjfKIMX8ozZZ25nvZ+tTyOyOMMlMGP/pSMrRI+kaj47QO a5oiZSnXXDrqyoqXfq6KDlpIzmk9495Tfe1/jphgOgd5EVjUoYx4+wHwG wZf0Qw/L4g1zBI9k1FoZwvuK0uHL/1N7Pi6qxjApfNAVnfzY9Wgei58UC g==; IronPort-SDR: cGlkGdL4KITIdHBwzHNoNWwTDIuCsVQqSpm0TeoUMRj/3jqVl8pywhxOUCSQPXhuOt1ePcLy0L cZGFeM0LN3nR6D/gsmWgCpuzfOIV6u46BHCQVe/Jm2KS6SQWxkLRaCbrVv3MPEq32RArRli3Yg IWTxbHnJucbPdn3yU1vyqxxAxMRvzDv3dX6zQndEj/zYKkObInJb5SPyAg85ZreyP1IFvCbN24 M+joBRK5fyp9uQbFXZBgPg4CcCY5nu066vynKWO0vP4fEtNyuu2SBA8P0DfeyJmBKogWxHM8ev dH8= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="139073329" IronPort-SDR: JRngCyMcOIBzqaR6oa+WNnesprRBcC6zo/QK9pSWH87FUz8ezXCLOzejYq4XzPmbzJqdXR6s9a 6KZV51RZdmuYm6w1eJNvwyOsKv3Gi8ddQ= IronPort-SDR: VMFvLY5S7qLuPZeUU9YEfHUupRUayj4a9hNENTlBBehMh3lyJKHxZacFNp2FyoA7wJx+k2ViqG m229gVsY5/eA== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 02/11] target/riscv: Don't overwrite the reset vector Date: Thu, 28 May 2020 15:14:12 -0700 Message-Id: X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.153.144; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa5.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:22:43 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The reset vector is set in the init function don't set it again in realize. Signed-off-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 059d71f2c7..5eb3c02735 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -133,6 +133,7 @@ static void riscv_base32_cpu_init(Object *obj) CPURISCVState *env =3D &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, 0); + set_resetvec(env, DEFAULT_RSTVEC); } =20 static void rv32gcsu_priv1_09_1_cpu_init(Object *obj) @@ -180,6 +181,7 @@ static void riscv_base64_cpu_init(Object *obj) CPURISCVState *env =3D &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, 0); + set_resetvec(env, DEFAULT_RSTVEC); } =20 static void rv64gcsu_priv1_09_1_cpu_init(Object *obj) @@ -399,7 +401,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error *= *errp) } =20 set_priv_version(env, priv_version); - set_resetvec(env, DEFAULT_RSTVEC); =20 if (cpu->cfg.mmu) { set_feature(env, RISCV_FEATURE_MMU); --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590704942; cv=none; d=zohomail.com; s=zohoarc; b=hAwwbU82kHGmLd/AoycaHI2kh5nxtER/4MvdPuuntaC2K/4YwdxjuaSOuMvSuXxKauATcTQBi5H62ewdyeeIlvmhPezVZpvwOIMg9tXxd+VHYu/INOJSs2/ZOujPNDA7tgstMcq+uHEIOrY8fPE8JmmraQnNkBg96D7WYj+EABE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590704942; 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=62sut+gu2wow94ErZt47OAfVFjgHLjuBgpYOd7WV5yU=; b=gnkdm7JiL7oAJImToEtbsrtzW4OyQNcU/knSfI1OkxybvtffnChpQTE6DTrUrknBAyvaR0D3wOt7WCxLh4GTRz7uaE3Lu1B11rzf5DQjUq2lcnu+ocYoLT2LQIiEaggiRMSy6dOKqr6tX5rueAYybJvD7MK9a0WCe5n+VIKs7+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590704942144609.5727188404434; Thu, 28 May 2020 15:29:02 -0700 (PDT) Received: from localhost ([::1]:54852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR1I-0002l9-Eu for importer@patchew.org; Thu, 28 May 2020 18:29:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvQ-0002AH-Ek; Thu, 28 May 2020 18:22:56 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:48454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvN-0005c9-OF; Thu, 28 May 2020 18:22:55 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:22:52 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:06 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:22:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704574; x=1622240574; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=95oYIs1BVKa8lJpKUNyTJ6K2xLTQpJSfhvRfZcrvMYo=; b=BdidjeVBt51LDUinZKLXJKWSsK0vJVcfmTohDx3GXjTdtghG+E9ivcm3 VaWh7roJnfjUTFZo5Q1Kw9xbCAo3PVCUX41yTh3V1z8FLWDZ0RvPXLFcD 2cRCNH4vyckvQnbvM/BMkp3XqsbmHWDD8mJ4BGcbhOb/uZAHfFbU6AJnO oh484ZoWT4rzksLGwf87m9FNM7uXWS1PC2Laso5anmE4cER8sY0nJlBDl DZvjTMPchExpXStMuGHGx6u6RoCIrlnSYzSAMXxh2CGnU3N+wPtr3mFdb QE2hRGVuyaN7UaMk64t+K03KRu/iL+rw5S+JiI3qzL97BGBj2WVbnlT4x w==; IronPort-SDR: 2u73v+OPiHZ1XTpAjbwTX0JEzORaPFB2iIV/BWI+U+4DO1AK4MrZftxqHF9SCudPpiSDSGd0FQ YNkDxHJpHYuDQ/LGLWzRd11qOHiwQ3N/Rk/FiCQTTHcaIJeroV6txgMOU89PdnGvRYoWh3ojVn wfexdTEOdvArVF/C9zKcMhhA9wkf0wlnvHswNL6aYSaj99Tt4r5IhsYvDyDFuqhAHIP7VsvSA1 ks1XAGHeaSzDVMYsqwvj59L73sFg+V9kBmL3MuXBoi+YuhIhct1ZSQKzTwnNfRExW/SYSCpJPb N5Y= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="139073332" IronPort-SDR: lSShjQcbl5ulWyE8SXG2cWJP8PaOF9Qbk3ZBfnFIW9JOzdfTgTKbbQz/JsoJRqigiLS0N+oaQU 6dNoveD/n5e1Sitp7YkotJdsZorSql5OI= IronPort-SDR: f80anS23G5A8BJ9SCr8oFhK3Ht4jPat+tFbF82se8wvJ/JGX3sPuF0YjyzbIaelFCChimsU29s Un6xl1W5KrxA== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 03/11] target/riscv: Disable the MMU correctly Date: Thu, 28 May 2020 15:14:15 -0700 Message-Id: <3e5b7d781f56c7a625c7c8ca5e38a9544e2995c2.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.153.144; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa5.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:22:43 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Previously if we didn't enable the MMU it would be enabled in the realize() function anyway. Let's ensure that if we don't want the MMU we disable it. We also don't need to enable the MMU as it will be enalbed in realize() by default. Signed-off-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/cpu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 5eb3c02735..8deba3d16d 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -142,7 +142,6 @@ static void rv32gcsu_priv1_09_1_cpu_init(Object *obj) set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_09_1); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_MMU); set_feature(env, RISCV_FEATURE_PMP); } =20 @@ -152,7 +151,6 @@ static void rv32gcsu_priv1_10_0_cpu_init(Object *obj) set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_MMU); set_feature(env, RISCV_FEATURE_PMP); } =20 @@ -163,6 +161,7 @@ static void rv32imacu_nommu_cpu_init(Object *obj) set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); set_feature(env, RISCV_FEATURE_PMP); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); } =20 static void rv32imafcu_nommu_cpu_init(Object *obj) @@ -172,6 +171,7 @@ static void rv32imafcu_nommu_cpu_init(Object *obj) set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); set_feature(env, RISCV_FEATURE_PMP); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); } =20 #elif defined(TARGET_RISCV64) @@ -190,7 +190,6 @@ static void rv64gcsu_priv1_09_1_cpu_init(Object *obj) set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_09_1); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_MMU); set_feature(env, RISCV_FEATURE_PMP); } =20 @@ -200,7 +199,6 @@ static void rv64gcsu_priv1_10_0_cpu_init(Object *obj) set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_MMU); set_feature(env, RISCV_FEATURE_PMP); } =20 @@ -211,6 +209,7 @@ static void rv64imacu_nommu_cpu_init(Object *obj) set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); set_feature(env, RISCV_FEATURE_PMP); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); } =20 #endif --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590704943; cv=none; d=zohomail.com; s=zohoarc; b=ZcpO5en1W5TzMhbGTvNfcftmt1wjYEAxN6W14VOkk43/m3JELNBcwXWuFd4e2J2Uyz5OdCfXYD4PZidnWPrg6+6DKeaC6pMuwYidkQn8udQaC2IztuY8iLYklWSx5P9WlPR3vNdSyd3rjkxR0gkPxQq3zd+o94eZoTAAcDVayyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590704943; 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=xszBhSRJkYUSvbcLp0uY+VicPG5cVh43FlTht810chY=; b=ciPd3g8M3hbR1L2iUuX697SIZOGbeWtogu3iEfM86jpYKcAbLsWgG94wHZ8JNpSe0qe3k6ZcIbFxPpoBVj8SrcFMNvCfEsCHq5McAb+TkVS4F7Y6X5+7Zhz2EH6h00jpaOjrPRiOjJiTCH/DnY3/mDoI14blYeIF6d0hvTPV9C8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15907049435161023.1171513117928; Thu, 28 May 2020 15:29:03 -0700 (PDT) Received: from localhost ([::1]:54936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR1J-0002n7-Qd for importer@patchew.org; Thu, 28 May 2020 18:29:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvT-0002Fn-Kz; Thu, 28 May 2020 18:22:59 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:43643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvQ-0005o1-Qz; Thu, 28 May 2020 18:22:58 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:22:53 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:42 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip01.wdc.com with ESMTP; 28 May 2020 15:22:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704576; x=1622240576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7lsaaaazJWD7znUV85BSVopoiWRkactNOEbF5Q2Y7Zo=; b=EfYlD7aKH6DY4lE2e+9lOpa1lhnNPo9tNKPR1D0gLYUDeIvI8fOE7/d/ ZZ1olgOLEjOGbxioJhi18MfmGmaKI9yZ7TLQT/+SspeiCT9GEZImn728M nOu4PdTHA5Q/el1G+Z+BZ0Fzv7v4x4W6zRokvnlIck7x0geyFDCrktUWz XzGfVYPMkFeTAU6ah3mXxLlq5fT4TD//LuYAL8fCsOSklAH5AWLJf/muT ItqGwXWVo8BJmKppZefovigrrtuDOlyyDedTVIUzJ0jngKOrcrVRMCCja iJqqmvtkYfMaB17dP8ma65+E31aBPAGoQ9fH4N6pdRZ2O/tUheJOubvQ9 w==; IronPort-SDR: HfScqUDsMfjGSHNdN0UZuGEQq0P8+atXo0NAkdTfHaF2mnDyC+5kr0zgG70pdr6fj6UBLHjIiI wSAa3+cuA9McwRmN4tsXbWSx6zuKGTF2Rzp/JTy5oJoctVJegc3fjMtJyKaYqs9rDsH2Zyjcz/ H4mElgfB/TlUcH/V/1NKH+BvB6VPnl/wZ2PPT6lacXyFzvEOTz6cAEoBSwEzZQ8d4QyEg2slaH BBDkzhvK3r8Xrbiz/jQg9FTnaM2mfMsIGx7FpqojNTnnELDgFABF/VRjUDfjRldMY89qAo8jwA vZw= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="138744572" IronPort-SDR: ntWTFAl8DyLGBOoU6Y9gvLxuDXQYRd6aAEB7R6v5//66Tly0EprHNW/HgBzudy7FkIniclsBA4 KQWKrFszM+wAwrlh4qv7BdPC+8yA5aEZM= IronPort-SDR: JHQh9Tm1DmN/QU7rdSoBQBzDyOfZH5dm5ui38BiRJc8l0HZM3Js/cHRMWMVLcd7OgxSeyzkn9o WxK+bcWmIi+g== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 04/11] target/riscv: Don't set PMP feature in the cpu init Date: Thu, 28 May 2020 15:14:17 -0700 Message-Id: X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.154.42; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:22:54 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The PMP is enabled by default via the "pmp" property so there is no need for us to set it in the init function. As all CPUs have PMP support just remove the set_feature() call in the CPU init functions. Signed-off-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/cpu.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8deba3d16d..406e8f37d7 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -142,7 +142,6 @@ static void rv32gcsu_priv1_09_1_cpu_init(Object *obj) set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_09_1); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); } =20 static void rv32gcsu_priv1_10_0_cpu_init(Object *obj) @@ -151,7 +150,6 @@ static void rv32gcsu_priv1_10_0_cpu_init(Object *obj) set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); } =20 static void rv32imacu_nommu_cpu_init(Object *obj) @@ -160,7 +158,6 @@ static void rv32imacu_nommu_cpu_init(Object *obj) set_misa(env, RV32 | RVI | RVM | RVA | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); qdev_prop_set_bit(DEVICE(obj), "mmu", false); } =20 @@ -170,7 +167,6 @@ static void rv32imafcu_nommu_cpu_init(Object *obj) set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); qdev_prop_set_bit(DEVICE(obj), "mmu", false); } =20 @@ -190,7 +186,6 @@ static void rv64gcsu_priv1_09_1_cpu_init(Object *obj) set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_09_1); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); } =20 static void rv64gcsu_priv1_10_0_cpu_init(Object *obj) @@ -199,7 +194,6 @@ static void rv64gcsu_priv1_10_0_cpu_init(Object *obj) set_misa(env, RV64 | RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); } =20 static void rv64imacu_nommu_cpu_init(Object *obj) @@ -208,7 +202,6 @@ static void rv64imacu_nommu_cpu_init(Object *obj) set_misa(env, RV64 | RVI | RVM | RVA | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); set_resetvec(env, DEFAULT_RSTVEC); - set_feature(env, RISCV_FEATURE_PMP); qdev_prop_set_bit(DEVICE(obj), "mmu", false); } =20 --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590705121; cv=none; d=zohomail.com; s=zohoarc; b=UR5W3cRbpen6NBsBgSQj4ZNi/O2IVVCsTfV+2m1lSaS6aZcQtlaPlKgvSWQ/LCFsuViRa/05SJXYSBOTt7/7014J8SK2S3/uvPuFnOt6VkCTBvClagHXiir9eyxMMczTdU4Hz9F+HyBtYke1L7J2neqVKSy9l758bwaKlQwAJgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590705121; 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=b+Hp4LkwLfuxaX0KeqM1T48H8cWOr2eXpYL2DzZI22s=; b=Ch5S0re/+Ijzmegclfl+uTpWBFS6EZHzkO8kAJySsyZzfGDFxrQ+uq8pdp3+vi5RakCHN+UtwoD7181bk205IOSuyPyrv66RgXL/usceWVnZV/kHEqe8yCE+5ldmmunrIMFf+tPz+0dLNFDm/J6lnLOl/+0u5YRIqDdvDhb1FOM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590705121891606.8849036674632; Thu, 28 May 2020 15:32:01 -0700 (PDT) Received: from localhost ([::1]:35314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR4C-0006la-Bu for importer@patchew.org; Thu, 28 May 2020 18:32:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvc-0002W5-2U; Thu, 28 May 2020 18:23:08 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:43649) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvV-0005sD-Er; Thu, 28 May 2020 18:23:06 -0400 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:22:56 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:44 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip01.wdc.com with ESMTP; 28 May 2020 15:22:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704581; x=1622240581; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YSfmtlnUPoc+DRubFLCIUkLA+JbOhAPeXjCFaLFXhWU=; b=OUdeqHPrvJYM5tdy7JYyG81wBZmqkcfYHup7GrvvDbxS/6RLPUGJdNa8 V+fpqq1WkB1Y6VnrQU8eDZy57+Oq6w2w643wKINRRL5sLwXwo6JQaLOjM 3O3vjAAV8C2UvK9ulcuKPECrwwAjO/CR51YNjRgkT3nRPJrfiA2dbX9iN EU7qTpoGegGhyiDvGrmSIo1I5UmmrJISC2UL0pnUy8ElIr5wGukW1ShuW y483g+K5L+gtVFzgXc2e4YOMjE1+5D5xWVxh+Wo/d8aorT9z6xP61Hake W3l6ey/xud6hpQUWncDxw7SPA9+e5bVCPgYORXb0IJLT+NYq3V9riTr41 Q==; IronPort-SDR: ln0A5ObGoC+Yzz6waLULf+0x5shLZDgDvVfMXEyUHxt2EytBnq3zHhn+EQlhWQmKgHBYKmSRwZ +nvQ1kZXyd6mimQEruJJDGsWwlJwrU5fVGVlRxm0D2f6dDY9C55LWY9AMH/T03zgcqBwIrZfNB x7xxMhlbkSWzg44W+CcY6g+lcGdENY1kncS3PraeaGKCUmemL3OFEreETnNc/LV7YIRNTLZbXT KDgkrOWj4km1LSacu7ItlxxHjslJzQogcM8JpRzhs7a7w4d7zaSB+Ca2/lpym7CG1eb02kAHya dzg= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="138744575" IronPort-SDR: uTjoFDptbKPmoCSvnlLTc/mL70a4axeBK+RMRLj1IeCRW6dPcfAxC5reVb0evbpsR6wgRTrYqu FCAtpGax3By18t7TzjJk25Xqu9vXcVECI= IronPort-SDR: E9C9vKZeKL2aOAAwffPzF732LUHxvBQXhMilpzt8PheUW+OQ/Uhr5duhRJTAPatzd5JhR+QwHX mK0FufewaG5w== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 05/11] target/riscv: Add the lowRISC Ibex CPU Date: Thu, 28 May 2020 15:14:20 -0700 Message-Id: <92832b1e7fc59b4728fd47f7c59456525e6c1936.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.154.42; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:22:54 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Ibex is a small and efficient, 32-bit, in-order RISC-V core with a 2-stage pipeline that implements the RV32IMC instruction set architecture. For more details on lowRISC see here: https://github.com/lowRISC/ibex Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: LIU Zhiwei --- target/riscv/cpu.h | 1 + target/riscv/cpu.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index d0e7f5b9c5..8733d7467f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -35,6 +35,7 @@ #define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any") #define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32") #define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") +#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex") #define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31") #define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34") #define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51") diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 406e8f37d7..6e0d4d1dda 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -152,6 +152,15 @@ static void rv32gcsu_priv1_10_0_cpu_init(Object *obj) set_resetvec(env, DEFAULT_RSTVEC); } =20 +static void rv32imcu_nommu_cpu_init(Object *obj) +{ + CPURISCVState *env =3D &RISCV_CPU(obj)->env; + set_misa(env, RV32 | RVI | RVM | RVC | RVU); + set_priv_version(env, PRIV_VERSION_1_10_0); + set_resetvec(env, 0x8090); + qdev_prop_set_bit(DEVICE(obj), "mmu", false); +} + static void rv32imacu_nommu_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; @@ -611,6 +620,7 @@ static const TypeInfo riscv_cpu_type_infos[] =3D { DEFINE_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), #if defined(TARGET_RISCV32) DEFINE_CPU(TYPE_RISCV_CPU_BASE32, riscv_base32_cpu_init), + DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32imcu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31, rv32imacu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34, rv32imafcu_nommu_cpu_init), DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34, rv32gcsu_priv1_10_0_cpu_in= it), --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590705126; cv=none; d=zohomail.com; s=zohoarc; b=b+vEkM98UE/GWWRglr64ZUzhWGi2TxyMyr8r155uQ5bDvwd4umJZWGMiYmkv/4+0oCUpeb08XDFIEKhIaP3KcAU8CekXW8A/wwbe6+155p8IX/h5aER7TZXL6CiAeO2zbz15HWESARBzDV84Aqygn3msuf7Yjj/G5gFoMdiTB0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590705126; 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=q6Hv03gsbxLFcOTQmbZdJ+nO77it9bgmMg6yPL8m/w0=; b=XIWor5j+7MEkerCfygPPwh7SEu68kz+E7h2CofMMv06Wlh0kJyZvtPaKLlanuO3i9CLK2iOsT7oIA/Lma+LQaLN4GgVwpRhWjQNXDYAmB7Xbzpw8SgQqZBVGiyf0YFTvtFDMhwXxcZsq2mI+jMwVYPEAP4i5iCR0PAG2gCF3rFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590705126298109.1985404590007; Thu, 28 May 2020 15:32:06 -0700 (PDT) Received: from localhost ([::1]:35578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR4G-0006sG-R9 for importer@patchew.org; Thu, 28 May 2020 18:32:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvv-0003Il-5X; Thu, 28 May 2020 18:23:27 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:15467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvb-0005wh-Ov; Thu, 28 May 2020 18:23:25 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:23:00 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:14 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:22:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704588; x=1622240588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KYfczJA0QrAWU4jD8Q/oTPZtjMyyiheipkCyBvJs9mw=; b=I5/4KRXzaA6lb3gUff9iNEf7g6dg8ghscCp21/137rv904yNaQMgXQGP IXVo/FfHgk1nf5HKiKA0mJDYmh2t7n2M7Zd4ZVpo5YOztfsNq3tzBNlaO MfGnGwQmTjs8LVhTxaSMjV0z3cMpNELRKc5dJddYHPqKc5yN27s+Qjkfl Wutb2Nis13zyg+cEmK1/Ifj6SUO4OsG7scA14RwjAp7Y5rayhKNuzmUf1 TCYbiaws1xpM4TugNQSfscHeV3yx8bA/eK002D/hQZWON1Ts0uv7fspa5 ZjKEmeEpMl9LsyZpmS0kld5EjEx4fzHkpEJVx8E0dw68d8MIzuHBeDWPM Q==; IronPort-SDR: Zv8Ui+a9RzBoiyuWgJt7bUKVpS77MtJTWVVqnKjpoT7AfsZUM+U+FL16OJUcWeer9YqCepjf8O Cq+pJTu9JqNhts+mjtyFjysZvek1lP6bknqccbUAmGkTkSfARIvbK5sbxhb3piBM3Bb1OiFkAG B6COz9SIPB7DfetgxaCO2U7BONE6iStEIyy64mrZBaBvj/0z/o83gzwzllXThF2l2qSc5yvy+O JFjTfb21KxD9kXAM5LukwjucC2K4VVQFnGLPgSxAW1TlcQoKvXnYbA1c6H/0nsa6ERd4qVHRTa 0/U= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="143075995" IronPort-SDR: fIeDrgueuEFiLh+OhvqGtCxHtAtpUoZqVG+1m7VO+/WOFoWz/+cXTcSLOR/BwlA1aoAbIU/u3H Unit6NmRLxWnsDcb9dKU6pg80//uyzCOs= IronPort-SDR: Vpbf2uR4Nke+4DZ4WMJF9Ej6ACJ8A8nYYO0A1Xb/FjqG9gxIZ3aAVfUzd0dNSA+MpI0jBxupKd Nfc3ifmfozwA== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 06/11] riscv: Initial commit of OpenTitan machine Date: Thu, 28 May 2020 15:14:23 -0700 Message-Id: <0ab3cecbe801f9e14ad1a5447d02483b9008fdbb.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.153.141; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa3.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:23:00 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This adds a barebone OpenTitan machine to QEMU. Signed-off-by: Alistair Francis Reviewed-by: Bin Meng --- default-configs/riscv32-softmmu.mak | 1 + default-configs/riscv64-softmmu.mak | 11 +- include/hw/riscv/opentitan.h | 68 ++++++++++ hw/riscv/opentitan.c | 184 ++++++++++++++++++++++++++++ MAINTAINERS | 9 ++ hw/riscv/Kconfig | 5 + hw/riscv/Makefile.objs | 1 + 7 files changed, 278 insertions(+), 1 deletion(-) create mode 100644 include/hw/riscv/opentitan.h create mode 100644 hw/riscv/opentitan.c 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/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h new file mode 100644 index 0000000000..a4b6499444 --- /dev/null +++ b/include/hw/riscv/opentitan.h @@ -0,0 +1,68 @@ +/* + * 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_PWRMGR, + IBEX_RSTMGR, + IBEX_CLKMGR, + IBEX_PINMUX, + IBEX_ALERT_HANDLER, + IBEX_NMI_GEN, + IBEX_USBDEV, + IBEX_PADCTRL, +}; + +#endif diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c new file mode 100644 index 0000000000..b4fb836466 --- /dev/null +++ b/hw/riscv/opentitan.c @@ -0,0 +1,184 @@ +/* + * 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_PWRMGR] =3D { 0x400A0000, 0x10000 }, + [IBEX_RSTMGR] =3D { 0x400B0000, 0x10000 }, + [IBEX_CLKMGR] =3D { 0x400C0000, 0x10000 }, + [IBEX_AES] =3D { 0x40110000, 0x10000 }, + [IBEX_HMAC] =3D { 0x40120000, 0x10000 }, + [IBEX_ALERT_HANDLER] =3D { 0x40130000, 0x10000 }, + [IBEX_NMI_GEN] =3D { 0x40140000, 0x10000 }, + [IBEX_USBDEV] =3D { 0x40150000, 0x10000 }, + [IBEX_PADCTRL] =3D { 0x40160000, 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, NULL= ); + } + + 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.pwrmgr", + memmap[IBEX_PWRMGR].base, memmap[IBEX_PWRMGR].size); + create_unimplemented_device("riscv.lowrisc.ibex.rstmgr", + memmap[IBEX_RSTMGR].base, memmap[IBEX_RSTMGR].size); + create_unimplemented_device("riscv.lowrisc.ibex.clkmgr", + memmap[IBEX_CLKMGR].base, memmap[IBEX_CLKMGR].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.nmi_gen", + memmap[IBEX_NMI_GEN].base, memmap[IBEX_NMI_GEN].size); + create_unimplemented_device("riscv.lowrisc.ibex.usbdev", + memmap[IBEX_USBDEV].base, memmap[IBEX_USBDEV].size); + create_unimplemented_device("riscv.lowrisc.ibex.padctrl", + memmap[IBEX_PADCTRL].base, memmap[IBEX_PADCTRL].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/MAINTAINERS b/MAINTAINERS index 0944d9c731..3e7d9cb0a5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1238,6 +1238,15 @@ 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/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 --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590704947; cv=none; d=zohomail.com; s=zohoarc; b=S7W3xpQMX5sA3clzmQ18Y8yfFzn3gfzh+D+6WNCDZNOrqJc/PczTdg1B8mdnqyWm8bcmBD5esVf52RrqyFuBBsrs1rdKDjfqKt6kQ7G40SA8Z4inF6RvLz/DgDiOyZccqtR2xapfuP7bE4KZchn12HD3ucHclnZDnM5Ct9nMvQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590704947; 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=GKV4h43nG75IKQHlaonqA650nrqsnYw+wChI1ipy1aw=; b=ke0vmxSPRKLv4d9rDbo+jrsdSfSK8E6xVG/KS4cyUx5K0uTI1/FvLnjN4WWGJ77zlFBkVnnVq0zZaomUN1rEOW9SS6K0V7fRSbcPH0UaGewl84HH9KfgkjYESkOYqlVCdk1HHjYRCMck7IXa+E/4XBJWwp1cJdnZP6lRxJEXKNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590704947702927.5747494105279; Thu, 28 May 2020 15:29:07 -0700 (PDT) Received: from localhost ([::1]:55236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR1N-0002uE-Mv for importer@patchew.org; Thu, 28 May 2020 18:29:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvx-0003RB-T3; Thu, 28 May 2020 18:23:29 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:15469) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvf-00061B-My; Thu, 28 May 2020 18:23:29 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:23:02 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:17 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:23:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704592; x=1622240592; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EjVNIOYn4WSka+EWuzKHqBuxC+TY7dRI/Oh2Z79Vwmg=; b=GrqYjEGg5nv1JGZbIpziMRwEMmPtuViqmUr8rTzHOO6cJr8VwYbf5tWO f0BEqBpgI728k3eHZRNfluQxonR7yRwtnD0LpOXNnCbrC/hPuf73pqquE d0CCS40l0xDQ32UtWB9KEX95CJBj6/McGrx15D69j1RjOjVmjuK9aeQW6 Rb2LDJ5aGwi8V9I8P9ObajIuG311mX6YteKsMecYAxCtahMM3JIYHcvuF nZVmVlt2b18MAXvA8rZorGECiHYS7rWY45Ahp18Ky+mL5jxrmZqR2C5dq izwaEz96+oxxyuJ3W/ywlOOVH46DWElycZjaoURVvfRvzZj3hXwiXdZsq Q==; IronPort-SDR: iZnpbj2oUjsH3/vzE6bzHPuFUfmorNu+VjUQgOnlgO4w8/5B86tohsElpqwy4vYkpeThEZ9Bto ip3y0toTUbsu1+3Gemux4rp4z3CP5+ptg8bSapOJxsRPfOorA4V4mkX1Fv8t028Fcw5WLFWvbo rja6qcSPrL7E3oQDjc2dcdhj3Om1ecrp89YjQpX6pnC1XvYe7Cy1ccCpky7X7r5FAq/oSc0Ayp hqKw9T79ba18SxxdUWtCODhZ+TS+EdFUmwSV7IyPW1xWOSgh3jEUt5rxS89smx058gItKAlvaD jJs= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="143075996" IronPort-SDR: O0KvUEwL/MPsjiOOlsSnKJnXoj270tMcoxyuRMSwzFTr+345GvCQqIOzaqi3hjH1sNCZmzxJ2j K+1OhtQRRrKz4KJcPFnHg8xFibC5l1tV4= IronPort-SDR: vRW4s0tR7IA8NYTmubyZPApoYZbTOGnatZiyGT1MlIyvEa56wqCGolNNFvEBqbsxlx1AfvLKPM lk9OrD1oM+1A== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 07/11] hw/char: Initial commit of Ibex UART Date: Thu, 28 May 2020 15:14:25 -0700 Message-Id: <73cce2d0edd0d41ba15df403a2096bfa70bf0565.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.153.141; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa3.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:23:00 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is the initial commit of the Ibex UART device. Serial TX is working, while RX has been implemeneted but untested. This is based on the documentation from: https://docs.opentitan.org/hw/ip/uart/doc/ Signed-off-by: Alistair Francis Reviewed-by: LIU Zhiwei --- include/hw/char/ibex_uart.h | 110 ++++++++ hw/char/ibex_uart.c | 492 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/char/Makefile.objs | 1 + hw/riscv/Kconfig | 4 + 5 files changed, 609 insertions(+) create mode 100644 include/hw/char/ibex_uart.h create mode 100644 hw/char/ibex_uart.c diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h new file mode 100644 index 0000000000..2bec772615 --- /dev/null +++ b/include/hw/char/ibex_uart.h @@ -0,0 +1,110 @@ +/* + * QEMU lowRISC Ibex UART device + * + * Copyright (c) 2020 Western Digital + * + * 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. + */ + +#ifndef HW_IBEX_UART_H +#define HW_IBEX_UART_H + +#include "hw/sysbus.h" +#include "chardev/char-fe.h" +#include "qemu/timer.h" + +#define IBEX_UART_INTR_STATE 0x00 + #define INTR_STATE_TX_WATERMARK (1 << 0) + #define INTR_STATE_RX_WATERMARK (1 << 1) + #define INTR_STATE_TX_EMPTY (1 << 2) + #define INTR_STATE_RX_OVERFLOW (1 << 3) +#define IBEX_UART_INTR_ENABLE 0x04 +#define IBEX_UART_INTR_TEST 0x08 + +#define IBEX_UART_CTRL 0x0c + #define UART_CTRL_TX_ENABLE (1 << 0) + #define UART_CTRL_RX_ENABLE (1 << 1) + #define UART_CTRL_NF (1 << 2) + #define UART_CTRL_SLPBK (1 << 4) + #define UART_CTRL_LLPBK (1 << 5) + #define UART_CTRL_PARITY_EN (1 << 6) + #define UART_CTRL_PARITY_ODD (1 << 7) + #define UART_CTRL_RXBLVL (3 << 8) + #define UART_CTRL_NCO (0xFFFF << 16) + +#define IBEX_UART_STATUS 0x10 + #define UART_STATUS_TXFULL (1 << 0) + #define UART_STATUS_RXFULL (1 << 1) + #define UART_STATUS_TXEMPTY (1 << 2) + #define UART_STATUS_RXIDLE (1 << 4) + #define UART_STATUS_RXEMPTY (1 << 5) + +#define IBEX_UART_RDATA 0x14 +#define IBEX_UART_WDATA 0x18 + +#define IBEX_UART_FIFO_CTRL 0x1c + #define FIFO_CTRL_RXRST (1 << 0) + #define FIFO_CTRL_TXRST (1 << 1) + #define FIFO_CTRL_RXILVL (7 << 2) + #define FIFO_CTRL_RXILVL_SHIFT (2) + #define FIFO_CTRL_TXILVL (3 << 5) + #define FIFO_CTRL_TXILVL_SHIFT (5) + +#define IBEX_UART_FIFO_STATUS 0x20 +#define IBEX_UART_OVRD 0x24 +#define IBEX_UART_VAL 0x28 +#define IBEX_UART_TIMEOUT_CTRL 0x2c + +#define IBEX_UART_TX_FIFO_SIZE 16 + +#define TYPE_IBEX_UART "ibex-uart" +#define IBEX_UART(obj) \ + OBJECT_CHECK(IbexUartState, (obj), TYPE_IBEX_UART) + +typedef struct { + /* */ + SysBusDevice parent_obj; + + /* */ + MemoryRegion mmio; + + uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE]; + uint32_t tx_level; + + QEMUTimer *fifo_trigger_handle; + uint64_t char_tx_time; + + uint32_t uart_intr_state; + uint32_t uart_intr_enable; + uint32_t uart_ctrl; + uint32_t uart_status; + uint32_t uart_rdata; + uint32_t uart_fifo_ctrl; + uint32_t uart_fifo_status; + uint32_t uart_ovrd; + uint32_t uart_val; + uint32_t uart_timeout_ctrl; + + CharBackend chr; + qemu_irq tx_watermark; + qemu_irq rx_watermark; + qemu_irq tx_empty; + qemu_irq rx_overflow; +} IbexUartState; +#endif /* HW_IBEX_UART_H */ diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c new file mode 100644 index 0000000000..c416325d73 --- /dev/null +++ b/hw/char/ibex_uart.c @@ -0,0 +1,492 @@ +/* + * QEMU lowRISC Ibex UART device + * + * Copyright (c) 2020 Western Digital + * + * For details check the documentation here: + * https://docs.opentitan.org/hw/ip/uart/doc/ + * + * 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 "hw/char/ibex_uart.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "qemu/log.h" +#include "qemu/module.h" + +static void ibex_uart_update_irqs(IbexUartState *s) +{ + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_TX_WATERMARK= ) { + qemu_set_irq(s->tx_watermark, 1); + } else { + qemu_set_irq(s->tx_watermark, 0); + } + + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_RX_WATERMARK= ) { + qemu_set_irq(s->rx_watermark, 1); + } else { + qemu_set_irq(s->rx_watermark, 0); + } + + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_TX_EMPTY) { + qemu_set_irq(s->tx_empty, 1); + } else { + qemu_set_irq(s->tx_empty, 0); + } + + if (s->uart_intr_state & s->uart_intr_enable & INTR_STATE_RX_OVERFLOW)= { + qemu_set_irq(s->rx_overflow, 1); + } else { + qemu_set_irq(s->rx_overflow, 0); + } +} + +static int ibex_uart_can_receive(void *opaque) +{ + IbexUartState *s =3D opaque; + + if (s->uart_ctrl & UART_CTRL_RX_ENABLE) { + return 1; + } + + return 0; +} + +static void ibex_uart_receive(void *opaque, const uint8_t *buf, int size) +{ + IbexUartState *s =3D opaque; + uint8_t rx_fifo_level =3D (s->uart_fifo_ctrl & FIFO_CTRL_RXILVL) + >> FIFO_CTRL_RXILVL_SHIFT; + + s->uart_rdata =3D *buf; + + s->uart_status &=3D ~UART_STATUS_RXIDLE; + s->uart_status &=3D ~UART_STATUS_RXEMPTY; + + if (size > rx_fifo_level) { + s->uart_intr_state |=3D INTR_STATE_RX_WATERMARK; + } + + ibex_uart_update_irqs(s); +} + +static gboolean ibex_uart_xmit(GIOChannel *chan, GIOCondition cond, + void *opaque) +{ + IbexUartState *s =3D opaque; + uint8_t tx_fifo_level =3D (s->uart_fifo_ctrl & FIFO_CTRL_TXILVL) + >> FIFO_CTRL_TXILVL_SHIFT; + int ret; + + /* instant drain the fifo when there's no back-end */ + if (!qemu_chr_fe_backend_connected(&s->chr)) { + s->tx_level =3D 0; + return FALSE; + } + + if (!s->tx_level) { + s->uart_status &=3D UART_STATUS_TXFULL; + s->uart_status |=3D UART_STATUS_TXEMPTY; + s->uart_intr_state |=3D INTR_STATE_TX_EMPTY; + s->uart_intr_state &=3D ~INTR_STATE_TX_WATERMARK; + ibex_uart_update_irqs(s); + return FALSE; + } + + ret =3D qemu_chr_fe_write(&s->chr, s->tx_fifo, s->tx_level); + + if (ret >=3D 0) { + s->tx_level -=3D ret; + memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_level); + } + + if (s->tx_level) { + guint r =3D qemu_chr_fe_add_watch(&s->chr, G_IO_OUT | G_IO_HUP, + ibex_uart_xmit, s); + if (!r) { + s->tx_level =3D 0; + return FALSE; + } + } + + /* Clear the TX Full bit */ + if (s->tx_level !=3D IBEX_UART_TX_FIFO_SIZE) { + s->uart_status &=3D ~UART_STATUS_TXFULL; + } + + /* Disable the TX_WATERMARK IRQ */ + if (s->tx_level < tx_fifo_level) { + s->uart_intr_state &=3D ~INTR_STATE_TX_WATERMARK; + } + + /* Set TX empty */ + if (s->tx_level =3D=3D 0) { + s->uart_status |=3D UART_STATUS_TXEMPTY; + s->uart_intr_state |=3D INTR_STATE_TX_EMPTY; + } + + ibex_uart_update_irqs(s); + return FALSE; +} + +static void uart_write_tx_fifo(IbexUartState *s, const uint8_t *buf, + int size) +{ + uint64_t current_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + uint8_t tx_fifo_level =3D (s->uart_fifo_ctrl & FIFO_CTRL_TXILVL) + >> FIFO_CTRL_TXILVL_SHIFT; + + if (size > IBEX_UART_TX_FIFO_SIZE - s->tx_level) { + size =3D IBEX_UART_TX_FIFO_SIZE - s->tx_level; + qemu_log_mask(LOG_GUEST_ERROR, "ibex_uart: TX FIFO overflow"); + } + + memcpy(s->tx_fifo + s->tx_level, buf, size); + s->tx_level +=3D size; + + if (s->tx_level > 0) { + s->uart_status &=3D ~UART_STATUS_TXEMPTY; + } + + if (s->tx_level >=3D tx_fifo_level) { + s->uart_intr_state |=3D INTR_STATE_TX_WATERMARK; + ibex_uart_update_irqs(s); + } + + if (s->tx_level =3D=3D IBEX_UART_TX_FIFO_SIZE) { + s->uart_status |=3D UART_STATUS_TXFULL; + } + + timer_mod(s->fifo_trigger_handle, current_time + + (s->char_tx_time * 4)); +} + +static void ibex_uart_reset(DeviceState *dev) +{ + IbexUartState *s =3D IBEX_UART(dev); + + s->uart_intr_state =3D 0x00000000; + s->uart_intr_state =3D 0x00000000; + s->uart_intr_enable =3D 0x00000000; + s->uart_ctrl =3D 0x00000000; + s->uart_status =3D 0x0000003c; + s->uart_rdata =3D 0x00000000; + s->uart_fifo_ctrl =3D 0x00000000; + s->uart_fifo_status =3D 0x00000000; + s->uart_ovrd =3D 0x00000000; + s->uart_val =3D 0x00000000; + s->uart_timeout_ctrl =3D 0x00000000; + + s->tx_level =3D 0; + + s->char_tx_time =3D (NANOSECONDS_PER_SECOND / 230400) * 10; + + ibex_uart_update_irqs(s); +} + +static uint64_t ibex_uart_read(void *opaque, hwaddr addr, + unsigned int size) +{ + IbexUartState *s =3D opaque; + uint64_t retvalue =3D 0; + + switch (addr) { + case IBEX_UART_INTR_STATE: + retvalue =3D s->uart_intr_state; + break; + case IBEX_UART_INTR_ENABLE: + retvalue =3D s->uart_intr_enable; + break; + case IBEX_UART_INTR_TEST: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: wdata is write only\n", __func__); + break; + + case IBEX_UART_CTRL: + retvalue =3D s->uart_ctrl; + break; + case IBEX_UART_STATUS: + retvalue =3D s->uart_status; + break; + + case IBEX_UART_RDATA: + retvalue =3D s->uart_rdata; + if (s->uart_ctrl & UART_CTRL_RX_ENABLE) { + qemu_chr_fe_accept_input(&s->chr); + + s->uart_status |=3D UART_STATUS_RXIDLE; + s->uart_status |=3D UART_STATUS_RXEMPTY; + } + break; + case IBEX_UART_WDATA: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: wdata is write only\n", __func__); + break; + + case IBEX_UART_FIFO_CTRL: + retvalue =3D s->uart_fifo_ctrl; + break; + case IBEX_UART_FIFO_STATUS: + retvalue =3D s->uart_fifo_status; + + retvalue |=3D s->tx_level & 0x1F; + + qemu_log_mask(LOG_UNIMP, + "%s: RX fifos are not supported\n", __func__); + break; + + case IBEX_UART_OVRD: + retvalue =3D s->uart_ovrd; + qemu_log_mask(LOG_UNIMP, + "%s: ovrd is not supported\n", __func__); + break; + case IBEX_UART_VAL: + retvalue =3D s->uart_val; + qemu_log_mask(LOG_UNIMP, + "%s: val is not supported\n", __func__); + break; + case IBEX_UART_TIMEOUT_CTRL: + retvalue =3D s->uart_timeout_ctrl; + qemu_log_mask(LOG_UNIMP, + "%s: timeout_ctrl is not supported\n", __func__); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); + return 0; + } + + return retvalue; +} + +static void ibex_uart_write(void *opaque, hwaddr addr, + uint64_t val64, unsigned int size) +{ + IbexUartState *s =3D opaque; + uint32_t value =3D val64; + + switch (addr) { + case IBEX_UART_INTR_STATE: + /* Write 1 clear */ + s->uart_intr_state &=3D ~value; + ibex_uart_update_irqs(s); + break; + case IBEX_UART_INTR_ENABLE: + s->uart_intr_enable =3D value; + ibex_uart_update_irqs(s); + break; + case IBEX_UART_INTR_TEST: + s->uart_intr_state |=3D value; + ibex_uart_update_irqs(s); + break; + + case IBEX_UART_CTRL: + s->uart_ctrl =3D value; + + if (value & UART_CTRL_NF) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_NF is not supported\n", __func__); + } + if (value & UART_CTRL_SLPBK) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_SLPBK is not supported\n", __func= __); + } + if (value & UART_CTRL_LLPBK) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_LLPBK is not supported\n", __func= __); + } + if (value & UART_CTRL_PARITY_EN) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_PARITY_EN is not supported\n", + __func__); + } + if (value & UART_CTRL_PARITY_ODD) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_PARITY_ODD is not supported\n", + __func__); + } + if (value & UART_CTRL_RXBLVL) { + qemu_log_mask(LOG_UNIMP, + "%s: UART_CTRL_RXBLVL is not supported\n", __fun= c__); + } + if (value & UART_CTRL_NCO) { + uint64_t baud =3D ((value & UART_CTRL_NCO) >> 16); + baud *=3D 1000; + baud /=3D 2 ^ 20; + + s->char_tx_time =3D (NANOSECONDS_PER_SECOND / baud) * 10; + } + break; + case IBEX_UART_STATUS: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: status is read only\n", __func__); + break; + + case IBEX_UART_RDATA: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: rdata is read only\n", __func__); + break; + case IBEX_UART_WDATA: + uart_write_tx_fifo(s, (uint8_t *) &value, 1); + break; + + case IBEX_UART_FIFO_CTRL: + s->uart_fifo_ctrl =3D value; + + if (value & FIFO_CTRL_RXRST) { + qemu_log_mask(LOG_UNIMP, + "%s: RX fifos are not supported\n", __func__); + } + if (value & FIFO_CTRL_TXRST) { + s->tx_level =3D 0; + } + break; + case IBEX_UART_FIFO_STATUS: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: fifo_status is read only\n", __func__); + break; + + case IBEX_UART_OVRD: + s->uart_ovrd =3D value; + qemu_log_mask(LOG_UNIMP, + "%s: ovrd is not supported\n", __func__); + break; + case IBEX_UART_VAL: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: val is read only\n", __func__); + break; + case IBEX_UART_TIMEOUT_CTRL: + s->uart_timeout_ctrl =3D value; + qemu_log_mask(LOG_UNIMP, + "%s: timeout_ctrl is not supported\n", __func__); + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Bad offset 0x%"HWADDR_PRIx"\n", __func__, addr); + } +} + +static void fifo_trigger_update(void *opaque) +{ + IbexUartState *s =3D opaque; + + if (s->uart_ctrl & UART_CTRL_TX_ENABLE) { + ibex_uart_xmit(NULL, G_IO_OUT, s); + } +} + +static const MemoryRegionOps ibex_uart_ops =3D { + .read =3D ibex_uart_read, + .write =3D ibex_uart_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl.min_access_size =3D 4, + .impl.max_access_size =3D 4, +}; + +static int cadence_uart_post_load(void *opaque, int version_id) +{ + IbexUartState *s =3D opaque; + + ibex_uart_update_irqs(s); + return 0; +} + +static const VMStateDescription vmstate_ibex_uart =3D { + .name =3D TYPE_IBEX_UART, + .version_id =3D 1, + .minimum_version_id =3D 1, + .post_load =3D cadence_uart_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_UINT8_ARRAY(tx_fifo, IbexUartState, + IBEX_UART_TX_FIFO_SIZE), + VMSTATE_UINT32(tx_level, IbexUartState), + VMSTATE_UINT64(char_tx_time, IbexUartState), + VMSTATE_TIMER_PTR(fifo_trigger_handle, IbexUartState), + VMSTATE_UINT32(uart_intr_state, IbexUartState), + VMSTATE_UINT32(uart_intr_enable, IbexUartState), + VMSTATE_UINT32(uart_ctrl, IbexUartState), + VMSTATE_UINT32(uart_status, IbexUartState), + VMSTATE_UINT32(uart_rdata, IbexUartState), + VMSTATE_UINT32(uart_fifo_ctrl, IbexUartState), + VMSTATE_UINT32(uart_fifo_status, IbexUartState), + VMSTATE_UINT32(uart_ovrd, IbexUartState), + VMSTATE_UINT32(uart_val, IbexUartState), + VMSTATE_UINT32(uart_timeout_ctrl, IbexUartState), + VMSTATE_END_OF_LIST() + } +}; + +static Property ibex_uart_properties[] =3D { + DEFINE_PROP_CHR("chardev", IbexUartState, chr), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ibex_uart_init(Object *obj) +{ + IbexUartState *s =3D IBEX_UART(obj); + + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->tx_watermark); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->rx_watermark); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->tx_empty); + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->rx_overflow); + + memory_region_init_io(&s->mmio, obj, &ibex_uart_ops, s, + TYPE_IBEX_UART, 0x400); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void ibex_uart_realize(DeviceState *dev, Error **errp) +{ + IbexUartState *s =3D IBEX_UART(dev); + + s->fifo_trigger_handle =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + fifo_trigger_update, s); + + qemu_chr_fe_set_handlers(&s->chr, ibex_uart_can_receive, + ibex_uart_receive, NULL, NULL, + s, NULL, true); +} + +static void ibex_uart_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D ibex_uart_reset; + dc->realize =3D ibex_uart_realize; + dc->vmsd =3D &vmstate_ibex_uart; + device_class_set_props(dc, ibex_uart_properties); +} + +static const TypeInfo ibex_uart_info =3D { + .name =3D TYPE_IBEX_UART, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IbexUartState), + .instance_init =3D ibex_uart_init, + .class_init =3D ibex_uart_class_init, +}; + +static void ibex_uart_register_types(void) +{ + type_register_static(&ibex_uart_info); +} + +type_init(ibex_uart_register_types) diff --git a/MAINTAINERS b/MAINTAINERS index 3e7d9cb0a5..a1ce186a7e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1245,7 +1245,9 @@ M: Alistair Francis L: qemu-riscv@nongnu.org S: Supported F: hw/riscv/opentitan.c +F: hw/char/ibex_uart.c F: include/hw/riscv/opentitan.h +F: include/hw/char/ibex_uart.h =20 SH4 Machines ------------ diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs index 9e9a6c1aff..633996be5b 100644 --- a/hw/char/Makefile.objs +++ b/hw/char/Makefile.objs @@ -12,6 +12,7 @@ common-obj-$(CONFIG_VIRTIO_SERIAL) +=3D virtio-console.o common-obj-$(CONFIG_XILINX) +=3D xilinx_uartlite.o common-obj-$(CONFIG_XEN) +=3D xen_console.o common-obj-$(CONFIG_CADENCE) +=3D cadence_uart.o +common-obj-$(CONFIG_IBEX) +=3D ibex_uart.o =20 common-obj-$(CONFIG_EXYNOS4) +=3D exynos4210_uart.o common-obj-$(CONFIG_COLDFIRE) +=3D mcf_uart.o diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index 94d19571f7..28947ef3e0 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -4,6 +4,9 @@ config HTIF config HART bool =20 +config IBEX + bool + config SIFIVE bool select MSI_NONBROKEN @@ -29,6 +32,7 @@ config SPIKE =20 config OPENTITAN bool + select IBEX select HART select UNIMP =20 --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590705275; cv=none; d=zohomail.com; s=zohoarc; b=HWuMp3NA6FJLawe7gLXQKkViFEPiRzZiZWvUwZF8rBmY3ZaySe29jx23PB2pxPySxa5eJ0UedY81EaopDttHShFQmnfvGzLSBaietDxQUDlcAwiwn+ABj2w/zcEKKZ2MxCges3oCKfJl27n3+l/Kklcrv9eJtk/MqZk1ibc1dbA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590705275; h=Content-Type: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=15IiBBnW0Gj3pnk0QtQKOv7ruwsxG9XFajQDY+U9E4w=; b=YFc8EI9/H7lK3864j6O8WSKHdgn0AL+PXIHRKli8CzJMoprzORdXeahZnQ5lS2ZRGTpqjsfDn/G6fmsAUQDZ+D+rF31kd5QnL4jzi9E7hcQC46OlSPdOdpk3W+7AeZKg1q+YZsix3UgigGhP65r35Cq/CFXilPv/z6tuTi8uy8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590705275295236.39044834243475; Thu, 28 May 2020 15:34:35 -0700 (PDT) Received: from localhost ([::1]:44362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR6f-0002qe-D3 for importer@patchew.org; Thu, 28 May 2020 18:34:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvw-0003Mn-Gk; Thu, 28 May 2020 18:23:28 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:15473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvj-00064j-FA; Thu, 28 May 2020 18:23:28 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:23:05 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:20 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:23:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704595; x=1622240595; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Bvwri5Zp6ypKxEBHfELl3xgsE3Zz5p1AOKRot2+qvMI=; b=RHYsUqWCIbVyEP6DIJDC3ozQWbWD7KQxIXKsdQIwNbRPf/pROGqNuOv1 29+oRCWtPS6DpC0dio6NqGL9XOY76wEhVufC3kARrDM4v46O0EcQGLsCi y81D/n5EqtOOvSpCbOSsOV0v6bDeD+i5Wnq/IinJxVXyWgOYONPEAlpC0 arerxKOogJ3HyU6nzfcRX95NDrtK0KfDWVfxT4qS11U6+k8hXVIWlO+X+ Fg6V4pewiHFdLx+pZV/UXz7c/NlSR9j4OiAAImm4o5EdJy48kmCyuhLcJ VWkFD6w2HrEtkudgO4C0POvK3Q85Ew8zYlXyX+Tiom+fKHFysFO+kfPgb w==; IronPort-SDR: Wns6Oli53qmNWwVuqRUpUX8euEl9/OCmJ2i0gxm068qjHJsmXoVa4jQsCrWJbIY3GRFO4zb+UF b/ax/eq9rjbdGiXj49XzTRiT2GQrvM8oLdzQn5VsEL1fOnSPW4fh5j+vmLKlQPMFQFgsrKbRsi j0mXc+HB23SCXgCfpE37hAS9pj5QbFuTZPjdruMnn+95avrl19GbcZ/WMrQnhGxnKts+B6bak9 ajj4ymw65HurOvuLcHgk6LYWjIvccdNDqTRWizzWBdM6K7BSYZ1yw3FxpFTa7EU5hBodycsQeX LSY= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="143076000" IronPort-SDR: 364b1cxoxDmxO/qimifdG/XxMNpE6QBNQd3/Esj3wz8up8TmZ7zDQiNLtCqIq+wtv+j69gxWQJ ynIaOtqxn8OR5OzFFKfJIRwh4AMnHnM7M= IronPort-SDR: w1TmiYuA0XDny548qkIocyTfE9pgIByM/fsewdefvm+WJpjptldfjVOWVqH9ODhJ/CxV7uFG4Z /uwrZwGsFD/w== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 08/11] hw/intc: Initial commit of lowRISC Ibex PLIC Date: Thu, 28 May 2020 15:14:28 -0700 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=216.71.153.141; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa3.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:23:00 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The Ibex core contains a PLIC that although similar to the RISC-V spec is not RISC-V spec compliant. This patch implements a Ibex PLIC in a somewhat generic way. As the current RISC-V PLIC needs tidying up, my hope is that as the Ibex PLIC move towards spec compliance this PLIC implementation can be updated until it can replace the current PLIC. Signed-off-by: Alistair Francis Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/intc/ibex_plic.h | 63 +++++++++ hw/intc/ibex_plic.c | 261 ++++++++++++++++++++++++++++++++++++ MAINTAINERS | 2 + hw/intc/Makefile.objs | 1 + 4 files changed, 327 insertions(+) create mode 100644 include/hw/intc/ibex_plic.h create mode 100644 hw/intc/ibex_plic.c diff --git a/include/hw/intc/ibex_plic.h b/include/hw/intc/ibex_plic.h new file mode 100644 index 0000000000..ddc7909903 --- /dev/null +++ b/include/hw/intc/ibex_plic.h @@ -0,0 +1,63 @@ +/* + * QEMU RISC-V lowRISC Ibex PLIC + * + * 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_IBEX_PLIC_H +#define HW_IBEX_PLIC_H + +#include "hw/sysbus.h" + +#define TYPE_IBEX_PLIC "ibex-plic" +#define IBEX_PLIC(obj) \ + OBJECT_CHECK(IbexPlicState, (obj), TYPE_IBEX_PLIC) + +typedef struct IbexPlicState { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + MemoryRegion mmio; + + uint32_t *pending; + uint32_t *source; + uint32_t *priority; + uint32_t *enable; + uint32_t threshold; + uint32_t claim; + + /* config */ + uint32_t num_cpus; + uint32_t num_sources; + + uint32_t pending_base; + uint32_t pending_num; + + uint32_t source_base; + uint32_t source_num; + + uint32_t priority_base; + uint32_t priority_num; + + uint32_t enable_base; + uint32_t enable_num; + + uint32_t threshold_base; + + uint32_t claim_base; +} IbexPlicState; + +#endif /* HW_IBEX_PLIC_H */ diff --git a/hw/intc/ibex_plic.c b/hw/intc/ibex_plic.c new file mode 100644 index 0000000000..41079518c6 --- /dev/null +++ b/hw/intc/ibex_plic.c @@ -0,0 +1,261 @@ +/* + * QEMU RISC-V lowRISC Ibex PLIC + * + * Copyright (c) 2020 Western Digital + * + * Documentation avaliable: https://docs.opentitan.org/hw/ip/rv_plic/doc/ + * + * 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 "qemu/log.h" +#include "hw/qdev-properties.h" +#include "hw/core/cpu.h" +#include "hw/boards.h" +#include "hw/pci/msi.h" +#include "target/riscv/cpu_bits.h" +#include "target/riscv/cpu.h" +#include "hw/intc/ibex_plic.h" + +static bool addr_between(uint32_t addr, uint32_t base, uint32_t num) +{ + uint32_t end =3D base + (num * 0x04); + + if (addr >=3D base && addr < end) { + return true; + } + + return false; +} + +static void ibex_plic_irqs_set_pending(IbexPlicState *s, int irq, bool lev= el) +{ + int pending_num =3D irq / 32; + + s->pending[pending_num] |=3D level << (irq % 32); +} + +static bool ibex_plic_irqs_pending(IbexPlicState *s, uint32_t context) +{ + int i; + + for (i =3D 0; i < s->pending_num; i++) { + uint32_t irq_num =3D ctz64(s->pending[i]) + (i * 32); + + if (!(s->pending[i] & s->enable[i])) { + /* No pending and enabled IRQ */ + continue; + } + + if (s->priority[irq_num] > s->threshold) { + if (!s->claim) { + s->claim =3D irq_num; + } + return true; + } + } + + return false; +} + +static void ibex_plic_update(IbexPlicState *s) +{ + CPUState *cpu; + int level, i; + + for (i =3D 0; i < s->num_cpus; i++) { + cpu =3D qemu_get_cpu(i); + + if (!cpu) { + continue; + } + + level =3D ibex_plic_irqs_pending(s, 0); + + riscv_cpu_update_mip(RISCV_CPU(cpu), MIP_MEIP, BOOL_TO_MASK(level)= ); + } +} + +static void ibex_plic_reset(DeviceState *dev) +{ + IbexPlicState *s =3D IBEX_PLIC(dev); + + s->threshold =3D 0x00000000; + s->claim =3D 0x00000000; +} + +static uint64_t ibex_plic_read(void *opaque, hwaddr addr, + unsigned int size) +{ + IbexPlicState *s =3D opaque; + int offset; + uint32_t ret =3D 0; + + if (addr_between(addr, s->pending_base, s->pending_num)) { + offset =3D (addr - s->pending_base) / 4; + ret =3D s->pending[offset]; + } else if (addr_between(addr, s->source_base, s->source_num)) { + qemu_log_mask(LOG_UNIMP, + "%s: Interrupt source mode not supported\n", __func_= _); + } else if (addr_between(addr, s->priority_base, s->priority_num)) { + offset =3D (addr - s->priority_base) / 4; + ret =3D s->priority[offset]; + } else if (addr_between(addr, s->enable_base, s->enable_num)) { + offset =3D (addr - s->enable_base) / 4; + ret =3D s->enable[offset]; + } else if (addr_between(addr, s->threshold_base, 1)) { + ret =3D s->threshold; + } else if (addr_between(addr, s->claim_base, 1)) { + int pending_num =3D s->claim / 32; + s->pending[pending_num] &=3D ~(1 << (s->claim % 32)); + + ret =3D s->claim; + } + + return ret; +} + +static void ibex_plic_write(void *opaque, hwaddr addr, + uint64_t value, unsigned int size) +{ + IbexPlicState *s =3D opaque; + + if (addr_between(addr, s->pending_base, s->pending_num)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Pending registers are read only\n", __func__); + } else if (addr_between(addr, s->source_base, s->source_num)) { + qemu_log_mask(LOG_UNIMP, + "%s: Interrupt source mode not supported\n", __func_= _); + } else if (addr_between(addr, s->priority_base, s->priority_num)) { + uint32_t irq =3D ((addr - s->priority_base) >> 2) + 1; + s->priority[irq] =3D value & 7; + } else if (addr_between(addr, s->enable_base, s->enable_num)) { + uint32_t enable_reg =3D (addr - s->enable_base) / 4; + + s->enable[enable_reg] =3D value; + } else if (addr_between(addr, s->threshold_base, 1)) { + s->threshold =3D value & 3; + } else if (addr_between(addr, s->claim_base, 1)) { + if (s->claim =3D=3D value) { + /* Interrupt was completed */ + s->claim =3D 0; + } + } + + ibex_plic_update(s); +} + +static const MemoryRegionOps ibex_plic_ops =3D { + .read =3D ibex_plic_read, + .write =3D ibex_plic_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4 + } +}; + +static void ibex_plic_irq_request(void *opaque, int irq, int level) +{ + IbexPlicState *s =3D opaque; + + ibex_plic_irqs_set_pending(s, irq, level > 0); + ibex_plic_update(s); +} + +static Property ibex_plic_properties[] =3D { + DEFINE_PROP_UINT32("num-cpus", IbexPlicState, num_cpus, 1), + DEFINE_PROP_UINT32("num-sources", IbexPlicState, num_sources, 80), + + DEFINE_PROP_UINT32("pending-base", IbexPlicState, pending_base, 0), + DEFINE_PROP_UINT32("pending-num", IbexPlicState, pending_num, 3), + + DEFINE_PROP_UINT32("source-base", IbexPlicState, source_base, 0x0c), + DEFINE_PROP_UINT32("source-num", IbexPlicState, source_num, 3), + + DEFINE_PROP_UINT32("priority-base", IbexPlicState, priority_base, 0x18= ), + DEFINE_PROP_UINT32("priority-num", IbexPlicState, priority_num, 80), + + DEFINE_PROP_UINT32("enable-base", IbexPlicState, enable_base, 0x200), + DEFINE_PROP_UINT32("enable-num", IbexPlicState, enable_num, 3), + + DEFINE_PROP_UINT32("threshold-base", IbexPlicState, threshold_base, 0x= 20c), + + DEFINE_PROP_UINT32("claim-base", IbexPlicState, claim_base, 0x210), + DEFINE_PROP_END_OF_LIST(), +}; + +static void ibex_plic_init(Object *obj) +{ + IbexPlicState *s =3D IBEX_PLIC(obj); + + memory_region_init_io(&s->mmio, obj, &ibex_plic_ops, s, + TYPE_IBEX_PLIC, 0x400); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); +} + +static void ibex_plic_realize(DeviceState *dev, Error **errp) +{ + IbexPlicState *s =3D IBEX_PLIC(dev); + int i; + + s->pending =3D g_new0(uint32_t, s->pending_num); + s->source =3D g_new0(uint32_t, s->source_num); + s->priority =3D g_new0(uint32_t, s->priority_num); + s->enable =3D g_new0(uint32_t, s->enable_num); + + qdev_init_gpio_in(dev, ibex_plic_irq_request, s->num_sources); + + /* + * We can't allow the supervisor to control SEIP as this would allow t= he + * supervisor to clear a pending external interrupt which will result = in + * a lost interrupt in the case a PLIC is attached. The SEIP bit must = be + * hardware controlled when a PLIC is attached. + */ + MachineState *ms =3D MACHINE(qdev_get_machine()); + unsigned int smp_cpus =3D ms->smp.cpus; + for (i =3D 0; i < smp_cpus; i++) { + RISCVCPU *cpu =3D RISCV_CPU(qemu_get_cpu(i)); + if (riscv_cpu_claim_interrupts(cpu, MIP_SEIP) < 0) { + error_report("SEIP already claimed"); + exit(1); + } + } + + msi_nonbroken =3D true; +} + +static void ibex_plic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D ibex_plic_reset; + device_class_set_props(dc, ibex_plic_properties); + dc->realize =3D ibex_plic_realize; +} + +static const TypeInfo ibex_plic_info =3D { + .name =3D TYPE_IBEX_PLIC, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IbexPlicState), + .instance_init =3D ibex_plic_init, + .class_init =3D ibex_plic_class_init, +}; + +static void ibex_plic_register_types(void) +{ + type_register_static(&ibex_plic_info); +} + +type_init(ibex_plic_register_types) diff --git a/MAINTAINERS b/MAINTAINERS index a1ce186a7e..d6b2819e44 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1246,8 +1246,10 @@ L: qemu-riscv@nongnu.org S: Supported F: hw/riscv/opentitan.c F: hw/char/ibex_uart.c +F: hw/intc/ibex_plic.c F: include/hw/riscv/opentitan.h F: include/hw/char/ibex_uart.h +F: include/hw/intc/ibex_plic.h =20 SH4 Machines ------------ diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs index f726d87532..a61e6728fe 100644 --- a/hw/intc/Makefile.objs +++ b/hw/intc/Makefile.objs @@ -49,3 +49,4 @@ obj-$(CONFIG_ARM_GIC) +=3D arm_gicv3_cpuif.o obj-$(CONFIG_MIPS_CPS) +=3D mips_gic.o obj-$(CONFIG_NIOS2) +=3D nios2_iic.o obj-$(CONFIG_OMPIC) +=3D ompic.o +obj-$(CONFIG_IBEX) +=3D ibex_plic.o --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590705310; cv=none; d=zohomail.com; s=zohoarc; b=cjbXW0WS4F1Xz+LT6zPVc/vrGfyVoqDiDRa2cHWzqRClU6enj8d2XRJjN5JvQ8nxyjgAz1y0PpKGLopjmB3oe6rMSS3bW8llPJfZGKWzs8hXxDPS/l5g04SAMpjesNFHvbXu7F90Vg08QNXA7ZI7ejRsg6hoskEaWM4KUldhTGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590705310; h=Content-Type: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=/Zs6QCw9hka2CQ5zfExC4TyeGv7uEmI1jJZDvp3KiDw=; b=nMktQE+rk1jYRd5arBWrV87cv0wXZ2ZaON3xx7YAjFBt+4kKk1Lv8kFM/OweLqqPgLFbQf6X8IDGPLh5ZG3l3yvu5ku04Sq21kxe4ngfj50a+cqIWiRBhBEelqvNL00VDBZwJmZLbbnHXjzM1/rMNBva+H69Kz5BRv/hMHZ99A0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590705310448330.99032973726196; Thu, 28 May 2020 15:35:10 -0700 (PDT) Received: from localhost ([::1]:46424 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR7F-0003iX-7X for importer@patchew.org; Thu, 28 May 2020 18:35:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvx-0003PK-Bb; Thu, 28 May 2020 18:23:29 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:15467) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvw-0005wh-2B; Thu, 28 May 2020 18:23:28 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:23:08 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:22 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:23:07 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704608; x=1622240608; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Yze3hqguLA+ZPW/079pxXd43GbTnC7jJ94uG3nnkdwo=; b=gOUJsLmZ//afauicJU9T/Fj+zWrUXxTwwk+GYD5M8z4yrftVwutQL8p0 e/Fx4MAOSTBJRhUbvUEgDLEl54fiZbJkUDGfPZbyPLSY858FNIhGdi3Mq ohN2/I5YmF/eWUMMvXSO3m09mmuZS5wesGDm2lvIu+IsGjRxTz/3ETtll x9p3+pxhEpHnxdjo/y644Iwr/nHbyivWuf25gCDDyIYQjtfARzSe1sNgH 1ltvTVzyux2YGLzz9VzYub0bbnECz8UdTwfYbww87D/f9t2Ovo+KxyNxc tUuxdfI1g6rL+NRfeQRlrem4eMXgoVvWwNX+7RrHhFKfJZzvVofQPyCCT A==; IronPort-SDR: kS2OuoX8KBd1U+WpAEv2t3lITF4uZcwphZGRNq2Nd2hRTwNd1hyEtdr71XpBxMs2a+baStkQWO 9HhENxMt9+oWT8pqW6H3PdGKHMiTC0b9O3y5FPEuuOUilzRuN73WWAq+VXm+uQUtIk2IudFP5W 1J/qh+gUl24udA81cZIQz99uC5PS+6xjZD2W9VUu9xGR6J/f38Np7e/NHZmbXxv3PrZO2xcURS jNkTxjhq6TK5ABHEqzIqQ6NhhvzTtrIE9vpPmsfc6TooT7ZLjopLTG85aNEebfzZGZ1A4aXr0Y bxo= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="143076003" IronPort-SDR: fYG4cr/87UO2YhVTL+9Rdhxs2uyqNkkA5oanPaGnl9SMbfltTGM4HwD4QaKsxBGsoCAplHBGXO hxrDNOOSFPqhQMqfGq996bW9lzPmFDas4= IronPort-SDR: paoOaApGnr9Ga9GNrBqYUPkhRlrzVX43pz2h+Yr4M6dqmILWzxFJ5AoABDOQ0fzxYKb928QAOE hcSvh6ADqRug== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 09/11] riscv/opentitan: Connect the PLIC device Date: Thu, 28 May 2020 15:14:31 -0700 Message-Id: <377c075d02a082b6ea5c8cb853118671ac7ede1e.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=216.71.153.141; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa3.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:23:00 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/riscv/opentitan.h | 3 +++ hw/riscv/opentitan.c | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h index a4b6499444..76f72905a8 100644 --- a/include/hw/riscv/opentitan.h +++ b/include/hw/riscv/opentitan.h @@ -20,6 +20,7 @@ #define HW_OPENTITAN_H =20 #include "hw/riscv/riscv_hart.h" +#include "hw/intc/ibex_plic.h" =20 #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc" #define RISCV_IBEX_SOC(obj) \ @@ -31,6 +32,8 @@ typedef struct LowRISCIbexSoCState { =20 /*< public >*/ RISCVHartArrayState cpus; + IbexPlicState plic; + MemoryRegion flash_mem; MemoryRegion rom; } LowRISCIbexSoCState; diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index b4fb836466..46a3a93c5e 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -25,6 +25,7 @@ #include "hw/misc/unimp.h" #include "hw/riscv/boot.h" #include "exec/address-spaces.h" +#include "sysemu/sysemu.h" =20 static const struct MemmapEntry { hwaddr base; @@ -97,6 +98,9 @@ static void riscv_lowrisc_ibex_soc_init(Object *obj) object_initialize_child(obj, "cpus", &s->cpus, sizeof(s->cpus), TYPE_RISCV_HART_ARRAY, &error_abort, NULL); + + sysbus_init_child_obj(obj, "plic", &s->plic, + sizeof(s->plic), TYPE_IBEX_PLIC); } =20 static void riscv_lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **e= rrp) @@ -105,6 +109,9 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState = *dev_soc, Error **errp) MachineState *ms =3D MACHINE(qdev_get_machine()); LowRISCIbexSoCState *s =3D RISCV_IBEX_SOC(dev_soc); MemoryRegion *sys_mem =3D get_system_memory(); + DeviceState *dev; + SysBusDevice *busdev; + Error *err =3D NULL; =20 object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type", &error_abort); @@ -125,6 +132,16 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState= *dev_soc, Error **errp) memory_region_add_subregion(sys_mem, memmap[IBEX_FLASH].base, &s->flash_mem); =20 + /* PLIC */ + dev =3D DEVICE(&s->plic); + object_property_set_bool(OBJECT(&s->plic), true, "realized", &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + busdev =3D SYS_BUS_DEVICE(dev); + sysbus_mmio_map(busdev, 0, memmap[IBEX_PLIC].base); + create_unimplemented_device("riscv.lowrisc.ibex.uart", memmap[IBEX_UART].base, memmap[IBEX_UART].size); create_unimplemented_device("riscv.lowrisc.ibex.gpio", @@ -145,8 +162,6 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState = *dev_soc, Error **errp) 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", --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590705129; cv=none; d=zohomail.com; s=zohoarc; b=UbEayWC9b4mIekjqJ3kdUySocQzjoXhFK9AzQCXp81732bBI+AZKWuVDElVzEo5uuacD5JVmx7in1eLZ/ySdM1lv93bC3SAHN5mulCXEXLSLnZFpTSyYMgkylfm+xpi8UOFLX2HW9JWbHHt3m8uQTPNPZemfwFw8e/BImyd3bzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590705129; h=Content-Type: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=Ik2zEH7+F4jWTSMaMxbEX2HBwlpg9kp86Tbl/fN3eYg=; b=QabLXfVL7qoTIZve/UAJAlOFGvnuRB4lR9QtO3FMDcPhZ2FmfhfPO1nh1ZY0FMM9Yyvq0rnWc3UWsHeARPtpiqLd1QFC4hAHcfDzUyLTQmO9wMGmBrCgd+L4wy5yrsUaGa2n9WmQdjOSFjvYAeCKH2HrUzRH0ZpZgStBOx8O49E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590705129722557.3015020232012; Thu, 28 May 2020 15:32:09 -0700 (PDT) Received: from localhost ([::1]:35814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR4K-0006xy-7e for importer@patchew.org; Thu, 28 May 2020 18:32:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvy-0003TS-Mw; Thu, 28 May 2020 18:23:30 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:15473) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvx-00064j-6Y; Thu, 28 May 2020 18:23:30 -0400 Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:23:10 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:12:25 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip01.wdc.com with ESMTP; 28 May 2020 15:23:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704609; x=1622240609; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9/aKzwRUwMelxdl0MSf660AguaNfWJ19QIoTXawk/pg=; b=YQE+pMuC9fj38qr+4gknPYv3oUF9ZRYzX2IDmwHob4nUm35Dcq1ML/1m UWI1kTYTn6UPoK6LNxPd5PEoI6N/JgeaWxERz71ckZUZawvQTfu3cptaA Uceos9SleZsIAr6PQD8yGYWAmrFWsWSbmpmubKmxqae8TgSaeQnfm1mKy V3blZZdwQUC+a6z0bkNhinDiRl8W7YIOfJQ/PZ0eg218CXVfqCyHVtKAR q4v6hH+8ZPouXZ6NKPcys/JWSqWl+Hb0vv4dgJKUkl5nTCyYBypSNxdY4 YSTzJE60iMxCme8kkjxSl6JvL9VB+Y9xdurFUwSIOHxk/VKsCCAzq37GO Q==; IronPort-SDR: 3a3iSXxj0DOTwzIYPQEIIbSFKybgLG8iZIzoYqpWU+1cbIfLaVPtY6T043fHEpQrBwdTKoSx4B yj/+B2XanvQ3BY7PfYKN9TwjhvZqWpD8PgwlseSKfS5/NHddI2jxtZmHtPN2RwfhzGruAaviMH 3Ovx/CLl393Y9PZK2OhFIzeZhnnZVt3S25uLZqIYbez/Ao2f23DDjyiAq99/k+EX6+5lvmY6iM Frn4qD3JdnOof4tarots/w4eqqgUX++w/0JmWSNJjXLet25EnBFdtkYGNM29JCD/rdtJFTaJpy /CM= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="143076008" IronPort-SDR: lRNrPPgnzo7mnxvMceSZmexPxOgI9QW0aBOYQ+4zX9W1JEf4L+4PjsTZSplHp+kcOaRwfgLtLo VEn1qA5v0hZpAECIrbWVGajd/yROPTbDs= IronPort-SDR: SYH6gAcPbZrIHSKVGl/IeqPD1G3wPEUYr3NUKthp4N8QFTKaQGL2jkwrcO+PPNqshAC4KYFhXE Uux3mGV45fVA== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 10/11] riscv/opentitan: Connect the UART device Date: Thu, 28 May 2020 15:14:34 -0700 Message-Id: <5e3af7bd29be725113bf7f55d5026ff446673e05.1590704015.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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: pass client-ip=216.71.153.141; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa3.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:23:00 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: Alistair Francis Reviewed-by: Bin Meng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/riscv/opentitan.h | 13 +++++++++++++ hw/riscv/opentitan.c | 24 ++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/hw/riscv/opentitan.h b/include/hw/riscv/opentitan.h index 76f72905a8..8f29b9cbbf 100644 --- a/include/hw/riscv/opentitan.h +++ b/include/hw/riscv/opentitan.h @@ -21,6 +21,7 @@ =20 #include "hw/riscv/riscv_hart.h" #include "hw/intc/ibex_plic.h" +#include "hw/char/ibex_uart.h" =20 #define TYPE_RISCV_IBEX_SOC "riscv.lowrisc.ibex.soc" #define RISCV_IBEX_SOC(obj) \ @@ -33,6 +34,7 @@ typedef struct LowRISCIbexSoCState { /*< public >*/ RISCVHartArrayState cpus; IbexPlicState plic; + IbexUartState uart; =20 MemoryRegion flash_mem; MemoryRegion rom; @@ -68,4 +70,15 @@ enum { IBEX_PADCTRL, }; =20 +enum { + IBEX_UART_RX_PARITY_ERR_IRQ =3D 0x28, + IBEX_UART_RX_TIMEOUT_IRQ =3D 0x27, + IBEX_UART_RX_BREAK_ERR_IRQ =3D 0x26, + IBEX_UART_RX_FRAME_ERR_IRQ =3D 0x25, + IBEX_UART_RX_OVERFLOW_IRQ =3D 0x24, + IBEX_UART_TX_EMPTY_IRQ =3D 0x23, + IBEX_UART_RX_WATERMARK_IRQ =3D 0x22, + IBEX_UART_TX_WATERMARK_IRQ =3D 0x21, +}; + #endif diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c index 46a3a93c5e..a8844a870b 100644 --- a/hw/riscv/opentitan.c +++ b/hw/riscv/opentitan.c @@ -101,6 +101,9 @@ static void riscv_lowrisc_ibex_soc_init(Object *obj) =20 sysbus_init_child_obj(obj, "plic", &s->plic, sizeof(s->plic), TYPE_IBEX_PLIC); + + sysbus_init_child_obj(obj, "uart", &s->uart, + sizeof(s->uart), TYPE_IBEX_UART); } =20 static void riscv_lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **e= rrp) @@ -142,8 +145,25 @@ static void riscv_lowrisc_ibex_soc_realize(DeviceState= *dev_soc, Error **errp) busdev =3D SYS_BUS_DEVICE(dev); sysbus_mmio_map(busdev, 0, memmap[IBEX_PLIC].base); =20 - create_unimplemented_device("riscv.lowrisc.ibex.uart", - memmap[IBEX_UART].base, memmap[IBEX_UART].size); + /* UART */ + dev =3D DEVICE(&(s->uart)); + qdev_prop_set_chr(dev, "chardev", serial_hd(0)); + object_property_set_bool(OBJECT(&s->uart), true, "realized", &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + busdev =3D SYS_BUS_DEVICE(dev); + sysbus_mmio_map(busdev, 0, memmap[IBEX_UART].base); + sysbus_connect_irq(busdev, 0, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_TX_WATERMARK_IRQ)); + sysbus_connect_irq(busdev, 1, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_RX_WATERMARK_IRQ)); + sysbus_connect_irq(busdev, 2, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_TX_EMPTY_IRQ)); + sysbus_connect_irq(busdev, 3, qdev_get_gpio_in(DEVICE(&s->plic), + IBEX_UART_RX_OVERFLOW_IRQ)); + create_unimplemented_device("riscv.lowrisc.ibex.gpio", memmap[IBEX_GPIO].base, memmap[IBEX_GPIO].size); create_unimplemented_device("riscv.lowrisc.ibex.spi", --=20 2.26.2 From nobody Fri May 17 00:07:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1590704977; cv=none; d=zohomail.com; s=zohoarc; b=myQMrJu/F7wGsdaXPGZbcQoA6cY6YQq46rmeSuqh5Qe1czvMOWMz4lN2gmQGCb+KURr1ICoHnjnxxb/wQLyTFYv+yCfIUFpOpAY8bTLCY8L/dKRBCVIaMufADC9HFMOFkXSl5JYhbckyBMtcuHoQfCTFpvcM//KfZ9XABOwSFUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590704977; 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=rhWBHK5003Udi37cw2EI+fP2MKeIgFWQr9pnE8gh7sc=; b=aRafp1Bo1Zp+geODQmRTwKmRuK1NQBl7c5mUI55l6Cox1OH2uin56OamARf9g7g9hX+jKC8zU9TCQ7rvfDT7hWxu/Su/wMbXEscjBrf4e7sp9Yi0n1okKliLyjhhIRe+FP+ujlOl6jORGm2+RFduqh3GPyNet4GYGmJno0wfG4I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.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; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590704977750553.0896411796351; Thu, 28 May 2020 15:29:37 -0700 (PDT) Received: from localhost ([::1]:57962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeR1s-00041Z-GJ for importer@patchew.org; Thu, 28 May 2020 18:29:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvw-0003Lf-1o; Thu, 28 May 2020 18:23:28 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:48497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeQvu-0006IY-0T; Thu, 28 May 2020 18:23:27 -0400 Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 29 May 2020 06:23:14 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2020 15:13:01 -0700 Received: from 6xf7cg2.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.57.123]) by uls-op-cesaip02.wdc.com with ESMTP; 28 May 2020 15:23:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590704607; x=1622240607; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6FATJBjY3MEsYgFLnJ2w8QG6m7aF0O7YWGLLllI2F4A=; b=r4ss8FpTt6yUzS0zNHcA++vE+hwkIcCjijeA7ea1JYrgeKNQ8+xgIA9L POMoH5FYnLhgQraKXo0IC+T37YnsYs66Mx9wi/QlMUZ16UfiFNgF/IqeW A7H9JD0ov5x0aaSVfTLk/7zuCGTyxtIbauYK3Vf7gpoQQ6euLOZ0678MB ZS6owT0ioHPFdkRYexIHUvZM1BV3qDKkQhxkJvX1l08WIsb5mmjMzL0Wn NcTq/g6wm6Mv5d3FZscO/jwITO4IqEo+EJPbZ2Zaj5PoIh4c0GIdO0jZT XkTW98lI6D5qexkQDuFfDQhaL46Bu621TdECy719iRuLpIqK3VYG+SW1t w==; IronPort-SDR: UwUDBSvsJQOg29TQbKbLDS1ZR9QiKnnDrQ22p5isPT+Uwq5iFl3xPsPYg9VCKIbgBmXVzdmk1c iiq0pbgS+KnrnWywZDoNonMiCv8d6stTmT0cZPeI8SEAFCXJ1DdBx4CGXAPuGnhOpRYMauW3Bw hzIiehEfNJ4eohgx8LyLgnsCS1lxGqx4CPF9nPutgQTj1nlOvFP6y6SwKeiHJIsjOKNz2urNUw 6RqpWG5TLGIQywBVCQbPKIwG9P5vqmpm+PDpiQGLfCNamkFWXlnrPdttCeaW41OjF+bsTbyc3t tp4= X-IronPort-AV: E=Sophos;i="5.73,446,1583164800"; d="scan'208";a="139073358" IronPort-SDR: KCiwM/VVW3mn7KHWN1Kovjl7nD7pkkW4WAre/CgP6mZX/mX00ywaJdvGdB63R87HkUi2msZyll yLCMn4q53T1jZIb72Ff5TBl/FbevT0Oj0= IronPort-SDR: 0d0iMb9OJowJMvUW7MJ8E/BmF6O6JUPE4NYem3LcCqm6BG5STgBzWMTy5QUPfbF2a3PPPXgoRF M9g/pH5L0Arg== WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v5 11/11] target/riscv: Use a smaller guess size for no-MMU PMP Date: Thu, 28 May 2020 15:14:36 -0700 Message-Id: X-Mailer: git-send-email 2.26.2 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: pass client-ip=216.71.153.144; envelope-from=prvs=4104b2603=alistair.francis@wdc.com; helo=esa5.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/28 18:22:43 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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, bmeng.cn@gmail.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Alistair Francis Reviewed-by: Bin Meng --- target/riscv/pmp.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c index 0e6b640fbd..9418660f1b 100644 --- a/target/riscv/pmp.c +++ b/target/riscv/pmp.c @@ -233,12 +233,16 @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ul= ong addr, return true; } =20 - /* - * if size is unknown (0), assume that all bytes - * from addr to the end of the page will be accessed. - */ if (size =3D=3D 0) { - pmp_size =3D -(addr | TARGET_PAGE_MASK); + if (riscv_feature(env, RISCV_FEATURE_MMU)) { + /* + * If size is unknown (0), assume that all bytes + * from addr to the end of the page will be accessed. + */ + pmp_size =3D -(addr | TARGET_PAGE_MASK); + } else { + pmp_size =3D sizeof(target_ulong); + } } else { pmp_size =3D size; } --=20 2.26.2