All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v2 14/18] lib: utils/ipi: Use scratch space to save per-HART MSWI pointer
Date: Mon,  5 Jun 2023 17:07:45 +0530	[thread overview]
Message-ID: <20230605113749.230696-15-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 MSWI pointer.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
 lib/utils/ipi/aclint_mswi.c | 43 ++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 10 deletions(-)

diff --git a/lib/utils/ipi/aclint_mswi.c b/lib/utils/ipi/aclint_mswi.c
index ac8570b..f47b3bc 100644
--- a/lib/utils/ipi/aclint_mswi.c
+++ b/lib/utils/ipi/aclint_mswi.c
@@ -12,21 +12,30 @@
 #include <sbi/riscv_io.h>
 #include <sbi/sbi_domain.h>
 #include <sbi/sbi_error.h>
-#include <sbi/sbi_hartmask.h>
 #include <sbi/sbi_ipi.h>
+#include <sbi/sbi_scratch.h>
 #include <sbi/sbi_timer.h>
 #include <sbi_utils/ipi/aclint_mswi.h>
 
-static struct aclint_mswi_data *mswi_hartid2data[SBI_HARTMASK_MAX_BITS];
+static unsigned long mswi_ptr_offset;
+
+#define mswi_get_hart_data_ptr(__scratch)				\
+	sbi_scratch_read_type((__scratch), void *, mswi_ptr_offset)
+
+#define mswi_set_hart_data_ptr(__scratch, __mswi)			\
+	sbi_scratch_write_type((__scratch), void *, mswi_ptr_offset, (__mswi))
 
 static void mswi_ipi_send(u32 target_hart)
 {
 	u32 *msip;
+	struct sbi_scratch *scratch;
 	struct aclint_mswi_data *mswi;
 
-	if (SBI_HARTMASK_MAX_BITS <= target_hart)
+	scratch = sbi_hartid_to_scratch(target_hart);
+	if (!scratch)
 		return;
-	mswi = mswi_hartid2data[target_hart];
+
+	mswi = mswi_get_hart_data_ptr(scratch);
 	if (!mswi)
 		return;
 
@@ -38,11 +47,14 @@ static void mswi_ipi_send(u32 target_hart)
 static void mswi_ipi_clear(u32 target_hart)
 {
 	u32 *msip;
+	struct sbi_scratch *scratch;
 	struct aclint_mswi_data *mswi;
 
-	if (SBI_HARTMASK_MAX_BITS <= target_hart)
+	scratch = sbi_hartid_to_scratch(target_hart);
+	if (!scratch)
 		return;
-	mswi = mswi_hartid2data[target_hart];
+
+	mswi = mswi_get_hart_data_ptr(scratch);
 	if (!mswi)
 		return;
 
@@ -69,19 +81,30 @@ int aclint_mswi_cold_init(struct aclint_mswi_data *mswi)
 {
 	u32 i;
 	int rc;
+	struct sbi_scratch *scratch;
 	unsigned long pos, region_size;
 	struct sbi_domain_memregion reg;
 
 	/* Sanity checks */
 	if (!mswi || (mswi->addr & (ACLINT_MSWI_ALIGN - 1)) ||
 	    (mswi->size < (mswi->hart_count * sizeof(u32))) ||
-	    (mswi->first_hartid + mswi->hart_count > SBI_HARTMASK_MAX_BITS) ||
 	    (!mswi->hart_count || mswi->hart_count > ACLINT_MSWI_MAX_HARTS))
 		return SBI_EINVAL;
 
-	/* Update MSWI hartid table */
-	for (i = 0; i < mswi->hart_count; i++)
-		mswi_hartid2data[mswi->first_hartid + i] = mswi;
+	/* Allocate scratch space pointer */
+	if (!mswi_ptr_offset) {
+		mswi_ptr_offset = sbi_scratch_alloc_type_offset(void *);
+		if (!mswi_ptr_offset)
+			return SBI_ENOMEM;
+	}
+
+	/* Update MSWI pointer in scratch space */
+	for (i = 0; i < mswi->hart_count; i++) {
+		scratch = sbi_hartid_to_scratch(mswi->first_hartid + i);
+		if (!scratch)
+			return SBI_ENOENT;
+		mswi_set_hart_data_ptr(scratch, mswi);
+	}
 
 	/* Add MSWI regions to the root domain */
 	for (pos = 0; pos < mswi->size; pos += ACLINT_MSWI_ALIGN) {
-- 
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 ` [PATCH v2 07/18] lib: sbi: Use scratch space to save per-HART domain pointer Anup Patel
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 ` Anup Patel [this message]
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-15-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.