forked from Mirrors/opensbi
		
	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 <anup.patel@wdc.com>
This commit is contained in:
		@@ -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)
 | 
			
		||||
static inline int sbi_platform_irqchip_init(struct sbi_platform *plat,
 | 
			
		||||
					    u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	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)
 | 
			
		||||
{
 | 
			
		||||
	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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user