Re: [PATCH v4 3/3] sysreset: provide SBI based sysreset driver

2021-09-09 Thread Bin Meng
On Thu, Sep 9, 2021 at 10:14 PM Bin Meng  wrote:
>
> On Thu, Sep 9, 2021 at 9:11 PM Heinrich Schuchardt
>  wrote:
> >
> > From: Heinrich Schuchardt 

nits: this From: line is incorrect as it does not match SoB

> >
> > Provide sysreset driver using the SBI system reset extension.
> >
> > Signed-off-by: Heinrich Schuchardt 
> > ---
> > v4:
> > * remove the UEFI SystemReset() implementation
> > * simplify the code using an array to translate reset types
> > * remove a superfluos check to determine if the device was probed
> > ---
> >  MAINTAINERS |  1 +
> >  arch/riscv/cpu/cpu.c| 13 -
> >  arch/riscv/include/asm/sbi.h|  1 +
> >  arch/riscv/lib/sbi.c| 21 +++---
> >  drivers/sysreset/Kconfig| 12 
> >  drivers/sysreset/Makefile   |  1 +
> >  drivers/sysreset/sysreset_sbi.c | 51 +
> >  7 files changed, 95 insertions(+), 5 deletions(-)
> >  create mode 100644 drivers/sysreset/sysreset_sbi.c
> >

Regards,
Bin


Re: [PATCH v4 3/3] sysreset: provide SBI based sysreset driver

2021-09-09 Thread Bin Meng
On Thu, Sep 9, 2021 at 9:11 PM Heinrich Schuchardt
 wrote:
>
> From: Heinrich Schuchardt 
>
> Provide sysreset driver using the SBI system reset extension.
>
> Signed-off-by: Heinrich Schuchardt 
> ---
> v4:
> * remove the UEFI SystemReset() implementation
> * simplify the code using an array to translate reset types
> * remove a superfluos check to determine if the device was probed
> ---
>  MAINTAINERS |  1 +
>  arch/riscv/cpu/cpu.c| 13 -
>  arch/riscv/include/asm/sbi.h|  1 +
>  arch/riscv/lib/sbi.c| 21 +++---
>  drivers/sysreset/Kconfig| 12 
>  drivers/sysreset/Makefile   |  1 +
>  drivers/sysreset/sysreset_sbi.c | 51 +
>  7 files changed, 95 insertions(+), 5 deletions(-)
>  create mode 100644 drivers/sysreset/sysreset_sbi.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 4cf0c33c5d..88d7aa2bc7 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1017,6 +1017,7 @@ T:git 
> https://source.denx.de/u-boot/custodians/u-boot-riscv.git
>  F: arch/riscv/
>  F: cmd/riscv/
>  F: doc/usage/sbi.rst
> +F: drivers/sysreset/sysreset_sbi.c
>  F: drivers/timer/andes_plmt_timer.c
>  F: drivers/timer/sifive_clint_timer.c
>  F: tools/prelink-riscv.c
> diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c
> index c894ac10b5..8e49b6d736 100644
> --- a/arch/riscv/cpu/cpu.c
> +++ b/arch/riscv/cpu/cpu.c
> @@ -6,6 +6,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -138,7 +139,17 @@ int arch_cpu_init_dm(void)
>
>  int arch_early_init_r(void)
>  {
> -   return riscv_cpu_probe();
> +   int ret;
> +
> +   ret = riscv_cpu_probe();
> +   if (ret)
> +   return ret;
> +
> +   if (IS_ENABLED(CONFIG_SYSRESET_SBI))
> +   device_bind_driver(gd->dm_root, "sbi-sysreset",
> +  "sbi-sysreset", NULL);
> +
> +   return 0;
>  }
>
>  /**
> diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
> index 34a115afc3..5030892b47 100644
> --- a/arch/riscv/include/asm/sbi.h
> +++ b/arch/riscv/include/asm/sbi.h
> @@ -153,5 +153,6 @@ void sbi_set_timer(uint64_t stime_value);
>  long sbi_get_spec_version(void);
>  int sbi_get_impl_id(void);
>  int sbi_probe_extension(int ext);
> +void sbi_srst_reset(unsigned long type, unsigned long reason);
>
>  #endif
> diff --git a/arch/riscv/lib/sbi.c b/arch/riscv/lib/sbi.c
> index 77845a73ca..8508041f2a 100644
> --- a/arch/riscv/lib/sbi.c
> +++ b/arch/riscv/lib/sbi.c
> @@ -8,13 +8,14 @@
>   */
>
>  #include 
> +#include 
>  #include 
>  #include 
>
> -struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
> -   unsigned long arg1, unsigned long arg2,
> -   unsigned long arg3, unsigned long arg4,
> -   unsigned long arg5)
> +struct sbiret __efi_runtime sbi_ecall(int ext, int fid, unsigned long arg0,
> + unsigned long arg1, unsigned long arg2,
> + unsigned long arg3, unsigned long arg4,
> + unsigned long arg5)

unnecessary change

>  {
> struct sbiret ret;
>
> @@ -108,6 +109,18 @@ int sbi_probe_extension(int extid)
> return -ENOTSUPP;
>  }
>
> +/**
> + * sbi_srst_reset() - invoke system reset extension
> + *
> + * @type:  type of reset
> + * @reason:reason for reset
> + */
> +void __efi_runtime sbi_srst_reset(unsigned long type, unsigned long reason)

remove __efi_runtime

> +{
> +   sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason,
> + 0, 0, 0, 0);
> +}
> +
>  #ifdef CONFIG_SBI_V01
>
>  /**
> diff --git a/drivers/sysreset/Kconfig b/drivers/sysreset/Kconfig
> index ac77ffbc8b..43a948cfcd 100644
> --- a/drivers/sysreset/Kconfig
> +++ b/drivers/sysreset/Kconfig
> @@ -85,6 +85,18 @@ config SYSRESET_PSCI
>   Enable PSCI SYSTEM_RESET function call.  To use this, PSCI firmware
>   must be running on your system.
>
> +config SYSRESET_SBI
> +   bool "Enable support for SBI System Reset"
> +   depends on RISCV_SMODE && SBI_V02
> +   select SYSRESET_CMD_POWEROFF if CMD_POWEROFF
> +   help
> + Enable system reset and poweroff via the SBI system reset extension.
> + The extension was introduced in version 0.3 of the SBI 
> specification.
> +
> + If the SBI implementation provides the extension, is board specific.
> + The RISC-V platform specification mandates the extension for rich
> + operating system platforms.
> +
>  config SYSRESET_SOCFPGA
> bool "Enable support for Intel SOCFPGA family"
> depends on ARCH_SOCFPGA && (TARGET_SOCFPGA_GEN5 || 
> TARGET_SOCFPGA_ARRIA10)
> diff --git a/drivers/sysreset/Makefile b/drivers/sysreset/Makefile
> index de81c399d7..8e00be0779 100644
> ---