From patchwork Fri Apr 29 15:51:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=LlT2LYWn; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=iwALoUrI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcSm6L7Dz9sBF for ; Sat, 30 Apr 2022 01:52:40 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=RW8oSDz8PSCvoETxEXv2Gd/jsDmzFVcNyLzmLCxuHBM=; b=LlT2LYWnmen3Lc Qr9djxxSXFI5IhTS6/AmpHzBwWjBi6N9Wh0njW1TmXjSfE623vzYdHwUFdbVCPx+LpZjL/10re00e P344ta5pzNMYav/ceoqQIWSELdHQaO91pKl6CCggg/CZz3fnFNqqNuF057zk/O02PFUg6kIft/FfS AKuCZTlhMQQ3bEvnslzDqRBb1yk2atbjtZn1aBw5xKVgufNSmetJKTcFTk2laQetM6A0efvTAI16j rNIMg1fLm4VUpqCmxysuRiLoSKFTV49GLtiHCddiigWCZTJwFv+KLz8cznryAMXSwuqzke0Zio4n8 s2Gurxkd2IlSitH1sNfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSut-00BphD-P7; Fri, 29 Apr 2022 15:52:23 +0000 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSur-00Bpfu-6q for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:22 +0000 Received: by mail-pg1-x530.google.com with SMTP id 15so6838973pgf.4 for ; Fri, 29 Apr 2022 08:52:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i1jtef7VfSZalDYmnGrcqvq+ZdSOTZUc8Sfign3+uzk=; b=iwALoUrIhmIySYq2ilg4CpkG3ctzVRjUqd8ENXf+i+PPNLjAwx2LFj2uFVwtRe0+2d xeQ0WGPILUW7wJiFa2ePH6iuHtw9CTgSSeLNL+3CMcIzCeHAT0AnD/ExRo4akDcFPMmM 5tBP6z80qCNCeUmfeh+laMpGuc2I4alHIq9QUrA+N+1LZDA5+Y6pS27p4mlJtM/U7tPD EaVzcGrdpsu5NGEAr77efOAyNw830yBXXKB69u7Ayu9FHhTAVPmhORZTWpIclRfpdXMI ixOQ3K61YGV+HjKyiXNO39n+VMrF5vHaKfxwgARsz9zptnvvfGQu6f0Fqmwo5UpfQAmu pvHw== 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=i1jtef7VfSZalDYmnGrcqvq+ZdSOTZUc8Sfign3+uzk=; b=T1+ZXi10B6dGu519kBwFKyq4FxEahNZ929ggxCk8O5f8ObkDFJ8NuQOU3QQBNxIwwJ JN52pT/hgIxllVlnoC4xoiXqAiujasIa0v5ktVAhCA9Iezr0FVDKorPqDgWDHecI/eOv pK4Y6/bdP2MbH8dpcJS03ck3J/5Qq33oOi5NCxLTi76q4mAM/zdYVbRniTXwZCuprnX2 8g+DPvpgu/A/nyFJerfOtue9HnRl+Nbh7V6cMsxnlJ7T7ae0REig9E3z8GcRWFv0fQux KGcL/mfRI2CkIM+tJE9FUWL++Zsgm7UGoZBTV4RKbpmkUzKnwSJ/9yMo71UqWrAQ64Yv RwrA== X-Gm-Message-State: AOAM530Ex4QqlzNknlYQVu6Q+g5NNnKpeYWZnwRwQPO/uDhVy5HGmsaG st7gmV8dbC5mMZO5GFz1OgKltVMKyLi68w== X-Google-Smtp-Source: ABdhPJxhVCnDEC7JlI5S9aeLFo9cKxkzM2f3RSvN0EUG9Tt/W7CsDVqz2CkPO8UhHHvjAZ6FYSTvwQ== X-Received: by 2002:a63:5217:0:b0:3c1:5bb1:1f1 with SMTP id g23-20020a635217000000b003c15bb101f1mr9363pgb.543.1651247538816; Fri, 29 Apr 2022 08:52:18 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:18 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 01/11] lib: sbi: Detect and print privileged spec version Date: Fri, 29 Apr 2022 21:21:41 +0530 Message-Id: <20220429155151.314788-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085221_292122_9C85FF77 X-CRM114-Status: GOOD ( 15.15 ) 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: It is possible to guess privileged spec versions based on the CSRs that where introduced in different privleged spec versions. In future, if we are not able guess privileged spec version then we can h [...] 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:530 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org It is possible to guess privileged spec versions based on the CSRs that where introduced in different privleged spec versions. In future, if we are not able guess privileged spec version then we can have platform provide it. We add privileged spec version as per-hart feature and try to guess it based on presense of mcounteren, mcountinhibit, and menvcfg CSRs. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_hart.h | 15 ++++++++++++ lib/sbi/sbi_hart.c | 52 +++++++++++++++++++++++++++++++++++++----- lib/sbi/sbi_init.c | 2 ++ 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 1d09374..3c37933 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -12,6 +12,18 @@ #include +/** Possible privileged specification versions of a hart */ +enum sbi_hart_priv_versions { + /** Unknown privileged specification */ + SBI_HART_PRIV_VER_UNKNOWN = 0, + /** Privileged specification v1.10 */ + SBI_HART_PRIV_VER_1_10 = 1, + /** Privileged specification v1.11 */ + SBI_HART_PRIV_VER_1_11 = 2, + /** Privileged specification v1.12 */ + SBI_HART_PRIV_VER_1_12 = 3, +}; + /** Possible feature flags of a hart */ enum sbi_hart_features { /** Hart has S-mode counter enable */ @@ -56,6 +68,9 @@ unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch); unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch); unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch); int sbi_hart_pmp_configure(struct sbi_scratch *scratch); +int sbi_hart_priv_version(struct sbi_scratch *scratch); +void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, + char *version_str, int nvstr); bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature); void sbi_hart_get_features_str(struct sbi_scratch *scratch, char *features_str, int nfstr); diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 229c14a..ed4e631 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -28,6 +28,7 @@ extern void __sbi_expected_trap_hext(void); void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap; struct hart_features { + int priv_version; unsigned long features; unsigned int pmp_count; unsigned int pmp_addr_bits; @@ -334,6 +335,39 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch) return 0; } +int sbi_hart_priv_version(struct sbi_scratch *scratch) +{ + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); + + return hfeatures->priv_version; +} + +void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, + char *version_str, int nvstr) +{ + char *temp; + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); + + switch (hfeatures->priv_version) { + case SBI_HART_PRIV_VER_1_10: + temp = "v1.10"; + break; + case SBI_HART_PRIV_VER_1_11: + temp = "v1.11"; + break; + case SBI_HART_PRIV_VER_1_12: + temp = "v1.12"; + break; + default: + temp = "unknown"; + break; + } + + sbi_snprintf(version_str, nvstr, "%s", temp); +} + /** * Check whether a particular hart feature is available * @@ -583,6 +617,7 @@ __mhpm_skip: /* Detect if hart supports SCOUNTEREN feature */ val = csr_read_allowed(CSR_SCOUNTEREN, (unsigned long)&trap); if (!trap.cause) { + hfeatures->priv_version = SBI_HART_PRIV_VER_1_10; csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap, val); if (!trap.cause) hfeatures->features |= SBI_HART_HAS_SCOUNTEREN; @@ -591,6 +626,7 @@ __mhpm_skip: /* Detect if hart supports MCOUNTEREN feature */ val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap); if (!trap.cause) { + hfeatures->priv_version = SBI_HART_PRIV_VER_1_10; csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap, val); if (!trap.cause) hfeatures->features |= SBI_HART_HAS_MCOUNTEREN; @@ -600,8 +636,17 @@ __mhpm_skip: val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap); if (!trap.cause) { csr_write_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap, val); - if (!trap.cause) + if (!trap.cause) { + hfeatures->priv_version = SBI_HART_PRIV_VER_1_11; hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT; + } + } + + /* Detect if hart has menvcfg CSR */ + csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap); + if (!trap.cause) { + hfeatures->priv_version = SBI_HART_PRIV_VER_1_12; + hfeatures->features |= SBI_HART_HAS_MENVCFG; } /* Counter overflow/filtering is not useful without mcounter/inhibit */ @@ -625,11 +670,6 @@ __mhpm_skip: hfeatures->features |= SBI_HART_HAS_AIA; __aia_skip: - /* Detect if hart has menvcfg CSR */ - csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap); - if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_MENVCFG; - /** * Detect if hart supports stimecmp CSR(Sstc extension) and menvcfg is * implemented. diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 2b9e5ae..660b11f 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -139,6 +139,8 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid) /* Boot HART details */ sbi_printf("Boot HART ID : %u\n", hartid); sbi_printf("Boot HART Domain : %s\n", dom->name); + sbi_hart_get_priv_version_str(scratch, str, sizeof(str)); + sbi_printf("Boot HART Priv Version : %s\n", str); misa_string(xlen, str, sizeof(str)); sbi_printf("Boot HART ISA : %s\n", str); sbi_hart_get_features_str(scratch, str, sizeof(str)); From patchwork Fri Apr 29 15:51:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624430 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=evAGV/xz; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=baqZHUK/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcSm6Sb4z9sFr for ; Sat, 30 Apr 2022 01:52:40 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=tp2Jakp0YXJ6KZQTu3BodRUg1kodnOuW+9jEq83s+/Q=; b=evAGV/xzqqoA95 L5Nmvsahzw+np3hsl0qk24IVVDc8woSuwhv6EKB/3s8fuoapsdQSGqEsgVcTy+2lxqmIKNk1VJlKR 92Dguhnqr+yuOnn2AGxZtrLOp+st5dYQKM+P6kq6Fy0m7xeAMhAzszPqDMCXudJ+gB20Jw9mHZU+9 Gw2zgFNeX6ZLbsqEjNJsk/cUBWPWCsC5Skd8vdELZS53i5RVn/eSCpctJ1lQ84PjCMAi7CxePZNiR szGtbRo4l2uXyhLYfdjVokk/SZkwLUpAXuTceMPfHnzy1bvQWYZDG037ngMTLarS3oVLO+lq7joTt uej2l0NiFic/A/VRNiww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSuv-00Bphn-DV; Fri, 29 Apr 2022 15:52:25 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSus-00BpgZ-2N for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:23 +0000 Received: by mail-pj1-x1029.google.com with SMTP id e24so7481226pjt.2 for ; Fri, 29 Apr 2022 08:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZEd3/5dojq+4rNkH6WEVmO9UT4o0wLjZDBij6kUDe3Q=; b=baqZHUK/ttwYHSAbuq/EHTWnx7gGMmEsi5fmTdFbNQFxVdVZXReduAKTMCvTxpiCts 18OLo5QlS3nJnvRfMHSN8L0JXMrDvkL2yFZXNSULKKkti6GM1rjmpprZwrEugxDJ2ulo 1Sxru19iTn+RKtVNYuxk5Lt5objbyEtqYK6pgVenUS5B+1gvGlAdQ3dZcGMWoxxNHBRA i5/j8OKApgnxGaV4gpTEJZDkb+850keSchOZcZsZ9f6LMvmLEOG/B+4h1+f0jDR1kL3O E3KKhxGk0dr9qtlMWKnrireFyuGaeVxs0YtcqEUitQ+qMNvoFzpfFRkKVhGv8/Jccog1 s2LQ== 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=ZEd3/5dojq+4rNkH6WEVmO9UT4o0wLjZDBij6kUDe3Q=; b=Fwx2YY4FqAjEh89NYfc6baW/jGoi3z32bi1u8YpOk7WSIfh7eACJ5cWGJx8u1YnKEU jfDJhozkA08KBVFCHzNLETJS7Oc3bT89otHts3I9GGYKz9EiC0TIbtstRl5D/5Flg7qW qs3/nIsEcR8E4YthkJqnxbNHqe4Bjeg4P5EHk8rPV9HfNZzUXgfCW6fQENQ0y/cEEZq1 6vmysTH/VRQVglOl1Uj8cc1d7yhVRaHKBdLxsEuAa8foBk8FVeewWzX02OzUgf/NcUyk +tJRDGsro6SGTHq89Emt2+TkNp1xgZsfwxdOdAemebwHnIIyCXd+bsd/LkwC99NlenQQ jIbg== X-Gm-Message-State: AOAM531aklrMsQS/ajXU5McxrYMK668OaUmJCjFk9w+O/anJ47ONhWuO vDlH/e394UVZLBURf4/DSAbjDQ== X-Google-Smtp-Source: ABdhPJzK8meTK6GJqRpHEQEt48Yt2D20sTOPtJNy5kxdwkAUZvgVChkl2EzXHxCyL5p+fxIjWVqrew== X-Received: by 2002:a17:90a:2a01:b0:1d9:44ad:2627 with SMTP id i1-20020a17090a2a0100b001d944ad2627mr4686670pjd.195.1651247541561; Fri, 29 Apr 2022 08:52:21 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:21 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 02/11] lib: sbi: Remove 's' and 'u' from misa_string() output Date: Fri, 29 Apr 2022 21:21:42 +0530 Message-Id: <20220429155151.314788-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085222_143580_93D32957 X-CRM114-Status: UNSURE ( 8.88 ) X-CRM114-Notice: Please train this message. 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: Both 's' and 'u' are not treated as ISA extensions since these are privilege modes so let's remove it from misa_string() output. Signed-off-by: Anup Patel --- lib/sbi/riscv_asm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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:1029 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Both 's' and 'u' are not treated as ISA extensions since these are privilege modes so let's remove it from misa_string() output. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/sbi/riscv_asm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 5eab1ed..0ebf41d 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -53,7 +53,7 @@ int misa_xlen(void) void misa_string(int xlen, char *out, unsigned int out_sz) { unsigned int i, pos = 0; - const char valid_isa_order[] = "iemafdqclbjtpvnsuhkorwxyzg"; + const char valid_isa_order[] = "iemafdqclbjtpvnhkorwxyzg"; if (!out) return; From patchwork Fri Apr 29 15:51:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=r/HQ/k+Z; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=kIHKv55q; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcSm6Vqrz9sFt for ; Sat, 30 Apr 2022 01:52:40 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=iKs6CtepTaQqgc7cqFfHXNZN76cTSzSEf6v3+B5vPzM=; b=r/HQ/k+Zt1FCrb D54VkSwUePfQKxEkckMJaZWJNRu8tpwWv5NqM8liY+oQ/yTD+b45WT0DS/s15JweoA1dWHjDF/cp4 T+GGzq8umcS+ikoNSuplqEonXs12EQMZ7SHiw56J/AJ37H4BLf78JmVU1ZssoAhY1ow86xa0p8NS7 rm6rT76zzVHqH6CRrUmMWVzOa5W3Dr+t3vQERWPX5yo9HgF15MYPX1ziUHbv4Q/sLo50P0KmV1aWT uYKpqJ9n1vCSjmToPduCcPp9uFHoBvC/u/FvzoTqeY+xYGHldpziBp3MNPTP8NIaWx4K5uIkfw7wk 4dJW+Nq4lccOTtG43zPA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSuw-00BpiV-TW; Fri, 29 Apr 2022 15:52:26 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSuu-00BphT-QA for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:26 +0000 Received: by mail-pj1-x1029.google.com with SMTP id bd19-20020a17090b0b9300b001d98af6dcd1so10868993pjb.4 for ; Fri, 29 Apr 2022 08:52:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YaThY3T9hKfTTw3NwpjZoxoc3bflWdnfDW12m5jenN4=; b=kIHKv55qJeCdpaI1n/wASVSY8hM+LPK6mBqSUgkcL7kVBFYYqkHS6atA5t22/TDFTm DaLBskjFzdT+8MmDGhK1YTrFWDKEajZQi60QRL1v5YDIMrLTYrGmyQqEBrEYMKJqpcNB o+pZEIxBwLOSQbQtolKCb74nHTuLv2jqc55UopX85zeB+rzYju1hEm77vAtQPuZrPq5y Agw0613UbDGk+z+UCkA2DPDF5APOx14xYyC4l67kB6XkHhzhb9f6gPtzVTLU40n5T/B5 IFnPBsPMihrier/RynIHFy9soKihxcwbiK7tpjyJzhELVSDJ66WSBZaBL2TVrJ/r7tWF b86A== 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=YaThY3T9hKfTTw3NwpjZoxoc3bflWdnfDW12m5jenN4=; b=lE4CGP8LfNlCb14vBFzZVHKF9NPIgxm+h5i6fk2nd5aGb2OjUzYI4ASevKJmUsyahz GxEwk0DL+YRDWJG4E2WMAE0OwS+IbOnrGMKknBwpJCSU2IliqJcO9ZevHrsLh7aRN1xW qTU9dQ85yA4hCLTTlHEPQWoixtrhsJ6YgMBN+yGLzJUigcSna3z1p21y1Gi5IQpfhKzo YoSLj9K2d3rru1hN7kSgPbnkNQ78GDDzS1+wTkX1nx778r8vV2gFHKYDGMOL7WbZgc2R OW4CzZvuA5VkSZPVoqh6lLu98TKGB/m+fFkMb0NKzBVEknx+7obqO1c6sdUoZnHj3puk TqRw== X-Gm-Message-State: AOAM532w6QWtp71Fc25CZ0vTuVlspjGiNNN/H2CLuyMkco8vd7VSN1BB jd4MPF2LT2Pso7kj4qeiSe1NoLdzKIY7Hw== X-Google-Smtp-Source: ABdhPJylu6Y6XN2j4WU1h9OaWB2oxC2KmhxQWh+3Lr9uVAUFcP9I19L8z7SXsZKDEajSH7BmeDlokg== X-Received: by 2002:a17:90a:bb8f:b0:1d9:650e:10f5 with SMTP id v15-20020a17090abb8f00b001d9650e10f5mr4608606pjr.148.1651247544339; Fri, 29 Apr 2022 08:52:24 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:23 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 03/11] lib: sbi: Update the name of ISA string printed at boot time Date: Fri, 29 Apr 2022 21:21:43 +0530 Message-Id: <20220429155151.314788-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085224_883841_DCCBEC59 X-CRM114-Status: UNSURE ( 9.36 ) X-CRM114-Notice: Please train this message. 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: The ISA string printed at boot time is not the complete ISA string representing all single letter and multi-letter extensions rather it is base ISA string derived from misa CSR so let us update the bo [...] 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:1029 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The ISA string printed at boot time is not the complete ISA string representing all single letter and multi-letter extensions rather it is base ISA string derived from misa CSR so let us update the boot print accordingly. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/sbi/sbi_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 660b11f..c4def58 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -142,7 +142,7 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid) sbi_hart_get_priv_version_str(scratch, str, sizeof(str)); sbi_printf("Boot HART Priv Version : %s\n", str); misa_string(xlen, str, sizeof(str)); - sbi_printf("Boot HART ISA : %s\n", str); + sbi_printf("Boot HART Base ISA : %s\n", str); sbi_hart_get_features_str(scratch, str, sizeof(str)); sbi_printf("Boot HART Features : %s\n", str); sbi_printf("Boot HART PMP Count : %d\n", From patchwork Fri Apr 29 15:51:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624433 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=ZZQ5Bfek; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=CyC1qkg7; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcSt478Zz9sBB for ; Sat, 30 Apr 2022 01:52:46 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=eur1gqSf8VTsbsjOMH60huR8CN4jP1ROMU4UwBdd97o=; b=ZZQ5Bfek4NTHkZ 3/0vyORWL9bsLoF9XcTa85yAaTHV7mJxoo/0sO43KuMb/VgV+/QTea8AFb2+SHAOim+RCZFTEy0U4 jQ1bIFda2kA86Q3Ktq20s9ZqHa4iXx466Lvs2yhsSPLV3v9Kz2hOOe1IdrDWO04qABpdF/1fM+fTs M5CNn/PkYt2BGKYTZcGEpRQDnhrcx+xFGnxgykfYmHdvIQTnBuFkSFP6eH6GhEbtHEdBRdFe23Y9U qc9umO/WnpwZqfAG45r0V0h7y1QRhhrVhQFXcm/tgI8gG8ooQdVlVnU2inu4ybLAUL87R18KdpBF0 rm7aRJfPRMPdtJL+DIjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv3-00Bplj-Ee; Fri, 29 Apr 2022 15:52:33 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv0-00Bpik-2l for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:31 +0000 Received: by mail-pj1-x102e.google.com with SMTP id gj17-20020a17090b109100b001d8b390f77bso10901107pjb.1 for ; Fri, 29 Apr 2022 08:52:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hGiQKlMHlzdpJvInlvZkoHJvUWTTd8675l0BHGIu2HA=; b=CyC1qkg7gDXjsQsQfAClYWmV/srG2ITJHZrGVaQKQeq5iLY4LeJbxTFuUjKXsPpTWF JrluM2ZnGeAdvyXBhRDJyMVqyxvGirIyYV8u59I2n2uIV2a0mWl4ff2aJptkY2llkylq EktUwYcS2alO4OIJvn9vlz6xBtT8QYdNQw5mMMyAlT23RWdocqScScezNE/fAH+lJNZ8 Zq/lFWzzh5cpFQbb+xgQ4CfX3OekfEA/Ge0LLZIMUVmgWh/f5hWRvXdTuvKfvvrpqTk8 nF49/MNDCa0ZEP2oDwyo7vFcLX33XorI1NYvmODQhn6KjJwp0mWmdmYZD1Y2Kp+gdo3X yPyg== 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=hGiQKlMHlzdpJvInlvZkoHJvUWTTd8675l0BHGIu2HA=; b=CADAx/S+AyMPYrzLdFKnyiKba7bbO4lBm47+mNbTgdiuUVzCDXD3b9YJ5gSPpdrn4r FS8/bPMX+o+l/lbWLrkIoZ4zZD65kBvMxu2k10w3CdNbakhD25Bm6GtqxlkqBy1+0FAM srkYqMZ7fiMxtp8vY9XAsEPerDFvK2KDk6oTDKL/B0/rcuT0+E3yCMa8tB6T/jFZfjAL hdbYsMbi30Wz0f4Z+u8rlsGPB8W6EO3vbdWDSI+s5VzOLguPJb4lSHcFH2DCCTk1ibIi LrkQn1050ri9iQNsI9IbOumed8NboLwdU/R0fzMycNV32s3Ael6uPDeIhDPSfttwEhZA CU4Q== X-Gm-Message-State: AOAM532zZoTKkFf4vRgdyByyvONtjEKViGXSe9AhfR8Q3/KL1eecNLrL 8FW9Ri9ujKTMUZZ5dwyI5gbODDSNIMLVYA== X-Google-Smtp-Source: ABdhPJyFFzYN36clxFFzV8UquteMIKHsfA3Mlh35IAwOLjv5bb4nVRNyzz5BGAXw6nqvLgqqdMXw3w== X-Received: by 2002:a17:902:854c:b0:159:a70:deca with SMTP id d12-20020a170902854c00b001590a70decamr59734plo.142.1651247547131; Fri, 29 Apr 2022 08:52:27 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:26 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 04/11] lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart features Date: Fri, 29 Apr 2022 21:21:44 +0530 Message-Id: <20220429155151.314788-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085230_162580_F744C192 X-CRM114-Status: GOOD ( 14.11 ) 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: If a hart implements privileged spec v1.10 (or higher) then we can safely assume that [m|s]counteren CSR are present and we don't need MCOUNTEREN and SCOUNTEREN as hart features. Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 18 +++++++ lib/sbi/sbi_emulate_csr.c | 4 ++-- lib/sbi/sbi_hart.c | 29 +++++ lib/sbi/ [...] 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:102e 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If a hart implements privileged spec v1.10 (or higher) then we can safely assume that [m|s]counteren CSR are present and we don't need MCOUNTEREN and SCOUNTEREN as hart features. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_hart.h | 18 +++++++----------- lib/sbi/sbi_emulate_csr.c | 4 ++-- lib/sbi/sbi_hart.c | 29 +++++------------------------ lib/sbi/sbi_pmu.c | 3 ++- 4 files changed, 16 insertions(+), 38 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 3c37933..4665a62 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -26,24 +26,20 @@ enum sbi_hart_priv_versions { /** Possible feature flags of a hart */ enum sbi_hart_features { - /** Hart has S-mode counter enable */ - SBI_HART_HAS_SCOUNTEREN = (1 << 0), - /** Hart has M-mode counter enable */ - SBI_HART_HAS_MCOUNTEREN = (1 << 1), /** Hart has counter inhibit CSR */ - SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2), + SBI_HART_HAS_MCOUNTINHIBIT = (1 << 0), /** Hart has sscofpmf extension */ - SBI_HART_HAS_SSCOFPMF = (1 << 3), + SBI_HART_HAS_SSCOFPMF = (1 << 1), /** HART has timer csr implementation in hardware */ - SBI_HART_HAS_TIME = (1 << 4), + SBI_HART_HAS_TIME = (1 << 2), /** HART has AIA local interrupt CSRs */ - SBI_HART_HAS_AIA = (1 << 5), + SBI_HART_HAS_AIA = (1 << 3), /** HART has menvcfg CSR */ - SBI_HART_HAS_MENVCFG = (1 << 6), + SBI_HART_HAS_MENVCFG = (1 << 4), /** HART has mstateen CSR **/ - SBI_HART_HAS_SMSTATEEN = (1 << 7), + SBI_HART_HAS_SMSTATEEN = (1 << 5), /** HART has SSTC extension implemented in hardware */ - SBI_HART_HAS_SSTC = (1 << 8), + SBI_HART_HAS_SSTC = (1 << 6), /** Last index of Hart features*/ SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC, diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c index dbb1755..aec9d3c 100644 --- a/lib/sbi/sbi_emulate_csr.c +++ b/lib/sbi/sbi_emulate_csr.c @@ -24,7 +24,7 @@ static bool hpm_allowed(int hpm_num, ulong prev_mode, bool virt) struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); if (prev_mode <= PRV_S) { - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) { + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) { cen &= csr_read(CSR_MCOUNTEREN); if (virt) cen &= csr_read(CSR_HCOUNTEREN); @@ -33,7 +33,7 @@ static bool hpm_allowed(int hpm_num, ulong prev_mode, bool virt) } } if (prev_mode == PRV_U) { - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN)) + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) cen &= csr_read(CSR_SCOUNTEREN); else cen = 0; diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index ed4e631..ed8a061 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -58,7 +58,7 @@ static void mstatus_init(struct sbi_scratch *scratch) /* Disable user mode usage of all perf counters except default ones (CY, TM, IR) */ if (misa_extension('S') && - sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN)) + sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) csr_write(CSR_SCOUNTEREN, 7); /** @@ -66,7 +66,7 @@ static void mstatus_init(struct sbi_scratch *scratch) * Supervisor mode usage for all counters are enabled by default * But counters will not run until mcountinhibit is set. */ - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) csr_write(CSR_MCOUNTEREN, -1); /* All programmable counters will start running at runtime after S-mode request */ @@ -402,12 +402,6 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) return NULL; switch (feature) { - case SBI_HART_HAS_SCOUNTEREN: - fstr = "scounteren"; - break; - case SBI_HART_HAS_MCOUNTEREN: - fstr = "mcounteren"; - break; case SBI_HART_HAS_MCOUNTINHIBIT: fstr = "mcountinhibit"; break; @@ -614,23 +608,10 @@ __mhpm_skip: #undef __check_csr_2 #undef __check_csr - /* Detect if hart supports SCOUNTEREN feature */ - val = csr_read_allowed(CSR_SCOUNTEREN, (unsigned long)&trap); - if (!trap.cause) { - hfeatures->priv_version = SBI_HART_PRIV_VER_1_10; - csr_write_allowed(CSR_SCOUNTEREN, (unsigned long)&trap, val); - if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_SCOUNTEREN; - } - - /* Detect if hart supports MCOUNTEREN feature */ + /* Detect if hart supports Priv v1.10 */ val = csr_read_allowed(CSR_MCOUNTEREN, (unsigned long)&trap); - if (!trap.cause) { + if (!trap.cause) hfeatures->priv_version = SBI_HART_PRIV_VER_1_10; - csr_write_allowed(CSR_MCOUNTEREN, (unsigned long)&trap, val); - if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_MCOUNTEREN; - } /* Detect if hart supports MCOUNTINHIBIT feature */ val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap); @@ -651,7 +632,7 @@ __mhpm_skip: /* Counter overflow/filtering is not useful without mcounter/inhibit */ if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT && - hfeatures->features & SBI_HART_HAS_MCOUNTEREN) { + hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { /* Detect if hart supports sscofpmf */ csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap); if (!trap.cause) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 7ea0ca5..853229e 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -729,7 +729,8 @@ void sbi_pmu_exit(struct sbi_scratch *scratch) if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8); - csr_write(CSR_MCOUNTEREN, -1); + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) + csr_write(CSR_MCOUNTEREN, -1); pmu_reset_event_map(hartid); } From patchwork Fri Apr 29 15:51:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=aKkl3f23; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=Zfr0urI3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcSv6mFrz9sBB for ; Sat, 30 Apr 2022 01:52:47 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=5GQCg8aZHPhMT3oFgqd+xvwr+uxudgH3/tc2mFrwVeA=; b=aKkl3f233o74li fnCrDuyP4BH2sFewhtJPj1k7O3476emvBiMdE5YBSbxgWMRPsxZNBSPDBDgHvvCZ69tij1sr7ynaE /K6OpOvnXl5uXLxvL2gnHB6EIWKN55h2Qah/ex5hm7IHDC1jN7oQleaPnLcCmcwka0hfHOly75RAg yGPKOkg6R4UhvK/Tzy4onu2spskP8YMVwFhIROnVJs0h8BsTQ2ABRFwDBgibRgIaJD30hXSt9fCzt Eym4WBshv69VdrrB+1nGdqwRjOwOm2JyMe+uoHupWWLMrOQNpvVdDeCwTyrrLtdRs/HMiTzcaz5fa tTl/wupX+Ve1y0qdIWog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv5-00Bpml-20; Fri, 29 Apr 2022 15:52:35 +0000 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv2-00Bpju-0S for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:33 +0000 Received: by mail-pf1-x42e.google.com with SMTP id x23so1968073pff.9 for ; Fri, 29 Apr 2022 08:52:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PIHreOMXXOgVphfi+vASQ44A/IYky4OQQTHmQbQeoPA=; b=Zfr0urI37Ek89FTAQ1Wzjt5drgJpoiHHxUvDOwOn5DwxiSiKFfZcXm2Y+PB6buwHbg zh8F3VUmz/4mulahcF9Je3VV3wKeu6AMysiPfTOB6kb2S67mXMYsINITdc8N9antDVlO a92i+BsdKV+/pUcd9D+sQlkyYpQNsxh8zolO6TcQbB21/Tb0gT6/zihN3H2A8eGYLg4U skdcbjdKVOvroJn3ndoJkBFfVcwHy+V9exR9y0U+z+sOTninO1DG5hiirn4lUiPTQMZK wWswGBE3pAYdJhoynnnQIczn0X3ku5zaNCfSfyPzaV9Cimt6tEFlGdoJEDiDtvZ0rqq8 cHKA== 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=PIHreOMXXOgVphfi+vASQ44A/IYky4OQQTHmQbQeoPA=; b=Jt2Y7KhLa4lp07Nm9zzVACzvKvWEHEMnJyajkQxGJkNXTYVTbKIsMSh0fUewRneiky svzrhzNjAR96dBBQtIDFwXjZP76YPExU4ee65DV4efHj4p9x0Wk+g/19bWAAQBAGVdYR Z979NMgMolw2uYiMPZf7GUXZ5KaX4Tson7ErDM7hLKoWi12s7GkknWBJTIxfzHWV0+Cc IzqcnDqU6MfSWRyvn5zqiXcxwJnrbuCa+NUvvdc7jNXjE2jY3JpBjwa4qptp4Sd/D1GO jajw4ovpb52Qm1jI5ZpfvJ9AHvvDJG6a4qi3udup4aIIYTzCudKvRAgCGC7zkh03ezxN dcDw== X-Gm-Message-State: AOAM531KvJTPpxd2DuWOcedOeYRBlCLB422wmQwGULc0EjQ/3j5KZr/E 31xza1yT+ptIEiTZFqmUTP4kQQ== X-Google-Smtp-Source: ABdhPJy/m1snrwXGKzI2hBurFyL82jw61iqL6VTz/LIO3K/doBToe5x9XyrNIRVKk+MljF/0FhbV9Q== X-Received: by 2002:a05:6a00:b4e:b0:50d:a75a:ec6e with SMTP id p14-20020a056a000b4e00b0050da75aec6emr5901783pfo.19.1651247549909; Fri, 29 Apr 2022 08:52:29 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:29 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 05/11] lib: sbi: Remove MCOUNTINHIBT hart feature Date: Fri, 29 Apr 2022 21:21:45 +0530 Message-Id: <20220429155151.314788-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085232_069470_5CE293B6 X-CRM114-Status: GOOD ( 16.30 ) 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: If a hart implements privileged spec v1.11 (or higher) then we can safely assume that mcountinhibit CSR is present and we don't need MCOUNTINHIBT as a hart feature. Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 14 ++++++-------- lib/sbi/sbi_hart.c | 23 ++++++++ lib/sbi/sbi_pmu.c | 10 +++++----- 3 files changed, 19 [...] 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:42e 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If a hart implements privileged spec v1.11 (or higher) then we can safely assume that mcountinhibit CSR is present and we don't need MCOUNTINHIBT as a hart feature. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_hart.h | 14 ++++++-------- lib/sbi/sbi_hart.c | 23 ++++++++--------------- lib/sbi/sbi_pmu.c | 10 +++++----- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 4665a62..bc6b766 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -26,20 +26,18 @@ enum sbi_hart_priv_versions { /** Possible feature flags of a hart */ enum sbi_hart_features { - /** Hart has counter inhibit CSR */ - SBI_HART_HAS_MCOUNTINHIBIT = (1 << 0), /** Hart has sscofpmf extension */ - SBI_HART_HAS_SSCOFPMF = (1 << 1), + SBI_HART_HAS_SSCOFPMF = (1 << 0), /** HART has timer csr implementation in hardware */ - SBI_HART_HAS_TIME = (1 << 2), + SBI_HART_HAS_TIME = (1 << 1), /** HART has AIA local interrupt CSRs */ - SBI_HART_HAS_AIA = (1 << 3), + SBI_HART_HAS_AIA = (1 << 2), /** HART has menvcfg CSR */ - SBI_HART_HAS_MENVCFG = (1 << 4), + SBI_HART_HAS_MENVCFG = (1 << 3), /** HART has mstateen CSR **/ - SBI_HART_HAS_SMSTATEEN = (1 << 5), + SBI_HART_HAS_SMSTATEEN = (1 << 4), /** HART has SSTC extension implemented in hardware */ - SBI_HART_HAS_SSTC = (1 << 6), + SBI_HART_HAS_SSTC = (1 << 5), /** Last index of Hart features*/ SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index ed8a061..0fe88cb 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -70,7 +70,7 @@ static void mstatus_init(struct sbi_scratch *scratch) csr_write(CSR_MCOUNTEREN, -1); /* All programmable counters will start running at runtime after S-mode request */ - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11) csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8); /** @@ -402,9 +402,6 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) return NULL; switch (feature) { - case SBI_HART_HAS_MCOUNTINHIBIT: - fstr = "mcountinhibit"; - break; case SBI_HART_HAS_SSCOFPMF: fstr = "sscofpmf"; break; @@ -613,26 +610,22 @@ __mhpm_skip: if (!trap.cause) hfeatures->priv_version = SBI_HART_PRIV_VER_1_10; - /* Detect if hart supports MCOUNTINHIBIT feature */ + /* Detect if hart supports Priv v1.11 */ val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap); - if (!trap.cause) { - csr_write_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap, val); - if (!trap.cause) { - hfeatures->priv_version = SBI_HART_PRIV_VER_1_11; - hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT; - } - } + if (!trap.cause && + (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_10)) + hfeatures->priv_version = SBI_HART_PRIV_VER_1_11; /* Detect if hart has menvcfg CSR */ csr_read_allowed(CSR_MENVCFG, (unsigned long)&trap); - if (!trap.cause) { + if (!trap.cause && + (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_11)) { hfeatures->priv_version = SBI_HART_PRIV_VER_1_12; hfeatures->features |= SBI_HART_HAS_MENVCFG; } /* Counter overflow/filtering is not useful without mcounter/inhibit */ - if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT && - hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { + if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { /* Detect if hart supports sscofpmf */ csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap); if (!trap.cause) diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 853229e..386bf4d 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -300,7 +300,7 @@ static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update) if (cidx > num_hw_ctrs || cidx == 1) return SBI_EINVAL; - if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11) goto skip_inhibit_update; /* @@ -372,7 +372,7 @@ static int pmu_ctr_stop_hw(uint32_t cidx) struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); unsigned long mctr_inhbt; - if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + if (sbi_hart_priv_version(scratch) < SBI_HART_PRIV_VER_1_11) return 0; mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT); @@ -524,7 +524,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo !sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) return fixed_ctr; - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11) mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT); for (i = 0; i < num_hw_events; i++) { temp = &hw_event_map[i]; @@ -551,7 +551,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo if (active_events[hartid][cbase] != SBI_PMU_EVENT_IDX_INVALID) continue; /* If mcountinhibit is supported, the bit must be enabled */ - if ((sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) && + if ((sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11) && !__test_bit(cbase, &mctr_inhbt)) continue; /* We found a valid counter that is not started yet */ @@ -726,7 +726,7 @@ void sbi_pmu_exit(struct sbi_scratch *scratch) { u32 hartid = current_hartid(); - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11) csr_write(CSR_MCOUNTINHIBIT, 0xFFFFFFF8); if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_10) From patchwork Fri Apr 29 15:51:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624435 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=CS0U1bxp; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=EoJPo8Xj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcSy3Kt0z9sBB for ; Sat, 30 Apr 2022 01:52:50 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=U0yPew64yaMDifNrtPX8fT+c/JeCEOhxXM67F01VD6Y=; b=CS0U1bxpmKLORi GDICTYIWyUIdZklRHjZDl/qRiUkMRbfI0xjw0+OHeA2qyy5fkx0hE5oAZLSmiCvdUQtnt77qQzXx6 r/zGMVPZfKHIc30bb0I3/rLWIXFJCEjl1Ls9/ZYDawgVGOQ6twLf5epPad/D7PhgnhpWgoOnXekwI qVluTWgPx5/furEBkkN9xKwEj/tCzGpITHpq89ZqS2fM3NqE9D83fv+QDIuLq0OvgK6aM/rM9PVx0 0j/oK600kXtSndjQ5TXJjoZZmSPJ0RV9G8lELa9IPvoSqQvFhpTBCUw3o8xiLUhleu24AU1d/cSHq BpD97BHl47FHhpaCrwHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv7-00BppL-W0; Fri, 29 Apr 2022 15:52:37 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv5-00Bple-Gk for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:37 +0000 Received: by mail-pf1-x429.google.com with SMTP id i24so7249109pfa.7 for ; Fri, 29 Apr 2022 08:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uRFxYY7W8dbeNGDra/cnt3Yq5bkt7rOyA1yl1/UkIeM=; b=EoJPo8XjCf22LG951UZbZEr5qEpVs+3jjtM0YUuWoX4fendVdWAQEghsHUA3Ho5Fj3 Od7Ooe24HMhDxI0KriSpB/w4AeAK8oHyUc8uyuxf7Bt0VYyhdQW7ronVCTLJd6jdga5Y GnbpHdRepS/2vEDznCR+F2G2SY3r0Bdrq6zQRFbhc2+c8hsonsEZzTbkcu6qUH6kZwf2 scysqpED04C+hqFWVguQ9VUNbbftEDZ0e4Rtm9R9irUsQPz+9EsDO8pbUNDmDINMvdfc r2qJ+VWboHIa+Viz51Tnxguamuz0SccUegATtQAdNK2FHtnmOEiDNcd/v0vu0yzlSbrA fAGQ== 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=uRFxYY7W8dbeNGDra/cnt3Yq5bkt7rOyA1yl1/UkIeM=; b=PWWXASinexvfeRdz4DV848HzxH2m1UWQ8D1UOuZJNL3pkjlpGCXqMDGYho/jTT/7Om uCMujzf3LTkneFtksgH3JxOPxhacDKxMsTnPktE/AWSichiMGSjVXQ8C7eEdLGYQNwJm /6KbpkoTSdwaGQj7TJZEbTgMdJrPkRNAszon/HcRbUaH4zWQKd6lY487URdgd8EhbPv5 881sL1qJ5sErmzHu0MDuATaHgfJHfuPMBoKZkq3bhyoKITs+/5p4jRNwbwuz+nSl1s9P KAlKoS3LBLfxiJXu6x6HVPMMdMDfWDUNN60hAbajWY7NCBCZm8k2MmcLTFrxPe2wc1LF qO/g== X-Gm-Message-State: AOAM530u7/oVTWqqhDJ7pBuJ7N6fGP1Qa1oL3Yg5WwaFSBYbdUT+2Tc2 LEUvrgj7ncoMEJACiODcr/NZ3A== X-Google-Smtp-Source: ABdhPJz4BNryGhaHpGWfpblIZYsvEB6pN3A47/r0NOJC6gqUkzYUHkgGhGUNbvqhEWLvi/dADj9HSQ== X-Received: by 2002:a05:6a00:1903:b0:4fa:fa9e:42e6 with SMTP id y3-20020a056a00190300b004fafa9e42e6mr40424247pfi.1.1651247552718; Fri, 29 Apr 2022 08:52:32 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:32 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 06/11] lib: sbi: Remove MENVCFG hart feature Date: Fri, 29 Apr 2022 21:21:46 +0530 Message-Id: <20220429155151.314788-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085235_608644_7BAF545D X-CRM114-Status: GOOD ( 11.26 ) 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: If a hart implements privileged spec v1.12 (or higher) then we can safely assume that menvcfg CSR is present and we don't need MENVCFG as a hart feature. Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 6 ++---- lib/sbi/sbi_hart.c | 32 ++++++++++++ 2 files changed, 14 insertions(+), 24 deletions(-) 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:429 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If a hart implements privileged spec v1.12 (or higher) then we can safely assume that menvcfg CSR is present and we don't need MENVCFG as a hart feature. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_hart.h | 6 ++---- lib/sbi/sbi_hart.c | 32 ++++++++++++-------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index bc6b766..c985674 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -32,12 +32,10 @@ enum sbi_hart_features { SBI_HART_HAS_TIME = (1 << 1), /** HART has AIA local interrupt CSRs */ SBI_HART_HAS_AIA = (1 << 2), - /** HART has menvcfg CSR */ - SBI_HART_HAS_MENVCFG = (1 << 3), /** HART has mstateen CSR **/ - SBI_HART_HAS_SMSTATEEN = (1 << 4), + SBI_HART_HAS_SMSTATEEN = (1 << 3), /** HART has SSTC extension implemented in hardware */ - SBI_HART_HAS_SSTC = (1 << 5), + SBI_HART_HAS_SSTC = (1 << 4), /** Last index of Hart features*/ SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 0fe88cb..5ee5ddd 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -97,10 +97,8 @@ static void mstatus_init(struct sbi_scratch *scratch) mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32; #endif mstateen_val |= SMSTATEEN_STATEN; - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MENVCFG)) - mstateen_val |= SMSTATEEN0_HSENVCFG; - else - mstateen_val &= ~SMSTATEEN0_HSENVCFG; + mstateen_val |= SMSTATEEN0_HSENVCFG; + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_AIA)) mstateen_val |= (SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT | SMSTATEEN0_IMSIC); @@ -113,7 +111,7 @@ static void mstatus_init(struct sbi_scratch *scratch) #endif } - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MENVCFG)) { + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) { menvcfg_val = csr_read(CSR_MENVCFG); /* @@ -413,9 +411,6 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) case SBI_HART_HAS_SSTC: fstr = "sstc"; break; - case SBI_HART_HAS_MENVCFG: - fstr = "menvcfg"; - break; case SBI_HART_HAS_SMSTATEEN: fstr = "smstateen"; break; @@ -616,13 +611,11 @@ __mhpm_skip: (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_10)) hfeatures->priv_version = SBI_HART_PRIV_VER_1_11; - /* Detect if hart has menvcfg CSR */ + /* 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_11)) hfeatures->priv_version = SBI_HART_PRIV_VER_1_12; - hfeatures->features |= SBI_HART_HAS_MENVCFG; - } /* Counter overflow/filtering is not useful without mcounter/inhibit */ if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { @@ -644,20 +637,19 @@ __mhpm_skip: hfeatures->features |= SBI_HART_HAS_AIA; __aia_skip: - /** - * Detect if hart supports stimecmp CSR(Sstc extension) and menvcfg is - * implemented. - */ - if (hfeatures->features & SBI_HART_HAS_MENVCFG) { + /* 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) hfeatures->features |= SBI_HART_HAS_SSTC; } /* Detect if hart supports mstateen CSRs */ - val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap); - if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_SMSTATEEN; + if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { + val = csr_read_allowed(CSR_MSTATEEN0, (unsigned long)&trap); + if (!trap.cause) + hfeatures->features |= SBI_HART_HAS_SMSTATEEN; + } return; } From patchwork Fri Apr 29 15:51:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624436 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=JXTnEhI+; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=fKMB+k1v; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcT06HBGz9sBB for ; Sat, 30 Apr 2022 01:52:52 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=hHrNLV4dBkINyPsvu5nl9KnixaqEOTRnlo/1O3UXyxw=; b=JXTnEhI+UpTAIt XhJdr5yA8wLIM/tlI+tH39lKhFD7CkvGt9N/LyY2a2R17zO8LH07aenJptyBZioxhMbRPBCo5aWso cYQCV/b9XSZZArRsyj8oMN7SRKswpXyb93K7mldCO6ujdMGqxkJueBX3f/fHAAkwt6vyxUcAZhlEt VCzYdjj0R9VrMMzNJC0aa2p3CQQWxI/NixiJc3N8Ei4Rm7PDm0gccyLV1+uyZ9Fl50KV/YKJtdxSM B7BksbweBalkiubWkHGKTPVExFLRRASFWRyWRyHI0B+FHIv1E21ibCNzeNZ2i0r6koiXA7HIMfpW3 3SaVaDjuHsGNWO6k2njA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvA-00Bprk-Ir; Fri, 29 Apr 2022 15:52:40 +0000 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSv7-00BpnY-2l for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:38 +0000 Received: by mail-pg1-x535.google.com with SMTP id s137so6832780pgs.5 for ; Fri, 29 Apr 2022 08:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O5VLghBeXhnL8rer7u0y8qxvc+QVIa22UO2NarDOL6w=; b=fKMB+k1v5pnzjykh/jGAvSKVqGsH2pjV0Ft+j3ax5e/KnyScVuZI5Rlx5m/Kzb/HoG +BvjsEKbUOAfinnrRVfdUdnfagHxjrPHiU8EAUe/XftYCoWRsVABkEBfAMiXnPJdX2an NtS/6hptZADFpFezmY55tb+WGB6PyJv9+6RehxzuOUghql3knPZoqY/VMfWvb2Hgio3p 22jGQv8uwOYbV3mS7zmTBu9OgQf2Zf6mrXPUCKG7Dq2kebZsc5Sa6mWPAmEC7ynVATIm fIHuOPy+Tvr8uX5d7HIf1/I7oBup3hqfW+oj+E/KR87Qp0xnYm8b77xfstWojujLsOo6 pKRQ== 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=O5VLghBeXhnL8rer7u0y8qxvc+QVIa22UO2NarDOL6w=; b=6OIg0zk+HzoJqKPKSRBvImBUA5ZX/oD4HJk2zkzFdxuKW99c6w4Fow1fLFUYohKw+b 3WzZ1Em+DK5j1nrz3qY0BOxn9FZ1oDB+P8NOj4nBAWE8PKXkbpjxqwyQpaCex2IEGhPV QfESaT6/bPAa/0KuA/HViK6bsni2EIVROOFH4AENOZTJ9nOJxO8hvfQHSnFcthZg5wmQ /UFMTYgJ25t45ooBn+MvxZ1oa7TpMuHCIX/QT/2w4qysYoirf07xOMdpxs/U4kq73+vd 4gXRkDSDEsgV1tXxxYzLlLYmLt40wwez6et1G0F+6HjhbC/meI5aRhcrkkbY2aDOt9UZ R8Pw== X-Gm-Message-State: AOAM533zESx5mAt+hNc8iPEHi5FnTYdXrq4UNzoVdzO+4JyjIRjEztRM rdzrnhixK+HRHP3wbbAMtPvIhw== X-Google-Smtp-Source: ABdhPJyywO09IuaQnuDQsbT4WMudFqJC6ejV5KxyWHeT/Yri6t9U8H4/aewbsUC1HRvdIBAHQMz/Yw== X-Received: by 2002:a63:6e84:0:b0:398:1338:689 with SMTP id j126-20020a636e84000000b0039813380689mr23615pgc.283.1651247555538; Fri, 29 Apr 2022 08:52:35 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:34 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 07/11] lib: sbi: Fix AIA feature detection Date: Fri, 29 Apr 2022 21:21:47 +0530 Message-Id: <20220429155151.314788-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085237_151200_640FAC00 X-CRM114-Status: UNSURE ( 9.11 ) X-CRM114-Notice: Please train this message. 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: The AIA feature detection uses unnecessary goto which is not need and AIA case in sbi_hart_feature_id2string() does not break. This patch fixes both issues in AIA feature detection. Signed-off-by: Anup Patel --- lib/sbi/sbi_hart.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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:535 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The AIA feature detection uses unnecessary goto which is not need and AIA case in sbi_hart_feature_id2string() does not break. This patch fixes both issues in AIA feature detection. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/sbi/sbi_hart.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 5ee5ddd..fdfb6d9 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -408,6 +408,7 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) break; case SBI_HART_HAS_AIA: fstr = "aia"; + break; case SBI_HART_HAS_SSTC: fstr = "sstc"; break; @@ -632,10 +633,8 @@ __mhpm_skip: /* Detect if hart has AIA local interrupt CSRs */ csr_read_allowed(CSR_MTOPI, (unsigned long)&trap); - if (trap.cause) - goto __aia_skip; - hfeatures->features |= SBI_HART_HAS_AIA; -__aia_skip: + if (!trap.cause) + hfeatures->features |= SBI_HART_HAS_AIA; /* Detect if hart supports stimecmp CSR(Sstc extension) */ if (hfeatures->priv_version >= SBI_HART_PRIV_VER_1_12) { From patchwork Fri Apr 29 15:51:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=zoQc/8Ck; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=LJdEixg+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcT762LDz9sBB for ; Sat, 30 Apr 2022 01:52:59 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=BOamwh6NmjoTsthT7d4nXaC51GHgGa90qhqDP9l6cMY=; b=zoQc/8CkySSr4G hDWIygYYz0Kst160q1mJ8JJm/TM3jotWZO86nuAxfXEdSJXxJboifX96OPsP2r35EFO7viL2HBrum 6paXjaBDSt2f5/GX+WtHe+u8oqXut7xtWtIkqcxMxlt5ljUFboVjBXwwB6bEcfVSzZSp7OZOj0rVv RAAJpgrZzLpZ1QqtwPmxyo5CFm/uGPHglHxS89SSmlof0AdwFklMKsMh9DVvbRX7sjC2lpqCOKW9D kqeMVl7aoBNGx9vu67HDD6BfaiDChzF3REGb/aOo6DhwL9g7p1ihpyNAlOSQK2w5sFeXeQc7ACMFn nYOMLNjs7YnBH/btGstA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvG-00Bpxs-A9; Fri, 29 Apr 2022 15:52:46 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvB-00BpqE-JY for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:44 +0000 Received: by mail-pj1-x1030.google.com with SMTP id bd19-20020a17090b0b9300b001d98af6dcd1so10869491pjb.4 for ; Fri, 29 Apr 2022 08:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HWlN7JxhP/133ILpB+yvID+OdDagi64ctPmhTuIiWkU=; b=LJdEixg+Oy55JzZirWWUlDDQ0R/j+Xr9IasUZrVpT3VkmOqZTMouGQMt9ZrEpOckhk 36NJuOZ92AMgjw9OLCysLgvejW76TqiqQ7yBW1Fg4zRHBOAgjYWglxpk+XMF8dz5t+rT 4zbp/c3GQkXxiBdTpMWL+QU+rxBQXVWDKq5BtsM5veDmVRdQF5UGX/Zv3kUUeTjoNqY8 6rmbnI38L07Ko+QVJJysHfMln62D5mB9JZOpQWAM9NX9aXSIqIg5lLF7K5S/lncHbkKM MIjrq7i0y3O2caBO9HWndQT36V54PVRrF71qIn1fvaJxtlRSn/58Lk6lBAe4n817OEvz w3Fw== 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=HWlN7JxhP/133ILpB+yvID+OdDagi64ctPmhTuIiWkU=; b=oWdPD/2tMZe7UhL69EmqLyS5822EWinrQQcSs/FDZ/3L3qcLBzStOahjj1x+wi3kiu +NfjTt0w1MWppJWZy1i3x8oI6elGY9fJ0o0n5nMH/OKbbNipexb1QV9RygF73EkyVBCV NjhWABruVDWbedv5yNc0tzt0S1bMg7uzeIMXqqwVADEXmN1GZvhykM4BqCziQ1ywy7f9 5Faunk7Jn81tZSwlF+a7TStHaycopWIaJ+GRCQZ6/XfIpqG3GPfaWYmmieBsbeVNdJoA b9XCHd0YcGqQNpTF5ZgPI0yPcBut2hrLvebRCI7oHBFoOzgMzDeIf7zq97PA20rU/XY0 OAVw== X-Gm-Message-State: AOAM530mIItuWmdhxid1anXNDvMLPDrPkDSaoLQn6iiE/DBZc0VlJpwj x2egijvwMrrgu6QxyHdRejXujHAq7tl7OA== X-Google-Smtp-Source: ABdhPJxz8v94AMRoUS3E7S68V97yes0fV530GwK9rwpupV3PBxQAfMDH/7wrO3vimuoVfn47u1KxNQ== X-Received: by 2002:a17:902:b682:b0:15d:29:9820 with SMTP id c2-20020a170902b68200b0015d00299820mr28570785pls.134.1651247558340; Fri, 29 Apr 2022 08:52:38 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:37 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 08/11] lib: sbi: Convert hart features into hart extensions Date: Fri, 29 Apr 2022 21:21:48 +0530 Message-Id: <20220429155151.314788-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085241_672656_99324CEE X-CRM114-Status: GOOD ( 22.90 ) 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: Since past few years, we have been using "hart features" in OpenSBI to represent all optionalities and multi-letter extensions defined by the RISC-V specifications. The RISC-V profiles specification has taken a different approach and started assigning extension names for all optionalities which did not have any extension name previously. (Refer, https://github.co [...] 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:1030 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Since past few years, we have been using "hart features" in OpenSBI to represent all optionalities and multi-letter extensions defined by the RISC-V specifications. The RISC-V profiles specification has taken a different approach and started assigning extension names for all optionalities which did not have any extension name previously. (Refer, https://github.com/riscv/riscv-profiles/blob/main/profiles.adoc) Inspired from the RISC-V profiles specification, we convert OpenSBI hart features into hart extensions. Going forward, we align the extension naming with RISC-V profiles specification. Currently, only "time CSR" and "AIA CSR" have not been assigned extension name but for everything else we have a name. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_hart.h | 35 ++++++------ lib/sbi/sbi_hart.c | 116 +++++++++++++++++++--------------------- lib/sbi/sbi_init.c | 4 +- lib/sbi/sbi_pmu.c | 6 +-- lib/sbi/sbi_timer.c | 6 +-- lib/sbi/sbi_trap.c | 4 +- lib/utils/fdt/fdt_pmu.c | 2 +- 7 files changed, 83 insertions(+), 90 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index c985674..8b21fd4 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -24,21 +24,21 @@ enum sbi_hart_priv_versions { SBI_HART_PRIV_VER_1_12 = 3, }; -/** Possible feature flags of a hart */ -enum sbi_hart_features { - /** Hart has sscofpmf extension */ - SBI_HART_HAS_SSCOFPMF = (1 << 0), - /** HART has timer csr implementation in hardware */ - SBI_HART_HAS_TIME = (1 << 1), - /** HART has AIA local interrupt CSRs */ - SBI_HART_HAS_AIA = (1 << 2), - /** HART has mstateen CSR **/ - SBI_HART_HAS_SMSTATEEN = (1 << 3), - /** HART has SSTC extension implemented in hardware */ - SBI_HART_HAS_SSTC = (1 << 4), +/** Possible ISA extensions of a hart */ +enum sbi_hart_extensions { + /** Hart has Sscofpmt extension */ + SBI_HART_EXT_SSCOFPMF = 0, + /** HART has HW time CSR (extension name not available) */ + SBI_HART_EXT_TIME, + /** HART has AIA CSRs (extension name not available) */ + SBI_HART_EXT_AIA, + /** HART has Smstateen CSR **/ + SBI_HART_EXT_SMSTATEEN, + /** HART has Sstc extension */ + SBI_HART_EXT_SSTC, - /** Last index of Hart features*/ - SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_SSTC, + /** Maximum index of Hart extension */ + SBI_HART_EXT_MAX, }; struct sbi_scratch; @@ -63,9 +63,10 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch); int sbi_hart_priv_version(struct sbi_scratch *scratch); void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, char *version_str, int nvstr); -bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature); -void sbi_hart_get_features_str(struct sbi_scratch *scratch, - char *features_str, int nfstr); +bool sbi_hart_has_extension(struct sbi_scratch *scratch, + enum sbi_hart_extensions ext); +void sbi_hart_get_extensions_str(struct sbi_scratch *scratch, + char *extension_str, int nestr); void __attribute__((noreturn)) sbi_hart_hang(void); diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index fdfb6d9..956d185 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -29,7 +29,7 @@ void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap; struct hart_features { int priv_version; - unsigned long features; + unsigned long extensions; unsigned int pmp_count; unsigned int pmp_addr_bits; unsigned long pmp_gran; @@ -83,7 +83,7 @@ static void mstatus_init(struct sbi_scratch *scratch) for (cidx = 0; cidx < num_mhpm; cidx++) { #if __riscv_xlen == 32 csr_write_num(CSR_MHPMEVENT3 + cidx, mhpmevent_init_val & 0xFFFFFFFF); - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) csr_write_num(CSR_MHPMEVENT3H + cidx, mhpmevent_init_val >> BITS_PER_LONG); #else @@ -91,7 +91,7 @@ static void mstatus_init(struct sbi_scratch *scratch) #endif } - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SMSTATEEN)) { + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SMSTATEEN)) { mstateen_val = csr_read(CSR_MSTATEEN0); #if __riscv_xlen == 32 mstateen_val |= ((uint64_t)csr_read(CSR_MSTATEEN0H)) << 32; @@ -99,7 +99,7 @@ static void mstatus_init(struct sbi_scratch *scratch) mstateen_val |= SMSTATEEN_STATEN; mstateen_val |= SMSTATEEN0_HSENVCFG; - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_AIA)) + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_AIA)) mstateen_val |= (SMSTATEEN0_AIA | SMSTATEEN0_SVSLCT | SMSTATEEN0_IMSIC); else @@ -153,7 +153,7 @@ static void mstatus_init(struct sbi_scratch *scratch) * Enable access to stimecmp if sstc extension is present in the * hardware. */ - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSTC)) { + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSTC)) { #if __riscv_xlen == 32 unsigned long menvcfgh_val; menvcfgh_val = csr_read(CSR_MENVCFGH); @@ -207,7 +207,7 @@ static int delegate_traps(struct sbi_scratch *scratch) /* Send M-mode interrupts and most exceptions to S-mode */ interrupts = MIP_SSIP | MIP_STIP | MIP_SEIP; - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) interrupts |= MIP_LCOFIP; exceptions = (1U << CAUSE_MISALIGNED_FETCH) | (1U << CAUSE_BREAKPOINT) | @@ -367,102 +367,94 @@ void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, } /** - * Check whether a particular hart feature is available + * Check whether a particular hart extension is available * * @param scratch pointer to the HART scratch space - * @param feature the feature to check - * @returns true (feature available) or false (feature not available) + * @param ext the extension number to check + * @returns true (available) or false (not available) */ -bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature) +bool sbi_hart_has_extension(struct sbi_scratch *scratch, + enum sbi_hart_extensions ext) { struct hart_features *hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset); - if (hfeatures->features & feature) + if (hfeatures->extensions & BIT(ext)) return true; else return false; } -static unsigned long hart_get_features(struct sbi_scratch *scratch) +static inline char *sbi_hart_extension_id2string(int ext) { - struct hart_features *hfeatures = - sbi_scratch_offset_ptr(scratch, hart_features_offset); - - return hfeatures->features; -} - -static inline char *sbi_hart_feature_id2string(unsigned long feature) -{ - char *fstr = NULL; - - if (!feature) - return NULL; + char *estr = NULL; - switch (feature) { - case SBI_HART_HAS_SSCOFPMF: - fstr = "sscofpmf"; + switch (ext) { + case SBI_HART_EXT_SSCOFPMF: + estr = "sscofpmf"; break; - case SBI_HART_HAS_TIME: - fstr = "time"; + case SBI_HART_EXT_TIME: + estr = "time"; break; - case SBI_HART_HAS_AIA: - fstr = "aia"; + case SBI_HART_EXT_AIA: + estr = "aia"; break; - case SBI_HART_HAS_SSTC: - fstr = "sstc"; + case SBI_HART_EXT_SSTC: + estr = "sstc"; break; - case SBI_HART_HAS_SMSTATEEN: - fstr = "smstateen"; + case SBI_HART_EXT_SMSTATEEN: + estr = "smstateen"; break; default: break; } - return fstr; + return estr; } /** - * Get the hart features in string format + * Get the hart extensions in string format * * @param scratch pointer to the HART scratch space - * @param features_str pointer to a char array where the features string will be - * updated - * @param nfstr length of the features_str. The feature string will be truncated - * if nfstr is not long enough. + * @param extensions_str pointer to a char array where the extensions string + * will be updated + * @param nestr length of the features_str. The feature string will be + * truncated if nestr is not long enough. */ -void sbi_hart_get_features_str(struct sbi_scratch *scratch, - char *features_str, int nfstr) +void sbi_hart_get_extensions_str(struct sbi_scratch *scratch, + char *extensions_str, int nestr) { - unsigned long features, feat = 1UL; + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); + int offset = 0, ext = 0; char *temp; - int offset = 0; - if (!features_str || nfstr <= 0) + if (!extensions_str || nestr <= 0) return; - sbi_memset(features_str, 0, nfstr); + sbi_memset(extensions_str, 0, nestr); - features = hart_get_features(scratch); - if (!features) + if (!hfeatures->extensions) goto done; do { - if (features & feat) { - temp = sbi_hart_feature_id2string(feat); + if (hfeatures->extensions & BIT(ext)) { + temp = sbi_hart_extension_id2string(ext); if (temp) { - sbi_snprintf(features_str + offset, nfstr, + sbi_snprintf(extensions_str + offset, + nestr - offset, "%s,", temp); offset = offset + sbi_strlen(temp) + 1; } } - feat = feat << 1; - } while (feat <= SBI_HART_HAS_LAST_FEATURE); + + ext++; + } while (ext <= SBI_HART_EXT_MAX); done: if (offset) - features_str[offset - 1] = '\0'; + extensions_str[offset - 1] = '\0'; else - sbi_strncpy(features_str, "none", nfstr); + sbi_strncpy(extensions_str, "none", nestr); } static unsigned long hart_pmp_get_allowed_addr(void) @@ -523,7 +515,7 @@ static void hart_detect_features(struct sbi_scratch *scratch) /* Reset hart features */ hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset); - hfeatures->features = 0; + hfeatures->extensions = 0; hfeatures->pmp_count = 0; hfeatures->mhpm_count = 0; @@ -623,31 +615,31 @@ __mhpm_skip: /* Detect if hart supports sscofpmf */ csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap); if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_SSCOFPMF; + hfeatures->extensions |= BIT(SBI_HART_EXT_SSCOFPMF); } /* Detect if hart supports time CSR */ csr_read_allowed(CSR_TIME, (unsigned long)&trap); if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_TIME; + hfeatures->extensions |= BIT(SBI_HART_EXT_TIME); /* Detect if hart has AIA local interrupt CSRs */ csr_read_allowed(CSR_MTOPI, (unsigned long)&trap); if (!trap.cause) - hfeatures->features |= SBI_HART_HAS_AIA; + hfeatures->extensions |= BIT(SBI_HART_EXT_AIA); /* 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) - hfeatures->features |= SBI_HART_HAS_SSTC; + hfeatures->extensions |= BIT(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) - hfeatures->features |= SBI_HART_HAS_SMSTATEEN; + hfeatures->extensions |= BIT(SBI_HART_EXT_SMSTATEEN); } return; diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index c4def58..d57efa7 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -143,8 +143,8 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid) sbi_printf("Boot HART Priv Version : %s\n", str); misa_string(xlen, str, sizeof(str)); sbi_printf("Boot HART Base ISA : %s\n", str); - sbi_hart_get_features_str(scratch, str, sizeof(str)); - sbi_printf("Boot HART Features : %s\n", str); + sbi_hart_get_extensions_str(scratch, str, sizeof(str)); + sbi_printf("Boot HART ISA Extensions : %s\n", str); sbi_printf("Boot HART PMP Count : %d\n", sbi_hart_pmp_count(scratch)); sbi_printf("Boot HART PMP Granularity : %lu\n", diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c index 386bf4d..b60799e 100644 --- a/lib/sbi/sbi_pmu.c +++ b/lib/sbi/sbi_pmu.c @@ -313,7 +313,7 @@ static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update) __clear_bit(cidx, &mctr_inhbt); - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) pmu_ctr_enable_irq_hw(cidx); csr_write(CSR_MCOUNTINHIBIT, mctr_inhbt); @@ -474,7 +474,7 @@ static int pmu_update_hw_mhpmevent(struct sbi_pmu_hw_event *hw_evt, int ctr_idx, * Always set the OVF bit(disable interrupts) and inhibit counting of * events in M-mode. The OVF bit should be enabled during the start call. */ - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) mhpmevent_val = (mhpmevent_val & ~MHPMEVENT_SSCOF_MASK) | MHPMEVENT_MINH | MHPMEVENT_OF; @@ -521,7 +521,7 @@ static int pmu_ctr_find_hw(unsigned long cbase, unsigned long cmask, unsigned lo */ fixed_ctr = pmu_ctr_find_fixed_fw(event_idx); if (fixed_ctr >= 0 && - !sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) + !sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) return fixed_ctr; if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_11) diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c index bf0f375..353886f 100644 --- a/lib/sbi/sbi_timer.c +++ b/lib/sbi/sbi_timer.c @@ -129,7 +129,7 @@ void sbi_timer_event_start(u64 next_event) * Update the stimecmp directly if available. This allows * the older software to leverage sstc extension on newer hardware. */ - if (sbi_hart_has_feature(sbi_scratch_thishart_ptr(), SBI_HART_HAS_SSTC)) { + if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(), SBI_HART_EXT_SSTC)) { #if __riscv_xlen == 32 csr_write(CSR_STIMECMP, next_event & 0xFFFFFFFF); csr_write(CSR_STIMECMPH, next_event >> 32); @@ -151,7 +151,7 @@ void sbi_timer_process(void) * directly without M-mode come in between. This function should * only invoked if M-mode programs the timer for its own purpose. */ - if (!sbi_hart_has_feature(sbi_scratch_thishart_ptr(), SBI_HART_HAS_SSTC)) + if (!sbi_hart_has_extension(sbi_scratch_thishart_ptr(), SBI_HART_EXT_SSTC)) csr_set(CSR_MIP, MIP_STIP); } @@ -180,7 +180,7 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot) if (!time_delta_off) return SBI_ENOMEM; - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_TIME)) + if (sbi_hart_has_extension(scratch, SBI_HART_EXT_TIME)) get_time_val = get_ticks; } else { if (!time_delta_off) diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 86bab6d..2c509e5 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -272,8 +272,8 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) } if (mcause & (1UL << (__riscv_xlen - 1))) { - if (sbi_hart_has_feature(sbi_scratch_thishart_ptr(), - SBI_HART_HAS_AIA)) + if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(), + SBI_HART_EXT_AIA)) rc = sbi_trap_aia_irq(regs, mcause); else rc = sbi_trap_nonaia_irq(regs, mcause); diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c index a2b048f..8ba6b08 100644 --- a/lib/utils/fdt/fdt_pmu.c +++ b/lib/utils/fdt/fdt_pmu.c @@ -53,7 +53,7 @@ int fdt_pmu_fixup(void *fdt) fdt_delprop(fdt, pmu_offset, "riscv,event-to-mhpmcounters"); fdt_delprop(fdt, pmu_offset, "riscv,event-to-mhpmevent"); fdt_delprop(fdt, pmu_offset, "riscv,raw-event-to-mhpmcounters"); - if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_SSCOFPMF)) + if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SSCOFPMF)) fdt_delprop(fdt, pmu_offset, "interrupts-extended"); return 0; From patchwork Fri Apr 29 15:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=fXFak1Y+; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=TJ3k4OQ1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcT764vrz9sBF for ; Sat, 30 Apr 2022 01:52:59 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=IOmvVjBT3cwVSOCguYReq6yof7C1rUqJ49bMxGY0yMA=; b=fXFak1Y+FBbmyw pjZZIWAJknVbX+3kpEX4lFqqVjq0x1KVYIA4Q/MXVm5exJcMQnP5GgmI4vEWlq/4bI2i2bBigCyxs WEgSFCHQJXFU+H3tO67vJiwJT+yomXmRf5VnANX1AguG21T1e9Js45MAS0d1sdL7m919tpHUoDqZT lyfCxzOcAd55MGUxBTI/ODYke+bzCh9xpg/vXkZUnhm7qrvszf+dQkrhQV+b+NMMfXTQhXPERQQH+ qbcwmIh+bqutwBkEN5PmB2+yS2CXXV6KU8eQfmuhx5pEfhg/zy8tstFRMQzQYImzwhMnpuwsxGdrw SUkKcKmoOvyWbfHjYAqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvH-00BpzC-FP; Fri, 29 Apr 2022 15:52:47 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvE-00BptX-E3 for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:45 +0000 Received: by mail-pf1-x42c.google.com with SMTP id a11so7269598pff.1 for ; Fri, 29 Apr 2022 08:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/gM9h3cfDOhdNhAlnuDkdNayk4hM6gLEo8lKMKySyWM=; b=TJ3k4OQ1BrPgJWVk6BA0TC/C0q1MdQTn4nok3SJJ4PBq+9wdXLLUT3oMA0XKqqQdGb YlCzXcNPXX3XLOYMmQWoZz5tSpzC6irmosFhZEvR0DRVxyaS5hRZxTEzTbh13xxqbly0 7/Z2d4OIIsCFbOxilcvBmxNzEkK3GCJdEhgjegLRf6EmT+mr2oLZjuxtEex652A0b99b YxnufUlobW/vHyCs/An3Ozl9z/ubEFuPW7a1nIClCzBPKEiZy2XGyYhrQNNp9RWHwrBX NGJ5OYk3cbaffJNffqp2vU7SS4Uh8yYUTMNclzF9zzVV00kgMaGkbB9iUGcu76N8Kpie hZgw== 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=/gM9h3cfDOhdNhAlnuDkdNayk4hM6gLEo8lKMKySyWM=; b=NE7fpv1QaPc1v08IvWsYr4Epz78cr3zRzNYKOwSwT9jhgCtvnz+qAEKnmJYvYQ6f8T qngfw3wBSk87GZhjqPyXVO2PT0zkLZ+VtXd1ev3cutoNVF7THJkkfkMTK26NXv8Wgebu mJ8SMm8FoCAHDrhQZVQUy6FmzSvm8q8NrG881eJXbmAm2l4wxcKRMu4IoaIyNcOqrziS xTazl44/kw3LhKmT8B/xEFRdpeoYzOzRN8r6bjtM3Q2GGjAsvwdSfrDQGpCPKbmKZSbU J0Fx/bpPgqY//nxQknzrn4Vf2WWVGdl9C6MMnKySnFhlcgg7N1cNCa/T8MtA3FRm5OzI pJZQ== X-Gm-Message-State: AOAM530izzebJZzieLZxX42LchlXNNp6uibjsZsUx3sCuSbYhHWP/Vit lYWqF6+DQCtL3I743FYeTDvOMw== X-Google-Smtp-Source: ABdhPJw3fJme5DRZOKHpXZONwG6ItmP4WpsqnO+7PGJPNILOQu3UWG1ay9mVH1cAAXP3X3x0/mXjFQ== X-Received: by 2002:a63:e355:0:b0:39d:7956:6d3c with SMTP id o21-20020a63e355000000b0039d79566d3cmr18751pgj.385.1651247561506; Fri, 29 Apr 2022 08:52:41 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:40 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 09/11] lib: sbi: Detect hart features only once for each hart Date: Fri, 29 Apr 2022 21:21:49 +0530 Message-Id: <20220429155151.314788-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085244_589011_ACE4817E X-CRM114-Status: GOOD ( 12.80 ) 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: Currently, the hart_detect_features() is called everytime a hart is stopped and started again which is unnecessary work. We update hart_detect_features() to detect hart features only once for each hart. 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, the hart_detect_features() is called everytime a hart is stopped and started again which is unnecessary work. We update hart_detect_features() to detect hart features only once for each hart. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- lib/sbi/sbi_hart.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 956d185..28a7e75 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -28,6 +28,7 @@ extern void __sbi_expected_trap_hext(void); void (*sbi_hart_expected_trap)(void) = &__sbi_expected_trap; struct hart_features { + bool detected; int priv_version; unsigned long extensions; unsigned int pmp_count; @@ -510,11 +511,15 @@ static int hart_pmu_get_allowed_bits(void) static void hart_detect_features(struct sbi_scratch *scratch) { struct sbi_trap_info trap = {0}; - struct hart_features *hfeatures; + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); unsigned long val, oldval; - /* Reset hart features */ - hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset); + /* If hart features already detected then do nothing */ + if (hfeatures->detected) + return; + + /* Clear hart features */ hfeatures->extensions = 0; hfeatures->pmp_count = 0; hfeatures->mhpm_count = 0; @@ -642,6 +647,9 @@ __mhpm_skip: hfeatures->extensions |= BIT(SBI_HART_EXT_SMSTATEEN); } + /* Mark hart feature detection done */ + hfeatures->detected = true; + return; } From patchwork Fri Apr 29 15:51:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624439 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=M8BHVJ0I; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=hxOzbNED; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcTB4hlpz9sBB for ; Sat, 30 Apr 2022 01:53:02 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=NvtCTxMaJgkD8nuoH/DVCHqhWz087we2czOTVPc1Hn0=; b=M8BHVJ0ItpTtDR lkK8FPcAiLZMdo7d+sHKnOKTBsgJySQ9TDI0Xl1pAWeN5NZQxfO/ySIky4YLPmguc6MOqMy1Y8syb a2tzI7dqMMKKnqM+jQNXOHrI8bUPK4XsAN52FZjfooLmM3oiGn8p8DRFYh/XUGo/M7wESic6StEdy ezQe3dorM8OjcsR8M5Kgcb78TEJlxmBVJXwxlqM8RsJojCZyuyxLegssAD0SZ4JADZspXCMKvF38b 2D6tvFz9wH+nTq0NzXu3svipqkb3+vt3djbSqmMqYDQ4nPojSyvm7KlfOV/J2QUmFRFx2P5t1Niba MUXRrbXyxLMaY7KFS8yw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvJ-00Bq0p-Az; Fri, 29 Apr 2022 15:52:49 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvG-00Bpwb-AZ for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:47 +0000 Received: by mail-pl1-x633.google.com with SMTP id n18so7495616plg.5 for ; Fri, 29 Apr 2022 08:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gc/Am/AN+roW4Ygu+J/MTMsQwNAGDdBananv7WDH8eI=; b=hxOzbNEDfoaD4ngkLXYEBsKDcHce4LzF72awh4vjdao2qgx4vldvK+v7kDFKXxYSml 0XKwwEUw5yv2D0Go8vrt22CfYY/Sl6nGNSLJZ9IYWO2Gb7UQkpO/NBCyExItKGLo0NfS ET+rvoNRrxsJsYTGPRIoV/P8q/90vMnX6SZ1/V5sA9ocL7OgyInWQzUdpFoXlzdMbLfC sC4G1MYVOSNKXFQIGqoKR4rvppktsWsCeqL8qS0m/Zxki8McuelVvcl8mvzkmuc+8eNh AgdKxhxgt9f5en1dgdv+jYEiurmjX4B60Q9vKT/AL+v/fl6x/QH2EyWYoVXcRysYvu6d KJlw== 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=gc/Am/AN+roW4Ygu+J/MTMsQwNAGDdBananv7WDH8eI=; b=bCQp87qlDT4vfNiCa6EJLZI4Ewy9d5TCPT7rOorIY5JN5TKIEdGhbbxT4232Abaau6 TLou3KWrnRGEXpFrN2oOpDiIPsLZX24rG6ku7TQWbASY8qMHk17mY33NmR1y1DnXFJr5 fB4Bko7FM3j3AjINA0Tagx213z/hK+HHYA/SbCC9vHqi0gkV5o28q2w2d9T4vxaqpYcd BfTnyYuzF7RBx/BXGFnAFOEKYQWlyJLEMv2/8RJlWJVPzjWfKavcxHzYkf+MyLuVKKrl artyki1aN5qraRvBDJiY6UxjbQXtjVJnW8YgpZDj+2twFRgdmXx2/rGK1htO99gHm3fV xlfQ== X-Gm-Message-State: AOAM531Q56s2zL6Z8Cw2El+hbT1BBASntSGqTZpmb3M8Nz3hRj+2SnQi odAG9J8Ga+iJM1ue35PcP6r6PA== X-Google-Smtp-Source: ABdhPJzViftgovbLhYjc3xNDb/TC7xIQ+w6GACMbCfIUSZxdiucLiJCipRylm1feajU7zK4fIhAbhg== X-Received: by 2002:a17:90b:1b10:b0:1dc:545:3f5b with SMTP id nu16-20020a17090b1b1000b001dc05453f5bmr4659025pjb.165.1651247564301; Fri, 29 Apr 2022 08:52:44 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:43 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 10/11] lib: sbi: Add sbi_hart_update_extension() function Date: Fri, 29 Apr 2022 21:21:50 +0530 Message-Id: <20220429155151.314788-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085246_398209_625FB865 X-CRM114-Status: GOOD ( 11.37 ) 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 add sbi_hart_update_extension() function which allow platforms to enable/disable hart extensions. Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 3 +++ lib/sbi/sbi_hart.c | 43 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) 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:633 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We add sbi_hart_update_extension() function which allow platforms to enable/disable hart extensions. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_hart.h | 3 +++ lib/sbi/sbi_hart.c | 43 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 8b21fd4..4661506 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -63,6 +63,9 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch); int sbi_hart_priv_version(struct sbi_scratch *scratch); void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, char *version_str, int nvstr); +void sbi_hart_update_extension(struct sbi_scratch *scratch, + enum sbi_hart_extensions ext, + bool enable); bool sbi_hart_has_extension(struct sbi_scratch *scratch, enum sbi_hart_extensions ext); void sbi_hart_get_extensions_str(struct sbi_scratch *scratch, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 28a7e75..3fc8899 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -367,6 +367,34 @@ void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, sbi_snprintf(version_str, nvstr, "%s", temp); } +static inline void __sbi_hart_update_extension( + struct hart_features *hfeatures, + enum sbi_hart_extensions ext, + bool enable) +{ + if (enable) + hfeatures->extensions |= BIT(ext); + else + hfeatures->extensions &= ~BIT(ext); +} + +/** + * Enable/Disable a particular hart extension + * + * @param scratch pointer to the HART scratch space + * @param ext the extension number to check + * @param enable new state of hart extension + */ +void sbi_hart_update_extension(struct sbi_scratch *scratch, + enum sbi_hart_extensions ext, + bool enable) +{ + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); + + __sbi_hart_update_extension(hfeatures, ext, enable); +} + /** * Check whether a particular hart extension is available * @@ -620,31 +648,36 @@ __mhpm_skip: /* Detect if hart supports sscofpmf */ csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap); if (!trap.cause) - hfeatures->extensions |= BIT(SBI_HART_EXT_SSCOFPMF); + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_SSCOFPMF, true); } /* Detect if hart supports time CSR */ csr_read_allowed(CSR_TIME, (unsigned long)&trap); if (!trap.cause) - hfeatures->extensions |= BIT(SBI_HART_EXT_TIME); + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_TIME, true); /* Detect if hart has AIA local interrupt CSRs */ csr_read_allowed(CSR_MTOPI, (unsigned long)&trap); if (!trap.cause) - hfeatures->extensions |= BIT(SBI_HART_EXT_AIA); + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_AIA, true); /* 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) - hfeatures->extensions |= BIT(SBI_HART_EXT_SSTC); + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_SSTC, true); } /* 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) - hfeatures->extensions |= BIT(SBI_HART_EXT_SMSTATEEN); + __sbi_hart_update_extension(hfeatures, + SBI_HART_EXT_SMSTATEEN, true); } /* Mark hart feature detection done */ From patchwork Fri Apr 29 15:51:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1624440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Q7in8PSI; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ventanamicro.com header.i=@ventanamicro.com header.a=rsa-sha256 header.s=google header.b=S14EeAuA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KqcTF2hXsz9sBB for ; Sat, 30 Apr 2022 01:53:05 +1000 (AEST) 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:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=6eKqGUxrp7PvVdv8bNHEQGXbgn3nDrqsG2Rw+RIb8io=; b=Q7in8PSIsKzBLj jiHnBYgd9sA7qoh2Acruwvg2WOrTVZ3UjUXiEbrGCCyeYKLyK/MZ6ZJpGqbv7kqaqWDB7jDRj1dHU FgKHbGPBRoVYnsxGWk8Lt+kH5TrDiMLWV6WprSjBwLyppV+rKwVLb721TmLhuLubv3FNwEMoHNQmJ ewMTV+HzaGn97eMss7hiihFnDiCJIUMr1nNJ/Wbe0CDDyP/cPzpgnr5L9pACP0Wet2k0uRraGM6h1 an6CpqvR/2Mqg9X0/xTwCaBdvzwB25bVHHcEaBjllDNSKLUp3/z+XKaNqyAmwLtK5cObF19j6yZbc HNKP80SUZhezpJROsLeA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvN-00Bq4p-92; Fri, 29 Apr 2022 15:52:53 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nkSvK-00BpzK-0l for opensbi@lists.infradead.org; Fri, 29 Apr 2022 15:52:51 +0000 Received: by mail-pl1-x62c.google.com with SMTP id l6so1115462pls.10 for ; Fri, 29 Apr 2022 08:52:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i05pSpsj9qG0xtrItJIyVuoB+ZnaildeUbO90flhI/M=; b=S14EeAuANOW5Ew3I8Kuv/fAVGNHAKq44hpWrqv9fcRUx3vh1TG+olieKj6ZAEQSixt pHoGO/K2ToXAEe7se5SMwai9zmRsVl7nMa6TGvNB8RnJLO3OBLc7mtJw3JwwbDXjoE0U CPvqNGHerY+6Z7DPQ2tYUmzpWqrDVF6X48lSMawytOyTMBMUD1qL7Aq9hToOc2LtBs78 h3+zBQI40DEh4EG1bnYfmS2lHKi1bJ/i2M1pA6vvsFDNNbYnocKZ7JhBrWbx1JwSU3Ee UdTtSGPCazLzs9QFYWeZkKs9ktS5fskzChON282NjcCzgetb9q4ZBY7M3wSlv29/T0kI npsg== 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=i05pSpsj9qG0xtrItJIyVuoB+ZnaildeUbO90flhI/M=; b=YzI/Mzv/TLrX/xOaRWoOBbifTmKXbF7qNKX8bRO5/p1BSu6OfGY5Yt+56tkBrgKCML iTwtrJgPyuaKlNofkM079JrpHqk3liOeCXzJ3kzBqBzHQXWS67AE5s7RzH4JxyEgrI88 U9USBSsiktMYBzME/st1S4WtRk2ujVGEOA09YKJvm6ia9KmfdRZbR0R5VkHgC5YWRcRN PbSCWl82ebwA/cteR0sQFeZSjx7HHvfyw++pDAzux4P/cdQfcwWVkAARD4LvnHIElAa6 k3oxnPayC67QeghT47sXgKoOiqOWEI2ZtDG71BtvXHU9Nvh94UZKwC2rdX7fZJVDVYd/ F66g== X-Gm-Message-State: AOAM531K7rw7b7jmM5GJkAdbgRiXFJJkM4d+UL849YbVIXmceA4skOXH 6yvr+0QVjzSc93e2ECKc+nqFDA== X-Google-Smtp-Source: ABdhPJx7KwV7LsOIfwsnPHlvgtGUlouJZYLECTk10IsEVwkCriQvXBBN9CgS4EzldZ9SqlLs7VfUmQ== X-Received: by 2002:a17:90b:1c04:b0:1d9:aeb8:58c7 with SMTP id oc4-20020a17090b1c0400b001d9aeb858c7mr4629219pjb.236.1651247567041; Fri, 29 Apr 2022 08:52:47 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([122.167.97.237]) by smtp.gmail.com with ESMTPSA id p2-20020a17090ad30200b001cd4989feb7sm15287280pju.3.2022.04.29.08.52.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Apr 2022 08:52:46 -0700 (PDT) From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Anup Patel Subject: [PATCH 11/11] lib: sbi_platform: Add callback to populate HART extensions Date: Fri, 29 Apr 2022 21:21:51 +0530 Message-Id: <20220429155151.314788-12-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220429155151.314788-1-apatel@ventanamicro.com> References: <20220429155151.314788-1-apatel@ventanamicro.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220429_085250_099163_CEDD7755 X-CRM114-Status: GOOD ( 12.88 ) 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 add platform specific extensions_init() callback which allows platforms to populate HART extensions for each HART. For example, the generic platform can populate HART extensions from HART ISA strin [...] 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:62c 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: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We add platform specific extensions_init() callback which allows platforms to populate HART extensions for each HART. For example, the generic platform can populate HART extensions from HART ISA string described in DeviceTree. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- include/sbi/sbi_platform.h | 18 ++++++++++++++++++ lib/sbi/sbi_hart.c | 18 ++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 2c777ac..87024db 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -89,6 +89,9 @@ struct sbi_platform_operations { */ int (*misa_get_xlen)(void); + /** Initialize (or populate) HART extensions for the platform */ + int (*extensions_init)(void); + /** Initialize (or populate) domains for the platform */ int (*domains_init)(void); @@ -453,6 +456,21 @@ static inline int sbi_platform_misa_xlen(const struct sbi_platform *plat) return -1; } +/** + * Initialize (or populate) HART extensions for the platform + * + * @param plat pointer to struct sbi_platform + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_extensions_init( + const struct sbi_platform *plat) +{ + if (plat && sbi_platform_ops(plat)->extensions_init) + return sbi_platform_ops(plat)->extensions_init(); + return 0; +} + /** * Initialize (or populate) domains for the platform * diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 3fc8899..8284792 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -536,16 +536,17 @@ static int hart_pmu_get_allowed_bits(void) return num_bits; } -static void hart_detect_features(struct sbi_scratch *scratch) +static int hart_detect_features(struct sbi_scratch *scratch) { struct sbi_trap_info trap = {0}; struct hart_features *hfeatures = sbi_scratch_offset_ptr(scratch, hart_features_offset); unsigned long val, oldval; + int rc; /* If hart features already detected then do nothing */ if (hfeatures->detected) - return; + return 0; /* Clear hart features */ hfeatures->extensions = 0; @@ -680,10 +681,15 @@ __mhpm_skip: SBI_HART_EXT_SMSTATEEN, true); } + /* Let platform populate extensions */ + rc = sbi_platform_extensions_init(sbi_platform_thishart_ptr()); + if (rc) + return rc; + /* Mark hart feature detection done */ hfeatures->detected = true; - return; + return 0; } int sbi_hart_reinit(struct sbi_scratch *scratch) @@ -705,6 +711,8 @@ int sbi_hart_reinit(struct sbi_scratch *scratch) int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot) { + int rc; + if (cold_boot) { if (misa_extension('H')) sbi_hart_expected_trap = &__sbi_expected_trap_hext; @@ -715,7 +723,9 @@ int sbi_hart_init(struct sbi_scratch *scratch, bool cold_boot) return SBI_ENOMEM; } - hart_detect_features(scratch); + rc = hart_detect_features(scratch); + if (rc) + return rc; return sbi_hart_reinit(scratch); }