From patchwork Thu Aug 31 03:39:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1828109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=UdqesD1j; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=LQ5NMD31; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RbnQN3Bbvz1yfm for ; Thu, 31 Aug 2023 13:56:12 +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=dWs8cfbwy7aE4otHBP+a2ld5w9FVM/f/cenfHy/1JdQ=; b=UdqesD1jf/1gLO t1RP6p8Krt7woMLrJshgnenRCHbvDSszrVzTxA/hqiFquj8gGyTI8TRoWEnrmBC5ypTpfTq8Bcr0L Ym37QiY5lNl55AdLus+gPd72v6dkvatTk4Qf6o7M+23VnNch1h+T6KUEUkNfzryvctKaUSqpn7AYD hq0ibHx6GgOXKNzYcOYaY6efEXqVWNJ9YVJYPHy1q2XCyLodPCPNYi7xxtVyy1Q9+Aih1hhlg2/h3 w04ayaUTlBaqDrx5oVSVWix4FemU2xkrRBe+oNkVaf1Fs3xnPJQyYvCuWxABDEQ6fm8sL1BMdgs9h S49vFdCO709bE01aqeVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbYmj-00Eb6r-2N; Thu, 31 Aug 2023 03:55:57 +0000 Received: from m126.mail.126.com ([220.181.12.26]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbYmf-00Eb6L-2z for opensbi@lists.infradead.org; Thu, 31 Aug 2023 03:55:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=cIlI0 cd7jjPF3QnOjGKRpkzms3D94VKm17ZqyxQ1Uho=; b=LQ5NMD31YUO8vsHUvaKAl j4sbYZCTQCeMR1z0XDjWcoMyDmMrQgDiSruBkuUsYPW9/oeAcoEkLE/nqMH/oi3a zrL7TIqSAkneAf8UJKAM4VQCZKdlBM2nlhOXDyGbGHUPO64uyvR7Z6tXUujRGWCC xjS3rAMviePKcIV7kDwYQA= Received: from t490.lan (unknown [210.22.74.39]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wAXPo13C_BksMbuAA--.5764S3; Thu, 31 Aug 2023 11:39:36 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [RFC PATCH 1/2] ilib: sbi: add sbi_platform_hart_index2id Date: Thu, 31 Aug 2023 11:39:29 +0800 Message-Id: <20230831033930.694299-2-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230831033930.694299-1-wxjstz@126.com> References: <20230831033930.694299-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wAXPo13C_BksMbuAA--.5764S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF4rWFWxZF1xtrWrKr17ZFb_yoW8Gr4DpF 1kCF4Syw40grn2y34UJ3W7ur4Y9w1SqFyUKrWUJw1Iy39xZas8trn0gF10y3sxXrsrA347 XF429r4DuF45ZrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pidMa8UUUUU= X-Originating-IP: [210.22.74.39] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBcxvcOmSQAPb0hAABs9 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230830_205554_783094_810E9E2A X-CRM114-Status: UNSURE ( 5.56 ) 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: Add sbi_platform_hart_index2id to find hart index by hartid. Signed-off-by: Xiang W --- include/sbi/sbi_platform.h | 10 ++++++++++ lib/sbi/sbi_platform.c | 9 +++++++++ 2 files changed, 19 insertions(+) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] -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 Add sbi_platform_hart_index2id to find hart index by hartid. Signed-off-by: Xiang W --- include/sbi/sbi_platform.h | 10 ++++++++++ lib/sbi/sbi_platform.c | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 3e9616f..6df5d8b 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -268,6 +268,16 @@ _Static_assert( */ u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid); +/** + * Get HART id for the given index + * + * @param plat porinter to struct sbi_platform + * @param index HART index + * + * @return -1U is invalid value +*/ +u32 sbi_platform_hart_index2id(const struct sbi_platform *plat, u32 index); + /** * Get the platform features in string format * diff --git a/lib/sbi/sbi_platform.c b/lib/sbi/sbi_platform.c index 445a8c1..25bbf99 100644 --- a/lib/sbi/sbi_platform.c +++ b/lib/sbi/sbi_platform.c @@ -88,3 +88,12 @@ u32 sbi_platform_hart_index(const struct sbi_platform *plat, u32 hartid) return hartid; } + +u32 sbi_platform_hart_index2id(const struct sbi_platform *plat, u32 index) +{ + if (!plat || index >= plat->hart_count) + return -1U; + if (plat->hart_index2id) + return plat->hart_index2id[index]; + return index; +} From patchwork Thu Aug 31 03:39:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang W X-Patchwork-Id: 1828090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Xkdviafx; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=126.com header.i=@126.com header.a=rsa-sha256 header.s=s110527 header.b=cf9vjM0y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Rbn3z3ZvRz1ygF for ; Thu, 31 Aug 2023 13:40:15 +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=Fc6ed5C2ZCEI8Lx8QY4po8y0TDv9mFmOq/tAN3EfQW4=; b=XkdviafxTeqo9u dfnVUS2w9YXWaj8VVHrwToyLn3a/i2EFD5r40zdS5QdXV3I5Ln+/A54XGzV7pxvhu/cWD14hp6lz2 sA/jhDJHZ/ja64mmWCSKdVFe5v4vOwxV65P5SzlT5FkaN0MW0dUHtLRik/L5gL0ALo/mKahWACZN2 4bRdMQhDsAI8PE0EBUneXywOTtcwRPHwp5qqrKQQSGG0/0HugqwZBk5JKcH2pBIynu6SXUAPrL/CH IXWpph5nYbNtmh60zRQiCooNatb+IvkXR1s/Vbn45DKPtEaiv5k/mLh32Ge//8p9OHqAYjdzOM+oF JdfWpLI7lyH9bsRK3VUg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbYXC-00EZKf-1t; Thu, 31 Aug 2023 03:39:54 +0000 Received: from m126.mail.126.com ([220.181.12.36]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qbYX9-00EZJK-0Y for opensbi@lists.infradead.org; Thu, 31 Aug 2023 03:39:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=ESjFR T3yicXdlqSLyCLbFtvdJ2JVNvQkBAI+PB5UECA=; b=cf9vjM0yNa0zwhULTa/l9 eC4vu2obX4BB2f40MPk8wvDt+O+PhM3c1NB1zp0RiSGR2PSra6KNVU27vPRxj97v BByPMkl6D5NsQ+KVpfy+Tv41uMnJfMAemkhXw/vC8ePEoRBmJIkYPvBsh2tk6xH4 NhtY6/qaxRZGWzCKZcxMKw= Received: from t490.lan (unknown [210.22.74.39]) by zwqz-smtp-mta-g2-0 (Coremail) with SMTP id _____wAXPo13C_BksMbuAA--.5764S4; Thu, 31 Aug 2023 11:39:37 +0800 (CST) From: Xiang W To: opensbi@lists.infradead.org Cc: Xiang W Subject: [RFC PATCH 2/2] lib: sbi: improve sbi_hartmask Date: Thu, 31 Aug 2023 11:39:30 +0800 Message-Id: <20230831033930.694299-3-wxjstz@126.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230831033930.694299-1-wxjstz@126.com> References: <20230831033930.694299-1-wxjstz@126.com> MIME-Version: 1.0 X-CM-TRANSID: _____wAXPo13C_BksMbuAA--.5764S4 X-Coremail-Antispam: 1Uf129KBjvJXoW3GFyxWF17Xr1kAw1UWrWxWFg_yoWfXr1xpF 15CFnrKw4I9F1Fy34DGw4kuF4akas5trnxG34xGw10yw45Awn5Xr48W342yFy2qFWFy3WY kw4jyr4UuF45ZFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zND7VLUUUUU= X-Originating-IP: [210.22.74.39] X-CM-SenderInfo: pz0m23b26rjloofrz/xtbBdATcOmSdLaEGIAACsH X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230830_203951_531077_BF4B42C8 X-CRM114-Status: GOOD ( 16.12 ) 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 original sbi_hartmask stores the hartid, instead it stores the hart index. this allows better utilization of the hartmask and avoids useless gaps. And it can also cope with some strange platforms, [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [wxjstz[at]126.com] 0.0 RCVD_IN_MSPIKE_L3 RBL: Low reputation (-3) [220.181.12.36 listed in bl.mailspike.net] -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 0.0 RCVD_IN_MSPIKE_BL Mailspike blacklisted 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 original sbi_hartmask stores the hartid, instead it stores the hart index. this allows better utilization of the hartmask and avoids useless gaps. And it can also cope with some strange platforms, for example, there is a hart with a particularly large id. Signed-off-by: Xiang W --- include/sbi/sbi_hartmask.h | 40 ++++++++++++++++++++++++++++---------- lib/sbi/sbi_domain.c | 26 +++++++++---------------- lib/sbi/sbi_init.c | 2 +- lib/sbi/sbi_ipi.c | 4 ++-- lib/sbi/sbi_system.c | 4 ++-- lib/sbi/sbi_tlb.c | 4 ++-- 6 files changed, 46 insertions(+), 34 deletions(-) diff --git a/include/sbi/sbi_hartmask.h b/include/sbi/sbi_hartmask.h index f1cef0c..1ba7549 100644 --- a/include/sbi/sbi_hartmask.h +++ b/include/sbi/sbi_hartmask.h @@ -11,6 +11,7 @@ #define __SBI_HARTMASK_H__ #include +#include /** * Maximum number of bits in a hartmask @@ -32,7 +33,11 @@ struct sbi_hartmask { /** Initialize hartmask to zero except a particular HART id */ #define SBI_HARTMASK_INIT_EXCEPT(__m, __h) \ - bitmap_zero_except(((__m)->bits), (__h), SBI_HARTMASK_MAX_BITS) + do { \ + u32 __i = sbi_platform_hart_index( \ + sbi_platform_ptr(sbi_scratch_thishart_ptr()), __h); \ + bitmap_zero_except(((__m)->bits), (__i), SBI_HARTMASK_MAX_BITS); \ + } while(0) /** * Get underlying bitmap of hartmask @@ -47,8 +52,10 @@ struct sbi_hartmask { */ static inline void sbi_hartmask_set_hart(u32 h, struct sbi_hartmask *m) { - if (h < SBI_HARTMASK_MAX_BITS) - __set_bit(h, m->bits); + u32 i = sbi_platform_hart_index( + sbi_platform_ptr(sbi_scratch_thishart_ptr()), h); + if (i < SBI_HARTMASK_MAX_BITS) + __set_bit(i, m->bits); } /** @@ -58,8 +65,10 @@ static inline void sbi_hartmask_set_hart(u32 h, struct sbi_hartmask *m) */ static inline void sbi_hartmask_clear_hart(u32 h, struct sbi_hartmask *m) { - if (h < SBI_HARTMASK_MAX_BITS) - __clear_bit(h, m->bits); + u32 i = sbi_platform_hart_index( + sbi_platform_ptr(sbi_scratch_thishart_ptr()), h); + if (i < SBI_HARTMASK_MAX_BITS) + __clear_bit(i, m->bits); } /** @@ -69,8 +78,10 @@ static inline void sbi_hartmask_clear_hart(u32 h, struct sbi_hartmask *m) */ static inline int sbi_hartmask_test_hart(u32 h, const struct sbi_hartmask *m) { - if (h < SBI_HARTMASK_MAX_BITS) - return __test_bit(h, m->bits); + u32 i = sbi_platform_hart_index( + sbi_platform_ptr(sbi_scratch_thishart_ptr()), h); + if (i < SBI_HARTMASK_MAX_BITS) + return __test_bit(i, m->bits); return 0; } @@ -134,8 +145,17 @@ static inline void sbi_hartmask_xor(struct sbi_hartmask *dstp, sbi_hartmask_bits(src2p), SBI_HARTMASK_MAX_BITS); } -/** Iterate over each HART in hartmask */ -#define sbi_hartmask_for_each_hart(__h, __m) \ - for_each_set_bit(__h, (__m)->bits, SBI_HARTMASK_MAX_BITS) +/** + * Iterate over each HART in hartmask + * __h hart id + * __i hart index + * __m hartmask +*/ +#define sbi_hartmask_for_each_hart(__h,__i, __m) \ + for((__i) = find_first_bit((__m)->bits, SBI_HARTMASK_MAX_BITS); \ + (__h) = sbi_platform_hart_index2id(\ + sbi_platform_ptr(sbi_scratch_thishart_ptr()),(__i)), \ + (__i) < SBI_HARTMASK_MAX_BITS; \ + (__i) = find_next_bit((__m)->bits, SBI_HARTMASK_MAX_BITS, (__i) + 1)) #endif diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index acd0f74..7495359 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -73,18 +73,10 @@ bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid) ulong sbi_domain_get_assigned_hartmask(const struct sbi_domain *dom, ulong hbase) { - ulong ret, bword, boff; - - if (!dom) - return 0; - - bword = BIT_WORD(hbase); - boff = BIT_WORD_OFFSET(hbase); - - ret = sbi_hartmask_bits(&dom->assigned_harts)[bword++] >> boff; - if (boff && bword < BIT_WORD(SBI_HARTMASK_MAX_BITS)) { - ret |= (sbi_hartmask_bits(&dom->assigned_harts)[bword] & - (BIT(boff) - 1UL)) << (BITS_PER_LONG - boff); + ulong ret = 0; + for (int i = 0; i < 8 * sizeof(ret); i++) { + if (sbi_domain_is_assigned_hart(dom, hbase + i)) + ret |= 1 << i; } return ret; @@ -276,7 +268,7 @@ static int sanitize_domain(const struct sbi_platform *plat, __func__, dom->name); return SBI_EINVAL; } - sbi_hartmask_for_each_hart(i, dom->possible_harts) { + sbi_hartmask_for_each_hart(i, j, dom->possible_harts) { if (sbi_platform_hart_invalid(plat, i)) { sbi_printf("%s: %s possible HART mask has invalid " "hart %d\n", __func__, dom->name, i); @@ -400,7 +392,7 @@ bool sbi_domain_check_addr_range(const struct sbi_domain *dom, void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) { - u32 i, k; + u32 i, j, k; unsigned long rstart, rend; struct sbi_domain_memregion *reg; @@ -412,7 +404,7 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) k = 0; sbi_printf("Domain%d HARTs %s: ", dom->index, suffix); - sbi_hartmask_for_each_hart(i, dom->possible_harts) + sbi_hartmask_for_each_hart(i, j, dom->possible_harts) sbi_printf("%s%d%s", (k++) ? "," : "", i, sbi_domain_is_assigned_hart(dom, i) ? "*" : ""); sbi_printf("\n"); @@ -495,7 +487,7 @@ void sbi_domain_dump_all(const char *suffix) int sbi_domain_register(struct sbi_domain *dom, const struct sbi_hartmask *assign_mask) { - u32 i; + u32 i, j; int rc; struct sbi_domain *tdom; u32 cold_hartid = current_hartid(); @@ -538,7 +530,7 @@ int sbi_domain_register(struct sbi_domain *dom, sbi_hartmask_clear_all(&dom->assigned_harts); /* Assign domain to HART if HART is a possible HART */ - sbi_hartmask_for_each_hart(i, assign_mask) { + sbi_hartmask_for_each_hart(i, j, assign_mask) { if (!sbi_hartmask_test_hart(i, dom->possible_harts)) continue; diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 35e6633..d4c18f0 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -524,7 +524,7 @@ void __noreturn sbi_init(struct sbi_scratch *scratch) u32 hartid = current_hartid(); const struct sbi_platform *plat = sbi_platform_ptr(scratch); - if ((SBI_HARTMASK_MAX_BITS <= hartid) || + if ((SBI_HARTMASK_MAX_BITS <= sbi_platform_hart_index(plat, hartid)) || sbi_platform_hart_invalid(plat, hartid)) sbi_hart_hang(); diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index ad09154..350dfb5 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -96,7 +96,7 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) { int rc; bool retry_needed; - ulong i, m; + ulong i, j, m; struct sbi_hartmask target_mask = {0}; struct sbi_domain *dom = sbi_domain_thishart_ptr(); struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); @@ -126,7 +126,7 @@ int sbi_ipi_send_many(ulong hmask, ulong hbase, u32 event, void *data) /* Send IPIs */ do { retry_needed = false; - sbi_hartmask_for_each_hart(i, &target_mask) { + sbi_hartmask_for_each_hart(i, j, &target_mask) { rc = sbi_ipi_send(scratch, i, event, data); if (rc == SBI_IPI_UPDATE_RETRY) retry_needed = true; diff --git a/lib/sbi/sbi_system.c b/lib/sbi/sbi_system.c index d803ffa..1354731 100644 --- a/lib/sbi/sbi_system.c +++ b/lib/sbi/sbi_system.c @@ -152,7 +152,7 @@ int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque) void (*jump_warmboot)(void) = (void (*)(void))scratch->warmboot_addr; unsigned int hartid = current_hartid(); unsigned long prev_mode; - unsigned long i; + unsigned long i, j; int ret; if (!dom || !dom->system_suspend_allowed) @@ -170,7 +170,7 @@ int sbi_system_suspend(u32 sleep_type, ulong resume_addr, ulong opaque) if (prev_mode != PRV_S && prev_mode != PRV_U) return SBI_EFAIL; - sbi_hartmask_for_each_hart(i, &dom->assigned_harts) { + sbi_hartmask_for_each_hart(i, j, &dom->assigned_harts) { if (i == hartid) continue; if (__sbi_hsm_hart_get_state(i) != SBI_HSM_STATE_STOPPED) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 26a87f3..f8a1aab 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -213,13 +213,13 @@ static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data) static void tlb_entry_process(struct sbi_tlb_info *tinfo) { - u32 rhartid; + u32 rhartid, rindex; struct sbi_scratch *rscratch = NULL; atomic_t *rtlb_sync = NULL; tinfo->local_fn(tinfo); - sbi_hartmask_for_each_hart(rhartid, &tinfo->smask) { + sbi_hartmask_for_each_hart(rhartid, rindex, &tinfo->smask) { rscratch = sbi_hartid_to_scratch(rhartid); if (!rscratch) continue;