All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v2 07/18] lib: sbi: Use scratch space to save per-HART domain pointer
Date: Mon,  5 Jun 2023 17:07:38 +0530	[thread overview]
Message-ID: <20230605113749.230696-8-apatel@ventanamicro.com> (raw)
In-Reply-To: <20230605113749.230696-1-apatel@ventanamicro.com>

Instead of using a global array indexed by hartid, we should use
scratch space to save per-HART domain pointer.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
 include/sbi/sbi_domain.h |  6 +----
 lib/sbi/sbi_domain.c     | 55 ++++++++++++++++++++++++++++++++--------
 2 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/include/sbi/sbi_domain.h b/include/sbi/sbi_domain.h
index 124ea90..b05bcf4 100644
--- a/include/sbi/sbi_domain.h
+++ b/include/sbi/sbi_domain.h
@@ -129,12 +129,8 @@ struct sbi_domain {
 /** The root domain instance */
 extern struct sbi_domain root;
 
-/** HART id to domain table */
-extern struct sbi_domain *hartid_to_domain_table[];
-
 /** Get pointer to sbi_domain from HART id */
-#define sbi_hartid_to_domain(__hartid) \
-	hartid_to_domain_table[__hartid]
+struct sbi_domain *sbi_hartid_to_domain(u32 hartid);
 
 /** Get pointer to sbi_domain for current HART */
 #define sbi_domain_thishart_ptr() \
diff --git a/lib/sbi/sbi_domain.c b/lib/sbi/sbi_domain.c
index 5800870..38a5902 100644
--- a/lib/sbi/sbi_domain.c
+++ b/lib/sbi/sbi_domain.c
@@ -23,7 +23,6 @@
  * the array to be null-terminated.
  */
 struct sbi_domain *domidx_to_domain_table[SBI_DOMAIN_MAX_INDEX + 1] = { 0 };
-struct sbi_domain *hartid_to_domain_table[SBI_HARTMASK_MAX_BITS] = { 0 };
 static u32 domain_count = 0;
 static bool domain_finalized = false;
 
@@ -39,6 +38,30 @@ struct sbi_domain root = {
 	.fw_region_inited = false,
 };
 
+static unsigned long domain_hart_ptr_offset;
+
+struct sbi_domain *sbi_hartid_to_domain(u32 hartid)
+{
+	struct sbi_scratch *scratch;
+
+	scratch = sbi_hartid_to_scratch(hartid);
+	if (!scratch || !domain_hart_ptr_offset)
+		return NULL;
+
+	return sbi_scratch_read_type(scratch, void *, domain_hart_ptr_offset);
+}
+
+static void update_hartid_to_domain(u32 hartid, struct sbi_domain *dom)
+{
+	struct sbi_scratch *scratch;
+
+	scratch = sbi_hartid_to_scratch(hartid);
+	if (!scratch)
+		return;
+
+	sbi_scratch_write_type(scratch, void *, domain_hart_ptr_offset, dom);
+}
+
 bool sbi_domain_is_assigned_hart(const struct sbi_domain *dom, u32 hartid)
 {
 	if (dom)
@@ -519,11 +542,11 @@ int sbi_domain_register(struct sbi_domain *dom,
 		if (!sbi_hartmask_test_hart(i, dom->possible_harts))
 			continue;
 
-		tdom = hartid_to_domain_table[i];
+		tdom = sbi_hartid_to_domain(i);
 		if (tdom)
 			sbi_hartmask_clear_hart(i,
 					&tdom->assigned_harts);
-		hartid_to_domain_table[i] = dom;
+		update_hartid_to_domain(i, dom);
 		sbi_hartmask_set_hart(i, &dom->assigned_harts);
 
 		/*
@@ -715,18 +738,23 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
 		return SBI_EINVAL;
 	}
 
+	domain_hart_ptr_offset = sbi_scratch_alloc_type_offset(void *);
+	if (!domain_hart_ptr_offset)
+		return SBI_ENOMEM;
+
 	root_memregs = sbi_calloc(sizeof(*root_memregs), ROOT_REGION_MAX + 1);
 	if (!root_memregs) {
 		sbi_printf("%s: no memory for root regions\n", __func__);
-		return SBI_ENOMEM;
+		rc = SBI_ENOMEM;
+		goto fail_free_domain_hart_ptr_offset;
 	}
 	root.regions = root_memregs;
 
 	root_hmask = sbi_zalloc(sizeof(*root_hmask));
 	if (!root_hmask) {
 		sbi_printf("%s: no memory for root hartmask\n", __func__);
-		sbi_free(root_memregs);
-		return SBI_ENOMEM;
+		rc = SBI_ENOMEM;
+		goto fail_free_root_memregs;
 	}
 	root.possible_harts = root_hmask;
 
@@ -771,11 +799,16 @@ int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid)
 
 	/* Finally register the root domain */
 	rc = sbi_domain_register(&root, root_hmask);
-	if (rc) {
-		sbi_free(root_hmask);
-		sbi_free(root_memregs);
-		return rc;
-	}
+	if (rc)
+		goto fail_free_root_hmask;
 
 	return 0;
+
+fail_free_root_hmask:
+	sbi_free(root_hmask);
+fail_free_root_memregs:
+	sbi_free(root_memregs);
+fail_free_domain_hart_ptr_offset:
+	sbi_scratch_free_offset(domain_hart_ptr_offset);
+	return rc;
 }
-- 
2.34.1



  parent reply	other threads:[~2023-06-05 11:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-05 11:37 [PATCH v2 00/18] Introduce and use simple heap allocator Anup Patel
2023-06-05 11:37 ` [PATCH v2 01/18] include: sbi_scratch: Add helper macros to access data type Anup Patel
2023-06-05 11:37 ` [PATCH v2 02/18] platform: Allow platforms to specify heap size Anup Patel
2023-06-05 11:37 ` [PATCH v2 03/18] lib: sbi: Introduce simple heap allocator Anup Patel
2023-06-05 11:37 ` [PATCH v2 04/18] lib: sbi: Print scratch size and usage at boot time Anup Patel
2023-06-05 11:37 ` [PATCH v2 05/18] lib: sbi_pmu: Use heap for per-HART PMU state Anup Patel
2023-06-05 11:37 ` [PATCH v2 06/18] lib: sbi: Use heap for root domain creation Anup Patel
2023-06-05 11:37 ` Anup Patel [this message]
2023-06-05 11:37 ` [PATCH v2 08/18] lib: utils/gpio: Use heap in SiFive and StartFive GPIO drivers Anup Patel
2023-06-05 11:37 ` [PATCH v2 09/18] lib: utils/i2c: Use heap in DesignWare and SiFive I2C drivers Anup Patel
2023-06-05 11:37 ` [PATCH v2 10/18] lib: utils/ipi: Use heap in ACLINT MSWI driver Anup Patel
2023-06-05 11:37 ` [PATCH v2 11/18] lib: utils/irqchip: Use heap in PLIC, APLIC and IMSIC drivers Anup Patel
2023-06-05 11:37 ` [PATCH v2 12/18] lib: utils/timer: Use heap in ACLINT MTIMER driver Anup Patel
2023-06-05 11:37 ` [PATCH v2 13/18] lib: utils/fdt: Use heap in FDT domain parsing Anup Patel
2023-06-05 11:37 ` [PATCH v2 14/18] lib: utils/ipi: Use scratch space to save per-HART MSWI pointer Anup Patel
2023-06-05 11:37 ` [PATCH v2 15/18] lib: utils/timer: Use scratch space to save per-HART MTIMER pointer Anup Patel
2023-06-05 11:37 ` [PATCH v2 16/18] lib: utils/irqchip: Use scratch space to save per-HART PLIC pointer Anup Patel
2023-06-05 11:37 ` [PATCH v2 17/18] lib: utils/irqchip: Don't check hartid in imsic_update_hartid_table() Anup Patel
2023-06-05 11:37 ` [PATCH v2 18/18] lib: utils/irqchip: Use scratch space to save per-HART IMSIC pointer Anup Patel
2023-06-06 10:33 ` [PATCH v2 00/18] Introduce and use simple heap allocator Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230605113749.230696-8-apatel@ventanamicro.com \
    --to=apatel@ventanamicro.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.