sbi_system.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. * Nick Kossifidis <mick@ics.forth.gr>
  9. */
  10. #include <sbi/riscv_asm.h>
  11. #include <sbi/sbi_bitops.h>
  12. #include <sbi/sbi_domain.h>
  13. #include <sbi/sbi_hart.h>
  14. #include <sbi/sbi_hsm.h>
  15. #include <sbi/sbi_platform.h>
  16. #include <sbi/sbi_system.h>
  17. #include <sbi/sbi_ipi.h>
  18. #include <sbi/sbi_init.h>
  19. bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason)
  20. {
  21. if (sbi_platform_system_reset_check(sbi_platform_thishart_ptr(),
  22. reset_type, reset_reason))
  23. return TRUE;
  24. return FALSE;
  25. }
  26. void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
  27. {
  28. ulong hbase = 0, hmask;
  29. u32 cur_hartid = current_hartid();
  30. struct sbi_domain *dom = sbi_domain_thishart_ptr();
  31. struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
  32. /* Send HALT IPI to every hart other than the current hart */
  33. while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &hmask)) {
  34. if (hbase <= cur_hartid)
  35. hmask &= ~(1UL << (cur_hartid - hbase));
  36. if (hmask)
  37. sbi_ipi_send_halt(hmask, hbase);
  38. hbase += BITS_PER_LONG;
  39. }
  40. /* Stop current HART */
  41. sbi_hsm_hart_stop(scratch, FALSE);
  42. /* Platform specific reset if domain allowed system reset */
  43. if (dom->system_reset_allowed)
  44. sbi_platform_system_reset(sbi_platform_ptr(scratch),
  45. reset_type, reset_reason);
  46. /* If platform specific reset did not work then do sbi_exit() */
  47. sbi_exit(scratch);
  48. }