forked from Mirrors/opensbi
		
	lib: Simplify sbi_platform early_init() and final_init() hooks
Instead of having separate early_init() and final_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one early_init() and one final_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated early_init() and final_init() hooks. Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
		@@ -34,10 +34,8 @@ struct sbi_platform {
 | 
			
		||||
	u32 hart_count;
 | 
			
		||||
	u32 hart_stack_size;
 | 
			
		||||
	u64 disabled_hart_mask;
 | 
			
		||||
	int (*cold_early_init)(void);
 | 
			
		||||
	int (*cold_final_init)(void);
 | 
			
		||||
	int (*warm_early_init)(u32 target_hart);
 | 
			
		||||
	int (*warm_final_init)(u32 target_hart);
 | 
			
		||||
	int (*early_init)(u32 hartid, bool cold_boot);
 | 
			
		||||
	int (*final_init)(u32 hartid, bool cold_boot);
 | 
			
		||||
	u32 (*pmp_region_count)(u32 target_hart);
 | 
			
		||||
	int (*pmp_region_info)(u32 target_hart, u32 index,
 | 
			
		||||
			       ulong *prot, ulong *addr, ulong *log2size);
 | 
			
		||||
@@ -105,33 +103,19 @@ static inline u32 sbi_platform_hart_stack_size(struct sbi_platform *plat)
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int sbi_platform_cold_early_init(struct sbi_platform *plat)
 | 
			
		||||
static inline int sbi_platform_early_init(struct sbi_platform *plat,
 | 
			
		||||
					  u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	if (plat && plat->cold_early_init)
 | 
			
		||||
		return plat->cold_early_init();
 | 
			
		||||
	if (plat && plat->early_init)
 | 
			
		||||
		return plat->early_init(hartid, cold_boot);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int sbi_platform_cold_final_init(struct sbi_platform *plat)
 | 
			
		||||
static inline int sbi_platform_final_init(struct sbi_platform *plat,
 | 
			
		||||
					  u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	if (plat && plat->cold_final_init)
 | 
			
		||||
		return plat->cold_final_init();
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int sbi_platform_warm_early_init(struct sbi_platform *plat,
 | 
			
		||||
					       u32 target_hart)
 | 
			
		||||
{
 | 
			
		||||
	if (plat && plat->warm_early_init)
 | 
			
		||||
		return plat->warm_early_init(target_hart);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int sbi_platform_warm_final_init(struct sbi_platform *plat,
 | 
			
		||||
					       u32 target_hart)
 | 
			
		||||
{
 | 
			
		||||
	if (plat && plat->warm_final_init)
 | 
			
		||||
		return plat->warm_final_init(target_hart);
 | 
			
		||||
	if (plat && plat->final_init)
 | 
			
		||||
		return plat->final_init(hartid, cold_boot);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -14,13 +14,11 @@
 | 
			
		||||
 | 
			
		||||
struct sbi_scratch;
 | 
			
		||||
 | 
			
		||||
int sbi_system_warm_early_init(struct sbi_scratch *scratch, u32 hartid);
 | 
			
		||||
int sbi_system_early_init(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
			  bool cold_boot);
 | 
			
		||||
 | 
			
		||||
int sbi_system_warm_final_init(struct sbi_scratch *scratch, u32 hartid);
 | 
			
		||||
 | 
			
		||||
int sbi_system_cold_early_init(struct sbi_scratch *scratch);
 | 
			
		||||
 | 
			
		||||
int sbi_system_cold_final_init(struct sbi_scratch *scratch);
 | 
			
		||||
int sbi_system_final_init(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
			  bool cold_boot);
 | 
			
		||||
 | 
			
		||||
void __attribute__((noreturn)) sbi_system_reboot(struct sbi_scratch *scratch,
 | 
			
		||||
						 u32 type);
 | 
			
		||||
 
 | 
			
		||||
@@ -34,11 +34,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch,
 | 
			
		||||
	char str[64];
 | 
			
		||||
	struct sbi_platform *plat = sbi_platform_ptr(scratch);
 | 
			
		||||
 | 
			
		||||
	rc = sbi_system_cold_early_init(scratch);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_system_warm_early_init(scratch, hartid);
 | 
			
		||||
	rc = sbi_system_early_init(scratch, hartid, TRUE);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
@@ -74,11 +70,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch,
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_system_cold_final_init(scratch);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_system_warm_final_init(scratch, hartid);
 | 
			
		||||
	rc = sbi_system_final_init(scratch, hartid, TRUE);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
@@ -125,7 +117,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch,
 | 
			
		||||
	if (sbi_platform_hart_disabled(plat, hartid))
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_system_warm_early_init(scratch, hartid);
 | 
			
		||||
	rc = sbi_system_early_init(scratch, hartid, FALSE);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
@@ -145,7 +137,7 @@ static void __attribute__((noreturn)) init_warmboot(struct sbi_scratch *scratch,
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_system_warm_final_init(scratch, hartid);
 | 
			
		||||
	rc = sbi_system_final_init(scratch, hartid, FALSE);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,24 +11,18 @@
 | 
			
		||||
#include <sbi/sbi_platform.h>
 | 
			
		||||
#include <sbi/sbi_system.h>
 | 
			
		||||
 | 
			
		||||
int sbi_system_warm_early_init(struct sbi_scratch *scratch, u32 hartid)
 | 
			
		||||
int sbi_system_early_init(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
			  bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return sbi_platform_warm_early_init(sbi_platform_ptr(scratch), hartid);
 | 
			
		||||
	return sbi_platform_early_init(sbi_platform_ptr(scratch),
 | 
			
		||||
					hartid, cold_boot);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_system_warm_final_init(struct sbi_scratch *scratch, u32 hartid)
 | 
			
		||||
int sbi_system_final_init(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
			  bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return sbi_platform_warm_final_init(sbi_platform_ptr(scratch), hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_system_cold_early_init(struct sbi_scratch *scratch)
 | 
			
		||||
{
 | 
			
		||||
	return sbi_platform_cold_early_init(sbi_platform_ptr(scratch));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_system_cold_final_init(struct sbi_scratch *scratch)
 | 
			
		||||
{
 | 
			
		||||
	return sbi_platform_cold_final_init(sbi_platform_ptr(scratch));
 | 
			
		||||
	return sbi_platform_final_init(sbi_platform_ptr(scratch),
 | 
			
		||||
					hartid, cold_boot);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void __attribute__((noreturn)) sbi_system_reboot(struct sbi_scratch *scratch,
 | 
			
		||||
 
 | 
			
		||||
@@ -102,8 +102,6 @@ struct sbi_platform platform = {
 | 
			
		||||
	.timer_event_start = clint_timer_event_start,
 | 
			
		||||
	.warm_timer_init = clint_warm_timer_init,
 | 
			
		||||
 | 
			
		||||
	.cold_final_init = NULL,
 | 
			
		||||
 | 
			
		||||
	.system_reboot = k210_system_reboot,
 | 
			
		||||
	.system_shutdown = k210_system_shutdown
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -29,11 +29,15 @@
 | 
			
		||||
#define SIFIVE_U_UART0_ADDR			0x10013000
 | 
			
		||||
#define SIFIVE_U_UART1_ADDR			0x10023000
 | 
			
		||||
 | 
			
		||||
static int sifive_u_cold_final_init(void)
 | 
			
		||||
static int sifive_u_final_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	u32 i;
 | 
			
		||||
	void *fdt = sbi_scratch_thishart_arg1_ptr();
 | 
			
		||||
	void *fdt;
 | 
			
		||||
 | 
			
		||||
	if (!cold_boot)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	fdt = sbi_scratch_thishart_arg1_ptr();
 | 
			
		||||
	for (i = 0; i < SIFIVE_U_HART_COUNT; i++)
 | 
			
		||||
		plic_fdt_fixup(fdt, "riscv,plic0", 2 * i);
 | 
			
		||||
 | 
			
		||||
@@ -110,7 +114,7 @@ struct sbi_platform platform = {
 | 
			
		||||
	.disabled_hart_mask = 0,
 | 
			
		||||
	.pmp_region_count = sifive_u_pmp_region_count,
 | 
			
		||||
	.pmp_region_info = sifive_u_pmp_region_info,
 | 
			
		||||
	.cold_final_init = sifive_u_cold_final_init,
 | 
			
		||||
	.final_init = sifive_u_final_init,
 | 
			
		||||
	.console_putc = sifive_uart_putc,
 | 
			
		||||
	.console_getc = sifive_uart_getc,
 | 
			
		||||
	.console_init = sifive_u_console_init,
 | 
			
		||||
 
 | 
			
		||||
@@ -29,11 +29,15 @@
 | 
			
		||||
#define VIRT_UART_BAUDRATE		115200
 | 
			
		||||
#define VIRT_UART_SHIFTREG_ADDR		1843200
 | 
			
		||||
 | 
			
		||||
static int virt_cold_final_init(void)
 | 
			
		||||
static int virt_final_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	u32 i;
 | 
			
		||||
	void *fdt = sbi_scratch_thishart_arg1_ptr();
 | 
			
		||||
	void *fdt;
 | 
			
		||||
 | 
			
		||||
	if (!cold_boot)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	fdt = sbi_scratch_thishart_arg1_ptr();
 | 
			
		||||
	for (i = 0; i < VIRT_HART_COUNT; i++)
 | 
			
		||||
		plic_fdt_fixup(fdt, "riscv,plic0", 2 * i);
 | 
			
		||||
 | 
			
		||||
@@ -111,7 +115,7 @@ struct sbi_platform platform = {
 | 
			
		||||
	.disabled_hart_mask = 0,
 | 
			
		||||
	.pmp_region_count = virt_pmp_region_count,
 | 
			
		||||
	.pmp_region_info = virt_pmp_region_info,
 | 
			
		||||
	.cold_final_init = virt_cold_final_init,
 | 
			
		||||
	.final_init = virt_final_init,
 | 
			
		||||
	.console_putc = uart8250_putc,
 | 
			
		||||
	.console_getc = uart8250_getc,
 | 
			
		||||
	.console_init = virt_console_init,
 | 
			
		||||
 
 | 
			
		||||
@@ -38,11 +38,15 @@
 | 
			
		||||
#define SIFIVE_PRCI_CLKMUXSTATUSREG    		0x002C
 | 
			
		||||
#define SIFIVE_PRCI_CLKMUX_STATUS_TLCLKSEL      (0x1 << 1)
 | 
			
		||||
 | 
			
		||||
static int sifive_u_cold_final_init(void)
 | 
			
		||||
static int sifive_u_final_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	u32 i;
 | 
			
		||||
	void *fdt = sbi_scratch_thishart_arg1_ptr();
 | 
			
		||||
	void *fdt;
 | 
			
		||||
 | 
			
		||||
	if (!cold_boot)
 | 
			
		||||
		return 0;
 | 
			
		||||
 | 
			
		||||
	fdt = sbi_scratch_thishart_arg1_ptr();
 | 
			
		||||
	plic_fdt_fixup(fdt, "riscv,plic0", 0);
 | 
			
		||||
	for (i = 1; i < SIFIVE_U_HART_COUNT; i++)
 | 
			
		||||
		plic_fdt_fixup(fdt, "riscv,plic0", 2 * i - 1);
 | 
			
		||||
@@ -130,7 +134,7 @@ struct sbi_platform platform = {
 | 
			
		||||
	.disabled_hart_mask = ~(1 << SIFIVE_U_HARITD_ENABLED),
 | 
			
		||||
	.pmp_region_count = sifive_u_pmp_region_count,
 | 
			
		||||
	.pmp_region_info = sifive_u_pmp_region_info,
 | 
			
		||||
	.cold_final_init = sifive_u_cold_final_init,
 | 
			
		||||
	.final_init = sifive_u_final_init,
 | 
			
		||||
	.console_putc = sifive_uart_putc,
 | 
			
		||||
	.console_getc = sifive_uart_getc,
 | 
			
		||||
	.console_init = sifive_u_console_init,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user