From nobody Thu Mar 28 14:16:13 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=1679169957; cv=none; d=zohomail.com; s=zohoarc; b=OKQm2ScKr9JEi+E4OU01U0haEfTloohyaPhBPUJyRn0+10mkfb63QDjMKXfNzapPMSf+BR1khWkuaJc4CG3/wmdFD84cGHIseKaVtbvrTUQU7lRBnjYR0DJ2Wzc9AwaspcvX046tmj0hgD1qRTYciGRXRFuQzlzp5wZ6xt5+pds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169957; 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=NyW3QIKPbWEcW/stEjEFae0dbXr8H0CnZzp+jGMhTkc=; b=kzp0psFyvM9L0ZOPs8i9+H5qTXtGRGg1WbYn1I1jU+uCDZQRL5cx+sMPRuoUzE4FoHoVYCCCBOdF2b0ARjPiGhAHbPvniYZPCUPzuuuLGEgv9AgoTp4ne8jznkBTocEUxQ66uASGgZzjYiwKWh7OakWEF+uk88KT/VG2f35uo+I= 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 1679169957857217.5621092624349; Sat, 18 Mar 2023 13:05:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnJ-0004yF-TE; Sat, 18 Mar 2023 16:04:49 -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 1pdcnI-0004xq-Kh for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:48 -0400 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnG-0006qe-KW for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:48 -0400 Received: by mail-ot1-x32c.google.com with SMTP id f19-20020a9d5f13000000b00693ce5a2f3eso4710836oti.8 for ; Sat, 18 Mar 2023 13:04:46 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169885; 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=NyW3QIKPbWEcW/stEjEFae0dbXr8H0CnZzp+jGMhTkc=; b=G8ExofvWDhtyXrbAoz1uAtVwL+icirHm8bCabNE+JWHPLXluA91ce4+wd2ytneG36q iJ9Hi3O6k07oUo+mxMty5D34ZUhmP704y3m6iPQAnOg3Z+jWGPDGyTb4mC2RR8i9uis/ oT/vJnZwwazNbHtxERoLav3WjC9FaiDilEJKOAGhnvvu4lONHeRWj9eomPDQoLJNygtE xW/mMJHXNUIWAgMppqGu077v9c+rZWEKLhCJOuJDoRB7UzzPlEEb2AIZNwC1pMPyF26Y M81vnCQSjZFj9cYqcPBIcAjw7ItKXN7zkZ8LmCVTBB1wRHj+bZzORcV1I9hz00j4wVHU Ty+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169885; 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=NyW3QIKPbWEcW/stEjEFae0dbXr8H0CnZzp+jGMhTkc=; b=5fnvvmsgSRcaZQGCcL7rEK8yJNN3vBiY4X9O6y9TMpU1CLq4MDl6mk5VHGiYY6Stip uPdZYId2D89gsDRh7d7AZ5SQpxqNcAg2H9pp7dDZHb2tBFlxSxse953t6995Cu2Fvyay R525UFlN517SMzkNmfZjCoE7kB1B7QX9tz0jAb5ZCKv+S+NCyQbimEKeMRYaz0CK7AST kuXjg09qcnBpaqqwUg85EY2v7edejHKJt78bdl54HZgvsD3P+UiL9/7SL9SdTiZmVxsU eFgKfdcBoIcRL7juNoq3EcCnd58IlNq7pbzMMHfm0XR+mNFeMiCtSZNLf2CunS5lI249 7Rzg== X-Gm-Message-State: AO0yUKWRLKKn5S4F+pjjsXFt5s/gQIMJPKx3ZYGxfwxk3TXItel3XjaL LvZd7g+PcDnSTP/EuZJwHfWJ5Ss0fiBwUN9hGv0= X-Google-Smtp-Source: AK7set9eymZLw0/gOoPqYZL3KgCBxbvTYd4yzZEq3m5Amja4UDwF1HDZjfUtjqWt85TrTbswgRj7iw== X-Received: by 2002:a9d:1b5:0:b0:69b:1665:8fb3 with SMTP id e50-20020a9d01b5000000b0069b16658fb3mr1295790ote.15.1679169885232; Sat, 18 Mar 2023 13:04:45 -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 for-8.1 v3 01/26] target/riscv/cpu.c: add riscv_cpu_validate_v() Date: Sat, 18 Mar 2023 17:04:11 -0300 Message-Id: <20230318200436.299464-2-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::32c; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x32c.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169958090100001 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(). Let's put it in its own function and do it earlier. We'll move it out of riscv_cpu_validate_set_extensions() in the near future, but for now this is enough to clean the code a bit. Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei --- target/riscv/cpu.c | 86 ++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1e97473af2..18591aa53a 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -802,6 +802,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, doing a set_misa() in the end. @@ -809,6 +849,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; uint32_t ext =3D 0; =20 /* Do some ISA extension error checking */ @@ -939,6 +980,14 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU= *cpu, Error **errp) } } =20 + if (cpu->cfg.ext_v) { + riscv_cpu_validate_v(env, &cpu->cfg, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + } + if (cpu->cfg.ext_zk) { cpu->cfg.ext_zkn =3D true; cpu->cfg.ext_zkr =3D true; @@ -993,44 +1042,7 @@ static void riscv_cpu_validate_set_extensions(RISCVCP= U *cpu, Error **errp) ext |=3D RVH; } if (cpu->cfg.ext_v) { - int vext_version =3D VEXT_VERSION_1_00_0; ext |=3D RVV; - 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); } if (cpu->cfg.ext_j) { ext |=3D RVJ; --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170169; cv=none; d=zohomail.com; s=zohoarc; b=doYBFrDwWco6ZHbfwfQ7VKOKMvmunitE+thNYcYhgVdwWcELPWmq1Jn04rPZhBFS7g+NBAsvXMlFPHptFBigH0tGe3FxIMPkt1baFcN8YogV/XnQvNEYDv/EGZXSIfG3ve1B7usR71fdwn3fKiYM4ETvi6DfBauWwCsX+M9Dblc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170169; 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=EV5OEE/WdNMUI185IdCQ9kgxw43fPzMUW63mdVe54zA=; b=Jc32FDLUyxohOlEjRCIlfeQJfGmFhk0hMviMXx3+o2LwJGvIdbXZV0g1Uv42pwGQ5a45QlWefkD9dHSmTxKjwAiJz/vX0DF1KFqYUMWoiW/ddJH2d3+fd0HFKM+YfET9h7nnqAZbaiEyAcyDM3YckKyJQwKHeiItnop62BUOcNQ= 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 167917016907076.61932622069378; Sat, 18 Mar 2023 13:09:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnM-0004zJ-FD; Sat, 18 Mar 2023 16:04:52 -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 1pdcnL-0004yX-0a for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:51 -0400 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnJ-0006rA-KZ for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:50 -0400 Received: by mail-oi1-x22b.google.com with SMTP id t10so2436980oiw.4 for ; Sat, 18 Mar 2023 13:04:49 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.04.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:04:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169888; 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=EV5OEE/WdNMUI185IdCQ9kgxw43fPzMUW63mdVe54zA=; b=IpmDUIfCCC2iFnO1uyChREBXD1lfSzcWxEoW23yc1Qn09RCmbPKRdxvlYHGK7TD8pZ oSgg60d31f8zGya3I96fGsmBIdB1Vw1oYK28H4NniJTRHFHVrybraRk1tyY2OaMmCFC7 CRx+5cOfL0lQsNWsWynryDVWOH+tmrT6b98uMHD0lmf2d9BZBHibUl4ISK9NvdqvMSBj aOg84xjnOnletG3fQryJaQvhEAo3P7wLBse+w6YcDbAOihDevMJo0LwN7AV6LwPDut6x fGtbe8RRQzj+HNLjYARAK7/Lf26xQgtaVB50oP4/iiU5/fKHXukZbvIBz9lDtnl9XgAS QzzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169888; 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=EV5OEE/WdNMUI185IdCQ9kgxw43fPzMUW63mdVe54zA=; b=0LzKvqDfuJdZjBBrB3m67sazDObpFITEzzeD/eaiFYM0mwqMHyT6sqN2KAcPnDC70w 2+5smW9SOxVsdwVRe42X0YRVn/TK8VM/7Mo/ns+W1RvPOOwhvGCtVIZUywqxPkUB4P+n ingMo/u5tgIW+fbWgwjxHCepFEJaDho6QpeJV8NSIVcSrWM399vo1/NuPsI6yJ6JybZx tYJoKAAEIWMCBHNYvNqAjGt5IrS4/C7eiDyVJIbaOLggbTahWnk+yzFqX8fUyPaBpgc8 jLzGgKXj7UqKhDr4aJRAXNn0Bs5xr6uFiAZPdSDlx4OVv5G2lnf/3m/WDH6wqLWxUY3n cFNA== X-Gm-Message-State: AO0yUKUBLn+wdEBMlL5o8Jb5nADw/r/NWcN3KodXc86C61gVxNpm8wee EUn8tkijDZvBO8/mdarl7fq6yqKv2nPAzNvlSgA= X-Google-Smtp-Source: AK7set+xbJlhLjLE3Xpcg+tJbY/gKyy/PGNW2E2jQvFD+iQfV3FJZcg7VpTIZ8RQUvP4Uz5Sjin2nw== X-Received: by 2002:a05:6808:1912:b0:386:c5ad:16ab with SMTP id bf18-20020a056808191200b00386c5ad16abmr5793344oib.10.1679169888057; Sat, 18 Mar 2023 13:04:48 -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 for-8.1 v3 02/26] target/riscv/cpu.c: remove set_vext_version() Date: Sat, 18 Mar 2023 17:04:12 -0300 Message-Id: <20230318200436.299464-3-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22b.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170171099100004 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 --- 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 18591aa53a..2752efe1eb 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) { @@ -839,7 +834,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 Thu Mar 28 14:16:13 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=1679169960; cv=none; d=zohomail.com; s=zohoarc; b=TPdU+mV821/W2zRdRk2tjDo1bVfda2hMwNxGTOeYTh6bS5taIJaJj8wDq+TAfqI8zYVUpT1ohsqXCtmu6QD65Oe3aRB/P99j5Dc7T1PojlcGmcpHwpU8kyRokMnHVZpm4XDvIXGRDP1nzGYrX0yUwkUvrqEPOeKCR+tLizy189Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169960; 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=y4yZ3wAir0o7gPbOYm0TNhTOmu7uQyMFvLvYKMxOY/Q=; b=UVuDohYm+JpdIqXgZhK2nlP8kZhzIhlXLaUisdC2oSPlIR8tDBRhNgI3eUscjftWsfTBCu7KhcIuoGkNtLes9NZIi5mgDf3uTUj7fhwxXX8mhtZkjlrId7eyzfdypqOoNgPW8ssEmKnmywfzEWN/cfB0NcZLReUhAI2PROks0Lc= 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 167916996077111.54707388070699; Sat, 18 Mar 2023 13:06:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnP-000505-46; Sat, 18 Mar 2023 16:04:55 -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 1pdcnO-0004zn-75 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:54 -0400 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnM-0006sR-I5 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:53 -0400 Received: by mail-oo1-xc2d.google.com with SMTP id a23-20020a4ad5d7000000b005250867d3d9so1316149oot.10 for ; Sat, 18 Mar 2023 13:04:52 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.04.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169891; 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=y4yZ3wAir0o7gPbOYm0TNhTOmu7uQyMFvLvYKMxOY/Q=; b=JHXxwfFdISGmN88zfIlQqIIBLyRzzOn4COQDstaKyyENxVj/XeET0ZvmtPm58y3WQl czn+pu/vNknNeAgYngluA6oGEET0SJww28wPXjNrMPO+CKk2en5a62iwk/Muataq92Jx iL0UFyTeUk77O4tuKFkgAp9qXb6duO3iMXpWMd0nBskb/xdwt6Fu02KORN5KkMySSMkq UJDzngDA8r4YB7Db6xhpMv6NTOkV5GEzPr9+y+ZlVLgDAOSig3OkMRTti5V2dXIVDzwD JI6sx3pcQKOJFx5CgBBxyD0Zk1I7WP35ZfJHQoBGexHpYeaEke+dKbduP0kWAPXGVDJv 3b2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169891; 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=y4yZ3wAir0o7gPbOYm0TNhTOmu7uQyMFvLvYKMxOY/Q=; b=Ed8vf4yjo6NRghsPp7gzvMiW3bparQ7CxWVpCz1mxjTDByo/FDS7k/vxjsECtDzeI9 r/JpWQw5EQh0C58Bd5naYB7Db5ubxe9KZIvPBD99fz0pueH2fmm6RZfuEoA1RCY+398b FTOlqebQt5vzcVrnm9XymQDTDrKxTPBaHlcyKFmG5Ep/cM0QXo+iChcMYRfgMCjRpMqZ q++GrjbDB4CBenXkm1ZIZwF/Yr5OfPdmukplZxcm7aSg6aXdPsq+DDlb/jyUFV7fnm6O gjOqsnGcwyZKXapcBvPW7W/f9wR1UANEtsa2CBmbYBwN7jWS0E5iCviIA3UbbtTz9kWs MNBQ== X-Gm-Message-State: AO0yUKVg6QF1spF3oeh1Vaeyw+/Lytbq90Mb87lTb7FX8oe8xslEhap2 JphdLfi5iCcZmhO3eSiA35G49+eqRj+O35E6dBA= X-Google-Smtp-Source: AK7set9yv2apBXVLffXYemSooXH+fz/i0UuySHOUrRjyAu5XW3kuwNBh/ieX/ILFj0GVaLP4OX/ccA== X-Received: by 2002:a4a:378e:0:b0:525:36b1:86dd with SMTP id r136-20020a4a378e000000b0052536b186ddmr1423612oor.7.1679169890956; Sat, 18 Mar 2023 13:04:50 -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 for-8.1 v3 03/26] target/riscv/cpu.c: remove set_priv_version() Date: Sat, 18 Mar 2023 17:04:13 -0300 Message-Id: <20230318200436.299464-4-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c2d; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc2d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169962146100009 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 --- target/riscv/cpu.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 2752efe1eb..18032dfd4e 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; register_cpu_props(obj); } =20 @@ -355,7 +350,7 @@ static void rv64_base_cpu_init(Object *obj) set_misa(env, MXL_RV64, 0); register_cpu_props(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 @@ -366,7 +361,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); register_cpu_props(obj); - 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 @@ -379,7 +374,7 @@ static void rv64_sifive_e_cpu_init(Object *obj) =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); register_cpu_props(obj); - 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); @@ -392,7 +387,7 @@ static void rv64_thead_c906_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | 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_g =3D true; cpu->cfg.ext_c =3D true; @@ -431,7 +426,7 @@ static void rv128_base_cpu_init(Object *obj) set_misa(env, MXL_RV128, 0); register_cpu_props(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 @@ -444,7 +439,7 @@ static void rv32_base_cpu_init(Object *obj) set_misa(env, MXL_RV32, 0); register_cpu_props(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 @@ -454,8 +449,9 @@ 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); + register_cpu_props(obj); - 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 @@ -468,7 +464,7 @@ static void rv32_sifive_e_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); register_cpu_props(obj); - 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); @@ -482,7 +478,7 @@ static void rv32_ibex_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); register_cpu_props(obj); - 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); @@ -497,7 +493,7 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) =20 set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); register_cpu_props(obj); - 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); @@ -1160,7 +1156,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 /* Force disable extensions if priv spec version does not match */ --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170018; cv=none; d=zohomail.com; s=zohoarc; b=RQqGsa5MojMYQCl5WakQNU0jS5fVL9749EpfUIvlMdiNkuHP6p9+zfRtJt4NGtO4eB2d4yJs4hdGhW9gX8o1xIbdnGelpMHD0lly4/jR1VYTkeulCYQ5MsQg/r8P+bu2olXx3PN3gRnf13dFT+K5rTYSHpmw3UIDafDttIOWhS4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170018; 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=4rTzH7idYU1tgJNSYCPX09c7tPogRTBHBl05b0u1Jxw=; b=ZebaLMSN6wPpGJDhhY3WEZzWMD0vBWRBmnwI5ROFwxyG4M7zm916FRS3Na4nQ7ZWx+Yi/Om3wCR8qW7WcGjTX0XNSYBSZ63VuYMAFhascKzripcMBXOy3yPB8hu/goVGiTbiDCXWBUPB+GYkEmt77V4ifme4m3nvVsQsugHI7Hw= 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 1679170018657687.3003384322145; Sat, 18 Mar 2023 13:06:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnT-00051X-1S; Sat, 18 Mar 2023 16:04:59 -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 1pdcnR-00050g-2K for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:57 -0400 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnP-0006sx-A5 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:56 -0400 Received: by mail-oo1-xc31.google.com with SMTP id x18-20020a4ae792000000b005376d6c9cfeso1260085oov.3 for ; Sat, 18 Mar 2023 13:04:54 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169894; 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=4rTzH7idYU1tgJNSYCPX09c7tPogRTBHBl05b0u1Jxw=; b=JtahI04iRUgUc4R2dh4lvVZzkWZFl8YYM22WjgCAcVfTmqIOEzKQLdEh2iLA2Jj773 AnZvbK6r+XlwuzUqZgUL90RO4Zq359Wzeuh2aNF7nA7G0/jIPloXQ4b/V4Q/F6LnegGB a1Q8qvvnKFGUFB70eAgFaqOHTH2KxAxAUQWgTPIIg6kpACd8uYkZ9lgEokgr6DmzZqlX 8qHiipjxn16oPlW3BcGMx3ddU9YE4sGtcEZWCpp/tGbTg0MaiQMYyaqH2l78uVlAQ9js 1i+W+jhuvOt5wC3EFY9bZe2bFlGWaa3aL1Qz0OivWJWa6OOkfciv75Ud4/Pou6TgjDoN otsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169894; 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=4rTzH7idYU1tgJNSYCPX09c7tPogRTBHBl05b0u1Jxw=; b=YyvusOIoCQptCXv82Ky3GdO1Q2bNbcFauoU1l/iKV4fESbmHP2dNIyM1o4kWA/TvQj ohwwaacigzS+gEvMKPxmU3Axs4fbWraa5TNWlFNEItqEMbQGs3aEYBjd3L9D9/dXCBhq 7QMP7fCggxo/Lrpcs0z9OuxVJ6RXUdDiA9r1S0K2SzmNPYwwCK28juHoOTbGA8h3sSI3 s2uvMJ8Q8g7oBBwuu1bAV0Ktn78In6maDzcX5rg4xiPo6TmEVS8FlFkxnJKP6xR4evc+ fk4ei9kZIJ34h/cNLoRFHepXS/esOXTRwxXWA2eFTAIbUz+kCOnl5fN83oOT7Au0+Q+g BG0g== X-Gm-Message-State: AO0yUKW58cl34nc1W5/gXEe6Itw+NiMjlvw1xEAvz0KfhpEd0YCQhLtl +URCvOi4AFX7b9zXIUU9kz7I5ClVsV1AivVxHos= X-Google-Smtp-Source: AK7set9K187HEkKDbq1Fp0+GvsbCxZL/oXPicQzJquWkfr/nU5ldIHlv8pZDsVtbKK14fKjWFw5oFw== X-Received: by 2002:a4a:9693:0:b0:536:6493:2434 with SMTP id s19-20020a4a9693000000b0053664932434mr1266067ooi.7.1679169893948; Sat, 18 Mar 2023 13:04:53 -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 for-8.1 v3 04/26] target/riscv: add PRIV_VERSION_LATEST Date: Sat, 18 Mar 2023 17:04:14 -0300 Message-Id: <20230318200436.299464-5-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c31; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc31.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170020365100001 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. Reviewed-by: Richard Henderson Signed-off-by: Daniel Henrique Barboza Reviewed-by: LIU Zhiwei --- 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 18032dfd4e..1ee322001b 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; register_cpu_props(obj); } =20 @@ -350,7 +350,7 @@ static void rv64_base_cpu_init(Object *obj) set_misa(env, MXL_RV64, 0); register_cpu_props(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 @@ -426,7 +426,7 @@ static void rv128_base_cpu_init(Object *obj) set_misa(env, MXL_RV128, 0); register_cpu_props(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 @@ -439,7 +439,7 @@ static void rv32_base_cpu_init(Object *obj) set_misa(env, MXL_RV32, 0); register_cpu_props(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 638e47c75a..76f81c6b68 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -88,6 +88,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 Thu Mar 28 14:16:13 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=1679169923; cv=none; d=zohomail.com; s=zohoarc; b=mv2J/R/+XcGvIv3qCshTilQj97MRSsMEhSVxjDhkj4nYo4E/rgF15JFF/72QIjGOLvyjZ48wurI5zkzWgQMnLRSttzu78S2BZ3z3L5DN8Me3A52uEVb4oCS33tH2VHrb4V5Nh8gAWEiUTc5rjLAGhYeXFUoNPLfPQkimDOEePME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169923; 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=9X/RtTs+28g3ykhi3pLH1l3iYUDqblx0oOtf2WwshWM=; b=HHNyX4VX5EAQ4FUF02GFfronzGN+YppvDT1oPz+P86Y368wPFVxBLcdmq2FoP7joUqH6un0yCTT6zb+NTfTMVbbDxNl75Y0GhcQZBDv/Eb3DVacs0x9IuIdsFCNLPBeH7uC9m23Enq9baGNLGFpBR5hICZrHSkKdLpH7gIB89NA= 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 1679169923387183.8501035346195; Sat, 18 Mar 2023 13:05:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnV-00051t-0S; Sat, 18 Mar 2023 16:05:01 -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 1pdcnT-00051Y-Kl for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:59 -0400 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnR-0006qU-Vu for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:04:59 -0400 Received: by mail-ot1-x32a.google.com with SMTP id w21-20020a9d6755000000b00698853a52c7so4706924otm.11 for ; Sat, 18 Mar 2023 13:04:57 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169897; 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=9X/RtTs+28g3ykhi3pLH1l3iYUDqblx0oOtf2WwshWM=; b=btFvX3a2ozNIIR9l6QhRXb2vjiga4zfhjgcm+tFrutNWOVuCECpe+rXLOkIK1JXJWU MV9cCElahrxKLkIfOB7iQZxAhsBJFR0rGxWjJhXffRsXcHFigWhyUiWHUngIoVCWqJVX 7G5MLxiw6b/NtBGD4/6kU+PWQfMraBf5ZEzDa/TptuSMSGGdK729lzy/yomFv+sMCxEK Wjv/PWrx7lwJu/gDEbx3rqW1DjTM4dqv1p/pfrO+r4waxryjUN+meSdAKS3hmH4tqm+U U9XHroVzMGE4gNDB54Qsc9hJETpisQEJbnlT9r1Fr0Yuh7BL5VqpnijQAD+vGLz0VEH8 DuJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169897; 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=9X/RtTs+28g3ykhi3pLH1l3iYUDqblx0oOtf2WwshWM=; b=mfb3z7FXXk0VqIiPJG77IYB8F1W1fsChHlmkQLH9bgYB9ysOrsNvivKZUpbWdcIgow ri3RExHbwBnOsjda+P0xriAWNqm2zWNutyktbriJiLQbh2v2eK5KTcNuHoKBh+S8pk3Y Gl0vd0pYoF4xhy5ONfK+/TtdB2KWsk7eQopoplZZcW1OatVS2fwQCuLoSxzSgHkqFLpz g+0ZdDC9oLbKpIVO6ztJG7Dpf3L9vuhdhkrcZ69fZ7qYhFKBXQZI37XrzXmwPaQCcKZQ qCKm7vfu0HBiI92QQBhrsD5TNPFAQg0YthqqIB1dJzZKGMtKvi08y0p4a1janu7ddLVc 4OBg== X-Gm-Message-State: AO0yUKU27dfAuIYUsgB0Ny+C4jjNGPs3uCy62mAv8yOh8QGGKzxMHjzG 0hCQUIGnP1ZKCqlIEga369qGknWRhN5rlJ07t1s= X-Google-Smtp-Source: AK7set8zV9pylaTcYQ+zMB3lC1FyXnYk00ONiXzg6u1vl21R1Bdu+qnYEXFL4epR38iIPjt8omts7g== X-Received: by 2002:a9d:6b19:0:b0:694:3972:dbae with SMTP id g25-20020a9d6b19000000b006943972dbaemr1558266otp.2.1679169896838; Sat, 18 Mar 2023 13:04:56 -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 for-8.1 v3 05/26] target/riscv/cpu.c: add priv_spec validate/disable_exts helpers Date: Sat, 18 Mar 2023 17:04:15 -0300 Message-Id: <20230318200436.299464-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::32a; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x32a.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169924853100002 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 --- 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 1ee322001b..17b301967c 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -833,6 +833,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, doing a set_misa() in the end. @@ -1002,6 +1048,12 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) cpu->cfg.ext_zksh =3D true; } =20 + /* + * Disable isa extensions based on priv spec after we + * validated and set everything we need. + */ + riscv_cpu_disable_priv_spec_isa_exts(cpu); + if (cpu->cfg.ext_i) { ext |=3D RVI; } @@ -1131,7 +1183,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); @@ -1140,40 +1191,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; - } - - /* 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 - } + riscv_cpu_validate_priv_spec(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; } =20 if (cpu->cfg.epmp && !cpu->cfg.pmp) { --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170061; cv=none; d=zohomail.com; s=zohoarc; b=GSFlNkg1Gfw8YyAL4+EXwi2kdum7xaNRNs5rd8JTlngzjtrsAr1LGiRQm3xNUDMZ+GteZt1f1CYgW5+iHs49R9w8JsH8NjNpIyKAfb+owyDI5lyd/ujlJa6XK7Ur6zLYlh3qzSfasa4hbNFqTkl8VWByGZLkzbthzE01VDAtsNU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170061; 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=edyvksieWPeu1SW2+k+C41ShJ9HM1xvZ3+am3Bxgf3Y=; b=iiK7oK2Bt8lUxg2TKQBwVkByHFvpRFVMrjbsX6MMn02L4Equyz0OglW6CrQeXPX6bq/xu5nweM8yK/ZCd9AxwGn4p2iBDenuTbpoEz/Lggv2D6qQpW4Zfg72epiacfG4I8aTrv36GzCc0HUjM6NAPOR2KlH7joipYFX6ZLAE22o= 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 1679170061661638.1763593757524; Sat, 18 Mar 2023 13:07:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnb-00053y-Hm; Sat, 18 Mar 2023 16:05:07 -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 1pdcnX-00052h-39 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:03 -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 1pdcnV-0006v3-BZ for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:02 -0400 Received: by mail-oi1-x230.google.com with SMTP id c11so6225131oiw.2 for ; Sat, 18 Mar 2023 13:05:00 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.04.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169899; 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=edyvksieWPeu1SW2+k+C41ShJ9HM1xvZ3+am3Bxgf3Y=; b=oXTpuAEvZNL8NEhbZqAFx7HLAmYSUvNkZNpRkVqN4EGYfvqdf0piJiZKXa22DAxR9w j9uPWqOoQaYaErh3S14zMk/okxR1/iZP3PvxCjNrVdyTE2jPE6lBEiCvv7t/R6Dp5sMf neOiOvVoaCZDJh6Bdt/J6JCNTApzy0jtSSz6fsnl2eRuQBE94yTzUKHkSVmDk6G1GtBC +C6jEV3776884eJxH4e6NcW6NZC5MqTEZOadIXSmCkeVfmN7SFfpVvln3AGh11ppAtAb fy9Nfom56yIjs9ZviBHp4rZVlMe3zv3LrlaT7pKuKMuSN5ZD25oiK5fAroiQlr9YWPCY EbzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169899; 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=edyvksieWPeu1SW2+k+C41ShJ9HM1xvZ3+am3Bxgf3Y=; b=UA4pVbdqJqwnzFsVGvr3wjl59HX7vvq0W383xRWRPGHZTAFZziOdQMKHpBEDquIHcR SY7WSUqC2o/WgwmEuf7uQl+EGSEU/U5FGSnuQIpMNDQa6ZMsGU8r9Qzmq1HnMT7oewMO aAFaeqZB6nBezkS5F6i1+tmvzqxGG0uvXjIcEJIi+ypwJFWw3n2hL6ER+7kRpcf/jQGx 6Dqhc43zSoGzfdXProtZnfnLCLSe34kxt9R0KBdlYMDMLr7SHewIZtGefTt+eqRs8AJf gfR1uVeo0sIdwmC8mYN5wOwPD2wm3u81VejxxoiiCqJlXy8YLsyuGirVfqq4ovJpyCSC rQ5A== X-Gm-Message-State: AO0yUKVNixpAAymFb+jsblK5q+70EFNlTBNEGWjjqVftXQzBO7KwRZ1k k19spjzqCr3nypAj/LYBYB6Z0O92FQGL0udO11g= X-Google-Smtp-Source: AK7set9PF6y9rYrA/I/l+jUYLAgZpaLiZumLaIBoZzlReP5zTNfnBRlRubOX7hdSyTERlO6pcHl0qQ== X-Received: by 2002:a05:6808:2a8c:b0:383:c945:124e with SMTP id fc12-20020a0568082a8c00b00383c945124emr6666371oib.36.1679169899748; Sat, 18 Mar 2023 13:04:59 -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 for-8.1 v3 06/26] target/riscv/cpu.c: add riscv_cpu_validate_misa_mxl() Date: Sat, 18 Mar 2023 17:04:16 -0300 Message-Id: <20230318200436.299464-7-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170062671100005 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 --- target/riscv/cpu.c | 51 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 17b301967c..1a298e5e55 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -879,6 +879,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, doing a set_misa() in the end. @@ -1180,9 +1207,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) { CPUState *cs =3D CPU(dev); 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); @@ -1197,6 +1222,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; + } + if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available @@ -1213,22 +1244,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 Thu Mar 28 14:16:13 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=1679169982; cv=none; d=zohomail.com; s=zohoarc; b=EFBQPhddBbJS/P6rgx8tg9s4L5uJsHxIUg3b2n/dRmwvoJpsVC0NaSEgNI6QRGFqgXrU7LGrb5EbVqEWBNaz1yVdWdoisP+CduPImYNV58ldjZDHmWbpzQg/oxvX1J6fDc387XcUTC/vDH8gANSYZcOA8QvEZX4FFN48doZrcTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169982; 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=x65YaMF/q551T09YOmWRrKe4JEANKzCqnWd/M7vc3rI=; b=j9qpdlmDWdZD3+gh4319TqE5INx1Bo/uQxQrZYdT1vhPyN0Bsj90kb5OmTAeu7XJ9mlKwrJX2RlYXsJAcADq/22/tSWkzWjf1o6qayfIFrokAvbDU+oFQGZm9JGKtkDIR+a9/TCqNS4XzZGIGIBzRjL0Nl2HaqXX6nNNNneuWUk= 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 1679169982594905.8916839060774; Sat, 18 Mar 2023 13:06:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnf-00055V-Iz; Sat, 18 Mar 2023 16:05:11 -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 1pdcnd-00054R-FS for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:09 -0400 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcna-00071F-Ky for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:09 -0400 Received: by mail-ot1-x335.google.com with SMTP id p11-20020a9d454b000000b0069d8eb419f9so4292010oti.4 for ; Sat, 18 Mar 2023 13:05:03 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169902; 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=x65YaMF/q551T09YOmWRrKe4JEANKzCqnWd/M7vc3rI=; b=WDZm6azOn6uOfqOOcJs0lPQuV5/BCwdx0DzFUIoDyS2FJBOqaJeqD9OF9Esk0mJL89 g5fTSeweyvMUx1qlYudPzwSFnS9qwgB5J8BgBWBipqHhettxypdhbvG7H7ci95+zx4d1 Y860YAy3mVfxIvm3tVbtV1H3d59RAB2k5ZGtaoNCYXQ5s6irJZMXDoUoHqK3+qW+bwS8 5C42lDRWCafo7LA62ljYPq9AD0UNxAdz8X0ZqA2/arTzVaVNMlGV3BosGyxckKPl3QxT Tj0Q7QsbpRKFDlKA8N9fcPb40sSHyqY+ue4r+dD9wZwOnv2L90TRA00LVtnn6NMKlZnf 0vYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169902; 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=x65YaMF/q551T09YOmWRrKe4JEANKzCqnWd/M7vc3rI=; b=GZQgqXKNbq3j0sL63hKzApGCAcKtB/PfKl+iaH57mz1zX/URu3pU9ljkRKqw6bb0Y3 G+fUfJE+/jHkIvidlf2DkpbRFOp8aAsVOOOwopNETbpoYZ3dET/AzE6/CtxBwGZ4xx/h BLj64jZ5FoKRRB2mzlAYK5h3uCod0mXsesBgwV4j2+uFy1QDnWjCab0eKkDu3AVHF2MY d+LrwplqIqIqY6qShDf20AqqLCec94GfjGtAJUAWDPnKQQGDM9BGIWiUOrFrU8NpiRHk dY42S42yRVBLKwX2RkXm1aTEqfXHj/LgQrSnPFUyJYoyuqMgUa4W4386KcmOk1CxgeIi dq7g== X-Gm-Message-State: AO0yUKXAA1g03aE9My8iuLS3ZOJs46AxnqqvdUCHNBFqxFM95s2WBGIc ubhfpDr5uzfgztbDFAPkprqK6jzO7x9rMUGRz4g= X-Google-Smtp-Source: AK7set9r843x8X3HshSBomOql/15knkrNkkOzmGnxugOq1ZPIX8wi4LUjotWn4+4RKtpn0uuHEJ4kQ== X-Received: by 2002:a9d:7412:0:b0:68b:c42c:700e with SMTP id n18-20020a9d7412000000b0068bc42c700emr1367903otk.4.1679169902744; Sat, 18 Mar 2023 13:05:02 -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 for-8.1 v3 07/26] target/riscv: move pmp and epmp validations to validate_set_extensions() Date: Sat, 18 Mar 2023 17:04:17 -0300 Message-Id: <20230318200436.299464-8-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::335; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x335.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169984197100003 Content-Type: text/plain; charset="utf-8" In the near future, write_misa() will use a variation of what we have now as riscv_cpu_validate_set_extensions(). The pmp and epmp validation will be required in write_misa() and it's already required here in riscv_cpu_realize(), so move it to riscv_cpu_validate_set_extensions(). Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1a298e5e55..7458845fec 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -916,6 +916,15 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU= *cpu, Error **errp) Error *local_err =3D NULL; uint32_t ext =3D 0; =20 + if (cpu->cfg.epmp && !cpu->cfg.pmp) { + /* + * Enhanced PMP should only be available + * on harts with PMP support + */ + error_setg(errp, "Invalid configuration: EPMP requires PMP support= "); + return; + } + /* Do some ISA extension error checking */ if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && cpu->cfg.ext_a && cpu->cfg.ext_f && @@ -1228,16 +1237,6 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 - if (cpu->cfg.epmp && !cpu->cfg.pmp) { - /* - * Enhanced PMP should only be available - * on harts with PMP support - */ - error_setg(errp, "Invalid configuration: EPMP requires PMP support= "); - return; - } - - #ifndef CONFIG_USER_ONLY if (cpu->cfg.ext_sstc) { riscv_timer_init(cpu); --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679169942; cv=none; d=zohomail.com; s=zohoarc; b=Rz1FbbYmZV3Mn0S/vJyoNr3Jgn7cJsyBFsrqapA9BlMXI/or1lxJCDCfDFaRxhV3+PJeQUrDrK21VVwHGTCIzMoUtkVbVHh4EnGLxJKEJ8iHBGJJwkJWwEii+gLW/bTxWW/UKIErxW7eispZYKUEOWDOdLKsrMH+dM8/zHbb7ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169942; 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=jEPTSkB86BpaaFtLEftxltn8EEKuvxXM6fE3vNx61Lo=; b=aEEfo6e/hXDbG5zJEVlMIE8l+j+XCgJuvCmjObh5ebL0nwa7Wxb2fKZ7JYmhtEOxomjfG9bvUZLupxQJghbjYw384ysK3fBUSenwAM+M9yiEoU9k+eN+BhjbY2CllvU32mFAqVe2d5hpBfqIbn5+UjQ5ZRNumGRkStKfqBDboJQ= 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 1679169942455935.4071771280426; Sat, 18 Mar 2023 13:05:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcng-00055p-QC; Sat, 18 Mar 2023 16:05: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 1pdcne-00054o-LF for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:10 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnb-00076X-5T for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:10 -0400 Received: by mail-oi1-x234.google.com with SMTP id r36so6207495oiw.7 for ; Sat, 18 Mar 2023 13:05:06 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169905; 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=jEPTSkB86BpaaFtLEftxltn8EEKuvxXM6fE3vNx61Lo=; b=TDDlvkp56ov3KIIHPlwZxNuiE87wOJf0PYPwXwb0XfAhmlqmDKEj1692eOnP5ehQMG NKhQ7YG6HPBGdM0gdspVNJzo4rgMSiFIaRcP4a2UAPrCWQl328GcJrQZ0VKkNnAX0dC4 s07juJFqiNrr8k5396eVZ1g7E2udYzrqvDz0WiZT4Jf8c3dkhFkToSMASC0G1auIpdpM /fwPwEYjsW9lW+zWHbkf82byWLDhUSDTKBaZCLpPutbMC3XMDXcTxBXCWI0ht669XE3O V8ukfKITIw1K/WM6xLbSRA8OEbmj+NStkjDIjvdMivF00flNyHo5PqXYY+lWgD+LCROi gPng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169905; 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=jEPTSkB86BpaaFtLEftxltn8EEKuvxXM6fE3vNx61Lo=; b=gEJcQ70Kh0+QJZK7FcRnsZSlZOei8YFHVHBDTIi7+H50tnZSAGljhVb+xm6Te1/RhP ETBpc0gKfPfouyS4mCdeRHsSrMHNlggiNmqOoy5C2Kbjyru1wJ24PPxW/akfuZl074h2 Z5Lbz7OOjTft3HcHVwuihelB+iNTmhN+S66J3cTruVONkLx+PvonezRH7r44xMBnEX09 Y4URJl5YWZ3XAuY7fRvtHVBuM9ZvnCbWjc1FVw3m/BI+Y6D14UUG3IBXsn8KGfQNf3k4 UthLcLFqxm+aOC+ADAKT7+gqH5Nla4uRdFJvN+cWj/Lc3z3ZjO1KGos4Hue6w27MCiLJ Ta0A== X-Gm-Message-State: AO0yUKWfFNbAb8+Np/Ozqe47eLBvOEQRtTSuyaAcq1H2CJODu3PHLCNU btIpF6Y1fVEaunVR20xILrnbh8dfxpiZ98TAsvA= X-Google-Smtp-Source: AK7set+8OZMuZrhaWKjkioENyu81i8Ly80Fc+V2AGZqYMXA/LA96yokoVxKYnHJX6afKBZyMX3yfZA== X-Received: by 2002:a54:4498:0:b0:36d:f6c4:1860 with SMTP id v24-20020a544498000000b0036df6c41860mr6115865oiv.34.1679169905650; Sat, 18 Mar 2023 13:05:05 -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 for-8.1 v3 08/26] target/riscv/cpu.c: validate extensions before riscv_timer_init() Date: Sat, 18 Mar 2023 17:04:18 -0300 Message-Id: <20230318200436.299464-9-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x234.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169944238100003 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 --- target/riscv/cpu.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7458845fec..fef55d7d79 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1237,12 +1237,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); @@ -1250,6 +1244,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 Thu Mar 28 14:16:13 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=1679169959; cv=none; d=zohomail.com; s=zohoarc; b=AVqEZpYvOAd/N/SrMuOfH7yUO6H4Ji5jnABVk4xpoNLc97C52qPU8y8o7IQKvwWT9LyieqX43SKp9gASobUVe+zv0KtRxl7BNMQLBkIpPbsv8TnXtJISDvnq5zaweZh0Or2OpJabScUzr6BGwvoDWGB8eF4q+KJ89pCuebNaDvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169959; 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=1LxDIouyTmW6CIiqQuxLm5ivPOp4dewieXsHrUESWZw=; b=iD6/GJQ0I9+gAZCMagoUoNM2PhDi1wOIJ1tT2fUiHwcClnXAif0OBMul0lvIJh7QddPbkKzo5frwUdkxukKA2Q98dzDsfpYlKJBs1Na+KZcunT0EzGOcjwE1w19q4xc1x4hmG/L3GWp7eN31A/UCwOFjRwJP5oh5nXSZle1+Q0U= 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 1679169959024782.2102823780021; Sat, 18 Mar 2023 13:05:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcng-00055n-Dp; Sat, 18 Mar 2023 16:05: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 1pdcnf-00055W-Iy for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:11 -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 1pdcnd-000776-NG for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:11 -0400 Received: by mail-oi1-x22a.google.com with SMTP id bo10so6201352oib.11 for ; Sat, 18 Mar 2023 13:05:09 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169908; 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=1LxDIouyTmW6CIiqQuxLm5ivPOp4dewieXsHrUESWZw=; b=PNeFx6YszROUxSpeYcRIeowUfrJZGyq7HS5A5ZXEqDJeNcHE94/yeEWaoyX+Z9ggaF oyM21vySe+lRJ3hYQtGzGlCtFLb1NkSM5Q0SYhCPtF+R5634Y/S36E9g+J9/9CCLorPk DvdihUPzu/yihmDsvQobMVi02Ap9zNuv84y0laEpOV/DZkzMVs6vx75yrbtLKwuE7YvF nj9AO+3CD6VUH/CKEWD8CAVlS3g9ekWXjZOu9/Qpt21zgENHKeNMz+I68+GOpq49M8wv QtWQaW3ritMsnUUEy3hyTLgF7EPH/ByNQKXGesUNEF4nIrR9iPWrloVxCial7DYYIpEv xSHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169908; 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=1LxDIouyTmW6CIiqQuxLm5ivPOp4dewieXsHrUESWZw=; b=uWnvKAmicDfowi4vNqY+dy7kyPGMq13FjLqtYfCQiJfVRwxoaSQ7sbSpcDmnanGdfj OfgzhwZPmuo7GJHqEGUN5TKXl25GLGzWkgbP9sDOgAUPRqgF3NGzAQR9JIWPHBO9xe5p 3LcDte3y9fFgnCLZPfgYtjTzcXK+AIfdxGdZq4b08oS+DHiGZVwqC8urNHPHXVNqtugT mX/dBEHmd6A+IWsV6dCPgmvB/0TBVAdIGGP151UKDvq5BvyM38yjozB46Z6btnNRgsZR 3FpKQqOerLYQqyCkisX2okD2t9Fi9ydMqNyzngZWRHD+e8O2Ihs0vQi1vHIo9SeZySyj IW9A== X-Gm-Message-State: AO0yUKU1oQu194J14IjNdHc7CdCyqVOEuWowm5NejUYeuAKWEpBh7uS6 GvOPnddggUpX5/Kza59gzBdeKwp63Zk29fJdMKo= X-Google-Smtp-Source: AK7set8duhfLZ/7ldizpc8ek5za9JIE0Dr69AgYcpyqcc4AIMfXozffST5Ndkz6qMgCsc1Fa37gv7g== X-Received: by 2002:a05:6808:68c:b0:386:c2a5:1fd3 with SMTP id k12-20020a056808068c00b00386c2a51fd3mr4493203oig.14.1679169908376; Sat, 18 Mar 2023 13:05:08 -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 for-8.1 v3 09/26] target/riscv/cpu.c: remove cfg setup from riscv_cpu_init() Date: Sat, 18 Mar 2023 17:04:19 -0300 Message-Id: <20230318200436.299464-10-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169960148100005 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 --- target/riscv/cpu.c | 60 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index fef55d7d79..c7b6e7b84b 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) @@ -340,6 +341,12 @@ static void riscv_any_cpu_init(Object *obj) =20 env->priv_ver =3D PRIV_VERSION_LATEST; register_cpu_props(obj); + + /* 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) @@ -358,13 +365,20 @@ 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); register_cpu_props(obj); 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) @@ -375,10 +389,14 @@ static void rv64_sifive_e_cpu_init(Object *obj) set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); register_cpu_props(obj); 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) @@ -411,6 +429,10 @@ 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.ext_ifencei =3D true; + cpu->cfg.pmp =3D true; } =20 static void rv128_base_cpu_init(Object *obj) @@ -447,7 +469,8 @@ 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); =20 register_cpu_props(obj); @@ -455,6 +478,12 @@ static void rv32_sifive_u_cpu_init(Object *obj) #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) @@ -465,10 +494,14 @@ static void rv32_sifive_e_cpu_init(Object *obj) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); register_cpu_props(obj); 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) @@ -479,11 +512,15 @@ static void rv32_ibex_cpu_init(Object *obj) set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); register_cpu_props(obj); 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) @@ -494,10 +531,14 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); register_cpu_props(obj); 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 @@ -1384,11 +1425,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 Thu Mar 28 14:16:13 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=1679169987; cv=none; d=zohomail.com; s=zohoarc; b=aWWk6OT3/czroGgodeKIygIMWv16UhK9YzWJQkCC1Jo4jwkVKvZ0teFn/arNNoiQ4zoLtVs42KtDR8d8u1wmfWT7jNcuQxzE6GBQAeoKcPwr5R2AT5DvrBQX/5KphWlDIM/Pw7VfbxCrE/QEHrtxr2dNc1jAZJzdmZ5+kn7Jrk4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169987; 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=KGHUYpVmGV+OzIAgNAop0j4Vk4kPrXqyPo/RElMU7P0=; b=hNSnxTXW1IEY4MnbQj/KturGKfKUYHPnGygM0elTkMc6FhH43mKDyq2H0fbpsmEkIsNq+3CvJFO9UpKsIotTHtEfXDUOtmXbrsMYvbZ61hh6xUgEmCYPLPmGy1WCQjLqkLqya/cjF9Ocuvh3VXxx55HzRMR5Os3BBV3vvLfCJkk= 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 1679169987925550.5285632425946; Sat, 18 Mar 2023 13:06:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnj-00057p-4S; Sat, 18 Mar 2023 16:05:15 -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 1pdcnh-00057I-UA for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:14 -0400 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcng-00078F-Db for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:13 -0400 Received: by mail-oo1-xc34.google.com with SMTP id o15-20020a4ae58f000000b00538c0ec9567so827155oov.1 for ; Sat, 18 Mar 2023 13:05:12 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169911; 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=KGHUYpVmGV+OzIAgNAop0j4Vk4kPrXqyPo/RElMU7P0=; b=mZhGZrxnkUI0SDuWnX5gsX77RGSRdldbf4UwdSqsWgOwUuxqXi1CQRjfmen8pVwJas +iy7pCIhxPwjoLgLPghVyZYc967eBN2L+aFBa+Fi5EkTFrRm7Dze94gph9zPwhwbmecN clWIIOUuO03iyf+oMJ3ofwm9BSw0hk+nJ6ZTe/jf1rViaPJJbwJLYDaS4bkuQQR2Sope g/qIuPQOwHT1yy7mizo5XUeJdwgqAK/mSC+euWk+RHovirqOvLL1km0VX1e/Y4H8y55j e8Ubnzfwvqt66PU8O2wuy7JzPejgAqKUQ8spiry0d9fUsCBHcyi2+swHNNVMBjnky8gQ Zx1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169911; 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=KGHUYpVmGV+OzIAgNAop0j4Vk4kPrXqyPo/RElMU7P0=; b=CBN6hcreYaIsk1s78kMq4XGqdSDCiPH+olvk3obG67qJRvNf3M6rt5Je0fxZ+4DtQH oKEgKNj2onwy6TXjnShcTEsv7An2i2e3kbXwzOlKTze7Ig6DKKQLZB4P0CCeeKV+YjrC JcDP1T340Ipea3dg9kjgO7jgRPZ6JdY8jlaieOvx3mnI2sbYqTayIXl8sdBrWuplTyHn EDzeadUJiqmot+zAYP5csO7DnXODzOClQe4waI8bKKzvFpnhzGp1Z5FnJ8QPHLS/c6tU Db46BNBMKjCFBHBGrXb1B5hD0FQ+wrf9tx8WZ7Za11rgnM79vS8F0ZggFxScpCyAZ4pF xzew== X-Gm-Message-State: AO0yUKUPEI9na887sE7Oe64BhlhgnSFNxzwzoOiLogn5FDofmy+tDuoT h4AUH9KMqyYDdFYMpq6khfoDrut5liTZdLz1vNw= X-Google-Smtp-Source: AK7set8yibs3XBZfysgy8GBnm1BjjN21tnFnZ/jSkCAj22lDf6aGNwdihuSWETF629eb92hItr/mjQ== X-Received: by 2002:a4a:5288:0:b0:537:4278:a593 with SMTP id d130-20020a4a5288000000b005374278a593mr1677078oob.9.1679169911052; Sat, 18 Mar 2023 13:05:11 -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 for-8.1 v3 10/26] target/riscv/cpu.c: avoid set_misa() in validate_set_extensions() Date: Sat, 18 Mar 2023 17:04:20 -0300 Message-Id: <20230318200436.299464-11-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c34; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc34.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169988255100003 Content-Type: text/plain; charset="utf-8" set_misa() will be tuned up to do more than it's already doing and it will be redundant to what riscv_cpu_validate_set_extensions() does. Note that we don't ever change env->misa_mlx in this function, so set_misa() can be replaced by just assigning env->misa_ext and env->misa_ext_mask to 'ext'. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index c7b6e7b84b..36c55abda0 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -949,7 +949,8 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, = Error **errp) =20 /* * Check consistency between chosen extensions while setting - * cpu->cfg accordingly, doing a set_misa() in the end. + * cpu->cfg accordingly, setting env->misa_ext and + * misa_ext_mask in the end. */ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { @@ -1168,7 +1169,7 @@ static void riscv_cpu_validate_set_extensions(RISCVCP= U *cpu, Error **errp) ext |=3D RVJ; } =20 - set_misa(env, env->misa_mxl, ext); + env->misa_ext_mask =3D env->misa_ext =3D ext; } =20 #ifndef CONFIG_USER_ONLY --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170147; cv=none; d=zohomail.com; s=zohoarc; b=LgClF44vhF7oChM2DaX0jR+0pHJG4XpeV1yd+BcTi2TrvDyaTHM/C2cV6CBuUH59cwMKC++DQCwwTgMHBwQ6j565O/pc5FXqNVP2rWq0VB6OWntEDY07nst2GwGdTZL3Ad1GJdHzl9ppAxbThiZkPFNogo9if5yVOJ6LgtSSgNc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170147; 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=n1KnuQqgygOO2YMozmY3X/7U/lNxPcvXX1UiChgZSKA=; b=YEb5SDl6DDpfdMptWHHLg98g+SsgxmXbPNuFw5k8YDu21pr8504PHlv4xIeMxlfULoKVlHAYfWsLCYbkQPRpMi+Vo2+8c+OpIpu7is4FYejaywh8DntZq2xwApOIAwo1LuzWmIkdtB8rOPzn+IAn76rlkt/vp/EXyXgp8hoFQjM= 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 1679170147212240.20996793920676; Sat, 18 Mar 2023 13:09:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnm-00058u-Le; Sat, 18 Mar 2023 16:05: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 1pdcnl-00058M-H6 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:17 -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 1pdcnj-00078p-Kt for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:17 -0400 Received: by mail-oi1-x22c.google.com with SMTP id bj30so6210260oib.6 for ; Sat, 18 Mar 2023 13:05:14 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169914; 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=n1KnuQqgygOO2YMozmY3X/7U/lNxPcvXX1UiChgZSKA=; b=hjZh7rTZtQIZVIHUBfIPc912pyH2Dc0tOetguubjLwRe51bM+20fnYLO31Q1jEmHR1 w3y2+bpo+YStOevc4JygemuqGOPAusFQGXodrngwH62wIXV90fN3k8cuQuOcV5EQTck8 6dBPjhsMYT50YaDW2YJIJqXiSZqoQVDaUlsGWgg+vj9eBZCaWwHm14e5xlMLkoXq7SWC oWWYWcD/AQJZlOdpglRdp6XZCgOBmoE9M2jdgjrAfxKuSYgkZdSz9u+Jus331PUsBsyq MJsiPGeVNOzfqd6vVYVfYpp2Gg3337OZuO++yIjTFc/1DR+IyK6RH8GpsTiwGp6NBfPJ JrIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169914; 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=n1KnuQqgygOO2YMozmY3X/7U/lNxPcvXX1UiChgZSKA=; b=6z1ZFgjknvjLtBAhY+7ee1OFyaSkCDhZ/aaF5mzAt1YCyADL/ChWDYNy8nbKl9ov67 KNlh/E9D0hHGI+JltK9vYo4HlPkQp5QfFbDQi3SlyJ5fhL83eT9IYy2kEsKwD1rUFH7k /fscPTdxt/iPx7f0/GxOA3mkCV4CFejNCqN8wN5X32cOsDw9XJo5ETs+TVSPRlbqoK/y BNlAq8CyC55K15GTbgrHF2UjtxiNCDwrZcaXzWoF15GSK2dTBZ9S6uf2NNlE4hCqWBRL LQxOob/elH6rFLH/hqV/WXgaMvOI9L3ZpiC6fOLig7On/C9BZR7JkAG+yM/pcvDi/S0N XzmQ== X-Gm-Message-State: AO0yUKUsVnhshRuOINuM4wd3V+Sdee8Jt5VQV/k/NclEfF3YFBROT7IC vQo22PnSzkzG+ZDWAU+lI5XPDTAXxMKXyiI2G6Q= X-Google-Smtp-Source: AK7set8sPkCFNqGo4nkKMg1p+rOJH6O2m4R+Q2KzyFIghiXp8kej9lssz90yYg3+p30U3leLIRyfDA== X-Received: by 2002:aca:f1d6:0:b0:386:ea71:9c99 with SMTP id p205-20020acaf1d6000000b00386ea719c99mr1155885oih.25.1679169913796; Sat, 18 Mar 2023 13:05:13 -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 for-8.1 v3 11/26] target/riscv/cpu.c: set cpu config in set_misa() Date: Sat, 18 Mar 2023 17:04:21 -0300 Message-Id: <20230318200436.299464-12-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170149057100007 Content-Type: text/plain; charset="utf-8" set_misa() is setting all 'misa' related env states and nothing else. But other functions, namely riscv_cpu_validate_set_extensions(), uses the config object to do its job. This creates a need to set the single letter extensions in the cfg object to keep both in sync. At this moment this is being done by register_cpu_props(), forcing every CPU to do a call to this function. Let's beef up set_misa() and make the function do the sync for us. This will relieve named CPUs to having to call register_cpu_props(), which will then be redesigned to a more specialized role next. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 40 ++++++++++++++++++++++++++++++++-------- target/riscv/cpu.h | 4 ++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 36c55abda0..7841676473 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -236,8 +236,40 @@ const char *riscv_cpu_get_trap_name(target_ulong cause= , bool async) =20 static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) { + RISCVCPU *cpu; + env->misa_mxl_max =3D env->misa_mxl =3D mxl; env->misa_ext_mask =3D env->misa_ext =3D ext; + + /* + * ext =3D 0 will only be a thing during cpu_init() functions + * as a way of setting an extension-agnostic CPU. We do + * not support clearing misa_ext* and the ext_N flags in + * RISCVCPUConfig in regular circunstances. + */ + if (ext =3D=3D 0) { + return; + } + + /* + * We can't use riscv_cpu_cfg() in this case because it is + * a read-only inline and we're going to change the values + * of cpu->cfg. + */ + cpu =3D env_archcpu(env); + + cpu->cfg.ext_i =3D ext & RVI; + cpu->cfg.ext_e =3D ext & RVE; + cpu->cfg.ext_m =3D ext & RVM; + cpu->cfg.ext_a =3D ext & RVA; + cpu->cfg.ext_f =3D ext & RVF; + cpu->cfg.ext_d =3D ext & RVD; + cpu->cfg.ext_v =3D ext & RVV; + cpu->cfg.ext_c =3D ext & RVC; + cpu->cfg.ext_s =3D ext & RVS; + cpu->cfg.ext_u =3D ext & RVU; + cpu->cfg.ext_h =3D ext & RVH; + cpu->cfg.ext_j =3D ext & RVJ; } =20 #ifndef CONFIG_USER_ONLY @@ -340,7 +372,6 @@ static void riscv_any_cpu_init(Object *obj) #endif =20 env->priv_ver =3D PRIV_VERSION_LATEST; - register_cpu_props(obj); =20 /* inherited from parent obj via riscv_cpu_init() */ cpu->cfg.ext_ifencei =3D true; @@ -368,7 +399,6 @@ static void rv64_sifive_u_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - register_cpu_props(obj); 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); @@ -387,7 +417,6 @@ 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); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -472,8 +501,6 @@ static void rv32_sifive_u_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); CPURISCVState *env =3D &cpu->env; set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); - - register_cpu_props(obj); 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); @@ -492,7 +519,6 @@ 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); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -510,7 +536,6 @@ static void rv32_ibex_cpu_init(Object *obj) RISCVCPU *cpu =3D RISCV_CPU(obj); =20 set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_11_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); @@ -529,7 +554,6 @@ 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); - register_cpu_props(obj); env->priv_ver =3D PRIV_VERSION_1_10_0; #ifndef CONFIG_USER_ONLY set_satp_mode_max_supported(cpu, VM_1_10_MBARE); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 76f81c6b68..ebe0fff668 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -66,8 +66,8 @@ #define RV(x) ((target_ulong)1 << (x - 'A')) =20 /* - * Consider updating register_cpu_props() when adding - * new MISA bits here. + * Consider updating set_misa() when adding new + * MISA bits here. */ #define RVI RV('I') #define RVE RV('E') /* E and I are mutually exclusive */ --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170006; cv=none; d=zohomail.com; s=zohoarc; b=nvfh8q3RgFWL73VbjVmrcZwsCrOf0WIi8LSTLwWsRRTKEWQ611SD8hxe6Pe//8CVSMnrIHZTVJqnu85QrtQeY5zCpGCvdt6tBXWMxdZJ17DrkQA3VMS5+KDwnXJjb4I94s9V1AnsXGvbDPpcKdn5YV4v6qgePnzzQrBcL0APuC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170006; 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=CguAyFnXN900gJ747DQtBtymkQ6WmWSHf4CsQ4yPU5I=; b=ITlUHuXtjOCcYLCSvdZP/zLJ5D0rdXBMWiOAWrMNSXCDbwXw+1v+U/RHqxVwC6TA7xkHUC1dndeAv1QlgT9XjAcZdOmwjT64EpR2Y6TrJOLKukNjW5IE3gUqd3eZF/HHIeaIIEp1hnttq8Jaf5NyM1Bl3QTxUXBpiItkWUPZBOU= 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 1679170006301674.5660381994944; Sat, 18 Mar 2023 13:06:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnp-00059x-63; Sat, 18 Mar 2023 16:05:21 -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 1pdcnn-00059E-Kp for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:19 -0400 Received: from mail-oo1-xc29.google.com ([2607:f8b0:4864:20::c29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnl-00079A-UQ for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:19 -0400 Received: by mail-oo1-xc29.google.com with SMTP id x24-20020a4aca98000000b0053a9bbbe449so244491ooq.9 for ; Sat, 18 Mar 2023 13:05:17 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169916; 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=CguAyFnXN900gJ747DQtBtymkQ6WmWSHf4CsQ4yPU5I=; b=AenRMaXUro/8lGtPotP5lLo2RcOkFfs/g/lkEMJwCZ64gZMcARLsYSvSErIpGcIK0Q E6kKQRwrcpzi1bbwv819jFvRAuZRf3QLVDrp5ImVrvUPttHQdECIMVlAeXnAaqDQ3H1g xwmL/nAgPsFkfUP1WuqhPhgfM2xv7nI9lo04MD2iWN9/qq/PoMG6wJj1KtqsxzwxbBHf YpUSjAC4+bAzIYMmnPX4EyND8ANDQgRA4X3nzkuJlUcVTaGq5QHG1j0ZS4UQWeUTgiGn K4+sfX1yx6LAsExPSra5pcA0X8CETNDkCy8hXKTluSXh1OqMZrd2hckbuu95ox4qKpWz +Pxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169916; 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=CguAyFnXN900gJ747DQtBtymkQ6WmWSHf4CsQ4yPU5I=; b=1Ajqz6+w1DauRet5QrMePKiYnuoEUB+Fl2RFY+/aeoQ413bMJx5nVws6knUMexuJNJ Uwl7Njuc/ObxjzMB2hRhYUOqhZWgFNLQJb88gbn0QII3p2YQBBzQ6dK+TpM7uQCVF36w wf3Ja81awK1E+wdIjqnZkH9mSozRX5r3mEoQc/xKLnT7ghwURoqxVhyaLZJMMzt1iDK1 AvEFJoDy/i3RDwWFmGk4EVhqWt22r6tlz+TXV6vl3t3z67aIp3sRzuh2xKK7Rj6T5Y2Z Xcub/kPeyCiOBErFznfFHyP0vGpKB+bdMcmNGOwvZ/0IAJZ2KOsqY55EddHvajH4Djse r1DQ== X-Gm-Message-State: AO0yUKU2Mv+2qWio9b9w3eOjv9QPTvfTW9u9axdbWdvGoORXxT5GBaFU 6qpg2tMqLMflsh0GAR9LUSCpkR1aTgLX2fbiUWk= X-Google-Smtp-Source: AK7set9vcFPLCoV5PFzkepxNhgUX9ztNitfHSHf7VJcyUdYI2HPehEfNwkLB+wb8JDK1c/Ggy9lTew== X-Received: by 2002:a4a:49d7:0:b0:538:57d4:2d62 with SMTP id z206-20020a4a49d7000000b0053857d42d62mr1366726ooa.2.1679169916561; Sat, 18 Mar 2023 13:05: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 Subject: [PATCH for-8.1 v3 12/26] target/riscv/cpu.c: redesign register_cpu_props() Date: Sat, 18 Mar 2023 17:04:22 -0300 Message-Id: <20230318200436.299464-13-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c29; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc29.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170008443100001 Content-Type: text/plain; charset="utf-8" Now that the function is a no-op if 'env.misa_ext !=3D 0', and no one that are setting misa_ext !=3D 0 is calling it because set_misa() is setting the cpu cfg accordingly, remove the now deprecated code and rename the function to register_generic_cpu_props(). This function is now doing exactly what the name says: it is creating user-facing properties to allow changes in the CPU cfg via the QEMU command line, setting default values if no user input is provided. Note that there's the possibility of a CPU to set a certain misa value and, at the same, also want user-facing flags and defaults from this function. This is not the case since commit 26b2bc58599c ("target/riscv: Don't expose the CPU properties on names CPUs"), but given that this is also a possibility, clarify in the function that using this function will overwrite existing values in cpu->cfg. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 48 ++++++++++------------------------------------ 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7841676473..6b5096d25e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -221,7 +221,7 @@ static const char * const riscv_intr_names[] =3D { "reserved" }; =20 -static void register_cpu_props(Object *obj); +static void register_generic_cpu_props(Object *obj); =20 const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) { @@ -386,7 +386,7 @@ static void rv64_base_cpu_init(Object *obj) CPURISCVState *env =3D &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, MXL_RV64, 0); - register_cpu_props(obj); + register_generic_cpu_props(obj); /* Set latest version of privileged specification */ env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY @@ -475,7 +475,7 @@ static void rv128_base_cpu_init(Object *obj) CPURISCVState *env =3D &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, MXL_RV128, 0); - register_cpu_props(obj); + register_generic_cpu_props(obj); /* Set latest version of privileged specification */ env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY @@ -488,7 +488,7 @@ static void rv32_base_cpu_init(Object *obj) CPURISCVState *env =3D &RISCV_CPU(obj)->env; /* We set this in the realise function */ set_misa(env, MXL_RV32, 0); - register_cpu_props(obj); + register_generic_cpu_props(obj); /* Set latest version of privileged specification */ env->priv_ver =3D PRIV_VERSION_LATEST; #ifndef CONFIG_USER_ONLY @@ -575,7 +575,7 @@ static void riscv_host_cpu_init(Object *obj) #elif defined(TARGET_RISCV64) set_misa(env, MXL_RV64, 0); #endif - register_cpu_props(obj); + register_generic_cpu_props(obj); } #endif =20 @@ -1557,44 +1557,16 @@ static Property riscv_cpu_extensions[] =3D { }; =20 /* - * Register CPU props based on env.misa_ext. If a non-zero - * value was set, register only the required cpu->cfg.ext_* - * properties and leave. env.misa_ext =3D 0 means that we want - * all the default properties to be registered. + * Register generic CPU props with user-facing flags declared + * in riscv_cpu_extensions[]. + * + * Note that this will overwrite existing values in cpu->cfg. */ -static void register_cpu_props(Object *obj) +static void register_generic_cpu_props(Object *obj) { - RISCVCPU *cpu =3D RISCV_CPU(obj); - uint32_t misa_ext =3D cpu->env.misa_ext; Property *prop; DeviceState *dev =3D DEVICE(obj); =20 - /* - * If misa_ext is not zero, set cfg properties now to - * allow them to be read during riscv_cpu_realize() - * later on. - */ - if (cpu->env.misa_ext !=3D 0) { - cpu->cfg.ext_i =3D misa_ext & RVI; - cpu->cfg.ext_e =3D misa_ext & RVE; - cpu->cfg.ext_m =3D misa_ext & RVM; - cpu->cfg.ext_a =3D misa_ext & RVA; - cpu->cfg.ext_f =3D misa_ext & RVF; - cpu->cfg.ext_d =3D misa_ext & RVD; - cpu->cfg.ext_v =3D misa_ext & RVV; - cpu->cfg.ext_c =3D misa_ext & RVC; - cpu->cfg.ext_s =3D misa_ext & RVS; - cpu->cfg.ext_u =3D misa_ext & RVU; - cpu->cfg.ext_h =3D misa_ext & RVH; - cpu->cfg.ext_j =3D misa_ext & RVJ; - - /* - * We don't want to set the default riscv_cpu_extensions - * in this case. - */ - return; - } - for (prop =3D riscv_cpu_extensions; prop && prop->name; prop++) { qdev_property_add_static(dev, prop); } --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679169973; cv=none; d=zohomail.com; s=zohoarc; b=Hrme7z4fGpdGi/h/yIzwQFLztHQyxy2QUmX5TUqHjJHtz5yHWmkA8kemePOnVLFpT8IieUgDJemWUui71hkQ05/W5yQVbRctelQWUBnK8ImWxk2B0qMbVKdPFCv6xQQ7DsVt4cBTa/zZjOGi8cYzrn90TW/mlMkGEEyxmncyn4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169973; 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=oYMlE/F1S0n9ko7FKmrIGnYN/pdSAseR81vgrE7fIjY=; b=duLgxrzyZeH6gjPuetu7IH+Qviw0o77giZ0T3JJZGK4hNkRZotz0+Xm98EKEO6Mm3Pi75y+vqqzRuYqCV3nJ+J4AIWSDiS610pXfDHfBAc5UIEE90t+i4WC5MLdqyvtEbhpldxwl/3dM4m6cEHrZThVEvJayXpT+Q4L9JmgilRA= 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 16791699735991017.0482192581103; Sat, 18 Mar 2023 13:06:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnr-0005GK-SN; Sat, 18 Mar 2023 16:05:23 -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 1pdcnq-0005CO-E3 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:22 -0400 Received: from mail-ot1-x335.google.com ([2607:f8b0:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcno-00071F-Ld for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:22 -0400 Received: by mail-ot1-x335.google.com with SMTP id p11-20020a9d454b000000b0069d8eb419f9so4292255oti.4 for ; Sat, 18 Mar 2023 13:05:20 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169919; 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=oYMlE/F1S0n9ko7FKmrIGnYN/pdSAseR81vgrE7fIjY=; b=FYIP7lzgrPg4DX8DNVP1GhTNpscbAX701BGtqWvack5Yh+0qUNGJTnkZ/QBByecbvp fmhM5GeKfeHIg/sOFP834LGV/sZHSYez64flKKa0dDiF8xSefW5B+fTjpqZuiq5VG+vA 8MAUEvyKk8wIPk1YxlQJtDH+xfC6/ybWTR/DemDF0ITHhwmJf7wuIBiNm5ZSvcCl9+KC bRxOBJwKSqeoZWrd+BEa8t4pNMEZymVFAaGOZusL3btoDiTNhCe0pCFXo56mrEyTXE+F xTu34ovMK0PQ+9SMfl5lvDm+DKAYEdGoEKl19YXUQ4009VvcMx0lWteZqw2u7/MQ9+g/ EwsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169919; 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=oYMlE/F1S0n9ko7FKmrIGnYN/pdSAseR81vgrE7fIjY=; b=M7VYiY/1Aq+80aXGEkY1WTbVHOaC8F05yXhsEeVk9zvP/y0kC4ClsJP9ANgrn1jfPY +4pQvILr6XnfWZxUk/izojz4hXXdT1+sFBVfLIqXnlRScG2cKO312k2oYSTEjl6uTRyb +Tv1fDDTOL8p3usSO+fqGR6LdBkcxiaPmV/pD4o0CZd2GOBaHWJlWi7KfxP5S4pBe4Tu dbnN9dy9OQ7fmz8D6oMnTBhOOhvQCPxZG500dAIgSVvYyluUMoDHTRbWsEPugcKgPoWs jmfkWS9ySmjFS3IfFHNwVHIEAuU1jSteGG22R7oXhpxZjb01+5rIt1cAgfQSxD1Dlqjf bN+Q== X-Gm-Message-State: AO0yUKUsNBOOZTcjLkxDbt8VGLmW5/d/6B2oLqkjYpoKJ9w3ycyMe85B Q6I6Ic4oLcWE9/qffVjBjkdgK8Un54gQ53rjsQs= X-Google-Smtp-Source: AK7set9uHWrVSJn7nreF7Tqf6gDVZjlppQLR/FExFpA4pBKTxN4TNZGPY/6kszjaWmWiAuQfmQUP3w== X-Received: by 2002:a9d:77c9:0:b0:686:5c66:1ff0 with SMTP id w9-20020a9d77c9000000b006865c661ff0mr1572604otl.5.1679169919336; Sat, 18 Mar 2023 13:05: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 for-8.1 v3 13/26] target/riscv: put env->misa_ext <-> cpu->cfg code into helpers Date: Sat, 18 Mar 2023 17:04:23 -0300 Message-Id: <20230318200436.299464-14-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::335; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x335.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169974235100001 Content-Type: text/plain; charset="utf-8" The extremely tedious code that sets cpu->cfg based on misa_ext, and vice-versa, is scattered around riscv_cpu_validate_set_extensions() and set_misa(). Introduce helpers to do this work, cleaning up the logic of both functions a bit. While we're at it, add a note in cpu.h informing that any future change in MISA RV* bits should also be reflected in the helpers as well. We'll want to keep env->misa_ext changes in sync with cpu->cfg during realize() in the next patches, and both helpers will have a role to play in that. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 120 ++++++++++++++++++++++++--------------------- target/riscv/cpu.h | 3 +- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 6b5096d25e..28d4c5f768 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -234,10 +234,69 @@ const char *riscv_cpu_get_trap_name(target_ulong caus= e, bool async) } } =20 -static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) +static uint32_t riscv_get_misa_ext_with_cpucfg(RISCVCPUConfig *cfg) { - RISCVCPU *cpu; + uint32_t ext =3D 0; =20 + if (cfg->ext_i) { + ext |=3D RVI; + } + if (cfg->ext_e) { + ext |=3D RVE; + } + if (cfg->ext_m) { + ext |=3D RVM; + } + if (cfg->ext_a) { + ext |=3D RVA; + } + if (cfg->ext_f) { + ext |=3D RVF; + } + if (cfg->ext_d) { + ext |=3D RVD; + } + if (cfg->ext_c) { + ext |=3D RVC; + } + if (cfg->ext_s) { + ext |=3D RVS; + } + if (cfg->ext_u) { + ext |=3D RVU; + } + if (cfg->ext_h) { + ext |=3D RVH; + } + if (cfg->ext_v) { + ext |=3D RVV; + } + if (cfg->ext_j) { + ext |=3D RVJ; + } + + return ext; +} + +static void riscv_set_cpucfg_with_misa(RISCVCPUConfig *cfg, + uint32_t misa_ext) +{ + cfg->ext_i =3D misa_ext & RVI; + cfg->ext_e =3D misa_ext & RVE; + cfg->ext_m =3D misa_ext & RVM; + cfg->ext_a =3D misa_ext & RVA; + cfg->ext_f =3D misa_ext & RVF; + cfg->ext_d =3D misa_ext & RVD; + cfg->ext_v =3D misa_ext & RVV; + cfg->ext_c =3D misa_ext & RVC; + cfg->ext_s =3D misa_ext & RVS; + cfg->ext_u =3D misa_ext & RVU; + cfg->ext_h =3D misa_ext & RVH; + cfg->ext_j =3D misa_ext & RVJ; +} + +static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) +{ env->misa_mxl_max =3D env->misa_mxl =3D mxl; env->misa_ext_mask =3D env->misa_ext =3D ext; =20 @@ -251,25 +310,7 @@ static void set_misa(CPURISCVState *env, RISCVMXL mxl,= uint32_t ext) return; } =20 - /* - * We can't use riscv_cpu_cfg() in this case because it is - * a read-only inline and we're going to change the values - * of cpu->cfg. - */ - cpu =3D env_archcpu(env); - - cpu->cfg.ext_i =3D ext & RVI; - cpu->cfg.ext_e =3D ext & RVE; - cpu->cfg.ext_m =3D ext & RVM; - cpu->cfg.ext_a =3D ext & RVA; - cpu->cfg.ext_f =3D ext & RVF; - cpu->cfg.ext_d =3D ext & RVD; - cpu->cfg.ext_v =3D ext & RVV; - cpu->cfg.ext_c =3D ext & RVC; - cpu->cfg.ext_s =3D ext & RVS; - cpu->cfg.ext_u =3D ext & RVU; - cpu->cfg.ext_h =3D ext & RVH; - cpu->cfg.ext_j =3D ext & RVJ; + riscv_set_cpucfg_with_misa(&env_archcpu(env)->cfg, ext); } =20 #ifndef CONFIG_USER_ONLY @@ -1156,42 +1197,7 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) */ riscv_cpu_disable_priv_spec_isa_exts(cpu); =20 - if (cpu->cfg.ext_i) { - ext |=3D RVI; - } - if (cpu->cfg.ext_e) { - ext |=3D RVE; - } - if (cpu->cfg.ext_m) { - ext |=3D RVM; - } - if (cpu->cfg.ext_a) { - ext |=3D RVA; - } - if (cpu->cfg.ext_f) { - ext |=3D RVF; - } - if (cpu->cfg.ext_d) { - ext |=3D RVD; - } - if (cpu->cfg.ext_c) { - ext |=3D RVC; - } - if (cpu->cfg.ext_s) { - ext |=3D RVS; - } - if (cpu->cfg.ext_u) { - ext |=3D RVU; - } - if (cpu->cfg.ext_h) { - ext |=3D RVH; - } - if (cpu->cfg.ext_v) { - ext |=3D RVV; - } - if (cpu->cfg.ext_j) { - ext |=3D RVJ; - } + ext =3D riscv_get_misa_ext_with_cpucfg(&cpu->cfg); =20 env->misa_ext_mask =3D env->misa_ext =3D ext; } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ebe0fff668..2263629332 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -66,7 +66,8 @@ #define RV(x) ((target_ulong)1 << (x - 'A')) =20 /* - * Consider updating set_misa() when adding new + * Consider updating riscv_get_misa_ext_with_cpucfg() + * and riscv_set_cpucfg_with_misa() when adding new * MISA bits here. */ #define RVI RV('I') --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170158; cv=none; d=zohomail.com; s=zohoarc; b=UXfsc0UxRbypNapKDrBCHjgtTmhb2OYGMXf92HlvaqFMssER1IyaoeSkLXUIS9c6y4qQA7Hn2fGQ4lokyF/Ssv0V9z4nJ3S6uE3NzJxDhmBuU0Ily6n61BsgPyE7STuGIvAqKYG9CBNOBNvqWw5PMTw++Kg0DW8ZgWQpFN26BKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170158; 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=2FfMN5ljB+YprrE4UltRQLz73prfFTbeqKbrs/aENp8=; b=FjTmCYbJoBkuh2BLd6iZOBuhw8Brh9o9SpapAFtbh9+7DZRg0JQ6RBSlu0ZMB9K3ktrL7ac7tw8dw8AAv30lt6/dgEINX/7oiNZmwEYYryGPLksOeUVpdH+NBm/L+51sDX+BAnTFS4q+hPqn68Azc3YG1TMwmsgJfMMVPQxT2Uo= 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 16791701584551010.5483664517784; Sat, 18 Mar 2023 13:09:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcnu-0005IW-S1; Sat, 18 Mar 2023 16:05:26 -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 1pdcns-0005HX-OH for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:24 -0400 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnr-0006sx-7i for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:24 -0400 Received: by mail-oo1-xc31.google.com with SMTP id x18-20020a4ae792000000b005376d6c9cfeso1260203oov.3 for ; Sat, 18 Mar 2023 13:05:22 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169922; 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=2FfMN5ljB+YprrE4UltRQLz73prfFTbeqKbrs/aENp8=; b=KPMtuaDXthd8SdA+kYQt2prhH8g9s8m50l9ezlOG2z6gueaDqX9+tpYL6uaSohkWA7 HOHq+QPtok/rfmY7gPUdVNqxiPr0bo8l2J4uBELIK8oU/wQQktVnP5CaGmuKjMPOG63Q xkZoUTl3UC/dmpj6UdOIyZIfJUURT4m8R5pGUZkp0+Bt77mqEE4wJHESzkFMYqloKK9C ZSPtUsPyQYoVfZ0WS16X5D6rV+zSLFzOoXtEzAF0A+Wwdo3tcatBcOCGUp3A0CWHG8G4 zakgWmGmckW+PvL3/k6YqFjrt2yT0RBOMpwnhUHDukC9PrpX6RJbAbOox8qyzfLxQDSU 320g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169922; 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=2FfMN5ljB+YprrE4UltRQLz73prfFTbeqKbrs/aENp8=; b=suTl4uYCWA6D650xFLjgHXvuhwEvBgVMKJjBd6VY9+Y64FJN6FhRizX/t4SMzvnYdZ IdWsuHqBPGVw6V6rR8WHPR8y4dJues9tSud2J4zog1geBfAM8MPrulFuMgicUJ2B5M5Q ex3F/KEpztBf/zfrQ9L/ROen8Jty4QtIZ1hLEaveEx8ZALgv/E9wFbD/lRBM9jkJklLl kwVRaqmzHpR2t+iYw87NapJcwGQn+7/StduoPWoRRl2TcRSJugZkFfzHm5AQjwXtCWvC aCw0NwmtCx2MuwWt4XFkd6uM9hmQ8VcRT17gyH8eS7SLzrEYSzUSJghQbY2BIj7edzZD 0MDA== X-Gm-Message-State: AO0yUKWRqhpOD9kM3eDYelqaEIpWm7icE2+6ZzTJ/MR2BsMJ6mNTNRN4 fDfdBE2oYk1tdBpvxB6WnSmgh0IcFYVFvsVLdgw= X-Google-Smtp-Source: AK7set+fe0VKVCgwJ7sq6FyibyDxqplXvAi3WC4hAcSpIFNOb9KH9YVMiFYn18jvzxy7iZL7e6jq/A== X-Received: by 2002:a4a:3350:0:b0:537:f9d4:a44c with SMTP id q77-20020a4a3350000000b00537f9d4a44cmr1460552ooq.5.1679169922234; Sat, 18 Mar 2023 13:05: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 for-8.1 v3 14/26] target/riscv: add RVG Date: Sat, 18 Mar 2023 17:04:24 -0300 Message-Id: <20230318200436.299464-15-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c31; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc31.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170159021100001 Content-Type: text/plain; charset="utf-8" The 'G' bit in misa_ext is a virtual extension that enables a set of extensions (i, m, a, f, d, icsr and ifencei). We're already have code to handle it but no bit definition. Add it. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 4 ++++ target/riscv/cpu.h | 1 + 2 files changed, 5 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 28d4c5f768..48ad7372b9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -274,6 +274,9 @@ static uint32_t riscv_get_misa_ext_with_cpucfg(RISCVCPU= Config *cfg) if (cfg->ext_j) { ext |=3D RVJ; } + if (cfg->ext_g) { + ext |=3D RVG; + } =20 return ext; } @@ -293,6 +296,7 @@ static void riscv_set_cpucfg_with_misa(RISCVCPUConfig *= cfg, cfg->ext_u =3D misa_ext & RVU; cfg->ext_h =3D misa_ext & RVH; cfg->ext_j =3D misa_ext & RVJ; + cfg->ext_g =3D misa_ext & RVG; } =20 static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 2263629332..dbb4df9df0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -82,6 +82,7 @@ #define RVU RV('U') #define RVH RV('H') #define RVJ RV('J') +#define RVG RV('G') =20 =20 /* Privileged specification version */ --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679169985; cv=none; d=zohomail.com; s=zohoarc; b=LXbbUrXrNhb6U56zeBwreVS1ZsepR40QUmOy0cu5cjBjSvkuqwtst6nfdsqphngRW717vqH2EiCGSc7WqVq1szhIsYOs3vnUb2ZRPQty18mfc+wOv0KBTOEgDiTz2U0rCVKrGSSCqBI483nF3QIBM984a6DiUiBfbMRJJS34Zdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679169985; 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=NAmDeC6RM/ZUTD0Fb3vBxdXraVyIqMtfH28cw/JTV1Y=; b=kT8CbwvLNFQ+nz95uis+STN0utH6d35kgg43vqdZXfRJirzQVy3HLEbBzzZXs/+i4Yb/svfw/3fW1g99/mJHvdrdGV5MBkMr+XtIGSUBrAOuoW8jkD0WWNBORpJrDK4BJ1HhieybALWuMbrI92UCLwTBeJFWJZYy724up/c1VGU= 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 167916998521965.0571218348199; Sat, 18 Mar 2023 13:06:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcny-0005JU-7i; Sat, 18 Mar 2023 16:05:30 -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 1pdcnw-0005Iv-17 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:28 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnu-0007Ar-8c for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:27 -0400 Received: by mail-oo1-xc30.google.com with SMTP id o26-20020a4ad49a000000b0053964a84b0fso687926oos.7 for ; Sat, 18 Mar 2023 13:05:25 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169925; 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=NAmDeC6RM/ZUTD0Fb3vBxdXraVyIqMtfH28cw/JTV1Y=; b=g1ZBAPi8slwtVf48qRRka0G5ELfKoiJXWd//4lpIl7roLFUQbt8Sh+d8JmMnGKodNo EhNrWrLEHWDsUj6y2m8LLq2C+NF0i4eElHDpOdmH3ccqrSlcqDXmp+OmuDLrcFZFmEgK rbryWEszQuZtCeIS35LnUkCSNvb0/iX1KTznaix5/7WJeKgoFV54jaPd2gKKssB59J18 DEL/9sXB1lm1QULuE+gXjGiyy2lHJR31ysWnFOMQh0HAZUDNIXtRz92kmNZhQnAA5YnC TvlUZyv3eSqadmOFvQHaInsqgHQdE8G3Ey3S4EaciClXSkJQhPKMi6rm6Ndwgn257+5r +Dxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169925; 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=NAmDeC6RM/ZUTD0Fb3vBxdXraVyIqMtfH28cw/JTV1Y=; b=R5P7sKy7NoNqCRXOawloXwtKA/u+sh0YkcfCb07drPqz9baFh3X/RYdhQp7uUy8meR grI6N4bvhitub5xrzfUSWxH6EBXFcs9knXscTeqPXnNscDUOODrGOThsgeXO/tLVCKVt EONna3dmZV7LCoLPi4LdiL3a5USnQI4Yx1dCiPfy+LGG0fQ1AzCJATbaE72AJk55b5VD CyHXUlWC/c8Q4cjhVvPOlOzh0rP9j/FXaeJ/uZgc3b89SH202GXujg7By3hhLLfH8jMU cPuheOUnPjy3G0ZgFJc8PzqsH8pkj2SFm/bc8nFhVY8jjuK482NJvE+0Niq0i8QyGSbA Kq1w== X-Gm-Message-State: AO0yUKX0k9TVk9s1m+vy1pyx+X5zCAm7/mghXwSIA8/omtHLIDJBTlcx QGd0i23RE38JWoUuzwy4M+7r7E+rCBJ75lUMs74= X-Google-Smtp-Source: AK7set9Mm2hpo3IhEKP+XLn7PdWZi+Kce62AXQyNsl+PcILAQJVaTXFwVKjVH2f2Mbvl6hhLDwbezA== X-Received: by 2002:a4a:9e81:0:b0:525:810e:8b75 with SMTP id u1-20020a4a9e81000000b00525810e8b75mr1408374ook.1.1679169924869; Sat, 18 Mar 2023 13:05:24 -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 for-8.1 v3 15/26] target/riscv/cpu.c: split RVG code from validate_set_extensions() Date: Sat, 18 Mar 2023 17:04:25 -0300 Message-Id: <20230318200436.299464-16-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c30; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc30.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679169986280100001 Content-Type: text/plain; charset="utf-8" We can set all RVG related extensions during realize time, before validate_set_extensions() itself. Put it in a separated function so the validate function already uses the updated state. Note that we're adding an extra constraint: ext_zfinx is a blocker for F, which is a requirement to enable G. If zfinx is enabled we'll have to error out. Note that we're setting both cfg->ext_N and env->misa_ext bits, instead of just setting cfg->ext_N. The intention here is to start syncing all misa_ext operations with its cpu->cfg flags, in preparation to allow for the validate function to operate using a misa_ext. This doesn't make any difference for the current code state, but will be a requirement for write_misa() later on. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 66 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 48ad7372b9..110b52712c 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -281,6 +281,42 @@ static uint32_t riscv_get_misa_ext_with_cpucfg(RISCVCP= UConfig *cfg) return ext; } =20 +static void riscv_cpu_enable_g(RISCVCPU *cpu, Error **errp) +{ + CPURISCVState *env =3D &cpu->env; + RISCVCPUConfig *cfg =3D &cpu->cfg; + + if (cpu->cfg.ext_zfinx) { + error_setg(errp, "Unable to enable G: Zfinx is enabled, " + "so F can not be enabled"); + return; + } + + if (!(cfg->ext_i && cfg->ext_m && cfg->ext_a && + cfg->ext_f && cfg->ext_d && + cfg->ext_icsr && cfg->ext_ifencei)) { + + warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); + cfg->ext_i =3D true; + env->misa_ext |=3D RVI; + + cfg->ext_m =3D true; + env->misa_ext |=3D RVM; + + cfg->ext_a =3D true; + env->misa_ext |=3D RVA; + + cfg->ext_f =3D true; + env->misa_ext |=3D RVF; + + cfg->ext_d =3D true; + env->misa_ext |=3D RVD; + + cfg->ext_icsr =3D true; + cfg->ext_ifencei =3D true; + } +} + static void riscv_set_cpucfg_with_misa(RISCVCPUConfig *cfg, uint32_t misa_ext) { @@ -1036,21 +1072,6 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) return; } =20 - /* Do some ISA extension error checking */ - if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && - cpu->cfg.ext_a && cpu->cfg.ext_f && - cpu->cfg.ext_d && - cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { - warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); - cpu->cfg.ext_i =3D true; - cpu->cfg.ext_m =3D true; - cpu->cfg.ext_a =3D true; - cpu->cfg.ext_f =3D true; - cpu->cfg.ext_d =3D true; - cpu->cfg.ext_icsr =3D true; - cpu->cfg.ext_ifencei =3D true; - } - if (cpu->cfg.ext_i && cpu->cfg.ext_e) { error_setg(errp, "I and E extensions are incompatible"); @@ -1293,6 +1314,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) CPUState *cs =3D CPU(dev); RISCVCPU *cpu =3D RISCV_CPU(dev); RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); + CPURISCVState *env =3D &cpu->env; Error *local_err =3D NULL; =20 cpu_exec_realizefn(cs, &local_err); @@ -1313,6 +1335,20 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 + if (cpu->cfg.ext_g) { + riscv_cpu_enable_g(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + + /* + * Sync env->misa_ext_mask with the new + * env->misa_ext val. + */ + env->misa_ext_mask =3D env->misa_ext; + } + riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170147; cv=none; d=zohomail.com; s=zohoarc; b=bUrEen/DSfE7Sgw3/fbl662hzvg6EwB/jrU4UWToPLxsVnKtD8s3gRIey/ukGLrJktieKm5AYzjt6e1rmTAZxu0Xzyn8iLEK5QWUE55c8LDPu96bV42yHknMdZe8pPBqMv2wynnzsWljMH/s/qsGWNtEohnuNy1TuaXGRFzzysM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170147; 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=ZeqEOURtN5CDBkL3IgSdpJl1qZrPfTDtB0kVopaF1e8=; b=JjkRpkDWS2RAyfIP4Za0PfzOnNwiXbi0I+GqEZqHIVeXN5TqjlZqXMqxhy7LSu/CaZUgV4WRCOag2/oY46wZm2tsgwvkbQUdy+v50lWS5qvClJSMHe6mgCeMBmZy8ly4znQS2cMEaG416uceTx3p+N4kAa3/0ypThzAtD2mgjO4= 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 1679170147244706.3086514161906; Sat, 18 Mar 2023 13:09:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdco2-0005Ka-7X; Sat, 18 Mar 2023 16:05:34 -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 1pdcnz-0005KA-06 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:31 -0400 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcnw-0007BL-UB for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:30 -0400 Received: by mail-ot1-x32a.google.com with SMTP id v17-20020a9d6051000000b0069a413e9cf6so4728844otj.3 for ; Sat, 18 Mar 2023 13:05:28 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169927; 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=ZeqEOURtN5CDBkL3IgSdpJl1qZrPfTDtB0kVopaF1e8=; b=A/0C9rtKOPii4JegLaBJOcO7zbtonVzOzArmLr7Vd3MFO5GgGyWQyUMGdCyNhtpUGP IRSYNFTowhjLRjO01H498YmbAE3nrEwOAB77M6hlAzMxewkYiZhnoqRt21zJ5/dw8It+ ytjw4+qa+2AR3M6KkyIXm1/rMR34f6/YPPlsrkTeCAhnd+HlWIDmEQppG5pmO8CTDLB8 h+FsRSZIAivttvYM16WRY77Rp76A75DYLjyM9HdPGoqSlmVPJ2/iAoOMgeynX5YjUgbL aVu0rx8IwGzDUZIbMP8fhNaX4s/PJ6ZSFXJD4aPXJ2BWcCB1DSiOOZF+LIjDD3DOm6kF n55g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169927; 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=ZeqEOURtN5CDBkL3IgSdpJl1qZrPfTDtB0kVopaF1e8=; b=tUdMVp1furTb+cr8kYnPGxTl5YiPPry0uJ5lmWxwM368Ic5IYBWS7Do0Tqv19JdsRD rTnsB9LyXZKb1wtz8wYOisEC+8a4bjwVy6Qfu5SEIvXd1hlA/8yNMqvoGyEh2voIodD7 Hu+m3LJtu1iapSFT1jrS4wQajkQ3QTqxFTIgkIdDiym8TrIjiQ6xffeH1DyTeZI8eRkm 0HUeKSi4ZUH+edAX9Cb/E1m46q6//kZ80vFeyMTVrsMftij2QZfGL55Zd2UNegLc9XZC 039S6tcQ4tfOufZqMPf8oEB6YvViuEk36kuT4rLU3ZjDUcN7APPIAcetNggaVpLJqWj9 rE+Q== X-Gm-Message-State: AO0yUKU8of7H7TklL9LwyZ1YXO0pZhEJ2IV0SdnoS7tdThuI9jxUOz2k dJTMRlpbAcfD/FobcXzOjPPocjaVlXDloJWy36M= X-Google-Smtp-Source: AK7set9aLO4CVYn1gGxQgN/WU8lUCvS1bfk9h+JLtTRsLokyQ2kAbE6T/BWwFrai1B7Wb+X9EK6QgQ== X-Received: by 2002:a05:6830:1e29:b0:698:b03a:4fc0 with SMTP id t9-20020a0568301e2900b00698b03a4fc0mr1528100otr.24.1679169927660; Sat, 18 Mar 2023 13:05:27 -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 for-8.1 v3 16/26] target/riscv/cpu.c: add riscv_cpu_validate_misa_ext() Date: Sat, 18 Mar 2023 17:04:26 -0300 Message-Id: <20230318200436.299464-17-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::32a; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x32a.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170149020100005 Content-Type: text/plain; charset="utf-8" Even after taking RVG off from riscv_cpu_validate_set_extensions(), the function is still doing too much. It is validating misa bits, then validating named extensions, and if the validation succeeds it's doing more changes in both cpu->cfg and MISA bits. It works for the support we have today, since we'll error out during realize() time. This is not enough to support write_misa() though - we don't want to error out if userspace writes something odd in the CSR. This patch starts splitting riscv_cpu_validate_set_extensions() into a three step process: validate misa_ext, validate cpu->cfg, then commit the configuration. This separation will allow us to use these functions in write_misa() without having to worry about saving CPU state during runtime because the function changed state but failed to validate. riscv_cpu_validate_misa_ext() will host all validations related to misa bits only. Validations using misa bits + name extensions will remain in validate_set_extensions(). Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 77 ++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 110b52712c..c7b05d7c4e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1025,6 +1025,43 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RIS= CVCPU *cpu) } } =20 +static void riscv_cpu_validate_misa_ext(RISCVCPU *cpu, Error **errp) +{ + if (cpu->cfg.ext_i && cpu->cfg.ext_e) { + error_setg(errp, + "I and E extensions are incompatible"); + return; + } + + if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { + error_setg(errp, + "Either I or E extension must be set"); + return; + } + + if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { + error_setg(errp, + "Setting S extension without U extension is illegal"); + return; + } + + if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { + error_setg(errp, + "H depends on an I base integer ISA with 32 x registers= "); + return; + } + + if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { + error_setg(errp, "H extension implicitly requires S-mode"); + return; + } + + if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { + error_setg(errp, "D extension requires F extension"); + return; + } +} + static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) { RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(cpu); @@ -1072,35 +1109,6 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) return; } =20 - if (cpu->cfg.ext_i && cpu->cfg.ext_e) { - error_setg(errp, - "I and E extensions are incompatible"); - return; - } - - if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { - error_setg(errp, - "Either I or E extension must be set"); - return; - } - - if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { - error_setg(errp, - "Setting S extension without U extension is illegal"); - return; - } - - if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { - error_setg(errp, - "H depends on an I base integer ISA with 32 x registers= "); - return; - } - - if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { - error_setg(errp, "H extension implicitly requires S-mode"); - return; - } - if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { error_setg(errp, "F extension requires Zicsr"); return; @@ -1120,11 +1128,6 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) return; } =20 - if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { - error_setg(errp, "D extension requires F extension"); - return; - } - /* The V vector extension depends on the Zve64d extension */ if (cpu->cfg.ext_v) { cpu->cfg.ext_zve64d =3D true; @@ -1349,6 +1352,12 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) env->misa_ext_mask =3D env->misa_ext; } =20 + riscv_cpu_validate_misa_ext(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + riscv_cpu_validate_set_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170030; cv=none; d=zohomail.com; s=zohoarc; b=WlXzwg9Vn/wmY+hrwgCb3HGjdgBClauWigrSH/5TqqqOf3KO1an0WIFiohlqYPy3G3Ck8TuQnSY7M79y2ZA8gLyiRiZ8bE+UCE0MSCr4dtgiE4AzRXH87AXVP0TkUnf2cBMXdqQ/PaqgPdtzKSM7hei7AYaLxx++IR/UFVRa5ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170030; 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=jJI1LTNEi5JDEtIjvTg/4fJy3Lb5havlDQtBmIy6/Rw=; b=WPX4BP857jbR7jFDJaNGtsO53dhutMAxGN4zYws46SZ/d4EtANN3zbol5fFYAilceG2YUlamx+fe+Dg50+6f5Td+K12HsfwQ5/tZk5x52sNnLK5JFCeCvJcCq3VigebLBSr3uuKXWEwsz70+IZzPz0R6XpF86qubqe2fVvPwGMU= 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 1679170030954636.3869226246974; Sat, 18 Mar 2023 13:07:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdco6-0005NZ-4Z; Sat, 18 Mar 2023 16:05:38 -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 1pdco1-0005Ke-IS for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:34 -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 1pdcnz-0007Bh-PB for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:33 -0400 Received: by mail-oi1-x22a.google.com with SMTP id w133so6224652oib.1 for ; Sat, 18 Mar 2023 13:05:31 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169930; 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=jJI1LTNEi5JDEtIjvTg/4fJy3Lb5havlDQtBmIy6/Rw=; b=FagsUicAxTHIo/ffncRUMea8dn4sYWigY/Cjx85yJp8JlzweAcJGbtN8UQWBs9n8RK pRLK9StqniffKCCsPz6b4UG27kbTY6yFBVR+FoAvPrxRrYY7JVw8LTO9x0wGra5JMJJb GJW156PoGso7z+xdCy8Rp7BKlpzdICwoa2sjvOBqnA43+TkUWPcGMDlYJJBlAhrVJSmO G206+dBNIdbtcx783RJB2o3mn5NKckFUicJrOCt06a1jIRGiUAhMF1+pjtCCVhS/4R7v 41o71MGs/5e0JOfPjzBo9vyDuqC0fyG1gC/O291p1RnZS27FUjpJLA7pMs1xt2/dXSaM 9doA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169930; 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=jJI1LTNEi5JDEtIjvTg/4fJy3Lb5havlDQtBmIy6/Rw=; b=4AaY7YvkbemXoHK259YUn1VjxVoMVu/k/RZmLOFtpI37gRHUQtEEXC0lh/Sr50EMKT sdWpfRf4WuxM8YqJqytBO5hVFkr3K+9q2nCpHNQd/6OMP7QoqVcsBknU9V0MnmVb3HbI imPZP04dvi1VGW4sdp3zTjYt7fHOFA9PTaa1HFVleh8SUcvvagxGzH3LoKdFzIU0Txyz 0O9lP8Qe50pmgajj1TeE0H2Hef8h6lzFDDeM6jkaG6QIgGULzWWTs1/GEtC6ZlyUzVQb wZABDlHyYoVdzluvdJCesl3g4qjc6GV9NPkh8qCs2evpJE8KCHCB786r4jPYVTbnJBWp hWpA== X-Gm-Message-State: AO0yUKUjk4xWMTOCTqCYILaCcBYeHD0KlRBbdP9aR3rk0d8xaBwTblVW y3/O0jsoSxhsHNsRU7I3avEDBP8CuwH/a6D8VQE= X-Google-Smtp-Source: AK7set8utNVRU5XWAsrmxGtvHMv59DBC769Wz7P4cjAhOd315davIaTPyLDmf2+37Mrur/urOECZLg== X-Received: by 2002:aca:1a09:0:b0:386:c625:5cd7 with SMTP id a9-20020aca1a09000000b00386c6255cd7mr3801721oia.24.1679169930514; Sat, 18 Mar 2023 13:05:30 -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 for-8.1 v3 17/26] target/riscv: move riscv_cpu_validate_v() to validate_misa_ext() Date: Sat, 18 Mar 2023 17:04:27 -0300 Message-Id: <20230318200436.299464-18-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170032552100001 Content-Type: text/plain; charset="utf-8" riscv_cpu_validate_v() consists of checking RVV related attributes, such as vlen and elen, and setting env->vext_spec. This can be done during riscv_cpu_validate_misa_ext() time, allowing us to fail earlier if RVV constrains are not met. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index c7b05d7c4e..1116686cd1 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1027,6 +1027,9 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISC= VCPU *cpu) =20 static void riscv_cpu_validate_misa_ext(RISCVCPU *cpu, Error **errp) { + CPURISCVState *env =3D &cpu->env; + Error *local_err =3D NULL; + if (cpu->cfg.ext_i && cpu->cfg.ext_e) { error_setg(errp, "I and E extensions are incompatible"); @@ -1060,6 +1063,14 @@ static void riscv_cpu_validate_misa_ext(RISCVCPU *cp= u, Error **errp) error_setg(errp, "D extension requires F extension"); return; } + + if (cpu->cfg.ext_v) { + riscv_cpu_validate_v(env, &cpu->cfg, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + } } =20 static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) @@ -1097,7 +1108,6 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu= , Error **errp) static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; - Error *local_err =3D NULL; uint32_t ext =3D 0; =20 if (cpu->cfg.epmp && !cpu->cfg.pmp) { @@ -1188,14 +1198,6 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) } } =20 - if (cpu->cfg.ext_v) { - riscv_cpu_validate_v(env, &cpu->cfg, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); - return; - } - } - if (cpu->cfg.ext_zk) { cpu->cfg.ext_zkn =3D true; cpu->cfg.ext_zkr =3D true; --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170011; cv=none; d=zohomail.com; s=zohoarc; b=MLHDTlVpf26s8t/9BocK2Vk/3cNXViK+IRNds0hB8WTB+7LXEUtYacZnaKZszj/ZQ1eJM0yXQrG/QTJwQTASfKf7oLcaC/1zTEUdKnLtjGENe/bS4CnDjF4gnaRKPtyCxFh1QvCghbrNNJkZpsIMWbc+ajS63ixmN1aiLDFc+po= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170011; 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=gUrnUOKftNGP2FPSgVGe+TWqw1fM66zN2Xsxfp1nXPw=; b=Q+vMZcA1ZdHUBB5qXaQkvUs/y2gj9DeWDDhVzX1XPrX/eBLPavZVQKz6slX0q35LsKlOGYR+FNbOZ0wOesoBy2CY4RUDKQYsmUhKxcx0CdPrtSnPuG8x7xLinJA3OlgGGO2sYLDRH4Lf/LHx0nzH3VJLK1UlnA3bqSc5YeGo2iM= 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 1679170011864193.0589794207607; Sat, 18 Mar 2023 13:06:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoE-0005WJ-GX; Sat, 18 Mar 2023 16:05:46 -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 1pdco4-0005Mw-L7 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:37 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdco2-0007Ar-FU for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:36 -0400 Received: by mail-oo1-xc30.google.com with SMTP id o26-20020a4ad49a000000b0053964a84b0fso687988oos.7 for ; Sat, 18 Mar 2023 13:05:34 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169933; 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=gUrnUOKftNGP2FPSgVGe+TWqw1fM66zN2Xsxfp1nXPw=; b=heibx168Er1sG2NUbiSDctbboJE/mqRffmb62ngiT8U6gUrVGJFEY8BXR+jDlkmmfK Dc7R1rTRpSKjVh7WEa0aitO0PdtwzmDD5N89ZtWHAr6/fcP15UlZehPJSEWDqqSfaIdK aeCXW1IxtGMBDv3R0gF441t0VmHrhVODi7Jc2LFKdqG4jeNhvtDiqLK7szPb71aAmS9B bXdMafDBsIsKX1tbved9KcZRn7Ko4MdCd0HndNxYzpwPCKRDurDFnRJ5Ywb/v3pBC3VM /eVx2KA78yspnv0NoPuhv7dw4vBI1nQGcHiQ778NLUaDZ7qJREa/RdKW5ckeLdLTyrjA 6lxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169933; 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=gUrnUOKftNGP2FPSgVGe+TWqw1fM66zN2Xsxfp1nXPw=; b=WDFJ2pW9bUJB5/vwHXzBD9ZJq0Fmpays2P0T5Odye7BjZo2Gz8kDCwM8pD7bI+GQOa rz3DDR+lBSM6GXS623LQ9cqg91c+14bkOZKCUcziAn9DrayVbjFRKiiPG3Ggpl+cPbrO LxHJuTAmK3IGsFJkuMCkrTu1iMW3QqZ5FUf1aBEorDppH7Ev/wPriGHChJwlUZyVFIlU Ixr0muWcUw/ImBVsH/aUyF5AsYms632F8fmW8Dlx027sF1tT3Sfko/mQXswXTVvUgoZl KUGykrBfQf7o21+RLeZBlN3O4i+dwbvbmAcpS3yXRR+HQDpWAJ2eH1PYufFd0I0fWRD2 Nj6g== X-Gm-Message-State: AO0yUKVr3Usy3WSa1AyC91NMCXEAHa/uaebRaynVyRUsunAi3a2OTLY2 hNeKD75cSZeHey5dQ2k1S8mo5VPLx0zArwJ/bhk= X-Google-Smtp-Source: AK7set/NPEzzz7ZFgc9YqJ8BKDThOzNXtCYhO7/oiLO3z0SmSGtIxQXAGU8TwL+sLynvJ+X31Q8iLA== X-Received: by 2002:a4a:330d:0:b0:538:cf7f:d5cb with SMTP id q13-20020a4a330d000000b00538cf7fd5cbmr1506535ooq.1.1679169933445; Sat, 18 Mar 2023 13:05:33 -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 for-8.1 v3 18/26] target/riscv: error out on priv failure for RVH Date: Sat, 18 Mar 2023 17:04:28 -0300 Message-Id: <20230318200436.299464-19-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c30; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc30.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170012355100003 Content-Type: text/plain; charset="utf-8" riscv_cpu_disable_priv_spec_isa_exts(), at the end of riscv_cpu_validate_set_extensions(), will disable cpu->cfg.ext_h and cpu->cfg.ext_v if priv_ver check fails. This check can be done in riscv_cpu_validate_misa_ext(). The difference here is that we're not silently disable it: we'll error out. Silently disabling a MISA extension after all the validation is completed can can cause inconsistencies that we don't have to deal with. Verify ealier and fail faster. Note that we're ignoring RVV priv_ver validation since its minimal priv is also the minimal value we support. RVH will error out if enabled under priv_ver under 1_12_0. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 1116686cd1..d8f2eca6ca 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1064,6 +1064,20 @@ static void riscv_cpu_validate_misa_ext(RISCVCPU *cp= u, Error **errp) return; } =20 + /* + * Check for priv spec version. RVH is 1_12_0, RVV is 1_10_0. + * We don't support anything under 1_10_0 so skip checking + * priv for RVV. + * + * We're hardcoding it here to avoid looping into the + * 50+ entries of isa_edata_arr[] just to check the RVH + * entry. + */ + if (cpu->cfg.ext_h && env->priv_ver < PRIV_VERSION_1_12_0) { + error_setg(errp, "H extension requires priv spec 1.12.0"); + return; + } + if (cpu->cfg.ext_v) { riscv_cpu_validate_v(env, &cpu->cfg, &local_err); if (local_err !=3D NULL) { --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170114; cv=none; d=zohomail.com; s=zohoarc; b=g59+UYG1wvKOEwVmCAyqD7cuxDNcz+Ay8TSWYNg+VySW8TYTayZ4aso4E9qrV1he/E5aMSYi/H2302QTfAO/PFlAa+hT4D/8LKzZpdPISXXzGLpd1QazlOqrCy+yBW2egfcL/IqAr+0nh9NGTB/wfA9k9HSStv/wu59TuIzdDBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170114; 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=4KwQdqmQndsZzKf5aoxFmYpjUR9gPSzP9IGgqEepMGk=; b=j2pEIRAEn/aZ3bZhRGkxQLUfS3SlLi6oYXf9yUAyPuemDLs9gFNmEkyX4RH5BA2HYEdvzC8T4rXLX1+p8rV030VzpJr6w7+ulgpzoLlVyIDyRtzMQ94WGNs2DdAQ/v7wxHYS6SWaoz57AObtwaYdP9cDFFnasXSWv6J3EB/c4W4= 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 1679170114747161.4142653441703; Sat, 18 Mar 2023 13:08:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoG-0005eu-AH; Sat, 18 Mar 2023 16:05:48 -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 1pdco7-0005Pr-OZ for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:40 -0400 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdco5-0007Ch-Kg for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:38 -0400 Received: by mail-oi1-x22e.google.com with SMTP id bd36so6189297oib.12 for ; Sat, 18 Mar 2023 13:05:37 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169936; 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=4KwQdqmQndsZzKf5aoxFmYpjUR9gPSzP9IGgqEepMGk=; b=St8Hl0tlRESllXEwP+0ih4iKVL+TTzDtFoyIEgzWyEnsZH2A0U85Vl8r+pUP6KXZ9E rICNveRlNIndqOvHs5q83pRx+AZndiFtdRnh/o5XcBol9o7Scizx43tW65/zSZXfLy+C zilFCCTQfhlYe1DDJC4ULuF0UgRlgDpYgUE8srztt/3JEDM/7xjeU6r98A59NNTcSihv 1kSOJO+38b7LNnC+gxBeuzPQvFnW6PYG25cNFjd8BXD0YNVv/ai9gkzrTNH8E6H3nVfl /B8R/Hh2W/sqKuLHrisscjwNx6hgcrfnpeRx32pqlCILj49HDHJuctuJASVoJV6z8FW1 D20w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169936; 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=4KwQdqmQndsZzKf5aoxFmYpjUR9gPSzP9IGgqEepMGk=; b=F5KlqXDFEwQT70+pDY4xzpC4x75XUwl4uidcSoJHDJJWwJuvr7X8jjTdFHouNK2bne 3z4LnCiiBSeFexRZ89ZyeAFEnrhI/ly+nfNlK8v2VkdG+ba6X7mvEF6Bp3cW6MgZsNkS Igmwp2kaK1us0whiUv3H6yA4rTarTTQOG0D4IRXNMOauYb3UdexZt01+Nrz1l2G5K2mn gas7tsNqd035JIR7G8R5+lKWtO4JViSBYtWiYbCeUBpbTt4LwzpUzwWWjpfd0TmMirah +P/0ZXsgQOda5FTlBnQ5m84PpebOlxMWLjBv4ksX5VTC1j9fGSoN9r9K5HU6LU8OkuGy MjEw== X-Gm-Message-State: AO0yUKUq8bWWMN2Iz5cHO3Kg8K/rq1fAtc+1p3PD7viiJXJHQWlSG6cu 2jOMz5ApOSMiD6jN5EDqjBZ6yDsdHpzf4c0qgTY= X-Google-Smtp-Source: AK7set9iOhNEUUBHHLVxgqSx47m00Q7iLVf7YOaJY0pppyu0COcH9pPiWuoLuq05AtuOpTTosljX6A== X-Received: by 2002:a05:6808:8cc:b0:36b:fbdb:eb61 with SMTP id k12-20020a05680808cc00b0036bfbdbeb61mr6554962oij.23.1679169936188; Sat, 18 Mar 2023 13:05:36 -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 for-8.1 v3 19/26] target/riscv: write env->misa_ext* in register_generic_cpu_props() Date: Sat, 18 Mar 2023 17:04:29 -0300 Message-Id: <20230318200436.299464-20-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22e; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22e.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170116927100003 Content-Type: text/plain; charset="utf-8" In the process of creating the user-facing flags in register_generic_cpu_props() we're also setting default values for the cpu->cfg flags that represents MISA bits. Leaving it as is will cause a discrepancy between users of this function (at this moment the non-named CPUs) and named CPUs. Named CPUs are using set_misa() with a non-zero 'ext' value, writing cpu->cfg in the process. They'll reach riscv_cpu_realize() in a state where env->misa_ext will reflect cpu->cfg, allowing functions to choose whether to use env->misa_ext or cpu->cfg to validate MISA bits. If we guarantee that env->misa_ext will always reflect cpu->cfg at the start of riscv_cpu_realize(), functions will be able to no longer rely on cpu->cfg for MISA validation. This happens to be one blocker we have to properly support write_misa(). Sync env->misa_ext* in register_generic_cpu_props(). After that, there will be no more places where env->misa_ext needs to be sync back with cpu->cfg, so remove the now obsolete code at the end of riscv_cpu_validate_set_extensions(). Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d8f2eca6ca..992edd1735 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1116,14 +1116,10 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *c= pu, Error **errp) =20 /* * Check consistency between chosen extensions while setting - * cpu->cfg accordingly, setting env->misa_ext and - * misa_ext_mask in the end. + * cpu->cfg accordingly. */ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) { - CPURISCVState *env =3D &cpu->env; - uint32_t ext =3D 0; - if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* * Enhanced PMP should only be available @@ -1240,10 +1236,6 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) * validated and set everything we need. */ riscv_cpu_disable_priv_spec_isa_exts(cpu); - - ext =3D riscv_get_misa_ext_with_cpucfg(&cpu->cfg); - - env->misa_ext_mask =3D env->misa_ext =3D ext; } =20 #ifndef CONFIG_USER_ONLY @@ -1354,6 +1346,10 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) return; } =20 + /* + * This is the last point where env->misa_ext* can + * be changed. + */ if (cpu->cfg.ext_g) { riscv_cpu_enable_g(cpu, &local_err); if (local_err !=3D NULL) { @@ -1631,10 +1627,12 @@ static Property riscv_cpu_extensions[] =3D { * Register generic CPU props with user-facing flags declared * in riscv_cpu_extensions[]. * - * Note that this will overwrite existing values in cpu->cfg. + * Note that this will overwrite existing values in cpu->cfg + * and MISA. */ static void register_generic_cpu_props(Object *obj) { + RISCVCPU *cpu =3D RISCV_CPU(obj); Property *prop; DeviceState *dev =3D DEVICE(obj); =20 @@ -1645,6 +1643,10 @@ static void register_generic_cpu_props(Object *obj) #ifndef CONFIG_USER_ONLY riscv_add_satp_mode_properties(obj); #endif + + /* Keep env->misa_ext and misa_ext_mask updated */ + cpu->env.misa_ext =3D riscv_get_misa_ext_with_cpucfg(&cpu->cfg); + cpu->env.misa_ext_mask =3D cpu->env.misa_ext; } =20 static Property riscv_cpu_properties[] =3D { --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170098; cv=none; d=zohomail.com; s=zohoarc; b=O6APt/KcgiQzK+jddtuPjSEHmIiYltb6BBqxdPGQ2shsbMm8MwEWRNYzzTAPKFlShIdMKOd4pb/FEkkTlRZSAvYuxvPKzTUgg6Mb5g4uPEEg2kPJfi+novE260nl3e9ElGRKDB2JEbBQS6kXT4/qXUSZaLih/8CJxVOJqFo3ino= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170098; 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=Q714BCJSZCAT1Di5JEJb4MnSNj0uuugGITfPZhRYTT0=; b=NVoEkT7Nd1Lt41aFV2pA9ulbcwuO0KSPte35w7XlNT5DdHiDhfK79YTFNzz+jjJApCyPqT1dkLoo9TqDXhEa/0dI1HlZkwCGZhGOSvxfRWATK5Hk2movOzO41L6p43kQ4nHg2XG7RZCRZlpb2YeyGe+uVad2CKq8aMzRFdzj8Lg= 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 1679170095050740.2898278492034; Sat, 18 Mar 2023 13:08:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoG-0005fj-Jc; Sat, 18 Mar 2023 16:05:48 -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 1pdcoA-0005U0-86 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:43 -0400 Received: from mail-oo1-xc34.google.com ([2607:f8b0:4864:20::c34]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdco8-0007DE-LJ for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:41 -0400 Received: by mail-oo1-xc34.google.com with SMTP id a23-20020a4ad5d7000000b005250867d3d9so1316486oot.10 for ; Sat, 18 Mar 2023 13:05:40 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169939; 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=Q714BCJSZCAT1Di5JEJb4MnSNj0uuugGITfPZhRYTT0=; b=A1g5xa79fjA18sAzfH9xqH6ZE8Lk4JIvvbfl7Du2o1XHiDwA8zg1cbgcnY6ALrwzmv rpFsTVt21FZruVVeZy6CvNHQao7gq9dCctW0bWeRLEY5rchizYVLBvWagfOCGaGhBJk0 PYPGAtR8SMX3xhD2sMLm/ZkRe4pXg9lsSbO/pFSW6kc1DZbLpn88yIY9B7tJd+hkNsji 4n2ZMceeNQ1U8iOtXfGlgAxhYA7qDDcs5ETlxlXfWPp46aeystLJ2X0hFftuqfDo60m3 GBjCEjkFORMih1rxsw9rdQ13bsOTfqZ8GHh+uEu0ym9mfAiqBMekGPUP1GCHCJYAcxUN SpIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169939; 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=Q714BCJSZCAT1Di5JEJb4MnSNj0uuugGITfPZhRYTT0=; b=xsrARo9s5EywiwD6l3qV+L4TJAJ8VTCUwPQdAJdbQ9sdTMU2tF3jvw+N3pFbIQAv5a pnNQ5tZBqlFLTpAP8YKisNaQsJgAioCx3qfAGZgx0SmCW//CN2b6VUUgd5yKbghXmgsy IP3hfSfCgNpsd2OWtKuIzeEsQW6F1ZzNa5hOSgAIhNVHMlCv5TgunjwhuKO+riJyk9El rCuxodh5Kjj6nLv63+GtM6PWFkkrpTBzY+1R4DO+ABvLCcLvaRFBM7SxgBwhVbjl23uh 0Q5SR+EC9xPfpw58fWeL22AXraDueggKN/V3q2Ci8STZ0pzZhWoaTEOYLOf8oT2ebyqF mwAw== X-Gm-Message-State: AO0yUKWy6JN71jNkOmTx6puP7dcfhBjki97hO3m1V2foUlZzDwF+RRaI /Z7Yu9gt3puXbxE2TM1noPurrXoCdSO4QVzN5PA= X-Google-Smtp-Source: AK7set9DYFZw0VgBrdXNdUkeipHZwCBRKdS/UMveC7lMx164zUPeUBKDnNpTcfdOCQXWCm4VXZhP/g== X-Received: by 2002:a4a:3395:0:b0:534:c38a:dafd with SMTP id q143-20020a4a3395000000b00534c38adafdmr602412ooq.6.1679169939262; Sat, 18 Mar 2023 13:05:39 -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 for-8.1 v3 20/26] target/riscv: make validate_misa_ext() use a misa_ext val Date: Sat, 18 Mar 2023 17:04:30 -0300 Message-Id: <20230318200436.299464-21-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::c34; envelope-from=dbarboza@ventanamicro.com; helo=mail-oo1-xc34.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170098844100001 Content-Type: text/plain; charset="utf-8" We have all MISA specific validations in riscv_cpu_validate_misa_ext(), and we have a guarantee that env->misa_ext will always be in sync with cpu->cfg at this point during realize time, so let's convert it to use a 'misa_ext' parameter instead of reading cpu->cfg. This will prepare the function to be used in write_misa() where we won't have an updated cpu->cfg object to work with. riscv_cpu_validate_v() is changed to receive a const pointer to the cpu->cfg object via riscv_cpu_cfg(). Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 992edd1735..7861f0421e 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -939,7 +939,8 @@ static void riscv_cpu_disas_set_info(CPUState *s, disas= semble_info *info) } } =20 -static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, +static void riscv_cpu_validate_v(CPURISCVState *env, + const RISCVCPUConfig *cfg, Error **errp) { int vext_version =3D VEXT_VERSION_1_00_0; @@ -1025,41 +1026,43 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RI= SCVCPU *cpu) } } =20 -static void riscv_cpu_validate_misa_ext(RISCVCPU *cpu, Error **errp) + +static void riscv_cpu_validate_misa_ext(CPURISCVState *env, + uint32_t misa_ext, + Error **errp) { - CPURISCVState *env =3D &cpu->env; Error *local_err =3D NULL; =20 - if (cpu->cfg.ext_i && cpu->cfg.ext_e) { + if (misa_ext & RVI && misa_ext & RVE) { error_setg(errp, "I and E extensions are incompatible"); return; } =20 - if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { + if (!(misa_ext & RVI) && !(misa_ext & RVE)) { error_setg(errp, "Either I or E extension must be set"); return; } =20 - if (cpu->cfg.ext_s && !cpu->cfg.ext_u) { + if (misa_ext & RVS && !(misa_ext & RVU)) { error_setg(errp, "Setting S extension without U extension is illegal"); return; } =20 - if (cpu->cfg.ext_h && !cpu->cfg.ext_i) { + if (misa_ext & RVH && !(misa_ext & RVI)) { error_setg(errp, "H depends on an I base integer ISA with 32 x registers= "); return; } =20 - if (cpu->cfg.ext_h && !cpu->cfg.ext_s) { + if (misa_ext & RVH && !(misa_ext & RVS)) { error_setg(errp, "H extension implicitly requires S-mode"); return; } =20 - if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { + if (misa_ext & RVD && !(misa_ext & RVF)) { error_setg(errp, "D extension requires F extension"); return; } @@ -1073,13 +1076,13 @@ static void riscv_cpu_validate_misa_ext(RISCVCPU *c= pu, Error **errp) * 50+ entries of isa_edata_arr[] just to check the RVH * entry. */ - if (cpu->cfg.ext_h && env->priv_ver < PRIV_VERSION_1_12_0) { + if (misa_ext & RVH && env->priv_ver < PRIV_VERSION_1_12_0) { error_setg(errp, "H extension requires priv spec 1.12.0"); return; } =20 - if (cpu->cfg.ext_v) { - riscv_cpu_validate_v(env, &cpu->cfg, &local_err); + if (misa_ext & RVV) { + riscv_cpu_validate_v(env, riscv_cpu_cfg(env), &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); return; @@ -1364,7 +1367,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) env->misa_ext_mask =3D env->misa_ext; } =20 - riscv_cpu_validate_misa_ext(cpu, &local_err); + riscv_cpu_validate_misa_ext(env, env->misa_ext, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); return; --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170066; cv=none; d=zohomail.com; s=zohoarc; b=URRk6ASbnTWzK64sy8+4aKGClm1l/Kg8x50t8ra1xwTrd8po4eTvUtfEOXXUeDRpyl5sT1oq4OEetxI8hMx6AaXIE25dUBkP9KiqNbqgRR5VpnDWQR/GbGTGc8YB0XWyMRNRt+gqFYx6jU+S0cUnww2JyKj4NuKigCIk7Muh8z8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170066; 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=o0rl6JVpTdkHoeH1u/5HjB+UHq/yyk05dEosKdOXvJw=; b=UsFnmyj3ZfJ+V2XCI7GBnfo3PufpQDKJ5tPFvKtQrB3IF/LdPBBMv/Rfo3N8Vg4OvkoNiDZuIeuJRwejowD1z6bsG5HgYSG/ZpSDSyZ4UWqNR4Cf3RjR37QLJdOovSXZXlBB6xQarORrYDQvxWihnqkHLkGz4U53frU4YXOuI6g= 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 1679170066664171.7424029119975; Sat, 18 Mar 2023 13:07:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoJ-0005i3-5E; Sat, 18 Mar 2023 16:05:51 -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 1pdcoF-0005cg-Kw for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:47 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcoD-0007Dk-Qt for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:47 -0400 Received: by mail-oi1-x22d.google.com with SMTP id s41so6188335oiw.13 for ; Sat, 18 Mar 2023 13:05:44 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169943; 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=o0rl6JVpTdkHoeH1u/5HjB+UHq/yyk05dEosKdOXvJw=; b=B/WAdZEsdVOWX8r/G2ajpzw36NW0da4XK/Pwugmukdq3QjpTPopi92hWPBwat7eQy9 PzrHq6zFecaa7OQovf/f9bp8lF6uf5z0betRHSQ1BOfKokq8Mp8+tQ1CLmiayiadM8p4 npfqEapNOcTr/7iGfOG9P73ypUwVJHoReJxwggDI2e2vgpBHAjJsINNIwvb+NqKikmKx bNwlfxicNg3Tu5jQR0XB449KsQUz1oZrJkMSGdLevZ0Yxwrr5Mr2pYGQsQR9VIGDNGt4 vbFIaMecFh3vDoNPshZmcG1UuR8Cvp2PPcOWWtCHJreIRJRzyMkyFEClCaXft7nkG3g8 ytiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169943; 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=o0rl6JVpTdkHoeH1u/5HjB+UHq/yyk05dEosKdOXvJw=; b=TGDTE+yTBsBzNSa2WWevDQVyurm9nWYNTwHIKDVaSc3vKTmlGY+/Enxg5W5lHX4kGB cUOMBQrx2P2LA//Y6+PAn4UlAMtDm53S2Vm9+2VN7tB9UJ5VuESLdEeS0h9PwNZ5cGB7 sjNAkorhgQsMwzY1wwnrRfvDuP1r+Aahf9A5/FuWg31IKqt+iSPpSSBRO7/+zW3oOr/O l/70ORfeU5zYpmiT5rPxR3dT4YLjpguRzwcICl+o4QFLRetACD3M5Ctf+AK6lEuD9Qi1 jOsE1tq4W2LUkJL8hhtKyoYwlHxRPYP5MjMV54gQo4p/HCfujuCl9i4QTd/pZiZdTFYS TIew== X-Gm-Message-State: AO0yUKU4cQI9f4N9WltkJK6Ngx/9MkfyKYUzk9TzFDqdLe7MiFefXjU0 BDgj2fUrQYLBnVU7ai67dSt3s8CcGm+jgu72DOE= X-Google-Smtp-Source: AK7set9XBji2pzM8Pr1EJXgHzyrNlmEJBFOEsQQXhJlRTHDqq6qn+l39/BeOh+qPUseWwUwBAw60zg== X-Received: by 2002:aca:2107:0:b0:384:3a4d:7f72 with SMTP id 7-20020aca2107000000b003843a4d7f72mr6543843oiz.9.1679169942039; Sat, 18 Mar 2023 13:05:42 -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 for-8.1 v3 21/26] target/riscv: split riscv_cpu_validate_set_extensions() Date: Sat, 18 Mar 2023 17:04:31 -0300 Message-Id: <20230318200436.299464-22-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22d.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170068712100003 Content-Type: text/plain; charset="utf-8" We're now ready to split riscv_cpu_validate_set_extensions() in two. None of these steps are going to touch env->misa_ext*. riscv_cpu_validate_extensions() will take care of all validations based on cpu->cfg values. cpu->cfg changes that are required for the validation are being tolerated here. This is the case of extensions such as ext_zfh enabling ext_zfhmin. The RVV chain enablement (ext_zve64d, ext_zve64f and ext_zve32f) is also being tolerated because the risk of failure is being mitigated by the RVV -> RVD && RVF dependency in validate_misa_ext() done prior. In an ideal world we would have all these extensions declared as object properties, with getters and setters, and we would be able to, e.g., enable ext_zfhmin as soon as ext_zfh is enabled. This would avoid cpu->cfg changes during riscv_cpu_validate_extensions(). Easier said than done, not just because of the hundreds of lines involved in it, but also because we want these properties to be available just for generic CPUs (named CPUs don't want these properties exposed for users). For now we'll work with that we have. riscv_cpu_commit_cpu_cfg() is the last step of the validation where more cpu->cfg properties are set and disabling of extensions due to priv spec happens. We're already validated everything we wanted, so any cpu->cfg change made here is valid. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7861f0421e..69fc0d17a5 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1118,10 +1118,10 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *c= pu, Error **errp) } =20 /* - * Check consistency between chosen extensions while setting - * cpu->cfg accordingly. + * Check consistency between chosen extensions. No changes + * in env->misa_ext are made. */ -static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) +static void riscv_cpu_validate_extensions(RISCVCPU *cpu, Error **errp) { if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* @@ -1210,7 +1210,10 @@ static void riscv_cpu_validate_set_extensions(RISCVC= PU *cpu, Error **errp) return; } } +} =20 +static void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu) +{ if (cpu->cfg.ext_zk) { cpu->cfg.ext_zkn =3D true; cpu->cfg.ext_zkr =3D true; @@ -1373,12 +1376,14 @@ static void riscv_cpu_realize(DeviceState *dev, Err= or **errp) return; } =20 - riscv_cpu_validate_set_extensions(cpu, &local_err); + riscv_cpu_validate_extensions(cpu, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); return; } =20 + riscv_cpu_commit_cpu_cfg(cpu); + #ifndef CONFIG_USER_ONLY if (cpu->cfg.ext_sstc) { riscv_timer_init(cpu); --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170026; cv=none; d=zohomail.com; s=zohoarc; b=LkIqCl6Oykig62eAZNnVOZ9UupLAFjtZp/7IjHQC2jmZH1WEFzGQdrbiRwMKfPZRtDQ3edyAePWWrlF1zZDCOLl5m081c2zzd1DFtHcLired9xxWESsZZZP6GX1IWkpXD30F8Q1S4BAPQILr1Y6YMhjdNoVRL7e839AmFmXPT1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170026; 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=EFLUuRJqF7aZfFtz85gk12Q0/bYGZM+qfzoZdHewqiQ=; b=RSKxFVOlJXZBzTd1L1YlQwKikibTCXypztoH7vo+Sbxi0cXNs2E2ZaIVF/ws0oLiFkQ60dBmhbCLeDbqcXxZgOPVTVMShVMNqs8N9dSGs6MIYDe9nElgwhVkZ+lluPRiT+IUdMbXqGO5jZsn6F5GEmCgrQPW/tDH8ALoIbjvHnU= 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 1679170026658586.7194034581474; Sat, 18 Mar 2023 13:07:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoK-0005j6-RZ; Sat, 18 Mar 2023 16:05:52 -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 1pdcoH-0005h5-HV for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:49 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcoE-0007EC-DK for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:48 -0400 Received: by mail-oi1-x234.google.com with SMTP id c11so6226101oiw.2 for ; Sat, 18 Mar 2023 13:05:45 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169945; 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=EFLUuRJqF7aZfFtz85gk12Q0/bYGZM+qfzoZdHewqiQ=; b=MwgDq068OkZ9/7JxkDP3L4+FmR+As4e1vU5Q40AHL8OsPnnx8o5Mq77YS9EDVWMBS5 PnahRFu+5NXXrKCPhqyIGOuUZoHPvcxQDbNynspP0UpgZYURT5+1Bcd1I9vxYBM5S4G4 hzk88hESWG13XdeQQHvY3t6GgHTt7KaPUrVVIj/oKtx5TZeVsTMXB94teOHWruOSutgL Ybz+7VUfait6TevYsVOAol3AhSjjlxy6l49CUDwDA0/dhsEF2BLnMjVDIjDOK80RFzJq F6b7xnBLdtR7DOj9cFv0jN6c7tYlfrTx5QvUOCfRknoyX9okKxMjhf/4qWRmIldcslZo sZiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169945; 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=EFLUuRJqF7aZfFtz85gk12Q0/bYGZM+qfzoZdHewqiQ=; b=oETR2+YjrczH1bM8HwGVdfCAbHsUBbzQ5J6KdZ9OAf/EprGEWyloz4bcxRep6H1tRl AsPOMBCstOixjsjHGi0vYjApqWeuyqlv0ivWeLbGJ7ZeLvouJ7tvWHMhuRrnUfzRG2aa E9xPuPx3BTrjDTuO0ur90ObkBkP0oFJQCtkBgK3WTxkh846SqI78EMoUN8UD9wAvfGiS nMMYdOjEZOiJlBu8IbomcGBPmk8tX2rJpV7jfp9bv8/o5CpNH659iDcgBDufmX19Lcnu mR4tFJpmZ6ffskVcw+xtRwIczYKU6lTwVgpc3dprNIqb5flgsElNXlOdzGbtUDD0A5/6 pCgg== X-Gm-Message-State: AO0yUKU4QYblB3afdfKrOSC4a+bl+llNzQp1B1v3gWE69a8WeJlVPrVI CsnIIbeRhIL1lNpBtRcGPA8Cpedfvwpq9vH/AWw= X-Google-Smtp-Source: AK7set/M3LDH9/T5dcC8fO7Ir9V3aTrLWzWAPH/XdzoPwLI9+54FS66QX/hqL+s1DzGD0jLMOyowsA== X-Received: by 2002:a05:6808:2a8c:b0:383:ca99:c70e with SMTP id fc12-20020a0568082a8c00b00383ca99c70emr6245363oib.59.1679169945001; Sat, 18 Mar 2023 13:05:45 -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 for-8.1 v3 22/26] target/riscv: use misa_ext val in riscv_cpu_validate_extensions() Date: Sat, 18 Mar 2023 17:04:32 -0300 Message-Id: <20230318200436.299464-23-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x234.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170028543100005 Content-Type: text/plain; charset="utf-8" Similar to what we did with riscv_cpu_validate_misa_ext(), let's read all MISA bits from a misa_ext val instead of reading from the cpu->cfg object. This will allow write_misa() to use riscv_cpu_validate_extensions(). Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 69fc0d17a5..e9172ec310 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1118,10 +1118,13 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *c= pu, Error **errp) } =20 /* - * Check consistency between chosen extensions. No changes - * in env->misa_ext are made. + * Check consistency between cpu->cfg extensions and a + * candidate misa_ext value. No changes in env->misa_ext + * are made. */ -static void riscv_cpu_validate_extensions(RISCVCPU *cpu, Error **errp) +static void riscv_cpu_validate_extensions(RISCVCPU *cpu, + uint32_t misa_ext, + Error **errp) { if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* @@ -1132,12 +1135,12 @@ static void riscv_cpu_validate_extensions(RISCVCPU = *cpu, Error **errp) return; } =20 - if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { + if (misa_ext & RVF && !cpu->cfg.ext_icsr) { error_setg(errp, "F extension requires Zicsr"); return; } =20 - if ((cpu->cfg.ext_zawrs) && !cpu->cfg.ext_a) { + if ((cpu->cfg.ext_zawrs) && !(misa_ext & RVA)) { error_setg(errp, "Zawrs extension requires A extension"); return; } @@ -1146,13 +1149,13 @@ static void riscv_cpu_validate_extensions(RISCVCPU = *cpu, Error **errp) cpu->cfg.ext_zfhmin =3D true; } =20 - if (cpu->cfg.ext_zfhmin && !cpu->cfg.ext_f) { + if (cpu->cfg.ext_zfhmin && !(misa_ext & RVF)) { error_setg(errp, "Zfh/Zfhmin extensions require F extension"); return; } =20 /* The V vector extension depends on the Zve64d extension */ - if (cpu->cfg.ext_v) { + if (misa_ext & RVV) { cpu->cfg.ext_zve64d =3D true; } =20 @@ -1166,12 +1169,12 @@ static void riscv_cpu_validate_extensions(RISCVCPU = *cpu, Error **errp) cpu->cfg.ext_zve32f =3D true; } =20 - if (cpu->cfg.ext_zve64d && !cpu->cfg.ext_d) { + if (cpu->cfg.ext_zve64d && !(misa_ext & RVD)) { error_setg(errp, "Zve64d/V extensions require D extension"); return; } =20 - if (cpu->cfg.ext_zve32f && !cpu->cfg.ext_f) { + if (cpu->cfg.ext_zve32f && !(misa_ext & RVF)) { error_setg(errp, "Zve32f/Zve64f extensions require F extension"); return; } @@ -1204,7 +1207,7 @@ static void riscv_cpu_validate_extensions(RISCVCPU *c= pu, Error **errp) error_setg(errp, "Zfinx extension requires Zicsr"); return; } - if (cpu->cfg.ext_f) { + if (misa_ext & RVF) { error_setg(errp, "Zfinx cannot be supported together with F extensio= n"); return; @@ -1376,7 +1379,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) return; } =20 - riscv_cpu_validate_extensions(cpu, &local_err); + riscv_cpu_validate_extensions(cpu, env->misa_ext, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); return; --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170169; cv=none; d=zohomail.com; s=zohoarc; b=JiVhIm1IVIBL0O7wcefytB0qaoFbb8NGkX1osu9Soj9kBLapRyIJ+Ug7GFWwephbAAEFDuwAy8FE/7m3EXgeR/C6jSPaXJ+a61Geu7/It/MfAB3m5dfn+fEE+1uzBquZ3QTaLYNASC8b1GJ8MSkAirG/bbwiZgz8JwqUFB1M/Sw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170169; 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=aDWF4TV4NNOMbib10TqpzKDvUtAnKVMCB7lDRnKm84M=; b=H4MUeObbSx/yOm5jG2I8C0cWGEQgQYiIhLTCQ3i7sUK76hOcJMtiLeQVtvBm9r+7UM43gwt+J9qLTE27mRrAb9AfAprfvwIsHRxvsvQue6F+3X8o/I+7VefWaElSbh8rnUVmYGMxrJn6SEEtd5++oXz9nsLIMO47OuWUfvx1KmE= 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 1679170169733740.486402348053; Sat, 18 Mar 2023 13:09:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoL-0005jk-Jt; Sat, 18 Mar 2023 16:05:53 -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 1pdcoJ-0005iM-Cg for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:51 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcoH-0007F7-9N for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:50 -0400 Received: by mail-ot1-x336.google.com with SMTP id x22-20020a056830409600b0069b30fb38f7so4726079ott.5 for ; Sat, 18 Mar 2023 13:05:48 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169948; 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=aDWF4TV4NNOMbib10TqpzKDvUtAnKVMCB7lDRnKm84M=; b=ba0mWAsBCDDr3qswfOgrbu3o5qGCD9jNSj+Lys8VaRURzu+8qpmOx6uNuItdxhIcJ6 JEgHgI75ogqAWJX/5YnWouFD1f2MQxsKQwZx1kyrsUwOEiw1Ewf/fVm0hx+24IyX5Yi8 9yzVsIvcTwC8KO2yBBjOAZRhfRaFgyxsjA9DN53LiW/bhiv8RUgqJTPmQsm+VCRbr0mr NoECNYC8Ny9FMuoMlzowPTW4dtzEp1OfqkxsBXSH037sKySjsSm8g6dcB3FyjjH2dsIn YnWEcbuN8UTJOVjWKRBWTh1ytf2aQSXqtybdo/zFjw5Aal8cFGH7mQp0P91MmAmD+Y6M PExQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169948; 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=aDWF4TV4NNOMbib10TqpzKDvUtAnKVMCB7lDRnKm84M=; b=ydEgt14xIqoHFFBFvC1PSIN/CHeBsAuIlgPyiF6eaNwzPWajeazfchlaBFiv7ds0wq /6my6IKoYPlDAX293fwEtAEHSTQjbhAogBZ2PpoNKkLMYRqe61Vv7QFtkd7EGf//j+LH NrNOxtQJkh4qJKnSubP35GDDvpL8GzLUiuKB4+q5PYQwZshOT5LXnO7qsRqogQT1dSKO Jqq+ZwtiBRqeAOweLHcLVZKnUe37P50JwkbLjmP7iKtiGp++UnEkU2EfuC1zFQPwNKAV IwJ6ea2rQqwzhWxE10dWALq7V2BSGp6y3JeAewwsVCJBYsn1GfLFycy882h6xv9nyEw8 Nhvw== X-Gm-Message-State: AO0yUKWzuylk0rfQx7+U2R6vprmopq7ac8GzhP56ez4wVwLkafafcBGm Y+JC22DiOCRxR2qoJAQXQklLXFcxOxMPxHsq4s8= X-Google-Smtp-Source: AK7set8ua1saI1cjj7bkld324nU6Zr13mi8gHF/KDUGkEj/fz7lB+dqvRn8obST8WX1EIaGQhoybzg== X-Received: by 2002:a9d:7f8d:0:b0:693:d8a3:1816 with SMTP id t13-20020a9d7f8d000000b00693d8a31816mr1446185otp.16.1679169947766; Sat, 18 Mar 2023 13:05:47 -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 for-8.1 v3 23/26] target/riscv: rework write_misa() Date: Sat, 18 Mar 2023 17:04:33 -0300 Message-Id: <20230318200436.299464-24-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::336; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x336.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170171099100003 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. 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; - handle RVE. This is done by filtering all bits but RVE from 'val'. Setting RVE will forcefully set only RVE - assuming it gets validated afterwards; - emulate the steps done by realize(): validate the candidate misa_ext val, then validate the configuration with the candidate misa_ext val, and finally commit the changes to cpu->cfg. If any of the validation steps fails, the write operation is a no-op. Let's keep write_misa() as experimental for now until this logic gains enough mileage. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 12 ++++------ target/riscv/cpu.h | 6 +++++ target/riscv/csr.c | 59 ++++++++++++++++++++++++++-------------------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index e9172ec310..67a46504bb 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1027,9 +1027,8 @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISC= VCPU *cpu) } =20 =20 -static void riscv_cpu_validate_misa_ext(CPURISCVState *env, - uint32_t misa_ext, - Error **errp) +void riscv_cpu_validate_misa_ext(CPURISCVState *env, uint32_t misa_ext, + Error **errp) { Error *local_err =3D NULL; =20 @@ -1122,9 +1121,8 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu= , Error **errp) * candidate misa_ext value. No changes in env->misa_ext * are made. */ -static void riscv_cpu_validate_extensions(RISCVCPU *cpu, - uint32_t misa_ext, - Error **errp) +void riscv_cpu_validate_extensions(RISCVCPU *cpu, uint32_t misa_ext, + Error **errp) { if (cpu->cfg.epmp && !cpu->cfg.pmp) { /* @@ -1215,7 +1213,7 @@ static void riscv_cpu_validate_extensions(RISCVCPU *c= pu, } } =20 -static void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu) +void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu) { if (cpu->cfg.ext_zk) { cpu->cfg.ext_zkn =3D true; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index dbb4df9df0..ca2ba6a647 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -593,6 +593,12 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, i= nt size, char *riscv_isa_string(RISCVCPU *cpu); void riscv_cpu_list(void); =20 +void riscv_cpu_validate_misa_ext(CPURISCVState *env, uint32_t misa_ext, + Error **errp); +void riscv_cpu_validate_extensions(RISCVCPU *cpu, uint32_t misa_ext, + Error **errp); +void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu); + #define cpu_list riscv_cpu_list #define cpu_mmu_index riscv_cpu_mmu_index =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index d522efc0b6..8d5e8f9ad1 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1343,39 +1343,17 @@ 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); + 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 @@ -1389,6 +1367,37 @@ static RISCVException write_misa(CPURISCVState *env,= int csrno, return RISCV_EXCP_NONE; } =20 + /* + * We'll handle special cases in separate. If one + * of these bits are enabled we'll handle them and + * end the CSR write. + */ + if (val & RVE && !(env->misa_ext & RVE)) { + /* + * RVE must be enabled by itself. Clear all other + * misa_env bits and let the validation do its + * job. + */ + val &=3D RVE; + } + + /* + * This flow is similar to what riscv_cpu_realize() does, + * with the difference that we will update env->misa_ext + * value if everything is ok. + */ + riscv_cpu_validate_misa_ext(env, val, &local_err); + if (local_err !=3D NULL) { + return RISCV_EXCP_NONE; + } + + riscv_cpu_validate_extensions(cpu, val, &local_err); + if (local_err !=3D NULL) { + return RISCV_EXCP_NONE; + } + + riscv_cpu_commit_cpu_cfg(cpu); + if (!(val & RVF)) { env->mstatus &=3D ~MSTATUS_FS; } --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170078; cv=none; d=zohomail.com; s=zohoarc; b=P7aezZHZBP0ZQwa3RXFYG1vYccC7SVBzzKvKWYt6TVE6BvUExrihWUoFeNy3XRN5yS9/LAu0j4aAm0lYnTN9Qq56QRfCQcLdCOyE5NSM0car6T0o3nSsolPYTsK3sbV/bRS75vFEYpN6qux05kDxzemY+Ne4MDQaDM4V/aPHv2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170078; 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=vt9kE6nXpZRbmPAxL8bMFdNpI5BJmqSAYbOTJpKdffU=; b=Wz06jF5gmbRZb02bbhW537ll2Qpl2tM2Py+VSaqeCgNpXELsbfQ2DacsAPnYKrcif8hM9bEXv7qOgpy0tHzPIv6q6SRNPkdIZUkMZGpwnFqsF/n45VCII2ClbUTMEqJpapcs/OFPpCOE7V3YHWRn32T839KoBRr1OP/9+xwQtx4= 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 1679170078819875.8125741167851; Sat, 18 Mar 2023 13:07:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoO-00064L-V2; Sat, 18 Mar 2023 16:05:56 -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 1pdcoL-0005jF-AP for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:53 -0400 Received: from mail-ot1-x336.google.com ([2607:f8b0:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcoJ-0007F7-M0 for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:53 -0400 Received: by mail-ot1-x336.google.com with SMTP id x22-20020a056830409600b0069b30fb38f7so4726128ott.5 for ; Sat, 18 Mar 2023 13:05:51 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169950; 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=vt9kE6nXpZRbmPAxL8bMFdNpI5BJmqSAYbOTJpKdffU=; b=npOMM7r58ZzjSpp2+OhKLPSd40KIVZpTeD1ltY3qEm8Ewl4PjSYcFTePBB/Ea40/9n nVZkIKU3wEBrKvrgPcS6EyHXZtax0WKIQBoNSysmCU97Ui4WLlirKlXI3/TgsmEvh5DF PlyCaPcB30HxkVWjHxjsmr1Pnig6cgHC2UwAX1lw/PE5wZBICPuKC7wni6taV0NSua/h nvUWQnBiEkDPK03jtQoXCqObcDJkrs8mgQ/WVxHFdyUhyDptaieYARRE253THYPknjwd XcskaZvhFrMgcWLlNoWrQNZs7kjxV23wnB43j2Lqi5J3PhUG8UudHkJ6/JPCH8sKFwp/ UkHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169950; 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=vt9kE6nXpZRbmPAxL8bMFdNpI5BJmqSAYbOTJpKdffU=; b=BtfvWOdTb1GJQQUVDIes8MF7Ln5NMqI+Cjfs/UTwcqLKEQNmlDzcvbYdYIxn8o4ISB bTTcZLuTEU/wHgijHWG+HhLfScZHFtRNEMQXg8lCOeWSZVhWeoJ/rgTVmoRUCcR68wKP a/7fRbB0iGBCBNMyWvtDLchhLzojjDQuPyNv7z9SwwS1iDhfJuPkq/QwJ31rl/gYja41 mEb+uzk8SKX9eB7bMVNBp50MeoC0GoAuifpcKr5I+KNAEXnVYqnswlSTTHPqRdF67Wzp iIBRkxWpWUkRctuKyM/pvXGyDqbHm0W+w5I7GAIYGKaBODhLz2G69MVtIy293SS+8Vtz 9MHQ== X-Gm-Message-State: AO0yUKXdTT7tVSkXoiHh8nSdJ1mh7ldfjPDblgL0E0ZMcUly+l/ZjT6e PFU8LOe16WobEPajka6Cun+PE04GbduNnIzNzrQ= X-Google-Smtp-Source: AK7set9yaBgj4EmAMpIkNqX3pC33Gr9I+izxh90vbrzs3G9XWid+g/Tp3W2kHl1BBOm7arAV8ZK2RA== X-Received: by 2002:a05:6830:5:b0:69b:6c9e:cd2d with SMTP id c5-20020a056830000500b0069b6c9ecd2dmr1295447otp.4.1679169950549; Sat, 18 Mar 2023 13:05:50 -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 for-8.1 v3 24/26] target/riscv: update cpu->cfg misa bits in commit_cpu_cfg() Date: Sat, 18 Mar 2023 17:04:34 -0300 Message-Id: <20230318200436.299464-25-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::336; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x336.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170080690100003 Content-Type: text/plain; charset="utf-8" write_misa() is able to use the same validation workflow riscv_cpu_realize() uses. But it's still not capable of updating cpu->cfg misa props yet. We have no way of blocking future (and current) code from checking env->misa_ext (via riscv_has_ext()) or reading cpu->cfg directly, so our best alternative is to keep everything in sync. riscv_cpu_commit_cpu_cfg() now receives an extra 'misa_ext' parameter. If this val is different from the existing env->misa_ext, update env->misa and cpu->cfg with the new value. riscv_cpu_realize() will ignore this code since env->misa_ext isn't touched during validation, but write_misa() will use it to keep cpu->cfg in sync with the new env->misa_ext value. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 16 ++++++++++++++-- target/riscv/cpu.h | 2 +- target/riscv/csr.c | 3 +-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 67a46504bb..2d2a354af3 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1213,8 +1213,20 @@ void riscv_cpu_validate_extensions(RISCVCPU *cpu, ui= nt32_t misa_ext, } } =20 -void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu) +void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu, uint32_t misa_ext) { + CPURISCVState *env =3D &cpu->env; + + /* + * write_misa() needs to update cpu->cfg with the new + * MISA bits. This is a no-op for the riscv_cpu_realize() + * path. + */ + if (env->misa_ext !=3D misa_ext) { + env->misa_ext =3D misa_ext; + riscv_set_cpucfg_with_misa(&cpu->cfg, misa_ext); + } + if (cpu->cfg.ext_zk) { cpu->cfg.ext_zkn =3D true; cpu->cfg.ext_zkr =3D true; @@ -1383,7 +1395,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) return; } =20 - riscv_cpu_commit_cpu_cfg(cpu); + riscv_cpu_commit_cpu_cfg(cpu, env->misa_ext); =20 #ifndef CONFIG_USER_ONLY if (cpu->cfg.ext_sstc) { diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index ca2ba6a647..befc3b8fff 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -597,7 +597,7 @@ void riscv_cpu_validate_misa_ext(CPURISCVState *env, ui= nt32_t misa_ext, Error **errp); void riscv_cpu_validate_extensions(RISCVCPU *cpu, uint32_t misa_ext, Error **errp); -void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu); +void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu, uint32_t misa_ext); =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 8d5e8f9ad1..839862f1a8 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1396,7 +1396,7 @@ static RISCVException write_misa(CPURISCVState *env, = int csrno, return RISCV_EXCP_NONE; } =20 - riscv_cpu_commit_cpu_cfg(cpu); + riscv_cpu_commit_cpu_cfg(cpu, val); =20 if (!(val & RVF)) { env->mstatus &=3D ~MSTATUS_FS; @@ -1404,7 +1404,6 @@ static RISCVException write_misa(CPURISCVState *env, = int csrno, =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 From nobody Thu Mar 28 14:16:13 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=1679170037; cv=none; d=zohomail.com; s=zohoarc; b=U4ANng94ekEbIuPsEfddaaStcRQWcBbOnMxOV9nNgiopnuxdIFOodAGFigAEEWpXFL/ACmZjGy+qP9h5QzBGi/ihdESUmKhrX+i7+sGRzQPgWxBMFdvxHizNMp15zBAAtIgI9DpkhjZHp3Do8aKi7sLalQSIAKNk1vqTy1UqAI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170037; 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=xmbX519e6VWvRcGzVkBcanGYNJBj4+Ut+TmCNDZrZTw=; b=Nw3jqpgohv0uJ7FinzmkDNx32o0iYokxr6UehkKulhCltNhuF4xDXW+72IpwlTJDcPaPHmotC3rKzI4ExEwffk/TFKYjicZ8/xVanYMb5br+pHIQU/60n28sEfsLVmJImuq2aZmOabI4ejyoG2gPN65oYpvFg71Bpm0ZQIRUOaw= 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 1679170037974847.6879183313818; Sat, 18 Mar 2023 13:07:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoS-0006VE-Q4; Sat, 18 Mar 2023 16:06:00 -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 1pdcoP-000669-6T for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:57 -0400 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcoN-0007GS-5R for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:05:56 -0400 Received: by mail-oi1-x22f.google.com with SMTP id bo10so6202285oib.11 for ; Sat, 18 Mar 2023 13:05:54 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169953; 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=xmbX519e6VWvRcGzVkBcanGYNJBj4+Ut+TmCNDZrZTw=; b=lDalFKOhDjCqnFs9A+siyq67oAHiCye/gjQLy+bpjifBMju0scqGJbpCDLl6U9YI2v wQFUQmNJGtSmSVCGxYZHPPLG7FOnd6MhxhqVUyYD6zQ6gtajo4nWTl0y38VeWUKoW6hI SvklaUBYjETIahN5m0w4epo7tQ59MQTE7C/sH37/V36WHzMcoTCK8A8Of/1bcXLNvRT/ Gi9KeT6QESJuxtbxQlZ4wsDWmUXFbJ4PckAypfyyxrAQ0aXU5mw6hYnXsskGN3VrKYMU ZiTUxHCsm+1+LdmU8O06M93iCv7hl2uzYrAp2jpaUFJNLaqWIyBeCkg+5rGN1JKg4okq hY6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169953; 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=xmbX519e6VWvRcGzVkBcanGYNJBj4+Ut+TmCNDZrZTw=; b=nUozDWyLZCqWvgDqbQca3ff+QuX3ZEMD4xFJKqIbpgm+5ekzGjR48K/S4lYlcHenOa 8F7ZSafFJshYcpbi7kSedXH53X4sqmW9RY0eg9JaeQE2r40bdMhOdrsU3xSM2kwbLle1 0MVZ8a5hqI+f3MrxK9MLfku1yIOGBGh6aZHJiAyDLDlAhm9ofJ15F/+FE7Hd7Lkdhors LrRZtgKAV0QmWauED0tgyNgU1yUzSO4tLEulbXFtErvPhj8d6OSCtrOfM/o1aQ0JbB4s g1rFHmW1S0Rc5+M8qzMyuPEOVP667qLG85ySap+kOaNtB08CygT6thSJb1j8C5Zidit0 Mh7A== X-Gm-Message-State: AO0yUKWMaMIiem8yKtrme9f2CITZH5kDKYp2iPL0w6hQDMmkGpRnLNMN pD3etF0GrFWo1YMbhoPTmo9cKRpj8Jvyw67DEgw= X-Google-Smtp-Source: AK7set/NmPVtu6tEJyH184gKpY/3ubiRKQyqEZhzUDWgMFg2hCCY2t9vY24SOhQq80rdBcDNimb+OA== X-Received: by 2002:aca:2801:0:b0:386:a4c9:40c1 with SMTP id 1-20020aca2801000000b00386a4c940c1mr5908465oix.7.1679169953544; Sat, 18 Mar 2023 13:05:53 -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 for-8.1 v3 25/26] target/riscv: allow write_misa() to enable RVG Date: Sat, 18 Mar 2023 17:04:35 -0300 Message-Id: <20230318200436.299464-26-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::22f; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170038582100001 Content-Type: text/plain; charset="utf-8" Allow write_misa() to enable RVG by changing riscv_cpu_enable_g() slighty: instead of returning void, return the current env->misa_ext value. This is then retrieved by 'val', which will add the RVG flag itself, and then we'll skip validation and go right into commiting the changes. The reason why it's ok to skip validation in this case is because we're only allowing RVG (and its associated extensions/Z extensions) to be enabled in the hart, and riscv_cpu_enable_g() already does its own validation before enabling itself. Everything else is considered to be already validated beforehand, so we don't need to repeat ourselves. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 7 +++++-- target/riscv/cpu.h | 2 ++ target/riscv/csr.c | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 2d2a354af3..73a5fa46ee 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -281,7 +281,8 @@ static uint32_t riscv_get_misa_ext_with_cpucfg(RISCVCPU= Config *cfg) return ext; } =20 -static void riscv_cpu_enable_g(RISCVCPU *cpu, Error **errp) + +target_ulong riscv_cpu_enable_g(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; RISCVCPUConfig *cfg =3D &cpu->cfg; @@ -289,7 +290,7 @@ static void riscv_cpu_enable_g(RISCVCPU *cpu, Error **e= rrp) if (cpu->cfg.ext_zfinx) { error_setg(errp, "Unable to enable G: Zfinx is enabled, " "so F can not be enabled"); - return; + return 0; } =20 if (!(cfg->ext_i && cfg->ext_m && cfg->ext_a && @@ -315,6 +316,8 @@ static void riscv_cpu_enable_g(RISCVCPU *cpu, Error **e= rrp) cfg->ext_icsr =3D true; cfg->ext_ifencei =3D true; } + + return env->misa_ext; } =20 static void riscv_set_cpucfg_with_misa(RISCVCPUConfig *cfg, diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index befc3b8fff..3ca1d4903c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -599,6 +599,8 @@ void riscv_cpu_validate_extensions(RISCVCPU *cpu, uint3= 2_t misa_ext, Error **errp); void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu, uint32_t misa_ext); =20 +target_ulong riscv_cpu_enable_g(RISCVCPU *cpu, Error **errp); + #define cpu_list riscv_cpu_list #define cpu_mmu_index riscv_cpu_mmu_index =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 839862f1a8..4335398c19 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1381,6 +1381,20 @@ static RISCVException write_misa(CPURISCVState *env,= int csrno, val &=3D RVE; } =20 + if (val & RVG && !(env->misa_ext & RVG)) { + /* + * If the write wants to enable RVG, only RVG and + * its dependencies will be updated in the CSR. + */ + val =3D riscv_cpu_enable_g(cpu, &local_err); + if (local_err !=3D NULL) { + return RISCV_EXCP_NONE; + } + + val |=3D RVG; + goto commit; + } + /* * This flow is similar to what riscv_cpu_realize() does, * with the difference that we will update env->misa_ext @@ -1396,6 +1410,7 @@ static RISCVException write_misa(CPURISCVState *env, = int csrno, return RISCV_EXCP_NONE; } =20 +commit: riscv_cpu_commit_cpu_cfg(cpu, val); =20 if (!(val & RVF)) { --=20 2.39.2 From nobody Thu Mar 28 14:16:13 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=1679170059; cv=none; d=zohomail.com; s=zohoarc; b=Jt1HBq8DkFc6YZqVJNVCEr3hEP6Sq+5XhcgaQXBAH9fSbCgD7asVOdeUnxfDkpp/IfzlvPGC/UQMuPskDTVwfDTpdaMoZ1e1hrKtFMTbhhILaTmkxI3R+s770WPQU1RM5TgFjVxFE3/64B2/oJfbfFI2WS4mM8CEUcCIZd7+o98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1679170059; 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=zD0xvzavcMOlqDmOuShYZOckRPbY+zDaBi9jT5/rz+A=; b=ZRdsPfYP4TiipGKYIBRb5oWpzk/8iCAoxIh3rSPHMwOAFQg3wwS0tFJ/wYFrntqcx90Tg6MGHCB/81OdiWbh2mNWCo7IuESsrck/wPYERLVbZcSq3QT7L9x2CZeXUW76dr5Mq0ZP+rK+dsM9tFBO57fJqC0b/ZVGqY6GbJJyqAs= 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 1679170059167674.072216825878; Sat, 18 Mar 2023 13:07:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pdcoU-0006ph-NY; Sat, 18 Mar 2023 16:06:02 -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 1pdcoS-0006Tp-GW for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:06:00 -0400 Received: from mail-ot1-x32f.google.com ([2607:f8b0:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pdcoQ-0007Gw-3d for qemu-devel@nongnu.org; Sat, 18 Mar 2023 16:06:00 -0400 Received: by mail-ot1-x32f.google.com with SMTP id v2-20020a056830090200b0069c6952f4d3so4717725ott.7 for ; Sat, 18 Mar 2023 13:05:57 -0700 (PDT) Received: from grind.dc1.ventanamicro.com ([177.95.89.231]) by smtp.gmail.com with ESMTPSA id f69-20020a4a5848000000b004a3d98b2ccdsm2122219oob.42.2023.03.18.13.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 13:05:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1679169956; 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=zD0xvzavcMOlqDmOuShYZOckRPbY+zDaBi9jT5/rz+A=; b=IeJVIH/q/jq9RoSzYObuC817WaFDlXTEdiHOndp5Te0CbGEo8ND/7OJjNDwhoFo/km NrhNgWC7QUPnoWg3opQsNJbKtOzthDZ/Qz5bUnpDovBO9VWRuZSeL5q8hkzjJFsIZmlW /jj3ylnyvxREqs7ZS3K9/9IDVfpKb17b9W2gb0WaFlS43xbrhDwqKeG2fkk1qTjuPS3U fOl7n0t76d5Im716ecFbqtaXOG0i9FiFMLF8d00nOH9fPsuYtFDA1sooIzrZQQpSZPmO M8S9+KNb0oqRr+uQnt0rjDEywNEtukeY2OQRh7vIrBvJ3LCdTUj2CuUM8vyKebspIq2l axig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679169956; 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=zD0xvzavcMOlqDmOuShYZOckRPbY+zDaBi9jT5/rz+A=; b=HEWKaIdumiCBA6Uj/PBD2UHJpP7/xNmnc/fKM6JJ/H9tjWbe0hKx1G9stYfltYxNtY 9Qp32VyqLv/9NaDJ9IKUpiGM44IUz4rdhiw1WA39yMn6kX7pDPg6a9Afgx6RbdEKRM+Z FgAw6sXPwOAcmqptjU9nHAqTmO0JHpz4ZQFAVqC4H0yR83lGAp3hqFWiv/hoK6Pj3ppE Bl+CweCzHuEMojOV/EjK1TKCgLp6Rj+0UgkWS2psxvC0UGposI2+qwD8DRRdgG9XkgT4 d57MmIFAAJcOJVDb/2TQRuyBSzq1/mcqOCl4Is9mdxDMNKHhtjYk4CliGCmqEBIVEua9 0mSA== X-Gm-Message-State: AO0yUKU+j1JhSFUB4M6IG/AFsmE9IUw4DKpIuHaQhH6782f2/iXxjPK+ 60Zx0BET8zLquH3p7zQPFX5lz/qm/3jH1v5LX+U= X-Google-Smtp-Source: AK7set9DILmrHXBNblRkySraNmNTt5EkG6fc926qHkwEgteNDgMCcpTxCB3o5eYH14AwvpEd8vzU2Q== X-Received: by 2002:a9d:75c5:0:b0:693:db45:8b71 with SMTP id c5-20020a9d75c5000000b00693db458b71mr1500717otl.8.1679169956435; Sat, 18 Mar 2023 13:05:56 -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 for-8.1 v3 26/26] target/riscv: allow write_misa() to enable RVV Date: Sat, 18 Mar 2023 17:04:36 -0300 Message-Id: <20230318200436.299464-27-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230318200436.299464-1-dbarboza@ventanamicro.com> References: <20230318200436.299464-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::32f; envelope-from=dbarboza@ventanamicro.com; helo=mail-ot1-x32f.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1679170060684100001 Content-Type: text/plain; charset="utf-8" Allow write_misa() to enable RVV like we did with RVG. We'll need a riscv_cpu_enable_v() to enable all related misa bits and Z extensions. This new helper validates the existing 'env' conf by using the existing riscv_cpu_validate_v(). We'll also check if we'll be able to enable 'F' by checking for ext_zfinx. As with RVG, enabling RVV is considered to be a standalone operation in write_misa(). This means that we'll guarantee that we're not being inconsistent in riscv_cpu_enable_v() and that we're okay with skipping regular validation. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 35 +++++++++++++++++++++++++++++++++++ target/riscv/cpu.h | 1 + target/riscv/csr.c | 14 ++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 73a5fa46ee..9c16b29f27 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -983,6 +983,41 @@ static void riscv_cpu_validate_v(CPURISCVState *env, env->vext_ver =3D vext_version; } =20 +target_ulong riscv_cpu_enable_v(RISCVCPU *cpu, Error **errp) +{ + CPURISCVState *env =3D &cpu->env; + RISCVCPUConfig *cfg =3D &cpu->cfg; + Error *local_err =3D NULL; + + riscv_cpu_validate_v(env, cfg, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return 0; + } + + if (cpu->cfg.ext_zfinx) { + error_setg(errp, "Unable to enable V: Zfinx is enabled, " + "so F can not be enabled"); + return 0; + } + + cfg->ext_f =3D true; + env->misa_ext |=3D RVF; + + cfg->ext_d =3D true; + env->misa_ext |=3D RVD; + + /* + * The V vector extension depends on the + * Zve32f, Zve64f and Zve64d extensions. + */ + cpu->cfg.ext_zve64d =3D true; + cpu->cfg.ext_zve64f =3D true; + cpu->cfg.ext_zve32f =3D true; + + return env->misa_ext; +} + static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) { CPURISCVState *env =3D &cpu->env; diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 3ca1d4903c..45e801d926 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -600,6 +600,7 @@ void riscv_cpu_validate_extensions(RISCVCPU *cpu, uint3= 2_t misa_ext, void riscv_cpu_commit_cpu_cfg(RISCVCPU *cpu, uint32_t misa_ext); =20 target_ulong riscv_cpu_enable_g(RISCVCPU *cpu, Error **errp); +target_ulong riscv_cpu_enable_v(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 4335398c19..e9e1afc57e 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1395,6 +1395,20 @@ static RISCVException write_misa(CPURISCVState *env,= int csrno, goto commit; } =20 + if (val & RVV && !(env->misa_ext & RVV)) { + /* + * If the write wants to enable RVV, only RVV and + * its dependencies will be updated in the CSR. + */ + val =3D riscv_cpu_enable_v(cpu, &local_err); + if (local_err !=3D NULL) { + return RISCV_EXCP_NONE; + } + + val |=3D RVV; + goto commit; + } + /* * This flow is similar to what riscv_cpu_realize() does, * with the difference that we will update env->misa_ext --=20 2.39.2