All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <anup@brainfault.org>
To: Palmer Dabbelt <palmerdabbelt@google.com>
Cc: Anup Patel <Anup.Patel@wdc.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Atish Patra <Atish.Patra@wdc.com>,
	Alistair Francis <Alistair.Francis@wdc.com>,
	linux-riscv <linux-riscv@lists.infradead.org>,
	"linux-kernel@vger.kernel.org List"
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v7 1/1] RISC-V: Use SBI SRST extension when available
Date: Wed, 7 Jul 2021 21:19:46 +0530	[thread overview]
Message-ID: <CAAhSdy2TcESa_zfO28VGPuOH6+7T+U-Pa25G959LvMCmU49pJA@mail.gmail.com> (raw)
In-Reply-To: <mhng-b2af24ea-608a-4e2c-af51-6dc7e415bf30@palmerdabbelt-glaptop>

On Wed, Jul 7, 2021 at 1:57 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>
> On Mon, 21 Jun 2021 21:46:46 PDT (-0700), anup@brainfault.org wrote:
> > Hi Palmer,
> >
> > On Wed, Jun 9, 2021 at 5:43 PM Anup Patel <anup.patel@wdc.com> wrote:
> >>
> >> The SBI SRST extension provides a standard way to poweroff and
> >> reboot the system irrespective to whether Linux RISC-V S-mode
> >> is running natively (HS-mode) or inside Guest/VM (VS-mode).
> >>
> >> The SBI SRST extension is available in the SBI v0.3 specification.
> >> (Refer, https://github.com/riscv/riscv-sbi-doc/releases/tag/v0.3.0-rc1)
> >
> > Can you please consider this patch for Linux-5.14-rc1 ?
> >
> > The SBI v0.3 spec is already frozen and this patch has been
> > floating on LKML for quite a few months now.
>
> I didn't realize that SBI-0.3 had been frozed.  That link is to a RC,
> the cooresponding v0.3.0 tag isn't in that repo.  Can you give me a
> pointer to the frozen spec?

Here's the link to SBI v0.3.0 tag:
https://github.com/riscv/riscv-sbi-doc/releases/tag/v0.3.0

We treat RC tags as frozen in SBI spec because no functional
changes are done in SBI spec after it is tagged as RC. We only
do typo fixes and clarifications on SBI spec RC release.

Regards,
Anup

>
> >
> > Regards,
> > Anup
> >
> >>
> >> This patch extends Linux RISC-V SBI implementation to detect
> >> and use SBI SRST extension.
> >>
> >> Signed-off-by: Anup Patel <anup.patel@wdc.com>
> >> Reviewed-by: Atish Patra <atish.patra@wdc.com>
> >> ---
> >>  arch/riscv/include/asm/sbi.h | 24 ++++++++++++++++++++++++
> >>  arch/riscv/kernel/sbi.c      | 35 +++++++++++++++++++++++++++++++++++
> >>  2 files changed, 59 insertions(+)
> >>
> >> diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
> >> index 0d42693cb65e..289621da4a2a 100644
> >> --- a/arch/riscv/include/asm/sbi.h
> >> +++ b/arch/riscv/include/asm/sbi.h
> >> @@ -27,6 +27,7 @@ enum sbi_ext_id {
> >>         SBI_EXT_IPI = 0x735049,
> >>         SBI_EXT_RFENCE = 0x52464E43,
> >>         SBI_EXT_HSM = 0x48534D,
> >> +       SBI_EXT_SRST = 0x53525354,
> >>  };
> >>
> >>  enum sbi_ext_base_fid {
> >> @@ -70,6 +71,21 @@ enum sbi_hsm_hart_status {
> >>         SBI_HSM_HART_STATUS_STOP_PENDING,
> >>  };
> >>
> >> +enum sbi_ext_srst_fid {
> >> +       SBI_EXT_SRST_RESET = 0,
> >> +};
> >> +
> >> +enum sbi_srst_reset_type {
> >> +       SBI_SRST_RESET_TYPE_SHUTDOWN = 0,
> >> +       SBI_SRST_RESET_TYPE_COLD_REBOOT,
> >> +       SBI_SRST_RESET_TYPE_WARM_REBOOT,
> >> +};
> >> +
> >> +enum sbi_srst_reset_reason {
> >> +       SBI_SRST_RESET_REASON_NONE = 0,
> >> +       SBI_SRST_RESET_REASON_SYS_FAILURE,
> >> +};
> >> +
> >>  #define SBI_SPEC_VERSION_DEFAULT       0x1
> >>  #define SBI_SPEC_VERSION_MAJOR_SHIFT   24
> >>  #define SBI_SPEC_VERSION_MAJOR_MASK    0x7f
> >> @@ -148,6 +164,14 @@ static inline unsigned long sbi_minor_version(void)
> >>         return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK;
> >>  }
> >>
> >> +/* Make SBI version */
> >> +static inline unsigned long sbi_mk_version(unsigned long major,
> >> +                                           unsigned long minor)
> >> +{
> >> +       return ((major & SBI_SPEC_VERSION_MAJOR_MASK) <<
> >> +               SBI_SPEC_VERSION_MAJOR_SHIFT) | minor;
> >> +}
> >> +
> >>  int sbi_err_map_linux_errno(int err);
> >>  #else /* CONFIG_RISCV_SBI */
> >>  static inline int sbi_remote_fence_i(const unsigned long *hart_mask) { return -1; }
> >> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> >> index 7402a417f38e..9a84f0cb5175 100644
> >> --- a/arch/riscv/kernel/sbi.c
> >> +++ b/arch/riscv/kernel/sbi.c
> >> @@ -7,6 +7,7 @@
> >>
> >>  #include <linux/init.h>
> >>  #include <linux/pm.h>
> >> +#include <linux/reboot.h>
> >>  #include <asm/sbi.h>
> >>  #include <asm/smp.h>
> >>
> >> @@ -501,6 +502,32 @@ int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
> >>  }
> >>  EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);
> >>
> >> +static void sbi_srst_reset(unsigned long type, unsigned long reason)
> >> +{
> >> +       sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason,
> >> +                 0, 0, 0, 0);
> >> +       pr_warn("%s: type=0x%lx reason=0x%lx failed\n",
> >> +               __func__, type, reason);
> >> +}
> >> +
> >> +static int sbi_srst_reboot(struct notifier_block *this,
> >> +                          unsigned long mode, void *cmd)
> >> +{
> >> +       sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
> >> +                      SBI_SRST_RESET_TYPE_WARM_REBOOT :
> >> +                      SBI_SRST_RESET_TYPE_COLD_REBOOT,
> >> +                      SBI_SRST_RESET_REASON_NONE);
> >> +       return NOTIFY_DONE;
> >> +}
> >> +
> >> +static struct notifier_block sbi_srst_reboot_nb;
> >> +
> >> +static void sbi_srst_power_off(void)
> >> +{
> >> +       sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN,
> >> +                      SBI_SRST_RESET_REASON_NONE);
> >> +}
> >> +
> >>  /**
> >>   * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
> >>   * @extid: The extension ID to be probed.
> >> @@ -608,6 +635,14 @@ void __init sbi_init(void)
> >>                 } else {
> >>                         __sbi_rfence    = __sbi_rfence_v01;
> >>                 }
> >> +               if ((sbi_spec_version >= sbi_mk_version(0, 3)) &&
> >> +                   (sbi_probe_extension(SBI_EXT_SRST) > 0)) {
> >> +                       pr_info("SBI SRST extension detected\n");
> >> +                       pm_power_off = sbi_srst_power_off;
> >> +                       sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot;
> >> +                       sbi_srst_reboot_nb.priority = 192;
> >> +                       register_restart_handler(&sbi_srst_reboot_nb);
> >> +               }
> >>         } else {
> >>                 __sbi_set_timer = __sbi_set_timer_v01;
> >>                 __sbi_send_ipi  = __sbi_send_ipi_v01;
> >> --
> >> 2.25.1
> >>

WARNING: multiple messages have this Message-ID (diff)
From: Anup Patel <anup@brainfault.org>
To: Palmer Dabbelt <palmerdabbelt@google.com>
Cc: Anup Patel <Anup.Patel@wdc.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	 Albert Ou <aou@eecs.berkeley.edu>,
	Atish Patra <Atish.Patra@wdc.com>,
	 Alistair Francis <Alistair.Francis@wdc.com>,
	linux-riscv <linux-riscv@lists.infradead.org>,
	 "linux-kernel@vger.kernel.org List"
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v7 1/1] RISC-V: Use SBI SRST extension when available
Date: Wed, 7 Jul 2021 21:19:46 +0530	[thread overview]
Message-ID: <CAAhSdy2TcESa_zfO28VGPuOH6+7T+U-Pa25G959LvMCmU49pJA@mail.gmail.com> (raw)
In-Reply-To: <mhng-b2af24ea-608a-4e2c-af51-6dc7e415bf30@palmerdabbelt-glaptop>

On Wed, Jul 7, 2021 at 1:57 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>
> On Mon, 21 Jun 2021 21:46:46 PDT (-0700), anup@brainfault.org wrote:
> > Hi Palmer,
> >
> > On Wed, Jun 9, 2021 at 5:43 PM Anup Patel <anup.patel@wdc.com> wrote:
> >>
> >> The SBI SRST extension provides a standard way to poweroff and
> >> reboot the system irrespective to whether Linux RISC-V S-mode
> >> is running natively (HS-mode) or inside Guest/VM (VS-mode).
> >>
> >> The SBI SRST extension is available in the SBI v0.3 specification.
> >> (Refer, https://github.com/riscv/riscv-sbi-doc/releases/tag/v0.3.0-rc1)
> >
> > Can you please consider this patch for Linux-5.14-rc1 ?
> >
> > The SBI v0.3 spec is already frozen and this patch has been
> > floating on LKML for quite a few months now.
>
> I didn't realize that SBI-0.3 had been frozed.  That link is to a RC,
> the cooresponding v0.3.0 tag isn't in that repo.  Can you give me a
> pointer to the frozen spec?

Here's the link to SBI v0.3.0 tag:
https://github.com/riscv/riscv-sbi-doc/releases/tag/v0.3.0

We treat RC tags as frozen in SBI spec because no functional
changes are done in SBI spec after it is tagged as RC. We only
do typo fixes and clarifications on SBI spec RC release.

Regards,
Anup

>
> >
> > Regards,
> > Anup
> >
> >>
> >> This patch extends Linux RISC-V SBI implementation to detect
> >> and use SBI SRST extension.
> >>
> >> Signed-off-by: Anup Patel <anup.patel@wdc.com>
> >> Reviewed-by: Atish Patra <atish.patra@wdc.com>
> >> ---
> >>  arch/riscv/include/asm/sbi.h | 24 ++++++++++++++++++++++++
> >>  arch/riscv/kernel/sbi.c      | 35 +++++++++++++++++++++++++++++++++++
> >>  2 files changed, 59 insertions(+)
> >>
> >> diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
> >> index 0d42693cb65e..289621da4a2a 100644
> >> --- a/arch/riscv/include/asm/sbi.h
> >> +++ b/arch/riscv/include/asm/sbi.h
> >> @@ -27,6 +27,7 @@ enum sbi_ext_id {
> >>         SBI_EXT_IPI = 0x735049,
> >>         SBI_EXT_RFENCE = 0x52464E43,
> >>         SBI_EXT_HSM = 0x48534D,
> >> +       SBI_EXT_SRST = 0x53525354,
> >>  };
> >>
> >>  enum sbi_ext_base_fid {
> >> @@ -70,6 +71,21 @@ enum sbi_hsm_hart_status {
> >>         SBI_HSM_HART_STATUS_STOP_PENDING,
> >>  };
> >>
> >> +enum sbi_ext_srst_fid {
> >> +       SBI_EXT_SRST_RESET = 0,
> >> +};
> >> +
> >> +enum sbi_srst_reset_type {
> >> +       SBI_SRST_RESET_TYPE_SHUTDOWN = 0,
> >> +       SBI_SRST_RESET_TYPE_COLD_REBOOT,
> >> +       SBI_SRST_RESET_TYPE_WARM_REBOOT,
> >> +};
> >> +
> >> +enum sbi_srst_reset_reason {
> >> +       SBI_SRST_RESET_REASON_NONE = 0,
> >> +       SBI_SRST_RESET_REASON_SYS_FAILURE,
> >> +};
> >> +
> >>  #define SBI_SPEC_VERSION_DEFAULT       0x1
> >>  #define SBI_SPEC_VERSION_MAJOR_SHIFT   24
> >>  #define SBI_SPEC_VERSION_MAJOR_MASK    0x7f
> >> @@ -148,6 +164,14 @@ static inline unsigned long sbi_minor_version(void)
> >>         return sbi_spec_version & SBI_SPEC_VERSION_MINOR_MASK;
> >>  }
> >>
> >> +/* Make SBI version */
> >> +static inline unsigned long sbi_mk_version(unsigned long major,
> >> +                                           unsigned long minor)
> >> +{
> >> +       return ((major & SBI_SPEC_VERSION_MAJOR_MASK) <<
> >> +               SBI_SPEC_VERSION_MAJOR_SHIFT) | minor;
> >> +}
> >> +
> >>  int sbi_err_map_linux_errno(int err);
> >>  #else /* CONFIG_RISCV_SBI */
> >>  static inline int sbi_remote_fence_i(const unsigned long *hart_mask) { return -1; }
> >> diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
> >> index 7402a417f38e..9a84f0cb5175 100644
> >> --- a/arch/riscv/kernel/sbi.c
> >> +++ b/arch/riscv/kernel/sbi.c
> >> @@ -7,6 +7,7 @@
> >>
> >>  #include <linux/init.h>
> >>  #include <linux/pm.h>
> >> +#include <linux/reboot.h>
> >>  #include <asm/sbi.h>
> >>  #include <asm/smp.h>
> >>
> >> @@ -501,6 +502,32 @@ int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
> >>  }
> >>  EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);
> >>
> >> +static void sbi_srst_reset(unsigned long type, unsigned long reason)
> >> +{
> >> +       sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason,
> >> +                 0, 0, 0, 0);
> >> +       pr_warn("%s: type=0x%lx reason=0x%lx failed\n",
> >> +               __func__, type, reason);
> >> +}
> >> +
> >> +static int sbi_srst_reboot(struct notifier_block *this,
> >> +                          unsigned long mode, void *cmd)
> >> +{
> >> +       sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ?
> >> +                      SBI_SRST_RESET_TYPE_WARM_REBOOT :
> >> +                      SBI_SRST_RESET_TYPE_COLD_REBOOT,
> >> +                      SBI_SRST_RESET_REASON_NONE);
> >> +       return NOTIFY_DONE;
> >> +}
> >> +
> >> +static struct notifier_block sbi_srst_reboot_nb;
> >> +
> >> +static void sbi_srst_power_off(void)
> >> +{
> >> +       sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN,
> >> +                      SBI_SRST_RESET_REASON_NONE);
> >> +}
> >> +
> >>  /**
> >>   * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
> >>   * @extid: The extension ID to be probed.
> >> @@ -608,6 +635,14 @@ void __init sbi_init(void)
> >>                 } else {
> >>                         __sbi_rfence    = __sbi_rfence_v01;
> >>                 }
> >> +               if ((sbi_spec_version >= sbi_mk_version(0, 3)) &&
> >> +                   (sbi_probe_extension(SBI_EXT_SRST) > 0)) {
> >> +                       pr_info("SBI SRST extension detected\n");
> >> +                       pm_power_off = sbi_srst_power_off;
> >> +                       sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot;
> >> +                       sbi_srst_reboot_nb.priority = 192;
> >> +                       register_restart_handler(&sbi_srst_reboot_nb);
> >> +               }
> >>         } else {
> >>                 __sbi_set_timer = __sbi_set_timer_v01;
> >>                 __sbi_send_ipi  = __sbi_send_ipi_v01;
> >> --
> >> 2.25.1
> >>

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  reply	other threads:[~2021-07-08  3:54 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09 12:13 [PATCH v7 0/1] SBI SRST extension support Anup Patel
2021-06-09 12:13 ` Anup Patel
2021-06-09 12:13 ` [PATCH v7 1/1] RISC-V: Use SBI SRST extension when available Anup Patel
2021-06-09 12:13   ` Anup Patel
2021-06-22  4:46   ` Anup Patel
2021-06-22  4:46     ` Anup Patel
2021-07-06 20:27     ` Palmer Dabbelt
2021-07-06 20:27       ` Palmer Dabbelt
2021-07-07 15:49       ` Anup Patel [this message]
2021-07-07 15:49         ` Anup Patel
2021-07-10  5:01         ` Anup Patel
2021-07-10  5:01           ` Anup Patel
2021-07-11 18:59           ` Palmer Dabbelt
2021-07-11 18:59             ` Palmer Dabbelt
2021-07-29  4:30             ` Palmer Dabbelt
2021-07-29  4:30               ` Palmer Dabbelt
2021-07-29  4:44               ` Anup Patel
2021-07-29  4:44                 ` Anup Patel
2021-07-29  5:18               ` Anup Patel
2021-07-29  5:18                 ` Anup Patel
2021-07-29  6:10               ` Atish Patra
2021-07-29  6:10                 ` Atish Patra
2021-11-09 15:19                 ` Heinrich Schuchardt
2021-11-09 15:19                   ` Heinrich Schuchardt
2021-11-12 22:49                   ` Atish Patra
2021-11-12 22:49                     ` Atish Patra
2022-01-11  9:32                     ` Aurelien Jarno
2022-01-11  9:32                       ` Aurelien Jarno
2022-01-11 18:40                       ` Palmer Dabbelt
2022-01-11 18:40                         ` Palmer Dabbelt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAhSdy2TcESa_zfO28VGPuOH6+7T+U-Pa25G959LvMCmU49pJA@mail.gmail.com \
    --to=anup@brainfault.org \
    --cc=Alistair.Francis@wdc.com \
    --cc=Anup.Patel@wdc.com \
    --cc=Atish.Patra@wdc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmerdabbelt@google.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.