From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120692; cv=none; d=zohomail.com; s=zohoarc; b=Vb5VjoXVkHzZjpD4ae45Yd844jY1fdgQa4Aig+72CgcGV3cBtindk//ZrSwzxLCoa/AKa53+U1cmvMJdE5yAaQHQ5wCZlDWmgQ5VzdVVHSImsfMuxajIvHX7jY9sp+hZ8yvW2S7QlyoTRSP1HnZky3WWJQlA7YSQIxlbVNf29B0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120692; 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=Gd8YfeDLqtnsOXHA+AJ6ejp6SdNe/hfDrQLtit29++Q=; b=eWUxjjSaFGxuKWDaE7iu7Uk/2pkywy00yFVfo7WArh94McmE22mgU/QqEmAp05KgHjnc5SVgQcRQxz7kTewAsXiV3f3dOuEZ6SUgswY+7RCnXA8yN89Ss5uaLP95wJ9pPoZCGMofy5jYykhcjFOVEsbYROepn5a7xnsgTFsiIG8= 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+importer2=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 1680120692257990.7493175634246; Wed, 29 Mar 2023 13:11:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6Z-0006JP-PU; Wed, 29 Mar 2023 16:09:12 -0400 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 1phc6Y-0006Fm-7V for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:10 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6W-0007nu-AL for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:09 -0400 Received: by mail-oi1-x22c.google.com with SMTP id f17so12527441oiw.10 for ; Wed, 29 Mar 2023 13:09:07 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120547; 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=Gd8YfeDLqtnsOXHA+AJ6ejp6SdNe/hfDrQLtit29++Q=; b=CFXRvJLdz6XMD1rN0m/2sN8NUAD4Ck/ZmdTOwKbcFq64lx+oknFgUGCyNnTpFBYKif qEci+tsRGw1OPQw88ZDiZBE7KqhSv3RXk1eFMIH86SgCMKLb2ayL8/VBcHGBwwHl/kN5 7tdY4u+X2GG1M7rnu42pL31YoT6anSAo2wd36lOZ0Em+Ry7LoDKwXL+GFYJ0V0fC9DDe ZzGM8JKw9bbqq1IIAijQnMlpT8+tculEnrdqnvAzh+PKc5k/zsWlKgOxsRdXOpcu7GC4 D0BFgPDUaBqPHfXoHKAhXa8hFWARel3PRe2jDuO3vhr8pqrEMDyCfzFQEgau9vjBlTtd YxmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120547; 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=Gd8YfeDLqtnsOXHA+AJ6ejp6SdNe/hfDrQLtit29++Q=; b=TbqVLIsveX4dMLFoM+TaLfNuSDjnTUVcQ2HOIc/XMSfazShLRKidgfYmR7jjCKBhC9 Qp7aoEm0GNtvmy19LxxL3tftuCG3DJL4u8WSvwDWTJy+W8ArsKAlM7Zk8U1xcv6FR2U4 NAas5sx7Z/pMlF7LeEi2/v+LE2QR5j/+ghttqUBx//NAEuUHJgviOwbd9l0eolzwNL1L jsNlNUImpzbpTca6AhwaE7bxxO1gKfIFcpT5HD4bJvGQwSOZvevIljBlWNhOm+e7vojb zhUbipMNlT0YHOEe1cdeN6200zModIQqucJQ9RFTU1rx0yxS6I1sUtntujwldh7yM4GU 5Z+w== X-Gm-Message-State: AAQBX9ccK4jeI3lrhmJde6vni6VWEzV6kvlg9ttnn4LLbw4zfNbb6Zve 2UF/eUUPy2lv1yAW0LFo4c1BzO4R4i16U8NFVbs= X-Google-Smtp-Source: AKy350Y43FXZv+BoboOF+0UDCqau5ujSnh4rZWwfPEfMmVQ8LtbLo9JsZMlD3NHIrjCIxscPDMZ/ew== X-Received: by 2002:a05:6808:1a06:b0:389:21:9483 with SMTP id bk6-20020a0568081a0600b0038900219483mr8877066oib.59.1680120546894; Wed, 29 Mar 2023 13:09:06 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 1/9] target/riscv/cpu.c: add riscv_cpu_validate_v() Date: Wed, 29 Mar 2023 17:08:48 -0300 Message-Id: <20230329200856.658733-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22c; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120694314100003 Content-Type: text/plain; charset="utf-8" The RVV verification will error out if fails and it's being done at the end of riscv_cpu_validate_set_extensions(), after we've already set some extensions that are dependent on RVV. Let's put it in its own function and do it earlier. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 89 +++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d8568a024c..610e55cb04 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -790,6 +790,46 @@ static void riscv_cpu_disas_set_info(CPUState *s, disa= ssemble_info *info) } } =20 +static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, + Error **errp) +{ + int vext_version =3D VEXT_VERSION_1_00_0; + + if (!is_power_of_2(cfg->vlen)) { + error_setg(errp, "Vector extension VLEN must be power of 2"); + return; + } + if (cfg->vlen > RV_VLEN_MAX || cfg->vlen < 128) { + error_setg(errp, + "Vector extension implementation only supports VLEN " + "in the range [128, %d]", RV_VLEN_MAX); + return; + } + if (!is_power_of_2(cfg->elen)) { + error_setg(errp, "Vector extension ELEN must be power of 2"); + return; + } + if (cfg->elen > 64 || cfg->elen < 8) { + error_setg(errp, + "Vector extension implementation only supports ELEN " + "in the range [8, 64]"); + return; + } + if (cfg->vext_spec) { + if (!g_strcmp0(cfg->vext_spec, "v1.0")) { + vext_version =3D VEXT_VERSION_1_00_0; + } else { + error_setg(errp, "Unsupported vector spec version '%s'", + cfg->vext_spec); + return; + } + } else { + qemu_log("vector version is not specified, " + "use the default value v1.0\n"); + } + set_vext_version(env, vext_version); +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -797,6 +837,7 @@ static void riscv_cpu_disas_set_info(CPUState *s, disas= semble_info *info) static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; + Error *local_err =3D NULL; =20 /* Do some ISA extension error checking */ if (riscv_has_ext(env, RVG) && @@ -865,8 +906,14 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU= *cpu, Error **errp) return; } =20 - /* The V vector extension depends on the Zve64d extension */ if (riscv_has_ext(env, RVV)) { + riscv_cpu_validate_v(env, &cpu->cfg, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + + /* The V vector extension depends on the Zve64d extension */ cpu->cfg.ext_zve64d =3D true; } =20 @@ -947,46 +994,6 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU= *cpu, Error **errp) cpu->cfg.ext_zksed =3D true; cpu->cfg.ext_zksh =3D true; } - - if (riscv_has_ext(env, RVV)) { - int vext_version =3D VEXT_VERSION_1_00_0; - if (!is_power_of_2(cpu->cfg.vlen)) { - error_setg(errp, - "Vector extension VLEN must be power of 2"); - return; - } - if (cpu->cfg.vlen > RV_VLEN_MAX || cpu->cfg.vlen < 128) { - error_setg(errp, - "Vector extension implementation only supports VLEN= " - "in the range [128, %d]", RV_VLEN_MAX); - return; - } - if (!is_power_of_2(cpu->cfg.elen)) { - error_setg(errp, - "Vector extension ELEN must be power of 2"); - return; - } - if (cpu->cfg.elen > 64 || cpu->cfg.elen < 8) { - error_setg(errp, - "Vector extension implementation only supports ELEN= " - "in the range [8, 64]"); - return; - } - if (cpu->cfg.vext_spec) { - if (!g_strcmp0(cpu->cfg.vext_spec, "v1.0")) { - vext_version =3D VEXT_VERSION_1_00_0; - } else { - error_setg(errp, - "Unsupported vector spec version '%s'", - cpu->cfg.vext_spec); - return; - } - } else { - qemu_log("vector version is not specified, " - "use the default value v1.0\n"); - } - set_vext_version(env, vext_version); - } } =20 #ifndef CONFIG_USER_ONLY --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120637; cv=none; d=zohomail.com; s=zohoarc; b=kX8mzC2P1dIahAzTlCJELTgT5RSO7S0ErIV039MVTgVw99ocRPD6oLcXKTObzuT4NgBDtpHr//CAdlpShW1hhn7yfcWdLVPtC681OiKM1iFvp4ShLvAJ21+1hYhmp6VQPxDf7GhqiSKbkkOddVYFiyD9ER82M8DLtzQt+hQAAk8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120637; 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=a7raJYv508hDPYTX7Dx1KX4h6DtiCuFfCm123h7f7NA=; b=bwcG4+RxoYaePqx9rOSnSB7RD9cPNlVOLgDOicPuc82LP3l51XKu6lkJK/WXPderPcR9j53jIgdEC0yrPznBA9W817U7y5YYo5kPDn6Ale0A4obsTGEcL7R26Wf1+fKe3xRBXB2POPfNwUj69wlOJtFEhbX2ccAg6YmRJ5gLqoU= 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+importer2=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 1680120637814524.039400447422; Wed, 29 Mar 2023 13:10:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6b-0006LD-TG; Wed, 29 Mar 2023 16:09:13 -0400 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 1phc6a-0006Kc-Sj for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:12 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6Z-0007oK-EH for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:12 -0400 Received: by mail-oi1-x236.google.com with SMTP id r16so12473492oij.5 for ; Wed, 29 Mar 2023 13:09:11 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120550; 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=a7raJYv508hDPYTX7Dx1KX4h6DtiCuFfCm123h7f7NA=; b=FulcEYrhXfxpHqHRYyNB0hoaZ8b98GPltA1TBOYeSNXG4QOVqUZxqCu9cJ5OPNdKoS 9ecizmzdRHwJaw3EXbxxBAaVGO3Qt1KEx5xvbG2yN8L+vvuaUK72lr0PmM3eaNX0Dvgk lvEwg6ukrBadadmxIlBGR6HaMV8+JhL3RroMfnt6qvc0JamclxOeRZ0am06NdnsyIjsX DE+biJsW4cbMYFCdDzfwlxh+9wGTG4fE8/cloQpRSg3GIeAmcJXRt/j/u0xUOttbclBS CTjPPja+Y1pZmIsvrazbiDE6OtKuW2aufFKNZwztDipEPvA+sCizkb7eRUcyj8ZTjjZc 7qVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120550; 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=a7raJYv508hDPYTX7Dx1KX4h6DtiCuFfCm123h7f7NA=; b=4DZWfmJowUD1DtbKbvNkvAS9iVRlbhV8psh9Bj1h4doH1U5INTz+CtIQNAySnhV6FH TJ3mhUxCi1/V6/CE0G85c6vsz2eoYTOUgojlH6d3m7vPKUrXVOKgWQbZtVKWA/S4ip49 xFo3ucitWu49OGX3LMfTP4CxJtdilJYAjx0TfDtNF757BTBkxJAwlfyoEiD7++RvE3k/ rTFa8TxVjqMsj5h3SsJWnIzXMH3/EwcyPRjY/XLsq5okTvs6+fzZNxF0du5fdAd4zRQM SFERT1MghlHRP6jgbva+BiTcmqNAt1TPrb00qdU4C9+P3Zw3NWvTeGeEC4cLFloiaTZt Q7fA== X-Gm-Message-State: AO0yUKV8YGCF2wfb33TVsIaTlBbRer4UNmKHwfkp6oinYYO9yRhDi4mL flXm7ug9B0s0ORx3rD6/tXRRPr796bGwR5vCsIs= X-Google-Smtp-Source: AK7set+/EbM9rqjga0p64CFqW+aWOnWYIh72ttbLEHHYbf70cOil7xSZloT+lqcOHnt+TokI44lAoQ== X-Received: by 2002:a05:6808:18a0:b0:387:205b:70c7 with SMTP id bi32-20020a05680818a000b00387205b70c7mr12484869oib.13.1680120550071; Wed, 29 Mar 2023 13:09:10 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 2/9] target/riscv/cpu.c: remove set_vext_version() Date: Wed, 29 Mar 2023 17:08:49 -0300 Message-Id: <20230329200856.658733-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120638548100001 Content-Type: text/plain; charset="utf-8" This setter is doing nothing else but setting env->vext_ver. Assign the value directly. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 610e55cb04..19e0a6a902 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -245,11 +245,6 @@ static void set_priv_version(CPURISCVState *env, int p= riv_ver) env->priv_ver =3D priv_ver; } =20 -static void set_vext_version(CPURISCVState *env, int vext_ver) -{ - env->vext_ver =3D vext_ver; -} - #ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str(const char *satp_mode_str) { @@ -827,7 +822,7 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RI= SCVCPUConfig *cfg, qemu_log("vector version is not specified, " "use the default value v1.0\n"); } - set_vext_version(env, vext_version); + env->vext_ver =3D vext_version; } =20 /* --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120645; cv=none; d=zohomail.com; s=zohoarc; b=M2PwvmOh1/EWFWdrn3vck/JHtTaml296VNCeJRv2zLik6p3F8fy3za0VhWMbXwtpj2sCSzZExyfWi91Gf9i2v61Q/JEPwyr9WJCOh5FrYkHS9c6yYRWGoeB+gzwu42bBJzk8Ifbn0Qk9SXfDZowLDtV2qGV2+eqUEUuipaNQAmw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120645; 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=Bm6qwYR8XuZ+a+qBmiIX7C9afndpAkzlukCQ+u6MAB8=; b=kxPavUM4JJBSPXLaSgYDcagu3oU6+0sU7Dg6KF5RRJJ4sPjld/H/26IkINVsukkyRfpeqlw/w/e1zwKNRsOawwdKbjzVBHK1TNEic4sMxvfI/91ONy5UlpW3PTVZFQ0196SlpPX3VYRs8Rbyva8Mau+URFEvyOl7SgWfK+YbNsg= 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+importer2=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 1680120645736629.6443093326632; Wed, 29 Mar 2023 13:10:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6g-0006My-Nt; Wed, 29 Mar 2023 16:09:18 -0400 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 1phc6f-0006MD-82 for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:17 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6c-0007oi-BY for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:16 -0400 Received: by mail-oi1-x22a.google.com with SMTP id q27so11810742oiw.0 for ; Wed, 29 Mar 2023 13:09:13 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120553; 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=Bm6qwYR8XuZ+a+qBmiIX7C9afndpAkzlukCQ+u6MAB8=; b=nHbVPqahPO0NdklQJWZp7FsgOrwF5ckTcxCuoaoQ5GNLWztuzcPxJ9XrfjVCw+CWlN Ec5SEx0DCkjN0fXcdr/sB1Ts5030AiUyydRm15gD0GQVnpe6ATAWwFNfdaREyYRX/4Eo 2zaYskKh+wTA2Rhtgwh9DhUGDwJbpTxhLahP2snvmva86s9TYT82Tc6RcIu05gozx80o RpO/JNFIVbrqCTzsCycXcwyH2PetEPcKbj48m3ocvUOdjQ+ixtfwhynVQ+0+nyGVqH5c qce6X4i7kY0yyiitdK3n1QJ7Mim8MxuC8n/ew2ELpQ5jUwOnyz1yH2EWPWimrCMjJeZH h8rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120553; 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=Bm6qwYR8XuZ+a+qBmiIX7C9afndpAkzlukCQ+u6MAB8=; b=pfvk6SXSOLP8/VJftD4HzOBt72mc8AH/1A3wjQiprjC11cdDTClwRS6Dth/67YpxHK XVnFhOs5g1mR57zGj82M+6rNymQNWV1G0aK92Y5p1QOEyRl0pIx32Vkqf3F8aCE9DL5n btRjHRkCtIoLUolE5Ss0WcUXg04T4xXd+RjVyK1hx9G977aIxDP3NmfK2g//pgrpKkiF /VdV1TRhoXRgsHmrU6rcAljaQepNUr+7NNEekxg6UXFmP+dEAznz3GgX+uUisv6kJrpU Qu71go5LYdCzNeVuE3NxAYgxGevKy8YrGTCgx0HOvTDI9PjMEVOcxTi712bpkPI/GiN6 SOSA== X-Gm-Message-State: AAQBX9cohvoLA6qrOHqcDAmLjNWLul02tWR1oQCdeLyq4/n7hKXJi/Ao D8gwVq1TbeHhtcDUIemVnVVuKQ9nmPekJcr4kpc= X-Google-Smtp-Source: AKy350bmOLxSFKsqTBbP8ckW0OSjvn5L44v1bx0rYeNlux61Pf08erC4NjCcodvLK9KB8St4QeAWBA== X-Received: by 2002:a05:6808:2081:b0:389:340e:be43 with SMTP id s1-20020a056808208100b00389340ebe43mr6258954oiw.48.1680120552909; Wed, 29 Mar 2023 13:09:12 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 3/9] target/riscv/cpu.c: remove set_priv_version() Date: Wed, 29 Mar 2023 17:08:50 -0300 Message-Id: <20230329200856.658733-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120646626100001 Content-Type: text/plain; charset="utf-8" The setter is doing nothing special. Just set env->priv_ver directly. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 19e0a6a902..75c3d4ed22 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -240,11 +240,6 @@ static void set_misa(CPURISCVState *env, RISCVMXL mxl,= uint32_t ext) env->misa_ext_mask =3D env->misa_ext =3D ext; } =20 -static void set_priv_version(CPURISCVState *env, int priv_ver) -{ - env->priv_ver =3D priv_ver; -} - #ifndef CONFIG_USER_ONLY static uint8_t satp_mode_from_str(const char *satp_mode_str) { @@ -343,7 +338,7 @@ static void riscv_any_cpu_init(Object *obj) VM_1_10_SV32 : VM_1_10_SV57); #endif =20 - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; } =20 #if defined(TARGET_RISCV64) @@ -354,7 +349,7 @@ static void rv64_base_cpu_init(Object *obj) set_misa(env, MXL_RV64, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -364,7 +359,7 @@ static void rv64_sifive_u_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39); #endif @@ -376,7 +371,7 @@ static void rv64_sifive_e_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -389,7 +384,7 @@ static void rv64_thead_c906_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU); - set_priv_version(env, PRIV_VERSION_1_11_0); + env->priv_ver =3D PRIV_VERSION_1_11_0; =20 cpu->cfg.ext_zfh =3D true; cpu->cfg.mmu =3D true; @@ -423,7 +418,7 @@ static void rv128_base_cpu_init(Object *obj) set_misa(env, MXL_RV128, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -436,7 +431,7 @@ static void rv32_base_cpu_init(Object *obj) set_misa(env, MXL_RV32, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - set_priv_version(env, PRIV_VERSION_1_12_0); + env->priv_ver =3D PRIV_VERSION_1_12_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif @@ -446,7 +441,7 @@ static void rv32_sifive_u_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif @@ -458,7 +453,7 @@ static void rv32_sifive_e_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -471,7 +466,7 @@ static void rv32_ibex_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_11_0); + env->priv_ver =3D PRIV_VERSION_1_11_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -485,7 +480,7 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); - set_priv_version(env, PRIV_VERSION_1_10_0); + env->priv_ver =3D PRIV_VERSION_1_10_0; cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -1113,7 +1108,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) } =20 if (priv_version >=3D PRIV_VERSION_1_10_0) { - set_priv_version(env, priv_version); + env->priv_ver =3D priv_version; } =20 riscv_cpu_validate_misa_priv(env, &local_err); --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120645; cv=none; d=zohomail.com; s=zohoarc; b=Y3huZNAtNYbGXhEGDmuRAZfP8B2W1xjxK1Cfv35HidUXhNc2M0YbXFGNl/GC/OzLNfq8kep4qXVyiEmQ4Kvq4sSFFvU5pgTOGCrsBvYgou6gnNriWhTn7mlGYmN2Uyb0WmjYx6nbvdIOjb0wPPscdvysCceQa5y5E3j1r30oU/A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120645; 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=Dz94/NiXBxZeIT56JK2x9vttFdPys2crTli6oE6SiOg=; b=Om2F1lWuOWyGcVZJ51qeTdrQj1xSmVhDVCPC8QC1s3usdfsv7xKbCEyYw2MUvKVhHgjp+3hODDWvdzIjY6xq+E/BjW2S/lcj6WQEX1Hw1r/B8gqFMezOVJFf5/QuC1pS1mL2155HNUK3oTRlAuMiA8cu8ydutVePZR8mFqjglTU= 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+importer2=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 1680120645950969.2591581300952; Wed, 29 Mar 2023 13:10:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6h-0006NF-Up; Wed, 29 Mar 2023 16:09:19 -0400 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 1phc6g-0006N0-O9 for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:18 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6f-0007nQ-3b for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:18 -0400 Received: by mail-oi1-x236.google.com with SMTP id b19so12543481oib.7 for ; Wed, 29 Mar 2023 13:09:16 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120556; 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=Dz94/NiXBxZeIT56JK2x9vttFdPys2crTli6oE6SiOg=; b=FmmisVVG3hyCfvUvV4pAuFQXPvICie6q4WHgTZvNiyM1r+J3C9K+mCKwW3hNjb2UU2 pXqByfwMsMfYnqy5VfIu39YbzQ6v9ptzev1DmlsVmEyQt56CyIYY46/zbhT1ds1jZKiY r/azE7htY6zhtn4SvqfScU+r05IJxQMlNPQjEMeiN39J4a1Dh7mOgmvqyrE4PpIESuyb C52fAvS/QY96m5SPN1/jTXji159lRgEVACokGK2rkkCxhrjyLo7VZ2hd/LRpbDlDqkRf rG8lRLSCnV4tRpbcRaNo2U2hQFIm8/iSUrCH9Owfynj1F3sXyCXFTB4bpOyL08sUGVY0 yc1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120556; 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=Dz94/NiXBxZeIT56JK2x9vttFdPys2crTli6oE6SiOg=; b=T1DX4qBT0IZBfiE5JuwuEu5ldqQRAgp9tcty4lVSABP3W6cn6qyBTdzIX4UCcbUKmt jP3NAgJpXMvWOYTSYgipQgMY7kTtkmD1hV7rMfqg0bqrX73+Dp8d8OH3utK52oN+NgWn OzbTU9hfXQxh1aeYc1kkZlq33lV5NAXAqkqa/PMXaUitqoDnQSS6tfK3SQuylaZRRM8n owl0I06SXFg+jOVnjbqvm3bjVKknKMIULCw+N0FE7TfLVuQWdKtIgS+cbEku4fp9z6EF zfEgcg/ZhAYcFFnxnlibkA4N9Be128RsPr3YJFSdSwyF4GcAV69a2ArD9ZECFvjj37wi KOPA== X-Gm-Message-State: AAQBX9eztrDpCiDMiVKsm5mOPbBUsCmi/vCFTOap3imbIRQItXkwWfLQ 7/lPHQjmWFzT5+5bsoeuxQWf7S5WtPt0gm9M7B4= X-Google-Smtp-Source: AKy350ZyWKzR1rAuUy3KHUk8PUbwhnsrOLiyrxZKD2IE/UnOWqN4Qdk4jwojdojuRZE6PVAsofzSMw== X-Received: by 2002:a05:6808:7ce:b0:387:50aa:5f3b with SMTP id f14-20020a05680807ce00b0038750aa5f3bmr1449628oij.6.1680120556081; Wed, 29 Mar 2023 13:09:16 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza , Richard Henderson Subject: [PATCH v6 4/9] target/riscv: add PRIV_VERSION_LATEST Date: Wed, 29 Mar 2023 17:08:51 -0300 Message-Id: <20230329200856.658733-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120646628100002 Content-Type: text/plain; charset="utf-8" All these generic CPUs are using the latest priv available, at this moment PRIV_VERSION_1_12_0: - riscv_any_cpu_init() - rv32_base_cpu_init() - rv64_base_cpu_init() - rv128_base_cpu_init() Create a new PRIV_VERSION_LATEST enum and use it in those cases. I'll make it easier to update everything at once when a new priv version is available. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Richard Henderson Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 8 ++++---- target/riscv/cpu.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 75c3d4ed22..1743e9ede3 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -338,7 +338,7 @@ static void riscv_any_cpu_init(Object *obj) VM_1_10_SV32 : VM_1_10_SV57); #endif =20 - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; } =20 #if defined(TARGET_RISCV64) @@ -349,7 +349,7 @@ static void rv64_base_cpu_init(Object *obj) set_misa(env, MXL_RV64, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -418,7 +418,7 @@ static void rv128_base_cpu_init(Object *obj) set_misa(env, MXL_RV128, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV57); #endif @@ -431,7 +431,7 @@ static void rv32_base_cpu_init(Object *obj) set_misa(env, MXL_RV32, 0); riscv_cpu_add_user_properties(obj); /* Set latest version of privileged specification */ - env->priv_ver =3D PRIV_VERSION_1_12_0; + env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 02f26130d5..03b5cc2cf4 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -86,6 +86,8 @@ enum { PRIV_VERSION_1_10_0 =3D 0, PRIV_VERSION_1_11_0, PRIV_VERSION_1_12_0, + + PRIV_VERSION_LATEST =3D PRIV_VERSION_1_12_0, }; =20 #define VEXT_VERSION_1_00_0 0x00010000 --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120612; cv=none; d=zohomail.com; s=zohoarc; b=DuEtLE9KOxyEq1y8C0KRkCt6fswF2308RVKRQeW2q9r6OPJyi3Zl/HeuXdRNDOdORXhJD0NMIdra0g8r4lRNMxCFTI5XQV7Adhq66a1lb5t1lRQrZORilWh8/bws5haxBLvvfHP4vNEzFSjY/20i9Ui8tscblLqgmDxxw51RKdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120612; 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=4qm4rp2E+k1ii135PS822pMVlB1BLT7vUwfUSFLvGwE=; b=JuiGF0a/RAVVGM6qchK0MWvnzUdi1qxZSRclCchpHh6CTJU/hSxhu+/gPxBgkPWeMCzlrCXwIDSaKkb0Cd9g2WPN2n4sg9unVp/PIyNJ9DAk1BdbZybZK2gT1g2oXAvZqmTDurmqdMj2Dp1hlyOc8g7cCR4B+y0TwQSvBl0/oSE= 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+importer2=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 1680120612644377.30501879380165; Wed, 29 Mar 2023 13:10:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6k-0006OF-V3; Wed, 29 Mar 2023 16:09:22 -0400 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 1phc6k-0006O0-Dl for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:22 -0400 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6i-0007nO-MB for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:22 -0400 Received: by mail-oi1-x235.google.com with SMTP id bj20so12552543oib.3 for ; Wed, 29 Mar 2023 13:09:20 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120559; 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=4qm4rp2E+k1ii135PS822pMVlB1BLT7vUwfUSFLvGwE=; b=hLYmChHLzaUfsi0NjLDH9umTnwr8INjKya2FR1ScrLvG1272c+Fpbmc1sho6oC/pTg QHNWlgRm3HihnyRDjOwNUrcpXFEsHuH5DOyWL5Ld0SjqSCn/3O2PsKjCpEG0FqWlFEf5 wqXj1YiD0r9CgFvw5CqDXEgJGVh1Ai/0yPyt0JW65TarQHH0SC74Q93QcAA6/xB3LCUo vz2n1aGGfu2vRsyADmFIGPkNxfCg7qeV8FeJWT9BdY5sVnBluBRlVX1rQpVYnAoXOTs6 pfQbb1exYto3dbtuXZdCPaSgp33yJP1WICFS7RmGHPPzEnXNYb9a3nr9hOqGkT5qUcC2 GK8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120559; 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=4qm4rp2E+k1ii135PS822pMVlB1BLT7vUwfUSFLvGwE=; b=we+dWK0yPL+MMvYaiHvcO9m/c+wHAstkoqQO1xv+xTzDxcRyx+S0/fNR0HkPs7Diyk PB267ruS6woZGuzMmILIv7YL3HGSD2k9Y0AmRlABW6xt/ituKaARp/tQHtq8vo0vttp3 xmwn1taoyJaMjYkIFCsFfxszqTDsePJTyJcxbHq3rU04ALbFCBBntaFzWN1zGpH7YaxY 9xQp8BhDTEGnap7Ebt+6mVzNNp271gmQ3OCs8XZeoZWJMo5tDiAix2gt9vFTg6jqAC9e fq68/9hfFn/WhGQMqtFQolHt8XQ0gnZKloTMDJD1D6d3T+JSQ+v37znEVUwEZAr29s4k Y87Q== X-Gm-Message-State: AO0yUKUasCQIyYECm1/MpKI78PM2bqwvnestVQLdVYPXLTi/NyfElzQf xsfsPzkaL7iTTHEGp0VQds7/w+ycOdz+7BD2ke4= X-Google-Smtp-Source: AK7set8VB06oxjQpx2lch0Id5gJmQvbw/IZKsq6+Io20WYZ60I8OFsRhNdLo6ttTpJvjcwcfpQq+WA== X-Received: by 2002:aca:1c11:0:b0:384:1c58:53a with SMTP id c17-20020aca1c11000000b003841c58053amr5961920oic.40.1680120559576; Wed, 29 Mar 2023 13:09:19 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 5/9] target/riscv/cpu.c: add priv_spec validate/disable_exts helpers Date: Wed, 29 Mar 2023 17:08:52 -0300 Message-Id: <20230329200856.658733-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::235; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120614504100002 Content-Type: text/plain; charset="utf-8" We're doing env->priv_spec validation and assignment at the start of riscv_cpu_realize(), which is fine, but then we're doing a force disable on extensions that aren't compatible with the priv version. This second step is being done too early. The disabled extensions might be re-enabled again in riscv_cpu_validate_set_extensions() by accident. A better place to put this code is at the end of riscv_cpu_validate_set_extensions() after all the validations are completed. Add a new helper, riscv_cpu_disable_priv_spec_isa_exts(), to disable the extesions after the validation is done. While we're at it, create a riscv_cpu_validate_priv_spec() helper to host all env->priv_spec related validation to unclog riscv_cpu_realize a bit. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 91 ++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1743e9ede3..8f0620376c 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -820,6 +820,52 @@ static void riscv_cpu_validate_v(CPURISCVState *env, R= ISCVCPUConfig *cfg, env->vext_ver =3D vext_version; } =20 +static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) +{ + CPURISCVState *env =3D &cpu->env; + int priv_version =3D -1; + + if (cpu->cfg.priv_spec) { + if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { + priv_version =3D PRIV_VERSION_1_12_0; + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { + priv_version =3D PRIV_VERSION_1_11_0; + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { + priv_version =3D PRIV_VERSION_1_10_0; + } else { + error_setg(errp, + "Unsupported privilege spec version '%s'", + cpu->cfg.priv_spec); + return; + } + + env->priv_ver =3D priv_version; + } +} + +static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) +{ + CPURISCVState *env =3D &cpu->env; + int i; + + /* Force disable extensions if priv spec version does not match */ + for (i =3D 0; i < ARRAY_SIZE(isa_edata_arr); i++) { + if (isa_ext_is_enabled(cpu, &isa_edata_arr[i]) && + (env->priv_ver < isa_edata_arr[i].min_version)) { + isa_ext_update_enabled(cpu, &isa_edata_arr[i], false); +#ifndef CONFIG_USER_ONLY + warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx + " because privilege spec version does not match", + isa_edata_arr[i].name, env->mhartid); +#else + warn_report("disabling %s extension because " + "privilege spec version does not match", + isa_edata_arr[i].name); +#endif + } + } +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -984,6 +1030,12 @@ static void riscv_cpu_validate_set_extensions(RISCVCP= U *cpu, Error **errp) cpu->cfg.ext_zksed =3D true; cpu->cfg.ext_zksh =3D true; } + + /* + * Disable isa extensions based on priv spec after we + * validated and set everything we need. + */ + riscv_cpu_disable_priv_spec_isa_exts(cpu); } =20 #ifndef CONFIG_USER_ONLY @@ -1083,7 +1135,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) CPURISCVState *env =3D &cpu->env; RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); CPUClass *cc =3D CPU_CLASS(mcc); - int i, priv_version =3D -1; Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -1092,23 +1143,10 @@ static void riscv_cpu_realize(DeviceState *dev, Err= or **errp) return; } =20 - if (cpu->cfg.priv_spec) { - if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { - priv_version =3D PRIV_VERSION_1_12_0; - } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { - priv_version =3D PRIV_VERSION_1_11_0; - } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { - priv_version =3D PRIV_VERSION_1_10_0; - } else { - error_setg(errp, - "Unsupported privilege spec version '%s'", - cpu->cfg.priv_spec); - return; - } - } - - if (priv_version >=3D PRIV_VERSION_1_10_0) { - env->priv_ver =3D priv_version; + riscv_cpu_validate_priv_spec(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; } =20 riscv_cpu_validate_misa_priv(env, &local_err); @@ -1117,23 +1155,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 - /* Force disable extensions if priv spec version does not match */ - for (i =3D 0; i < ARRAY_SIZE(isa_edata_arr); i++) { - if (isa_ext_is_enabled(cpu, &isa_edata_arr[i]) && - (env->priv_ver < isa_edata_arr[i].min_version)) { - isa_ext_update_enabled(cpu, &isa_edata_arr[i], false); -#ifndef CONFIG_USER_ONLY - warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx - " because privilege spec version does not match", - isa_edata_arr[i].name, env->mhartid); -#else - warn_report("disabling %s extension because " - "privilege spec version does not match", - isa_edata_arr[i].name); -#endif - } - } - if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120674; cv=none; d=zohomail.com; s=zohoarc; b=hnBs4s+jHdVhqHT6yodz7CwC32Q9LWzQW/+HjYznP0PKUEe1SlCXa1rCgadlEbZrnVqoyHS15WwX5c8kK6iMPbNvgDz7AwlsnSevmO2kxiPCOR4CB7wWVvnB/pB87Pxt5G2qajrJU3UM5oWQxbdMd8YYcv6L04CL2cWdte6YgpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120674; 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=EYVRv5okuTTY3DbepQQiz5pLfs3NIng0dJ4MkGLEnKk=; b=JUf/qGpnSt5EFaK4bY1PU0dEQ2QZBzBiPevg6FToJcQhQpcLuGfkla1ldtnlUR2f2WFwHaSHWQAAHNo4lkws+Xq/ZEnXdGYvlAwNi14cQXtGEJh81aAFCIO+wrm2RgS1kB1gwF+RoVWWVh7bk61QxbA1xwq4hiRLfzbWJYVMRGg= 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+importer2=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 1680120674046810.7697849783359; Wed, 29 Mar 2023 13:11:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6p-0006Pg-I3; Wed, 29 Mar 2023 16:09:27 -0400 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 1phc6n-0006P0-Ju for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:25 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6m-0007qR-3G for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:25 -0400 Received: by mail-oi1-x230.google.com with SMTP id r14so6872522oiw.12 for ; Wed, 29 Mar 2023 13:09:23 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120562; 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=EYVRv5okuTTY3DbepQQiz5pLfs3NIng0dJ4MkGLEnKk=; b=OgrkR9csRTToIHYUTq+YFrXFkGHVZxxGcq7w037WC7tO+Ws4ybr2qR6UAwmOFxN2yy ozQOT8YQracL6yQipyIUIdkjfKjUHrirWHO9qPuBeA+ZXDbFOhh3IAOhRNfzQChcKovw q1hWAeLOma7wTC6qSPu5cp7OjbS3YCm6VByO+3H2gAQAxIimIat6Gjc4lxXdOx+hcgpk zUmvRcew1JYkkNhDWDnViweSegPDcBOoO8jq57VLduXeuGXZgL/W2c00Rhie3gbdbKJq rL8J2gmusK1skGKazY1dOYsrHD8CgKoGm5jlx++d3qd8gmTF8iNdN8i2KDAbW/LNS3mw vRsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120562; 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=EYVRv5okuTTY3DbepQQiz5pLfs3NIng0dJ4MkGLEnKk=; b=AXhOiWZjDNKJNDTj/Fbpg+Zya+WtUyTVfNWBbZoWcu8wOyKIP8vwxrMmELK501935Q 2zMNzdru2H7mC0CAB4BHGn0QVFQ9+ZrM8QKJ2G/lZxTSkT/rxNl6AjPOV2ikvl95lJnw mTeQDwcDp8ay2uhW5qd6pgVJ3CDoCxzxm3p+qlVzjbtlyYy814RgPq5bTtpbU9U8kdlc dewiXL/OJsEts4UH2GRGptQvwLngizYOi/OVF3ue78uztbTr36HI/jW7EAbbwQajV0ue ZRjOIL3osbItzRUKCVamgrOU9vSBajkXhU+wHICN+PtXjkq/+M+aLFKxKQ60ScN+wNgy 39Ew== X-Gm-Message-State: AO0yUKVGxTHtoZ9wZVW7ZLoC3SzKv4lM2779S2H4Q/OlGO/Q9U23/29Y dsn93XBMBbvbfGmZw5FZud2TDN1RqHeHJ1YHJto= X-Google-Smtp-Source: AK7set8SdOY6hSjPZe7i5sW1gTTvH4/4LDckoUnYZyZiXEeldKnpEIRfYOdzyLJgYFsS1ri/5QmUGA== X-Received: by 2002:aca:1918:0:b0:387:6a3b:5a82 with SMTP id l24-20020aca1918000000b003876a3b5a82mr8434388oii.44.1680120562566; Wed, 29 Mar 2023 13:09:22 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 6/9] target/riscv/cpu.c: add riscv_cpu_validate_misa_mxl() Date: Wed, 29 Mar 2023 17:08:53 -0300 Message-Id: <20230329200856.658733-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120674691100001 Content-Type: text/plain; charset="utf-8" Let's remove more code that is open coded in riscv_cpu_realize() and put it into a helper. Let's also add an error message instead of just asserting out if env->misa_mxl_max !=3D env->misa_mlx. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 50 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 8f0620376c..e8045840bd 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -866,6 +866,33 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCV= CPU *cpu) } } =20 +static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) +{ + RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(cpu); + CPUClass *cc =3D CPU_CLASS(mcc); + CPURISCVState *env =3D &cpu->env; + + /* Validate that MISA_MXL is set properly. */ + switch (env->misa_mxl_max) { +#ifdef TARGET_RISCV64 + case MXL_RV64: + case MXL_RV128: + cc->gdb_core_xml_file =3D "riscv-64bit-cpu.xml"; + break; +#endif + case MXL_RV32: + cc->gdb_core_xml_file =3D "riscv-32bit-cpu.xml"; + break; + default: + g_assert_not_reached(); + } + + if (env->misa_mxl_max !=3D env->misa_mxl) { + error_setg(errp, "misa_mxl_max must be equal to misa_mxl"); + return; + } +} + /* * Check consistency between chosen extensions while setting * cpu->cfg accordingly. @@ -1134,7 +1161,6 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) RISCVCPU *cpu =3D RISCV_CPU(dev); CPURISCVState *env =3D &cpu->env; RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); - CPUClass *cc =3D CPU_CLASS(mcc); Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -1143,6 +1169,12 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 + riscv_cpu_validate_misa_mxl(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + riscv_cpu_validate_priv_spec(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); @@ -1171,22 +1203,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) } #endif /* CONFIG_USER_ONLY */ =20 - /* Validate that MISA_MXL is set properly. */ - switch (env->misa_mxl_max) { -#ifdef TARGET_RISCV64 - case MXL_RV64: - case MXL_RV128: - cc->gdb_core_xml_file =3D "riscv-64bit-cpu.xml"; - break; -#endif - case MXL_RV32: - cc->gdb_core_xml_file =3D "riscv-32bit-cpu.xml"; - break; - default: - g_assert_not_reached(); - } - assert(env->misa_mxl_max =3D=3D env->misa_mxl); - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120665; cv=none; d=zohomail.com; s=zohoarc; b=lwNnofpIMb4f1VH06t5ztm1YyA67BWJAHbGFuWHgJeAZ4a971OjPiH/N/9XDO9609wMQVcEjt1eQJoXGFWe9G+FA2lWk20f1clJ2trneMzBN4PqosnFiZx/uGFM3ualkYgAEj5/ag5TtxCUO9iDS1NqEqZrVzMxRHgiXcufY0eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120665; 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=qgoVXA/5VPqReZ8KfSmo3riuz4iRQirpLO1IVT3EBlc=; b=IDM84qVfq+QD+QiMRsbIcEd8ZfItOuWjcnkxkZ6JlmKzx085IYMsD5Htdks/yFIt3af4tOkYZLbGVhlBJ6JK6+FqF9ofpVk60TPdy32XD8SP5/Us0ACDsUrJ4fvQbrGN6GfppMMC0iKoxn/hL88KlH4W3KjeQd9hycn/gD67kbQ= 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+importer2=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 168012066536059.696210300685266; Wed, 29 Mar 2023 13:11:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6r-0006Py-4P; Wed, 29 Mar 2023 16:09:29 -0400 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 1phc6q-0006Pq-3a for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:28 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6o-0007qR-IV for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:27 -0400 Received: by mail-oi1-x230.google.com with SMTP id r14so6872620oiw.12 for ; Wed, 29 Mar 2023 13:09:26 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120565; 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=qgoVXA/5VPqReZ8KfSmo3riuz4iRQirpLO1IVT3EBlc=; b=lxpeXRzz+aqeoYhZTaAXBag14K239gBHz4N3G6EW+ORxGvKJXGVrMXM74+aE9TNzUD wqIihrhOHnJJFPz71fLeXulaDn0TTQf62fF3Dl1u6J0YwCHwwwCOeMkhCpFBpC3e/N3p hhxg56ysALL3pEcx8+jI0gSOavb4pmFqO0MMhBgnpgooVTSc2RJJw5jsjhLKvdw4zDUz n6cybsEOkCZWvczMUJ8nsTK8rhY9i7ff8BNqtagv9903mHQnn7vsS4sG7zg+2FEsX5AP IfvnzYIwOhTXDoQaUzkHOLrTgu9VwlYG4DsgZ/vTb2btR21Ux5stCecATGXox2up6ndF 9GAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120565; 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=qgoVXA/5VPqReZ8KfSmo3riuz4iRQirpLO1IVT3EBlc=; b=vCSfNRuvEoBKLAyU+hcUuKrzcBf3Os0Ssp7V+Gm2cs2tbtMOqoJGFVbAqLiC6rGxJF nUkjTAq7VaxZd78T0zQxz/wrvf/8KRHvnsE1ZKR3rnMl3gGvojZPcLwTxOxaUmWnGPBe 4220Pt4nR752fHbtVZ2bDCTpy5pEfZqxIAMbCAaYtHbGako0rZO4/0UKEP6NgrblPzV6 WX1AB6gCUQAdc8s0PTAyEQSqawuzR9oglp4nSAUdhXiw52ukWsTlyBc7TDSHQaiD2wXe NjpnD1WVtSEAnzkCAU2i/dd/gFQoWfyMKzjA433umorQ5JbHHam7GC915nCMAdD80DvC ikqQ== X-Gm-Message-State: AO0yUKUXWx/XWLx9Yl/fyOeylkQ9rUFbnSKT5yUL20pye6vf21e0F/lV OZg02cxxZC2hpKVkDy0PP3NOZTjpslI37eus2e8= X-Google-Smtp-Source: AK7set9iFJoaLI+wB/2r9PvD10PoX7XeL0diRcyehNXT8fAEKRI0yDP9BUx9zW8Gy5OJzIQEOg9kRg== X-Received: by 2002:a54:4f16:0:b0:386:cc99:b9f8 with SMTP id e22-20020a544f16000000b00386cc99b9f8mr10329732oiy.44.1680120565621; Wed, 29 Mar 2023 13:09:25 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 7/9] target/riscv/cpu.c: validate extensions before riscv_timer_init() Date: Wed, 29 Mar 2023 17:08:54 -0300 Message-Id: <20230329200856.658733-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120666676100001 Content-Type: text/plain; charset="utf-8" There is no need to init timers if we're not even sure that our extensions are valid. Execute riscv_cpu_validate_set_extensions() before riscv_timer_init(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index e8045840bd..331272c8a0 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1196,13 +1196,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 - -#ifndef CONFIG_USER_ONLY - if (cpu->cfg.ext_sstc) { - riscv_timer_init(cpu); - } -#endif /* CONFIG_USER_ONLY */ - riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); @@ -1210,6 +1203,10 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) } =20 #ifndef CONFIG_USER_ONLY + if (cpu->cfg.ext_sstc) { + riscv_timer_init(cpu); + } + if (cpu->cfg.pmu_num) { if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpm= f) { cpu->pmu_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120646; cv=none; d=zohomail.com; s=zohoarc; b=MnZ7xEx/Fm3iXTdWiH1Vl4b/JOSXtPD5O3beiq9FRfiimI2NZZLBwdpR6LFIGBy2bQwEofzUKZmjOxDSlE+6akf4+KnXl7F9eOopmLVs9LSgI3opUznIWHFRR8bym9iWwPVKcJmZMDZiV7oEBnVebEzYZdXYmkkdnC98x9dlINY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120646; 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=EIIlw0ncNCgaw7mUOc1O7mXJzdXX4xQn2w71xZ8Nxhs=; b=JhGtQQ4hs0z0NEG/omAjA1N0SzTKHeoBLfRXTG7VC7cDutVY61OhKgo7TyDbmbnV9mGFcDP/yTKC+8ErOU1sG3PektTMOk2oGx496ac7w6XBpAdfr+s3b0DI0gC1oA+0cV4bf3E6H72+yYB2spuoxjBbNiK9jraK3rBcIU1iyVw= 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+importer2=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 1680120646201198.88700730836638; Wed, 29 Mar 2023 13:10:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6u-0006Su-QG; Wed, 29 Mar 2023 16:09:32 -0400 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 1phc6t-0006Qm-Bo for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:31 -0400 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6r-0007oi-HF for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:31 -0400 Received: by mail-oi1-x22a.google.com with SMTP id q27so11811314oiw.0 for ; Wed, 29 Mar 2023 13:09:29 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120568; 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=EIIlw0ncNCgaw7mUOc1O7mXJzdXX4xQn2w71xZ8Nxhs=; b=jmT3Ks2bTqCa8W4zN3x2tlhO5zWWfFYZpCnRvSh2/EpruWi/gxUx6UF9MBShk5It+O tLUsAqkXqSOTYn1ktQv3U1ZP9XCKHoW7P0lUXvysmxA8WpNi26yH3InSy+t2mNtQkwBT bcNGEjVkH7CI5FDnC3g89OON+gQZwGaclof9Saj7EWnID+birXvf2fFFjNCj02cPDQ9S hwQMHe9VlPa9bRX6c44h/H1y6yvBcGtlyujfU5tU3ZeZK4tXDtL39jufDou/obHfwdTw B0mLpRaTGrzEv6JCJrHX8l8zkF1ioLijRCjZxaDbwQ10I46EOFPwpbJyebwr8j4NKQvd D7OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120568; 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=EIIlw0ncNCgaw7mUOc1O7mXJzdXX4xQn2w71xZ8Nxhs=; b=wxmLY2pLO1ynIKER7Ejc9dwj8GGro7uRNnykjvc7BnTtFClWQ7atWms1J5aBi8hXr4 oPceT9mGmdjEJu50AbvyepAsPzDKcIONcM2Jvhf+9hhk0kznrLnIJY0rt+8umpXw17PG 4y4jbkj1w2HxzmzQeJKmo52lwJSbEYFtDZOGTh2pQVoejIRfH3GzlbRUhEWcjheysuaO 9Z5/njMGnVDAPrXAmUazDC9KuO20afNW8fP+bGrNJjwKosmNvBCwfDqKR+6epXDGBvRV A3TsDiLqZh3aucTo85CPEUhcFyDfGbvOymwzhkxypZNCdhPgGebZ41mkKDSc9p8PjAmS LL1Q== X-Gm-Message-State: AO0yUKVltdGzZUfAUOSMZNGtdNQ6o0PDUVgoFr3mnEq9+/1vxRNgm/HE vMAMRaYeU29Qa2u/C/FF7LHqFAx6+mKV4JFZefM= X-Google-Smtp-Source: AK7set8jbVHucPkxzwCTz952d/u/VkNVt+ofeNBBkc3M4zc6kaQ7BO4aLGloH/PJztM4g0Pd7LhUEw== X-Received: by 2002:a05:6808:6190:b0:384:23da:6e73 with SMTP id dn16-20020a056808619000b0038423da6e73mr8014256oib.47.1680120568483; Wed, 29 Mar 2023 13:09:28 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 8/9] target/riscv/cpu.c: remove cfg setup from riscv_cpu_init() Date: Wed, 29 Mar 2023 17:08:55 -0300 Message-Id: <20230329200856.658733-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22a; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120646641100004 Content-Type: text/plain; charset="utf-8" We have 4 config settings being done in riscv_cpu_init(): ext_ifencei, ext_icsr, mmu and pmp. This is also the constructor of the "riscv-cpu" device, which happens to be the parent device of every RISC-V cpu. The result is that these 4 configs are being set every time, and every other CPU should always account for them. CPUs such as sifive_e need to disable settings that aren't enabled simply because the parent class happens to be enabling it. Moving all configurations from the parent class to each CPU will centralize the config of each CPU into its own init(), which is clearer than having to account to whatever happens to be set in the parent device. These settings are also being set in register_cpu_props() when no 'misa_ext' is set, so for these CPUs we don't need changes. Named CPUs will receive all cfgs that the parent were setting into their init(). Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei Reviewed-by: Weiwei Li Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 59 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 331272c8a0..4aa119b9bc 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -325,7 +325,8 @@ static void set_satp_mode_default_map(RISCVCPU *cpu) =20 static void riscv_any_cpu_init(Object *obj) { - CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + CPURISCVState *env =3D &cpu->env; #if defined(TARGET_RISCV32) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU); #elif defined(TARGET_RISCV64) @@ -339,6 +340,12 @@ static void riscv_any_cpu_init(Object *obj) #endif =20 env->priv_ver =3D PRIV_VERSION_LATEST; + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.mmu =3D true; + cpu->cfg.pmp =3D true; } =20 #if defined(TARGET_RISCV64) @@ -357,12 +364,19 @@ static void rv64_base_cpu_init(Object *obj) =20 static void rv64_sifive_u_cpu_init(Object *obj) { - CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.mmu =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv64_sifive_e_cpu_init(Object *obj) @@ -372,10 +386,14 @@ static void rv64_sifive_e_cpu_init(Object *obj) =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv64_thead_c906_cpu_init(Object *obj) @@ -403,6 +421,9 @@ static void rv64_thead_c906_cpu_init(Object *obj) #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_SV39); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.pmp =3D true; } =20 static void rv128_base_cpu_init(Object *obj) @@ -439,12 +460,19 @@ static void rv32_base_cpu_init(Object *obj) =20 static void rv32_sifive_u_cpu_init(Object *obj) { - CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.mmu =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv32_sifive_e_cpu_init(Object *obj) @@ -454,10 +482,14 @@ static void rv32_sifive_e_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv32_ibex_cpu_init(Object *obj) @@ -467,11 +499,15 @@ static void rv32_ibex_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_11_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif cpu->cfg.epmp =3D true; + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv32_imafcu_nommu_cpu_init(Object *obj) @@ -481,10 +517,14 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); env->priv_ver =3D PRIV_VERSION_1_10_0; - cpu->cfg.mmu =3D false; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); #endif + + /* inherited from parent obj via riscv_cpu_init() */ + cpu->cfg.ext_ifencei =3D true; + cpu->cfg.ext_icsr =3D true; + cpu->cfg.pmp =3D true; } #endif =20 @@ -1343,11 +1383,6 @@ static void riscv_cpu_init(Object *obj) { RISCVCPU *cpu =3D RISCV_CPU(obj); =20 - cpu->cfg.ext_ifencei =3D true; - cpu->cfg.ext_icsr =3D true; - cpu->cfg.mmu =3D true; - cpu->cfg.pmp =3D true; - cpu_set_cpustate_pointers(cpu); =20 #ifndef CONFIG_USER_ONLY --=20 2.39.2 From nobody Mon May 6 05:33:19 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1680120646; cv=none; d=zohomail.com; s=zohoarc; b=ZaIju9qIUdw4pMA9qDjOXmFayFQmLnNa6ZRoJoGNuXP0GuhLdfPkZYpSYu2jkzCsM4/pGaHNF7EGfQh2WZlz3a3H0avq0MSUAHzIZ1xgJDgAh+mZsPu9Kf8/63qDbRWvbP26ePXZ8BxtHV13uTjPPBGX+668JeBXDECEaggusU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680120646; 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=Hf1RHp8Jhq31cp8g2H2RGSPQr7fqMDhbwg1uKnWlGu8=; b=eLp9hnhdlnluUktvz1hHgeAfduMy/LZaSkWBf8KvBi17XC8ANkYzYY5Mt9kFZPiyp/83/oufiVmfKTCMhHu9ICZMwqwvKz40z1BlOaoKy6fvF6ncoXSw0WAPmle9JWsBtstIaHOQ7Ee8TFuxVL4iO+HGmwe3+Iyk3mnQimerg74= 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+importer2=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 1680120646176640.3937504496636; Wed, 29 Mar 2023 13:10:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1phc6z-0006Tm-7Y; Wed, 29 Mar 2023 16:09:37 -0400 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 1phc6w-0006TI-FY for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:34 -0400 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1phc6u-0007nQ-KN for qemu-devel@nongnu.org; Wed, 29 Mar 2023 16:09:34 -0400 Received: by mail-oi1-x236.google.com with SMTP id b19so12544029oib.7 for ; Wed, 29 Mar 2023 13:09:32 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id i206-20020acaead7000000b003874e6dfeefsm8195182oih.37.2023.03.29.13.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Mar 2023 13:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680120571; 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=Hf1RHp8Jhq31cp8g2H2RGSPQr7fqMDhbwg1uKnWlGu8=; b=aNXc+A6kd494+iJQtzxW9DDWGgl7fzXX3/v2RhD/eNuNlQqG9/gqfmE6iQEknlzwAK mzd/uRlBCvfxZN2EqHR/Qzkq7l0/YhcRAhgq94AMGKhnRRUieHIfkSyDkzSOz6saF4cD GJ2Ja+mgiuI/GD3IaNDFg11Of/r+YixKEH8JiqH8HtEKqXdPNKBlX2HCOd69qJk8GmXk ylu6T7yd6C0QlAW8KIuJUBYmJaMKZaBDqyzpj2HH5dQhhw2UrFzT+aN/2jXKHml2OJCZ OWYzuF5MlU9OX8Y23bl3wemf2G1+m47Qt6aNB/WY2tzIuoUW2b9fxZcBx6BWZNXQyZtt +q3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680120571; 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=Hf1RHp8Jhq31cp8g2H2RGSPQr7fqMDhbwg1uKnWlGu8=; b=rpqD7HT9q78msHRxrNbtpEm8YbJRRIogNMZjyjM89iovU3sYQazhXnk0ypE3/qH3wH 3QQ2IHNiftyNPOjXpQK7/GHoTa4x7n362ciROFJLWquRMccR1Zos5UQBgysH9Kt9Jem1 a7rZ/coFhaI4MXFJ0JrDLMcjWcaUaxwYAyUyBbEhG1RWGu5lGpyst7zSpoPjMtUBHuSH PminOu9lxPcY5NnUcRKxpSHj/VIGe6P6JaXlG2uiq3izHKKBmIKGYmEHOT4FMgVoTuqY wJrJfEi6BpTxHMsVjg41yHTvVjJJ+tuH8zQpXBM/Ye9NId1yv0He0fvQ2H9BxSOK3lp2 DTaA== X-Gm-Message-State: AAQBX9euDGdYryMrSxPQK9soqTSb8Ry41m32rX0iM3RbF7t3elkYsPtj fwScK8W8CbNTZsh9KQ4bRs1puW4s35cXvMPdtlw= X-Google-Smtp-Source: AKy350aEaoik52wokzi6wr4kMqvwJ9FY/CoM5ApZ8XtAYMXTSTrJQmWZg3qMin+t2HL19ytzjMpp7g== X-Received: by 2002:a05:6808:309b:b0:389:4f7b:949d with SMTP id bl27-20020a056808309b00b003894f7b949dmr4609466oib.22.1680120571510; Wed, 29 Mar 2023 13:09:31 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v6 9/9] target/riscv: rework write_misa() Date: Wed, 29 Mar 2023 17:08:56 -0300 Message-Id: <20230329200856.658733-10-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230329200856.658733-1-dbarboza@ventanamicro.com> References: <20230329200856.658733-1-dbarboza@ventanamicro.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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::236; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x236.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1680120646636100003 Content-Type: text/plain; charset="utf-8" write_misa() must use as much common logic as possible. We want to open code just the bits that are exclusive to the CSR write operation and TCG internals. Our validation is done with riscv_cpu_validate_set_extensions(), but we need a small tweak first. When enabling RVG we're doing: env->misa_ext |=3D RVI | RVM | RVA | RVF | RVD; env->misa_ext_mask =3D env->misa_ext; This works fine for realize() time but this can potentially overwrite env->misa_ext_mask if we reutilize the function for write_misa(). Instead of doing misa_ext_mask =3D misa_ext, sum up the RVG extensions in misa_ext_mask as well. This won't change realize() time behavior (misa_ext_mask is still =3D=3D misa_ext) and will ensure that write_misa() won't change misa_ext_mask by accident. After that, rewrite write_misa() to work as follows: - mask the write using misa_ext_mask to avoid enabling unsupported extensions; - suppress RVC if the next insn isn't aligned; - disable RVG if any of RVG dependencies are being disabled by the user; - assign env->misa_ext and run riscv_cpu_validate_set_extensions(). On error, rollback to the previous values of misa_ext and misa_ext_mask; - on success, check if there's a chance that misa_ext_mask was overwritten during the process and restore it; - handle RVF and MSTATUS_FS and continue as usual. Let's keep write_misa() as experimental for now until this logic gains enough mileage. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Weiwei Li --- target/riscv/cpu.c | 4 ++-- target/riscv/cpu.h | 1 + target/riscv/csr.c | 47 ++++++++++++++++++++-------------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 4aa119b9bc..c025bd77e3 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -937,7 +937,7 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, = Error **errp) * Check consistency between chosen extensions while setting * cpu->cfg accordingly. */ -static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; Error *local_err =3D NULL; @@ -953,7 +953,7 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU = *cpu, Error **errp) cpu->cfg.ext_ifencei =3D true; =20 env->misa_ext |=3D RVI | RVM | RVA | RVF | RVD; - env->misa_ext_mask =3D env->misa_ext; + env->misa_ext_mask |=3D RVI | RVM | RVA | RVF | RVD; } =20 if (riscv_has_ext(env, RVI) && riscv_has_ext(env, RVE)) { diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 03b5cc2cf4..13f6566962 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -575,6 +575,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, in= t size, bool probe, uintptr_t retaddr); char *riscv_isa_string(RISCVCPU *cpu); void riscv_cpu_list(void); +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); =20 #define cpu_list riscv_cpu_list #define cpu_mmu_index riscv_cpu_mmu_index diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d522efc0b6..37fd619b17 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1343,39 +1343,18 @@ static RISCVException read_misa(CPURISCVState *env,= int csrno, static RISCVException write_misa(CPURISCVState *env, int csrno, target_ulong val) { + RISCVCPU *cpu =3D env_archcpu(env); + uint32_t orig_misa_ext =3D env->misa_ext; + Error *local_err =3D NULL; + if (!riscv_cpu_cfg(env)->misa_w) { /* drop write to misa */ return RISCV_EXCP_NONE; } =20 - /* 'I' or 'E' must be present */ - if (!(val & (RVI | RVE))) { - /* It is not, drop write to misa */ - return RISCV_EXCP_NONE; - } - - /* 'E' excludes all other extensions */ - if (val & RVE) { - /* - * when we support 'E' we can do "val =3D RVE;" however - * for now we just drop writes if 'E' is present. - */ - return RISCV_EXCP_NONE; - } - - /* - * misa.MXL writes are not supported by QEMU. - * Drop writes to those bits. - */ - /* Mask extensions that are not supported by this hart */ val &=3D env->misa_ext_mask; =20 - /* 'D' depends on 'F', so clear 'D' if 'F' is not present */ - if ((val & RVD) && !(val & RVF)) { - val &=3D ~RVD; - } - /* * Suppress 'C' if next instruction is not aligned * TODO: this should check next_pc @@ -1384,18 +1363,32 @@ static RISCVException write_misa(CPURISCVState *env= , int csrno, val &=3D ~RVC; } =20 + /* Disable RVG if any of its dependencies are disabled */ + if (!(val & RVI && val & RVM && val & RVA && + val & RVF && val & RVD)) { + val &=3D ~RVG; + } + /* If nothing changed, do nothing. */ if (val =3D=3D env->misa_ext) { return RISCV_EXCP_NONE; } =20 - if (!(val & RVF)) { + env->misa_ext =3D val; + riscv_cpu_validate_set_extensions(cpu, &local_err); + if (local_err !=3D NULL) { + /* Rollback on validation error */ + env->misa_ext =3D orig_misa_ext; + + return RISCV_EXCP_NONE; + } + + if (!(env->misa_ext & RVF)) { env->mstatus &=3D ~MSTATUS_FS; } =20 /* flush translation cache */ tb_flush(env_cpu(env)); - env->misa_ext =3D val; env->xl =3D riscv_cpu_mxl(env); return RISCV_EXCP_NONE; } --=20 2.39.2