From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v2 16/18] lib: utils/irqchip: Use scratch space to save per-HART PLIC pointer
Date: Mon, 5 Jun 2023 17:07:47 +0530 [thread overview]
Message-ID: <20230605113749.230696-17-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 PLIC pointer and PLIC context numbers.
Signed-off-by: Anup Patel <apatel@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
lib/utils/irqchip/fdt_irqchip_plic.c | 88 +++++++++++++++++++++-------
1 file changed, 66 insertions(+), 22 deletions(-)
diff --git a/lib/utils/irqchip/fdt_irqchip_plic.c b/lib/utils/irqchip/fdt_irqchip_plic.c
index d733284..829c5ee 100644
--- a/lib/utils/irqchip/fdt_irqchip_plic.c
+++ b/lib/utils/irqchip/fdt_irqchip_plic.c
@@ -12,54 +12,77 @@
#include <sbi/riscv_io.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_heap.h>
-#include <sbi/sbi_hartmask.h>
+#include <sbi/sbi_scratch.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/irqchip/fdt_irqchip.h>
#include <sbi_utils/irqchip/plic.h>
-static struct plic_data *plic_hartid2data[SBI_HARTMASK_MAX_BITS];
-static int plic_hartid2context[SBI_HARTMASK_MAX_BITS][2] = { { -1 } };
+static unsigned long plic_ptr_offset;
+
+#define plic_get_hart_data_ptr(__scratch) \
+ sbi_scratch_read_type((__scratch), void *, plic_ptr_offset)
+
+#define plic_set_hart_data_ptr(__scratch, __plic) \
+ sbi_scratch_write_type((__scratch), void *, plic_ptr_offset, (__plic))
+
+static unsigned long plic_mcontext_offset;
+
+#define plic_get_hart_mcontext(__scratch) \
+ (sbi_scratch_read_type((__scratch), long, plic_mcontext_offset) - 1)
+
+#define plic_set_hart_mcontext(__scratch, __mctx) \
+ sbi_scratch_write_type((__scratch), long, plic_mcontext_offset, (__mctx) + 1)
+
+static unsigned long plic_scontext_offset;
+
+#define plic_get_hart_scontext(__scratch) \
+ (sbi_scratch_read_type((__scratch), long, plic_scontext_offset) - 1)
+
+#define plic_set_hart_scontext(__scratch, __sctx) \
+ sbi_scratch_write_type((__scratch), long, plic_scontext_offset, (__sctx) + 1)
void fdt_plic_priority_save(u8 *priority, u32 num)
{
- struct plic_data *plic = plic_hartid2data[current_hartid()];
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
- plic_priority_save(plic, priority, num);
+ plic_priority_save(plic_get_hart_data_ptr(scratch), priority, num);
}
void fdt_plic_priority_restore(const u8 *priority, u32 num)
{
- struct plic_data *plic = plic_hartid2data[current_hartid()];
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
- plic_priority_restore(plic, priority, num);
+ plic_priority_restore(plic_get_hart_data_ptr(scratch), priority, num);
}
void fdt_plic_context_save(bool smode, u32 *enable, u32 *threshold, u32 num)
{
- u32 hartid = current_hartid();
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
- plic_context_save(plic_hartid2data[hartid],
- plic_hartid2context[hartid][smode],
+ plic_context_save(plic_get_hart_data_ptr(scratch),
+ smode ? plic_get_hart_scontext(scratch) :
+ plic_get_hart_mcontext(scratch),
enable, threshold, num);
}
void fdt_plic_context_restore(bool smode, const u32 *enable, u32 threshold,
u32 num)
{
- u32 hartid = current_hartid();
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
- plic_context_restore(plic_hartid2data[hartid],
- plic_hartid2context[hartid][smode],
+ plic_context_restore(plic_get_hart_data_ptr(scratch),
+ smode ? plic_get_hart_scontext(scratch) :
+ plic_get_hart_mcontext(scratch),
enable, threshold, num);
}
static int irqchip_plic_warm_init(void)
{
- u32 hartid = current_hartid();
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
- return plic_warm_irqchip_init(plic_hartid2data[hartid],
- plic_hartid2context[hartid][0],
- plic_hartid2context[hartid][1]);
+ return plic_warm_irqchip_init(plic_get_hart_data_ptr(scratch),
+ plic_get_hart_mcontext(scratch),
+ plic_get_hart_scontext(scratch));
}
static int irqchip_plic_update_hartid_table(void *fdt, int nodeoff,
@@ -67,6 +90,7 @@ static int irqchip_plic_update_hartid_table(void *fdt, int nodeoff,
{
const fdt32_t *val;
u32 phandle, hwirq, hartid;
+ struct sbi_scratch *scratch;
int i, err, count, cpu_offset, cpu_intc_offset;
val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &count);
@@ -90,16 +114,17 @@ static int irqchip_plic_update_hartid_table(void *fdt, int nodeoff,
if (err)
continue;
- if (SBI_HARTMASK_MAX_BITS <= hartid)
+ scratch = sbi_hartid_to_scratch(hartid);
+ if (!scratch)
continue;
- plic_hartid2data[hartid] = pd;
+ plic_set_hart_data_ptr(scratch, pd);
switch (hwirq) {
case IRQ_M_EXT:
- plic_hartid2context[hartid][0] = i / 2;
+ plic_set_hart_mcontext(scratch, i / 2);
break;
case IRQ_S_EXT:
- plic_hartid2context[hartid][1] = i / 2;
+ plic_set_hart_scontext(scratch, i / 2);
break;
}
}
@@ -113,6 +138,24 @@ static int irqchip_plic_cold_init(void *fdt, int nodeoff,
int rc;
struct plic_data *pd;
+ if (!plic_ptr_offset) {
+ plic_ptr_offset = sbi_scratch_alloc_type_offset(void *);
+ if (!plic_ptr_offset)
+ return SBI_ENOMEM;
+ }
+
+ if (!plic_mcontext_offset) {
+ plic_mcontext_offset = sbi_scratch_alloc_type_offset(long);
+ if (!plic_mcontext_offset)
+ return SBI_ENOMEM;
+ }
+
+ if (!plic_scontext_offset) {
+ plic_scontext_offset = sbi_scratch_alloc_type_offset(long);
+ if (!plic_scontext_offset)
+ return SBI_ENOMEM;
+ }
+
pd = sbi_zalloc(sizeof(*pd));
if (!pd)
return SBI_ENOMEM;
@@ -150,7 +193,8 @@ static void thead_plic_plat_init(struct plic_data *pd)
void thead_plic_restore(void)
{
- struct plic_data *plic = plic_hartid2data[current_hartid()];
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+ struct plic_data *plic = plic_get_hart_data_ptr(scratch);
thead_plic_plat_init(plic);
}
--
2.34.1
next prev 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 ` [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 ` Anup Patel [this message]
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-17-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.