Author: jrtc27
Date: Mon Jun  8 17:57:21 2020
New Revision: 361932
URL: https://svnweb.freebsd.org/changeset/base/361932

Log:
  riscv: Use SBI shutdown call to implement RB_POWEROFF
  
  Currently we only call sbi_shutdown in cpu_reset, which means we reach
  "Please press any key to reboot." even when RB_POWEROFF is set, and only
  once the user presses a key do we then shutdown. Instead, register a
  shutdown_final event handler and make an SBI shutdown call if
  RB_POWEROFF is set.
  
  Reviewed by:  br, jhb (mentor), kp
  Approved by:  br, jhb (mentor), kp
  Differential Revision:        https://reviews.freebsd.org/D25183

Modified:
  head/sys/riscv/riscv/sbi.c

Modified: head/sys/riscv/riscv/sbi.c
==============================================================================
--- head/sys/riscv/riscv/sbi.c  Mon Jun  8 17:40:39 2020        (r361931)
+++ head/sys/riscv/riscv/sbi.c  Mon Jun  8 17:57:21 2020        (r361932)
@@ -29,8 +29,11 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
+#include <sys/kernel.h>
 #include <sys/systm.h>
 #include <sys/types.h>
+#include <sys/eventhandler.h>
+#include <sys/reboot.h>
 
 #include <machine/md_var.h>
 #include <machine/sbi.h>
@@ -80,6 +83,13 @@ sbi_get_mimpid(void)
        return (SBI_CALL0(SBI_EXT_ID_BASE, SBI_BASE_GET_MIMPID));
 }
 
+static void
+sbi_shutdown_final(void *dummy __unused, int howto)
+{
+       if ((howto & RB_POWEROFF) != 0)
+               sbi_shutdown();
+}
+
 void
 sbi_print_version(void)
 {
@@ -187,3 +197,12 @@ sbi_init(void)
        KASSERT(sbi_probe_extension(SBI_SHUTDOWN) != 0,
            ("SBI doesn't implement sbi_shutdown()"));
 }
+
+static void
+sbi_late_init(void *dummy __unused)
+{
+       EVENTHANDLER_REGISTER(shutdown_final, sbi_shutdown_final, NULL,
+           SHUTDOWN_PRI_LAST);
+}
+
+SYSINIT(sbi, SI_SUB_KLD, SI_ORDER_ANY, sbi_late_init, NULL);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to