From nobody Tue Nov 26 22:21:02 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1704492941; cv=none; d=zohomail.com; s=zohoarc; b=Y1w26xILFcxlIbjWIpiGakx5rSvOYyLNKXHoy5OAnoVehArK9Bi+6d2NQtB96WpTyF7TSvD8z6M74/vEi9xhXYRMgq/YBOlSGDTrsDGTWUKK+BH+nRDjaMG/Nfqh3Ltn3VHGPVW9ZYGgZo/dFP/MKMrGzgeUtp5AKcdSaPPcIj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704492941; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:Message-Id:Reply-To:To; bh=P+DSlWlsYYmfvUro+I+wBQwYUt4/Bqz6j14sqSuXYzQ=; b=M4uD4/k+HEWGy42PJjNWabg9FyOYldkNiC0NZ2g44VHDY22Bn/wk5z/BfyMGwJfjz1msKiGVU9K01UScIU4ubwzR4MlhHQL4nL/a4No5S3nhYdZlt60PQVasbiJF86Fyob37wKscLSd+uu6pzeriiNAd8ZIAB8QNhz8WqVyodxs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1704492941434986.8614801016366; Fri, 5 Jan 2024 14:15:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLsRm-0007PT-M5; Fri, 05 Jan 2024 17:13:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rLsRl-0007OL-1x for qemu-devel@nongnu.org; Fri, 05 Jan 2024 17:13:45 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rLsRj-00010i-Bn for qemu-devel@nongnu.org; Fri, 05 Jan 2024 17:13:44 -0500 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1d3ed1ca402so100895ad.2 for ; Fri, 05 Jan 2024 14:13:42 -0800 (PST) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w22-20020a1709029a9600b001d35223d0besm1850524plp.251.2024.01.05.14.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 14:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704492822; x=1705097622; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=P+DSlWlsYYmfvUro+I+wBQwYUt4/Bqz6j14sqSuXYzQ=; b=vXmH4wePBkZWMf2MgW1Ji2gyWD4jjeQfN7UrWEPGSc8Myga03LfObawl59abopL8vX 7NfivleiVHRn2uI815iiDj9NydkbRWMKM84cKtzH7kKk20Yd0aJM6zycNPc2pUz5hnxq mVOznVwDTUTEAvE6YCgIXxOECwpp4+tmIaBKxPvjxTlE29QurxGSjCyJKRzRSMSXaNiG kOTUMqE8C8Oa90/rdGzesRbXB+VN9fMq+XilZag/iQe0BHikuQ37uw9FxmT0K/W5G6Dk 0dbJyTQRiNseTSU5tkV7k8YtG4nx4uXgOXe6RXwiOU/v35FzXfR6dv5I7qmo8b3hQ5I5 vpkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704492822; x=1705097622; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P+DSlWlsYYmfvUro+I+wBQwYUt4/Bqz6j14sqSuXYzQ=; b=I++E3MxU72bnOywAus2eJ/QR5XKKJYn9u2Rv18HYYWoW3Fb0wfAJh/mZbgB5DbjcjX rbc0odScgRDmxc87jw7ZcTQ4w81xGynny8XtZ9eKEMgryf7fe9zgNZ9KzK8t9k1XBYBY hW0htsKf9o1Ar/7hH0z96ABbL3Ly++HRGuyRBWT89U8E9Lr1yZTgxXJuQS95BUHf4Jhv hpToZOjHlpvq29k2kDYwli1fGvSz1q6nZkaF7skX1djT1oxTMokeejtPoEOlX0RtUsax qMU8SkelxrNc80abGIVWdGmQ8e/ba/erSC63Y4n/Yt8YcMYtavXzawJWXd6Vl1neVT9Y MKZw== X-Gm-Message-State: AOJu0YxfiUQn4Zhgy6W22DJ2sn+Hv0myNVYLyO+m1g7tf4mk0XsmKrKd Aq9wCw7ZrGtAiEnd+S1Xf+9gmUa1tV2pynyjC/U6f1MiT7Y= X-Google-Smtp-Source: AGHT+IE8XVCqST3n8sfOYTEorensuw+awaKDTgBYY9YSk2ebTzs9SsE/VSyObJEjRD3lVwEdYU1yQA== X-Received: by 2002:a17:903:2447:b0:1d4:2473:e7de with SMTP id l7-20020a170903244700b001d42473e7demr156384pls.125.1704492822213; Fri, 05 Jan 2024 14:13:42 -0800 (PST) From: Atish Patra To: Cc: Kaiwen Xue , Atish Patra , Alistair Francis , Bin Meng , Daniel Henrique Barboza , Liu Zhiwei , Palmer Dabbelt , qemu-devel@nongnu.org, qemu-riscv@nongnu.org, Weiwei Li , kaiwenxue1@gmail.com Subject: [PATCH v3 4/5] target/riscv: Add cycle & instret privilege mode filtering support Date: Fri, 5 Jan 2024 14:13:26 -0800 Message-Id: <20240105221327.176764-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240105221327.176764-1-atishp@rivosinc.com> References: <20240105221327.176764-1-atishp@rivosinc.com> 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=2607:f8b0:4864:20::636; envelope-from=atishp@rivosinc.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1704492943297100001 Content-Type: text/plain; charset="utf-8" From: Kaiwen Xue QEMU only calculates dummy cycles and instructions, so there is no actual means to stop the icount in QEMU. Hence this patch merely adds the functionality of accessing the cfg registers, and cause no actual effects on the counting of cycle and instret counters. Signed-off-by: Atish Patra Signed-off-by: Kaiwen Xue Reviewed-by: Daniel Henrique Barboza --- target/riscv/csr.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 283468bbc652..3bd4aa22374f 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -233,6 +233,24 @@ static RISCVException sscofpmf_32(CPURISCVState *env, = int csrno) return sscofpmf(env, csrno); } =20 +static RISCVException smcntrpmf(CPURISCVState *env, int csrno) +{ + if (!riscv_cpu_cfg(env)->ext_smcntrpmf) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return RISCV_EXCP_NONE; +} + +static RISCVException smcntrpmf_32(CPURISCVState *env, int csrno) +{ + if (riscv_cpu_mxl(env) !=3D MXL_RV32) { + return RISCV_EXCP_ILLEGAL_INST; + } + + return smcntrpmf(env, csrno); +} + static RISCVException any(CPURISCVState *env, int csrno) { return RISCV_EXCP_NONE; @@ -818,6 +836,54 @@ static int read_hpmcounterh(CPURISCVState *env, int cs= rno, target_ulong *val) =20 #else /* CONFIG_USER_ONLY */ =20 +static int read_mcyclecfg(CPURISCVState *env, int csrno, target_ulong *val) +{ + *val =3D env->mcyclecfg; + return RISCV_EXCP_NONE; +} + +static int write_mcyclecfg(CPURISCVState *env, int csrno, target_ulong val) +{ + env->mcyclecfg =3D val; + return RISCV_EXCP_NONE; +} + +static int read_mcyclecfgh(CPURISCVState *env, int csrno, target_ulong *va= l) +{ + *val =3D env->mcyclecfgh; + return RISCV_EXCP_NONE; +} + +static int write_mcyclecfgh(CPURISCVState *env, int csrno, target_ulong va= l) +{ + env->mcyclecfgh =3D val; + return RISCV_EXCP_NONE; +} + +static int read_minstretcfg(CPURISCVState *env, int csrno, target_ulong *v= al) +{ + *val =3D env->minstretcfg; + return RISCV_EXCP_NONE; +} + +static int write_minstretcfg(CPURISCVState *env, int csrno, target_ulong v= al) +{ + env->minstretcfg =3D val; + return RISCV_EXCP_NONE; +} + +static int read_minstretcfgh(CPURISCVState *env, int csrno, target_ulong *= val) +{ + *val =3D env->minstretcfgh; + return RISCV_EXCP_NONE; +} + +static int write_minstretcfgh(CPURISCVState *env, int csrno, target_ulong = val) +{ + env->minstretcfgh =3D val; + return RISCV_EXCP_NONE; +} + static int read_mhpmevent(CPURISCVState *env, int csrno, target_ulong *val) { int evt_index =3D csrno - CSR_MCOUNTINHIBIT; @@ -4922,6 +4988,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { write_mcountinhibit, .min_priv_ver =3D PRIV_VERSION_1_11_0 }, =20 + [CSR_MCYCLECFG] =3D { "mcyclecfg", smcntrpmf, read_mcyclecfg, + write_mcyclecfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MINSTRETCFG] =3D { "minstretcfg", smcntrpmf, read_minstretcfg, + write_minstretcfg, + .min_priv_ver =3D PRIV_VERSION_1_12_0 }, + [CSR_MHPMEVENT3] =3D { "mhpmevent3", any, read_mhpmevent, write_mhpmevent }, [CSR_MHPMEVENT4] =3D { "mhpmevent4", any, read_mhpmevent, @@ -4981,6 +5054,13 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] =3D { [CSR_MHPMEVENT31] =3D { "mhpmevent31", any, read_mhpmevent, write_mhpmevent }, =20 + [CSR_MCYCLECFGH] =3D { "mcyclecfgh", smcntrpmf_32, read_mcyclecf= gh, + write_mcyclecfgh, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_MINSTRETCFGH] =3D { "minstretcfgh", smcntrpmf_32, read_minstret= cfgh, + write_minstretcfgh, + .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, + [CSR_MHPMEVENT3H] =3D { "mhpmevent3h", sscofpmf_32, read_mhpmev= enth, write_mhpmeventh, .min_priv_ver =3D PRIV_VERSION_1_12_0 = }, --=20 2.34.1