summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnup Patel <[email protected]>2018-12-26 18:27:35 +0530
committerAnup Patel <[email protected]>2018-12-27 09:35:09 +0530
commite34aa8a6719dd6c225e576e0617d05735776af6f (patch)
tree59b041b592b1f139cb7850a522813f392a28c70b
parent7b59571758a5dec75c89928a60d982b29629cee6 (diff)
lib: Simplify sbi_platform irqchip_init() hooks
Instead of having separate irqchip_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one irqchip_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated irqchip_init() hook. Signed-off-by: Anup Patel <[email protected]>
-rw-r--r--include/sbi/sbi_platform.h18
-rw-r--r--lib/sbi_init.c8
-rw-r--r--platform/kendryte/k210/platform.c25
-rw-r--r--platform/qemu/sifive_u/platform.c26
-rw-r--r--platform/qemu/virt/platform.c26
-rw-r--r--platform/sifive/hifive_u540/platform.c26
6 files changed, 63 insertions, 66 deletions
diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h
index e5c18965..503669b3 100644
--- a/include/sbi/sbi_platform.h
+++ b/include/sbi/sbi_platform.h
@@ -42,8 +42,7 @@ struct sbi_platform {
void (*console_putc)(char ch);
char (*console_getc)(void);
int (*console_init)(void);
- int (*cold_irqchip_init)(void);
- int (*warm_irqchip_init)(u32 target_hart);
+ int (*irqchip_init)(u32 hartid, bool cold_boot);
void (*ipi_inject)(u32 target_hart, u32 source_hart);
void (*ipi_sync)(u32 target_hart, u32 source_hart);
void (*ipi_clear)(u32 target_hart);
@@ -159,18 +158,11 @@ static inline int sbi_platform_console_init(struct sbi_platform *plat)
return 0;
}
-static inline int sbi_platform_warm_irqchip_init(struct sbi_platform *plat,
- u32 target_hart)
-{
- if (plat && plat->warm_irqchip_init)
- return plat->warm_irqchip_init(target_hart);
- return 0;
-}
-
-static inline int sbi_platform_cold_irqchip_init(struct sbi_platform *plat)
+static inline int sbi_platform_irqchip_init(struct sbi_platform *plat,
+ u32 hartid, bool cold_boot)
{
- if (plat && plat->cold_irqchip_init)
- return plat->cold_irqchip_init();
+ if (plat && plat->irqchip_init)
+ return plat->irqchip_init(hartid, cold_boot);
return 0;
}
diff --git a/lib/sbi_init.c b/lib/sbi_init.c
index 1f5d923e..448102e5 100644
--- a/lib/sbi_init.c
+++ b/lib/sbi_init.c
@@ -46,11 +46,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch,
if (rc)
sbi_hart_hang();
- rc = sbi_platform_cold_irqchip_init(plat);
- if (rc)
- sbi_hart_hang();
-
- rc = sbi_platform_warm_irqchip_init(plat, hartid);
+ rc = sbi_platform_irqchip_init(plat, hartid, TRUE);
if (rc)
sbi_hart_hang();
@@ -125,7 +121,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch,
if (rc)
sbi_hart_hang();
- rc = sbi_platform_warm_irqchip_init(plat, hartid);
+ rc = sbi_platform_irqchip_init(plat, hartid, FALSE);
if (rc)
sbi_hart_hang();
diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c
index ccb0ad66..43c32440 100644
--- a/platform/kendryte/k210/platform.c
+++ b/platform/kendryte/k210/platform.c
@@ -35,17 +35,21 @@ static char k210_console_getc(void)
return uarths_getc();
}
-static int k210_cold_irqchip_init(void)
+static int k210_irqchip_init(u32 hartid, bool cold_boot)
{
- return plic_cold_irqchip_init(PLIC_BASE_ADDR, PLIC_NUM_SOURCES,
- K210_HART_COUNT);
-}
+ int rc;
-static int k210_warm_irqchip_init(u32 core_id)
-{
- return plic_warm_irqchip_init(core_id,
- (2 * core_id),
- (2 * core_id + 1));
+ if (cold_boot) {
+ rc = plic_cold_irqchip_init(PLIC_BASE_ADDR,
+ PLIC_NUM_SOURCES,
+ K210_HART_COUNT);
+ if (rc)
+ return rc;
+ }
+
+ return plic_warm_irqchip_init(hartid,
+ (2 * hartid),
+ (2 * hartid + 1));
}
static int k210_cold_ipi_init(void)
@@ -87,8 +91,7 @@ struct sbi_platform platform = {
.console_putc = k210_console_putc,
.console_getc = k210_console_getc,
- .cold_irqchip_init = k210_cold_irqchip_init,
- .warm_irqchip_init = k210_warm_irqchip_init,
+ .irqchip_init = k210_irqchip_init,
.cold_ipi_init = k210_cold_ipi_init,
.warm_ipi_init = clint_warm_ipi_init,
diff --git a/platform/qemu/sifive_u/platform.c b/platform/qemu/sifive_u/platform.c
index bbbe055a..db6dccd5 100644
--- a/platform/qemu/sifive_u/platform.c
+++ b/platform/qemu/sifive_u/platform.c
@@ -74,18 +74,21 @@ static int sifive_u_console_init(void)
SIFIVE_U_PERIPH_CLK, 115200);
}
-static int sifive_u_cold_irqchip_init(void)
+static int sifive_u_irqchip_init(u32 hartid, bool cold_boot)
{
- return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR,
- SIFIVE_U_PLIC_NUM_SOURCES,
- SIFIVE_U_HART_COUNT);
-}
+ int rc;
-static int sifive_u_warm_irqchip_init(u32 target_hart)
-{
- return plic_warm_irqchip_init(target_hart,
- (2 * target_hart),
- (2 * target_hart + 1));
+ if (cold_boot) {
+ rc = plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR,
+ SIFIVE_U_PLIC_NUM_SOURCES,
+ SIFIVE_U_HART_COUNT);
+ if (rc)
+ return rc;
+ }
+
+ return plic_warm_irqchip_init(hartid,
+ (2 * hartid),
+ (2 * hartid + 1));
}
static int sifive_u_cold_ipi_init(void)
@@ -118,8 +121,7 @@ struct sbi_platform platform = {
.console_putc = sifive_uart_putc,
.console_getc = sifive_uart_getc,
.console_init = sifive_u_console_init,
- .cold_irqchip_init = sifive_u_cold_irqchip_init,
- .warm_irqchip_init = sifive_u_warm_irqchip_init,
+ .irqchip_init = sifive_u_irqchip_init,
.ipi_inject = clint_ipi_inject,
.ipi_sync = clint_ipi_sync,
.ipi_clear = clint_ipi_clear,
diff --git a/platform/qemu/virt/platform.c b/platform/qemu/virt/platform.c
index 9e0d21a2..986dfc57 100644
--- a/platform/qemu/virt/platform.c
+++ b/platform/qemu/virt/platform.c
@@ -75,18 +75,21 @@ static int virt_console_init(void)
VIRT_UART_BAUDRATE, 0, 1);
}
-static int virt_cold_irqchip_init(void)
+static int virt_irqchip_init(u32 hartid, bool cold_boot)
{
- return plic_cold_irqchip_init(VIRT_PLIC_ADDR,
- VIRT_PLIC_NUM_SOURCES,
- VIRT_HART_COUNT);
-}
+ int rc;
-static int virt_warm_irqchip_init(u32 target_hart)
-{
- return plic_warm_irqchip_init(target_hart,
- (2 * target_hart),
- (2 * target_hart + 1));
+ if (cold_boot) {
+ rc = plic_cold_irqchip_init(VIRT_PLIC_ADDR,
+ VIRT_PLIC_NUM_SOURCES,
+ VIRT_HART_COUNT);
+ if (rc)
+ return rc;
+ }
+
+ return plic_warm_irqchip_init(hartid,
+ (2 * hartid),
+ (2 * hartid + 1));
}
static int virt_cold_ipi_init(void)
@@ -119,8 +122,7 @@ struct sbi_platform platform = {
.console_putc = uart8250_putc,
.console_getc = uart8250_getc,
.console_init = virt_console_init,
- .cold_irqchip_init = virt_cold_irqchip_init,
- .warm_irqchip_init = virt_warm_irqchip_init,
+ .irqchip_init = virt_irqchip_init,
.ipi_inject = clint_ipi_inject,
.ipi_sync = clint_ipi_sync,
.ipi_clear = clint_ipi_clear,
diff --git a/platform/sifive/hifive_u540/platform.c b/platform/sifive/hifive_u540/platform.c
index 2db5dae8..6d6ac182 100644
--- a/platform/sifive/hifive_u540/platform.c
+++ b/platform/sifive/hifive_u540/platform.c
@@ -94,18 +94,21 @@ static int sifive_u_console_init(void)
peri_in_freq, SIFIVE_UART_BAUDRATE);
}
-static int sifive_u_cold_irqchip_init(void)
+static int sifive_u_irqchip_init(u32 hartid, bool cold_boot)
{
- return plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR,
- SIFIVE_U_PLIC_NUM_SOURCES,
- SIFIVE_U_HART_COUNT);
-}
+ int rc;
-static int sifive_u_warm_irqchip_init(u32 target_hart)
-{
- return plic_warm_irqchip_init(target_hart,
- (target_hart) ? (2 * target_hart - 1) : 0,
- (target_hart) ? (2 * target_hart) : -1);
+ if (cold_boot) {
+ rc = plic_cold_irqchip_init(SIFIVE_U_PLIC_ADDR,
+ SIFIVE_U_PLIC_NUM_SOURCES,
+ SIFIVE_U_HART_COUNT);
+ if (rc)
+ return rc;
+ }
+
+ return plic_warm_irqchip_init(hartid,
+ (hartid) ? (2 * hartid - 1) : 0,
+ (hartid) ? (2 * hartid) : -1);
}
static int sifive_u_cold_ipi_init(void)
@@ -138,8 +141,7 @@ struct sbi_platform platform = {
.console_putc = sifive_uart_putc,
.console_getc = sifive_uart_getc,
.console_init = sifive_u_console_init,
- .cold_irqchip_init = sifive_u_cold_irqchip_init,
- .warm_irqchip_init = sifive_u_warm_irqchip_init,
+ .irqchip_init = sifive_u_irqchip_init,
.ipi_inject = clint_ipi_inject,
.ipi_sync = clint_ipi_sync,
.ipi_clear = clint_ipi_clear,