From patchwork Sun Feb 6 09:18:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12736491 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1514C433F5 for ; Sun, 6 Feb 2022 09:32:00 +0000 (UTC) Received: from localhost ([::1]:39196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGdtn-0001vH-GY for qemu-devel@archiver.kernel.org; Sun, 06 Feb 2022 04:31:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGdh6-0007v7-8e for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:52 -0500 Received: from [2607:f8b0:4864:20::c2d] (port=36807 helo=mail-oo1-xc2d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGdh3-00012h-Kg for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:51 -0500 Received: by mail-oo1-xc2d.google.com with SMTP id r15-20020a4ae5cf000000b002edba1d3349so10305446oov.3 for ; Sun, 06 Feb 2022 01:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xsyBGPmuEohYbzq2IKhS66MWC7voJesO8CpZ+xmmjNo=; b=hSyXkGOJzdKXQhEEh87kxGadcnVRYqeVfm/bk0/4Z9EPZj/n9vXKpW9YXwwuirTMJP JKMMR7sfLcprgqUgyzMfxUBGHPcDCtoH/+yQt1h7f1W4u+i3QqfcmW4qR8ioUmw5iuKc NJFBDA2w+Kta/TSn9hPMQWCdCepy4LJ3OrbmrfWzBSwXt4je/p1XoNEJa/AJOri6DJpX MrTXAYEEQWdpsaALc1LJ6xGhjSC4EohMTGby6UK8PJA+Ca+xoJ+TPZ9wJua/Cvx+ng3z E7Clp3LoIdIk5AHKMnkA6Wpue010Bf9IGkmp4DXT9dHtEjAqUrkmywOcsI+37ifzzUwp 6W+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xsyBGPmuEohYbzq2IKhS66MWC7voJesO8CpZ+xmmjNo=; b=YU8IbBb09wwoUxoEpTbDn6Joe8z/ZKLr8XSM4ffIoZWin14fKyG/+yDto9naW7tb2S Xyq90gMe0AK5h6GlVM76Fpv6DioPbLFe6qqGlijPymXEwSlpX0gC1ntLjJMxs8AS6G+n fajJpFdbh7TbE6squZLMQns/ZpjeXfuzU+iQ/pEG7G0ee78Ut6+afLmZfxwocWNn6qE7 S/2lhSog1ZCum5OJ2+dgkYO7J1ZhTBRvecpiKdgOp043UbKTCX61dEYjKSa2MKm/rzzz vgaamiiNDzSQIInnC7pdKVxq1Cjuj9iB9Jgpd094rbUbcF+1NGcevr7jk+zIflze5XJJ J0hQ== X-Gm-Message-State: AOAM5305LSS3OCCu2T5SiUgiyW7GenyqIPTIDSkniCt5fQFzDvMuqifU 1yul14jbFqpLctCXbuGjt21H9DJNHeQKS8SN X-Google-Smtp-Source: ABdhPJy755QXDmopiMYggEWgYLiYXRKHa/bx2tStkhsg8C5kaaOg08fNOXEoliM2CfKVHzpUyuhZeA== X-Received: by 2002:a05:6870:13ca:: with SMTP id 10mr1929474oat.210.1644139128481; Sun, 06 Feb 2022 01:18:48 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 1sm1596841oab.16.2022.02.06.01.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 01:18:48 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [PATCH v3 1/6] target/riscv: Define simpler privileged spec version numbering Date: Sun, 6 Feb 2022 01:18:30 -0800 Message-Id: <20220206091835.1244296-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091835.1244296-1-atishp@rivosinc.com> References: <20220206091835.1244296-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::c2d (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::c2d; envelope-from=atishp@rivosinc.com; helo=mail-oo1-xc2d.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: qemu-riscv@nongnu.org, Atish Patra , Bin Meng , Richard Henderson , Alistair Francis , Palmer Dabbelt Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently, the privileged specification version are defined in a complex manner for no benefit. Simplify it by changing it to a simple enum based on. Suggested-by: Richard Henderson Signed-off-by: Atish Patra Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 9d24d678e98a..e5ff4c134c86 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -82,8 +82,11 @@ enum { RISCV_FEATURE_AIA }; -#define PRIV_VERSION_1_10_0 0x00011000 -#define PRIV_VERSION_1_11_0 0x00011100 +/* Privileged specification version */ +enum { + PRIV_VERSION_1_10_0 = 0, + PRIV_VERSION_1_11_0, +}; #define VEXT_VERSION_1_00_0 0x00010000 From patchwork Sun Feb 6 09:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12736492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B50DFC433EF for ; Sun, 6 Feb 2022 09:39:23 +0000 (UTC) Received: from localhost ([::1]:48180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGe0v-0008ON-Ro for qemu-devel@archiver.kernel.org; Sun, 06 Feb 2022 04:39:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGdh7-0007xg-3Y for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:53 -0500 Received: from [2607:f8b0:4864:20::331] (port=40622 helo=mail-ot1-x331.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGdh4-00012r-Ue for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:52 -0500 Received: by mail-ot1-x331.google.com with SMTP id x52-20020a05683040b400b0059ea92202daso8817188ott.7 for ; Sun, 06 Feb 2022 01:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EyU4+THqr3Y8pJWma7DCKWkG8X88FhKyF8Z3F935mXk=; b=DeEJuJKdoj0NZhvR5f7t3V/hpuY+3ezAjLO+WtuShf4YFEmrKAeUXNBnf6GOsyW/1t MoHsmtljrC8pUzJhd80DicVXhkB4Pzv4f/lNn/vzdu2Zb0uC6ACabqgnPReiY5bEYrYq LfFIb2vXPHZHgL4qAozr9zCXQc6D4SVS/1SAY/9hp7DpyKNin/nN7SXtuApWG3oWOWBw kAHV8CQQDD5OguezBSyeMDRs+2Ts9iRVicuV6qI3KURsWb3CNyFgvnjkdjkphwpHBp/k BIk+3ihOwlTMxz8xut/FUHyV6tLuZ/E0ehnXPY1inaiskPZXScx3eni9V5LrUFypES+H 9trw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EyU4+THqr3Y8pJWma7DCKWkG8X88FhKyF8Z3F935mXk=; b=b5yFBjodJD+SAw1otyBw7SaomJ4tazkxMjWEnOWAfx+yhWesxe2peFiubpiP3cZ7Ta Rwmra6pn2dlfIfjmSf7BNMxPuDNvhYEPmlWRIDt754XuFpD8FRAwHHZWJogPXICICGb8 RrAH5VLo0oIhHm46WocsnWEDIJjnBqU57tsAZRN4V27emVHx9gekzSWpM0meZPzYm3Wa 9SfvXbacl+0iTgs1EAMScxQRzWKxNWGmFkiMoaT9q4hJYkzllGWLnhCu4L8sk9ntjA0n Ug/9b6Ai8H+IJAVtOQm9OmW7dNijXcPTnGUrObbFMttPNv6U5zoITKqlUBGDJ+gil+zF gwOw== X-Gm-Message-State: AOAM533oR2czz+g9wtFWeVKUfqqANHVawAuLOm0MfTiZKwwp/sG9HSSk vn8n0dXztzBA23KB6H2UVRMHt9xeJT4o2AbJ X-Google-Smtp-Source: ABdhPJxsK+rSquopr6U5ArkFnbkEZKOVK6ZAJDDTF7giz1xHdift55ZNJiWoK29tfTqHVKgCkwRLRA== X-Received: by 2002:a05:6830:839:: with SMTP id t25mr2405711ots.372.1644139129698; Sun, 06 Feb 2022 01:18:49 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 1sm1596841oab.16.2022.02.06.01.18.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 01:18:49 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [PATCH v3 2/6] target/riscv: Add the privileged spec version 1.12.0 Date: Sun, 6 Feb 2022 01:18:31 -0800 Message-Id: <20220206091835.1244296-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091835.1244296-1-atishp@rivosinc.com> References: <20220206091835.1244296-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::331 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::331; envelope-from=atishp@rivosinc.com; helo=mail-ot1-x331.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Alistair Francis , Bin Meng , Atish Patra , Palmer Dabbelt , qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add the definition for ratified privileged specification version v1.12 Signed-off-by: Atish Patra Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index e5ff4c134c86..60b847141db2 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -86,6 +86,7 @@ enum { enum { PRIV_VERSION_1_10_0 = 0, PRIV_VERSION_1_11_0, + PRIV_VERSION_1_12_0, }; #define VEXT_VERSION_1_00_0 0x00010000 From patchwork Sun Feb 6 09:18:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12736483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCA2CC433F5 for ; Sun, 6 Feb 2022 09:23:19 +0000 (UTC) Received: from localhost ([::1]:57186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGdlO-00037D-SB for qemu-devel@archiver.kernel.org; Sun, 06 Feb 2022 04:23:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGdh8-000802-10 for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:54 -0500 Received: from [2607:f8b0:4864:20::332] (port=41600 helo=mail-ot1-x332.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGdh6-00013V-6T for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:53 -0500 Received: by mail-ot1-x332.google.com with SMTP id b12-20020a9d754c000000b0059eb935359eso8823450otl.8 for ; Sun, 06 Feb 2022 01:18:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O6PObwqwUIyUdHO/OYUSJ8TGMiaYgn/szHFribdqUcc=; b=2qRkEbyBeaZcg8kyyYOD/xH4GCJF/JRpc25V3BJ3CSNHa+y0UAiLsUK18+QE8GjDQU JoPeITXZvcgUiZc9qQROuNiXdlSzwhXD70000+Kh+/KSs7RjvEdaHmsnqPLAaN/XCUKl pMI5/QsB+SUCY+X/EzSyax0vv0Qj4twteuJtFWOfi2ZBkSdXXUZl/CdK1gBFqrWIbPBq wjQKTRTFe9g/ybB1JJM+AebSkCLZ9Q1Ye9cHT+R1C8A/u9SJzErD3A/DRjSyfoc2OIwd QTwuuNgM3NYkCBbaHV2ZRJ3qkX8XVa2rPyGSGo/ZseT5FeG0HXBynXNGZcaGLYAd9wLN dzPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O6PObwqwUIyUdHO/OYUSJ8TGMiaYgn/szHFribdqUcc=; b=RHJfeT+9LlSp/mDjCe9PH/R9Dq6pLZFI5b7NjOjiv0sGSu8lCVoys0aZG924GzodKd 7vcjFTx9ThAEn7ZvPNI8tbvwvyn0n4JseNIcXpqpbVWbbYfPwr4Nu5GXksPxzDRu/yIO ZcAMXxQ9PqoYKddeWhaofYru2U0ANO3QKE12/dadOwA2pYKu/lr6DdfUyh6r1sK45LQx QFvv7FDTeQZsxEiuBDSLbDRbOCOTS0b/Tmqx2PkbjP5QAlaH/Yco/HfScdpfIBsX+mFU lq3ooPtvjAeZI4yXva7wY/n+O290O7xESySDsw4NMvDiAMpTZOZ1mYWdKgM7fVVHTXzk IADQ== X-Gm-Message-State: AOAM532GxTSNvN381ADNx4QVk5CUGlwfCsmyHJAUUTY5jy81n4WFlm9H NVBRIxeIriILszTa4h+t2VKxeAF91f/asgBH X-Google-Smtp-Source: ABdhPJy455Y5gy3wZuaUODLdmKRZVHMMnUxF9Ci2eaVSOzlKFDwE0x34S/Klkd0X9MLuUKEdqh3CEQ== X-Received: by 2002:a05:6830:2328:: with SMTP id q8mr2442076otg.251.1644139130923; Sun, 06 Feb 2022 01:18:50 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 1sm1596841oab.16.2022.02.06.01.18.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 01:18:50 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [PATCH v3 3/6] target/riscv: Introduce privilege version field in the CSR ops. Date: Sun, 6 Feb 2022 01:18:32 -0800 Message-Id: <20220206091835.1244296-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091835.1244296-1-atishp@rivosinc.com> References: <20220206091835.1244296-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::332 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::332; envelope-from=atishp@rivosinc.com; helo=mail-ot1-x332.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Alistair Francis , Bin Meng , Atish Patra , Palmer Dabbelt , qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" To allow/disallow the CSR access based on the privilege spec, a new field in the csr_ops is introduced. It also adds the privileged specification version (v1.12) for the CSRs introduced in the v1.12. This includes the new ratified extensions such as Vector, Hypervisor and secconfig CSR. Signed-off-by: Atish Patra Reviewed-by: Alistair Francis --- target/riscv/cpu.h | 2 + target/riscv/csr.c | 103 ++++++++++++++++++++++++++++++--------------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 60b847141db2..0741f9822cf0 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -593,6 +593,8 @@ typedef struct { riscv_csr_op_fn op; riscv_csr_read128_fn read128; riscv_csr_write128_fn write128; + /* The default priv spec version should be PRIV_VERSION_1_10_0 (i.e 0) */ + uint32_t min_priv_ver; } riscv_csr_operations; /* CSR function table constants */ diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 8c63caa39245..25a0df498669 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2981,13 +2981,20 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_FRM] = { "frm", fs, read_frm, write_frm }, [CSR_FCSR] = { "fcsr", fs, read_fcsr, write_fcsr }, /* Vector CSRs */ - [CSR_VSTART] = { "vstart", vs, read_vstart, write_vstart }, - [CSR_VXSAT] = { "vxsat", vs, read_vxsat, write_vxsat }, - [CSR_VXRM] = { "vxrm", vs, read_vxrm, write_vxrm }, - [CSR_VCSR] = { "vcsr", vs, read_vcsr, write_vcsr }, - [CSR_VL] = { "vl", vs, read_vl }, - [CSR_VTYPE] = { "vtype", vs, read_vtype }, - [CSR_VLENB] = { "vlenb", vs, read_vlenb }, + [CSR_VSTART] = { "vstart", vs, read_vstart, write_vstart, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VXSAT] = { "vxsat", vs, read_vxsat, write_vxsat, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VXRM] = { "vxrm", vs, read_vxrm, write_vxrm, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VCSR] = { "vcsr", vs, read_vcsr, write_vcsr, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VL] = { "vl", vs, read_vl, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VTYPE] = { "vtype", vs, read_vtype, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VLENB] = { "vlenb", vs, read_vlenb, + .min_priv_ver = PRIV_VERSION_1_12_0 }, /* User Timers and Counters */ [CSR_CYCLE] = { "cycle", ctr, read_instret }, [CSR_INSTRET] = { "instret", ctr, read_instret }, @@ -3096,33 +3103,58 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_SIEH] = { "sieh", aia_smode32, NULL, NULL, rmw_sieh }, [CSR_SIPH] = { "siph", aia_smode32, NULL, NULL, rmw_siph }, - [CSR_HSTATUS] = { "hstatus", hmode, read_hstatus, write_hstatus }, - [CSR_HEDELEG] = { "hedeleg", hmode, read_hedeleg, write_hedeleg }, - [CSR_HIDELEG] = { "hideleg", hmode, NULL, NULL, rmw_hideleg }, - [CSR_HVIP] = { "hvip", hmode, NULL, NULL, rmw_hvip }, - [CSR_HIP] = { "hip", hmode, NULL, NULL, rmw_hip }, - [CSR_HIE] = { "hie", hmode, NULL, NULL, rmw_hie }, - [CSR_HCOUNTEREN] = { "hcounteren", hmode, read_hcounteren, write_hcounteren }, - [CSR_HGEIE] = { "hgeie", hmode, read_hgeie, write_hgeie }, - [CSR_HTVAL] = { "htval", hmode, read_htval, write_htval }, - [CSR_HTINST] = { "htinst", hmode, read_htinst, write_htinst }, - [CSR_HGEIP] = { "hgeip", hmode, read_hgeip, NULL }, - [CSR_HGATP] = { "hgatp", hmode, read_hgatp, write_hgatp }, - [CSR_HTIMEDELTA] = { "htimedelta", hmode, read_htimedelta, write_htimedelta }, - [CSR_HTIMEDELTAH] = { "htimedeltah", hmode32, read_htimedeltah, write_htimedeltah }, - - [CSR_VSSTATUS] = { "vsstatus", hmode, read_vsstatus, write_vsstatus }, - [CSR_VSIP] = { "vsip", hmode, NULL, NULL, rmw_vsip }, - [CSR_VSIE] = { "vsie", hmode, NULL, NULL, rmw_vsie }, - [CSR_VSTVEC] = { "vstvec", hmode, read_vstvec, write_vstvec }, - [CSR_VSSCRATCH] = { "vsscratch", hmode, read_vsscratch, write_vsscratch }, - [CSR_VSEPC] = { "vsepc", hmode, read_vsepc, write_vsepc }, - [CSR_VSCAUSE] = { "vscause", hmode, read_vscause, write_vscause }, - [CSR_VSTVAL] = { "vstval", hmode, read_vstval, write_vstval }, - [CSR_VSATP] = { "vsatp", hmode, read_vsatp, write_vsatp }, - - [CSR_MTVAL2] = { "mtval2", hmode, read_mtval2, write_mtval2 }, - [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst }, + [CSR_HSTATUS] = { "hstatus", hmode, read_hstatus, write_hstatus, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HEDELEG] = { "hedeleg", hmode, read_hedeleg, write_hedeleg, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HIDELEG] = { "hideleg", hmode, NULL, NULL, rmw_hideleg, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HVIP] = { "hvip", hmode, NULL, NULL, rmw_hvip, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HIP] = { "hip", hmode, NULL, NULL, rmw_hip, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HIE] = { "hie", hmode, NULL, NULL, rmw_hie, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HCOUNTEREN] = { "hcounteren", hmode, read_hcounteren, write_hcounteren, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HGEIE] = { "hgeie", hmode, read_hgeie, write_hgeie, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HTVAL] = { "htval", hmode, read_htval, write_htval, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HTINST] = { "htinst", hmode, read_htinst, write_htinst, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HGEIP] = { "hgeip", hmode, read_hgeip, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HGATP] = { "hgatp", hmode, read_hgatp, write_hgatp, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HTIMEDELTA] = { "htimedelta", hmode, read_htimedelta, write_htimedelta, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HTIMEDELTAH] = { "htimedeltah", hmode32, read_htimedeltah, write_htimedeltah, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + + [CSR_VSSTATUS] = { "vsstatus", hmode, read_vsstatus, write_vsstatus, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSIP] = { "vsip", hmode, NULL, NULL, rmw_vsip, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSIE] = { "vsie", hmode, NULL, NULL, rmw_vsie , + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSTVEC] = { "vstvec", hmode, read_vstvec, write_vstvec, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSSCRATCH] = { "vsscratch", hmode, read_vsscratch, write_vsscratch, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSEPC] = { "vsepc", hmode, read_vsepc, write_vsepc, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSCAUSE] = { "vscause", hmode, read_vscause, write_vscause, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSTVAL] = { "vstval", hmode, read_vstval, write_vstval, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_VSATP] = { "vsatp", hmode, read_vsatp, write_vsatp, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + + [CSR_MTVAL2] = { "mtval2", hmode, read_mtval2, write_mtval2, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_MTINST] = { "mtinst", hmode, read_mtinst, write_mtinst, + .min_priv_ver = PRIV_VERSION_1_12_0 }, /* Virtual Interrupts and Interrupt Priorities (H-extension with AIA) */ [CSR_HVIEN] = { "hvien", aia_hmode, read_zero, write_ignore }, @@ -3154,7 +3186,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_VSIPH] = { "vsiph", aia_hmode32, NULL, NULL, rmw_vsiph }, /* Physical Memory Protection */ - [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg }, + [CSR_MSECCFG] = { "mseccfg", epmp, read_mseccfg, write_mseccfg, + .min_priv_ver = PRIV_VERSION_1_12_0 }, [CSR_PMPCFG0] = { "pmpcfg0", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG1] = { "pmpcfg1", pmp, read_pmpcfg, write_pmpcfg }, [CSR_PMPCFG2] = { "pmpcfg2", pmp, read_pmpcfg, write_pmpcfg }, From patchwork Sun Feb 6 09:18:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12736499 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB2FFC433F5 for ; Sun, 6 Feb 2022 09:48:02 +0000 (UTC) Received: from localhost ([::1]:37612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGe9J-0003kC-Fn for qemu-devel@archiver.kernel.org; Sun, 06 Feb 2022 04:48:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGdh8-00082V-Ry for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:54 -0500 Received: from [2607:f8b0:4864:20::c2e] (port=42537 helo=mail-oo1-xc2e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGdh7-00014E-Bl for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:54 -0500 Received: by mail-oo1-xc2e.google.com with SMTP id w5-20020a4a9785000000b0030956914befso10262361ooi.9 for ; Sun, 06 Feb 2022 01:18:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=znQ0SVdA7leeqpez6/9lgiMyOZDn0ifFMpy9Ja+QSK0=; b=up1rXZ355Z/a7yDoSPYsucNZyDorXoBxPVqZM8jzbLiaDC/euqC00HNFIkpjUT4nT4 dkDINn5IBRPngp0eqK9awe8UfeT9lR859PJ0M1Uyr2rTjBIB471zJsVnaRIJbvBFNQ6S PZjnKIJ1Tbm8FjP77upP8rrfO4EpSnqfvBbfW/W12QF1fpZ9yBESZZFZvoFY9prXeYCI WG7VZuWLLBUXlOx99eG1I5v+8TrLf6ChDnle6wToTNTzMLqy6jHxMLaFB3sDdXhAZ1z+ Aq/IxkLYBdc+1PGp36A/x811Wsrhu68XuuHeiup1+VjgKCuQXW9/rxzEgJ9TqvQegI6H WSCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=znQ0SVdA7leeqpez6/9lgiMyOZDn0ifFMpy9Ja+QSK0=; b=GX2zMdV9nUSOiwQH8gs+x0SnoZ5SkkBdvkJOKWiG9vSLO+Bf/fjqISLJVGT5H2Gf5N mH5+HeVIpPC+tMfHcAijLGSv6O5aLJcEXyibcwlpeOpf1n0BqtAXS+6BIuSJVAjw5Va9 NfxWhRo4n0Tes10t8SqQB6lHbf5nKtVHoFLwaqA1wW/NAg+lvQgTjlIlA4sJ92uYBdYf hVAknY3ZuoR5zNoREjxoUSybDpKZr70fMqJxdDsvzSJhrE/pYZqQtC+t2m1m8cjR7mJF swlVDrI3V7o8SpjjYBTQ+wuOoFEqS6wPJ98R3cCxqKgEtd91F0wGI9v2DhzFmpjVWRqF B3+w== X-Gm-Message-State: AOAM531jdele5kqy944G8hClYA/lW+hXtuyY+x8ov5IjSY7a/CeHFqGx ewUy8o4uXOQTMhoL8WybEA5LPj+QiYlNnOwD X-Google-Smtp-Source: ABdhPJxnWZPr7pfZ+B1iVDPNx1xXIXP84Ehcy+frzwx1pLZshsvv5+ZxgkqJCuHV5LFYJceLs3R7zQ== X-Received: by 2002:a05:6870:7734:: with SMTP id dw52mr1160983oab.185.1644139132181; Sun, 06 Feb 2022 01:18:52 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 1sm1596841oab.16.2022.02.06.01.18.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 01:18:51 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [PATCH v3 4/6] target/riscv: Add support for mconfigptr Date: Sun, 6 Feb 2022 01:18:33 -0800 Message-Id: <20220206091835.1244296-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091835.1244296-1-atishp@rivosinc.com> References: <20220206091835.1244296-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::c2e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::c2e; envelope-from=atishp@rivosinc.com; helo=mail-oo1-xc2e.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Alistair Francis , Bin Meng , Atish Patra , Palmer Dabbelt , qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" RISC-V privileged specification v1.12 introduced a mconfigptr which will hold the physical address of a configuration data structure. As Qemu doesn't have a configuration data structure, is read as zero which is valid as per the priv spec. Signed-off-by: Atish Patra Reviewed-by: Alistair Francis --- target/riscv/cpu_bits.h | 1 + target/riscv/csr.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index f96d26399607..89440241632a 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -148,6 +148,7 @@ #define CSR_MARCHID 0xf12 #define CSR_MIMPID 0xf13 #define CSR_MHARTID 0xf14 +#define CSR_MCONFIGPTR 0xf15 /* Machine Trap Setup */ #define CSR_MSTATUS 0x300 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 25a0df498669..18fe17b62f51 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3021,6 +3021,8 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MIMPID] = { "mimpid", any, read_zero }, [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MCONFIGPTR] = { "mconfigptr", any, read_zero, + .min_priv_ver = PRIV_VERSION_1_12_0 }, /* Machine Trap Setup */ [CSR_MSTATUS] = { "mstatus", any, read_mstatus, write_mstatus, NULL, read_mstatus_i128 }, From patchwork Sun Feb 6 09:18:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12736484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66967C433F5 for ; Sun, 6 Feb 2022 09:23:23 +0000 (UTC) Received: from localhost ([::1]:57394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGdlS-0003GY-GH for qemu-devel@archiver.kernel.org; Sun, 06 Feb 2022 04:23:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGdhA-00089p-UQ for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:56 -0500 Received: from [2607:f8b0:4864:20::335] (port=41603 helo=mail-ot1-x335.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGdh8-00014f-NB for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:56 -0500 Received: by mail-ot1-x335.google.com with SMTP id b12-20020a9d754c000000b0059eb935359eso8823472otl.8 for ; Sun, 06 Feb 2022 01:18:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=er3O3f7Ph7vBsTAPhBit3sfvbgYjjR3ybH8BV0JDaWk=; b=YaNmajwON+mlMlavkv491DXjXpFzd+rfnHOq0sIZyoSLrbE+VNFXKWMZdYsw27rwNj SaLe7UR6U0kKM5jFL0MmDy+MfLOzvuaNP9RELRGnaDk3Ke4bVihGsPtLlqleuRDfWLbX WC4//fix1bgDrC5GyTPDrO1FoUO097eKsPpgwqA4dLsYkJlBYqzdYoNF8kvNbQ2gzWLo R/C5XLYruetfUZhoQ2BHCx02y6Ij9AVCceBpz4OHUwdprvvwUuKw8NMCt2g1MtCB2Xzs WC6i8hnz5tpHJeUZ78x7nyCxO2Wr4NIBjDviV151CfTKFPv2k5LaQVoyA8vKx/7ECxAe RNKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=er3O3f7Ph7vBsTAPhBit3sfvbgYjjR3ybH8BV0JDaWk=; b=Cp4T1SB9PMs3c0ZG1/dlCvHD511ANB1ETu5eA+lq7gkN+4kM5EYgFBM0RIWCtg8pJz eiC6CCNbpltknwGhnYbTPwb75yQhQEKWSKYANjOWGHf16H27w8u6mtCT+/umGctT+u/S eMe0UmZmCNPoeIMT3IFpDmqAnnMfM3LFa/luvMPQ0fIAZG1Fuq4E0a4nqtmgtamhKGkF qiXANwYB9/fRywo8ULPD9O4DXLPRhlMbAlReNAba5R2HvDW40ItrOer35TPM7ubgxv+K BMkd7iclo7mFuEo4wNlkXEPIel8zkMq7YtP6eWCQOGmk0IFSJMdVa8Vv7SVukAhE1pCg /KBA== X-Gm-Message-State: AOAM530hjhNQh/+e7IjBWawEHnqQ6+/WNiDijqgLWazv0a8TUbV7dygO HEpAzWloxtvtw//gJQOX7eqJtYlHdwzq8ubu X-Google-Smtp-Source: ABdhPJwPS/8LtEU4Pu1LaOB+/Pdy2Zra9Z0suA1bDgjT9vhEze8mSC6DZRW1BSkg+npMSP4ZyiT9fQ== X-Received: by 2002:a9d:3e02:: with SMTP id a2mr2411620otd.80.1644139133421; Sun, 06 Feb 2022 01:18:53 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 1sm1596841oab.16.2022.02.06.01.18.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 01:18:52 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [PATCH v3 5/6] target/riscv: Add *envcfg* CSRs support Date: Sun, 6 Feb 2022 01:18:34 -0800 Message-Id: <20220206091835.1244296-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091835.1244296-1-atishp@rivosinc.com> References: <20220206091835.1244296-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::335 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::335; envelope-from=atishp@rivosinc.com; helo=mail-ot1-x335.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Alistair Francis , Bin Meng , Atish Patra , Palmer Dabbelt , qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The RISC-V privileged specification v1.12 defines few execution environment configuration CSRs that can be used enable/disable extensions per privilege levels. Add the basic support for these CSRs. Signed-off-by: Atish Patra --- target/riscv/cpu.h | 5 ++ target/riscv/cpu_bits.h | 39 +++++++++++++++ target/riscv/csr.c | 107 ++++++++++++++++++++++++++++++++++++++++ target/riscv/machine.c | 24 +++++++++ 4 files changed, 175 insertions(+) diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 0741f9822cf0..e5c8694cf081 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -303,6 +303,11 @@ struct CPURISCVState { target_ulong spmbase; target_ulong upmmask; target_ulong upmbase; + + /* CSRs for execution enviornment configuration */ + uint64_t menvcfg; + target_ulong senvcfg; + uint64_t henvcfg; #endif float_status fp_status; diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h index 89440241632a..58a0a8d69f72 100644 --- a/target/riscv/cpu_bits.h +++ b/target/riscv/cpu_bits.h @@ -202,6 +202,9 @@ #define CSR_STVEC 0x105 #define CSR_SCOUNTEREN 0x106 +/* Supervisor Configuration CSRs */ +#define CSR_SENVCFG 0x10A + /* Supervisor Trap Handling */ #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 @@ -247,6 +250,10 @@ #define CSR_HTIMEDELTA 0x605 #define CSR_HTIMEDELTAH 0x615 +/* Hypervisor Configuration CSRs */ +#define CSR_HENVCFG 0x60A +#define CSR_HENVCFGH 0x61A + /* Virtual CSRs */ #define CSR_VSSTATUS 0x200 #define CSR_VSIE 0x204 @@ -290,6 +297,10 @@ #define CSR_VSIEH 0x214 #define CSR_VSIPH 0x254 +/* Machine Configuration CSRs */ +#define CSR_MENVCFG 0x30A +#define CSR_MENVCFGH 0x31A + /* Enhanced Physical Memory Protection (ePMP) */ #define CSR_MSECCFG 0x747 #define CSR_MSECCFGH 0x757 @@ -654,6 +665,34 @@ typedef enum RISCVException { #define PM_EXT_CLEAN 0x00000002ULL #define PM_EXT_DIRTY 0x00000003ULL +/* Execution enviornment configuration bits */ +#define MENVCFG_FIOM BIT(0) +#define MENVCFG_CBIE (3UL << 4) +#define MENVCFG_CBCFE BIT(6) +#define MENVCFG_CBZE BIT(7) +#define MENVCFG_PBMTE BIT(62) +#define MENVCFG_STCE BIT(63) + +/* For RV32 */ +#define MENVCFGH_PBMTE BIT(30) +#define MENVCFGH_STCE BIT(31) + +#define SENVCFG_FIOM MENVCFG_FIOM +#define SENVCFG_CBIE MENVCFG_CBIE +#define SENVCFG_CBCFE MENVCFG_CBCFE +#define SENVCFG_CBZE MENVCFG_CBZE + +#define HENVCFG_FIOM MENVCFG_FIOM +#define HENVCFG_CBIE MENVCFG_CBIE +#define HENVCFG_CBCFE MENVCFG_CBCFE +#define HENVCFG_CBZE MENVCFG_CBZE +#define HENVCFG_PBMTE MENVCFG_PBMTE +#define HENVCFG_STCE MENVCFG_STCE + +/* For RV32 */ +#define HENVCFGH_PBMTE MENVCFGH_PBMTE +#define HENVCFGH_STCE MENVCFGH_STCE + /* Offsets for every pair of control bits per each priv level */ #define XS_OFFSET 0ULL #define U_OFFSET 2ULL diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 18fe17b62f51..ff7e36596447 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -1366,6 +1366,101 @@ static RISCVException write_mtval(CPURISCVState *env, int csrno, return RISCV_EXCP_NONE; } +/* Execution environment configuration setup */ +static RISCVException read_menvcfg(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->menvcfg; + return RISCV_EXCP_NONE; +} + +static RISCVException write_menvcfg(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mask = MENVCFG_FIOM | MENVCFG_CBIE | MENVCFG_CBCFE | MENVCFG_CBZE; + + if (riscv_cpu_mxl(env) == MXL_RV64) { + mask |= MENVCFG_PBMTE | MENVCFG_STCE; + } + env->menvcfg = (env->menvcfg & ~mask) | (val & mask); + + return RISCV_EXCP_NONE; +} + +static RISCVException read_menvcfgh(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->menvcfg >> 32; + return RISCV_EXCP_NONE; +} + +static RISCVException write_menvcfgh(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mask = MENVCFG_PBMTE | MENVCFG_STCE; + uint64_t valh = (uint64_t)val << 32; + + env->menvcfg = (env->menvcfg & ~mask) | (valh & mask); + + return RISCV_EXCP_NONE; +} + +static RISCVException read_senvcfg(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->senvcfg; + return RISCV_EXCP_NONE; +} + +static RISCVException write_senvcfg(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mask = SENVCFG_FIOM | SENVCFG_CBIE | SENVCFG_CBCFE | SENVCFG_CBZE; + + env->senvcfg = (env->senvcfg & ~mask) | (val & mask); + + return RISCV_EXCP_NONE; +} + +static RISCVException read_henvcfg(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->henvcfg; + return RISCV_EXCP_NONE; +} + +static RISCVException write_henvcfg(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mask = HENVCFG_FIOM | HENVCFG_CBIE | HENVCFG_CBCFE | HENVCFG_CBZE; + + if (riscv_cpu_mxl(env) == MXL_RV64) { + mask |= HENVCFG_PBMTE | HENVCFG_STCE; + } + + env->henvcfg = (env->henvcfg & ~mask) | (val & mask); + + return RISCV_EXCP_NONE; +} + +static RISCVException read_henvcfgh(CPURISCVState *env, int csrno, + target_ulong *val) +{ + *val = env->henvcfg >> 32; + return RISCV_EXCP_NONE; +} + +static RISCVException write_henvcfgh(CPURISCVState *env, int csrno, + target_ulong val) +{ + uint64_t mask = HENVCFG_PBMTE | HENVCFG_STCE; + uint64_t valh = (uint64_t)val << 32; + + env->henvcfg = (env->henvcfg & ~mask) | (valh & mask); + + return RISCV_EXCP_NONE; +} + static RISCVException rmw_mip64(CPURISCVState *env, int csrno, uint64_t *ret_val, uint64_t new_val, uint64_t wr_mask) @@ -3069,6 +3164,18 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MVIPH] = { "mviph", aia_any32, read_zero, write_ignore }, [CSR_MIPH] = { "miph", aia_any32, NULL, NULL, rmw_miph }, + /* Execution environment configuration */ + [CSR_MENVCFG] = { "menvcfg", any, read_menvcfg, write_menvcfg, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_MENVCFGH] = { "menvcfgh", any32, read_menvcfgh, write_menvcfgh, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_SENVCFG] = { "senvcfg", smode, read_senvcfg, write_senvcfg, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HENVCFG] = { "henvcfg", hmode, read_henvcfg, write_henvcfg, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + [CSR_HENVCFGH] = { "henvcfgh", hmode32, read_henvcfgh, write_henvcfgh, + .min_priv_ver = PRIV_VERSION_1_12_0 }, + /* Supervisor Trap Setup */ [CSR_SSTATUS] = { "sstatus", smode, read_sstatus, write_sstatus, NULL, read_sstatus_i128 }, diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 9895930b2976..4a50a05937fa 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -220,6 +220,29 @@ static const VMStateDescription vmstate_kvmtimer = { } }; +/* TODO: henvcfg need both hyper_needed & envcfg_needed */ +static bool envcfg_needed(void *opaque) +{ + RISCVCPU *cpu = opaque; + CPURISCVState *env = &cpu->env; + + return (env->priv_ver >= PRIV_VERSION_1_12_0 ? 1 : 0); +} + +static const VMStateDescription vmstate_envcfg = { + .name = "cpu/envcfg", + .version_id = 1, + .minimum_version_id = 1, + .needed = envcfg_needed, + .fields = (VMStateField[]) { + VMSTATE_UINT64(env.menvcfg, RISCVCPU), + VMSTATE_UINTTL(env.senvcfg, RISCVCPU), + VMSTATE_UINT64(env.henvcfg, RISCVCPU), + + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_riscv_cpu = { .name = "cpu", .version_id = 3, @@ -280,6 +303,7 @@ const VMStateDescription vmstate_riscv_cpu = { &vmstate_pointermasking, &vmstate_rv128, &vmstate_kvmtimer, + &vmstate_envcfg, NULL } }; From patchwork Sun Feb 6 09:18:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12736505 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01359C433F5 for ; Sun, 6 Feb 2022 09:56:54 +0000 (UTC) Received: from localhost ([::1]:50442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGeHt-0004Qb-1B for qemu-devel@archiver.kernel.org; Sun, 06 Feb 2022 04:56:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGdhB-0008Bj-LM for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:57 -0500 Received: from [2607:f8b0:4864:20::230] (port=42683 helo=mail-oi1-x230.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGdhA-000158-1e for qemu-devel@nongnu.org; Sun, 06 Feb 2022 04:18:57 -0500 Received: by mail-oi1-x230.google.com with SMTP id v67so13850059oie.9 for ; Sun, 06 Feb 2022 01:18:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DpORpBZuRTgyXLMxgMIyGunVHEl3TZnt8/u2Ndv1j9A=; b=ZnFHX41mZA+eYqy36wCT4ZthuFYEk6lMIkhwNhqkJodbpf6nTab6jQ7VC2XjUBeCjk dmECiAj8kSXdb1tGlZm8XY3x/Fsm1hEwmQUcxyp66AJ6+3HqLUSYltnpuTKn+f+3ZBA1 ru7f7IS4m4xLgj9lHWtGwBwqGXjeHOufWxcDf1R+FxCkGJnwhoWcW7DIniPQSdW8+cTu 80jtUk8aUibrTKbEQ1rec7ndZ366sNnl6PMjy1qq2tVVVkEIHwVHgT+RPVZ0hg2UAWDP eFqhcxV9lmj8Vj3sKAQWH13pm+Zfb+PVjRAdlw93TCj84whkqbsvi0HwkRHoznNXpm3U vS9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DpORpBZuRTgyXLMxgMIyGunVHEl3TZnt8/u2Ndv1j9A=; b=0DLaSTbpy2F8pfJwtCE+tlXPOECPLSq4NSgGzykUmuXVdhfnQmODClUir8KT3pX8J9 Pma/U7/O20rwM9goWOtstu68ewnpzS6p71trO4rUd+XNWL2jCHks5GV/3V14B6nzDZH+ x1/hcrTtYw2iUCWXyyBlTL2S4bmrfY92KXhfVNhwGDLgpdgTy6WcwpZP3Mplnf4s6SU/ ISB8fEGqV71NY1rFWAXsZTy6YcSxgJOJw+YztaHSFEv0+pdd5wUhy+wWxdteLrNEYHQ4 L9s/IxzmvlGhrQzi4hVCuupQ4qIcquwBciQw5GgS/ZbLm7s8lilgSdl7QWS3bqXH3b77 alZA== X-Gm-Message-State: AOAM530L+VfR56VHydNrr18RXL3QKyOvIQ3hV9AkyDu6knCU10vonANP S1Imt53sJsP9wbeVa3C6uFwTnp8WPy6bSb+q X-Google-Smtp-Source: ABdhPJx/sNTvFtfld8wV9p7G2TMyGZmyvfzzT/zBiy9SEuvMF43l0aoa+H5iMEaH6OHRVrBNQsetlw== X-Received: by 2002:aca:a891:: with SMTP id r139mr4959191oie.337.1644139134819; Sun, 06 Feb 2022 01:18:54 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 1sm1596841oab.16.2022.02.06.01.18.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Feb 2022 01:18:54 -0800 (PST) From: Atish Patra To: qemu-devel@nongnu.org Subject: [PATCH v3 6/6] target/riscv: Enable privileged spec version 1.12 Date: Sun, 6 Feb 2022 01:18:35 -0800 Message-Id: <20220206091835.1244296-7-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220206091835.1244296-1-atishp@rivosinc.com> References: <20220206091835.1244296-1-atishp@rivosinc.com> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::230 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=atishp@rivosinc.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Alistair Francis , Bin Meng , Atish Patra , Palmer Dabbelt , qemu-riscv@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Virt machine uses privileged specification version 1.12 now. All other machine continue to use the default one defined for that machine unless changed to 1.12 by the user explicitly. Signed-off-by: Atish Patra Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 8 +++++--- target/riscv/csr.c | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 2668f9c358b2..1c72dfffdc61 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -150,7 +150,7 @@ static void riscv_any_cpu_init(Object *obj) #elif defined(TARGET_RISCV64) set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU); #endif - set_priv_version(env, PRIV_VERSION_1_11_0); + set_priv_version(env, PRIV_VERSION_1_12_0); } #if defined(TARGET_RISCV64) @@ -474,7 +474,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) } if (cpu->cfg.priv_spec) { - if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { + if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { + priv_version = PRIV_VERSION_1_12_0; + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { priv_version = PRIV_VERSION_1_11_0; } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { priv_version = PRIV_VERSION_1_10_0; @@ -489,7 +491,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) if (priv_version) { set_priv_version(env, priv_version); } else if (!env->priv_ver) { - set_priv_version(env, PRIV_VERSION_1_11_0); + set_priv_version(env, PRIV_VERSION_1_12_0); } if (cpu->cfg.mmu) { diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ff7e36596447..1c70c19cf9bd 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -2886,6 +2886,7 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, { /* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ int read_only = get_field(csrno, 0xC00) == 3; + int csr_min_priv = csr_ops[csrno].min_priv_ver; #if !defined(CONFIG_USER_ONLY) int effective_priv = env->priv; @@ -2918,6 +2919,10 @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, return RISCV_EXCP_ILLEGAL_INST; } + if (env->priv_ver < csr_min_priv) { + return RISCV_EXCP_ILLEGAL_INST; + } + return csr_ops[csrno].predicate(env, csrno); }