opensbi.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Jessica Clarke <jrtc27@jrtc27.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 15/17] lib: utils/irqchip: Use scratch space to save per-HART PLIC pointer
Date: Mon, 5 Jun 2023 06:43:46 +0100	[thread overview]
Message-ID: <C3911409-D000-4FC3-8302-4C4BAADACFE2@jrtc27.com> (raw)
In-Reply-To: <20230425123230.3943447-16-apatel@ventanamicro.com>

On 25 Apr 2023, at 13:32, Anup Patel <apatel@ventanamicro.com> wrote:
> 
> 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>
> ---
> lib/utils/irqchip/fdt_irqchip_plic.c | 108 +++++++++++++++++++++------
> 1 file changed, 86 insertions(+), 22 deletions(-)
> 
> diff --git a/lib/utils/irqchip/fdt_irqchip_plic.c b/lib/utils/irqchip/fdt_irqchip_plic.c
> index 605f44a..eb1e412 100644
> --- a/lib/utils/irqchip/fdt_irqchip_plic.c
> +++ b/lib/utils/irqchip/fdt_irqchip_plic.c
> @@ -12,54 +12,97 @@
> #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) \
> +({ \
> + (void *)(*((ulong *)sbi_scratch_offset_ptr((__scratch), \
> +   plic_ptr_offset))); \

Why all the casting rather than just storing the pointer?

Jess

> +})
> +
> +#define plic_set_hart_data_ptr(__scratch, __imsic) \
> +do { \
> + *((ulong *)sbi_scratch_offset_ptr((__scratch), plic_ptr_offset))\
> + = (ulong)(__imsic); \
> +} while (0)
> +
> +static unsigned long plic_mcontext_offset;
> +
> +#define plic_get_hart_mcontext(__scratch) \
> +({ \
> + long __ret = \
> + *((long *)sbi_scratch_offset_ptr((__scratch), plic_mcontext_offset));\
> + (__ret - 1); \
> +})
> +
> +#define plic_set_hart_mcontext(__scratch, __mcontext) \
> +do { \
> + *((long *)sbi_scratch_offset_ptr((__scratch), plic_mcontext_offset))\
> + = (long)(__mcontext + 1); \
> +} while (0)
> +
> +static unsigned long plic_scontext_offset;
> +
> +#define plic_get_hart_scontext(__scratch) \
> +({ \
> + long __ret = \
> + *((long *)sbi_scratch_offset_ptr((__scratch), plic_scontext_offset));\
> + (__ret - 1); \
> +})
> +
> +#define plic_set_hart_scontext(__scratch, __scontext) \
> +do { \
> + *((long *)sbi_scratch_offset_ptr((__scratch), plic_scontext_offset))\
> + = (long)(__scontext + 1); \
> +} while (0)
> 
> 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 +110,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 +134,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 +158,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_offset(sizeof(ulong));
> + if (!plic_ptr_offset)
> + return SBI_ENOMEM;
> + }
> +
> + if (!plic_mcontext_offset) {
> + plic_mcontext_offset = sbi_scratch_alloc_offset(sizeof(long));
> + if (!plic_mcontext_offset)
> + return SBI_ENOMEM;
> + }
> +
> + if (!plic_scontext_offset) {
> + plic_scontext_offset = sbi_scratch_alloc_offset(sizeof(long));
> + if (!plic_scontext_offset)
> + return SBI_ENOMEM;
> + }
> +
> pd = sbi_zalloc(sizeof(*pd));
> if (!pd)
> return SBI_ENOMEM;
> @@ -152,7 +215,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
> 
> 
> -- 
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi



  parent reply	other threads:[~2023-06-05  5:43 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 [this message]
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 ` [PATCH 17/17] lib: utils/irqchip: Use scratch space to save per-HART IMSIC pointer Anup Patel
2023-05-31 13:34   ` 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=C3911409-D000-4FC3-8302-4C4BAADACFE2@jrtc27.com \
    --to=jrtc27@jrtc27.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).