From patchwork Thu Aug 29 19:46:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1978606 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=toj+NBDv; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=lrVmgJol; 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 4WvsHH5zl9z1yfy for ; Fri, 30 Aug 2024 05:46:51 +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:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FJzEzRDfy6dpkTpMxSYM//urSmUsc9rKtBraYX4auns=; b=toj+NBDvu5vyEL KI4E8pUcYlFgiNrFAAV6FHQc39swPNZxju1JnNmNC54YNH/jdOJaQYD8wUXNTZuwckUx4ei1phZWu vJnPHz+Fha9RX4IOF6afRArq2rUkb/dihHUQeJWA/YfmqGWY8DzCGMHElg0WLxgi0N50Qzd6uL6BV QAuASspDJd5hAOxznnbI7qr6DpG7Zmt1VEPd0FeVrru+HV6tw4eAQBonQlWDhB3fU+oJtFQNYDRNT GbeV3F+WfT+JukBVVoWDIIKJZoKNAIWVxOA3EIH2fp1mKRf+yDVL/et0P5jcATo0mtE5rTdecpwvs a68CnyQDo8bXvQUmrh8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjl6R-00000003Q16-2nAn; Thu, 29 Aug 2024 19:46:43 +0000 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjl6M-00000003Pxi-25pd for opensbi@lists.infradead.org; Thu, 29 Aug 2024 19:46:40 +0000 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2d3d662631aso800688a91.1 for ; Thu, 29 Aug 2024 12:46:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1724960797; x=1725565597; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AvkouTHwaHJojIq5naAntBZ/Y3QiY1U0qV30KzHZR4g=; b=lrVmgJoljLJjgGnA3cQy4Ol9mhH4GSTr4fa0dV9h7OKcz3/gJ4efS13qIyiRMYJB6B X8yZEb05IHi5MMch7pHD3oMYcHXHOUEOJ/bnoBH24VlpOGNQOPm2E/iTLDlui/2P6Dvl 7jgIeg+u2BaSKGUpjA4DckaNzTmrC77TZYS72aqFqWUvLXihb6PU0zCKeNsFFztj/CIq 1DXCEFK+WZMg/oa/LedZ0d1lvcH78FVsBp5YG3WhSjBTxBXAzKrxtaMejc5Y+oduTZps EoDG/Au1Pj+LYxjCWI2vFR2MLgEbuDM0flp49WqPgKe+tTzBQCudQbM3NUgWXVOE2gJE xDvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724960797; x=1725565597; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AvkouTHwaHJojIq5naAntBZ/Y3QiY1U0qV30KzHZR4g=; b=pB9euEtMwTe98TYvT+DXaztaYazCWDvByoaBdxbWzVbBdb4g2ttH4N+nb4nLvp3ssk TD+jUPwCl/wk81GkpahUDZDi9yFZaHF3Y3kFveiRVLt7gtlMhKbf6XmQWvbLyywQEPrs OfxTOF2VSXVRcyfb639UJQ8dErcVHsP4OZKp7rfheagVmMiQ1NYjgqmc74B/F5B18UUF c5NgsJjQSlMhFE8HgId5nCiHMKWhil3aml6seAZdMTG+9ihr9789IORVwwUBotREkemS X0KYp+q7k3vWQiio3nKgy3Gk3GRHrHelrcjeESZRXgpU4bE2kjWlJLYhyse7MD3lcGBc SSig== X-Gm-Message-State: AOJu0YwbvQ1mu8zszHPNT9kLebjdL1Bxf2YKQv8mwe3EQoAzyfmuiIxe 3E1RCBeRJNTh1EeXn1cV5BHtM41t0FgaSVwxm4u79C++EJ3sxD0lQyIgCtthNyS5EXgvxM7xU40 mtVhcHblNH34g/MlW/x+RkycYyIM5mWcEpmSMRe1GdK78AkW0prsna7XS2WYkhulgi+6ZvK4190 eqBhX/6c0gMgl2yt2sulhbvqlKeA+fhbpC9ePyc7V1Icnt3mmLzcs= X-Google-Smtp-Source: AGHT+IGdPiPksj9i7uBuOWKlubN6FHxT5rfaYlobCF/NbeFWyUMJu82/Wlkt3zj7VeftPYukaTz9vQ== X-Received: by 2002:a17:90a:a00a:b0:2d3:c933:6c72 with SMTP id 98e67ed59e1d1-2d85616ec28mr4219421a91.8.1724960796806; Thu, 29 Aug 2024 12:46:36 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d85b39d051sm2086356a91.40.2024.08.29.12.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 12:46:36 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH 2/2] lib: sbi: Use a linked list to track domains Date: Thu, 29 Aug 2024 12:46:24 -0700 Message-ID: <20240829194634.3644683-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240829194634.3644683-1-samuel.holland@sifive.com> References: <20240829194634.3644683-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240829_124638_562719_FEADBD7E X-CRM114-Status: GOOD ( 19.47 ) X-Spam-Score: -2.1 (--) 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: This removes the compile-time limit on the number of domains. It also reduces firmware size by about 200 bytes by removing the lookup table. Signed-off-by: Samuel Holland --- Content analysis details: (-2.1 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:1035 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 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.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. 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 This removes the compile-time limit on the number of domains. It also reduces firmware size by about 200 bytes by removing the lookup table. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- include/sbi/sbi_domain.h | 18 +++++++----------- lib/sbi/sbi_domain.c | 30 +++++++++--------------------- lib/sbi/sbi_domain_context.c | 6 +++--- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h index 34ebd39d..313ae156 100644 --- a/include/sbi/sbi_domain.h +++ b/include/sbi/sbi_domain.h @@ -11,6 +11,7 @@ #define __SBI_DOMAIN_H__ #include +#include #include #include #include @@ -158,11 +159,10 @@ struct sbi_domain_memregion { unsigned long flags; }; -/** Maximum number of domains */ -#define SBI_DOMAIN_MAX_INDEX 32 - /** Representation of OpenSBI domain */ struct sbi_domain { + /** Node in linked list of domains */ + struct sbi_dlist node; /** Logical index of this domain */ u32 index; /** HARTs assigned to this domain */ @@ -206,16 +206,12 @@ void sbi_update_hartindex_to_domain(u32 hartindex, struct sbi_domain *dom); #define sbi_domain_thishart_ptr() \ sbi_hartindex_to_domain(sbi_hartid_to_hartindex(current_hartid())) -/** Index to domain table */ -extern struct sbi_domain *domidx_to_domain_table[]; - -/** Get pointer to sbi_domain from index */ -#define sbi_index_to_domain(__index) \ - domidx_to_domain_table[__index] +/** Head of linked list of domains */ +extern struct sbi_dlist domain_list; /** Iterate over each domain */ -#define sbi_domain_for_each(__i, __d) \ - for ((__i) = 0; ((__d) = sbi_index_to_domain(__i)); (__i)++) +#define sbi_domain_for_each(__d) \ + sbi_list_for_each_entry(__d, &domain_list, node) /** Iterate over each memory region of a domain */ #define sbi_domain_for_each_memregion(__d, __r) \ diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c index 374ac36b..7198e27e 100644 --- a/lib/sbi/sbi_domain.c +++ b/lib/sbi/sbi_domain.c @@ -13,16 +13,14 @@ #include #include #include +#include #include #include #include #include -/* - * We allocate an extra element because sbi_domain_for_each() expects - * the array to be null-terminated. - */ -struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX + 1] = { 0 }; +SBI_LIST_HEAD(domain_list); + static u32 domain_count = 0; static bool domain_finalized = false; @@ -519,10 +517,9 @@ void sbi_domain_dump(const struct sbi_domain *dom, const char *suffix) void sbi_domain_dump_all(const char *suffix) { - u32 i; const struct sbi_domain *dom; - sbi_domain_for_each(i, dom) { + sbi_domain_for_each(dom) { sbi_domain_dump(dom, suffix); sbi_printf("\n"); } @@ -541,21 +538,11 @@ int sbi_domain_register(struct sbi_domain *dom, return SBI_EINVAL; /* Check if domain already discovered */ - sbi_domain_for_each(i, tdom) { + sbi_domain_for_each(tdom) { if (tdom == dom) return SBI_EALREADY; } - /* - * Ensure that we have room for Domain Index to - * HART ID mapping - */ - if (SBI_DOMAIN_MAX_INDEX <= domain_count) { - sbi_printf("%s: No room for %s\n", - __func__, dom->name); - return SBI_ENOSPC; - } - /* Sanitize discovered domain */ rc = sanitize_domain(dom); if (rc) { @@ -565,9 +552,10 @@ int sbi_domain_register(struct sbi_domain *dom, return rc; } + sbi_list_add_tail(&dom->node, &domain_list); + /* Assign index to domain */ dom->index = domain_count++; - domidx_to_domain_table[dom->index] = dom; /* Initialize spinlock for dom->assigned_harts */ SPIN_LOCK_INIT(dom->assigned_harts_lock); @@ -692,7 +680,7 @@ int sbi_domain_root_add_memrange(unsigned long addr, unsigned long size, int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid) { int rc; - u32 i, dhart; + u32 dhart; struct sbi_domain *dom; const struct sbi_platform *plat = sbi_platform_ptr(scratch); @@ -705,7 +693,7 @@ int sbi_domain_finalize(struct sbi_scratch *scratch, u32 cold_hartid) } /* Startup boot HART of domains */ - sbi_domain_for_each(i, dom) { + sbi_domain_for_each(dom) { /* Domain boot HART index */ dhart = sbi_hartid_to_hartindex(dom->boot_hartid); diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index 49a2f769..1432e3a8 100755 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -107,7 +107,7 @@ int sbi_domain_context_enter(struct sbi_domain *dom) int sbi_domain_context_exit(void) { - u32 i, hartindex = sbi_hartid_to_hartindex(current_hartid()); + u32 hartindex = sbi_hartid_to_hartindex(current_hartid()); struct sbi_domain *dom; struct sbi_context *ctx = sbi_domain_context_thishart_ptr(); struct sbi_context *dom_ctx, *tmp; @@ -118,7 +118,7 @@ int sbi_domain_context_exit(void) * its context on the current hart if valid. */ if (!ctx) { - sbi_domain_for_each(i, dom) { + sbi_domain_for_each(dom) { if (!sbi_hartmask_test_hartindex(hartindex, dom->possible_harts)) continue; @@ -140,7 +140,7 @@ int sbi_domain_context_exit(void) /* If no previous caller context */ if (!dom_ctx) { /* Try to find next uninitialized user-defined domain's context */ - sbi_domain_for_each(i, dom) { + sbi_domain_for_each(dom) { if (dom == &root || dom == sbi_domain_thishart_ptr()) continue;