|
7 | 7 |
|
8 | 8 | #include <linux/init.h>
|
9 | 9 | #include <linux/pm.h>
|
| 10 | +#include <linux/reboot.h> |
10 | 11 | #include <asm/sbi.h>
|
11 | 12 | #include <asm/smp.h>
|
12 | 13 |
|
@@ -501,6 +502,32 @@ int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask,
|
501 | 502 | }
|
502 | 503 | EXPORT_SYMBOL(sbi_remote_hfence_vvma_asid);
|
503 | 504 |
|
| 505 | +static void sbi_srst_reset(unsigned long type, unsigned long reason) |
| 506 | +{ |
| 507 | + sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET, type, reason, |
| 508 | + 0, 0, 0, 0); |
| 509 | + pr_warn("%s: type=0x%lx reason=0x%lx failed\n", |
| 510 | + __func__, type, reason); |
| 511 | +} |
| 512 | + |
| 513 | +static int sbi_srst_reboot(struct notifier_block *this, |
| 514 | + unsigned long mode, void *cmd) |
| 515 | +{ |
| 516 | + sbi_srst_reset((mode == REBOOT_WARM || mode == REBOOT_SOFT) ? |
| 517 | + SBI_SRST_RESET_TYPE_WARM_REBOOT : |
| 518 | + SBI_SRST_RESET_TYPE_COLD_REBOOT, |
| 519 | + SBI_SRST_RESET_REASON_NONE); |
| 520 | + return NOTIFY_DONE; |
| 521 | +} |
| 522 | + |
| 523 | +static struct notifier_block sbi_srst_reboot_nb; |
| 524 | + |
| 525 | +static void sbi_srst_power_off(void) |
| 526 | +{ |
| 527 | + sbi_srst_reset(SBI_SRST_RESET_TYPE_SHUTDOWN, |
| 528 | + SBI_SRST_RESET_REASON_NONE); |
| 529 | +} |
| 530 | + |
504 | 531 | /**
|
505 | 532 | * sbi_probe_extension() - Check if an SBI extension ID is supported or not.
|
506 | 533 | * @extid: The extension ID to be probed.
|
@@ -608,6 +635,14 @@ void __init sbi_init(void)
|
608 | 635 | } else {
|
609 | 636 | __sbi_rfence = __sbi_rfence_v01;
|
610 | 637 | }
|
| 638 | + if ((sbi_spec_version >= sbi_mk_version(0, 3)) && |
| 639 | + (sbi_probe_extension(SBI_EXT_SRST) > 0)) { |
| 640 | + pr_info("SBI SRST extension detected\n"); |
| 641 | + pm_power_off = sbi_srst_power_off; |
| 642 | + sbi_srst_reboot_nb.notifier_call = sbi_srst_reboot; |
| 643 | + sbi_srst_reboot_nb.priority = 192; |
| 644 | + register_restart_handler(&sbi_srst_reboot_nb); |
| 645 | + } |
611 | 646 | } else {
|
612 | 647 | __sbi_set_timer = __sbi_set_timer_v01;
|
613 | 648 | __sbi_send_ipi = __sbi_send_ipi_v01;
|
|
0 commit comments