From nobody Sat Apr 20 00:45:05 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1674636165; cv=none; d=zohomail.com; s=zohoarc; b=TlVLvtReSN1hxIt7K/Tf58MUyQs/J9doF2E5kSiOb1leBxNThXg0oQc3Q0uoSp6nzih6Sc/Iws7LZZztEZ7VaLSwAQtGCyXS3g99P7u3fD/HYehZg4JScQrgWsWKgiY5Yr4vx/GnDbAjbJpbLqStZ5d0xTz/nPLIR9eHfl9Qzh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674636165; 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=cwmWUou3n7EK2dJeuj7/aaDxziEUHfXgfhDPpUIodg0=; b=F52DMBRBOszV++teH59I7976CUjcEcJf1UhbVG9XBNS1XyVMyUM3Gzch1501RYViJfYS6eXFP5U1KQlwvS0fto1CMm2NRrsX0eYcYm7xG9HNBU3xMIFzKy5W34NaCXM5QQ95LHieL8JayfInR+IZRlgETwLib4tqfnODOaX2mUo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674636165088790.4868681279801; Wed, 25 Jan 2023 00:42:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKbMI-0007pH-24; Wed, 25 Jan 2023 03:42:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKbMG-0007ok-V7 for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:42:16 -0500 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKbME-0007QO-Po for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:42:16 -0500 Received: by mail-wr1-x435.google.com with SMTP id r2so16239448wrv.7 for ; Wed, 25 Jan 2023 00:42:14 -0800 (PST) Received: from alex-rivos.home (lfbn-lyo-1-450-160.w2-7.abo.wanadoo.fr. [2.7.42.160]) by smtp.gmail.com with ESMTPSA id w14-20020a5d608e000000b002bc84c55758sm4609145wrt.63.2023.01.25.00.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 00:42:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=cwmWUou3n7EK2dJeuj7/aaDxziEUHfXgfhDPpUIodg0=; b=WpL9rvglxaPJswbSjl+3hVNq/kFYhxjifUM9Ob7HJnPn44ZYY8X53kpuVkvdyBz9Rr hLwUupIAy7G/JYeO/Hbk1XcZXonFtqRWNmQENa1CzUguuVnvjeiXkCqN7YLqE/xd1UjT GCNjbuvpYkZPiUFfZQG6yfb65mY9ZYzzG2bQV/OLHaMBC2lfmSva7hg/hLktnR3/j2fe AK2Ky2IFPyBZz9jAbEKSmdOvu9JyB5PiqpJe7wrStb2qXOIGZJwEZafKqDU2X4tLqIiU BIZVsTYzDupDfl/BK1I1LR4Ee3J2Phrvfch69vKmDgrxR4hXomowtt57vFtyhgK/HJG3 SiqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=cwmWUou3n7EK2dJeuj7/aaDxziEUHfXgfhDPpUIodg0=; b=qgJWAr0aW2mXOMidS5cJMLAFjQ8zVXqmEN6FLhKPag7FEacuuYTiaJTticqdwKOJsX jVxkm6pGeNvpymnLXA6br0Mg7fcHZrKg+5RYFhYfkxbY2Dy9nItY7MDu+Nt07UhzHqe1 FyW/5P6+Gw51g58zRn6hrad1F5mwNasvQQAL5MlTtBjb+W0O7XGVPUUhODtvJbWfECrI 10knDrLutEqJgN5B3xU810R0l9j4rCP6zJFgD9oJ7kWK86LN0WCh2x8mYe9V4FXG/zYI hHu+naEk9aYR75AfxPY+AyWPdqu7pLRk1mh7kXzuf2CtSNVL9ACirtNJ5mTqS4jlh9kV EhNg== X-Gm-Message-State: AO0yUKVD7Lwu0Zccqvp4D49wSX1veMoWVcmRm984CidQZcYLvgrTN2Jb dDlmzNtd1vsexKS48BbfFRa9iQ== X-Google-Smtp-Source: AK7set/F+bJPoWvq+YGQie12Nf1t3royEghLt6hYxMUUxx43b8XbzIBllSNNcA2OeN/X+GqwuX6nzQ== X-Received: by 2002:a05:6000:257:b0:2bf:bb48:ddaf with SMTP id m23-20020a056000025700b002bfbb48ddafmr834899wrz.7.1674636133233; Wed, 25 Jan 2023 00:42:13 -0800 (PST) From: Alexandre Ghiti To: Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Frank Chang , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Alexandre Ghiti Subject: [PATCH v7 1/5] riscv: Pass Object to register_cpu_props instead of DeviceState Date: Wed, 25 Jan 2023 09:41:03 +0100 Message-Id: <20230125084107.1580972-2-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125084107.1580972-1-alexghiti@rivosinc.com> References: <20230125084107.1580972-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=alexghiti@rivosinc.com; helo=mail-wr1-x435.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674636166661100002 Content-Type: text/plain; charset="utf-8" One can extract the DeviceState pointer from the Object pointer, so pass the Object for future commits to access other fields of Object. No functional changes intended. Signed-off-by: Alexandre Ghiti Reviewed-by: Alistair Francis Reviewed-by: Frank Chang Reviewed-by: Andrew Jones --- target/riscv/cpu.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index cc75ca7667..7181b34f86 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -200,7 +200,7 @@ static const char * const riscv_intr_names[] =3D { "reserved" }; =20 -static void register_cpu_props(DeviceState *dev); +static void register_cpu_props(Object *obj); =20 const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) { @@ -238,7 +238,7 @@ static void riscv_any_cpu_init(Object *obj) set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU); #endif set_priv_version(env, PRIV_VERSION_1_12_0); - register_cpu_props(DEVICE(obj)); + register_cpu_props(obj); } =20 #if defined(TARGET_RISCV64) @@ -247,7 +247,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(DEVICE(obj)); + register_cpu_props(obj); /* Set latest version of privileged specification */ set_priv_version(env, PRIV_VERSION_1_12_0); } @@ -280,7 +280,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(DEVICE(obj)); + register_cpu_props(obj); /* Set latest version of privileged specification */ set_priv_version(env, PRIV_VERSION_1_12_0); } @@ -290,7 +290,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(DEVICE(obj)); + register_cpu_props(obj); /* Set latest version of privileged specification */ set_priv_version(env, PRIV_VERSION_1_12_0); } @@ -343,7 +343,7 @@ static void riscv_host_cpu_init(Object *obj) #elif defined(TARGET_RISCV64) set_misa(env, MXL_RV64, 0); #endif - register_cpu_props(DEVICE(obj)); + register_cpu_props(obj); } #endif =20 @@ -1083,9 +1083,10 @@ static Property riscv_cpu_extensions[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 -static void register_cpu_props(DeviceState *dev) +static void register_cpu_props(Object *obj) { Property *prop; + DeviceState *dev =3D DEVICE(obj); =20 for (prop =3D riscv_cpu_extensions; prop && prop->name; prop++) { qdev_property_add_static(dev, prop); --=20 2.37.2 From nobody Sat Apr 20 00:45:05 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1674636220; cv=none; d=zohomail.com; s=zohoarc; b=erVOQ7aeq7ldIz39If/F7gqF5qxC+XAs2gfQjbeiSZIBxpHeybMZvjymbdn/+2QD3OHoS6WBvx+XJdPSy6VqoqH3uXm2EBhUuRGh4JJHnJq7YeXc9Oii3E9IHADonEVePWwwEkhjsxFNOY3Nvzhs/2hAD+cH9KANfGiC9pQGaAQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674636220; 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=+TrQUDShuSlYfHT4YnhyHx3S9WBzIjkLW6v+vF/2lyw=; b=OG/b4xXNO2FgqQeGzllpFBiN4tejDQVlvxNq6obKFs4Ijcr5TUq9oazAXzzBqVU3mtBpYd0Ogk1nP+R2KlgVi1XOAYZRaPVtYR+Xb+M4yPE9nW4LSFsbo1SEAN0F82Z6OCEBXLDRowukABUcqEsNjDMk9VVQ3EuLb7iyIp02DAQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674636220896922.7902447530038; Wed, 25 Jan 2023 00:43:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKbNK-0000h0-HQ; Wed, 25 Jan 2023 03:43:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKbNF-0000eH-9E for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:43:17 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKbND-0007bo-Dv for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:43:16 -0500 Received: by mail-wr1-x431.google.com with SMTP id r2so16241788wrv.7 for ; Wed, 25 Jan 2023 00:43:15 -0800 (PST) Received: from alex-rivos.home (lfbn-lyo-1-450-160.w2-7.abo.wanadoo.fr. [2.7.42.160]) by smtp.gmail.com with ESMTPSA id x6-20020a5d4906000000b002bc6c180738sm4363839wrq.90.2023.01.25.00.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 00:43:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=+TrQUDShuSlYfHT4YnhyHx3S9WBzIjkLW6v+vF/2lyw=; b=8R8nHv1V9HmeyRvkLYOz7Z1J45Ddw22pteExu33h0koeI9zCq3p8DqaqXl2yapLjmg 7pRUe0+YqAWByDSBGW0x9Nk72aKZwFvkoDQVNR8xidwYTifRFvwxpCqR4PLoZeSGPijg Z4NTSfl5urKLdMp/uVtGcruqM7jLVU/svfqezBd2vkiNeNg52l/LlbaEv17gJlJwNRVd tP6nZOQQWQqxS/bXx/g1XP9CQNC42DBS/pnXtpJP8QTFzoi+vscpQmLIoMAGzGHQiNhK U1P9Qd+bmtmQWxyvbxrb5Kn6SBA9YYxv5BanCPXNsxD+BD7ALSEG+PQbT/X5uxGH2Fca JbVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=+TrQUDShuSlYfHT4YnhyHx3S9WBzIjkLW6v+vF/2lyw=; b=7QI9Y6fdQUGE7iRLNQ/lTX6Zj7TGEeJ/5lFt31c9GNdRTiakkXJHU2ojRfedkY0iNZ b4AnyIHqh4uDDxwlPx3tj9c8Hljkps5QWmRx1QY4yKLyC7OvX6VoY5CQ64vjs8I0fYB6 /LUUxGIR7Iyt7odl9IlSVH1NLfjc/eVHpDEn1U9d0h+POmz8Gpq/CJwlWXliczrxoMDP /eDNOPnrvWuH6fb2ubL5zWSSTI+G6L5d4uipmwygHiD/H1IgoZzN0fxWIZKQBegbEZ0b WHIgWXypKGxtbuYM3dBEqo0Ey4I5cMpr3KJzMdR9Zs2RK5oce26755zyWbVlCjQuogFQ 1veQ== X-Gm-Message-State: AFqh2kqLB70k83S5NLbXpUUn8ntgplI1Rwr4ASICIIKlw31jm5MrB+/j zrQAtNTnAhgsk+fCei0aS/xpGgd8HTDRCjgm X-Google-Smtp-Source: AMrXdXud3UfGnFAFnf/YYiPjD1LXALQ4hLzEvqlmsCQaKviyKF25Mqoy8ZEt7oOHGIfvB5h1fQyNzQ== X-Received: by 2002:a05:6000:1f81:b0:2bd:f444:9677 with SMTP id bw1-20020a0560001f8100b002bdf4449677mr28128780wrb.66.1674636194042; Wed, 25 Jan 2023 00:43:14 -0800 (PST) From: Alexandre Ghiti To: Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Frank Chang , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Alexandre Ghiti Subject: [PATCH v7 2/5] riscv: Change type of valid_vm_1_10_[32|64] to bool Date: Wed, 25 Jan 2023 09:41:04 +0100 Message-Id: <20230125084107.1580972-3-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125084107.1580972-1-alexghiti@rivosinc.com> References: <20230125084107.1580972-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=alexghiti@rivosinc.com; helo=mail-wr1-x431.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674636223137100003 Content-Type: text/plain; charset="utf-8" This array is actually used as a boolean so swap its current char type to a boolean and at the same time, change the type of validate_vm to bool since it returns valid_vm_1_10_[32|64]. Suggested-by: Andrew Jones Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Reviewed-by: Alistair Francis --- target/riscv/csr.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 0db2c233e5..6b157806a5 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1117,16 +1117,16 @@ static const target_ulong hip_writable_mask =3D MIP= _VSSIP; static const target_ulong hvip_writable_mask =3D MIP_VSSIP | MIP_VSTIP | M= IP_VSEIP; static const target_ulong vsip_writable_mask =3D MIP_VSSIP; =20 -static const char valid_vm_1_10_32[16] =3D { - [VM_1_10_MBARE] =3D 1, - [VM_1_10_SV32] =3D 1 +static const bool valid_vm_1_10_32[16] =3D { + [VM_1_10_MBARE] =3D true, + [VM_1_10_SV32] =3D true }; =20 -static const char valid_vm_1_10_64[16] =3D { - [VM_1_10_MBARE] =3D 1, - [VM_1_10_SV39] =3D 1, - [VM_1_10_SV48] =3D 1, - [VM_1_10_SV57] =3D 1 +static const bool valid_vm_1_10_64[16] =3D { + [VM_1_10_MBARE] =3D true, + [VM_1_10_SV39] =3D true, + [VM_1_10_SV48] =3D true, + [VM_1_10_SV57] =3D true }; =20 /* Machine Information Registers */ @@ -1209,7 +1209,7 @@ static RISCVException read_mstatus(CPURISCVState *env= , int csrno, return RISCV_EXCP_NONE; } =20 -static int validate_vm(CPURISCVState *env, target_ulong vm) +static bool validate_vm(CPURISCVState *env, target_ulong vm) { if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { return valid_vm_1_10_32[vm & 0xf]; @@ -2648,7 +2648,8 @@ static RISCVException read_satp(CPURISCVState *env, i= nt csrno, static RISCVException write_satp(CPURISCVState *env, int csrno, target_ulong val) { - target_ulong vm, mask; + target_ulong mask; + bool vm; =20 if (!riscv_feature(env, RISCV_FEATURE_MMU)) { return RISCV_EXCP_NONE; --=20 2.37.2 From nobody Sat Apr 20 00:45:05 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1674636272; cv=none; d=zohomail.com; s=zohoarc; b=mjb+pjy0zRbuQv3s2fiNjN+HY1j8w6dU+bXyDP++axZ4H7byurDzXn74VU/gjdZuZf/fbqSF6PMbaoqMBrnZpsBES6ST3P59GR+WV/bMyMg6rfuj5vS0ULHdgyhcy+y3dVoQdiy9PIrS3PKnslCIZPGcvnhBG8OiU4hMpYsaMVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674636272; 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=6QAs4M/qcXVtPbdoNDbH0G/oO1ltrtInKZG8GbtYJvI=; b=apJs5NTS5sXJbAreVpLRjx2Vb1AS//kr2Gyc/sL0WHtSccVsB7WUIxdLHo3jW/vMCVEiJum4BtPDe/hcE6guBXLrUgRbLK2Jd6d8CKwXFu6rNHpgkSokS3vu9mFspgoGrVI1nLhbqPc9vRCG6oNE0c8Tnn02/PkZ8X/8ASCSJbg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674636272706762.1729448442619; Wed, 25 Jan 2023 00:44:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKbOK-0001R2-G1; Wed, 25 Jan 2023 03:44:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKbOG-0001ON-F1 for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:44:20 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKbOD-0007iP-O2 for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:44:19 -0500 Received: by mail-wr1-x430.google.com with SMTP id h16so16243935wrz.12 for ; Wed, 25 Jan 2023 00:44:16 -0800 (PST) Received: from alex-rivos.home (lfbn-lyo-1-450-160.w2-7.abo.wanadoo.fr. [2.7.42.160]) by smtp.gmail.com with ESMTPSA id e14-20020adfa44e000000b002be15ee1377sm3906440wra.22.2023.01.25.00.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 00:44:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=6QAs4M/qcXVtPbdoNDbH0G/oO1ltrtInKZG8GbtYJvI=; b=HVPnIBEQQ/nTjrj3D5+nVXv6Cbv2/N1RRrTRakrU3v4g9WOvH26LwEDvI5HsAUnp7Z yp/UVOUnaUlNl5t1AURgx+zPjISmlmw21ZxAImza/x9+HUM45cxDDLUdg5vEwt82fg4U jyiHKnHmRxg+kjEblwDusUzWqa7INRSz/nqsHDNADMSDXMu92b1k5pJ1LEnXGceABKPM fgaOCOGzMvva3EeISwQlQmniQ8XzU9/RuKelP+Pz3XnHCOorcxXE6PDtLaO8wWgXL3Ko X92GET6t1Tpp95JqL2bN/5OHTJ+1TGZ7DTpLl2pIGZjpfyXYlmpsZy8tEkJSG2AZxAfE L6Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=6QAs4M/qcXVtPbdoNDbH0G/oO1ltrtInKZG8GbtYJvI=; b=y4Pt+zWDLwEsLuaL1Z1yn5BbyNMBML2AsXHsWuGeIB2ZY4+/B8d9pYq/EeVGJivnja K9goTF56ZZn1Hk+8qnef7szb9Cztl1h7nUuWX0/XkYr4GEdgBb2xd8Cpe/xmleJWaCJg 2G96TMwSNOjkgTTAgtZa6/rMLeQos9P2zM4ESPFcVSqwzMgVzVCOJt54PEDIC21EHIE6 nxGOB3FoB3gBOL68DB39t0+nwRoguskQl/pTgZ9utrMu2GSKUZXuN7Fx7TO39uYxiq7x 2hzVl7iv4qQZ1hQVCLJsNh0UZK+vS231YbxfFA+m0cVPvQJFnmGAy3Y5PAv5IuBaUk+8 /35g== X-Gm-Message-State: AFqh2kptwcY/D2cjOuEOox4MQW8PMYUT/Tab2oOBRPgiktlWgKKAdN4c hPlP6/kwN8gdIm6dNfeyBelUdw== X-Google-Smtp-Source: AMrXdXuVJSs2flQ7w8pGYIC54Iv+KmKAVeAmWoZOMqFIeli8fCDaGxWjudBV5zsKnvVhkLeciIHdYg== X-Received: by 2002:a05:6000:a06:b0:2bc:858a:3df0 with SMTP id co6-20020a0560000a0600b002bc858a3df0mr32641392wrb.48.1674636254954; Wed, 25 Jan 2023 00:44:14 -0800 (PST) From: Alexandre Ghiti To: Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Frank Chang , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Alexandre Ghiti , Ludovic Henry Subject: [PATCH v7 3/5] riscv: Allow user to set the satp mode Date: Wed, 25 Jan 2023 09:41:05 +0100 Message-Id: <20230125084107.1580972-4-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125084107.1580972-1-alexghiti@rivosinc.com> References: <20230125084107.1580972-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::430; envelope-from=alexghiti@rivosinc.com; helo=mail-wr1-x430.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674636273240100003 Content-Type: text/plain; charset="utf-8" RISC-V specifies multiple sizes for addressable memory and Linux probes for the machine's support at startup via the satp CSR register (done in csr.c:validate_vm). As per the specification, sv64 must support sv57, which in turn must support sv48...etc. So we can restrict machine support by simply setting the "highest" supported mode and the bare mode is always supported. You can set the satp mode using the new properties "sv32", "sv39", "sv48", "sv57" and "sv64" as follows: -cpu rv64,sv57=3Don # Linux will boot using sv57 scheme -cpu rv64,sv39=3Don # Linux will boot using sv39 scheme -cpu rv64,sv57=3Doff # Linux will boot using sv48 scheme -cpu rv64 # Linux will boot using sv57 scheme by default We take the highest level set by the user: -cpu rv64,sv48=3Don,sv57=3Don # Linux will boot using sv57 scheme We make sure that invalid configurations are rejected: -cpu rv64,sv39=3Doff,sv48=3Don # sv39 must be supported if higher modes are # enabled We accept "redundant" configurations: -cpu rv64,sv48=3Don,sv57=3Doff # Linux will boot using sv48 scheme And contradictory configurations: -cpu rv64,sv48=3Don,sv48=3Doff # Linux will boot using sv39 scheme Co-Developed-by: Ludovic Henry Signed-off-by: Ludovic Henry Signed-off-by: Alexandre Ghiti --- target/riscv/cpu.c | 207 +++++++++++++++++++++++++++++++++++++++++++++ target/riscv/cpu.h | 19 +++++ target/riscv/csr.c | 12 ++- 3 files changed, 231 insertions(+), 7 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 7181b34f86..87153a0219 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -27,6 +27,7 @@ #include "time_helper.h" #include "exec/exec-all.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "qemu/error-report.h" #include "hw/qdev-properties.h" #include "migration/vmstate.h" @@ -229,6 +230,81 @@ static void set_vext_version(CPURISCVState *env, int v= ext_ver) env->vext_ver =3D vext_ver; } =20 +static uint8_t satp_mode_from_str(const char *satp_mode_str) +{ + if (!strncmp(satp_mode_str, "mbare", 5)) { + return VM_1_10_MBARE; + } + + if (!strncmp(satp_mode_str, "sv32", 4)) { + return VM_1_10_SV32; + } + + if (!strncmp(satp_mode_str, "sv39", 4)) { + return VM_1_10_SV39; + } + + if (!strncmp(satp_mode_str, "sv48", 4)) { + return VM_1_10_SV48; + } + + if (!strncmp(satp_mode_str, "sv57", 4)) { + return VM_1_10_SV57; + } + + if (!strncmp(satp_mode_str, "sv64", 4)) { + return VM_1_10_SV64; + } + + g_assert_not_reached(); +} + +uint8_t satp_mode_max_from_map(uint32_t map) +{ + /* map here has at least one bit set, so no problem with clz */ + return 31 - __builtin_clz(map); +} + +const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit) +{ + if (is_32_bit) { + switch (satp_mode) { + case VM_1_10_SV32: + return "sv32"; + case VM_1_10_MBARE: + return "none"; + } + } else { + switch (satp_mode) { + case VM_1_10_SV64: + return "sv64"; + case VM_1_10_SV57: + return "sv57"; + case VM_1_10_SV48: + return "sv48"; + case VM_1_10_SV39: + return "sv39"; + case VM_1_10_MBARE: + return "none"; + } + } + + g_assert_not_reached(); +} + +/* Sets the satp mode to the max supported */ +static void set_satp_mode_default(RISCVCPU *cpu) +{ + bool rv32 =3D riscv_cpu_mxl(&cpu->env) =3D=3D MXL_RV32; + + if (riscv_feature(&cpu->env, RISCV_FEATURE_MMU)) { + cpu->cfg.satp_mode.map |=3D + (1 << satp_mode_from_str(rv32 ? "sv32" : "sv57")); + } else { + cpu->cfg.satp_mode.map |=3D (1 << satp_mode_from_str("mbare")); + } +} + static void riscv_any_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; @@ -619,6 +695,83 @@ static void riscv_cpu_disas_set_info(CPUState *s, disa= ssemble_info *info) } } =20 +static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) +{ + bool rv32 =3D riscv_cpu_mxl(&cpu->env) =3D=3D MXL_RV32; + const bool *valid_vm =3D rv32 ? valid_vm_1_10_32 : valid_vm_1_10_64; + uint8_t satp_mode_max; + + if (cpu->cfg.satp_mode.map =3D=3D 0) { + if (cpu->cfg.satp_mode.init =3D=3D 0) { + /* If unset by the user, we fallback to the default satp mode.= */ + set_satp_mode_default(cpu); + } else { + /* + * Find the lowest level that was disabled and then enable the + * first valid level below which can be found in + * valid_vm_1_10_32/64. + */ + for (int i =3D 1; i < 16; ++i) { + if (!(cpu->cfg.satp_mode.map & (1 << i)) && + (cpu->cfg.satp_mode.init & (1 << i)) && + valid_vm[i]) { + for (int j =3D i - 1; j >=3D 0; --j) { + if (valid_vm[j]) { + cpu->cfg.satp_mode.map |=3D (1 << j); + break; + } + } + break; + } + } + } + } + + /* Make sure the configuration asked is supported by qemu */ + for (int i =3D 0; i < 16; ++i) { + if ((cpu->cfg.satp_mode.map & (1 << i)) && !valid_vm[i]) { + error_setg(errp, "satp_mode %s is not valid", + satp_mode_str(i, rv32)); + return; + } + } + + /* + * Make sure the user did not ask for an invalid configuration as per + * the specification. + */ + satp_mode_max =3D satp_mode_max_from_map(cpu->cfg.satp_mode.map); + + if (!rv32) { + for (int i =3D satp_mode_max - 1; i >=3D 0; --i) { + if (!(cpu->cfg.satp_mode.map & (1 << i)) && + (cpu->cfg.satp_mode.init & (1 << i)) && + valid_vm[i]) { + error_setg(errp, "cannot disable %s satp mode if %s " + "is enabled", satp_mode_str(i, false), + satp_mode_str(satp_mode_max, false)); + return; + } + } + } + + /* Finally expand the map so that all valid modes are set */ + for (int i =3D satp_mode_max - 1; i >=3D 0; --i) { + cpu->cfg.satp_mode.map |=3D (1 << i); + } +} + +static void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) +{ + Error *local_err =3D NULL; + + riscv_cpu_satp_mode_finalize(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } +} + static void riscv_cpu_realize(DeviceState *dev, Error **errp) { CPUState *cs =3D CPU(dev); @@ -919,6 +1072,12 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) } #endif =20 + riscv_cpu_finalize_features(cpu, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + riscv_cpu_register_gdb_regs_for_features(cs); =20 qemu_init_vcpu(cs); @@ -927,6 +1086,52 @@ static void riscv_cpu_realize(DeviceState *dev, Error= **errp) mcc->parent_realize(dev, errp); } =20 +static void cpu_riscv_get_satp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + RISCVSATPMap *satp_map =3D opaque; + uint8_t satp =3D satp_mode_from_str(name); + bool value; + + value =3D (satp_map->map & (1 << satp)); + + visit_type_bool(v, name, &value, errp); +} + +static void cpu_riscv_set_satp(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + RISCVSATPMap *satp_map =3D opaque; + uint8_t satp =3D satp_mode_from_str(name); + bool value; + + if (!visit_type_bool(v, name, &value, errp)) { + return; + } + + satp_map->map =3D deposit32(satp_map->map, satp, 1, value); + satp_map->init |=3D 1 << satp; +} + +static void riscv_add_satp_mode_properties(Object *obj) +{ + RISCVCPU *cpu =3D RISCV_CPU(obj); + + if (cpu->env.misa_mxl =3D=3D MXL_RV32) { + object_property_add(obj, "sv32", "bool", cpu_riscv_get_satp, + cpu_riscv_set_satp, NULL, &cpu->cfg.satp_mode); + } else { + object_property_add(obj, "sv39", "bool", cpu_riscv_get_satp, + cpu_riscv_set_satp, NULL, &cpu->cfg.satp_mode); + object_property_add(obj, "sv48", "bool", cpu_riscv_get_satp, + cpu_riscv_set_satp, NULL, &cpu->cfg.satp_mode); + object_property_add(obj, "sv57", "bool", cpu_riscv_get_satp, + cpu_riscv_set_satp, NULL, &cpu->cfg.satp_mode); + object_property_add(obj, "sv64", "bool", cpu_riscv_get_satp, + cpu_riscv_set_satp, NULL, &cpu->cfg.satp_mode); + } +} + #ifndef CONFIG_USER_ONLY static void riscv_cpu_set_irq(void *opaque, int irq, int level) { @@ -1091,6 +1296,8 @@ static void register_cpu_props(Object *obj) for (prop =3D riscv_cpu_extensions; prop && prop->name; prop++) { qdev_property_add_static(dev, prop); } + + riscv_add_satp_mode_properties(obj); } =20 static Property riscv_cpu_properties[] =3D { diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f5609b62a2..e37177db5c 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -27,6 +27,7 @@ #include "qom/object.h" #include "qemu/int128.h" #include "cpu_bits.h" +#include "qapi/qapi-types-common.h" =20 #define TCG_GUEST_DEFAULT_MO 0 =20 @@ -413,6 +414,17 @@ struct RISCVCPUClass { ResettablePhases parent_phases; }; =20 +/* + * map is a 16-bit bitmap: the most significant set bit in map is the maxi= mum + * satp mode that is supported. + * + * init is a 16-bit bitmap used to make sure the user selected a correct + * configuration as per the specification. + */ +typedef struct { + uint16_t map, init; +} RISCVSATPMap; + struct RISCVCPUConfig { bool ext_i; bool ext_e; @@ -488,6 +500,8 @@ struct RISCVCPUConfig { bool debug; =20 bool short_isa_string; + + RISCVSATPMap satp_mode; }; =20 typedef struct RISCVCPUConfig RISCVCPUConfig; @@ -794,9 +808,14 @@ enum riscv_pmu_event_idx { /* CSR function table */ extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; =20 +extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[]; + void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops); void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); =20 void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); =20 +uint8_t satp_mode_max_from_map(uint32_t map); +const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); + #endif /* RISCV_CPU_H */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 6b157806a5..3c02055825 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1117,12 +1117,12 @@ static const target_ulong hip_writable_mask =3D MIP= _VSSIP; static const target_ulong hvip_writable_mask =3D MIP_VSSIP | MIP_VSTIP | M= IP_VSEIP; static const target_ulong vsip_writable_mask =3D MIP_VSSIP; =20 -static const bool valid_vm_1_10_32[16] =3D { +const bool valid_vm_1_10_32[16] =3D { [VM_1_10_MBARE] =3D true, [VM_1_10_SV32] =3D true }; =20 -static const bool valid_vm_1_10_64[16] =3D { +const bool valid_vm_1_10_64[16] =3D { [VM_1_10_MBARE] =3D true, [VM_1_10_SV39] =3D true, [VM_1_10_SV48] =3D true, @@ -1211,11 +1211,9 @@ static RISCVException read_mstatus(CPURISCVState *en= v, int csrno, =20 static bool validate_vm(CPURISCVState *env, target_ulong vm) { - if (riscv_cpu_mxl(env) =3D=3D MXL_RV32) { - return valid_vm_1_10_32[vm & 0xf]; - } else { - return valid_vm_1_10_64[vm & 0xf]; - } + RISCVCPU *cpu =3D RISCV_CPU(env_cpu(env)); + + return ((vm & 0xf) <=3D satp_mode_max_from_map(cpu->cfg.satp_mode.map)= ); } =20 static RISCVException write_mstatus(CPURISCVState *env, int csrno, --=20 2.37.2 From nobody Sat Apr 20 00:45:05 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1674636330; cv=none; d=zohomail.com; s=zohoarc; b=ImpPPafIrKYLDsEO/euB8hNL1vu4HCgn/H89aWwhDtH5TV+CBdw+4FTCwKsP4NArzPTtRXYD7NPUr/oSM77JVAwUDAdhT/Fu/vMDAN6IJK1Cnzuda/3GrhxOPXbEh1e0fQAkAz+s3cPsOzn92E2NBW68D0vfV1bz0XD/tCyV+8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674636330; 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=3yGrRxVpE9jR3zWgDo+5wf6yMvDUWB9G3saBbfXZCg4=; b=kN7lmTxBzm+cRJUxZiq7LAgn+JC6OC1+oGcSjWBPQaYWxbHulvXOxkwwt8KJsq4zRncFexcgN+o/BerFGDjrIIU5KdAY2Qt6IGG6s3xRJBpuEqT85WhPjM2DuE4hYDD1gQnIzAvlNqDZZ5ehe/msP7YkXP2lb//cGx0UvB/TLfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674636330087464.90513868868493; Wed, 25 Jan 2023 00:45:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKbPG-0003Rn-Px; Wed, 25 Jan 2023 03:45:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKbPF-0003Ip-2e for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:45:21 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKbPB-000851-HU for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:45:20 -0500 Received: by mail-wm1-x334.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so711610wmb.2 for ; Wed, 25 Jan 2023 00:45:17 -0800 (PST) Received: from alex-rivos.home (lfbn-lyo-1-450-160.w2-7.abo.wanadoo.fr. [2.7.42.160]) by smtp.gmail.com with ESMTPSA id i28-20020a05600c4b1c00b003dab40f9eafsm1109101wmp.35.2023.01.25.00.45.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 00:45:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=3yGrRxVpE9jR3zWgDo+5wf6yMvDUWB9G3saBbfXZCg4=; b=Y6G/0jkmy7MiGnGG9B795FrYM278mFXZsiCgPWjH5HcbDn6TUW2HxIOhZss1VcHWky Thnlr4ymOcM8XSwZ26tyXpQjlouATMmbhGY3S+W13T3q4C2pFEZ8feyCLK9bifz/UWU2 k8dZ7l+zL6y8DI5HEHgvWXc8SDtp7G/kBy8vYelJzhAFhWB+HNEPHeET7rsRWSzF3PUO qSGIX0ktVdFoQTRprCLKvXo57ZO9hpkxS6ZmRE/OpaBhGCRtEOHhPM2kwFrGgRVZdhYC F95kw/7y6X6OMco1T7MsXMAizKPtF04bL3VcduIY8f0i+ziBa40ncYDsq1Yi86a3B1Ia pKLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=3yGrRxVpE9jR3zWgDo+5wf6yMvDUWB9G3saBbfXZCg4=; b=4l+x5Lvjrjm6NnF9p2Ri0HqgVmKqRjAROWAr0R7dgCJC9EUq4D/xrXTfEdNt5ndw56 3NqKgE3jazg4giHCR+r0CaYPWY0lLsM/VvvC8Qv20NUE9FT6cwdYyvLmO5mODfAhh8dN jU+Q79LEVtBhBtRQX19Fcl3D0GpVlUFnV09kamTwCmWclg9Elbnl341gNKpx7raWq+DV GWMOjuBPlr6sG8woaBQRMIs2WZf0b+A9asPQw3EUcxt2XGR5HyfpGB3TmijbZyBIKNdf vBG3gO6FWHCX6BME8zZZW4b+RxhKEM7BPuCDj2kNr1j65c9Jib3c3h5fYDVi2UTTC4Ow A6Lg== X-Gm-Message-State: AFqh2kqC0A991CUQytbcXZQv36/XRkiVrXR+pylbCduLhwuMFh2axxaY wMV10oa/kbIL5mP46KlwLmIycQ== X-Google-Smtp-Source: AMrXdXsJ7NBnoLBaYEwg9JT5/xA9e7Ec44kUI8pj6KzaFsQN/4leBYUgdWmZGOheoBUeaDywz89gyA== X-Received: by 2002:a1c:f310:0:b0:3db:15d9:1485 with SMTP id q16-20020a1cf310000000b003db15d91485mr24981725wmq.39.1674636315947; Wed, 25 Jan 2023 00:45:15 -0800 (PST) From: Alexandre Ghiti To: Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Frank Chang , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Alexandre Ghiti Subject: [PATCH v7 4/5] riscv: Introduce satp mode hw capabilities Date: Wed, 25 Jan 2023 09:41:06 +0100 Message-Id: <20230125084107.1580972-5-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125084107.1580972-1-alexghiti@rivosinc.com> References: <20230125084107.1580972-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alexghiti@rivosinc.com; helo=mail-wm1-x334.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674636331728100003 Content-Type: text/plain; charset="utf-8" Currently, the max satp mode is set with the only constraint that it must be implemented in qemu, i.e. set in valid_vm_1_10_[32|64]. But we actually need to add another level of constraint: what the hw is actually capable of, because currently, a linux booting on a sifive-u54 boots in sv57 mode which is incompatible with the cpu's sv39 max capability. So add a new bitmap to RISCVSATPMap which contains this capability and initialize it in every XXX_cpu_init. Finally: - valid_vm_1_10_[32|64] constrains which satp mode the CPU can use - the CPU hw capabilities constrains what the user may select - the user's selection then constrains what's available to the guest OS. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones --- target/riscv/cpu.c | 74 +++++++++++++++++++++++++++++++--------------- target/riscv/cpu.h | 8 +++-- 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 87153a0219..bba9c39bb8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -292,26 +292,36 @@ const char *satp_mode_str(uint8_t satp_mode, bool is_= 32_bit) g_assert_not_reached(); } =20 -/* Sets the satp mode to the max supported */ -static void set_satp_mode_default(RISCVCPU *cpu) +static void set_satp_mode_max_supported(RISCVCPU *cpu, + uint8_t satp_mode) { bool rv32 =3D riscv_cpu_mxl(&cpu->env) =3D=3D MXL_RV32; + const bool *valid_vm =3D rv32 ? valid_vm_1_10_32 : valid_vm_1_10_64; =20 - if (riscv_feature(&cpu->env, RISCV_FEATURE_MMU)) { - cpu->cfg.satp_mode.map |=3D - (1 << satp_mode_from_str(rv32 ? "sv32" : "sv57")); - } else { - cpu->cfg.satp_mode.map |=3D (1 << satp_mode_from_str("mbare")); + for (int i =3D 0; i <=3D satp_mode; ++i) { + if (valid_vm[i]) { + cpu->cfg.satp_mode.supported |=3D (1 << i); + } } } =20 +/* Sets the satp mode to the max supported */ +static void set_satp_mode_default(RISCVCPU *cpu) +{ + cpu->cfg.satp_mode.map =3D cpu->cfg.satp_mode.supported; +} + static void riscv_any_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + #if defined(TARGET_RISCV32) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU); + set_satp_mode_max_supported(cpu, VM_1_10_SV32); #elif defined(TARGET_RISCV64) set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU); + set_satp_mode_max_supported(cpu, VM_1_10_SV57); #endif set_priv_version(env, PRIV_VERSION_1_12_0); register_cpu_props(obj); @@ -321,18 +331,24 @@ static void riscv_any_cpu_init(Object *obj) static void rv64_base_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + /* We set this in the realise function */ 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); + set_satp_mode_max_supported(cpu, VM_1_10_SV57); } =20 static void rv64_sifive_u_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); + set_satp_mode_max_supported(cpu, VM_1_10_SV39); } =20 static void rv64_sifive_e_cpu_init(Object *obj) @@ -343,6 +359,7 @@ static void rv64_sifive_e_cpu_init(Object *obj) set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); cpu->cfg.mmu =3D false; + set_satp_mode_max_supported(cpu, VM_1_10_MBARE); } =20 static void rv128_base_cpu_init(Object *obj) @@ -354,11 +371,13 @@ static void rv128_base_cpu_init(Object *obj) exit(EXIT_FAILURE); } CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); /* We set this in the realise function */ 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); + set_satp_mode_max_supported(cpu, VM_1_10_SV57); } #else static void rv32_base_cpu_init(Object *obj) @@ -369,13 +388,17 @@ static void rv32_base_cpu_init(Object *obj) register_cpu_props(obj); /* Set latest version of privileged specification */ set_priv_version(env, PRIV_VERSION_1_12_0); + set_satp_mode_max_supported(cpu, VM_1_10_SV32); } =20 static void rv32_sifive_u_cpu_init(Object *obj) { CPURISCVState *env =3D &RISCV_CPU(obj)->env; + RISCVCPU *cpu =3D RISCV_CPU(obj); + set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); + set_satp_mode_max_supported(cpu, VM_1_10_SV32); } =20 static void rv32_sifive_e_cpu_init(Object *obj) @@ -386,6 +409,7 @@ static void rv32_sifive_e_cpu_init(Object *obj) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); cpu->cfg.mmu =3D false; + set_satp_mode_max_supported(cpu, VM_1_10_MBARE); } =20 static void rv32_ibex_cpu_init(Object *obj) @@ -396,6 +420,7 @@ static void rv32_ibex_cpu_init(Object *obj) set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_11_0); cpu->cfg.mmu =3D false; + set_satp_mode_max_supported(cpu, VM_1_10_MBARE); cpu->cfg.epmp =3D true; } =20 @@ -407,6 +432,7 @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); set_priv_version(env, PRIV_VERSION_1_10_0); cpu->cfg.mmu =3D false; + set_satp_mode_max_supported(cpu, VM_1_10_MBARE); } #endif =20 @@ -698,8 +724,9 @@ static void riscv_cpu_disas_set_info(CPUState *s, disas= semble_info *info) static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) { bool rv32 =3D riscv_cpu_mxl(&cpu->env) =3D=3D MXL_RV32; - const bool *valid_vm =3D rv32 ? valid_vm_1_10_32 : valid_vm_1_10_64; - uint8_t satp_mode_max; + uint8_t satp_mode_map_max; + uint8_t satp_mode_supported_max =3D + satp_mode_max_from_map(cpu->cfg.satp_mode.supporte= d); =20 if (cpu->cfg.satp_mode.map =3D=3D 0) { if (cpu->cfg.satp_mode.init =3D=3D 0) { @@ -714,9 +741,9 @@ static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu,= Error **errp) for (int i =3D 1; i < 16; ++i) { if (!(cpu->cfg.satp_mode.map & (1 << i)) && (cpu->cfg.satp_mode.init & (1 << i)) && - valid_vm[i]) { + (cpu->cfg.satp_mode.supported & (1 << i))) { for (int j =3D i - 1; j >=3D 0; --j) { - if (valid_vm[j]) { + if (cpu->cfg.satp_mode.supported & (1 << j)) { cpu->cfg.satp_mode.map |=3D (1 << j); break; } @@ -727,36 +754,35 @@ static void riscv_cpu_satp_mode_finalize(RISCVCPU *cp= u, Error **errp) } } =20 - /* Make sure the configuration asked is supported by qemu */ - for (int i =3D 0; i < 16; ++i) { - if ((cpu->cfg.satp_mode.map & (1 << i)) && !valid_vm[i]) { - error_setg(errp, "satp_mode %s is not valid", - satp_mode_str(i, rv32)); - return; - } + satp_mode_map_max =3D satp_mode_max_from_map(cpu->cfg.satp_mode.map); + + /* Make sure the user asked for a supported configuration (HW and qemu= ) */ + if (satp_mode_map_max > satp_mode_supported_max) { + error_setg(errp, "satp_mode %s is higher than hw max capability %s= ", + satp_mode_str(satp_mode_map_max, rv32), + satp_mode_str(satp_mode_supported_max, rv32)); + return; } =20 /* * Make sure the user did not ask for an invalid configuration as per * the specification. */ - satp_mode_max =3D satp_mode_max_from_map(cpu->cfg.satp_mode.map); - if (!rv32) { - for (int i =3D satp_mode_max - 1; i >=3D 0; --i) { + for (int i =3D satp_mode_map_max - 1; i >=3D 0; --i) { if (!(cpu->cfg.satp_mode.map & (1 << i)) && (cpu->cfg.satp_mode.init & (1 << i)) && - valid_vm[i]) { + (cpu->cfg.satp_mode.supported & (1 << i))) { error_setg(errp, "cannot disable %s satp mode if %s " "is enabled", satp_mode_str(i, false), - satp_mode_str(satp_mode_max, false)); + satp_mode_str(satp_mode_map_max, false)); return; } } } =20 /* Finally expand the map so that all valid modes are set */ - for (int i =3D satp_mode_max - 1; i >=3D 0; --i) { + for (int i =3D satp_mode_map_max - 1; i >=3D 0; --i) { cpu->cfg.satp_mode.map |=3D (1 << i); } } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e37177db5c..b591122099 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -416,13 +416,17 @@ struct RISCVCPUClass { =20 /* * map is a 16-bit bitmap: the most significant set bit in map is the maxi= mum - * satp mode that is supported. + * satp mode that is supported. It may be chosen by the user and must resp= ect + * what qemu implements (valid_1_10_32/64) and what the hw is capable of + * (supported bitmap below). * * init is a 16-bit bitmap used to make sure the user selected a correct * configuration as per the specification. + * + * supported is a 16-bit bitmap used to reflect the hw capabilities. */ typedef struct { - uint16_t map, init; + uint16_t map, init, supported; } RISCVSATPMap; =20 struct RISCVCPUConfig { --=20 2.37.2 From nobody Sat Apr 20 00:45:05 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1674636420; cv=none; d=zohomail.com; s=zohoarc; b=PE6mVo7NhAQZZeV4zPobuF2HOYlLjQt1oonPYSxksqACeHnpiNQ6IpQphFkZZF1TMdc7Pnsi+fxeVigwPBr++XkZbo1xh2XyIor/EzQ/q7LQ1SprPYeGFUWNuGRS4/tu0+9yJKqvCcMICETJReWcWq1X79kLJXjNpk1eJ+B1n7E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674636420; 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=IRWvpmPRHrukoIwIrFR+ERY535b3mU7yJB9xTFeVSNc=; b=LcY943cP2Cudtjubv7faeqKNTqWobz6RV4AIm0tJnJihCOMTnC4WhQegf07YG1qfw+dcyG/i2s6mNnojwVkdQS+/uZIqtblnRqxxt4BaU6pWNzcbBSBIlWdv+L8MvdZD2V5JaovMhJKW5ANfCIaXR9AKqX+pqPoRngJSyUBu2O0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1674636420909719.9573946125842; Wed, 25 Jan 2023 00:47:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pKbQJ-0006nH-8A; Wed, 25 Jan 2023 03:46:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pKbQC-0006Kr-II for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:46:22 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pKbQA-0008BX-6B for qemu-devel@nongnu.org; Wed, 25 Jan 2023 03:46:19 -0500 Received: by mail-wm1-x32e.google.com with SMTP id c4-20020a1c3504000000b003d9e2f72093so717975wma.1 for ; Wed, 25 Jan 2023 00:46:17 -0800 (PST) Received: from alex-rivos.home (lfbn-lyo-1-450-160.w2-7.abo.wanadoo.fr. [2.7.42.160]) by smtp.gmail.com with ESMTPSA id m18-20020adfe952000000b00286ad197346sm3850791wrn.70.2023.01.25.00.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 00:46:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; 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=IRWvpmPRHrukoIwIrFR+ERY535b3mU7yJB9xTFeVSNc=; b=bpklNfsyt9jwLJshAAnAoZ/GHctkWTO28Qwllz1TSEUmsKBGcN2pb1RYJM6MOv+cSa CncmPExEEvKiR75sKhOVuTSdI3IxUowLNcWQr9ftcGEcd1BqgBTut0Yy0nkyk8M89hgU vCjAXGz+GAbQudECk9/DKbDwJvpYtiDwl7E7lqfUpGtfISdVT0rr+m6sqCUD16HEGa24 KKmTrsgLLCt/2fyCGPmFDGFZoZmN+C2p0BJwtPfwqvgPKGDtZPyYkc2JVyMgxOCXyGjy WC35zA5hkvU0578RO43hyzARzBz0pGptxpg0Jo7686dJYKrD0Bad7fjk6pe/QRWnTyZj ByRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=IRWvpmPRHrukoIwIrFR+ERY535b3mU7yJB9xTFeVSNc=; b=iIwWK17v0bSjV8eFneLOcVaP+ZoekZR91SSWdVtS/2h2N1rCSfrDFbC+JRalzBwZqI NPPfo8Bmg9n3/qsTNjmd+GFoBtLKEgiksVGjS0whS5aNR3zy+XEkGHbfceoXy4l/8vFZ KjcMa+8ajp1RB5qnvRuGusYxde/jIPfB9SlcRblRIXCXcy4aEVwYRJpObx8B9ZDehAOt wE4ud8qv2fduOwEkjFm+WJ5uQaFv7dtJIabktwiB1FJhNlXiGJS1NwSw/a/bx+hRrnTD Qe17HXVzwUm3uopubU6up7Hj2KfZZwuy40WfeFz46IqS1fkxMSAeqaP7oKcvpYFUDPuR IdNw== X-Gm-Message-State: AFqh2koVMQKNeJMUqy8vaYDMPc7PX6wmte/nilaAg23Z2yTgdPq8oaXf eECLD4n1QAP3A9Kb0Vif6M0H/A== X-Google-Smtp-Source: AMrXdXvne5enjH73X+2/5xZIXijlQmkC4gon0WWBwXXANi6Ki2QTTFD2siDqqA2TIe2H1l4DylpQag== X-Received: by 2002:a05:600c:4191:b0:3d4:5741:af9b with SMTP id p17-20020a05600c419100b003d45741af9bmr38612590wmh.0.1674636376790; Wed, 25 Jan 2023 00:46:16 -0800 (PST) From: Alexandre Ghiti To: Palmer Dabbelt , Alistair Francis , Bin Meng , Andrew Jones , Frank Chang , qemu-riscv@nongnu.org, qemu-devel@nongnu.org Cc: Alexandre Ghiti Subject: [PATCH v7 5/5] riscv: Correctly set the device-tree entry 'mmu-type' Date: Wed, 25 Jan 2023 09:41:07 +0100 Message-Id: <20230125084107.1580972-6-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230125084107.1580972-1-alexghiti@rivosinc.com> References: <20230125084107.1580972-1-alexghiti@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=alexghiti@rivosinc.com; helo=mail-wm1-x32e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @rivosinc-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1674636422179100003 Content-Type: text/plain; charset="utf-8" The 'mmu-type' should reflect what the hardware is capable of so use the new satp_mode field in RISCVCPUConfig to do that. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Reviewed-by: Alistair Francis --- hw/riscv/virt.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index 94ff2a1584..48d034a5f7 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -228,7 +228,8 @@ static void create_fdt_socket_cpus(RISCVVirtState *s, i= nt socket, int cpu; uint32_t cpu_phandle; MachineState *mc =3D MACHINE(s); - char *name, *cpu_name, *core_name, *intc_name; + uint8_t satp_mode_max; + char *name, *cpu_name, *core_name, *intc_name, *sv_name; =20 for (cpu =3D s->soc[socket].num_harts - 1; cpu >=3D 0; cpu--) { cpu_phandle =3D (*phandle)++; @@ -236,14 +237,14 @@ static void create_fdt_socket_cpus(RISCVVirtState *s,= int socket, cpu_name =3D g_strdup_printf("/cpus/cpu@%d", s->soc[socket].hartid_base + cpu); qemu_fdt_add_subnode(mc->fdt, cpu_name); - if (riscv_feature(&s->soc[socket].harts[cpu].env, - RISCV_FEATURE_MMU)) { - qemu_fdt_setprop_string(mc->fdt, cpu_name, "mmu-type", - (is_32_bit) ? "riscv,sv32" : "riscv,sv= 48"); - } else { - qemu_fdt_setprop_string(mc->fdt, cpu_name, "mmu-type", - "riscv,none"); - } + + satp_mode_max =3D satp_mode_max_from_map( + s->soc[socket].harts[cpu].cfg.satp_mode.map); + sv_name =3D g_strdup_printf("riscv,%s", + satp_mode_str(satp_mode_max, is_32_bit)); + qemu_fdt_setprop_string(mc->fdt, cpu_name, "mmu-type", sv_name); + g_free(sv_name); + name =3D riscv_isa_string(&s->soc[socket].harts[cpu]); qemu_fdt_setprop_string(mc->fdt, cpu_name, "riscv,isa", name); g_free(name); --=20 2.37.2