From nobody Mon Feb 9 20:36:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.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=1566604561; cv=none; d=zoho.com; s=zohoarc; b=Ut0twibJr/CRxp9j0mLd7Zz5VBxc2wo/RMZKkTnlUKfmG1bbAEVhWKvoLwXLX8TUMH9vJ5YpU6W2X4T344SoHUNscXDTYm7mHL54+sjoDpT1tiUM/94YjQH9RyuPfUpPDvFZyxtTsbzNlHnSSID9ZVVXxqj4MySQd2HwfInuEPc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566604561; 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:ARC-Authentication-Results; bh=K0OoahaaxOkpT8aDXFgkR1AwUCokBAbgm2JLc6dxcFY=; b=GtAs99k2Ynt4EZkhN1XmSdVYeEVs3UgVOeEVo7hGbG4GJNU7VxWhVm10BjtAqZUDIu/JiiKTYcpP7wcTdPS2P6daQlthPy/fFXHFwiiMF6sZ9xIon5K3YozEHVVgWTVY0i2Jeaevp00iG2Ah3bNrGls9/GXPFM96Dtc+vNxggyc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail header.i=@wdc.com; spf=pass (zoho.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 1566604561095332.39234344696024; Fri, 23 Aug 2019 16:56:01 -0700 (PDT) Received: from localhost ([::1]:35116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1JPT-00068J-IW for importer@patchew.org; Fri, 23 Aug 2019 19:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1JBp-0000fQ-Ff for qemu-devel@nongnu.org; Fri, 23 Aug 2019 19:41:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1JBo-000068-0r for qemu-devel@nongnu.org; Fri, 23 Aug 2019 19:41:53 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:50262) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1JBn-0008WT-Nw; Fri, 23 Aug 2019 19:41:51 -0400 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Aug 2019 07:42:22 +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; 23 Aug 2019 16:39:08 -0700 Received: from risc6-mainframe.sdcorp.global.sandisk.com (HELO risc6-mainframe.int.fusionio.com) ([10.196.157.58]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Aug 2019 16:41: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=1566603743; x=1598139743; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hGnS7Aac7mIfYIQO11OO+v94Mp+zZko9Z6e39Hi5wek=; b=mwikRrTMqAWcj5jmaWADhVHrS0YngTJH2aXBHPIC2CVFnwwdXwRyNsuo bBx8DZxH0ytc+ljiecRIDpKoukMbkbE+pL+fccjpSu6TuEAZSYoPg5AJW IhtmZIwkhbueFnLgf+M7bLOtM6pYdimKV3Evf3YpqB7qvr04MT/N2cpPj Q1NXSw01uw+EFUI4ge3nt/YZbeYVFxCb9AEN7f5MGf4qwZC+JBmWKIeRl eJwOJW89eXFAweWLXjW4SXeJ4/OeDNJadBT97HLQcsMwLvRe5OW42cSgC PuX45nYu7wteR8GU0pzyWr94Z3Xgh3hryZGXHTETKKJYawLDvMkrsWwNU A==; IronPort-SDR: YaMDbXY1MHtkeVsWuw4aNn2fvfVA1R/oyClGzrviWmVWvVC4tIPXhJ9Kiajn+e2fEleK5M3byR N0D+zk4lT6DiDc7miYEQyR+OCQFhRWD1Qk8oc95FJ7zijsFarLgZWZ+RjklL52kAyBXvxcaS0i Iit44O3t+XeLsQiUdZFs2gszz/KIZvavAdIRbMIk/Fyy465/mwoFjpSDkzL36XgZKtdKtdljgU fsQWR+JfakJkNVexSlHpGhrJG5B3eZBxe09VmG2xdYCsD6yD6Hyl8j7wvVTU8agMLI8+XJi0Kh Joo= X-IronPort-AV: E=Sophos;i="5.64,422,1559491200"; d="scan'208";a="217013891" IronPort-SDR: CNQAjvX/EBVSp7oeHeYQFxUhQsb7llhWnp6UZl98zXT1uHRe/hpwPYJ7bX/ilMU7b9XfhxWc+O dDPxJE63uiMKphxbpTTYQFkhFmGRIxf6gmLum+avNO/2+f9ml1OtfaY2YAbbKtFoL2LbPedffG 1G+l5kVF3NxV7wKuFNVnIBdryjFg9yjUxhpi/2J98ScX3km+qI87nWvkNcTsCMfrNqw7lOJnHi dN7LrfjAUXmFSS3ne/d+Bcjx7us3WfwNKgHh3DsY0zqDgafpv94Jz6LhVOJCMc7M/prYyEZOwb 1H1sqbzQY6zRdcmrc3YipsUc IronPort-SDR: uLWoPAf1/41IXYpYl69tfesewC8EjZiuBN1/Qvc4FSsimgYggLB4+7xcCVHjONm6ytkGyZK/gx 0mlpD6msFHfI+Ct3+Arun+qEIz+HYPGOD0vUajR5GPz9iCK9GKQzCaAGGcAD1vfRFBMQZduAsF NMXJElYFVBZu2Roq3Fn0snjDbDiShCHnk3R3diFv1be27YszfDUCAZGflAmMqTrn/VFmNUWc+9 NfwXcRNpKuqqPyZmzPtJRc+LWZyHBxsELb78MvnIxafAt2QJuaIx2g1ur28f9rKpzi7//qt1Ye Wnk= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Date: Fri, 23 Aug 2019 16:38:10 -0700 Message-Id: X-Mailer: git-send-email 2.22.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x X-Received-From: 68.232.143.124 Subject: [Qemu-devel] [PATCH v1 08/28] target/riscv: Add Hypervisor CSR access functions 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: alistair23@gmail.com, Anup.Patel@wdc.com, palmer@sifive.com, alistair.francis@wdc.com, Atish.Patra@wdc.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: Palmer Dabbelt --- target/riscv/csr.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 471f23a1d0..388775d45a 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -98,6 +98,20 @@ static int smode(CPURISCVState *env, int csrno) return -!riscv_has_ext(env, RVS); } =20 +static int hmode(CPURISCVState *env, int csrno) +{ + if (riscv_has_ext(env, RVS) && + riscv_has_ext(env, RVH)) { + /* Hypervisor extension is supported */ + if ((env->priv =3D=3D PRV_S && !riscv_cpu_virt_enabled(env)) || + env->priv =3D=3D PRV_M) { + return 0; + } + } + + return -1; +} + static int pmp(CPURISCVState *env, int csrno) { return -!riscv_feature(env, RISCV_FEATURE_PMP); @@ -754,6 +768,55 @@ static int write_satp(CPURISCVState *env, int csrno, t= arget_ulong val) return 0; } =20 +/* Hypervisor Extensions */ +static int read_hstatus(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->hstatus; + return 0; +} + +static int write_hstatus(CPURISCVState *env, int csrno, target_ulong val) +{ + env->hstatus =3D val; + return 0; +} + +static int read_hedeleg(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->hedeleg; + return 0; +} + +static int write_hedeleg(CPURISCVState *env, int csrno, target_ulong val) +{ + env->hedeleg =3D val; + return 0; +} + +static int read_hideleg(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->hideleg; + return 0; +} + +static int write_hideleg(CPURISCVState *env, int csrno, target_ulong val) +{ + env->hideleg =3D val; + return 0; +} + +static int read_hgatp(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->hgatp; + return 0; +} + +static int write_hgatp(CPURISCVState *env, int csrno, target_ulong val) +{ + env->hgatp =3D val; + return 0; +} + /* Physical Memory Protection */ static int read_pmpcfg(CPURISCVState *env, int csrno, target_ulong *val) { @@ -950,6 +1013,11 @@ static riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = =3D { /* Supervisor Protection and Translation */ [CSR_SATP] =3D { smode, read_satp, write_satp = }, =20 + [CSR_HSTATUS] =3D { hmode, read_hstatus, write_hstat= us }, + [CSR_HEDELEG] =3D { hmode, read_hedeleg, write_hedel= eg }, + [CSR_HIDELEG] =3D { hmode, read_hideleg, write_hidel= eg }, + [CSR_HGATP] =3D { hmode, read_hgatp, write_hgatp= }, + /* Physical Memory Protection */ [CSR_PMPCFG0 ... CSR_PMPADDR9] =3D { pmp, read_pmpcfg, write_pmpc= fg }, [CSR_PMPADDR0 ... CSR_PMPADDR15] =3D { pmp, read_pmpaddr, write_pmpa= ddr }, --=20 2.22.0