forked from Mirrors/opensbi
		
	lib: Simplify sbi_platform timer_init() hooks
Instead of having separate timer_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one timer_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated timer_init() hook. Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
		@@ -50,8 +50,7 @@ struct sbi_platform {
 | 
			
		||||
	u64 (*timer_value)(void);
 | 
			
		||||
	void (*timer_event_stop)(u32 target_hart);
 | 
			
		||||
	void (*timer_event_start)(u32 target_hart, u64 next_event);
 | 
			
		||||
	int (*cold_timer_init)(void);
 | 
			
		||||
	int (*warm_timer_init)(u32 target_hart);
 | 
			
		||||
	int (*timer_init)(u32 hartid, bool cold_boot);
 | 
			
		||||
	int (*system_reboot)(u32 type);
 | 
			
		||||
	int (*system_shutdown)(u32 type);
 | 
			
		||||
} __attribute__((packed));
 | 
			
		||||
@@ -216,18 +215,11 @@ static inline void sbi_platform_timer_event_start(struct sbi_platform *plat,
 | 
			
		||||
		plat->timer_event_start(target_hart, next_event);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int sbi_platform_warm_timer_init(struct sbi_platform *plat,
 | 
			
		||||
					       u32 target_hart)
 | 
			
		||||
static inline int sbi_platform_timer_init(struct sbi_platform *plat,
 | 
			
		||||
					  u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	if (plat && plat->warm_timer_init)
 | 
			
		||||
		return plat->warm_timer_init(target_hart);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int sbi_platform_cold_timer_init(struct sbi_platform *plat)
 | 
			
		||||
{
 | 
			
		||||
	if (plat && plat->cold_timer_init)
 | 
			
		||||
		return plat->cold_timer_init();
 | 
			
		||||
	if (plat && plat->timer_init)
 | 
			
		||||
		return plat->timer_init(hartid, cold_boot);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -23,8 +23,7 @@ void sbi_timer_event_start(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
 | 
			
		||||
void sbi_timer_process(struct sbi_scratch *scratch, u32 hartid);
 | 
			
		||||
 | 
			
		||||
int sbi_timer_warm_init(struct sbi_scratch *scratch, u32 hartid);
 | 
			
		||||
 | 
			
		||||
int sbi_timer_cold_init(struct sbi_scratch *scratch);
 | 
			
		||||
int sbi_timer_init(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
		   bool cold_boot);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -54,11 +54,7 @@ static void __attribute__((noreturn)) init_coldboot(struct sbi_scratch *scratch,
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_timer_cold_init(scratch);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
	rc = sbi_timer_warm_init(scratch, hartid);
 | 
			
		||||
	rc = sbi_timer_init(scratch, 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_timer_warm_init(scratch, hartid);
 | 
			
		||||
	rc = sbi_timer_init(scratch, hartid, FALSE);
 | 
			
		||||
	if (rc)
 | 
			
		||||
		sbi_hart_hang();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -67,12 +67,9 @@ void sbi_timer_process(struct sbi_scratch *scratch, u32 hartid)
 | 
			
		||||
	csr_set(mip, MIP_STIP);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_timer_warm_init(struct sbi_scratch *scratch, u32 hartid)
 | 
			
		||||
int sbi_timer_init(struct sbi_scratch *scratch, u32 hartid,
 | 
			
		||||
		   bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return sbi_platform_warm_timer_init(sbi_platform_ptr(scratch), hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_timer_cold_init(struct sbi_scratch *scratch)
 | 
			
		||||
{
 | 
			
		||||
	return sbi_platform_cold_timer_init(sbi_platform_ptr(scratch));
 | 
			
		||||
	return sbi_platform_timer_init(sbi_platform_ptr(scratch),
 | 
			
		||||
					hartid, cold_boot);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -66,9 +66,18 @@ static int k210_ipi_init(u32 hartid, bool cold_boot)
 | 
			
		||||
	return clint_warm_ipi_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int k210_cold_timer_init(void)
 | 
			
		||||
static int k210_timer_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return clint_cold_timer_init(CLINT_BASE_ADDR, K210_HART_COUNT);
 | 
			
		||||
	int rc;
 | 
			
		||||
 | 
			
		||||
	if (cold_boot) {
 | 
			
		||||
		rc = clint_cold_timer_init(CLINT_BASE_ADDR,
 | 
			
		||||
					   K210_HART_COUNT);
 | 
			
		||||
		if (rc)
 | 
			
		||||
			return rc;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return clint_warm_timer_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int k210_system_reboot(u32 type)
 | 
			
		||||
@@ -107,11 +116,10 @@ struct sbi_platform platform = {
 | 
			
		||||
	.ipi_sync = clint_ipi_sync,
 | 
			
		||||
	.ipi_clear = clint_ipi_clear,
 | 
			
		||||
 | 
			
		||||
	.cold_timer_init = k210_cold_timer_init,
 | 
			
		||||
	.timer_init = k210_timer_init,
 | 
			
		||||
	.timer_value = clint_timer_value,
 | 
			
		||||
	.timer_event_stop = clint_timer_event_stop,
 | 
			
		||||
	.timer_event_start = clint_timer_event_start,
 | 
			
		||||
	.warm_timer_init = clint_warm_timer_init,
 | 
			
		||||
 | 
			
		||||
	.system_reboot = k210_system_reboot,
 | 
			
		||||
	.system_shutdown = k210_system_shutdown
 | 
			
		||||
 
 | 
			
		||||
@@ -105,10 +105,18 @@ static int sifive_u_ipi_init(u32 hartid, bool cold_boot)
 | 
			
		||||
	return clint_warm_ipi_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sifive_u_cold_timer_init(void)
 | 
			
		||||
static int sifive_u_timer_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR,
 | 
			
		||||
				     SIFIVE_U_HART_COUNT);
 | 
			
		||||
	int rc;
 | 
			
		||||
 | 
			
		||||
	if (cold_boot) {
 | 
			
		||||
		rc = clint_cold_timer_init(SIFIVE_U_CLINT_ADDR,
 | 
			
		||||
					   SIFIVE_U_HART_COUNT);
 | 
			
		||||
		if (rc)
 | 
			
		||||
			return rc;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return clint_warm_timer_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sifive_u_system_down(u32 type)
 | 
			
		||||
@@ -137,8 +145,7 @@ struct sbi_platform platform = {
 | 
			
		||||
	.timer_value = clint_timer_value,
 | 
			
		||||
	.timer_event_stop = clint_timer_event_stop,
 | 
			
		||||
	.timer_event_start = clint_timer_event_start,
 | 
			
		||||
	.warm_timer_init = clint_warm_timer_init,
 | 
			
		||||
	.cold_timer_init = sifive_u_cold_timer_init,
 | 
			
		||||
	.timer_init = sifive_u_timer_init,
 | 
			
		||||
	.system_reboot = sifive_u_system_down,
 | 
			
		||||
	.system_shutdown = sifive_u_system_down
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -106,10 +106,18 @@ static int virt_ipi_init(u32 hartid, bool cold_boot)
 | 
			
		||||
	return clint_warm_ipi_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int virt_cold_timer_init(void)
 | 
			
		||||
static int virt_timer_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return clint_cold_timer_init(VIRT_CLINT_ADDR,
 | 
			
		||||
				     VIRT_HART_COUNT);
 | 
			
		||||
	int rc;
 | 
			
		||||
 | 
			
		||||
	if (cold_boot) {
 | 
			
		||||
		rc = clint_cold_timer_init(VIRT_CLINT_ADDR,
 | 
			
		||||
					   VIRT_HART_COUNT);
 | 
			
		||||
		if (rc)
 | 
			
		||||
			return rc;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return clint_warm_timer_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int virt_system_down(u32 type)
 | 
			
		||||
@@ -138,8 +146,7 @@ struct sbi_platform platform = {
 | 
			
		||||
	.timer_value = clint_timer_value,
 | 
			
		||||
	.timer_event_stop = clint_timer_event_stop,
 | 
			
		||||
	.timer_event_start = clint_timer_event_start,
 | 
			
		||||
	.warm_timer_init = clint_warm_timer_init,
 | 
			
		||||
	.cold_timer_init = virt_cold_timer_init,
 | 
			
		||||
	.timer_init = virt_timer_init,
 | 
			
		||||
	.system_reboot = virt_system_down,
 | 
			
		||||
	.system_shutdown = virt_system_down
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -126,10 +126,18 @@ static int sifive_u_ipi_init(u32 hartid, bool cold_boot)
 | 
			
		||||
	return clint_warm_ipi_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sifive_u_cold_timer_init(void)
 | 
			
		||||
static int sifive_u_timer_init(u32 hartid, bool cold_boot)
 | 
			
		||||
{
 | 
			
		||||
	return clint_cold_timer_init(SIFIVE_U_CLINT_ADDR,
 | 
			
		||||
				     SIFIVE_U_HART_COUNT);
 | 
			
		||||
	int rc;
 | 
			
		||||
 | 
			
		||||
	if (cold_boot) {
 | 
			
		||||
		rc = clint_cold_timer_init(SIFIVE_U_CLINT_ADDR,
 | 
			
		||||
					   SIFIVE_U_HART_COUNT);
 | 
			
		||||
		if (rc)
 | 
			
		||||
			return rc;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return clint_warm_timer_init(hartid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sifive_u_system_down(u32 type)
 | 
			
		||||
@@ -158,8 +166,7 @@ struct sbi_platform platform = {
 | 
			
		||||
	.timer_value = clint_timer_value,
 | 
			
		||||
	.timer_event_stop = clint_timer_event_stop,
 | 
			
		||||
	.timer_event_start = clint_timer_event_start,
 | 
			
		||||
	.warm_timer_init = clint_warm_timer_init,
 | 
			
		||||
	.cold_timer_init = sifive_u_cold_timer_init,
 | 
			
		||||
	.timer_init = sifive_u_timer_init,
 | 
			
		||||
	.system_reboot = sifive_u_system_down,
 | 
			
		||||
	.system_shutdown = sifive_u_system_down
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user