aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSamuel Holland <samuel.holland@sifive.com>2024-11-04 20:10:06 -0800
committerAnup Patel <anup@brainfault.org>2024-11-28 11:35:01 +0530
commit56fddce83f163e5e90ea82bf78a8df3d990b0572 (patch)
treed8830216f94abf2f83ea8a09340583ac1ce2c86f /lib
parentc6c22f00f457264560ca05414e9f9e0c5c3438db (diff)
downloadopensbi-56fddce83f163e5e90ea82bf78a8df3d990b0572.zip
opensbi-56fddce83f163e5e90ea82bf78a8df3d990b0572.tar.gz
opensbi-56fddce83f163e5e90ea82bf78a8df3d990b0572.tar.bz2
lib: utils/irqchip: Move per-hart data from fdt_plic to plic
The per-hart PLIC pointer is not really specific to FDT platforms. Move it into the main driver and drop the extra wrapper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/irqchip/fdt_irqchip_plic.c49
-rw-r--r--lib/utils/irqchip/plic.c49
2 files changed, 46 insertions, 52 deletions
diff --git a/lib/utils/irqchip/fdt_irqchip_plic.c b/lib/utils/irqchip/fdt_irqchip_plic.c
index 3826d2a..ebde7ee 100644
--- a/lib/utils/irqchip/fdt_irqchip_plic.c
+++ b/lib/utils/irqchip/fdt_irqchip_plic.c
@@ -18,48 +18,11 @@
#include <sbi_utils/irqchip/fdt_irqchip.h>
#include <sbi_utils/irqchip/plic.h>
-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))
-
-struct plic_data *fdt_plic_get(void)
-{
- struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
-
- return plic_get_hart_data_ptr(scratch);
-}
-
-void fdt_plic_suspend(void)
-{
- struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
-
- plic_suspend(plic_get_hart_data_ptr(scratch));
-}
-
-void fdt_plic_resume(void)
-{
- struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
-
- plic_resume(plic_get_hart_data_ptr(scratch));
-}
-
-static int irqchip_plic_warm_init(void)
-{
- struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
-
- return plic_warm_irqchip_init(plic_get_hart_data_ptr(scratch));
-}
-
static int irqchip_plic_update_context_map(const void *fdt, int nodeoff,
struct plic_data *pd)
{
const fdt32_t *val;
u32 phandle, hwirq, hartid, hartindex;
- struct sbi_scratch *scratch;
int i, err, count, cpu_offset, cpu_intc_offset;
val = fdt_getprop(fdt, nodeoff, "interrupts-extended", &count);
@@ -84,11 +47,9 @@ static int irqchip_plic_update_context_map(const void *fdt, int nodeoff,
continue;
hartindex = sbi_hartid_to_hartindex(hartid);
- scratch = sbi_hartindex_to_scratch(hartindex);
- if (!scratch)
+ if (hartindex == -1U)
continue;
- plic_set_hart_data_ptr(scratch, pd);
switch (hwirq) {
case IRQ_M_EXT:
pd->context_map[hartindex][PLIC_M_CONTEXT] = i / 2;
@@ -110,12 +71,6 @@ static int irqchip_plic_cold_init(const 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;
- }
-
pd = sbi_zalloc(PLIC_DATA_SIZE(plat->hart_count));
if (!pd)
return SBI_ENOMEM;
@@ -153,6 +108,6 @@ static const struct fdt_match irqchip_plic_match[] = {
struct fdt_irqchip fdt_irqchip_plic = {
.match_table = irqchip_plic_match,
.cold_init = irqchip_plic_cold_init,
- .warm_init = irqchip_plic_warm_init,
+ .warm_init = plic_warm_irqchip_init,
.exit = NULL,
};
diff --git a/lib/utils/irqchip/plic.c b/lib/utils/irqchip/plic.c
index ab58e39..ca506c4 100644
--- a/lib/utils/irqchip/plic.c
+++ b/lib/utils/irqchip/plic.c
@@ -27,6 +27,21 @@
#define THEAD_PLIC_CTRL_REG 0x1ffffc
+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))
+
+struct plic_data *plic_get(void)
+{
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+
+ return plic_get_hart_data_ptr(scratch);
+}
+
static u32 plic_get_priority(const struct plic_data *plic, u32 source)
{
volatile void *plic_priority = (char *)plic->addr +
@@ -109,8 +124,10 @@ static int plic_context_init(const struct plic_data *plic, int context_id,
return 0;
}
-void plic_suspend(const struct plic_data *plic)
+void plic_suspend(void)
{
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+ const struct plic_data *plic = plic_get_hart_data_ptr(scratch);
u32 ie_words = PLIC_IE_WORDS(plic);
u32 *data_word = plic->pm_data;
u8 *data_byte;
@@ -138,8 +155,10 @@ void plic_suspend(const struct plic_data *plic)
*data_byte++ = plic_get_priority(plic, i);
}
-void plic_resume(const struct plic_data *plic)
+void plic_resume(void)
{
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+ const struct plic_data *plic = plic_get_hart_data_ptr(scratch);
u32 ie_words = PLIC_IE_WORDS(plic);
u32 *data_word = plic->pm_data;
u8 *data_byte;
@@ -170,8 +189,10 @@ void plic_resume(const struct plic_data *plic)
plic_delegate(plic);
}
-int plic_warm_irqchip_init(const struct plic_data *plic)
+int plic_warm_irqchip_init(void)
{
+ struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+ const struct plic_data *plic = plic_get_hart_data_ptr(scratch);
u32 hartindex = current_hartindex();
s16 m_cntx_id = plic->context_map[hartindex][PLIC_M_CONTEXT];
s16 s_cntx_id = plic->context_map[hartindex][PLIC_S_CONTEXT];
@@ -201,11 +222,17 @@ int plic_warm_irqchip_init(const struct plic_data *plic)
int plic_cold_irqchip_init(struct plic_data *plic)
{
- int i;
+ int i, ret;
if (!plic)
return SBI_EINVAL;
+ if (!plic_ptr_offset) {
+ plic_ptr_offset = sbi_scratch_alloc_type_offset(void *);
+ if (!plic_ptr_offset)
+ return SBI_ENOMEM;
+ }
+
if (plic->flags & PLIC_FLAG_ENABLE_PM) {
unsigned long data_size = 0;
@@ -237,7 +264,19 @@ int plic_cold_irqchip_init(struct plic_data *plic)
plic_delegate(plic);
- return sbi_domain_root_add_memrange(plic->addr, plic->size, BIT(20),
+ ret = sbi_domain_root_add_memrange(plic->addr, plic->size, BIT(20),
(SBI_DOMAIN_MEMREGION_MMIO |
SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW));
+ if (ret)
+ return ret;
+
+ for (u32 i = 0; i <= sbi_scratch_last_hartindex(); i++) {
+ if (plic->context_map[i][PLIC_M_CONTEXT] < 0 &&
+ plic->context_map[i][PLIC_S_CONTEXT] < 0)
+ continue;
+
+ plic_set_hart_data_ptr(sbi_hartindex_to_scratch(i), plic);
+ }
+
+ return 0;
}