forked from Mirrors/opensbi
lib: sbi: Simplify system reset platform operations
Instead of having system_reset_check() and system_reset() callbacks in platform operations, it will be much simpler for reset driver to directly register these operations as a device to the sbi_system implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
This commit is contained in:
@@ -18,10 +18,25 @@
|
||||
#include <sbi/sbi_ipi.h>
|
||||
#include <sbi/sbi_init.h>
|
||||
|
||||
static const struct sbi_system_reset_device *reset_dev = NULL;
|
||||
|
||||
const struct sbi_system_reset_device *sbi_system_reset_get_device(void)
|
||||
{
|
||||
return reset_dev;
|
||||
}
|
||||
|
||||
void sbi_system_reset_set_device(const struct sbi_system_reset_device *dev)
|
||||
{
|
||||
if (!dev || reset_dev)
|
||||
return;
|
||||
|
||||
reset_dev = dev;
|
||||
}
|
||||
|
||||
bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason)
|
||||
{
|
||||
if (sbi_platform_system_reset_check(sbi_platform_thishart_ptr(),
|
||||
reset_type, reset_reason))
|
||||
if (reset_dev && reset_dev->system_reset_check &&
|
||||
reset_dev->system_reset_check(reset_type, reset_reason))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
@@ -47,9 +62,9 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
|
||||
sbi_hsm_hart_stop(scratch, FALSE);
|
||||
|
||||
/* Platform specific reset if domain allowed system reset */
|
||||
if (dom->system_reset_allowed)
|
||||
sbi_platform_system_reset(sbi_platform_ptr(scratch),
|
||||
reset_type, reset_reason);
|
||||
if (dom->system_reset_allowed &&
|
||||
reset_dev && reset_dev->system_reset)
|
||||
reset_dev->system_reset(reset_type, reset_reason);
|
||||
|
||||
/* If platform specific reset did not work then do sbi_exit() */
|
||||
sbi_exit(scratch);
|
||||
|
@@ -23,20 +23,6 @@ static struct fdt_reset *reset_drivers[] = {
|
||||
|
||||
static struct fdt_reset *current_driver = NULL;
|
||||
|
||||
int fdt_system_reset_check(u32 reset_type, u32 reset_reason)
|
||||
{
|
||||
if (current_driver && current_driver->system_reset_check)
|
||||
return current_driver->system_reset_check(reset_type,
|
||||
reset_reason);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fdt_system_reset(u32 reset_type, u32 reset_reason)
|
||||
{
|
||||
if (current_driver && current_driver->system_reset)
|
||||
current_driver->system_reset(reset_type, reset_reason);
|
||||
}
|
||||
|
||||
int fdt_reset_init(void)
|
||||
{
|
||||
int pos, noff, rc;
|
||||
|
@@ -11,6 +11,12 @@
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
#include <sbi_utils/sys/htif.h>
|
||||
|
||||
static int htif_reset_init(void *fdt, int nodeoff,
|
||||
const struct fdt_match *match)
|
||||
{
|
||||
return htif_system_reset_init();
|
||||
}
|
||||
|
||||
static const struct fdt_match htif_reset_match[] = {
|
||||
{ .compatible = "ucb,htif0" },
|
||||
{ },
|
||||
@@ -18,6 +24,5 @@ static const struct fdt_match htif_reset_match[] = {
|
||||
|
||||
struct fdt_reset fdt_reset_htif = {
|
||||
.match_table = htif_reset_match,
|
||||
.system_reset_check = htif_system_reset_check,
|
||||
.system_reset = htif_system_reset
|
||||
.init = htif_reset_init
|
||||
};
|
||||
|
@@ -33,6 +33,4 @@ static const struct fdt_match sifive_test_reset_match[] = {
|
||||
struct fdt_reset fdt_reset_sifive = {
|
||||
.match_table = sifive_test_reset_match,
|
||||
.init = sifive_test_reset_init,
|
||||
.system_reset_check = sifive_test_system_reset_check,
|
||||
.system_reset = sifive_test_system_reset
|
||||
};
|
||||
|
@@ -7,8 +7,10 @@
|
||||
#include <sbi/sbi_bitops.h>
|
||||
#include <sbi/sbi_hart.h>
|
||||
#include <sbi/sbi_scratch.h>
|
||||
#include <sbi/sbi_system.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
#include <sbi_utils/reset/fdt_reset.h>
|
||||
|
||||
#include "fdt_reset_thead.h"
|
||||
|
||||
struct custom_csr custom_csr[MAX_CUSTOM_CSR];
|
||||
@@ -37,6 +39,22 @@ static void clone_csrs(int cnt)
|
||||
}
|
||||
}
|
||||
|
||||
static int thead_system_reset_check(u32 type, u32 reason)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void thead_system_reset(u32 type, u32 reason)
|
||||
{
|
||||
ebreak();
|
||||
}
|
||||
|
||||
static struct sbi_system_reset_device thead_reset = {
|
||||
.name = "thead_reset",
|
||||
.system_reset_check = thead_system_reset_check,
|
||||
.system_reset = thead_system_reset
|
||||
};
|
||||
|
||||
extern void __thead_pre_start_warm(void);
|
||||
static int thead_reset_init(void *fdt, int nodeoff,
|
||||
const struct fdt_match *match)
|
||||
@@ -106,19 +124,11 @@ static int thead_reset_init(void *fdt, int nodeoff,
|
||||
}
|
||||
}
|
||||
|
||||
sbi_system_reset_set_device(&thead_reset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int thead_system_reset_check(u32 type, u32 reason)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void thead_system_reset(u32 type, u32 reason)
|
||||
{
|
||||
ebreak();
|
||||
}
|
||||
|
||||
static const struct fdt_match thead_reset_match[] = {
|
||||
{ .compatible = "thead,reset-sample" },
|
||||
{ },
|
||||
@@ -126,7 +136,5 @@ static const struct fdt_match thead_reset_match[] = {
|
||||
|
||||
struct fdt_reset fdt_reset_thead = {
|
||||
.match_table = thead_reset_match,
|
||||
.init = thead_reset_init,
|
||||
.system_reset_check = thead_system_reset_check,
|
||||
.system_reset = thead_system_reset
|
||||
.init = thead_reset_init
|
||||
};
|
||||
|
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <sbi/riscv_locks.h>
|
||||
#include <sbi/sbi_console.h>
|
||||
#include <sbi/sbi_system.h>
|
||||
#include <sbi_utils/sys/htif.h>
|
||||
|
||||
#define HTIF_DATA_BITS 48
|
||||
@@ -154,15 +155,28 @@ int htif_serial_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int htif_system_reset_check(u32 type, u32 reason)
|
||||
static int htif_system_reset_check(u32 type, u32 reason)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
void htif_system_reset(u32 type, u32 reason)
|
||||
static void htif_system_reset(u32 type, u32 reason)
|
||||
{
|
||||
while (1) {
|
||||
fromhost = 0;
|
||||
tohost = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static struct sbi_system_reset_device htif_reset = {
|
||||
.name = "htif",
|
||||
.system_reset_check = htif_system_reset_check,
|
||||
.system_reset = htif_system_reset
|
||||
};
|
||||
|
||||
int htif_system_reset_init(void)
|
||||
{
|
||||
sbi_system_reset_set_device(&htif_reset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/sbi_ecall_interface.h>
|
||||
#include <sbi/sbi_system.h>
|
||||
#include <sbi_utils/sys/sifive_test.h>
|
||||
|
||||
#define FINISHER_FAIL 0x3333
|
||||
@@ -17,7 +18,7 @@
|
||||
|
||||
static void *sifive_test_base;
|
||||
|
||||
int sifive_test_system_reset_check(u32 type, u32 reason)
|
||||
static int sifive_test_system_reset_check(u32 type, u32 reason)
|
||||
{
|
||||
switch (type) {
|
||||
case SBI_SRST_RESET_TYPE_SHUTDOWN:
|
||||
@@ -29,7 +30,7 @@ int sifive_test_system_reset_check(u32 type, u32 reason)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sifive_test_system_reset(u32 type, u32 reason)
|
||||
static void sifive_test_system_reset(u32 type, u32 reason)
|
||||
{
|
||||
/*
|
||||
* Tell the "finisher" that the simulation
|
||||
@@ -49,9 +50,16 @@ void sifive_test_system_reset(u32 type, u32 reason)
|
||||
}
|
||||
}
|
||||
|
||||
static struct sbi_system_reset_device sifive_test_reset = {
|
||||
.name = "sifive_test",
|
||||
.system_reset_check = sifive_test_system_reset_check,
|
||||
.system_reset = sifive_test_system_reset
|
||||
};
|
||||
|
||||
int sifive_test_init(unsigned long base)
|
||||
{
|
||||
sifive_test_base = (void *)base;
|
||||
sbi_system_reset_set_device(&sifive_test_reset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user