All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 17/17] lib: utils/irqchip: Use scratch space to save per-HART IMSIC pointer
Date: Tue, 25 Apr 2023 18:02:30 +0530	[thread overview]
Message-ID: <20230425123230.3943447-18-apatel@ventanamicro.com> (raw)
In-Reply-To: <20230425123230.3943447-1-apatel@ventanamicro.com>

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

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 lib/utils/irqchip/fdt_irqchip_imsic.c |  4 +-
 lib/utils/irqchip/imsic.c             | 87 ++++++++++++++++++++++-----
 2 files changed, 74 insertions(+), 17 deletions(-)

diff --git a/lib/utils/irqchip/fdt_irqchip_imsic.c b/lib/utils/irqchip/fdt_irqchip_imsic.c
index 574cadc..20ee0d8 100644
--- a/lib/utils/irqchip/fdt_irqchip_imsic.c
+++ b/lib/utils/irqchip/fdt_irqchip_imsic.c
@@ -78,13 +78,13 @@ static int irqchip_imsic_cold_init(void *fdt, int nodeoff,
 		return 0;
 	}
 
-	rc = irqchip_imsic_update_hartid_table(fdt, nodeoff, id);
+	rc = imsic_cold_irqchip_init(id);
 	if (rc) {
 		sbi_free(id);
 		return rc;
 	}
 
-	rc = imsic_cold_irqchip_init(id);
+	rc = irqchip_imsic_update_hartid_table(fdt, nodeoff, id);
 	if (rc) {
 		sbi_free(id);
 		return rc;
diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c
index 11667cd..2b3e9da 100644
--- a/lib/utils/irqchip/imsic.c
+++ b/lib/utils/irqchip/imsic.c
@@ -13,10 +13,10 @@
 #include <sbi/riscv_encoding.h>
 #include <sbi/sbi_console.h>
 #include <sbi/sbi_domain.h>
-#include <sbi/sbi_hartmask.h>
 #include <sbi/sbi_ipi.h>
 #include <sbi/sbi_irqchip.h>
 #include <sbi/sbi_error.h>
+#include <sbi/sbi_scratch.h>
 #include <sbi_utils/irqchip/imsic.h>
 
 #define IMSIC_MMIO_PAGE_LE		0x00
@@ -79,33 +79,69 @@ do { \
 	csr_clear(CSR_MIREG, __v); \
 } while (0)
 
-static struct imsic_data *imsic_hartid2data[SBI_HARTMASK_MAX_BITS];
-static int imsic_hartid2file[SBI_HARTMASK_MAX_BITS];
+static unsigned long imsic_ptr_offset;
+
+#define imsic_get_hart_data_ptr(__scratch)				\
+({									\
+	(void *)(*((ulong *)sbi_scratch_offset_ptr((__scratch),		\
+						   imsic_ptr_offset)));\
+})
+
+#define imsic_set_hart_data_ptr(__scratch, __imsic)			\
+do {									\
+	*((ulong *)sbi_scratch_offset_ptr((__scratch), imsic_ptr_offset))\
+					= (ulong)(__imsic);		\
+} while (0)
+
+static unsigned long imsic_file_offset;
+
+#define imsic_get_hart_file(__scratch)					\
+({									\
+	*((long *)sbi_scratch_offset_ptr((__scratch), imsic_file_offset));\
+})
+
+#define imsic_set_hart_file(__scratch, __file)				\
+do {									\
+	*((long *)sbi_scratch_offset_ptr((__scratch), imsic_file_offset))\
+					= (long)(__file);		\
+} while (0)
 
 int imsic_map_hartid_to_data(u32 hartid, struct imsic_data *imsic, int file)
 {
-	if (!imsic || !imsic->targets_mmode ||
-	    (SBI_HARTMASK_MAX_BITS <= hartid))
+	struct sbi_scratch *scratch;
+
+	if (!imsic || !imsic->targets_mmode)
 		return SBI_EINVAL;
 
-	imsic_hartid2data[hartid] = imsic;
-	imsic_hartid2file[hartid] = file;
+	scratch = sbi_hartid_to_scratch(hartid);
+	if (!scratch)
+		return SBI_ENOENT;
+
+	imsic_set_hart_data_ptr(scratch, imsic);
+	imsic_set_hart_file(scratch, file);
 	return 0;
 }
 
 struct imsic_data *imsic_get_data(u32 hartid)
 {
-	if (SBI_HARTMASK_MAX_BITS <= hartid)
+	struct sbi_scratch *scratch;
+
+	scratch = sbi_hartid_to_scratch(hartid);
+	if (!scratch)
 		return NULL;
-	return imsic_hartid2data[hartid];
+
+	return imsic_get_hart_data_ptr(scratch);
 }
 
 int imsic_get_target_file(u32 hartid)
 {
-	if ((SBI_HARTMASK_MAX_BITS <= hartid) ||
-	    !imsic_hartid2data[hartid])
+	struct sbi_scratch *scratch;
+
+	scratch = sbi_hartid_to_scratch(hartid);
+	if (!scratch)
 		return SBI_ENOENT;
-	return imsic_hartid2file[hartid];
+
+	return imsic_get_hart_file(scratch);
 }
 
 static int imsic_external_irqfn(struct sbi_trap_regs *regs)
@@ -133,9 +169,16 @@ static void imsic_ipi_send(u32 target_hart)
 {
 	unsigned long reloff;
 	struct imsic_regs *regs;
-	struct imsic_data *data = imsic_hartid2data[target_hart];
-	int file = imsic_hartid2file[target_hart];
+	struct imsic_data *data;
+	struct sbi_scratch *scratch;
+	int file;
 
+	scratch = sbi_hartid_to_scratch(target_hart);
+	if (!scratch)
+		return;
+
+	data = imsic_get_hart_data_ptr(scratch);
+	file = imsic_get_hart_file(scratch);
 	if (!data || !data->targets_mmode)
 		return;
 
@@ -204,7 +247,7 @@ void imsic_local_irqchip_init(void)
 
 int imsic_warm_irqchip_init(void)
 {
-	struct imsic_data *imsic = imsic_hartid2data[current_hartid()];
+	struct imsic_data *imsic = imsic_get_data(current_hartid());
 
 	/* Sanity checks */
 	if (!imsic || !imsic->targets_mmode)
@@ -306,6 +349,20 @@ int imsic_cold_irqchip_init(struct imsic_data *imsic)
 	if (!imsic->targets_mmode)
 		return SBI_EINVAL;
 
+	/* Allocate scratch space pointer */
+	if (!imsic_ptr_offset) {
+		imsic_ptr_offset = sbi_scratch_alloc_offset(sizeof(ulong));
+		if (!imsic_ptr_offset)
+			return SBI_ENOMEM;
+	}
+
+	/* Allocate scratch space file */
+	if (!imsic_file_offset) {
+		imsic_file_offset = sbi_scratch_alloc_offset(sizeof(long));
+		if (!imsic_file_offset)
+			return SBI_ENOMEM;
+	}
+
 	/* Setup external interrupt function for IMSIC */
 	sbi_irqchip_set_irqfn(imsic_external_irqfn);
 
-- 
2.34.1



  parent reply	other threads:[~2023-04-25 12:32 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 12:32 [PATCH 00/17] Introduce and use simple heap allocator Anup Patel
2023-04-25 12:32 ` [PATCH 01/17] platform: Allow platforms to specify heap size Anup Patel
2023-05-31 11:17   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 02/17] lib: sbi: Introduce simple heap allocator Anup Patel
2023-05-31 12:11   ` Andrew Jones
2023-06-04 10:17     ` Anup Patel
2023-04-25 12:32 ` [PATCH 03/17] lib: sbi: Print scratch size and usage at boot time Anup Patel
2023-05-31 12:20   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 04/17] lib: sbi_pmu: Use heap for per-HART PMU state Anup Patel
2023-05-31 12:32   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 05/17] lib: sbi: Use heap for root domain creation Anup Patel
2023-05-31 12:34   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 06/17] lib: sbi: Use scratch space to save per-HART domain pointer Anup Patel
2023-05-31 12:39   ` Andrew Jones
2023-06-04 10:38     ` Anup Patel
2023-04-25 12:32 ` [PATCH 07/17] lib: utils/gpio: Use heap in SiFive and StartFive GPIO drivers Anup Patel
2023-05-31 12:42   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 08/17] lib: utils/i2c: Use heap in DesignWare and SiFive I2C drivers Anup Patel
2023-05-31 12:42   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 09/17] lib: utils/ipi: Use heap in ACLINT MSWI driver Anup Patel
2023-05-31 12:43   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 10/17] lib: utils/irqchip: Use heap in PLIC, APLIC and IMSIC drivers Anup Patel
2023-05-31 12:46   ` Andrew Jones
2023-06-04 11:43     ` Anup Patel
2023-04-25 12:32 ` [PATCH 11/17] lib: utils/timer: Use heap in ACLINT MTIMER driver Anup Patel
2023-05-31 12:50   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 12/17] lib: utils/fdt: Use heap in FDT domain parsing Anup Patel
2023-05-31 13:02   ` Andrew Jones
2023-06-05  4:00     ` Anup Patel
2023-04-25 12:32 ` [PATCH 13/17] lib: utils/ipi: Use scratch space to save per-HART MSWI pointer Anup Patel
2023-05-31 13:03   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 14/17] lib: utils/timer: Use scratch space to save per-HART MTIMER pointer Anup Patel
2023-05-31 13:06   ` Andrew Jones
2023-04-25 12:32 ` [PATCH 15/17] lib: utils/irqchip: Use scratch space to save per-HART PLIC pointer Anup Patel
2023-05-31 13:12   ` Andrew Jones
2023-06-05  5:31     ` Anup Patel
2023-06-05  5:43   ` Jessica Clarke
2023-06-05  6:51     ` Anup Patel
2023-06-05  6:57       ` Jessica Clarke
2023-06-05 11:23         ` Anup Patel
2023-04-25 12:32 ` [PATCH 16/17] lib: utils/irqchip: Don't check hartid in imsic_update_hartid_table() Anup Patel
2023-05-31 13:14   ` Andrew Jones
2023-04-25 12:32 ` Anup Patel [this message]
2023-05-31 13:34   ` [PATCH 17/17] lib: utils/irqchip: Use scratch space to save per-HART IMSIC pointer Andrew Jones

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=20230425123230.3943447-18-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.