sbi_ecall_srst.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2020 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. * Atish Patra <atish.patra@wdc.com>
  9. */
  10. #include <sbi/sbi_error.h>
  11. #include <sbi/sbi_ecall.h>
  12. #include <sbi/sbi_ecall_interface.h>
  13. #include <sbi/sbi_trap.h>
  14. #include <sbi/sbi_system.h>
  15. static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
  16. const struct sbi_trap_regs *regs,
  17. unsigned long *out_val,
  18. struct sbi_trap_info *out_trap)
  19. {
  20. if (funcid == SBI_EXT_SRST_RESET) {
  21. if ((((u32)-1U) <= ((u64)regs->a0)) ||
  22. (((u32)-1U) <= ((u64)regs->a1)))
  23. return SBI_EINVAL;
  24. switch (regs->a0) {
  25. case SBI_SRST_RESET_TYPE_SHUTDOWN:
  26. case SBI_SRST_RESET_TYPE_COLD_REBOOT:
  27. case SBI_SRST_RESET_TYPE_WARM_REBOOT:
  28. break;
  29. default:
  30. return SBI_EINVAL;
  31. }
  32. switch (regs->a1) {
  33. case SBI_SRST_RESET_REASON_NONE:
  34. case SBI_SRST_RESET_REASON_SYSFAIL:
  35. break;
  36. default:
  37. return SBI_EINVAL;
  38. }
  39. if (sbi_system_reset_supported(regs->a0, regs->a1))
  40. sbi_system_reset(regs->a0, regs->a1);
  41. }
  42. return SBI_ENOTSUPP;
  43. }
  44. static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
  45. {
  46. u32 type, count = 0;
  47. /*
  48. * At least one standard reset types should be supported by
  49. * the platform for SBI SRST extension to be usable.
  50. */
  51. for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
  52. if (sbi_system_reset_supported(type,
  53. SBI_SRST_RESET_REASON_NONE))
  54. count++;
  55. }
  56. *out_val = (count) ? 1 : 0;
  57. return 0;
  58. }
  59. struct sbi_ecall_extension ecall_srst = {
  60. .extid_start = SBI_EXT_SRST,
  61. .extid_end = SBI_EXT_SRST,
  62. .handle = sbi_ecall_srst_handler,
  63. .probe = sbi_ecall_srst_probe,
  64. };