From patchwork Tue Dec 12 08:58:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 1874983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YUrDaiYt; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=idMG4BQO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqCGC6P8xz20H5 for ; Tue, 12 Dec 2023 19:58:59 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4sZfQA1w8c6nTGOp4VbETxy6bvJsV8fWhefM0Plvuus=; b=YUrDaiYtufEze0 zrzwaQR1etzC1SG37OZl2dOGrMoPrOXQ59ONDcaVuCrgJutA3EUFaAXVM8V+XmBXWLyMAOBj72Zog YvEwO8vQeSyH4UPXcf61J+aOIarykDWFftLmWshj2TrJV5SFCPwQdHExmz3TObnWlC1Yx3lektcBz rBEU+jQMo5jcM3jPSVcxaVypQTosNlSeWNbrr7cbcBPANaLTY83ACftmP9wBReJV2Hy5gxyjR83dc 8eY/W7xLzfT05Q4wC84YW1sJgZ4V//OBiFBjwuHnZEeE+mOi3UebKtd5zZyrMYRHif+sAA66D8qBh pWWsD6q2/Wl21nEy4YBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCybI-00B78J-1i; Tue, 12 Dec 2023 08:58:48 +0000 Received: from mail-oi1-x236.google.com ([2607:f8b0:4864:20::236]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCybE-00B76Z-2h for opensbi@lists.infradead.org; Tue, 12 Dec 2023 08:58:46 +0000 Received: by mail-oi1-x236.google.com with SMTP id 5614622812f47-3b9b90f8708so3547912b6e.2 for ; Tue, 12 Dec 2023 00:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702371522; x=1702976322; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=UINwaXihbsEvKNCn6hzrSA6yk/u3WWwkYYYOmEleX0Y=; b=idMG4BQOd6Xyx4MaxaqMkGaAEdiByQG2uCyP/Qz8yFzorQJ2//Sk6vKtHInbTja7D/ 4uJh+8V728O1u9pwbj6ieWzJ+DToei+92d3CQMF59l50I7CTQTRjC6x6iVymch70oUSB zwkZWGYEvrARhTujQ2EMN1fRw/eHc1LK8ayo9+lM64lXpV/7eDB6PTV7DOw4a8/KdJIv CcT1HqwKaLaBjqpGi8ia31mf7hggqCxCZDJamCw+5sxkwYgxwBwsPNfyDf0dwHRqJdaa oZQiI6H4UOgAhYZZtZ3qiCS+7VMPJUM0WEaK+3Gg9ge+meKYRmi26IfLUPNlP4G5CgGl /GYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702371522; x=1702976322; h=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=UINwaXihbsEvKNCn6hzrSA6yk/u3WWwkYYYOmEleX0Y=; b=tfeVl6zzKIm3DhCl7uqyuTa7ou1oUFHRj34JIpg3SRcN83rmwJ3VXAkBVbyrA7bsPN jR7djHxzm+q05ipkQodeiQrBtbL27i8YqQHpMEg0iFdrNJIO+lVKHlN7HdTeZrMnO8Ep bxFS74N46UN07fctcA67okJaeFFxUKmGQeI9GUgeWyIVBwAeoRXWx/6TEEbP5joKSdKv 2YHjuI+mE229PMJ86Aof16KsdyuVBmtZC/5aNSPH1bEwJHvYY+kj+yGLgbj3AoCPkUrZ VOwXSz21xOou2XbLqp449N287CLv7k07LSfkQyORxHK5GhDpn63JlFQ2WRYDIaNiO1RP FFhA== X-Gm-Message-State: AOJu0Yyrtk247XxT+8HPD8D0q/2GEkSScbdmODiDnuHd+uUnYEtxBtx8 oMVqO2vbzg+10th76j2hxsFAhYXTafBdslgC3bKd7EBMM/pEeDPmWsbXZhdDio+iSodDbNgCytd mcz4bQzT/FZlHNn+McyqiNIm9H6IbVaxIaOQ4NcjK8i9T+/8lzgxAdIoxxyqMFLMH6QziR8lLB9 cOm4611liGDSZug3wNKQ== X-Google-Smtp-Source: AGHT+IGjlPt2UU/5zq0+arZPDXmtiCOfLsoxEQPzbHsFjLQ9wC7U1u1LCdOrtgtS7g9yizEgqFrpPA== X-Received: by 2002:a05:6808:2f10:b0:3b9:de62:2baa with SMTP id gu16-20020a0568082f1000b003b9de622baamr7696179oib.20.1702371522203; Tue, 12 Dec 2023 00:58:42 -0800 (PST) Received: from hsinchu26.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id f26-20020aa79d9a000000b006cb94825843sm7610830pfq.180.2023.12.12.00.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 00:58:41 -0800 (PST) From: Yong-Xuan Wang To: opensbi@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang Subject: [PATCH v3 1/4] lib: sbi: Improve the code of privilege mode and extensions detection Date: Tue, 12 Dec 2023 08:58:32 +0000 Message-Id: <20231212085835.26824-2-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231212085835.26824-1-yongxuan.wang@sifive.com> References: <20231212085835.26824-1-yongxuan.wang@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_005844_872284_DDB13F2A X-CRM114-Status: GOOD ( 10.40 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: We can enhance the code by creating 2 unified interface with macro for privilege mode and extensions detection, which relies on supported privilege modes and CSRs. Signed-off-by: Yong-Xuan Wang Reviewed-by: Anup Patel --- lib/sbi/sbi_hart.c | 88 ++++++++++++++++++++ 1 file changed, 38 ins [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:236 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We can enhance the code by creating 2 unified interface with macro for privilege mode and extensions detection, which relies on supported privilege modes and CSRs. Signed-off-by: Yong-Xuan Wang Reviewed-by: Anup Patel --- lib/sbi/sbi_hart.c | 88 ++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 6acff378..13998f1c 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -807,6 +807,7 @@ static int hart_detect_features(struct sbi_scratch *scratch) sbi_memset(hfeatures->extensions, 0, sizeof(hfeatures->extensions)); hfeatures->pmp_count = 0; hfeatures->mhpm_mask = 0; + hfeatures->priv_version = SBI_HART_PRIV_VER_UNKNOWN; #define __check_hpm_csr(__csr, __mask) \ oldval = csr_read_allowed(__csr, (ulong)&trap); \ @@ -899,67 +900,54 @@ __pmp_skip: #undef __check_csr_2 #undef __check_csr - /* Detect if hart supports Priv v1.10 */ - val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap); - if (!trap.cause) - hfeatures->priv_version = SBI_HART_PRIV_VER_1_10; - /* Detect if hart supports Priv v1.11 */ - val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap); - if (!trap.cause && - (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_10)) - hfeatures->priv_version = SBI_HART_PRIV_VER_1_11; +#define __check_priv(__csr, __base_priv, __priv) \ + val = csr_read_allowed(__csr, (ulong)&trap); \ + if (!trap.cause && (hfeatures->priv_version >= __base_priv)) { \ + hfeatures->priv_version = __priv; \ + } + /* Detect if hart supports Priv v1.10 */ + __check_priv(CSR_MCOUNTEREN, + SBI_HART_PRIV_VER_UNKNOWN, SBI_HART_PRIV_VER_1_10); + /* Detect if hart supports Priv v1.11 */ + __check_priv(CSR_MCOUNTINHIBIT, + SBI_HART_PRIV_VER_1_10, SBI_HART_PRIV_VER_1_11); /* Detect if hart supports Priv v1.12 */ - csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap); - if (!trap.cause && - (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11)) - hfeatures->priv_version = SBI_HART_PRIV_VER_1_12; + __check_priv(CSR_MENVCFG, + SBI_HART_PRIV_VER_1_11, SBI_HART_PRIV_VER_1_12); - /* Counter overflow/filtering is not useful without mcounter/inhibit */ - if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11) { - /* Detect if hart supports sscofpmf */ - csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap); - if (!trap.cause) - __sbi_hart_update_extension(hfeatures, - SBI_HART_EXT_SSCOFPMF, true); +#undef __check_priv_csr + +#define __check_ext_csr(__base_priv, __csr, __ext) \ + if (hfeatures->priv_version >= __base_priv) { \ + csr_read_allowed(__csr, (ulong)&trap); \ + if (!trap.cause) \ + __sbi_hart_update_extension(hfeatures, \ + __ext, true); \ } + /* Counter overflow/filtering is not useful without mcounter/inhibit */ + /* Detect if hart supports sscofpmf */ + __check_ext_csr(SBI_HART_PRIV_VER_1_11, + CSR_SCOUNTOVF, SBI_HART_EXT_SSCOFPMF); /* Detect if hart supports time CSR */ - csr_read_allowed(CSR_TIME, (unsigned long)&trap); - if (!trap.cause) - __sbi_hart_update_extension(hfeatures, - SBI_HART_EXT_ZICNTR, true); - + __check_ext_csr(SBI_HART_PRIV_VER_UNKNOWN, + CSR_TIME, SBI_HART_EXT_ZICNTR); /* Detect if hart has AIA local interrupt CSRs */ - csr_read_allowed(CSR_MTOPI, (unsigned long)&trap); - if (!trap.cause) - __sbi_hart_update_extension(hfeatures, - SBI_HART_EXT_SMAIA, true); - + __check_ext_csr(SBI_HART_PRIV_VER_UNKNOWN, + CSR_MTOPI, SBI_HART_EXT_SMAIA); /* Detect if hart supports stimecmp CSR(Sstc extension) */ - if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { - csr_read_allowed(CSR_STIMECMP, (unsigned long)&trap); - if (!trap.cause) - __sbi_hart_update_extension(hfeatures, - SBI_HART_EXT_SSTC, true); - } - + __check_ext_csr(SBI_HART_PRIV_VER_1_12, + CSR_STIMECMP, SBI_HART_EXT_SSTC); /* Detect if hart supports mstateen CSRs */ - if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { - val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap); - if (!trap.cause) - __sbi_hart_update_extension(hfeatures, - SBI_HART_EXT_SMSTATEEN, true); - } - + __check_ext_csr(SBI_HART_PRIV_VER_1_12, + CSR_MSTATEEN0, SBI_HART_EXT_SMSTATEEN); /* Detect if hart supports smcntrpmf */ - if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { - csr_read_allowed(CSR_MCYCLECFG, (unsigned long)&trap); - if (!trap.cause) - __sbi_hart_update_extension(hfeatures, - SBI_HART_EXT_SMCNTRPMF, true); - } + __check_ext_csr(SBI_HART_PRIV_VER_1_12, + CSR_MCYCLECFG, SBI_HART_EXT_SMCNTRPMF); + +#undef __check_ext_csr /* Let platform populate extensions */ rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr(), From patchwork Tue Dec 12 08:58:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 1874984 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ajUxw7Ny; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=W624mZVe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqCGF4h2Mz20Gd for ; Tue, 12 Dec 2023 19:59:01 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=t/g0uGmhgVv8CfsoQsT60zPU7wo90uTVIBupkchOiTw=; b=ajUxw7NyqzMYjH XR/qg+ON4cEvKvKwh4p7tynzkTJKVP4jlPcqRbNMDDV/oCyhpL3eedHHDhKtRtrjavACLoXFMEilP XdaF+mdrJVSnXqPi7aB3K0LBGUDAe9nkdiaeh8IHUu/X6AJc3yWAfkfXKoKNM/m7Osnl03uiImpVj AqFvNgbUROnwEskUt7MVBl/o0fR9yB0dAlmUCV03aDLro0gnGViPhijr3HazFYG8zF2Rirl/z/Yf2 ob1T0ZkxSz9dJYxPB/yb/lDcDd0k2h8VCqPtd3j7fkoojvXYEY3kHfpNzUTh8TRIUBy/DOpAhQlj4 ulSuzwMWGsGOGAlqOgpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCybK-00B79A-17; Tue, 12 Dec 2023 08:58:50 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCybH-00B76n-0y for opensbi@lists.infradead.org; Tue, 12 Dec 2023 08:58:48 +0000 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6ce9c8c45a7so3325810b3a.0 for ; Tue, 12 Dec 2023 00:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702371524; x=1702976324; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=WASjlF5Lhdm2DLW7wBCIH7POg1R0XVGMxitjP/n3jAg=; b=W624mZVeRY6qAaV+nazm1R+KcOQjRyAoMLiKhRoUxWFJoZxQMBs7kaG74VuSrHdkA+ JKbsKYi3hajz6o6oILT1YJwWhfGSvec9bFVRSuqs1mLiX1pGqFq6u7QmzIbBPHjetAwP 1O+0phSPnl0b4y8bY9HDFjHmbSuqea9uOhZFlZKM/5Nfkb+ivCFKDvWu7JqcAXFspH3V mkOTESxcGiZnd5WyVrXYZSfBaaPkVsRhTBo3piPYBoivWZDQI5VfmLdsECV03dA1ygKJ iI3rxN5jedJr+VbMa2TM7nrFI1CqIYsH6cHkYqnPVVX5Vzn0knT/Q5N/Mydir+X2VnDg dFrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702371524; x=1702976324; h=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=WASjlF5Lhdm2DLW7wBCIH7POg1R0XVGMxitjP/n3jAg=; b=cE9iG9QrMWCDxvBnMTU1cE27RBnHeEvhVynyp+HAiHzjZPu/MEM+hDRswYLAPjm4bz KPUDXyNvXLE+mh+BYZYm0vUSSClo9HvXHapJaBEmnUx1+1l9x03suaGMZml4s34GMxn7 XXJrV509Frct8MXNszYQrTC5/TPrDkvB4S4ZksgiZy6dECIVgDFkj48gaSBLoUON44xJ nU1Pbs/IiVewmWnwfgf2v7lDTw6Ws6Ywa+8fPu/WePnUSnx9yLGy5BqI4RtCSj7ZAKPZ 24oS5UypHRMK//7k/Of7LFmtPK358NCJDJLB4pZSERemC4PCYpHkD5axkkqYT8hFtzrn jQLA== X-Gm-Message-State: AOJu0Ywhl3pGOPLBgt9+R24v9UDwfEZiTvA3NLwfxz8zCAQQ2aoWrWmT pZM9ck99X0/DveG/d/iikm+MgmS2C5W+Cv7+tYCUJpyX6SNUX3qncOUeKrg0yo0X2o/Ty4O2Y0n xOqK1uyCuUc03iJOxbyOjAcB9814vs++RpeWe3+kVvMFM/z76wRuNX1pq+wkf1pK3BttJlo2qt6 ozDNGMcrrdcmPh/7OV/A== X-Google-Smtp-Source: AGHT+IGp3qtW7LuQJk4MleQJ+azC0L+yW73QX3zBQfj0WF1IwkuCwtM2+cvU8wuaEu9wLRyFOZfRcg== X-Received: by 2002:a05:6a00:aca:b0:6ce:7ddb:cfa9 with SMTP id c10-20020a056a000aca00b006ce7ddbcfa9mr3128578pfl.48.1702371524031; Tue, 12 Dec 2023 00:58:44 -0800 (PST) Received: from hsinchu26.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id f26-20020aa79d9a000000b006cb94825843sm7610830pfq.180.2023.12.12.00.58.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 00:58:43 -0800 (PST) From: Yong-Xuan Wang To: opensbi@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang Subject: [PATCH v3 2/4] lib: sbi: Refactor the code for enable extensions in menvfg CSR Date: Tue, 12 Dec 2023 08:58:33 +0000 Message-Id: <20231212085835.26824-3-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231212085835.26824-1-yongxuan.wang@sifive.com> References: <20231212085835.26824-1-yongxuan.wang@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_005847_340093_D390E959 X-CRM114-Status: GOOD ( 10.14 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Use 1 variable to store the value of menvcfg. Signed-off-by: Yong-Xuan Wang Reviewed-by: Anup Patel --- include/sbi/riscv_encoding.h | 5 ----- lib/sbi/sbi_hart.c | 15 ++++++--------- 2 files change [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42c listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Use 1 variable to store the value of menvcfg. Signed-off-by: Yong-Xuan Wang Reviewed-by: Anup Patel --- include/sbi/riscv_encoding.h | 5 ----- lib/sbi/sbi_hart.c | 15 ++++++--------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 0996d649..f20df761 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -207,13 +207,8 @@ #define MHPMEVENT_SSCOF_MASK _ULL(0xFFFF000000000000) -#if __riscv_xlen > 32 #define ENVCFG_STCE (_ULL(1) << 63) #define ENVCFG_PBMTE (_ULL(1) << 62) -#else -#define ENVCFGH_STCE (_UL(1) << 31) -#define ENVCFGH_PBMTE (_UL(1) << 30) -#endif #define ENVCFG_CBZE (_UL(1) << 7) #define ENVCFG_CBCFE (_UL(1) << 6) #define ENVCFG_CBIE_SHIFT 4 diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 13998f1c..5734c09d 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -108,6 +108,9 @@ static void mstatus_init(struct sbi_scratch *scratch) if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) { menvcfg_val = csr_read(CSR_MENVCFG); +#if __riscv_xlen == 32 + menvcfg_val |= ((uint64_t)csr_read(CSR_MENVCFGH)) << 32; +#endif /* * Set menvcfg.CBZE == 1 @@ -139,9 +142,7 @@ static void mstatus_init(struct sbi_scratch *scratch) * If Svpbmt extension is not available then menvcfg.PBMTE * will be read-only zero. */ -#if __riscv_xlen > 32 menvcfg_val |= ENVCFG_PBMTE; -#endif /* * The spec doesn't explicitly describe the reset value of menvcfg. @@ -149,17 +150,13 @@ static void mstatus_init(struct sbi_scratch *scratch) * hardware. */ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSTC)) { -#if __riscv_xlen == 32 - unsigned long menvcfgh_val; - menvcfgh_val = csr_read(CSR_MENVCFGH); - menvcfgh_val |= ENVCFGH_STCE; - csr_write(CSR_MENVCFGH, menvcfgh_val); -#else menvcfg_val |= ENVCFG_STCE; -#endif } csr_write(CSR_MENVCFG, menvcfg_val); +#if __riscv_xlen == 32 + csr_write(CSR_MENVCFGH, menvcfg_val >> 32); +#endif /* Enable S-mode access to seed CSR */ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZKR)) { From patchwork Tue Dec 12 08:58:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 1874985 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Kx4hAYN/; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=XwTueei0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqCGH4849z20Gd for ; Tue, 12 Dec 2023 19:59:03 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zQYb9JLv/phwe6TTVaONp+o7A/v1Sa3LZac9MH7MWQo=; b=Kx4hAYN/w0tHCI blabLb3LAaRuXGYCpAmsEt0JfjGe2sTkay8D6Gx13Qyyd2RrjadQnDb01sTr4NwWD2ia6x7mUQff2 3lX/KKGJcto6Yfk1QttB05GCdZVVwRx1/v3fy7WarB2DecAUvcreFmHPTk5GYItIQtN0mYKHoa10h k9S2rZh1NsM7xdvRP6F6kjsXKyQQFLdioeVH3bnxt/QMxBQcji7U3FaUZ3pSNcZyxHZp9TphbLIkS HudzRyxrqub+HT/WVMqxlX0I1bcxCiX87APCDMkJ5D+YgZ1ApWj2wgvkyJ1H8Kq7aV8bLeJoU13bh YhfqemVROgcSLOFzbVSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCybL-00B79h-2n; Tue, 12 Dec 2023 08:58:51 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCybI-00B77q-2H for opensbi@lists.infradead.org; Tue, 12 Dec 2023 08:58:50 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6cda22140f2so4699141b3a.1 for ; Tue, 12 Dec 2023 00:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702371526; x=1702976326; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=yLEPQd2/R0gUFXId2N/QMo/zGmHqCSebGyr9d4BpL+E=; b=XwTueei0hn7eeERYUYO/i3xey1vrScQX4suHkFcM1GxuVif4h7roSRIRKreJA3T5jj 7oYA+wKYX0l8zQtIn0ZHUTkjas6OD5DtFJU5jVxUFkKsdBO7AR7ozR1EXYuNXlXgDtuo FCwDkrbwVfF3ZXaO3uVgjZzIdibojCY4qo3lnmu3WlVvk0cukvUIbUYYJV1VFMn84MM3 SP8RNPoVgZj5WTbWzNbmrBUY6pIm5uD39i6OETpMeZ4E09Pqf8o7cpzDON6/CaWNbPNT WOe45eVNt2poooX6RsUHEdVuNfrNONzLcKOmZA8GrAEiNnf5QU1E33RBTj5vZQZoZyor 7r3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702371526; x=1702976326; h=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=yLEPQd2/R0gUFXId2N/QMo/zGmHqCSebGyr9d4BpL+E=; b=A6yh1IVmPoQsyG2/r6+Hgs+com699/duU+atY3AY6iPDHNwa24aCraY3RJyLDqdzyg pjxiRiPn5sQtRwBHSCj7fnBI72XNGhqpQuDIvL3VewyepiFODogPytFPDmZ69HqYQtwJ Hi0+k64buVAz633Soi82UOrz0FGc/SQN/XE1KwNAbr895O/ILiykjJ8Kefbo5/nKh9eT qgE9WlcP/5iNV8FNvbIxN42aJ1w8gnF/Bql43Ftea85A10hdIQhACezZtWVXOhG/8JpG TU3tXjwxxKsZobVXovMvGWhknV3NRqxE4l+2lJBAkOYusTW9+W6WIU0N7qlnTar9b31p SeYA== X-Gm-Message-State: AOJu0Yx3wKFDgMTRBamQFXouk+n5I0jN9AOwAMvTATB8yYWF8wRKkTaX r8uCB/038/YYCfaFZtIXo0j4ajT2YRDPANF/R97yvjZTLPSt9kkEZoQZc8jBCR0UJF1hgsn32Nz ynRJK/s1+0Rj6i2QmAXF4p7BPKLxs5szUAJn9ZIkYVIDP/owS8Mz0xHOXWc/o2Res3xiTpnfdt2 s/X9QR+FAALqv6QUM8eA== X-Google-Smtp-Source: AGHT+IELTVSXD0hZ+OPvDZrNkPi9rWhpMGouFtV8/TiLfI3i7eklLITFaFVlU6+lCpAtYJWqJdHNcQ== X-Received: by 2002:a05:6a20:6a03:b0:18b:d2f5:122f with SMTP id p3-20020a056a206a0300b0018bd2f5122fmr7330778pzk.26.1702371526362; Tue, 12 Dec 2023 00:58:46 -0800 (PST) Received: from hsinchu26.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id f26-20020aa79d9a000000b006cb94825843sm7610830pfq.180.2023.12.12.00.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 00:58:45 -0800 (PST) From: Yong-Xuan Wang To: opensbi@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang Subject: [PATCH v3 3/4] lib: sbi: Using one array to define the name of extensions Date: Tue, 12 Dec 2023 08:58:34 +0000 Message-Id: <20231212085835.26824-4-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231212085835.26824-1-yongxuan.wang@sifive.com> References: <20231212085835.26824-1-yongxuan.wang@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_005848_780881_2B68E52F X-CRM114-Status: GOOD ( 13.05 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Define an array sbi_hart_ext to map extension ID and name , and use it for ISA parsing and printing out the supported extensions. Signed-off-by: Yong-Xuan Wang --- include/sbi/sbi_hart.h | 7 ++++ lib/sbi/sbi_hart.c | 68 +++++++++++ lib/utils/fdt/fdt_helper.c | 6 ++-- 3 files [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:436 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Define an array sbi_hart_ext to map extension ID and name , and use it for ISA parsing and printing out the supported extensions. Signed-off-by: Yong-Xuan Wang Reviewed-by: Anup Patel --- include/sbi/sbi_hart.h | 7 ++++ lib/sbi/sbi_hart.c | 68 +++++++++++--------------------------- lib/utils/fdt/fdt_helper.c | 6 ++-- 3 files changed, 31 insertions(+), 50 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 0aefc2be..77138232 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -52,6 +52,13 @@ enum sbi_hart_extensions { SBI_HART_EXT_MAX, }; +struct sbi_hart_ext_data { + const unsigned int id; + const char *name; +}; + +extern const struct sbi_hart_ext_data sbi_hart_ext[]; + /* * Smepmp enforces access boundaries between M-mode and * S/U-mode. When it is enabled, the PMPs are programmed diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 5734c09d..06b5f87e 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -659,48 +659,24 @@ bool sbi_hart_has_extension(struct sbi_scratch *scratch, return false; } -static inline char *sbi_hart_extension_id2string(int ext) -{ - char *estr = NULL; - - switch (ext) { - case SBI_HART_EXT_SMAIA: - estr = "smaia"; - break; - case SBI_HART_EXT_SMSTATEEN: - estr = "smstateen"; - break; - case SBI_HART_EXT_SSCOFPMF: - estr = "sscofpmf"; - break; - case SBI_HART_EXT_SSTC: - estr = "sstc"; - break; - case SBI_HART_EXT_ZICNTR: - estr = "zicntr"; - break; - case SBI_HART_EXT_ZIHPM: - estr = "zihpm"; - break; - case SBI_HART_EXT_ZKR: - estr = "zkr"; - break; - case SBI_HART_EXT_SMEPMP: - estr = "smepmp"; - break; - case SBI_HART_EXT_SMCNTRPMF: - estr = "smcntrpmf"; - break; - case SBI_HART_EXT_XANDESPMU: - estr = "xandespmu"; - break; - default: - break; - } - - return estr; +#define __SBI_HART_EXT_DATA(_name, _id) { \ + .name = #_name, \ + .id = _id, \ } +const struct sbi_hart_ext_data sbi_hart_ext[] = { + __SBI_HART_EXT_DATA(smaia, SBI_HART_EXT_SMAIA), + __SBI_HART_EXT_DATA(smepmp, SBI_HART_EXT_SMEPMP), + __SBI_HART_EXT_DATA(smstateen, SBI_HART_EXT_SMSTATEEN), + __SBI_HART_EXT_DATA(sscofpmf, SBI_HART_EXT_SSCOFPMF), + __SBI_HART_EXT_DATA(sstc, SBI_HART_EXT_SSTC), + __SBI_HART_EXT_DATA(zicntr, SBI_HART_EXT_ZICNTR), + __SBI_HART_EXT_DATA(zihpm, SBI_HART_EXT_ZIHPM), + __SBI_HART_EXT_DATA(zkr, SBI_HART_EXT_ZKR), + __SBI_HART_EXT_DATA(smcntrpmf, SBI_HART_EXT_SMCNTRPMF), + __SBI_HART_EXT_DATA(xandespmu, SBI_HART_EXT_XANDESPMU), +}; + /** * Get the hart extensions in string format * @@ -716,20 +692,16 @@ void sbi_hart_get_extensions_str(struct sbi_scratch *scratch, struct sbi_hart_features *hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset); int offset = 0, ext = 0; - char *temp; if (!extensions_str || nestr <= 0) return; sbi_memset(extensions_str, 0, nestr); for_each_set_bit(ext, hfeatures->extensions, SBI_HART_EXT_MAX) { - temp = sbi_hart_extension_id2string(ext); - if (temp) { - sbi_snprintf(extensions_str + offset, - nestr - offset, - "%s,", temp); - offset = offset + sbi_strlen(temp) + 1; - } + sbi_snprintf(extensions_str + offset, + nestr - offset, + "%s,", sbi_hart_ext[ext].name); + offset = offset + sbi_strlen(sbi_hart_ext[ext].name) + 1; } if (offset) diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index 78c1f380..4ed6bbc1 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -401,8 +401,10 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions) continue; \ } - set_multi_letter_ext("smepmp", SBI_HART_EXT_SMEPMP); - set_multi_letter_ext("zkr", SBI_HART_EXT_ZKR); + for (j = 0; j < SBI_HART_EXT_MAX; j++) { + set_multi_letter_ext(sbi_hart_ext[j].name, + sbi_hart_ext[j].id); + } #undef set_multi_letter_ext } From patchwork Tue Dec 12 08:58:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong-Xuan Wang X-Patchwork-Id: 1874986 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lE7gJUtH; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=O6Iy35mW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SqCGK1FZSz20Gd for ; Tue, 12 Dec 2023 19:59:05 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kk+3xQ068APfL+XmFVnkIxiSLxJxwAQEs9j2KrjTM2o=; b=lE7gJUtHrFcm2m dyhiDSZmghEoUhyTuxyJYqxfzTmTfVDP/AzpIdGLbX2q/K4Y0g5aTbzmfKeQG42GZJfjmWm/LJnLv LcQAB/+EdfTpwgbO0aRZNZaWQvS4pSL3nCxqlQypmLLYvpeCoGhlatxiVmNVuYdB3Ft+9HXdd+slf l+FvTKgQuoOy+YSDUAhWtpzho1BryHrcUZCZZ2RRlVvyZVk03f24BtUqqrY7DAflHIbr747CUZZl3 56bLlQWd9MJP/46sq3hRZHyqCIHpTx7kq12r8f7Rf6V3rJ8Gw8NX+KKYtj9S9MPtZ+Z1KpsflqxRs uPCZkyaj9svbe9cmVJnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rCybN-00B7AS-1K; Tue, 12 Dec 2023 08:58:53 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rCybK-00B78v-33 for opensbi@lists.infradead.org; Tue, 12 Dec 2023 08:58:52 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5910b21896eso888258eaf.0 for ; Tue, 12 Dec 2023 00:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1702371529; x=1702976329; darn=lists.infradead.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=sJpy273mh1OAaI6RTtLrR9ozU+00XiTIc069yFvYgK0=; b=O6Iy35mW+fGwwY2/f+1lgs0sHo+OwSoH57f33n+d1vk6PYn3pAWZgL92pfXDwHt20T Lpem257k1ib9PXdheboA7vGWNa+nh7Bd+M6sP2ezOiXRV9T/uDxXURSeBVLOdqp2TNm2 5T9ReJfoaECUhPIZDcwbhHtqm0KCM7slglqC7IdcltPFskvTaWna6jcQPifB9zltLwQO kvwZOG6CHTH7QSNNRARIQU9LCq9TkrhJkHMKOuSMM8WM9MYJopBA6/pRrUjJW8ah722r Yxz+wOI/p5XzwqhBiGCzvLcv8xBU2+DzdbYYje+ItyHE0+XUkcPJhFvgw9+AZ9ggxHKt utQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702371529; x=1702976329; h=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=sJpy273mh1OAaI6RTtLrR9ozU+00XiTIc069yFvYgK0=; b=szF0aUJfR7FndSyLdWcQQzWJJItrnwARAau2VJ/Mbfc3nE1QWPYd3TC16QkVlKvmSN aDt2fYlWDfaCAPz0SwyZKiN9vV18mF/2YRwhtd3kDCXLpw7+wm6JlcnT15yElMvAAt0G yVf8W9di/RSM+eBaNfhhKfsVvAUj6AjXXtobaSzRAub9m3vGoST7kS/jEfTLNI0CmAjQ 2RwJ1tsrdMPCXA11TpXlQ0K9/rlzRmQHQSa8oetFg6ljm1wDyBAeMmcEJRpKssEyNBf5 eY8f9Y1JmTwrWLQVjzaKOF4SkVJpVkFF6/6p6dJhIP0ZOqIuaqtXqk/sZOJL0NhH6bLl e/OQ== X-Gm-Message-State: AOJu0Ywl5fzzgyu9BNfz81DblkgUmjcAWrLN3n54wt8l66XfHLVxg9gv dW5sONJCdr4rvWAwJdh41LVLd6IhszsrixykCUCBzt3HSpB549qLqIzuli9P7ptW8UoIinBmPRH CIfztbUU9g1RK1Dwafz77a8MnmMYJpg3PMW8dNp1HeGIBHh5cOPdOSQB+3NWJglFLBNuGBWX0+I V+Nf6QEgsFOOEi4cftTw== X-Google-Smtp-Source: AGHT+IH9S8BF1vOj2dE9MXNC+Acpn2xqrqt2NCJ2aDkj06x3NWiduTuR2lu+XX60TBZM8d0vejjnrQ== X-Received: by 2002:a05:6358:3a0f:b0:168:dd37:172d with SMTP id g15-20020a0563583a0f00b00168dd37172dmr3460402rwe.20.1702371527878; Tue, 12 Dec 2023 00:58:47 -0800 (PST) Received: from hsinchu26.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id f26-20020aa79d9a000000b006cb94825843sm7610830pfq.180.2023.12.12.00.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 00:58:47 -0800 (PST) From: Yong-Xuan Wang To: opensbi@lists.infradead.org Cc: greentime.hu@sifive.com, vincent.chen@sifive.com, Yong-Xuan Wang Subject: [PATCH v3 4/4] lib: sbi: Detect extensions from the ISA string in DT Date: Tue, 12 Dec 2023 08:58:35 +0000 Message-Id: <20231212085835.26824-5-yongxuan.wang@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231212085835.26824-1-yongxuan.wang@sifive.com> References: <20231212085835.26824-1-yongxuan.wang@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_005850_984713_32297A02 X-CRM114-Status: GOOD ( 12.68 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Enable access to some extensions through menvcfg and show them in "Boot HART ISA Extensions" if they are present in the device tree. Signed-off-by: Yong-Xuan Wang --- include/sbi/sbi_hart.h | 6 +++++ lib/sbi/sbi_hart.c | 51 +++++++++++++ 2 files changed, 22 insertions(+), 35 d [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:c36 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Enable access to some extensions through menvcfg and show them in "Boot HART ISA Extensions" if they are present in the device tree. Signed-off-by: Yong-Xuan Wang Reviewed-by: Anup Patel --- include/sbi/sbi_hart.h | 6 +++++ lib/sbi/sbi_hart.c | 51 +++++++++++++----------------------------- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 77138232..47be251d 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -47,6 +47,12 @@ enum sbi_hart_extensions { SBI_HART_EXT_SMCNTRPMF, /** Hart has Xandespmu extension */ SBI_HART_EXT_XANDESPMU, + /** Hart has Zicboz extension */ + SBI_HART_EXT_ZICBOZ, + /** Hart has Zicbom extension */ + SBI_HART_EXT_ZICBOM, + /** Hart has Svpbmt extension */ + SBI_HART_EXT_SVPBMT, /** Maximum index of Hart extension */ SBI_HART_EXT_MAX, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 06b5f87e..6a9f6a71 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -112,46 +112,24 @@ static void mstatus_init(struct sbi_scratch *scratch) menvcfg_val |= ((uint64_t)csr_read(CSR_MENVCFGH)) << 32; #endif - /* - * Set menvcfg.CBZE == 1 - * - * If Zicboz extension is not available then writes to - * menvcfg.CBZE will be ignored because it is a WARL field. - */ - menvcfg_val |= ENVCFG_CBZE; +#define __set_menvcfg_ext(__ext, __bit) \ + if (sbi_hart_has_extension(scratch, __ext)) { \ + menvcfg_val |= __bit; \ + } /* - * Set menvcfg.CBCFE == 1 - * - * If Zicbom extension is not available then writes to - * menvcfg.CBCFE will be ignored because it is a WARL field. + * Enable access to extensions if they are present in the + * hardware or in the device tree. */ - menvcfg_val |= ENVCFG_CBCFE; - /* - * Set menvcfg.CBIE == 3 - * - * If Zicbom extension is not available then writes to - * menvcfg.CBIE will be ignored because it is a WARL field. - */ - menvcfg_val |= ENVCFG_CBIE_INV << ENVCFG_CBIE_SHIFT; + __set_menvcfg_ext(SBI_HART_EXT_ZICBOZ, ENVCFG_CBZE); + __set_menvcfg_ext(SBI_HART_EXT_ZICBOM, ENVCFG_CBCFE); + __set_menvcfg_ext(SBI_HART_EXT_ZICBOM, + ENVCFG_CBIE_INV << ENVCFG_CBIE_SHIFT); + __set_menvcfg_ext(SBI_HART_EXT_SVPBMT, ENVCFG_PBMTE); + __set_menvcfg_ext(SBI_HART_EXT_SSTC, ENVCFG_STCE); - /* - * Set menvcfg.PBMTE == 1 for RV64 or RV128 - * - * If Svpbmt extension is not available then menvcfg.PBMTE - * will be read-only zero. - */ - menvcfg_val |= ENVCFG_PBMTE; - - /* - * The spec doesn't explicitly describe the reset value of menvcfg. - * Enable access to stimecmp if sstc extension is present in the - * hardware. - */ - if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSTC)) { - menvcfg_val |= ENVCFG_STCE; - } +#undef __set_menvcfg_ext csr_write(CSR_MENVCFG, menvcfg_val); #if __riscv_xlen == 32 @@ -675,6 +653,9 @@ const struct sbi_hart_ext_data sbi_hart_ext[] = { __SBI_HART_EXT_DATA(zkr, SBI_HART_EXT_ZKR), __SBI_HART_EXT_DATA(smcntrpmf, SBI_HART_EXT_SMCNTRPMF), __SBI_HART_EXT_DATA(xandespmu, SBI_HART_EXT_XANDESPMU), + __SBI_HART_EXT_DATA(zicboz, SBI_HART_EXT_ZICBOZ), + __SBI_HART_EXT_DATA(zicbom, SBI_HART_EXT_ZICBOM), + __SBI_HART_EXT_DATA(svpbmt, SBI_HART_EXT_SVPBMT), }; /**