aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <samuel.holland@sifive.com>2024-11-04 20:10:07 -0800
committerAnup Patel <anup@brainfault.org>2024-11-28 11:37:25 +0530
commite3e5686ef903d037c6b5835a6752481a07faf99f (patch)
treec254982b0cd822c710a27e51c3b6a5f9e1a2ad1d
parent56fddce83f163e5e90ea82bf78a8df3d990b0572 (diff)
downloadopensbi-e3e5686ef903d037c6b5835a6752481a07faf99f.zip
opensbi-e3e5686ef903d037c6b5835a6752481a07faf99f.tar.gz
opensbi-e3e5686ef903d037c6b5835a6752481a07faf99f.tar.bz2
lib: sbi_irqchip: Register devices during cold init
Have the SBI irqchip core keep track of registered irqchip devices. This is useful for any callbacks the irqchip driver may have, such as for warm initialization, the external interrupt handler function, and any future support for handling external interrupts (beyond IPIs) in M-mode. This improves on the tracking done in fdt_irqchip.c, as it tracks device instances, not just drivers, so callbacks can target a specific device. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
-rw-r--r--include/sbi/sbi_irqchip.h10
-rw-r--r--lib/sbi/sbi_irqchip.c8
-rw-r--r--lib/utils/irqchip/aplic.c7
-rw-r--r--lib/utils/irqchip/imsic.c6
-rw-r--r--lib/utils/irqchip/plic.c7
5 files changed, 38 insertions, 0 deletions
diff --git a/include/sbi/sbi_irqchip.h b/include/sbi/sbi_irqchip.h
index 0ed02eb..c88b760 100644
--- a/include/sbi/sbi_irqchip.h
+++ b/include/sbi/sbi_irqchip.h
@@ -10,10 +10,17 @@
#ifndef __SBI_IRQCHIP_H__
#define __SBI_IRQCHIP_H__
+#include <sbi/sbi_list.h>
#include <sbi/sbi_types.h>
struct sbi_scratch;
+/** irqchip hardware device */
+struct sbi_irqchip_device {
+ /** Node in the list of irqchip devices */
+ struct sbi_dlist node;
+};
+
/**
* Set external interrupt handling function
*
@@ -34,6 +41,9 @@ void sbi_irqchip_set_irqfn(int (*fn)(void));
*/
int sbi_irqchip_process(void);
+/** Register an irqchip device to receive callbacks */
+void sbi_irqchip_add_device(struct sbi_irqchip_device *dev);
+
/** Initialize interrupt controllers */
int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot);
diff --git a/lib/sbi/sbi_irqchip.c b/lib/sbi/sbi_irqchip.c
index 0ae604a..2ab9d1f 100644
--- a/lib/sbi/sbi_irqchip.c
+++ b/lib/sbi/sbi_irqchip.c
@@ -8,8 +8,11 @@
*/
#include <sbi/sbi_irqchip.h>
+#include <sbi/sbi_list.h>
#include <sbi/sbi_platform.h>
+static SBI_LIST_HEAD(irqchip_list);
+
static int default_irqfn(void)
{
return SBI_ENODEV;
@@ -28,6 +31,11 @@ int sbi_irqchip_process(void)
return ext_irqfn();
}
+void sbi_irqchip_add_device(struct sbi_irqchip_device *dev)
+{
+ sbi_list_add_tail(&dev->node, &irqchip_list);
+}
+
int sbi_irqchip_init(struct sbi_scratch *scratch, bool cold_boot)
{
int rc;
diff --git a/lib/utils/irqchip/aplic.c b/lib/utils/irqchip/aplic.c
index 28f2f26..2737184 100644
--- a/lib/utils/irqchip/aplic.c
+++ b/lib/utils/irqchip/aplic.c
@@ -12,6 +12,7 @@
#include <sbi/sbi_console.h>
#include <sbi/sbi_domain.h>
#include <sbi/sbi_error.h>
+#include <sbi/sbi_irqchip.h>
#include <sbi_utils/irqchip/aplic.h>
#define APLIC_MAX_IDC (1UL << 14)
@@ -165,6 +166,9 @@ static int aplic_check_msicfg(struct aplic_msicfg_data *msicfg)
return 0;
}
+static struct sbi_irqchip_device aplic_device = {
+};
+
int aplic_cold_irqchip_init(struct aplic_data *aplic)
{
int rc;
@@ -275,5 +279,8 @@ int aplic_cold_irqchip_init(struct aplic_data *aplic)
return rc;
}
+ /* Register irqchip device */
+ sbi_irqchip_add_device(&aplic_device);
+
return 0;
}
diff --git a/lib/utils/irqchip/imsic.c b/lib/utils/irqchip/imsic.c
index ae8b31e..a3b2cf0 100644
--- a/lib/utils/irqchip/imsic.c
+++ b/lib/utils/irqchip/imsic.c
@@ -345,6 +345,9 @@ int imsic_data_check(struct imsic_data *imsic)
return 0;
}
+static struct sbi_irqchip_device imsic_device = {
+};
+
int imsic_cold_irqchip_init(struct imsic_data *imsic)
{
int i, rc;
@@ -387,6 +390,9 @@ int imsic_cold_irqchip_init(struct imsic_data *imsic)
return rc;
}
+ /* Register irqchip device */
+ sbi_irqchip_add_device(&imsic_device);
+
/* Register IPI device */
sbi_ipi_set_device(&imsic_ipi_device);
diff --git a/lib/utils/irqchip/plic.c b/lib/utils/irqchip/plic.c
index ca506c4..f9eb741 100644
--- a/lib/utils/irqchip/plic.c
+++ b/lib/utils/irqchip/plic.c
@@ -15,6 +15,7 @@
#include <sbi/sbi_domain.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_heap.h>
+#include <sbi/sbi_irqchip.h>
#include <sbi/sbi_string.h>
#include <sbi_utils/irqchip/plic.h>
@@ -220,6 +221,9 @@ int plic_warm_irqchip_init(void)
return 0;
}
+static struct sbi_irqchip_device plic_device = {
+};
+
int plic_cold_irqchip_init(struct plic_data *plic)
{
int i, ret;
@@ -278,5 +282,8 @@ int plic_cold_irqchip_init(struct plic_data *plic)
plic_set_hart_data_ptr(sbi_hartindex_to_scratch(i), plic);
}
+ /* Register irqchip device */
+ sbi_irqchip_add_device(&plic_device);
+
return 0;
}